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