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