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