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