9c24eb424ba760237ec91ea2eee8d76291529abd
[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[gCb->rlcThpt.numActvUe].ueIdx = ueId;
710             gCb->rlcThpt.thptPerUe[gCb->rlcThpt.numActvUe].dataVol = 0;
711             gCb->rlcThpt.numActvUe++;
712             
713             if((rlcChkTmr(gCb, (PTR)(&gCb->rlcThpt), EVENT_RLC_THROUGHPUT_TMR)) == FALSE)
714             {
715                printf("\nHLAL Starting Throughput timer");
716                rlcStartTmr(gCb, (PTR)(&gCb->rlcThpt), EVENT_RLC_THROUGHPUT_TMR);
717             }
718          }
719
720          /* Validate LChId for UM and AM modes */
721          if ((entCfg->lCh[0].lChId <= 0) ||
722              ((entCfg->entMode == RLC_MODE_AM)&&
723                (entCfg->lCh[1].lChId <= 0)))
724          {
725             /* Fill entCfm structure */                               
726             RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
727                   CKW_CFG_CFM_NOK, CKW_CFG_REAS_INVALID_LCHID);           
728             return RFAILED;                                        
729          }                                                            
730
731          /* Create RB CB */
732          RLC_ALLOC(gCb,rlcRbCb, sizeof (RlcDlRbCb));
733          if (rlcRbCb == NULL)
734          {
735             /* Fill entCfm structure */                           
736             RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,CKW_CFG_CFM_NOK,
737                                     CKW_CFG_REAS_RB_CREAT_FAIL); 
738             DU_LOG("\nERROR  -->  RLC_DL : Memory allocation failed RBID:%d CELLID:%d",
739                      entCfg->rbId,
740                      cellId);
741             return RFAILED; 
742          }
743
744          /* copy the RB Cb into UECb */
745          rlcRbCb->rlcId.rbId = entCfg->rbId;
746          if(entCfg->rbType == CM_LTE_SRB)
747             ueCb->srbCb[entCfg->rbId] = rlcRbCb;
748          else
749             ueCb->drbCb[entCfg->rbId] = rlcRbCb;
750          
751          RLC_LMM_RB_STS_INC(gCb);
752
753       }
754       else
755       {
756          if (entCfg->entMode == RLC_MODE_TM)
757          {
758             reason = CKW_CFG_REAS_RB_MODE_MIS;
759          }
760          else
761          {
762             reason = CKW_CFG_REAS_LCHTYPE_MIS;
763          }
764
765          /* Fill entCfm structure */
766          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK, reason);
767          return RFAILED;
768       }
769    }
770
771
772    rlcRbCb->rlcId.cellId = cellId;
773    rlcRbCb->rlcId.ueId   = ueId;
774    rlcRbCb->rlcId.rbType = entCfg->rbType;
775    rlcRbCb->inst         = gCb->init.inst;
776 #ifdef TENB_MULT_CELL_SUPPRT
777    rlcRbCb->rguSapId     = entCfg->rguSapId;
778 #endif
779
780
781    /* Fill RB CB */
782    if (rlcCfgFillDlRbCb(gCb,rlcRbCb, ueCb, entCfg) != ROK)
783    {
784       /* Fill entCfm structure */
785       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
786                CKW_CFG_REAS_RB_CREAT_FAIL);
787
788       /* Delete RB CB created */
789       RLC_FREE(gCb,rlcRbCb, sizeof(RlcDlRbCb));
790       DU_LOG("\nERROR  -->  RLC_DL : Filling of RbCb failed UEID:%d CELLID:%d",
791                ueId,
792                cellId);
793       return RFAILED;
794    }
795    rlcRbCb->qci = entCfg->qci;
796 #ifdef LTE_L2_MEAS
797    rlcRbCb->ueCb =  ueCb;
798    if (entCfg->lCh[0].type == CM_LTE_LCH_DTCH)
799    {
800       /* ccpu00129778 */
801       rlcAddToDlL2Meas(gCb, rlcRbCb,cellId,ueId); 
802    }
803 #endif /* LTE_L2_MEAS */
804
805    /* Fill entCfm structure */
806    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
807
808    return ROK;
809
810
811 \f
812 /** 
813  * @brief
814  *    This primitive reconfigures the existing RB in Ue/Cell Cb.
815  *
816  * @details
817  *    This primitive executes following steps in reconfiguration of existing
818  *    RB -
819  *    - If UE ID is 0 then
820  *       - Check for CELL CB is present
821  *       - If yes, Check for RB ID
822  *          - If RB ID is present Reconfigure the RB CB
823  *          - Else, Status Indication with Reason
824  *       - Else, Status Indication with Reason
825  *    - Else,
826  *       - Check for UE CB is present
827  *       - If yes, Check for RB ID
828  *          - If RB ID is prenset Reconfigure the CELL CB
829  *          - Else, Status Indication with Reason
830  *       - Else, Status Indication with Reason
831  *    - Fill entity confirmation
832  *
833  * @param [in]    gCb      -  RLC Instance Control Block
834  * @param [in]    ueId     -  UE Identifier
835  * @param [in]    cellId   -  CELL Identifier
836  * @param [in]    entCfg   -  Entity Configuration to be done.
837  * @param [out]   entCfm   -  Entity Confirmation
838  *
839  * @return  S16
840  *    -#ROK
841  *    -#RFAILED
842  */
843 S16 rlcCfgReCfgDlRb
844 (
845 RlcCb               *gCb,
846 CmLteRnti          ueId,
847 CmLteCellId        cellId,
848 RlcEntCfgInfo      *entCfg,
849 RlcEntCfgCfmInfo   *entCfm
850 )
851 {
852    RlcDlRbCb     *rbCb;     /* RB Control Block */
853    RlcDlRbCb     tRbCb;     /* KW RB Control Block */
854    RlcDlCellCb   *cellCb;   /* Cell Control Block */
855    RlcDlUeCb     *ueCb;     /* Ue Control Block */
856    uint8_t       ret;
857
858    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgReCfgRb(cellId(%d), cfgType(%d)) RBID:%d",
859             cellId, entCfg->cfgType,entCfg->rbId);
860
861
862    /* Check for UeCb or CellCb */
863    if (ueId == 0)
864    { 
865       if(entCfg->rbId >= RLC_MAX_RB_PER_CELL)
866       {
867          /* Fill entCfm structure */
868          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
869                              CKW_CFG_REAS_RB_UNKWN);
870          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId , Max is [%d] UEID:%d CELLID:%d",
871                   RLC_MAX_RB_PER_CELL,
872                   ueId,
873                   cellId);
874          return RFAILED;
875       }
876       /* Get cellCb */
877       rlcDbmFetchDlCellCb(gCb,cellId, &cellCb);
878       if(!cellCb)
879       {
880          /* Fill entCfm structure */
881          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
882                              CKW_CFG_REAS_CELL_UNKWN);
883          DU_LOG("\nERROR  -->  RLC_DL : CellCb not found ueId:%d RBID:%d CELLID:%d",
884                   ueId,
885                   entCfg->rbId,
886                   cellId);
887          return RFAILED;
888       }
889
890       /* Get rbCb */
891       RLC_DBM_GET_CELL_RBCB(entCfg->rbId, cellCb->rbCb, rbCb);
892
893       if (!rbCb)
894       {
895          /* Fill entCfm structure */
896          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
897                CKW_CFG_REAS_RB_UNKWN);
898          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d RBID:%d not found",
899                   cellId,
900                   entCfg->rbId);
901          return RFAILED;
902       }
903
904       /* Take backup of rbCb before updating.
905        * Because in failure case restore original rbCb
906        */
907       memcpy(&tRbCb, rbCb, sizeof(RlcDlRbCb));
908
909       /* Update rbCb */
910       ret = rlcCfgUpdateDlRb(gCb,rbCb, cellCb,entCfg);
911       if (ret != ROK)
912       {
913          /* Fill entCfm structure */
914          RLC_CFG_FILL_CFG_CFM(entCfm, 
915                              entCfg->rbId, 
916                              entCfg->rbType, 
917                              CKW_CFG_CFM_NOK,
918                              ret);
919
920          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%u RBID:%d updation failed",
921                   cellId,
922                   entCfg->rbId);
923          memcpy(rbCb, &tRbCb, sizeof(RlcDlRbCb));
924
925          return (ret);
926       }
927    }
928    else
929    {
930       if (!(RLC_VALIDATE_UE_RBID(entCfg->rbType, entCfg->rbId)))
931       {
932          /* Fill entCfm structure */
933          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
934                CKW_CFG_REAS_RB_UNKWN);
935          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d Invalid RBID:%d for RbType[%d]",
936                   cellId,
937                   entCfg->rbId,
938                   entCfg->rbType);
939          return RFAILED;
940       }
941       /* Get ueCb */
942       ret = rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb);
943       if (ret != ROK)
944       {
945          /* Fill entCfm structure */
946          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
947                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
948          DU_LOG("\nERROR  -->  RLC_DL : UEID:%d UeCb not found RBID:%d",
949                   ueId,
950                   entCfg->rbId);
951          return (ret);
952       }
953
954       /* Get rbCb */
955       RLC_DBM_GET_RBCB_FROM_UECB(entCfg->rbId, entCfg->rbType, ueCb, rbCb);
956
957       if ( rbCb == NULLP)
958       {
959          /* Fill entCfm structure */
960          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
961                CKW_CFG_REAS_RB_UNKWN);
962          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d RBID:%d not found",
963                   cellId,
964                   entCfg->rbId);
965          return (ret);
966       }
967
968       /* Take backup of rbCb before updating.
969        * Because in failure case restore original rbCb
970        */
971       memcpy(&tRbCb, rbCb, sizeof(RlcDlRbCb));
972
973       /* Update rbCb */
974       ret = rlcCfgUpdateDlRb(gCb,rbCb,ueCb, entCfg);
975       if (ret != CKW_CFG_REAS_NONE)
976       {
977          /* Fill entCfm structure */
978          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
979                ret);
980         DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d RBID:%d updation failed",
981                   cellId,
982                   entCfg->rbId);
983          memcpy(rbCb, &tRbCb, sizeof(RlcDlRbCb));
984
985          return (ret);
986       }
987    }
988
989    /* Fill entCfm structure */
990    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
991
992    return ROK;
993
994
995 \f
996 /** 
997  * @brief This primitive deletes the existing RB in Ue/Cell Cb.
998  *
999  * @details
1000  *    - If UE ID is 0 then
1001  *      - Check for CELL CB is present
1002  *       - If yes, Check for RB ID
1003  *      - If RB ID is prenset Delete the RB CB
1004  *       - If there is no RB CB exist in CELL CB then Delete CELL CB.
1005  *      - Else, Status Indication with Reason
1006  *      - Else, Status Indication with Reason
1007  *    - Else,
1008  *      - Check for UE CB is present
1009  *      - If yes, Check for RB ID
1010  *        - If RB ID is prenset Delete the RB CB
1011  *          - If there is no RB CB exist in UE CB then Delete UE CB.
1012  *        - Else, Status Indication with Reason
1013  *      - Else, Status Indication with Reason
1014  *    - Fill entity confirmation
1015  *
1016  * @param [in]    gCb      -  RLC Instance Control Block
1017  * @param [in]    ueId     -  UE Identifier
1018  * @param [in]    cellId   -  CELL Identifier
1019  * @param [in]    entCfg   -  Entity Configuration to be done.
1020  * @param [out]   entCfm   -  Entity Confirmation
1021  *
1022  * @return  S16
1023  *    -#ROK
1024  *    -#RFAILED
1025  */
1026 S16 rlcCfgDelDlRb
1027 (
1028 RlcCb               *gCb,
1029 CmLteRnti          ueId,
1030 CmLteCellId        cellId,
1031 RlcEntCfgInfo      *entCfg,
1032 RlcEntCfgCfmInfo   *entCfm
1033 )
1034 {
1035    S16          ret;       /* Return Value */
1036    RlcDlUeCb     *ueCb;     /* UE Control Block */
1037    RlcDlCellCb   *cellCb;   /* UE Control Block */
1038    RlcDlRbCb     *rlcRbCb;   /* KW RB Control Block */
1039
1040    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgDelRb(RBID(%d), cellId(%d), cfgType(%d))",
1041             entCfg->rbId, 
1042             cellId, 
1043             entCfg->cfgType);
1044
1045    ret = ROK;
1046
1047    /* Get cellCb and delete rbCb from it */
1048    if (ueId == 0)
1049    {
1050       if(entCfg->rbId >= RLC_MAX_RB_PER_CELL)
1051       {
1052          /* Fill entCfm structure */
1053          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1054                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1055          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId, Max is [%d] UEID:%d CELLID:%d",
1056                   RLC_MAX_RB_PER_CELL,
1057                   ueId,
1058                   cellId);
1059          return RFAILED;
1060       }
1061       /* Get cellCb */
1062       rlcDbmFetchDlCellCb(gCb,cellId, &cellCb);
1063       if (!cellCb)
1064       {
1065          /* Fill entCfm structure */
1066          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1067                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1068          DU_LOG("\nERROR  -->  RLC_DL : CellCb not found UEID:%d RBID:%d",
1069                   ueId,
1070                   entCfg->rbId);
1071          return (ret);
1072       }
1073
1074       /* Get rbCb */
1075       RLC_DBM_GET_CELL_RBCB(entCfg->rbId, cellCb->rbCb, rlcRbCb);
1076
1077       if ( rlcRbCb == NULLP)
1078       {
1079          /* Fill entCfm structure */
1080          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1081                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1082          DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:RbId[%d] not found",
1083                   cellId,
1084                   entCfg->rbId);
1085          return (ret);
1086       }
1087
1088       /* Assign NULLP to rbCb in rbCbLst */
1089       cellCb->rbCb[entCfg->rbId] = NULLP;
1090
1091       /* Assign NULLP to dlRbCb/ulRbCb.
1092        * Delete Hashlist allocated for it if any */
1093       cellCb->lCh[rlcRbCb->lch.lChId - 1].dlRbCb = NULLP;
1094       RLC_FREE(gCb,rlcRbCb, sizeof(RlcDlRbCb));   /*Vartika: Mem leak fix */  
1095    }
1096     /* Get ueCb and delete rbCb from it */
1097    else
1098    {
1099       if (!(RLC_VALIDATE_UE_RBID(entCfg->rbType, entCfg->rbId)))
1100       {
1101          /* Fill entCfm structure */
1102          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1103                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1104          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId for RbType[%d] UEID:%d CELLID:%d", 
1105                   entCfg->rbType,
1106                   ueId,
1107                   cellId);
1108          return RFAILED;
1109       }
1110
1111       /* Get ueCb */
1112       ret = rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb);
1113       if (ret != ROK)
1114       {
1115          /* Fill entCfm structure */
1116          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1117                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
1118           DU_LOG("\nERROR  -->  RLC_DL : UeId [%d]: UeCb not found RBID:%d",
1119                   ueId,
1120                   entCfg->rbId);
1121          return (ret);
1122       }
1123
1124       /* Get rbCb */
1125       RLC_DBM_GET_RBCB_FROM_UECB(entCfg->rbId, entCfg->rbType, ueCb, rlcRbCb);
1126
1127       if ( rlcRbCb == NULLP)
1128       {
1129          /* Fill entCfm structure */
1130          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1131                CKW_CFG_REAS_RB_UNKWN);
1132          DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:RbId[%d] not found",
1133                   cellId,
1134                   entCfg->rbId);
1135          return (ret);
1136       }
1137
1138       ueCb->lCh[rlcRbCb->lch.lChId - 1].dlRbCb = NULLP;
1139
1140 #ifdef LTE_L2_MEAS
1141       RLC_UPD_L2_DECR_NONIP_PER_QCI_RB_COUNT(gCb, rlcRbCb);
1142 #endif
1143       /* Free the Buffers of RbCb */
1144       if( RLC_MODE_UM == rlcRbCb->mode)
1145       {
1146          rlcUmmFreeDlRbCb(gCb,rlcRbCb);
1147          /* Delete RbCb  */
1148          RLC_FREE(gCb,rlcRbCb, sizeof(RlcDlRbCb));     
1149       }
1150       else if( RLC_MODE_AM == rlcRbCb->mode)
1151       {
1152          rlcAmmFreeDlRbCb(gCb,rlcRbCb);
1153       }
1154
1155       /* Assign NULLP to rbCb in rbCbLst */
1156       if ( entCfg->rbType == CM_LTE_SRB )
1157       {
1158          ueCb->srbCb[entCfg->rbId] = NULLP;
1159       }
1160       else
1161       {
1162          ueCb->drbCb[entCfg->rbId] = NULLP;
1163       }
1164    }
1165
1166    RLC_LMM_RB_STS_DEC(gCb);
1167
1168    /* Fill entCfm structure */
1169    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_OK, 
1170                        CKW_CFG_REAS_NONE);
1171
1172    return (ret);
1173
1174
1175 \f
1176 /** 
1177  * @brief This primitive re-establish the existing RB in Ue/Cell Cb.
1178  *
1179  * @details
1180  *    - If UE ID is 0 then
1181  *      - Check for CELL 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  *    - Else,
1187  *      - Check for UE CB is present
1188  *      - If yes, Check for RB ID
1189  *        - If RB ID is prenset initialize the parameters of the RB CB
1190  *        - Else, Status Indication with Reason
1191  *      - Else, Status Indication with Reason
1192  *    - Fill entity confirmation
1193  *
1194  * @param [in]    gCb      -  RLC Instance Control Block
1195  * @param [in]    ueId     -  UE Identifier
1196  * @param [in]    cellId   -  CELL Identifier
1197  * @param [in]    entCfg   -  Entity Configuration to be done.
1198  * @param [out]   entCfm   -  Entity Confirmation
1199  *
1200  * @return  S16
1201  *    -# ROK
1202  *    -# RFAILED
1203  */
1204 S16 rlcCfgReEstDlRb
1205 (
1206 RlcCb              *gCb,
1207 CmLteRnti          ueId,
1208 CmLteCellId        cellId,
1209 Bool               sndReEstInd,
1210 RlcEntCfgInfo      *entCfg,
1211 RlcEntCfgCfmInfo   *entCfm
1212 )
1213 {
1214    RlcDlRbCb     *rbCb;   /* RB Control Block */
1215    CmLteRlcId   rlcId;   /* RLC Identifier */
1216
1217    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgReEstDlRb(ueId(%d), cellId(%d), cfgType(%d))",
1218             ueId, 
1219             cellId, 
1220             entCfg->cfgType);
1221
1222    /* Get rlcId */
1223    rlcId.ueId = ueId;
1224    rlcId.cellId = cellId;
1225    rlcId.rbId = entCfg->rbId;
1226    rlcId.rbType = entCfg->rbType;
1227
1228    rlcDbmFetchDlRbCbByRbId(gCb,&rlcId, &rbCb);
1229    if (rbCb == NULLP)
1230    {
1231       /* Fill entCfm structure */
1232       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, rlcId.rbType, CKW_CFG_CFM_NOK,
1233             CKW_CFG_REAS_RB_UNKWN);
1234       DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:RbId[%d] not found",
1235                cellId,
1236                entCfg->rbId);
1237       return RFAILED;
1238    }
1239
1240    rbCb->rlcId.ueId = ueId;
1241
1242    switch (rbCb->mode)
1243    {
1244       case RLC_MODE_TM:
1245          {
1246             rlcDlTmmReEstablish(gCb,rbCb);
1247             break;
1248          }
1249
1250       case RLC_MODE_UM:
1251          {
1252             rlcDlUmmReEstablish(gCb,rlcId,sndReEstInd,rbCb);
1253             break;
1254          }
1255
1256       case RLC_MODE_AM:
1257          {           
1258             rlcAmmDlReEstablish(gCb, rlcId, rbCb);
1259             break;
1260          }
1261    }
1262
1263    /* Fill entCfm structure */
1264    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1265       CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
1266
1267    return ROK;
1268
1269
1270 \f
1271 /** 
1272  * @brief This primitive deletes the RBs in Ue Cb.
1273  *
1274  * @details
1275  *    - If UE ID is 0 then
1276  *      - Status Indication with Reason
1277  *    - Else,
1278  *      - Check for UE CB is present
1279  *      - If yes, Delete all RB CB in UE CB and Delete UE CB also.
1280  *      - Else, Status Indication with Reason
1281  *    - Fill entity confirmation
1282  *
1283  * @param [in]    gCb      -  RLC Instance Control Block
1284  * @param [in]    ueId     -  UE Identifier
1285  * @param [in]    cellId   -  CELL Identifier
1286  * @param [in]    entCfg   -  Entity Configuration to be done.
1287  * @param [out]   entCfm   -  Entity Confirmation
1288  *
1289  * @return  S16
1290  *    -#ROK
1291  *    -#RFAILED
1292  */
1293 S16 rlcCfgDelDlUe
1294 (
1295 RlcCb              *gCb,
1296 CmLteRnti          ueId,
1297 CmLteCellId        cellId,
1298 RlcEntCfgInfo      *entCfg,
1299 RlcEntCfgCfmInfo   *entCfm
1300 )
1301 {
1302    S16        ret;     /* Return Value */
1303    RlcDlUeCb   *ueCb;   /* UE Control Block */
1304
1305    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgDelUe(ueId(%d), cellId(%d), cfgType(%d))",
1306             ueId, 
1307             cellId, 
1308             entCfg->cfgType);
1309
1310    ret = ROK;
1311
1312    /* Check for ueId is present or not */
1313    if ( ueId == 0 )
1314    {
1315       /* Fill entCfm structure */
1316       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1317           CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
1318       DU_LOG("\nERROR  -->  RLC_DL : ueId(%d), cellId(%d)",
1319                ueId, 
1320                cellId);
1321       return RFAILED;
1322    }
1323
1324    /* Fetch Ue Cb */
1325    ret = rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb);
1326    if (ret != ROK)
1327    {
1328       /* Fill entCfm structure */
1329       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1330          CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
1331       DU_LOG("\nERROR  -->  RLC_DL : UEID:%d UeCb not found RBID:%d",
1332                ueId,
1333                entCfg->rbId);
1334       return RFAILED;
1335    }
1336
1337 #ifdef LTE_L2_MEAS
1338    rlcDelFrmDlL2Meas(gCb,cellId,ueId);
1339    rlcDbmDelAllDlL2MeasTbFrmUe(gCb,ueCb);
1340 #endif
1341    /* Delete Ue Cb */
1342    rlcDbmDelDlUeCb(gCb,ueCb, FALSE);
1343
1344    /* Fill entCfm structure */
1345    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1346       CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
1347
1348    return ROK;
1349
1350
1351
1352 /**
1353  * @brief This primitive deletes the RBs in Ue Cb.
1354  *
1355  * @details
1356  *    - If CELL ID is 0 then
1357  *      - Status Indication with Reason
1358  *    - Else,
1359  *      - Check for CELL CB is present
1360  *      - If yes, Delete all RB CB in CELL CB and Delete CELL CB also.
1361  *      - Else, Status Indication with Reason
1362  *    - Fill entity confirmation
1363  *
1364  * @param [in]    cellId   -  CELL Identifier
1365  * @param [in]    entCfg   -  Entity Configuration to be done.
1366  * @param [out]   entCfm   -  Entity Confirmation
1367  *
1368  * @return S16
1369  *    -#ROK
1370  *    -#RFAILED
1371  */
1372 S16 rlcCfgDelDlCell
1373 (
1374 RlcCb               *gCb,
1375 CmLteCellId        cellId,
1376 RlcEntCfgInfo      *entCfg,
1377 RlcEntCfgCfmInfo   *entCfm
1378 )
1379 {
1380    RlcDlCellCb   *cellCb;   /* UE Control Block */
1381    uint8_t       rbId;      /* RB Identifier */
1382
1383    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgDelCell( cellId(%d), cfgType(%d)",
1384          cellId, 
1385          entCfg->cfgType);
1386
1387    cellCb = NULLP;
1388    rbId = entCfg->rbId;
1389
1390    /* Check for ueId is present or not */
1391    if ( cellId == 0 )
1392    {
1393       /* Fill entCfm structure */
1394       RLC_CFG_FILL_CFG_CFM(entCfm, rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1395             CKW_CFG_REAS_CELL_UNKWN);
1396       DU_LOG("\nERROR  -->  RLC_DL : cellId is 0 (%d) ",
1397                cellId);
1398       return RFAILED;
1399    }
1400
1401    /* Fetch Ue Cb */
1402    rlcDbmFetchDlCellCb(gCb,cellId, &cellCb);
1403    if (!cellCb)
1404    {
1405       /* Fill entCfm structure */
1406       RLC_CFG_FILL_CFG_CFM(entCfm, rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1407             CKW_CFG_REAS_CELL_UNKWN);
1408       DU_LOG("\nERROR  -->  RLC_DL : CellCb not found for RBID:%d",
1409                entCfg->rbId);
1410       return RFAILED;
1411    }
1412
1413    /* Delete Ue Cb */
1414    rlcDbmDelDlCellCb(gCb,cellCb);
1415
1416    /* Fill entCfm structure */
1417   /* kw005.201 added support for L2 Measurement */         
1418    RLC_CFG_FILL_CFG_CFM(entCfm, rbId, entCfg->rbType, CKW_CFG_CFM_OK,
1419                        CKW_CFG_REAS_NONE);
1420
1421    return ROK;
1422
1423
1424 /**
1425  * @brief This primitive changes the ueId of Ue Cb.
1426  *
1427  * @details
1428  *    - If oldUeId and newUeId are
1429  *      - Confirm the Status with Reason
1430  *    - If UeId not present
1431  *      - Confirm the Status with Reason
1432  *    - Create New UeCb
1433  *    - Copy rbCbs from old UeCb to new UeCb
1434  *    - Delete old UeCb
1435  *    - Fill entity confirmation
1436  *
1437  * @param [in]    ueInfo      -  Old UE Information
1438  * @param [in]    newUeInfo   -  New UE Information
1439  * @param [out]   status      -  Status
1440  *
1441  * @return  S16
1442  *    -# ROK
1443  *    -# RFAILED
1444  */
1445 S16 rlcCfgDlUeIdChng
1446 (
1447 RlcCb        *gCb,
1448 CkwUeInfo   *ueInfo,
1449 CkwUeInfo   *newUeInfo,
1450 CmStatus    *status
1451 )
1452 {
1453    RlcDlUeCb *ueCb;
1454 /*kw004.201 Adding of Missing Trace in RLC PDCP*/
1455
1456    if ( (ueInfo->ueId == newUeInfo->ueId) && 
1457         (ueInfo->cellId == newUeInfo->cellId))
1458    {
1459       status->reason = CKW_CFG_REAS_SAME_UEID;
1460       status->status = CKW_CFG_CFM_NOK; 
1461       DU_LOG("\nERROR  -->  RLC_DL : Old UeId[%d] same as new UeId[%d]",
1462             ueInfo->ueId,
1463             newUeInfo->ueId);
1464       return RFAILED;
1465    } 
1466    
1467    if(ROK == rlcDbmFetchDlUeCb(gCb,newUeInfo->ueId, newUeInfo->cellId, &ueCb))
1468    {
1469       DU_LOG("\nERROR  -->  RLC_DL : NewUeId[%d]:ueCb already exists",
1470             newUeInfo->ueId);
1471       status->reason = CKW_CFG_REAS_UE_EXISTS;
1472       status->status = CKW_CFG_CFM_NOK;
1473       return RFAILED;
1474    }
1475   
1476    if(ROK != rlcDbmFetchDlUeCb(gCb,ueInfo->ueId, ueInfo->cellId, &ueCb))
1477    {
1478
1479       DU_LOG("\nERROR  -->  RLC_DL : UeId [%d]: UeCb not found",
1480             ueInfo->ueId);
1481       status->reason = CKW_CFG_REAS_UE_UNKWN;
1482       status->status = CKW_CFG_CFM_NOK;
1483       return RFAILED;
1484    }
1485   
1486 #ifdef LTE_L2_MEAS
1487    rlcHdlMeasDlUeIdChg(gCb, ueInfo->cellId, ueInfo->ueId, newUeInfo->ueId);
1488 #endif   
1489    if(ROK != cmHashListDelete(&(gCb->u.dlCb->ueLstCp), (PTR) ueCb))
1490    {
1491       DU_LOG("\nERROR  -->  RLC_DL : UeId[%u] HashList Deletion Failed",
1492             ueInfo->ueId);
1493       status->reason = CKW_CFG_REAS_UE_CREAT_FAIL;
1494       status->status = CKW_CFG_CFM_NOK;
1495       return RFAILED;
1496    }
1497    
1498    /* update the hash key with new values */ 
1499    ueCb->ueId = newUeInfo->ueId;
1500    ueCb->cellId = newUeInfo->cellId;
1501
1502    if(ROK != cmHashListInsert(&(gCb->u.dlCb->ueLstCp), 
1503                               (PTR)ueCb, (uint8_t *)&(ueCb->ueId),
1504                               (uint16_t) sizeof(CmLteRnti)))
1505
1506    {
1507       DU_LOG("\nERROR  -->  RLC_DL : UeId[%u] HashList Insertion Failed",
1508             newUeInfo->ueId);
1509       status->reason = CKW_CFG_REAS_UE_CREAT_FAIL;
1510       status->status = CKW_CFG_CFM_NOK;
1511       return RFAILED;
1512    }  
1513   
1514    return ROK;
1515
1516
1517 /********************************************************************30**
1518
1519          End of file
1520 **********************************************************************/