Ue Create Request from DU_APP to MAC
[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 "du_ue_mgr.h"
20
21 #ifdef EGTP_TEST
22 U32 sduId = 0;
23 #endif
24
25 DuMacDlCcchInd packMacDlCcchIndOpts[] =
26 {
27    packMacDlCcchInd,   /* Loose coupling */
28    MacHdlDlCcchInd,    /* TIght coupling */
29    packMacDlCcchInd    /* Light weight-loose coupling */
30 };
31
32 DuMacUeCreateReq packMacUeCreateReqOpts[] =
33 {
34    packDuMacUeCreateReq,       /* Loose coupling */
35    MacHdlUeCreateReq,          /* TIght coupling */
36    packDuMacUeCreateReq,       /* Light weight-loose coupling */
37 };
38
39 /******************************************************************
40  *
41  * @brief Send UE configuration to RLC
42  *
43  * @details
44  *
45  *    Function : duSendUeCreateReqToRlc
46  *
47  *    Functionality: Send UeCreateReqToRlc
48  *
49  * @return ROK     - success
50  *         RFAILED - failure
51  *
52  * ****************************************************************/
53 S16 duSendUeCreateReqToRlc()
54 {
55    U8  idx;
56    Pst pst;
57    CkwCfgInfo *ueCfg;
58    
59    DU_SET_ZERO(&ueCfg, sizeof(ueCfg));
60    DU_SET_ZERO(&pst, sizeof(Pst));
61
62    DU_ALLOC(ueCfg, sizeof(CkwCfgInfo));
63
64 #ifdef EGTP_TEST
65    ueCfg->ueId = UE_ID;
66 #endif
67    ueCfg->cellId = NR_CELL_ID;
68    ueCfg->numEnt = 1;
69    
70    for(idx = 0; idx < ueCfg->numEnt; idx++)
71    {
72 #ifdef EGTP_TEST
73       ueCfg->entCfg[idx].rbId           = RB_ID;
74       ueCfg->entCfg[idx].rbType         = CM_LTE_DRB;
75       ueCfg->entCfg[idx].lCh[0].lChId   = LC_ID;
76       ueCfg->entCfg[idx].lCh[0].type    = CM_LTE_LCH_DTCH;
77 #endif
78       ueCfg->entCfg[idx].entMode        = CM_LTE_MODE_UM;
79       ueCfg->entCfg[idx].dir            = CKW_CFG_DIR_BOTH;
80       switch(ueCfg->entCfg[idx].entMode)
81       {
82          case CM_LTE_MODE_TM:
83          {
84             break;
85          }
86
87          case CM_LTE_MODE_UM:
88          {
89             ueCfg->entCfg[idx].m.umInfo.dl.snLen = 1;      /* For 12 bit SN */
90             ueCfg->entCfg[idx].m.umInfo.ul.snLen = 1;      /* For 12 bit SN */
91             ueCfg->entCfg[idx].m.umInfo.ul.reOrdTmr = 10;  /* in msec */
92             break;
93          }
94
95          case CM_LTE_MODE_AM:
96          {
97             break;
98          }
99          
100          default:
101             break;
102       } /* End of switch(entMode) */
103    } /* End of entity configuration for loop */
104
105    /* Fill Pst */
106    pst.selector  = DU_SELECTOR_LWLC;
107    pst.srcEnt    = ENTDUAPP;
108    pst.dstEnt    = ENTKW;
109    pst.dstInst   = RLC_UL_INST;
110    pst.dstProcId = DU_PROC;
111    pst.srcProcId = DU_PROC;
112    pst.region    = duCb.init.region;
113
114    /* Sending to RLC */
115    packUeCreateReq(&pst, ueCfg);
116
117    RETVALUE(ROK); 
118 } /* End of duSendUeCreateReqToRlc */
119
120 /*******************************************************************
121  *
122  * @brief Handles EGTP data from CU 
123  *
124  * @details
125  *
126  *    Function : duHdlEgtpData
127  *
128  *    Functionality: 
129  *      Processes EGTP header and sends data to RLC
130  *
131  * @params[in]  Pointer to EGTP Message 
132  * @return ROK     - success
133  *         RFAILED - failure
134  *
135  * ****************************************************************/
136 S16 duHdlEgtpDlData(EgtpMsg  *egtpMsg)
137 {
138    /* TODO : Extract RbId/UeID/CellID/SduId from database
139       using tunnel id in egtp header */
140    
141    DU_LOG("\nDU_APP : Processing DL data");
142    
143    Pst pst;
144    KwuDatReqInfo datReqInfo;
145
146 #ifdef EGTP_TEST
147    datReqInfo.rlcId.rbId = RB_ID;
148    datReqInfo.rlcId.rbType = CM_LTE_DRB;
149    datReqInfo.rlcId.ueId = UE_ID;
150    datReqInfo.rlcId.cellId = NR_CELL_ID;
151    
152    datReqInfo.sduId = ++sduId;
153    datReqInfo.lcType = CM_LTE_LCH_DTCH;
154 #endif
155    /* Filling pst and Sending to RLC DL */
156    pst.selector  = DU_SELECTOR_LWLC;
157    pst.srcEnt    = ENTDUAPP;
158    pst.dstEnt    = ENTKW;
159    pst.dstInst   = RLC_DL_INST;
160    pst.dstProcId = DU_PROC;
161    pst.srcProcId = DU_PROC;
162    pst.region    = duCb.init.region;
163
164    cmPkKwuDatReq(&pst, &datReqInfo, egtpMsg->msg);
165    return ROK;
166 }
167
168 /*******************************************************************
169  *
170  * @brief Handles UL data and send to CU
171  *
172  * @details
173  *
174  *    Function : duHdlRlcUlData
175  *
176  *    Functionality: 
177  *     Processes UL Data from RLC and sends to CU
178  * 
179  *  @params[in]  Pointer to EGTP Message 
180  *  @return ROK     - success
181  *          RFAILED - failure
182  * 
183  *****************************************************************/
184
185 PUBLIC S16 duHdlRlcUlData(Pst *pst, KwuDatIndInfo* datInd, Buffer *mBuf)
186 {
187    DU_LOG("\nDU_APP : Received UL Data at DU_APP");
188  
189    /* Send UL data to CU via EGTP */
190    duSendEgtpDatInd(mBuf);
191    SPutMsg(mBuf);
192
193    return ROK;
194 }
195
196 /******************************************************************
197 *
198 * @brief Builds and Sends DL CCCH Ind to MAC
199 *
200 * @details
201 *
202 *    Function : duBuildAndSendDlCcchInd 
203 *
204 *    Functionality: Builds and sends DL CCCH Ind Msg to MAC
205 *
206 * @params[in] dlCcchMsg - uint8_t*
207 * @return ROK     - success
208 *         RFAILED - failure
209 *
210 * ****************************************************************/
211 uint8_t duBuildAndSendDlCcchInd(uint16_t cellId, uint16_t crnti, \
212   DlCcchMsgType msgType, uint8_t *dlCcchMsg, uint16_t dlCcchMsgSize)
213 {
214         uint8_t ret                  = ROK;
215         uint16_t idx2;
216    DlCcchIndInfo *dlCcchIndInfo = NULLP;
217    Pst pst;
218    
219         memset(&pst, 0, sizeof(Pst));
220    DU_LOG("\nDU APP : Building and Sending DL CCCH Ind to MAC");
221
222         DU_ALLOC_SHRABL_BUF(dlCcchIndInfo, sizeof(DlCcchIndInfo));
223
224    if(!dlCcchIndInfo)
225    {
226                 DU_LOG("\nDU APP : Memory alloc failed while building DL CCCH Ind");
227                 return RFAILED;
228         }
229
230         dlCcchIndInfo->cellId = cellId;
231         dlCcchIndInfo->crnti = crnti;
232         dlCcchIndInfo->msgType = msgType;
233         dlCcchIndInfo->dlCcchMsgLen = dlCcchMsgSize;
234
235         DU_ALLOC_SHRABL_BUF(dlCcchIndInfo->dlCcchMsg, dlCcchIndInfo->dlCcchMsgLen);
236         if(!dlCcchIndInfo->dlCcchMsg)
237    {
238                 DU_LOG("\nDU APP : Memory alloc failed while building DL CCCH Ind");
239                 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo, sizeof(DlCcchIndInfo));
240                 return RFAILED;
241         }
242         for(idx2 = 0; idx2 < dlCcchIndInfo->dlCcchMsgLen; idx2++)
243         {
244            dlCcchIndInfo->dlCcchMsg[idx2] = dlCcchMsg[idx2];
245         }
246         DU_FREE(dlCcchMsg, dlCcchMsgSize);
247
248         /* Fill Pst */
249         pst.selector  = DU_MAC_LWLC;
250         pst.srcEnt    = ENTDUAPP;
251         pst.dstEnt    = ENTRG;
252         pst.dstInst   = 0;
253         pst.srcInst   = 0;
254         pst.dstProcId = DU_PROC;
255         pst.srcProcId = DU_PROC;
256         pst.region    = DU_APP_MEM_REGION;
257         pst.pool      = DU_POOL;
258         pst.event     = EVENT_MAC_DL_CCCH_IND;
259
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 < DU_MAX_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, RG_POOL, ulCcchIndInfo->ulCcchMsg, strlen((const char*)ulCcchIndInfo->ulCcchMsg));
448    DU_FREE_SHRABL_BUF(MAC_MEM_REGION, RG_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].startSymbolAndLength = \
540           PDSCH_START_SYMBOL_LEN;
541          initDlBwp->pdschCfg.rbgSize = RBG_SIZE_CONFIG1;
542          initDlBwp->pdschCfg.numCodeWordsSchByDci = CODEWORDS_SCHED_BY_DCI_N1;
543          initDlBwp->pdschCfg.bundlingType = TYPE_STATIC_BUNDLING;
544                 }
545    }
546
547 }
548
549 /******************************************************************
550  *
551  * @brief Fills Initial UL Bandwidth Part
552  *
553  * @details
554  *
555  *    Function : fillInitUlBwp
556  *
557  *    Functionality: Fills Initial UL Bandwidth Part
558  *
559  *
560  *****************************************************************/
561 void fillInitUlBwp(InitialUlBwp *initUlBwp)
562 {
563    uint8_t idx;
564    if(initUlBwp)
565    {
566       initUlBwp->pucchPresent = FALSE;
567
568       /*Filling PUSCH Config */
569       initUlBwp->puschPresent = TRUE;
570                 if(initUlBwp->puschPresent)
571                 {
572          initUlBwp->puschCfg.dmrsUlCfgForPuschMapTypeA.addPos = ADDITIONALPOSITION_POS0; 
573          initUlBwp->puschCfg.dmrsUlCfgForPuschMapTypeA.transPrecodDisabled. \
574            scramblingId0 = SCRAMBLING_ID; 
575          initUlBwp->puschCfg.resourceAllocType = RESOURCEALLOCATION_TYPE1;
576          initUlBwp->puschCfg.numTimeDomRsrcAlloc = 1;
577          idx = 0;
578          if(initUlBwp->puschCfg.numTimeDomRsrcAlloc <= MAX_NUM_UL_ALLOC)
579          {
580             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].k2 = PUSCH_K2;
581             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].mappingType =\
582               MAPPING_TYPEA;
583             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbolAndLength =\
584               PUSCH_START_SYMBOL_LEN;
585          }
586          initUlBwp->puschCfg.transformPrecoder = TRANSFORM_PRECODER_DISABLED;
587                 }
588    }
589    else
590    {
591       DU_LOG("\n DUAPP: Memory is NULL of InitalUlBwp");
592    }
593
594 }
595 /******************************************************************
596  *
597  * @brief Fills SpCell Group Info
598  *
599  * @details
600  *
601  *    Function : fillSpCellGrpInfo
602  *
603  *    Functionality: Fills Sp Cell Group Info
604  *
605  *
606  *****************************************************************/
607 void fillSpCellGrpInfo(SpCellCfg *spCell)
608 {
609    if(spCell)
610    {
611       spCell->servCellIdx = SERV_CELL_IDX;
612       /* Filling Initial Dl Bwp */
613       fillInitDlBwp(&spCell->servCellCfg.initDlBwp);
614
615       spCell->servCellCfg.numDlBwpToAdd    = 0; 
616       spCell->servCellCfg.firstActvDlBwpId = ACTIVE_DL_BWP_ID;
617       spCell->servCellCfg.defaultDlBwpId   = ACTIVE_DL_BWP_ID;
618       spCell->servCellCfg.bwpInactivityTmr = NULLP;
619       spCell->servCellCfg.pdschServCellCfg.maxMimoLayers = NULLP;
620       spCell->servCellCfg.pdschServCellCfg.maxCodeBlkGrpPerTb = NULLP;
621       spCell->servCellCfg.pdschServCellCfg.codeBlkGrpFlushInd = NULLP;
622       spCell->servCellCfg.pdschServCellCfg.xOverhead = NULLP;
623       spCell->servCellCfg.pdschServCellCfg.numHarqProcForPdsch =\
624            NUM_HARQ_PROC_FOR_PDSCH_N_16;
625       /* Filling Initial UL Bwp*/
626       fillInitUlBwp(&spCell->servCellCfg.initUlBwp);
627       spCell->servCellCfg.numUlBwpToAdd     = 0; 
628       spCell->servCellCfg.firstActvUlBwpId  = ACTIVE_DL_BWP_ID; 
629    }
630    else
631    {
632       DU_LOG("\n DU_APP: Memory is NULL for SpCellGrp");
633    }
634 }
635
636 /******************************************************************
637  *
638  * @brief Fills Physical Cell Group Info
639  *
640  * @details
641  *
642  *    Function : fillPhyCellGrpInfo
643  *
644  *    Functionality: Fills Physical Cell Group Info
645  *
646  *
647  *****************************************************************/
648 void fillPhyCellGrpInfo(PhyCellGrpCfg *cellGrp)
649 {
650    if(cellGrp)
651    {
652       cellGrp->pdschHarqAckCodebook = PDSCH_HARQ_ACK_CODEBOOK_DYNAMIC;
653       cellGrp->pNrFr1 = P_NR_FR1;
654    }
655    else
656    {
657       DU_LOG("\nDUAPP: Memory is NULL for Physical Cell Group");
658    }
659 }
660
661 /******************************************************************
662  *
663  * @brief Fills Mac Cell Group Info
664  *
665  * @details
666  *
667  *    Function : fillMacCellGrpInfo
668  *
669  *    Functionality: Fills Mac Cell Group Info
670  *
671  *
672  *****************************************************************/
673 void fillMacCellGrpInfo(MacCellGrpCfg *cellGrp)
674 {
675    uint8_t idx;
676
677    if(cellGrp)
678    {
679       /* Filling Scheduling Request Config */
680       cellGrp->schReqCfg.addModListCount = 1;
681       if(cellGrp->schReqCfg.addModListCount <= MAX_NUM_SR_CFG_PER_CELL_GRP)
682       {
683          for(idx = 0; idx < cellGrp->schReqCfg.addModListCount; idx++)
684          {
685             cellGrp->schReqCfg.addModList[idx].schedReqId    = SCH_REQ_ID;
686             cellGrp->schReqCfg.addModList[idx].srProhibitTmr = SR_PROHIBIT_MS_32;
687             cellGrp->schReqCfg.addModList[idx].srTransMax    = SR_TRANS_MAX_N_16;
688          }
689       }
690       cellGrp->schReqCfg.relListCount = 0;
691
692       /* Filling Tag config */
693       cellGrp->tagCfg.addModListCount = 1;
694       if(cellGrp->tagCfg.addModListCount <= MAC_NUM_TAGS)
695       {
696          for(idx = 0; idx < cellGrp->tagCfg.addModListCount; idx++)
697          {
698             cellGrp->tagCfg.addModList[idx].tagId = TAG_ID;
699             cellGrp->tagCfg.addModList[idx].timeAlignTimer = TIME_ALIGNMENT_TIMER_INFINITY;
700          }
701       }
702       cellGrp->tagCfg.relListCount = 0;
703       
704       /* Filling PHR config */
705       cellGrp->phrCfgSetupPres = true;
706       cellGrp->phrCfg.periodicTimer = PHR_PERIODIC_TIMER_INFINITY;
707       cellGrp->phrCfg.prohibitTimer = PHR_PROHIBIT_TIMER_SF_0;
708       cellGrp->phrCfg.txPowerFactor = PHR_TX_PWR_FACTOR_CHANGE_INFINITY;
709       cellGrp->phrCfg.multiplePHR   = false;
710       cellGrp->phrCfg.dummy         = false;
711       cellGrp->phrCfg.phrType2OtherCell = false;
712       cellGrp->phrCfg.phrOtherCG = PHR_MODE_OTHER_CG_REAL;  
713
714    }
715    else
716    {
717       DU_LOG("\nDUAPP: Memory is NULL for Master Cell Group");
718    }
719 }
720
721 /******************************************************************
722  *
723  * @brief Fills Logical Channel Config List
724  *
725  * @details
726  *
727  *    Function : fillLcCfgList
728  *
729  *    Functionality: Fills Logical channel Config List
730  *
731  *
732  *****************************************************************/
733 void fillLcCfgList(LcCfg *lcCfgInfo)
734 {
735    if(lcCfgInfo)
736    {
737       lcCfgInfo->lcId = SRB_ID_1;
738       lcCfgInfo->drbQos = NULLP;
739       lcCfgInfo->snssai = NULLP;
740       lcCfgInfo->ulLcCfg = NULLP;
741       lcCfgInfo->dlLcCfg.lcp = LC_PRIORITY_1;
742       
743 #if 0
744       /* TODO: To be filled on receving UE CONTEXT SETUP from CU */
745       /* Filling Qos characteristics */
746       lcCfgInfo->drbQos.fiveQiType = QoS_Characteristics_PR_non_Dynamic_5QI;
747       lcCfgInfo->drbQos.u.nonDyn5Qi.fiveQi = 0;
748       lcCfgInfo->drbQos.u.nonDyn5Qi.priorLevel = 0;
749       lcCfgInfo->drbQos.u.nonDyn5Qi.avgWindow = 0;
750       lcCfgInfo->drbQos.u.nonDyn5Qi.maxDataBurstVol = 0;
751
752       /* Filling NgRAN */
753       lcCfgInfo->drbQos.ngRanRetPri.priorityLevel = PriorityLevel_highest;
754       lcCfgInfo->drbQos.ngRanRetPri.preEmptionCap = \
755        Pre_emptionCapability_may_trigger_pre_emption;
756       lcCfgInfo->drbQos.ngRanRetPri.preEmptionVul = \
757        Pre_emptionVulnerability_not_pre_emptable;
758
759       /* Filling Grb Qos */
760       lcCfgInfo->drbQos.grbQosInfo.maxFlowBitRateDl  = 0;
761       lcCfgInfo->drbQos.grbQosInfo.maxFlowBitRateUl  = 0;
762       lcCfgInfo->drbQos.grbQosInfo.guarFlowBitRateDl = 0;
763       lcCfgInfo->drbQos.grbQosInfo.guarFlowBitRateUl = 0;
764       
765       /* Filling S-NSSAI */
766       /* TODO :To be filled when UE Context Setup Request is sent from CU */
767       /* Filling UL Logical Channel Config */
768       lcCfgInfo->ulLcCfg.priority = 0;
769       lcCfgInfo->ulLcCfg.lcGroup  = 0;
770       lcCfgInfo->ulLcCfg.schReqId = 0;
771       lcCfgInfo->ulLcCfg.pbr = 0;
772       lcCfgInfo->ulLcCfg.bsd = 0;
773         
774       /* Filling DL Logical Channel Config */
775       lcCfgInfo->dlLcCfg.lcp = 0;
776 #endif
777    }
778    else
779    {
780       DU_LOG("\n Memory is null for LcCfgList");
781    }
782 }
783
784 /******************************************************************
785  *
786  * @brief Fills MacUeCfg structure
787  *
788  * @details
789  *
790  *    Function : fillMacUeCfg
791  *
792  *    Functionality: Fills MacUeCfg
793  *
794  *
795  *****************************************************************/
796 void fillMacUeCfg(MacUeCfg *ueCfg)
797 {
798    uint8_t idx;
799
800    /* Filling MacCellGroup Config */ 
801    fillMacCellGrpInfo(&ueCfg->macCellGrpCfg);
802    /* Filling PhyCellGroup Config */ 
803    fillPhyCellGrpInfo(&ueCfg->phyCellGrpCfg);
804    /* Filling SpCellGroup Config */ 
805    fillSpCellGrpInfo(&ueCfg->spCellCfg);
806    /* Filling AMBR for UL and DL */ 
807         ueCfg->maxAggrBitRate = NULLP;
808    /* Filling LC Context */
809    ueCfg->numLcs = SRB_ID_1;
810    if(ueCfg->numLcs < MAX_NUM_LOGICAL_CHANNELS)
811    {
812       for(idx = 0; idx < ueCfg->numLcs; idx++)
813       {   
814          fillLcCfgList(&ueCfg->lcCfgList[idx]);
815       }
816    }
817
818 }
819
820 /******************************************************************
821  *
822  * @brief creates UE context
823  *
824  * @details
825  *
826  *    Function : duCreateUeCb
827  *
828  *    Functionality: Creates UE Conetxt
829  *
830  * @params[in] UeCcchCtxt Pointer
831  *             UeIdx Pointer
832  *
833  * @return ROK     - success
834  *         RFAILED - failure
835  * ****************************************************************/
836 uint8_t duCreateUeCb(UeCcchCtxt *ueCcchCtxt, uint32_t gnbCuUeF1apId)
837 {
838         uint8_t cellIdx = 0;
839         uint8_t ret     = ROK;
840         uint8_t ueIdx;
841
842    for(cellIdx = 0; cellIdx < DU_MAX_CELLS; cellIdx++)
843         {
844            if(ueCcchCtxt->cellId == duCb.actvCellLst[cellIdx]->cellId)
845                 {
846                    ueIdx = ueCcchCtxt->crnti % DU_UE_START_CRNTI;
847          DU_LOG("\nDU_APP: Filling UeCb for ueIdx [%d]", ueIdx);
848                    duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId = ueCcchCtxt->gnbDuUeF1apId;
849                    duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId = gnbCuUeF1apId;
850          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState       = UE_ACTIVE;
851          
852                         /* Filling Mac Ue Config */ 
853          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg, 0, sizeof(MacUeCfg));
854          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg.cellIdx       = ueCcchCtxt->cellId;
855          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg.ueIdx         = ueIdx;
856          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg.crnti         = ueCcchCtxt->crnti;
857          fillMacUeCfg(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg);
858                    duCb.actvCellLst[cellIdx]->numActvUes++;
859                         memset(ueCcchCtxt, 0, sizeof(UeCcchCtxt));
860
861                         /* Send Ue Create Request to MAC */
862                         ret = duBuildAndSendUeCreateReqToMac(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].macUeCfg.cellIdx, ueIdx);
863                         if(ret)
864                            DU_LOG("\nDU_APP: Failed to send UE create request to MAC");
865                 }
866    }
867
868         return ret;
869 }
870
871 /******************************************************************
872  *
873  * @brief Builds and Send UE Create Request to MAC
874  *
875  * @details
876  *
877  *    Function : duBuildAndSendUeCreateReqToMac
878  *
879  *    Functionality: Builds and Send UE Create Request to MAC
880  *
881  * @Params[in]  cellId,
882  *              ueIdx
883  * @return ROK     - success
884  *         RFAILED - failure
885  *
886  * ****************************************************************/
887
888 uint8_t duBuildAndSendUeCreateReqToMac(uint16_t cellId, uint8_t ueIdx)
889 {
890    uint8_t ret = ROK;
891    MacUeCfg *macUeCfg = NULLP;
892    Pst pst;
893
894    memset(&pst, 0, sizeof(Pst));
895
896    /* Fill Pst */
897    pst.selector  = DU_MAC_LWLC;
898    pst.srcEnt    = ENTDUAPP;
899    pst.srcInst   = DU_INST;
900    pst.dstEnt    = ENTRG;
901    pst.dstInst   = 0;
902    pst.dstProcId = DU_PROC;
903    pst.srcProcId = DU_PROC;
904    pst.region    = DU_APP_MEM_REGION;
905    pst.pool      = DU_POOL;
906    pst.event     = EVENT_MAC_UE_CREATE_REQ;
907
908    /* Copying ueCb to a sharable buffer */
909    DU_ALLOC_SHRABL_BUF(macUeCfg, sizeof(MacUeCfg));
910         if(macUeCfg)
911         {
912                 memset(macUeCfg, 0, sizeof(MacUeCfg));
913       memcpy(macUeCfg, &duCb.actvCellLst[cellId - 1]->ueCb[ueIdx].macUeCfg, sizeof(MacUeCfg));
914       /* Processing one Ue at a time to MAC */
915                 ret = (*packMacUeCreateReqOpts[pst.selector])(&pst, macUeCfg);
916                 if(ret)
917                 {
918          DU_LOG("\nDU_APP : Failure in sending Ue Create Req to MAC");
919                    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macUeCfg, sizeof(MacUeCfg));
920                         ret = RFAILED;
921                 }
922         }
923         else
924         {
925            DU_LOG("\n DU_APP: Memory alloc failed at duBuildAndSendUeCreateReq()");
926                 ret = RFAILED;
927         }
928         return ret;
929 }
930
931 /**********************************************************************
932          End of file
933 ***********************************************************************/