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