DL RRC Message Transfer from DU APP to RLC [Issue-ID: ODUHIGH-45]
[o-du/l2.git] / src / du_app / du_ue_mgr.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17  *******************************************************************************/
18 /* This file contains UE management handling functionality for DU APP */
19 #include "common_def.h"
20 #include "lrg.h"
21 #include "lrg.x"
22 #include "ckw.h"
23 #include "ckw.x"
24 #include "kwu.h"
25 #include "kwu.x"
26 #include "lkw.h"
27 #include "lkw.x"
28 #include "legtp.h"
29 #include "du_app_mac_inf.h"
30 #include "du_app_rlc_inf.h"
31 #include "du_cfg.h"
32 #include "du_utils.h"
33 #include<ProtocolIE-Field.h>
34 #include "F1AP-PDU.h"
35 #include "du_mgr.h"
36 #include "du_f1ap_msg_hdl.h"
37 #include "du_ue_mgr.h"
38
39 #ifdef EGTP_TEST
40 U32 sduId = 0;
41 #endif
42
43 DuMacDlCcchInd packMacDlCcchIndOpts[] =
44 {
45    packMacDlCcchInd,   /* Loose coupling */
46    MacProcDlCcchInd,    /* TIght coupling */
47    packMacDlCcchInd    /* Light weight-loose coupling */
48 };
49
50 DuMacUeCreateReq packMacUeCreateReqOpts[] =
51 {
52    packDuMacUeCreateReq,       /* Loose coupling */
53    MacProcUeCreateReq,          /* TIght coupling */
54    packDuMacUeCreateReq,       /* Light weight-loose coupling */
55 };
56
57 DuRlcUlUeCreateReq packRlcUlUeCreateReqOpts[] =
58 {
59    packDuRlcUlUeCreateReq,       /* Loose coupling */
60    RlcUlProcUeCreateReq,          /* TIght coupling */
61    packDuRlcUlUeCreateReq,       /* Light weight-loose coupling */
62 };
63
64 DuDlRrcMsgToRlcFunc duSendDlRrcMsgToRlcOpts[] =
65 {
66    packDlRrcMsgToRlc,          /* Loose coupling */ 
67    RlcProcDlRrcMsgTransfer,       /* Tight coupling */
68    packDlRrcMsgToRlc           /* Light weight-loose coupling */
69 };
70
71 /*******************************************************************
72  *
73  * @brief Handles EGTP data from CU 
74  *
75  * @details
76  *
77  *    Function : duHdlEgtpData
78  *
79  *    Functionality: 
80  *      Processes EGTP header and sends data to RLC
81  *
82  * @params[in]  Pointer to EGTP Message 
83  * @return ROK     - success
84  *         RFAILED - failure
85  *
86  * ****************************************************************/
87 uint8_t duHdlEgtpDlData(EgtpMsg  *egtpMsg)
88 {
89
90    /* TODO : Extract RbId/UeID/CellID/SduId from database
91       using tunnel id in egtp header */
92
93    DU_LOG("\nDU_APP : Processing DL data");
94 #ifdef EGTP_TEST
95    Pst pst;
96    KwuDatReqInfo datReqInfo;
97
98    datReqInfo.rlcId.rbId = RB_ID;
99    datReqInfo.rlcId.rbType = CM_LTE_DRB;
100    datReqInfo.rlcId.ueId = UE_ID;
101    datReqInfo.rlcId.cellId = NR_CELL_ID;
102
103    datReqInfo.sduId = ++sduId;
104    datReqInfo.lcType = CM_LTE_LCH_DTCH;
105
106    /* Filling pst and Sending to RLC DL */
107    pst.selector  = ODU_SELECTOR_LWLC;
108    pst.srcEnt    = ENTDUAPP;
109    pst.dstEnt    = ENTRLC;
110    pst.dstInst   = RLC_DL_INST;
111    pst.dstProcId = DU_PROC;
112    pst.srcProcId = DU_PROC;
113    pst.region    = duCb.init.region;
114
115    cmPkKwuDatReq(&pst, &datReqInfo, egtpMsg->msg);
116 #else
117    //duBuildAndSendDlRrcMsgToRlc();
118 #endif
119    return ROK;
120 }
121
122 /*******************************************************************
123  *
124  * @brief Handles UL data and send to CU
125  *
126  * @details
127  *
128  *    Function : duHdlRlcUlData
129  *
130  *    Functionality: 
131  *     Processes UL Data from RLC and sends to CU
132  * 
133  *  @params[in]  Pointer to EGTP Message 
134  *  @return ROK     - success
135  *          RFAILED - failure
136  * 
137  *****************************************************************/
138
139 uint8_t duHdlRlcUlData(Pst *pst, KwuDatIndInfo* datInd, Buffer *mBuf)
140 {
141    DU_LOG("\nDU_APP : Received UL Data at DU_APP");
142
143    /* Send UL data to CU via EGTP */
144    duSendEgtpDatInd(mBuf);
145    ODU_PUT_MSG_BUF(mBuf);
146
147    return ROK;
148 }
149
150 /******************************************************************
151  *
152  * @brief Builds and Sends DL CCCH Ind to MAC
153  *
154  * @details
155  *
156  *    Function : duBuildAndSendDlCcchInd 
157  *
158  *    Functionality: Builds and sends DL CCCH Ind Msg to MAC
159  *
160  * @params[in] dlCcchMsg - uint8_t*
161  * @return ROK     - success
162  *         RFAILED - failure
163  *
164  * ****************************************************************/
165 uint8_t duBuildAndSendDlCcchInd(uint16_t *cellId, uint16_t *crnti, \
166       DlCcchMsgType msgType, uint8_t *dlCcchMsg, uint16_t dlCcchMsgSize)
167 {
168    uint8_t ret                  = ROK;
169    uint16_t idx2;
170    DlCcchIndInfo *dlCcchIndInfo = NULLP;
171    Pst pst;
172    memset(&pst, 0, sizeof(Pst));
173
174    DU_LOG("\nDU APP : Building and Sending DL CCCH Ind to MAC");
175
176    DU_ALLOC_SHRABL_BUF(dlCcchIndInfo, sizeof(DlCcchIndInfo));
177
178    if(!dlCcchIndInfo)
179    {
180       DU_LOG("\nDU APP : Memory alloc failed while building DL CCCH Ind");
181       return RFAILED;
182    }
183
184    dlCcchIndInfo->cellId = *cellId;
185    dlCcchIndInfo->crnti = *crnti;
186    dlCcchIndInfo->msgType = msgType;
187    dlCcchIndInfo->dlCcchMsgLen = dlCcchMsgSize;
188
189    DU_ALLOC_SHRABL_BUF(dlCcchIndInfo->dlCcchMsg, dlCcchIndInfo->dlCcchMsgLen);
190    if(!dlCcchIndInfo->dlCcchMsg)
191    {
192       DU_LOG("\nDU APP : Memory alloc failed while building DL CCCH Ind");
193       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo, sizeof(DlCcchIndInfo));
194       return RFAILED;
195    }
196    for(idx2 = 0; idx2 < dlCcchIndInfo->dlCcchMsgLen; idx2++)
197    {
198       dlCcchIndInfo->dlCcchMsg[idx2] = dlCcchMsg[idx2];
199    }
200    DU_FREE(dlCcchMsg, dlCcchMsgSize);
201
202    /* Fill Pst */
203    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_DL_CCCH_IND);
204    ret = (*packMacDlCcchIndOpts[pst.selector])(&pst, dlCcchIndInfo);
205    if(ret != ROK)
206    {
207       DU_LOG("\nDU_APP : Failure in sending DL CCCH to MAC");
208       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo->dlCcchMsg,\
209             dlCcchIndInfo->dlCcchMsgLen);
210       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo, \
211             sizeof(DlCcchIndInfo));
212       ret = RFAILED; 
213    }
214
215    return ret;
216
217 }
218
219 /*******************************************************************
220  *
221  * @brief Build and Send DL RRC Message transfer to RLC
222  *
223  * @details
224  *
225  *    Function : duBuildAndSendDlRrcMsgToRlc
226  *
227  *    Functionality:
228  *      Build and Send DL RRC Message transfer to RLC
229  *
230  * @params[in] Cell ID
231  *             UE Index
232  *             Logical Channgel ID
233  *             RRC Message
234  *             RRC Message Length
235  * @return ROK     - success
236  *         RFAILED - failure
237  *
238  * ****************************************************************/
239 uint8_t duBuildAndSendDlRrcMsgToRlc(uint16_t cellId, RlcUeCfg ueCfg, \
240    uint8_t lcId, bool deliveryStaReq, uint16_t rrcMsgLen, uint8_t *rrcMsg)
241 {
242    Pst  pst;
243    uint8_t ret;
244    uint8_t lcIdx;
245    RlcDlRrcMsgInfo  *dlRrcMsgInfo;
246
247    DU_ALLOC_SHRABL_BUF(dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
248    if(!dlRrcMsgInfo)
249    {
250       DU_LOG("\nDU APP : Memory allocation failed for dlRrcMsgInfo in \
251          duBuildAndSendDlRrcMsgToRlc");
252       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rrcMsg, rrcMsgLen);
253       return RFAILED;
254    }
255
256    /* Filling up the RRC msg info */
257    dlRrcMsgInfo->cellId = cellId;
258    dlRrcMsgInfo->ueIdx = ueCfg.ueIdx;
259    for(lcIdx = 0; lcIdx <= MAX_NUM_LOGICAL_CHANNELS; lcIdx++)
260    {
261       if(ueCfg.rlcBearerCfg[lcIdx].lcId == lcId)
262       {
263          dlRrcMsgInfo->rbType = ueCfg.rlcBearerCfg[lcIdx].rbType;
264          dlRrcMsgInfo->rbId = ueCfg.rlcBearerCfg[lcIdx].rbId;
265          dlRrcMsgInfo->lcType = ueCfg.rlcBearerCfg[lcIdx].lcType;
266          dlRrcMsgInfo->lcId = ueCfg.rlcBearerCfg[lcIdx].lcId;
267          break;
268       }
269    }
270    dlRrcMsgInfo->execDup = false;
271    dlRrcMsgInfo->deliveryStaRpt = deliveryStaReq;
272    dlRrcMsgInfo->rrcMsg = rrcMsg;
273    dlRrcMsgInfo->msgLen = rrcMsgLen;
274
275    /* Filling post structure and sending msg */ 
276    memset(&pst, 0, sizeof(Pst));
277    FILL_PST_DUAPP_TO_RLC(pst, RLC_DL_INST, EVENT_DL_RRC_MSG_TRANS_TO_RLC);
278    ret = (*duSendDlRrcMsgToRlcOpts[pst.selector])(&pst, dlRrcMsgInfo);
279    if(ret != ROK)
280    {
281       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rrcMsg, rrcMsgLen);
282       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
283       return RFAILED;
284    }
285
286    return ROK;
287
288
289 /*******************************************************************
290  *
291  * @brief Process UE context setup request from CU
292  *
293  * @details
294  *
295  *    Function : procUeCintextSetupReq
296  *
297  *    Functionality: Process UE context setup request from CU
298  *
299  * @params[in] F1AP message
300  * @return ROK     - success
301  *         RFAILED - failure
302  *
303  * ****************************************************************/
304 uint8_t procUeContextSetupReq(F1AP_PDU_t *f1apMsg)
305 {
306    uint8_t    ret = ROK;
307    uint8_t    ieIdx, byteIdx, ueIdx;
308    uint8_t    *rrcMsg = NULLP;
309    uint16_t   rrcMsgLen;
310    uint16_t   cellId, cellIdx;
311    uint32_t   gnbDuUeF1apId;    /* GNB DU UE F1AP ID */
312    uint32_t   gnbCuUeF1apId;    /* GNB CU UE F1AP ID */
313    bool       deliveryStaReq = false;   /* RRC msg delivery status request */
314    DuUeCb     *ueCb = NULLP;
315    UEContextSetupRequest_t   *ueSetReq = NULLP;
316   
317    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
318
319    /* TODO : fetch remaining values from f1ap msg */
320    for(ieIdx=0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
321    {
322       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
323       {
324          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
325             {
326                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
327                break;
328             }
329          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
330             {
331                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
332                break;
333             }
334          case ProtocolIE_ID_id_ServCellIndex:
335             {
336                cellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
337                break;
338             }
339          case ProtocolIE_ID_id_RRCContainer: 
340             {
341                rrcMsgLen = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size;
342                DU_ALLOC_SHRABL_BUF(rrcMsg, rrcMsgLen);
343                if(!rrcMsg)
344                {
345                   DU_LOG("\nDU APP : Memory allocation failed for RRC Msg in procUeCtxtSetupReq");
346                   return RFAILED;
347                }
348                memcpy(rrcMsg, ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
349                   rrcMsgLen);
350                break;
351             }
352          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
353             {
354                deliveryStaReq = true;          
355                break;
356             }
357          default:
358             {
359                break;
360             }
361       }
362    }
363
364    cellId = duCb.actvCellLst[cellIdx]->cellId;
365    for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
366    {
367       if((duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId) &&
368          (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId &&
369          duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState == UE_ACTIVE))
370       {
371          ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
372          break;
373       }
374    }
375
376    /* TODO :  send RB config to MAC/RLC */
377
378    /* Sending DL RRC Message to RLC */
379    if(ueIdx != MAX_NUM_UE)
380    {
381       ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->rlcUeCfg, SRB_ID_1, \
382                deliveryStaReq,  rrcMsgLen, rrcMsg); 
383    }
384    else
385    {
386       DU_LOG("\nDU APP : No UE found for CuUeF1apId[%d] and DuUeF1apId[%d]", \
387          gnbCuUeF1apId, gnbDuUeF1apId);
388       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rrcMsg, rrcMsgLen);
389       ret = RFAILED;
390    }
391
392    return ret;
393 }
394
395 /******************************************************************
396  *
397  * @brief Processes DL RRC Message Transfer  sent by CU
398  *
399  * @details
400  *
401  *    Function : procDlRrcMsgTrans 
402  *
403  *    Functionality: Processes DL RRC Message Transfer sent by CU
404  *
405  * @params[in] F1AP_PDU_t ASN decoded F1AP message
406  * @return ROK     - success
407  *         RFAILED - failure
408  *
409  * ****************************************************************/
410 uint8_t procDlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
411 {
412    DLRRCMessageTransfer_t *dlRrcMsg = NULLP;
413    uint8_t                *dlCcchMsg = NULLP;
414    uint8_t                idx, ret, srbId;
415    uint16_t               idx2, crnti, cellId, dlCcchMsgSize;
416    uint32_t               gnbCuUeF1apId, gnbDuUeF1apId;
417
418
419    DU_LOG("\nDU_APP : DL RRC message transfer Recevied");
420    dlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
421
422    ret = ROK;
423
424    for(idx=0; idx<dlRrcMsg->protocolIEs.list.count; idx++)
425    {
426       switch(dlRrcMsg->protocolIEs.list.array[idx]->id)
427       {
428          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
429             {
430                gnbCuUeF1apId = dlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
431                break;
432             }
433          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
434             {
435                gnbDuUeF1apId = dlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
436                break;
437             }
438          case ProtocolIE_ID_id_SRBID:
439             {
440                srbId = dlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
441                break;
442             }
443          case ProtocolIE_ID_id_ExecuteDuplication:
444             break;
445
446          case ProtocolIE_ID_id_RRCContainer:
447             {
448                if(dlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
449                {
450                   dlCcchMsgSize = dlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
451                   DU_ALLOC(dlCcchMsg, dlCcchMsgSize);
452                   for(idx2 = 0; idx2 < dlCcchMsgSize; idx2++)
453                   {
454                      dlCcchMsg[idx2] = \
455                         dlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf[idx2];
456                   }
457                }
458                else
459                {
460                   DU_LOG("\nDU_APP : RRC Container Size is invalid:%ld",\
461                         dlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
462                }
463                break;
464             }
465
466          default:
467             DU_LOG("\nDU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
468                   dlRrcMsg->protocolIEs.list.array[idx]->id);
469       }
470    }
471
472    for(idx=0; idx<duCb.numUe; idx++)
473    {
474       if(gnbDuUeF1apId == duCb.ueCcchCtxt[idx].gnbDuUeF1apId)
475       {
476          crnti  = duCb.ueCcchCtxt[idx].crnti;
477          cellId = duCb.ueCcchCtxt[idx].cellId;
478          break;
479       }
480    }
481    if(srbId == SRB_ID_1) //RRC connection setup
482    {
483       ret = duBuildAndSendDlCcchInd(&cellId, &crnti, RRC_SETUP, dlCcchMsg, dlCcchMsgSize);
484       if(ret)
485       {
486          DU_LOG("\nDU_APP: Falied at duBuildAndSendDlCcchInd()");
487       }
488       else
489       {
490          if(duCb.actvCellLst[cellId-1]->numActvUes < MAX_NUM_UE)
491          {
492             ret = duCreateUeCb(&duCb.ueCcchCtxt[idx], gnbCuUeF1apId);
493             if(ret)
494             {
495                DU_LOG("\nDU_APP: Failed at duCreateUeCb for cellId [%d]", duCb.ueCcchCtxt[idx].cellId);
496                ret = RFAILED;
497             }
498          }
499          else
500          {
501             DU_LOG("\nDU_APP: Max Active UEs has reached");
502             ret = RFAILED;
503          }
504       }
505    }            
506    return ret;
507 }
508
509 /******************************************************************
510  *
511  * @brief Generates GNB DU Ue F1AP ID
512  *
513  * @details
514  *
515  *    Function : genGnbDuUeF1apId
516  *
517  *    Functionality: Generates GNB DU Ue F1AP ID
518  *
519  * @params[in] void
520  * @return gnbDuF1apId
521  *
522  * ****************************************************************/
523 uint32_t genGnbDuUeF1apId()
524 {
525    static uint32_t gnbDuUeF1apId = 0;
526
527    return ++gnbDuUeF1apId;
528 }
529
530 /******************************************************************
531  *
532  * @brief Processes UL CCCH Ind recvd from MAC
533  *
534  * @details
535  *
536  *    Function : duProcUlCcchInd
537  *
538  *    Functionality: Processes UL CCCH Ind recvd from MAC
539  *
540  * @params[in] UlCcchIndInfo *ulCcchIndInfo
541  * @return ROK     - success
542  *         RFAILED - failure
543  *
544  * ****************************************************************/
545 uint8_t duProcUlCcchInd(UlCcchIndInfo *ulCcchIndInfo)
546 {
547
548    uint8_t ret = ROK;
549    uint32_t gnbDuUeF1apId = 0;
550
551    gnbDuUeF1apId = genGnbDuUeF1apId();
552
553    /* Store Ue mapping */
554    duCb.ueCcchCtxt[duCb.numUe].gnbDuUeF1apId = gnbDuUeF1apId;
555    duCb.ueCcchCtxt[duCb.numUe].crnti         = ulCcchIndInfo->crnti;
556    duCb.ueCcchCtxt[duCb.numUe].cellId        = ulCcchIndInfo->cellId;
557
558    duCb.numUe++;
559
560    ret = (BuildAndSendInitialRrcMsgTransfer(gnbDuUeF1apId, ulCcchIndInfo->crnti, ulCcchIndInfo->ulCcchMsgLen,
561             ulCcchIndInfo->ulCcchMsg));
562    if(ret != ROK)
563    {
564       DU_LOG("\nDU_APP : BuildAndSendInitialRrcMsgTransfer failed");
565    }
566
567    DU_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
568    DU_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
569
570    return ret;
571
572 }
573
574 /******************************************************************
575  *
576  * @brief Fills Initial DL Bandwidth Part
577  *
578  * @details
579  *
580  *    Function : fillInitDlBwp
581  *
582  *    Functionality: Fills Initial DL Bandwidth Part
583  *
584  *
585  *****************************************************************/
586 void fillInitDlBwp(InitialDlBwp *initDlBwp)
587 {
588    uint8_t idx = 0;
589    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
590    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
591
592
593    if(initDlBwp)
594    {
595       /* Filling PDCCH Config */
596       initDlBwp->pdcchPresent = TRUE;
597       if(initDlBwp->pdcchPresent)
598       {
599          initDlBwp->pdcchCfg.numCRsetToAddMod = PDCCH_CTRL_RSRC_SET_ONE_ID;
600          memset(initDlBwp->pdcchCfg.cRSetToAddModList, 0, MAX_NUM_CRSET);
601          if(initDlBwp->pdcchCfg.numCRsetToAddMod <= MAX_NUM_CRSET)
602          {
603             initDlBwp->pdcchCfg.cRSetToAddModList[idx].cRSetId = \
604                PDCCH_CTRL_RSRC_SET_ONE_ID;
605             memset(initDlBwp->pdcchCfg.cRSetToAddModList[idx].freqDomainRsrc, 0,\
606                FREQ_DOM_RSRC_SIZE); 
607             coreset0EndPrb = CORESET0_END_PRB;
608             coreset1StartPrb = coreset0EndPrb +6;
609             coreset1NumPrb = CORESET1_NUM_PRB;
610             /* calculate the PRBs */
611             schAllocFreqDomRscType0(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
612             memcpy(initDlBwp->pdcchCfg.cRSetToAddModList[idx].freqDomainRsrc, freqDomainResource,
613                FREQ_DOM_RSRC_SIZE);
614
615             initDlBwp->pdcchCfg.cRSetToAddModList[idx].duration = \
616                PDCCH_CTRL_RSRC_SET_ONE_DURATION;
617             initDlBwp->pdcchCfg.cRSetToAddModList[idx].cceRegMappingType = \
618                CCE_REG_MAPPINGTYPE_PR_NONINTERLEAVED;
619             initDlBwp->pdcchCfg.cRSetToAddModList[idx].precoderGranularity = \
620                ALL_CONTIGUOUS_RBS;
621             initDlBwp->pdcchCfg.cRSetToAddModList[idx].dmrsScramblingId = \
622                SCRAMBLING_ID;
623          }
624          initDlBwp->pdcchCfg.numCRsetToRel = 0;
625          /* Filling Serach Space */
626          initDlBwp->pdcchCfg.numSearchSpcToAddMod = PDCCH_CTRL_RSRC_SET_ONE_ID;
627          memset(initDlBwp->pdcchCfg.searchSpcToAddModList, 0, MAX_NUM_CRSET);
628          if(initDlBwp->pdcchCfg.numSearchSpcToAddMod <= MAX_NUM_CRSET)
629          {
630             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].searchSpaceId =\
631                PDCCH_SRCH_SPC_TWO_ID;
632             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].cRSetId = \
633                PDCCH_CTRL_RSRC_SET_ONE_ID;
634             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].\
635                mSlotPeriodicityAndOffset = SLOTPERIODICITYANDOFFSET_PR_SL1;
636             memset(initDlBwp->pdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot, 0,\
637                MONITORING_SYMB_WITHIN_SLOT_SIZE);
638             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot[idx] =\
639                PDCCH_SYMBOL_WITHIN_SLOT;
640             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel1 =\
641                AGGREGATIONLEVEL_N8; 
642             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel2 =\
643                AGGREGATIONLEVEL_N8; 
644             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel4 =\
645                AGGREGATIONLEVEL_N4; 
646             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel8 =\
647                AGGREGATIONLEVEL_N2; 
648             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel16 =\
649                AGGREGATIONLEVEL_N1;
650             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].searchSpaceType = \
651                SEARCHSPACETYPE_PR_UE_SPECIFIC;
652             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].ueSpecificDciFormat =\
653                PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
654
655             initDlBwp->pdcchCfg.numSearchSpcToRel = 0;
656
657          }
658       }
659       /* Filling PDSCH Config */
660       initDlBwp->pdschPresent = TRUE;
661       if(initDlBwp->pdschPresent)
662       {
663          initDlBwp->pdschCfg.dmrsDlCfgForPdschMapTypeA.addPos = ADDITIONALPOSITION_POS0;
664          initDlBwp->pdschCfg.resourceAllocType = RESOURCEALLOCATION_TYPE1;
665          initDlBwp->pdschCfg.numTimeDomRsrcAlloc = 1;
666          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].mappingType = \
667             MAPPING_TYPEA;
668          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].startSymbol = PDSCH_START_SYMBOL; 
669          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].symbolLength = PDSCH_LENGTH_SYMBOL;
670          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].startSymbolAndLength = \
671             calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
672          initDlBwp->pdschCfg.rbgSize = RBG_SIZE_CONFIG1;
673          initDlBwp->pdschCfg.numCodeWordsSchByDci = CODEWORDS_SCHED_BY_DCI_N1;
674          initDlBwp->pdschCfg.bundlingType = TYPE_STATIC_BUNDLING;
675       }
676    }
677
678 }
679
680 /******************************************************************
681  *
682  * @brief Fills Initial UL Bandwidth Part
683  *
684  * @details
685  *
686  *    Function : fillInitUlBwp
687  *
688  *    Functionality: Fills Initial UL Bandwidth Part
689  *
690  *
691  *****************************************************************/
692 void fillInitUlBwp(InitialUlBwp *initUlBwp)
693 {
694    uint8_t idx;
695    if(initUlBwp)
696    {
697       initUlBwp->pucchPresent = FALSE;
698
699       /*Filling PUSCH Config */
700       initUlBwp->puschPresent = TRUE;
701       if(initUlBwp->puschPresent)
702       {
703          initUlBwp->puschCfg.dmrsUlCfgForPuschMapTypeA.addPos = ADDITIONALPOSITION_POS0; 
704          initUlBwp->puschCfg.dmrsUlCfgForPuschMapTypeA.transPrecodDisabled. \
705             scramblingId0 = SCRAMBLING_ID; 
706          initUlBwp->puschCfg.resourceAllocType = RESOURCEALLOCATION_TYPE1;
707          initUlBwp->puschCfg.numTimeDomRsrcAlloc = 1;
708          idx = 0;
709          if(initUlBwp->puschCfg.numTimeDomRsrcAlloc <= MAX_NUM_UL_ALLOC)
710          {
711             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].k2 = PUSCH_K2;
712             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].mappingType =\
713                MAPPING_TYPEA;
714             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbol = PUSCH_START_SYMBOL;
715             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].symbolLength = PUSCH_LENGTH_SYMBOL;
716             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbolAndLength =\
717                calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
718          }
719          initUlBwp->puschCfg.transformPrecoder = TRANSFORM_PRECODER_DISABLED;
720       }
721    }
722    else
723    {
724       DU_LOG("\n DUAPP: Memory is NULL of InitalUlBwp");
725    }
726
727 }
728 /******************************************************************
729  *
730  * @brief Fills SpCell Group Info
731  *
732  * @details
733  *
734  *    Function : fillSpCellGrpInfo
735  *
736  *    Functionality: Fills Sp Cell Group Info
737  *
738  *
739  *****************************************************************/
740 void fillSpCellGrpInfo(SpCellCfg *spCell)
741 {
742    if(spCell)
743    {
744       spCell->servCellIdx = SERV_CELL_IDX;
745       /* Filling Initial Dl Bwp */
746       fillInitDlBwp(&spCell->servCellCfg.initDlBwp);
747
748       spCell->servCellCfg.numDlBwpToAdd    = 0; 
749       spCell->servCellCfg.firstActvDlBwpId = ACTIVE_DL_BWP_ID;
750       spCell->servCellCfg.defaultDlBwpId   = ACTIVE_DL_BWP_ID;
751       spCell->servCellCfg.bwpInactivityTmr = NULLP;
752       spCell->servCellCfg.pdschServCellCfg.maxMimoLayers = NULLP;
753       spCell->servCellCfg.pdschServCellCfg.maxCodeBlkGrpPerTb = NULLP;
754       spCell->servCellCfg.pdschServCellCfg.codeBlkGrpFlushInd = NULLP;
755       spCell->servCellCfg.pdschServCellCfg.xOverhead = NULLP;
756       spCell->servCellCfg.pdschServCellCfg.numHarqProcForPdsch =\
757          NUM_HARQ_PROC_FOR_PDSCH_N_16;
758       /* Filling Initial UL Bwp*/
759       fillInitUlBwp(&spCell->servCellCfg.initUlBwp);
760       spCell->servCellCfg.numUlBwpToAdd     = 0; 
761       spCell->servCellCfg.firstActvUlBwpId  = ACTIVE_DL_BWP_ID; 
762    }
763    else
764    {
765       DU_LOG("\n DU_APP: Memory is NULL for SpCellGrp");
766    }
767 }
768
769 /******************************************************************
770  *
771  * @brief Fills Physical Cell Group Info
772  *
773  * @details
774  *
775  *    Function : fillPhyCellGrpInfo
776  *
777  *    Functionality: Fills Physical Cell Group Info
778  *
779  *
780  *****************************************************************/
781 void fillPhyCellGrpInfo(PhyCellGrpCfg *cellGrp)
782 {
783    if(cellGrp)
784    {
785       cellGrp->pdschHarqAckCodebook = PDSCH_HARQ_ACK_CODEBOOK_DYNAMIC;
786       cellGrp->pNrFr1 = P_NR_FR1;
787    }
788    else
789    {
790       DU_LOG("\nDUAPP: Memory is NULL for Physical Cell Group");
791    }
792 }
793
794 /******************************************************************
795  *
796  * @brief Fills Mac Cell Group Info
797  *
798  * @details
799  *
800  *    Function : fillMacCellGrpInfo
801  *
802  *    Functionality: Fills Mac Cell Group Info
803  *
804  *
805  *****************************************************************/
806 void fillMacCellGrpInfo(MacCellGrpCfg *cellGrp)
807 {
808    uint8_t idx;
809
810    if(cellGrp)
811    {
812       /* Filling Scheduling Request Config */
813       cellGrp->schReqCfg.addModListCount = 1;
814       if(cellGrp->schReqCfg.addModListCount <= MAX_NUM_SR_CFG_PER_CELL_GRP)
815       {
816          for(idx = 0; idx < cellGrp->schReqCfg.addModListCount; idx++)
817          {
818             cellGrp->schReqCfg.addModList[idx].schedReqId    = SCH_REQ_ID;
819             cellGrp->schReqCfg.addModList[idx].srProhibitTmr = SR_PROHIBIT_MS_32;
820             cellGrp->schReqCfg.addModList[idx].srTransMax    = SR_TRANS_MAX_N_16;
821          }
822       }
823       cellGrp->schReqCfg.relListCount = 0;
824
825       /* Filling Tag config */
826       cellGrp->tagCfg.addModListCount = 1;
827       if(cellGrp->tagCfg.addModListCount <= MAC_NUM_TAGS)
828       {
829          for(idx = 0; idx < cellGrp->tagCfg.addModListCount; idx++)
830          {
831             cellGrp->tagCfg.addModList[idx].tagId = TAG_ID;
832             cellGrp->tagCfg.addModList[idx].timeAlignTimer = TIME_ALIGNMENT_TIMER_INFINITY;
833          }
834       }
835       cellGrp->tagCfg.relListCount = 0;
836
837       /* Filling BSR config */
838       cellGrp->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR;
839       cellGrp->bsrTmrCfg.retxTimer = RETX_BSR_TMR;
840       cellGrp->bsrTmrCfg.srDelayTimer = SR_DELAY_TMR;
841
842       /* Filling PHR config */
843       cellGrp->phrCfgSetupPres = true;
844       cellGrp->phrCfg.periodicTimer = PHR_PERIODIC_TIMER_INFINITY;
845       cellGrp->phrCfg.prohibitTimer = PHR_PROHIBIT_TIMER_SF_0;
846       cellGrp->phrCfg.txPowerFactor = PHR_TX_PWR_FACTOR_CHANGE_INFINITY;
847       cellGrp->phrCfg.multiplePHR   = false;
848       cellGrp->phrCfg.dummy         = false;
849       cellGrp->phrCfg.phrType2OtherCell = false;
850       cellGrp->phrCfg.phrOtherCG = PHR_MODE_OTHER_CG_REAL;  
851
852    }
853    else
854    {
855       DU_LOG("\nDUAPP: Memory is NULL for Master Cell Group");
856    }
857 }
858
859 /******************************************************************
860  *
861  * @brief Fills Logical Channel Config List
862  *
863  * @details
864  *
865  *    Function : fillLcCfgList
866  *
867  *    Functionality: Fills Logical channel Config List
868  *
869  *
870  *****************************************************************/
871 void fillLcCfgList(LcCfg *lcCfgInfo)
872 {
873    if(lcCfgInfo)
874    {
875       lcCfgInfo->lcId = SRB_ID_1;
876       lcCfgInfo->drbQos = NULLP;
877       lcCfgInfo->snssai = NULLP;
878       lcCfgInfo->ulLcCfg = NULLP;
879       lcCfgInfo->dlLcCfg.lcp = LC_PRIORITY_1;
880
881 #if 0
882       /* TODO: To be filled on receving UE CONTEXT SETUP from CU */
883       /* Filling Qos characteristics */
884       lcCfgInfo->drbQos.fiveQiType = QoS_Characteristics_PR_non_Dynamic_5QI;
885       lcCfgInfo->drbQos.u.nonDyn5Qi.fiveQi = 0;
886       lcCfgInfo->drbQos.u.nonDyn5Qi.priorLevel = 0;
887       lcCfgInfo->drbQos.u.nonDyn5Qi.avgWindow = 0;
888       lcCfgInfo->drbQos.u.nonDyn5Qi.maxDataBurstVol = 0;
889
890       /* Filling NgRAN */
891       lcCfgInfo->drbQos.ngRanRetPri.priorityLevel = PriorityLevel_highest;
892       lcCfgInfo->drbQos.ngRanRetPri.preEmptionCap = \
893                                                     Pre_emptionCapability_may_trigger_pre_emption;
894       lcCfgInfo->drbQos.ngRanRetPri.preEmptionVul = \
895                                                     Pre_emptionVulnerability_not_pre_emptable;
896
897       /* Filling Grb Qos */
898       lcCfgInfo->drbQos.grbQosInfo.maxFlowBitRateDl  = 0;
899       lcCfgInfo->drbQos.grbQosInfo.maxFlowBitRateUl  = 0;
900       lcCfgInfo->drbQos.grbQosInfo.guarFlowBitRateDl = 0;
901       lcCfgInfo->drbQos.grbQosInfo.guarFlowBitRateUl = 0;
902
903       /* Filling S-NSSAI */
904       /* TODO :To be filled when UE Context Setup Request is sent from CU */
905       /* Filling UL Logical Channel Config */
906       lcCfgInfo->ulLcCfg.priority = 0;
907       lcCfgInfo->ulLcCfg.lcGroup  = 0;
908       lcCfgInfo->ulLcCfg.schReqId = 0;
909       lcCfgInfo->ulLcCfg.pbr = 0;
910       lcCfgInfo->ulLcCfg.bsd = 0;
911
912       /* Filling DL Logical Channel Config */
913       lcCfgInfo->dlLcCfg.lcp = 0;
914 #endif
915    }
916    else
917    {
918       DU_LOG("\n Memory is null for LcCfgList");
919    }
920 }
921
922 /******************************************************************
923  *
924  * @brief Fills MacUeCfg structure
925  *
926  * @details
927  *
928  *    Function : fillMacUeCfg
929  *
930  *    Functionality: Fills MacUeCfg
931  *
932  *
933  *****************************************************************/
934 void fillMacUeCfg(uint16_t cellId, uint8_t ueIdx,\
935   uint16_t crnti, MacUeCfg *ueCfg)
936 {
937    uint8_t idx;
938    ueCfg->cellId       = cellId;
939    ueCfg->ueIdx        = ueIdx;
940    ueCfg->crnti        = crnti;
941    /* Filling MacCellGroup Config */ 
942    fillMacCellGrpInfo(&ueCfg->macCellGrpCfg);
943    /* Filling PhyCellGroup Config */ 
944    fillPhyCellGrpInfo(&ueCfg->phyCellGrpCfg);
945    /* Filling SpCellGroup Config */ 
946    fillSpCellGrpInfo(&ueCfg->spCellCfg);
947    /* Filling AMBR for UL and DL */ 
948    ueCfg->maxAggrBitRate = NULLP;
949    /* Filling LC Context */
950    ueCfg->numLcs = SRB_ID_1;
951    if(ueCfg->numLcs < MAX_NUM_LOGICAL_CHANNELS)
952    {
953       for(idx = 0; idx < ueCfg->numLcs; idx++)
954       {   
955          fillLcCfgList(&ueCfg->lcCfgList[idx]);
956       }
957    }
958
959 }
960
961 /******************************************************************
962  *
963  * @brief Fills Rlc AM Information
964  *
965  * @details
966  *
967  *    Function : fillAmInfo
968  *
969  *    Functionality: Fills Rlc AM Information
970  *
971  *
972  *****************************************************************/
973 void fillAmInfo(AmBearerCfg *amCfg)
974 {
975    /* DL AM */
976    amCfg->dlAmCfg.snLenDl     = AM_SIZE_12;
977    amCfg->dlAmCfg.pollRetxTmr = POLL_RETX_TMR_45MS;
978    amCfg->dlAmCfg.pollPdu     = POLL_PDU_TMR_INFINITY;
979    amCfg->dlAmCfg.pollByte    = POLL_BYTES_INFINITY;
980    amCfg->dlAmCfg.maxRetxTh   = RETX_TH_8;   
981  
982    /* UL AM */
983    amCfg->ulAmCfg.snLenUl     = AM_SIZE_12;
984    amCfg->ulAmCfg.reAssemTmr  = RE_ASM_40MS; 
985    amCfg->ulAmCfg.statProhTmr = PROH_35MS;
986
987 }
988
989 /******************************************************************
990  *
991  * @brief Fills RLC UM Bi Directional Information
992  *
993  * @details
994  *
995  *    Function : fillUmBiDirInfo
996  *
997  *    Functionality: Fills RLC UM Bi Directional Information
998  *
999  *
1000  *****************************************************************/
1001 void fillUmBiDirInfo(UmBiDirBearerCfg *umBiDirCfg)
1002 {
1003    /* UL UM BI DIR INFO */
1004    umBiDirCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1005    umBiDirCfg->ulUmCfg.reAssemTmr = RE_ASM_40MS;
1006
1007    /* DL UM BI DIR INFO */
1008    umBiDirCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
1009
1010 }
1011
1012 /******************************************************************
1013  *
1014  * @brief Fills RLC UM Uni Directional UL Information
1015  *
1016  * @details
1017  *
1018  *    Function : fillUmUniDirUlInfo
1019  *
1020  *    Functionality: Fills RLC UM Uni Directional Info
1021  *
1022  *
1023  *****************************************************************/
1024 void fillUmUniDirUlInfo(UmUniDirUlBearerCfg *umUniDirUlCfg)
1025 {
1026    umUniDirUlCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1027    umUniDirUlCfg->ulUmCfg.reAssemTmr = RE_ASM_40MS;
1028 }
1029
1030 /******************************************************************
1031  *
1032  * @brief Fills RLC UM Uni Directional DL Information
1033  *
1034  * @details
1035  *
1036  *    Function : fillUmUniDirDlInfo
1037  *
1038  *    Functionality: Fills RLC UM Uni Directional DL Info
1039  *
1040  *
1041  *****************************************************************/
1042 void fillUmUniDirDlInfo(UmUniDirDlBearerCfg *umUniDirDlCfg)
1043 {
1044    umUniDirDlCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
1045 }
1046
1047 /******************************************************************
1048  *
1049  * @brief Fills RlcBearerCfg structure
1050  *
1051  * @details
1052  *
1053  *    Function : fillRlcBearerCfg
1054  *
1055  *    Functionality: Fills Rlc Bearer Cfg
1056  *
1057  *
1058  *****************************************************************/
1059 void fillRlcBearerCfg(uint16_t cellId, uint8_t ueIdx, RlcUeCfg *ueCfg)
1060 {
1061    uint8_t idx;
1062    ueCfg->cellId       = cellId;
1063    ueCfg->ueIdx        = ueIdx;
1064    ueCfg->numLcs       = SRB_ID_1; 
1065
1066    for(idx = 0; idx < ueCfg->numLcs; idx++)
1067    {
1068       ueCfg->rlcBearerCfg[idx].rbId         = RB_ID_SRB;
1069       ueCfg->rlcBearerCfg[idx].rbType       = RB_TYPE_SRB;
1070       ueCfg->rlcBearerCfg[idx].lcId         = SRB_ID_1;
1071       ueCfg->rlcBearerCfg[idx].lcType       = LCH_DCCH;
1072       ueCfg->rlcBearerCfg[idx].rlcMode      = RLC_AM;
1073       switch(ueCfg->rlcBearerCfg[idx].rlcMode)
1074       {
1075          case RLC_AM:
1076             memset(&ueCfg->rlcBearerCfg[idx].u.amCfg, 0, sizeof(AmBearerCfg));
1077             fillAmInfo(&ueCfg->rlcBearerCfg[idx].u.amCfg);
1078             break;
1079          case RLC_UM_BI_DIRECTIONAL:
1080             memset(&ueCfg->rlcBearerCfg[idx].u.umBiDirCfg, 0, sizeof(UmBiDirBearerCfg));
1081             fillUmBiDirInfo(&ueCfg->rlcBearerCfg[idx].u.umBiDirCfg);
1082             break;
1083          case RLC_UM_UNI_DIRECTIONAL_UL:
1084             memset(&ueCfg->rlcBearerCfg[idx].u.umUniDirUlCfg, 0, sizeof(UmUniDirUlBearerCfg));
1085             fillUmUniDirUlInfo(&ueCfg->rlcBearerCfg[idx].u.umUniDirUlCfg);
1086             break;
1087          case RLC_UM_UNI_DIRECTIONAL_DL:
1088             memset(&ueCfg->rlcBearerCfg[idx].u.umUniDirDlCfg, 0, sizeof(UmUniDirDlBearerCfg));
1089             fillUmUniDirDlInfo(&ueCfg->rlcBearerCfg[idx].u.umUniDirDlCfg);
1090             break;
1091          default :
1092             DU_LOG("\nDU_APP: Rlc Mode invalid %d", ueCfg->rlcBearerCfg[idx].rlcMode);
1093             break;
1094       }
1095    }
1096 }
1097
1098 /******************************************************************
1099  *
1100  * @brief creates UE context
1101  *
1102  * @details
1103  *
1104  *    Function : duCreateUeCb
1105  *
1106  *    Functionality: Creates UE Conetxt
1107  *
1108  * @params[in] UeCcchCtxt Pointer
1109  *             UeIdx Pointer
1110  *
1111  * @return ROK     - success
1112  *         RFAILED - failure
1113  * ****************************************************************/
1114 uint8_t duCreateUeCb(UeCcchCtxt *ueCcchCtxt, uint32_t gnbCuUeF1apId)
1115 {
1116    uint8_t cellIdx = 0;
1117    uint8_t ret     = ROK;
1118    uint8_t ueIdx;
1119
1120    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
1121    {
1122       if(ueCcchCtxt->cellId == duCb.actvCellLst[cellIdx]->cellId)
1123       {
1124          GET_UE_IDX(ueCcchCtxt->crnti, ueIdx);
1125          DU_LOG("\nDU_APP: Filling UeCb for ueIdx [%d]", ueIdx);
1126
1127          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbDuUeF1apId = ueCcchCtxt->gnbDuUeF1apId;
1128          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbCuUeF1apId = gnbCuUeF1apId;
1129          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].ueState       = UE_ACTIVE;
1130
1131          /* Filling Mac Ue Config */ 
1132          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg, 0, sizeof(MacUeCfg));
1133          ret = duBuildAndSendUeCreateReqToMac(ueCcchCtxt->cellId, ueIdx, ueCcchCtxt->crnti,\
1134                 &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg);
1135          if(ret)
1136             DU_LOG("\nDU_APP: Failed to send UE create request to MAC");
1137          
1138          /* Filling Rlc Ue Config */
1139          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg, 0, sizeof(RlcUeCfg));
1140          ret = duBuildAndSendUeCreateReqToRlc(ueCcchCtxt->cellId, ueIdx, \
1141                 &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg);
1142          if(ret)
1143             DU_LOG("\nDU_APP: Failed to send UE create request to RLC");
1144
1145          duCb.actvCellLst[cellIdx]->numActvUes++;
1146          memset(ueCcchCtxt, 0, sizeof(UeCcchCtxt));
1147       }
1148    }
1149    return ret;
1150 }
1151
1152 /******************************************************************
1153  *
1154  * @brief Builds and Send UE Create Request to MAC
1155  *
1156  * @details
1157  *
1158  *    Function : duBuildAndSendUeCreateReqToMac
1159  *
1160  *    Functionality: Builds and Send UE Create Request to MAC
1161  *
1162  * @Params[in]  cellId,
1163  *              ueIdx
1164  * @return ROK     - success
1165  *         RFAILED - failure
1166  *
1167  * ****************************************************************/
1168
1169 uint8_t duBuildAndSendUeCreateReqToMac(uint16_t cellId, uint8_t ueIdx,\
1170    uint16_t crnti, MacUeCfg *duMacUeCfg)
1171 {
1172    uint8_t ret = ROK;
1173    MacUeCfg *macUeCfg = NULLP;
1174    Pst pst;
1175    memset(&pst, 0, sizeof(Pst));
1176
1177    fillMacUeCfg(cellId, ueIdx, crnti, duMacUeCfg);
1178
1179    /* Fill Pst */
1180    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_CREATE_REQ);
1181
1182    /* Copying ueCb to a sharable buffer */
1183    DU_ALLOC_SHRABL_BUF(macUeCfg, sizeof(MacUeCfg));
1184    if(macUeCfg)
1185    {
1186       memset(macUeCfg, 0, sizeof(MacUeCfg));
1187       memcpy(macUeCfg, &duCb.actvCellLst[cellId - 1]->ueCb[ueIdx -1].macUeCfg, sizeof(MacUeCfg));
1188       DU_LOG("\nDU_APP: Sending UE create request to MAC");
1189
1190       /* Processing one Ue at a time to MAC */
1191       ret = (*packMacUeCreateReqOpts[pst.selector])(&pst, macUeCfg);
1192       if(ret)
1193       {
1194          DU_LOG("\nDU_APP : Failure in sending Ue Create Req to MAC");
1195          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macUeCfg, sizeof(MacUeCfg));
1196          ret = RFAILED;
1197       }
1198    }
1199    else
1200    {
1201       DU_LOG("\n DU_APP: Memory alloc failed at duBuildAndSendUeCreateReqToMac()");
1202       ret = RFAILED;
1203    }
1204    return ret;
1205 }
1206
1207 /*******************************************************************
1208  *
1209  * @brief Handle UE create response from MAC
1210  *
1211  * @details
1212  *
1213  *    Function : DuHandleMacUeCreateRsp
1214  *
1215  *    Functionality: Handle UE create response from MAC
1216  *
1217  * @params[in] Pointer to MacUeCfgRsp and Pst 
1218  * @return ROK     - success
1219  *         RFAILED - failure
1220  *
1221  * ****************************************************************/
1222 uint8_t DuHandleMacUeCreateRsp(Pst *pst, MacUeCfgRsp *cfgRsp)
1223 {
1224    if(cfgRsp->result == MAC_DU_APP_RSP_OK)
1225    {
1226       DU_LOG("\nDU APP : MAC UE Create Response : SUCCESS [UE IDX : %d]", cfgRsp->ueIdx);
1227    }
1228    else
1229    {
1230       DU_LOG("\nDU APP : MAC UE Create Response : FAILURE [UE IDX : %d]", cfgRsp->ueIdx);
1231    }
1232    return ROK;
1233 }
1234
1235 /*******************************************************************
1236  *
1237  * @brief Processes UE create Req to RLC UL
1238  *
1239  * @details
1240  *
1241  *    Function : duBuildAndSendUeCreateReqToRlc
1242  *
1243  *    Functionality: 
1244  *     Processes UE create Req to RLC UL
1245  * 
1246  *  @params[in]  cellId,
1247  *               ueIdx,
1248  *               Pointer to RlcUeCfg
1249  *  @return ROK     - success
1250  *          RFAILED - failure
1251  * 
1252  *****************************************************************/
1253
1254 uint8_t duBuildAndSendUeCreateReqToRlc(uint16_t cellId, uint8_t ueIdx, RlcUeCfg *duRlcUeCfg)
1255 {
1256    uint8_t ret = ROK;
1257    RlcUeCfg *rlcUeCfg = NULLP;
1258    Pst pst;
1259    memset(&pst, 0, sizeof(Pst));
1260   
1261    fillRlcBearerCfg(cellId, ueIdx, duRlcUeCfg);
1262    FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UL_UE_CREATE_REQ);
1263
1264    /* Copying ueCfg to a sharable buffer */
1265    DU_ALLOC_SHRABL_BUF(rlcUeCfg, sizeof(RlcUeCfg));
1266    if(rlcUeCfg)
1267    {
1268       memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
1269       memcpy(rlcUeCfg, duRlcUeCfg, sizeof(RlcUeCfg));
1270       /* Processing one Ue at a time to RLC */
1271       DU_LOG("\nDU_APP: Sending UE create request to RLC UL");
1272       ret = (*packRlcUlUeCreateReqOpts[pst.selector])(&pst, rlcUeCfg);
1273       if(ret)
1274       {
1275          DU_LOG("\nDU_APP : Failure in sending Ue Create Req to RLC");
1276          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rlcUeCfg, sizeof(RlcUeCfg));
1277          ret = RFAILED;
1278       }
1279    }
1280    else
1281    {
1282       DU_LOG("\n DU_APP: Memory alloc failed at duBuildAndSendUeCreateReqToRlc()");
1283       ret = RFAILED;
1284    }
1285    return ret;
1286 }
1287
1288
1289
1290 /*******************************************************************
1291  *
1292  * @brief Processes UE create Rsp received from RLC UL
1293  *
1294  * @details
1295  *
1296  *    Function : DuProcRlcUlUeCfgRsp
1297  *
1298  *    Functionality: 
1299  *     Processes UE create Rsp received from RLC UL
1300  * 
1301  *  @params[in]  Post structure
1302  *               Pointer to RlcCfgCfm
1303  *  @return ROK     - success
1304  *          RFAILED - failure
1305  * 
1306  *****************************************************************/
1307
1308 uint8_t DuProcRlcUlUeCreateRsp(Pst *pst, RlcUeCfgRsp *cfgRsp)
1309 {
1310    uint8_t ret = ROK;
1311
1312    if(cfgRsp)
1313    {
1314       if(cfgRsp->result == RLC_DU_APP_RSP_OK)
1315       {
1316          DU_LOG("\nDU_APP: RLC UE Create Response : SUCCESS [UE IDX:%d]", cfgRsp->ueIdx);
1317       }
1318       else
1319       {
1320          DU_LOG("\nDU_APP: RLC UE Create Response : FAILED [UE IDX:%d, REASON :%d]",\
1321             cfgRsp->ueIdx, cfgRsp->reason);
1322          ret = RFAILED;
1323       }
1324       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(RlcUeCfgRsp));
1325    }
1326    else
1327    {
1328       DU_LOG("\nDU_APP: Received RLC Ue Create Response is NULL");
1329       ret = RFAILED;
1330    }
1331    return ret;
1332 }
1333 /**********************************************************************
1334   End of file
1335  ***********************************************************************/