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