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