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