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