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