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