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