[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-423]UE context creation at RLC in Target...
[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, 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    macUeCfg->ueId = gnbDuUef1apId;
1174    GET_CRNTI(macUeCfg->crnti, macUeCfg->ueId);
1175
1176    if(!ueCfgDb)
1177    {
1178       fillDefaultMacCellGrpInfo(macUeCfg);
1179       fillDefaultPhyCellGrpInfo(macUeCfg);
1180
1181       if((fillDefaultSpCellGrpInfo(macUeCfg)) != ROK)
1182       {
1183          DU_LOG("\nERROR  --> DUAPP : Failed in fillDefaultSpCellGrpInfo");
1184          return RFAILED;
1185       }
1186
1187       macUeCfg->ambrCfg = NULLP;
1188       fillDefaultModulation(macUeCfg);
1189       fillMacSrb1LcCfg(&macUeCfg->lcCfgList[0]);
1190       macUeCfg->numLcs++;
1191    }
1192    else
1193    {
1194       if(ueCfgDb->dataTransmissionAction == STOP_TRANSMISSION)
1195       {
1196          macUeCfg->transmissionAction = ueCfgDb->dataTransmissionAction; 
1197          return ROK;
1198       }
1199
1200       GET_CELL_IDX(cellId, cellIdx);
1201       if(duCb.actvCellLst[cellIdx])
1202          duMacDb = &duCb.actvCellLst[cellIdx]->ueCb[macUeCfg->ueId-1].macUeCfg;
1203       else
1204       {
1205          DU_LOG("\nERROR  -->  DU APP : Cell Id [%d] does not exist", cellId);
1206          return RFAILED;
1207       }
1208       duMacDb->macUeCfgState = UE_CFG_INPROGRESS;
1209       
1210       if(ueCfgDb->cellGrpCfg)
1211       {
1212          ret = procUeReCfgCellInfo(macUeCfg, duMacDb, ueCfgDb->cellGrpCfg);
1213          if(ret == ROK)
1214          {
1215             if(macUeCfg->spCellCfgPres == true)
1216             {
1217                if(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschPresent)
1218                {
1219                   fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc,\
1220                         &macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, NULL);
1221                }
1222                if(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschPresent)
1223                {
1224                   fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
1225                         NULL, &macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg);
1226                }
1227             }
1228
1229             if(duMacDb)
1230                ret = fillAmbr(&macUeCfg->ambrCfg, ueCfgDb->ambrCfg , &duMacDb->ambrCfg, FALSE);
1231             else
1232                ret = fillAmbr(&macUeCfg->ambrCfg, ueCfgDb->ambrCfg , NULL, FALSE);
1233
1234             duFillModulationDetails(macUeCfg, duMacDb, ueCfgDb->ueNrCapability);
1235          }
1236       }
1237       else
1238       {
1239          fillDefaultMacCellGrpInfo(macUeCfg);
1240          fillDefaultPhyCellGrpInfo(macUeCfg);
1241          fillDefaultSpCellGrpInfo(macUeCfg);
1242          fillDefaultModulation(macUeCfg);
1243       }
1244
1245       /* Filling LC Context */
1246       for(dbIdx = 0; (dbIdx < ueCfgDb->numMacLcs && ret == ROK); dbIdx++)
1247       {
1248          if(!ueCfgDb->macLcCfg[dbIdx].ulLcCfgPres)
1249          {
1250             /* Filling default UL LC config in MAC if not present */
1251             ueCfgDb->macLcCfg[dbIdx].ulLcCfgPres = true;
1252             fillDefaultUlLcCfg(&ueCfgDb->macLcCfg[dbIdx].ulLcCfg);
1253          }
1254
1255          if(duMacDb)
1256          {
1257             for(lcIdx = 0; lcIdx < duMacDb->numLcs; lcIdx++)
1258             {
1259                if(ueCfgDb->macLcCfg[dbIdx].lcId == duMacDb->lcCfgList[lcIdx].lcId)
1260                {
1261                   lcIdFound = true;
1262                   if((ueCfgDb->macLcCfg[dbIdx].configType == CONFIG_UNKNOWN) ||
1263                         (ueCfgDb->macLcCfg[dbIdx].configType == CONFIG_MOD))
1264                   {
1265                      ueCfgDb->macLcCfg[dbIdx].configType = CONFIG_MOD;
1266                      ret = fillMacLcCfgToAddMod(&macUeCfg->lcCfgList[dbIdx], &ueCfgDb->macLcCfg[dbIdx],\
1267                            &duMacDb->lcCfgList[lcIdx], FALSE);
1268                   }
1269                }
1270                else
1271                   lcIdFound = false;
1272             }
1273          }
1274
1275          if(!lcIdFound)
1276          {
1277             /* ADD/DEL CONFIG */
1278             ret = fillMacLcCfgToAddMod(&macUeCfg->lcCfgList[dbIdx], &ueCfgDb->macLcCfg[dbIdx], NULL, FALSE);
1279          }
1280          if(ret == ROK)
1281          {
1282             macUeCfg->numLcs++;
1283          }
1284          else
1285          {
1286             DU_LOG("\nERROR  -->  DU APP : Failed to add Lc at Idx %d in fillMacUeCfg()", dbIdx); 
1287             break;
1288          }
1289       }/*End of Outer FOR loop */
1290       memcpy(&ueCfgDb->copyOfmacUeCfg, macUeCfg, sizeof(MacUeCfg));
1291    }
1292    return ret;
1293 }
1294
1295 /******************************************************************
1296  *
1297  * @brief Fills Rlc AM Information
1298  *
1299  * @details
1300  *
1301  *    Function : fillDefaultAmInfo
1302  *
1303  *    Functionality: Fills Rlc AM Information
1304  *
1305  * @params[in]  AmBearerCfg *amCfg
1306  * @return void
1307  *
1308  *****************************************************************/
1309 void fillDefaultAmInfo(AmBearerCfg *amCfg)
1310 {
1311    /* DL AM */
1312    amCfg->dlAmCfg.snLenDl     = AM_SIZE_12;
1313    amCfg->dlAmCfg.pollRetxTmr = T_POLL_RETRANSMIT_VAL;
1314    amCfg->dlAmCfg.pollPdu     = POLL_PDU_VAL;
1315    amCfg->dlAmCfg.pollByte    = POLL_BYTE_VAL;
1316    amCfg->dlAmCfg.maxRetxTh   = MAX_RETX_THRESHOLD_VAL;   
1317  
1318    /* UL AM */
1319    amCfg->ulAmCfg.snLenUl     = AM_SIZE_12;
1320    amCfg->ulAmCfg.reAssemTmr  = T_REASSEMBLY_VAL; 
1321    amCfg->ulAmCfg.statProhTmr = T_STATUS_PROHIBHIT_VAL;
1322 }
1323
1324 /******************************************************************
1325  *
1326  * @brief Fills RLC UM Bi Directional Information
1327  *
1328  * @details
1329  *
1330  *    Function : fillDefaultUmBiInfo
1331  *
1332  *    Functionality: Fills RLC UM Bi Directional Information
1333  *
1334  * @params[in]  UmBiDirBearerCfg *umBiDirCfg
1335  * @return void
1336  *
1337  *****************************************************************/
1338 void fillDefaultUmBiInfo(UmBiDirBearerCfg *umBiDirCfg)
1339 {
1340    /* UL UM BI DIR INFO */
1341    umBiDirCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1342    umBiDirCfg->ulUmCfg.reAssemTmr = T_REASSEMBLY_VAL;
1343
1344    /* DL UM BI DIR INFO */
1345    umBiDirCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
1346 }
1347
1348 /******************************************************************
1349  *
1350  * @brief Fills RLC UM Uni Directional UL Information
1351  *
1352  * @details
1353  *
1354  *    Function : fillDefaultUmUlInfo
1355  *
1356  *    Functionality: Fills RLC UM Uni Directional Info
1357  *
1358  * @params[in]  UmUniDirUlBearerCfg *UmUlCfg
1359  * @return void
1360  *
1361  *****************************************************************/
1362 void fillDefaultUmUlInfo(UmUniDirUlBearerCfg *UmUlCfg)
1363 {
1364    UmUlCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1365    UmUlCfg->ulUmCfg.reAssemTmr = T_REASSEMBLY_VAL;
1366 }
1367
1368 /******************************************************************
1369  *
1370  * @brief Fills RLC UM Uni Directional DL Information
1371  *
1372  * @details
1373  *
1374  *    Function : fillDefaultUmDlInfo
1375  *
1376  *    Functionality: Fills RLC UM Uni Directional DL Info
1377  *
1378  * @params[in]  UmUniDirDlBearerCfg *UmDlCfg
1379  * @return void
1380  *
1381  *****************************************************************/
1382 void fillDefaultUmDlInfo(UmUniDirDlBearerCfg *UmDlCfg)
1383 {
1384    UmDlCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
1385 }
1386
1387 /******************************************************************
1388  *
1389  * @brief Builds Rlc Mode Default Configuration
1390  *
1391  * @details
1392  *
1393  *    Function : fillDefaultRlcModeCfg
1394  *
1395  *    Functionality: Builds Rlc Mode Default Configuration
1396  *
1397  * @params[in]  rlcMode, RlcBearerCfg *lcCfg
1398  * @return ROK/RFAILED
1399  *
1400  *****************************************************************/
1401
1402 uint8_t fillDefaultRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *lcCfg)
1403 {
1404    if(lcCfg)
1405    {
1406       switch(rlcMode)
1407       {
1408          case RLC_AM :
1409             {
1410                if(!lcCfg->u.amCfg)
1411                {
1412                   DU_ALLOC_SHRABL_BUF(lcCfg->u.amCfg, sizeof(AmBearerCfg));
1413                   if(lcCfg->u.amCfg)
1414                      fillDefaultAmInfo(lcCfg->u.amCfg);
1415                   else
1416                   {
1417                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at AmCfg at fillDefaultRlcModeCfg()");
1418                      return RFAILED;
1419                   }
1420                }
1421                break;
1422             }
1423          case RLC_UM_BI_DIRECTIONAL :
1424             {
1425                if(!lcCfg->u.umBiDirCfg)
1426                {
1427                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
1428                   if(lcCfg->u.umBiDirCfg)
1429                      fillDefaultUmBiInfo(lcCfg->u.umBiDirCfg);
1430                   else
1431                   {
1432                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmBiDirCfg at fillDefaultRlcModeCfg()");
1433                      return RFAILED;
1434                   }
1435                }
1436                break;
1437             }
1438          case RLC_UM_UNI_DIRECTIONAL_UL :
1439             {
1440                if(!lcCfg->u.umUniDirUlCfg)
1441                {
1442                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
1443                   if(lcCfg->u.umUniDirUlCfg)
1444                      fillDefaultUmUlInfo(lcCfg->u.umUniDirUlCfg);
1445                   else
1446                   {
1447                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmUniDirUlCfg at fillDefaultRlcModeCfg()");
1448                      return RFAILED;
1449                   }
1450                }
1451                break;
1452             }
1453          case RLC_UM_UNI_DIRECTIONAL_DL :
1454             {
1455                if(!lcCfg->u.umUniDirDlCfg)
1456                {
1457                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
1458                   if(lcCfg->u.umUniDirDlCfg)
1459                      fillDefaultUmDlInfo(lcCfg->u.umUniDirDlCfg);
1460                   else
1461                   {
1462                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmUniDirDlCfg at fillDefaultRlcModeCfg()");
1463                      return RFAILED;
1464                   }
1465                }
1466                break;
1467             }
1468          default:
1469             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
1470             return RFAILED;
1471       }
1472
1473    }
1474    else
1475    {
1476       DU_LOG("\nERROR  -->  DUAPP: Received LC Config is NULL");
1477       return RFAILED;
1478    }
1479    return ROK;
1480 }
1481
1482 /*******************************************************************
1483  *
1484  * @brief Function to fill Rlc Lc Cfg for SRB1
1485  *
1486  * @details
1487  *
1488  *    Function : fillRlcSrb1LcCfg
1489  *
1490  *    Functionality: 
1491  *     Function to fill Rlc Lc Cfg for SRB1
1492  * 
1493  *  @params[in]     Pointer to RlcBearerCfg
1494  *  @return ROK/RFAILED
1495  * 
1496  *****************************************************************/
1497
1498 uint8_t fillRlcSrb1LcCfg(RlcBearerCfg *rlcLcCfg)
1499 {
1500    uint8_t ret = ROK;
1501
1502    rlcLcCfg->rbId   = SRB1_LCID;
1503    rlcLcCfg->rbType = RB_TYPE_SRB;
1504    rlcLcCfg->lcId   = SRB1_LCID;
1505    rlcLcCfg->lcType = LCH_DCCH;
1506    rlcLcCfg->rlcMode = RLC_AM;
1507    rlcLcCfg->configType = CONFIG_ADD;
1508    ret = fillDefaultRlcModeCfg(rlcLcCfg->rlcMode, rlcLcCfg);
1509    rlcLcCfg->isLcAddModRspSent = true;
1510    return ret;
1511 }
1512
1513 /*******************************************************************
1514  *
1515  * @brief Processes UE ReConfig Req to RLC UL
1516  *
1517  * @details
1518  *
1519  *    Function : sendUeReCfgReqToRlc
1520  *
1521  *    Functionality: 
1522  *     Processes UE Reconfig Req to RLC UL
1523  * 
1524  *  @params[in]     Pointer to RlcUeCfg
1525  *  @return ROK     - success
1526  *          RFAILED - failure
1527  * 
1528  *****************************************************************/
1529
1530 uint8_t sendUeReCfgReqToRlc(RlcUeCfg *rlcUeCfg)
1531 {
1532    uint8_t ret;
1533    Pst pst;
1534    
1535    FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_RECONFIG_REQ);
1536    if(rlcUeCfg)
1537    {
1538       /* Processing one Ue at a time to RLC */
1539       DU_LOG("\nDEBUG   -->  DU_APP: Sending Ue Reconfig Request to RLC UL");
1540       ret = (*packRlcUeReconfigReqOpts[pst.selector])(&pst, rlcUeCfg);
1541       if(ret == RFAILED)
1542       {
1543          DU_LOG("\nERROR  -->  DU_APP : Failed to send Ue Reconfig Req to RLC at sendUeReCfgReqToRlc()");
1544          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rlcUeCfg, sizeof(RlcUeCfg));
1545       }
1546    }
1547    else
1548    {
1549       DU_LOG("\nERROR  -->   DU_APP: Received RlcUeCfg is NULL at sendUeReCfgReqToRlc()");
1550       ret = RFAILED;
1551    }
1552    return ret;
1553 }
1554
1555 /******************************************************************
1556  *
1557  * @brief Fills Snssai information
1558  *
1559  * @details
1560  *
1561  *    Function : fillSnssaiInfo
1562  *
1563  *    Functionality: Fills Snssai information
1564  *
1565  *  @params[in]    LcCfg *snssaiTobeSend, LcCfg *snssaiDb, LcCfg *oldSnssai,
1566  *  Bool toUpdateg
1567  *  @return ROK     - success
1568  *          RFAILED - failure
1569  * 
1570  *****************************************************************/
1571 uint8_t fillSnssaiInfo(Snssai *snssaiTobeSend, Snssai *snssaiDb, Snssai **oldSnssai, Bool toUpdate)
1572 {
1573    if(!toUpdate)
1574    {
1575       if(snssaiDb)
1576          snssaiTobeSend = snssaiDb;
1577       else if(oldSnssai)
1578          snssaiTobeSend = *oldSnssai;
1579       else
1580          snssaiTobeSend = NULL;
1581    }
1582    else
1583    {
1584       if(snssaiDb)
1585       {
1586          if(*oldSnssai)
1587             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, *oldSnssai, sizeof(Snssai));
1588
1589          DU_ALLOC_SHRABL_BUF(*oldSnssai, sizeof(Snssai));
1590          if(*oldSnssai == NULL)
1591          {
1592             DU_LOG("\nERROR  -->  DU APP : Memory Alloc Failed at fillSnssaiInfo()");
1593             return RFAILED;
1594          }
1595          memcpy(*oldSnssai, snssaiDb, sizeof(Snssai));
1596       }
1597    }
1598    return ROK;
1599 }
1600 /******************************************************************
1601  *
1602  * @brief Fills RlcBearerCfg structure
1603  *
1604  * @details
1605  *
1606  *    Function : fillRlcUeCfg
1607  *
1608  *    Functionality: Fills Rlc Bearer Cfg
1609  *
1610  *
1611  *****************************************************************/
1612 uint8_t fillRlcUeCfg(uint16_t cellId, uint8_t duUeF1apId, DuUeCfg *ueCfgDb, RlcUeCfg *rlcUeCfg)
1613 {
1614    uint8_t ret, dbIdx, lcIdx, cellIdx;
1615    bool lcIdFound = false;
1616    RlcUeCfg *duRlcDb = NULLP;
1617
1618    ret = ROK;
1619    rlcUeCfg->cellId       = cellId;
1620    rlcUeCfg->ueId         = duUeF1apId;
1621
1622    if(!ueCfgDb)
1623    {
1624       /* Initial RB being Added */ 
1625       ret = fillRlcSrb1LcCfg(&rlcUeCfg->rlcLcCfg[0]);
1626       if(ret == ROK)
1627          rlcUeCfg->numLcs++;
1628       else
1629          memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
1630    }
1631    else
1632    {
1633       /* Fetch RlcDb from DuUeCb */ 
1634       GET_CELL_IDX(cellId, cellIdx);
1635       duRlcDb = &duCb.actvCellLst[cellIdx]->ueCb[rlcUeCfg->ueId-1].rlcUeCfg;
1636       duRlcDb->rlcUeCfgState = UE_CFG_INPROGRESS;
1637
1638       for(dbIdx = 0; (dbIdx < ueCfgDb->numRlcLcs && ret == ROK); dbIdx++)
1639       {
1640          ret = fillDefaultRlcModeCfg(ueCfgDb->rlcLcCfg[dbIdx].rlcMode, &ueCfgDb->rlcLcCfg[dbIdx]);
1641          if(ret == RFAILED)
1642          {
1643             DU_LOG("\n ERROR  -->  DU APP : Failed to fill Rlc Mode at fillRlcUeCfg()");
1644             memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
1645             return ret;
1646          }
1647
1648          if(duRlcDb)
1649          {
1650             /* Fill Rlc Ue Cfg List for ADD/MOD/DEL */
1651             for(lcIdx = 0; lcIdx < duRlcDb->numLcs; lcIdx++)
1652             { 
1653                if(ueCfgDb->rlcLcCfg[dbIdx].lcId == duRlcDb->rlcLcCfg[lcIdx].lcId)
1654                {
1655                   lcIdFound = true;
1656                   if((ueCfgDb->rlcLcCfg[dbIdx].configType == CONFIG_UNKNOWN)||
1657                         (ueCfgDb->rlcLcCfg[dbIdx].configType == CONFIG_MOD))
1658                   {
1659                      /* MOD */ 
1660                      ueCfgDb->rlcLcCfg[dbIdx].configType = CONFIG_MOD; /* update Db for MOD type */
1661                      memcpy(&rlcUeCfg->rlcLcCfg[dbIdx], &ueCfgDb->rlcLcCfg[dbIdx], sizeof(RlcBearerCfg));
1662                      fillSnssaiInfo(rlcUeCfg->rlcLcCfg[dbIdx].snssai, ueCfgDb->rlcLcCfg[dbIdx].snssai,\
1663                            &duRlcDb->rlcLcCfg[lcIdx].snssai,false);
1664                   }
1665                }
1666                else
1667                   lcIdFound = false;
1668             }
1669          }
1670
1671          if(!lcIdFound)
1672          {
1673             /* ADD/ DEL Config Type */
1674             memcpy(&rlcUeCfg->rlcLcCfg[dbIdx], &ueCfgDb->rlcLcCfg[dbIdx], sizeof(RlcBearerCfg));
1675             fillSnssaiInfo(rlcUeCfg->rlcLcCfg[dbIdx].snssai, ueCfgDb->rlcLcCfg[dbIdx].snssai, NULL, false);
1676          }
1677          rlcUeCfg->numLcs++;
1678       }
1679    }
1680    return ret;
1681 }
1682
1683 /******************************************************************
1684  *
1685  * @brief creates UE context
1686  *
1687  * @details
1688  *
1689  *    Function : duCreateUeCb
1690  *
1691  *    Functionality: Creates UE Conetxt
1692  *
1693  * @params[in] UeCcchCtxt Pointer
1694  *             UeIdx Pointer
1695  *
1696  * @return ROK     - success
1697  *         RFAILED - failure
1698  * ****************************************************************/
1699 uint8_t duCreateUeCb(UeCcchCtxt *ueCcchCtxt, uint32_t gnbCuUeF1apId)
1700 {
1701    uint8_t cellIdx = 0;
1702    uint8_t ret     = ROK;
1703    uint8_t ueId = 0, ueIdx = 0;
1704
1705    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
1706    {
1707       if(duCb.actvCellLst[cellIdx] && (ueCcchCtxt->cellId == duCb.actvCellLst[cellIdx]->cellId))
1708       {
1709          GET_UE_ID(ueCcchCtxt->crnti, ueId);
1710          DU_LOG("\nDEBUG   -->  DU_APP: Filling UeCb for ueId [%d]", ueId);
1711
1712          ueIdx = ueId-1;
1713          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].f1UeDb        = NULLP;
1714          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti         = ueCcchCtxt->crnti;
1715          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId = ueCcchCtxt->gnbDuUeF1apId;
1716          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId = gnbCuUeF1apId;
1717          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].drbBitMap     = NULLP;
1718          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState       = UE_ACTIVE;
1719
1720          /* Filling Mac Ue Config */ 
1721          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg, 0, sizeof(MacUeCfg));
1722          ret = duBuildAndSendUeCreateReqToMac(ueCcchCtxt->cellId, ueCcchCtxt->gnbDuUeF1apId, NULL, 
1723                &duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg);
1724          if(ret == RFAILED)
1725             DU_LOG("\nERROR  -->  DU APP : Failed to send UE create request to MAC");
1726
1727          /* Filling Rlc Ue Config */
1728          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg, 0, sizeof(RlcUeCfg));
1729          ret = duBuildAndSendUeCreateReqToRlc(ueCcchCtxt->cellId, ueCcchCtxt->gnbDuUeF1apId, NULL,
1730                &duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg);
1731          if(ret == RFAILED)
1732             DU_LOG("\nERROR  -->  DU APP : Failed to send UE create request to RLC");
1733
1734          duCb.actvCellLst[cellIdx]->numActvUes++;
1735          memset(ueCcchCtxt, 0, sizeof(UeCcchCtxt));
1736          duCb.numUe--;
1737       }
1738    }
1739    return ret;
1740 }
1741
1742 /******************************************************************
1743  *
1744  * @brief Builds and Send UE Create Request to MAC
1745  *
1746  * @details
1747  *
1748  *    Function : duBuildAndSendUeCreateReqToMac
1749  *
1750  *    Functionality: Builds and Send UE Create Request to MAC
1751  *
1752  * @Params[in]  cellId,
1753  *              ueId,
1754  *              crnti,
1755  *              UE config extracted from F1AP msg
1756  *              MAC UE config struct to be filled
1757  * @return ROK     - success
1758  *         RFAILED - failure
1759  *
1760  * ****************************************************************/
1761
1762 uint8_t duBuildAndSendUeCreateReqToMac(uint16_t cellId, uint8_t gnbDuUeF1apId, DuUeCfg *ueCfgDb, MacUeCfg *duMacUeCfg)
1763 {
1764    uint8_t  ret = ROK;
1765    MacUeCfg *macUeCfg = NULLP;
1766    Pst       pst;
1767    memset(&pst, 0, sizeof(Pst));
1768
1769
1770    ret = fillMacUeCfg(cellId, gnbDuUeF1apId, ueCfgDb, duMacUeCfg);
1771    if(ret == RFAILED)
1772    {
1773       DU_LOG("\nERROR  -->  DU APP : Failed to fill MacUeCfg at duBuildAndSendUeCreateReqToMac()");
1774       return RFAILED;
1775    }
1776
1777    /* Fill Pst */
1778    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_CREATE_REQ);
1779
1780    /* Copying ueCb to a sharable buffer */
1781    DU_ALLOC_SHRABL_BUF(macUeCfg, sizeof(MacUeCfg));
1782    if(macUeCfg)
1783    {
1784       memset(macUeCfg, 0, sizeof(MacUeCfg));
1785       memcpy(macUeCfg, duMacUeCfg, sizeof(MacUeCfg));
1786       DU_LOG("\nDEBUG   -->  DU_APP: Sending UE create request to MAC");
1787
1788       /* Processing one Ue at a time to MAC */
1789       ret = (*packMacUeCreateReqOpts[pst.selector])(&pst, macUeCfg);
1790       if(ret == RFAILED)
1791       {
1792          DU_LOG("\nERROR  -->  DU_APP : Failure in sending Ue Create Req to MAC at duBuildAndSendUeCreateReqToMac()");
1793          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macUeCfg, sizeof(MacUeCfg));
1794       }
1795    }
1796    else
1797    {
1798       DU_LOG("\n ERROR  -->  DU APP : Memory alloc failed at duBuildAndSendUeCreateReqToMac()");
1799       ret = RFAILED;
1800    }
1801    return ret;
1802 }
1803
1804 /*******************************************************************
1805  *
1806  * @brief To update DuUeCb Mac Cfg
1807  *
1808  * @details
1809  *
1810  *    Function : duUpdateMacCfg
1811  *    Functionality:  update DuUeCb MAC Cfg
1812  *
1813  * @params[in] DuUeCb Pointer
1814  *             F1UeContextSetupDb pointer 
1815  * @return ROK     - success
1816  *         RFAILED - failure
1817  *
1818  * ****************************************************************/
1819 uint8_t duUpdateMacCfg(MacUeCfg *macUeCfg, F1UeContextSetupDb *f1UeDb) 
1820 {
1821    uint8_t ret, lcIdx, dbIdx, numLcs, lcDelIdx, cellIdx;
1822    MacUeCfg *oldMacUeCfg;
1823    ret = ROK;
1824    
1825    GET_CELL_IDX(macUeCfg->cellId, cellIdx);
1826    if(duCb.actvCellLst[cellIdx] == NULLP)
1827    {
1828       DU_LOG("\nERROR  --> DU APP: CellId[%d] not found", macUeCfg->cellId);
1829       return RFAILED;
1830    }
1831    oldMacUeCfg = &duCb.actvCellLst[cellIdx]->ueCb[macUeCfg->ueId-1].macUeCfg;
1832
1833    /*Filling Cell Group Cfg*/
1834    ret =  procUeReCfgCellInfo(macUeCfg, &f1UeDb->duUeCfg.copyOfmacUeCfg, f1UeDb->duUeCfg.cellGrpCfg);
1835    if(ret == ROK)
1836    {
1837       if(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschPresent)
1838       {
1839          fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc,\
1840                &macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, NULL);
1841       }
1842       if(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschPresent)
1843       {
1844          fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
1845                NULL, &macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg);
1846       }
1847       ret = fillAmbr(NULL, f1UeDb->duUeCfg.ambrCfg, &oldMacUeCfg->ambrCfg, true);
1848       duFillModulationDetails(macUeCfg, oldMacUeCfg, f1UeDb->duUeCfg.ueNrCapability);
1849    }
1850
1851    /* Filling LC Context */
1852    for(dbIdx = 0; (dbIdx < f1UeDb->duUeCfg.numMacLcs && ret == ROK); dbIdx++)
1853    {
1854       numLcs = macUeCfg->numLcs;
1855       for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
1856       {
1857          if(f1UeDb->duUeCfg.macLcCfg[dbIdx].lcId ==  macUeCfg->lcCfgList[lcIdx].lcId)
1858          {
1859             if(f1UeDb->duUeCfg.macLcCfg[dbIdx].configType == CONFIG_MOD)
1860             {
1861                ret = fillMacLcCfgToAddMod(NULL, &f1UeDb->duUeCfg.macLcCfg[dbIdx], &macUeCfg->lcCfgList[lcIdx], true);
1862             }
1863             else if(f1UeDb->duUeCfg.macLcCfg[dbIdx].configType == CONFIG_DEL)
1864             {
1865                /* Free memory at matched  lcIdx index */
1866                freeMacLcCfg(&macUeCfg->lcCfgList[lcIdx]);
1867                macUeCfg->numLcs--;
1868                for(lcDelIdx = lcIdx; lcDelIdx < macUeCfg->numLcs; lcDelIdx++)
1869                {
1870                   /* moving all elements one index ahead */
1871                   ret = fillMacLcCfgToAddMod(NULL,  &macUeCfg->lcCfgList[lcDelIdx+1], &macUeCfg->lcCfgList[lcDelIdx], true);
1872                   freeMacLcCfg(&macUeCfg->lcCfgList[lcDelIdx+1]);
1873                   if(ret == RFAILED)
1874                   {
1875                      DU_LOG("\nERROR  -->  DU APP : Failed to delete LC at Idx %d in duUpdateMacCfg()", lcDelIdx);
1876                      break;
1877                   }
1878                }
1879             }
1880          }
1881       } 
1882       if(f1UeDb->duUeCfg.macLcCfg[dbIdx].configType == CONFIG_ADD)
1883       {
1884          ret = fillMacLcCfgToAddMod(NULL, &f1UeDb->duUeCfg.macLcCfg[dbIdx], &macUeCfg->lcCfgList[numLcs], true);
1885          if(ret == RFAILED)
1886          {
1887             DU_LOG("\nERROR  -->  DU APP : Failed to add LC at Idx %d in duUpdateMacCfg()", numLcs);
1888             break;
1889          }
1890          macUeCfg->numLcs++;
1891       }
1892                 
1893    }
1894    return ret;
1895 }
1896
1897 /******************************************************************
1898  *
1899  * @brief Function to fill the RLC Lc cfg from ueSetupReqDb
1900  *
1901  * @details
1902  *
1903  *    Function : fillRlcCfgToAddMod
1904  *
1905  *    Functionality: Function to fill the RLC Lc cfg from ueSetupReqDb
1906  *
1907  *
1908  *****************************************************************/
1909
1910 uint8_t fillRlcCfgToAddMod(RlcBearerCfg *lcCfg, RlcBearerCfg *f1UeDbLcCfg)
1911 {
1912    lcCfg->configType = f1UeDbLcCfg->configType;
1913    lcCfg->rbId       = f1UeDbLcCfg->rbId;
1914    lcCfg->rbType     = f1UeDbLcCfg->rbType;
1915    lcCfg->lcId       = f1UeDbLcCfg->lcId;
1916    lcCfg->lcType     = f1UeDbLcCfg->lcType;
1917    lcCfg->rlcMode    = f1UeDbLcCfg->rlcMode;
1918    
1919    switch(lcCfg->rlcMode)
1920    {
1921       case RLC_AM :
1922          {
1923             if(!lcCfg->u.amCfg)
1924             {
1925                DU_ALLOC_SHRABL_BUF(lcCfg->u.amCfg, sizeof(AmBearerCfg));
1926                if(!lcCfg->u.amCfg)
1927                   return RFAILED;
1928             }
1929             /* DL AM */
1930             lcCfg->u.amCfg->dlAmCfg.snLenDl     = f1UeDbLcCfg->u.amCfg->dlAmCfg.snLenDl;    
1931             lcCfg->u.amCfg->dlAmCfg.pollRetxTmr = f1UeDbLcCfg->u.amCfg->dlAmCfg.pollRetxTmr;
1932             lcCfg->u.amCfg->dlAmCfg.pollPdu     = f1UeDbLcCfg->u.amCfg->dlAmCfg.pollPdu;
1933             lcCfg->u.amCfg->dlAmCfg.pollByte    = f1UeDbLcCfg->u.amCfg->dlAmCfg.pollByte;   
1934             lcCfg->u.amCfg->dlAmCfg.maxRetxTh   = f1UeDbLcCfg->u.amCfg->dlAmCfg.maxRetxTh;   
1935
1936             /* UL AM */
1937             lcCfg->u.amCfg->ulAmCfg.snLenUl     = f1UeDbLcCfg->u.amCfg->ulAmCfg.snLenUl;
1938             lcCfg->u.amCfg->ulAmCfg.reAssemTmr  = f1UeDbLcCfg->u.amCfg->ulAmCfg.reAssemTmr; 
1939             lcCfg->u.amCfg->ulAmCfg.statProhTmr = f1UeDbLcCfg->u.amCfg->ulAmCfg.statProhTmr;
1940             break;
1941          }
1942       case RLC_UM_BI_DIRECTIONAL :
1943          {
1944             if(!lcCfg->u.umBiDirCfg)
1945             {
1946                DU_ALLOC_SHRABL_BUF(lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
1947                if(!lcCfg->u.umBiDirCfg)
1948                   return RFAILED;
1949             }
1950             /* UL UM BI DIR INFO */
1951             lcCfg->u.umBiDirCfg->ulUmCfg.snLenUlUm  = f1UeDbLcCfg->u.umBiDirCfg->ulUmCfg.snLenUlUm;  
1952             lcCfg->u.umBiDirCfg->ulUmCfg.reAssemTmr = f1UeDbLcCfg->u.umBiDirCfg->ulUmCfg.reAssemTmr;
1953             /* DL UM BI DIR INFO */
1954             lcCfg->u.umBiDirCfg->dlUmCfg.snLenDlUm  = f1UeDbLcCfg->u.umBiDirCfg->dlUmCfg.snLenDlUm;
1955             break;
1956          }
1957       case RLC_UM_UNI_DIRECTIONAL_UL :
1958          {
1959             if(!lcCfg->u.umUniDirUlCfg)
1960             {
1961                DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
1962                if(!lcCfg->u.umUniDirUlCfg)
1963                   return RFAILED;
1964             }
1965             lcCfg->u.umUniDirUlCfg->ulUmCfg.snLenUlUm  = f1UeDbLcCfg->u.umUniDirUlCfg->ulUmCfg.snLenUlUm;  
1966             lcCfg->u.umUniDirUlCfg->ulUmCfg.reAssemTmr = f1UeDbLcCfg->u.umUniDirUlCfg->ulUmCfg.reAssemTmr;
1967             break;
1968
1969          }
1970       case RLC_UM_UNI_DIRECTIONAL_DL :
1971          {
1972             if(!lcCfg->u.umUniDirDlCfg)
1973             {
1974                DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
1975                if(!lcCfg->u.umUniDirDlCfg)
1976                   return RFAILED;
1977             }
1978             lcCfg->u.umUniDirDlCfg->dlUmCfg.snLenDlUm  = f1UeDbLcCfg->u.umUniDirDlCfg->dlUmCfg.snLenDlUm;
1979             break;
1980          }
1981       default:
1982          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at fillRlcCfgToAddMod()", lcCfg->rlcMode);
1983          return RFAILED;
1984    }
1985    return ROK;
1986 }
1987
1988 /*******************************************************************
1989  *
1990  * @brief To update DuUeCb Rlc Lc Cfg
1991  *
1992  * @details
1993  *
1994  *    Function : duUpdateRlcLcCfg
1995  *    Functionality:  update DuUeCb Rlc Lc Cfg
1996  *
1997  * @params[in] DuUeCb Pointer
1998  *             F1UeContextSetupDb pointer 
1999  * @return ROK     - success
2000  *         RFAILED - failure
2001  *
2002  * ****************************************************************/
2003
2004 uint8_t duUpdateRlcLcCfg(RlcUeCfg *rlcUeCfg, F1UeContextSetupDb *f1UeDb)
2005 {
2006    uint8_t ret, lcIdx, dbIdx, numLcs, lcDelIdx;
2007
2008    ret = ROK;
2009    for(dbIdx = 0; (dbIdx < f1UeDb->duUeCfg.numRlcLcs && ret ==ROK); dbIdx++)
2010    {
2011       numLcs = rlcUeCfg->numLcs;
2012       for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
2013       {
2014          if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].lcId == rlcUeCfg->rlcLcCfg[lcIdx].lcId)
2015          {
2016             if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].configType == CONFIG_MOD)
2017             {
2018                ret = fillRlcCfgToAddMod(&rlcUeCfg->rlcLcCfg[lcIdx], &f1UeDb->duUeCfg.rlcLcCfg[dbIdx]);
2019                if(ret == RFAILED)
2020                {
2021                   DU_LOG("\nERROR  -->  DU APP : Failed to modify LC at Idx %d in duUpdateRlcCfg()", lcDelIdx);
2022                   break;
2023                }
2024                fillSnssaiInfo(NULL, f1UeDb->duUeCfg.rlcLcCfg[dbIdx].snssai, &rlcUeCfg->rlcLcCfg[lcIdx].snssai, true);
2025             }
2026             else if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].configType == CONFIG_DEL)
2027             {
2028                /* Free memory at matched lcIdx index */
2029                freeRlcLcCfg(&rlcUeCfg->rlcLcCfg[lcIdx]);
2030                rlcUeCfg->numLcs--;
2031                for(lcDelIdx = lcIdx; lcDelIdx < rlcUeCfg->numLcs; lcDelIdx++)
2032                {
2033                   ret = fillRlcCfgToAddMod(&rlcUeCfg->rlcLcCfg[lcDelIdx], &rlcUeCfg->rlcLcCfg[lcDelIdx+1]);
2034                   fillSnssaiInfo(NULL, rlcUeCfg->rlcLcCfg[lcDelIdx+1].snssai, &rlcUeCfg->rlcLcCfg[lcDelIdx].snssai,\
2035                   true);
2036                   freeRlcLcCfg(&rlcUeCfg->rlcLcCfg[lcDelIdx+1]);
2037                   if(ret == RFAILED)
2038                   {
2039                      DU_LOG("\nERROR  -->  DU APP : Failed to delete LC at Idx %d in duUpdateRlcCfg()", lcDelIdx);
2040                      break;
2041                   }
2042                }
2043             }
2044          }
2045       }
2046       if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].configType == CONFIG_ADD)
2047       {
2048          ret = fillRlcCfgToAddMod(&rlcUeCfg->rlcLcCfg[lcIdx], &f1UeDb->duUeCfg.rlcLcCfg[dbIdx]);
2049          if(ret == ROK)
2050          {    
2051             fillSnssaiInfo(NULL, f1UeDb->duUeCfg.rlcLcCfg[dbIdx].snssai, &rlcUeCfg->rlcLcCfg[ rlcUeCfg->numLcs].snssai,\
2052                   true);
2053             rlcUeCfg->numLcs++;
2054          }
2055       }
2056    }
2057    return ret;
2058 }
2059
2060 /*******************************************************************
2061  *
2062  * @brief Function to fill Tunnel Config to Add/Mod
2063  * 
2064  *
2065  * @details
2066  *
2067  *    Function : fillTnlCfgToAddMod
2068  *
2069  *    Functionality: Function to fill tunnel Config to Add/Mod
2070  *
2071  * @params[in] Pointer to tnlCfgDb,
2072  *             pointer to f1TnlCfg
2073  * @return ROK     - success
2074  *         RFAILED - failure
2075  *
2076  * ****************************************************************/
2077 uint8_t fillTnlCfgToAddMod(UpTnlCfg **ueCbTnlCfg, UpTnlCfg *f1TnlCfg)
2078 {
2079    if(*ueCbTnlCfg)
2080    {
2081       DU_FREE((*ueCbTnlCfg)->tnlCfg1, sizeof(GtpTnlCfg));
2082       DU_FREE(*ueCbTnlCfg, sizeof(UpTnlCfg));
2083    }
2084
2085    if(*ueCbTnlCfg == NULLP)
2086    {
2087       /* copying to DuCb Tnl Cfg */
2088       DU_ALLOC(*ueCbTnlCfg, sizeof(UpTnlCfg));
2089       if(*ueCbTnlCfg == NULLP)
2090       {
2091          DU_LOG("\nERROR  -->  DU_APP : fillTnlCfgToAddMod: Memory Alloc failed for drbId[%d]", f1TnlCfg->drbId);
2092          return RFAILED;
2093       }
2094    }
2095    memset(*ueCbTnlCfg, 0, sizeof(UpTnlCfg));
2096    (*ueCbTnlCfg)->configType = f1TnlCfg->configType;
2097    (*ueCbTnlCfg)->cellId    = f1TnlCfg->cellId;
2098    (*ueCbTnlCfg)->ueId      = f1TnlCfg->ueId;
2099    (*ueCbTnlCfg)->drbId     = f1TnlCfg->drbId;
2100    if(f1TnlCfg->tnlCfg1)
2101    {
2102       if((*ueCbTnlCfg)->tnlCfg1 == NULLP)
2103       {
2104          DU_ALLOC((*ueCbTnlCfg)->tnlCfg1, sizeof(GtpTnlCfg));
2105          if((*ueCbTnlCfg)->tnlCfg1 == NULLP)
2106          {
2107             DU_LOG("\nERROR  -->  DU_APP : fillTnlCfgToAddMod: Memory Alloc failed for tnlCfg1 for drbId[%d]", f1TnlCfg->drbId);
2108             return RFAILED;
2109          }
2110       }
2111       memset((*ueCbTnlCfg)->tnlCfg1, 0, sizeof(GtpTnlCfg));
2112       (*ueCbTnlCfg)->tnlCfg1->teId = f1TnlCfg->tnlCfg1->teId;
2113       (*ueCbTnlCfg)->tnlCfg1->ulTnlAddress = f1TnlCfg->tnlCfg1->ulTnlAddress;
2114       (*ueCbTnlCfg)->tnlCfg1->dlTnlAddress = f1TnlCfg->tnlCfg1->dlTnlAddress;
2115    }
2116    return ROK;
2117 }
2118
2119 /*******************************************************************
2120  *
2121  * @brief Processing the tunnel Request to EGTP
2122  *        
2123  * @details
2124  *
2125  *    Function : duProcEgtpTunnelCfg
2126  *
2127  *    Functionality: Processing the tunnel Request to EGTP
2128  *
2129  * @params[in] UptnlCfg *duTnlCfg, UpTnlCfg *f1TnlCfg 
2130  * @return ROK     - success
2131  *         RFAILED - failure
2132  *
2133  * ****************************************************************/
2134
2135 uint8_t duProcEgtpTunnelCfg(uint8_t ueCbIdx, UpTnlCfg *duTnlCfg, UpTnlCfg *f1TnlCfg)
2136 {
2137    uint8_t ret = RFAILED, delIdx;
2138
2139    if(f1TnlCfg->tnlCfg1 == NULLP)
2140    {
2141       DU_LOG("\nERROR  -->  DU_APP : Tunnel config not found");
2142       return ret;
2143    }
2144
2145    if(f1TnlCfg->configType == CONFIG_ADD)
2146    {
2147       if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_ADD, NULLP, f1TnlCfg->tnlCfg1) == ROK)
2148       {
2149          if(fillTnlCfgToAddMod(&duCb.upTnlCfg[duCb.numTeId], f1TnlCfg) == ROK)
2150          {
2151             duCb.numTeId++;
2152             ret = ROK;
2153          }
2154       }      
2155    }
2156    else if(f1TnlCfg->configType == CONFIG_MOD)
2157    {
2158       if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_MOD, duTnlCfg->tnlCfg1->teId, f1TnlCfg->tnlCfg1) == ROK)
2159       {
2160          if(fillTnlCfgToAddMod(&duTnlCfg, f1TnlCfg) == ROK)
2161          {
2162             ret = ROK;
2163          }
2164       }   
2165    }
2166    else if(f1TnlCfg->configType == CONFIG_DEL)
2167    {
2168       if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_DEL, duTnlCfg->tnlCfg1->teId, f1TnlCfg->tnlCfg1) == ROK)
2169       {    
2170          /* Free memory at drbIdx */
2171          duCb.numTeId--;
2172          for(delIdx = ueCbIdx; delIdx < duCb.numTeId; delIdx++)
2173          {
2174             /* moving all elements one index ahead */
2175             ret = fillTnlCfgToAddMod(&duCb.upTnlCfg[delIdx], duCb.upTnlCfg[delIdx+1]);
2176             if(ret != ROK)
2177             {
2178                return ret;
2179             }
2180          }
2181          if(duCb.upTnlCfg[delIdx])
2182          {
2183             DU_FREE(duCb.upTnlCfg[delIdx]->tnlCfg1, sizeof(GtpTnlCfg));
2184             DU_FREE(duCb.upTnlCfg[delIdx], sizeof(UpTnlCfg));
2185          }
2186       }   
2187    }
2188    return ret;
2189 }
2190
2191 /***********************************************************************
2192  *
2193  * @brief Function to fill Tunnel Config
2194  *        and sends tunnel Req to EGTP
2195  * 
2196  *
2197  * @details
2198  *
2199  *    Function : duUpdateTunnelCfgDb
2200  *
2201  *    Functionality: Function to fill tunnel Config
2202  *                   and sends tunnel Cfg Req to EGTP
2203  *
2204  * @params[in] ueId, cellId, DuUeCfg 
2205  * @return ROK     - success
2206  *         RFAILED - failure
2207  *
2208  * ****************************************************************/
2209
2210 uint8_t duUpdateTunnelCfgDb(uint8_t ueId, uint8_t cellId, DuUeCfg *duUeCfg)
2211 {
2212    uint8_t ret = ROK, drbIdx, teIdx;
2213    bool drbFound = false;
2214
2215    /*If Add/Mod tunnels request for that DRB is successful in EGTP */
2216    /*then update drbId and tunnel Info in duCb */
2217    for(drbIdx=0; drbIdx < duUeCfg->numDrb; drbIdx++)
2218    {
2219       duUeCfg->upTnlInfo[drbIdx].cellId = cellId;
2220       duUeCfg->upTnlInfo[drbIdx].ueId = ueId;
2221       for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
2222       {
2223          if((duCb.upTnlCfg[teIdx]->ueId == duUeCfg->upTnlInfo[drbIdx].ueId) && \
2224             (duCb.upTnlCfg[teIdx]->drbId == duUeCfg->upTnlInfo[drbIdx].drbId))
2225          {
2226             drbFound = true; /* existing DRB */
2227             if(duProcEgtpTunnelCfg(teIdx, duCb.upTnlCfg[teIdx], &duUeCfg->upTnlInfo[drbIdx]) != ROK)
2228             {
2229                DU_LOG("\nERROR  -> DU_APP : duUpdateTunnelCfgDb: Failed to modify tunnel req for Drb id[%d]",
2230                      duUeCfg->upTnlInfo[drbIdx].drbId);
2231                ret = RFAILED;
2232             }
2233             break;
2234          }
2235          else
2236             drbFound = false;
2237       }
2238
2239       if(!drbFound && ret == ROK)/* new DRB to Add */
2240       {
2241          if(duProcEgtpTunnelCfg(NULLP, NULLP, &duUeCfg->upTnlInfo[drbIdx]) != ROK)
2242          {
2243             DU_LOG("\nERROR  -> DU_APP : duUpdateTunnelCfgDb: Failed to add tunnel req for Drb id[%d]",
2244                   duUeCfg->upTnlInfo[drbIdx].drbId);
2245             ret = RFAILED;
2246             break;
2247          }
2248       }
2249       else
2250          break;
2251    }
2252    return ret;
2253 }
2254
2255 /*******************************************************************
2256  *
2257  * @brief @brief To update DuUeCb Mac and Rlc Ue Cfg
2258  * 
2259  *
2260  * @details
2261  *
2262  *    Function : duUpdateDuUeCbCfg
2263  *
2264  *    Functionality: update DuUeCb Mac and Rlc Ue Cfg
2265  *
2266  * @params[in] ueId, cellIdx 
2267  * @return ROK     - success
2268  *         RFAILED - failure
2269  *
2270  * ****************************************************************/
2271
2272 uint8_t duUpdateDuUeCbCfg(uint8_t ueId, uint8_t cellId)
2273 {
2274    uint8_t ret = ROK, cellIdx = 0, crnti=0;
2275    DuUeCb *ueCb = NULLP;
2276
2277    GET_CELL_IDX(cellId, cellIdx);
2278    ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
2279
2280    /*Filling RLC Ue Cfg */
2281    ueCb->rlcUeCfg.cellId = cellId;
2282    ueCb->rlcUeCfg.ueId   = ueId;
2283    ret = duUpdateRlcLcCfg(&ueCb->rlcUeCfg, ueCb->f1UeDb);
2284    if(ret == ROK)
2285    {
2286       /*Filling MAC Ue Cfg */
2287       GET_CRNTI(crnti, ueId);
2288       ueCb->macUeCfg.cellId = cellId;
2289       ueCb->macUeCfg.ueId  = ueId;
2290       ueCb->macUeCfg.crnti  = crnti;
2291       ret = duUpdateMacCfg(&ueCb->macUeCfg, ueCb->f1UeDb);
2292       if(ret == RFAILED)
2293          DU_LOG("\nERROR  -->  DU APP : Failed while updating MAC LC Config at duUpdateDuUeCbCfg()");
2294       else
2295       {
2296          if(duUpdateTunnelCfgDb(ueId, cellId, &ueCb->f1UeDb->duUeCfg) != ROK)
2297          {
2298             DU_LOG("\nERROR  -->  DU_APP : Failed to establish tunnel in duUpdateDuUeCbCfg()");
2299             return RFAILED;
2300          }
2301       }
2302    }
2303    else
2304       DU_LOG("\nERROR  -->  DU APP : Failed while updating RLC LC Config at duUpdateDuUeCbCfg()");
2305    return ret;
2306 }
2307
2308 /*******************************************************************
2309  *
2310  * @brief Handle UE config response from MAC
2311  *
2312  * @details
2313  *
2314  *    Function : DuProcMacUeCfgRsp
2315  *
2316  *    Functionality: Handle UE Config response from MAC
2317  *
2318  * @params[in] Pointer to MacUeCfgRsp and Pst 
2319  * @return ROK     - success
2320  *         RFAILED - failure
2321  *
2322  * ****************************************************************/
2323 uint8_t DuProcMacUeCfgRsp(Pst *pst, MacUeCfgRsp *cfgRsp)
2324 {
2325    uint8_t ret = ROK;
2326    uint16_t cellIdx;
2327
2328    if(cfgRsp)
2329    {
2330       GET_CELL_IDX(cfgRsp->cellId, cellIdx);
2331       if(cfgRsp->result == MAC_DU_APP_RSP_OK)
2332       {
2333          if(pst->event == EVENT_MAC_UE_CREATE_RSP)
2334          {
2335             DU_LOG("\nINFO   -->  DU APP : MAC UE Create Response : SUCCESS [DU UE F1AP ID : %d]", cfgRsp->ueId);
2336
2337             if(duCb.actvCellLst[cellIdx] && 
2338                   (duCb.actvCellLst[cellIdx]->ueCb[cfgRsp->ueId -1].gnbDuUeF1apId == cfgRsp->ueId))
2339             {
2340                duCb.actvCellLst[cellIdx]->ueCb[cfgRsp->ueId -1].macUeCfg.macUeCfgState = UE_CREATE_COMPLETE;
2341
2342               if((duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].ueState == UE_HANDIN_IN_PROGRESS) && 
2343               (duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].macUeCfg.macUeCfgState == UE_CREATE_COMPLETE) &&
2344               (duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].rlcUeCfg.rlcUeCfgState == UE_CREATE_COMPLETE))
2345               {
2346                  if((ret = duUpdateDuUeCbCfg(cfgRsp->ueId, cfgRsp->cellId)) == ROK)
2347                  {
2348                     if((BuildAndSendUeCtxtRsp(cfgRsp->cellId, cfgRsp->ueId)) != ROK)
2349                     {
2350                        DU_LOG("\nERROR  ->  DU APP : Failure in BuildAndSendUeCtxtRsp()");
2351                        return RFAILED;
2352                     }
2353                  }
2354                  else
2355                  {
2356                     DU_LOG("\nERROR  ->  DU APP : Failure in updating DU UE CB");
2357                     return RFAILED;
2358                  }
2359               }
2360             }
2361          }
2362          else if(pst->event == EVENT_MAC_UE_RECONFIG_RSP)
2363          {
2364             DU_LOG("\nINFO   -->  DU APP : MAC UE Reconfig Response : SUCCESS [DU UE F1AP ID : %d]", cfgRsp->ueId);
2365             if(duCb.actvCellLst[cellIdx] && 
2366                   (duCb.actvCellLst[cellIdx]->ueCb[cfgRsp->ueId -1].gnbDuUeF1apId == cfgRsp->ueId))
2367             {
2368                duCb.actvCellLst[cellIdx]->ueCb[cfgRsp->ueId -1].macUeCfg.macUeCfgState = UE_RECFG_COMPLETE;
2369                if((duCb.actvCellLst[cellIdx]->ueCb[cfgRsp->ueId -1].macUeCfg.macUeCfgState == UE_RECFG_COMPLETE) &&
2370                      (duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].rlcUeCfg.rlcUeCfgState == UE_RECFG_COMPLETE))
2371                {
2372                   if((ret = duUpdateDuUeCbCfg(cfgRsp->ueId, cfgRsp->cellId)) == ROK)
2373                   {  
2374                      if((BuildAndSendUeCtxtRsp(cfgRsp->cellId, cfgRsp->ueId)) != ROK)
2375                      {
2376                         DU_LOG("\nERROR  ->  DU APP : Failure in BuildAndSendUeCtxtRsp()");
2377                         return RFAILED;
2378                      }
2379                   }
2380                   else
2381                   {
2382                      DU_LOG("\nERROR  ->  DU APP : Failure in updating DU UE CB");
2383                      return RFAILED;
2384                   }
2385                }
2386             }
2387          }
2388       }
2389       else
2390       {
2391          DU_LOG("\nERROR  -->  DU APP : MAC UE CFG Response for EVENT[%d]: FAILURE [DU UE F1AP ID : %d]", pst->event, cfgRsp->ueId);
2392          if(pst->event == EVENT_MAC_UE_RECONFIG_RSP)
2393          {
2394             //TODO: Send the failure case in Ue Context Setup Response
2395          }
2396          ret = RFAILED;
2397       }
2398       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(MacUeCfgRsp));
2399    }
2400    else
2401    {
2402       DU_LOG("\nERROR  -->  DU APP : Received MAC Ue Config Response is NULL at DuProcMacUeCfgRsp()");
2403       ret = RFAILED;
2404    }
2405    return ret;
2406 }
2407
2408
2409 /*******************************************************************
2410  *
2411  * @brief Processes UE create Req to RLC UL
2412  *
2413  * @details
2414  *
2415  *    Function : duBuildAndSendUeCreateReqToRlc
2416  *
2417  *    Functionality: 
2418  *     Processes UE create Req to RLC UL
2419  * 
2420  *  @params[in]  cellId,
2421  *               ueId,
2422  *               Pointer to RlcUeCfg
2423  *  @return ROK     - success
2424  *          RFAILED - failure
2425  * 
2426  *****************************************************************/
2427
2428 uint8_t duBuildAndSendUeCreateReqToRlc(uint16_t cellId, uint8_t gnbDuUeF1apId, DuUeCfg *ueCfgDb, RlcUeCfg *duRlcUeCfg)
2429 {
2430    uint8_t  ret = ROK;
2431    RlcUeCfg *rlcUeCfg = NULLP;
2432    Pst       pst;
2433   
2434    ret = fillRlcUeCfg(cellId, gnbDuUeF1apId, ueCfgDb, duRlcUeCfg);
2435    if(ret == RFAILED)
2436    {
2437       DU_LOG("\nERROR  -->  DU APP : Failed to fill Rlc Ue Cfg at duBuildAndSendUeCreateReqToRlc()");
2438       return ret;
2439    }
2440
2441    FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_CREATE_REQ);
2442    /* Copying ueCfg to a sharable buffer */
2443    DU_ALLOC_SHRABL_BUF(rlcUeCfg, sizeof(RlcUeCfg));
2444    if(rlcUeCfg)
2445    {
2446       memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
2447       memcpy(rlcUeCfg, duRlcUeCfg, sizeof(RlcUeCfg));
2448       /* Processing one Ue at a time to RLC */
2449       DU_LOG("\nDEBUG   -->  DU_APP: Sending UE create request to RLC UL");
2450       ret = (*packRlcUeCreateReqOpts[pst.selector])(&pst, rlcUeCfg);
2451       if(ret == RFAILED)
2452       {
2453          DU_LOG("\nERROR  -->  DU_APP : Failure in sending Ue Create Req to RLC");
2454          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rlcUeCfg, sizeof(RlcUeCfg));
2455          ret = RFAILED;
2456       }
2457    }
2458    else
2459    {
2460       DU_LOG("\n ERROR  -->  DU APP : Memory alloc failed at duBuildAndSendUeCreateReqToRlc()");
2461       ret = RFAILED;
2462    }
2463    return ret;
2464 }
2465
2466 /*******************************************************************
2467  *
2468  * @brief Processes UE create Rsp received from RLC UL
2469  *
2470  * @details
2471  *
2472  
2473  *    Function : DuProcRlcUeCfgRsp
2474  *
2475  *    Functionality: 
2476  *     Processes UE create Rsp received from RLC UL
2477  * 
2478  *  @params[in]  Post structure
2479  *               Pointer to RlcCfgCfm
2480  *  @return ROK     - success
2481  *          RFAILED - failure
2482  * 
2483  *****************************************************************/
2484 uint8_t DuProcRlcUeCfgRsp(Pst *pst, RlcUeCfgRsp *cfgRsp)
2485 {
2486    uint8_t ret = ROK;
2487
2488    if(cfgRsp)
2489    {
2490       if(cfgRsp->result == RLC_DU_APP_RSP_OK)
2491       {
2492          if(pst->event == EVENT_RLC_UE_CREATE_RSP)
2493          {
2494             DU_LOG("\nINFO   -->  DU_APP: RLC UE Create Response : SUCCESS [UE IDX:%d]", cfgRsp->ueId);
2495             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].rlcUeCfg.rlcUeCfgState = UE_CREATE_COMPLETE;
2496
2497             if((duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].ueState == UE_HANDIN_IN_PROGRESS) &&
2498             (duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].macUeCfg.macUeCfgState == UE_CREATE_COMPLETE) &&
2499             (duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].rlcUeCfg.rlcUeCfgState == UE_CREATE_COMPLETE))
2500             {
2501                if((ret = duUpdateDuUeCbCfg(cfgRsp->ueId, cfgRsp->cellId)) == ROK)
2502                {
2503                   if((BuildAndSendUeCtxtRsp(cfgRsp->cellId, cfgRsp->ueId)) != ROK)
2504                   {
2505                      DU_LOG("\nERROR  -->  DU APP : Failure in BuildAndSendUeCtxtRsp");
2506                      return RFAILED;
2507                   }
2508                }
2509                else
2510                {
2511                   DU_LOG("\nERROR  -->  DU APP : Failure in updating DU UE CB");
2512                   return RFAILED;
2513                }
2514             }
2515          }
2516          else if(pst->event == EVENT_RLC_UE_RECONFIG_RSP)
2517          {
2518             DU_LOG("\nINFO   -->  DU_APP: RLC UE Reconfig Response : SUCCESS [UE IDX:%d]", cfgRsp->ueId);
2519
2520             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].rlcUeCfg.rlcUeCfgState = UE_RECFG_COMPLETE;
2521             if((duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].macUeCfg.macUeCfgState == UE_RECFG_COMPLETE) &&
2522                   (duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueId -1].rlcUeCfg.rlcUeCfgState == UE_RECFG_COMPLETE))
2523             {
2524                if((ret = duUpdateDuUeCbCfg(cfgRsp->ueId, cfgRsp->cellId)) == ROK)
2525                {
2526                   if((BuildAndSendUeCtxtRsp(cfgRsp->cellId, cfgRsp->ueId)) != ROK)
2527                   {
2528                      DU_LOG("\nERROR  -->  DU APP : Failure in BuildAndSendUeCtxtRsp");
2529                      return RFAILED;
2530                   }
2531                }
2532                else
2533                {
2534                   DU_LOG("\nERROR  -->  DU APP : Failure in updating DU UE CB");
2535                   return RFAILED;
2536                }
2537             }
2538          }
2539       }
2540       else
2541       {
2542          DU_LOG("\nERROR  -->  DU_APP: RLC UE CFG Response for EVENT[%d] : FAILED [UE IDX : %d, REASON :%d]",\
2543                pst->event, cfgRsp->ueId, cfgRsp->reason);
2544          if((pst->event == EVENT_RLC_UE_RECONFIG_RSP))
2545          {
2546             //TODO: update failure case in ue Context setup Response
2547          }
2548          ret = RFAILED;
2549       }
2550       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(RlcUeCfgRsp));
2551    }
2552    else
2553    {
2554       DU_LOG("\nERROR  -->  DU_APP: Received RLC Ue Config Response is NULL at DuProcRlcUeCfgRsp()");
2555       ret = RFAILED;
2556    }
2557    return ret;
2558 }
2559
2560 /*******************************************************************
2561  *
2562  * @brief Builds and Send Ue Reconfig Req to RLC
2563  *
2564  * @details
2565  *
2566  *    Function : duBuildAndSendUeReCfgReqToRLC
2567  *
2568  *    Functionality: Builds and Send Ue Reconfig Req to RLC
2569  *
2570  * @params[in] cellId, crnti
2571  *             DuUeCfg *ueCfgDb
2572  *             RlcUeCfg *rlcUeCfg
2573  * @return ROK     - success
2574  *         RFAILED - failure
2575  *
2576  * ****************************************************************/
2577
2578 uint8_t duBuildAndSendUeReCfgReqToRlc(uint8_t cellId, uint8_t gnbDuUeF1apId, uint8_t crnti, DuUeCfg *ueCfgDb)
2579 {
2580    uint8_t ret = ROK;
2581    RlcUeCfg *rlcUeCfg = NULLP;
2582
2583    DU_ALLOC_SHRABL_BUF(rlcUeCfg, sizeof(RlcUeCfg));
2584    if(rlcUeCfg)
2585    {
2586       memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
2587       ret = fillRlcUeCfg(cellId, gnbDuUeF1apId, ueCfgDb, rlcUeCfg);
2588       if(ret == RFAILED)
2589          DU_LOG("\nERROR  -->  DU APP : Failed at duBuildAndSendUeReCfgReqToRlc()");
2590       else
2591          ret = sendUeReCfgReqToRlc(rlcUeCfg);
2592    }
2593    else
2594    {
2595       DU_LOG("\nERROR  -->  DU APP : Memory Alloc failed at duBuildAndSendUeReCfgReqToRlc()");
2596       ret = RFAILED;
2597    }
2598    return ret;
2599 }
2600
2601 /*******************************************************************
2602  *
2603  * @brief Builds and Send Ue Reconfig Req to MAC
2604  *
2605  * @details
2606  *
2607  *    Function : duBuildAndSendUeReCfgReqToMac
2608  *
2609  *    Functionality: Builds and Send Ue Reconfig Req to MAC
2610  *
2611  * @params[in] CellGroupConfigRrc_t *macCellGrpCfg
2612  *             DuUeCfg *ueCfgDb
2613  *             MacUeCfg    *macUeCfg
2614  * @return ROK     - success
2615  *         RFAILED - failure
2616  *
2617  * ****************************************************************/
2618
2619 uint8_t duBuildAndSendUeReCfgReqToMac(uint8_t cellId, uint8_t duUeF1apId, uint8_t crnti, DuUeCfg *ueCfgDb)
2620 {
2621    uint8_t ret = ROK;
2622    MacUeCfg *macUeCfg = NULLP;
2623
2624    DU_ALLOC_SHRABL_BUF(macUeCfg, sizeof(MacUeCfg));
2625    if(macUeCfg)
2626    {
2627       memset(macUeCfg, 0, sizeof(MacUeCfg));
2628       ret = fillMacUeCfg(cellId, duUeF1apId, ueCfgDb, macUeCfg);
2629       if(ret == RFAILED)
2630          DU_LOG("\nERROR  -->  DU APP : Failed to fill Mac Ue Cfg at duBuildAndSendUeReCfgReqToMac()");
2631       else
2632          ret = sendUeReCfgReqToMac(macUeCfg);
2633    }
2634    else
2635    {
2636       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed for macUeCfg at duBuildAndSendUeReCfgReqToMac()");
2637       ret = RFAILED;
2638    }
2639    return ret;
2640 }
2641
2642 /*******************************************************************
2643  *
2644  * @brief Build and Send Ue context setup request
2645  *
2646  * @details
2647  *
2648  
2649  *    Function : duBuildAndSendUeContextSetupReq
2650  *
2651  *    Functionality: 
2652  *     Build and Send Ue context setup request
2653  * 
2654  *  @params[in]  cellId, crnti, DuUeCfg pointer
2655  *  @return ROK     - success
2656  *          RFAILED - failure
2657  * 
2658  *****************************************************************/
2659
2660 uint8_t duBuildAndSendUeContextSetupReq(uint16_t cellId, DuUeCb *ueCb)
2661 {
2662    uint8_t ret = ROK;
2663    uint16_t crnti; 
2664    DuUeCfg *duUeCfg = NULLP;
2665
2666    DU_LOG("\nDEBUG   -->  DU_APP: Processing Ue Context Setup Request for cellId [%d]", cellId);
2667
2668    if(!ueCb)
2669    {
2670       DU_LOG("\nERROR  -->  DU APP : UE Cb is NULL");
2671       return RFAILED;
2672    }
2673
2674    crnti = ueCb->crnti;
2675    duUeCfg = &ueCb->f1UeDb->duUeCfg;
2676
2677    /* If UE is being handed-in to this DU, UE context setup request will create
2678     * new UE context at MAC/SCH and RLC.
2679     * If UE is in active state, UE contex setup request will lead to
2680     * reconfiguration of UE at MAC/SCH and RLC
2681     */
2682    if(ueCb->ueState == UE_HANDIN_IN_PROGRESS)
2683    {
2684       /* Filling MAC UE Config */
2685       memset(&ueCb->macUeCfg, 0, sizeof(MacUeCfg));
2686
2687       /* Since UE attach has not yet happened, crnti is unknow. Hence passing 0 */
2688       ret = duBuildAndSendUeCreateReqToMac(cellId, ueCb->gnbDuUeF1apId, duUeCfg, &ueCb->macUeCfg);
2689       if(ret == RFAILED)
2690          DU_LOG("\nERROR  -->  DU APP : Failed to send UE create request to MAC");
2691
2692       ret = duBuildAndSendUeCreateReqToRlc(cellId, ueCb->gnbDuUeF1apId, duUeCfg, &ueCb->rlcUeCfg);
2693       if(ret == RFAILED)
2694          DU_LOG("\nERROR  --> DU APP : Failed to send UE create request to RLC");
2695
2696    }
2697    else
2698    {
2699       /* Filling RLC UE Reconfig */ 
2700       ret = duBuildAndSendUeReCfgReqToRlc(cellId, ueCb->gnbDuUeF1apId, crnti, duUeCfg);
2701       if(ret == RFAILED)
2702          DU_LOG("\nERROR  -->  DU APP : Failed to build ctxt setup req for RLC at duBuildAndSendUeContextSetupReq()");
2703
2704       /* Filling MAC UE Reconfig */
2705       ret = duBuildAndSendUeReCfgReqToMac(cellId, ueCb->gnbDuUeF1apId, crnti, duUeCfg);
2706       if(ret == RFAILED)
2707          DU_LOG("\nERROR  -->  DU APP : Failed at build ctxt setup req for MAC at duBuildAndSendUeContextSetupReq()");
2708    }
2709
2710    return ret;
2711 }
2712
2713 /*******************************************************************
2714  *
2715  * @brief Processes DL Rsp received from RLC DL
2716  *
2717  * @details
2718  *
2719  
2720  *    Function : DuProcRlcDlRrcMsgRsp
2721  *
2722  *    Functionality: 
2723  *     Processes UE Rsp received from RLC DL
2724  * 
2725  *  @params[in]  Post structure
2726  *               Pointer to RlcCfgCfm
2727  *  @return ROK     - success
2728  *          RFAILED - failure
2729  * 
2730  *****************************************************************/
2731 uint8_t DuProcRlcDlRrcMsgRsp(Pst *pst, RlcDlRrcMsgRsp *dlRrcMsg)
2732 {
2733    uint8_t ret = ROK, ueId = 0;
2734    uint16_t cellId, crnti;
2735    DuUeCb *ueCb = NULLP;
2736    DlMsgState state;
2737
2738    state = dlRrcMsg->state;
2739    cellId = dlRrcMsg->cellId;
2740    crnti = dlRrcMsg->crnti;
2741    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlRrcMsg, sizeof(RlcDlRrcMsgRsp));
2742
2743    if(state == TRANSMISSION_COMPLETE)
2744    {
2745       GET_UE_ID(crnti, ueId);
2746       ueCb = &duCb.actvCellLst[cellId -1]->ueCb[ueId -1];
2747
2748       if(ueCb->f1UeDb && ueCb->f1UeDb->dlRrcMsgPres)
2749       {
2750          if(ueCb->f1UeDb->actionType == UE_CTXT_SETUP)
2751          {
2752             ret = duBuildAndSendUeContextSetupReq(cellId, ueCb);
2753             if(ret == RFAILED)
2754                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Setup Request in DuProcRlcDlRrcMsgRsp()");
2755          }
2756          
2757          if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
2758          {
2759             ret = duBuildAndSendUeContextModReq(cellId, ueCb->gnbDuUeF1apId, crnti, &ueCb->f1UeDb->duUeCfg);
2760             if(ret == RFAILED)
2761                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Mod Request in DuProcRlcDlRrcMsgRsp()");
2762          }
2763
2764          if(ueCb->f1UeDb->actionType == UE_CTXT_RELEASE && ueCb->ueState == UE_ACTIVE)
2765          {
2766             ret = duBuildAndSendUeDeleteReq(cellId, crnti);
2767             if(ret == RFAILED)
2768             {
2769                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Release Request in DuProcRlcDlRrcMsgRsp()");
2770             }
2771          }
2772       }
2773    }
2774    else
2775       DU_LOG("\nERROR  -->  DU APP : Failed to transmit DL RRC Msg");
2776
2777    return ret;
2778 }
2779 /*******************************************************************
2780  *
2781  * @brief Process UE context setup request from CU
2782  *
2783  * @details
2784  *
2785  *    Function : duProcUeContextSetupRequest 
2786  *
2787  *    Functionality: Process UE context setup request from CU
2788  *
2789  * @params[in] F1AP message
2790  * @return ROK     - success
2791  *         RFAILED - failure
2792  *
2793  * ****************************************************************/
2794
2795 uint8_t duProcUeContextSetupRequest(DuUeCb *ueCb)
2796 {
2797    uint8_t ret, cellId;
2798
2799    ret = ROK;
2800    if(ueCb)
2801    {
2802       cellId = duCb.actvCellLst[ueCb->f1UeDb->cellIdx]->cellId;
2803
2804       /* Send DL RRC msg for security Mode */
2805       if(ueCb->f1UeDb->dlRrcMsg)
2806       {
2807          if(ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
2808          {
2809             /* Sending DL RRC Message to RLC */
2810             ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->rlcUeCfg, ueCb->f1UeDb->dlRrcMsg);
2811             if(ret == RFAILED)
2812             {
2813                DU_LOG("\nERROR  -->  DU APP : Failed to send DL RRC msg in duProcUeContextSetupRequest()");
2814                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
2815                      ueCb->f1UeDb->dlRrcMsg->rrcMsgSize);
2816                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
2817             }
2818          }
2819       }
2820       else if(ueCb->f1UeDb->actionType == UE_CTXT_SETUP)
2821       {
2822          ret = duBuildAndSendUeContextSetupReq(cellId, ueCb);
2823          if(ret == RFAILED)
2824          {
2825             DU_LOG("\nERROR  -->  DU APP : Failed to build ue context setup Req in duProcUeContextSetupRequest()");
2826          }
2827       }
2828    }
2829    else
2830    {
2831       //TODO: To send the failure cause in UeContextSetupRsp
2832       DU_LOG("ERROR  -->  DU APP : Failed to process UE CNTXT SETUP REQ at duProcUeContextSetupRequest()");
2833    }
2834    return ret;
2835 }
2836
2837 /*******************************************************************
2838  *
2839  * @brief Build and Send Ue context mod request
2840  *
2841  * @details
2842  *
2843  *
2844  *    Function : duBuildAndSendUeContextModReq
2845  *
2846  *    Functionality: 
2847  *     Build and Send Ue context mod request
2848  * 
2849  *  @params[in]  cellId, crnti, DuUeCfg pointer
2850  *  @return ROK     - success
2851  *          RFAILED - failure
2852  * 
2853  *****************************************************************/
2854
2855 uint8_t duBuildAndSendUeContextModReq(uint16_t cellId, uint8_t gnbDuUeF1apId, uint16_t crnti, DuUeCfg *duUeCfg)
2856 {
2857    uint8_t ret = ROK;
2858
2859    DU_LOG("\nDEBUG   -->  DU_APP: Processing Ue Context Mod Request for cellId [%d]", cellId);
2860    /* Filling RLC Ue Reconfig */ 
2861    ret = duBuildAndSendUeReCfgReqToRlc(cellId, gnbDuUeF1apId, crnti, duUeCfg);
2862    if(ret == RFAILED)
2863       DU_LOG("\nERROR  -->  DU APP : Failed to build ctxt setup req for RLC at duBuildAndSendUeContextModReq()");
2864    
2865    /* Filling MAC Ue Reconfig */
2866    ret = duBuildAndSendUeReCfgReqToMac(cellId, gnbDuUeF1apId, crnti, duUeCfg);
2867    if(ret == RFAILED)
2868       DU_LOG("\nERROR  -->  DU APP : Failed at build ctxt setup req for MAC at duBuildAndSendUeContextModReq()");
2869
2870    return ret;
2871 }
2872 /*******************************************************************
2873  *
2874  * @brief Processing Ue context mod request
2875  *
2876  * @details
2877  *
2878  *
2879  *    Function : duProcUeContextModReq 
2880  *
2881  *    Functionality:
2882  *        Processing  Ue context mod request
2883  *
2884  *  @params[in] DuUeCb *ueCb 
2885  *  @return ROK     - success
2886  *          RFAILED - failure
2887  *
2888  *****************************************************************/
2889
2890 uint8_t duProcUeContextModReq(DuUeCb *ueCb)
2891 {
2892    uint8_t ret, cellId;
2893
2894    ret = ROK;
2895    if(ueCb)
2896    {
2897       cellId = duCb.actvCellLst[ueCb->f1UeDb->cellIdx]->cellId;
2898       /* Send DL RRC msg for security Mode */
2899       if(ueCb->f1UeDb->dlRrcMsg)
2900       {
2901          if(ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
2902          {
2903             /* Sending DL RRC Message to RLC */
2904             ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->rlcUeCfg, ueCb->f1UeDb->dlRrcMsg);
2905             if(ret == RFAILED)
2906             {
2907                DU_LOG("\nERROR  -->  DU APP : Failed to send DL RRC msg in duProcUeContextModReq()");
2908                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
2909                      ueCb->f1UeDb->dlRrcMsg->rrcMsgSize);
2910                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
2911             }
2912          }
2913       }
2914       else if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
2915       {
2916          ret = duBuildAndSendUeContextModReq(cellId, ueCb->gnbDuUeF1apId, ueCb->crnti, &ueCb->f1UeDb->duUeCfg);
2917          if(ret == RFAILED)
2918          {
2919             DU_LOG("\nERROR  -->  DU APP : Failed to build ue context setup Req in duProcUeContextModReq()");
2920             return RFAILED;
2921          }
2922       }
2923       else if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || (ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE))
2924       {
2925          if((BuildAndSendUeContextModRsp(ueCb) != ROK))
2926          {
2927             DU_LOG("\nERROR  -->  DU APP : Failed to build UE Context modification response");
2928             return RFAILED;
2929          }
2930       }
2931    }
2932    else
2933    {
2934       //TODO: To send the failure cause in UeContextModRsp
2935       
2936       DU_LOG("ERROR  -->  DU APP : Failed to process UE CNTXT MOD REQ at duProcUeContextModReq()");
2937       return RFAILED;
2938    }
2939    return ROK;
2940 }
2941
2942 /*******************************************************************
2943 *
2944 * @brief Function to delete Pdsch ServCellCfg
2945 *
2946 * @details
2947 *
2948 *    Function : deletePdschServCellCfg
2949 *
2950 *    Functionality: Function to delete Pdsch ServCellCfg
2951 *
2952 * @params[in] PdschServCellCfg *pdschServCellCfg
2953 * @return void
2954 *
2955 * ****************************************************************/
2956
2957 void deletePdschServCellCfg(PdschServCellCfg *pdschServCellCfg)
2958 {
2959    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
2960    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
2961    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
2962    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->xOverhead, sizeof(PdschXOverhead));
2963 }
2964
2965 /*******************************************************************
2966  *
2967 * @brief delete MacUeCfg from duCb
2968 *
2969 * @details
2970 *
2971 *    Function : deleteMacUeCfg 
2972 *
2973 *    Functionality: delete MacUeCfg from duCb
2974 *
2975 * @params[in] Pointer to MacUeCfg 
2976 * @return ROK     - success
2977 *         RFAILED - failure
2978 *
2979 *******************************************************************/
2980
2981 void deleteMacUeCfg(MacUeCfg *ueCfg)
2982 {
2983    uint8_t lcCfgIdx=0;
2984    
2985    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,ueCfg->ambrCfg, sizeof(AmbrCfg));
2986    if(ueCfg->spCellCfgPres)
2987    {
2988       freeUeReCfgCellGrpInfo(ueCfg);
2989    }
2990    for(lcCfgIdx=0; lcCfgIdx< ueCfg->numLcs; lcCfgIdx++)
2991    {
2992       freeMacLcCfg(&ueCfg->lcCfgList[lcCfgIdx]);
2993    }
2994    memset(ueCfg, 0, sizeof(MacUeCfg));
2995 }
2996
2997 /*******************************************************************
2998 *
2999 * @brief delete UE Configuration of a particular UE
3000 *
3001 * @details
3002 *
3003 *    Function : deleteUeCfg 
3004 *
3005 *    Functionality: delete UE Configuration of a particular UE 
3006 *
3007 * @params[in] uint16_t cellIdx, uint8_t ueId
3008 * @return ROK     - success
3009 *         RFAILED - failure
3010 *
3011 * ****************************************************************/
3012 uint8_t  deleteUeCfg(uint16_t cellId, uint8_t ueId)
3013 {
3014    uint8_t tnlIdx = 0;
3015    uint16_t cellIdx = 0;
3016    DuUeCb *ueCb = NULLP;
3017    
3018    GET_CELL_IDX(cellId, cellIdx);
3019    if(duCb.actvCellLst[cellIdx] != NULLP)
3020    {
3021       if((duCb.actvCellLst[cellIdx]->ueCb[ueId-1].macUeCfg.macUeCfgState == UE_DELETE_COMPLETE)\
3022             &&(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].rlcUeCfg.rlcUeCfgState == UE_DELETE_COMPLETE))
3023       {
3024          ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
3025          deleteMacUeCfg(&ueCb->macUeCfg);
3026          deleteRlcUeCfg(&ueCb->rlcUeCfg);
3027          if(ueCb->f1UeDb !=NULLP)
3028          {
3029             freeF1UeDb(ueCb->f1UeDb);
3030          }
3031          for(tnlIdx = 0; tnlIdx < duCb.numTeId; )
3032          {
3033             if(duCb.upTnlCfg[tnlIdx]->ueId == ueId)
3034             {
3035                duCb.upTnlCfg[tnlIdx]->configType = CONFIG_DEL;
3036                duProcEgtpTunnelCfg(tnlIdx, duCb.upTnlCfg[tnlIdx], duCb.upTnlCfg[tnlIdx]);
3037             }
3038             else
3039                tnlIdx++;
3040          }
3041          unsetBitInUeBitMap(cellId, ueId-1);
3042          duCb.actvCellLst[cellIdx]->numActvUes--;
3043          memset(ueCb, 0, sizeof(DuUeCb));
3044       }
3045       else
3046       {
3047          return RFAILED;
3048       }
3049    }
3050    else
3051    {
3052       DU_LOG("\nERROR  --> DU APP : deleteUeCfg(): CellIdx[%d] is not found", cellIdx);
3053       return RFAILED;
3054    }
3055    return ROK;
3056 }
3057
3058
3059 /*******************************************************************
3060 *
3061 * @brief Handle UE delete response from MAC
3062 *
3063 * @details
3064 *
3065 *    Function : DuProcMacUeDeleteRsp
3066 *
3067 *    Functionality: Handle UE delete response from MAC
3068 *
3069 * @params[in] Pointer to MacUeDeleteRsp and Pst
3070 * @return ROK     - success
3071 *         RFAILED - failure
3072 *
3073 * ****************************************************************/
3074
3075 uint8_t DuProcMacUeDeleteRsp(Pst *pst, MacUeDeleteRsp *deleteRsp)
3076 {
3077    uint8_t  ret =ROK,ueId=0;
3078    uint16_t cellIdx=0;
3079    uint32_t gnbCuUeF1apId =0 , gnbDuUeF1apId =0;
3080    
3081    if(deleteRsp)
3082    {
3083       if(deleteRsp->result == SUCCESS)
3084       {
3085          DU_LOG("\nINFO   -->  DU APP : MAC UE Delete Response : SUCCESS [UE IDX : %d]", deleteRsp->ueId);
3086          GET_CELL_IDX(deleteRsp->cellId, cellIdx);
3087          if(duCb.actvCellLst[cellIdx])
3088          {
3089             duCb.actvCellLst[cellIdx]->ueCb[deleteRsp->ueId -1].macUeCfg.macUeCfgState = UE_DELETE_COMPLETE;
3090             ueId = deleteRsp->ueId;
3091             gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
3092             gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
3093             if(deleteUeCfg(deleteRsp->cellId, ueId) == ROK)
3094             {
3095                ret = BuildAndSendUeContextReleaseComplete(deleteRsp->cellId, gnbCuUeF1apId, gnbDuUeF1apId);
3096                if(ret != ROK)
3097                {
3098                   DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): failed to send UE context release complete");
3099                }
3100             }
3101
3102          }
3103       }
3104       else
3105       {
3106          DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): MAC UE Delete Response : FAILURE [UE IDX : %d]",\
3107          deleteRsp->ueId);
3108          ret =  RFAILED;
3109       }
3110       DU_FREE_SHRABL_BUF(pst->region, pst->pool, deleteRsp, sizeof(MacUeDeleteRsp));
3111    }
3112    else
3113    {
3114       DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): MAC UE Delete Response is null");
3115       ret = RFAILED;
3116    }
3117    return ret;
3118 }
3119
3120 /*******************************************************************
3121  *
3122  * @brief Processes UE Delete Rsp received from RLC 
3123  *
3124  * @details
3125  *
3126  *    Function : DuProcRlcUeDeleteRsp
3127  *
3128  *    Functionality:
3129  *     Processes UE Delete Rsp received from RLC 
3130  *
3131  *  @params[in]  Post structure
3132  *               Pointer to RlcUeDeleteRsp
3133  *  @return ROK     - success
3134  *          RFAILED - failure
3135  *
3136  * *****************************************************************/
3137
3138 uint8_t DuProcRlcUeDeleteRsp(Pst *pst, RlcUeDeleteRsp *delRsp)
3139 {
3140    uint8_t  ueId = 0, ret = ROK;
3141    uint16_t cellIdx = 0,crnti=0;
3142
3143    if(delRsp)
3144    {
3145       ueId = delRsp->ueId;
3146       GET_CELL_IDX(delRsp->cellId, cellIdx);
3147
3148       if(delRsp->result == SUCCESSFUL)
3149       {
3150          DU_LOG("\nINFO   -->  DU_APP: RLC UE Delete Response : SUCCESS [UE IDX:%d]", ueId);
3151          if(duCb.actvCellLst[cellIdx]!=NULLP)
3152          {
3153             duCb.actvCellLst[cellIdx]->ueCb[ueId-1].rlcUeCfg.rlcUeCfgState = UE_DELETE_COMPLETE;
3154             GET_CRNTI(crnti, ueId);
3155             if(sendUeDeleteReqToMac(delRsp->cellId, ueId, crnti) == RFAILED)
3156             {
3157                DU_LOG("\nERROR  -->  DU APP : duBuildAndSendUeDeleteReq(): Failed to build UE  delete req for MAC ");
3158                return RFAILED;
3159             }
3160
3161          }
3162       }
3163       else
3164       {
3165          DU_LOG("\nERROR   -->  DU_APP: RLC UE Delete Response : FAILED [UE IDX:%d]", ueId);
3166          ret = RFAILED;
3167       }
3168       DU_FREE_SHRABL_BUF(pst->region, pst->pool, delRsp, sizeof(RlcUeDeleteRsp));
3169
3170    }
3171    return ret;
3172 }
3173
3174 /*******************************************************************
3175  *
3176  * @brief Sending UE Delete Req To Mac
3177 *
3178 * @details
3179 *
3180 *    Function : sendUeDeleteReqToMac
3181 *
3182 *    Functionality:
3183 *     sending UE Delete Req To Mac
3184 *
3185 *  @params[in]    cellId, ueId, crnti 
3186 *  @return ROK     - success
3187 *          RFAILED - failure
3188 *
3189 *****************************************************************/
3190
3191 uint8_t sendUeDeleteReqToMac(uint16_t cellId, uint8_t ueId, uint16_t crnti)
3192 {
3193    Pst pst;
3194    uint8_t ret=ROK;
3195    MacUeDelete *ueDelete = NULLP;
3196
3197    DU_ALLOC_SHRABL_BUF(ueDelete, sizeof(MacUeDelete));
3198    if(ueDelete)
3199    {
3200       ueDelete->cellId = cellId;
3201       ueDelete->ueId   = ueId;
3202       ueDelete->crnti  = crnti;
3203       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_DELETE_REQ);
3204
3205       DU_LOG("\nDEBUG  -->  DU_APP: Sending UE delete Request to MAC ");
3206       ret = (*packMacUeDeleteReqOpts[pst.selector])(&pst, ueDelete);
3207       if(ret == RFAILED)
3208       {
3209          DU_LOG("\nERROR  -->  DU_APP: sendUeDeleteReqToMac(): Failed to send UE delete Req to MAC");
3210          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueDelete, sizeof(MacUeDelete));
3211       }
3212    }
3213    else
3214    {
3215       DU_LOG("\nERROR  -->   DU_APP: sendUeDeleteReqToMac(): Failed to allocate memory"); 
3216       ret = RFAILED;
3217    }
3218    return ret;
3219 }
3220
3221 /*******************************************************************
3222  *
3223  * @brief Sending UE Delete Req To Rlc
3224  *
3225  * @details
3226  *
3227  *    Function : sendUeDeleteReqToRlc
3228  *
3229  *    Functionality:
3230  *     Sending UE Delete Req To Rlc
3231  *
3232  *  @params[in]  cellId, ueId 
3233  *  @return ROK     - success
3234  *          RFAILED - failure
3235  *
3236  *****************************************************************/
3237
3238 uint8_t sendUeDeleteReqToRlc(uint16_t cellId, uint8_t ueId)
3239 {
3240    uint8_t ret;
3241    Pst pst;
3242    RlcUeDelete *ueDelete;
3243
3244    DU_ALLOC_SHRABL_BUF(ueDelete, sizeof(RlcUeDelete));
3245    if(ueDelete !=NULLP)
3246    {
3247       ueDelete->cellId = cellId;
3248       ueDelete->ueId = ueId;
3249       FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_DELETE_REQ);
3250
3251       ret = (*packRlcUeDeleteReqOpts[pst.selector])(&pst, ueDelete);
3252       if(ret == RFAILED)
3253       {
3254          DU_LOG("\nERROR  -->  DU_APP : sendUeDeleteReqToRlc():Failed to send UE Delete  Req to RLC"); 
3255          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueDelete, sizeof(RlcUeDelete));
3256       }
3257    }
3258    else
3259    {
3260       DU_LOG("\nERROR  -->   DU_APP: sendUeDeleteReqToRlc():Memory allocation failed");
3261       ret = RFAILED;
3262    }
3263    return ret;
3264 }
3265
3266 /*******************************************************************
3267  *
3268  * @brief DU processes UE delete req from CU and sends to MAC and RLC 
3269  *
3270  * @details
3271  *
3272  *    Function : duBuildAndSendUeDeleteReq
3273  *
3274  *    Functionality: DU processes UE delete req from CU and sends to MAC 
3275  *                   and RLC 
3276  *
3277  * @params[in] cellId, crnti 
3278  * @return ROK     - success
3279  *         RFAILED - failure
3280  *
3281  * ****************************************************************/
3282
3283 uint8_t duBuildAndSendUeDeleteReq(uint16_t cellId, uint16_t crnti)
3284 {
3285    uint8_t  ueId =0;
3286    uint16_t cellIdx = 0;
3287
3288    DU_LOG("\nDEBUG  -->  DU_APP: Processing UE Delete Request ");
3289    GET_CELL_IDX(cellId, cellIdx);
3290    GET_UE_ID(crnti, ueId);
3291
3292    if(duCb.actvCellLst[cellIdx] != NULLP)
3293    {
3294       if(crnti != duCb.actvCellLst[cellIdx]->ueCb[ueId - 1].crnti)
3295       {
3296          DU_LOG("\nERROR  -->  DU APP : duBuildAndSendUeDeleteReq(): CRNTI [%d] not found", crnti);
3297          return RFAILED;
3298       }
3299
3300       duCb.actvCellLst[cellIdx]->ueCb[ueId - 1].ueState = UE_DELETION_IN_PROGRESS; 
3301       if(sendUeDeleteReqToRlc(cellId, ueId) == RFAILED)
3302       {
3303          DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp():Failed to build UE  delete req for RLC ");
3304          return RFAILED;
3305       }
3306    }
3307    else
3308    {
3309       DU_LOG("\nERROR  -->  DU APP : duBuildAndSendUeDeleteReq(): Cell Id is not found");
3310       return RFAILED;
3311    }
3312
3313    return ROK;
3314 }
3315
3316 /*******************************************************************
3317  *
3318  * @brief delete RlcUeCfg from duCb
3319  *
3320  * @details
3321  *
3322  *    Function : deleteRlcUeCfg
3323  *
3324  *    Functionality:
3325  *       delete  RlcUeCfg from duCb
3326  *
3327  *  @params[in] RlcUeCfg *ueCfg 
3328  *               
3329  *  @return ROK     - success
3330  *          RFAILED - failure
3331  *
3332  *****************************************************************/
3333
3334 void deleteRlcUeCfg(RlcUeCfg *ueCfg)
3335 {
3336    uint8_t lcIdx = 0;
3337    RlcBearerCfg *lcCfg= NULLP;
3338    if(ueCfg)
3339    {
3340       for(lcIdx =0 ; lcIdx < ueCfg->numLcs ; lcIdx++)
3341       {
3342          lcCfg = &ueCfg->rlcLcCfg[lcIdx];
3343          switch(lcCfg->rlcMode)
3344          {
3345             case RLC_AM :
3346                {
3347                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
3348                   break;
3349                }
3350             case RLC_UM_BI_DIRECTIONAL :
3351                {
3352                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
3353                   break;
3354                }
3355             case RLC_UM_UNI_DIRECTIONAL_UL :
3356                {
3357                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
3358                   break;
3359                }
3360             case RLC_UM_UNI_DIRECTIONAL_DL :
3361                {
3362                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
3363                   break;
3364                }
3365          }
3366          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
3367       }
3368       memset(ueCfg, 0, sizeof(RlcUeCfg));
3369    }
3370 }
3371
3372 /*******************************************************************
3373 *
3374 * @brief Du process Ue Context Release Command
3375 *
3376 * @details
3377 *
3378 *    Function : duProcUeContextReleaseCommand 
3379 *
3380 *    Functionality: Du process Ue Context Release Command 
3381 *
3382 * @params[in] DuUeCb *duUeCb 
3383 * @return ROK     - success
3384 *         RFAILED - failure
3385 *
3386 * ****************************************************************/
3387 uint8_t duProcUeContextReleaseCommand(uint16_t cellId, DuUeCb *duUeCb)
3388 {
3389    uint8_t ret =ROK, ueId=0;
3390    uint16_t crnti = 0;
3391
3392    if(duUeCb != NULLP)
3393    {
3394       crnti = duUeCb->crnti;
3395       GET_UE_ID(crnti, ueId);
3396       
3397       if(duUeCb->f1UeDb)
3398       {
3399          /* Send DL RRC msg for RRC release */
3400          if(duUeCb->f1UeDb->dlRrcMsg)
3401          {
3402             if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu != NULLP)
3403             {
3404                ret = duBuildAndSendDlRrcMsgToRlc(cellId, duCb.actvCellLst[duUeCb->f1UeDb->cellIdx]->ueCb[ueId-1].rlcUeCfg,\
3405                      duUeCb->f1UeDb->dlRrcMsg);
3406                if(ret == RFAILED)
3407                {
3408                   DU_LOG("\nERROR  -->  DU APP : duProcUeContextReleaseCommand() : Failed to send DL RRC msg");
3409                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
3410                         duUeCb->f1UeDb->dlRrcMsg->rrcMsgSize);
3411                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
3412                }
3413             }
3414          }
3415       }
3416       else
3417       {
3418          ret = duBuildAndSendUeDeleteReq(cellId,crnti);
3419          if(ret == RFAILED)
3420          {
3421             DU_LOG("\nERROR  -->  DU APP : duProcUeContextReleaseCommand(): Failed to build and send Ue Delete request");
3422          }
3423       }
3424    }
3425    return ret;
3426 }
3427
3428 /**********************************************************************
3429   End of file
3430 ***********************************************************************/