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