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