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