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