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