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