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