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