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