Deleted the rlog folder
[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          }
711
712          /* Validate LChId for UM and AM modes */
713          if ((entCfg->lCh[0].lChId <= 0) ||
714              ((entCfg->entMode == RLC_MODE_AM)&&
715                (entCfg->lCh[1].lChId <= 0)))
716          {
717             /* Fill entCfm structure */                               
718             RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
719                   CKW_CFG_CFM_NOK, CKW_CFG_REAS_INVALID_LCHID);           
720             return RFAILED;                                        
721          }                                                            
722
723          /* Create RB CB */
724          RLC_ALLOC(gCb,rlcRbCb, sizeof (RlcDlRbCb));
725          if (rlcRbCb == NULL)
726          {
727             /* Fill entCfm structure */                           
728             RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,CKW_CFG_CFM_NOK,
729                                     CKW_CFG_REAS_RB_CREAT_FAIL); 
730             DU_LOG("\nERROR  -->  RLC_DL : Memory allocation failed RBID:%d CELLID:%d",
731                      entCfg->rbId,
732                      cellId);
733             return RFAILED; 
734          }
735
736          /* copy the RB Cb into UECb */
737          rlcRbCb->rlcId.rbId = entCfg->rbId;
738          if(entCfg->rbType == CM_LTE_SRB)
739             ueCb->srbCb[entCfg->rbId] = rlcRbCb;
740          else
741             ueCb->drbCb[entCfg->rbId] = rlcRbCb;
742          
743          RLC_LMM_RB_STS_INC(gCb);
744
745       }
746       else
747       {
748          if (entCfg->entMode == RLC_MODE_TM)
749          {
750             reason = CKW_CFG_REAS_RB_MODE_MIS;
751          }
752          else
753          {
754             reason = CKW_CFG_REAS_LCHTYPE_MIS;
755          }
756
757          /* Fill entCfm structure */
758          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK, reason);
759          return RFAILED;
760       }
761    }
762
763
764    rlcRbCb->rlcId.cellId = cellId;
765    rlcRbCb->rlcId.ueId   = ueId;
766    rlcRbCb->rlcId.rbType = entCfg->rbType;
767    rlcRbCb->inst         = gCb->init.inst;
768 #ifdef TENB_MULT_CELL_SUPPRT
769    rlcRbCb->rguSapId     = entCfg->rguSapId;
770 #endif
771
772
773    /* Fill RB CB */
774    if (rlcCfgFillDlRbCb(gCb,rlcRbCb, ueCb, entCfg) != ROK)
775    {
776       /* Fill entCfm structure */
777       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
778                CKW_CFG_REAS_RB_CREAT_FAIL);
779
780       /* Delete RB CB created */
781       RLC_FREE(gCb,rlcRbCb, sizeof(RlcDlRbCb));
782       DU_LOG("\nERROR  -->  RLC_DL : Filling of RbCb failed UEID:%d CELLID:%d",
783                ueId,
784                cellId);
785       return RFAILED;
786    }
787    rlcRbCb->qci = entCfg->qci;
788 #ifdef LTE_L2_MEAS
789    rlcRbCb->ueCb =  ueCb;
790    if (entCfg->lCh[0].type == CM_LTE_LCH_DTCH)
791    {
792       /* ccpu00129778 */
793       rlcAddToDlL2Meas(gCb, rlcRbCb,cellId,ueId); 
794    }
795 #endif /* LTE_L2_MEAS */
796
797    /* Fill entCfm structure */
798    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
799
800    return ROK;
801
802
803 \f
804 /** 
805  * @brief
806  *    This primitive reconfigures the existing RB in Ue/Cell Cb.
807  *
808  * @details
809  *    This primitive executes following steps in reconfiguration of existing
810  *    RB -
811  *    - If UE ID is 0 then
812  *       - Check for CELL CB is present
813  *       - If yes, Check for RB ID
814  *          - If RB ID is present Reconfigure the RB CB
815  *          - Else, Status Indication with Reason
816  *       - Else, Status Indication with Reason
817  *    - Else,
818  *       - Check for UE CB is present
819  *       - If yes, Check for RB ID
820  *          - If RB ID is prenset Reconfigure the CELL CB
821  *          - Else, Status Indication with Reason
822  *       - Else, Status Indication with Reason
823  *    - Fill entity confirmation
824  *
825  * @param [in]    gCb      -  RLC Instance Control Block
826  * @param [in]    ueId     -  UE Identifier
827  * @param [in]    cellId   -  CELL Identifier
828  * @param [in]    entCfg   -  Entity Configuration to be done.
829  * @param [out]   entCfm   -  Entity Confirmation
830  *
831  * @return  S16
832  *    -#ROK
833  *    -#RFAILED
834  */
835 S16 rlcCfgReCfgDlRb
836 (
837 RlcCb               *gCb,
838 CmLteRnti          ueId,
839 CmLteCellId        cellId,
840 RlcEntCfgInfo      *entCfg,
841 RlcEntCfgCfmInfo   *entCfm
842 )
843 {
844    RlcDlRbCb     *rbCb;     /* RB Control Block */
845    RlcDlRbCb     tRbCb;     /* KW RB Control Block */
846    RlcDlCellCb   *cellCb;   /* Cell Control Block */
847    RlcDlUeCb     *ueCb;     /* Ue Control Block */
848    uint8_t       ret;
849
850    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgReCfgRb(cellId(%d), cfgType(%d)) RBID:%d",
851             cellId, entCfg->cfgType,entCfg->rbId);
852
853
854    /* Check for UeCb or CellCb */
855    if (ueId == 0)
856    { 
857       if(entCfg->rbId >= RLC_MAX_RB_PER_CELL)
858       {
859          /* Fill entCfm structure */
860          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
861                              CKW_CFG_REAS_RB_UNKWN);
862          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId , Max is [%d] UEID:%d CELLID:%d",
863                   RLC_MAX_RB_PER_CELL,
864                   ueId,
865                   cellId);
866          return RFAILED;
867       }
868       /* Get cellCb */
869       rlcDbmFetchDlCellCb(gCb,cellId, &cellCb);
870       if(!cellCb)
871       {
872          /* Fill entCfm structure */
873          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
874                              CKW_CFG_REAS_CELL_UNKWN);
875          DU_LOG("\nERROR  -->  RLC_DL : CellCb not found ueId:%d RBID:%d CELLID:%d",
876                   ueId,
877                   entCfg->rbId,
878                   cellId);
879          return RFAILED;
880       }
881
882       /* Get rbCb */
883       RLC_DBM_GET_CELL_RBCB(entCfg->rbId, cellCb->rbCb, rbCb);
884
885       if (!rbCb)
886       {
887          /* Fill entCfm structure */
888          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
889                CKW_CFG_REAS_RB_UNKWN);
890          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d RBID:%d not found",
891                   cellId,
892                   entCfg->rbId);
893          return RFAILED;
894       }
895
896       /* Take backup of rbCb before updating.
897        * Because in failure case restore original rbCb
898        */
899       memcpy(&tRbCb, rbCb, sizeof(RlcDlRbCb));
900
901       /* Update rbCb */
902       ret = rlcCfgUpdateDlRb(gCb,rbCb, cellCb,entCfg);
903       if (ret != ROK)
904       {
905          /* Fill entCfm structure */
906          RLC_CFG_FILL_CFG_CFM(entCfm, 
907                              entCfg->rbId, 
908                              entCfg->rbType, 
909                              CKW_CFG_CFM_NOK,
910                              ret);
911
912          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%u RBID:%d updation failed",
913                   cellId,
914                   entCfg->rbId);
915          memcpy(rbCb, &tRbCb, sizeof(RlcDlRbCb));
916
917          return (ret);
918       }
919    }
920    else
921    {
922       if (!(RLC_VALIDATE_UE_RBID(entCfg->rbType, entCfg->rbId)))
923       {
924          /* Fill entCfm structure */
925          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
926                CKW_CFG_REAS_RB_UNKWN);
927          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d Invalid RBID:%d for RbType[%d]",
928                   cellId,
929                   entCfg->rbId,
930                   entCfg->rbType);
931          return RFAILED;
932       }
933       /* Get ueCb */
934       ret = rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb);
935       if (ret != ROK)
936       {
937          /* Fill entCfm structure */
938          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
939                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
940          DU_LOG("\nERROR  -->  RLC_DL : UEID:%d UeCb not found RBID:%d",
941                   ueId,
942                   entCfg->rbId);
943          return (ret);
944       }
945
946       /* Get rbCb */
947       RLC_DBM_GET_RBCB_FROM_UECB(entCfg->rbId, entCfg->rbType, ueCb, rbCb);
948
949       if ( rbCb == NULLP)
950       {
951          /* Fill entCfm structure */
952          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
953                CKW_CFG_REAS_RB_UNKWN);
954          DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d RBID:%d not found",
955                   cellId,
956                   entCfg->rbId);
957          return (ret);
958       }
959
960       /* Take backup of rbCb before updating.
961        * Because in failure case restore original rbCb
962        */
963       memcpy(&tRbCb, rbCb, sizeof(RlcDlRbCb));
964
965       /* Update rbCb */
966       ret = rlcCfgUpdateDlRb(gCb,rbCb,ueCb, entCfg);
967       if (ret != CKW_CFG_REAS_NONE)
968       {
969          /* Fill entCfm structure */
970          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
971                ret);
972         DU_LOG("\nERROR  -->  RLC_DL : CELLID:%d RBID:%d updation failed",
973                   cellId,
974                   entCfg->rbId);
975          memcpy(rbCb, &tRbCb, sizeof(RlcDlRbCb));
976
977          return (ret);
978       }
979    }
980
981    /* Fill entCfm structure */
982    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
983
984    return ROK;
985
986
987 \f
988 /** 
989  * @brief This primitive deletes the existing RB in Ue/Cell Cb.
990  *
991  * @details
992  *    - If UE ID is 0 then
993  *      - Check for CELL CB is present
994  *       - If yes, Check for RB ID
995  *      - If RB ID is prenset Delete the RB CB
996  *       - If there is no RB CB exist in CELL CB then Delete CELL CB.
997  *      - Else, Status Indication with Reason
998  *      - Else, Status Indication with Reason
999  *    - Else,
1000  *      - Check for UE CB is present
1001  *      - If yes, Check for RB ID
1002  *        - If RB ID is prenset Delete the RB CB
1003  *          - If there is no RB CB exist in UE CB then Delete UE CB.
1004  *        - Else, Status Indication with Reason
1005  *      - Else, Status Indication with Reason
1006  *    - Fill entity confirmation
1007  *
1008  * @param [in]    gCb      -  RLC Instance Control Block
1009  * @param [in]    ueId     -  UE Identifier
1010  * @param [in]    cellId   -  CELL Identifier
1011  * @param [in]    entCfg   -  Entity Configuration to be done.
1012  * @param [out]   entCfm   -  Entity Confirmation
1013  *
1014  * @return  S16
1015  *    -#ROK
1016  *    -#RFAILED
1017  */
1018 S16 rlcCfgDelDlRb
1019 (
1020 RlcCb               *gCb,
1021 CmLteRnti          ueId,
1022 CmLteCellId        cellId,
1023 RlcEntCfgInfo      *entCfg,
1024 RlcEntCfgCfmInfo   *entCfm
1025 )
1026 {
1027    S16          ret;       /* Return Value */
1028    RlcDlUeCb     *ueCb;     /* UE Control Block */
1029    RlcDlCellCb   *cellCb;   /* UE Control Block */
1030    RlcDlRbCb     *rlcRbCb;   /* KW RB Control Block */
1031
1032    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgDelRb(RBID(%d), cellId(%d), cfgType(%d))",
1033             entCfg->rbId, 
1034             cellId, 
1035             entCfg->cfgType);
1036
1037    ret = ROK;
1038
1039    /* Get cellCb and delete rbCb from it */
1040    if (ueId == 0)
1041    {
1042       if(entCfg->rbId >= RLC_MAX_RB_PER_CELL)
1043       {
1044          /* Fill entCfm structure */
1045          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1046                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1047          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId, Max is [%d] UEID:%d CELLID:%d",
1048                   RLC_MAX_RB_PER_CELL,
1049                   ueId,
1050                   cellId);
1051          return RFAILED;
1052       }
1053       /* Get cellCb */
1054       rlcDbmFetchDlCellCb(gCb,cellId, &cellCb);
1055       if (!cellCb)
1056       {
1057          /* Fill entCfm structure */
1058          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1059                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1060          DU_LOG("\nERROR  -->  RLC_DL : CellCb not found UEID:%d RBID:%d",
1061                   ueId,
1062                   entCfg->rbId);
1063          return (ret);
1064       }
1065
1066       /* Get rbCb */
1067       RLC_DBM_GET_CELL_RBCB(entCfg->rbId, cellCb->rbCb, rlcRbCb);
1068
1069       if ( rlcRbCb == NULLP)
1070       {
1071          /* Fill entCfm structure */
1072          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1073                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1074          DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:RbId[%d] not found",
1075                   cellId,
1076                   entCfg->rbId);
1077          return (ret);
1078       }
1079
1080       /* Assign NULLP to rbCb in rbCbLst */
1081       cellCb->rbCb[entCfg->rbId] = NULLP;
1082
1083       /* Assign NULLP to dlRbCb/ulRbCb.
1084        * Delete Hashlist allocated for it if any */
1085       cellCb->lCh[rlcRbCb->lch.lChId - 1].dlRbCb = NULLP;
1086       RLC_FREE(gCb,rlcRbCb, sizeof(RlcDlRbCb));   /*Vartika: Mem leak fix */  
1087    }
1088     /* Get ueCb and delete rbCb from it */
1089    else
1090    {
1091       if (!(RLC_VALIDATE_UE_RBID(entCfg->rbType, entCfg->rbId)))
1092       {
1093          /* Fill entCfm structure */
1094          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1095                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_RB_UNKWN);
1096          DU_LOG("\nERROR  -->  RLC_DL : Invalid RbId for RbType[%d] UEID:%d CELLID:%d", 
1097                   entCfg->rbType,
1098                   ueId,
1099                   cellId);
1100          return RFAILED;
1101       }
1102
1103       /* Get ueCb */
1104       ret = rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb);
1105       if (ret != ROK)
1106       {
1107          /* Fill entCfm structure */
1108          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, 
1109                              CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
1110           DU_LOG("\nERROR  -->  RLC_DL : UeId [%d]: UeCb not found RBID:%d",
1111                   ueId,
1112                   entCfg->rbId);
1113          return (ret);
1114       }
1115
1116       /* Get rbCb */
1117       RLC_DBM_GET_RBCB_FROM_UECB(entCfg->rbId, entCfg->rbType, ueCb, rlcRbCb);
1118
1119       if ( rlcRbCb == NULLP)
1120       {
1121          /* Fill entCfm structure */
1122          RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1123                CKW_CFG_REAS_RB_UNKWN);
1124          DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:RbId[%d] not found",
1125                   cellId,
1126                   entCfg->rbId);
1127          return (ret);
1128       }
1129
1130       ueCb->lCh[rlcRbCb->lch.lChId - 1].dlRbCb = NULLP;
1131
1132 #ifdef LTE_L2_MEAS
1133       RLC_UPD_L2_DECR_NONIP_PER_QCI_RB_COUNT(gCb, rlcRbCb);
1134 #endif
1135       /* Free the Buffers of RbCb */
1136       if( RLC_MODE_UM == rlcRbCb->mode)
1137       {
1138          rlcUmmFreeDlRbCb(gCb,rlcRbCb);
1139          /* Delete RbCb  */
1140          RLC_FREE(gCb,rlcRbCb, sizeof(RlcDlRbCb));     
1141       }
1142       else if( RLC_MODE_AM == rlcRbCb->mode)
1143       {
1144          rlcAmmFreeDlRbCb(gCb,rlcRbCb);
1145       }
1146
1147       /* Assign NULLP to rbCb in rbCbLst */
1148       if ( entCfg->rbType == CM_LTE_SRB )
1149       {
1150          ueCb->srbCb[entCfg->rbId] = NULLP;
1151       }
1152       else
1153       {
1154          ueCb->drbCb[entCfg->rbId] = NULLP;
1155       }
1156    }
1157
1158    RLC_LMM_RB_STS_DEC(gCb);
1159
1160    /* Fill entCfm structure */
1161    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType, CKW_CFG_CFM_OK, 
1162                        CKW_CFG_REAS_NONE);
1163
1164    return (ret);
1165
1166
1167 \f
1168 /** 
1169  * @brief This primitive re-establish the existing RB in Ue/Cell Cb.
1170  *
1171  * @details
1172  *    - If UE ID is 0 then
1173  *      - Check for CELL CB is present
1174  *      - If yes, Check for RB ID
1175  *        - If RB ID is prenset initialize the parameters of the RB CB
1176  *        - Else, Status Indication with Reason
1177  *      - Else, Status Indication with Reason
1178  *    - Else,
1179  *      - Check for UE CB is present
1180  *      - If yes, Check for RB ID
1181  *        - If RB ID is prenset initialize the parameters of the RB CB
1182  *        - Else, Status Indication with Reason
1183  *      - Else, Status Indication with Reason
1184  *    - Fill entity confirmation
1185  *
1186  * @param [in]    gCb      -  RLC Instance Control Block
1187  * @param [in]    ueId     -  UE Identifier
1188  * @param [in]    cellId   -  CELL Identifier
1189  * @param [in]    entCfg   -  Entity Configuration to be done.
1190  * @param [out]   entCfm   -  Entity Confirmation
1191  *
1192  * @return  S16
1193  *    -# ROK
1194  *    -# RFAILED
1195  */
1196 S16 rlcCfgReEstDlRb
1197 (
1198 RlcCb              *gCb,
1199 CmLteRnti          ueId,
1200 CmLteCellId        cellId,
1201 Bool               sndReEstInd,
1202 RlcEntCfgInfo      *entCfg,
1203 RlcEntCfgCfmInfo   *entCfm
1204 )
1205 {
1206    RlcDlRbCb     *rbCb;   /* RB Control Block */
1207    CmLteRlcId   rlcId;   /* RLC Identifier */
1208
1209    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgReEstDlRb(ueId(%d), cellId(%d), cfgType(%d))",
1210             ueId, 
1211             cellId, 
1212             entCfg->cfgType);
1213
1214    /* Get rlcId */
1215    rlcId.ueId = ueId;
1216    rlcId.cellId = cellId;
1217    rlcId.rbId = entCfg->rbId;
1218    rlcId.rbType = entCfg->rbType;
1219
1220    rlcDbmFetchDlRbCbByRbId(gCb,&rlcId, &rbCb);
1221    if (rbCb == NULLP)
1222    {
1223       /* Fill entCfm structure */
1224       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, rlcId.rbType, CKW_CFG_CFM_NOK,
1225             CKW_CFG_REAS_RB_UNKWN);
1226       DU_LOG("\nERROR  -->  RLC_DL : CellId[%u]:RbId[%d] not found",
1227                cellId,
1228                entCfg->rbId);
1229       return RFAILED;
1230    }
1231
1232    rbCb->rlcId.ueId = ueId;
1233
1234    switch (rbCb->mode)
1235    {
1236       case RLC_MODE_TM:
1237          {
1238             rlcDlTmmReEstablish(gCb,rbCb);
1239             break;
1240          }
1241
1242       case RLC_MODE_UM:
1243          {
1244             rlcDlUmmReEstablish(gCb,rlcId,sndReEstInd,rbCb);
1245             break;
1246          }
1247
1248       case RLC_MODE_AM:
1249          {           
1250             rlcAmmDlReEstablish(gCb, rlcId, rbCb);
1251             break;
1252          }
1253    }
1254
1255    /* Fill entCfm structure */
1256    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1257       CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
1258
1259    return ROK;
1260
1261
1262 \f
1263 /** 
1264  * @brief This primitive deletes the RBs in Ue Cb.
1265  *
1266  * @details
1267  *    - If UE ID is 0 then
1268  *      - Status Indication with Reason
1269  *    - Else,
1270  *      - Check for UE CB is present
1271  *      - If yes, Delete all RB CB in UE CB and Delete UE CB also.
1272  *      - Else, Status Indication with Reason
1273  *    - Fill entity confirmation
1274  *
1275  * @param [in]    gCb      -  RLC Instance Control Block
1276  * @param [in]    ueId     -  UE Identifier
1277  * @param [in]    cellId   -  CELL Identifier
1278  * @param [in]    entCfg   -  Entity Configuration to be done.
1279  * @param [out]   entCfm   -  Entity Confirmation
1280  *
1281  * @return  S16
1282  *    -#ROK
1283  *    -#RFAILED
1284  */
1285 S16 rlcCfgDelDlUe
1286 (
1287 RlcCb              *gCb,
1288 CmLteRnti          ueId,
1289 CmLteCellId        cellId,
1290 RlcEntCfgInfo      *entCfg,
1291 RlcEntCfgCfmInfo   *entCfm
1292 )
1293 {
1294    S16        ret;     /* Return Value */
1295    RlcDlUeCb   *ueCb;   /* UE Control Block */
1296
1297    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgDelUe(ueId(%d), cellId(%d), cfgType(%d))",
1298             ueId, 
1299             cellId, 
1300             entCfg->cfgType);
1301
1302    ret = ROK;
1303
1304    /* Check for ueId is present or not */
1305    if ( ueId == 0 )
1306    {
1307       /* Fill entCfm structure */
1308       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1309           CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
1310       DU_LOG("\nERROR  -->  RLC_DL : ueId(%d), cellId(%d)",
1311                ueId, 
1312                cellId);
1313       return RFAILED;
1314    }
1315
1316    /* Fetch Ue Cb */
1317    ret = rlcDbmFetchDlUeCb(gCb,ueId, cellId, &ueCb);
1318    if (ret != ROK)
1319    {
1320       /* Fill entCfm structure */
1321       RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1322          CKW_CFG_CFM_NOK, CKW_CFG_REAS_UE_UNKWN);
1323       DU_LOG("\nERROR  -->  RLC_DL : UEID:%d UeCb not found RBID:%d",
1324                ueId,
1325                entCfg->rbId);
1326       return RFAILED;
1327    }
1328
1329 #ifdef LTE_L2_MEAS
1330    rlcDelFrmDlL2Meas(gCb,cellId,ueId);
1331    rlcDbmDelAllDlL2MeasTbFrmUe(gCb,ueCb);
1332 #endif
1333    /* Delete Ue Cb */
1334    rlcDbmDelDlUeCb(gCb,ueCb, FALSE);
1335
1336    /* Fill entCfm structure */
1337    RLC_CFG_FILL_CFG_CFM(entCfm, entCfg->rbId, entCfg->rbType,
1338       CKW_CFG_CFM_OK, CKW_CFG_REAS_NONE);
1339
1340    return ROK;
1341
1342
1343
1344 /**
1345  * @brief This primitive deletes the RBs in Ue Cb.
1346  *
1347  * @details
1348  *    - If CELL ID is 0 then
1349  *      - Status Indication with Reason
1350  *    - Else,
1351  *      - Check for CELL CB is present
1352  *      - If yes, Delete all RB CB in CELL CB and Delete CELL CB also.
1353  *      - Else, Status Indication with Reason
1354  *    - Fill entity confirmation
1355  *
1356  * @param [in]    cellId   -  CELL Identifier
1357  * @param [in]    entCfg   -  Entity Configuration to be done.
1358  * @param [out]   entCfm   -  Entity Confirmation
1359  *
1360  * @return S16
1361  *    -#ROK
1362  *    -#RFAILED
1363  */
1364 S16 rlcCfgDelDlCell
1365 (
1366 RlcCb               *gCb,
1367 CmLteCellId        cellId,
1368 RlcEntCfgInfo      *entCfg,
1369 RlcEntCfgCfmInfo   *entCfm
1370 )
1371 {
1372    RlcDlCellCb   *cellCb;   /* UE Control Block */
1373    uint8_t       rbId;      /* RB Identifier */
1374
1375    DU_LOG("\nDEBUG  -->  RLC_DL : rlcCfgDelCell( cellId(%d), cfgType(%d)",
1376          cellId, 
1377          entCfg->cfgType);
1378
1379    cellCb = NULLP;
1380    rbId = entCfg->rbId;
1381
1382    /* Check for ueId is present or not */
1383    if ( cellId == 0 )
1384    {
1385       /* Fill entCfm structure */
1386       RLC_CFG_FILL_CFG_CFM(entCfm, rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1387             CKW_CFG_REAS_CELL_UNKWN);
1388       DU_LOG("\nERROR  -->  RLC_DL : cellId is 0 (%d) ",
1389                cellId);
1390       return RFAILED;
1391    }
1392
1393    /* Fetch Ue Cb */
1394    rlcDbmFetchDlCellCb(gCb,cellId, &cellCb);
1395    if (!cellCb)
1396    {
1397       /* Fill entCfm structure */
1398       RLC_CFG_FILL_CFG_CFM(entCfm, rbId, entCfg->rbType, CKW_CFG_CFM_NOK,
1399             CKW_CFG_REAS_CELL_UNKWN);
1400       DU_LOG("\nERROR  -->  RLC_DL : CellCb not found for RBID:%d",
1401                entCfg->rbId);
1402       return RFAILED;
1403    }
1404
1405    /* Delete Ue Cb */
1406    rlcDbmDelDlCellCb(gCb,cellCb);
1407
1408    /* Fill entCfm structure */
1409   /* kw005.201 added support for L2 Measurement */         
1410    RLC_CFG_FILL_CFG_CFM(entCfm, rbId, entCfg->rbType, CKW_CFG_CFM_OK,
1411                        CKW_CFG_REAS_NONE);
1412
1413    return ROK;
1414
1415
1416 /**
1417  * @brief This primitive changes the ueId of Ue Cb.
1418  *
1419  * @details
1420  *    - If oldUeId and newUeId are
1421  *      - Confirm the Status with Reason
1422  *    - If UeId not present
1423  *      - Confirm the Status with Reason
1424  *    - Create New UeCb
1425  *    - Copy rbCbs from old UeCb to new UeCb
1426  *    - Delete old UeCb
1427  *    - Fill entity confirmation
1428  *
1429  * @param [in]    ueInfo      -  Old UE Information
1430  * @param [in]    newUeInfo   -  New UE Information
1431  * @param [out]   status      -  Status
1432  *
1433  * @return  S16
1434  *    -# ROK
1435  *    -# RFAILED
1436  */
1437 S16 rlcCfgDlUeIdChng
1438 (
1439 RlcCb        *gCb,
1440 CkwUeInfo   *ueInfo,
1441 CkwUeInfo   *newUeInfo,
1442 CmStatus    *status
1443 )
1444 {
1445    RlcDlUeCb *ueCb;
1446 /*kw004.201 Adding of Missing Trace in RLC PDCP*/
1447
1448    if ( (ueInfo->ueId == newUeInfo->ueId) && 
1449         (ueInfo->cellId == newUeInfo->cellId))
1450    {
1451       status->reason = CKW_CFG_REAS_SAME_UEID;
1452       status->status = CKW_CFG_CFM_NOK; 
1453       DU_LOG("\nERROR  -->  RLC_DL : Old UeId[%d] same as new UeId[%d]",
1454             ueInfo->ueId,
1455             newUeInfo->ueId);
1456       return RFAILED;
1457    } 
1458    
1459    if(ROK == rlcDbmFetchDlUeCb(gCb,newUeInfo->ueId, newUeInfo->cellId, &ueCb))
1460    {
1461       DU_LOG("\nERROR  -->  RLC_DL : NewUeId[%d]:ueCb already exists",
1462             newUeInfo->ueId);
1463       status->reason = CKW_CFG_REAS_UE_EXISTS;
1464       status->status = CKW_CFG_CFM_NOK;
1465       return RFAILED;
1466    }
1467   
1468    if(ROK != rlcDbmFetchDlUeCb(gCb,ueInfo->ueId, ueInfo->cellId, &ueCb))
1469    {
1470
1471       DU_LOG("\nERROR  -->  RLC_DL : UeId [%d]: UeCb not found",
1472             ueInfo->ueId);
1473       status->reason = CKW_CFG_REAS_UE_UNKWN;
1474       status->status = CKW_CFG_CFM_NOK;
1475       return RFAILED;
1476    }
1477   
1478 #ifdef LTE_L2_MEAS
1479    rlcHdlMeasDlUeIdChg(gCb, ueInfo->cellId, ueInfo->ueId, newUeInfo->ueId);
1480 #endif   
1481    if(ROK != cmHashListDelete(&(gCb->u.dlCb->ueLstCp), (PTR) ueCb))
1482    {
1483       DU_LOG("\nERROR  -->  RLC_DL : UeId[%u] HashList Deletion Failed",
1484             ueInfo->ueId);
1485       status->reason = CKW_CFG_REAS_UE_CREAT_FAIL;
1486       status->status = CKW_CFG_CFM_NOK;
1487       return RFAILED;
1488    }
1489    
1490    /* update the hash key with new values */ 
1491    ueCb->ueId = newUeInfo->ueId;
1492    ueCb->cellId = newUeInfo->cellId;
1493
1494    if(ROK != cmHashListInsert(&(gCb->u.dlCb->ueLstCp), 
1495                               (PTR)ueCb, (uint8_t *)&(ueCb->ueId),
1496                               (uint16_t) sizeof(CmLteRnti)))
1497
1498    {
1499       DU_LOG("\nERROR  -->  RLC_DL : UeId[%u] HashList Insertion Failed",
1500             newUeInfo->ueId);
1501       status->reason = CKW_CFG_REAS_UE_CREAT_FAIL;
1502       status->status = CKW_CFG_CFM_NOK;
1503       return RFAILED;
1504    }  
1505   
1506    return ROK;
1507
1508
1509 /********************************************************************30**
1510
1511          End of file
1512 **********************************************************************/