d009614f9d6ed8d837d361e9a408be151a1867ce
[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]  DuMacUeCfg *macUeCfg
782  * @return ROK - Success
783  *         RFAILED - Failure
784  *
785  *****************************************************************/
786 uint8_t fillDefaultSpCellGrpInfo(DuMacUeCfg *macUeCfg)
787 {
788    SpCellRecfg *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.numDlBwpToAddOrMod    = 0; 
806       spCell->servCellCfg.numDlBwpToRel    = 0; 
807       spCell->servCellCfg.firstActvDlBwpId = ACTIVE_DL_BWP_ID;
808       spCell->servCellCfg.defaultDlBwpId   = ACTIVE_DL_BWP_ID;
809       spCell->servCellCfg.bwpInactivityTmr = NULLP;
810       spCell->servCellCfg.pdschServCellCfg.maxMimoLayers = NULLP;
811       spCell->servCellCfg.pdschServCellCfg.maxCodeBlkGrpPerTb = NULLP;
812       spCell->servCellCfg.pdschServCellCfg.codeBlkGrpFlushInd = NULLP;
813       spCell->servCellCfg.pdschServCellCfg.xOverhead = NULLP;
814       spCell->servCellCfg.pdschServCellCfg.numHarqProcForPdsch = NUM_HARQ_PROC_FOR_PDSCH_N_16;
815
816       /* Filling Initial UL Bwp*/
817       fillDefaultInitUlBwp(&spCell->servCellCfg.initUlBwp);
818       spCell->servCellCfg.numUlBwpToAddOrMod  = 0; 
819       spCell->servCellCfg.numUlBwpToRel       = 0; 
820       spCell->servCellCfg.firstActvUlBwpId    = ACTIVE_DL_BWP_ID; 
821    }
822    else
823    {
824       DU_LOG("\nERROR  -->  DU APP : Memory is NULL for SpCellGrp");
825       return RFAILED;
826    }
827    return ROK;
828 }
829
830 /******************************************************************
831  *
832  * @brief Fills Physical Cell Group Info
833  *
834  * @details
835  *
836  *    Function : fillDefaultPhyCellGrpInfo
837  *
838  *    Functionality: Fills Physical Cell Group Info
839  *
840  * @params[in]  DuMacUeCfg *macUeCfg
841  * @return void
842  *
843  *****************************************************************/
844 void fillDefaultPhyCellGrpInfo(DuMacUeCfg *macUeCfg)
845 {
846    PhyCellGrpCfg *cellGrp = NULL;
847
848    if(macUeCfg)
849       cellGrp = &macUeCfg->phyCellGrpCfg;
850
851    if(cellGrp)
852    {
853       macUeCfg->phyCellGrpCfgPres = true;
854       cellGrp->pdschHarqAckCodebook = PDSCH_HARQ_ACK_CODEBOOK_DYNAMIC;
855       cellGrp->pNrFr1 = P_NR_FR1;
856    }
857    else
858    {
859       DU_LOG("\nERROR  -->  DU APP : Memory is NULL for Physical Cell Group");
860    }
861 }
862
863 /******************************************************************
864  *
865  * @brief Fills Mac Cell Group Info
866  *
867  * @details
868  *
869  *    Function : fillDefaultMacCellGrpInfo
870  *
871  *    Functionality: Fills Mac Cell Group Info
872  *
873  * @params[in]  DuMacUeCfg *macUeCfg
874  * @return void
875  *
876  *****************************************************************/
877 void fillDefaultMacCellGrpInfo(DuMacUeCfg *macUeCfg)
878 {
879    uint8_t idx;
880    MacCellGrpCfg *cellGrp = NULL;
881    
882    if(macUeCfg)
883       cellGrp = &macUeCfg->macCellGrpCfg;
884
885    if(cellGrp)
886    {
887       macUeCfg->macCellGrpCfgPres = true;
888
889       /* Filling Scheduling Request Config */
890       cellGrp->schReqCfg.addModListCount = 1;
891       if(cellGrp->schReqCfg.addModListCount <= MAX_NUM_SR_CFG_PER_CELL_GRP)
892       {
893          for(idx = 0; idx < cellGrp->schReqCfg.addModListCount; idx++)
894          {
895             cellGrp->schReqCfg.addModList[idx].schedReqId    = SCH_REQ_ID;
896             cellGrp->schReqCfg.addModList[idx].srProhibitTmr = SR_PROHIBIT_MS_32;
897             cellGrp->schReqCfg.addModList[idx].srTransMax    = SR_TRANS_MAX_N_16;
898          }
899       }
900       cellGrp->schReqCfg.relListCount = 0;
901
902       /* Filling Tag config */
903       cellGrp->tagCfg.addModListCount = 1;
904       if(cellGrp->tagCfg.addModListCount <= MAC_NUM_TAGS)
905       {
906          for(idx = 0; idx < cellGrp->tagCfg.addModListCount; idx++)
907          {
908             cellGrp->tagCfg.addModList[idx].tagId = TAG_ID;
909             cellGrp->tagCfg.addModList[idx].timeAlignTimer = TIME_ALIGNMENT_TIMER_INFINITY;
910          }
911       }
912       cellGrp->tagCfg.relListCount = 0;
913
914       /* Filling BSR config */
915       cellGrp->bsrTmrCfg.periodicTimer = BSR_PERIODIC_TIMER_SF_10;
916       cellGrp->bsrTmrCfg.retxTimer = BSR_RETX_TIMER_SF_320;
917       cellGrp->bsrTmrCfg.srDelayTimer = BSR_SR_DELAY_TMR_2560;
918
919       /* Filling PHR config */
920       cellGrp->phrCfgSetupPres = true;
921       cellGrp->phrCfg.periodicTimer = PHR_PERIODIC_TIMER_INFINITY;
922       cellGrp->phrCfg.prohibitTimer = PHR_PROHIBIT_TIMER_SF_0;
923       cellGrp->phrCfg.txPowerFactor = PHR_TX_PWR_FACTOR_CHANGE_INFINITY;
924       cellGrp->phrCfg.multiplePHR   = false;
925       cellGrp->phrCfg.dummy         = false;
926       cellGrp->phrCfg.phrType2OtherCell = false;
927       cellGrp->phrCfg.phrOtherCG = PHR_MODE_OTHER_CG_REAL;  
928
929       /* Filling Drx Config */
930 #ifdef NR_DRX
931       cellGrp->drxCfg.drxOnDurationTimer.onDurationTimerValInMs = DRX_ONDURATION_TIMER_VALUE_PRESENT_IN_MS;
932       if(!cellGrp->drxCfg.drxOnDurationTimer.onDurationTimerValInMs)
933          cellGrp->drxCfg.drxOnDurationTimer.onDurationtimerValue.subMilliSeconds = \
934                                                                                    DRX_ONDURATION_TIMER_VALUE_IN_SUBMS;
935       else
936          cellGrp->drxCfg.drxOnDurationTimer.onDurationtimerValue.milliSeconds = \
937                                                                                 DRX_ONDURATION_TIMER_VALUE_IN_MS;
938       cellGrp->drxCfg.drxInactivityTimer = DRX_INACTIVITY_TIMER;
939       cellGrp->drxCfg.drxHarqRttTimerDl = DRX_HARQ_RTT_TIMER_DL;
940       cellGrp->drxCfg.drxHarqRttTimerUl = DRX_HARQ_RTT_TIMER_UL;
941       cellGrp->drxCfg.drxRetransmissionTimerDl = DRX_RETRANSMISSION_TIMER_DL;
942       cellGrp->drxCfg.drxRetransmissionTimerUl = DRX_RETRANSMISSION_TIMER_UL;
943       cellGrp->drxCfg.drxLongCycleStartOffset.drxLongCycleStartOffsetVal = DRX_LONG_CYCLE_START_OFFSET_VAL;
944       cellGrp->drxCfg.drxLongCycleStartOffset.drxLongCycleStartOffsetChoice = DRX_LONG_CYCLE_START_OFFSET_CHOICE;
945       cellGrp->drxCfg.shortDrxPres = DRX_SHORT_CYCLE_PRESENT;
946       if(cellGrp->drxCfg.shortDrxPres)
947       {
948          cellGrp->drxCfg.shortDrx.drxShortCycle = DRX_SHORT_CYCLE;
949          cellGrp->drxCfg.shortDrx.drxShortCycleTimer = DRX_SHORT_CYCLE_TIMER;
950       }
951       cellGrp->drxCfg.drxSlotOffset = DRX_SLOT_OFFSET;
952 #endif
953
954    }
955    else
956    {
957       DU_LOG("\nERROR  -->  DU APP : Memory is NULL for Master Cell Group");
958    }
959 }
960
961 /*******************************************************************
962  *
963  * @brief Fills default modulation info for a UE
964  *
965  * @details
966  *
967  *    Function : fillDefaultModulation
968  *
969  *    Functionality: Fills default modulation info for a UE
970  *
971  * @params[in] Pointer to MAC UE configuration
972  * @return ROK     - success
973  *         RFAILED - failure
974  *
975  * ****************************************************************/
976 void fillDefaultModulation(DuMacUeCfg *ueCfg)
977 {
978    ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
979    ueCfg->dlModInfo.mcsIndex = DEFAULT_MCS;
980    ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64; /* Spec 38.214-Table 5.1.3.1-1 */
981
982    ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
983    ueCfg->ulModInfo.mcsIndex = DEFAULT_MCS;
984    ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64; /* Spec 38.214-Table 5.1.3.1-1 */
985 }
986
987 /******************************************************************
988  *
989  * @brief Function to fill Mac Lc Cfg for SRB1
990  *
991  * @details
992  *
993  *    Function : fillMacSrb1LcCfg
994  *
995  *    Functionality: Function to fill Mac Lc cfg for SRB1
996  *
997  * @params[in]  LcCfg *lcCfg, LcCfg *ueSetReqDb
998  * @return void
999  *****************************************************************/
1000
1001 void fillMacSrb1LcCfg(DuLcCfg *macLcCfg)
1002 {
1003    macLcCfg->lcConfig.lcId   = SRB1_LCID;
1004    macLcCfg->configType = CONFIG_ADD;
1005    macLcCfg->lcConfig.drbQos = NULLP;
1006    macLcCfg->lcConfig.snssai = NULLP;
1007    macLcCfg->lcConfig.ulLcCfgPres = true;
1008    fillDefaultUlLcCfg(&macLcCfg->lcConfig.ulLcCfg);
1009 }
1010
1011 /******************************************************************
1012  *
1013  * @brief Function to fill the Lc cfg from ueSetupReqDb
1014  *
1015  * @details
1016  *
1017  *    Function : fillMacLcCfgToAddMod
1018  *
1019  *    Functionality: Function to fill the Lc cfg from ueSetupReqDb
1020  *
1021  * @params[in]  LcCfg *lcCfg, LcCfg *ueSetReqDb
1022  * @return ROK/RFAILED
1023  *
1024  *****************************************************************/
1025
1026 uint8_t fillMacLcCfgToAddMod(DuLcCfg *macLcCfgToSend, DuLcCfg *ueLcCfgDb, DuLcCfg *oldLcCfg, Bool toUpdate)
1027 {
1028    if(!toUpdate)
1029    {
1030       if(macLcCfgToSend)
1031       {
1032          macLcCfgToSend->lcConfig.lcId = ueLcCfgDb->lcConfig.lcId;
1033          macLcCfgToSend->configType = ueLcCfgDb->configType;
1034
1035          if(ueLcCfgDb->lcConfig.drbQos)
1036             macLcCfgToSend->lcConfig.drbQos = ueLcCfgDb->lcConfig.drbQos;
1037          else if(oldLcCfg)
1038             macLcCfgToSend->lcConfig.drbQos = oldLcCfg->lcConfig.drbQos;
1039          else
1040             macLcCfgToSend->lcConfig.drbQos = NULL;
1041
1042          if(ueLcCfgDb->lcConfig.snssai)
1043             macLcCfgToSend->lcConfig.snssai = ueLcCfgDb->lcConfig.snssai;
1044          else if(oldLcCfg)
1045             macLcCfgToSend->lcConfig.snssai = oldLcCfg->lcConfig.snssai;
1046          else
1047             macLcCfgToSend->lcConfig.snssai = NULL;
1048
1049          macLcCfgToSend->lcConfig.ulLcCfgPres = ueLcCfgDb->lcConfig.ulLcCfgPres;
1050          memcpy(&macLcCfgToSend->lcConfig.ulLcCfg, &ueLcCfgDb->lcConfig.ulLcCfg, sizeof(UlLcCfg));
1051          memcpy(&macLcCfgToSend->lcConfig.dlLcCfg, &ueLcCfgDb->lcConfig.dlLcCfg, sizeof(DlLcCfg));
1052       }
1053    }
1054    else
1055    {
1056       oldLcCfg->lcConfig.lcId = ueLcCfgDb->lcConfig.lcId;
1057       oldLcCfg->configType = ueLcCfgDb->configType;
1058
1059       if(ueLcCfgDb->lcConfig.drbQos)
1060       {
1061          if(oldLcCfg->lcConfig.drbQos)
1062             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, oldLcCfg->lcConfig.drbQos, sizeof(DrbQosInfo));
1063
1064          DU_ALLOC_SHRABL_BUF(oldLcCfg->lcConfig.drbQos, sizeof(DrbQosInfo));
1065          if(oldLcCfg->lcConfig.drbQos == NULL)
1066          {
1067             DU_LOG("\nERROR  -->  DU APP : Memory Alloc Failed at fillMacLcCfgToAddMod()");
1068             return RFAILED;
1069          }
1070          memcpy(oldLcCfg->lcConfig.drbQos, ueLcCfgDb->lcConfig.drbQos, sizeof(DrbQosInfo));
1071       }
1072
1073       if(ueLcCfgDb->lcConfig.snssai)
1074       {
1075          if(oldLcCfg->lcConfig.snssai)
1076             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, oldLcCfg->lcConfig.snssai, sizeof(Snssai));
1077
1078          DU_ALLOC_SHRABL_BUF(oldLcCfg->lcConfig.snssai, sizeof(Snssai));
1079          if(oldLcCfg->lcConfig.snssai == NULL)
1080          {
1081             DU_LOG("\nERROR  -->  DU APP : Memory Alloc Failed at fillMacLcCfgToAddMod()");
1082             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, oldLcCfg->lcConfig.drbQos, sizeof(DrbQosInfo));
1083             return RFAILED;
1084          }
1085          memcpy(oldLcCfg->lcConfig.snssai, ueLcCfgDb->lcConfig.snssai, sizeof(Snssai));
1086       }
1087
1088       oldLcCfg->lcConfig.ulLcCfgPres = ueLcCfgDb->lcConfig.ulLcCfgPres;
1089       memcpy(&oldLcCfg->lcConfig.ulLcCfg, &ueLcCfgDb->lcConfig.ulLcCfg, sizeof(UlLcCfg));
1090       memcpy(&oldLcCfg->lcConfig.dlLcCfg, &ueLcCfgDb->lcConfig.dlLcCfg, sizeof(DlLcCfg));
1091    }
1092    return ROK;
1093 }
1094
1095 /******************************************************************
1096  *
1097  * @brief Function to copy the Bit rate from ueSetupReqDb
1098  *
1099  * @details
1100  *
1101  *    Function : fillAmbr
1102  *
1103  *    Functionality: Function to copy bit Rate from ueSetupReqDb
1104  *
1105  * @params[in]  AmbrCfg **macAmbr, AmbrCfg  *ueDbAmbr
1106  * @return ROK/RFAILED
1107  *
1108  *****************************************************************/
1109
1110 uint8_t fillAmbr(AmbrCfg **macAmbrCfgToSend, AmbrCfg *ueDbAmbr, AmbrCfg **oldMacAmbrCfg, Bool toUpdate)
1111 {
1112    if(!toUpdate)
1113    {
1114       if(ueDbAmbr)
1115       {
1116          *macAmbrCfgToSend = ueDbAmbr;
1117       }
1118       else if(oldMacAmbrCfg)
1119          *macAmbrCfgToSend = *oldMacAmbrCfg;       
1120    }
1121    else
1122    {
1123       if(ueDbAmbr)
1124       {
1125          if(oldMacAmbrCfg)
1126          {
1127             if(*oldMacAmbrCfg)
1128             {
1129                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, *oldMacAmbrCfg, sizeof(AmbrCfg));
1130             }
1131             DU_ALLOC_SHRABL_BUF(*oldMacAmbrCfg, sizeof(AmbrCfg));
1132             if(*oldMacAmbrCfg == NULLP)
1133             {
1134                DU_LOG("\nERROR  -->  DU APP : Memory Alloc Failed at fillAmbr()");
1135                return RFAILED;
1136             }
1137             memset(*oldMacAmbrCfg, 0, sizeof(AmbrCfg));
1138             (*oldMacAmbrCfg)->ulBr = ueDbAmbr->ulBr;
1139          }
1140       }
1141    }
1142
1143    return ROK;
1144 }
1145
1146 /******************************************************************
1147  *
1148  * @brief Builds and Send UE ReConfig Request to MAC
1149  *
1150  * @details
1151  *
1152  *    Function : sendUeRecfgReqToMac
1153  *
1154  *    Functionality: Builds and Send UE ReConfig Request to MAC
1155  *
1156  * @Params[in]  MacUeRecfg pointer
1157  * @return ROK     - success
1158  *         RFAILED - failure
1159  *
1160  * ****************************************************************/
1161
1162 uint8_t sendUeRecfgReqToMac(MacUeRecfg *macUeRecfg)
1163 {
1164    uint8_t ret = ROK;
1165    Pst pst;
1166
1167    /* Fill Pst */
1168    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_RECONFIG_REQ);
1169
1170    if(macUeRecfg)
1171    {
1172       /* Processing one Ue at a time to MAC */
1173       DU_LOG("\nDEBUG   -->  DU_APP: Sending Ue Reconfig Request to MAC");
1174       ret = (*packMacUeReconfigReqOpts[pst.selector])(&pst, macUeRecfg);
1175       if(ret == RFAILED)
1176       {
1177          DU_LOG("\nERROR  -->  DU APP : Failed to send Reconfig Request to MAC at sendUeRecfgReqToMac()");
1178          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macUeRecfg, sizeof(MacUeRecfg));
1179       }
1180    }
1181    else
1182    {
1183       DU_LOG("\nERROR  -->  DU_APP: Received macUeRecfg is NULLP at sendUeRecfgReqToMac()");
1184       ret = RFAILED;
1185    }
1186    return ret;
1187 }
1188
1189
1190
1191 /******************************************************************
1192  *
1193  * @brief update DuMacUeCfg structure
1194  *
1195  * @details
1196  *
1197  *    Function : updateDuMacUeCfg
1198  *
1199  *    Functionality: Fills DuMacUeCfg
1200  *
1201  * @params[in]  cellId, ueId, crnti, 
1202  *              DuUeCfg  pointer,
1203  *              DuMacUeCfg pointer
1204  * @return ROK/RFAILED
1205  *
1206  *****************************************************************/
1207 uint8_t updateDuMacUeCfg(uint16_t cellId, uint8_t gnbDuUef1apId, uint16_t crnti, DuUeCfg *ueCfgDb, DuMacUeCfg *duMacUeCfg)
1208 {
1209    uint8_t ret = ROK, dbIdx = 0, lcIdx = 0, cellIdx = 0;
1210    bool lcIdFound = false;
1211    DuMacUeCfg *duMacDb = NULLP;
1212
1213    duMacUeCfg->cellId = cellId;
1214    duMacUeCfg->ueId = gnbDuUef1apId;
1215    duMacUeCfg->crnti = crnti;
1216
1217    if(!ueCfgDb)
1218    {
1219       fillDefaultMacCellGrpInfo(duMacUeCfg);
1220       fillDefaultPhyCellGrpInfo(duMacUeCfg);
1221
1222       if((fillDefaultSpCellGrpInfo(duMacUeCfg)) != ROK)
1223       {
1224          DU_LOG("\nERROR  --> DUAPP : Failed in fillDefaultSpCellGrpInfo");
1225          return RFAILED;
1226       }
1227
1228       duMacUeCfg->ambrCfg = NULLP;
1229       fillDefaultModulation(duMacUeCfg);
1230       fillMacSrb1LcCfg(&duMacUeCfg->lcCfgList[0]);
1231       duMacUeCfg->numLcs++;
1232    }
1233    else
1234    {
1235       if(ueCfgDb->dataTransmissionAction == STOP_TRANSMISSION)
1236       {
1237          duMacUeCfg->transmissionAction = ueCfgDb->dataTransmissionAction; 
1238          return ROK;
1239       }
1240
1241       GET_CELL_IDX(cellId, cellIdx);
1242       if(duCb.actvCellLst[cellIdx])
1243          duMacDb = &duCb.actvCellLst[cellIdx]->ueCb[duMacUeCfg->ueId-1].duMacUeCfg;
1244       else
1245       {
1246          DU_LOG("\nERROR  -->  DU APP : Cell Id [%d] does not exist", cellId);
1247          return RFAILED;
1248       }
1249       duMacDb->macUeCfgState = UE_CFG_INPROGRESS;
1250       
1251       if(ueCfgDb->cellGrpCfg)
1252       {
1253          ret = procUeRecfgCellInfo(duMacUeCfg, duMacDb, ueCfgDb->cellGrpCfg);
1254          if(ret == ROK)
1255          {
1256             if(duMacUeCfg->spCellCfgPres == true)
1257             {
1258                if(duMacUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschPresent)
1259                {
1260                   fillStartSymbolAndLen(duMacUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc,\
1261                         &duMacUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, NULL);
1262                }
1263                if(duMacUeCfg->spCellCfg.servCellCfg.initUlBwp.puschPresent)
1264                {
1265                   fillStartSymbolAndLen(duMacUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
1266                         NULL, &duMacUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg);
1267                }
1268             }
1269
1270             if(duMacDb)
1271                ret = fillAmbr(&duMacUeCfg->ambrCfg, ueCfgDb->ambrCfg , &duMacDb->ambrCfg, FALSE);
1272             else
1273                ret = fillAmbr(&duMacUeCfg->ambrCfg, ueCfgDb->ambrCfg , NULL, FALSE);
1274
1275             duFillModulationDetails(duMacUeCfg, duMacDb, ueCfgDb->ueNrCapability);
1276          }
1277       }
1278       else
1279       {
1280          fillDefaultMacCellGrpInfo(duMacUeCfg);
1281          fillDefaultPhyCellGrpInfo(duMacUeCfg);
1282          fillDefaultSpCellGrpInfo(duMacUeCfg);
1283          fillDefaultModulation(duMacUeCfg);
1284          duMacUeCfg->ambrCfg = NULLP;
1285       }
1286
1287 #ifdef NR_DRX
1288       
1289       duMacUeCfg->drxConfigIndicatorRelease = ueCfgDb->drxConfigIndicatorRelease;
1290
1291       if(ueCfgDb->drxCyclePres)
1292       {
1293          duMacUeCfg->macCellGrpCfg.drxCfg.drxLongCycleStartOffset.drxLongCycleStartOffsetChoice = ueCfgDb->drxCycle.drxLongCycleLength;
1294          if(ueCfgDb->drxCycle.shortDrxCyclePres)
1295          {
1296             duMacUeCfg->macCellGrpCfg.drxCfg.shortDrxPres = true;
1297             duMacUeCfg->macCellGrpCfg.drxCfg.shortDrx.drxShortCycle = ueCfgDb->drxCycle.shortDrxCycle.drxShortCycle;
1298             duMacUeCfg->macCellGrpCfg.drxCfg.shortDrx.drxShortCycleTimer = ueCfgDb->drxCycle.shortDrxCycle.drxShortCycleTimer;
1299          }
1300          else
1301          {
1302             duMacUeCfg->macCellGrpCfg.drxCfg.shortDrxPres = false;
1303          }
1304       }
1305 #endif
1306
1307       /* Filling LC Context */
1308       for(dbIdx = 0; (dbIdx < ueCfgDb->numMacLcs && ret == ROK); dbIdx++)
1309       {
1310          if(!ueCfgDb->macLcCfg[dbIdx].lcConfig.ulLcCfgPres)
1311          {
1312             /* Filling default UL LC config in MAC if not present */
1313             ueCfgDb->macLcCfg[dbIdx].lcConfig.ulLcCfgPres = true;
1314             fillDefaultUlLcCfg(&ueCfgDb->macLcCfg[dbIdx].lcConfig.ulLcCfg);
1315          }
1316
1317          if(duMacDb)
1318          {
1319             for(lcIdx = 0; lcIdx < duMacDb->numLcs; lcIdx++)
1320             {
1321                if(ueCfgDb->macLcCfg[dbIdx].lcConfig.lcId == duMacDb->lcCfgList[lcIdx].lcConfig.lcId)
1322                {
1323                   lcIdFound = true;
1324                   if((ueCfgDb->macLcCfg[dbIdx].configType == CONFIG_UNKNOWN) ||
1325                         (ueCfgDb->macLcCfg[dbIdx].configType == CONFIG_MOD))
1326                   {
1327                      ueCfgDb->macLcCfg[dbIdx].configType = CONFIG_MOD;
1328                      ret = fillMacLcCfgToAddMod(&duMacUeCfg->lcCfgList[dbIdx], &ueCfgDb->macLcCfg[dbIdx],\
1329                            &duMacDb->lcCfgList[lcIdx], FALSE);
1330                   }
1331                }
1332                else
1333                   lcIdFound = false;
1334             }
1335          }
1336
1337          if(!lcIdFound)
1338          {
1339             /* ADD/DEL CONFIG */
1340             ret = fillMacLcCfgToAddMod(&duMacUeCfg->lcCfgList[dbIdx], &ueCfgDb->macLcCfg[dbIdx], NULL, FALSE);
1341          }
1342          if(ret == ROK)
1343          {
1344             duMacUeCfg->numLcs++;
1345          }
1346          else
1347          {
1348             DU_LOG("\nERROR  -->  DU APP : Failed to add Lc at Idx %d in updateDuMacUeCfg()", dbIdx); 
1349             break;
1350          }
1351       }/*End of Outer FOR loop */
1352       memcpy(&ueCfgDb->copyOfmacUeCfg, duMacUeCfg, sizeof(DuMacUeCfg));
1353    }
1354    return ret;
1355 }
1356
1357 /******************************************************************
1358  *
1359  * @brief Fills Rlc AM Information
1360  *
1361  * @details
1362  *
1363  *    Function : fillDefaultAmInfo
1364  *
1365  *    Functionality: Fills Rlc AM Information
1366  *
1367  * @params[in]  AmBearerCfg *amCfg
1368  * @return void
1369  *
1370  *****************************************************************/
1371 void fillDefaultAmInfo(AmBearerCfg *amCfg)
1372 {
1373    /* DL AM */
1374    amCfg->dlAmCfg.snLenDl     = AM_SIZE_12;
1375    amCfg->dlAmCfg.pollRetxTmr = T_POLL_RETRANSMIT_VAL;
1376    amCfg->dlAmCfg.pollPdu     = POLL_PDU_VAL;
1377    amCfg->dlAmCfg.pollByte    = POLL_BYTE_VAL;
1378    amCfg->dlAmCfg.maxRetxTh   = MAX_RETX_THRESHOLD_VAL;   
1379  
1380    /* UL AM */
1381    amCfg->ulAmCfg.snLenUl     = AM_SIZE_12;
1382    amCfg->ulAmCfg.reAssemTmr  = T_REASSEMBLY_VAL; 
1383    amCfg->ulAmCfg.statProhTmr = T_STATUS_PROHIBHIT_VAL;
1384 }
1385
1386 /******************************************************************
1387  *
1388  * @brief Fills RLC UM Bi Directional Information
1389  *
1390  * @details
1391  *
1392  *    Function : fillDefaultUmBiInfo
1393  *
1394  *    Functionality: Fills RLC UM Bi Directional Information
1395  *
1396  * @params[in]  UmBiDirBearerCfg *umBiDirCfg
1397  * @return void
1398  *
1399  *****************************************************************/
1400 void fillDefaultUmBiInfo(UmBiDirBearerCfg *umBiDirCfg)
1401 {
1402    /* UL UM BI DIR INFO */
1403    umBiDirCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1404    umBiDirCfg->ulUmCfg.reAssemTmr = T_REASSEMBLY_VAL;
1405
1406    /* DL UM BI DIR INFO */
1407    umBiDirCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
1408 }
1409
1410 /******************************************************************
1411  *
1412  * @brief Fills RLC UM Uni Directional UL Information
1413  *
1414  * @details
1415  *
1416  *    Function : fillDefaultUmUlInfo
1417  *
1418  *    Functionality: Fills RLC UM Uni Directional Info
1419  *
1420  * @params[in]  UmUniDirUlBearerCfg *UmUlCfg
1421  * @return void
1422  *
1423  *****************************************************************/
1424 void fillDefaultUmUlInfo(UmUniDirUlBearerCfg *UmUlCfg)
1425 {
1426    UmUlCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1427    UmUlCfg->ulUmCfg.reAssemTmr = T_REASSEMBLY_VAL;
1428 }
1429
1430 /******************************************************************
1431  *
1432  * @brief Fills RLC UM Uni Directional DL Information
1433  *
1434  * @details
1435  *
1436  *    Function : fillDefaultUmDlInfo
1437  *
1438  *    Functionality: Fills RLC UM Uni Directional DL Info
1439  *
1440  * @params[in]  UmUniDirDlBearerCfg *UmDlCfg
1441  * @return void
1442  *
1443  *****************************************************************/
1444 void fillDefaultUmDlInfo(UmUniDirDlBearerCfg *UmDlCfg)
1445 {
1446    UmDlCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
1447 }
1448
1449 /******************************************************************
1450  *
1451  * @brief Builds Rlc Mode Default Configuration
1452  *
1453  * @details
1454  *
1455  *    Function : fillDefaultRlcModeCfg
1456  *
1457  *    Functionality: Builds Rlc Mode Default Configuration
1458  *
1459  * @params[in]  rlcMode, RlcBearerCfg *lcCfg
1460  * @return ROK/RFAILED
1461  *
1462  *****************************************************************/
1463
1464 uint8_t fillDefaultRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *lcCfg)
1465 {
1466    if(lcCfg)
1467    {
1468       switch(rlcMode)
1469       {
1470          case RLC_AM :
1471             {
1472                if(!lcCfg->u.amCfg)
1473                {
1474                   DU_ALLOC_SHRABL_BUF(lcCfg->u.amCfg, sizeof(AmBearerCfg));
1475                   if(lcCfg->u.amCfg)
1476                      fillDefaultAmInfo(lcCfg->u.amCfg);
1477                   else
1478                   {
1479                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at AmCfg at fillDefaultRlcModeCfg()");
1480                      return RFAILED;
1481                   }
1482                }
1483                break;
1484             }
1485          case RLC_UM_BI_DIRECTIONAL :
1486             {
1487                if(!lcCfg->u.umBiDirCfg)
1488                {
1489                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
1490                   if(lcCfg->u.umBiDirCfg)
1491                      fillDefaultUmBiInfo(lcCfg->u.umBiDirCfg);
1492                   else
1493                   {
1494                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmBiDirCfg at fillDefaultRlcModeCfg()");
1495                      return RFAILED;
1496                   }
1497                }
1498                break;
1499             }
1500          case RLC_UM_UNI_DIRECTIONAL_UL :
1501             {
1502                if(!lcCfg->u.umUniDirUlCfg)
1503                {
1504                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
1505                   if(lcCfg->u.umUniDirUlCfg)
1506                      fillDefaultUmUlInfo(lcCfg->u.umUniDirUlCfg);
1507                   else
1508                   {
1509                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmUniDirUlCfg at fillDefaultRlcModeCfg()");
1510                      return RFAILED;
1511                   }
1512                }
1513                break;
1514             }
1515          case RLC_UM_UNI_DIRECTIONAL_DL :
1516             {
1517                if(!lcCfg->u.umUniDirDlCfg)
1518                {
1519                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
1520                   if(lcCfg->u.umUniDirDlCfg)
1521                      fillDefaultUmDlInfo(lcCfg->u.umUniDirDlCfg);
1522                   else
1523                   {
1524                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmUniDirDlCfg at fillDefaultRlcModeCfg()");
1525                      return RFAILED;
1526                   }
1527                }
1528                break;
1529             }
1530          default:
1531             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
1532             return RFAILED;
1533       }
1534
1535    }
1536    else
1537    {
1538       DU_LOG("\nERROR  -->  DUAPP: Received LC Config is NULL");
1539       return RFAILED;
1540    }
1541    return ROK;
1542 }
1543
1544 /*******************************************************************
1545  *
1546  * @brief Function to fill Rlc Lc Cfg for SRB1
1547  *
1548  * @details
1549  *
1550  *    Function : fillRlcSrb1LcCfg
1551  *
1552  *    Functionality: 
1553  *     Function to fill Rlc Lc Cfg for SRB1
1554  * 
1555  *  @params[in]     Pointer to RlcBearerCfg
1556  *  @return ROK/RFAILED
1557  * 
1558  *****************************************************************/
1559
1560 uint8_t fillRlcSrb1LcCfg(RlcBearerCfg *rlcLcCfg)
1561 {
1562    uint8_t ret = ROK;
1563
1564    rlcLcCfg->rbId   = SRB1_LCID;
1565    rlcLcCfg->rbType = RB_TYPE_SRB;
1566    rlcLcCfg->lcId   = SRB1_LCID;
1567    rlcLcCfg->lcType = LCH_DCCH;
1568    rlcLcCfg->rlcMode = RLC_AM;
1569    rlcLcCfg->configType = CONFIG_ADD;
1570    ret = fillDefaultRlcModeCfg(rlcLcCfg->rlcMode, rlcLcCfg);
1571    rlcLcCfg->isLcAddModRspSent = true;
1572    return ret;
1573 }
1574
1575 /*******************************************************************
1576  *
1577  * @brief Processes UE ReConfig Req to RLC UL
1578  *
1579  * @details
1580  *
1581  *    Function : sendUeRecfgReqToRlc
1582  *
1583  *    Functionality: 
1584  *     Processes UE Reconfig Req to RLC UL
1585  * 
1586  *  @params[in]     Pointer to RlcUeCfg
1587  *  @return ROK     - success
1588  *          RFAILED - failure
1589  * 
1590  *****************************************************************/
1591
1592 uint8_t sendUeRecfgReqToRlc(RlcUeCfg *rlcUeCfg)
1593 {
1594    uint8_t ret;
1595    Pst pst;
1596    
1597    FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_RECONFIG_REQ);
1598    if(rlcUeCfg)
1599    {
1600       /* Processing one Ue at a time to RLC */
1601       DU_LOG("\nDEBUG   -->  DU_APP: Sending Ue Reconfig Request to RLC UL");
1602       ret = (*packRlcUeReconfigReqOpts[pst.selector])(&pst, rlcUeCfg);
1603       if(ret == RFAILED)
1604       {
1605          DU_LOG("\nERROR  -->  DU_APP : Failed to send Ue Reconfig Req to RLC at sendUeRecfgReqToRlc()");
1606          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rlcUeCfg, sizeof(RlcUeCfg));
1607       }
1608    }
1609    else
1610    {
1611       DU_LOG("\nERROR  -->   DU_APP: Received RlcUeCfg is NULL at sendUeRecfgReqToRlc()");
1612       ret = RFAILED;
1613    }
1614    return ret;
1615 }
1616
1617 /******************************************************************
1618  *
1619  * @brief Fills Snssai information
1620  *
1621  * @details
1622  *
1623  *    Function : fillSnssaiInfo
1624  *
1625  *    Functionality: Fills Snssai information
1626  *
1627  *  @params[in]    LcCfg *snssaiTobeSend, LcCfg *snssaiDb, LcCfg *oldSnssai,
1628  *  Bool toUpdateg
1629  *  @return ROK     - success
1630  *          RFAILED - failure
1631  * 
1632  *****************************************************************/
1633 uint8_t fillSnssaiInfo(Snssai *snssaiTobeSend, Snssai *snssaiDb, Snssai **oldSnssai, Bool toUpdate)
1634 {
1635    if(!toUpdate)
1636    {
1637       if(snssaiDb)
1638          snssaiTobeSend = snssaiDb;
1639       else if(oldSnssai)
1640          snssaiTobeSend = *oldSnssai;
1641       else
1642          snssaiTobeSend = NULL;
1643    }
1644    else
1645    {
1646       if(snssaiDb)
1647       {
1648          if(*oldSnssai)
1649             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, *oldSnssai, sizeof(Snssai));
1650
1651          DU_ALLOC_SHRABL_BUF(*oldSnssai, sizeof(Snssai));
1652          if(*oldSnssai == NULL)
1653          {
1654             DU_LOG("\nERROR  -->  DU APP : Memory Alloc Failed at fillSnssaiInfo()");
1655             return RFAILED;
1656          }
1657          memcpy(*oldSnssai, snssaiDb, sizeof(Snssai));
1658       }
1659    }
1660    return ROK;
1661 }
1662 /******************************************************************
1663  *
1664  * @brief Fills RlcBearerCfg structure
1665  *
1666  * @details
1667  *
1668  *    Function : fillRlcUeCfg
1669  *
1670  *    Functionality: Fills Rlc Bearer Cfg
1671  *
1672  *
1673  *****************************************************************/
1674 uint8_t fillRlcUeCfg(uint16_t cellId, uint8_t duUeF1apId, DuUeCfg *ueCfgDb, RlcUeCfg *rlcUeCfg)
1675 {
1676    uint8_t ret, dbIdx, lcIdx, cellIdx;
1677    bool lcIdFound = false;
1678    RlcUeCfg *duRlcDb = NULLP;
1679
1680    ret = ROK;
1681    rlcUeCfg->cellId       = cellId;
1682    rlcUeCfg->ueId         = duUeF1apId;
1683
1684    if(!ueCfgDb)
1685    {
1686       /* Initial RB being Added */ 
1687       ret = fillRlcSrb1LcCfg(&rlcUeCfg->rlcLcCfg[0]);
1688       if(ret == ROK)
1689          rlcUeCfg->numLcs++;
1690       else
1691          memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
1692    }
1693    else
1694    {
1695       /* Fetch RlcDb from DuUeCb */ 
1696       GET_CELL_IDX(cellId, cellIdx);
1697       duRlcDb = &duCb.actvCellLst[cellIdx]->ueCb[rlcUeCfg->ueId-1].rlcUeCfg;
1698       duRlcDb->rlcUeCfgState = UE_CFG_INPROGRESS;
1699
1700       for(dbIdx = 0; (dbIdx < ueCfgDb->numRlcLcs && ret == ROK); dbIdx++)
1701       {
1702          ret = fillDefaultRlcModeCfg(ueCfgDb->rlcLcCfg[dbIdx].rlcMode, &ueCfgDb->rlcLcCfg[dbIdx]);
1703          if(ret == RFAILED)
1704          {
1705             DU_LOG("\n ERROR  -->  DU APP : Failed to fill Rlc Mode at fillRlcUeCfg()");
1706             memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
1707             return ret;
1708          }
1709
1710          if(duRlcDb)
1711          {
1712             /* Fill Rlc Ue Cfg List for ADD/MOD/DEL */
1713             for(lcIdx = 0; lcIdx < duRlcDb->numLcs; lcIdx++)
1714             { 
1715                if(ueCfgDb->rlcLcCfg[dbIdx].lcId == duRlcDb->rlcLcCfg[lcIdx].lcId)
1716                {
1717                   lcIdFound = true;
1718                   if((ueCfgDb->rlcLcCfg[dbIdx].configType == CONFIG_UNKNOWN)||
1719                         (ueCfgDb->rlcLcCfg[dbIdx].configType == CONFIG_MOD))
1720                   {
1721                      /* MOD */ 
1722                      ueCfgDb->rlcLcCfg[dbIdx].configType = CONFIG_MOD; /* update Db for MOD type */
1723                      memcpy(&rlcUeCfg->rlcLcCfg[dbIdx], &ueCfgDb->rlcLcCfg[dbIdx], sizeof(RlcBearerCfg));
1724                      fillSnssaiInfo(rlcUeCfg->rlcLcCfg[dbIdx].snssai, ueCfgDb->rlcLcCfg[dbIdx].snssai,\
1725                            &duRlcDb->rlcLcCfg[lcIdx].snssai,false);
1726                   }
1727                }
1728                else
1729                   lcIdFound = false;
1730             }
1731          }
1732
1733          if(!lcIdFound)
1734          {
1735             /* ADD/ DEL Config Type */
1736             memcpy(&rlcUeCfg->rlcLcCfg[dbIdx], &ueCfgDb->rlcLcCfg[dbIdx], sizeof(RlcBearerCfg));
1737             fillSnssaiInfo(rlcUeCfg->rlcLcCfg[dbIdx].snssai, ueCfgDb->rlcLcCfg[dbIdx].snssai, NULL, false);
1738          }
1739          rlcUeCfg->numLcs++;
1740       }
1741    }
1742    return ret;
1743 }
1744
1745 /******************************************************************
1746  *
1747  * @brief creates UE context
1748  *
1749  * @details
1750  *
1751  *    Function : duCreateUeCb
1752  *
1753  *    Functionality: Creates UE Conetxt
1754  *
1755  * @params[in] UeCcchCtxt Pointer
1756  *             UeIdx Pointer
1757  *
1758  * @return ROK     - success
1759  *         RFAILED - failure
1760  * ****************************************************************/
1761 uint8_t duCreateUeCb(UeCcchCtxt *ueCcchCtxt, uint32_t gnbCuUeF1apId)
1762 {
1763    uint8_t cellIdx = 0;
1764    uint8_t ret     = ROK;
1765    uint8_t ueId = 0, ueIdx = 0;
1766
1767    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
1768    {
1769       if(duCb.actvCellLst[cellIdx] && (ueCcchCtxt->cellId == duCb.actvCellLst[cellIdx]->cellId))
1770       {
1771          GET_UE_ID(ueCcchCtxt->crnti, ueId);
1772          DU_LOG("\nDEBUG   -->  DU_APP: Filling UeCb for ueId [%d]", ueId);
1773
1774          ueIdx = ueId-1;
1775          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].f1UeDb        = NULLP;
1776          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti         = ueCcchCtxt->crnti;
1777          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId = ueCcchCtxt->gnbDuUeF1apId;
1778          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId = gnbCuUeF1apId;
1779          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].drbBitMap     = NULLP;
1780          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState       = UE_ACTIVE;
1781
1782          /* Filling Mac Ue Config */ 
1783          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duMacUeCfg, 0, sizeof(DuMacUeCfg));
1784          ret = duBuildAndSendUeCreateReqToMac(ueCcchCtxt->cellId, ueCcchCtxt->gnbDuUeF1apId, ueCcchCtxt->crnti, NULL, 
1785                &duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duMacUeCfg);
1786          if(ret == RFAILED)
1787             DU_LOG("\nERROR  -->  DU APP : Failed to send UE create request to MAC");
1788
1789          /* Filling Rlc Ue Config */
1790          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg, 0, sizeof(RlcUeCfg));
1791          ret = duBuildAndSendUeCreateReqToRlc(ueCcchCtxt->cellId, ueCcchCtxt->gnbDuUeF1apId, NULL,
1792                &duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg);
1793          if(ret == RFAILED)
1794             DU_LOG("\nERROR  -->  DU APP : Failed to send UE create request to RLC");
1795
1796          duCb.actvCellLst[cellIdx]->numActvUes++;
1797          memset(ueCcchCtxt, 0, sizeof(UeCcchCtxt));
1798          duCb.numUe--;
1799       }
1800    }
1801    return ret;
1802 }
1803
1804 /**********************************************************************************
1805  *
1806  * @brief Fills Ue Cfg from DU DB to MacUeCfg
1807  *
1808  * @details
1809  *
1810  *    Function : fillMacUeCfg
1811  *
1812  *    Functionality: fills ue Cfg to be sent to MAC
1813  *
1814  * @params[in] DuMacUeCfg Pointer
1815  *             MacUeCfg Pointer
1816  *
1817  * @return ROK     - success
1818  *         RFAILED - failure
1819  * *******************************************************************************/
1820 void fillMacUeCfg(DuMacUeCfg *duMacUeCfg, MacUeCfg *macUeCfg)
1821 {
1822    uint8_t lcIdx = 0;
1823
1824    macUeCfg->cellId = duMacUeCfg->cellId;
1825    macUeCfg->ueId = duMacUeCfg->ueId;
1826    macUeCfg->crnti = duMacUeCfg->crnti;
1827    macUeCfg->macCellGrpCfgPres = duMacUeCfg->macCellGrpCfgPres;
1828    if(macUeCfg->macCellGrpCfgPres)
1829    {
1830       memcpy(&macUeCfg->macCellGrpCfg, &duMacUeCfg->macCellGrpCfg, sizeof(MacCellGrpCfg));
1831    }
1832    macUeCfg->phyCellGrpCfgPres = duMacUeCfg->phyCellGrpCfgPres;
1833    if(macUeCfg->phyCellGrpCfgPres)
1834    {
1835       memcpy(&macUeCfg->phyCellGrpCfg, &duMacUeCfg->phyCellGrpCfg, sizeof(PhyCellGrpCfg));
1836    }
1837    macUeCfg->spCellCfgPres = duMacUeCfg->spCellCfgPres;
1838    if(macUeCfg->spCellCfgPres)
1839    {
1840       macUeCfg->spCellCfg.servCellIdx = duMacUeCfg->spCellCfg.servCellIdx;
1841       macUeCfg->spCellCfg.servCellCfg.initDlBwp = duMacUeCfg->spCellCfg.servCellCfg.initDlBwp;
1842       macUeCfg->spCellCfg.servCellCfg.numDlBwpToAdd = duMacUeCfg->spCellCfg.servCellCfg.numDlBwpToAddOrMod;
1843       if(macUeCfg->spCellCfg.servCellCfg.numDlBwpToAdd > 0)
1844       {
1845          memcpy(macUeCfg->spCellCfg.servCellCfg.dlBwpToAddList, duMacUeCfg->spCellCfg.servCellCfg.dlBwpToAddOrModList, \
1846                    (sizeof(DlBwpInfo) * MAX_NUM_BWP));
1847       }
1848       macUeCfg->spCellCfg.servCellCfg.firstActvDlBwpId = duMacUeCfg->spCellCfg.servCellCfg.firstActvDlBwpId;
1849       macUeCfg->spCellCfg.servCellCfg.defaultDlBwpId = duMacUeCfg->spCellCfg.servCellCfg.defaultDlBwpId;
1850       macUeCfg->spCellCfg.servCellCfg.bwpInactivityTmr = duMacUeCfg->spCellCfg.servCellCfg.bwpInactivityTmr;
1851       memcpy(&macUeCfg->spCellCfg.servCellCfg.pdschServCellCfg, &duMacUeCfg->spCellCfg.servCellCfg.pdschServCellCfg, sizeof(PdschServCellCfg));
1852       memcpy(&macUeCfg->spCellCfg.servCellCfg.initUlBwp, &duMacUeCfg->spCellCfg.servCellCfg.initUlBwp, sizeof(InitialUlBwp));
1853       macUeCfg->spCellCfg.servCellCfg.numUlBwpToAdd = duMacUeCfg->spCellCfg.servCellCfg.numUlBwpToAddOrMod;
1854       if(macUeCfg->spCellCfg.servCellCfg.numUlBwpToAdd > 0)
1855       {
1856          memcpy(macUeCfg->spCellCfg.servCellCfg.ulBwpToAddList, duMacUeCfg->spCellCfg.servCellCfg.ulBwpToAddOrModList,\
1857                  (sizeof(UlBwpInfo) * MAX_NUM_BWP));
1858       }
1859       macUeCfg->spCellCfg.servCellCfg.firstActvUlBwpId =  duMacUeCfg->spCellCfg.servCellCfg.firstActvUlBwpId;
1860    }
1861    if(duMacUeCfg->ambrCfg != NULLP)
1862    {
1863       memcpy(macUeCfg->ambrCfg, duMacUeCfg->ambrCfg, sizeof(AmbrCfg));
1864    }
1865    memcpy(&macUeCfg->dlModInfo, &duMacUeCfg->dlModInfo, sizeof(ModulationInfo));
1866    memcpy(&macUeCfg->ulModInfo, &duMacUeCfg->ulModInfo, sizeof(ModulationInfo));
1867    if(duMacUeCfg->numLcs > 0)
1868    {
1869       macUeCfg->numLcs = 0;
1870       for(lcIdx = 0; lcIdx < duMacUeCfg->numLcs; lcIdx++)
1871       {
1872          if(duMacUeCfg->lcCfgList[lcIdx].configType == CONFIG_ADD)
1873          {
1874             //VS: To thoroughly check
1875             memcpy(&macUeCfg->lcCfgList[macUeCfg->numLcs], &duMacUeCfg->lcCfgList[lcIdx].lcConfig, sizeof(LcCfg));
1876             macUeCfg->numLcs++;
1877          }
1878       }
1879    }
1880 }
1881
1882 /******************************************************************
1883  *
1884  * @brief Builds and Send UE Create Request to MAC
1885  *
1886  * @details
1887  *
1888  *    Function : duBuildAndSendUeCreateReqToMac
1889  *
1890  *    Functionality: Builds and Send UE Create Request to MAC
1891  *
1892  * @Params[in]  cellId,
1893  *              ueId,
1894  *              crnti,
1895  *              UE config extracted from F1AP msg
1896  *              MAC UE config struct to be filled
1897  * @return ROK     - success
1898  *         RFAILED - failure
1899  *
1900  * ****************************************************************/
1901
1902 uint8_t duBuildAndSendUeCreateReqToMac(uint16_t cellId, uint8_t gnbDuUeF1apId, uint16_t crnti, DuUeCfg *ueCfgDb, DuMacUeCfg *duMacUeCfg)
1903 {
1904    uint8_t  ret = ROK;
1905    MacUeCfg *macUeCfg = NULLP;
1906    Pst       pst;
1907    memset(&pst, 0, sizeof(Pst));
1908
1909
1910    ret = updateDuMacUeCfg(cellId, gnbDuUeF1apId, crnti, ueCfgDb, duMacUeCfg);
1911    if(ret == RFAILED)
1912    {
1913       DU_LOG("\nERROR  -->  DU APP : Failed to fill MacUeCfg at duBuildAndSendUeCreateReqToMac()");
1914       return RFAILED;
1915    }
1916
1917    /* Fill Pst */
1918    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_CREATE_REQ);
1919
1920    /* Copying ueCb to a sharable buffer */
1921    DU_ALLOC_SHRABL_BUF(macUeCfg, sizeof(MacUeCfg));
1922    if(macUeCfg)
1923    {
1924       memset(macUeCfg, 0, sizeof(MacUeCfg));
1925       fillMacUeCfg(duMacUeCfg, macUeCfg); 
1926       DU_LOG("\nDEBUG   -->  DU_APP: Sending UE create request to MAC");
1927
1928       /* Processing one Ue at a time to MAC */
1929       ret = (*packMacUeCreateReqOpts[pst.selector])(&pst, macUeCfg);
1930       if(ret == RFAILED)
1931       {
1932          DU_LOG("\nERROR  -->  DU_APP : Failure in sending Ue Create Req to MAC at duBuildAndSendUeCreateReqToMac()");
1933          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macUeCfg, sizeof(MacUeCfg));
1934       }
1935    }
1936    else
1937    {
1938       DU_LOG("\n ERROR  -->  DU APP : Memory alloc failed at duBuildAndSendUeCreateReqToMac()");
1939       ret = RFAILED;
1940    }
1941    return ret;
1942 }
1943
1944 /*******************************************************************
1945  *
1946  * @brief Build and send RACH Resource request to MAC
1947  *
1948  * @details
1949  *
1950  *    Function : duBuildAndSendRachRsrcReqToMac
1951  *    Functionality:
1952  *        Build and send RACH Resource request to MAC
1953  *
1954  * @params[in] Cell Id
1955  *             UE Id
1956  * @return ROK     - success
1957  *         RFAILED - failure
1958  *
1959  * ****************************************************************/
1960 uint8_t duBuildAndSendRachRsrcReqToMac(uint16_t cellId, uint16_t ueId)
1961 {
1962    uint16_t cellIdx = 0, ssbIdx = 0;
1963    Pst pst;
1964    MacRachRsrcReq *rachRsrcReq = NULLP;
1965
1966    GET_CELL_IDX(cellId, cellIdx);
1967    if(duCb.actvCellLst[cellIdx] == NULLP)
1968    {
1969       DU_LOG("\nERROR  -->  DU APP : Cell Id [%d] not found in duBuildAndSendRachRsrcReqToMac()", cellId);
1970       return RFAILED;
1971    }
1972
1973    DU_ALLOC_SHRABL_BUF(rachRsrcReq, sizeof(MacRachRsrcReq));
1974    if(!rachRsrcReq)
1975    {
1976       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH Resource Request in \
1977             duBuildAndSendRachRsrcReqToMac()");
1978       return RFAILED;
1979    }
1980
1981    rachRsrcReq->cellId = cellId;
1982    rachRsrcReq->ueId = ueId;
1983    rachRsrcReq->numSsb = duCfgParam.macCellCfg.prachCfg.ssbPerRach;
1984    for(ssbIdx = 0; ssbIdx < rachRsrcReq->numSsb; ssbIdx++)
1985    {
1986       rachRsrcReq->ssbIdx[ssbIdx] = ssbIdx;
1987    }
1988
1989    /* Fill Pst */
1990    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_RACH_RESOURCE_REQ);
1991    
1992    if(((*packMacRachRsrcReqOpts[pst.selector])(&pst, rachRsrcReq)) != ROK)
1993    {
1994       DU_LOG("\nERROR  -->  DU_APP : Failure in sending RACH Resource Request to MAC at \
1995             duBuildAndSendRachRsrcReqToMac()");
1996       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rachRsrcReq, sizeof(MacRachRsrcReq));
1997       return RFAILED;
1998    }
1999
2000    return ROK;
2001 }
2002
2003 /*******************************************************************
2004  *
2005  * @brief Process RACH resource response from MAC
2006  *
2007  * @details
2008  *
2009  *    Function : DuProcMacRachRsrcRsp
2010  *    Functionality:
2011  *        Process RACH resource response from MAC
2012  *
2013  * @params[in] Post structure
2014  *             RACH resource response
2015  * @return ROK     - success
2016  *         RFAILED - failure
2017  *
2018  * ****************************************************************/
2019 uint8_t DuProcMacRachRsrcRsp(Pst *pst, MacRachRsrcRsp *rachRsrcRsp)
2020 {
2021    uint8_t  ret = RFAILED;
2022    uint16_t cellIdx = 0;
2023    DuCellCb *cellCb = NULLP;
2024    DuUeCb   *ueCb = NULLP;
2025
2026    DU_LOG("\nINFO  -->  DU APP : Received RACH Resource Response from MAC. Cell ID [%d] UE ID [%d]",
2027          rachRsrcRsp->cellId, rachRsrcRsp->ueId);
2028
2029    if(rachRsrcRsp->result == MAC_DU_APP_RSP_OK)
2030    {
2031       DU_LOG("\nINFO : DU APP : RACH Resource Response from MAC : Result [SUCCESS]");
2032
2033       /* Fetch Cell Cb */
2034       GET_CELL_IDX(rachRsrcRsp->cellId, cellIdx);
2035       if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->cellId == rachRsrcRsp->cellId))
2036       {
2037          cellCb = duCb.actvCellLst[cellIdx];
2038
2039          /* Fetch UE CB */
2040          if(cellCb->ueCb[rachRsrcRsp->ueId-1].gnbDuUeF1apId == rachRsrcRsp->ueId)
2041          {
2042             ueCb = &cellCb->ueCb[rachRsrcRsp->ueId-1];
2043
2044             /* Store CRNTI alloted to this UE by MAC */
2045             ueCb->crnti = rachRsrcRsp->newCrnti;
2046
2047             /* Store the assigned CF-RA resources */
2048             memcpy(&ueCb->cfraResource, &rachRsrcRsp->cfraResource, sizeof(MacCfraResource));
2049
2050             /* RACH resources allocated to UE is sent to CU in UE Context Setup Response
2051              * along with the result of UE Context setup requested by CU */
2052             if((ret = BuildAndSendUeCtxtRsp(rachRsrcRsp->cellId, rachRsrcRsp->ueId)) != ROK)
2053                DU_LOG("\nERROR  ->  DU APP : Failure in BuildAndSendUeCtxtRsp()");
2054          }
2055          else
2056             DU_LOG("\nERROR  -->  DU APP : UE ID [%d] not found in DuProcMacRachRsrcRsp", rachRsrcRsp->ueId);
2057       }
2058       else
2059          DU_LOG("\nERROR  -->  DU APP : Cell ID [%d] not found in DuProcMacRachRsrcRsp", rachRsrcRsp->cellId);
2060    }
2061    else
2062       DU_LOG("\nINFO : DU APP : RACH Resource Response from MAC : Result [FAILURE]");
2063
2064    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rachRsrcRsp, sizeof(MacRachRsrcRsp));
2065    return ret;
2066 }
2067
2068 /*******************************************************************
2069  *
2070  * @brief To update DuUeCb Mac Cfg
2071  *
2072  * @details
2073  *
2074  *    Function : duUpdateMacCfg
2075  *    Functionality:  update DuUeCb MAC Cfg
2076  *
2077  * @params[in] DuUeCb Pointer
2078  *             F1UeContextSetupDb pointer 
2079  * @return ROK     - success
2080  *         RFAILED - failure
2081  *
2082  * ****************************************************************/
2083 uint8_t duUpdateMacCfg(DuMacUeCfg *macUeCfg, F1UeContextSetupDb *f1UeDb) 
2084 {
2085    uint8_t ret, lcIdx, dbIdx, numLcs, lcDelIdx, cellIdx;
2086    DuMacUeCfg *oldMacUeCfg;
2087    ret = ROK;
2088
2089    GET_CELL_IDX(macUeCfg->cellId, cellIdx);
2090    if(duCb.actvCellLst[cellIdx] == NULLP)
2091    {
2092       DU_LOG("\nERROR  --> DU APP: CellId[%d] not found", macUeCfg->cellId);
2093       return RFAILED;
2094    }
2095    oldMacUeCfg = &duCb.actvCellLst[cellIdx]->ueCb[macUeCfg->ueId-1].duMacUeCfg;
2096
2097    /*Filling Cell Group Cfg*/
2098    ret =  procUeRecfgCellInfo(macUeCfg, &f1UeDb->duUeCfg.copyOfmacUeCfg, f1UeDb->duUeCfg.cellGrpCfg);
2099 #ifdef NR_DRX
2100    memcpy(&macUeCfg->macCellGrpCfg.drxCfg, &f1UeDb->duUeCfg.copyOfmacUeCfg.macCellGrpCfg.drxCfg, sizeof(DrxCfg));
2101 #endif
2102    if(ret == ROK)
2103    {
2104       if(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschPresent)
2105       {
2106          fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc,\
2107                &macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, NULL);
2108       }
2109       if(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschPresent)
2110       {
2111          fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
2112                NULL, &macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg);
2113       }
2114       ret = fillAmbr(NULL, f1UeDb->duUeCfg.ambrCfg, &oldMacUeCfg->ambrCfg, true);
2115       duFillModulationDetails(macUeCfg, oldMacUeCfg, f1UeDb->duUeCfg.ueNrCapability);
2116    }
2117
2118    /* Filling LC Context */
2119    for(dbIdx = 0; (dbIdx < f1UeDb->duUeCfg.numMacLcs && ret == ROK); dbIdx++)
2120    {
2121       numLcs = macUeCfg->numLcs;
2122       for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
2123       {
2124          if(f1UeDb->duUeCfg.macLcCfg[dbIdx].lcConfig.lcId ==  macUeCfg->lcCfgList[lcIdx].lcConfig.lcId)
2125          {
2126             if(f1UeDb->duUeCfg.macLcCfg[dbIdx].configType == CONFIG_MOD)
2127             {
2128                ret = fillMacLcCfgToAddMod(NULL, &f1UeDb->duUeCfg.macLcCfg[dbIdx], &macUeCfg->lcCfgList[lcIdx], true);
2129             }
2130             else if(f1UeDb->duUeCfg.macLcCfg[dbIdx].configType == CONFIG_DEL)
2131             {
2132                /* Free memory at matched  lcIdx index */
2133                freeMacLcCfg(&macUeCfg->lcCfgList[lcIdx].lcConfig);
2134                macUeCfg->numLcs--;
2135                for(lcDelIdx = lcIdx; lcDelIdx < macUeCfg->numLcs; lcDelIdx++)
2136                {
2137                   /* moving all elements one index ahead */
2138                   ret = fillMacLcCfgToAddMod(NULL,  &macUeCfg->lcCfgList[lcDelIdx+1], &macUeCfg->lcCfgList[lcDelIdx], true);
2139                   freeMacLcCfg(&macUeCfg->lcCfgList[lcDelIdx+1].lcConfig);
2140                   if(ret == RFAILED)
2141                   {
2142                      DU_LOG("\nERROR  -->  DU APP : Failed to delete LC at Idx %d in duUpdateMacCfg()", lcDelIdx);
2143                      break;
2144                   }
2145                }
2146             }
2147          }
2148       } 
2149       if(f1UeDb->duUeCfg.macLcCfg[dbIdx].configType == CONFIG_ADD)
2150       {
2151          ret = fillMacLcCfgToAddMod(NULL, &f1UeDb->duUeCfg.macLcCfg[dbIdx], &macUeCfg->lcCfgList[numLcs], true);
2152          if(ret == RFAILED)
2153          {
2154             DU_LOG("\nERROR  -->  DU APP : Failed to add LC at Idx %d in duUpdateMacCfg()", numLcs);
2155             break;
2156          }
2157          macUeCfg->numLcs++;
2158       }
2159
2160    }
2161    return ret;
2162 }
2163
2164 /******************************************************************
2165  *
2166  * @brief Function to fill the RLC Lc cfg from ueSetupReqDb
2167  *
2168  * @details
2169  *
2170  *    Function : fillRlcCfgToAddMod
2171  *
2172  *    Functionality: Function to fill the RLC Lc cfg from ueSetupReqDb
2173  *
2174  *
2175  *****************************************************************/
2176
2177 uint8_t fillRlcCfgToAddMod(RlcBearerCfg *lcCfg, RlcBearerCfg *f1UeDbLcCfg)
2178 {
2179    lcCfg->configType = f1UeDbLcCfg->configType;
2180    lcCfg->rbId       = f1UeDbLcCfg->rbId;
2181    lcCfg->rbType     = f1UeDbLcCfg->rbType;
2182    lcCfg->lcId       = f1UeDbLcCfg->lcId;
2183    lcCfg->lcType     = f1UeDbLcCfg->lcType;
2184    lcCfg->rlcMode    = f1UeDbLcCfg->rlcMode;
2185    
2186    switch(lcCfg->rlcMode)
2187    {
2188       case RLC_AM :
2189          {
2190             if(!lcCfg->u.amCfg)
2191             {
2192                DU_ALLOC_SHRABL_BUF(lcCfg->u.amCfg, sizeof(AmBearerCfg));
2193                if(!lcCfg->u.amCfg)
2194                   return RFAILED;
2195             }
2196             /* DL AM */
2197             lcCfg->u.amCfg->dlAmCfg.snLenDl     = f1UeDbLcCfg->u.amCfg->dlAmCfg.snLenDl;    
2198             lcCfg->u.amCfg->dlAmCfg.pollRetxTmr = f1UeDbLcCfg->u.amCfg->dlAmCfg.pollRetxTmr;
2199             lcCfg->u.amCfg->dlAmCfg.pollPdu     = f1UeDbLcCfg->u.amCfg->dlAmCfg.pollPdu;
2200             lcCfg->u.amCfg->dlAmCfg.pollByte    = f1UeDbLcCfg->u.amCfg->dlAmCfg.pollByte;   
2201             lcCfg->u.amCfg->dlAmCfg.maxRetxTh   = f1UeDbLcCfg->u.amCfg->dlAmCfg.maxRetxTh;   
2202
2203             /* UL AM */
2204             lcCfg->u.amCfg->ulAmCfg.snLenUl     = f1UeDbLcCfg->u.amCfg->ulAmCfg.snLenUl;
2205             lcCfg->u.amCfg->ulAmCfg.reAssemTmr  = f1UeDbLcCfg->u.amCfg->ulAmCfg.reAssemTmr; 
2206             lcCfg->u.amCfg->ulAmCfg.statProhTmr = f1UeDbLcCfg->u.amCfg->ulAmCfg.statProhTmr;
2207             break;
2208          }
2209       case RLC_UM_BI_DIRECTIONAL :
2210          {
2211             if(!lcCfg->u.umBiDirCfg)
2212             {
2213                DU_ALLOC_SHRABL_BUF(lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
2214                if(!lcCfg->u.umBiDirCfg)
2215                   return RFAILED;
2216             }
2217             /* UL UM BI DIR INFO */
2218             lcCfg->u.umBiDirCfg->ulUmCfg.snLenUlUm  = f1UeDbLcCfg->u.umBiDirCfg->ulUmCfg.snLenUlUm;  
2219             lcCfg->u.umBiDirCfg->ulUmCfg.reAssemTmr = f1UeDbLcCfg->u.umBiDirCfg->ulUmCfg.reAssemTmr;
2220             /* DL UM BI DIR INFO */
2221             lcCfg->u.umBiDirCfg->dlUmCfg.snLenDlUm  = f1UeDbLcCfg->u.umBiDirCfg->dlUmCfg.snLenDlUm;
2222             break;
2223          }
2224       case RLC_UM_UNI_DIRECTIONAL_UL :
2225          {
2226             if(!lcCfg->u.umUniDirUlCfg)
2227             {
2228                DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
2229                if(!lcCfg->u.umUniDirUlCfg)
2230                   return RFAILED;
2231             }
2232             lcCfg->u.umUniDirUlCfg->ulUmCfg.snLenUlUm  = f1UeDbLcCfg->u.umUniDirUlCfg->ulUmCfg.snLenUlUm;  
2233             lcCfg->u.umUniDirUlCfg->ulUmCfg.reAssemTmr = f1UeDbLcCfg->u.umUniDirUlCfg->ulUmCfg.reAssemTmr;
2234             break;
2235
2236          }
2237       case RLC_UM_UNI_DIRECTIONAL_DL :
2238          {
2239             if(!lcCfg->u.umUniDirDlCfg)
2240             {
2241                DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
2242                if(!lcCfg->u.umUniDirDlCfg)
2243                   return RFAILED;
2244             }
2245             lcCfg->u.umUniDirDlCfg->dlUmCfg.snLenDlUm  = f1UeDbLcCfg->u.umUniDirDlCfg->dlUmCfg.snLenDlUm;
2246             break;
2247          }
2248       default:
2249          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at fillRlcCfgToAddMod()", lcCfg->rlcMode);
2250          return RFAILED;
2251    }
2252    return ROK;
2253 }
2254
2255 /*******************************************************************
2256  *
2257  * @brief To update DuUeCb Rlc Lc Cfg
2258  *
2259  * @details
2260  *
2261  *    Function : duUpdateRlcLcCfg
2262  *    Functionality:  update DuUeCb Rlc Lc Cfg
2263  *
2264  * @params[in] DuUeCb Pointer
2265  *             F1UeContextSetupDb pointer 
2266  * @return ROK     - success
2267  *         RFAILED - failure
2268  *
2269  * ****************************************************************/
2270
2271 uint8_t duUpdateRlcLcCfg(RlcUeCfg *rlcUeCfg, F1UeContextSetupDb *f1UeDb)
2272 {
2273    uint8_t ret, lcIdx, dbIdx, numLcs, lcDelIdx;
2274
2275    ret = ROK;
2276    for(dbIdx = 0; (dbIdx < f1UeDb->duUeCfg.numRlcLcs && ret ==ROK); dbIdx++)
2277    {
2278       numLcs = rlcUeCfg->numLcs;
2279       for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
2280       {
2281          if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].lcId == rlcUeCfg->rlcLcCfg[lcIdx].lcId)
2282          {
2283             if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].configType == CONFIG_MOD)
2284             {
2285                ret = fillRlcCfgToAddMod(&rlcUeCfg->rlcLcCfg[lcIdx], &f1UeDb->duUeCfg.rlcLcCfg[dbIdx]);
2286                if(ret == RFAILED)
2287                {
2288                   DU_LOG("\nERROR  -->  DU APP : Failed to modify LC at Idx %d in duUpdateRlcCfg()", lcDelIdx);
2289                   break;
2290                }
2291                fillSnssaiInfo(NULL, f1UeDb->duUeCfg.rlcLcCfg[dbIdx].snssai, &rlcUeCfg->rlcLcCfg[lcIdx].snssai, true);
2292             }
2293             else if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].configType == CONFIG_DEL)
2294             {
2295                /* Free memory at matched lcIdx index */
2296                freeRlcLcCfg(&rlcUeCfg->rlcLcCfg[lcIdx]);
2297                rlcUeCfg->numLcs--;
2298                for(lcDelIdx = lcIdx; lcDelIdx < rlcUeCfg->numLcs; lcDelIdx++)
2299                {
2300                   ret = fillRlcCfgToAddMod(&rlcUeCfg->rlcLcCfg[lcDelIdx], &rlcUeCfg->rlcLcCfg[lcDelIdx+1]);
2301                   fillSnssaiInfo(NULL, rlcUeCfg->rlcLcCfg[lcDelIdx+1].snssai, &rlcUeCfg->rlcLcCfg[lcDelIdx].snssai,\
2302                   true);
2303                   freeRlcLcCfg(&rlcUeCfg->rlcLcCfg[lcDelIdx+1]);
2304                   if(ret == RFAILED)
2305                   {
2306                      DU_LOG("\nERROR  -->  DU APP : Failed to delete LC at Idx %d in duUpdateRlcCfg()", lcDelIdx);
2307                      break;
2308                   }
2309                }
2310             }
2311          }
2312       }
2313       if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].configType == CONFIG_ADD)
2314       {
2315          ret = fillRlcCfgToAddMod(&rlcUeCfg->rlcLcCfg[lcIdx], &f1UeDb->duUeCfg.rlcLcCfg[dbIdx]);
2316          if(ret == ROK)
2317          {    
2318             fillSnssaiInfo(NULL, f1UeDb->duUeCfg.rlcLcCfg[dbIdx].snssai, &rlcUeCfg->rlcLcCfg[ rlcUeCfg->numLcs].snssai,\
2319                   true);
2320             rlcUeCfg->numLcs++;
2321          }
2322       }
2323    }
2324    return ret;
2325 }
2326
2327 /*******************************************************************
2328  *
2329  * @brief Function to fill Tunnel Config to Add/Mod
2330  * 
2331  *
2332  * @details
2333  *
2334  *    Function : fillTnlCfgToAddMod
2335  *
2336  *    Functionality: Function to fill tunnel Config to Add/Mod
2337  *
2338  * @params[in] Pointer to tnlCfgDb,
2339  *             pointer to f1TnlCfg
2340  * @return ROK     - success
2341  *         RFAILED - failure
2342  *
2343  * ****************************************************************/
2344 uint8_t fillTnlCfgToAddMod(UpTnlCfg **ueCbTnlCfg, UpTnlCfg *f1TnlCfg)
2345 {
2346    if(*ueCbTnlCfg)
2347    {
2348       DU_FREE((*ueCbTnlCfg)->tnlCfg1, sizeof(GtpTnlCfg));
2349       DU_FREE(*ueCbTnlCfg, sizeof(UpTnlCfg));
2350    }
2351
2352    if(*ueCbTnlCfg == NULLP)
2353    {
2354       /* copying to DuCb Tnl Cfg */
2355       DU_ALLOC(*ueCbTnlCfg, sizeof(UpTnlCfg));
2356       if(*ueCbTnlCfg == NULLP)
2357       {
2358          DU_LOG("\nERROR  -->  DU_APP : fillTnlCfgToAddMod: Memory Alloc failed for drbId[%d]", f1TnlCfg->drbId);
2359          return RFAILED;
2360       }
2361    }
2362    memset(*ueCbTnlCfg, 0, sizeof(UpTnlCfg));
2363    (*ueCbTnlCfg)->configType = f1TnlCfg->configType;
2364    (*ueCbTnlCfg)->cellId    = f1TnlCfg->cellId;
2365    (*ueCbTnlCfg)->ueId      = f1TnlCfg->ueId;
2366    (*ueCbTnlCfg)->drbId     = f1TnlCfg->drbId;
2367    if(f1TnlCfg->tnlCfg1)
2368    {
2369       if((*ueCbTnlCfg)->tnlCfg1 == NULLP)
2370       {
2371          DU_ALLOC((*ueCbTnlCfg)->tnlCfg1, sizeof(GtpTnlCfg));
2372          if((*ueCbTnlCfg)->tnlCfg1 == NULLP)
2373          {
2374             DU_LOG("\nERROR  -->  DU_APP : fillTnlCfgToAddMod: Memory Alloc failed for tnlCfg1 for drbId[%d]", f1TnlCfg->drbId);
2375             return RFAILED;
2376          }
2377       }
2378       memset((*ueCbTnlCfg)->tnlCfg1, 0, sizeof(GtpTnlCfg));
2379       (*ueCbTnlCfg)->tnlCfg1->teId = f1TnlCfg->tnlCfg1->teId;
2380       (*ueCbTnlCfg)->tnlCfg1->ulTnlAddress = f1TnlCfg->tnlCfg1->ulTnlAddress;
2381       (*ueCbTnlCfg)->tnlCfg1->dlTnlAddress = f1TnlCfg->tnlCfg1->dlTnlAddress;
2382    }
2383    return ROK;
2384 }
2385
2386 /*******************************************************************
2387  *
2388  * @brief Processing the tunnel Request to EGTP
2389  *        
2390  * @details
2391  *
2392  *    Function : duProcEgtpTunnelCfg
2393  *
2394  *    Functionality: Processing the tunnel Request to EGTP
2395  *
2396  * @params[in] UptnlCfg *duTnlCfg, UpTnlCfg *f1TnlCfg 
2397  * @return ROK     - success
2398  *         RFAILED - failure
2399  *
2400  * ****************************************************************/
2401
2402 uint8_t duProcEgtpTunnelCfg(uint8_t ueCbIdx, UpTnlCfg *duTnlCfg, UpTnlCfg *f1TnlCfg)
2403 {
2404    uint8_t ret = RFAILED, delIdx;
2405
2406    if(f1TnlCfg->tnlCfg1 == NULLP)
2407    {
2408       DU_LOG("\nERROR  -->  DU_APP : Tunnel config not found");
2409       return ret;
2410    }
2411
2412    if(f1TnlCfg->configType == CONFIG_ADD)
2413    {
2414       if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_ADD, NULLP, f1TnlCfg->tnlCfg1) == ROK)
2415       {
2416          if(fillTnlCfgToAddMod(&duCb.upTnlCfg[duCb.numTeId], f1TnlCfg) == ROK)
2417          {
2418             duCb.numTeId++;
2419             ret = ROK;
2420          }
2421       }      
2422    }
2423    else if(f1TnlCfg->configType == CONFIG_MOD)
2424    {
2425       if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_MOD, duTnlCfg->tnlCfg1->teId, f1TnlCfg->tnlCfg1) == ROK)
2426       {
2427          if(fillTnlCfgToAddMod(&duTnlCfg, f1TnlCfg) == ROK)
2428          {
2429             ret = ROK;
2430          }
2431       }   
2432    }
2433    else if(f1TnlCfg->configType == CONFIG_DEL)
2434    {
2435       if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_DEL, duTnlCfg->tnlCfg1->teId, f1TnlCfg->tnlCfg1) == ROK)
2436       {    
2437          /* Free memory at drbIdx */
2438          duCb.numTeId--;
2439          for(delIdx = ueCbIdx; delIdx < duCb.numTeId; delIdx++)
2440          {
2441             /* moving all elements one index ahead */
2442             ret = fillTnlCfgToAddMod(&duCb.upTnlCfg[delIdx], duCb.upTnlCfg[delIdx+1]);
2443             if(ret != ROK)
2444             {
2445                return ret;
2446             }
2447          }
2448          if(duCb.upTnlCfg[delIdx])
2449          {
2450             DU_FREE(duCb.upTnlCfg[delIdx]->tnlCfg1, sizeof(GtpTnlCfg));
2451             DU_FREE(duCb.upTnlCfg[delIdx], sizeof(UpTnlCfg));
2452          }
2453       }   
2454    }
2455    return ret;
2456 }
2457
2458 /***********************************************************************
2459  *
2460  * @brief Function to fill Tunnel Config
2461  *        and sends tunnel Req to EGTP
2462  * 
2463  *
2464  * @details
2465  *
2466  *    Function : duUpdateTunnelCfgDb
2467  *
2468  *    Functionality: Function to fill tunnel Config
2469  *                   and sends tunnel Cfg Req to EGTP
2470  *
2471  * @params[in] ueId, cellId, DuUeCfg 
2472  * @return ROK     - success
2473  *         RFAILED - failure
2474  *
2475  * ****************************************************************/
2476
2477 uint8_t duUpdateTunnelCfgDb(uint8_t ueId, uint8_t cellId, DuUeCfg *duUeCfg)
2478 {
2479    uint8_t ret = ROK, drbIdx, teIdx;
2480    bool drbFound = false;
2481
2482    /*If Add/Mod tunnels request for that DRB is successful in EGTP */
2483    /*then update drbId and tunnel Info in duCb */
2484    for(drbIdx=0; drbIdx < duUeCfg->numDrb; drbIdx++)
2485    {
2486       duUeCfg->upTnlInfo[drbIdx].cellId = cellId;
2487       duUeCfg->upTnlInfo[drbIdx].ueId = ueId;
2488       for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
2489       {
2490          if((duCb.upTnlCfg[teIdx]->ueId == duUeCfg->upTnlInfo[drbIdx].ueId) && \
2491             (duCb.upTnlCfg[teIdx]->drbId == duUeCfg->upTnlInfo[drbIdx].drbId))
2492          {
2493             drbFound = true; /* existing DRB */
2494             if(duProcEgtpTunnelCfg(teIdx, duCb.upTnlCfg[teIdx], &duUeCfg->upTnlInfo[drbIdx]) != ROK)
2495             {
2496                DU_LOG("\nERROR  -> DU_APP : duUpdateTunnelCfgDb: Failed to modify tunnel req for Drb id[%d]",
2497                      duUeCfg->upTnlInfo[drbIdx].drbId);
2498                ret = RFAILED;
2499             }
2500             break;
2501          }
2502          else
2503             drbFound = false;
2504       }
2505
2506       if(!drbFound && ret == ROK)/* new DRB to Add */
2507       {
2508          if(duProcEgtpTunnelCfg(NULLP, NULLP, &duUeCfg->upTnlInfo[drbIdx]) != ROK)
2509          {
2510             DU_LOG("\nERROR  -> DU_APP : duUpdateTunnelCfgDb: Failed to add tunnel req for Drb id[%d]",
2511                   duUeCfg->upTnlInfo[drbIdx].drbId);
2512             ret = RFAILED;
2513             break;
2514          }
2515       }
2516    }
2517    return ret;
2518 }
2519
2520 /*******************************************************************
2521  *
2522  * @brief @brief To update DuUeCb Mac and Rlc Ue Cfg
2523  * 
2524  *
2525  * @details
2526  *
2527  *    Function : duUpdateDuUeCbCfg
2528  *
2529  *    Functionality: update DuUeCb Mac and Rlc Ue Cfg
2530  *
2531  * @params[in] ueId, cellIdx 
2532  * @return ROK     - success
2533  *         RFAILED - failure
2534  *
2535  * ****************************************************************/
2536
2537 uint8_t duUpdateDuUeCbCfg(uint8_t ueId, uint8_t cellId)
2538 {
2539    uint8_t ret = ROK, cellIdx = 0, crnti=0;
2540    DuUeCb *ueCb = NULLP;
2541
2542    GET_CELL_IDX(cellId, cellIdx);
2543    ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
2544
2545    /*Filling RLC Ue Cfg */
2546    ueCb->rlcUeCfg.cellId = cellId;
2547    ueCb->rlcUeCfg.ueId   = ueId;
2548    ret = duUpdateRlcLcCfg(&ueCb->rlcUeCfg, ueCb->f1UeDb);
2549    if(ret == ROK)
2550    {
2551       /*Filling MAC Ue Cfg */
2552       GET_CRNTI(crnti, ueId);
2553       ueCb->duMacUeCfg.cellId = cellId;
2554       ueCb->duMacUeCfg.ueId  = ueId;
2555       ueCb->duMacUeCfg.crnti  = crnti;
2556       ret = duUpdateMacCfg(&ueCb->duMacUeCfg, ueCb->f1UeDb);
2557       if(ret == RFAILED)
2558          DU_LOG("\nERROR  -->  DU APP : Failed while updating MAC LC Config at duUpdateDuUeCbCfg()");
2559       else
2560       {
2561          if(duUpdateTunnelCfgDb(ueId, cellId, &ueCb->f1UeDb->duUeCfg) != ROK)
2562          {
2563             DU_LOG("\nERROR  -->  DU_APP : Failed to establish tunnel in duUpdateDuUeCbCfg()");
2564             return RFAILED;
2565          }
2566       }
2567    }
2568    else
2569       DU_LOG("\nERROR  -->  DU APP : Failed while updating RLC LC Config at duUpdateDuUeCbCfg()");
2570    return ret;
2571 }
2572
2573 /*******************************************************************
2574  *
2575  * @brief Handle UE config response from MAC
2576  *
2577  * @details
2578  *
2579  *    Function : DuProcMacUeCfgRsp
2580  *
2581  *    Functionality: Handle UE Config response from MAC
2582  *
2583  * @params[in] Pointer to MacUeCfgRsp and Pst 
2584  * @return ROK     - success
2585  *         RFAILED - failure
2586  *
2587  * ****************************************************************/
2588 uint8_t DuProcMacUeCfgRsp(Pst *pst, MacUeCfgRsp *cfgRsp)
2589 {
2590    uint8_t ret = ROK;
2591    uint16_t cellIdx;
2592
2593    if(cfgRsp)
2594    {
2595       GET_CELL_IDX(cfgRsp->cellId, cellIdx);
2596       if(cfgRsp->result == MAC_DU_APP_RSP_OK)
2597       {
2598          if(pst->event == EVENT_MAC_UE_CREATE_RSP)
2599          {
2600             DU_LOG("\nINFO   -->  DU APP : MAC UE Create Response : SUCCESS [DU UE F1AP ID : %d]", cfgRsp->ueId);
2601
2602             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[cfgRsp->ueId -1].gnbDuUeF1apId == cfgRsp->ueId))
2603             {
2604                duCb.actvCellLst[cellIdx]->ueCb[cfgRsp->ueId -1].duMacUeCfg.macUeCfgState = UE_CREATE_COMPLETE;
2605
2606               if((duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].ueState == UE_HANDIN_IN_PROGRESS) && 
2607                     (duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].duMacUeCfg.macUeCfgState == UE_CREATE_COMPLETE) &&
2608                      (duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].rlcUeCfg.rlcUeCfgState == UE_CREATE_COMPLETE))
2609                {
2610                   if((ret = duUpdateDuUeCbCfg(cfgRsp->ueId, cfgRsp->cellId)) == ROK)
2611                   {
2612                      /* If UE is in handover, RACH resource needs to be requested
2613                       * from MAC for CFRA */
2614                      if((duBuildAndSendRachRsrcReqToMac(cfgRsp->cellId, cfgRsp->ueId)) != ROK)
2615                      {
2616                         DU_LOG("\nERROR  --> DU APP : Failed to send RACH Resource Request to MAC");
2617                         DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(MacUeCfgRsp));
2618                         return RFAILED;
2619                      }
2620                   }
2621                   else
2622                   {
2623                      DU_LOG("\nERROR  ->  DU APP : Failure in updating DU UE CB");
2624                      DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(MacUeCfgRsp));
2625                      return RFAILED;
2626                   }
2627                }
2628             }
2629          }
2630       }
2631       else
2632       {
2633          DU_LOG("\nERROR  -->  DU APP : MAC UE CFG Response for EVENT[%d]: FAILURE [DU UE F1AP ID : %d]", pst->event, cfgRsp->ueId);
2634          ret = RFAILED;
2635       }
2636       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(MacUeCfgRsp));
2637    }
2638    else
2639    {
2640       DU_LOG("\nERROR  -->  DU APP : Received MAC Ue Config Response is NULL at DuProcMacUeCfgRsp()");
2641       ret = RFAILED;
2642    }
2643    return ret;
2644 }
2645
2646 /*******************************************************************
2647  *
2648  * @brief Handle UE Reconfig response from MAC
2649  *
2650  * @details
2651  *
2652  *    Function : DuProcMacUeRecfgRsp
2653  *
2654  *    Functionality: Handle UE ReConfig response from MAC
2655  *
2656  * @params[in] Pointer to MacUeRecfgRsp and Pst 
2657  * @return ROK     - success
2658  *         RFAILED - failure
2659  *
2660  * ****************************************************************/
2661 uint8_t DuProcMacUeRecfgRsp(Pst *pst, MacUeRecfgRsp *reCfgRsp)
2662 {
2663    uint8_t ret = ROK;
2664    uint16_t cellIdx;
2665
2666    if(reCfgRsp)
2667    {
2668       GET_CELL_IDX(reCfgRsp->cellId, cellIdx);
2669       if(reCfgRsp->result == MAC_DU_APP_RSP_OK)
2670       {
2671          if(pst->event == EVENT_MAC_UE_RECONFIG_RSP)
2672          {
2673             DU_LOG("\nINFO   -->  DU APP : MAC UE Reconfig Response : SUCCESS [DU UE F1AP ID : %d]", reCfgRsp->ueId);
2674             if(duCb.actvCellLst[cellIdx] && 
2675                   (duCb.actvCellLst[cellIdx]->ueCb[reCfgRsp->ueId -1].gnbDuUeF1apId == reCfgRsp->ueId))
2676             {
2677                duCb.actvCellLst[cellIdx]->ueCb[reCfgRsp->ueId -1].duMacUeCfg.macUeCfgState = UE_RECFG_COMPLETE;
2678                if((duCb.actvCellLst[cellIdx]->ueCb[reCfgRsp->ueId -1].duMacUeCfg.macUeCfgState == UE_RECFG_COMPLETE) &&
2679                      (duCb.actvCellLst[reCfgRsp->cellId -1]->ueCb[reCfgRsp->ueId -1].rlcUeCfg.rlcUeCfgState == UE_RECFG_COMPLETE))
2680                {
2681                   if((ret = duUpdateDuUeCbCfg(reCfgRsp->ueId, reCfgRsp->cellId)) == ROK)
2682                   {  
2683                      if((BuildAndSendUeCtxtRsp(reCfgRsp->cellId, reCfgRsp->ueId)) != ROK)
2684                      {
2685                         DU_LOG("\nERROR  ->  DU APP : Failure in BuildAndSendUeCtxtRsp()");
2686                         DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, reCfgRsp, sizeof(MacUeRecfgRsp));
2687                         return RFAILED;
2688                      }
2689                   }
2690                   else
2691                   {
2692                      DU_LOG("\nERROR  ->  DU APP : Failure in updating DU UE CB");
2693                      DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, reCfgRsp, sizeof(MacUeRecfgRsp));
2694                      return RFAILED;
2695                   }
2696                }
2697             }
2698          }
2699       }
2700       else
2701       {
2702          DU_LOG("\nERROR  -->  DU APP : MAC UE RECFG Response for EVENT[%d]: FAILURE [DU UE F1AP ID : %d]", pst->event, reCfgRsp->ueId);
2703          if(pst->event == EVENT_MAC_UE_RECONFIG_RSP)
2704          {
2705             //TODO: Send the failure case in Ue Context Setup Response
2706          }
2707          ret = RFAILED;
2708       }
2709       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, reCfgRsp, sizeof(MacUeRecfgRsp));
2710    }
2711    else
2712    {
2713       DU_LOG("\nERROR  -->  DU APP : Received MAC Ue ReConfig Response is NULL at DuProcMacUeRecfgRsp()");
2714       ret = RFAILED;
2715    }
2716    return ret;
2717 }
2718
2719 /*******************************************************************
2720  *
2721  * @brief Processes UE create Req to RLC UL
2722  *
2723  * @details
2724  *
2725  *    Function : duBuildAndSendUeCreateReqToRlc
2726  *
2727  *    Functionality: 
2728  *     Processes UE create Req to RLC UL
2729  * 
2730  *  @params[in]  cellId,
2731  *               ueId,
2732  *               Pointer to RlcUeCfg
2733  *  @return ROK     - success
2734  *          RFAILED - failure
2735  * 
2736  *****************************************************************/
2737
2738 uint8_t duBuildAndSendUeCreateReqToRlc(uint16_t cellId, uint8_t gnbDuUeF1apId, DuUeCfg *ueCfgDb, RlcUeCfg *duRlcUeCfg)
2739 {
2740    uint8_t  ret = ROK;
2741    RlcUeCfg *rlcUeCfg = NULLP;
2742    Pst       pst;
2743   
2744    ret = fillRlcUeCfg(cellId, gnbDuUeF1apId, ueCfgDb, duRlcUeCfg);
2745    if(ret == RFAILED)
2746    {
2747       DU_LOG("\nERROR  -->  DU APP : Failed to fill Rlc Ue Cfg at duBuildAndSendUeCreateReqToRlc()");
2748       return ret;
2749    }
2750
2751    FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_CREATE_REQ);
2752    /* Copying ueCfg to a sharable buffer */
2753    DU_ALLOC_SHRABL_BUF(rlcUeCfg, sizeof(RlcUeCfg));
2754    if(rlcUeCfg)
2755    {
2756       memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
2757       memcpy(rlcUeCfg, duRlcUeCfg, sizeof(RlcUeCfg));
2758       /* Processing one Ue at a time to RLC */
2759       DU_LOG("\nDEBUG   -->  DU_APP: Sending UE create request to RLC UL");
2760       ret = (*packRlcUeCreateReqOpts[pst.selector])(&pst, rlcUeCfg);
2761       if(ret == RFAILED)
2762       {
2763          DU_LOG("\nERROR  -->  DU_APP : Failure in sending Ue Create Req to RLC");
2764          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rlcUeCfg, sizeof(RlcUeCfg));
2765          ret = RFAILED;
2766       }
2767    }
2768    else
2769    {
2770       DU_LOG("\n ERROR  -->  DU APP : Memory alloc failed at duBuildAndSendUeCreateReqToRlc()");
2771       ret = RFAILED;
2772    }
2773    return ret;
2774 }
2775
2776 /*******************************************************************
2777  *
2778  * @brief Processes UE create Rsp received from RLC UL
2779  *
2780  * @details
2781  *
2782  
2783  *    Function : DuProcRlcUeCfgRsp
2784  *
2785  *    Functionality: 
2786  *     Processes UE create Rsp received from RLC UL
2787  * 
2788  *  @params[in]  Post structure
2789  *               Pointer to RlcCfgCfm
2790  *  @return ROK     - success
2791  *          RFAILED - failure
2792  * 
2793  *****************************************************************/
2794 uint8_t DuProcRlcUeCfgRsp(Pst *pst, RlcUeCfgRsp *cfgRsp)
2795 {
2796    uint8_t ret = ROK;
2797
2798    if(cfgRsp)
2799    {
2800       if(cfgRsp->result == RLC_DU_APP_RSP_OK)
2801       {
2802          if(pst->event == EVENT_RLC_UE_CREATE_RSP)
2803          {
2804             DU_LOG("\nINFO   -->  DU_APP: RLC UE Create Response : SUCCESS [UE IDX:%d]", cfgRsp->ueId);
2805             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].rlcUeCfg.rlcUeCfgState = UE_CREATE_COMPLETE;
2806
2807             if((duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].ueState == UE_HANDIN_IN_PROGRESS) &&
2808                   (duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].duMacUeCfg.macUeCfgState == UE_CREATE_COMPLETE) &&
2809                   (duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].rlcUeCfg.rlcUeCfgState == UE_CREATE_COMPLETE))
2810             {
2811                if((ret = duUpdateDuUeCbCfg(cfgRsp->ueId, cfgRsp->cellId)) == ROK)
2812                {
2813                   /* If UE is in handover, RACH resource needs to be requested
2814                    * from MAC for CFRA */
2815                   if((duBuildAndSendRachRsrcReqToMac(cfgRsp->cellId, cfgRsp->ueId)) != ROK)
2816                   {
2817                      DU_LOG("\nERROR  --> DU APP : Failed to send RACH Resource Request to MAC");
2818                      DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(MacUeCfgRsp));
2819                      DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(RlcUeCfgRsp));
2820                      return RFAILED;
2821                   }
2822                }
2823                else
2824                {
2825                   DU_LOG("\nERROR  -->  DU APP : Failure in updating DU UE CB");
2826                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(RlcUeCfgRsp));
2827                   return RFAILED;
2828                }
2829             }
2830          }
2831          else if(pst->event == EVENT_RLC_UE_RECONFIG_RSP)
2832          {
2833             DU_LOG("\nINFO   -->  DU_APP: RLC UE Reconfig Response : SUCCESS [UE IDX:%d]", cfgRsp->ueId);
2834
2835             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].rlcUeCfg.rlcUeCfgState = UE_RECFG_COMPLETE;
2836             if((duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].duMacUeCfg.macUeCfgState == UE_RECFG_COMPLETE) &&
2837                   (duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].rlcUeCfg.rlcUeCfgState == UE_RECFG_COMPLETE))
2838             {
2839                if((ret = duUpdateDuUeCbCfg(cfgRsp->ueId, cfgRsp->cellId)) == ROK)
2840                {
2841                   if((BuildAndSendUeCtxtRsp(cfgRsp->cellId, cfgRsp->ueId)) != ROK)
2842                   {
2843                      DU_LOG("\nERROR  -->  DU APP : Failure in BuildAndSendUeCtxtRsp");
2844                      DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(RlcUeCfgRsp));
2845                      return RFAILED;
2846                   }
2847                }
2848                else
2849                {
2850                   DU_LOG("\nERROR  -->  DU APP : Failure in updating DU UE CB");
2851                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(RlcUeCfgRsp));
2852                   return RFAILED;
2853                }
2854             }
2855          }
2856       }
2857       else
2858       {
2859          DU_LOG("\nERROR  -->  DU_APP: RLC UE CFG Response for EVENT[%d] : FAILED [UE IDX : %d, REASON :%d]",\
2860                pst->event, cfgRsp->ueId, cfgRsp->reason);
2861          if((pst->event == EVENT_RLC_UE_RECONFIG_RSP))
2862          {
2863             //TODO: update failure case in ue Context setup Response
2864          }
2865          ret = RFAILED;
2866       }
2867       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(RlcUeCfgRsp));
2868    }
2869    else
2870    {
2871       DU_LOG("\nERROR  -->  DU_APP: Received RLC Ue Config Response is NULL at DuProcRlcUeCfgRsp()");
2872       ret = RFAILED;
2873    }
2874    return ret;
2875 }
2876
2877 /*******************************************************************
2878  *
2879  * @brief Builds and Send Ue Reconfig Req to RLC
2880  *
2881  * @details
2882  *
2883  *    Function : duBuildAndSendUeRecfgReqToRLC
2884  *
2885  *    Functionality: Builds and Send Ue Reconfig Req to RLC
2886  *
2887  * @params[in] cellId, crnti
2888  *             DuUeCfg *ueCfgDb
2889  *             RlcUeCfg *rlcUeCfg
2890  * @return ROK     - success
2891  *         RFAILED - failure
2892  *
2893  * ****************************************************************/
2894
2895 uint8_t duBuildAndSendUeRecfgReqToRlc(uint8_t cellId, uint8_t gnbDuUeF1apId, uint8_t crnti, DuUeCfg *ueCfgDb)
2896 {
2897    uint8_t ret = ROK;
2898    RlcUeCfg *rlcUeCfg = NULLP;
2899
2900    DU_ALLOC_SHRABL_BUF(rlcUeCfg, sizeof(RlcUeCfg));
2901    if(rlcUeCfg)
2902    {
2903       memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
2904       ret = fillRlcUeCfg(cellId, gnbDuUeF1apId, ueCfgDb, rlcUeCfg);
2905       if(ret == RFAILED)
2906          DU_LOG("\nERROR  -->  DU APP : Failed at duBuildAndSendUeRecfgReqToRlc()");
2907       else
2908          ret = sendUeRecfgReqToRlc(rlcUeCfg);
2909    }
2910    else
2911    {
2912       DU_LOG("\nERROR  -->  DU APP : Memory Alloc failed at duBuildAndSendUeRecfgReqToRlc()");
2913       ret = RFAILED;
2914    }
2915    return ret;
2916 }
2917
2918 /**********************************************************************************
2919  *
2920  * @brief Fills Ue ReCfg from DU DB to MacUeRecfg
2921  *
2922  * @details
2923  *
2924  *    Function : fillMacUeRecfg
2925  *
2926  *    Functionality: fills ue ReCfg to be sent to MAC
2927  *
2928  * @params[in] DuMacUeCfg Pointer
2929  *             MacUeRecfg Pointer
2930  *
2931  * @return void 
2932  * *******************************************************************************/
2933 void fillMacUeRecfg(DuMacUeCfg *duMacUeCfg, MacUeRecfg *macUeRecfg)
2934 {
2935    uint8_t lcIdx = 0;
2936
2937    macUeRecfg->cellId = duMacUeCfg->cellId;
2938    macUeRecfg->ueId = duMacUeCfg->ueId;
2939    macUeRecfg->crnti = duMacUeCfg->crnti;
2940    macUeRecfg->macCellGrpRecfgPres = duMacUeCfg->macCellGrpCfgPres;
2941    if(macUeRecfg->macCellGrpRecfgPres)
2942    {
2943       memcpy(&macUeRecfg->macCellGrpRecfg, &duMacUeCfg->macCellGrpCfg, sizeof(MacCellGrpCfg));
2944    }
2945    macUeRecfg->phyCellGrpRecfgPres = duMacUeCfg->phyCellGrpCfgPres;
2946    if(macUeRecfg->phyCellGrpRecfgPres)
2947    {
2948       memcpy(&macUeRecfg->phyCellGrpRecfg, &duMacUeCfg->phyCellGrpCfg, sizeof(PhyCellGrpCfg));
2949    }
2950    macUeRecfg->spCellRecfgPres = duMacUeCfg->spCellCfgPres;
2951    if(macUeRecfg->spCellRecfgPres)
2952    {
2953       memcpy(&macUeRecfg->spCellRecfg, &duMacUeCfg->spCellCfg, sizeof(SpCellRecfg));
2954    }
2955    if(duMacUeCfg->ambrCfg != NULLP)
2956    {
2957       DU_ALLOC_SHRABL_BUF(macUeRecfg->ambrRecfg, sizeof(AmbrCfg));
2958       memcpy(macUeRecfg->ambrRecfg, duMacUeCfg->ambrCfg, sizeof(AmbrCfg));
2959    }
2960    memcpy(&macUeRecfg->dlModInfo, &duMacUeCfg->dlModInfo, sizeof(ModulationInfo));
2961    memcpy(&macUeRecfg->ulModInfo, &duMacUeCfg->ulModInfo, sizeof(ModulationInfo));
2962    if(duMacUeCfg->numLcs > 0)
2963    {
2964       macUeRecfg->numLcsToAdd = 0;
2965       macUeRecfg->numLcsToDel = 0;
2966       macUeRecfg->numLcsToMod = 0;
2967
2968       for(lcIdx = 0; lcIdx < duMacUeCfg->numLcs; lcIdx++)
2969       {
2970          if(duMacUeCfg->lcCfgList[lcIdx].configType == CONFIG_ADD)
2971          {
2972             /*VS: To thoroughly check*/
2973             memcpy(&macUeRecfg->lcCfgAdd[macUeRecfg->numLcsToAdd], &duMacUeCfg->lcCfgList[lcIdx].lcConfig, sizeof(LcCfg));
2974             macUeRecfg->numLcsToAdd++;
2975          }
2976          if(duMacUeCfg->lcCfgList[lcIdx].configType == CONFIG_DEL)
2977          {
2978             /*VS: To thoroughly check*/
2979             macUeRecfg->lcIdToDel[macUeRecfg->numLcsToDel] = duMacUeCfg->lcCfgList[lcIdx].lcConfig.lcId;
2980             macUeRecfg->numLcsToDel++;
2981          }
2982          if(duMacUeCfg->lcCfgList[lcIdx].configType == CONFIG_MOD)
2983          {
2984             /*VS: To thoroughly check*/
2985             memcpy(&macUeRecfg->lcCfgMod[macUeRecfg->numLcsToMod], &duMacUeCfg->lcCfgList[lcIdx].lcConfig, sizeof(LcCfg));
2986             macUeRecfg->numLcsToMod++;
2987          }
2988       }
2989    }
2990    macUeRecfg->transmissionAction = duMacUeCfg->transmissionAction;
2991 #ifdef NR_DRX
2992    macUeRecfg->drxConfigIndicatorRelease = duMacUeCfg->drxConfigIndicatorRelease;
2993 #endif
2994 }
2995
2996 /*******************************************************************
2997  *
2998  * @brief Builds and Send Ue Reconfig Req to MAC
2999  *
3000  * @details
3001  *
3002  *    Function : duBuildAndSendUeRecfgReqToMac
3003  *
3004  *    Functionality: Builds and Send Ue Reconfig Req to MAC
3005  *
3006  * @params[in] CellGroupConfigRrc_t *macCellGrpCfg
3007  *             DuUeCfg *ueCfgDb
3008  * @return ROK     - success
3009  *         RFAILED - failure
3010  *
3011  * ****************************************************************/
3012
3013 uint8_t duBuildAndSendUeRecfgReqToMac(uint8_t cellId, uint8_t duUeF1apId, uint8_t crnti, DuUeCfg *ueCfgDb)
3014 {
3015    uint8_t ret = ROK;
3016    DuMacUeCfg *duMacUeCfg = NULLP;
3017    MacUeRecfg *macUeRecfg = NULLP;
3018
3019    DU_ALLOC(duMacUeCfg, sizeof(DuMacUeCfg));
3020    DU_ALLOC_SHRABL_BUF(macUeRecfg, sizeof(MacUeRecfg));
3021    if(macUeRecfg && duMacUeCfg)
3022    {
3023       memset(duMacUeCfg, 0, sizeof(DuMacUeCfg));
3024       memset(macUeRecfg, 0, sizeof(MacUeRecfg));
3025       ret = updateDuMacUeCfg(cellId, duUeF1apId, crnti, ueCfgDb, duMacUeCfg);
3026       fillMacUeRecfg(duMacUeCfg, macUeRecfg);
3027       if(ret == RFAILED)
3028          DU_LOG("\nERROR  -->  DU APP : Failed to fill Mac Ue Cfg at duBuildAndSendUeRecfgReqToMac()");
3029       else
3030          ret = sendUeRecfgReqToMac(macUeRecfg);
3031    }
3032    else
3033    {
3034       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed for macUeCfg at duBuildAndSendUeRecfgReqToMac()");
3035       ret = RFAILED;
3036    }
3037    DU_FREE(duMacUeCfg, sizeof(DuMacUeCfg));
3038    
3039    return ret;
3040 }
3041
3042 /*******************************************************************
3043  *
3044  * @brief Build and Send Ue context setup request
3045  *
3046  * @details
3047  *
3048  
3049  *    Function : duBuildAndSendUeContextSetupReq
3050  *
3051  *    Functionality: 
3052  *     Build and Send Ue context setup request
3053  * 
3054  *  @params[in]  cellId, crnti, DuUeCfg pointer
3055  *  @return ROK     - success
3056  *          RFAILED - failure
3057  * 
3058  *****************************************************************/
3059
3060 uint8_t duBuildAndSendUeContextSetupReq(uint16_t cellId, DuUeCb *ueCb)
3061 {
3062    uint8_t ret = ROK;
3063    uint16_t crnti; 
3064    DuUeCfg *duUeCfg = NULLP;
3065
3066    DU_LOG("\nDEBUG   -->  DU_APP: Processing Ue Context Setup Request for cellId [%d]", cellId);
3067
3068    if(!ueCb)
3069    {
3070       DU_LOG("\nERROR  -->  DU APP : UE Cb is NULL");
3071       return RFAILED;
3072    }
3073
3074    crnti = ueCb->crnti;
3075    duUeCfg = &ueCb->f1UeDb->duUeCfg;
3076
3077    /* If UE is being handed-in to this DU, UE context setup request will create
3078     * new UE context at MAC/SCH and RLC.
3079     * If UE is in active state, UE contex setup request will lead to
3080     * reconfiguration of UE at MAC/SCH and RLC
3081     */
3082    if(ueCb->ueState == UE_HANDIN_IN_PROGRESS)
3083    {
3084       /* Filling MAC UE Config */
3085       memset(&ueCb->duMacUeCfg, 0, sizeof(DuMacUeCfg));
3086
3087       /* Since UE attach has not yet happened, crnti is unknow. Hence passing 0 */
3088       ret = duBuildAndSendUeCreateReqToMac(cellId, ueCb->gnbDuUeF1apId, 0, duUeCfg, &ueCb->duMacUeCfg);
3089       if(ret == RFAILED)
3090          DU_LOG("\nERROR  -->  DU APP : Failed to send UE create request to MAC");
3091
3092       ret = duBuildAndSendUeCreateReqToRlc(cellId, ueCb->gnbDuUeF1apId, duUeCfg, &ueCb->rlcUeCfg);
3093       if(ret == RFAILED)
3094          DU_LOG("\nERROR  --> DU APP : Failed to send UE create request to RLC");
3095
3096    }
3097    else
3098    {
3099       /* Filling RLC UE Reconfig */ 
3100       ret = duBuildAndSendUeRecfgReqToRlc(cellId, ueCb->gnbDuUeF1apId, crnti, duUeCfg);
3101       if(ret == RFAILED)
3102          DU_LOG("\nERROR  -->  DU APP : Failed to build ctxt setup req for RLC at duBuildAndSendUeContextSetupReq()");
3103
3104       /* Filling MAC UE Reconfig */
3105       ret = duBuildAndSendUeRecfgReqToMac(cellId, ueCb->gnbDuUeF1apId, crnti, duUeCfg);
3106       if(ret == RFAILED)
3107          DU_LOG("\nERROR  -->  DU APP : Failed at build ctxt setup req for MAC at duBuildAndSendUeContextSetupReq()");
3108    }
3109
3110    return ret;
3111 }
3112
3113 /*******************************************************************
3114  *
3115  * @brief Processes DL Rsp received from RLC DL
3116  *
3117  * @details
3118  *
3119  
3120  *    Function : DuProcRlcDlRrcMsgRsp
3121  *
3122  *    Functionality: 
3123  *     Processes UE Rsp received from RLC DL
3124  * 
3125  *  @params[in]  Post structure
3126  *               Pointer to RlcCfgCfm
3127  *  @return ROK     - success
3128  *          RFAILED - failure
3129  * 
3130  *****************************************************************/
3131 uint8_t DuProcRlcDlRrcMsgRsp(Pst *pst, RlcDlRrcMsgRsp *dlRrcMsg)
3132 {
3133    uint8_t ret = ROK, ueId = 0;
3134    uint16_t cellId, crnti;
3135    DuUeCb *ueCb = NULLP;
3136    DlMsgState state;
3137
3138    state = dlRrcMsg->state;
3139    cellId = dlRrcMsg->cellId;
3140    crnti = dlRrcMsg->crnti;
3141    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlRrcMsg, sizeof(RlcDlRrcMsgRsp));
3142
3143    if(state == TRANSMISSION_COMPLETE)
3144    {
3145       GET_UE_ID(crnti, ueId);
3146       ueCb = &duCb.actvCellLst[cellId -1]->ueCb[ueId -1];
3147
3148       if(ueCb->f1UeDb && ueCb->f1UeDb->dlRrcMsgPres)
3149       {
3150          if(ueCb->f1UeDb->actionType == UE_CTXT_SETUP)
3151          {
3152             ret = duBuildAndSendUeContextSetupReq(cellId, ueCb);
3153             if(ret == RFAILED)
3154                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Setup Request in DuProcRlcDlRrcMsgRsp()");
3155          }
3156          
3157          if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
3158          {
3159             ret = duBuildAndSendUeContextModReq(cellId, ueCb->gnbDuUeF1apId, crnti, &ueCb->f1UeDb->duUeCfg);
3160             if(ret == RFAILED)
3161                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Mod Request in DuProcRlcDlRrcMsgRsp()");
3162          }
3163
3164          if(ueCb->f1UeDb->actionType == UE_CTXT_RELEASE && ueCb->ueState == UE_ACTIVE)
3165          {
3166             ret = duBuildAndSendUeDeleteReq(cellId, crnti);
3167             if(ret == RFAILED)
3168             {
3169                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Release Request in DuProcRlcDlRrcMsgRsp()");
3170             }
3171          }
3172       }
3173    }
3174    else
3175       DU_LOG("\nERROR  -->  DU APP : Failed to transmit DL RRC Msg");
3176
3177    return ret;
3178 }
3179 /*******************************************************************
3180  *
3181  * @brief Process UE context setup request from CU
3182  *
3183  * @details
3184  *
3185  *    Function : duProcUeContextSetupRequest 
3186  *
3187  *    Functionality: Process UE context setup request from CU
3188  *
3189  * @params[in] F1AP message
3190  * @return ROK     - success
3191  *         RFAILED - failure
3192  *
3193  * ****************************************************************/
3194
3195 uint8_t duProcUeContextSetupRequest(DuUeCb *ueCb)
3196 {
3197    uint8_t ret, cellId;
3198
3199    ret = ROK;
3200    if(ueCb)
3201    {
3202       cellId = duCb.actvCellLst[ueCb->f1UeDb->cellIdx]->cellId;
3203
3204       /* Send DL RRC msg for security Mode */
3205       if(ueCb->f1UeDb->dlRrcMsg)
3206       {
3207          if(ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
3208          {
3209             /* Sending DL RRC Message to RLC */
3210             ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->rlcUeCfg, ueCb->f1UeDb->dlRrcMsg);
3211             if(ret == RFAILED)
3212             {
3213                DU_LOG("\nERROR  -->  DU APP : Failed to send DL RRC msg in duProcUeContextSetupRequest()");
3214                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
3215                      ueCb->f1UeDb->dlRrcMsg->rrcMsgSize);
3216                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
3217             }
3218          }
3219       }
3220       else if(ueCb->f1UeDb->actionType == UE_CTXT_SETUP)
3221       {
3222          ret = duBuildAndSendUeContextSetupReq(cellId, ueCb);
3223          if(ret == RFAILED)
3224          {
3225             DU_LOG("\nERROR  -->  DU APP : Failed to build ue context setup Req in duProcUeContextSetupRequest()");
3226          }
3227       }
3228    }
3229    else
3230    {
3231       //TODO: To send the failure cause in UeContextSetupRsp
3232       DU_LOG("ERROR  -->  DU APP : Failed to process UE CNTXT SETUP REQ at duProcUeContextSetupRequest()");
3233    }
3234    return ret;
3235 }
3236
3237 /*******************************************************************
3238  *
3239  * @brief Build and Send Ue context mod request
3240  *
3241  * @details
3242  *
3243  *
3244  *    Function : duBuildAndSendUeContextModReq
3245  *
3246  *    Functionality: 
3247  *     Build and Send Ue context mod request
3248  * 
3249  *  @params[in]  cellId, crnti, DuUeCfg pointer
3250  *  @return ROK     - success
3251  *          RFAILED - failure
3252  * 
3253  *****************************************************************/
3254
3255 uint8_t duBuildAndSendUeContextModReq(uint16_t cellId, uint8_t gnbDuUeF1apId, uint16_t crnti, DuUeCfg *duUeCfg)
3256 {
3257    uint8_t ret = ROK;
3258
3259    DU_LOG("\nDEBUG   -->  DU_APP: Processing Ue Context Mod Request for cellId [%d]", cellId);
3260    /* Filling RLC Ue Reconfig */ 
3261    ret = duBuildAndSendUeRecfgReqToRlc(cellId, gnbDuUeF1apId, crnti, duUeCfg);
3262    if(ret == RFAILED)
3263       DU_LOG("\nERROR  -->  DU APP : Failed to build ctxt setup req for RLC at duBuildAndSendUeContextModReq()");
3264    
3265    /* Filling MAC Ue Reconfig */
3266    ret = duBuildAndSendUeRecfgReqToMac(cellId, gnbDuUeF1apId, crnti, duUeCfg);
3267    if(ret == RFAILED)
3268       DU_LOG("\nERROR  -->  DU APP : Failed at build ctxt setup req for MAC at duBuildAndSendUeContextModReq()");
3269
3270    return ret;
3271 }
3272 /*******************************************************************
3273  *
3274  * @brief Processing Ue context mod request
3275  *
3276  * @details
3277  *
3278  *
3279  *    Function : duProcUeContextModReq 
3280  *
3281  *    Functionality:
3282  *        Processing  Ue context mod request
3283  *
3284  *  @params[in] DuUeCb *ueCb 
3285  *  @return ROK     - success
3286  *          RFAILED - failure
3287  *
3288  *****************************************************************/
3289
3290 uint8_t duProcUeContextModReq(DuUeCb *ueCb)
3291 {
3292    uint8_t ret, cellId;
3293
3294    ret = ROK;
3295    if(ueCb)
3296    {
3297       cellId = duCb.actvCellLst[ueCb->f1UeDb->cellIdx]->cellId;
3298       /* Send DL RRC msg for security Mode */
3299       if(ueCb->f1UeDb->dlRrcMsg)
3300       {
3301          if(ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
3302          {
3303             /* Sending DL RRC Message to RLC */
3304             ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->rlcUeCfg, ueCb->f1UeDb->dlRrcMsg);
3305             if(ret == RFAILED)
3306             {
3307                DU_LOG("\nERROR  -->  DU APP : Failed to send DL RRC msg in duProcUeContextModReq()");
3308                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
3309                      ueCb->f1UeDb->dlRrcMsg->rrcMsgSize);
3310                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
3311             }
3312          }
3313       }
3314       else if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
3315       {
3316          ret = duBuildAndSendUeContextModReq(cellId, ueCb->gnbDuUeF1apId, ueCb->crnti, &ueCb->f1UeDb->duUeCfg);
3317          if(ret == RFAILED)
3318          {
3319             DU_LOG("\nERROR  -->  DU APP : Failed to build ue context setup Req in duProcUeContextModReq()");
3320             return RFAILED;
3321          }
3322       }
3323       else if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || (ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE))
3324       {
3325          if((BuildAndSendUeContextModRsp(ueCb) != ROK))
3326          {
3327             DU_LOG("\nERROR  -->  DU APP : Failed to build UE Context modification response");
3328             return RFAILED;
3329          }
3330       }
3331    }
3332    else
3333    {
3334       //TODO: To send the failure cause in UeContextModRsp
3335       
3336       DU_LOG("ERROR  -->  DU APP : Failed to process UE CNTXT MOD REQ at duProcUeContextModReq()");
3337       return RFAILED;
3338    }
3339    return ROK;
3340 }
3341
3342 /*******************************************************************
3343 *
3344 * @brief Build and send dedicated RACH resource release request to MAC
3345 *
3346 * @details
3347 *
3348 *    Function : duBuildAndSendRachRsrcRelToMac
3349 *
3350 *    Functionality: Function to Build and send dedicated RACH resource 
3351 *    release request to MAC
3352 *
3353 * @params[in] Cell ID
3354 *             UE CB
3355 * @return ROK - Success
3356 *         RFAILED - Failure
3357 *
3358 * ****************************************************************/
3359 uint8_t duBuildAndSendRachRsrcRelToMac(uint16_t cellId, DuUeCb *ueCb)
3360 {
3361    Pst pst;
3362    MacRachRsrcRel *rachRsrcRel = NULLP;
3363
3364    DU_ALLOC_SHRABL_BUF(rachRsrcRel, sizeof(MacRachRsrcRel));
3365    if(!rachRsrcRel)
3366    {
3367       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH Resource Release in \
3368             duBuildAndSendRachRsrcRelToMac()");
3369       return RFAILED;
3370    }
3371
3372    rachRsrcRel->cellId = cellId;
3373    rachRsrcRel->ueId = ueCb->gnbDuUeF1apId;
3374    rachRsrcRel->crnti = ueCb->crnti;
3375
3376    /* Fill Pst */
3377    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_RACH_RESOURCE_REL);
3378
3379    if(((*packMacRachRsrcRelOpts[pst.selector])(&pst, rachRsrcRel)) != ROK)
3380    {
3381       DU_LOG("\nERROR  -->  DU_APP : Failure in sending RACH Resource Release to MAC at \
3382             duBuildAndSendRachRsrcRelToMac()");
3383       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rachRsrcRel, sizeof(MacRachRsrcRel));
3384       return RFAILED;
3385    }
3386
3387    return ROK;
3388 }
3389
3390 /*******************************************************************
3391  *
3392 * @brief delete DuMacUeCfg from duCb
3393 *
3394 * @details
3395 *
3396 *    Function : deleteMacUeCfg 
3397 *
3398 *    Functionality: delete DuMacUeCfg from duCb
3399 *
3400 * @params[in] Pointer to DuMacUeCfg
3401 * @return ROK     - success
3402 *         RFAILED - failure
3403 *
3404 *******************************************************************/
3405
3406 void deleteMacUeCfg(DuMacUeCfg *ueCfg)
3407 {
3408    uint8_t lcCfgIdx=0;
3409    
3410    if(ueCfg->spCellCfgPres)
3411    {
3412       freeUeRecfgCellGrpInfo(ueCfg);
3413    }
3414    if(ueCfg->ambrCfg)
3415    {
3416       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,ueCfg->ambrCfg, sizeof(AmbrCfg));
3417    }
3418    for(lcCfgIdx=0; lcCfgIdx< ueCfg->numLcs; lcCfgIdx++)
3419    {
3420       freeMacLcCfg(&ueCfg->lcCfgList[lcCfgIdx].lcConfig);
3421    }
3422    memset(ueCfg, 0, sizeof(DuMacUeCfg));
3423 }
3424
3425 /*******************************************************************
3426 *
3427 * @brief delete UE Configuration of a particular UE
3428 *
3429 * @details
3430 *
3431 *    Function : deleteUeCfg 
3432 *
3433 *    Functionality: delete UE Configuration of a particular UE 
3434 *
3435 * @params[in] uint16_t cellIdx, uint8_t ueId
3436 * @return ROK     - success
3437 *         RFAILED - failure
3438 *
3439 * ****************************************************************/
3440 uint8_t  deleteUeCfg(uint16_t cellId, uint8_t ueId)
3441 {
3442    uint8_t tnlIdx = 0;
3443    uint16_t cellIdx = 0;
3444    DuUeCb *ueCb = NULLP;
3445    
3446    GET_CELL_IDX(cellId, cellIdx);
3447    if(duCb.actvCellLst[cellIdx] != NULLP)
3448    {
3449       if((duCb.actvCellLst[cellIdx]->ueCb[ueId-1].duMacUeCfg.macUeCfgState == UE_DELETE_COMPLETE)\
3450             &&(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].rlcUeCfg.rlcUeCfgState == UE_DELETE_COMPLETE))
3451       {
3452          ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
3453          deleteMacUeCfg(&ueCb->duMacUeCfg);
3454          deleteRlcUeCfg(&ueCb->rlcUeCfg);
3455          if(ueCb->f1UeDb !=NULLP)
3456          {
3457             freeF1UeDb(ueCb->f1UeDb);
3458          }
3459          for(tnlIdx = 0; tnlIdx < duCb.numTeId; )
3460          {
3461             if(duCb.upTnlCfg[tnlIdx]->ueId == ueId)
3462             {
3463                duCb.upTnlCfg[tnlIdx]->configType = CONFIG_DEL;
3464                duProcEgtpTunnelCfg(tnlIdx, duCb.upTnlCfg[tnlIdx], duCb.upTnlCfg[tnlIdx]);
3465             }
3466             else
3467                tnlIdx++;
3468          }
3469          unsetBitInUeBitMap(cellId, ueId-1);
3470          duCb.actvCellLst[cellIdx]->numActvUes--;
3471          memset(ueCb, 0, sizeof(DuUeCb));
3472       }
3473       else
3474       {
3475          return RFAILED;
3476       }
3477    }
3478    else
3479    {
3480       DU_LOG("\nERROR  --> DU APP : deleteUeCfg(): CellIdx[%d] is not found", cellIdx);
3481       return RFAILED;
3482    }
3483    return ROK;
3484 }
3485
3486
3487 /*******************************************************************
3488 *
3489 * @brief Handle UE delete response from MAC
3490 *
3491 * @details
3492 *
3493 *    Function : DuProcMacUeDeleteRsp
3494 *
3495 *    Functionality: Handle UE delete response from MAC
3496 *
3497 * @params[in] Pointer to MacUeDeleteRsp and Pst
3498 * @return ROK     - success
3499 *         RFAILED - failure
3500 *
3501 * ****************************************************************/
3502
3503 uint8_t DuProcMacUeDeleteRsp(Pst *pst, MacUeDeleteRsp *deleteRsp)
3504 {
3505    uint8_t  ret =ROK,ueId=0;
3506    uint16_t cellIdx=0;
3507    uint32_t gnbCuUeF1apId =0 , gnbDuUeF1apId =0;
3508    
3509    if(deleteRsp)
3510    {
3511       if(deleteRsp->result == DEL_SUCCESSFUL)
3512       {
3513          DU_LOG("\nINFO   -->  DU APP : MAC UE Delete Response : SUCCESS [UE IDX : %d]", deleteRsp->ueId);
3514          GET_CELL_IDX(deleteRsp->cellId, cellIdx);
3515          if(duCb.actvCellLst[cellIdx])
3516          {
3517             duCb.actvCellLst[cellIdx]->ueCb[deleteRsp->ueId -1].duMacUeCfg.macUeCfgState = UE_DELETE_COMPLETE;
3518             ueId = deleteRsp->ueId;
3519             gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
3520             gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
3521             if(deleteUeCfg(deleteRsp->cellId, ueId) == ROK)
3522             {
3523                ret = BuildAndSendUeContextReleaseComplete(deleteRsp->cellId, gnbCuUeF1apId, gnbDuUeF1apId);
3524                if(ret != ROK)
3525                {
3526                   DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): failed to send UE context release complete");
3527                }
3528             }
3529
3530          }
3531       }
3532       else
3533       {
3534          DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): MAC UE Delete Response : FAILURE [UE IDX : %d]",\
3535          deleteRsp->ueId);
3536          ret =  RFAILED;
3537       }
3538       DU_FREE_SHRABL_BUF(pst->region, pst->pool, deleteRsp, sizeof(MacUeDeleteRsp));
3539    }
3540    else
3541    {
3542       DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): MAC UE Delete Response is null");
3543       ret = RFAILED;
3544    }
3545    return ret;
3546 }
3547
3548 /*******************************************************************
3549  *
3550  * @brief Processes UE Delete Rsp received from RLC 
3551  *
3552  * @details
3553  *
3554  *    Function : DuProcRlcUeDeleteRsp
3555  *
3556  *    Functionality:
3557  *     Processes UE Delete Rsp received from RLC 
3558  *
3559  *  @params[in]  Post structure
3560  *               Pointer to RlcUeDeleteRsp
3561  *  @return ROK     - success
3562  *          RFAILED - failure
3563  *
3564  * *****************************************************************/
3565
3566 uint8_t DuProcRlcUeDeleteRsp(Pst *pst, RlcUeDeleteRsp *delRsp)
3567 {
3568    uint8_t  ueId = 0, ret = ROK;
3569    uint16_t cellIdx = 0,crnti=0;
3570
3571    if(delRsp)
3572    {
3573       ueId = delRsp->ueId;
3574       GET_CELL_IDX(delRsp->cellId, cellIdx);
3575
3576       if(delRsp->result == SUCCESSFUL)
3577       {
3578          DU_LOG("\nINFO   -->  DU_APP: RLC UE Delete Response : SUCCESS [UE IDX:%d]", ueId);
3579          if(duCb.actvCellLst[cellIdx]!=NULLP)
3580          {
3581             duCb.actvCellLst[cellIdx]->ueCb[ueId-1].rlcUeCfg.rlcUeCfgState = UE_DELETE_COMPLETE;
3582             GET_CRNTI(crnti, ueId);
3583             if(sendUeDeleteReqToMac(delRsp->cellId, ueId, crnti) == RFAILED)
3584             {
3585                DU_LOG("\nERROR  -->  DU APP : duBuildAndSendUeDeleteReq(): Failed to build UE  delete req for MAC ");
3586                return RFAILED;
3587             }
3588
3589          }
3590       }
3591       else
3592       {
3593          DU_LOG("\nERROR   -->  DU_APP: RLC UE Delete Response : FAILED [UE IDX:%d]", ueId);
3594          ret = RFAILED;
3595       }
3596       DU_FREE_SHRABL_BUF(pst->region, pst->pool, delRsp, sizeof(RlcUeDeleteRsp));
3597
3598    }
3599    return ret;
3600 }
3601
3602 /*******************************************************************
3603  *
3604  * @brief Sending UE Delete Req To Mac
3605 *
3606 * @details
3607 *
3608 *    Function : sendUeDeleteReqToMac
3609 *
3610 *    Functionality:
3611 *     sending UE Delete Req To Mac
3612 *
3613 *  @params[in]    cellId, ueId, crnti 
3614 *  @return ROK     - success
3615 *          RFAILED - failure
3616 *
3617 *****************************************************************/
3618
3619 uint8_t sendUeDeleteReqToMac(uint16_t cellId, uint8_t ueId, uint16_t crnti)
3620 {
3621    Pst pst;
3622    uint8_t ret=ROK;
3623    MacUeDelete *ueDelete = NULLP;
3624
3625    DU_ALLOC_SHRABL_BUF(ueDelete, sizeof(MacUeDelete));
3626    if(ueDelete)
3627    {
3628       ueDelete->cellId = cellId;
3629       ueDelete->ueId   = ueId;
3630       ueDelete->crnti  = crnti;
3631       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_DELETE_REQ);
3632
3633       DU_LOG("\nDEBUG  -->  DU_APP: Sending UE delete Request to MAC ");
3634       ret = (*packMacUeDeleteReqOpts[pst.selector])(&pst, ueDelete);
3635       if(ret == RFAILED)
3636       {
3637          DU_LOG("\nERROR  -->  DU_APP: sendUeDeleteReqToMac(): Failed to send UE delete Req to MAC");
3638          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueDelete, sizeof(MacUeDelete));
3639       }
3640    }
3641    else
3642    {
3643       DU_LOG("\nERROR  -->   DU_APP: sendUeDeleteReqToMac(): Failed to allocate memory"); 
3644       ret = RFAILED;
3645    }
3646    return ret;
3647 }
3648
3649 /*******************************************************************
3650  *
3651  * @brief Sending UE Delete Req To Rlc
3652  *
3653  * @details
3654  *
3655  *    Function : sendUeDeleteReqToRlc
3656  *
3657  *    Functionality:
3658  *     Sending UE Delete Req To Rlc
3659  *
3660  *  @params[in]  cellId, ueId 
3661  *  @return ROK     - success
3662  *          RFAILED - failure
3663  *
3664  *****************************************************************/
3665
3666 uint8_t sendUeDeleteReqToRlc(uint16_t cellId, uint8_t ueId)
3667 {
3668    uint8_t ret;
3669    Pst pst;
3670    RlcUeDelete *ueDelete;
3671
3672    DU_ALLOC_SHRABL_BUF(ueDelete, sizeof(RlcUeDelete));
3673    if(ueDelete !=NULLP)
3674    {
3675       ueDelete->cellId = cellId;
3676       ueDelete->ueId = ueId;
3677       FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_DELETE_REQ);
3678
3679       ret = (*packRlcUeDeleteReqOpts[pst.selector])(&pst, ueDelete);
3680       if(ret == RFAILED)
3681       {
3682          DU_LOG("\nERROR  -->  DU_APP : sendUeDeleteReqToRlc():Failed to send UE Delete  Req to RLC"); 
3683          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueDelete, sizeof(RlcUeDelete));
3684       }
3685    }
3686    else
3687    {
3688       DU_LOG("\nERROR  -->   DU_APP: sendUeDeleteReqToRlc():Memory allocation failed");
3689       ret = RFAILED;
3690    }
3691    return ret;
3692 }
3693
3694 /*******************************************************************
3695  *
3696  * @brief DU processes UE delete req from CU and sends to MAC and RLC 
3697  *
3698  * @details
3699  *
3700  *    Function : duBuildAndSendUeDeleteReq
3701  *
3702  *    Functionality: DU processes UE delete req from CU and sends to MAC 
3703  *                   and RLC 
3704  *
3705  * @params[in] cellId, crnti 
3706  * @return ROK     - success
3707  *         RFAILED - failure
3708  *
3709  * ****************************************************************/
3710
3711 uint8_t duBuildAndSendUeDeleteReq(uint16_t cellId, uint16_t crnti)
3712 {
3713    uint8_t  ueId =0;
3714    uint16_t cellIdx = 0;
3715
3716    DU_LOG("\nDEBUG  -->  DU_APP: Processing UE Delete Request ");
3717    GET_CELL_IDX(cellId, cellIdx);
3718    GET_UE_ID(crnti, ueId);
3719
3720    if(duCb.actvCellLst[cellIdx] != NULLP)
3721    {
3722       if(crnti != duCb.actvCellLst[cellIdx]->ueCb[ueId - 1].crnti)
3723       {
3724          DU_LOG("\nERROR  -->  DU APP : duBuildAndSendUeDeleteReq(): CRNTI [%d] not found", crnti);
3725          return RFAILED;
3726       }
3727
3728       duCb.actvCellLst[cellIdx]->ueCb[ueId - 1].ueState = UE_DELETION_IN_PROGRESS; 
3729       if(sendUeDeleteReqToRlc(cellId, ueId) == RFAILED)
3730       {
3731          DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp():Failed to build UE  delete req for RLC ");
3732          return RFAILED;
3733       }
3734    }
3735    else
3736    {
3737       DU_LOG("\nERROR  -->  DU APP : duBuildAndSendUeDeleteReq(): Cell Id is not found");
3738       return RFAILED;
3739    }
3740
3741    return ROK;
3742 }
3743
3744 /*******************************************************************
3745  *
3746  * @brief delete RlcUeCfg from duCb
3747  *
3748  * @details
3749  *
3750  *    Function : deleteRlcUeCfg
3751  *
3752  *    Functionality:
3753  *       delete  RlcUeCfg from duCb
3754  *
3755  *  @params[in] RlcUeCfg *ueCfg 
3756  *               
3757  *  @return ROK     - success
3758  *          RFAILED - failure
3759  *
3760  *****************************************************************/
3761
3762 void deleteRlcUeCfg(RlcUeCfg *ueCfg)
3763 {
3764    uint8_t lcIdx = 0;
3765    RlcBearerCfg *lcCfg= NULLP;
3766    if(ueCfg)
3767    {
3768       for(lcIdx =0 ; lcIdx < ueCfg->numLcs ; lcIdx++)
3769       {
3770          lcCfg = &ueCfg->rlcLcCfg[lcIdx];
3771          switch(lcCfg->rlcMode)
3772          {
3773             case RLC_AM :
3774                {
3775                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
3776                   break;
3777                }
3778             case RLC_UM_BI_DIRECTIONAL :
3779                {
3780                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
3781                   break;
3782                }
3783             case RLC_UM_UNI_DIRECTIONAL_UL :
3784                {
3785                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
3786                   break;
3787                }
3788             case RLC_UM_UNI_DIRECTIONAL_DL :
3789                {
3790                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
3791                   break;
3792                }
3793          }
3794          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
3795       }
3796       memset(ueCfg, 0, sizeof(RlcUeCfg));
3797    }
3798 }
3799
3800 /*******************************************************************
3801 *
3802 * @brief Du process Ue Context Release Command
3803 *
3804 * @details
3805 *
3806 *    Function : duProcUeContextReleaseCommand 
3807 *
3808 *    Functionality: Du process Ue Context Release Command 
3809 *
3810 * @params[in] DuUeCb *duUeCb 
3811 * @return ROK     - success
3812 *         RFAILED - failure
3813 *
3814 * ****************************************************************/
3815 uint8_t duProcUeContextReleaseCommand(uint16_t cellId, DuUeCb *duUeCb)
3816 {
3817    uint8_t ret =ROK, ueId=0;
3818    uint16_t crnti = 0;
3819
3820    if(duUeCb != NULLP)
3821    {
3822       crnti = duUeCb->crnti;
3823       GET_UE_ID(crnti, ueId);
3824       
3825       if(duUeCb->f1UeDb)
3826       {
3827          /* Send DL RRC msg for RRC release */
3828          if(duUeCb->f1UeDb->dlRrcMsg)
3829          {
3830             if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu != NULLP)
3831             {
3832                ret = duBuildAndSendDlRrcMsgToRlc(cellId, duCb.actvCellLst[duUeCb->f1UeDb->cellIdx]->ueCb[ueId-1].rlcUeCfg,\
3833                      duUeCb->f1UeDb->dlRrcMsg);
3834                if(ret == RFAILED)
3835                {
3836                   DU_LOG("\nERROR  -->  DU APP : duProcUeContextReleaseCommand() : Failed to send DL RRC msg");
3837                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
3838                         duUeCb->f1UeDb->dlRrcMsg->rrcMsgSize);
3839                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
3840                }
3841             }
3842          }
3843       }
3844       else
3845       {
3846          ret = duBuildAndSendUeDeleteReq(cellId,crnti);
3847          if(ret == RFAILED)
3848          {
3849             DU_LOG("\nERROR  -->  DU APP : duProcUeContextReleaseCommand(): Failed to build and send Ue Delete request");
3850          }
3851       }
3852    }
3853    return ret;
3854 }
3855
3856 /**********************************************************************
3857   End of file
3858 ***********************************************************************/