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