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