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