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