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