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