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