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