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