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