<JIRA ID: ODUHIGH-389: DL Thproughput Per SNSSAI>
[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    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgFillRbCb(ueId(%d),cellId(%d) rbType(%d))",
319          rbCb->rlcId.ueId,
320          rbCb->rlcId.cellId, 
321          entCfg->rbType);
322
323    /* Initialize according to entMode */
324    switch (entCfg->entMode)
325    {
326       case RLC_MODE_TM:
327          {
328             rbCb->lch.lChId  = entCfg->lCh[0].lChId;
329             rbCb->lch.lChType = entCfg->lCh[0].type;
330             rbCb->dir = entCfg->dir;
331             break;
332          }
333
334       case RLC_MODE_UM:
335          {
336             rbCb->lch.lChId  = entCfg->lCh[0].lChId;
337             rbCb->lch.lChType = entCfg->lCh[0].type;
338             rbCb->dir = entCfg->dir;
339
340             /* Spec 38.322 Section 7.1 
341              * All UM state variables can take values from 0 to 63 for 6 bit SN or 
342              * from 0 to 4095 for 12 bit SN. All arithmetic operations on UM state 
343              * variables are affected by the UM modulus 
344              * (i.e. final value = [value from arithmetic operation] modulo 64
345              * for 6 bit SN and 4096 for 12 bit SN)
346              */
347             rbCb->m.umDl.snLen = entCfg->m.umInfo.dl.snLen;
348             if (entCfg->m.umInfo.dl.snLen == RLC_UM_CFG_6BIT_SN_LEN)
349                rbCb->m.umDl.modBitMask = 0x3f;
350             else
351                rbCb->m.umDl.modBitMask = 0xfff;
352
353             ueCb->lCh[rbCb->lch.lChId - 1].dlRbCb = rbCb;
354
355             break;
356          }
357       case RLC_MODE_AM:
358          {
359             /* Down Link Information 
360              * indx = 0 as Down Link   */
361             rbCb->lch.lChId  = entCfg->lCh[0].lChId;
362             rbCb->lch.lChType = entCfg->lCh[0].type;
363             rbCb->dir = RLC_DIR_BOTH;
364
365             rbCb->m.amDl.pollPdu = entCfg->m.amInfo.dl.pollPdu;
366             rbCb->m.amDl.pollByte = entCfg->m.amInfo.dl.pollByte;
367             rbCb->m.amDl.maxRetx = entCfg->m.amInfo.dl.maxRetx;
368             rbCb->m.amDl.pollRetxTmrInt = entCfg->m.amInfo.dl.pollRetxTmr;
369             rbCb->m.amDl.snLen = entCfg->m.amInfo.dl.snLen;
370
371             if(RLC_AM_CFG_12BIT_SN_LEN == rbCb->m.amDl.snLen)
372             {
373                rbCb->m.amDl.snModMask = (1 << RLC_SN_LEN_12BITS) - 1; /* 5GNR */
374             }
375             else 
376             {
377                rbCb->m.amDl.snModMask = (1 << RLC_SN_LEN_18BITS) - 1; /* 5GNR */
378             }
379
380             cmInitTimers(&(rbCb->m.amDl.pollRetxTmr), 1);
381             ueCb->lCh[rbCb->lch.lChId - 1].dlRbCb = rbCb;
382
383 #ifndef LTE_TDD 
384             uint32_t hashIndex;
385             RLC_ALLOC(gCb,
386                   rbCb->m.amDl.txBufLst,
387                   (RLC_TX_BUF_BIN_SIZE * sizeof(CmLListCp)));
388             for(hashIndex = 0; hashIndex < RLC_TX_BUF_BIN_SIZE; hashIndex++)
389             {
390                cmLListInit(&(rbCb->m.amDl.txBufLst[hashIndex]));
391             }
392 #endif
393             break;
394          }
395       default:
396          {
397             DU_LOG("\nERROR  -->  RLC_DL : Invalid RB Mode ueId(%d),cellId(%d)",
398                   rbCb->rlcId.ueId,
399                   rbCb->rlcId.cellId);
400             return RFAILED;
401          }
402    }
403
404    if(entCfg->snssai)
405    {
406       RLC_ALLOC(gCb, rbCb->snssai, sizeof(Snssai));
407       if(rbCb->snssai == NULLP)
408       {
409          DU_LOG("\nERROR  --> RLC_DL : rlcCfgFillDlRbCb(): Failed to allocate memory");
410          return RFAILED;
411       }
412       memcpy(rbCb->snssai, entCfg->snssai, sizeof(Snssai));
413
414       /*Create the entry of this SNSSAI if not exist in Snssai Tput list*/
415       if(rlcHandleSnssaiTputlist(gCb, rbCb->snssai, CREATE) == NULLP)
416       {
417          DU_LOG("\nERROR  --> RLC_DL : rlcCfgFillDlRbCb(): SNSSAI insertion in Tput list failed");
418       }
419    }
420    rbCb->mode = entCfg->entMode;
421    rbCb->discTmrInt = entCfg->discardTmr;
422
423    return ROK;
424
425
426 \f
427 /** 
428  * @brief This primitive Initializes the RB Cb
429  *
430  * @param [in]    gCb      -  RLC Instance Control Block
431  * @param [out]   rbCb     -  RB Control Block
432  * @param [in]    ptr      -  Void pointer
433  * @param [in]    entCfg   -  Entity Configuration
434  *
435  * @return  S16
436  *    -#ROK
437  *    -#RFAILED
438  */
439 static S16 rlcCfgUpdateDlRb
440 (
441 RlcCb           *gCb,
442 RlcDlRbCb       *rbCb,
443 void            *ptr,
444 RlcEntCfgInfo   *entCfg
445 )
446 {
447    
448    if (rbCb->mode != entCfg->entMode)
449    {
450       DU_LOG("\nERROR  -->  RLC_DL : RB Mode Mismatch : exp [%d] rcv [%d] UEID:%d CELLID:%d", 
451             rbCb->mode, 
452             entCfg->entMode,
453             rbCb->rlcId.ueId,
454             rbCb->rlcId.cellId);
455       return (CKW_CFG_REAS_RB_MODE_MIS);
456    }
457
458    switch (rbCb->mode)
459    {
460       case RLC_MODE_TM:
461       {
462          RlcDlCellCb *cellCb = (RlcDlCellCb *)ptr;
463
464          rbCb->dir = entCfg->dir;
465          rbCb->lch.lChId = entCfg->lCh[0].lChId;
466          rbCb->lch.lChType = entCfg->lCh[0].type;
467          cellCb->lCh[rbCb->lch.lChId - 1].dlRbCb = rbCb;
468          break;
469       }
470
471       case RLC_MODE_UM:
472       {
473          RlcDlUeCb *ueCb = (RlcDlUeCb *)ptr;
474
475          if (entCfg->lCh[0].type == CM_LTE_LCH_DCCH)
476          {
477             return (CKW_CFG_REAS_LCHTYPE_MIS);
478          }
479          
480          ueCb->lCh[rbCb->lch.lChId - 1].dlRbCb = NULLP;
481          ueCb->lCh[entCfg->lCh[0].lChId - 1].dlRbCb = rbCb;
482
483          rbCb->lch.lChId = entCfg->lCh[0].lChId;
484          rbCb->lch.lChType = entCfg->lCh[0].type;
485          rbCb->dir = entCfg->dir;
486          break;
487       }
488
489       case RLC_MODE_AM:
490       {
491          RlcDlUeCb *ueCb = (RlcDlUeCb *)ptr;
492
493          ueCb->lCh[rbCb->lch.lChId - 1].dlRbCb = NULLP;
494          ueCb->lCh[entCfg->lCh[1].lChId - 1].dlRbCb = rbCb;
495          
496          /* Down Link */
497          rbCb->lch.lChId = entCfg->lCh[1].lChId;
498          rbCb->lch.lChType = entCfg->lCh[1].type;
499          rbCb->m.amDl.pollRetxTmrInt = entCfg->m.amInfo.dl.pollRetxTmr;
500          rbCb->m.amDl.pollPdu = entCfg->m.amInfo.dl.pollPdu;
501          rbCb->m.amDl.pollByte = entCfg->m.amInfo.dl.pollByte;
502          rbCb->m.amDl.maxRetx = entCfg->m.amInfo.dl.maxRetx;
503          
504          break;
505       }
506    }
507
508    if(entCfg->snssai)
509    {
510       if(!rbCb->snssai)
511       {
512          RLC_ALLOC(gCb, rbCb->snssai, sizeof(Snssai));
513          if(rbCb->snssai == NULLP)
514          {
515             DU_LOG("\nERROR  --> RLC_DL : rlcCfgFillDlRbCb(): Failed to allocate memory");
516             return RFAILED;
517          }
518       }
519       memcpy(rbCb->snssai,entCfg->snssai,sizeof(Snssai));
520    }
521 /* AGHOSH */
522    rbCb->discTmrInt = entCfg->discardTmr;
523 /* AGHOSH */
524    return (CKW_CFG_REAS_NONE);
525
526
527 \f
528 /** 
529  * @brief 
530  *    This primitive adds new RB in Ue/Cell Cb.
531  *
532  * @details
533  *    This function does following steps -
534  *    - If UE ID is 0 then
535  *    - Check for CELL CB is present
536  *    - If yes, Check for RB ID
537  *       - If RB ID is present Status Indication with reason
538  *       - Else, Create New RB CB in CELL CB
539  *    - If no Create New CELL CB and RB CB
540  *    - Else,
541  *       - Check for UE CB is present
542  *       - If yes Check for RB ID
543  *          - If RB ID is present Status Indication with reason
544  *          - Else, Create New RB CB in UE CB
545  *          - If no Create New UE CB and RB CB
546  *    - Fill entity confirmation
547  *
548  * @param [in]    gCb      -  RLC Instance Control Block
549  * @param [in]    ueId     -  UE Identifier
550  * @param [in]    cellId   -  CELL Identifier
551  * @param [in]    entCfg   -  Entity Configuration to be done.
552  * @param [out]   entCfm   -  Entity Confirmation.
553  *
554  * @return  S16
555  *    -# ROK
556  *    -# RFAILED
557  */
558 S16 rlcCfgAddDlRb
559 (
560 RlcCb               *gCb,
561 CmLteRnti          ueId,
562 CmLteCellId        cellId,
563 RlcEntCfgInfo      *entCfg,
564 RlcEntCfgCfmInfo   *entCfm
565 )
566 {
567    RlcDlUeCb     *ueCb = NULLP;   /* UE Control Block */
568    RlcDlCellCb   *cellCb;         /* Cell Control Block */
569    RlcDlRbCb     *rlcRbCb;         /* KW RB Control Block */
570    uint8_t       reason;          /* Rb Identifier */
571
572    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgAddRb(cellId(%d),UEID:%d cfgType(%d))",
573          cellId, 
574          ueId,
575          entCfg->cfgType);
576
577    if (cellId == 0)
578    {
579       /* Fill entCfm structure */
580       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
581             CKW_CFG_REAS_CELL_UNKWN);
582       DU_LOG("\nERROR  -->  RLC_DL : Add DLRb,CellId is 0 for UEID:%d",
583             ueId);
584       return RFAILED;
585    }
586    if ((entCfg->rguSapId >= gCb->genCfg.maxRguSaps) || (entCfg->rguSapId < 0))
587    {
588       RLCDBGP_ERROR(gCb, "rlcCfgAddDlRb(ueId(%u), cellId(%u), Invalid rguSapId (%d)\n",
589             ueId, cellId, entCfg->rguSapId);
590       return RFAILED; 
591    }
592
593
594    /* Process Adding new RB */
595    if (ueId == 0)
596    {
597       if(entCfg->rbId >= RLC_MAX_RB_PER_CELL)
598       {
599          /* Fill entCfm structure */
600          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
601                CKW_CFG_CFM_NOK,
602                CKW_CFG_REAS_RB_UNKWN);
603          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId ,Max is [%d] CELLID:%d UEID:%d",
604                RLC_MAX_RB_PER_CELL,
605                cellId,
606                ueId);
607          return RFAILED;
608       }
609
610       if (((entCfg->lCh[0].type == CM_LTE_LCH_BCCH) || 
611                (entCfg->lCh[0].type == CM_LTE_LCH_PCCH) ||
612                (entCfg->lCh[0].type == CM_LTE_LCH_CCCH)) &&
613             (entCfg->entMode == RLC_MODE_TM))
614       {
615          /* Cell CB present */
616          rlcDbmFetchDlCellCb(gCb, cellId, &cellCb);
617          if(cellCb)
618          {
619             /* Get rbCb from cellCb->rbCb List */
620             if (( cellCb->rbCb[entCfg->rbId] != NULLP))
621             {
622                /* Fill entCfm structure */
623                RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
624                      CKW_CFG_CFM_NOK,
625                      CKW_CFG_REAS_RB_PRSNT);
626                DU_LOG("\nERROR  -->  RLC_DL : RbId [%d] already exists UEID:%d",
627                      entCfg->rbId,
628                      ueId);
629                return RFAILED;
630             }
631          }
632          else  /* Cell CB UNKNOWN */
633          {
634             /* Create CELL CB */
635             if ( ROK != rlcDbmCreateDlCellCb(gCb,cellId, &cellCb))
636             {
637                /* Fill entCfm structure */
638                RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
639                      CKW_CFG_CFM_NOK,
640                      CKW_CFG_REAS_CELL_CREAT_FAIL);
641                DU_LOG("\nERROR  -->  RLC_DL : cellCb Creation failed RBID:%d UEID:%d",
642                      entCfg->rbId,
643                      ueId);
644                return RFAILED;
645             }
646          }
647
648          /* Validate LChId */
649          if(entCfg->lCh[0].lChId <= 0)
650          {
651             DU_LOG("\nERROR  -->  RLC_DL : Invalid LcId CELLID:%d UEID:%d RBID:%d",
652                   cellId,
653                   ueId,
654                   entCfg->rbId);
655             /* Fill entCfm structure */                               
656             RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
657                   CKW_CFG_CFM_NOK, CKW_CFG_REAS_INVALID_LCHID);           
658             return RFAILED;                                        
659          }                                                            
660
661          /* Create RB CB */
662          RLC_ALLOC(gCb,rlcRbCb, sizeof (RlcDlRbCb));
663          if (!rlcRbCb)
664          {
665             DU_LOG("\nERROR  -->  RLC_DL : Memory allocation failed for rbId:%d CELLID:%d",
666                   entCfg->rbId,
667                   ueId);
668             /* Fill entCfm structure */                           
669             RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
670                   CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_CREAT_FAIL); 
671             return RFAILED; 
672          }
673          rlcRbCb->rlcId.rbId = entCfg->rbId;
674          cellCb->rbCb[entCfg->rbId] = rlcRbCb;
675          RLC_LMM_RB_STS_INC(gCb);
676          cellCb->lCh[entCfg->lCh[0].lChId - 1].dlRbCb = rlcRbCb;
677       }
678       else
679       {
680          reason= (entCfg->entMode != RLC_MODE_TM)? CKW_CFG_REAS_RB_MODE_MIS:
681             CKW_CFG_REAS_LCHTYPE_MIS;
682          /* Fill entCfm structure */
683          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
684                CKW_CFG_CFM_NOK, reason);
685          return RFAILED;
686       }
687    }
688    else
689    {
690       if (!(RLC_VALIDATE_UE_RBID(entCfg->rbType, entCfg->rbId)))
691       {
692          /* Fill entCfm structure */
693          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
694                CKW_CFG_REAS_RB_UNKWN);
695          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId for RbType[%d] UEID:%d", 
696                entCfg->rbType,
697                ueId);
698          return RFAILED;
699       }
700       if ((((entCfg->lCh[0].type == CM_LTE_LCH_DCCH) && 
701                   (entCfg->entMode != RLC_MODE_UM) && 
702                   (CM_LTE_SRB == entCfg->rbType)) ||
703                ((entCfg->lCh[0].type == CM_LTE_LCH_DTCH) && 
704                 (CM_LTE_DRB == entCfg->rbType))) &&
705             (entCfg->entMode != RLC_MODE_TM))
706       {
707          /* UE CB present */
708          if ( rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb) == ROK)
709          {
710             /* Get rbCb from ueCb->rbCb list */
711             RLC_DBM_GET_RBCB_FROM_UECB(entCfg->rbId, entCfg->rbType, ueCb, rlcRbCb);
712
713             if(( rlcRbCb != NULLP))
714             {
715                /* Fill entCfm structure */
716                RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
717                      CKW_CFG_REAS_RB_PRSNT);
718                DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:rbId [%d] already exists",
719                      cellId,
720                      entCfg->rbId);
721                return RFAILED;
722             }
723          }
724          else  /* UE CB UNKNOWN */
725          {
726             /* Create UE CB */
727             if ( rlcDbmCreateDlUeCb(gCb,ueId, cellId, &ueCb) != ROK)
728             {
729                /* Fill entCfm structure */
730                RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
731                      CKW_CFG_REAS_UE_CREAT_FAIL);
732                DU_LOG("\nERROR  -->  RLC_DL : UeId [%u]:ueCb Creation Failed RBID:%d",
733                      ueId,
734                      entCfg->rbId);
735                return RFAILED;
736             }
737             /* Start throughput calculation for this UE */
738             gCb->rlcThpt.ueTputInfo.thptPerUe[ueId -1].ueId  = ueId;
739             gCb->rlcThpt.ueTputInfo.thptPerUe[ueId -1].dataVol = 0;
740             gCb->rlcThpt.ueTputInfo.numActvUe++;
741          }
742
743          /* Validate LChId for UM and AM modes */
744          if ((entCfg->lCh[0].lChId <= 0) ||
745                ((entCfg->entMode == RLC_MODE_AM)&&
746                 (entCfg->lCh[1].lChId <= 0)))
747          {
748             /* Fill entCfm structure */                               
749             RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
750                   CKW_CFG_CFM_NOK, CKW_CFG_REAS_INVALID_LCHID);           
751             return RFAILED;                                        
752          }                                                            
753
754          /* Create RB CB */
755          RLC_ALLOC(gCb,rlcRbCb, sizeof (RlcDlRbCb));
756          if (rlcRbCb == NULL)
757          {
758             /* Fill entCfm structure */                           
759             RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,CKW_CFG_CFM_NOK,
760                   CKW_CFG_REAS_RB_CREAT_FAIL); 
761             DU_LOG("\nERROR  -->  RLC_DL : Memory allocation failed RBID:%d CELLID:%d",
762                   entCfg->rbId,
763                   cellId);
764             return RFAILED; 
765          }
766
767          /* copy the RB Cb into UECb */
768          rlcRbCb->rlcId.rbId = entCfg->rbId;
769          if(entCfg->rbType == CM_LTE_SRB)
770             ueCb->srbCb[entCfg->rbId] = rlcRbCb;
771          else
772             ueCb->drbCb[entCfg->rbId] = rlcRbCb;
773
774          RLC_LMM_RB_STS_INC(gCb);
775
776       }
777       else
778       {
779          if (entCfg->entMode == RLC_MODE_TM)
780          {
781             reason = CKW_CFG_REAS_RB_MODE_MIS;
782          }
783          else
784          {
785             reason = CKW_CFG_REAS_LCHTYPE_MIS;
786          }
787
788          /* Fill entCfm structure */
789          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK, reason);
790          return RFAILED;
791       }
792    }
793
794
795    rlcRbCb->rlcId.cellId = cellId;
796    rlcRbCb->rlcId.ueId   = ueId;
797    rlcRbCb->rlcId.rbType = entCfg->rbType;
798    rlcRbCb->inst         = gCb->init.inst;
799 #ifdef TENB_MULT_CELL_SUPPRT
800    rlcRbCb->rguSapId     = entCfg->rguSapId;
801 #endif
802
803
804    /* Fill RB CB */
805    if (rlcCfgFillDlRbCb(gCb,rlcRbCb, ueCb, entCfg) != ROK)
806    {
807       /* Fill entCfm structure */
808       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
809             CKW_CFG_REAS_RB_CREAT_FAIL);
810
811       /* Delete RB CB created */
812       RLC_FREE(gCb,rlcRbCb, sizeof(RlcDlRbCb));
813       DU_LOG("\nERROR  -->  RLC_DL : Filling of RbCb failed UEID:%d CELLID:%d",
814             ueId,
815             cellId);
816       return RFAILED;
817    }
818    rlcRbCb->qci = entCfg->qci;
819 #ifdef LTE_L2_MEAS
820    rlcRbCb->ueCb =  ueCb;
821    if (entCfg->lCh[0].type == CM_LTE_LCH_DTCH)
822    {
823       /* ccpu00129778 */
824       rlcAddToDlL2Meas(gCb, rlcRbCb,cellId,ueId); 
825    }
826 #endif /* LTE_L2_MEAS */
827
828    /* Fill entCfm structure */
829    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
830
831    return ROK;
832
833
834 \f
835 /** 
836  * @brief
837  *    This primitive reconfigures the existing RB in Ue/Cell Cb.
838  *
839  * @details
840  *    This primitive executes following steps in reconfiguration of existing
841  *    RB -
842  *    - If UE ID is 0 then
843  *       - Check for CELL CB is present
844  *       - If yes, Check for RB ID
845  *          - If RB ID is present Reconfigure the RB CB
846  *          - Else, Status Indication with Reason
847  *       - Else, Status Indication with Reason
848  *    - Else,
849  *       - Check for UE CB is present
850  *       - If yes, Check for RB ID
851  *          - If RB ID is prenset Reconfigure the CELL CB
852  *          - Else, Status Indication with Reason
853  *       - Else, Status Indication with Reason
854  *    - Fill entity confirmation
855  *
856  * @param [in]    gCb      -  RLC Instance Control Block
857  * @param [in]    ueId     -  UE Identifier
858  * @param [in]    cellId   -  CELL Identifier
859  * @param [in]    entCfg   -  Entity Configuration to be done.
860  * @param [out]   entCfm   -  Entity Confirmation
861  *
862  * @return  S16
863  *    -#ROK
864  *    -#RFAILED
865  */
866 S16 rlcCfgReCfgDlRb
867 (
868 RlcCb               *gCb,
869 CmLteRnti          ueId,
870 CmLteCellId        cellId,
871 RlcEntCfgInfo      *entCfg,
872 RlcEntCfgCfmInfo   *entCfm
873 )
874 {
875    RlcDlRbCb     *rbCb;     /* RB Control Block */
876    RlcDlRbCb     tRbCb;     /* KW RB Control Block */
877    RlcDlCellCb   *cellCb;   /* Cell Control Block */
878    RlcDlUeCb     *ueCb;     /* Ue Control Block */
879    uint8_t       ret;
880
881    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgReCfgRb(cellId(%d), cfgType(%d)) RBID:%d",
882             cellId, entCfg->cfgType,entCfg->rbId);
883
884
885    /* Check for UeCb or CellCb */
886    if (ueId == 0)
887    { 
888       if(entCfg->rbId >= RLC_MAX_RB_PER_CELL)
889       {
890          /* Fill entCfm structure */
891          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
892                              CKW_CFG_REAS_RB_UNKWN);
893          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId , Max is [%d] UEID:%d CELLID:%d",
894                   RLC_MAX_RB_PER_CELL,
895                   ueId,
896                   cellId);
897          return RFAILED;
898       }
899       /* Get cellCb */
900       rlcDbmFetchDlCellCb(gCb,cellId, &cellCb);
901       if(!cellCb)
902       {
903          /* Fill entCfm structure */
904          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
905                              CKW_CFG_REAS_CELL_UNKWN);
906          DU_LOG("\nERROR  -->  RLC_DL : CellCb not found ueId:%d RBID:%d CELLID:%d",
907                   ueId,
908                   entCfg->rbId,
909                   cellId);
910          return RFAILED;
911       }
912
913       /* Get rbCb */
914       RLC_DBM_GET_CELL_RBCB(entCfg->rbId, cellCb->rbCb, rbCb);
915
916       if (!rbCb)
917       {
918          /* Fill entCfm structure */
919          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
920                CKW_CFG_REAS_RB_UNKWN);
921          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d RBID:%d not found",
922                   cellId,
923                   entCfg->rbId);
924          return RFAILED;
925       }
926
927       /* Take backup of rbCb before updating.
928        * Because in failure case restore original rbCb
929        */
930       memcpy(&tRbCb, rbCb, sizeof(RlcDlRbCb));
931
932       /* Update rbCb */
933       ret = rlcCfgUpdateDlRb(gCb,rbCb, cellCb,entCfg);
934       if (ret != ROK)
935       {
936          /* Fill entCfm structure */
937          RLC_CFG_FILL_CFG_CFM(entCfm, 
938                              entCfg->rbId, 
939                              entCfg->rbType, 
940                              CKW_CFG_CFM_NOK,
941                              ret);
942
943          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%u RBID:%d updation failed",
944                   cellId,
945                   entCfg->rbId);
946          memcpy(rbCb, &tRbCb, sizeof(RlcDlRbCb));
947
948          return (ret);
949       }
950    }
951    else
952    {
953       if (!(RLC_VALIDATE_UE_RBID(entCfg->rbType, entCfg->rbId)))
954       {
955          /* Fill entCfm structure */
956          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
957                CKW_CFG_REAS_RB_UNKWN);
958          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d Invalid RBID:%d for RbType[%d]",
959                   cellId,
960                   entCfg->rbId,
961                   entCfg->rbType);
962          return RFAILED;
963       }
964       /* Get ueCb */
965       ret = rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb);
966       if (ret != ROK)
967       {
968          /* Fill entCfm structure */
969          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
970                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
971          DU_LOG("\nERROR  -->  RLC_DL : UEID:%d UeCb not found RBID:%d",
972                   ueId,
973                   entCfg->rbId);
974          return (ret);
975       }
976
977       /* Get rbCb */
978       RLC_DBM_GET_RBCB_FROM_UECB(entCfg->rbId, entCfg->rbType, ueCb, rbCb);
979
980       if ( rbCb == NULLP)
981       {
982          /* Fill entCfm structure */
983          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
984                CKW_CFG_REAS_RB_UNKWN);
985          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d RBID:%d not found",
986                   cellId,
987                   entCfg->rbId);
988          return (ret);
989       }
990
991       /* Take backup of rbCb before updating.
992        * Because in failure case restore original rbCb
993        */
994       memcpy(&tRbCb, rbCb, sizeof(RlcDlRbCb));
995
996       /* Update rbCb */
997       ret = rlcCfgUpdateDlRb(gCb,rbCb,ueCb, entCfg);
998       if (ret != CKW_CFG_REAS_NONE)
999       {
1000          /* Fill entCfm structure */
1001          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1002                ret);
1003         DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d RBID:%d updation failed",
1004                   cellId,
1005                   entCfg->rbId);
1006          memcpy(rbCb, &tRbCb, sizeof(RlcDlRbCb));
1007
1008          return (ret);
1009       }
1010    }
1011
1012    /* Fill entCfm structure */
1013    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
1014
1015    return ROK;
1016
1017
1018 \f
1019 /** 
1020  * @brief This primitive deletes the existing RB in Ue/Cell Cb.
1021  *
1022  * @details
1023  *    - If UE ID is 0 then
1024  *      - Check for CELL CB is present
1025  *       - If yes, Check for RB ID
1026  *      - If RB ID is prenset Delete the RB CB
1027  *       - If there is no RB CB exist in CELL CB then Delete CELL CB.
1028  *      - Else, Status Indication with Reason
1029  *      - Else, Status Indication with Reason
1030  *    - Else,
1031  *      - Check for UE CB is present
1032  *      - If yes, Check for RB ID
1033  *        - If RB ID is prenset Delete the RB CB
1034  *          - If there is no RB CB exist in UE CB then Delete UE CB.
1035  *        - Else, Status Indication with Reason
1036  *      - Else, Status Indication with Reason
1037  *    - Fill entity confirmation
1038  *
1039  * @param [in]    gCb      -  RLC Instance Control Block
1040  * @param [in]    ueId     -  UE Identifier
1041  * @param [in]    cellId   -  CELL Identifier
1042  * @param [in]    entCfg   -  Entity Configuration to be done.
1043  * @param [out]   entCfm   -  Entity Confirmation
1044  *
1045  * @return  S16
1046  *    -#ROK
1047  *    -#RFAILED
1048  */
1049 S16 rlcCfgDelDlRb
1050 (
1051 RlcCb               *gCb,
1052 CmLteRnti          ueId,
1053 CmLteCellId        cellId,
1054 RlcEntCfgInfo      *entCfg,
1055 RlcEntCfgCfmInfo   *entCfm
1056 )
1057 {
1058    S16          ret;       /* Return Value */
1059    RlcDlUeCb     *ueCb;     /* UE Control Block */
1060    RlcDlCellCb   *cellCb;   /* UE Control Block */
1061    RlcDlRbCb     *rlcRbCb;   /* KW RB Control Block */
1062
1063    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgDelRb(RBID(%d), cellId(%d), cfgType(%d))",
1064             entCfg->rbId, 
1065             cellId, 
1066             entCfg->cfgType);
1067
1068    ret = ROK;
1069
1070    /* Get cellCb and delete rbCb from it */
1071    if (ueId == 0)
1072    {
1073       if(entCfg->rbId >= RLC_MAX_RB_PER_CELL)
1074       {
1075          /* Fill entCfm structure */
1076          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1077                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1078          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId, Max is [%d] UEID:%d CELLID:%d",
1079                   RLC_MAX_RB_PER_CELL,
1080                   ueId,
1081                   cellId);
1082          return RFAILED;
1083       }
1084       /* Get cellCb */
1085       rlcDbmFetchDlCellCb(gCb,cellId, &cellCb);
1086       if (!cellCb)
1087       {
1088          /* Fill entCfm structure */
1089          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1090                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1091          DU_LOG("\nERROR  -->  RLC_DL : CellCb not found UEID:%d RBID:%d",
1092                   ueId,
1093                   entCfg->rbId);
1094          return (ret);
1095       }
1096
1097       /* Get rbCb */
1098       RLC_DBM_GET_CELL_RBCB(entCfg->rbId, cellCb->rbCb, rlcRbCb);
1099
1100       if ( rlcRbCb == NULLP)
1101       {
1102          /* Fill entCfm structure */
1103          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1104                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1105          DU_LOG("\nERROR  -->  RLC_DL : 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->snssai, sizeof(Snssai)); 
1118       RLC_FREE(gCb,rlcRbCb, sizeof(RlcDlRbCb));   /*Vartika: Mem leak fix */  
1119    }
1120     /* Get ueCb and delete rbCb from it */
1121    else
1122    {
1123       if (!(RLC_VALIDATE_UE_RBID(entCfg->rbType, entCfg->rbId)))
1124       {
1125          /* Fill entCfm structure */
1126          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1127                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1128          DU_LOG("\nERROR  -->  RLC_DL : 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           DU_LOG("\nERROR  -->  RLC_DL : UeId [%d]: UeCb not found RBID:%d",
1143                   ueId,
1144                   entCfg->rbId);
1145          return (ret);
1146       }
1147
1148       /* Get rbCb */
1149       RLC_DBM_GET_RBCB_FROM_UECB(entCfg->rbId, entCfg->rbType, ueCb, rlcRbCb);
1150
1151       if ( rlcRbCb == NULLP)
1152       {
1153          /* Fill entCfm structure */
1154          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1155                CKW_CFG_REAS_RB_UNKWN);
1156          DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:RbId[%d] not found",
1157                   cellId,
1158                   entCfg->rbId);
1159          return (ret);
1160       }
1161       ueCb->lCh[rlcRbCb->lch.lChId - 1].dlRbCb = NULLP;
1162
1163 #ifdef LTE_L2_MEAS
1164       RLC_UPD_L2_DECR_NONIP_PER_QCI_RB_COUNT(gCb, rlcRbCb);
1165 #endif
1166       /* Free the Buffers of RbCb */
1167       if( RLC_MODE_UM == rlcRbCb->mode)
1168       {
1169          rlcUmmFreeDlRbCb(gCb,rlcRbCb);
1170          /* Delete RbCb  */
1171          RLC_FREE(gCb,rlcRbCb, sizeof(RlcDlRbCb));     
1172       }
1173       else if( RLC_MODE_AM == rlcRbCb->mode)
1174       {
1175          rlcAmmFreeDlRbCb(gCb,rlcRbCb);
1176       }
1177
1178       /* Assign NULLP to rbCb in rbCbLst */
1179       if ( entCfg->rbType == CM_LTE_SRB )
1180       {
1181          ueCb->srbCb[entCfg->rbId] = NULLP;
1182       }
1183       else
1184       {
1185          ueCb->drbCb[entCfg->rbId] = NULLP;
1186       }
1187    }
1188
1189    RLC_LMM_RB_STS_DEC(gCb);
1190
1191    /* Fill entCfm structure */
1192    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_OK, 
1193                        CKW_CFG_REAS_NONE);
1194
1195    return (ret);
1196
1197
1198 \f
1199 /** 
1200  * @brief This primitive re-establish the existing RB in Ue/Cell Cb.
1201  *
1202  * @details
1203  *    - If UE ID is 0 then
1204  *      - Check for CELL CB is present
1205  *      - If yes, Check for RB ID
1206  *        - If RB ID is prenset initialize the parameters of the RB CB
1207  *        - Else, Status Indication with Reason
1208  *      - Else, Status Indication with Reason
1209  *    - Else,
1210  *      - Check for UE CB is present
1211  *      - If yes, Check for RB ID
1212  *        - If RB ID is prenset initialize the parameters of the RB CB
1213  *        - Else, Status Indication with Reason
1214  *      - Else, Status Indication with Reason
1215  *    - Fill entity confirmation
1216  *
1217  * @param [in]    gCb      -  RLC Instance Control Block
1218  * @param [in]    ueId     -  UE Identifier
1219  * @param [in]    cellId   -  CELL Identifier
1220  * @param [in]    entCfg   -  Entity Configuration to be done.
1221  * @param [out]   entCfm   -  Entity Confirmation
1222  *
1223  * @return  S16
1224  *    -# ROK
1225  *    -# RFAILED
1226  */
1227 S16 rlcCfgReEstDlRb
1228 (
1229 RlcCb              *gCb,
1230 CmLteRnti          ueId,
1231 CmLteCellId        cellId,
1232 Bool               sndReEstInd,
1233 RlcEntCfgInfo      *entCfg,
1234 RlcEntCfgCfmInfo   *entCfm
1235 )
1236 {
1237    RlcDlRbCb     *rbCb;   /* RB Control Block */
1238    CmLteRlcId   rlcId;   /* RLC Identifier */
1239
1240    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgReEstDlRb(ueId(%d), cellId(%d), cfgType(%d))",
1241             ueId, 
1242             cellId, 
1243             entCfg->cfgType);
1244
1245    /* Get rlcId */
1246    rlcId.ueId = ueId;
1247    rlcId.cellId = cellId;
1248    rlcId.rbId = entCfg->rbId;
1249    rlcId.rbType = entCfg->rbType;
1250
1251    rlcDbmFetchDlRbCbByRbId(gCb,&rlcId, &rbCb);
1252    if (rbCb == NULLP)
1253    {
1254       /* Fill entCfm structure */
1255       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, rlcId.rbType, CKW_CFG_CFM_NOK,
1256             CKW_CFG_REAS_RB_UNKWN);
1257       DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:RbId[%d] not found",
1258                cellId,
1259                entCfg->rbId);
1260       return RFAILED;
1261    }
1262
1263    rbCb->rlcId.ueId = ueId;
1264
1265    switch (rbCb->mode)
1266    {
1267       case RLC_MODE_TM:
1268          {
1269             rlcDlTmmReEstablish(gCb,rbCb);
1270             break;
1271          }
1272
1273       case RLC_MODE_UM:
1274          {
1275             rlcDlUmmReEstablish(gCb,rlcId,sndReEstInd,rbCb);
1276             break;
1277          }
1278
1279       case RLC_MODE_AM:
1280          {           
1281             rlcAmmDlReEstablish(gCb, rlcId, rbCb);
1282             break;
1283          }
1284    }
1285
1286    /* Fill entCfm structure */
1287    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1288       CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
1289
1290    return ROK;
1291
1292
1293 \f
1294 /** 
1295  * @brief This primitive deletes the RBs in Ue Cb.
1296  *
1297  * @details
1298  *    - If UE ID is 0 then
1299  *      - Status Indication with Reason
1300  *    - Else,
1301  *      - Check for UE CB is present
1302  *      - If yes, Delete all RB CB in UE CB and Delete UE CB also.
1303  *      - Else, Status Indication with Reason
1304  *    - Fill entity confirmation
1305  *
1306  * @param [in]    gCb      -  RLC Instance Control Block
1307  * @param [in]    ueId     -  UE Identifier
1308  * @param [in]    cellId   -  CELL Identifier
1309  * @param [in]    entCfg   -  Entity Configuration to be done.
1310  * @param [out]   entCfm   -  Entity Confirmation
1311  *
1312  * @return  S16
1313  *    -#ROK
1314  *    -#RFAILED
1315  */
1316 S16 rlcCfgDelDlUe
1317 (
1318 RlcCb              *gCb,
1319 CmLteRnti          ueId,
1320 CmLteCellId        cellId,
1321 RlcEntCfgInfo      *entCfg,
1322 RlcEntCfgCfmInfo   *entCfm
1323 )
1324 {
1325    S16        ret;     /* Return Value */
1326    RlcDlUeCb   *ueCb;   /* UE Control Block */
1327
1328    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgDelUe(ueId(%d), cellId(%d), cfgType(%d))",
1329             ueId, 
1330             cellId, 
1331             entCfg->cfgType);
1332
1333    ret = ROK;
1334
1335    /* Check for ueId is present or not */
1336    if ( ueId == 0 )
1337    {
1338       /* Fill entCfm structure */
1339       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1340           CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
1341       DU_LOG("\nERROR  -->  RLC_DL : ueId(%d), cellId(%d)",
1342                ueId, 
1343                cellId);
1344       return RFAILED;
1345    }
1346
1347    /* Fetch Ue Cb */
1348    ret = rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb);
1349    if (ret != ROK)
1350    {
1351       /* Fill entCfm structure */
1352       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1353          CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
1354       DU_LOG("\nERROR  -->  RLC_DL : UEID:%d UeCb not found RBID:%d",
1355                ueId,
1356                entCfg->rbId);
1357       return RFAILED;
1358    }
1359
1360 #ifdef LTE_L2_MEAS
1361    rlcDelFrmDlL2Meas(gCb,cellId,ueId);
1362    rlcDbmDelAllDlL2MeasTbFrmUe(gCb,ueCb);
1363 #endif
1364    /* Delete Ue Cb */
1365    rlcDbmDelDlUeCb(gCb,ueCb, FALSE);
1366
1367    /* Fill entCfm structure */
1368    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1369       CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
1370
1371    return ROK;
1372
1373
1374
1375 /**
1376  * @brief This primitive deletes the RBs in Ue Cb.
1377  *
1378  * @details
1379  *    - If CELL ID is 0 then
1380  *      - Status Indication with Reason
1381  *    - Else,
1382  *      - Check for CELL CB is present
1383  *      - If yes, Delete all RB CB in CELL CB and Delete CELL CB also.
1384  *      - Else, Status Indication with Reason
1385  *    - Fill entity confirmation
1386  *
1387  * @param [in]    cellId   -  CELL Identifier
1388  * @param [in]    entCfg   -  Entity Configuration to be done.
1389  * @param [out]   entCfm   -  Entity Confirmation
1390  *
1391  * @return S16
1392  *    -#ROK
1393  *    -#RFAILED
1394  */
1395 S16 rlcCfgDelDlCell
1396 (
1397 RlcCb               *gCb,
1398 CmLteCellId        cellId,
1399 RlcEntCfgInfo      *entCfg,
1400 RlcEntCfgCfmInfo   *entCfm
1401 )
1402 {
1403    RlcDlCellCb   *cellCb;   /* UE Control Block */
1404    uint8_t       rbId;      /* RB Identifier */
1405
1406    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgDelCell( cellId(%d), cfgType(%d)",
1407          cellId, 
1408          entCfg->cfgType);
1409
1410    cellCb = NULLP;
1411    rbId = entCfg->rbId;
1412
1413    /* Check for ueId is present or not */
1414    if ( cellId == 0 )
1415    {
1416       /* Fill entCfm structure */
1417       RLC_CFG_FILL_CFG_CFM(entCfm, rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1418             CKW_CFG_REAS_CELL_UNKWN);
1419       DU_LOG("\nERROR  -->  RLC_DL : cellId is 0 (%d) ",
1420                cellId);
1421       return RFAILED;
1422    }
1423
1424    /* Fetch Ue Cb */
1425    rlcDbmFetchDlCellCb(gCb,cellId, &cellCb);
1426    if (!cellCb)
1427    {
1428       /* Fill entCfm structure */
1429       RLC_CFG_FILL_CFG_CFM(entCfm, rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1430             CKW_CFG_REAS_CELL_UNKWN);
1431       DU_LOG("\nERROR  -->  RLC_DL : CellCb not found for RBID:%d",
1432                entCfg->rbId);
1433       return RFAILED;
1434    }
1435
1436    /* Delete Ue Cb */
1437    rlcDbmDelDlCellCb(gCb,cellCb);
1438
1439    /* Fill entCfm structure */
1440   /* kw005.201 added support for L2 Measurement */         
1441    RLC_CFG_FILL_CFG_CFM(entCfm, rbId, entCfg->rbType, CKW_CFG_CFM_OK,
1442                        CKW_CFG_REAS_NONE);
1443
1444    return ROK;
1445
1446
1447 /**
1448  * @brief This primitive changes the ueId of Ue Cb.
1449  *
1450  * @details
1451  *    - If oldUeId and newUeId are
1452  *      - Confirm the Status with Reason
1453  *    - If UeId not present
1454  *      - Confirm the Status with Reason
1455  *    - Create New UeCb
1456  *    - Copy rbCbs from old UeCb to new UeCb
1457  *    - Delete old UeCb
1458  *    - Fill entity confirmation
1459  *
1460  * @param [in]    ueInfo      -  Old UE Information
1461  * @param [in]    newUeInfo   -  New UE Information
1462  * @param [out]   status      -  Status
1463  *
1464  * @return  S16
1465  *    -# ROK
1466  *    -# RFAILED
1467  */
1468 S16 rlcCfgDlUeIdChng
1469 (
1470 RlcCb        *gCb,
1471 CkwUeInfo   *ueInfo,
1472 CkwUeInfo   *newUeInfo,
1473 CmStatus    *status
1474 )
1475 {
1476    RlcDlUeCb *ueCb;
1477 /*kw004.201 Adding of Missing Trace in RLC PDCP*/
1478
1479    if ( (ueInfo->ueId == newUeInfo->ueId) && 
1480         (ueInfo->cellId == newUeInfo->cellId))
1481    {
1482       status->reason = CKW_CFG_REAS_SAME_UEID;
1483       status->status = CKW_CFG_CFM_NOK; 
1484       DU_LOG("\nERROR  -->  RLC_DL : Old UeId[%d] same as new UeId[%d]",
1485             ueInfo->ueId,
1486             newUeInfo->ueId);
1487       return RFAILED;
1488    } 
1489    
1490    if(ROK == rlcDbmFetchDlUeCb(gCb,newUeInfo->ueId, newUeInfo->cellId, &ueCb))
1491    {
1492       DU_LOG("\nERROR  -->  RLC_DL : NewUeId[%d]:ueCb already exists",
1493             newUeInfo->ueId);
1494       status->reason = CKW_CFG_REAS_UE_EXISTS;
1495       status->status = CKW_CFG_CFM_NOK;
1496       return RFAILED;
1497    }
1498   
1499    if(ROK != rlcDbmFetchDlUeCb(gCb,ueInfo->ueId, ueInfo->cellId, &ueCb))
1500    {
1501
1502       DU_LOG("\nERROR  -->  RLC_DL : UeId [%d]: UeCb not found",
1503             ueInfo->ueId);
1504       status->reason = CKW_CFG_REAS_UE_UNKWN;
1505       status->status = CKW_CFG_CFM_NOK;
1506       return RFAILED;
1507    }
1508   
1509 #ifdef LTE_L2_MEAS
1510    rlcHdlMeasDlUeIdChg(gCb, ueInfo->cellId, ueInfo->ueId, newUeInfo->ueId);
1511 #endif   
1512    if(ROK != cmHashListDelete(&(gCb->u.dlCb->ueLstCp), (PTR) ueCb))
1513    {
1514       DU_LOG("\nERROR  -->  RLC_DL : UeId[%u] HashList Deletion Failed",
1515             ueInfo->ueId);
1516       status->reason = CKW_CFG_REAS_UE_CREAT_FAIL;
1517       status->status = CKW_CFG_CFM_NOK;
1518       return RFAILED;
1519    }
1520    
1521    /* update the hash key with new values */ 
1522    ueCb->ueId = newUeInfo->ueId;
1523    ueCb->cellId = newUeInfo->cellId;
1524
1525    if(ROK != cmHashListInsert(&(gCb->u.dlCb->ueLstCp), 
1526                               (PTR)ueCb, (uint8_t *)&(ueCb->ueId),
1527                               (uint16_t) sizeof(CmLteRnti)))
1528
1529    {
1530       DU_LOG("\nERROR  -->  RLC_DL : UeId[%u] HashList Insertion Failed",
1531             newUeInfo->ueId);
1532       status->reason = CKW_CFG_REAS_UE_CREAT_FAIL;
1533       status->status = CKW_CFG_CFM_NOK;
1534       return RFAILED;
1535    }  
1536   
1537    return ROK;
1538
1539
1540 /********************************************************************30**
1541
1542          End of file
1543 **********************************************************************/