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