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