74fe66d598c30ad053dececa8c491357849e3a51
[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]->ueIdx;
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.actvCellLst[cellIdx]->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, ueIdx, crnti, 
1173  *              DuUeCfg  pointer,
1174  *              MacUeCfg pointer
1175  * @return ROK/RFAILED
1176  *
1177  *****************************************************************/
1178 uint8_t fillMacUeCfg(uint16_t cellId, uint8_t ueIdx, uint16_t crnti, \
1179    DuUeCfg *ueCfgDb, MacUeCfg *macUeCfg)
1180 {
1181    uint8_t ret, dbIdx, lcIdx, cellIdx;
1182    bool lcIdFound = false;
1183    MacUeCfg *duMacDb = NULLP;
1184
1185    ret =ROK;
1186
1187    if(!ueCfgDb)
1188    {
1189       macUeCfg->cellId       = cellId;
1190       macUeCfg->ueIdx        = ueIdx;
1191       macUeCfg->crnti        = crnti;
1192
1193       fillDefaultMacCellGrpInfo(macUeCfg);
1194       fillDefaultPhyCellGrpInfo(macUeCfg);
1195       fillDefaultSpCellGrpInfo(macUeCfg);
1196       macUeCfg->ambrCfg = NULLP;
1197       fillDefaultModulation(macUeCfg);
1198       fillMacSrb1LcCfg(&macUeCfg->lcCfgList[0]);
1199       macUeCfg->numLcs++;
1200    }
1201    else
1202    {
1203       /* Fetching MacDb from DuUeCb */
1204       GET_CELL_IDX(cellId, cellIdx);
1205       duMacDb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg;
1206       duMacDb->macUeCfgState = UE_CFG_INPROGRESS;
1207       /* Fetching MaUeCfg List for ADD/MOD/DEL */
1208       macUeCfg->cellId       = cellId;
1209       macUeCfg->ueIdx        = ueIdx;
1210       macUeCfg->crnti        = crnti;
1211       ret = procUeReCfgCellInfo(macUeCfg, duMacDb, ueCfgDb->cellGrpCfg);
1212       if(ret == ROK)
1213       {
1214          if(macUeCfg->spCellCfgPres == true)
1215          {
1216             if(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschPresent)
1217             {
1218                fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc,\
1219                      &macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, NULL);
1220             }
1221             if(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschPresent)
1222             {
1223                fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
1224                      NULL, &macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg);
1225             }
1226          }
1227          ret = fillAmbr(&macUeCfg->ambrCfg, ueCfgDb->ambrCfg , &duMacDb->ambrCfg, FALSE);
1228          duFillModulationDetails(macUeCfg, duMacDb, ueCfgDb->ueNrCapability);
1229       }
1230
1231       /* Filling LC Context */
1232       for(dbIdx = 0; (dbIdx < ueCfgDb->numMacLcs && ret == ROK); dbIdx++)
1233       {
1234          if(!ueCfgDb->macLcCfg[dbIdx].ulLcCfgPres)
1235          {
1236             /* Filling default UL LC config in MAC if not present */
1237             ueCfgDb->macLcCfg[dbIdx].ulLcCfgPres = true;
1238             fillDefaultUlLcCfg(&ueCfgDb->macLcCfg[dbIdx].ulLcCfg);
1239          }
1240          for(lcIdx = 0; lcIdx < duMacDb->numLcs; lcIdx++)
1241          {
1242             if(ueCfgDb->macLcCfg[dbIdx].lcId == duMacDb->lcCfgList[lcIdx].lcId)
1243             {
1244                lcIdFound = true;
1245                if((ueCfgDb->macLcCfg[dbIdx].configType == CONFIG_UNKNOWN) ||
1246                      (ueCfgDb->macLcCfg[dbIdx].configType == CONFIG_MOD))
1247                {
1248                   ueCfgDb->macLcCfg[dbIdx].configType = CONFIG_MOD;
1249                   ret = fillMacLcCfgToAddMod(&macUeCfg->lcCfgList[dbIdx], &ueCfgDb->macLcCfg[dbIdx],\
1250                   &duMacDb->lcCfgList[lcIdx], FALSE);
1251                }
1252             }
1253             else
1254                lcIdFound = false;
1255          }
1256          if(!lcIdFound)
1257          {
1258             /* ADD/DEL CONFIG */
1259             ret = fillMacLcCfgToAddMod(&macUeCfg->lcCfgList[dbIdx], &ueCfgDb->macLcCfg[dbIdx], NULL, FALSE);
1260          }
1261          if(ret == ROK)
1262          {
1263             macUeCfg->numLcs++;
1264          }
1265          else
1266          {
1267             DU_LOG("\nERROR  -->  DU APP : Failed to add Lc at Idx %d in fillMacUeCfg()", dbIdx); 
1268             break;
1269          }
1270       }/*End of Outer FOR loop */
1271       memcpy(&ueCfgDb->copyOfmacUeCfg, macUeCfg, sizeof(MacUeCfg));
1272    }
1273    return ret;
1274 }
1275
1276 /******************************************************************
1277  *
1278  * @brief Fills Rlc AM Information
1279  *
1280  * @details
1281  *
1282  *    Function : fillDefaultAmInfo
1283  *
1284  *    Functionality: Fills Rlc AM Information
1285  *
1286  * @params[in]  AmBearerCfg *amCfg
1287  * @return void
1288  *
1289  *****************************************************************/
1290 void fillDefaultAmInfo(AmBearerCfg *amCfg)
1291 {
1292    /* DL AM */
1293    amCfg->dlAmCfg.snLenDl     = AM_SIZE_12;
1294    amCfg->dlAmCfg.pollRetxTmr = T_POLL_RETRANSMIT_VAL;
1295    amCfg->dlAmCfg.pollPdu     = POLL_PDU_VAL;
1296    amCfg->dlAmCfg.pollByte    = POLL_BYTE_VAL;
1297    amCfg->dlAmCfg.maxRetxTh   = MAX_RETX_THRESHOLD_VAL;   
1298  
1299    /* UL AM */
1300    amCfg->ulAmCfg.snLenUl     = AM_SIZE_12;
1301    amCfg->ulAmCfg.reAssemTmr  = T_REASSEMBLY_VAL; 
1302    amCfg->ulAmCfg.statProhTmr = T_STATUS_PROHIBHIT_VAL;
1303 }
1304
1305 /******************************************************************
1306  *
1307  * @brief Fills RLC UM Bi Directional Information
1308  *
1309  * @details
1310  *
1311  *    Function : fillDefaultUmBiInfo
1312  *
1313  *    Functionality: Fills RLC UM Bi Directional Information
1314  *
1315  * @params[in]  UmBiDirBearerCfg *umBiDirCfg
1316  * @return void
1317  *
1318  *****************************************************************/
1319 void fillDefaultUmBiInfo(UmBiDirBearerCfg *umBiDirCfg)
1320 {
1321    /* UL UM BI DIR INFO */
1322    umBiDirCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1323    umBiDirCfg->ulUmCfg.reAssemTmr = T_REASSEMBLY_VAL;
1324
1325    /* DL UM BI DIR INFO */
1326    umBiDirCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
1327 }
1328
1329 /******************************************************************
1330  *
1331  * @brief Fills RLC UM Uni Directional UL Information
1332  *
1333  * @details
1334  *
1335  *    Function : fillDefaultUmUlInfo
1336  *
1337  *    Functionality: Fills RLC UM Uni Directional Info
1338  *
1339  * @params[in]  UmUniDirUlBearerCfg *UmUlCfg
1340  * @return void
1341  *
1342  *****************************************************************/
1343 void fillDefaultUmUlInfo(UmUniDirUlBearerCfg *UmUlCfg)
1344 {
1345    UmUlCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1346    UmUlCfg->ulUmCfg.reAssemTmr = T_REASSEMBLY_VAL;
1347 }
1348
1349 /******************************************************************
1350  *
1351  * @brief Fills RLC UM Uni Directional DL Information
1352  *
1353  * @details
1354  *
1355  *    Function : fillDefaultUmDlInfo
1356  *
1357  *    Functionality: Fills RLC UM Uni Directional DL Info
1358  *
1359  * @params[in]  UmUniDirDlBearerCfg *UmDlCfg
1360  * @return void
1361  *
1362  *****************************************************************/
1363 void fillDefaultUmDlInfo(UmUniDirDlBearerCfg *UmDlCfg)
1364 {
1365    UmDlCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
1366 }
1367
1368 /******************************************************************
1369  *
1370  * @brief Builds Rlc Mode Default Configuration
1371  *
1372  * @details
1373  *
1374  *    Function : fillDefaultRlcModeCfg
1375  *
1376  *    Functionality: Builds Rlc Mode Default Configuration
1377  *
1378  * @params[in]  rlcMode, RlcBearerCfg *lcCfg
1379  * @return ROK/RFAILED
1380  *
1381  *****************************************************************/
1382
1383 uint8_t fillDefaultRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *lcCfg)
1384 {
1385    if(lcCfg)
1386    {
1387       switch(rlcMode)
1388       {
1389          case RLC_AM :
1390             {
1391                if(!lcCfg->u.amCfg)
1392                {
1393                   DU_ALLOC_SHRABL_BUF(lcCfg->u.amCfg, sizeof(AmBearerCfg));
1394                   if(lcCfg->u.amCfg)
1395                      fillDefaultAmInfo(lcCfg->u.amCfg);
1396                   else
1397                   {
1398                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at AmCfg at fillDefaultRlcModeCfg()");
1399                      return RFAILED;
1400                   }
1401                }
1402                break;
1403             }
1404          case RLC_UM_BI_DIRECTIONAL :
1405             {
1406                if(!lcCfg->u.umBiDirCfg)
1407                {
1408                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
1409                   if(lcCfg->u.umBiDirCfg)
1410                      fillDefaultUmBiInfo(lcCfg->u.umBiDirCfg);
1411                   else
1412                   {
1413                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmBiDirCfg at fillDefaultRlcModeCfg()");
1414                      return RFAILED;
1415                   }
1416                }
1417                break;
1418             }
1419          case RLC_UM_UNI_DIRECTIONAL_UL :
1420             {
1421                if(!lcCfg->u.umUniDirUlCfg)
1422                {
1423                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
1424                   if(lcCfg->u.umUniDirUlCfg)
1425                      fillDefaultUmUlInfo(lcCfg->u.umUniDirUlCfg);
1426                   else
1427                   {
1428                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmUniDirUlCfg at fillDefaultRlcModeCfg()");
1429                      return RFAILED;
1430                   }
1431                }
1432                break;
1433             }
1434          case RLC_UM_UNI_DIRECTIONAL_DL :
1435             {
1436                if(!lcCfg->u.umUniDirDlCfg)
1437                {
1438                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
1439                   if(lcCfg->u.umUniDirDlCfg)
1440                      fillDefaultUmDlInfo(lcCfg->u.umUniDirDlCfg);
1441                   else
1442                   {
1443                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmUniDirDlCfg at fillDefaultRlcModeCfg()");
1444                      return RFAILED;
1445                   }
1446                }
1447                break;
1448             }
1449          default:
1450             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
1451             return RFAILED;
1452       }
1453
1454    }
1455    else
1456    {
1457       DU_LOG("\nERROR  -->  DUAPP: Received LC Config is NULL");
1458       return RFAILED;
1459    }
1460    return ROK;
1461 }
1462
1463 /*******************************************************************
1464  *
1465  * @brief Function to fill Rlc Lc Cfg for SRB1
1466  *
1467  * @details
1468  *
1469  *    Function : fillRlcSrb1LcCfg
1470  *
1471  *    Functionality: 
1472  *     Function to fill Rlc Lc Cfg for SRB1
1473  * 
1474  *  @params[in]     Pointer to RlcBearerCfg
1475  *  @return ROK/RFAILED
1476  * 
1477  *****************************************************************/
1478
1479 uint8_t fillRlcSrb1LcCfg(RlcBearerCfg *rlcLcCfg)
1480 {
1481    uint8_t ret = ROK;
1482
1483    rlcLcCfg->rbId   = SRB1_LCID;
1484    rlcLcCfg->rbType = RB_TYPE_SRB;
1485    rlcLcCfg->lcId   = SRB1_LCID;
1486    rlcLcCfg->lcType = LCH_DCCH;
1487    rlcLcCfg->rlcMode = RLC_AM;
1488    rlcLcCfg->configType = CONFIG_ADD;
1489    ret = fillDefaultRlcModeCfg(rlcLcCfg->rlcMode, rlcLcCfg);
1490    return ret;
1491 }
1492
1493 /*******************************************************************
1494  *
1495  * @brief Processes UE ReConfig Req to RLC UL
1496  *
1497  * @details
1498  *
1499  *    Function : sendUeReCfgReqToRlc
1500  *
1501  *    Functionality: 
1502  *     Processes UE Reconfig Req to RLC UL
1503  * 
1504  *  @params[in]     Pointer to RlcUeCfg
1505  *  @return ROK     - success
1506  *          RFAILED - failure
1507  * 
1508  *****************************************************************/
1509
1510 uint8_t sendUeReCfgReqToRlc(RlcUeCfg *rlcUeCfg)
1511 {
1512    uint8_t ret;
1513    Pst pst;
1514    
1515    FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_RECONFIG_REQ);
1516    if(rlcUeCfg)
1517    {
1518       /* Processing one Ue at a time to RLC */
1519       DU_LOG("\nDEBUG   -->  DU_APP: Sending Ue Reconfig Request to RLC UL");
1520       ret = (*packRlcUeReconfigReqOpts[pst.selector])(&pst, rlcUeCfg);
1521       if(ret == RFAILED)
1522       {
1523          DU_LOG("\nERROR  -->  DU_APP : Failed to send Ue Reconfig Req to RLC at sendUeReCfgReqToRlc()");
1524          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rlcUeCfg, sizeof(RlcUeCfg));
1525       }
1526    }
1527    else
1528    {
1529       DU_LOG("\nERROR  -->   DU_APP: Received RlcUeCfg is NULL at sendUeReCfgReqToRlc()");
1530       ret = RFAILED;
1531    }
1532    return ret;
1533 }
1534
1535 /******************************************************************
1536  *
1537  * @brief Fills Snssai information
1538  *
1539  * @details
1540  *
1541  *    Function : fillSnssaiInfo
1542  *
1543  *    Functionality: Fills Snssai information
1544  *
1545  *  @params[in]    LcCfg *snssaiTobeSend, LcCfg *snssaiDb, LcCfg *oldSnssai,
1546  *  Bool toUpdateg
1547  *  @return ROK     - success
1548  *          RFAILED - failure
1549  * 
1550  *****************************************************************/
1551 uint8_t fillSnssaiInfo(Snssai *snssaiTobeSend, Snssai *snssaiDb, Snssai **oldSnssai, Bool toUpdate)
1552 {
1553    if(!toUpdate)
1554    {
1555       if(snssaiDb)
1556          snssaiTobeSend = snssaiDb;
1557       else if(oldSnssai)
1558          snssaiTobeSend = *oldSnssai;
1559       else
1560          snssaiTobeSend = NULL;
1561    }
1562    else
1563    {
1564       if(snssaiDb)
1565       {
1566          if(*oldSnssai)
1567             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, *oldSnssai, sizeof(Snssai));
1568
1569          DU_ALLOC_SHRABL_BUF(*oldSnssai, sizeof(Snssai));
1570          if(*oldSnssai == NULL)
1571          {
1572             DU_LOG("\nERROR  -->  DU APP : Memory Alloc Failed at fillSnssaiInfo()");
1573             return RFAILED;
1574          }
1575          memcpy(*oldSnssai, snssaiDb, sizeof(Snssai));
1576       }
1577    }
1578    return ROK;
1579 }
1580 /******************************************************************
1581  *
1582  * @brief Fills RlcBearerCfg structure
1583  *
1584  * @details
1585  *
1586  *    Function : fillRlcUeCfg
1587  *
1588  *    Functionality: Fills Rlc Bearer Cfg
1589  *
1590  *
1591  *****************************************************************/
1592 uint8_t fillRlcUeCfg(uint16_t cellId, uint8_t ueIdx,\
1593    DuUeCfg *ueCfgDb, RlcUeCfg *rlcUeCfg)
1594 {
1595    uint8_t ret, dbIdx, lcIdx, cellIdx;
1596    bool lcIdFound = false;
1597    RlcUeCfg *duRlcDb = NULLP;
1598
1599    ret = ROK;
1600    if(!ueCfgDb)
1601    {
1602       /* Initial RB being Added */ 
1603       rlcUeCfg->cellId       = cellId;
1604       rlcUeCfg->ueId         = ueIdx;
1605       ret = fillRlcSrb1LcCfg(&rlcUeCfg->rlcLcCfg[0]);
1606       if(ret == ROK)
1607          rlcUeCfg->numLcs++;
1608       else
1609          memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
1610    }
1611    else
1612    {
1613       /* Fetch RlcDb from DuUeCb */ 
1614       GET_CELL_IDX(cellId, cellIdx);
1615       duRlcDb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg;
1616       duRlcDb->rlcUeCfgState = UE_CFG_INPROGRESS;
1617       /*Filling RlcUeCfg */
1618       rlcUeCfg->cellId       = cellId;
1619       rlcUeCfg->ueId         = ueIdx;
1620       for(dbIdx = 0; (dbIdx < ueCfgDb->numRlcLcs && ret == ROK); dbIdx++)
1621       {
1622          ret = fillDefaultRlcModeCfg(ueCfgDb->rlcLcCfg[dbIdx].rlcMode, &ueCfgDb->rlcLcCfg[dbIdx]);
1623          if(ret == RFAILED)
1624          {
1625             DU_LOG("\n ERROR  -->  DU APP : Failed to fill Rlc Mode at fillRlcUeCfg()");
1626             memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
1627             return ret;
1628          }
1629          /* Fill Rlc Ue Cfg List for ADD/MOD/DEL */
1630          for(lcIdx = 0; lcIdx < duRlcDb->numLcs; lcIdx++)
1631          { 
1632             if(ueCfgDb->rlcLcCfg[dbIdx].lcId == duRlcDb->rlcLcCfg[lcIdx].lcId)
1633             {
1634                lcIdFound = true;
1635                if((ueCfgDb->rlcLcCfg[dbIdx].configType == CONFIG_UNKNOWN)||
1636                      (ueCfgDb->rlcLcCfg[dbIdx].configType == CONFIG_MOD))
1637                {
1638                   /* MOD */ 
1639                   ueCfgDb->rlcLcCfg[dbIdx].configType = CONFIG_MOD; /* update Db for MOD type */
1640                   memcpy(&rlcUeCfg->rlcLcCfg[dbIdx], &ueCfgDb->rlcLcCfg[dbIdx], sizeof(RlcBearerCfg));
1641                   fillSnssaiInfo(rlcUeCfg->rlcLcCfg[dbIdx].snssai, ueCfgDb->rlcLcCfg[dbIdx].snssai,\
1642                   &duRlcDb->rlcLcCfg[lcIdx].snssai,false);
1643                }
1644             }
1645             else
1646                lcIdFound = false;
1647          }
1648          if(!lcIdFound)
1649          {
1650             /* ADD/ DEL Config Type */
1651             memcpy(&rlcUeCfg->rlcLcCfg[dbIdx], &ueCfgDb->rlcLcCfg[dbIdx], sizeof(RlcBearerCfg));
1652             fillSnssaiInfo(rlcUeCfg->rlcLcCfg[dbIdx].snssai, ueCfgDb->rlcLcCfg[dbIdx].snssai, NULL, false);
1653          }
1654          rlcUeCfg->numLcs++;
1655       }
1656    }
1657    return ret;
1658 }
1659
1660 /******************************************************************
1661  *
1662  * @brief creates UE context
1663  *
1664  * @details
1665  *
1666  *    Function : duCreateUeCb
1667  *
1668  *    Functionality: Creates UE Conetxt
1669  *
1670  * @params[in] UeCcchCtxt Pointer
1671  *             UeIdx Pointer
1672  *
1673  * @return ROK     - success
1674  *         RFAILED - failure
1675  * ****************************************************************/
1676 uint8_t duCreateUeCb(UeCcchCtxt *ueCcchCtxt, uint32_t gnbCuUeF1apId)
1677 {
1678    uint8_t cellIdx = 0;
1679    uint8_t ret     = ROK;
1680    uint8_t ueIdx;
1681
1682    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
1683    {
1684       if(ueCcchCtxt->cellId == duCb.actvCellLst[cellIdx]->cellId)
1685       {
1686          GET_UE_IDX(ueCcchCtxt->crnti, ueIdx);
1687          DU_LOG("\nDEBUG   -->  DU_APP: Filling UeCb for ueIdx [%d]", ueIdx);
1688
1689          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].f1UeDb        = NULLP;
1690          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].crnti         = ueCcchCtxt->crnti;
1691          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbDuUeF1apId = ueCcchCtxt->gnbDuUeF1apId;
1692          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbCuUeF1apId = gnbCuUeF1apId;
1693          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].drbBitMap     = NULLP;
1694          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].ueState       = UE_ACTIVE;
1695
1696          /* Filling Mac Ue Config */ 
1697          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg, 0, sizeof(MacUeCfg));
1698          ret = duBuildAndSendUeCreateReqToMac(ueCcchCtxt->cellId, ueIdx, ueCcchCtxt->crnti,\
1699                 &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg);
1700          if(ret == RFAILED)
1701             DU_LOG("\nERROR  -->  DU APP : Failed to send UE create request to MAC");
1702          
1703          /* Filling Rlc Ue Config */
1704          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg, 0, sizeof(RlcUeCfg));
1705          ret = duBuildAndSendUeCreateReqToRlc(ueCcchCtxt->cellId, ueIdx, \
1706                 &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg);
1707          if(ret == RFAILED)
1708             DU_LOG("\nERROR  -->  DU APP : Failed to send UE create request to RLC");
1709
1710          duCb.actvCellLst[cellIdx]->numActvUes++;
1711          memset(ueCcchCtxt, 0, sizeof(UeCcchCtxt));
1712     duCb.numUe--;
1713       }
1714    }
1715    return ret;
1716 }
1717
1718 /******************************************************************
1719  *
1720  * @brief Builds and Send UE Create Request to MAC
1721  *
1722  * @details
1723  *
1724  *    Function : duBuildAndSendUeCreateReqToMac
1725  *
1726  *    Functionality: Builds and Send UE Create Request to MAC
1727  *
1728  * @Params[in]  cellId,
1729  *              ueIdx
1730  * @return ROK     - success
1731  *         RFAILED - failure
1732  *
1733  * ****************************************************************/
1734
1735 uint8_t duBuildAndSendUeCreateReqToMac(uint16_t cellId, uint8_t ueIdx,\
1736    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, ueIdx, 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->ueIdx-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)->ueIdx     = f1TnlCfg->ueIdx;
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] ueIdx, cellId, DuUeCfg 
2173  * @return ROK     - success
2174  *         RFAILED - failure
2175  *
2176  * ****************************************************************/
2177
2178 uint8_t duUpdateTunnelCfgDb(uint8_t ueIdx, 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].ueIdx = ueIdx;
2189       for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
2190       {
2191          if((duCb.upTnlCfg[teIdx]->ueIdx == duUeCfg->upTnlInfo[drbIdx].ueIdx) && \
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] ueIdx, cellIdx 
2235  * @return ROK     - success
2236  *         RFAILED - failure
2237  *
2238  * ****************************************************************/
2239
2240 uint8_t duUpdateDuUeCbCfg(uint8_t ueIdx, 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[ueIdx-1].macUeCfg. \
2248          macUeCfgState == UE_RECFG_COMPLETE) &&
2249       (duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg. \
2250          rlcUeCfgState == UE_RECFG_COMPLETE))
2251    {
2252       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1];
2253
2254       /*Filling RLC Ue Cfg */
2255       ueCb->rlcUeCfg.cellId = cellId;
2256       ueCb->rlcUeCfg.ueId   = ueIdx;
2257       ret = duUpdateRlcLcCfg(&ueCb->rlcUeCfg, ueCb->f1UeDb);
2258       if(ret == ROK)
2259       {
2260          /*Filling MAC Ue Cfg */
2261          GET_CRNTI(crnti, ueIdx);
2262          ueCb->macUeCfg.cellId = cellId;
2263          ueCb->macUeCfg.ueIdx  = ueIdx;
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(ueIdx, 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->ueIdx);
2311             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueIdx -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->ueIdx);
2317             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueIdx -1].\
2318                macUeCfg.macUeCfgState = UE_RECFG_COMPLETE;
2319             if((ret = duUpdateDuUeCbCfg(cfgRsp->ueIdx, cfgRsp->cellId)) == ROK)
2320             {
2321                BuildAndSendUeCtxtRsp(cfgRsp->cellId, cfgRsp->ueIdx);
2322             }
2323          }
2324       }
2325       else
2326       {
2327          DU_LOG("\nERROR  -->  DU APP : MAC UE CFG Response for EVENT[%d]: FAILURE [UE IDX : %d]", pst->event, cfgRsp->ueIdx);
2328          if(pst->event == EVENT_MAC_UE_RECONFIG_RSP)
2329          {
2330             //TODO: Send the failure case in Ue Context Setup Response
2331          }
2332          ret = RFAILED;
2333       }
2334       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(MacUeCfgRsp));
2335    }
2336    else
2337    {
2338       DU_LOG("\nERROR  -->  DU APP : Received MAC Ue Config Response is NULL at DuProcMacUeCfgRsp()");
2339       ret = RFAILED;
2340    }
2341    return ret;
2342 }
2343
2344
2345 /*******************************************************************
2346  *
2347  * @brief Processes UE create Req to RLC UL
2348  *
2349  * @details
2350  *
2351  *    Function : duBuildAndSendUeCreateReqToRlc
2352  *
2353  *    Functionality: 
2354  *     Processes UE create Req to RLC UL
2355  * 
2356  *  @params[in]  cellId,
2357  *               ueIdx,
2358  *               Pointer to RlcUeCfg
2359  *  @return ROK     - success
2360  *          RFAILED - failure
2361  * 
2362  *****************************************************************/
2363
2364 uint8_t duBuildAndSendUeCreateReqToRlc(uint16_t cellId, uint8_t ueIdx,\
2365    RlcUeCfg *duRlcUeCfg)
2366 {
2367    uint8_t  ret = ROK;
2368    RlcUeCfg *rlcUeCfg = NULLP;
2369    Pst       pst;
2370   
2371    ret = fillRlcUeCfg(cellId, ueIdx, NULL, duRlcUeCfg);
2372    if(ret == RFAILED)
2373    {
2374       DU_LOG("\nERROR  -->  DU APP : Failed to fill Rlc Ue Cfg at duBuildAndSendUeCreateReqToRlc()");
2375       return ret;
2376    }
2377
2378    FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_CREATE_REQ);
2379    /* Copying ueCfg to a sharable buffer */
2380    DU_ALLOC_SHRABL_BUF(rlcUeCfg, sizeof(RlcUeCfg));
2381    if(rlcUeCfg)
2382    {
2383       memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
2384       memcpy(rlcUeCfg, duRlcUeCfg, sizeof(RlcUeCfg));
2385       /* Processing one Ue at a time to RLC */
2386       DU_LOG("\nDEBUG   -->  DU_APP: Sending UE create request to RLC UL");
2387       ret = (*packRlcUeCreateReqOpts[pst.selector])(&pst, rlcUeCfg);
2388       if(ret == RFAILED)
2389       {
2390          DU_LOG("\nERROR  -->  DU_APP : Failure in sending Ue Create Req to RLC");
2391          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rlcUeCfg, sizeof(RlcUeCfg));
2392          ret = RFAILED;
2393       }
2394    }
2395    else
2396    {
2397       DU_LOG("\n ERROR  -->  DU APP : Memory alloc failed at duBuildAndSendUeCreateReqToRlc()");
2398       ret = RFAILED;
2399    }
2400    return ret;
2401 }
2402
2403 /*******************************************************************
2404  *
2405  * @brief Processes UE create Rsp received from RLC UL
2406  *
2407  * @details
2408  *
2409  
2410  *    Function : DuProcRlcUeCfgRsp
2411  *
2412  *    Functionality: 
2413  *     Processes UE create Rsp received from RLC UL
2414  * 
2415  *  @params[in]  Post structure
2416  *               Pointer to RlcCfgCfm
2417  *  @return ROK     - success
2418  *          RFAILED - failure
2419  * 
2420  *****************************************************************/
2421 uint8_t DuProcRlcUeCfgRsp(Pst *pst, RlcUeCfgRsp *cfgRsp)
2422 {
2423    uint8_t ret = ROK;
2424
2425    if(cfgRsp)
2426    {
2427       if(cfgRsp->result == RLC_DU_APP_RSP_OK)
2428       {
2429          if(pst->event == EVENT_RLC_UE_CREATE_RSP)
2430          {
2431             DU_LOG("\nINFO   -->  DU_APP: RLC UE Create Response : SUCCESS [UE IDX:%d]", cfgRsp->ueId);
2432             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].\
2433                rlcUeCfg.rlcUeCfgState = UE_CREATE_COMPLETE;
2434          }
2435          else if(pst->event == EVENT_RLC_UE_RECONFIG_RSP)
2436          {
2437             DU_LOG("\nINFO   -->  DU_APP: RLC UE Reconfig Response : SUCCESS [UE IDX:%d]", cfgRsp->ueId);
2438             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].\
2439                rlcUeCfg.rlcUeCfgState = UE_RECFG_COMPLETE;
2440             if((ret = duUpdateDuUeCbCfg(cfgRsp->ueId, cfgRsp->cellId)) == ROK)
2441             {
2442                BuildAndSendUeCtxtRsp(cfgRsp->cellId, cfgRsp->ueId);
2443             }   
2444          }
2445       }
2446       else
2447       {
2448          DU_LOG("\nERROR  -->  DU_APP: RLC UE CFG Response for EVENT[%d] : FAILED [UE IDX : %d, REASON :%d]",\
2449                pst->event, cfgRsp->ueId, cfgRsp->reason);
2450          if((pst->event == EVENT_RLC_UE_RECONFIG_RSP))
2451          {
2452             //TODO: update failure case in ue Context setup Response
2453          }
2454          ret = RFAILED;
2455       }
2456       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(RlcUeCfgRsp));
2457    }
2458    else
2459    {
2460       DU_LOG("\nERROR  -->  DU_APP: Received RLC Ue Config Response is NULL at DuProcRlcUeCfgRsp()");
2461       ret = RFAILED;
2462    }
2463    return ret;
2464 }
2465
2466 /*******************************************************************
2467  *
2468  * @brief Builds and Send Ue Reconfig Req to RLC
2469  *
2470  * @details
2471  *
2472  *    Function : duBuildAndSendUeReCfgReqToRLC
2473  *
2474  *    Functionality: Builds and Send Ue Reconfig Req to RLC
2475  *
2476  * @params[in] cellId, crnti
2477  *             DuUeCfg *ueCfgDb
2478  *             RlcUeCfg *rlcUeCfg
2479  * @return ROK     - success
2480  *         RFAILED - failure
2481  *
2482  * ****************************************************************/
2483
2484 uint8_t duBuildAndSendUeReCfgReqToRlc(uint8_t cellId, uint8_t crnti, DuUeCfg *ueCfgDb)
2485 {
2486    uint8_t ret = ROK, ueIdx = 0;
2487    RlcUeCfg *rlcUeCfg = NULLP;
2488
2489    GET_UE_IDX(crnti, ueIdx);
2490    DU_ALLOC_SHRABL_BUF(rlcUeCfg, sizeof(RlcUeCfg));
2491    if(rlcUeCfg)
2492    {
2493       memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
2494       ret = fillRlcUeCfg(cellId, ueIdx, ueCfgDb, rlcUeCfg);
2495       if(ret == RFAILED)
2496          DU_LOG("\nERROR  -->  DU APP : Failed at duBuildAndSendUeReCfgReqToRlc()");
2497       else
2498          ret = sendUeReCfgReqToRlc(rlcUeCfg);
2499    }
2500    else
2501    {
2502       DU_LOG("\nERROR  -->  DU APP : Memory Alloc failed at duBuildAndSendUeReCfgReqToRlc()");
2503       ret = RFAILED;
2504    }
2505    return ret;
2506 }
2507
2508 /*******************************************************************
2509  *
2510  * @brief Builds and Send Ue Reconfig Req to MAC
2511  *
2512  * @details
2513  *
2514  *    Function : duBuildAndSendUeReCfgReqToMac
2515  *
2516  *    Functionality: Builds and Send Ue Reconfig Req to MAC
2517  *
2518  * @params[in] CellGroupConfigRrc_t *macCellGrpCfg
2519  *             DuUeCfg *ueCfgDb
2520  *             MacUeCfg    *macUeCfg
2521  * @return ROK     - success
2522  *         RFAILED - failure
2523  *
2524  * ****************************************************************/
2525
2526 uint8_t duBuildAndSendUeReCfgReqToMac(uint8_t cellId, uint8_t crnti, DuUeCfg *ueCfgDb)
2527 {
2528    uint8_t ret, ueIdx = 0;
2529    MacUeCfg *macUeCfg = NULLP;
2530
2531    ret = ROK;
2532    GET_UE_IDX(crnti, ueIdx);
2533
2534    DU_ALLOC_SHRABL_BUF(macUeCfg, sizeof(MacUeCfg));
2535    if(macUeCfg)
2536    {
2537       memset(macUeCfg, 0, sizeof(MacUeCfg));
2538       ret = fillMacUeCfg(cellId, ueIdx, crnti, ueCfgDb, macUeCfg);
2539       if(ret == RFAILED)
2540          DU_LOG("\nERROR  -->  DU APP : Failed to fill Mac Ue Cfg at duBuildAndSendUeReCfgReqToMac()");
2541       else
2542          ret = sendUeReCfgReqToMac(macUeCfg);
2543    }
2544    else
2545    {
2546       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed for macUeCfg at duBuildAndSendUeReCfgReqToMac()");
2547       ret = RFAILED;
2548    }
2549    return ret;
2550 }
2551
2552 /*******************************************************************
2553  *
2554  * @brief Build and Send Ue context setup request
2555  *
2556  * @details
2557  *
2558  
2559  *    Function : duBuildAndSendUeContextSetupReq
2560  *
2561  *    Functionality: 
2562  *     Build and Send Ue context setup request
2563  * 
2564  *  @params[in]  cellId, crnti, DuUeCfg pointer
2565  *  @return ROK     - success
2566  *          RFAILED - failure
2567  * 
2568  *****************************************************************/
2569
2570 uint8_t duBuildAndSendUeContextSetupReq(uint16_t cellId, uint16_t crnti, DuUeCfg *duUeCfg)
2571 {
2572    uint8_t ret = ROK;
2573
2574    DU_LOG("\nDEBUG   -->  DU_APP: Processing Ue Context Setup Request for cellId [%d]", cellId);
2575    /* Filling RLC Ue Reconfig */ 
2576    ret = duBuildAndSendUeReCfgReqToRlc(cellId, crnti, duUeCfg);
2577    if(ret == RFAILED)
2578       DU_LOG("\nERROR  -->  DU APP : Failed to build ctxt setup req for RLC at duBuildAndSendUeContextSetupReq()");
2579    
2580    /* Filling MAC Ue Reconfig */
2581    ret = duBuildAndSendUeReCfgReqToMac(cellId, crnti, duUeCfg);
2582    if(ret == RFAILED)
2583       DU_LOG("\nERROR  -->  DU APP : Failed at build ctxt setup req for MAC at duBuildAndSendUeContextSetupReq()");
2584
2585    return ret;
2586 }
2587
2588 /*******************************************************************
2589  *
2590  * @brief Processes DL Rsp received from RLC DL
2591  *
2592  * @details
2593  *
2594  
2595  *    Function : DuProcRlcDlRrcMsgRsp
2596  *
2597  *    Functionality: 
2598  *     Processes UE Rsp received from RLC DL
2599  * 
2600  *  @params[in]  Post structure
2601  *               Pointer to RlcCfgCfm
2602  *  @return ROK     - success
2603  *          RFAILED - failure
2604  * 
2605  *****************************************************************/
2606 uint8_t DuProcRlcDlRrcMsgRsp(Pst *pst, RlcDlRrcMsgRsp *dlRrcMsg)
2607 {
2608    uint8_t ret = ROK, ueIdx = 0;
2609    uint16_t cellId, crnti;
2610    DuUeCb *ueCb = NULLP;
2611    DlMsgState state;
2612
2613    state = dlRrcMsg->state;
2614    cellId = dlRrcMsg->cellId;
2615    crnti = dlRrcMsg->crnti;
2616    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlRrcMsg, sizeof(RlcDlRrcMsgRsp));
2617
2618    if(state == TRANSMISSION_COMPLETE)
2619    {
2620       GET_UE_IDX(crnti, ueIdx);
2621       ueCb = &duCb.actvCellLst[cellId -1]->ueCb[ueIdx -1];
2622
2623       if(ueCb->f1UeDb && ueCb->f1UeDb->dlRrcMsgPres)
2624       {
2625          if(ueCb->f1UeDb->actionType == UE_CTXT_SETUP)
2626          {
2627             ret = duBuildAndSendUeContextSetupReq(cellId, crnti, &ueCb->f1UeDb->duUeCfg);
2628             if(ret == RFAILED)
2629                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Setup Request in DuProcRlcDlRrcMsgRsp()");
2630          }
2631          
2632          if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
2633          {
2634             ret = duBuildAndSendUeContextModReq(cellId, crnti, &ueCb->f1UeDb->duUeCfg);
2635             if(ret == RFAILED)
2636                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Mod Request in DuProcRlcDlRrcMsgRsp()");
2637          }
2638
2639          if(ueCb->f1UeDb->actionType == UE_CTXT_RELEASE && ueCb->ueState == UE_ACTIVE)
2640          {
2641             ret = duBuildAndSendUeDeleteReq(cellId, crnti);
2642             if(ret == RFAILED)
2643             {
2644                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Release Request in DuProcRlcDlRrcMsgRsp()");
2645             }
2646          }
2647       }
2648    }
2649    else
2650       DU_LOG("\nERROR  -->  DU APP : Failed to transmit DL RRC Msg");
2651
2652    return ret;
2653 }
2654 /*******************************************************************
2655  *
2656  * @brief Process UE context setup request from CU
2657  *
2658  * @details
2659  *
2660  *    Function : duProcUeContextSetupRequest 
2661  *
2662  *    Functionality: Process UE context setup request from CU
2663  *
2664  * @params[in] F1AP message
2665  * @return ROK     - success
2666  *         RFAILED - failure
2667  *
2668  * ****************************************************************/
2669
2670 uint8_t duProcUeContextSetupRequest(DuUeCb *ueCb)
2671 {
2672    uint8_t ret, cellId;
2673
2674    ret = ROK;
2675    if(ueCb)
2676    {
2677       cellId = duCb.actvCellLst[ueCb->f1UeDb->cellIdx]->cellId;
2678       /* Send DL RRC msg for security Mode */
2679       if(ueCb->f1UeDb->dlRrcMsg)
2680       {
2681          if(ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
2682          {
2683             /* Sending DL RRC Message to RLC */
2684             ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->rlcUeCfg, ueCb->f1UeDb->dlRrcMsg);
2685             if(ret == RFAILED)
2686             {
2687                DU_LOG("\nERROR  -->  DU APP : Failed to send DL RRC msg in duProcUeContextSetupRequest()");
2688                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
2689                      ueCb->f1UeDb->dlRrcMsg->rrcMsgSize);
2690                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
2691             }
2692          }
2693       }
2694       else if(ueCb->f1UeDb->actionType == UE_CTXT_SETUP)
2695       {
2696          ret = duBuildAndSendUeContextSetupReq(cellId, ueCb->crnti, &ueCb->f1UeDb->duUeCfg);
2697          if(ret == RFAILED)
2698          {
2699             DU_LOG("\nERROR  -->  DU APP : Failed to build ue context setup Req in duProcUeContextSetupRequest()");
2700          }
2701       }
2702    }
2703    else
2704    {
2705       //TODO: To send the failure cause in UeContextSetupRsp
2706       DU_LOG("ERROR  -->  DU APP : Failed to process UE CNTXT SETUP REQ at duProcUeContextSetupRequest()");
2707    }
2708    return ret;
2709 }
2710
2711 /*******************************************************************
2712  *
2713  * @brief Build and Send Ue context mod request
2714  *
2715  * @details
2716  *
2717  *
2718  *    Function : duBuildAndSendUeContextModReq
2719  *
2720  *    Functionality: 
2721  *     Build and Send Ue context mod request
2722  * 
2723  *  @params[in]  cellId, crnti, DuUeCfg pointer
2724  *  @return ROK     - success
2725  *          RFAILED - failure
2726  * 
2727  *****************************************************************/
2728
2729 uint8_t duBuildAndSendUeContextModReq(uint16_t cellId, uint16_t crnti, DuUeCfg *duUeCfg)
2730 {
2731    uint8_t ret = ROK;
2732
2733    DU_LOG("\nDEBUG   -->  DU_APP: Processing Ue Context Mod Request for cellId [%d]", cellId);
2734    /* Filling RLC Ue Reconfig */ 
2735    ret = duBuildAndSendUeReCfgReqToRlc(cellId, crnti, duUeCfg);
2736    if(ret == RFAILED)
2737       DU_LOG("\nERROR  -->  DU APP : Failed to build ctxt setup req for RLC at duBuildAndSendUeContextModReq()");
2738    
2739    /* Filling MAC Ue Reconfig */
2740    ret = duBuildAndSendUeReCfgReqToMac(cellId, crnti, duUeCfg);
2741    if(ret == RFAILED)
2742       DU_LOG("\nERROR  -->  DU APP : Failed at build ctxt setup req for MAC at duBuildAndSendUeContextModReq()");
2743
2744    return ret;
2745 }
2746 /*******************************************************************
2747  *
2748  * @brief Processing Ue context mod request
2749  *
2750  * @details
2751  *
2752  *
2753  *    Function : duProcUeContextModReq 
2754  *
2755  *    Functionality:
2756  *        Processing  Ue context mod request
2757  *
2758  *  @params[in] DuUeCb *ueCb 
2759  *  @return ROK     - success
2760  *          RFAILED - failure
2761  *
2762  *****************************************************************/
2763
2764 uint8_t duProcUeContextModReq(DuUeCb *ueCb)
2765 {
2766    uint8_t ret, cellId;
2767
2768    ret = ROK;
2769    if(ueCb)
2770    {
2771       cellId = duCb.actvCellLst[ueCb->f1UeDb->cellIdx]->cellId;
2772       /* Send DL RRC msg for security Mode */
2773       if(ueCb->f1UeDb->dlRrcMsg)
2774       {
2775          if(ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
2776          {
2777             /* Sending DL RRC Message to RLC */
2778             ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->rlcUeCfg, ueCb->f1UeDb->dlRrcMsg);
2779             if(ret == RFAILED)
2780             {
2781                DU_LOG("\nERROR  -->  DU APP : Failed to send DL RRC msg in duProcUeContextModReq()");
2782                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
2783                      ueCb->f1UeDb->dlRrcMsg->rrcMsgSize);
2784                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
2785             }
2786          }
2787       }
2788       else
2789       {
2790          ret = duBuildAndSendUeContextModReq(cellId, ueCb->crnti, &ueCb->f1UeDb->duUeCfg);
2791          if(ret == RFAILED)
2792          {
2793             DU_LOG("\nERROR  -->  DU APP : Failed to build ue context setup Req in duProcUeContextModReq()");
2794          }
2795       }
2796    }
2797    else
2798    {
2799       //TODO: To send the failure cause in UeContextModRsp
2800       DU_LOG("ERROR  -->  DU APP : Failed to process UE CNTXT MOD REQ at duProcUeContextModReq()");
2801    }
2802    return ROK;
2803 }
2804
2805 /*******************************************************************
2806 *
2807 * @brief Function to delete Pdsch ServCellCfg
2808 *
2809 * @details
2810 *
2811 *    Function : deletePdschServCellCfg
2812 *
2813 *    Functionality: Function to delete Pdsch ServCellCfg
2814 *
2815 * @params[in] PdschServCellCfg *pdschServCellCfg
2816 * @return void
2817 *
2818 * ****************************************************************/
2819
2820 void deletePdschServCellCfg(PdschServCellCfg *pdschServCellCfg)
2821 {
2822    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
2823    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
2824    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
2825    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->xOverhead, sizeof(PdschXOverhead));
2826 }
2827
2828 /*******************************************************************
2829  *
2830 * @brief delete MacUeCfg from duCb
2831 *
2832 * @details
2833 *
2834 *    Function : deleteMacUeCfg 
2835 *
2836 *    Functionality: delete MacUeCfg from duCb
2837 *
2838 * @params[in] Pointer to MacUeCfg 
2839 * @return ROK     - success
2840 *         RFAILED - failure
2841 *
2842 *******************************************************************/
2843
2844 void deleteMacUeCfg(MacUeCfg *ueCfg)
2845 {
2846    uint8_t lcCfgIdx=0;
2847    
2848    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,ueCfg->ambrCfg, sizeof(AmbrCfg));
2849    if(ueCfg->spCellCfgPres)
2850    {
2851       freeUeReCfgCellGrpInfo(ueCfg);
2852    }
2853    for(lcCfgIdx=0; lcCfgIdx< ueCfg->numLcs; lcCfgIdx++)
2854    {
2855       freeMacLcCfg(&ueCfg->lcCfgList[lcCfgIdx]);
2856    }
2857    memset(ueCfg, 0, sizeof(MacUeCfg));
2858 }
2859
2860 /*******************************************************************
2861 *
2862 * @brief delete UE Configuration of a particular UE
2863 *
2864 * @details
2865 *
2866 *    Function : deleteUeCfg 
2867 *
2868 *    Functionality: delete UE Configuration of a particular UE 
2869 *
2870 * @params[in] uint16_t cellIdx, uint8_t ueIdx
2871 * @return ROK     - success
2872 *         RFAILED - failure
2873 *
2874 * ****************************************************************/
2875 uint8_t  deleteUeCfg(uint16_t cellIdx, uint8_t ueIdx)
2876 {
2877    uint8_t tnlIdx = 0;
2878    DuUeCb *ueCb = NULLP;
2879    
2880    if(duCb.actvCellLst[cellIdx] != NULLP)
2881    {
2882       if((duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg.macUeCfgState == UE_DELETE_COMPLETE)\
2883             &&(duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg.rlcUeCfgState == UE_DELETE_COMPLETE))
2884       {
2885          ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1];
2886          deleteMacUeCfg(&ueCb->macUeCfg);
2887          deleteRlcUeCfg(&ueCb->rlcUeCfg);
2888          if(ueCb->f1UeDb !=NULLP)
2889          {
2890             freeF1UeDb(ueCb->f1UeDb);
2891          }
2892          for(tnlIdx = 0; tnlIdx < duCb.numTeId; )
2893          {
2894             if(duCb.upTnlCfg[tnlIdx]->ueIdx == ueIdx)
2895             {
2896                duCb.upTnlCfg[tnlIdx]->configType = CONFIG_DEL;
2897                duProcEgtpTunnelCfg(tnlIdx, duCb.upTnlCfg[tnlIdx], duCb.upTnlCfg[tnlIdx]);
2898             }
2899             else
2900                tnlIdx++;
2901          }
2902          duCb.actvCellLst[cellIdx]->numActvUes--;
2903          memset(ueCb, 0, sizeof(DuUeCb));
2904       }
2905       else
2906       {
2907          return RFAILED;
2908       }
2909    }
2910    else
2911    {
2912       DU_LOG("\nERROR  --> DU APP : deleteUeCfg(): CellIdx[%d] is not found", cellIdx);
2913       return RFAILED;
2914    }
2915    return ROK;
2916 }
2917
2918
2919 /*******************************************************************
2920 *
2921 * @brief Handle UE delete response from MAC
2922 *
2923 * @details
2924 *
2925 *    Function : DuProcMacUeDeleteRsp
2926 *
2927 *    Functionality: Handle UE delete response from MAC
2928 *
2929 * @params[in] Pointer to MacUeDeleteRsp and Pst
2930 * @return ROK     - success
2931 *         RFAILED - failure
2932 *
2933 * ****************************************************************/
2934
2935 uint8_t DuProcMacUeDeleteRsp(Pst *pst, MacUeDeleteRsp *deleteRsp)
2936 {
2937    uint8_t  ret =ROK,ueId=0;
2938    uint16_t cellIdx=0;
2939    uint32_t gnbCuUeF1apId =0 , gnbDuUeF1apId =0;
2940    
2941    if(deleteRsp)
2942    {
2943       if(deleteRsp->result == SUCCESS)
2944       {
2945          DU_LOG("\nINFO   -->  DU APP : MAC UE Delete Response : SUCCESS [UE IDX : %d]", deleteRsp->ueId);
2946          GET_CELL_IDX(deleteRsp->cellId, cellIdx);
2947          if(duCb.actvCellLst[cellIdx])
2948          {
2949             duCb.actvCellLst[cellIdx]->ueCb[deleteRsp->ueId -1].macUeCfg.macUeCfgState = UE_DELETE_COMPLETE;
2950             ueId = deleteRsp->ueId;
2951             gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
2952             gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
2953             if(deleteUeCfg(cellIdx, ueId) == ROK)
2954             {
2955                ret = BuildAndSendUeContextReleaseComplete(deleteRsp->cellId, gnbCuUeF1apId, gnbDuUeF1apId);
2956                if(ret != ROK)
2957                {
2958                   DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): failed to send UE context release complete");
2959                }
2960             }
2961
2962          }
2963       }
2964       else
2965       {
2966          DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): MAC UE Delete Response : FAILURE [UE IDX : %d]",\
2967          deleteRsp->ueId);
2968          ret =  RFAILED;
2969       }
2970       DU_FREE_SHRABL_BUF(pst->region, pst->pool, deleteRsp, sizeof(MacUeDeleteRsp));
2971    }
2972    else
2973    {
2974       DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): MAC UE Delete Response is null");
2975       ret = RFAILED;
2976    }
2977    return ret;
2978 }
2979
2980 /*******************************************************************
2981  *
2982  * @brief Processes UE Delete Rsp received from RLC 
2983  *
2984  * @details
2985  *
2986  *    Function : DuProcRlcUeDeleteRsp
2987  *
2988  *    Functionality:
2989  *     Processes UE Delete Rsp received from RLC 
2990  *
2991  *  @params[in]  Post structure
2992  *               Pointer to RlcUeDeleteRsp
2993  *  @return ROK     - success
2994  *          RFAILED - failure
2995  *
2996  * *****************************************************************/
2997
2998 uint8_t DuProcRlcUeDeleteRsp(Pst *pst, RlcUeDeleteRsp *delRsp)
2999 {
3000    uint8_t  ueId = 0, ret = ROK;
3001    uint16_t cellIdx = 0,crnti=0;
3002
3003    if(delRsp)
3004    {
3005       ueId = delRsp->ueId;
3006       GET_CELL_IDX(delRsp->cellId, cellIdx);
3007
3008       if(delRsp->result == SUCCESSFUL)
3009       {
3010          DU_LOG("\nINFO   -->  DU_APP: RLC UE Delete Response : SUCCESS [UE IDX:%d]", ueId);
3011          if(duCb.actvCellLst[cellIdx]!=NULLP)
3012          {
3013             duCb.actvCellLst[cellIdx]->ueCb[ueId-1].rlcUeCfg.rlcUeCfgState = UE_DELETE_COMPLETE;
3014             GET_CRNTI(crnti, ueId);
3015             if(sendUeDeleteReqToMac(delRsp->cellId, ueId, crnti) == RFAILED)
3016             {
3017                DU_LOG("\nERROR  -->  DU APP : duBuildAndSendUeDeleteReq(): Failed to build UE  delete req for MAC ");
3018                return RFAILED;
3019             }
3020
3021          }
3022       }
3023       else
3024       {
3025          DU_LOG("\nERROR   -->  DU_APP: RLC UE Delete Response : FAILED [UE IDX:%d]", ueId);
3026          ret = RFAILED;
3027       }
3028       DU_FREE_SHRABL_BUF(pst->region, pst->pool, delRsp, sizeof(RlcUeDeleteRsp));
3029
3030    }
3031    return ret;
3032 }
3033
3034 /*******************************************************************
3035  *
3036  * @brief Sending UE Delete Req To Mac
3037 *
3038 * @details
3039 *
3040 *    Function : sendUeDeleteReqToMac
3041 *
3042 *    Functionality:
3043 *     sending UE Delete Req To Mac
3044 *
3045 *  @params[in]    cellId, ueId, crnti 
3046 *  @return ROK     - success
3047 *          RFAILED - failure
3048 *
3049 *****************************************************************/
3050
3051 uint8_t sendUeDeleteReqToMac(uint16_t cellId, uint8_t ueId, uint16_t crnti)
3052 {
3053    Pst pst;
3054    uint8_t ret=ROK;
3055    MacUeDelete *ueDelete = NULLP;
3056
3057    DU_ALLOC_SHRABL_BUF(ueDelete, sizeof(MacUeDelete));
3058    if(ueDelete)
3059    {
3060       ueDelete->cellId = cellId;
3061       ueDelete->ueId   = ueId;
3062       ueDelete->crnti  = crnti;
3063       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_DELETE_REQ);
3064
3065       DU_LOG("\nDEBUG  -->  DU_APP: Sending UE delete Request to MAC ");
3066       ret = (*packMacUeDeleteReqOpts[pst.selector])(&pst, ueDelete);
3067       if(ret == RFAILED)
3068       {
3069          DU_LOG("\nERROR  -->  DU_APP: sendUeDeleteReqToMac(): Failed to send UE delete Req to MAC");
3070          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueDelete, sizeof(MacUeDelete));
3071       }
3072    }
3073    else
3074    {
3075       DU_LOG("\nERROR  -->   DU_APP: sendUeDeleteReqToMac(): Failed to allocate memory"); 
3076       ret = RFAILED;
3077    }
3078    return ret;
3079 }
3080
3081 /*******************************************************************
3082  *
3083  * @brief Sending UE Delete Req To Rlc
3084  *
3085  * @details
3086  *
3087  *    Function : sendUeDeleteReqToRlc
3088  *
3089  *    Functionality:
3090  *     Sending UE Delete Req To Rlc
3091  *
3092  *  @params[in]  cellId, ueId 
3093  *  @return ROK     - success
3094  *          RFAILED - failure
3095  *
3096  *****************************************************************/
3097
3098 uint8_t sendUeDeleteReqToRlc(uint16_t cellId, uint8_t ueId)
3099 {
3100    uint8_t ret;
3101    Pst pst;
3102    RlcUeDelete *ueDelete;
3103
3104    DU_ALLOC_SHRABL_BUF(ueDelete, sizeof(RlcUeDelete));
3105    if(ueDelete !=NULLP)
3106    {
3107       ueDelete->cellId = cellId;
3108       ueDelete->ueId = ueId;
3109       FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_DELETE_REQ);
3110
3111       ret = (*packRlcUeDeleteReqOpts[pst.selector])(&pst, ueDelete);
3112       if(ret == RFAILED)
3113       {
3114          DU_LOG("\nERROR  -->  DU_APP : sendUeDeleteReqToRlc():Failed to send UE Delete  Req to RLC"); 
3115          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueDelete, sizeof(RlcUeDelete));
3116       }
3117    }
3118    else
3119    {
3120       DU_LOG("\nERROR  -->   DU_APP: sendUeDeleteReqToRlc():Memory allocation failed");
3121       ret = RFAILED;
3122    }
3123    return ret;
3124 }
3125
3126 /*******************************************************************
3127  *
3128  * @brief DU processes UE delete req from CU and sends to MAC and RLC 
3129  *
3130  * @details
3131  *
3132  *    Function : duBuildAndSendUeDeleteReq
3133  *
3134  *    Functionality: DU processes UE delete req from CU and sends to MAC 
3135  *                   and RLC 
3136  *
3137  * @params[in] cellId, crnti 
3138  * @return ROK     - success
3139  *         RFAILED - failure
3140  *
3141  * ****************************************************************/
3142
3143 uint8_t duBuildAndSendUeDeleteReq(uint16_t cellId, uint16_t crnti)
3144 {
3145    uint8_t  ueId =0;
3146    uint16_t cellIdx = 0;
3147
3148    DU_LOG("\nDEBUG  -->  DU_APP: Processing UE Delete Request ");
3149    GET_CELL_IDX(cellId, cellIdx);
3150    GET_UE_IDX(crnti, ueId);
3151
3152    if(duCb.actvCellLst[cellIdx] != NULLP)
3153    {
3154       if(crnti != duCb.actvCellLst[cellIdx]->ueCb[ueId - 1].crnti)
3155       {
3156          DU_LOG("\nERROR  -->  DU APP : duBuildAndSendUeDeleteReq(): CRNTI [%d] not found", crnti);
3157          return RFAILED;
3158       }
3159
3160       duCb.actvCellLst[cellIdx]->ueCb[ueId - 1].ueState = UE_DELETION_IN_PROGRESS; 
3161       if(sendUeDeleteReqToRlc(cellId, ueId) == RFAILED)
3162       {
3163          DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp():Failed to build UE  delete req for RLC ");
3164          return RFAILED;
3165       }
3166    }
3167    else
3168    {
3169       DU_LOG("\nERROR  -->  DU APP : duBuildAndSendUeDeleteReq(): Cell Id is not found");
3170       return RFAILED;
3171    }
3172
3173    return ROK;
3174 }
3175
3176 /*******************************************************************
3177  *
3178  * @brief delete RlcUeCfg from duCb
3179  *
3180  * @details
3181  *
3182  *    Function : deleteRlcUeCfg
3183  *
3184  *    Functionality:
3185  *       delete  RlcUeCfg from duCb
3186  *
3187  *  @params[in] RlcUeCfg *ueCfg 
3188  *               
3189  *  @return ROK     - success
3190  *          RFAILED - failure
3191  *
3192  *****************************************************************/
3193
3194 void deleteRlcUeCfg(RlcUeCfg *ueCfg)
3195 {
3196    uint8_t lcIdx = 0;
3197    RlcBearerCfg *lcCfg= NULLP;
3198    if(ueCfg)
3199    {
3200       for(lcIdx =0 ; lcIdx < ueCfg->numLcs ; lcIdx++)
3201       {
3202          lcCfg = &ueCfg->rlcLcCfg[lcIdx];
3203          switch(lcCfg->rlcMode)
3204          {
3205             case RLC_AM :
3206                {
3207                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
3208                   break;
3209                }
3210             case RLC_UM_BI_DIRECTIONAL :
3211                {
3212                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
3213                   break;
3214                }
3215             case RLC_UM_UNI_DIRECTIONAL_UL :
3216                {
3217                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
3218                   break;
3219                }
3220             case RLC_UM_UNI_DIRECTIONAL_DL :
3221                {
3222                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
3223                   break;
3224                }
3225          }
3226          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
3227       }
3228       memset(ueCfg, 0, sizeof(RlcUeCfg));
3229    }
3230 }
3231
3232 /*******************************************************************
3233 *
3234 * @brief Du process Ue Context Release Command
3235 *
3236 * @details
3237 *
3238 *    Function : duProcUeContextReleaseCommand 
3239 *
3240 *    Functionality: Du process Ue Context Release Command 
3241 *
3242 * @params[in] DuUeCb *duUeCb 
3243 * @return ROK     - success
3244 *         RFAILED - failure
3245 *
3246 * ****************************************************************/
3247 uint8_t duProcUeContextReleaseCommand(DuUeCb *duUeCb)
3248 {
3249    uint8_t ret =ROK, ueIdx=0;
3250    uint16_t cellId=0,crnti =0;
3251    if(duUeCb == NULLP)
3252    {
3253       DU_LOG("\nERROR  -->  DU APP : duProcUeContextReleaseCommand() : duUeCb is null");
3254       return RFAILED;
3255    }
3256    if(duUeCb->f1UeDb == NULLP)
3257    {
3258       DU_LOG("\nERROR  -->  DU APP : duProcUeContextReleaseCommand() : f1UeDb is null");
3259       return RFAILED;
3260    }
3261    
3262    cellId = duCb.actvCellLst[duUeCb->f1UeDb->cellIdx]->cellId;
3263    crnti = duUeCb->crnti;
3264    GET_UE_IDX(crnti, ueIdx);
3265    
3266    /* Send DL RRC msg for RRC release */
3267    if(duUeCb->f1UeDb->dlRrcMsg)
3268    {
3269       if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu != NULLP)
3270       {
3271          ret = duBuildAndSendDlRrcMsgToRlc(cellId, duCb.actvCellLst[duUeCb->f1UeDb->cellIdx]->ueCb[ueIdx-1].rlcUeCfg,\
3272                duUeCb->f1UeDb->dlRrcMsg);
3273          if(ret == RFAILED)
3274          {
3275             DU_LOG("\nERROR  -->  DU APP : duProcUeContextReleaseCommand() : Failed to send DL RRC msg");
3276             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
3277                   duUeCb->f1UeDb->dlRrcMsg->rrcMsgSize);
3278             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
3279          }
3280       }
3281    }
3282    else
3283    {
3284       ret = duBuildAndSendUeDeleteReq(cellId,crnti);
3285       if(ret == RFAILED)
3286       {
3287          DU_LOG("\nERROR  -->  DU APP : duProcUeContextReleaseCommand(): Failed to build and send Ue Delete request");
3288       }
3289    }
3290
3291    return ret;
3292 }
3293
3294 /**********************************************************************
3295   End of file
3296 ***********************************************************************/