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