Memory handling fixes [Issue-ID: ODUHIGH-337]
[o-du/l2.git] / src / du_app / du_ue_mgr.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 /* This file contains UE management handling functionality for DU APP */
19 #include "common_def.h"
20 #include "lrg.h"
21 #include "lrg.x"
22 #include "ckw.h"
23 #include "ckw.x"
24 #include "kwu.h"
25 #include "kwu.x"
26 #include "lkw.h"
27 #include "lkw.x"
28 #include "legtp.h"
29 #include "du_app_mac_inf.h"
30 #include "du_app_rlc_inf.h"
31 #include "du_cfg.h"
32 #include "du_utils.h"
33 #include "du_mgr.h"
34 #include "du_f1ap_msg_hdl.h"
35 #include "du_ue_mgr.h"
36
37 DuMacDlCcchInd packMacDlCcchIndOpts[] =
38 {
39    packMacDlCcchInd,           /* Loose coupling */
40    MacProcDlCcchInd,           /* TIght coupling */
41    packMacDlCcchInd            /* Light weight-loose coupling */
42 };
43
44 DuMacUeCreateReq packMacUeCreateReqOpts[] =
45 {
46    packDuMacUeCreateReq,       /* Loose coupling */
47    MacProcUeCreateReq,         /* TIght coupling */
48    packDuMacUeCreateReq        /* Light weight-loose coupling */
49 };
50
51 DuRlcUeCreateReq packRlcUeCreateReqOpts[] =
52 {
53    packDuRlcUeCreateReq,       /* Loose coupling */
54    RlcProcUeCreateReq,         /* TIght coupling */
55    packDuRlcUeCreateReq        /* Light weight-loose coupling */
56 };
57
58 DuDlRrcMsgToRlcFunc duSendDlRrcMsgToRlcOpts[] =
59 {
60    packDlRrcMsgToRlc,          /* Loose coupling */ 
61    RlcProcDlRrcMsgTransfer,    /* Tight coupling */
62    packDlRrcMsgToRlc           /* Light weight-loose coupling */
63 };
64
65 DuRlcUeReconfigReq packRlcUeReconfigReqOpts[] =
66 {
67    packDuRlcUeReconfigReq,     /* Loose coupling */
68    RlcProcUeReconfigReq,       /* TIght coupling */
69    packDuRlcUeReconfigReq      /* Light weight-loose coupling */
70 };
71
72 DuMacUeReconfigReq packMacUeReconfigReqOpts[] =
73 {
74    packDuMacUeReconfigReq,     /* Loose coupling */
75    MacProcUeReconfigReq,       /* TIght coupling */
76    packDuMacUeReconfigReq      /* Light weight-loose coupling */
77 };
78
79 DuRlcDlUserDataToRlcFunc duSendRlcDlUserDataToRlcOpts[] =
80 {
81    packRlcDlUserDataToRlc,        /* Loose coupling */ 
82    RlcProcDlUserDataTransfer,  /* Tight coupling */
83    packRlcDlUserDataToRlc         /* Light weight-loose coupling */
84 };
85
86 DuMacUeDeleteReq packMacUeDeleteReqOpts[] =
87 {
88    packDuMacUeDeleteReq,       /* Loose coupling */
89    MacProcUeDeleteReq,         /* TIght coupling */
90    packDuMacUeDeleteReq        /* Light weight-loose coupling */
91 };
92
93 DuRlcUeDeleteReq packRlcUeDeleteReqOpts[] =
94 {
95    packDuRlcUeDeleteReq,       /* Loose coupling */
96    RlcProcUeDeleteReq,         /* TIght coupling */
97    packDuRlcUeDeleteReq        /* Light weight-loose coupling */
98 };
99
100 DuMacCellDeleteReq packMacCellDeleteReqOpts[] =
101 {
102    packDuMacCellDeleteReq,       /* Loose coupling */
103    MacProcCellDeleteReq,         /* TIght coupling */
104    packDuMacCellDeleteReq        /* Light weight-loose coupling */
105 };
106
107 /*******************************************************************
108  *
109  * @brief Function to fillDlUserDataInfo
110  *
111  * @details
112  *
113  *    Function : fillDlUserDataInfo
114  *
115  *    Functionality:
116  *      Function to fillDlUserDataInfo
117  *
118  * @params[in] teId,
119  *             dlDataMsgInfo
120  *
121  * @return ROK     - success
122  *         RFAILED - failure
123  *
124  * ****************************************************************/
125
126 uint8_t fillDlUserDataInfo(uint32_t teId, RlcDlUserDataInfo *dlDataMsgInfo)
127 {
128    uint8_t drbIdx;
129
130    for(drbIdx = 0; drbIdx < duCb.numDrb; drbIdx++)
131    {
132       if(duCb.upTnlCfg[drbIdx] && (duCb.upTnlCfg[drbIdx]->tnlCfg1 != NULLP))
133       {
134         if(duCb.upTnlCfg[drbIdx]->tnlCfg1->teId == teId)
135         {
136            dlDataMsgInfo->cellId = duCb.upTnlCfg[drbIdx]->cellId;
137            dlDataMsgInfo->ueIdx = duCb.upTnlCfg[drbIdx]->ueIdx;
138            dlDataMsgInfo->rbId = duCb.upTnlCfg[drbIdx]->drbId;
139            return ROK;
140         }
141       }
142    }
143    return RFAILED;
144 }
145
146  /*******************************************************************
147  *
148  * @brief Build and Send DL Data Message transfer to RLC
149  *
150  * @details
151  *
152  *    Function : duBuildAndSendDlUserDataToRlc
153  *
154  *    Functionality:
155  *      Build and Send DL Data Message transfer to RLC
156  *
157  * @params[in] Cell ID
158  *             UE Index
159  *             Logical Channgel ID
160  *             RRC Message
161  *             RRC Message Length
162  * @return ROK     - success
163  *         RFAILED - failure
164  *
165  * ****************************************************************/
166
167 uint8_t duBuildAndSendDlUserDataToRlc(uint16_t msgLen, EgtpMsg *egtpMsg)
168 {
169    uint8_t ret = RFAILED;
170    Pst     pst;
171    RlcDlUserDataInfo *dlDataMsgInfo = NULLP;
172
173    DU_ALLOC_SHRABL_BUF(dlDataMsgInfo, sizeof(RlcDlUserDataInfo));
174    if(!dlDataMsgInfo)
175    {
176       DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed for dlDataMsgInfo in duHdlEgtpDlData()");
177       return RFAILED;
178    }
179    memset(dlDataMsgInfo, 0, sizeof(RlcDlUserDataInfo));
180    dlDataMsgInfo->dlMsg = egtpMsg->msg;
181    dlDataMsgInfo->msgLen = msgLen;
182
183    /* Filling DL DATA Msg Info */
184    if(fillDlUserDataInfo(egtpMsg->msgHdr.teId, dlDataMsgInfo) == ROK)
185    {
186       /* Filling post structure and sending msg */ 
187       FILL_PST_DUAPP_TO_RLC(pst, RLC_DL_INST, EVENT_DL_USER_DATA_TRANS_TO_RLC);
188       DU_LOG("\nDEBUG  -->  DU_APP : Sending User Data Msg to RLC \n");
189       ret = (*duSendRlcDlUserDataToRlcOpts[pst.selector])(&pst, dlDataMsgInfo);
190    }
191    if(ret != ROK)
192    {
193       DU_LOG("\nERROR  -->  DU_APP : Failed to send User Data to RLC in duHdlEgtpDlData()");
194       ODU_PUT_MSG_BUF(dlDataMsgInfo->dlMsg);
195       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlDataMsgInfo, sizeof(RlcDlUserDataInfo));
196    }
197    return ret;
198 }
199
200 /*******************************************************************
201  *
202  * @brief Handles EGTP data from CU 
203  *
204  * @details
205  *
206  *    Function : duHdlEgtpData
207  *
208  *    Functionality: 
209  *      Processes EGTP header and sends data to RLC
210  *
211  * @params[in]  Pointer to EGTP Message 
212  * @return ROK     - success
213  *         RFAILED - failure
214  *
215  * ****************************************************************/
216 uint8_t duHdlEgtpDlData(EgtpMsg  *egtpMsg)
217 {
218    uint16_t msgLen = 0;
219    DU_LOG("\nDEBUG  --> DU_APP : Processing DL data in duHdlEgtpDlData()");
220    
221    if(!egtpMsg->msg)
222    {
223       DU_LOG("\nERROR  -->  DU_APP : Recevied Dl Data is NULLP in duHdlEgtpDlData()");
224       return RFAILED;
225    }
226    ODU_GET_MSG_LEN(egtpMsg->msg, (MsgLen *)&msgLen);
227    if(duBuildAndSendDlUserDataToRlc(msgLen, egtpMsg) != ROK)
228    {
229       DU_LOG("\nERROR  -->  DU_APP : Failed to build DL USer Data in duHdlEgtpDlData()");
230       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, egtpMsg->msg, msgLen);
231       return RFAILED;
232    }
233    return ROK;
234 }
235
236 /******************************************************************
237  *
238  * @brief Builds and Sends DL CCCH Ind to MAC
239  *
240  * @details
241  *
242  *    Function : duBuildAndSendDlCcchInd 
243  *
244  *    Functionality: Builds and sends DL CCCH Ind Msg to MAC
245  *
246  * @params[in] dlCcchMsg - uint8_t*
247  * @return ROK     - success
248  *         RFAILED - failure
249  *
250  * ****************************************************************/
251 uint8_t duBuildAndSendDlCcchInd(uint16_t *cellId, uint16_t *crnti, \
252       DlCcchMsgType msgType, uint16_t dlCcchMsgSize, uint8_t *dlCcchMsg)
253 {
254    uint8_t  ret                  = ROK;
255    uint16_t idx2;
256    DlCcchIndInfo *dlCcchIndInfo = NULLP;
257    Pst pst;
258
259    DU_LOG("\nDEBUG   -->  DU APP : Building and Sending DL CCCH Ind to MAC");
260
261    DU_ALLOC_SHRABL_BUF(dlCcchIndInfo, sizeof(DlCcchIndInfo));
262
263    if(!dlCcchIndInfo)
264    {
265       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed while building DL CCCH Ind");
266       return RFAILED;
267    }
268
269    dlCcchIndInfo->cellId = *cellId;
270    dlCcchIndInfo->crnti = *crnti;
271    dlCcchIndInfo->msgType = msgType;
272    dlCcchIndInfo->dlCcchMsgLen = dlCcchMsgSize;
273
274    DU_ALLOC_SHRABL_BUF(dlCcchIndInfo->dlCcchMsg, dlCcchIndInfo->dlCcchMsgLen);
275    if(!dlCcchIndInfo->dlCcchMsg)
276    {
277       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed while building DL CCCH Ind");
278       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo, sizeof(DlCcchIndInfo));
279       return RFAILED;
280    }
281    for(idx2 = 0; idx2 < dlCcchIndInfo->dlCcchMsgLen; idx2++)
282    {
283       dlCcchIndInfo->dlCcchMsg[idx2] = dlCcchMsg[idx2];
284    }
285    DU_FREE(dlCcchMsg, dlCcchMsgSize);
286
287    /* Fill Pst */
288    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_DL_CCCH_IND);
289    ret = (*packMacDlCcchIndOpts[pst.selector])(&pst, dlCcchIndInfo);
290    if(ret != ROK)
291    {
292       DU_LOG("\nERROR  -->  DU_APP : Failure in sending DL CCCH to MAC");
293       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo->dlCcchMsg,\
294             dlCcchIndInfo->dlCcchMsgLen);
295       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo, \
296             sizeof(DlCcchIndInfo));
297       ret = RFAILED; 
298    }
299
300    return ret;
301
302 }
303
304 /*******************************************************************
305  *
306  * @brief Build and Send DL RRC Message transfer to RLC
307  *
308  * @details
309  *
310  *    Function : duBuildAndSendDlRrcMsgToRlc
311  *
312  *    Functionality:
313  *      Build and Send DL RRC Message transfer to RLC
314  *
315  * @params[in] Cell ID
316  *             UE Index
317  *             Logical Channgel ID
318  *             RRC Message
319  *             RRC Message Length
320  * @return ROK     - success
321  *         RFAILED - failure
322  *
323  * ****************************************************************/
324 uint8_t duBuildAndSendDlRrcMsgToRlc(uint16_t cellId, RlcUeCfg ueCfg, F1DlRrcMsg *f1DlRrcMsg)
325 {
326    Pst     pst;
327    uint8_t ret;
328    uint8_t lcIdx;
329    RlcDlRrcMsgInfo  *dlRrcMsgInfo = NULLP;
330
331    if(!f1DlRrcMsg)
332    {
333       DU_LOG("\nERROR  -->  DU APP : Received Dl RRC Msg is NULL at duBuildAndSendDlRrcMsgToRlc()");
334       return RFAILED;
335    }
336
337    DU_ALLOC_SHRABL_BUF(dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
338    if(!dlRrcMsgInfo)
339    {
340       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for dlRrcMsgInfo in \
341          duBuildAndSendDlRrcMsgToRlc");
342       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1DlRrcMsg->rrcMsgPdu, f1DlRrcMsg->rrcMsgSize);
343       return RFAILED;
344    }
345    
346    /* Filling up the RRC msg info */
347    dlRrcMsgInfo->cellId = cellId;
348    dlRrcMsgInfo->ueIdx = ueCfg.ueIdx;
349    for(lcIdx = 0; lcIdx <= MAX_NUM_LC; lcIdx++)
350    {
351       if(ueCfg.rlcLcCfg[lcIdx].lcId == f1DlRrcMsg->srbId)
352       {
353          dlRrcMsgInfo->rbType = ueCfg.rlcLcCfg[lcIdx].rbType;
354          dlRrcMsgInfo->rbId   = ueCfg.rlcLcCfg[lcIdx].rbId;
355          dlRrcMsgInfo->lcType = ueCfg.rlcLcCfg[lcIdx].lcType;
356          dlRrcMsgInfo->lcId   = ueCfg.rlcLcCfg[lcIdx].lcId;
357          break;
358       }
359    }
360    dlRrcMsgInfo->execDup = f1DlRrcMsg->execDup;
361    dlRrcMsgInfo->deliveryStaRpt = f1DlRrcMsg->deliveryStatRpt;
362    dlRrcMsgInfo->msgLen = f1DlRrcMsg->rrcMsgSize;
363    dlRrcMsgInfo->rrcMsg = f1DlRrcMsg->rrcMsgPdu;
364
365    /* Filling post structure and sending msg */ 
366    FILL_PST_DUAPP_TO_RLC(pst, RLC_DL_INST, EVENT_DL_RRC_MSG_TRANS_TO_RLC);
367    DU_LOG("\nDEBUG   -->  DU_APP: Sending Dl RRC Msg to RLC \n");
368    ret = (*duSendDlRrcMsgToRlcOpts[pst.selector])(&pst, dlRrcMsgInfo);
369    if(ret != ROK)
370    {
371       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1DlRrcMsg->rrcMsgPdu, f1DlRrcMsg->rrcMsgSize);
372       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
373       return RFAILED;
374    }
375
376    return ROK;
377
378
379
380
381 /******************************************************************
382  *
383  * @brief Process DL RRC Msg recevied from F1AP
384  *
385  * @details
386  *
387  *    Function : duProcDlRrcMsg
388  *
389  *    Functionality: Process DL RRC Msg recevied from F1AP
390  *
391  * @params[in] dlCcchMsg - uint8_t*
392  * @return ROK     - success
393  *         RFAILED - failure
394  *
395  * ****************************************************************/
396
397 uint8_t duProcDlRrcMsg(F1DlRrcMsg *dlRrcMsg)
398 {
399    uint8_t ueIdx, ret;
400    uint16_t crnti, cellId, cellIdx;
401    bool ueCcchCtxtFound = false;
402    bool ueFound = false;
403
404    ret = ROK;
405
406    if(dlRrcMsg->srbId == SRB0_LCID) //RRC connection setup
407    {
408       for(ueIdx=0; ueIdx<duCb.numUe; ueIdx++)
409       {
410          if(dlRrcMsg->gnbDuUeF1apId == duCb.ueCcchCtxt[ueIdx].gnbDuUeF1apId)
411          {
412             ueCcchCtxtFound = true;
413             crnti  = duCb.ueCcchCtxt[ueIdx].crnti;
414             cellId = duCb.ueCcchCtxt[ueIdx].cellId;
415             break;
416          }
417       }
418    }
419    if(ueCcchCtxtFound)
420    {
421       ret = duBuildAndSendDlCcchInd(&cellId, &crnti, RRC_SETUP, dlRrcMsg->rrcMsgSize, dlRrcMsg->rrcMsgPdu);
422       if(ret == RFAILED)
423       {
424          DU_LOG("\nERROR  -->  DU APP : Failed to build DlCcch Ind at procDlRrcMsgTrans()");
425       }
426       else
427       {
428          if(duCb.actvCellLst[cellId-1]->numActvUes < MAX_NUM_UE)
429          {
430             ret = duCreateUeCb(&duCb.ueCcchCtxt[ueIdx], dlRrcMsg->gnbCuUeF1apId);
431             if(ret == RFAILED)
432             {
433                DU_LOG("\nERROR  -->  DU APP : Failed to createUeCb for cellId [%d] at procDlRrcMsgTrans()", \
434                      duCb.ueCcchCtxt[ueIdx].cellId);
435             }
436          }
437          else
438          {
439             DU_LOG("\nERROR   -->  DU_APP: Max Active UEs has reached at procDlRrcMsgTrans()");
440             ret = RFAILED;
441          }
442       }
443    }
444    else
445    {
446       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
447       {
448          for(ueIdx = 0 ; ueIdx < MAX_NUM_UE; ueIdx++)
449          {
450             if((dlRrcMsg->gnbCuUeF1apId == duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId)
451                   && (dlRrcMsg->gnbDuUeF1apId == duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId))
452             {
453                ueFound = true;
454                ret = duBuildAndSendDlRrcMsgToRlc(duCb.actvCellLst[cellIdx]->cellId, \
455                      duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg, dlRrcMsg);
456                break; 
457             }
458          }
459          if(ueFound)
460             break;
461       }
462       if(!ueFound)
463          ret = RFAILED;
464    }
465    return ret;
466 }
467
468 /******************************************************************
469  *
470  * @brief Generates GNB DU Ue F1AP ID
471  *
472  * @details
473  *
474  *    Function : genGnbDuUeF1apId
475  *
476  *    Functionality: Generates GNB DU Ue F1AP ID
477  *
478  * @params[in] void
479  * @return gnbDuF1apId
480  *
481  * ****************************************************************/
482 uint32_t genGnbDuUeF1apId()
483 {
484    static uint32_t gnbDuUeF1apId = 0;
485
486    return ++gnbDuUeF1apId;
487 }
488
489 /******************************************************************
490  *
491  * @brief Processes UL CCCH Ind recvd from MAC
492  *
493  * @details
494  *
495  *    Function : duProcUlCcchInd
496  *
497  *    Functionality: Processes UL CCCH Ind recvd from MAC
498  *
499  * @params[in] UlCcchIndInfo *ulCcchIndInfo
500  * @return ROK     - success
501  *         RFAILED - failure
502  *
503  * ****************************************************************/
504 uint8_t duProcUlCcchInd(UlCcchIndInfo *ulCcchIndInfo)
505 {
506
507    uint8_t ret = ROK;
508    uint32_t gnbDuUeF1apId = 0;
509
510    gnbDuUeF1apId = genGnbDuUeF1apId();
511
512    /* Store Ue mapping */
513    duCb.ueCcchCtxt[duCb.numUe].gnbDuUeF1apId = gnbDuUeF1apId;
514    duCb.ueCcchCtxt[duCb.numUe].crnti         = ulCcchIndInfo->crnti;
515    duCb.ueCcchCtxt[duCb.numUe].cellId        = ulCcchIndInfo->cellId;
516
517    duCb.numUe++;
518
519    ret = (BuildAndSendInitialRrcMsgTransfer(gnbDuUeF1apId, ulCcchIndInfo->crnti, ulCcchIndInfo->ulCcchMsgLen,
520             ulCcchIndInfo->ulCcchMsg));
521    if(ret != ROK)
522    {
523       DU_LOG("\nERROR  -->  DU_APP : BuildAndSendInitialRrcMsgTransfer failed");
524    }
525
526    DU_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
527    DU_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
528
529    return ret;
530
531 }
532
533 /******************************************************************
534  *
535  * @brief Fills Default UL LC Cfg
536  *
537  * @details
538  *
539  *    Function : fillDefaultUlLcCfg
540  *
541  *    Functionality: Fills Default UL LC Cfg
542  *
543  * @params[in]  UlLcCfg *ulLcCfg 
544  * @return void
545  *****************************************************************/
546 void fillDefaultUlLcCfg(UlLcCfg *ulLcCfg)
547 {
548    ulLcCfg->priority = LC_PRIORITY_1;
549    ulLcCfg->lcGroup =  0;
550    ulLcCfg->schReqId = 0;
551    ulLcCfg->pbr = PBR_KBPS_INFINITY;
552    ulLcCfg->bsd = BSD_MS_1000;
553 }
554
555 /******************************************************************
556  *
557  * @brief Fills Initial DL Bandwidth Part
558  *
559  * @details
560  *
561  *    Function : fillDefaultInitDlBwp
562  *
563  *    Functionality: Fills Initial DL Bandwidth Part
564  *
565  * @params[in]  InitialDlBwp *initDlBwp
566  * @return void
567  *
568  *****************************************************************/
569 void fillDefaultInitDlBwp(InitialDlBwp *initDlBwp)
570 {
571    uint8_t idx = 0;
572    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
573    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
574
575
576    if(initDlBwp)
577    {
578       /* Filling PDCCH Config */
579       initDlBwp->pdcchPresent = TRUE;
580       if(initDlBwp->pdcchPresent)
581       {
582          initDlBwp->pdcchCfg.numCRsetToAddMod = PDCCH_CTRL_RSRC_SET_ONE_ID;
583          memset(initDlBwp->pdcchCfg.cRSetToAddModList, 0, MAX_NUM_CRSET);
584          if(initDlBwp->pdcchCfg.numCRsetToAddMod <= MAX_NUM_CRSET)
585          {
586             initDlBwp->pdcchCfg.cRSetToAddModList[idx].cRSetId = \
587                PDCCH_CTRL_RSRC_SET_ONE_ID;
588             memset(initDlBwp->pdcchCfg.cRSetToAddModList[idx].freqDomainRsrc, 0,\
589                FREQ_DOM_RSRC_SIZE); 
590             coreset0EndPrb = CORESET0_END_PRB;
591             coreset1StartPrb = coreset0EndPrb +6;
592             coreset1NumPrb = CORESET1_NUM_PRB;
593             /* calculate the PRBs */
594             freqDomRscAllocType0(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
595             memcpy(initDlBwp->pdcchCfg.cRSetToAddModList[idx].freqDomainRsrc, freqDomainResource,
596                FREQ_DOM_RSRC_SIZE);
597
598             initDlBwp->pdcchCfg.cRSetToAddModList[idx].duration = \
599                PDCCH_CTRL_RSRC_SET_ONE_DURATION;
600             initDlBwp->pdcchCfg.cRSetToAddModList[idx].cceRegMappingType = \
601                CCE_REG_MAPPINGTYPE_PR_NONINTERLEAVED;
602             initDlBwp->pdcchCfg.cRSetToAddModList[idx].precoderGranularity = \
603                ALL_CONTIGUOUS_RBS;
604             initDlBwp->pdcchCfg.cRSetToAddModList[idx].dmrsScramblingId = \
605                SCRAMBLING_ID;
606          }
607          initDlBwp->pdcchCfg.numCRsetToRel = 0;
608          /* Filling Serach Space */
609          initDlBwp->pdcchCfg.numSearchSpcToAddMod = PDCCH_CTRL_RSRC_SET_ONE_ID;
610          memset(initDlBwp->pdcchCfg.searchSpcToAddModList, 0, MAX_NUM_CRSET);
611          if(initDlBwp->pdcchCfg.numSearchSpcToAddMod <= MAX_NUM_CRSET)
612          {
613             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].searchSpaceId =\
614                PDCCH_SRCH_SPC_TWO_ID;
615             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].cRSetId = \
616                PDCCH_CTRL_RSRC_SET_ONE_ID;
617             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].\
618                mSlotPeriodicityAndOffset = SLOTPERIODICITYANDOFFSET_PR_SL1;
619             memset(initDlBwp->pdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot, 0,\
620                MONITORING_SYMB_WITHIN_SLOT_SIZE);
621             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot[idx] =\
622                PDCCH_SYMBOL_WITHIN_SLOT;
623             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel1 =\
624                AGGREGATIONLEVEL_N8; 
625             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel2 =\
626                AGGREGATIONLEVEL_N8; 
627             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel4 =\
628                AGGREGATIONLEVEL_N4; 
629             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel8 =\
630                AGGREGATIONLEVEL_N2; 
631             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel16 =\
632                AGGREGATIONLEVEL_N1;
633             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].searchSpaceType = \
634                SEARCHSPACETYPE_PR_UE_SPECIFIC;
635             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].ueSpecificDciFormat =\
636                PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
637
638             initDlBwp->pdcchCfg.numSearchSpcToRel = 0;
639
640          }
641       }
642       /* Filling PDSCH Config */
643       initDlBwp->pdschPresent = TRUE;
644       if(initDlBwp->pdschPresent)
645       {
646          initDlBwp->pdschCfg.dmrsDlCfgForPdschMapTypeA.addPos = ADDITIONALPOSITION_POS0;
647          initDlBwp->pdschCfg.resourceAllocType = RESOURCEALLOCATION_TYPE1;
648          initDlBwp->pdschCfg.numTimeDomRsrcAlloc = 1;
649          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].mappingType = \
650             MAPPING_TYPEA;
651          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].startSymbol = PDSCH_START_SYMBOL; 
652          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].symbolLength = PDSCH_LENGTH_SYMBOL;
653          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].startSymbolAndLength = \
654             calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
655          initDlBwp->pdschCfg.rbgSize = RBG_SIZE_CONFIG1;
656          initDlBwp->pdschCfg.numCodeWordsSchByDci = CODEWORDS_SCHED_BY_DCI_N1;
657          initDlBwp->pdschCfg.bundlingType = TYPE_STATIC_BUNDLING;
658          initDlBwp->pdschCfg.bundlingInfo.StaticBundling.size = 0;
659       }
660    }
661
662 }
663
664 /******************************************************************
665  *
666  * @brief Fills Initial UL Bandwidth Part
667  *
668  * @details
669  *
670  *    Function : fillDefaultInitUlBwp
671  *
672  *    Functionality: Fills Initial UL Bandwidth Part
673  *
674  * @params[in]  InitialUlBwp *initUlBwp
675  * @return void
676  *
677  *****************************************************************/
678 void fillDefaultInitUlBwp(InitialUlBwp *initUlBwp)
679 {
680    uint8_t idx;
681    if(initUlBwp)
682    {
683       initUlBwp->pucchPresent = FALSE;
684
685       /*Filling PUSCH Config */
686       initUlBwp->puschPresent = TRUE;
687       if(initUlBwp->puschPresent)
688       {
689          initUlBwp->puschCfg.dataScramblingId = SCRAMBLING_ID;
690          initUlBwp->puschCfg.dmrsUlCfgForPuschMapTypeA.addPos = ADDITIONALPOSITION_POS0; 
691          initUlBwp->puschCfg.dmrsUlCfgForPuschMapTypeA.transPrecodDisabled. \
692             scramblingId0 = SCRAMBLING_ID; 
693          initUlBwp->puschCfg.resourceAllocType = RESOURCEALLOCATION_TYPE1;
694          initUlBwp->puschCfg.numTimeDomRsrcAlloc = 1;
695          idx = 0;
696          if(initUlBwp->puschCfg.numTimeDomRsrcAlloc <= MAX_NUM_UL_ALLOC)
697          {
698             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].k2 = PUSCH_K2;
699             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].mappingType =\
700                MAPPING_TYPEA;
701             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbol = PUSCH_START_SYMBOL;
702             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].symbolLength = PUSCH_LENGTH_SYMBOL;
703             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbolAndLength =\
704                calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
705          }
706          initUlBwp->puschCfg.transformPrecoder = TRANSFORM_PRECODER_DISABLED;
707       }
708    }
709    else
710    {
711       DU_LOG("\nERROR  -->  DU APP : Memory is NULL of InitalUlBwp");
712    }
713
714 }
715 /******************************************************************
716  *
717  * @brief Fills SpCell Group Info
718  *
719  * @details
720  *
721  *    Function : fillDefaultSpCellGrpInfo
722  *
723  *    Functionality: Fills Sp Cell Group Info
724  *
725  * @params[in]  SpCellCfg *spCell
726  * @return void
727  *
728  *****************************************************************/
729 void fillDefaultSpCellGrpInfo(SpCellCfg *spCell)
730 {
731    if(spCell)
732    {
733       spCell->servCellIdx = SERV_CELL_IDX;
734       /* Filling Initial Dl Bwp */
735       fillDefaultInitDlBwp(&spCell->servCellCfg.initDlBwp);
736
737       spCell->servCellCfg.numDlBwpToAdd    = 0; 
738       spCell->servCellCfg.firstActvDlBwpId = ACTIVE_DL_BWP_ID;
739       spCell->servCellCfg.defaultDlBwpId   = ACTIVE_DL_BWP_ID;
740       spCell->servCellCfg.bwpInactivityTmr = NULLP;
741       spCell->servCellCfg.pdschServCellCfg.maxMimoLayers = NULLP;
742       spCell->servCellCfg.pdschServCellCfg.maxCodeBlkGrpPerTb = NULLP;
743       spCell->servCellCfg.pdschServCellCfg.codeBlkGrpFlushInd = NULLP;
744       spCell->servCellCfg.pdschServCellCfg.xOverhead = NULLP;
745       spCell->servCellCfg.pdschServCellCfg.numHarqProcForPdsch =\
746          NUM_HARQ_PROC_FOR_PDSCH_N_16;
747       /* Filling Initial UL Bwp*/
748       fillDefaultInitUlBwp(&spCell->servCellCfg.initUlBwp);
749       spCell->servCellCfg.numUlBwpToAdd     = 0; 
750       spCell->servCellCfg.firstActvUlBwpId  = ACTIVE_DL_BWP_ID; 
751    }
752    else
753    {
754       DU_LOG("\nERROR  -->  DU APP : Memory is NULL for SpCellGrp");
755    }
756 }
757
758 /******************************************************************
759  *
760  * @brief Fills Physical Cell Group Info
761  *
762  * @details
763  *
764  *    Function : fillDefaultPhyCellGrpInfo
765  *
766  *    Functionality: Fills Physical Cell Group Info
767  *
768  * @params[in]  PhyCellGrpCfg *cellGrp
769  * @return void
770  *
771  *****************************************************************/
772 void fillDefaultPhyCellGrpInfo(PhyCellGrpCfg *cellGrp)
773 {
774    if(cellGrp)
775    {
776       cellGrp->pdschHarqAckCodebook = PDSCH_HARQ_ACK_CODEBOOK_DYNAMIC;
777       cellGrp->pNrFr1 = P_NR_FR1;
778    }
779    else
780    {
781       DU_LOG("\nERROR  -->  DU APP : Memory is NULL for Physical Cell Group");
782    }
783 }
784
785 /******************************************************************
786  *
787  * @brief Fills Mac Cell Group Info
788  *
789  * @details
790  *
791  *    Function : fillDefaultMacCellGrpInfo
792  *
793  *    Functionality: Fills Mac Cell Group Info
794  *
795  * @params[in]  MacCellGrpCfg *cellGrp
796  * @return void
797  *
798  *****************************************************************/
799 void fillDefaultMacCellGrpInfo(MacCellGrpCfg *cellGrp)
800 {
801    uint8_t idx;
802
803    if(cellGrp)
804    {
805       /* Filling Scheduling Request Config */
806       cellGrp->schReqCfg.addModListCount = 1;
807       if(cellGrp->schReqCfg.addModListCount <= MAX_NUM_SR_CFG_PER_CELL_GRP)
808       {
809          for(idx = 0; idx < cellGrp->schReqCfg.addModListCount; idx++)
810          {
811             cellGrp->schReqCfg.addModList[idx].schedReqId    = SCH_REQ_ID;
812             cellGrp->schReqCfg.addModList[idx].srProhibitTmr = SR_PROHIBIT_MS_32;
813             cellGrp->schReqCfg.addModList[idx].srTransMax    = SR_TRANS_MAX_N_16;
814          }
815       }
816       cellGrp->schReqCfg.relListCount = 0;
817
818       /* Filling Tag config */
819       cellGrp->tagCfg.addModListCount = 1;
820       if(cellGrp->tagCfg.addModListCount <= MAC_NUM_TAGS)
821       {
822          for(idx = 0; idx < cellGrp->tagCfg.addModListCount; idx++)
823          {
824             cellGrp->tagCfg.addModList[idx].tagId = TAG_ID;
825             cellGrp->tagCfg.addModList[idx].timeAlignTimer = TIME_ALIGNMENT_TIMER_INFINITY;
826          }
827       }
828       cellGrp->tagCfg.relListCount = 0;
829
830       /* Filling BSR config */
831       cellGrp->bsrTmrCfg.periodicTimer = BSR_PERIODIC_TIMER_SF_10;
832       cellGrp->bsrTmrCfg.retxTimer = BSR_RETX_TIMER_SF_320;
833       cellGrp->bsrTmrCfg.srDelayTimer = BSR_SR_DELAY_TMR_2560;
834
835       /* Filling PHR config */
836       cellGrp->phrCfgSetupPres = true;
837       cellGrp->phrCfg.periodicTimer = PHR_PERIODIC_TIMER_INFINITY;
838       cellGrp->phrCfg.prohibitTimer = PHR_PROHIBIT_TIMER_SF_0;
839       cellGrp->phrCfg.txPowerFactor = PHR_TX_PWR_FACTOR_CHANGE_INFINITY;
840       cellGrp->phrCfg.multiplePHR   = false;
841       cellGrp->phrCfg.dummy         = false;
842       cellGrp->phrCfg.phrType2OtherCell = false;
843       cellGrp->phrCfg.phrOtherCG = PHR_MODE_OTHER_CG_REAL;  
844
845    }
846    else
847    {
848       DU_LOG("\nERROR  -->  DU APP : Memory is NULL for Master Cell Group");
849    }
850 }
851
852 /*******************************************************************
853  *
854  * @brief Fills default modulation info for a UE
855  *
856  * @details
857  *
858  *    Function : fillDefaultModulation
859  *
860  *    Functionality: Fills default modulation info for a UE
861  *
862  * @params[in] Pointer to MAC UE configuration
863  * @return ROK     - success
864  *         RFAILED - failure
865  *
866  * ****************************************************************/
867 void fillDefaultModulation(MacUeCfg *ueCfg)
868 {
869    ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
870    ueCfg->dlModInfo.mcsIndex = SIB1_MCS;
871    ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64; /* Spec 38.214-Table 5.1.3.1-1 */
872
873    ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
874    ueCfg->ulModInfo.mcsIndex = SIB1_MCS;
875    ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64; /* Spec 38.214-Table 5.1.3.1-1 */
876 }
877
878 /******************************************************************
879  *
880  * @brief Function to fill Mac Lc Cfg for SRB1
881  *
882  * @details
883  *
884  *    Function : fillMacSrb1LcCfg
885  *
886  *    Functionality: Function to fill Mac Lc cfg for SRB1
887  *
888  * @params[in]  LcCfg *lcCfg, LcCfg *ueSetReqDb
889  * @return void
890  *****************************************************************/
891
892 void fillMacSrb1LcCfg(LcCfg *macLcCfg)
893 {
894    macLcCfg->lcId   = SRB1_LCID;
895    macLcCfg->configType = CONFIG_ADD;
896    macLcCfg->drbQos = NULLP;
897    macLcCfg->snssai = NULLP;
898    macLcCfg->ulLcCfgPres = true;
899    fillDefaultUlLcCfg(&macLcCfg->ulLcCfg);
900 }
901
902 /******************************************************************
903  *
904  * @brief Function to fill the Lc cfg from ueSetupReqDb
905  *
906  * @details
907  *
908  *    Function : fillMacLcCfgToAddMod
909  *
910  *    Functionality: Function to fill the Lc cfg from ueSetupReqDb
911  *
912  * @params[in]  LcCfg *lcCfg, LcCfg *ueSetReqDb
913  * @return ROK/RFAILED
914  *
915  *****************************************************************/
916
917 uint8_t fillMacLcCfgToAddMod(LcCfg *lcCfg, LcCfg *ueSetReqDb)
918 {
919    uint8_t ret = ROK; 
920    lcCfg->lcId = ueSetReqDb->lcId;
921    lcCfg->configType = ueSetReqDb->configType;
922    /* Filling DRBQOS */
923    if(ueSetReqDb->drbQos)
924    {
925       if(!lcCfg->drbQos)
926       {
927          DU_ALLOC_SHRABL_BUF(lcCfg->drbQos, sizeof(DrbQosInfo));
928          if(!lcCfg->drbQos)
929          {
930             DU_LOG("\nERROR  -->  DU APP : Memory Alloc failed at drQos at fillMacLcCfgToAddMod()");
931             return RFAILED;
932          }
933       }
934       if(ret == ROK)
935       {
936          memcpy(lcCfg->drbQos, ueSetReqDb->drbQos, sizeof(DrbQosInfo));
937       }
938    }
939    else
940    {
941       lcCfg->drbQos = NULLP;
942    }
943
944    if(ret == ROK)
945    {
946       if(ueSetReqDb->snssai)
947       {
948          if(!lcCfg->snssai)
949          {
950             DU_ALLOC_SHRABL_BUF(lcCfg->snssai, sizeof(Snssai));
951             if(!lcCfg->snssai)
952             {
953                DU_LOG("\nERROR  -->  DU APP : Memory Alloc failed at snnsai at fillMacLcCfgToAddMod()");
954                ret = RFAILED;
955             }
956          }
957          if(ret == ROK)
958          {
959             /* Filling SNSSAI */
960             memcpy(lcCfg->snssai, ueSetReqDb->snssai, sizeof(Snssai));
961          }
962          else
963          {
964             lcCfg->snssai = NULLP;
965             if(lcCfg->drbQos)
966             {
967                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
968                lcCfg->drbQos = NULLP;
969             }
970             return ret;
971          }
972       }
973       else
974          lcCfg->snssai = NULLP;
975    }
976    lcCfg->ulLcCfgPres = ueSetReqDb->ulLcCfgPres;
977    memcpy(&lcCfg->ulLcCfg, &ueSetReqDb->ulLcCfg, sizeof(UlLcCfg));
978    memcpy(&lcCfg->dlLcCfg, &ueSetReqDb->dlLcCfg, sizeof(DlLcCfg));
979    return ret;
980 }
981
982 /******************************************************************
983  *
984  * @brief Function to copy the Bit rate from ueSetupReqDb
985  *
986  * @details
987  *
988  *    Function : fillAmbr
989  *
990  *    Functionality: Function to copy bit Rate from ueSetupReqDb
991  *
992  * @params[in]  AmbrCfg **macAmbr, AmbrCfg  *ueDbAmbr
993  * @return ROK/RFAILED
994  *
995  *****************************************************************/
996
997 uint8_t fillAmbr(AmbrCfg **macAmbr, AmbrCfg *ueDbAmbr)
998 {
999    if(ueDbAmbr)
1000    {
1001       if(*macAmbr == NULLP)
1002       {
1003          DU_ALLOC_SHRABL_BUF(*macAmbr, sizeof(AmbrCfg));
1004          if(*macAmbr == NULLP)
1005          {
1006             DU_LOG("\nERROR  -->  DU APP : Memory Alloc Failed at fillAmbr()");
1007             return RFAILED;
1008          }
1009       }
1010       memset(*macAmbr, 0, sizeof(AmbrCfg));
1011       (*macAmbr)->ulBr = ueDbAmbr->ulBr;
1012    }
1013    else
1014    {
1015       *macAmbr = NULLP;
1016    }
1017    return ROK;
1018 }
1019
1020 /******************************************************************
1021  *
1022  * @brief Builds and Send UE ReConfig Request to MAC
1023  *
1024  * @details
1025  *
1026  *    Function : sendUeReCfgReqToMac
1027  *
1028  *    Functionality: Builds and Send UE ReConfig Request to MAC
1029  *
1030  * @Params[in]  MacUeCfg pointer
1031  * @return ROK     - success
1032  *         RFAILED - failure
1033  *
1034  * ****************************************************************/
1035
1036 uint8_t sendUeReCfgReqToMac(MacUeCfg *macUeCfg)
1037 {
1038    uint8_t ret = ROK;
1039    Pst pst;
1040    
1041    /* Fill Pst */
1042    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_RECONFIG_REQ);
1043    
1044    if(macUeCfg)
1045    {
1046       /* Processing one Ue at a time to MAC */
1047       DU_LOG("\nDEBUG   -->  DU_APP: Sending Ue Reconfig Request to MAC");
1048       ret = (*packMacUeReconfigReqOpts[pst.selector])(&pst, macUeCfg);
1049       if(ret == RFAILED)
1050       {
1051          DU_LOG("\nERROR  -->  DU APP : Failed to send Reconfig Request to MAC at sendUeReCfgReqToMac()");
1052          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macUeCfg, sizeof(MacUeCfg));
1053       }
1054    }
1055    else
1056    {
1057       DU_LOG("\nERROR  -->  DU_APP: Received macUeCfg is NULLP at sendUeReCfgReqToMac()");
1058       ret = RFAILED;
1059    }
1060    return ret;
1061 }
1062
1063 /******************************************************************
1064  *
1065  * @brief Function to return Drb LcId
1066  *
1067  * @details
1068  *
1069  *    Function : getDrbLcId
1070  *
1071  *    Functionality: Function to return Drb LcId
1072  *
1073  * Returns: lcId - SUCCESS
1074  *         RFAILED - FAILURE
1075  *****************************************************************/
1076
1077 uint8_t getDrbLcId(uint32_t *drbBitMap)
1078 {
1079    uint8_t bitMask = 1, bitPos = 0;
1080    bitPos = MIN_DRB_LCID;
1081
1082    while(bitPos <= MAX_DRB_LCID)
1083    {
1084       if((*drbBitMap & (bitMask << bitPos)) == 0)
1085       {
1086          *drbBitMap = ((bitMask << bitPos)| *drbBitMap);
1087          return bitPos;
1088       }
1089       else
1090       {
1091          bitPos++;
1092       }
1093    }
1094    DU_LOG("\nERROR   -->  DU_APP: Max LC Reached in getDrbLcId()");
1095    return RFAILED;
1096 }
1097
1098 /******************************************************************
1099  *
1100  * @brief Fills MacUeCfg structure
1101  *
1102  * @details
1103  *
1104  *    Function : fillMacUeCfg
1105  *
1106  *    Functionality: Fills MacUeCfg
1107  *
1108  * @params[in]  cellId, ueIdx, crnti, 
1109  *              DuUeCfg  pointer,
1110  *              MacUeCfg pointer
1111  * @return ROK/RFAILED
1112  *
1113  *****************************************************************/
1114 uint8_t fillMacUeCfg(uint16_t cellId, uint8_t ueIdx, uint16_t crnti, \
1115    DuUeCfg *ueCfgDb, MacUeCfg *macUeCfg)
1116 {
1117    uint8_t ret, dbIdx, lcIdx, cellIdx;
1118    bool lcIdFound = false;
1119    MacUeCfg *duMacDb = NULLP;
1120
1121    ret =ROK;
1122
1123    if(!ueCfgDb)
1124    {
1125       macUeCfg->cellId       = cellId;
1126       macUeCfg->ueIdx        = ueIdx;
1127       macUeCfg->crnti        = crnti;
1128       fillDefaultMacCellGrpInfo(&macUeCfg->macCellGrpCfg);
1129       fillDefaultPhyCellGrpInfo(&macUeCfg->phyCellGrpCfg);
1130       fillDefaultSpCellGrpInfo(&macUeCfg->spCellCfg);
1131       macUeCfg->ambrCfg = NULLP;
1132       fillMacSrb1LcCfg(&macUeCfg->lcCfgList[0]);
1133       fillDefaultModulation(macUeCfg);
1134       macUeCfg->numLcs++;
1135    }
1136    else
1137    {
1138       /* Fetching MacDb from DuUeCb */
1139       GET_CELL_IDX(cellId, cellIdx);
1140       duMacDb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg;
1141       duMacDb->macUeCfgState = UE_CFG_INPROGRESS;
1142       /* Fetching MaUeCfg List for ADD/MOD/DEL */
1143       macUeCfg->cellId       = cellId;
1144       macUeCfg->ueIdx        = ueIdx;
1145       macUeCfg->crnti        = crnti;
1146       ret = procUeReCfgCellInfo(macUeCfg, ueCfgDb->cellGrpCfg);
1147       if(ret == ROK)
1148       {
1149          if(macUeCfg->spCellCfgPres == true)
1150          {
1151             if(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschPresent)
1152             {
1153                fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc,\
1154                      &macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, NULL);
1155             }
1156             if(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschPresent)
1157             {
1158                fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
1159                      NULL, &macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg);
1160             }
1161          }
1162          ret = fillAmbr(&macUeCfg->ambrCfg, ueCfgDb->ambrCfg);
1163          duFillModulationDetails(macUeCfg, duMacDb, ueCfgDb->ueNrCapability);
1164       }
1165
1166       /* Filling LC Context */
1167       for(dbIdx = 0; (dbIdx < ueCfgDb->numMacLcs && ret == ROK); dbIdx++)
1168       {
1169          if(!ueCfgDb->macLcCfg[dbIdx].ulLcCfgPres)
1170          {
1171             /* Filling default UL LC config in MAC if not present */
1172             ueCfgDb->macLcCfg[dbIdx].ulLcCfgPres = true;
1173             fillDefaultUlLcCfg(&ueCfgDb->macLcCfg[dbIdx].ulLcCfg);
1174          }
1175          for(lcIdx = 0; lcIdx < duMacDb->numLcs; lcIdx++)
1176          {
1177             if(ueCfgDb->macLcCfg[dbIdx].lcId == duMacDb->lcCfgList[lcIdx].lcId)
1178             {
1179                lcIdFound = true;
1180                if((ueCfgDb->macLcCfg[dbIdx].configType == CONFIG_UNKNOWN) ||
1181                      (ueCfgDb->macLcCfg[dbIdx].configType == CONFIG_MOD))
1182                {
1183                   ueCfgDb->macLcCfg[dbIdx].configType = CONFIG_MOD;
1184                   ret = fillMacLcCfgToAddMod(&macUeCfg->lcCfgList[dbIdx], &ueCfgDb->macLcCfg[dbIdx]);
1185                }
1186             }
1187             else
1188                lcIdFound = false;
1189          }
1190          if(!lcIdFound)
1191          {
1192             /* ADD/DEL CONFIG */
1193             ret = fillMacLcCfgToAddMod(&macUeCfg->lcCfgList[dbIdx], &ueCfgDb->macLcCfg[dbIdx]);
1194          }
1195          if(ret == ROK)
1196          {
1197             macUeCfg->numLcs++;
1198          }
1199          else
1200          {
1201             DU_LOG("\nERROR  -->  DU APP : Failed to add Lc at Idx %d in fillMacUeCfg()", dbIdx); 
1202             break;
1203          }
1204       }/*End of Outer FOR loop */
1205    }
1206    return ret;
1207 }
1208
1209 /******************************************************************
1210  *
1211  * @brief Fills Rlc AM Information
1212  *
1213  * @details
1214  *
1215  *    Function : fillDefaultAmInfo
1216  *
1217  *    Functionality: Fills Rlc AM Information
1218  *
1219  * @params[in]  AmBearerCfg *amCfg
1220  * @return void
1221  *
1222  *****************************************************************/
1223 void fillDefaultAmInfo(AmBearerCfg *amCfg)
1224 {
1225    /* DL AM */
1226    amCfg->dlAmCfg.snLenDl     = AM_SIZE_12;
1227    amCfg->dlAmCfg.pollRetxTmr = T_POLL_RETRANSMIT_VAL;
1228    amCfg->dlAmCfg.pollPdu     = POLL_PDU_VAL;
1229    amCfg->dlAmCfg.pollByte    = POLL_BYTE_VAL;
1230    amCfg->dlAmCfg.maxRetxTh   = MAX_RETX_THRESHOLD_VAL;   
1231  
1232    /* UL AM */
1233    amCfg->ulAmCfg.snLenUl     = AM_SIZE_12;
1234    amCfg->ulAmCfg.reAssemTmr  = T_REASSEMBLY_VAL; 
1235    amCfg->ulAmCfg.statProhTmr = T_STATUS_PROHIBHIT_VAL;
1236 }
1237
1238 /******************************************************************
1239  *
1240  * @brief Fills RLC UM Bi Directional Information
1241  *
1242  * @details
1243  *
1244  *    Function : fillDefaultUmBiInfo
1245  *
1246  *    Functionality: Fills RLC UM Bi Directional Information
1247  *
1248  * @params[in]  UmBiDirBearerCfg *umBiDirCfg
1249  * @return void
1250  *
1251  *****************************************************************/
1252 void fillDefaultUmBiInfo(UmBiDirBearerCfg *umBiDirCfg)
1253 {
1254    /* UL UM BI DIR INFO */
1255    umBiDirCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1256    umBiDirCfg->ulUmCfg.reAssemTmr = T_REASSEMBLY_VAL;
1257
1258    /* DL UM BI DIR INFO */
1259    umBiDirCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
1260 }
1261
1262 /******************************************************************
1263  *
1264  * @brief Fills RLC UM Uni Directional UL Information
1265  *
1266  * @details
1267  *
1268  *    Function : fillDefaultUmUlInfo
1269  *
1270  *    Functionality: Fills RLC UM Uni Directional Info
1271  *
1272  * @params[in]  UmUniDirUlBearerCfg *UmUlCfg
1273  * @return void
1274  *
1275  *****************************************************************/
1276 void fillDefaultUmUlInfo(UmUniDirUlBearerCfg *UmUlCfg)
1277 {
1278    UmUlCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1279    UmUlCfg->ulUmCfg.reAssemTmr = T_REASSEMBLY_VAL;
1280 }
1281
1282 /******************************************************************
1283  *
1284  * @brief Fills RLC UM Uni Directional DL Information
1285  *
1286  * @details
1287  *
1288  *    Function : fillDefaultUmDlInfo
1289  *
1290  *    Functionality: Fills RLC UM Uni Directional DL Info
1291  *
1292  * @params[in]  UmUniDirDlBearerCfg *UmDlCfg
1293  * @return void
1294  *
1295  *****************************************************************/
1296 void fillDefaultUmDlInfo(UmUniDirDlBearerCfg *UmDlCfg)
1297 {
1298    UmDlCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
1299 }
1300
1301 /******************************************************************
1302  *
1303  * @brief Builds Rlc Mode Default Configuration
1304  *
1305  * @details
1306  *
1307  *    Function : fillDefaultRlcModeCfg
1308  *
1309  *    Functionality: Builds Rlc Mode Default Configuration
1310  *
1311  * @params[in]  rlcMode, RlcBearerCfg *lcCfg
1312  * @return ROK/RFAILED
1313  *
1314  *****************************************************************/
1315
1316 uint8_t fillDefaultRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *lcCfg)
1317 {
1318
1319    if(lcCfg)
1320    {
1321       switch(rlcMode)
1322       {
1323          case RLC_AM :
1324             {
1325                if(!lcCfg->u.amCfg)
1326                {
1327                  DU_ALLOC_SHRABL_BUF(lcCfg->u.amCfg, sizeof(AmBearerCfg));
1328                  if(lcCfg->u.amCfg)
1329                     fillDefaultAmInfo(lcCfg->u.amCfg);
1330                  else
1331                  {
1332                     DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at AmCfg at fillDefaultRlcModeCfg()");
1333                     return RFAILED;
1334                  }
1335                }
1336                break;
1337             }
1338          case RLC_UM_BI_DIRECTIONAL :
1339             {
1340                if(!lcCfg->u.umBiDirCfg)
1341                {
1342                  DU_ALLOC_SHRABL_BUF(lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
1343                  if(lcCfg->u.umBiDirCfg)
1344                     fillDefaultUmBiInfo(lcCfg->u.umBiDirCfg);
1345                  else
1346                  {
1347                     DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmBiDirCfg at fillDefaultRlcModeCfg()");
1348                     return RFAILED;
1349                  }
1350                }
1351                break;
1352             }
1353          case RLC_UM_UNI_DIRECTIONAL_UL :
1354             {
1355                if(!lcCfg->u.umUniDirUlCfg)
1356                {
1357                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
1358                   if(lcCfg->u.umUniDirUlCfg)
1359                     fillDefaultUmUlInfo(lcCfg->u.umUniDirUlCfg);
1360                   else
1361                   {
1362                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmUniDirUlCfg at fillDefaultRlcModeCfg()");
1363                      return RFAILED;
1364                   }
1365                }
1366                break;
1367             }
1368          case RLC_UM_UNI_DIRECTIONAL_DL :
1369             {
1370                if(!lcCfg->u.umUniDirDlCfg)
1371                {
1372                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
1373                   if(lcCfg->u.umUniDirDlCfg)
1374                    fillDefaultUmDlInfo(lcCfg->u.umUniDirDlCfg);
1375                   else
1376                   {
1377                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmUniDirDlCfg at fillDefaultRlcModeCfg()");
1378                      return RFAILED;
1379                   }
1380                }
1381                break;
1382             }
1383          default:
1384             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
1385             return RFAILED;
1386       }
1387
1388    }
1389    else
1390    {
1391       DU_LOG("\nERROR  -->  DUAPP: Received LC Config is NULL");
1392       return RFAILED;
1393    }
1394    return ROK;
1395 }
1396
1397 /*******************************************************************
1398  *
1399  * @brief Function to fill Rlc Lc Cfg for SRB1
1400  *
1401  * @details
1402  *
1403  *    Function : fillRlcSrb1LcCfg
1404  *
1405  *    Functionality: 
1406  *     Function to fill Rlc Lc Cfg for SRB1
1407  * 
1408  *  @params[in]     Pointer to RlcBearerCfg
1409  *  @return ROK/RFAILED
1410  * 
1411  *****************************************************************/
1412
1413 uint8_t fillRlcSrb1LcCfg(RlcBearerCfg *rlcLcCfg)
1414 {
1415    uint8_t ret = ROK;
1416
1417    rlcLcCfg->rbId   = SRB1_LCID;
1418    rlcLcCfg->rbType = RB_TYPE_SRB;
1419    rlcLcCfg->lcId   = SRB1_LCID;
1420    rlcLcCfg->lcType = LCH_DCCH;
1421    rlcLcCfg->rlcMode = RLC_AM;
1422    rlcLcCfg->configType = CONFIG_ADD;
1423    ret = fillDefaultRlcModeCfg(rlcLcCfg->rlcMode, rlcLcCfg);
1424    return ret;
1425 }
1426
1427 /*******************************************************************
1428  *
1429  * @brief Processes UE ReConfig Req to RLC UL
1430  *
1431  * @details
1432  *
1433  *    Function : sendUeReCfgReqToRlc
1434  *
1435  *    Functionality: 
1436  *     Processes UE Reconfig Req to RLC UL
1437  * 
1438  *  @params[in]     Pointer to RlcUeCfg
1439  *  @return ROK     - success
1440  *          RFAILED - failure
1441  * 
1442  *****************************************************************/
1443
1444 uint8_t sendUeReCfgReqToRlc(RlcUeCfg *rlcUeCfg)
1445 {
1446    uint8_t ret;
1447    Pst pst;
1448    
1449    FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_RECONFIG_REQ);
1450    if(rlcUeCfg)
1451    {
1452       /* Processing one Ue at a time to RLC */
1453       DU_LOG("\nDEBUG   -->  DU_APP: Sending Ue Reconfig Request to RLC UL");
1454       ret = (*packRlcUeReconfigReqOpts[pst.selector])(&pst, rlcUeCfg);
1455       if(ret == RFAILED)
1456       {
1457          DU_LOG("\nERROR  -->  DU_APP : Failed to send Ue Reconfig Req to RLC at sendUeReCfgReqToRlc()");
1458          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rlcUeCfg, sizeof(RlcUeCfg));
1459       }
1460    }
1461    else
1462    {
1463       DU_LOG("\nERROR  -->   DU_APP: Received RlcUeCfg is NULL at sendUeReCfgReqToRlc()");
1464       ret = RFAILED;
1465    }
1466    return ret;
1467 }
1468
1469 /******************************************************************
1470  *
1471  * @brief Fills RlcBearerCfg structure
1472  *
1473  * @details
1474  *
1475  *    Function : fillRlcUeCfg
1476  *
1477  *    Functionality: Fills Rlc Bearer Cfg
1478  *
1479  *
1480  *****************************************************************/
1481 uint8_t fillRlcUeCfg(uint16_t cellId, uint8_t ueIdx,\
1482    DuUeCfg *ueCfgDb, RlcUeCfg *rlcUeCfg)
1483 {
1484    uint8_t ret, dbIdx, lcIdx, cellIdx;
1485    bool lcIdFound = false;
1486    RlcUeCfg *duRlcDb = NULLP;
1487
1488    ret = ROK;
1489    if(!ueCfgDb)
1490    {
1491       /* Initial RB being Added */ 
1492       rlcUeCfg->cellId       = cellId;
1493       rlcUeCfg->ueIdx        = ueIdx;
1494       ret = fillRlcSrb1LcCfg(&rlcUeCfg->rlcLcCfg[0]);
1495       if(ret == ROK)
1496          rlcUeCfg->numLcs++;
1497       else
1498          memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
1499    }
1500    else
1501    {
1502       /* Fetch RlcDb from DuUeCb */ 
1503       GET_CELL_IDX(cellId, cellIdx);
1504       duRlcDb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg;
1505       duRlcDb->rlcUeCfgState = UE_CFG_INPROGRESS;
1506       /*Filling RlcUeCfg */
1507       rlcUeCfg->cellId       = cellId;
1508       rlcUeCfg->ueIdx        = ueIdx;
1509       for(dbIdx = 0; (dbIdx < ueCfgDb->numRlcLcs && ret == ROK); dbIdx++)
1510       {
1511          ret = fillDefaultRlcModeCfg(ueCfgDb->rlcLcCfg[dbIdx].rlcMode, &ueCfgDb->rlcLcCfg[dbIdx]);
1512          if(ret == RFAILED)
1513          {
1514             DU_LOG("\n ERROR  -->  DU APP : Failed to fill Rlc Mode at fillRlcUeCfg()");
1515             memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
1516             return ret;
1517          }
1518          /* Fill Rlc Ue Cfg List for ADD/MOD/DEL */
1519          for(lcIdx = 0; lcIdx < duRlcDb->numLcs; lcIdx++)
1520          { 
1521             if(ueCfgDb->rlcLcCfg[dbIdx].lcId == duRlcDb->rlcLcCfg[lcIdx].lcId)
1522             {
1523                lcIdFound = true;
1524                if((ueCfgDb->rlcLcCfg[dbIdx].configType == CONFIG_UNKNOWN)||
1525                      (ueCfgDb->rlcLcCfg[dbIdx].configType == CONFIG_MOD))
1526                {
1527                   /* MOD */ 
1528                   ueCfgDb->rlcLcCfg[dbIdx].configType = CONFIG_MOD; /* update Db for MOD type */
1529                   memcpy(&rlcUeCfg->rlcLcCfg[dbIdx], &ueCfgDb->rlcLcCfg[dbIdx], sizeof(RlcBearerCfg));
1530                }
1531             }
1532             else
1533                lcIdFound = false;
1534          }
1535          if(!lcIdFound)
1536          {
1537             /* ADD/ DEL Config Type */
1538             memcpy(&rlcUeCfg->rlcLcCfg[dbIdx], &ueCfgDb->rlcLcCfg[dbIdx], sizeof(RlcBearerCfg));
1539          }
1540          rlcUeCfg->numLcs++;
1541       }
1542    }
1543    return ret;
1544 }
1545
1546 /******************************************************************
1547  *
1548  * @brief creates UE context
1549  *
1550  * @details
1551  *
1552  *    Function : duCreateUeCb
1553  *
1554  *    Functionality: Creates UE Conetxt
1555  *
1556  * @params[in] UeCcchCtxt Pointer
1557  *             UeIdx Pointer
1558  *
1559  * @return ROK     - success
1560  *         RFAILED - failure
1561  * ****************************************************************/
1562 uint8_t duCreateUeCb(UeCcchCtxt *ueCcchCtxt, uint32_t gnbCuUeF1apId)
1563 {
1564    uint8_t cellIdx = 0;
1565    uint8_t ret     = ROK;
1566    uint8_t ueIdx;
1567
1568    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
1569    {
1570       if(ueCcchCtxt->cellId == duCb.actvCellLst[cellIdx]->cellId)
1571       {
1572          GET_UE_IDX(ueCcchCtxt->crnti, ueIdx);
1573          DU_LOG("\nDEBUG   -->  DU_APP: Filling UeCb for ueIdx [%d]", ueIdx);
1574
1575          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].f1UeDb        = NULLP;
1576          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].crnti         = ueCcchCtxt->crnti;
1577          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbDuUeF1apId = ueCcchCtxt->gnbDuUeF1apId;
1578          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbCuUeF1apId = gnbCuUeF1apId;
1579          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].drbBitMap     = NULLP;
1580          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].ueState       = UE_ACTIVE;
1581
1582          /* Filling Mac Ue Config */ 
1583          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg, 0, sizeof(MacUeCfg));
1584          ret = duBuildAndSendUeCreateReqToMac(ueCcchCtxt->cellId, ueIdx, ueCcchCtxt->crnti,\
1585                 &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg);
1586          if(ret == RFAILED)
1587             DU_LOG("\nERROR  -->  DU APP : Failed to send UE create request to MAC");
1588          
1589          /* Filling Rlc Ue Config */
1590          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg, 0, sizeof(RlcUeCfg));
1591          ret = duBuildAndSendUeCreateReqToRlc(ueCcchCtxt->cellId, ueIdx, \
1592                 &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg);
1593          if(ret == RFAILED)
1594             DU_LOG("\nERROR  -->  DU APP : Failed to send UE create request to RLC");
1595
1596          duCb.actvCellLst[cellIdx]->numActvUes++;
1597          memset(ueCcchCtxt, 0, sizeof(UeCcchCtxt));
1598       }
1599    }
1600    return ret;
1601 }
1602
1603 /******************************************************************
1604  *
1605  * @brief Builds and Send UE Create Request to MAC
1606  *
1607  * @details
1608  *
1609  *    Function : duBuildAndSendUeCreateReqToMac
1610  *
1611  *    Functionality: Builds and Send UE Create Request to MAC
1612  *
1613  * @Params[in]  cellId,
1614  *              ueIdx
1615  * @return ROK     - success
1616  *         RFAILED - failure
1617  *
1618  * ****************************************************************/
1619
1620 uint8_t duBuildAndSendUeCreateReqToMac(uint16_t cellId, uint8_t ueIdx,\
1621    uint16_t crnti, MacUeCfg *duMacUeCfg)
1622 {
1623    uint8_t  ret = ROK;
1624    MacUeCfg *macUeCfg = NULLP;
1625    Pst       pst;
1626    memset(&pst, 0, sizeof(Pst));
1627
1628
1629    ret = fillMacUeCfg(cellId, ueIdx, crnti, NULL, duMacUeCfg);
1630    if(ret == RFAILED)
1631    {
1632       DU_LOG("\nERROR  -->  DU APP : Failed to fill MacUeCfg at duBuildAndSendUeCreateReqToMac()");
1633       return RFAILED;
1634    }
1635    /* Fill Pst */
1636    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_CREATE_REQ);
1637
1638    /* Copying ueCb to a sharable buffer */
1639    DU_ALLOC_SHRABL_BUF(macUeCfg, sizeof(MacUeCfg));
1640    if(macUeCfg)
1641    {
1642       memset(macUeCfg, 0, sizeof(MacUeCfg));
1643       memcpy(macUeCfg, duMacUeCfg, sizeof(MacUeCfg));
1644       DU_LOG("\nDEBUG   -->  DU_APP: Sending UE create request to MAC");
1645
1646       /* Processing one Ue at a time to MAC */
1647       ret = (*packMacUeCreateReqOpts[pst.selector])(&pst, macUeCfg);
1648       if(ret == RFAILED)
1649       {
1650          DU_LOG("\nERROR  -->  DU_APP : Failure in sending Ue Create Req to MAC at duBuildAndSendUeCreateReqToMac()");
1651          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macUeCfg, sizeof(MacUeCfg));
1652       }
1653    }
1654    else
1655    {
1656       DU_LOG("\n ERROR  -->  DU APP : Memory alloc failed at duBuildAndSendUeCreateReqToMac()");
1657       ret = RFAILED;
1658    }
1659    return ret;
1660 }
1661
1662 /*******************************************************************
1663  *
1664  * @brief To update DuUeCb Mac Cfg
1665  *
1666  * @details
1667  *
1668  *    Function : duUpdateMacCfg
1669  *    Functionality:  update DuUeCb MAC Cfg
1670  *
1671  * @params[in] DuUeCb Pointer
1672  *             F1UeContextSetupDb pointer 
1673  * @return ROK     - success
1674  *         RFAILED - failure
1675  *
1676  * ****************************************************************/
1677 uint8_t duUpdateMacCfg(MacUeCfg *macUeCfg, F1UeContextSetupDb *f1UeDb) 
1678 {
1679    uint8_t ret, lcIdx, dbIdx, numLcs, lcDelIdx, cellIdx;
1680    MacUeCfg *oldMacUeCfg;
1681    ret = ROK;
1682
1683    /*Filling Cell Group Cfg*/
1684    ret =  procUeReCfgCellInfo(macUeCfg, f1UeDb->duUeCfg.cellGrpCfg);
1685    if(ret == ROK)
1686    {
1687       if(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschPresent)
1688       {
1689          fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc,\
1690                &macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, NULL);
1691       }
1692       if(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschPresent)
1693       {
1694          fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
1695                NULL, &macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg);
1696       }
1697       ret = fillAmbr(&macUeCfg->ambrCfg, f1UeDb->duUeCfg.ambrCfg);
1698
1699       GET_CELL_IDX(macUeCfg->cellId, cellIdx);
1700       oldMacUeCfg = &duCb.actvCellLst[cellIdx]->ueCb[macUeCfg->ueIdx-1].macUeCfg;
1701       duFillModulationDetails(macUeCfg, oldMacUeCfg, f1UeDb->duUeCfg.ueNrCapability);
1702    }
1703
1704    /* Filling LC Context */
1705    for(dbIdx = 0; (dbIdx < f1UeDb->duUeCfg.numMacLcs && ret == ROK); dbIdx++)
1706    {
1707       numLcs = macUeCfg->numLcs;
1708       for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
1709       {
1710          if(f1UeDb->duUeCfg.macLcCfg[dbIdx].lcId ==  macUeCfg->lcCfgList[lcIdx].lcId)
1711          {
1712             if(f1UeDb->duUeCfg.macLcCfg[dbIdx].configType == CONFIG_MOD)
1713             {
1714                ret = fillMacLcCfgToAddMod(&macUeCfg->lcCfgList[lcIdx],&f1UeDb->duUeCfg.macLcCfg[dbIdx]);
1715             }
1716             else if(f1UeDb->duUeCfg.macLcCfg[dbIdx].configType == CONFIG_DEL)
1717             {
1718                /* Free memory at matched  lcIdx index */
1719                freeMacLcCfg(&macUeCfg->lcCfgList[lcIdx]);
1720                macUeCfg->numLcs--;
1721                for(lcDelIdx = lcIdx; lcDelIdx < macUeCfg->numLcs; lcDelIdx++)
1722                {
1723                   /* moving all elements one index ahead */
1724                   ret = fillMacLcCfgToAddMod(&macUeCfg->lcCfgList[lcDelIdx], &macUeCfg->lcCfgList[lcDelIdx+1]);
1725                   freeMacLcCfg(&macUeCfg->lcCfgList[lcDelIdx+1]);
1726                   if(ret == RFAILED)
1727                   {
1728                      DU_LOG("\nERROR  -->  DU APP : Failed to delete LC at Idx %d in duUpdateMacCfg()", lcDelIdx);
1729                      break;
1730                   }
1731                }
1732             }
1733          }
1734       } 
1735       if(f1UeDb->duUeCfg.macLcCfg[dbIdx].configType == CONFIG_ADD)
1736       {
1737          ret = fillMacLcCfgToAddMod(&macUeCfg->lcCfgList[numLcs], &f1UeDb->duUeCfg.macLcCfg[dbIdx]);
1738          if(ret == RFAILED)
1739          {
1740             DU_LOG("\nERROR  -->  DU APP : Failed to add LC at Idx %d in duUpdateMacCfg()", numLcs);
1741             break;
1742          }
1743          macUeCfg->numLcs++;
1744       }
1745                 
1746    }
1747    return ret;
1748 }
1749
1750 /******************************************************************
1751  *
1752  * @brief Function to fill the RLC Lc cfg from ueSetupReqDb
1753  *
1754  * @details
1755  *
1756  *    Function : fillRlcCfgToAddMod
1757  *
1758  *    Functionality: Function to fill the RLC Lc cfg from ueSetupReqDb
1759  *
1760  *
1761  *****************************************************************/
1762
1763 uint8_t fillRlcCfgToAddMod(RlcBearerCfg *lcCfg, RlcBearerCfg *f1UeDbLcCfg)
1764 {
1765    lcCfg->configType = f1UeDbLcCfg->configType;
1766    lcCfg->rbId       = f1UeDbLcCfg->rbId;
1767    lcCfg->rbType     = f1UeDbLcCfg->rbType;
1768    lcCfg->lcId       = f1UeDbLcCfg->lcId;
1769    lcCfg->lcType     = f1UeDbLcCfg->lcType;
1770    lcCfg->rlcMode    = f1UeDbLcCfg->rlcMode;
1771    switch(lcCfg->rlcMode)
1772    {
1773       case RLC_AM :
1774       {
1775          if(!lcCfg->u.amCfg)
1776          {
1777             DU_ALLOC_SHRABL_BUF(lcCfg->u.amCfg, sizeof(AmBearerCfg));
1778             if(!lcCfg->u.amCfg)
1779                return RFAILED;
1780          }
1781          /* DL AM */
1782          lcCfg->u.amCfg->dlAmCfg.snLenDl     = f1UeDbLcCfg->u.amCfg->dlAmCfg.snLenDl;    
1783          lcCfg->u.amCfg->dlAmCfg.pollRetxTmr = f1UeDbLcCfg->u.amCfg->dlAmCfg.pollRetxTmr;
1784          lcCfg->u.amCfg->dlAmCfg.pollPdu     = f1UeDbLcCfg->u.amCfg->dlAmCfg.pollPdu;
1785          lcCfg->u.amCfg->dlAmCfg.pollByte    = f1UeDbLcCfg->u.amCfg->dlAmCfg.pollByte;   
1786          lcCfg->u.amCfg->dlAmCfg.maxRetxTh   = f1UeDbLcCfg->u.amCfg->dlAmCfg.maxRetxTh;   
1787  
1788          /* UL AM */
1789          lcCfg->u.amCfg->ulAmCfg.snLenUl     = f1UeDbLcCfg->u.amCfg->ulAmCfg.snLenUl;
1790          lcCfg->u.amCfg->ulAmCfg.reAssemTmr  = f1UeDbLcCfg->u.amCfg->ulAmCfg.reAssemTmr; 
1791          lcCfg->u.amCfg->ulAmCfg.statProhTmr = f1UeDbLcCfg->u.amCfg->ulAmCfg.statProhTmr;
1792          break;
1793       }
1794       case RLC_UM_BI_DIRECTIONAL :
1795       {
1796          if(!lcCfg->u.umBiDirCfg)
1797          {
1798             DU_ALLOC_SHRABL_BUF(lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
1799             if(!lcCfg->u.umBiDirCfg)
1800                 return RFAILED;
1801          }
1802          /* UL UM BI DIR INFO */
1803          lcCfg->u.umBiDirCfg->ulUmCfg.snLenUlUm  = f1UeDbLcCfg->u.umBiDirCfg->ulUmCfg.snLenUlUm;  
1804          lcCfg->u.umBiDirCfg->ulUmCfg.reAssemTmr = f1UeDbLcCfg->u.umBiDirCfg->ulUmCfg.reAssemTmr;
1805          /* DL UM BI DIR INFO */
1806          lcCfg->u.umBiDirCfg->dlUmCfg.snLenDlUm  = f1UeDbLcCfg->u.umBiDirCfg->dlUmCfg.snLenDlUm;
1807          break;
1808       }
1809       case RLC_UM_UNI_DIRECTIONAL_UL :
1810       {
1811          if(!lcCfg->u.umUniDirUlCfg)
1812          {
1813             DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
1814             if(!lcCfg->u.umUniDirUlCfg)
1815                return RFAILED;
1816          }
1817          lcCfg->u.umUniDirUlCfg->ulUmCfg.snLenUlUm  = f1UeDbLcCfg->u.umUniDirUlCfg->ulUmCfg.snLenUlUm;  
1818          lcCfg->u.umUniDirUlCfg->ulUmCfg.reAssemTmr = f1UeDbLcCfg->u.umUniDirUlCfg->ulUmCfg.reAssemTmr;
1819          break;
1820
1821       }
1822       case RLC_UM_UNI_DIRECTIONAL_DL :
1823       {
1824          if(!lcCfg->u.umUniDirDlCfg)
1825          {
1826             DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
1827             if(!lcCfg->u.umUniDirDlCfg)
1828                return RFAILED;
1829          }
1830          lcCfg->u.umUniDirDlCfg->dlUmCfg.snLenDlUm  = f1UeDbLcCfg->u.umUniDirDlCfg->dlUmCfg.snLenDlUm;
1831          break;
1832       }
1833       default:
1834          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at fillRlcCfgToAddMod()", lcCfg->rlcMode);
1835          return RFAILED;
1836    }
1837    return ROK;
1838 }
1839
1840 /*******************************************************************
1841  *
1842  * @brief To update DuUeCb Rlc Lc Cfg
1843  *
1844  * @details
1845  *
1846  *    Function : duUpdateRlcLcCfg
1847  *    Functionality:  update DuUeCb Rlc Lc Cfg
1848  *
1849  * @params[in] DuUeCb Pointer
1850  *             F1UeContextSetupDb pointer 
1851  * @return ROK     - success
1852  *         RFAILED - failure
1853  *
1854  * ****************************************************************/
1855
1856 uint8_t duUpdateRlcLcCfg(RlcUeCfg *rlcUeCfg, F1UeContextSetupDb *f1UeDb)
1857 {
1858    uint8_t ret, lcIdx, dbIdx, numLcs, lcDelIdx;
1859
1860    ret = ROK;
1861    for(dbIdx = 0; (dbIdx < f1UeDb->duUeCfg.numRlcLcs && ret ==ROK); dbIdx++)
1862    {
1863       numLcs = rlcUeCfg->numLcs;
1864       for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
1865       {
1866          if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].lcId == rlcUeCfg->rlcLcCfg[lcIdx].lcId)
1867          {
1868             if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].configType == CONFIG_MOD)
1869             {
1870                ret = fillRlcCfgToAddMod(&rlcUeCfg->rlcLcCfg[lcIdx], &f1UeDb->duUeCfg.rlcLcCfg[dbIdx]);
1871             }
1872             else if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].configType == CONFIG_DEL)
1873             {
1874                /* Free memory at matched lcIdx index */
1875                freeRlcLcCfg(&rlcUeCfg->rlcLcCfg[lcIdx]);
1876                rlcUeCfg->numLcs--;
1877                for(lcDelIdx = lcIdx; lcDelIdx < rlcUeCfg->numLcs; lcDelIdx++)
1878                {
1879                   ret = fillRlcCfgToAddMod(&rlcUeCfg->rlcLcCfg[lcDelIdx], &rlcUeCfg->rlcLcCfg[lcDelIdx+1]);
1880                   freeRlcLcCfg(&rlcUeCfg->rlcLcCfg[lcDelIdx+1]);
1881                   if(ret == RFAILED)
1882                   {
1883                      DU_LOG("\nERROR  -->  DU APP : Failed to delete LC at Idx %d in duUpdateRlcCfg()", lcDelIdx);
1884                      break;
1885                   }
1886                }
1887             }
1888          }
1889       }
1890       if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].configType == CONFIG_ADD)
1891       {
1892          ret = fillRlcCfgToAddMod(&rlcUeCfg->rlcLcCfg[lcIdx], &f1UeDb->duUeCfg.rlcLcCfg[dbIdx]);
1893          if(ret == ROK)
1894             rlcUeCfg->numLcs++;
1895       }
1896    }
1897    return ret;
1898 }
1899
1900
1901 /*******************************************************************
1902  *
1903  * @brief Function to fill Tunnel Config to Add/Mod
1904  * 
1905  *
1906  * @details
1907  *
1908  *    Function : fillTnlCfgToAddMod
1909  *
1910  *    Functionality: Function to fill tunnel Config to Add/Mod
1911  *
1912  * @params[in] Pointer to tnlCfgDb,
1913  *             pointer to f1TnlCfg
1914  * @return ROK     - success
1915  *         RFAILED - failure
1916  *
1917  * ****************************************************************/
1918 uint8_t fillTnlCfgToAddMod(UpTnlCfg **ueCbTnlCfg, UpTnlCfg *f1TnlCfg)
1919 {
1920    if(*ueCbTnlCfg == NULLP)
1921    {
1922       /* copying to DuCb Tnl Cfg */
1923       DU_ALLOC(*ueCbTnlCfg, sizeof(UpTnlCfg));
1924       if(*ueCbTnlCfg == NULLP)
1925       {
1926          DU_LOG("\nERROR  -->  DU_APP : fillTnlCfgToAddMod: Memory Alloc failed for drbId[%d]", f1TnlCfg->drbId);
1927          return RFAILED;
1928       }
1929    }
1930    memset(*ueCbTnlCfg, 0, sizeof(UpTnlCfg));
1931    (*ueCbTnlCfg)->configType = f1TnlCfg->configType;
1932    (*ueCbTnlCfg)->cellId    = f1TnlCfg->cellId;
1933    (*ueCbTnlCfg)->ueIdx     = f1TnlCfg->ueIdx;
1934    (*ueCbTnlCfg)->drbId     = f1TnlCfg->drbId;
1935    if(f1TnlCfg->tnlCfg1)
1936    {
1937       if((*ueCbTnlCfg)->tnlCfg1 == NULLP)
1938       {
1939          DU_ALLOC((*ueCbTnlCfg)->tnlCfg1, sizeof(GtpTnlCfg));
1940          if((*ueCbTnlCfg)->tnlCfg1 == NULLP)
1941          {
1942             DU_LOG("\nERROR  -->  DU_APP : fillTnlCfgToAddMod: Memory Alloc failed for tnlCfg1 for drbId[%d]", f1TnlCfg->drbId);
1943             return RFAILED;
1944          }
1945       }
1946       memset((*ueCbTnlCfg)->tnlCfg1, 0, sizeof(GtpTnlCfg));
1947       (*ueCbTnlCfg)->tnlCfg1->teId = f1TnlCfg->tnlCfg1->teId;
1948       (*ueCbTnlCfg)->tnlCfg1->ulTnlAddress = f1TnlCfg->tnlCfg1->ulTnlAddress;
1949       (*ueCbTnlCfg)->tnlCfg1->dlTnlAddress = f1TnlCfg->tnlCfg1->dlTnlAddress;
1950    }
1951    return ROK;
1952 }
1953
1954 /*******************************************************************
1955  *
1956  * @brief Processing the tunnel Request to EGTP
1957  *        
1958  * @details
1959  *
1960  *    Function : duProcEgtpTunnelCfg
1961  *
1962  *    Functionality: Processing the tunnel Request to EGTP
1963  *
1964  * @params[in] UptnlCfg *duTnlCfg, UpTnlCfg *f1TnlCfg 
1965  * @return ROK     - success
1966  *         RFAILED - failure
1967  *
1968  * ****************************************************************/
1969
1970 uint8_t duProcEgtpTunnelCfg(uint8_t ueCbIdx, UpTnlCfg *duTnlCfg, UpTnlCfg *f1TnlCfg)
1971 {
1972    uint8_t ret = RFAILED, delIdx;
1973
1974    if(f1TnlCfg->tnlCfg1 == NULLP)
1975    {
1976       DU_LOG("\nERROR  -->  DU_APP : Tunnel config not found");
1977       return ret;
1978    }
1979
1980    if(f1TnlCfg->configType == CONFIG_ADD)
1981    {
1982       if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_ADD, NULLP, f1TnlCfg->tnlCfg1) == ROK)
1983       {
1984          if(fillTnlCfgToAddMod(&duCb.upTnlCfg[duCb.numDrb], f1TnlCfg) == ROK)
1985          {
1986             duCb.numDrb++;
1987             ret = ROK;
1988          }
1989       }      
1990    }
1991    else if(f1TnlCfg->configType == CONFIG_MOD)
1992    {
1993       if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_MOD, duTnlCfg->tnlCfg1->teId, f1TnlCfg->tnlCfg1) == ROK)
1994       {
1995          if(fillTnlCfgToAddMod(&duTnlCfg, f1TnlCfg) == ROK)
1996          {
1997             ret = ROK;
1998          }
1999       }   
2000    }
2001    else if(f1TnlCfg->configType == CONFIG_DEL)
2002    {
2003       if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_DEL, duTnlCfg->tnlCfg1->teId, f1TnlCfg->tnlCfg1) == ROK)
2004       {    
2005          /* Free memory at drbIdx */
2006          DU_FREE(duTnlCfg->tnlCfg1, sizeof(GtpTnlCfg));
2007          DU_FREE(duTnlCfg, sizeof(UpTnlCfg));
2008          duCb.numDrb--;
2009          for(delIdx = ueCbIdx; delIdx < duCb.numDrb; delIdx++)
2010          {
2011             /* moving all elements one index ahead */
2012             ret = fillTnlCfgToAddMod(&duCb.upTnlCfg[delIdx], duCb.upTnlCfg[delIdx+1]);
2013             if(ret != ROK)
2014             {
2015                return ret;
2016             }
2017          }
2018       }   
2019    }
2020    return ret;
2021 }
2022
2023 /***********************************************************************
2024  *
2025  * @brief Function to fill Tunnel Config
2026  *        and sends tunnel Req to EGTP
2027  * 
2028  *
2029  * @details
2030  *
2031  *    Function : duUpdateTunnelCfgDb
2032  *
2033  *    Functionality: Function to fill tunnel Config
2034  *                   and sends tunnel Cfg Req to EGTP
2035  *
2036  * @params[in] ueIdx, cellId, DuUeCfg 
2037  * @return ROK     - success
2038  *         RFAILED - failure
2039  *
2040  * ****************************************************************/
2041
2042 uint8_t duUpdateTunnelCfgDb(uint8_t ueIdx, uint8_t cellId, DuUeCfg *duUeCfg)
2043 {
2044    uint8_t ret = ROK, drbIdx, duCbDrbIdx;
2045    bool drbFound = false;
2046
2047    /*If Add/Mod tunnels request for that DRB is successful in EGTP */
2048    /*then update drbId and tunnel Info in duCb */
2049    for(drbIdx=0; drbIdx < duUeCfg->numDrb; drbIdx++)
2050    {
2051       duUeCfg->upTnlInfo[drbIdx].cellId = cellId;
2052       duUeCfg->upTnlInfo[drbIdx].ueIdx = ueIdx;
2053       for(duCbDrbIdx = 0; duCbDrbIdx < duCb.numDrb; duCbDrbIdx++)
2054       {
2055          if(duCb.upTnlCfg[duCbDrbIdx]->drbId == duUeCfg->upTnlInfo[drbIdx].drbId)
2056          {
2057             drbFound = true; /* existing DRB */
2058             if(duProcEgtpTunnelCfg(duCbDrbIdx, duCb.upTnlCfg[duCbDrbIdx], &duUeCfg->upTnlInfo[drbIdx]) != ROK)
2059             {
2060                DU_LOG("\nERROR  -> DU_APP : duUpdateTunnelCfgDb: Failed to modify tunnel req for Drb id[%d]",
2061                duUeCfg->upTnlInfo[drbIdx].drbId);
2062                ret = RFAILED;
2063             }
2064             break;
2065          }
2066          else
2067             drbFound = false;
2068       }
2069       if(!drbFound && ret == ROK)/* new DRB to Add */
2070       {
2071          if(duProcEgtpTunnelCfg(NULLP, NULLP, &duUeCfg->upTnlInfo[drbIdx]) != ROK)
2072          {
2073             DU_LOG("\nERROR  -> DU_APP : duUpdateTunnelCfgDb: Failed to add tunnel req for Drb id[%d]",
2074             duUeCfg->upTnlInfo[drbIdx].drbId);
2075             ret = RFAILED;
2076             break;
2077          }
2078       }
2079       else
2080          break;
2081    }
2082    return ret;
2083 }
2084
2085 /*******************************************************************
2086  *
2087  * @brief @brief To update DuUeCb Mac and Rlc Ue Cfg
2088  * 
2089  *
2090  * @details
2091  *
2092  *    Function : duUpdateDuUeCbCfg
2093  *
2094  *    Functionality: update DuUeCb Mac and Rlc Ue Cfg
2095  *
2096  * @params[in] ueIdx, cellIdx 
2097  * @return ROK     - success
2098  *         RFAILED - failure
2099  *
2100  * ****************************************************************/
2101
2102 uint8_t duUpdateDuUeCbCfg(uint8_t ueIdx, uint8_t cellId)
2103 {
2104    uint8_t ret = ROK, cellIdx = 0, crnti=0;
2105    DuUeCb *ueCb = NULLP;
2106
2107    GET_CELL_IDX(cellId, cellIdx);
2108    
2109    if((duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg. \
2110          macUeCfgState == UE_RECFG_COMPLETE) &&
2111       (duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg. \
2112          rlcUeCfgState == UE_RECFG_COMPLETE))
2113    {
2114       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1];
2115
2116       /*Filling RLC Ue Cfg */
2117       ueCb->rlcUeCfg.cellId = cellId;
2118       ueCb->rlcUeCfg.ueIdx  = ueIdx;
2119       ret = duUpdateRlcLcCfg(&ueCb->rlcUeCfg, ueCb->f1UeDb);
2120       if(ret == ROK)
2121       {
2122          /*Filling MAC Ue Cfg */
2123          GET_CRNTI(crnti, ueIdx);
2124          ueCb->macUeCfg.cellId = cellId;
2125          ueCb->macUeCfg.ueIdx  = ueIdx;
2126          ueCb->macUeCfg.crnti  = crnti;
2127          ret = duUpdateMacCfg(&ueCb->macUeCfg, ueCb->f1UeDb);
2128          if(ret == RFAILED)
2129             DU_LOG("\nERROR  -->  DU APP : Failed while updating MAC LC Config at duUpdateDuUeCbCfg()");
2130          else
2131          {
2132             if(duUpdateTunnelCfgDb(ueIdx, cellId, &ueCb->f1UeDb->duUeCfg) != ROK)
2133             {
2134                DU_LOG("\nERROR  -->  DU_APP : Failed to establish tunnel in duUpdateDuUeCbCfg()");
2135                return RFAILED;
2136             }
2137          }
2138       }
2139       else
2140          DU_LOG("\nERROR  -->  DU APP : Failed while updating RLC LC Config at duUpdateDuUeCbCfg()");
2141    }
2142    else
2143       ret = RFAILED;
2144    return ret;
2145 }
2146
2147 /*******************************************************************
2148  *
2149  * @brief Handle UE config response from MAC
2150  *
2151  * @details
2152  *
2153  *    Function : DuProcMacUeCfgRsp
2154  *
2155  *    Functionality: Handle UE Config response from MAC
2156  *
2157  * @params[in] Pointer to MacUeCfgRsp and Pst 
2158  * @return ROK     - success
2159  *         RFAILED - failure
2160  *
2161  * ****************************************************************/
2162 uint8_t DuProcMacUeCfgRsp(Pst *pst, MacUeCfgRsp *cfgRsp)
2163 {
2164    uint8_t ret = ROK;
2165
2166    if(cfgRsp)
2167    {
2168       if(cfgRsp->result == MAC_DU_APP_RSP_OK)
2169       {
2170          if(pst->event == EVENT_MAC_UE_CREATE_RSP)
2171          {
2172             DU_LOG("\nINFO   -->  DU APP : MAC UE Create Response : SUCCESS [UE IDX : %d]", cfgRsp->ueIdx);
2173             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueIdx -1].\
2174                macUeCfg.macUeCfgState = UE_CREATE_COMPLETE;
2175          }
2176          else if(pst->event == EVENT_MAC_UE_RECONFIG_RSP)
2177          {
2178             DU_LOG("\nINFO   -->  DU APP : MAC UE Reconfig Response : SUCCESS [UE IDX : %d]", cfgRsp->ueIdx);
2179             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueIdx -1].\
2180                macUeCfg.macUeCfgState = UE_RECFG_COMPLETE;
2181             if((ret = duUpdateDuUeCbCfg(cfgRsp->ueIdx, cfgRsp->cellId)) == ROK)
2182             {
2183                BuildAndSendUeCtxtRsp(cfgRsp->ueIdx, cfgRsp->cellId);
2184             }
2185          }
2186       }
2187       else
2188       {
2189          DU_LOG("\nERROR  -->  DU APP : MAC UE CFG Response for EVENT[%d]: FAILURE [UE IDX : %d]", pst->event, cfgRsp->ueIdx);
2190          if(pst->event == EVENT_MAC_UE_RECONFIG_RSP)
2191          {
2192             //TODO: Send the failure case in Ue Context Setup Response
2193          }
2194          ret = RFAILED;
2195       }
2196       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(MacUeCfgRsp));
2197    }
2198    else
2199    {
2200       DU_LOG("\nERROR  -->  DU APP : Received MAC Ue Config Response is NULL at DuProcMacUeCfgRsp()");
2201       ret = RFAILED;
2202    }
2203    return ret;
2204 }
2205
2206
2207 /*******************************************************************
2208  *
2209  * @brief Processes UE create Req to RLC UL
2210  *
2211  * @details
2212  *
2213  *    Function : duBuildAndSendUeCreateReqToRlc
2214  *
2215  *    Functionality: 
2216  *     Processes UE create Req to RLC UL
2217  * 
2218  *  @params[in]  cellId,
2219  *               ueIdx,
2220  *               Pointer to RlcUeCfg
2221  *  @return ROK     - success
2222  *          RFAILED - failure
2223  * 
2224  *****************************************************************/
2225
2226 uint8_t duBuildAndSendUeCreateReqToRlc(uint16_t cellId, uint8_t ueIdx,\
2227    RlcUeCfg *duRlcUeCfg)
2228 {
2229    uint8_t  ret = ROK;
2230    RlcUeCfg *rlcUeCfg = NULLP;
2231    Pst       pst;
2232   
2233    ret = fillRlcUeCfg(cellId, ueIdx, NULL, duRlcUeCfg);
2234    if(ret == RFAILED)
2235    {
2236       DU_LOG("\nERROR  -->  DU APP : Failed to fill Rlc Ue Cfg at duBuildAndSendUeCreateReqToRlc()");
2237       return ret;
2238    }
2239
2240    FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_CREATE_REQ);
2241    /* Copying ueCfg to a sharable buffer */
2242    DU_ALLOC_SHRABL_BUF(rlcUeCfg, sizeof(RlcUeCfg));
2243    if(rlcUeCfg)
2244    {
2245       memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
2246       memcpy(rlcUeCfg, duRlcUeCfg, sizeof(RlcUeCfg));
2247       /* Processing one Ue at a time to RLC */
2248       DU_LOG("\nDEBUG   -->  DU_APP: Sending UE create request to RLC UL");
2249       ret = (*packRlcUeCreateReqOpts[pst.selector])(&pst, rlcUeCfg);
2250       if(ret == RFAILED)
2251       {
2252          DU_LOG("\nERROR  -->  DU_APP : Failure in sending Ue Create Req to RLC");
2253          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rlcUeCfg, sizeof(RlcUeCfg));
2254          ret = RFAILED;
2255       }
2256    }
2257    else
2258    {
2259       DU_LOG("\n ERROR  -->  DU APP : Memory alloc failed at duBuildAndSendUeCreateReqToRlc()");
2260       ret = RFAILED;
2261    }
2262    return ret;
2263 }
2264
2265 /*******************************************************************
2266  *
2267  * @brief Processes UE create Rsp received from RLC UL
2268  *
2269  * @details
2270  *
2271  
2272  *    Function : DuProcRlcUeCfgRsp
2273  *
2274  *    Functionality: 
2275  *     Processes UE create Rsp received from RLC UL
2276  * 
2277  *  @params[in]  Post structure
2278  *               Pointer to RlcCfgCfm
2279  *  @return ROK     - success
2280  *          RFAILED - failure
2281  * 
2282  *****************************************************************/
2283 uint8_t DuProcRlcUeCfgRsp(Pst *pst, RlcUeCfgRsp *cfgRsp)
2284 {
2285    uint8_t ret = ROK;
2286
2287    if(cfgRsp)
2288    {
2289       if(cfgRsp->result == RLC_DU_APP_RSP_OK)
2290       {
2291          if(pst->event == EVENT_RLC_UE_CREATE_RSP)
2292          {
2293             DU_LOG("\nINFO   -->  DU_APP: RLC UE Create Response : SUCCESS [UE IDX:%d]", cfgRsp->ueIdx);
2294             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueIdx -1].\
2295                rlcUeCfg.rlcUeCfgState = UE_CREATE_COMPLETE;
2296          }
2297          else if(pst->event == EVENT_RLC_UE_RECONFIG_RSP)
2298          {
2299             DU_LOG("\nINFO   -->  DU_APP: RLC UE Reconfig Response : SUCCESS [UE IDX:%d]", cfgRsp->ueIdx);
2300             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueIdx -1].\
2301                rlcUeCfg.rlcUeCfgState = UE_RECFG_COMPLETE;
2302             if((ret = duUpdateDuUeCbCfg(cfgRsp->ueIdx, cfgRsp->cellId)) == ROK)
2303             {
2304                BuildAndSendUeCtxtRsp(cfgRsp->ueIdx, cfgRsp->cellId);
2305             }   
2306          }
2307       }
2308       else
2309       {
2310          DU_LOG("\nERROR  -->  DU_APP: RLC UE CFG Response for EVENT[%d] : FAILED [UE IDX : %d, REASON :%d]",\
2311                pst->event, cfgRsp->ueIdx, cfgRsp->reason);
2312          if((pst->event == EVENT_RLC_UE_RECONFIG_RSP))
2313          {
2314             //TODO: update failure case in ue Context setup Response
2315          }
2316          ret = RFAILED;
2317       }
2318       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(RlcUeCfgRsp));
2319    }
2320    else
2321    {
2322       DU_LOG("\nERROR  -->  DU_APP: Received RLC Ue Config Response is NULL at DuProcRlcUeCfgRsp()");
2323       ret = RFAILED;
2324    }
2325    return ret;
2326 }
2327
2328 /*******************************************************************
2329  *
2330  * @brief Builds and Send Ue Reconfig Req to RLC
2331  *
2332  * @details
2333  *
2334  *    Function : duBuildAndSendUeReCfgReqToRLC
2335  *
2336  *    Functionality: Builds and Send Ue Reconfig Req to RLC
2337  *
2338  * @params[in] cellId, crnti
2339  *             DuUeCfg *ueCfgDb
2340  *             RlcUeCfg *rlcUeCfg
2341  * @return ROK     - success
2342  *         RFAILED - failure
2343  *
2344  * ****************************************************************/
2345
2346 uint8_t duBuildAndSendUeReCfgReqToRlc(uint8_t cellId, uint8_t crnti, DuUeCfg *ueCfgDb)
2347 {
2348    uint8_t ret = ROK, ueIdx = 0;
2349    RlcUeCfg *rlcUeCfg = NULLP;
2350
2351    GET_UE_IDX(crnti, ueIdx);
2352    DU_ALLOC_SHRABL_BUF(rlcUeCfg, sizeof(RlcUeCfg));
2353    if(rlcUeCfg)
2354    {
2355       memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
2356       ret = fillRlcUeCfg(cellId, ueIdx, ueCfgDb, rlcUeCfg);
2357       if(ret == RFAILED)
2358          DU_LOG("\nERROR  -->  DU APP : Failed at duBuildAndSendUeReCfgReqToRlc()");
2359       else
2360          ret = sendUeReCfgReqToRlc(rlcUeCfg);
2361    }
2362    else
2363    {
2364       DU_LOG("\nERROR  -->  DU APP : Memory Alloc failed at duBuildAndSendUeReCfgReqToRlc()");
2365       ret = RFAILED;
2366    }
2367    return ret;
2368 }
2369
2370 /*******************************************************************
2371  *
2372  * @brief Builds and Send Ue Reconfig Req to MAC
2373  *
2374  * @details
2375  *
2376  *    Function : duBuildAndSendUeReCfgReqToMac
2377  *
2378  *    Functionality: Builds and Send Ue Reconfig Req to MAC
2379  *
2380  * @params[in] CellGroupConfigRrc_t *macCellGrpCfg
2381  *             DuUeCfg *ueCfgDb
2382  *             MacUeCfg    *macUeCfg
2383  * @return ROK     - success
2384  *         RFAILED - failure
2385  *
2386  * ****************************************************************/
2387
2388 uint8_t duBuildAndSendUeReCfgReqToMac(uint8_t cellId, uint8_t crnti, DuUeCfg *ueCfgDb)
2389 {
2390    uint8_t ret, ueIdx = 0;
2391    MacUeCfg *macUeCfg = NULLP;
2392
2393    ret = ROK;
2394    GET_UE_IDX(crnti, ueIdx);
2395
2396    DU_ALLOC_SHRABL_BUF(macUeCfg, sizeof(MacUeCfg));
2397    if(macUeCfg)
2398    {
2399       memset(macUeCfg, 0, sizeof(MacUeCfg));
2400       ret = fillMacUeCfg(cellId, ueIdx, crnti, ueCfgDb, macUeCfg);
2401       if(ret == RFAILED)
2402          DU_LOG("\nERROR  -->  DU APP : Failed to fill Mac Ue Cfg at duBuildAndSendUeReCfgReqToMac()");
2403       else
2404          ret = sendUeReCfgReqToMac(macUeCfg);
2405    }
2406    else
2407    {
2408       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed for macUeCfg at duBuildAndSendUeReCfgReqToMac()");
2409       ret = RFAILED;
2410    }
2411    return ret;
2412 }
2413
2414 /*******************************************************************
2415  *
2416  * @brief Build and Send Ue context setup request
2417  *
2418  * @details
2419  *
2420  
2421  *    Function : duBuildAndSendUeContextSetupReq
2422  *
2423  *    Functionality: 
2424  *     Build and Send Ue context setup request
2425  * 
2426  *  @params[in]  cellId, crnti, DuUeCfg pointer
2427  *  @return ROK     - success
2428  *          RFAILED - failure
2429  * 
2430  *****************************************************************/
2431
2432 uint8_t duBuildAndSendUeContextSetupReq(uint16_t cellId, uint16_t crnti, DuUeCfg *duUeCfg)
2433 {
2434    uint8_t ret = ROK;
2435
2436    DU_LOG("\nDEBUG   -->  DU_APP: Processing Ue Context Setup Request for cellId [%d]", cellId);
2437    /* Filling RLC Ue Reconfig */ 
2438    ret = duBuildAndSendUeReCfgReqToRlc(cellId, crnti, duUeCfg);
2439    if(ret == RFAILED)
2440       DU_LOG("\nERROR  -->  DU APP : Failed to build ctxt setup req for RLC at duBuildAndSendUeContextSetupReq()");
2441    
2442    /* Filling MAC Ue Reconfig */
2443    ret = duBuildAndSendUeReCfgReqToMac(cellId, crnti, duUeCfg);
2444    if(ret == RFAILED)
2445       DU_LOG("\nERROR  -->  DU APP : Failed at build ctxt setup req for MAC at duBuildAndSendUeContextSetupReq()");
2446
2447    return ret;
2448 }
2449
2450 /*******************************************************************
2451  *
2452  * @brief Processes DL Rsp received from RLC DL
2453  *
2454  * @details
2455  *
2456  
2457  *    Function : DuProcRlcDlRrcMsgRsp
2458  *
2459  *    Functionality: 
2460  *     Processes UE Rsp received from RLC DL
2461  * 
2462  *  @params[in]  Post structure
2463  *               Pointer to RlcCfgCfm
2464  *  @return ROK     - success
2465  *          RFAILED - failure
2466  * 
2467  *****************************************************************/
2468 uint8_t DuProcRlcDlRrcMsgRsp(Pst *pst, RlcDlRrcMsgRsp *dlRrcMsg)
2469 {
2470    uint8_t ret = ROK, ueIdx = 0;
2471    DuUeCb *ueCb = NULLP;
2472
2473    if(dlRrcMsg->state == TRANSMISSION_COMPLETE)
2474    {
2475       GET_UE_IDX(dlRrcMsg->crnti, ueIdx);
2476       ueCb = &duCb.actvCellLst[dlRrcMsg->cellId -1]->ueCb[ueIdx -1];
2477       if(ueCb->f1UeDb && ueCb->f1UeDb->dlRrcMsgPres)
2478       {
2479          if(ueCb->f1UeDb->actionType == UE_CTXT_SETUP)
2480          {
2481             ret = duBuildAndSendUeContextSetupReq(dlRrcMsg->cellId, dlRrcMsg->crnti, &ueCb->f1UeDb->duUeCfg);
2482             if(ret == RFAILED)
2483                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Setup Request in DuProcRlcDlRrcMsgRsp()");
2484          }
2485          if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
2486          {
2487             ret = duBuildAndSendUeContextModReq(dlRrcMsg->cellId, dlRrcMsg->crnti, &ueCb->f1UeDb->duUeCfg);
2488             if(ret == RFAILED)
2489                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Mod Request in DuProcRlcDlRrcMsgRsp()");
2490          }
2491       }
2492    }
2493    else
2494       DU_LOG("\nERROR  -->  DU APP : Failed to transmit DL RRC Msg");
2495
2496    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlRrcMsg, sizeof(RlcDlRrcMsgRsp));
2497    return ret;
2498 }
2499 /*******************************************************************
2500  *
2501  * @brief Process UE context setup request from CU
2502  *
2503  * @details
2504  *
2505  *    Function : duProcUeContextSetupRequest 
2506  *
2507  *    Functionality: Process UE context setup request from CU
2508  *
2509  * @params[in] F1AP message
2510  * @return ROK     - success
2511  *         RFAILED - failure
2512  *
2513  * ****************************************************************/
2514
2515 uint8_t duProcUeContextSetupRequest(DuUeCb *ueCb)
2516 {
2517    uint8_t ret, cellId;
2518
2519    ret = ROK;
2520    if(ueCb)
2521    {
2522       cellId = duCb.actvCellLst[ueCb->f1UeDb->cellIdx]->cellId;
2523       /* Send DL RRC msg for security Mode */
2524       if(ueCb->f1UeDb->dlRrcMsg)
2525       {
2526          if(ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
2527          {
2528             /* Sending DL RRC Message to RLC */
2529             ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->rlcUeCfg, ueCb->f1UeDb->dlRrcMsg);
2530             if(ret == RFAILED)
2531             {
2532                DU_LOG("\nERROR  -->  DU APP : Failed to send DL RRC msg in duProcUeContextSetupRequest()");
2533                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
2534                      ueCb->f1UeDb->dlRrcMsg->rrcMsgSize);
2535                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
2536             }
2537          }
2538       }
2539       else if(ueCb->f1UeDb->actionType == UE_CTXT_SETUP)
2540       {
2541          ret = duBuildAndSendUeContextSetupReq(cellId, ueCb->crnti, &ueCb->f1UeDb->duUeCfg);
2542          if(ret == RFAILED)
2543          {
2544             DU_LOG("\nERROR  -->  DU APP : Failed to build ue context setup Req in duProcUeContextSetupRequest()");
2545          }
2546       }
2547    }
2548    else
2549    {
2550       //TODO: To send the failure cause in UeContextSetupRsp
2551       DU_LOG("ERROR  -->  DU APP : Failed to process UE CNTXT SETUP REQ at duProcUeContextSetupRequest()");
2552    }
2553    return ret;
2554 }
2555
2556 /*******************************************************************
2557  *
2558  * @brief Build and Send Ue context mod request
2559  *
2560  * @details
2561  *
2562  *
2563  *    Function : duBuildAndSendUeContextModReq
2564  *
2565  *    Functionality: 
2566  *     Build and Send Ue context mod request
2567  * 
2568  *  @params[in]  cellId, crnti, DuUeCfg pointer
2569  *  @return ROK     - success
2570  *          RFAILED - failure
2571  * 
2572  *****************************************************************/
2573
2574 uint8_t duBuildAndSendUeContextModReq(uint16_t cellId, uint16_t crnti, DuUeCfg *duUeCfg)
2575 {
2576    uint8_t ret = ROK;
2577
2578    DU_LOG("\nDEBUG   -->  DU_APP: Processing Ue Context Mod Request for cellId [%d]", cellId);
2579    /* Filling RLC Ue Reconfig */ 
2580    ret = duBuildAndSendUeReCfgReqToRlc(cellId, crnti, duUeCfg);
2581    if(ret == RFAILED)
2582       DU_LOG("\nERROR  -->  DU APP : Failed to build ctxt setup req for RLC at duBuildAndSendUeContextModReq()");
2583    
2584    /* Filling MAC Ue Reconfig */
2585    ret = duBuildAndSendUeReCfgReqToMac(cellId, crnti, duUeCfg);
2586    if(ret == RFAILED)
2587       DU_LOG("\nERROR  -->  DU APP : Failed at build ctxt setup req for MAC at duBuildAndSendUeContextModReq()");
2588
2589    return ret;
2590 }
2591 /*******************************************************************
2592  *
2593  * @brief Processing Ue context mod request
2594  *
2595  * @details
2596  *
2597  *
2598  *    Function : duProcUeContextModReq 
2599  *
2600  *    Functionality:
2601  *        Processing  Ue context mod request
2602  *
2603  *  @params[in] DuUeCb *ueCb 
2604  *  @return ROK     - success
2605  *          RFAILED - failure
2606  *
2607  *****************************************************************/
2608
2609 uint8_t duProcUeContextModReq(DuUeCb *ueCb)
2610 {
2611    uint8_t ret, cellId;
2612
2613    ret = ROK;
2614    if(ueCb)
2615    {
2616       cellId = duCb.actvCellLst[ueCb->f1UeDb->cellIdx]->cellId;
2617       /* Send DL RRC msg for security Mode */
2618       if(ueCb->f1UeDb->dlRrcMsg)
2619       {
2620          if(ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
2621          {
2622             /* Sending DL RRC Message to RLC */
2623             ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->rlcUeCfg, ueCb->f1UeDb->dlRrcMsg);
2624             if(ret == RFAILED)
2625             {
2626                DU_LOG("\nERROR  -->  DU APP : Failed to send DL RRC msg in duProcUeContextModReq()");
2627                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
2628                      ueCb->f1UeDb->dlRrcMsg->rrcMsgSize);
2629                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
2630             }
2631          }
2632       }
2633       else
2634       {
2635          ret = duBuildAndSendUeContextModReq(cellId, ueCb->crnti, &ueCb->f1UeDb->duUeCfg);
2636          if(ret == RFAILED)
2637          {
2638             DU_LOG("\nERROR  -->  DU APP : Failed to build ue context setup Req in duProcUeContextModReq()");
2639          }
2640       }
2641    }
2642    else
2643    {
2644       //TODO: To send the failure cause in UeContextModRsp
2645       DU_LOG("ERROR  -->  DU APP : Failed to process UE CNTXT MOD REQ at duProcUeContextModReq()");
2646    }
2647    return ROK;
2648 }
2649
2650 /*******************************************************************
2651 *
2652 * @brief Function to delete Pdsch ServCellCfg
2653 *
2654 * @details
2655 *
2656 *    Function : deletePdschServCellCfg
2657 *
2658 *    Functionality: Function to delete Pdsch ServCellCfg
2659 *
2660 * @params[in] PdschServCellCfg *pdschServCellCfg
2661 * @return void
2662 *
2663 * ****************************************************************/
2664
2665 void deletePdschServCellCfg(PdschServCellCfg *pdschServCellCfg)
2666 {
2667    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
2668    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
2669    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
2670    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->xOverhead, sizeof(PdschXOverhead));
2671 }
2672
2673 /*******************************************************************
2674  *
2675 * @brief delete MacUeCfg from duCb
2676 *
2677 * @details
2678 *
2679 *    Function : deleteMacUeCfg 
2680 *
2681 *    Functionality: delete MacUeCfg from duCb
2682 *
2683 * @params[in] Pointer to MacUeCfg 
2684 * @return ROK     - success
2685 *         RFAILED - failure
2686 *
2687 *******************************************************************/
2688
2689 void deleteMacUeCfg(MacUeCfg *ueCfg)
2690 {
2691    uint8_t lcCfgIdx;
2692    uint8_t resrcIdx;
2693    ServCellCfgInfo *servCellCfg;
2694    PucchResrcInfo *resrcToAddModList;
2695
2696    if(ueCfg)
2697    {
2698       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,ueCfg->ambrCfg, sizeof(AmbrCfg));
2699       if(ueCfg->spCellCfgPres)
2700       {
2701          servCellCfg = &ueCfg->spCellCfg.servCellCfg;
2702          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,servCellCfg->bwpInactivityTmr, sizeof(uint8_t));
2703          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,servCellCfg->initUlBwp.pucchCfg.resrcSet,\
2704          sizeof(PucchResrcSetCfg));
2705          if(servCellCfg->initUlBwp.pucchCfg.resrc)
2706          {
2707             /*freeing the PucchResrcCfg*/
2708             for(resrcIdx= 0; resrcIdx< servCellCfg->initUlBwp.pucchCfg.resrc->resrcToAddModListCount; resrcIdx++)
2709             {
2710                resrcToAddModList=&servCellCfg->initUlBwp.pucchCfg.resrc->resrcToAddModList[resrcIdx];
2711                switch(resrcToAddModList->pucchFormat)
2712                {
2713                   case PUCCH_FORMAT_0:
2714                      {
2715                         DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,resrcToAddModList->PucchFormat.format0 ,\
2716                         sizeof(PucchFormat0));
2717                         break;
2718                      }
2719                   case PUCCH_FORMAT_1:
2720                      {
2721                         DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,resrcToAddModList->PucchFormat.format1 ,\
2722                         sizeof(PucchFormat1));
2723                         break;
2724                      }
2725                   case PUCCH_FORMAT_2:
2726                      {
2727                         DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,resrcToAddModList->PucchFormat.format2 ,\
2728                         sizeof(PucchFormat2_3));
2729                         break;
2730                      }
2731                   case PUCCH_FORMAT_3:
2732                      {
2733                         DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,resrcToAddModList->PucchFormat.format3 ,\
2734                         sizeof(PucchFormat2_3));
2735                         break;
2736                      }
2737                   case PUCCH_FORMAT_4:
2738                      {
2739                         DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,resrcToAddModList->PucchFormat.format4 ,\
2740                         sizeof(PucchFormat4));
2741                         break;
2742                      }
2743                }
2744             }
2745             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,servCellCfg->initUlBwp.pucchCfg.resrc,\
2746             sizeof(PucchResrcCfg));
2747          }
2748          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,servCellCfg->initUlBwp.pucchCfg.format1,\
2749          sizeof(PucchFormatCfg));
2750          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,servCellCfg->initUlBwp.pucchCfg.format2,\
2751          sizeof(PucchFormatCfg));
2752          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,servCellCfg->initUlBwp.pucchCfg.format3,\
2753          sizeof(PucchFormatCfg));
2754          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,servCellCfg->initUlBwp.pucchCfg.format4,\
2755          sizeof(PucchFormatCfg));
2756          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,servCellCfg->initUlBwp.pucchCfg.schedReq,\
2757          sizeof(PucchSchedReqCfg));
2758          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,servCellCfg->initUlBwp.pucchCfg.multiCsiCfg,\
2759          sizeof(PucchMultiCsiCfg));
2760          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,servCellCfg->initUlBwp.pucchCfg.spatialInfo,\
2761          sizeof(PucchSpatialCfg));
2762          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,servCellCfg->initUlBwp.pucchCfg.dlDataToUlAck ,\
2763          sizeof(PucchDlDataToUlAck));
2764          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,servCellCfg->initUlBwp.pucchCfg.powerControl,\
2765          sizeof(PucchPowerControl));
2766          deletePdschServCellCfg(&servCellCfg->pdschServCellCfg);
2767       }
2768       for(lcCfgIdx=0; lcCfgIdx< ueCfg->numLcs; lcCfgIdx++)
2769       {
2770          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,ueCfg->lcCfgList[lcCfgIdx].drbQos, sizeof(DrbQosInfo));
2771          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,ueCfg->lcCfgList[lcCfgIdx].snssai, sizeof(Snssai));
2772       }
2773    }
2774    memset(ueCfg, 0, sizeof(MacUeCfg));
2775 }
2776
2777 /*******************************************************************
2778 *
2779 * @brief delete UE Configuration of a particular UE
2780 *
2781 * @details
2782 *
2783 *    Function : deleteUeCfg 
2784 *
2785 *    Functionality: delete UE Configuration of a particular UE 
2786 *
2787 * @params[in] uint16_t cellIdx, uint8_t ueIdx
2788 * @return ROK     - success
2789 *         RFAILED - failure
2790 *
2791 * ****************************************************************/
2792 uint8_t  deleteUeCfg(uint16_t cellIdx, uint8_t ueIdx)
2793 {
2794    DuUeCb *ueCb = NULLP;
2795    if(duCb.actvCellLst[cellIdx] != NULLP)
2796    {
2797       if((duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg.macUeCfgState == UE_DELETE_COMPLETE)\
2798             &&(duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg.rlcUeCfgState == UE_DELETE_COMPLETE))
2799       {
2800          ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1];
2801          deleteMacUeCfg(&ueCb->macUeCfg);
2802          deleteRlcUeCfg(&ueCb->rlcUeCfg);
2803          if(ueCb->f1UeDb !=NULLP)
2804          {
2805             freeF1UeDb(ueCb->f1UeDb);
2806          }
2807          duCb.actvCellLst[cellIdx]->numActvUes--;
2808          memset(ueCb, 0, sizeof(DuUeCb));
2809       }
2810       else
2811       {
2812          DU_LOG("INFO  --> DU APP : deleteUeCfg(): MAC or RLC UE configuration state not UE_DELETE_COMPLETE");
2813          return RFAILED;
2814       }
2815    }
2816    else
2817    {
2818       DU_LOG("ERROR  --> DU APP : deleteUeCfg(): CellIdx[%d] is not found", cellIdx);
2819       return RFAILED;
2820    }
2821    return ROK;
2822 }
2823
2824
2825 /*******************************************************************
2826 *
2827 * @brief Handle UE delete response from MAC
2828 *
2829 * @details
2830 *
2831 *    Function : DuProcMacUeDeleteRsp
2832 *
2833 *    Functionality: Handle UE delete response from MAC
2834 *
2835 * @params[in] Pointer to MacUeDeleteRsp and Pst
2836 * @return ROK     - success
2837 *         RFAILED - failure
2838 *
2839 * ****************************************************************/
2840
2841 uint8_t DuProcMacUeDeleteRsp(Pst *pst, MacUeDeleteRsp *deleteRsp)
2842 {
2843    uint8_t  ueIdx = 0,ret =ROK;
2844    uint16_t cellIdx=0;
2845    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId =0;
2846
2847    if(deleteRsp)
2848    {
2849       if(deleteRsp->result == SUCCESS)
2850       {
2851          DU_LOG("\nINFO   -->  DU APP : MAC UE Delete Response : SUCCESS [UE IDX : %d]", deleteRsp->ueIdx);
2852          GET_CELL_IDX(deleteRsp->cellId, cellIdx);
2853          ueIdx = deleteRsp->ueIdx;
2854          if(duCb.actvCellLst[cellIdx])
2855          {
2856             duCb.actvCellLst[cellIdx]->ueCb[deleteRsp->ueIdx -1].macUeCfg.macUeCfgState = UE_DELETE_COMPLETE;
2857             gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbDuUeF1apId;
2858             gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbCuUeF1apId;
2859             if(deleteUeCfg(cellIdx, ueIdx) == ROK)
2860             {
2861                  ret = BuildAndSendUeContextReleaseComplete(gnbCuUeF1apId, gnbDuUeF1apId);
2862                  if(ret !=ROK)
2863                  {   
2864                     DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): failed to send UE context release complete");
2865                  }
2866             }
2867          }
2868       }
2869       else
2870       {
2871          DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): MAC UE Delete Response : FAILURE [UE IDX : %d]",\
2872          deleteRsp->ueIdx);
2873          ret =  RFAILED;
2874       }
2875       DU_FREE_SHRABL_BUF(pst->region, pst->pool, deleteRsp, sizeof(MacUeDeleteRsp));
2876    }
2877    else
2878    {
2879       DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): MAC UE Delete Response is null");
2880       ret = RFAILED;
2881    }
2882    return ret;
2883 }
2884
2885 /*******************************************************************
2886  *
2887  * @brief Processes UE Delete Rsp received from RLC 
2888  *
2889  * @details
2890  *
2891  *    Function : DuProcRlcUeDeleteRsp
2892  *
2893  *    Functionality:
2894  *     Processes UE Delete Rsp received from RLC 
2895  *
2896  *  @params[in]  Post structure
2897  *               Pointer to RlcUeDeleteRsp
2898  *  @return ROK     - success
2899  *          RFAILED - failure
2900  *
2901  * *****************************************************************/
2902
2903 uint8_t DuProcRlcUeDeleteRsp(Pst *pst, RlcUeDeleteRsp *delRsp)
2904 {
2905    uint8_t  ueIdx = 0, ret = ROK;
2906    uint16_t cellIdx = 0;
2907    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId =0;   
2908
2909    if(delRsp)
2910    {
2911       ueIdx = delRsp->ueIdx;
2912       GET_CELL_IDX(delRsp->cellId, cellIdx);
2913
2914       if(delRsp->result == SUCCESSFUL)
2915       {
2916          DU_LOG("\nINFO   -->  DU_APP: RLC UE Delete Response : SUCCESS [UE IDX:%d]", ueIdx);
2917          if(duCb.actvCellLst[cellIdx]!=NULLP)
2918          {
2919             duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg.rlcUeCfgState = UE_DELETE_COMPLETE;
2920             gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbDuUeF1apId;
2921             gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbCuUeF1apId;
2922             if(deleteUeCfg(cellIdx, ueIdx) == ROK)
2923             {
2924                 ret = BuildAndSendUeContextReleaseComplete(gnbCuUeF1apId, gnbDuUeF1apId);
2925                 if(ret != ROK)
2926                 {
2927                    DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): failed to send UE context release complete");
2928                 }
2929             }
2930          }
2931       }
2932       else
2933       {
2934          DU_LOG("\nERROR   -->  DU_APP: RLC UE Delete Response : FAILED [UE IDX:%d]", ueIdx);
2935          ret = RFAILED;
2936       }
2937       DU_FREE_SHRABL_BUF(pst->region, pst->pool, delRsp, sizeof(RlcUeDeleteRsp));
2938
2939    }
2940    return ret;
2941 }
2942
2943 /*******************************************************************
2944  *
2945  * @brief Sending UE Delete Req To Mac
2946 *
2947 * @details
2948 *
2949 *    Function : sendUeDeleteReqToMac
2950 *
2951 *    Functionality:
2952 *     sending UE Delete Req To Mac
2953 *
2954 *  @params[in]    cellId, ueIdx, crnti 
2955 *  @return ROK     - success
2956 *          RFAILED - failure
2957 *
2958 *****************************************************************/
2959
2960 uint8_t sendUeDeleteReqToMac(uint16_t cellId, uint8_t ueIdx, uint16_t crnti)
2961 {
2962    Pst pst;
2963    uint8_t ret=ROK;
2964    MacUeDelete *ueDelete = NULLP;
2965
2966    DU_ALLOC_SHRABL_BUF(ueDelete, sizeof(MacUeDelete));
2967    if(ueDelete)
2968    {
2969       ueDelete->cellId = cellId;
2970       ueDelete->ueIdx  = ueIdx;
2971       ueDelete->crnti  = crnti;
2972       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_DELETE_REQ);
2973
2974       /* Processing one Ue at a time to MAC */
2975       DU_LOG("\nDEBUG  -->  DU_APP: Sending UE delete Request to MAC ");
2976       ret = (*packMacUeDeleteReqOpts[pst.selector])(&pst, ueDelete);
2977       if(ret == RFAILED)
2978       {
2979          DU_LOG("\nERROR  -->  DU_APP: sendUeDeleteReqToMac(): Failed to send UE delete Req to MAC");
2980          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueDelete, sizeof(MacUeDelete));
2981       }
2982    }
2983    else
2984    {
2985       DU_LOG("\nERROR  -->   DU_APP: sendUeDeleteReqToMac(): Failed to allocate memory"); 
2986       ret = RFAILED;
2987    }
2988    return ret;
2989 }
2990
2991 /*******************************************************************
2992  *
2993  * @brief Sending UE Delete Req To Rlc
2994  *
2995  * @details
2996  *
2997  *    Function : sendUeDeleteReqToRlc
2998  *
2999  *    Functionality:
3000  *     Sending UE Delete Req To Rlc
3001  *
3002  *  @params[in]  cellId, ueIdx 
3003  *  @return ROK     - success
3004  *          RFAILED - failure
3005  *
3006  *****************************************************************/
3007
3008 uint8_t sendUeDeleteReqToRlc(uint16_t cellId, uint8_t ueIdx)
3009 {
3010    uint8_t ret;
3011    Pst pst;
3012    RlcUeDelete *ueDelete;
3013
3014    DU_ALLOC_SHRABL_BUF(ueDelete, sizeof(RlcUeDelete));
3015    if(ueDelete !=NULLP)
3016    {
3017       ueDelete->cellId = cellId;
3018       ueDelete->ueIdx = ueIdx;
3019       FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_DELETE_REQ);
3020
3021       ret = (*packRlcUeDeleteReqOpts[pst.selector])(&pst, ueDelete);
3022       if(ret == RFAILED)
3023       {
3024          DU_LOG("\nERROR  -->  DU_APP : sendUeDeleteReqToRlc():Failed to send UE Delete  Req to RLC"); 
3025          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueDelete, sizeof(RlcUeDelete));
3026       }
3027    }
3028    else
3029    {
3030       DU_LOG("\nERROR  -->   DU_APP: sendUeDeleteReqToRlc():Memory allocation failed");
3031       ret = RFAILED;
3032    }
3033    return ret;
3034 }
3035
3036 /*******************************************************************
3037  *
3038  * @brief DU processes UE delete req from CU and sends to MAC and RLC 
3039  *
3040  * @details
3041  *
3042  *    Function : duProcUeDeleteReq
3043  *
3044  *    Functionality: DU processes UE delete req from CU and sends to MAC 
3045  *                   and RLC 
3046  *
3047  * @params[in] cellId, crnti 
3048  * @return ROK     - success
3049  *         RFAILED - failure
3050  *
3051  * ****************************************************************/
3052
3053 uint8_t duProcUeDeleteReq(uint16_t cellId)
3054 {
3055    uint8_t  ueIdx = 0, ueId =0;
3056    uint16_t cellIdx = 0, crnti   = 0;
3057
3058    DU_LOG("\nDEBUG   -->  DU_APP: Processing UE Delete Request ");
3059    GET_CELL_IDX(cellId, cellIdx);
3060    GET_CRNTI(crnti,ueIdx);
3061
3062    if(duCb.actvCellLst[cellIdx] != NULLP)
3063    {
3064       for(ueIdx =0;ueIdx< duCb.actvCellLst[cellIdx]->numActvUes; ueIdx++)
3065       {
3066          ueId = ueIdx+1;
3067          if(sendUeDeleteReqToRlc(cellId, ueId) == RFAILED)
3068          {
3069             DU_LOG("\nERROR  -->  DU APP : duProcUeDeleteReq():Failed to build UE  delete req for RLC ");
3070             return RFAILED;
3071          }
3072
3073          GET_CRNTI(crnti,ueId);
3074          if(sendUeDeleteReqToMac(cellId, ueId, crnti) == RFAILED)
3075          {
3076             DU_LOG("\nERROR  -->  DU APP : duProcUeDeleteReq(): Failed to build UE  delete req for MAC ");
3077             return RFAILED;
3078          }
3079       }
3080    }
3081    else
3082    {
3083       DU_LOG("\nERROR  -->  DU APP : duProcUeDeleteReq(): Cell Id is not found");
3084       return RFAILED;
3085    }
3086
3087    return ROK;
3088 }
3089
3090 /*******************************************************************
3091  *
3092  * @brief delete RlcUeCfg from duCb
3093  *
3094  * @details
3095  *
3096  *    Function : deleteRlcUeCfg
3097  *
3098  *    Functionality:
3099  *       delete  RlcUeCfg from duCb
3100  *
3101  *  @params[in] RlcUeCfg *ueCfg 
3102  *               
3103  *  @return ROK     - success
3104  *          RFAILED - failure
3105  *
3106  *****************************************************************/
3107
3108 void deleteRlcUeCfg(RlcUeCfg *ueCfg)
3109 {
3110    uint8_t lcIdx = 0;
3111    RlcBearerCfg *lcCfg= NULLP;
3112    if(ueCfg)
3113    {
3114       for(lcIdx =0 ; lcIdx < ueCfg->numLcs ; lcIdx++)
3115       {
3116          lcCfg = &ueCfg->rlcLcCfg[lcIdx];
3117          switch(lcCfg->rlcMode)
3118          {
3119             case RLC_AM :
3120                {
3121                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
3122                   break;
3123                }
3124             case RLC_UM_BI_DIRECTIONAL :
3125                {
3126                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
3127                   break;
3128                }
3129             case RLC_UM_UNI_DIRECTIONAL_UL :
3130                {
3131                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
3132                   break;
3133                }
3134             case RLC_UM_UNI_DIRECTIONAL_DL :
3135                {
3136                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
3137                   break;
3138                }
3139          }
3140       }
3141       memset(ueCfg, 0, sizeof(RlcUeCfg));
3142    }
3143 }
3144
3145 /*******************************************************************
3146  *
3147  * @brief Delete DU CellCb information 
3148  *
3149  * @details
3150  *
3151  *    Function : deleteDuCellCb
3152  *
3153  *    Functionality: Delete DU CellCb information
3154  *
3155  * @params[in] DuCellCb *cellCb
3156  * @return ROK     - success
3157  *         RFAILED - failure
3158  *
3159  * ****************************************************************/
3160
3161 void deleteDuCellCb(DuCellCb *cellCb)
3162 {
3163
3164    if(cellCb->duMacCellCfg)
3165    {
3166       if(cellCb->duMacCellCfg->prachCfg.fdm[0].unsuedRootSeq)
3167       {
3168          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cellCb->duMacCellCfg->prachCfg.fdm[0].unsuedRootSeq,\
3169                cellCb->duMacCellCfg->prachCfg.fdm[0].numUnusedRootSeq);
3170       }
3171       if(cellCb->duMacCellCfg->sib1Cfg.sib1Pdu)
3172       {
3173          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,cellCb->duMacCellCfg->sib1Cfg.sib1Pdu,\
3174                cellCb->duMacCellCfg->sib1Cfg.sib1PduLen);
3175       }
3176       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cellCb->duMacCellCfg, sizeof(MacCellCfg));
3177    }
3178    memset(cellCb, 0, sizeof(DuCellCb));
3179
3180 }
3181
3182 /*******************************************************************
3183  *
3184  * @brief Handle Cell delete response from MAC
3185  *
3186  * @details
3187  *
3188  *    Function : DuProcMacCellDeleteRsp
3189  *
3190  *    Functionality: Handle Cell delete response from MAC
3191  *
3192  * @params[in] Pointer to MacCellDeleteRsp and Pst
3193  * @return ROK     - success
3194  *         RFAILED - failure
3195  *
3196  * ****************************************************************/
3197
3198 uint8_t DuProcMacCellDeleteRsp(Pst *pst, MacCellDeleteRsp *deleteRsp)
3199 {
3200    uint8_t ret = ROK;
3201    uint16_t cellIdx=0;
3202    if(deleteRsp)
3203    {
3204       if(deleteRsp->result == SUCCESSFUL_RSP)
3205       {
3206          GET_CELL_IDX(deleteRsp->cellId, cellIdx);
3207          DU_LOG("\nINFO   -->  DU APP : MAC CELL Delete Response : SUCCESS [CELL IDX : %d]", deleteRsp->cellId);
3208          if(duCb.actvCellLst[cellIdx]->cellId == deleteRsp->cellId)
3209          {
3210             deleteDuCellCb(duCb.actvCellLst[cellIdx]);
3211             duCb.numActvCells--;
3212             DU_FREE(duCb.actvCellLst[cellIdx], sizeof(DuCellCb));
3213          }
3214          else
3215          {
3216             DU_LOG("\nERROR  -->  DU APP : DuProcMacCellDeleteRsp(): CellId [%d] doesnot exist", deleteRsp->cellId);
3217             ret = RFAILED;
3218          }
3219       }
3220       else
3221       {
3222          DU_LOG("\nERROR  -->  DU APP : DuProcMacCellDeleteRsp(): MAC CELL Delete Response : FAILED\
3223          [CELL IDX : %d]", deleteRsp->cellId);
3224          ret = RFAILED;
3225       }
3226       DU_FREE_SHRABL_BUF(pst->region, pst->pool, deleteRsp, sizeof(MacUeDeleteRsp));
3227    }
3228    else
3229    {
3230       DU_LOG("\nERROR  -->  DU APP : DuProcMacCellDeleteRsp(): Received MAC cell delete response is NULL");
3231       ret = RFAILED;
3232    }
3233    return ret;
3234 }
3235
3236 /*******************************************************************
3237  *
3238  * @brief Sending Cell Delete Req To Mac
3239  *
3240  * @details
3241  *
3242  *    Function : sendCellDeleteReqToMac
3243  *
3244  *    Functionality:
3245  *     sending Cell Delete Req To Mac
3246  *
3247  *  @params[in]    uint16_t cellId
3248  *  @return ROK     - success
3249  *          RFAILED - failure
3250  *
3251  *
3252  *****************************************************************/
3253
3254 uint8_t sendCellDeleteReqToMac(uint16_t cellId)
3255 {
3256    Pst pst;
3257    uint8_t ret=ROK;
3258    MacCellDelete *cellDelete = NULLP;
3259    
3260    DU_ALLOC(cellDelete, sizeof(MacCellDelete));
3261    if(cellDelete)
3262    {
3263       cellDelete->cellId = cellId;
3264       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_DELETE_REQ);
3265
3266       DU_LOG("\nINFO   -->  DU APP : Sending Cell Delete Request to MAC");  
3267       /* Processing one Cell at a time to MAC */
3268       ret = (*packMacCellDeleteReqOpts[pst.selector])(&pst, cellDelete);
3269       if(ret == RFAILED)
3270       {
3271          DU_LOG("\nERROR  -->  DU APP : sendCellDeleteReqToMac(): Failed to send Cell delete Req to MAC");
3272          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cellDelete, sizeof(MacCellDelete));
3273       }
3274    }
3275    else
3276    {
3277       DU_LOG("\nERROR  -->   DU APP : sendCellDeleteReqToMac(): Failed to allocate memory"); 
3278       ret = RFAILED;
3279    }
3280    return ret;
3281 }
3282
3283 /*******************************************************************
3284  *
3285  * @brief DU preocess Cell Delete Req to MAC 
3286  *
3287  * @details
3288  *
3289  *    Function : duProcCellDeleteReq 
3290  *
3291  *    Functionality: DU process Cell Delete Req to MAC 
3292  *
3293  * @params[in] uint16_t cellId
3294  * @return ROK     - success
3295  *         RFAILED - failure
3296  *
3297  * ****************************************************************/
3298
3299 uint8_t duProcCellDeleteReq(uint16_t cellId)
3300 {
3301    uint16_t cellIdx = 0;
3302    
3303    DU_LOG("\nINFO   -->  DU APP : Processing Cell Delete Request ");
3304    GET_CELL_IDX(cellId, cellIdx);
3305
3306    if(duCb.actvCellLst[cellIdx] != NULLP)
3307    {
3308       if(duBuildAndSendMacCellStop() == RFAILED)
3309       {
3310          DU_LOG("\nERROR  -->  DU APP : duProcCellDeleteReq(): Failed to process Cell delete req for cellId[%d]",cellId);
3311          return RFAILED;
3312       }
3313       
3314       if(duCb.actvCellLst[cellIdx]->numActvUes)
3315       {
3316          DU_LOG("\nERROR  -->  DU APP : duProcCellDeleteReq(): Active UEs present Failed to process cell Delete\
3317          Req for cellID[%d]", cellId);
3318          return RFAILED;
3319       }
3320       if(sendCellDeleteReqToMac(cellId) == RFAILED)
3321       {
3322          DU_LOG("\nERROR  -->  DU APP : duProcCellDeleteReq(): Failed to build and send Cell delete req for MAC for\
3323          cellId[%d]",cellId);
3324          return RFAILED;
3325       }
3326    }
3327    else
3328    {
3329       DU_LOG("\nERROR  -->  DU APP : duProcCellDeleteReq(): CellId[%d] is not found", cellId);
3330       return RFAILED;
3331    }
3332
3333    return ROK;
3334 }
3335
3336 /**********************************************************************
3337   End of file
3338 ***********************************************************************/