89c4318c8ba2b675e07c56a9f6c3b54621991834
[o-du/l2.git] / src / 5gnrrlc / rlc_cfg_dl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /********************************************************************20**
20
21         Name:    NR RLC - Configuration Manager file
22
23         Type:    C source file
24
25         Desc:    It contains the following configuraiton primtives
26                  for different actions
27                     -- rlcCfgValdtEntCfg
28                     -- rlcCfgFillRbCb
29                     -- rlcCfgRbInit
30                     -- rlcCfgAddRb
31                     -- rlcCfgReCfgRb
32                     -- rlcCfgDelRb
33                     -- rlcCfgReEstRb
34                     -- rlcCfgDelUe
35
36         File:    rlc_cfg_dl.c
37
38 *********************************************************************21*/
39
40 /** @file rlc_cfg_dl.c
41 @brief RLC Downlink Configuration Module
42 **/
43
44 \f
45 /* header (.h) include files */
46 #include "common_def.h"
47 #include "math.h"
48 #include "lkw.h"           /* LKW defines */
49 #include "ckw.h"           /* CKW defines */
50 #include "kwu.h"           /* KWU defines */
51 #include "rgu.h"           /* RGU defines */
52 #include "rlc_err.h"        /* RLC error options */
53 #include "rlc_env.h"        /* RLC environment options */
54
55
56 /* extern (.x) include files */
57 #include "lkw.x"           /* LKW */
58 #include "ckw.x"           /* CKW */
59 #include "kwu.x"           /* KWU */
60 #include "rgu.x"           /* RGU */
61
62 #include "rlc_utils.h"            /* RLC defines */
63 #include "rlc_dl_ul_inf.h"
64 #include "rlc_dl.h"
65 #include "du_app_rlc_inf.h"
66
67 #define RLC_MODULE RLC_DBGMASK_CFG
68 /*Added for adding new Ue in onging L2 Meas*/
69 #ifdef LTE_L2_MEAS
70 /**
71  *
72  * @brief Handle modification of UE ID for L2 Meas data structs
73  *       
74  *
75  *  @param[in] ueId     ue ID
76  *
77  *  @return  S16
78  *      -# ROK 
79  *      -# RFAILED 
80  *
81 */
82 static S16 rlcHdlMeasDlUeIdChg(RlcCb *gCb, uint8_t cellId,uint8_t oldUeId, uint8_t newUeId)
83 {
84    RlcL2MeasEvtCb *measEvtCb = NULLP;
85    RlcL2MeasCb    *measCb    = NULLP;
86    uint16_t       cntr;
87    uint16_t       ueIdx = 0;     
88
89    for(cntr = 0; cntr < LKW_MAX_L2MEAS; cntr++)
90    {
91       measEvtCb = &(gCb->u.dlCb->rlcL2Cb.rlcL2EvtCb[cntr]);
92       measCb = &(measEvtCb->measCb);
93
94
95       if(measCb->measType & LKW_L2MEAS_DL_IP ) 
96       {
97
98          for(ueIdx = 0; ueIdx < measCb->val.ipThMeas.numUes; ueIdx++)
99          {
100             if((measCb->val.ipThMeas.ueInfoLst[ueIdx].ueId) == oldUeId)
101             {
102                measCb->val.ipThMeas.ueInfoLst[ueIdx].ueId = newUeId;
103                break;
104             }
105          }
106       }
107    }
108    return ROK;
109 }
110
111 /**
112  *
113  * @brief Handler to delete an UE's L2 Meas ctxt
114  *       
115 *
116  *  @param[in] ueId     ue ID
117  *
118  *  @return  S16
119  *      -# ROK 
120  *      -# RFAILED 
121  *
122 */
123 static S16 rlcDelFrmDlL2Meas(RlcCb *gCb, uint8_t cellId,uint8_t ueId)
124 {
125    RlcL2MeasEvtCb *measEvtCb = NULLP;
126    RlcL2MeasCb    *measCb    = NULLP;
127    uint16_t       cntr;
128    uint16_t       ueIdx = 0;     
129
130
131    for(cntr = 0; cntr < LKW_MAX_L2MEAS; cntr++)
132    {
133       measEvtCb = &gCb->u.dlCb->rlcL2Cb.rlcL2EvtCb[cntr];
134       measCb = &(measEvtCb->measCb);
135
136
137       if(measCb->measType & LKW_L2MEAS_DL_IP )
138       {
139
140          for(ueIdx = 0; ((ueIdx < measCb->val.ipThMeas.numUes) &&
141                        (ueIdx < gCb->genCfg.maxUe)); ueIdx++)
142          {
143             if((measCb->val.ipThMeas.ueInfoLst[ueIdx].ueId) == ueId)
144             {
145                measCb->val.ipThMeas.ueInfoLst[ueIdx].isValid = FALSE;
146                if (measCb->val.ipThMeas.numUes-1 == ueIdx)
147                {
148                   measCb->val.ipThMeas.numUes--;
149                }
150                break;
151             }
152          }
153       }
154    }
155
156    return ROK;
157 }
158
159
160 static S16 rlcAddToDlL2Meas(RlcCb *gCb, RlcDlRbCb *rlcRbCb,uint8_t cellId,uint8_t ueId)
161 {
162    RlcL2MeasEvtCb *measEvtCb = NULLP;
163    RlcL2MeasCb    *measCb    = NULLP;
164    uint16_t       cntr;
165    uint16_t       cntr1;
166    uint16_t       ueIdx = 0;
167    uint16_t       qciIdx = 0;
168    uint16_t       *numQci;
169    #ifndef XEON_SPECIFIC_CHANGES 
170    uint8_t        freeIdx = gCb->genCfg.maxUe;
171    #else
172    uint16_t       freeIdx = LKW_MAX_UE;
173    #endif
174
175
176    for(cntr = 0; cntr < LKW_MAX_L2MEAS; cntr++)
177    {
178       measEvtCb = &gCb->u.dlCb->rlcL2Cb.rlcL2EvtCb[cntr];
179       measCb = &(measEvtCb->measCb);
180
181       freeIdx = gCb->genCfg.maxUe;
182
183       if(measCb->measType & 
184           (LKW_L2MEAS_ACT_UE | LKW_L2MEAS_UU_LOSS | LKW_L2MEAS_DL_DELAY))
185       {
186          for(cntr1 =0;((cntr1 < measCb->val.nonIpThMeas.numQci) &&
187                        (cntr1 < LKW_MAX_QCI));cntr1++)
188          {
189             if(measCb->val.nonIpThMeas.qci[cntr1] != rlcRbCb->qci)
190             {
191                measCb->val.nonIpThMeas.qci[cntr1]  = rlcRbCb->qci;
192                gCb->u.dlCb->rlcL2Cb.measOn[rlcRbCb->qci] |=measCb->measType;
193                break;
194             }
195          }
196       }
197
198       if(((rlcRbCb->rbL2Cb.measOn & measCb->measType) == LKW_L2MEAS_NONE))
199       {
200          if (measCb->measType & LKW_L2MEAS_ACT_UE)
201          {
202             if((rlcRbCb->mode == RLC_MODE_UM) &&
203                   (rlcRbCb->dir & RLC_DIR_DL ))
204             {
205                if (rlcRbCb->m.umDl.sduQ.count)
206                {
207                   if (rlcRbCb->ueCb->numActRb[rlcRbCb->qci] == 0)
208                   {
209                      rlcRbCb->ueCb->numActRb[rlcRbCb->qci]++;
210                      gCb->u.dlCb->rlcL2Cb.numActUe[rlcRbCb->qci]++;
211                   }
212                }
213             }
214             else if (rlcRbCb->mode == RLC_MODE_AM)
215             {
216                if ((rlcRbCb->m.amDl.cntrlBo) ||
217                      (rlcRbCb->m.amDl.retxBo)  ||
218                      (rlcRbCb->m.amDl.bo))
219                {
220                   if (rlcRbCb->ueCb->numActRb[rlcRbCb->qci] == 0)
221                   {
222                      rlcRbCb->ueCb->numActRb[rlcRbCb->qci]++;
223                      gCb->u.dlCb->rlcL2Cb.numActUe[rlcRbCb->qci]++;
224                   }
225                }
226             }
227          }
228       }
229       if((measCb->measType & LKW_L2MEAS_DL_IP))
230       {
231
232          for(ueIdx = 0; ((ueIdx < measCb->val.ipThMeas.numUes) &&
233                          (ueIdx < gCb->genCfg.maxUe)); ueIdx++)
234          {
235             if ((freeIdx == gCb->genCfg.maxUe) && 
236                   (measCb->val.ipThMeas.ueInfoLst[ueIdx].isValid == FALSE))
237             {
238                freeIdx = ueIdx;
239                continue;
240             }
241             if((measCb->val.ipThMeas.ueInfoLst[ueIdx].ueId) == ueId)
242             {
243                break;
244             }
245          }
246
247          if (ueIdx ==  measCb->val.ipThMeas.numUes)
248          {
249             if (gCb->genCfg.maxUe == measCb->val.ipThMeas.numUes)
250             {
251                return RFAILED;  
252             }
253             if (gCb->genCfg.maxUe == freeIdx)
254             {               
255                measCb->val.ipThMeas.numUes++;
256             }
257             else
258             {
259                ueIdx = freeIdx;
260             }
261             measCb->val.ipThMeas.ueInfoLst[ueIdx].isValid = TRUE;
262             memset(&measCb->val.ipThMeas.ueInfoLst[ueIdx].measData[0],0x00,(sizeof(RlcL2Cntr) *LKW_MAX_QCI));
263             measCb->val.ipThMeas.ueInfoLst[ueIdx].numQci = 0;
264          }
265          measCb->val.ipThMeas.ueInfoLst[ueIdx].ueId = ueId;
266          measCb->val.ipThMeas.ueInfoLst[ueIdx].cellId = cellId;
267          numQci = &(measCb->val.ipThMeas.ueInfoLst[ueIdx].numQci);
268
269          for (qciIdx =0; ((qciIdx <  *numQci) &&
270                            (qciIdx < LKW_MAX_QCI)) ; qciIdx++)
271          {
272             if (measCb->val.ipThMeas.ueInfoLst[ueIdx].qci[qciIdx] == rlcRbCb->qci)
273             {
274                break;
275             }
276          }
277
278          /* Fix Klock Warning */
279          if ((qciIdx == *numQci) && (qciIdx < LKW_MAX_QCI))
280          {
281             measCb->val.ipThMeas.ueInfoLst[ueIdx].qci[qciIdx] = rlcRbCb->qci;
282             (*numQci)++;
283          }
284
285          rlcUtlPlcMeasDatInL2Sts(&measCb->val.ipThMeas.ueInfoLst[ueIdx].measData[rlcRbCb->qci],
286                &rlcRbCb->rbL2Cb, measCb->measType);
287       }
288       else if (measCb->measType & 
289          (LKW_L2MEAS_DL_DISC | LKW_L2MEAS_DL_DELAY | LKW_L2MEAS_UU_LOSS))
290       {
291          rlcUtlPlcMeasDatInL2Sts(&measCb->val.nonIpThMeas.measData[rlcRbCb->qci],
292                &rlcRbCb->rbL2Cb, measCb->measType);
293          measCb->val.nonIpThMeas.qci[rlcRbCb->qci] = rlcRbCb->qci;
294          measCb->val.nonIpThMeas.measData[rlcRbCb->qci].totDrbsPerQci++;
295       }
296       rlcRbCb->rbL2Cb.measOn |= measCb->measType;      
297    }
298    return ROK;
299 }/*rlcAddToDlL2Meas*/ 
300 #endif /*LTE_L2_MEAS*/
301
302 \f
303 /** 
304  * @brief
305  *     This primitive fills the RbCb 
306  *
307  * @param [in]    gCb      -  RLC Instance Control Block
308  * @param [out]   rbCb     -  RB Control Block
309  * @param [out]   ueCb     -  UE Control Block
310  * @param [in]    entCfg   -  RLC Entity configuration
311  *
312  * @return  S16
313  *    -#ROK
314  *    -#RFAILED
315  */
316 static S16 rlcCfgFillDlRbCb(RlcCb *gCb,RlcDlRbCb *rbCb,RlcDlUeCb *ueCb,RlcEntCfgInfo *entCfg)
317 {
318
319    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgFillRbCb(ueId(%d),cellId(%d) rbType(%d))",
320                 rbCb->rlcId.ueId,
321                 rbCb->rlcId.cellId, 
322                 entCfg->rbType);
323
324    /* Initialize according to entMode */
325    switch (entCfg->entMode)
326    {
327       case RLC_MODE_TM:
328       {
329          rbCb->lch.lChId  = entCfg->lCh[0].lChId;
330          rbCb->lch.lChType = entCfg->lCh[0].type;
331          rbCb->dir = entCfg->dir;
332          break;
333       }
334
335       case RLC_MODE_UM:
336       {
337          rbCb->lch.lChId  = entCfg->lCh[0].lChId;
338          rbCb->lch.lChType = entCfg->lCh[0].type;
339          rbCb->dir = entCfg->dir;
340
341          /* Spec 38.322 Section 7.1 
342           * All UM state variables can take values from 0 to 63 for 6 bit SN or 
343           * from 0 to 4095 for 12 bit SN. All arithmetic operations on UM state 
344           * variables are affected by the UM modulus 
345           * (i.e. final value = [value from arithmetic operation] modulo 64
346           * for 6 bit SN and 4096 for 12 bit SN)
347           */
348          rbCb->m.umDl.snLen = entCfg->m.umInfo.dl.snLen;
349          if (entCfg->m.umInfo.dl.snLen == RLC_UM_CFG_6BIT_SN_LEN)
350             rbCb->m.umDl.modBitMask = 0x3f;
351          else
352             rbCb->m.umDl.modBitMask = 0xfff;
353
354          ueCb->lCh[rbCb->lch.lChId - 1].dlRbCb = rbCb;
355
356          break;
357       }
358       case RLC_MODE_AM:
359       {
360          /* Down Link Information 
361           * indx = 0 as Down Link   */
362          rbCb->lch.lChId  = entCfg->lCh[0].lChId;
363          rbCb->lch.lChType = entCfg->lCh[0].type;
364          rbCb->dir = RLC_DIR_BOTH;
365
366          rbCb->m.amDl.pollPdu = entCfg->m.amInfo.dl.pollPdu;
367          rbCb->m.amDl.pollByte = entCfg->m.amInfo.dl.pollByte;
368          rbCb->m.amDl.maxRetx = entCfg->m.amInfo.dl.maxRetx;
369          rbCb->m.amDl.pollRetxTmrInt = entCfg->m.amInfo.dl.pollRetxTmr;
370          rbCb->m.amDl.snLen = entCfg->m.amInfo.dl.snLen;
371          
372          if(RLC_AM_CFG_12BIT_SN_LEN == rbCb->m.amDl.snLen)
373          {
374             rbCb->m.amDl.snModMask = (1 << RLC_SN_LEN_12BITS) - 1; /* 5GNR */
375          }
376          else 
377          {
378             rbCb->m.amDl.snModMask = (1 << RLC_SN_LEN_18BITS) - 1; /* 5GNR */
379          }
380
381          cmInitTimers(&(rbCb->m.amDl.pollRetxTmr), 1);
382          ueCb->lCh[rbCb->lch.lChId - 1].dlRbCb = rbCb;
383        
384 #ifndef LTE_TDD 
385              uint32_t hashIndex;
386               RLC_ALLOC(gCb,
387                     rbCb->m.amDl.txBufLst,
388                     (RLC_TX_BUF_BIN_SIZE * sizeof(CmLListCp)));
389               for(hashIndex = 0; hashIndex < RLC_TX_BUF_BIN_SIZE; hashIndex++)
390               {
391                   cmLListInit(&(rbCb->m.amDl.txBufLst[hashIndex]));
392               }
393 #endif
394          break;
395       }
396       default:
397       {
398          DU_LOG("\nERROR  -->  RLC_DL : Invalid RB Mode ueId(%d),cellId(%d)",
399                   rbCb->rlcId.ueId,
400                   rbCb->rlcId.cellId);
401          return RFAILED;
402       }
403    }
404    rbCb->mode = entCfg->entMode;
405    rbCb->discTmrInt = entCfg->discardTmr;
406
407    return ROK;
408
409
410 \f
411 /** 
412  * @brief This primitive Initializes the RB Cb
413  *
414  * @param [in]    gCb      -  RLC Instance Control Block
415  * @param [out]   rbCb     -  RB Control Block
416  * @param [in]    ptr      -  Void pointer
417  * @param [in]    entCfg   -  Entity Configuration
418  *
419  * @return  S16
420  *    -#ROK
421  *    -#RFAILED
422  */
423 static S16 rlcCfgUpdateDlRb
424 (
425 RlcCb           *gCb,
426 RlcDlRbCb       *rbCb,
427 void            *ptr,
428 RlcEntCfgInfo   *entCfg
429 )
430 {
431    
432    if (rbCb->mode != entCfg->entMode)
433    {
434       DU_LOG("\nERROR  -->  RLC_DL : RB Mode Mismatch : exp [%d] rcv [%d] UEID:%d CELLID:%d", 
435             rbCb->mode, 
436             entCfg->entMode,
437             rbCb->rlcId.ueId,
438             rbCb->rlcId.cellId);
439       return (CKW_CFG_REAS_RB_MODE_MIS);
440    }
441
442    switch (rbCb->mode)
443    {
444       case RLC_MODE_TM:
445       {
446          RlcDlCellCb *cellCb = (RlcDlCellCb *)ptr;
447
448          rbCb->dir = entCfg->dir;
449          rbCb->lch.lChId = entCfg->lCh[0].lChId;
450          rbCb->lch.lChType = entCfg->lCh[0].type;
451
452          cellCb->lCh[rbCb->lch.lChId - 1].dlRbCb = rbCb;
453          break;
454       }
455
456       case RLC_MODE_UM:
457       {
458          RlcDlUeCb *ueCb = (RlcDlUeCb *)ptr;
459
460          if (entCfg->lCh[0].type == CM_LTE_LCH_DCCH)
461          {
462             return (CKW_CFG_REAS_LCHTYPE_MIS);
463          }
464          ueCb->lCh[rbCb->lch.lChId - 1].dlRbCb = NULLP;
465          ueCb->lCh[entCfg->lCh[0].lChId - 1].dlRbCb = rbCb;
466
467          rbCb->lch.lChId = entCfg->lCh[0].lChId;
468          rbCb->lch.lChType = entCfg->lCh[0].type;
469          rbCb->dir = entCfg->dir;
470          break;
471       }
472
473       case RLC_MODE_AM:
474       {
475          RlcDlUeCb *ueCb = (RlcDlUeCb *)ptr;
476
477          ueCb->lCh[rbCb->lch.lChId - 1].dlRbCb = NULLP;
478          ueCb->lCh[entCfg->lCh[1].lChId - 1].dlRbCb = rbCb;
479          
480          /* Down Link */
481          rbCb->lch.lChId = entCfg->lCh[1].lChId;
482          rbCb->lch.lChType = entCfg->lCh[1].type;
483          rbCb->m.amDl.pollRetxTmrInt = entCfg->m.amInfo.dl.pollRetxTmr;
484          rbCb->m.amDl.pollPdu = entCfg->m.amInfo.dl.pollPdu;
485          rbCb->m.amDl.pollByte = entCfg->m.amInfo.dl.pollByte;
486          rbCb->m.amDl.maxRetx = entCfg->m.amInfo.dl.maxRetx;
487          
488          break;
489       }
490    }
491
492 /* AGHOSH */
493    rbCb->discTmrInt = entCfg->discardTmr;
494 /* AGHOSH */
495    return (CKW_CFG_REAS_NONE);
496
497
498 \f
499 /** 
500  * @brief 
501  *    This primitive adds new RB in Ue/Cell Cb.
502  *
503  * @details
504  *    This function does following steps -
505  *    - If UE ID is 0 then
506  *    - Check for CELL CB is present
507  *    - If yes, Check for RB ID
508  *       - If RB ID is present Status Indication with reason
509  *       - Else, Create New RB CB in CELL CB
510  *    - If no Create New CELL CB and RB CB
511  *    - Else,
512  *       - Check for UE CB is present
513  *       - If yes Check for RB ID
514  *          - If RB ID is present Status Indication with reason
515  *          - Else, Create New RB CB in UE CB
516  *          - If no Create New UE CB and RB CB
517  *    - Fill entity confirmation
518  *
519  * @param [in]    gCb      -  RLC Instance Control Block
520  * @param [in]    ueId     -  UE Identifier
521  * @param [in]    cellId   -  CELL Identifier
522  * @param [in]    entCfg   -  Entity Configuration to be done.
523  * @param [out]   entCfm   -  Entity Confirmation.
524  *
525  * @return  S16
526  *    -# ROK
527  *    -# RFAILED
528  */
529 S16 rlcCfgAddDlRb
530 (
531 RlcCb               *gCb,
532 CmLteRnti          ueId,
533 CmLteCellId        cellId,
534 RlcEntCfgInfo      *entCfg,
535 RlcEntCfgCfmInfo   *entCfm
536 )
537 {
538    RlcDlUeCb     *ueCb = NULLP;   /* UE Control Block */
539    RlcDlCellCb   *cellCb;         /* Cell Control Block */
540    RlcDlRbCb     *rlcRbCb;         /* KW RB Control Block */
541    uint8_t       reason;          /* Rb Identifier */
542
543    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgAddRb(cellId(%d),UEID:%d cfgType(%d))",
544                 cellId, 
545                 ueId,
546                 entCfg->cfgType);
547
548    if (cellId == 0)
549    {
550       /* Fill entCfm structure */
551       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
552                           CKW_CFG_REAS_CELL_UNKWN);
553       DU_LOG("\nERROR  -->  RLC_DL : Add DLRb,CellId is 0 for UEID:%d",
554                ueId);
555       return RFAILED;
556    }
557    if ((entCfg->rguSapId >= gCb->genCfg.maxRguSaps) || (entCfg->rguSapId < 0))
558    {
559          RLCDBGP_ERROR(gCb, "rlcCfgAddDlRb(ueId(%u), cellId(%u), Invalid rguSapId (%d)\n",
560                ueId, cellId, entCfg->rguSapId);
561          return RFAILED; 
562    }
563
564
565    /* Process Adding new RB */
566    if (ueId == 0)
567    {
568       if(entCfg->rbId >= RLC_MAX_RB_PER_CELL)
569       {
570          /* Fill entCfm structure */
571          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
572                              CKW_CFG_CFM_NOK,
573                              CKW_CFG_REAS_RB_UNKWN);
574          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId ,Max is [%d] CELLID:%d UEID:%d",
575                   RLC_MAX_RB_PER_CELL,
576                   cellId,
577                   ueId);
578          return RFAILED;
579       }
580
581       if (((entCfg->lCh[0].type == CM_LTE_LCH_BCCH) || 
582            (entCfg->lCh[0].type == CM_LTE_LCH_PCCH) ||
583            (entCfg->lCh[0].type == CM_LTE_LCH_CCCH)) &&
584           (entCfg->entMode == RLC_MODE_TM))
585       {
586          /* Cell CB present */
587          rlcDbmFetchDlCellCb(gCb, cellId, &cellCb);
588          if(cellCb)
589          {
590             /* Get rbCb from cellCb->rbCb List */
591             if (( cellCb->rbCb[entCfg->rbId] != NULLP))
592             {
593                /* Fill entCfm structure */
594                RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
595                                    CKW_CFG_CFM_NOK,
596                                    CKW_CFG_REAS_RB_PRSNT);
597                DU_LOG("\nERROR  -->  RLC_DL : RbId [%d] already exists UEID:%d",
598                         entCfg->rbId,
599                         ueId);
600                return RFAILED;
601             }
602          }
603          else  /* Cell CB UNKNOWN */
604          {
605             /* Create CELL CB */
606             if ( ROK != rlcDbmCreateDlCellCb(gCb,cellId, &cellCb))
607             {
608                /* Fill entCfm structure */
609                RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
610                                    CKW_CFG_CFM_NOK,
611                                    CKW_CFG_REAS_CELL_CREAT_FAIL);
612                DU_LOG("\nERROR  -->  RLC_DL : cellCb Creation failed RBID:%d UEID:%d",
613                         entCfg->rbId,
614                         ueId);
615                return RFAILED;
616             }
617          }
618
619          /* Validate LChId */
620          if(entCfg->lCh[0].lChId <= 0)
621          {
622             DU_LOG("\nERROR  -->  RLC_DL : Invalid LcId CELLID:%d UEID:%d RBID:%d",
623                      cellId,
624                      ueId,
625                      entCfg->rbId);
626             /* Fill entCfm structure */                               
627             RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
628                   CKW_CFG_CFM_NOK, CKW_CFG_REAS_INVALID_LCHID);           
629             return RFAILED;                                        
630          }                                                            
631
632          /* Create RB CB */
633          RLC_ALLOC(gCb,rlcRbCb, sizeof (RlcDlRbCb));
634          if (!rlcRbCb)
635          {
636             DU_LOG("\nERROR  -->  RLC_DL : Memory allocation failed for rbId:%d CELLID:%d",
637                      entCfg->rbId,
638                      ueId);
639             /* Fill entCfm structure */                           
640             RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
641                                 CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_CREAT_FAIL); 
642             return RFAILED; 
643          }
644          rlcRbCb->rlcId.rbId = entCfg->rbId;
645          cellCb->rbCb[entCfg->rbId] = rlcRbCb;
646          RLC_LMM_RB_STS_INC(gCb);
647          cellCb->lCh[entCfg->lCh[0].lChId - 1].dlRbCb = rlcRbCb;
648       }
649       else
650       {
651          reason= (entCfg->entMode != RLC_MODE_TM)? CKW_CFG_REAS_RB_MODE_MIS:
652                                                       CKW_CFG_REAS_LCHTYPE_MIS;
653          /* Fill entCfm structure */
654          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
655                              CKW_CFG_CFM_NOK, reason);
656          return RFAILED;
657       }
658    }
659    else
660    {
661       if (!(RLC_VALIDATE_UE_RBID(entCfg->rbType, entCfg->rbId)))
662       {
663          /* Fill entCfm structure */
664          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
665                CKW_CFG_REAS_RB_UNKWN);
666          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId for RbType[%d] UEID:%d", 
667                   entCfg->rbType,
668                   ueId);
669          return RFAILED;
670       }
671       if ((((entCfg->lCh[0].type == CM_LTE_LCH_DCCH) && 
672             (entCfg->entMode != RLC_MODE_UM) && 
673             (CM_LTE_SRB == entCfg->rbType)) ||
674            ((entCfg->lCh[0].type == CM_LTE_LCH_DTCH) && 
675             (CM_LTE_DRB == entCfg->rbType))) &&
676           (entCfg->entMode != RLC_MODE_TM))
677       {
678          /* UE CB present */
679          if ( rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb) == ROK)
680          {
681             /* Get rbCb from ueCb->rbCb list */
682             RLC_DBM_GET_RBCB_FROM_UECB(entCfg->rbId, entCfg->rbType, ueCb, rlcRbCb);
683
684             if(( rlcRbCb != NULLP))
685             {
686                /* Fill entCfm structure */
687                RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
688                      CKW_CFG_REAS_RB_PRSNT);
689                DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:rbId [%d] already exists",
690                         cellId,
691                         entCfg->rbId);
692                return RFAILED;
693             }
694          }
695          else  /* UE CB UNKNOWN */
696          {
697             /* Create UE CB */
698             if ( rlcDbmCreateDlUeCb(gCb,ueId, cellId, &ueCb) != ROK)
699             {
700                /* Fill entCfm structure */
701                RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
702                      CKW_CFG_REAS_UE_CREAT_FAIL);
703                DU_LOG("\nERROR  -->  RLC_DL : UeId [%u]:ueCb Creation Failed RBID:%d",
704                         ueId,
705                         entCfg->rbId);
706                return RFAILED;
707             }
708             /* Start throughput calculation for this UE */
709             gCb->rlcThpt.thptPerUe[ueId -1].ueId  = ueId;
710             gCb->rlcThpt.thptPerUe[ueId -1].dataVol = 0;
711             gCb->rlcThpt.numActvUe++;
712          }
713
714          /* Validate LChId for UM and AM modes */
715          if ((entCfg->lCh[0].lChId <= 0) ||
716              ((entCfg->entMode == RLC_MODE_AM)&&
717                (entCfg->lCh[1].lChId <= 0)))
718          {
719             /* Fill entCfm structure */                               
720             RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
721                   CKW_CFG_CFM_NOK, CKW_CFG_REAS_INVALID_LCHID);           
722             return RFAILED;                                        
723          }                                                            
724
725          /* Create RB CB */
726          RLC_ALLOC(gCb,rlcRbCb, sizeof (RlcDlRbCb));
727          if (rlcRbCb == NULL)
728          {
729             /* Fill entCfm structure */                           
730             RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,CKW_CFG_CFM_NOK,
731                                     CKW_CFG_REAS_RB_CREAT_FAIL); 
732             DU_LOG("\nERROR  -->  RLC_DL : Memory allocation failed RBID:%d CELLID:%d",
733                      entCfg->rbId,
734                      cellId);
735             return RFAILED; 
736          }
737
738          /* copy the RB Cb into UECb */
739          rlcRbCb->rlcId.rbId = entCfg->rbId;
740          if(entCfg->rbType == CM_LTE_SRB)
741             ueCb->srbCb[entCfg->rbId] = rlcRbCb;
742          else
743             ueCb->drbCb[entCfg->rbId] = rlcRbCb;
744          
745          RLC_LMM_RB_STS_INC(gCb);
746
747       }
748       else
749       {
750          if (entCfg->entMode == RLC_MODE_TM)
751          {
752             reason = CKW_CFG_REAS_RB_MODE_MIS;
753          }
754          else
755          {
756             reason = CKW_CFG_REAS_LCHTYPE_MIS;
757          }
758
759          /* Fill entCfm structure */
760          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK, reason);
761          return RFAILED;
762       }
763    }
764
765
766    rlcRbCb->rlcId.cellId = cellId;
767    rlcRbCb->rlcId.ueId   = ueId;
768    rlcRbCb->rlcId.rbType = entCfg->rbType;
769    rlcRbCb->inst         = gCb->init.inst;
770 #ifdef TENB_MULT_CELL_SUPPRT
771    rlcRbCb->rguSapId     = entCfg->rguSapId;
772 #endif
773
774
775    /* Fill RB CB */
776    if (rlcCfgFillDlRbCb(gCb,rlcRbCb, ueCb, entCfg) != ROK)
777    {
778       /* Fill entCfm structure */
779       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
780                CKW_CFG_REAS_RB_CREAT_FAIL);
781
782       /* Delete RB CB created */
783       RLC_FREE(gCb,rlcRbCb, sizeof(RlcDlRbCb));
784       DU_LOG("\nERROR  -->  RLC_DL : Filling of RbCb failed UEID:%d CELLID:%d",
785                ueId,
786                cellId);
787       return RFAILED;
788    }
789    rlcRbCb->qci = entCfg->qci;
790 #ifdef LTE_L2_MEAS
791    rlcRbCb->ueCb =  ueCb;
792    if (entCfg->lCh[0].type == CM_LTE_LCH_DTCH)
793    {
794       /* ccpu00129778 */
795       rlcAddToDlL2Meas(gCb, rlcRbCb,cellId,ueId); 
796    }
797 #endif /* LTE_L2_MEAS */
798
799    /* Fill entCfm structure */
800    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
801
802    return ROK;
803
804
805 \f
806 /** 
807  * @brief
808  *    This primitive reconfigures the existing RB in Ue/Cell Cb.
809  *
810  * @details
811  *    This primitive executes following steps in reconfiguration of existing
812  *    RB -
813  *    - If UE ID is 0 then
814  *       - Check for CELL CB is present
815  *       - If yes, Check for RB ID
816  *          - If RB ID is present Reconfigure the RB CB
817  *          - Else, Status Indication with Reason
818  *       - Else, Status Indication with Reason
819  *    - Else,
820  *       - Check for UE CB is present
821  *       - If yes, Check for RB ID
822  *          - If RB ID is prenset Reconfigure the CELL CB
823  *          - Else, Status Indication with Reason
824  *       - Else, Status Indication with Reason
825  *    - Fill entity confirmation
826  *
827  * @param [in]    gCb      -  RLC Instance Control Block
828  * @param [in]    ueId     -  UE Identifier
829  * @param [in]    cellId   -  CELL Identifier
830  * @param [in]    entCfg   -  Entity Configuration to be done.
831  * @param [out]   entCfm   -  Entity Confirmation
832  *
833  * @return  S16
834  *    -#ROK
835  *    -#RFAILED
836  */
837 S16 rlcCfgReCfgDlRb
838 (
839 RlcCb               *gCb,
840 CmLteRnti          ueId,
841 CmLteCellId        cellId,
842 RlcEntCfgInfo      *entCfg,
843 RlcEntCfgCfmInfo   *entCfm
844 )
845 {
846    RlcDlRbCb     *rbCb;     /* RB Control Block */
847    RlcDlRbCb     tRbCb;     /* KW RB Control Block */
848    RlcDlCellCb   *cellCb;   /* Cell Control Block */
849    RlcDlUeCb     *ueCb;     /* Ue Control Block */
850    uint8_t       ret;
851
852    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgReCfgRb(cellId(%d), cfgType(%d)) RBID:%d",
853             cellId, entCfg->cfgType,entCfg->rbId);
854
855
856    /* Check for UeCb or CellCb */
857    if (ueId == 0)
858    { 
859       if(entCfg->rbId >= RLC_MAX_RB_PER_CELL)
860       {
861          /* Fill entCfm structure */
862          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
863                              CKW_CFG_REAS_RB_UNKWN);
864          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId , Max is [%d] UEID:%d CELLID:%d",
865                   RLC_MAX_RB_PER_CELL,
866                   ueId,
867                   cellId);
868          return RFAILED;
869       }
870       /* Get cellCb */
871       rlcDbmFetchDlCellCb(gCb,cellId, &cellCb);
872       if(!cellCb)
873       {
874          /* Fill entCfm structure */
875          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
876                              CKW_CFG_REAS_CELL_UNKWN);
877          DU_LOG("\nERROR  -->  RLC_DL : CellCb not found ueId:%d RBID:%d CELLID:%d",
878                   ueId,
879                   entCfg->rbId,
880                   cellId);
881          return RFAILED;
882       }
883
884       /* Get rbCb */
885       RLC_DBM_GET_CELL_RBCB(entCfg->rbId, cellCb->rbCb, rbCb);
886
887       if (!rbCb)
888       {
889          /* Fill entCfm structure */
890          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
891                CKW_CFG_REAS_RB_UNKWN);
892          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d RBID:%d not found",
893                   cellId,
894                   entCfg->rbId);
895          return RFAILED;
896       }
897
898       /* Take backup of rbCb before updating.
899        * Because in failure case restore original rbCb
900        */
901       memcpy(&tRbCb, rbCb, sizeof(RlcDlRbCb));
902
903       /* Update rbCb */
904       ret = rlcCfgUpdateDlRb(gCb,rbCb, cellCb,entCfg);
905       if (ret != ROK)
906       {
907          /* Fill entCfm structure */
908          RLC_CFG_FILL_CFG_CFM(entCfm, 
909                              entCfg->rbId, 
910                              entCfg->rbType, 
911                              CKW_CFG_CFM_NOK,
912                              ret);
913
914          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%u RBID:%d updation failed",
915                   cellId,
916                   entCfg->rbId);
917          memcpy(rbCb, &tRbCb, sizeof(RlcDlRbCb));
918
919          return (ret);
920       }
921    }
922    else
923    {
924       if (!(RLC_VALIDATE_UE_RBID(entCfg->rbType, entCfg->rbId)))
925       {
926          /* Fill entCfm structure */
927          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
928                CKW_CFG_REAS_RB_UNKWN);
929          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d Invalid RBID:%d for RbType[%d]",
930                   cellId,
931                   entCfg->rbId,
932                   entCfg->rbType);
933          return RFAILED;
934       }
935       /* Get ueCb */
936       ret = rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb);
937       if (ret != ROK)
938       {
939          /* Fill entCfm structure */
940          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
941                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
942          DU_LOG("\nERROR  -->  RLC_DL : UEID:%d UeCb not found RBID:%d",
943                   ueId,
944                   entCfg->rbId);
945          return (ret);
946       }
947
948       /* Get rbCb */
949       RLC_DBM_GET_RBCB_FROM_UECB(entCfg->rbId, entCfg->rbType, ueCb, rbCb);
950
951       if ( rbCb == NULLP)
952       {
953          /* Fill entCfm structure */
954          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
955                CKW_CFG_REAS_RB_UNKWN);
956          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d RBID:%d not found",
957                   cellId,
958                   entCfg->rbId);
959          return (ret);
960       }
961
962       /* Take backup of rbCb before updating.
963        * Because in failure case restore original rbCb
964        */
965       memcpy(&tRbCb, rbCb, sizeof(RlcDlRbCb));
966
967       /* Update rbCb */
968       ret = rlcCfgUpdateDlRb(gCb,rbCb,ueCb, entCfg);
969       if (ret != CKW_CFG_REAS_NONE)
970       {
971          /* Fill entCfm structure */
972          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
973                ret);
974         DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d RBID:%d updation failed",
975                   cellId,
976                   entCfg->rbId);
977          memcpy(rbCb, &tRbCb, sizeof(RlcDlRbCb));
978
979          return (ret);
980       }
981    }
982
983    /* Fill entCfm structure */
984    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
985
986    return ROK;
987
988
989 \f
990 /** 
991  * @brief This primitive deletes the existing RB in Ue/Cell Cb.
992  *
993  * @details
994  *    - If UE ID is 0 then
995  *      - Check for CELL CB is present
996  *       - If yes, Check for RB ID
997  *      - If RB ID is prenset Delete the RB CB
998  *       - If there is no RB CB exist in CELL CB then Delete CELL CB.
999  *      - Else, Status Indication with Reason
1000  *      - Else, Status Indication with Reason
1001  *    - Else,
1002  *      - Check for UE CB is present
1003  *      - If yes, Check for RB ID
1004  *        - If RB ID is prenset Delete the RB CB
1005  *          - If there is no RB CB exist in UE CB then Delete UE CB.
1006  *        - Else, Status Indication with Reason
1007  *      - Else, Status Indication with Reason
1008  *    - Fill entity confirmation
1009  *
1010  * @param [in]    gCb      -  RLC Instance Control Block
1011  * @param [in]    ueId     -  UE Identifier
1012  * @param [in]    cellId   -  CELL Identifier
1013  * @param [in]    entCfg   -  Entity Configuration to be done.
1014  * @param [out]   entCfm   -  Entity Confirmation
1015  *
1016  * @return  S16
1017  *    -#ROK
1018  *    -#RFAILED
1019  */
1020 S16 rlcCfgDelDlRb
1021 (
1022 RlcCb               *gCb,
1023 CmLteRnti          ueId,
1024 CmLteCellId        cellId,
1025 RlcEntCfgInfo      *entCfg,
1026 RlcEntCfgCfmInfo   *entCfm
1027 )
1028 {
1029    S16          ret;       /* Return Value */
1030    RlcDlUeCb     *ueCb;     /* UE Control Block */
1031    RlcDlCellCb   *cellCb;   /* UE Control Block */
1032    RlcDlRbCb     *rlcRbCb;   /* KW RB Control Block */
1033
1034    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgDelRb(RBID(%d), cellId(%d), cfgType(%d))",
1035             entCfg->rbId, 
1036             cellId, 
1037             entCfg->cfgType);
1038
1039    ret = ROK;
1040
1041    /* Get cellCb and delete rbCb from it */
1042    if (ueId == 0)
1043    {
1044       if(entCfg->rbId >= RLC_MAX_RB_PER_CELL)
1045       {
1046          /* Fill entCfm structure */
1047          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1048                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1049          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId, Max is [%d] UEID:%d CELLID:%d",
1050                   RLC_MAX_RB_PER_CELL,
1051                   ueId,
1052                   cellId);
1053          return RFAILED;
1054       }
1055       /* Get cellCb */
1056       rlcDbmFetchDlCellCb(gCb,cellId, &cellCb);
1057       if (!cellCb)
1058       {
1059          /* Fill entCfm structure */
1060          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1061                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1062          DU_LOG("\nERROR  -->  RLC_DL : CellCb not found UEID:%d RBID:%d",
1063                   ueId,
1064                   entCfg->rbId);
1065          return (ret);
1066       }
1067
1068       /* Get rbCb */
1069       RLC_DBM_GET_CELL_RBCB(entCfg->rbId, cellCb->rbCb, rlcRbCb);
1070
1071       if ( rlcRbCb == NULLP)
1072       {
1073          /* Fill entCfm structure */
1074          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1075                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1076          DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:RbId[%d] not found",
1077                   cellId,
1078                   entCfg->rbId);
1079          return (ret);
1080       }
1081
1082       /* Assign NULLP to rbCb in rbCbLst */
1083       cellCb->rbCb[entCfg->rbId] = NULLP;
1084
1085       /* Assign NULLP to dlRbCb/ulRbCb.
1086        * Delete Hashlist allocated for it if any */
1087       cellCb->lCh[rlcRbCb->lch.lChId - 1].dlRbCb = NULLP;
1088       RLC_FREE(gCb,rlcRbCb, sizeof(RlcDlRbCb));   /*Vartika: Mem leak fix */  
1089    }
1090     /* Get ueCb and delete rbCb from it */
1091    else
1092    {
1093       if (!(RLC_VALIDATE_UE_RBID(entCfg->rbType, entCfg->rbId)))
1094       {
1095          /* Fill entCfm structure */
1096          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1097                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1098          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId for RbType[%d] UEID:%d CELLID:%d", 
1099                   entCfg->rbType,
1100                   ueId,
1101                   cellId);
1102          return RFAILED;
1103       }
1104
1105       /* Get ueCb */
1106       ret = rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb);
1107       if (ret != ROK)
1108       {
1109          /* Fill entCfm structure */
1110          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1111                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
1112           DU_LOG("\nERROR  -->  RLC_DL : UeId [%d]: UeCb not found RBID:%d",
1113                   ueId,
1114                   entCfg->rbId);
1115          return (ret);
1116       }
1117
1118       /* Get rbCb */
1119       RLC_DBM_GET_RBCB_FROM_UECB(entCfg->rbId, entCfg->rbType, ueCb, rlcRbCb);
1120
1121       if ( rlcRbCb == NULLP)
1122       {
1123          /* Fill entCfm structure */
1124          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1125                CKW_CFG_REAS_RB_UNKWN);
1126          DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:RbId[%d] not found",
1127                   cellId,
1128                   entCfg->rbId);
1129          return (ret);
1130       }
1131
1132       ueCb->lCh[rlcRbCb->lch.lChId - 1].dlRbCb = NULLP;
1133
1134 #ifdef LTE_L2_MEAS
1135       RLC_UPD_L2_DECR_NONIP_PER_QCI_RB_COUNT(gCb, rlcRbCb);
1136 #endif
1137       /* Free the Buffers of RbCb */
1138       if( RLC_MODE_UM == rlcRbCb->mode)
1139       {
1140          rlcUmmFreeDlRbCb(gCb,rlcRbCb);
1141          /* Delete RbCb  */
1142          RLC_FREE(gCb,rlcRbCb, sizeof(RlcDlRbCb));     
1143       }
1144       else if( RLC_MODE_AM == rlcRbCb->mode)
1145       {
1146          rlcAmmFreeDlRbCb(gCb,rlcRbCb);
1147       }
1148
1149       /* Assign NULLP to rbCb in rbCbLst */
1150       if ( entCfg->rbType == CM_LTE_SRB )
1151       {
1152          ueCb->srbCb[entCfg->rbId] = NULLP;
1153       }
1154       else
1155       {
1156          ueCb->drbCb[entCfg->rbId] = NULLP;
1157       }
1158    }
1159
1160    RLC_LMM_RB_STS_DEC(gCb);
1161
1162    /* Fill entCfm structure */
1163    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_OK, 
1164                        CKW_CFG_REAS_NONE);
1165
1166    return (ret);
1167
1168
1169 \f
1170 /** 
1171  * @brief This primitive re-establish the existing RB in Ue/Cell Cb.
1172  *
1173  * @details
1174  *    - If UE ID is 0 then
1175  *      - Check for CELL CB is present
1176  *      - If yes, Check for RB ID
1177  *        - If RB ID is prenset initialize the parameters of the RB CB
1178  *        - Else, Status Indication with Reason
1179  *      - Else, Status Indication with Reason
1180  *    - Else,
1181  *      - Check for UE CB is present
1182  *      - If yes, Check for RB ID
1183  *        - If RB ID is prenset initialize the parameters of the RB CB
1184  *        - Else, Status Indication with Reason
1185  *      - Else, Status Indication with Reason
1186  *    - Fill entity confirmation
1187  *
1188  * @param [in]    gCb      -  RLC Instance Control Block
1189  * @param [in]    ueId     -  UE Identifier
1190  * @param [in]    cellId   -  CELL Identifier
1191  * @param [in]    entCfg   -  Entity Configuration to be done.
1192  * @param [out]   entCfm   -  Entity Confirmation
1193  *
1194  * @return  S16
1195  *    -# ROK
1196  *    -# RFAILED
1197  */
1198 S16 rlcCfgReEstDlRb
1199 (
1200 RlcCb              *gCb,
1201 CmLteRnti          ueId,
1202 CmLteCellId        cellId,
1203 Bool               sndReEstInd,
1204 RlcEntCfgInfo      *entCfg,
1205 RlcEntCfgCfmInfo   *entCfm
1206 )
1207 {
1208    RlcDlRbCb     *rbCb;   /* RB Control Block */
1209    CmLteRlcId   rlcId;   /* RLC Identifier */
1210
1211    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgReEstDlRb(ueId(%d), cellId(%d), cfgType(%d))",
1212             ueId, 
1213             cellId, 
1214             entCfg->cfgType);
1215
1216    /* Get rlcId */
1217    rlcId.ueId = ueId;
1218    rlcId.cellId = cellId;
1219    rlcId.rbId = entCfg->rbId;
1220    rlcId.rbType = entCfg->rbType;
1221
1222    rlcDbmFetchDlRbCbByRbId(gCb,&rlcId, &rbCb);
1223    if (rbCb == NULLP)
1224    {
1225       /* Fill entCfm structure */
1226       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, rlcId.rbType, CKW_CFG_CFM_NOK,
1227             CKW_CFG_REAS_RB_UNKWN);
1228       DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:RbId[%d] not found",
1229                cellId,
1230                entCfg->rbId);
1231       return RFAILED;
1232    }
1233
1234    rbCb->rlcId.ueId = ueId;
1235
1236    switch (rbCb->mode)
1237    {
1238       case RLC_MODE_TM:
1239          {
1240             rlcDlTmmReEstablish(gCb,rbCb);
1241             break;
1242          }
1243
1244       case RLC_MODE_UM:
1245          {
1246             rlcDlUmmReEstablish(gCb,rlcId,sndReEstInd,rbCb);
1247             break;
1248          }
1249
1250       case RLC_MODE_AM:
1251          {           
1252             rlcAmmDlReEstablish(gCb, rlcId, rbCb);
1253             break;
1254          }
1255    }
1256
1257    /* Fill entCfm structure */
1258    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1259       CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
1260
1261    return ROK;
1262
1263
1264 \f
1265 /** 
1266  * @brief This primitive deletes the RBs in Ue Cb.
1267  *
1268  * @details
1269  *    - If UE ID is 0 then
1270  *      - Status Indication with Reason
1271  *    - Else,
1272  *      - Check for UE CB is present
1273  *      - If yes, Delete all RB CB in UE CB and Delete UE CB also.
1274  *      - Else, Status Indication with Reason
1275  *    - Fill entity confirmation
1276  *
1277  * @param [in]    gCb      -  RLC Instance Control Block
1278  * @param [in]    ueId     -  UE Identifier
1279  * @param [in]    cellId   -  CELL Identifier
1280  * @param [in]    entCfg   -  Entity Configuration to be done.
1281  * @param [out]   entCfm   -  Entity Confirmation
1282  *
1283  * @return  S16
1284  *    -#ROK
1285  *    -#RFAILED
1286  */
1287 S16 rlcCfgDelDlUe
1288 (
1289 RlcCb              *gCb,
1290 CmLteRnti          ueId,
1291 CmLteCellId        cellId,
1292 RlcEntCfgInfo      *entCfg,
1293 RlcEntCfgCfmInfo   *entCfm
1294 )
1295 {
1296    S16        ret;     /* Return Value */
1297    RlcDlUeCb   *ueCb;   /* UE Control Block */
1298
1299    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgDelUe(ueId(%d), cellId(%d), cfgType(%d))",
1300             ueId, 
1301             cellId, 
1302             entCfg->cfgType);
1303
1304    ret = ROK;
1305
1306    /* Check for ueId is present or not */
1307    if ( ueId == 0 )
1308    {
1309       /* Fill entCfm structure */
1310       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1311           CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
1312       DU_LOG("\nERROR  -->  RLC_DL : ueId(%d), cellId(%d)",
1313                ueId, 
1314                cellId);
1315       return RFAILED;
1316    }
1317
1318    /* Fetch Ue Cb */
1319    ret = rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb);
1320    if (ret != ROK)
1321    {
1322       /* Fill entCfm structure */
1323       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1324          CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
1325       DU_LOG("\nERROR  -->  RLC_DL : UEID:%d UeCb not found RBID:%d",
1326                ueId,
1327                entCfg->rbId);
1328       return RFAILED;
1329    }
1330
1331 #ifdef LTE_L2_MEAS
1332    rlcDelFrmDlL2Meas(gCb,cellId,ueId);
1333    rlcDbmDelAllDlL2MeasTbFrmUe(gCb,ueCb);
1334 #endif
1335    /* Delete Ue Cb */
1336    rlcDbmDelDlUeCb(gCb,ueCb, FALSE);
1337
1338    /* Fill entCfm structure */
1339    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1340       CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
1341
1342    return ROK;
1343
1344
1345
1346 /**
1347  * @brief This primitive deletes the RBs in Ue Cb.
1348  *
1349  * @details
1350  *    - If CELL ID is 0 then
1351  *      - Status Indication with Reason
1352  *    - Else,
1353  *      - Check for CELL CB is present
1354  *      - If yes, Delete all RB CB in CELL CB and Delete CELL CB also.
1355  *      - Else, Status Indication with Reason
1356  *    - Fill entity confirmation
1357  *
1358  * @param [in]    cellId   -  CELL Identifier
1359  * @param [in]    entCfg   -  Entity Configuration to be done.
1360  * @param [out]   entCfm   -  Entity Confirmation
1361  *
1362  * @return S16
1363  *    -#ROK
1364  *    -#RFAILED
1365  */
1366 S16 rlcCfgDelDlCell
1367 (
1368 RlcCb               *gCb,
1369 CmLteCellId        cellId,
1370 RlcEntCfgInfo      *entCfg,
1371 RlcEntCfgCfmInfo   *entCfm
1372 )
1373 {
1374    RlcDlCellCb   *cellCb;   /* UE Control Block */
1375    uint8_t       rbId;      /* RB Identifier */
1376
1377    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgDelCell( cellId(%d), cfgType(%d)",
1378          cellId, 
1379          entCfg->cfgType);
1380
1381    cellCb = NULLP;
1382    rbId = entCfg->rbId;
1383
1384    /* Check for ueId is present or not */
1385    if ( cellId == 0 )
1386    {
1387       /* Fill entCfm structure */
1388       RLC_CFG_FILL_CFG_CFM(entCfm, rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1389             CKW_CFG_REAS_CELL_UNKWN);
1390       DU_LOG("\nERROR  -->  RLC_DL : cellId is 0 (%d) ",
1391                cellId);
1392       return RFAILED;
1393    }
1394
1395    /* Fetch Ue Cb */
1396    rlcDbmFetchDlCellCb(gCb,cellId, &cellCb);
1397    if (!cellCb)
1398    {
1399       /* Fill entCfm structure */
1400       RLC_CFG_FILL_CFG_CFM(entCfm, rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1401             CKW_CFG_REAS_CELL_UNKWN);
1402       DU_LOG("\nERROR  -->  RLC_DL : CellCb not found for RBID:%d",
1403                entCfg->rbId);
1404       return RFAILED;
1405    }
1406
1407    /* Delete Ue Cb */
1408    rlcDbmDelDlCellCb(gCb,cellCb);
1409
1410    /* Fill entCfm structure */
1411   /* kw005.201 added support for L2 Measurement */         
1412    RLC_CFG_FILL_CFG_CFM(entCfm, rbId, entCfg->rbType, CKW_CFG_CFM_OK,
1413                        CKW_CFG_REAS_NONE);
1414
1415    return ROK;
1416
1417
1418 /**
1419  * @brief This primitive changes the ueId of Ue Cb.
1420  *
1421  * @details
1422  *    - If oldUeId and newUeId are
1423  *      - Confirm the Status with Reason
1424  *    - If UeId not present
1425  *      - Confirm the Status with Reason
1426  *    - Create New UeCb
1427  *    - Copy rbCbs from old UeCb to new UeCb
1428  *    - Delete old UeCb
1429  *    - Fill entity confirmation
1430  *
1431  * @param [in]    ueInfo      -  Old UE Information
1432  * @param [in]    newUeInfo   -  New UE Information
1433  * @param [out]   status      -  Status
1434  *
1435  * @return  S16
1436  *    -# ROK
1437  *    -# RFAILED
1438  */
1439 S16 rlcCfgDlUeIdChng
1440 (
1441 RlcCb        *gCb,
1442 CkwUeInfo   *ueInfo,
1443 CkwUeInfo   *newUeInfo,
1444 CmStatus    *status
1445 )
1446 {
1447    RlcDlUeCb *ueCb;
1448 /*kw004.201 Adding of Missing Trace in RLC PDCP*/
1449
1450    if ( (ueInfo->ueId == newUeInfo->ueId) && 
1451         (ueInfo->cellId == newUeInfo->cellId))
1452    {
1453       status->reason = CKW_CFG_REAS_SAME_UEID;
1454       status->status = CKW_CFG_CFM_NOK; 
1455       DU_LOG("\nERROR  -->  RLC_DL : Old UeId[%d] same as new UeId[%d]",
1456             ueInfo->ueId,
1457             newUeInfo->ueId);
1458       return RFAILED;
1459    } 
1460    
1461    if(ROK == rlcDbmFetchDlUeCb(gCb,newUeInfo->ueId, newUeInfo->cellId, &ueCb))
1462    {
1463       DU_LOG("\nERROR  -->  RLC_DL : NewUeId[%d]:ueCb already exists",
1464             newUeInfo->ueId);
1465       status->reason = CKW_CFG_REAS_UE_EXISTS;
1466       status->status = CKW_CFG_CFM_NOK;
1467       return RFAILED;
1468    }
1469   
1470    if(ROK != rlcDbmFetchDlUeCb(gCb,ueInfo->ueId, ueInfo->cellId, &ueCb))
1471    {
1472
1473       DU_LOG("\nERROR  -->  RLC_DL : UeId [%d]: UeCb not found",
1474             ueInfo->ueId);
1475       status->reason = CKW_CFG_REAS_UE_UNKWN;
1476       status->status = CKW_CFG_CFM_NOK;
1477       return RFAILED;
1478    }
1479   
1480 #ifdef LTE_L2_MEAS
1481    rlcHdlMeasDlUeIdChg(gCb, ueInfo->cellId, ueInfo->ueId, newUeInfo->ueId);
1482 #endif   
1483    if(ROK != cmHashListDelete(&(gCb->u.dlCb->ueLstCp), (PTR) ueCb))
1484    {
1485       DU_LOG("\nERROR  -->  RLC_DL : UeId[%u] HashList Deletion Failed",
1486             ueInfo->ueId);
1487       status->reason = CKW_CFG_REAS_UE_CREAT_FAIL;
1488       status->status = CKW_CFG_CFM_NOK;
1489       return RFAILED;
1490    }
1491    
1492    /* update the hash key with new values */ 
1493    ueCb->ueId = newUeInfo->ueId;
1494    ueCb->cellId = newUeInfo->cellId;
1495
1496    if(ROK != cmHashListInsert(&(gCb->u.dlCb->ueLstCp), 
1497                               (PTR)ueCb, (uint8_t *)&(ueCb->ueId),
1498                               (uint16_t) sizeof(CmLteRnti)))
1499
1500    {
1501       DU_LOG("\nERROR  -->  RLC_DL : UeId[%u] HashList Insertion Failed",
1502             newUeInfo->ueId);
1503       status->reason = CKW_CFG_REAS_UE_CREAT_FAIL;
1504       status->status = CKW_CFG_CFM_NOK;
1505       return RFAILED;
1506    }  
1507   
1508    return ROK;
1509
1510
1511 /********************************************************************30**
1512
1513          End of file
1514 **********************************************************************/