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