MAC Clean-up [Issue-ID: ODUHIGH-212]
[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 "lkw.x"
23 #include "legtp.h"
24 #include "du_app_mac_inf.h"
25 #include "du_cfg.h"
26 #include "du_ue_mgr.h"
27 #include "du_utils.h"
28 #include<ProtocolIE-Field.h>
29 #include "F1AP-PDU.h"
30
31 #ifdef EGTP_TEST
32 U32 sduId = 0;
33 #endif
34
35 DuMacDlCcchInd packMacDlCcchIndOpts[] =
36 {
37    packMacDlCcchInd,   /* Loose coupling */
38    MacProcDlCcchInd,    /* TIght coupling */
39    packMacDlCcchInd    /* Light weight-loose coupling */
40 };
41
42 DuMacUeCreateReq packMacUeCreateReqOpts[] =
43 {
44    packDuMacUeCreateReq,       /* Loose coupling */
45    MacProcUeCreateReq,          /* TIght coupling */
46    packDuMacUeCreateReq,       /* Light weight-loose coupling */
47 };
48
49 /******************************************************************
50  *
51  * @brief Send UE configuration to RLC
52  *
53  * @details
54  *
55  *    Function : duSendUeCreateReqToRlc
56  *
57  *    Functionality: Send UeCreateReqToRlc
58  *
59  * @return ROK     - success
60  *         RFAILED - failure
61  *
62  * ****************************************************************/
63 S16 duSendUeCreateReqToRlc()
64 {
65    U8  idx;
66    Pst pst;
67    CkwCfgInfo *ueCfg;
68
69    DU_SET_ZERO(&ueCfg, sizeof(ueCfg));
70    DU_SET_ZERO(&pst, sizeof(Pst));
71
72    DU_ALLOC(ueCfg, sizeof(CkwCfgInfo));
73
74 #ifdef EGTP_TEST
75    ueCfg->ueId = UE_ID;
76 #endif
77    ueCfg->cellId = NR_CELL_ID;
78    ueCfg->numEnt = 1;
79
80    for(idx = 0; idx < ueCfg->numEnt; idx++)
81    {
82 #ifdef EGTP_TEST
83       ueCfg->entCfg[idx].rbId           = RB_ID;
84       ueCfg->entCfg[idx].rbType         = CM_LTE_DRB;
85       ueCfg->entCfg[idx].lCh[0].lChId   = LC_ID;
86       ueCfg->entCfg[idx].lCh[0].type    = CM_LTE_LCH_DTCH;
87 #endif
88       ueCfg->entCfg[idx].entMode        = CM_LTE_MODE_UM;
89       ueCfg->entCfg[idx].dir            = CKW_CFG_DIR_BOTH;
90       switch(ueCfg->entCfg[idx].entMode)
91       {
92          case CM_LTE_MODE_TM:
93             {
94                break;
95             }
96
97          case CM_LTE_MODE_UM:
98             {
99                ueCfg->entCfg[idx].m.umInfo.dl.snLen = 1;      /* For 12 bit SN */
100                ueCfg->entCfg[idx].m.umInfo.ul.snLen = 1;      /* For 12 bit SN */
101                ueCfg->entCfg[idx].m.umInfo.ul.reOrdTmr = 10;  /* in msec */
102                break;
103             }
104
105          case CM_LTE_MODE_AM:
106             {
107                break;
108             }
109
110          default:
111             break;
112       } /* End of switch(entMode) */
113    } /* End of entity configuration for loop */
114
115    /* Fill Pst */
116    pst.selector  = ODU_SELECTOR_LWLC;
117    pst.srcEnt    = ENTDUAPP;
118    pst.dstEnt    = ENTKW;
119    pst.dstInst   = RLC_UL_INST;
120    pst.dstProcId = DU_PROC;
121    pst.srcProcId = DU_PROC;
122    pst.region    = duCb.init.region;
123
124    /* Sending to RLC */
125    packUeCreateReq(&pst, ueCfg);
126
127    RETVALUE(ROK); 
128 } /* End of duSendUeCreateReqToRlc */
129
130 /*******************************************************************
131  *
132  * @brief Handles EGTP data from CU 
133  *
134  * @details
135  *
136  *    Function : duHdlEgtpData
137  *
138  *    Functionality: 
139  *      Processes EGTP header and sends data to RLC
140  *
141  * @params[in]  Pointer to EGTP Message 
142  * @return ROK     - success
143  *         RFAILED - failure
144  *
145  * ****************************************************************/
146 S16 duHdlEgtpDlData(EgtpMsg  *egtpMsg)
147 {
148    /* TODO : Extract RbId/UeID/CellID/SduId from database
149       using tunnel id in egtp header */
150
151    DU_LOG("\nDU_APP : Processing DL data");
152
153    Pst pst;
154    KwuDatReqInfo datReqInfo;
155
156 #ifdef EGTP_TEST
157    datReqInfo.rlcId.rbId = RB_ID;
158    datReqInfo.rlcId.rbType = CM_LTE_DRB;
159    datReqInfo.rlcId.ueId = UE_ID;
160    datReqInfo.rlcId.cellId = NR_CELL_ID;
161
162    datReqInfo.sduId = ++sduId;
163    datReqInfo.lcType = CM_LTE_LCH_DTCH;
164 #endif
165    /* Filling pst and Sending to RLC DL */
166    pst.selector  = ODU_SELECTOR_LWLC;
167    pst.srcEnt    = ENTDUAPP;
168    pst.dstEnt    = ENTKW;
169    pst.dstInst   = RLC_DL_INST;
170    pst.dstProcId = DU_PROC;
171    pst.srcProcId = DU_PROC;
172    pst.region    = duCb.init.region;
173
174    cmPkKwuDatReq(&pst, &datReqInfo, egtpMsg->msg);
175    return ROK;
176 }
177
178 /*******************************************************************
179  *
180  * @brief Handles UL data and send to CU
181  *
182  * @details
183  *
184  *    Function : duHdlRlcUlData
185  *
186  *    Functionality: 
187  *     Processes UL Data from RLC and sends to CU
188  * 
189  *  @params[in]  Pointer to EGTP Message 
190  *  @return ROK     - success
191  *          RFAILED - failure
192  * 
193  *****************************************************************/
194
195 PUBLIC S16 duHdlRlcUlData(Pst *pst, KwuDatIndInfo* datInd, Buffer *mBuf)
196 {
197    DU_LOG("\nDU_APP : Received UL Data at DU_APP");
198
199    /* Send UL data to CU via EGTP */
200    duSendEgtpDatInd(mBuf);
201    SPutMsg(mBuf);
202
203    return ROK;
204 }
205
206 /******************************************************************
207  *
208  * @brief Builds and Sends DL CCCH Ind to MAC
209  *
210  * @details
211  *
212  *    Function : duBuildAndSendDlCcchInd 
213  *
214  *    Functionality: Builds and sends DL CCCH Ind Msg to MAC
215  *
216  * @params[in] dlCcchMsg - uint8_t*
217  * @return ROK     - success
218  *         RFAILED - failure
219  *
220  * ****************************************************************/
221 uint8_t duBuildAndSendDlCcchInd(uint16_t cellId, uint16_t crnti, \
222       DlCcchMsgType msgType, uint8_t *dlCcchMsg, uint16_t dlCcchMsgSize)
223 {
224    uint8_t ret                  = ROK;
225    uint16_t idx2;
226    DlCcchIndInfo *dlCcchIndInfo = NULLP;
227    Pst pst;
228
229    memset(&pst, 0, sizeof(Pst));
230    DU_LOG("\nDU APP : Building and Sending DL CCCH Ind to MAC");
231
232    DU_ALLOC_SHRABL_BUF(dlCcchIndInfo, sizeof(DlCcchIndInfo));
233
234    if(!dlCcchIndInfo)
235    {
236       DU_LOG("\nDU APP : Memory alloc failed while building DL CCCH Ind");
237       return RFAILED;
238    }
239
240    dlCcchIndInfo->cellId = cellId;
241    dlCcchIndInfo->crnti = crnti;
242    dlCcchIndInfo->msgType = msgType;
243    dlCcchIndInfo->dlCcchMsgLen = dlCcchMsgSize;
244
245    DU_ALLOC_SHRABL_BUF(dlCcchIndInfo->dlCcchMsg, dlCcchIndInfo->dlCcchMsgLen);
246    if(!dlCcchIndInfo->dlCcchMsg)
247    {
248       DU_LOG("\nDU APP : Memory alloc failed while building DL CCCH Ind");
249       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo, sizeof(DlCcchIndInfo));
250       return RFAILED;
251    }
252    for(idx2 = 0; idx2 < dlCcchIndInfo->dlCcchMsgLen; idx2++)
253    {
254       dlCcchIndInfo->dlCcchMsg[idx2] = dlCcchMsg[idx2];
255    }
256    DU_FREE(dlCcchMsg, dlCcchMsgSize);
257
258    /* Fill Pst */
259    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_DL_CCCH_IND);
260    ret = (*packMacDlCcchIndOpts[pst.selector])(&pst, dlCcchIndInfo);
261    if(ret != ROK)
262    {
263       DU_LOG("\nDU_APP : Failure in sending DL CCCH to MAC");
264       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo->dlCcchMsg,\
265             dlCcchIndInfo->dlCcchMsgLen);
266       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo, \
267             sizeof(DlCcchIndInfo));
268       ret = RFAILED; 
269    }
270
271    return ret;
272
273 }
274
275 /******************************************************************
276  *
277  * @brief Processes DL RRC Message Transfer  sent by CU
278  *
279  * @details
280  *
281  *    Function : procDlRrcMsgTrans 
282  *
283  *    Functionality: Processes DL RRC Message Transfer sent by CU
284  *
285  * @params[in] F1AP_PDU_t ASN decoded F1AP message
286  * @return ROK     - success
287  *         RFAILED - failure
288  *
289  * ****************************************************************/
290 uint8_t procDlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
291 {
292    DLRRCMessageTransfer_t *dlRrcMsg = NULLP;
293    uint8_t                *dlCcchMsg = NULLP;
294    uint8_t                idx, ret, srbId;
295    uint16_t               idx2, crnti, cellId, dlCcchMsgSize;
296    uint32_t               gnbCuUeF1apId, gnbDuUeF1apId;
297
298
299    DU_LOG("\nDU_APP : DL RRC message transfer Recevied");
300    dlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
301
302    ret = ROK;
303
304    for(idx=0; idx<dlRrcMsg->protocolIEs.list.count; idx++)
305    {
306       switch(dlRrcMsg->protocolIEs.list.array[idx]->id)
307       {
308          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
309             {
310                gnbCuUeF1apId = dlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
311                break;
312             }
313          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
314             {
315                gnbDuUeF1apId = dlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
316                break;
317             }
318          case ProtocolIE_ID_id_SRBID:
319             {
320                srbId = dlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
321                break;
322             }
323          case ProtocolIE_ID_id_ExecuteDuplication:
324             break;
325
326          case ProtocolIE_ID_id_RRCContainer:
327             {
328                if(dlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
329                {
330                   dlCcchMsgSize = dlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
331                   DU_ALLOC(dlCcchMsg, dlCcchMsgSize);
332                   for(idx2 = 0; idx2 < dlCcchMsgSize; idx2++)
333                   {
334                      dlCcchMsg[idx2] = \
335                         dlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf[idx2];
336                   }
337                }
338                else
339                {
340                   DU_LOG("\nDU_APP : RRC Container Size is invalid:%ld",\
341                         dlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
342                }
343                break;
344             }
345
346          default:
347             DU_LOG("\nDU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
348                   dlRrcMsg->protocolIEs.list.array[idx]->id);
349       }
350    }
351
352    for(idx=0; idx<duCb.numUe; idx++)
353    {
354       if(gnbDuUeF1apId == duCb.ueCcchCtxt[idx].gnbDuUeF1apId)
355       {
356          crnti  = duCb.ueCcchCtxt[idx].crnti;
357          cellId = duCb.ueCcchCtxt[idx].cellId;
358          break;
359       }
360    }
361    if(srbId == SRB_ID_1) //RRC connection setup
362    {
363       ret = duBuildAndSendDlCcchInd(cellId, crnti, RRC_SETUP, dlCcchMsg, dlCcchMsgSize);
364       if(ret)
365       {
366          DU_LOG("\nDU_APP: Falied at duBuildAndSendDlCcchInd()");
367       }
368       else
369       {
370          if(duCb.actvCellLst[cellId-1]->numActvUes < MAX_NUM_UE)
371          {
372             ret = duCreateUeCb(&duCb.ueCcchCtxt[idx], gnbCuUeF1apId);
373             if(ret)
374             {
375                DU_LOG("\nDU_APP: Failed at duCreateUeCb for cellId [%d]", duCb.ueCcchCtxt[idx].cellId);
376                ret = RFAILED;
377             }
378          }
379          else
380          {
381             DU_LOG("\nDU_APP: Max Active UEs has reached");
382             ret = RFAILED;
383          }
384       }
385    }            
386    return ret;
387 }
388
389 /******************************************************************
390  *
391  * @brief Generates GNB DU Ue F1AP ID
392  *
393  * @details
394  *
395  *    Function : genGnbDuUeF1apId
396  *
397  *    Functionality: Generates GNB DU Ue F1AP ID
398  *
399  * @params[in] void
400  * @return gnbDuF1apId
401  *
402  * ****************************************************************/
403 uint32_t genGnbDuUeF1apId()
404 {
405    static uint32_t gnbDuUeF1apId = 0;
406
407    return ++gnbDuUeF1apId;
408 }
409
410 /******************************************************************
411  *
412  * @brief Processes UL CCCH Ind recvd from MAC
413  *
414  * @details
415  *
416  *    Function : duProcUlCcchInd
417  *
418  *    Functionality: Processes UL CCCH Ind recvd from MAC
419  *
420  * @params[in] UlCcchIndInfo *ulCcchIndInfo
421  * @return ROK     - success
422  *         RFAILED - failure
423  *
424  * ****************************************************************/
425 uint8_t duProcUlCcchInd(UlCcchIndInfo *ulCcchIndInfo)
426 {
427
428    uint8_t ret = ROK;
429    uint32_t gnbDuUeF1apId = 0;
430
431    gnbDuUeF1apId = genGnbDuUeF1apId();
432
433    /* Store Ue mapping */
434    duCb.ueCcchCtxt[duCb.numUe].gnbDuUeF1apId = gnbDuUeF1apId;
435    duCb.ueCcchCtxt[duCb.numUe].crnti         = ulCcchIndInfo->crnti;
436    duCb.ueCcchCtxt[duCb.numUe].cellId        = ulCcchIndInfo->cellId;
437
438    duCb.numUe++;
439
440    ret = (BuildAndSendInitialRrcMsgTransfer(gnbDuUeF1apId, ulCcchIndInfo->crnti,
441             ulCcchIndInfo->ulCcchMsg));
442    if(ret != ROK)
443    {
444       DU_LOG("\nDU_APP : BuildAndSendInitialRrcMsgTransfer failed");
445    }
446
447    DU_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, strlen((const char*)ulCcchIndInfo->ulCcchMsg));
448    DU_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
449
450    return ret;
451
452 }
453
454 /******************************************************************
455  *
456  * @brief Fills Initial DL Bandwidth Part
457  *
458  * @details
459  *
460  *    Function : fillInitDlBwp
461  *
462  *    Functionality: Fills Initial DL Bandwidth Part
463  *
464  *
465  *****************************************************************/
466 void fillInitDlBwp(InitialDlBwp *initDlBwp)
467 {
468    uint8_t idx = 0;
469
470    if(initDlBwp)
471    {
472       /* Filling PDCCH Config */
473       initDlBwp->pdcchPresent = TRUE;
474       if(initDlBwp->pdcchPresent)
475       {
476          initDlBwp->pdcchCfg.numCRsetToAddMod = PDCCH_CTRL_RSRC_SET_ONE_ID;
477          memset(initDlBwp->pdcchCfg.cRSetToAddModList, 0, MAX_NUM_CRSET);
478          if(initDlBwp->pdcchCfg.numCRsetToAddMod <= MAX_NUM_CRSET)
479          {
480             initDlBwp->pdcchCfg.cRSetToAddModList[idx].cRSetId = \
481                PDCCH_CTRL_RSRC_SET_ONE_ID;
482             memset(initDlBwp->pdcchCfg.cRSetToAddModList[idx].freqDomainRsrc, 0,\
483                FREQ_DOM_RSRC_SIZE); 
484             initDlBwp->pdcchCfg.cRSetToAddModList[idx].freqDomainRsrc[idx] =\
485                PDCCH_FREQ_DOM_RSRC;
486             initDlBwp->pdcchCfg.cRSetToAddModList[idx].duration = \
487                PDCCH_CTRL_RSRC_SET_ONE_DURATION;
488             initDlBwp->pdcchCfg.cRSetToAddModList[idx].cceRegMappingType = \
489                CCE_REG_MAPPINGTYPE_PR_NONINTERLEAVED;
490             initDlBwp->pdcchCfg.cRSetToAddModList[idx].precoderGranularity = \
491                ALL_CONTIGUOUS_RBS;
492             initDlBwp->pdcchCfg.cRSetToAddModList[idx].dmrsScramblingId = \
493                SCRAMBLING_ID;
494          }
495          initDlBwp->pdcchCfg.numCRsetToRel = 0;
496          /* Filling Serach Space */
497          initDlBwp->pdcchCfg.numSearchSpcToAddMod = PDCCH_CTRL_RSRC_SET_ONE_ID;
498          memset(initDlBwp->pdcchCfg.searchSpcToAddModList, 0, MAX_NUM_CRSET);
499          if(initDlBwp->pdcchCfg.numSearchSpcToAddMod <= MAX_NUM_CRSET)
500          {
501             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].searchSpaceId =\
502                PDCCH_SRCH_SPC_TWO_ID;
503             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].cRSetId = \
504                PDCCH_CTRL_RSRC_SET_ONE_ID;
505             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].\
506                mSlotPeriodicityAndOffset = SLOTPERIODICITYANDOFFSET_PR_SL1;
507             memset(initDlBwp->pdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot, 0,\
508                MONITORING_SYMB_WITHIN_SLOT_SIZE);
509             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot[idx] =\
510                PDCCH_SYMBOL_WITHIN_SLOT;
511             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel1 =\
512                AGGREGATIONLEVEL_N8; 
513             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel2 =\
514                AGGREGATIONLEVEL_N8; 
515             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel4 =\
516                AGGREGATIONLEVEL_N4; 
517             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel8 =\
518                AGGREGATIONLEVEL_N2; 
519             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel16 =\
520                AGGREGATIONLEVEL_N1;
521             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].searchSpaceType = \
522                SEARCHSPACETYPE_PR_UE_SPECIFIC;
523             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].ueSpecificDciFormat =\
524                PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
525
526             initDlBwp->pdcchCfg.numSearchSpcToRel = 0;
527
528          }
529       }
530       /* Filling PDSCH Config */
531       initDlBwp->pdschPresent = TRUE;
532       if(initDlBwp->pdschPresent)
533       {
534          initDlBwp->pdschCfg.dmrsDlCfgForPdschMapTypeA.addPos = ADDITIONALPOSITION_POS0;
535          initDlBwp->pdschCfg.resourceAllocType = RESOURCEALLOCATION_TYPE1;
536          initDlBwp->pdschCfg.numTimeDomRsrcAlloc = 1;
537          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].mappingType = \
538             MAPPING_TYPEA;
539          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].startSymbol = PDSCH_START_SYMBOL; 
540          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].symbolLength = PDSCH_LENGTH_SYMBOL;
541          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].startSymbolAndLength = \
542             calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
543          initDlBwp->pdschCfg.rbgSize = RBG_SIZE_CONFIG1;
544          initDlBwp->pdschCfg.numCodeWordsSchByDci = CODEWORDS_SCHED_BY_DCI_N1;
545          initDlBwp->pdschCfg.bundlingType = TYPE_STATIC_BUNDLING;
546       }
547    }
548
549 }
550
551 /******************************************************************
552  *
553  * @brief Fills Initial UL Bandwidth Part
554  *
555  * @details
556  *
557  *    Function : fillInitUlBwp
558  *
559  *    Functionality: Fills Initial UL Bandwidth Part
560  *
561  *
562  *****************************************************************/
563 void fillInitUlBwp(InitialUlBwp *initUlBwp)
564 {
565    uint8_t idx;
566    if(initUlBwp)
567    {
568       initUlBwp->pucchPresent = FALSE;
569
570       /*Filling PUSCH Config */
571       initUlBwp->puschPresent = TRUE;
572       if(initUlBwp->puschPresent)
573       {
574          initUlBwp->puschCfg.dmrsUlCfgForPuschMapTypeA.addPos = ADDITIONALPOSITION_POS0; 
575          initUlBwp->puschCfg.dmrsUlCfgForPuschMapTypeA.transPrecodDisabled. \
576             scramblingId0 = SCRAMBLING_ID; 
577          initUlBwp->puschCfg.resourceAllocType = RESOURCEALLOCATION_TYPE1;
578          initUlBwp->puschCfg.numTimeDomRsrcAlloc = 1;
579          idx = 0;
580          if(initUlBwp->puschCfg.numTimeDomRsrcAlloc <= MAX_NUM_UL_ALLOC)
581          {
582             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].k2 = PUSCH_K2;
583             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].mappingType =\
584                MAPPING_TYPEA;
585             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbol = PUSCH_START_SYMBOL;
586             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].symbolLength = PUSCH_LENGTH_SYMBOL;
587             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbolAndLength =\
588                calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
589          }
590          initUlBwp->puschCfg.transformPrecoder = TRANSFORM_PRECODER_DISABLED;
591       }
592    }
593    else
594    {
595       DU_LOG("\n DUAPP: Memory is NULL of InitalUlBwp");
596    }
597
598 }
599 /******************************************************************
600  *
601  * @brief Fills SpCell Group Info
602  *
603  * @details
604  *
605  *    Function : fillSpCellGrpInfo
606  *
607  *    Functionality: Fills Sp Cell Group Info
608  *
609  *
610  *****************************************************************/
611 void fillSpCellGrpInfo(SpCellCfg *spCell)
612 {
613    if(spCell)
614    {
615       spCell->servCellIdx = SERV_CELL_IDX;
616       /* Filling Initial Dl Bwp */
617       fillInitDlBwp(&spCell->servCellCfg.initDlBwp);
618
619       spCell->servCellCfg.numDlBwpToAdd    = 0; 
620       spCell->servCellCfg.firstActvDlBwpId = ACTIVE_DL_BWP_ID;
621       spCell->servCellCfg.defaultDlBwpId   = ACTIVE_DL_BWP_ID;
622       spCell->servCellCfg.bwpInactivityTmr = NULLP;
623       spCell->servCellCfg.pdschServCellCfg.maxMimoLayers = NULLP;
624       spCell->servCellCfg.pdschServCellCfg.maxCodeBlkGrpPerTb = NULLP;
625       spCell->servCellCfg.pdschServCellCfg.codeBlkGrpFlushInd = NULLP;
626       spCell->servCellCfg.pdschServCellCfg.xOverhead = NULLP;
627       spCell->servCellCfg.pdschServCellCfg.numHarqProcForPdsch =\
628          NUM_HARQ_PROC_FOR_PDSCH_N_16;
629       /* Filling Initial UL Bwp*/
630       fillInitUlBwp(&spCell->servCellCfg.initUlBwp);
631       spCell->servCellCfg.numUlBwpToAdd     = 0; 
632       spCell->servCellCfg.firstActvUlBwpId  = ACTIVE_DL_BWP_ID; 
633    }
634    else
635    {
636       DU_LOG("\n DU_APP: Memory is NULL for SpCellGrp");
637    }
638 }
639
640 /******************************************************************
641  *
642  * @brief Fills Physical Cell Group Info
643  *
644  * @details
645  *
646  *    Function : fillPhyCellGrpInfo
647  *
648  *    Functionality: Fills Physical Cell Group Info
649  *
650  *
651  *****************************************************************/
652 void fillPhyCellGrpInfo(PhyCellGrpCfg *cellGrp)
653 {
654    if(cellGrp)
655    {
656       cellGrp->pdschHarqAckCodebook = PDSCH_HARQ_ACK_CODEBOOK_DYNAMIC;
657       cellGrp->pNrFr1 = P_NR_FR1;
658    }
659    else
660    {
661       DU_LOG("\nDUAPP: Memory is NULL for Physical Cell Group");
662    }
663 }
664
665 /******************************************************************
666  *
667  * @brief Fills Mac Cell Group Info
668  *
669  * @details
670  *
671  *    Function : fillMacCellGrpInfo
672  *
673  *    Functionality: Fills Mac Cell Group Info
674  *
675  *
676  *****************************************************************/
677 void fillMacCellGrpInfo(MacCellGrpCfg *cellGrp)
678 {
679    uint8_t idx;
680
681    if(cellGrp)
682    {
683       /* Filling Scheduling Request Config */
684       cellGrp->schReqCfg.addModListCount = 1;
685       if(cellGrp->schReqCfg.addModListCount <= MAX_NUM_SR_CFG_PER_CELL_GRP)
686       {
687          for(idx = 0; idx < cellGrp->schReqCfg.addModListCount; idx++)
688          {
689             cellGrp->schReqCfg.addModList[idx].schedReqId    = SCH_REQ_ID;
690             cellGrp->schReqCfg.addModList[idx].srProhibitTmr = SR_PROHIBIT_MS_32;
691             cellGrp->schReqCfg.addModList[idx].srTransMax    = SR_TRANS_MAX_N_16;
692          }
693       }
694       cellGrp->schReqCfg.relListCount = 0;
695
696       /* Filling Tag config */
697       cellGrp->tagCfg.addModListCount = 1;
698       if(cellGrp->tagCfg.addModListCount <= MAC_NUM_TAGS)
699       {
700          for(idx = 0; idx < cellGrp->tagCfg.addModListCount; idx++)
701          {
702             cellGrp->tagCfg.addModList[idx].tagId = TAG_ID;
703             cellGrp->tagCfg.addModList[idx].timeAlignTimer = TIME_ALIGNMENT_TIMER_INFINITY;
704          }
705       }
706       cellGrp->tagCfg.relListCount = 0;
707
708       /* Filling BSR config */
709       cellGrp->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR;
710       cellGrp->bsrTmrCfg.retxTimer = RETX_BSR_TMR;
711       cellGrp->bsrTmrCfg.srDelayTimer = SR_DELAY_TMR;
712
713       /* Filling PHR config */
714       cellGrp->phrCfgSetupPres = true;
715       cellGrp->phrCfg.periodicTimer = PHR_PERIODIC_TIMER_INFINITY;
716       cellGrp->phrCfg.prohibitTimer = PHR_PROHIBIT_TIMER_SF_0;
717       cellGrp->phrCfg.txPowerFactor = PHR_TX_PWR_FACTOR_CHANGE_INFINITY;
718       cellGrp->phrCfg.multiplePHR   = false;
719       cellGrp->phrCfg.dummy         = false;
720       cellGrp->phrCfg.phrType2OtherCell = false;
721       cellGrp->phrCfg.phrOtherCG = PHR_MODE_OTHER_CG_REAL;  
722
723    }
724    else
725    {
726       DU_LOG("\nDUAPP: Memory is NULL for Master Cell Group");
727    }
728 }
729
730 /******************************************************************
731  *
732  * @brief Fills Logical Channel Config List
733  *
734  * @details
735  *
736  *    Function : fillLcCfgList
737  *
738  *    Functionality: Fills Logical channel Config List
739  *
740  *
741  *****************************************************************/
742 void fillLcCfgList(LcCfg *lcCfgInfo)
743 {
744    if(lcCfgInfo)
745    {
746       lcCfgInfo->lcId = SRB_ID_1;
747       lcCfgInfo->drbQos = NULLP;
748       lcCfgInfo->snssai = NULLP;
749       lcCfgInfo->ulLcCfg = NULLP;
750       lcCfgInfo->dlLcCfg.lcp = LC_PRIORITY_1;
751
752 #if 0
753       /* TODO: To be filled on receving UE CONTEXT SETUP from CU */
754       /* Filling Qos characteristics */
755       lcCfgInfo->drbQos.fiveQiType = QoS_Characteristics_PR_non_Dynamic_5QI;
756       lcCfgInfo->drbQos.u.nonDyn5Qi.fiveQi = 0;
757       lcCfgInfo->drbQos.u.nonDyn5Qi.priorLevel = 0;
758       lcCfgInfo->drbQos.u.nonDyn5Qi.avgWindow = 0;
759       lcCfgInfo->drbQos.u.nonDyn5Qi.maxDataBurstVol = 0;
760
761       /* Filling NgRAN */
762       lcCfgInfo->drbQos.ngRanRetPri.priorityLevel = PriorityLevel_highest;
763       lcCfgInfo->drbQos.ngRanRetPri.preEmptionCap = \
764                                                     Pre_emptionCapability_may_trigger_pre_emption;
765       lcCfgInfo->drbQos.ngRanRetPri.preEmptionVul = \
766                                                     Pre_emptionVulnerability_not_pre_emptable;
767
768       /* Filling Grb Qos */
769       lcCfgInfo->drbQos.grbQosInfo.maxFlowBitRateDl  = 0;
770       lcCfgInfo->drbQos.grbQosInfo.maxFlowBitRateUl  = 0;
771       lcCfgInfo->drbQos.grbQosInfo.guarFlowBitRateDl = 0;
772       lcCfgInfo->drbQos.grbQosInfo.guarFlowBitRateUl = 0;
773
774       /* Filling S-NSSAI */
775       /* TODO :To be filled when UE Context Setup Request is sent from CU */
776       /* Filling UL Logical Channel Config */
777       lcCfgInfo->ulLcCfg.priority = 0;
778       lcCfgInfo->ulLcCfg.lcGroup  = 0;
779       lcCfgInfo->ulLcCfg.schReqId = 0;
780       lcCfgInfo->ulLcCfg.pbr = 0;
781       lcCfgInfo->ulLcCfg.bsd = 0;
782
783       /* Filling DL Logical Channel Config */
784       lcCfgInfo->dlLcCfg.lcp = 0;
785 #endif
786    }
787    else
788    {
789       DU_LOG("\n Memory is null for LcCfgList");
790    }
791 }
792
793 /******************************************************************
794  *
795  * @brief Fills MacUeCfg structure
796  *
797  * @details
798  *
799  *    Function : fillMacUeCfg
800  *
801  *    Functionality: Fills MacUeCfg
802  *
803  *
804  *****************************************************************/
805 void fillMacUeCfg(MacUeCfg *ueCfg)
806 {
807    uint8_t idx;
808
809    /* Filling MacCellGroup Config */ 
810    fillMacCellGrpInfo(&ueCfg->macCellGrpCfg);
811    /* Filling PhyCellGroup Config */ 
812    fillPhyCellGrpInfo(&ueCfg->phyCellGrpCfg);
813    /* Filling SpCellGroup Config */ 
814    fillSpCellGrpInfo(&ueCfg->spCellCfg);
815    /* Filling AMBR for UL and DL */ 
816    ueCfg->maxAggrBitRate = NULLP;
817    /* Filling LC Context */
818    ueCfg->numLcs = SRB_ID_1;
819    if(ueCfg->numLcs < MAX_NUM_LOGICAL_CHANNELS)
820    {
821       for(idx = 0; idx < ueCfg->numLcs; idx++)
822       {   
823          fillLcCfgList(&ueCfg->lcCfgList[idx]);
824       }
825    }
826
827 }
828
829 /******************************************************************
830  *
831  * @brief creates UE context
832  *
833  * @details
834  *
835  *    Function : duCreateUeCb
836  *
837  *    Functionality: Creates UE Conetxt
838  *
839  * @params[in] UeCcchCtxt Pointer
840  *             UeIdx Pointer
841  *
842  * @return ROK     - success
843  *         RFAILED - failure
844  * ****************************************************************/
845 uint8_t duCreateUeCb(UeCcchCtxt *ueCcchCtxt, uint32_t gnbCuUeF1apId)
846 {
847    uint8_t cellIdx = 0;
848    uint8_t ret     = ROK;
849    uint8_t ueIdx;
850
851    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
852    {
853       if(ueCcchCtxt->cellId == duCb.actvCellLst[cellIdx]->cellId)
854       {
855          GET_UE_IDX(ueCcchCtxt->crnti, ueIdx);
856          DU_LOG("\nDU_APP: Filling UeCb for ueIdx [%d]", ueIdx);
857
858          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId = ueCcchCtxt->gnbDuUeF1apId;
859          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId = gnbCuUeF1apId;
860          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState       = UE_ACTIVE;
861
862          /* Filling Mac Ue Config */ 
863          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg, 0, sizeof(MacUeCfg));
864          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg.cellId        = ueCcchCtxt->cellId;
865          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg.ueIdx         = ueIdx;
866          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg.crnti         = ueCcchCtxt->crnti;
867          fillMacUeCfg(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg);
868          duCb.actvCellLst[cellIdx]->numActvUes++;
869          memset(ueCcchCtxt, 0, sizeof(UeCcchCtxt));
870
871          /* Send Ue Create Request to MAC */
872          ret = duBuildAndSendUeCreateReqToMac(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg.cellId, ueIdx);
873          if(ret)
874             DU_LOG("\nDU_APP: Failed to send UE create request to MAC");
875       }
876    }
877
878    return ret;
879 }
880
881 /******************************************************************
882  *
883  * @brief Builds and Send UE Create Request to MAC
884  *
885  * @details
886  *
887  *    Function : duBuildAndSendUeCreateReqToMac
888  *
889  *    Functionality: Builds and Send UE Create Request to MAC
890  *
891  * @Params[in]  cellId,
892  *              ueIdx
893  * @return ROK     - success
894  *         RFAILED - failure
895  *
896  * ****************************************************************/
897
898 uint8_t duBuildAndSendUeCreateReqToMac(uint16_t cellId, uint8_t ueIdx)
899 {
900    uint8_t ret = ROK;
901    MacUeCfg *macUeCfg = NULLP;
902    Pst pst;
903
904    memset(&pst, 0, sizeof(Pst));
905
906    /* Fill Pst */
907    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_CREATE_REQ);
908
909    /* Copying ueCb to a sharable buffer */
910    DU_ALLOC_SHRABL_BUF(macUeCfg, sizeof(MacUeCfg));
911    if(macUeCfg)
912    {
913       memset(macUeCfg, 0, sizeof(MacUeCfg));
914       memcpy(macUeCfg, &duCb.actvCellLst[cellId - 1]->ueCb[ueIdx].macUeCfg, sizeof(MacUeCfg));
915       /* Processing one Ue at a time to MAC */
916       ret = (*packMacUeCreateReqOpts[pst.selector])(&pst, macUeCfg);
917       if(ret)
918       {
919          DU_LOG("\nDU_APP : Failure in sending Ue Create Req to MAC");
920          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macUeCfg, sizeof(MacUeCfg));
921          ret = RFAILED;
922       }
923    }
924    else
925    {
926       DU_LOG("\n DU_APP: Memory alloc failed at duBuildAndSendUeCreateReq()");
927       ret = RFAILED;
928    }
929    return ret;
930 }
931
932 /*******************************************************************
933  *
934  * @brief Handle UE create response from MAC
935  *
936  * @details
937  *
938  *    Function : duHandleMacUeCreateRsp
939  *
940  *    Functionality: Handle UE create response from MAC
941  *
942  * @params[in] 
943  * @return ROK     - success
944  *         RFAILED - failure
945  *
946  * ****************************************************************/
947 uint8_t duHandleMacUeCreateRsp(Pst *pst, MacUeCfgRsp *cfgRsp)
948 {
949    if(cfgRsp->result == MAC_DU_APP_RSP_OK)
950    {
951       DU_LOG("\nDU APP : MAC UE Create Response : SUCCESS [UE IDX : %d]", cfgRsp->ueIdx);
952    }
953    else
954    {
955       DU_LOG("\nDU APP : MAC UE Create Response : FAILURE [UE IDX : %d]", cfgRsp->ueIdx);
956    }
957    return ROK;
958 }
959
960 /**********************************************************************
961   End of file
962  ***********************************************************************/