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