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