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