Fixes for memory optimization [JIRA ID - ODUHIGH-354]
[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 "du_mgr.h"
34 #include "du_f1ap_msg_hdl.h"
35 #include "du_ue_mgr.h"
36
37 #ifdef O1_ENABLE
38 #include "AlarmInterface.h"
39 #include "ConfigInterface.h"
40 #endif
41
42 DuMacDlCcchInd packMacDlCcchIndOpts[] =
43 {
44    packMacDlCcchInd,           /* Loose coupling */
45    MacProcDlCcchInd,           /* TIght coupling */
46    packMacDlCcchInd            /* Light weight-loose coupling */
47 };
48
49 DuMacUeCreateReq packMacUeCreateReqOpts[] =
50 {
51    packDuMacUeCreateReq,       /* Loose coupling */
52    MacProcUeCreateReq,         /* TIght coupling */
53    packDuMacUeCreateReq        /* Light weight-loose coupling */
54 };
55
56 DuRlcUeCreateReq packRlcUeCreateReqOpts[] =
57 {
58    packDuRlcUeCreateReq,       /* Loose coupling */
59    RlcProcUeCreateReq,         /* TIght coupling */
60    packDuRlcUeCreateReq        /* Light weight-loose coupling */
61 };
62
63 DuDlRrcMsgToRlcFunc duSendDlRrcMsgToRlcOpts[] =
64 {
65    packDlRrcMsgToRlc,          /* Loose coupling */ 
66    RlcProcDlRrcMsgTransfer,    /* Tight coupling */
67    packDlRrcMsgToRlc           /* Light weight-loose coupling */
68 };
69
70 DuRlcUeReconfigReq packRlcUeReconfigReqOpts[] =
71 {
72    packDuRlcUeReconfigReq,     /* Loose coupling */
73    RlcProcUeReconfigReq,       /* TIght coupling */
74    packDuRlcUeReconfigReq      /* Light weight-loose coupling */
75 };
76
77 DuMacUeReconfigReq packMacUeReconfigReqOpts[] =
78 {
79    packDuMacUeReconfigReq,     /* Loose coupling */
80    MacProcUeReconfigReq,       /* TIght coupling */
81    packDuMacUeReconfigReq      /* Light weight-loose coupling */
82 };
83
84 DuRlcDlUserDataToRlcFunc duSendRlcDlUserDataToRlcOpts[] =
85 {
86    packRlcDlUserDataToRlc,        /* Loose coupling */ 
87    RlcProcDlUserDataTransfer,  /* Tight coupling */
88    packRlcDlUserDataToRlc         /* Light weight-loose coupling */
89 };
90
91 DuMacUeDeleteReq packMacUeDeleteReqOpts[] =
92 {
93    packDuMacUeDeleteReq,       /* Loose coupling */
94    MacProcUeDeleteReq,         /* TIght coupling */
95    packDuMacUeDeleteReq        /* Light weight-loose coupling */
96 };
97
98 DuRlcUeDeleteReq packRlcUeDeleteReqOpts[] =
99 {
100    packDuRlcUeDeleteReq,       /* Loose coupling */
101    RlcProcUeDeleteReq,         /* TIght coupling */
102    packDuRlcUeDeleteReq        /* Light weight-loose coupling */
103 };
104
105 /*******************************************************************
106  *
107  * @brief Function to fillDlUserDataInfo
108  *
109  * @details
110  *
111  *    Function : fillDlUserDataInfo
112  *
113  *    Functionality:
114  *      Function to fillDlUserDataInfo
115  *
116  * @params[in] teId,
117  *             dlDataMsgInfo
118  *
119  * @return ROK     - success
120  *         RFAILED - failure
121  *
122  * ****************************************************************/
123
124 uint8_t fillDlUserDataInfo(uint32_t teId, RlcDlUserDataInfo *dlDataMsgInfo)
125 {
126    uint8_t drbIdx;
127
128    for(drbIdx = 0; drbIdx < duCb.numDrb; drbIdx++)
129    {
130       if(duCb.upTnlCfg[drbIdx] && (duCb.upTnlCfg[drbIdx]->tnlCfg1 != NULLP))
131       {
132         if(duCb.upTnlCfg[drbIdx]->tnlCfg1->teId == teId)
133         {
134            dlDataMsgInfo->cellId = duCb.upTnlCfg[drbIdx]->cellId;
135            dlDataMsgInfo->ueIdx = duCb.upTnlCfg[drbIdx]->ueIdx;
136            dlDataMsgInfo->rbId = duCb.upTnlCfg[drbIdx]->drbId;
137            return ROK;
138         }
139       }
140    }
141    return RFAILED;
142 }
143
144  /*******************************************************************
145  *
146  * @brief Build and Send DL Data Message transfer to RLC
147  *
148  * @details
149  *
150  *    Function : duBuildAndSendDlUserDataToRlc
151  *
152  *    Functionality:
153  *      Build and Send DL Data Message transfer to RLC
154  *
155  * @params[in] Cell ID
156  *             UE Index
157  *             Logical Channgel ID
158  *             RRC Message
159  *             RRC Message Length
160  * @return ROK     - success
161  *         RFAILED - failure
162  *
163  * ****************************************************************/
164
165 uint8_t duBuildAndSendDlUserDataToRlc(uint16_t msgLen, EgtpMsg *egtpMsg)
166 {
167    uint8_t ret = RFAILED;
168    Pst     pst;
169    RlcDlUserDataInfo *dlDataMsgInfo = NULLP;
170
171    DU_ALLOC_SHRABL_BUF(dlDataMsgInfo, sizeof(RlcDlUserDataInfo));
172    if(!dlDataMsgInfo)
173    {
174       DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed for dlDataMsgInfo in duHdlEgtpDlData()");
175       return RFAILED;
176    }
177    memset(dlDataMsgInfo, 0, sizeof(RlcDlUserDataInfo));
178    dlDataMsgInfo->dlMsg = egtpMsg->msg;
179    dlDataMsgInfo->msgLen = msgLen;
180
181    /* Filling DL DATA Msg Info */
182    if(fillDlUserDataInfo(egtpMsg->msgHdr.teId, dlDataMsgInfo) == ROK)
183    {
184       /* Filling post structure and sending msg */ 
185       FILL_PST_DUAPP_TO_RLC(pst, RLC_DL_INST, EVENT_DL_USER_DATA_TRANS_TO_RLC);
186       DU_LOG("\nDEBUG  -->  DU_APP : Sending User Data Msg to RLC \n");
187       ret = (*duSendRlcDlUserDataToRlcOpts[pst.selector])(&pst, dlDataMsgInfo);
188    }
189    if(ret != ROK)
190    {
191       DU_LOG("\nERROR  -->  DU_APP : Failed to send User Data to RLC in duHdlEgtpDlData()");
192       ODU_PUT_MSG_BUF(dlDataMsgInfo->dlMsg);
193       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlDataMsgInfo, sizeof(RlcDlUserDataInfo));
194    }
195    return ret;
196 }
197
198 /*******************************************************************
199  *
200  * @brief Handles EGTP data from CU 
201  *
202  * @details
203  *
204  *    Function : duHdlEgtpData
205  *
206  *    Functionality: 
207  *      Processes EGTP header and sends data to RLC
208  *
209  * @params[in]  Pointer to EGTP Message 
210  * @return ROK     - success
211  *         RFAILED - failure
212  *
213  * ****************************************************************/
214 uint8_t duHdlEgtpDlData(EgtpMsg  *egtpMsg)
215 {
216    uint16_t msgLen = 0;
217
218 #ifdef CALL_FLOW_DEBUG_LOG
219     DU_LOG("\nCall Flow: ENTEGTP -> ENTDUAPP : EVENT_HDL_RECV_DL_DATA\n");
220 #endif
221
222    DU_LOG("\nDEBUG  --> DU_APP : Processing DL data in duHdlEgtpDlData()");
223    
224    if(!egtpMsg->msg)
225    {
226       DU_LOG("\nERROR  -->  DU_APP : Recevied Dl Data is NULLP in duHdlEgtpDlData()");
227       return RFAILED;
228    }
229    ODU_GET_MSG_LEN(egtpMsg->msg, (MsgLen *)&msgLen);
230    if(duBuildAndSendDlUserDataToRlc(msgLen, egtpMsg) != ROK)
231    {
232       DU_LOG("\nERROR  -->  DU_APP : Failed to build DL USer Data in duHdlEgtpDlData()");
233       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, egtpMsg->msg, msgLen);
234       return RFAILED;
235    }
236    return ROK;
237 }
238
239 /******************************************************************
240  *
241  * @brief Builds and Sends DL CCCH Ind to MAC
242  *
243  * @details
244  *
245  *    Function : duBuildAndSendDlCcchInd 
246  *
247  *    Functionality: Builds and sends DL CCCH Ind Msg to MAC
248  *
249  * @params[in] dlCcchMsg - uint8_t*
250  * @return ROK     - success
251  *         RFAILED - failure
252  *
253  * ****************************************************************/
254 uint8_t duBuildAndSendDlCcchInd(uint16_t *cellId, uint16_t *crnti, \
255       DlCcchMsgType msgType, uint16_t dlCcchMsgSize, uint8_t *dlCcchMsg)
256 {
257    uint8_t  ret                  = ROK;
258    uint16_t idx2;
259    DlCcchIndInfo *dlCcchIndInfo = NULLP;
260    Pst pst;
261
262    DU_LOG("\nDEBUG   -->  DU APP : Building and Sending DL CCCH Ind to MAC");
263
264    DU_ALLOC_SHRABL_BUF(dlCcchIndInfo, sizeof(DlCcchIndInfo));
265
266    if(!dlCcchIndInfo)
267    {
268       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed while building DL CCCH Ind");
269       return RFAILED;
270    }
271
272    dlCcchIndInfo->cellId = *cellId;
273    dlCcchIndInfo->crnti = *crnti;
274    dlCcchIndInfo->msgType = msgType;
275    dlCcchIndInfo->dlCcchMsgLen = dlCcchMsgSize;
276
277    DU_ALLOC_SHRABL_BUF(dlCcchIndInfo->dlCcchMsg, dlCcchIndInfo->dlCcchMsgLen);
278    if(!dlCcchIndInfo->dlCcchMsg)
279    {
280       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed while building DL CCCH Ind");
281       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo, sizeof(DlCcchIndInfo));
282       return RFAILED;
283    }
284    for(idx2 = 0; idx2 < dlCcchIndInfo->dlCcchMsgLen; idx2++)
285    {
286       dlCcchIndInfo->dlCcchMsg[idx2] = dlCcchMsg[idx2];
287    }
288    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchMsg, dlCcchMsgSize);
289
290    /* Fill Pst */
291    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_DL_CCCH_IND);
292    ret = (*packMacDlCcchIndOpts[pst.selector])(&pst, dlCcchIndInfo);
293    if(ret != ROK)
294    {
295       DU_LOG("\nERROR  -->  DU_APP : Failure in sending DL CCCH to MAC");
296       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo->dlCcchMsg,\
297             dlCcchIndInfo->dlCcchMsgLen);
298       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo, \
299             sizeof(DlCcchIndInfo));
300       ret = RFAILED; 
301    }
302
303    return ret;
304
305 }
306
307 /*******************************************************************
308  *
309  * @brief Build and Send DL RRC Message transfer to RLC
310  *
311  * @details
312  *
313  *    Function : duBuildAndSendDlRrcMsgToRlc
314  *
315  *    Functionality:
316  *      Build and Send DL RRC Message transfer to RLC
317  *
318  * @params[in] Cell ID
319  *             UE Index
320  *             Logical Channgel ID
321  *             RRC Message
322  *             RRC Message Length
323  * @return ROK     - success
324  *         RFAILED - failure
325  *
326  * ****************************************************************/
327 uint8_t duBuildAndSendDlRrcMsgToRlc(uint16_t cellId, RlcUeCfg ueCfg, F1DlRrcMsg *f1DlRrcMsg)
328 {
329    Pst     pst;
330    uint8_t ret;
331    uint8_t lcIdx;
332    RlcDlRrcMsgInfo  *dlRrcMsgInfo = NULLP;
333
334    if(!f1DlRrcMsg)
335    {
336       DU_LOG("\nERROR  -->  DU APP : Received Dl RRC Msg is NULL at duBuildAndSendDlRrcMsgToRlc()");
337       return RFAILED;
338    }
339
340    DU_ALLOC_SHRABL_BUF(dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
341    if(!dlRrcMsgInfo)
342    {
343       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for dlRrcMsgInfo in \
344          duBuildAndSendDlRrcMsgToRlc");
345       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1DlRrcMsg->rrcMsgPdu, f1DlRrcMsg->rrcMsgSize);
346       return RFAILED;
347    }
348    
349    /* Filling up the RRC msg info */
350    dlRrcMsgInfo->cellId = cellId;
351    dlRrcMsgInfo->ueIdx = ueCfg.ueIdx;
352    for(lcIdx = 0; lcIdx <= MAX_NUM_LC; lcIdx++)
353    {
354       if(ueCfg.rlcLcCfg[lcIdx].lcId == f1DlRrcMsg->srbId)
355       {
356          dlRrcMsgInfo->rbType = ueCfg.rlcLcCfg[lcIdx].rbType;
357          dlRrcMsgInfo->rbId   = ueCfg.rlcLcCfg[lcIdx].rbId;
358          dlRrcMsgInfo->lcType = ueCfg.rlcLcCfg[lcIdx].lcType;
359          dlRrcMsgInfo->lcId   = ueCfg.rlcLcCfg[lcIdx].lcId;
360          break;
361       }
362    }
363    dlRrcMsgInfo->execDup = f1DlRrcMsg->execDup;
364    dlRrcMsgInfo->deliveryStaRpt = f1DlRrcMsg->deliveryStatRpt;
365    dlRrcMsgInfo->msgLen = f1DlRrcMsg->rrcMsgSize;
366    dlRrcMsgInfo->rrcMsg = f1DlRrcMsg->rrcMsgPdu;
367
368    /* Filling post structure and sending msg */ 
369    FILL_PST_DUAPP_TO_RLC(pst, RLC_DL_INST, EVENT_DL_RRC_MSG_TRANS_TO_RLC);
370    DU_LOG("\nDEBUG   -->  DU_APP: Sending Dl RRC Msg to RLC \n");
371    ret = (*duSendDlRrcMsgToRlcOpts[pst.selector])(&pst, dlRrcMsgInfo);
372    if(ret != ROK)
373    {
374       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1DlRrcMsg->rrcMsgPdu, f1DlRrcMsg->rrcMsgSize);
375       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
376       return RFAILED;
377    }
378
379    return ROK;
380
381
382
383
384 /******************************************************************
385  *
386  * @brief Process DL RRC Msg recevied from F1AP
387  *
388  * @details
389  *
390  *    Function : duProcDlRrcMsg
391  *
392  *    Functionality: Process DL RRC Msg recevied from F1AP
393  *
394  * @params[in] dlCcchMsg - uint8_t*
395  * @return ROK     - success
396  *         RFAILED - failure
397  *
398  * ****************************************************************/
399
400 uint8_t duProcDlRrcMsg(F1DlRrcMsg *dlRrcMsg)
401 {
402    uint8_t ueIdx, ret;
403    uint16_t crnti, cellId, cellIdx;
404    bool ueCcchCtxtFound = false;
405    bool ueFound = false;
406
407    ret = ROK;
408
409    if(dlRrcMsg->srbId == SRB0_LCID) //RRC connection setup
410    {
411       for(ueIdx=0; ueIdx<duCb.numUe; ueIdx++)
412       {
413          if(dlRrcMsg->gnbDuUeF1apId == duCb.ueCcchCtxt[ueIdx].gnbDuUeF1apId)
414          {
415             ueCcchCtxtFound = true;
416             crnti  = duCb.ueCcchCtxt[ueIdx].crnti;
417             cellId = duCb.ueCcchCtxt[ueIdx].cellId;
418             break;
419          }
420       }
421    }
422    if(ueCcchCtxtFound)
423    {
424       ret = duBuildAndSendDlCcchInd(&cellId, &crnti, RRC_SETUP, dlRrcMsg->rrcMsgSize, dlRrcMsg->rrcMsgPdu);
425       if(ret == RFAILED)
426       {
427          DU_LOG("\nERROR  -->  DU APP : Failed to build DlCcch Ind at procDlRrcMsgTrans()");
428       }
429       else
430       {
431          if(duCb.actvCellLst[cellId-1]->numActvUes < MAX_NUM_UE)
432          {
433             ret = duCreateUeCb(&duCb.ueCcchCtxt[ueIdx], dlRrcMsg->gnbCuUeF1apId);
434             if(ret == RFAILED)
435             {
436                DU_LOG("\nERROR  -->  DU APP : Failed to createUeCb for cellId [%d] at procDlRrcMsgTrans()", \
437                      duCb.ueCcchCtxt[ueIdx].cellId);
438             }
439          }
440          else
441          {
442             DU_LOG("\nERROR   -->  DU_APP: Max Active UEs has reached at procDlRrcMsgTrans()");
443             ret = RFAILED;
444          }
445       }
446    }
447    else
448    {
449       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
450       {
451          for(ueIdx = 0 ; ueIdx < MAX_NUM_UE; ueIdx++)
452          {
453             if((dlRrcMsg->gnbCuUeF1apId == duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId)
454                   && (dlRrcMsg->gnbDuUeF1apId == duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId))
455             {
456                ueFound = true;
457                ret = duBuildAndSendDlRrcMsgToRlc(duCb.actvCellLst[cellIdx]->cellId, \
458                      duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg, dlRrcMsg);
459                break; 
460             }
461          }
462          if(ueFound)
463             break;
464       }
465       if(!ueFound)
466          ret = RFAILED;
467    }
468    return ret;
469 }
470
471 /******************************************************************
472  *
473  * @brief Generates GNB DU Ue F1AP ID
474  *
475  * @details
476  *
477  *    Function : genGnbDuUeF1apId
478  *
479  *    Functionality: Generates GNB DU Ue F1AP ID
480  *
481  * @params[in] void
482  * @return gnbDuF1apId
483  *
484  * ****************************************************************/
485 int32_t genGnbDuUeF1apId(uint8_t cellId)
486 {
487     uint8_t cellIdx =0;
488
489     GET_CELL_IDX(cellId, cellIdx);
490     if(duCb.actvCellLst[cellIdx])
491     {
492        return  ++duCb.actvCellLst[cellIdx]->gnbDuUeF1apIdGenerator;
493     }
494     else
495     {
496        DU_LOG("ERROR  --> DU_APP : genGnbDuUeF1apId(): CellId[%d] does not exist", cellId);
497     }
498     return -1;
499 }
500
501 /******************************************************************
502  *
503  * @brief Processes UL CCCH Ind recvd from MAC
504  *
505  * @details
506  *
507  *    Function : duProcUlCcchInd
508  *
509  *    Functionality: Processes UL CCCH Ind recvd from MAC
510  *
511  * @params[in] UlCcchIndInfo *ulCcchIndInfo
512  * @return ROK     - success
513  *         RFAILED - failure
514  *
515  * ****************************************************************/
516 uint8_t duProcUlCcchInd(UlCcchIndInfo *ulCcchIndInfo)
517 {
518
519    uint8_t ret = ROK;
520    int32_t gnbDuUeF1apId = 0;
521
522    gnbDuUeF1apId = genGnbDuUeF1apId(ulCcchIndInfo->cellId);
523    
524    if(gnbDuUeF1apId == -1)
525    {
526       DU_LOG("ERROR  --> DU_APP : duProcUlCcchInd(): Received cellId[%d] does not exist", ulCcchIndInfo->cellId);
527       return RFAILED;
528    }
529
530    /* Store Ue mapping */
531    duCb.ueCcchCtxt[duCb.numUe].gnbDuUeF1apId = (uint32_t)gnbDuUeF1apId;
532    duCb.ueCcchCtxt[duCb.numUe].crnti         = ulCcchIndInfo->crnti;
533    duCb.ueCcchCtxt[duCb.numUe].cellId        = ulCcchIndInfo->cellId;
534
535    duCb.numUe++;
536
537    ret = (BuildAndSendInitialRrcMsgTransfer(gnbDuUeF1apId, ulCcchIndInfo->crnti, ulCcchIndInfo->ulCcchMsgLen,
538             ulCcchIndInfo->ulCcchMsg));
539    if(ret != ROK)
540    {
541       DU_LOG("\nERROR  -->  DU_APP : BuildAndSendInitialRrcMsgTransfer failed");
542    }
543
544    DU_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
545    DU_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
546
547    return ret;
548
549 }
550
551 /******************************************************************
552  *
553  * @brief Fills Default UL LC Cfg
554  *
555  * @details
556  *
557  *    Function : fillDefaultUlLcCfg
558  *
559  *    Functionality: Fills Default UL LC Cfg
560  *
561  * @params[in]  UlLcCfg *ulLcCfg 
562  * @return void
563  *****************************************************************/
564 void fillDefaultUlLcCfg(UlLcCfg *ulLcCfg)
565 {
566    ulLcCfg->priority = LC_PRIORITY_1;
567    ulLcCfg->lcGroup =  0;
568    ulLcCfg->schReqId = 0;
569    ulLcCfg->pbr = PBR_KBPS_INFINITY;
570    ulLcCfg->bsd = BSD_MS_1000;
571 }
572
573 /******************************************************************
574  *
575  * @brief Fills Initial DL Bandwidth Part
576  *
577  * @details
578  *
579  *    Function : fillDefaultInitDlBwp
580  *
581  *    Functionality: Fills Initial DL Bandwidth Part
582  *
583  * @params[in]  InitialDlBwp *initDlBwp
584  * @return void
585  *
586  *****************************************************************/
587 void fillDefaultInitDlBwp(InitialDlBwp *initDlBwp)
588 {
589    uint8_t idx = 0;
590    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
591    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
592
593
594    if(initDlBwp)
595    {
596       /* Filling PDCCH Config */
597       initDlBwp->pdcchPresent = TRUE;
598       if(initDlBwp->pdcchPresent)
599       {
600          initDlBwp->pdcchCfg.numCRsetToAddMod = PDCCH_CTRL_RSRC_SET_ONE_ID;
601          memset(initDlBwp->pdcchCfg.cRSetToAddModList, 0, MAX_NUM_CRSET);
602          if(initDlBwp->pdcchCfg.numCRsetToAddMod <= MAX_NUM_CRSET)
603          {
604             initDlBwp->pdcchCfg.cRSetToAddModList[idx].cRSetId = \
605                PDCCH_CTRL_RSRC_SET_ONE_ID;
606             memset(initDlBwp->pdcchCfg.cRSetToAddModList[idx].freqDomainRsrc, 0,\
607                FREQ_DOM_RSRC_SIZE); 
608             coreset0EndPrb = CORESET0_END_PRB;
609             coreset1StartPrb = coreset0EndPrb +6;
610             coreset1NumPrb = CORESET1_NUM_PRB;
611             /* calculate the PRBs */
612             freqDomRscAllocType0(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
613             memcpy(initDlBwp->pdcchCfg.cRSetToAddModList[idx].freqDomainRsrc, freqDomainResource,
614                FREQ_DOM_RSRC_SIZE);
615
616             initDlBwp->pdcchCfg.cRSetToAddModList[idx].duration = \
617                PDCCH_CTRL_RSRC_SET_ONE_DURATION;
618             initDlBwp->pdcchCfg.cRSetToAddModList[idx].cceRegMappingType = \
619                CCE_REG_MAPPINGTYPE_PR_NONINTERLEAVED;
620             initDlBwp->pdcchCfg.cRSetToAddModList[idx].precoderGranularity = \
621                ALL_CONTIGUOUS_RBS;
622             initDlBwp->pdcchCfg.cRSetToAddModList[idx].dmrsScramblingId = \
623                SCRAMBLING_ID;
624          }
625          initDlBwp->pdcchCfg.numCRsetToRel = 0;
626          /* Filling Serach Space */
627          initDlBwp->pdcchCfg.numSearchSpcToAddMod = PDCCH_CTRL_RSRC_SET_ONE_ID;
628          memset(initDlBwp->pdcchCfg.searchSpcToAddModList, 0, MAX_NUM_CRSET);
629          if(initDlBwp->pdcchCfg.numSearchSpcToAddMod <= MAX_NUM_CRSET)
630          {
631             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].searchSpaceId =\
632                PDCCH_SRCH_SPC_TWO_ID;
633             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].cRSetId = \
634                PDCCH_CTRL_RSRC_SET_ONE_ID;
635             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].\
636                mSlotPeriodicityAndOffset = SLOTPERIODICITYANDOFFSET_PR_SL1;
637             memset(initDlBwp->pdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot, 0,\
638                MONITORING_SYMB_WITHIN_SLOT_SIZE);
639             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot[idx] =\
640                PDCCH_SYMBOL_WITHIN_SLOT;
641             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel1 =\
642                AGGREGATIONLEVEL_N8; 
643             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel2 =\
644                AGGREGATIONLEVEL_N8; 
645             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel4 =\
646                AGGREGATIONLEVEL_N4; 
647             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel8 =\
648                AGGREGATIONLEVEL_N2; 
649             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel16 =\
650                AGGREGATIONLEVEL_N1;
651             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].searchSpaceType = \
652                SEARCHSPACETYPE_PR_UE_SPECIFIC;
653             initDlBwp->pdcchCfg.searchSpcToAddModList[idx].ueSpecificDciFormat =\
654                PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
655
656             initDlBwp->pdcchCfg.numSearchSpcToRel = 0;
657
658          }
659       }
660       /* Filling PDSCH Config */
661       initDlBwp->pdschPresent = TRUE;
662       if(initDlBwp->pdschPresent)
663       {
664          initDlBwp->pdschCfg.dmrsDlCfgForPdschMapTypeA.addPos = ADDITIONALPOSITION_POS0;
665          initDlBwp->pdschCfg.resourceAllocType = RESOURCEALLOCATION_TYPE1;
666          initDlBwp->pdschCfg.numTimeDomRsrcAlloc = 1;
667          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].mappingType = \
668             MAPPING_TYPEA;
669          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].startSymbol = PDSCH_START_SYMBOL; 
670          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].symbolLength = PDSCH_LENGTH_SYMBOL;
671          initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].startSymbolAndLength = \
672             calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
673          initDlBwp->pdschCfg.rbgSize = RBG_SIZE_CONFIG1;
674          initDlBwp->pdschCfg.numCodeWordsSchByDci = CODEWORDS_SCHED_BY_DCI_N1;
675          initDlBwp->pdschCfg.bundlingType = TYPE_STATIC_BUNDLING;
676          initDlBwp->pdschCfg.bundlingInfo.StaticBundling.size = 0;
677       }
678    }
679
680 }
681
682 /******************************************************************
683  *
684  * @brief Fills Initial UL Bandwidth Part
685  *
686  * @details
687  *
688  *    Function : fillDefaultInitUlBwp
689  *
690  *    Functionality: Fills Initial UL Bandwidth Part
691  *
692  * @params[in]  InitialUlBwp *initUlBwp
693  * @return void
694  *
695  *****************************************************************/
696 void fillDefaultInitUlBwp(InitialUlBwp *initUlBwp)
697 {
698    uint8_t idx;
699    if(initUlBwp)
700    {
701       initUlBwp->pucchPresent = FALSE;
702
703       /*Filling PUSCH Config */
704       initUlBwp->puschPresent = TRUE;
705       if(initUlBwp->puschPresent)
706       {
707          initUlBwp->puschCfg.dataScramblingId = SCRAMBLING_ID;
708          initUlBwp->puschCfg.dmrsUlCfgForPuschMapTypeA.addPos = ADDITIONALPOSITION_POS0; 
709          initUlBwp->puschCfg.dmrsUlCfgForPuschMapTypeA.transPrecodDisabled. \
710             scramblingId0 = SCRAMBLING_ID; 
711          initUlBwp->puschCfg.resourceAllocType = RESOURCEALLOCATION_TYPE1;
712          initUlBwp->puschCfg.numTimeDomRsrcAlloc = 2;
713          idx = 0;
714          if(initUlBwp->puschCfg.numTimeDomRsrcAlloc <= MAX_NUM_UL_ALLOC)
715          {
716             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].k2 = PUSCH_K2_CFG1;
717             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].mappingType =\
718                MAPPING_TYPEA;
719             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbol = PUSCH_START_SYMBOL;
720             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].symbolLength = PUSCH_LENGTH_SYMBOL;
721             initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbolAndLength =\
722                calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
723
724        idx++;
725        initUlBwp->puschCfg.timeDomRsrcAllocList[idx].k2 = PUSCH_K2_CFG2;
726        initUlBwp->puschCfg.timeDomRsrcAllocList[idx].mappingType = MAPPING_TYPEA;
727        initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbol = PUSCH_START_SYMBOL;
728        initUlBwp->puschCfg.timeDomRsrcAllocList[idx].symbolLength = PUSCH_LENGTH_SYMBOL;
729        initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbolAndLength =\
730           calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
731          }
732          initUlBwp->puschCfg.transformPrecoder = TRANSFORM_PRECODER_DISABLED;
733       }
734    }
735    else
736    {
737       DU_LOG("\nERROR  -->  DU APP : Memory is NULL of InitalUlBwp");
738    }
739
740 }
741 /******************************************************************
742  *
743  * @brief Fills SpCell Group Info
744  *
745  * @details
746  *
747  *    Function : fillDefaultSpCellGrpInfo
748  *
749  *    Functionality: Fills Sp Cell Group Info
750  *
751  * @params[in]  MacUeCfg *macUeCfg
752  * @return void
753  *
754  *****************************************************************/
755 void fillDefaultSpCellGrpInfo(MacUeCfg *macUeCfg)
756 {
757    SpCellCfg *spCell = NULL;
758
759    if(macUeCfg)
760       spCell = &macUeCfg->spCellCfg;
761
762    if(spCell)
763    {
764       macUeCfg->spCellCfgPres = true;
765
766       spCell->servCellIdx = SERV_CELL_IDX;
767       /* Filling Initial Dl Bwp */
768       fillDefaultInitDlBwp(&spCell->servCellCfg.initDlBwp);
769
770       spCell->servCellCfg.numDlBwpToAdd    = 0; 
771       spCell->servCellCfg.firstActvDlBwpId = ACTIVE_DL_BWP_ID;
772       spCell->servCellCfg.defaultDlBwpId   = ACTIVE_DL_BWP_ID;
773       spCell->servCellCfg.bwpInactivityTmr = NULLP;
774       spCell->servCellCfg.pdschServCellCfg.maxMimoLayers = NULLP;
775       spCell->servCellCfg.pdschServCellCfg.maxCodeBlkGrpPerTb = NULLP;
776       spCell->servCellCfg.pdschServCellCfg.codeBlkGrpFlushInd = NULLP;
777       spCell->servCellCfg.pdschServCellCfg.xOverhead = NULLP;
778       spCell->servCellCfg.pdschServCellCfg.numHarqProcForPdsch =\
779          NUM_HARQ_PROC_FOR_PDSCH_N_16;
780       /* Filling Initial UL Bwp*/
781       fillDefaultInitUlBwp(&spCell->servCellCfg.initUlBwp);
782       spCell->servCellCfg.numUlBwpToAdd     = 0; 
783       spCell->servCellCfg.firstActvUlBwpId  = ACTIVE_DL_BWP_ID; 
784    }
785    else
786    {
787       DU_LOG("\nERROR  -->  DU APP : Memory is NULL for SpCellGrp");
788    }
789 }
790
791 /******************************************************************
792  *
793  * @brief Fills Physical Cell Group Info
794  *
795  * @details
796  *
797  *    Function : fillDefaultPhyCellGrpInfo
798  *
799  *    Functionality: Fills Physical Cell Group Info
800  *
801  * @params[in]  MacUeCfg *macUeCfg
802  * @return void
803  *
804  *****************************************************************/
805 void fillDefaultPhyCellGrpInfo(MacUeCfg *macUeCfg)
806 {
807    PhyCellGrpCfg *cellGrp = NULL;
808
809    if(macUeCfg)
810       cellGrp = &macUeCfg->phyCellGrpCfg;
811
812    if(cellGrp)
813    {
814       macUeCfg->phyCellGrpCfgPres = true;
815       cellGrp->pdschHarqAckCodebook = PDSCH_HARQ_ACK_CODEBOOK_DYNAMIC;
816       cellGrp->pNrFr1 = P_NR_FR1;
817    }
818    else
819    {
820       DU_LOG("\nERROR  -->  DU APP : Memory is NULL for Physical Cell Group");
821    }
822 }
823
824 /******************************************************************
825  *
826  * @brief Fills Mac Cell Group Info
827  *
828  * @details
829  *
830  *    Function : fillDefaultMacCellGrpInfo
831  *
832  *    Functionality: Fills Mac Cell Group Info
833  *
834  * @params[in]  MacUeCfg *macUeCfg
835  * @return void
836  *
837  *****************************************************************/
838 void fillDefaultMacCellGrpInfo(MacUeCfg *macUeCfg)
839 {
840    uint8_t idx;
841    MacCellGrpCfg *cellGrp = NULL;
842
843    if(macUeCfg)
844       cellGrp = &macUeCfg->macCellGrpCfg;
845
846    if(cellGrp)
847    {
848       macUeCfg->macCellGrpCfgPres = true;
849
850       /* Filling Scheduling Request Config */
851       cellGrp->schReqCfg.addModListCount = 1;
852       if(cellGrp->schReqCfg.addModListCount <= MAX_NUM_SR_CFG_PER_CELL_GRP)
853       {
854          for(idx = 0; idx < cellGrp->schReqCfg.addModListCount; idx++)
855          {
856             cellGrp->schReqCfg.addModList[idx].schedReqId    = SCH_REQ_ID;
857             cellGrp->schReqCfg.addModList[idx].srProhibitTmr = SR_PROHIBIT_MS_32;
858             cellGrp->schReqCfg.addModList[idx].srTransMax    = SR_TRANS_MAX_N_16;
859          }
860       }
861       cellGrp->schReqCfg.relListCount = 0;
862
863       /* Filling Tag config */
864       cellGrp->tagCfg.addModListCount = 1;
865       if(cellGrp->tagCfg.addModListCount <= MAC_NUM_TAGS)
866       {
867          for(idx = 0; idx < cellGrp->tagCfg.addModListCount; idx++)
868          {
869             cellGrp->tagCfg.addModList[idx].tagId = TAG_ID;
870             cellGrp->tagCfg.addModList[idx].timeAlignTimer = TIME_ALIGNMENT_TIMER_INFINITY;
871          }
872       }
873       cellGrp->tagCfg.relListCount = 0;
874
875       /* Filling BSR config */
876       cellGrp->bsrTmrCfg.periodicTimer = BSR_PERIODIC_TIMER_SF_10;
877       cellGrp->bsrTmrCfg.retxTimer = BSR_RETX_TIMER_SF_320;
878       cellGrp->bsrTmrCfg.srDelayTimer = BSR_SR_DELAY_TMR_2560;
879
880       /* Filling PHR config */
881       cellGrp->phrCfgSetupPres = true;
882       cellGrp->phrCfg.periodicTimer = PHR_PERIODIC_TIMER_INFINITY;
883       cellGrp->phrCfg.prohibitTimer = PHR_PROHIBIT_TIMER_SF_0;
884       cellGrp->phrCfg.txPowerFactor = PHR_TX_PWR_FACTOR_CHANGE_INFINITY;
885       cellGrp->phrCfg.multiplePHR   = false;
886       cellGrp->phrCfg.dummy         = false;
887       cellGrp->phrCfg.phrType2OtherCell = false;
888       cellGrp->phrCfg.phrOtherCG = PHR_MODE_OTHER_CG_REAL;  
889
890    }
891    else
892    {
893       DU_LOG("\nERROR  -->  DU APP : Memory is NULL for Master Cell Group");
894    }
895 }
896
897 /*******************************************************************
898  *
899  * @brief Fills default modulation info for a UE
900  *
901  * @details
902  *
903  *    Function : fillDefaultModulation
904  *
905  *    Functionality: Fills default modulation info for a UE
906  *
907  * @params[in] Pointer to MAC UE configuration
908  * @return ROK     - success
909  *         RFAILED - failure
910  *
911  * ****************************************************************/
912 void fillDefaultModulation(MacUeCfg *ueCfg)
913 {
914    ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
915    ueCfg->dlModInfo.mcsIndex = SIB1_MCS;
916    ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64; /* Spec 38.214-Table 5.1.3.1-1 */
917
918    ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
919    ueCfg->ulModInfo.mcsIndex = SIB1_MCS;
920    ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64; /* Spec 38.214-Table 5.1.3.1-1 */
921 }
922
923 /******************************************************************
924  *
925  * @brief Function to fill Mac Lc Cfg for SRB1
926  *
927  * @details
928  *
929  *    Function : fillMacSrb1LcCfg
930  *
931  *    Functionality: Function to fill Mac Lc cfg for SRB1
932  *
933  * @params[in]  LcCfg *lcCfg, LcCfg *ueSetReqDb
934  * @return void
935  *****************************************************************/
936
937 void fillMacSrb1LcCfg(LcCfg *macLcCfg)
938 {
939    macLcCfg->lcId   = SRB1_LCID;
940    macLcCfg->configType = CONFIG_ADD;
941    macLcCfg->drbQos = NULLP;
942    macLcCfg->snssai = NULLP;
943    macLcCfg->ulLcCfgPres = true;
944    fillDefaultUlLcCfg(&macLcCfg->ulLcCfg);
945 }
946
947 /******************************************************************
948  *
949  * @brief Function to fill the Lc cfg from ueSetupReqDb
950  *
951  * @details
952  *
953  *    Function : fillMacLcCfgToAddMod
954  *
955  *    Functionality: Function to fill the Lc cfg from ueSetupReqDb
956  *
957  * @params[in]  LcCfg *lcCfg, LcCfg *ueSetReqDb
958  * @return ROK/RFAILED
959  *
960  *****************************************************************/
961
962 uint8_t fillMacLcCfgToAddMod(LcCfg *macLcCfgToSend, LcCfg *ueLcCfgDb, LcCfg *oldLcCfg, Bool toUpdate)
963 {
964    if(!toUpdate)
965    {
966       if(macLcCfgToSend)
967       {
968          macLcCfgToSend->lcId = ueLcCfgDb->lcId;
969          macLcCfgToSend->configType = ueLcCfgDb->configType;
970
971          if(ueLcCfgDb->drbQos)
972             macLcCfgToSend->drbQos = ueLcCfgDb->drbQos;
973          else if(oldLcCfg)
974             macLcCfgToSend->drbQos = oldLcCfg->drbQos;
975          else
976             macLcCfgToSend->drbQos = NULL;
977
978          if(ueLcCfgDb->snssai)
979             macLcCfgToSend->snssai = ueLcCfgDb->snssai;
980          else if(oldLcCfg)
981             macLcCfgToSend->snssai = oldLcCfg->snssai;
982          else
983             macLcCfgToSend->snssai = NULL;
984
985          macLcCfgToSend->ulLcCfgPres = ueLcCfgDb->ulLcCfgPres;
986          memcpy(&macLcCfgToSend->ulLcCfg, &ueLcCfgDb->ulLcCfg, sizeof(UlLcCfg));
987          memcpy(&macLcCfgToSend->dlLcCfg, &ueLcCfgDb->dlLcCfg, sizeof(DlLcCfg));
988       }
989    }
990    else
991    {
992       oldLcCfg->lcId = ueLcCfgDb->lcId;
993       oldLcCfg->configType = ueLcCfgDb->configType;
994
995       if(ueLcCfgDb->drbQos)
996       {
997          if(oldLcCfg->drbQos)
998             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, oldLcCfg->drbQos, sizeof(DrbQosInfo));
999
1000          DU_ALLOC_SHRABL_BUF(oldLcCfg->drbQos, sizeof(DrbQosInfo));
1001          if(oldLcCfg->drbQos == NULL)
1002          {
1003             DU_LOG("\nERROR  -->  DU APP : Memory Alloc Failed at fillMacLcCfgToAddMod()");
1004             return RFAILED;
1005          }
1006          memcpy(oldLcCfg->drbQos, ueLcCfgDb->drbQos, sizeof(DrbQosInfo));
1007       }
1008
1009       if(ueLcCfgDb->snssai)
1010       {
1011          if(oldLcCfg->snssai)
1012             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, oldLcCfg->snssai, sizeof(Snssai));
1013
1014          DU_ALLOC_SHRABL_BUF(oldLcCfg->snssai, sizeof(Snssai));
1015          if(oldLcCfg->snssai == NULL)
1016          {
1017             DU_LOG("\nERROR  -->  DU APP : Memory Alloc Failed at fillMacLcCfgToAddMod()");
1018             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, oldLcCfg->drbQos, sizeof(DrbQosInfo));
1019             return RFAILED;
1020          }
1021          memcpy(oldLcCfg->snssai, ueLcCfgDb->snssai, sizeof(Snssai));
1022       }
1023
1024       oldLcCfg->ulLcCfgPres = ueLcCfgDb->ulLcCfgPres;
1025       memcpy(&oldLcCfg->ulLcCfg, &ueLcCfgDb->ulLcCfg, sizeof(UlLcCfg));
1026       memcpy(&oldLcCfg->dlLcCfg, &ueLcCfgDb->dlLcCfg, sizeof(DlLcCfg));
1027    }
1028    return ROK;
1029 }
1030
1031 /******************************************************************
1032  *
1033  * @brief Function to copy the Bit rate from ueSetupReqDb
1034  *
1035  * @details
1036  *
1037  *    Function : fillAmbr
1038  *
1039  *    Functionality: Function to copy bit Rate from ueSetupReqDb
1040  *
1041  * @params[in]  AmbrCfg **macAmbr, AmbrCfg  *ueDbAmbr
1042  * @return ROK/RFAILED
1043  *
1044  *****************************************************************/
1045
1046 uint8_t fillAmbr(AmbrCfg **macAmbrCfgToSend, AmbrCfg *ueDbAmbr, AmbrCfg **oldMacAmbrCfg, Bool toUpdate)
1047 {
1048    if(!toUpdate)
1049    {
1050       if(ueDbAmbr)
1051       {
1052          *macAmbrCfgToSend = ueDbAmbr;
1053       }
1054       else
1055          *macAmbrCfgToSend = *oldMacAmbrCfg;       
1056    }
1057    else
1058    {
1059       if(ueDbAmbr)
1060       {
1061          if(*oldMacAmbrCfg)
1062          {
1063             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, *oldMacAmbrCfg, sizeof(AmbrCfg));
1064          }
1065          DU_ALLOC_SHRABL_BUF(*oldMacAmbrCfg, sizeof(AmbrCfg));
1066          if(*oldMacAmbrCfg == NULLP)
1067          {
1068             DU_LOG("\nERROR  -->  DU APP : Memory Alloc Failed at fillAmbr()");
1069             return RFAILED;
1070          }
1071          memset(*oldMacAmbrCfg, 0, sizeof(AmbrCfg));
1072          (*oldMacAmbrCfg)->ulBr = ueDbAmbr->ulBr;
1073       }
1074    }
1075
1076    return ROK;
1077 }
1078
1079 /******************************************************************
1080  *
1081  * @brief Builds and Send UE ReConfig Request to MAC
1082  *
1083  * @details
1084  *
1085  *    Function : sendUeReCfgReqToMac
1086  *
1087  *    Functionality: Builds and Send UE ReConfig Request to MAC
1088  *
1089  * @Params[in]  MacUeCfg pointer
1090  * @return ROK     - success
1091  *         RFAILED - failure
1092  *
1093  * ****************************************************************/
1094
1095 uint8_t sendUeReCfgReqToMac(MacUeCfg *macUeCfg)
1096 {
1097    uint8_t ret = ROK;
1098    Pst pst;
1099    
1100    /* Fill Pst */
1101    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_RECONFIG_REQ);
1102    
1103    if(macUeCfg)
1104    {
1105       /* Processing one Ue at a time to MAC */
1106       DU_LOG("\nDEBUG   -->  DU_APP: Sending Ue Reconfig Request to MAC");
1107       ret = (*packMacUeReconfigReqOpts[pst.selector])(&pst, macUeCfg);
1108       if(ret == RFAILED)
1109       {
1110          DU_LOG("\nERROR  -->  DU APP : Failed to send Reconfig Request to MAC at sendUeReCfgReqToMac()");
1111          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macUeCfg, sizeof(MacUeCfg));
1112       }
1113    }
1114    else
1115    {
1116       DU_LOG("\nERROR  -->  DU_APP: Received macUeCfg is NULLP at sendUeReCfgReqToMac()");
1117       ret = RFAILED;
1118    }
1119    return ret;
1120 }
1121
1122 /******************************************************************
1123  *
1124  * @brief Function to return Drb LcId
1125  *
1126  * @details
1127  *
1128  *    Function : getDrbLcId
1129  *
1130  *    Functionality: Function to return Drb LcId
1131  *
1132  * Returns: lcId - SUCCESS
1133  *         RFAILED - FAILURE
1134  *****************************************************************/
1135
1136 uint8_t getDrbLcId(uint32_t *drbBitMap)
1137 {
1138    uint8_t bitMask = 1, bitPos = 0;
1139    bitPos = MIN_DRB_LCID;
1140
1141    while(bitPos <= MAX_DRB_LCID)
1142    {
1143       if((*drbBitMap & (bitMask << bitPos)) == 0)
1144       {
1145          *drbBitMap = ((bitMask << bitPos)| *drbBitMap);
1146          return bitPos;
1147       }
1148       else
1149       {
1150          bitPos++;
1151       }
1152    }
1153    DU_LOG("\nERROR   -->  DU_APP: Max LC Reached in getDrbLcId()");
1154    return RFAILED;
1155 }
1156
1157 /******************************************************************
1158  *
1159  * @brief Fills MacUeCfg structure
1160  *
1161  * @details
1162  *
1163  *    Function : fillMacUeCfg
1164  *
1165  *    Functionality: Fills MacUeCfg
1166  *
1167  * @params[in]  cellId, ueIdx, crnti, 
1168  *              DuUeCfg  pointer,
1169  *              MacUeCfg pointer
1170  * @return ROK/RFAILED
1171  *
1172  *****************************************************************/
1173 uint8_t fillMacUeCfg(uint16_t cellId, uint8_t ueIdx, uint16_t crnti, \
1174    DuUeCfg *ueCfgDb, MacUeCfg *macUeCfg)
1175 {
1176    uint8_t ret, dbIdx, lcIdx, cellIdx;
1177    bool lcIdFound = false;
1178    MacUeCfg *duMacDb = NULLP;
1179
1180    ret =ROK;
1181
1182    if(!ueCfgDb)
1183    {
1184       macUeCfg->cellId       = cellId;
1185       macUeCfg->ueIdx        = ueIdx;
1186       macUeCfg->crnti        = crnti;
1187
1188       fillDefaultMacCellGrpInfo(macUeCfg);
1189       fillDefaultPhyCellGrpInfo(macUeCfg);
1190       fillDefaultSpCellGrpInfo(macUeCfg);
1191       macUeCfg->ambrCfg = NULLP;
1192       fillDefaultModulation(macUeCfg);
1193       fillMacSrb1LcCfg(&macUeCfg->lcCfgList[0]);
1194       macUeCfg->numLcs++;
1195    }
1196    else
1197    {
1198       /* Fetching MacDb from DuUeCb */
1199       GET_CELL_IDX(cellId, cellIdx);
1200       duMacDb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg;
1201       duMacDb->macUeCfgState = UE_CFG_INPROGRESS;
1202       /* Fetching MaUeCfg List for ADD/MOD/DEL */
1203       macUeCfg->cellId       = cellId;
1204       macUeCfg->ueIdx        = ueIdx;
1205       macUeCfg->crnti        = crnti;
1206       ret = procUeReCfgCellInfo(macUeCfg, duMacDb, ueCfgDb->cellGrpCfg);
1207       if(ret == ROK)
1208       {
1209          if(macUeCfg->spCellCfgPres == true)
1210          {
1211             if(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschPresent)
1212             {
1213                fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc,\
1214                      &macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, NULL);
1215             }
1216             if(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschPresent)
1217             {
1218                fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
1219                      NULL, &macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg);
1220             }
1221          }
1222          ret = fillAmbr(&macUeCfg->ambrCfg, ueCfgDb->ambrCfg , &duMacDb->ambrCfg, FALSE);
1223          duFillModulationDetails(macUeCfg, duMacDb, ueCfgDb->ueNrCapability);
1224       }
1225
1226       /* Filling LC Context */
1227       for(dbIdx = 0; (dbIdx < ueCfgDb->numMacLcs && ret == ROK); dbIdx++)
1228       {
1229          if(!ueCfgDb->macLcCfg[dbIdx].ulLcCfgPres)
1230          {
1231             /* Filling default UL LC config in MAC if not present */
1232             ueCfgDb->macLcCfg[dbIdx].ulLcCfgPres = true;
1233             fillDefaultUlLcCfg(&ueCfgDb->macLcCfg[dbIdx].ulLcCfg);
1234          }
1235          for(lcIdx = 0; lcIdx < duMacDb->numLcs; lcIdx++)
1236          {
1237             if(ueCfgDb->macLcCfg[dbIdx].lcId == duMacDb->lcCfgList[lcIdx].lcId)
1238             {
1239                lcIdFound = true;
1240                if((ueCfgDb->macLcCfg[dbIdx].configType == CONFIG_UNKNOWN) ||
1241                      (ueCfgDb->macLcCfg[dbIdx].configType == CONFIG_MOD))
1242                {
1243                   ueCfgDb->macLcCfg[dbIdx].configType = CONFIG_MOD;
1244                   ret = fillMacLcCfgToAddMod(&macUeCfg->lcCfgList[dbIdx], &ueCfgDb->macLcCfg[dbIdx], &duMacDb->lcCfgList[lcIdx], FALSE);
1245                }
1246             }
1247             else
1248                lcIdFound = false;
1249          }
1250          if(!lcIdFound)
1251          {
1252             /* ADD/DEL CONFIG */
1253             ret = fillMacLcCfgToAddMod(&macUeCfg->lcCfgList[dbIdx], &ueCfgDb->macLcCfg[dbIdx], NULL, FALSE);
1254          }
1255          if(ret == ROK)
1256          {
1257             macUeCfg->numLcs++;
1258          }
1259          else
1260          {
1261             DU_LOG("\nERROR  -->  DU APP : Failed to add Lc at Idx %d in fillMacUeCfg()", dbIdx); 
1262             break;
1263          }
1264       }/*End of Outer FOR loop */
1265       memcpy(&ueCfgDb->copyOfmacUeCfg, macUeCfg, sizeof(MacUeCfg));
1266    }
1267    return ret;
1268 }
1269
1270 /******************************************************************
1271  *
1272  * @brief Fills Rlc AM Information
1273  *
1274  * @details
1275  *
1276  *    Function : fillDefaultAmInfo
1277  *
1278  *    Functionality: Fills Rlc AM Information
1279  *
1280  * @params[in]  AmBearerCfg *amCfg
1281  * @return void
1282  *
1283  *****************************************************************/
1284 void fillDefaultAmInfo(AmBearerCfg *amCfg)
1285 {
1286    /* DL AM */
1287    amCfg->dlAmCfg.snLenDl     = AM_SIZE_12;
1288    amCfg->dlAmCfg.pollRetxTmr = T_POLL_RETRANSMIT_VAL;
1289    amCfg->dlAmCfg.pollPdu     = POLL_PDU_VAL;
1290    amCfg->dlAmCfg.pollByte    = POLL_BYTE_VAL;
1291    amCfg->dlAmCfg.maxRetxTh   = MAX_RETX_THRESHOLD_VAL;   
1292  
1293    /* UL AM */
1294    amCfg->ulAmCfg.snLenUl     = AM_SIZE_12;
1295    amCfg->ulAmCfg.reAssemTmr  = T_REASSEMBLY_VAL; 
1296    amCfg->ulAmCfg.statProhTmr = T_STATUS_PROHIBHIT_VAL;
1297 }
1298
1299 /******************************************************************
1300  *
1301  * @brief Fills RLC UM Bi Directional Information
1302  *
1303  * @details
1304  *
1305  *    Function : fillDefaultUmBiInfo
1306  *
1307  *    Functionality: Fills RLC UM Bi Directional Information
1308  *
1309  * @params[in]  UmBiDirBearerCfg *umBiDirCfg
1310  * @return void
1311  *
1312  *****************************************************************/
1313 void fillDefaultUmBiInfo(UmBiDirBearerCfg *umBiDirCfg)
1314 {
1315    /* UL UM BI DIR INFO */
1316    umBiDirCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1317    umBiDirCfg->ulUmCfg.reAssemTmr = T_REASSEMBLY_VAL;
1318
1319    /* DL UM BI DIR INFO */
1320    umBiDirCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
1321 }
1322
1323 /******************************************************************
1324  *
1325  * @brief Fills RLC UM Uni Directional UL Information
1326  *
1327  * @details
1328  *
1329  *    Function : fillDefaultUmUlInfo
1330  *
1331  *    Functionality: Fills RLC UM Uni Directional Info
1332  *
1333  * @params[in]  UmUniDirUlBearerCfg *UmUlCfg
1334  * @return void
1335  *
1336  *****************************************************************/
1337 void fillDefaultUmUlInfo(UmUniDirUlBearerCfg *UmUlCfg)
1338 {
1339    UmUlCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1340    UmUlCfg->ulUmCfg.reAssemTmr = T_REASSEMBLY_VAL;
1341 }
1342
1343 /******************************************************************
1344  *
1345  * @brief Fills RLC UM Uni Directional DL Information
1346  *
1347  * @details
1348  *
1349  *    Function : fillDefaultUmDlInfo
1350  *
1351  *    Functionality: Fills RLC UM Uni Directional DL Info
1352  *
1353  * @params[in]  UmUniDirDlBearerCfg *UmDlCfg
1354  * @return void
1355  *
1356  *****************************************************************/
1357 void fillDefaultUmDlInfo(UmUniDirDlBearerCfg *UmDlCfg)
1358 {
1359    UmDlCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
1360 }
1361
1362 /******************************************************************
1363  *
1364  * @brief Builds Rlc Mode Default Configuration
1365  *
1366  * @details
1367  *
1368  *    Function : fillDefaultRlcModeCfg
1369  *
1370  *    Functionality: Builds Rlc Mode Default Configuration
1371  *
1372  * @params[in]  rlcMode, RlcBearerCfg *lcCfg
1373  * @return ROK/RFAILED
1374  *
1375  *****************************************************************/
1376
1377 uint8_t fillDefaultRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *lcCfg)
1378 {
1379
1380    if(lcCfg)
1381    {
1382       switch(rlcMode)
1383       {
1384          case RLC_AM :
1385             {
1386                if(!lcCfg->u.amCfg)
1387                {
1388                  DU_ALLOC_SHRABL_BUF(lcCfg->u.amCfg, sizeof(AmBearerCfg));
1389                  if(lcCfg->u.amCfg)
1390                     fillDefaultAmInfo(lcCfg->u.amCfg);
1391                  else
1392                  {
1393                     DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at AmCfg at fillDefaultRlcModeCfg()");
1394                     return RFAILED;
1395                  }
1396                }
1397                break;
1398             }
1399          case RLC_UM_BI_DIRECTIONAL :
1400             {
1401                if(!lcCfg->u.umBiDirCfg)
1402                {
1403                  DU_ALLOC_SHRABL_BUF(lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
1404                  if(lcCfg->u.umBiDirCfg)
1405                     fillDefaultUmBiInfo(lcCfg->u.umBiDirCfg);
1406                  else
1407                  {
1408                     DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmBiDirCfg at fillDefaultRlcModeCfg()");
1409                     return RFAILED;
1410                  }
1411                }
1412                break;
1413             }
1414          case RLC_UM_UNI_DIRECTIONAL_UL :
1415             {
1416                if(!lcCfg->u.umUniDirUlCfg)
1417                {
1418                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
1419                   if(lcCfg->u.umUniDirUlCfg)
1420                     fillDefaultUmUlInfo(lcCfg->u.umUniDirUlCfg);
1421                   else
1422                   {
1423                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmUniDirUlCfg at fillDefaultRlcModeCfg()");
1424                      return RFAILED;
1425                   }
1426                }
1427                break;
1428             }
1429          case RLC_UM_UNI_DIRECTIONAL_DL :
1430             {
1431                if(!lcCfg->u.umUniDirDlCfg)
1432                {
1433                   DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
1434                   if(lcCfg->u.umUniDirDlCfg)
1435                    fillDefaultUmDlInfo(lcCfg->u.umUniDirDlCfg);
1436                   else
1437                   {
1438                      DU_LOG("\n ERROR  -->  DU APP : Memory Alloc failed at UmUniDirDlCfg at fillDefaultRlcModeCfg()");
1439                      return RFAILED;
1440                   }
1441                }
1442                break;
1443             }
1444          default:
1445             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
1446             return RFAILED;
1447       }
1448
1449    }
1450    else
1451    {
1452       DU_LOG("\nERROR  -->  DUAPP: Received LC Config is NULL");
1453       return RFAILED;
1454    }
1455    return ROK;
1456 }
1457
1458 /*******************************************************************
1459  *
1460  * @brief Function to fill Rlc Lc Cfg for SRB1
1461  *
1462  * @details
1463  *
1464  *    Function : fillRlcSrb1LcCfg
1465  *
1466  *    Functionality: 
1467  *     Function to fill Rlc Lc Cfg for SRB1
1468  * 
1469  *  @params[in]     Pointer to RlcBearerCfg
1470  *  @return ROK/RFAILED
1471  * 
1472  *****************************************************************/
1473
1474 uint8_t fillRlcSrb1LcCfg(RlcBearerCfg *rlcLcCfg)
1475 {
1476    uint8_t ret = ROK;
1477
1478    rlcLcCfg->rbId   = SRB1_LCID;
1479    rlcLcCfg->rbType = RB_TYPE_SRB;
1480    rlcLcCfg->lcId   = SRB1_LCID;
1481    rlcLcCfg->lcType = LCH_DCCH;
1482    rlcLcCfg->rlcMode = RLC_AM;
1483    rlcLcCfg->configType = CONFIG_ADD;
1484    ret = fillDefaultRlcModeCfg(rlcLcCfg->rlcMode, rlcLcCfg);
1485    return ret;
1486 }
1487
1488 /*******************************************************************
1489  *
1490  * @brief Processes UE ReConfig Req to RLC UL
1491  *
1492  * @details
1493  *
1494  *    Function : sendUeReCfgReqToRlc
1495  *
1496  *    Functionality: 
1497  *     Processes UE Reconfig Req to RLC UL
1498  * 
1499  *  @params[in]     Pointer to RlcUeCfg
1500  *  @return ROK     - success
1501  *          RFAILED - failure
1502  * 
1503  *****************************************************************/
1504
1505 uint8_t sendUeReCfgReqToRlc(RlcUeCfg *rlcUeCfg)
1506 {
1507    uint8_t ret;
1508    Pst pst;
1509    
1510    FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_RECONFIG_REQ);
1511    if(rlcUeCfg)
1512    {
1513       /* Processing one Ue at a time to RLC */
1514       DU_LOG("\nDEBUG   -->  DU_APP: Sending Ue Reconfig Request to RLC UL");
1515       ret = (*packRlcUeReconfigReqOpts[pst.selector])(&pst, rlcUeCfg);
1516       if(ret == RFAILED)
1517       {
1518          DU_LOG("\nERROR  -->  DU_APP : Failed to send Ue Reconfig Req to RLC at sendUeReCfgReqToRlc()");
1519          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rlcUeCfg, sizeof(RlcUeCfg));
1520       }
1521    }
1522    else
1523    {
1524       DU_LOG("\nERROR  -->   DU_APP: Received RlcUeCfg is NULL at sendUeReCfgReqToRlc()");
1525       ret = RFAILED;
1526    }
1527    return ret;
1528 }
1529
1530 /******************************************************************
1531  *
1532  * @brief Fills RlcBearerCfg structure
1533  *
1534  * @details
1535  *
1536  *    Function : fillRlcUeCfg
1537  *
1538  *    Functionality: Fills Rlc Bearer Cfg
1539  *
1540  *
1541  *****************************************************************/
1542 uint8_t fillRlcUeCfg(uint16_t cellId, uint8_t ueIdx,\
1543    DuUeCfg *ueCfgDb, RlcUeCfg *rlcUeCfg)
1544 {
1545    uint8_t ret, dbIdx, lcIdx, cellIdx;
1546    bool lcIdFound = false;
1547    RlcUeCfg *duRlcDb = NULLP;
1548
1549    ret = ROK;
1550    if(!ueCfgDb)
1551    {
1552       /* Initial RB being Added */ 
1553       rlcUeCfg->cellId       = cellId;
1554       rlcUeCfg->ueIdx        = ueIdx;
1555       ret = fillRlcSrb1LcCfg(&rlcUeCfg->rlcLcCfg[0]);
1556       if(ret == ROK)
1557          rlcUeCfg->numLcs++;
1558       else
1559          memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
1560    }
1561    else
1562    {
1563       /* Fetch RlcDb from DuUeCb */ 
1564       GET_CELL_IDX(cellId, cellIdx);
1565       duRlcDb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg;
1566       duRlcDb->rlcUeCfgState = UE_CFG_INPROGRESS;
1567       /*Filling RlcUeCfg */
1568       rlcUeCfg->cellId       = cellId;
1569       rlcUeCfg->ueIdx        = ueIdx;
1570       for(dbIdx = 0; (dbIdx < ueCfgDb->numRlcLcs && ret == ROK); dbIdx++)
1571       {
1572          ret = fillDefaultRlcModeCfg(ueCfgDb->rlcLcCfg[dbIdx].rlcMode, &ueCfgDb->rlcLcCfg[dbIdx]);
1573          if(ret == RFAILED)
1574          {
1575             DU_LOG("\n ERROR  -->  DU APP : Failed to fill Rlc Mode at fillRlcUeCfg()");
1576             memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
1577             return ret;
1578          }
1579          /* Fill Rlc Ue Cfg List for ADD/MOD/DEL */
1580          for(lcIdx = 0; lcIdx < duRlcDb->numLcs; lcIdx++)
1581          { 
1582             if(ueCfgDb->rlcLcCfg[dbIdx].lcId == duRlcDb->rlcLcCfg[lcIdx].lcId)
1583             {
1584                lcIdFound = true;
1585                if((ueCfgDb->rlcLcCfg[dbIdx].configType == CONFIG_UNKNOWN)||
1586                      (ueCfgDb->rlcLcCfg[dbIdx].configType == CONFIG_MOD))
1587                {
1588                   /* MOD */ 
1589                   ueCfgDb->rlcLcCfg[dbIdx].configType = CONFIG_MOD; /* update Db for MOD type */
1590                   memcpy(&rlcUeCfg->rlcLcCfg[dbIdx], &ueCfgDb->rlcLcCfg[dbIdx], sizeof(RlcBearerCfg));
1591                }
1592             }
1593             else
1594                lcIdFound = false;
1595          }
1596          if(!lcIdFound)
1597          {
1598             /* ADD/ DEL Config Type */
1599             memcpy(&rlcUeCfg->rlcLcCfg[dbIdx], &ueCfgDb->rlcLcCfg[dbIdx], sizeof(RlcBearerCfg));
1600          }
1601          rlcUeCfg->numLcs++;
1602       }
1603    }
1604    return ret;
1605 }
1606
1607 /******************************************************************
1608  *
1609  * @brief creates UE context
1610  *
1611  * @details
1612  *
1613  *    Function : duCreateUeCb
1614  *
1615  *    Functionality: Creates UE Conetxt
1616  *
1617  * @params[in] UeCcchCtxt Pointer
1618  *             UeIdx Pointer
1619  *
1620  * @return ROK     - success
1621  *         RFAILED - failure
1622  * ****************************************************************/
1623 uint8_t duCreateUeCb(UeCcchCtxt *ueCcchCtxt, uint32_t gnbCuUeF1apId)
1624 {
1625    uint8_t cellIdx = 0;
1626    uint8_t ret     = ROK;
1627    uint8_t ueIdx;
1628
1629    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
1630    {
1631       if(ueCcchCtxt->cellId == duCb.actvCellLst[cellIdx]->cellId)
1632       {
1633          GET_UE_IDX(ueCcchCtxt->crnti, ueIdx);
1634          DU_LOG("\nDEBUG   -->  DU_APP: Filling UeCb for ueIdx [%d]", ueIdx);
1635
1636          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].f1UeDb        = NULLP;
1637          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].crnti         = ueCcchCtxt->crnti;
1638          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbDuUeF1apId = ueCcchCtxt->gnbDuUeF1apId;
1639          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbCuUeF1apId = gnbCuUeF1apId;
1640          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].drbBitMap     = NULLP;
1641          duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].ueState       = UE_ACTIVE;
1642
1643          /* Filling Mac Ue Config */ 
1644          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg, 0, sizeof(MacUeCfg));
1645          ret = duBuildAndSendUeCreateReqToMac(ueCcchCtxt->cellId, ueIdx, ueCcchCtxt->crnti,\
1646                 &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg);
1647          if(ret == RFAILED)
1648             DU_LOG("\nERROR  -->  DU APP : Failed to send UE create request to MAC");
1649          
1650          /* Filling Rlc Ue Config */
1651          memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg, 0, sizeof(RlcUeCfg));
1652          ret = duBuildAndSendUeCreateReqToRlc(ueCcchCtxt->cellId, ueIdx, \
1653                 &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg);
1654          if(ret == RFAILED)
1655             DU_LOG("\nERROR  -->  DU APP : Failed to send UE create request to RLC");
1656
1657          duCb.actvCellLst[cellIdx]->numActvUes++;
1658          memset(ueCcchCtxt, 0, sizeof(UeCcchCtxt));
1659     duCb.numUe--;
1660       }
1661    }
1662    return ret;
1663 }
1664
1665 /******************************************************************
1666  *
1667  * @brief Builds and Send UE Create Request to MAC
1668  *
1669  * @details
1670  *
1671  *    Function : duBuildAndSendUeCreateReqToMac
1672  *
1673  *    Functionality: Builds and Send UE Create Request to MAC
1674  *
1675  * @Params[in]  cellId,
1676  *              ueIdx
1677  * @return ROK     - success
1678  *         RFAILED - failure
1679  *
1680  * ****************************************************************/
1681
1682 uint8_t duBuildAndSendUeCreateReqToMac(uint16_t cellId, uint8_t ueIdx,\
1683    uint16_t crnti, MacUeCfg *duMacUeCfg)
1684 {
1685    uint8_t  ret = ROK;
1686    MacUeCfg *macUeCfg = NULLP;
1687    Pst       pst;
1688    memset(&pst, 0, sizeof(Pst));
1689
1690
1691    ret = fillMacUeCfg(cellId, ueIdx, crnti, NULL, duMacUeCfg);
1692    if(ret == RFAILED)
1693    {
1694       DU_LOG("\nERROR  -->  DU APP : Failed to fill MacUeCfg at duBuildAndSendUeCreateReqToMac()");
1695       return RFAILED;
1696    }
1697    /* Fill Pst */
1698    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_CREATE_REQ);
1699
1700    /* Copying ueCb to a sharable buffer */
1701    DU_ALLOC_SHRABL_BUF(macUeCfg, sizeof(MacUeCfg));
1702    if(macUeCfg)
1703    {
1704       memset(macUeCfg, 0, sizeof(MacUeCfg));
1705       memcpy(macUeCfg, duMacUeCfg, sizeof(MacUeCfg));
1706       DU_LOG("\nDEBUG   -->  DU_APP: Sending UE create request to MAC");
1707
1708       /* Processing one Ue at a time to MAC */
1709       ret = (*packMacUeCreateReqOpts[pst.selector])(&pst, macUeCfg);
1710       if(ret == RFAILED)
1711       {
1712          DU_LOG("\nERROR  -->  DU_APP : Failure in sending Ue Create Req to MAC at duBuildAndSendUeCreateReqToMac()");
1713          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macUeCfg, sizeof(MacUeCfg));
1714       }
1715    }
1716    else
1717    {
1718       DU_LOG("\n ERROR  -->  DU APP : Memory alloc failed at duBuildAndSendUeCreateReqToMac()");
1719       ret = RFAILED;
1720    }
1721    return ret;
1722 }
1723
1724 /*******************************************************************
1725  *
1726  * @brief To update DuUeCb Mac Cfg
1727  *
1728  * @details
1729  *
1730  *    Function : duUpdateMacCfg
1731  *    Functionality:  update DuUeCb MAC Cfg
1732  *
1733  * @params[in] DuUeCb Pointer
1734  *             F1UeContextSetupDb pointer 
1735  * @return ROK     - success
1736  *         RFAILED - failure
1737  *
1738  * ****************************************************************/
1739 uint8_t duUpdateMacCfg(MacUeCfg *macUeCfg, F1UeContextSetupDb *f1UeDb) 
1740 {
1741    uint8_t ret, lcIdx, dbIdx, numLcs, lcDelIdx, cellIdx;
1742    MacUeCfg *oldMacUeCfg;
1743    ret = ROK;
1744    
1745    GET_CELL_IDX(macUeCfg->cellId, cellIdx);
1746    oldMacUeCfg = &duCb.actvCellLst[cellIdx]->ueCb[macUeCfg->ueIdx-1].macUeCfg;
1747
1748    /*Filling Cell Group Cfg*/
1749    ret =  procUeReCfgCellInfo(macUeCfg, &f1UeDb->duUeCfg.copyOfmacUeCfg, f1UeDb->duUeCfg.cellGrpCfg);
1750    if(ret == ROK)
1751    {
1752       if(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschPresent)
1753       {
1754          fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc,\
1755                &macUeCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, NULL);
1756       }
1757       if(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschPresent)
1758       {
1759          fillStartSymbolAndLen(macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
1760                NULL, &macUeCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg);
1761       }
1762       ret = fillAmbr(NULL, f1UeDb->duUeCfg.ambrCfg, &oldMacUeCfg->ambrCfg, true);
1763       duFillModulationDetails(macUeCfg, oldMacUeCfg, f1UeDb->duUeCfg.ueNrCapability);
1764    }
1765
1766    /* Filling LC Context */
1767    for(dbIdx = 0; (dbIdx < f1UeDb->duUeCfg.numMacLcs && ret == ROK); dbIdx++)
1768    {
1769       numLcs = macUeCfg->numLcs;
1770       for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
1771       {
1772          if(f1UeDb->duUeCfg.macLcCfg[dbIdx].lcId ==  macUeCfg->lcCfgList[lcIdx].lcId)
1773          {
1774             if(f1UeDb->duUeCfg.macLcCfg[dbIdx].configType == CONFIG_MOD)
1775             {
1776                ret = fillMacLcCfgToAddMod(NULL, &f1UeDb->duUeCfg.macLcCfg[dbIdx], &macUeCfg->lcCfgList[lcIdx], true);
1777             }
1778             else if(f1UeDb->duUeCfg.macLcCfg[dbIdx].configType == CONFIG_DEL)
1779             {
1780                /* Free memory at matched  lcIdx index */
1781                freeMacLcCfg(&macUeCfg->lcCfgList[lcIdx]);
1782                macUeCfg->numLcs--;
1783                for(lcDelIdx = lcIdx; lcDelIdx < macUeCfg->numLcs; lcDelIdx++)
1784                {
1785                   /* moving all elements one index ahead */
1786                   ret = fillMacLcCfgToAddMod(NULL,  &macUeCfg->lcCfgList[lcDelIdx+1], &macUeCfg->lcCfgList[lcDelIdx], true);
1787                   freeMacLcCfg(&macUeCfg->lcCfgList[lcDelIdx+1]);
1788                   if(ret == RFAILED)
1789                   {
1790                      DU_LOG("\nERROR  -->  DU APP : Failed to delete LC at Idx %d in duUpdateMacCfg()", lcDelIdx);
1791                      break;
1792                   }
1793                }
1794             }
1795          }
1796       } 
1797       if(f1UeDb->duUeCfg.macLcCfg[dbIdx].configType == CONFIG_ADD)
1798       {
1799          ret = fillMacLcCfgToAddMod(NULL, &f1UeDb->duUeCfg.macLcCfg[dbIdx], &macUeCfg->lcCfgList[numLcs], true);
1800          if(ret == RFAILED)
1801          {
1802             DU_LOG("\nERROR  -->  DU APP : Failed to add LC at Idx %d in duUpdateMacCfg()", numLcs);
1803             break;
1804          }
1805          macUeCfg->numLcs++;
1806       }
1807                 
1808    }
1809    return ret;
1810 }
1811
1812 /******************************************************************
1813  *
1814  * @brief Function to fill the RLC Lc cfg from ueSetupReqDb
1815  *
1816  * @details
1817  *
1818  *    Function : fillRlcCfgToAddMod
1819  *
1820  *    Functionality: Function to fill the RLC Lc cfg from ueSetupReqDb
1821  *
1822  *
1823  *****************************************************************/
1824
1825 uint8_t fillRlcCfgToAddMod(RlcBearerCfg *lcCfg, RlcBearerCfg *f1UeDbLcCfg)
1826 {
1827    lcCfg->configType = f1UeDbLcCfg->configType;
1828    lcCfg->rbId       = f1UeDbLcCfg->rbId;
1829    lcCfg->rbType     = f1UeDbLcCfg->rbType;
1830    lcCfg->lcId       = f1UeDbLcCfg->lcId;
1831    lcCfg->lcType     = f1UeDbLcCfg->lcType;
1832    lcCfg->rlcMode    = f1UeDbLcCfg->rlcMode;
1833    switch(lcCfg->rlcMode)
1834    {
1835       case RLC_AM :
1836       {
1837          if(!lcCfg->u.amCfg)
1838          {
1839             DU_ALLOC_SHRABL_BUF(lcCfg->u.amCfg, sizeof(AmBearerCfg));
1840             if(!lcCfg->u.amCfg)
1841                return RFAILED;
1842          }
1843          /* DL AM */
1844          lcCfg->u.amCfg->dlAmCfg.snLenDl     = f1UeDbLcCfg->u.amCfg->dlAmCfg.snLenDl;    
1845          lcCfg->u.amCfg->dlAmCfg.pollRetxTmr = f1UeDbLcCfg->u.amCfg->dlAmCfg.pollRetxTmr;
1846          lcCfg->u.amCfg->dlAmCfg.pollPdu     = f1UeDbLcCfg->u.amCfg->dlAmCfg.pollPdu;
1847          lcCfg->u.amCfg->dlAmCfg.pollByte    = f1UeDbLcCfg->u.amCfg->dlAmCfg.pollByte;   
1848          lcCfg->u.amCfg->dlAmCfg.maxRetxTh   = f1UeDbLcCfg->u.amCfg->dlAmCfg.maxRetxTh;   
1849  
1850          /* UL AM */
1851          lcCfg->u.amCfg->ulAmCfg.snLenUl     = f1UeDbLcCfg->u.amCfg->ulAmCfg.snLenUl;
1852          lcCfg->u.amCfg->ulAmCfg.reAssemTmr  = f1UeDbLcCfg->u.amCfg->ulAmCfg.reAssemTmr; 
1853          lcCfg->u.amCfg->ulAmCfg.statProhTmr = f1UeDbLcCfg->u.amCfg->ulAmCfg.statProhTmr;
1854          break;
1855       }
1856       case RLC_UM_BI_DIRECTIONAL :
1857       {
1858          if(!lcCfg->u.umBiDirCfg)
1859          {
1860             DU_ALLOC_SHRABL_BUF(lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
1861             if(!lcCfg->u.umBiDirCfg)
1862                 return RFAILED;
1863          }
1864          /* UL UM BI DIR INFO */
1865          lcCfg->u.umBiDirCfg->ulUmCfg.snLenUlUm  = f1UeDbLcCfg->u.umBiDirCfg->ulUmCfg.snLenUlUm;  
1866          lcCfg->u.umBiDirCfg->ulUmCfg.reAssemTmr = f1UeDbLcCfg->u.umBiDirCfg->ulUmCfg.reAssemTmr;
1867          /* DL UM BI DIR INFO */
1868          lcCfg->u.umBiDirCfg->dlUmCfg.snLenDlUm  = f1UeDbLcCfg->u.umBiDirCfg->dlUmCfg.snLenDlUm;
1869          break;
1870       }
1871       case RLC_UM_UNI_DIRECTIONAL_UL :
1872       {
1873          if(!lcCfg->u.umUniDirUlCfg)
1874          {
1875             DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
1876             if(!lcCfg->u.umUniDirUlCfg)
1877                return RFAILED;
1878          }
1879          lcCfg->u.umUniDirUlCfg->ulUmCfg.snLenUlUm  = f1UeDbLcCfg->u.umUniDirUlCfg->ulUmCfg.snLenUlUm;  
1880          lcCfg->u.umUniDirUlCfg->ulUmCfg.reAssemTmr = f1UeDbLcCfg->u.umUniDirUlCfg->ulUmCfg.reAssemTmr;
1881          break;
1882
1883       }
1884       case RLC_UM_UNI_DIRECTIONAL_DL :
1885       {
1886          if(!lcCfg->u.umUniDirDlCfg)
1887          {
1888             DU_ALLOC_SHRABL_BUF(lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
1889             if(!lcCfg->u.umUniDirDlCfg)
1890                return RFAILED;
1891          }
1892          lcCfg->u.umUniDirDlCfg->dlUmCfg.snLenDlUm  = f1UeDbLcCfg->u.umUniDirDlCfg->dlUmCfg.snLenDlUm;
1893          break;
1894       }
1895       default:
1896          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at fillRlcCfgToAddMod()", lcCfg->rlcMode);
1897          return RFAILED;
1898    }
1899    return ROK;
1900 }
1901
1902 /*******************************************************************
1903  *
1904  * @brief To update DuUeCb Rlc Lc Cfg
1905  *
1906  * @details
1907  *
1908  *    Function : duUpdateRlcLcCfg
1909  *    Functionality:  update DuUeCb Rlc Lc Cfg
1910  *
1911  * @params[in] DuUeCb Pointer
1912  *             F1UeContextSetupDb pointer 
1913  * @return ROK     - success
1914  *         RFAILED - failure
1915  *
1916  * ****************************************************************/
1917
1918 uint8_t duUpdateRlcLcCfg(RlcUeCfg *rlcUeCfg, F1UeContextSetupDb *f1UeDb)
1919 {
1920    uint8_t ret, lcIdx, dbIdx, numLcs, lcDelIdx;
1921
1922    ret = ROK;
1923    for(dbIdx = 0; (dbIdx < f1UeDb->duUeCfg.numRlcLcs && ret ==ROK); dbIdx++)
1924    {
1925       numLcs = rlcUeCfg->numLcs;
1926       for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
1927       {
1928          if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].lcId == rlcUeCfg->rlcLcCfg[lcIdx].lcId)
1929          {
1930             if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].configType == CONFIG_MOD)
1931             {
1932                ret = fillRlcCfgToAddMod(&rlcUeCfg->rlcLcCfg[lcIdx], &f1UeDb->duUeCfg.rlcLcCfg[dbIdx]);
1933             }
1934             else if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].configType == CONFIG_DEL)
1935             {
1936                /* Free memory at matched lcIdx index */
1937                freeRlcLcCfg(&rlcUeCfg->rlcLcCfg[lcIdx]);
1938                rlcUeCfg->numLcs--;
1939                for(lcDelIdx = lcIdx; lcDelIdx < rlcUeCfg->numLcs; lcDelIdx++)
1940                {
1941                   ret = fillRlcCfgToAddMod(&rlcUeCfg->rlcLcCfg[lcDelIdx], &rlcUeCfg->rlcLcCfg[lcDelIdx+1]);
1942                   freeRlcLcCfg(&rlcUeCfg->rlcLcCfg[lcDelIdx+1]);
1943                   if(ret == RFAILED)
1944                   {
1945                      DU_LOG("\nERROR  -->  DU APP : Failed to delete LC at Idx %d in duUpdateRlcCfg()", lcDelIdx);
1946                      break;
1947                   }
1948                }
1949             }
1950          }
1951       }
1952       if(f1UeDb->duUeCfg.rlcLcCfg[dbIdx].configType == CONFIG_ADD)
1953       {
1954          ret = fillRlcCfgToAddMod(&rlcUeCfg->rlcLcCfg[lcIdx], &f1UeDb->duUeCfg.rlcLcCfg[dbIdx]);
1955          if(ret == ROK)
1956             rlcUeCfg->numLcs++;
1957       }
1958    }
1959    return ret;
1960 }
1961
1962
1963 /*******************************************************************
1964  *
1965  * @brief Function to fill Tunnel Config to Add/Mod
1966  * 
1967  *
1968  * @details
1969  *
1970  *    Function : fillTnlCfgToAddMod
1971  *
1972  *    Functionality: Function to fill tunnel Config to Add/Mod
1973  *
1974  * @params[in] Pointer to tnlCfgDb,
1975  *             pointer to f1TnlCfg
1976  * @return ROK     - success
1977  *         RFAILED - failure
1978  *
1979  * ****************************************************************/
1980 uint8_t fillTnlCfgToAddMod(UpTnlCfg **ueCbTnlCfg, UpTnlCfg *f1TnlCfg)
1981 {
1982    if(*ueCbTnlCfg)
1983    {
1984       DU_FREE((*ueCbTnlCfg)->tnlCfg1, sizeof(GtpTnlCfg));
1985       DU_FREE(*ueCbTnlCfg, sizeof(UpTnlCfg));
1986    }
1987
1988    if(*ueCbTnlCfg == NULLP)
1989    {
1990       /* copying to DuCb Tnl Cfg */
1991       DU_ALLOC(*ueCbTnlCfg, sizeof(UpTnlCfg));
1992       if(*ueCbTnlCfg == NULLP)
1993       {
1994          DU_LOG("\nERROR  -->  DU_APP : fillTnlCfgToAddMod: Memory Alloc failed for drbId[%d]", f1TnlCfg->drbId);
1995          return RFAILED;
1996       }
1997    }
1998    memset(*ueCbTnlCfg, 0, sizeof(UpTnlCfg));
1999    (*ueCbTnlCfg)->configType = f1TnlCfg->configType;
2000    (*ueCbTnlCfg)->cellId    = f1TnlCfg->cellId;
2001    (*ueCbTnlCfg)->ueIdx     = f1TnlCfg->ueIdx;
2002    (*ueCbTnlCfg)->drbId     = f1TnlCfg->drbId;
2003    if(f1TnlCfg->tnlCfg1)
2004    {
2005       if((*ueCbTnlCfg)->tnlCfg1 == NULLP)
2006       {
2007          DU_ALLOC((*ueCbTnlCfg)->tnlCfg1, sizeof(GtpTnlCfg));
2008          if((*ueCbTnlCfg)->tnlCfg1 == NULLP)
2009          {
2010             DU_LOG("\nERROR  -->  DU_APP : fillTnlCfgToAddMod: Memory Alloc failed for tnlCfg1 for drbId[%d]", f1TnlCfg->drbId);
2011             return RFAILED;
2012          }
2013       }
2014       memset((*ueCbTnlCfg)->tnlCfg1, 0, sizeof(GtpTnlCfg));
2015       (*ueCbTnlCfg)->tnlCfg1->teId = f1TnlCfg->tnlCfg1->teId;
2016       (*ueCbTnlCfg)->tnlCfg1->ulTnlAddress = f1TnlCfg->tnlCfg1->ulTnlAddress;
2017       (*ueCbTnlCfg)->tnlCfg1->dlTnlAddress = f1TnlCfg->tnlCfg1->dlTnlAddress;
2018    }
2019    return ROK;
2020 }
2021
2022 /*******************************************************************
2023  *
2024  * @brief Processing the tunnel Request to EGTP
2025  *        
2026  * @details
2027  *
2028  *    Function : duProcEgtpTunnelCfg
2029  *
2030  *    Functionality: Processing the tunnel Request to EGTP
2031  *
2032  * @params[in] UptnlCfg *duTnlCfg, UpTnlCfg *f1TnlCfg 
2033  * @return ROK     - success
2034  *         RFAILED - failure
2035  *
2036  * ****************************************************************/
2037
2038 uint8_t duProcEgtpTunnelCfg(uint8_t ueCbIdx, UpTnlCfg *duTnlCfg, UpTnlCfg *f1TnlCfg)
2039 {
2040    uint8_t ret = RFAILED, delIdx;
2041
2042    if(f1TnlCfg->tnlCfg1 == NULLP)
2043    {
2044       DU_LOG("\nERROR  -->  DU_APP : Tunnel config not found");
2045       return ret;
2046    }
2047
2048    if(f1TnlCfg->configType == CONFIG_ADD)
2049    {
2050       if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_ADD, NULLP, f1TnlCfg->tnlCfg1) == ROK)
2051       {
2052          if(fillTnlCfgToAddMod(&duCb.upTnlCfg[duCb.numDrb], f1TnlCfg) == ROK)
2053          {
2054             duCb.numDrb++;
2055             ret = ROK;
2056          }
2057       }      
2058    }
2059    else if(f1TnlCfg->configType == CONFIG_MOD)
2060    {
2061       if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_MOD, duTnlCfg->tnlCfg1->teId, f1TnlCfg->tnlCfg1) == ROK)
2062       {
2063          if(fillTnlCfgToAddMod(&duTnlCfg, f1TnlCfg) == ROK)
2064          {
2065             ret = ROK;
2066          }
2067       }   
2068    }
2069    else if(f1TnlCfg->configType == CONFIG_DEL)
2070    {
2071       if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_DEL, duTnlCfg->tnlCfg1->teId, f1TnlCfg->tnlCfg1) == ROK)
2072       {    
2073          /* Free memory at drbIdx */
2074          duCb.numDrb--;
2075          for(delIdx = ueCbIdx; delIdx < duCb.numDrb; delIdx++)
2076          {
2077             /* moving all elements one index ahead */
2078             ret = fillTnlCfgToAddMod(&duCb.upTnlCfg[delIdx], duCb.upTnlCfg[delIdx+1]);
2079             if(ret != ROK)
2080             {
2081                return ret;
2082             }
2083          }
2084          if(duCb.upTnlCfg[delIdx])
2085          {
2086             DU_FREE(duCb.upTnlCfg[delIdx]->tnlCfg1, sizeof(GtpTnlCfg));
2087             DU_FREE(duCb.upTnlCfg[delIdx], sizeof(UpTnlCfg));
2088          }
2089       }   
2090    }
2091    return ret;
2092 }
2093
2094 /***********************************************************************
2095  *
2096  * @brief Function to fill Tunnel Config
2097  *        and sends tunnel Req to EGTP
2098  * 
2099  *
2100  * @details
2101  *
2102  *    Function : duUpdateTunnelCfgDb
2103  *
2104  *    Functionality: Function to fill tunnel Config
2105  *                   and sends tunnel Cfg Req to EGTP
2106  *
2107  * @params[in] ueIdx, cellId, DuUeCfg 
2108  * @return ROK     - success
2109  *         RFAILED - failure
2110  *
2111  * ****************************************************************/
2112
2113 uint8_t duUpdateTunnelCfgDb(uint8_t ueIdx, uint8_t cellId, DuUeCfg *duUeCfg)
2114 {
2115    uint8_t ret = ROK, drbIdx, duCbDrbIdx;
2116    bool drbFound = false;
2117
2118    /*If Add/Mod tunnels request for that DRB is successful in EGTP */
2119    /*then update drbId and tunnel Info in duCb */
2120    for(drbIdx=0; drbIdx < duUeCfg->numDrb; drbIdx++)
2121    {
2122       duUeCfg->upTnlInfo[drbIdx].cellId = cellId;
2123       duUeCfg->upTnlInfo[drbIdx].ueIdx = ueIdx;
2124       for(duCbDrbIdx = 0; duCbDrbIdx < duCb.numDrb; duCbDrbIdx++)
2125       {
2126          if(duCb.upTnlCfg[duCbDrbIdx]->drbId == duUeCfg->upTnlInfo[drbIdx].drbId)
2127          {
2128             drbFound = true; /* existing DRB */
2129             if(duProcEgtpTunnelCfg(duCbDrbIdx, duCb.upTnlCfg[duCbDrbIdx], &duUeCfg->upTnlInfo[drbIdx]) != ROK)
2130             {
2131                DU_LOG("\nERROR  -> DU_APP : duUpdateTunnelCfgDb: Failed to modify tunnel req for Drb id[%d]",
2132                duUeCfg->upTnlInfo[drbIdx].drbId);
2133                ret = RFAILED;
2134             }
2135             break;
2136          }
2137          else
2138             drbFound = false;
2139       }
2140       if(!drbFound && ret == ROK)/* new DRB to Add */
2141       {
2142          if(duProcEgtpTunnelCfg(NULLP, NULLP, &duUeCfg->upTnlInfo[drbIdx]) != ROK)
2143          {
2144             DU_LOG("\nERROR  -> DU_APP : duUpdateTunnelCfgDb: Failed to add tunnel req for Drb id[%d]",
2145             duUeCfg->upTnlInfo[drbIdx].drbId);
2146             ret = RFAILED;
2147             break;
2148          }
2149       }
2150       else
2151          break;
2152    }
2153    return ret;
2154 }
2155
2156 /*******************************************************************
2157  *
2158  * @brief @brief To update DuUeCb Mac and Rlc Ue Cfg
2159  * 
2160  *
2161  * @details
2162  *
2163  *    Function : duUpdateDuUeCbCfg
2164  *
2165  *    Functionality: update DuUeCb Mac and Rlc Ue Cfg
2166  *
2167  * @params[in] ueIdx, cellIdx 
2168  * @return ROK     - success
2169  *         RFAILED - failure
2170  *
2171  * ****************************************************************/
2172
2173 uint8_t duUpdateDuUeCbCfg(uint8_t ueIdx, uint8_t cellId)
2174 {
2175    uint8_t ret = ROK, cellIdx = 0, crnti=0;
2176    DuUeCb *ueCb = NULLP;
2177
2178    GET_CELL_IDX(cellId, cellIdx);
2179    
2180    if((duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg. \
2181          macUeCfgState == UE_RECFG_COMPLETE) &&
2182       (duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg. \
2183          rlcUeCfgState == UE_RECFG_COMPLETE))
2184    {
2185       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1];
2186
2187       /*Filling RLC Ue Cfg */
2188       ueCb->rlcUeCfg.cellId = cellId;
2189       ueCb->rlcUeCfg.ueIdx  = ueIdx;
2190       ret = duUpdateRlcLcCfg(&ueCb->rlcUeCfg, ueCb->f1UeDb);
2191       if(ret == ROK)
2192       {
2193          /*Filling MAC Ue Cfg */
2194          GET_CRNTI(crnti, ueIdx);
2195          ueCb->macUeCfg.cellId = cellId;
2196          ueCb->macUeCfg.ueIdx  = ueIdx;
2197          ueCb->macUeCfg.crnti  = crnti;
2198          ret = duUpdateMacCfg(&ueCb->macUeCfg, ueCb->f1UeDb);
2199          if(ret == RFAILED)
2200             DU_LOG("\nERROR  -->  DU APP : Failed while updating MAC LC Config at duUpdateDuUeCbCfg()");
2201          else
2202          {
2203             if(duUpdateTunnelCfgDb(ueIdx, cellId, &ueCb->f1UeDb->duUeCfg) != ROK)
2204             {
2205                DU_LOG("\nERROR  -->  DU_APP : Failed to establish tunnel in duUpdateDuUeCbCfg()");
2206                     return RFAILED;
2207             }
2208          }
2209       }
2210       else
2211          DU_LOG("\nERROR  -->  DU APP : Failed while updating RLC LC Config at duUpdateDuUeCbCfg()");
2212    }
2213    else
2214       ret = RFAILED;
2215    return ret;
2216 }
2217
2218 /*******************************************************************
2219  *
2220  * @brief Handle UE config response from MAC
2221  *
2222  * @details
2223  *
2224  *    Function : DuProcMacUeCfgRsp
2225  *
2226  *    Functionality: Handle UE Config response from MAC
2227  *
2228  * @params[in] Pointer to MacUeCfgRsp and Pst 
2229  * @return ROK     - success
2230  *         RFAILED - failure
2231  *
2232  * ****************************************************************/
2233 uint8_t DuProcMacUeCfgRsp(Pst *pst, MacUeCfgRsp *cfgRsp)
2234 {
2235    uint8_t ret = ROK;
2236
2237    if(cfgRsp)
2238    {
2239       if(cfgRsp->result == MAC_DU_APP_RSP_OK)
2240       {
2241          if(pst->event == EVENT_MAC_UE_CREATE_RSP)
2242          {
2243             DU_LOG("\nINFO   -->  DU APP : MAC UE Create Response : SUCCESS [UE IDX : %d]", cfgRsp->ueIdx);
2244             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueIdx -1].\
2245                macUeCfg.macUeCfgState = UE_CREATE_COMPLETE;
2246          }
2247          else if(pst->event == EVENT_MAC_UE_RECONFIG_RSP)
2248          {
2249             DU_LOG("\nINFO   -->  DU APP : MAC UE Reconfig Response : SUCCESS [UE IDX : %d]", cfgRsp->ueIdx);
2250             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueIdx -1].\
2251                macUeCfg.macUeCfgState = UE_RECFG_COMPLETE;
2252             if((ret = duUpdateDuUeCbCfg(cfgRsp->ueIdx, cfgRsp->cellId)) == ROK)
2253             {
2254                BuildAndSendUeCtxtRsp(cfgRsp->cellId, cfgRsp->ueIdx);
2255             }
2256          }
2257       }
2258       else
2259       {
2260          DU_LOG("\nERROR  -->  DU APP : MAC UE CFG Response for EVENT[%d]: FAILURE [UE IDX : %d]", pst->event, cfgRsp->ueIdx);
2261          if(pst->event == EVENT_MAC_UE_RECONFIG_RSP)
2262          {
2263             //TODO: Send the failure case in Ue Context Setup Response
2264          }
2265          ret = RFAILED;
2266       }
2267       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(MacUeCfgRsp));
2268    }
2269    else
2270    {
2271       DU_LOG("\nERROR  -->  DU APP : Received MAC Ue Config Response is NULL at DuProcMacUeCfgRsp()");
2272       ret = RFAILED;
2273    }
2274    return ret;
2275 }
2276
2277
2278 /*******************************************************************
2279  *
2280  * @brief Processes UE create Req to RLC UL
2281  *
2282  * @details
2283  *
2284  *    Function : duBuildAndSendUeCreateReqToRlc
2285  *
2286  *    Functionality: 
2287  *     Processes UE create Req to RLC UL
2288  * 
2289  *  @params[in]  cellId,
2290  *               ueIdx,
2291  *               Pointer to RlcUeCfg
2292  *  @return ROK     - success
2293  *          RFAILED - failure
2294  * 
2295  *****************************************************************/
2296
2297 uint8_t duBuildAndSendUeCreateReqToRlc(uint16_t cellId, uint8_t ueIdx,\
2298    RlcUeCfg *duRlcUeCfg)
2299 {
2300    uint8_t  ret = ROK;
2301    RlcUeCfg *rlcUeCfg = NULLP;
2302    Pst       pst;
2303   
2304    ret = fillRlcUeCfg(cellId, ueIdx, NULL, duRlcUeCfg);
2305    if(ret == RFAILED)
2306    {
2307       DU_LOG("\nERROR  -->  DU APP : Failed to fill Rlc Ue Cfg at duBuildAndSendUeCreateReqToRlc()");
2308       return ret;
2309    }
2310
2311    FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_CREATE_REQ);
2312    /* Copying ueCfg to a sharable buffer */
2313    DU_ALLOC_SHRABL_BUF(rlcUeCfg, sizeof(RlcUeCfg));
2314    if(rlcUeCfg)
2315    {
2316       memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
2317       memcpy(rlcUeCfg, duRlcUeCfg, sizeof(RlcUeCfg));
2318       /* Processing one Ue at a time to RLC */
2319       DU_LOG("\nDEBUG   -->  DU_APP: Sending UE create request to RLC UL");
2320       ret = (*packRlcUeCreateReqOpts[pst.selector])(&pst, rlcUeCfg);
2321       if(ret == RFAILED)
2322       {
2323          DU_LOG("\nERROR  -->  DU_APP : Failure in sending Ue Create Req to RLC");
2324          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rlcUeCfg, sizeof(RlcUeCfg));
2325          ret = RFAILED;
2326       }
2327    }
2328    else
2329    {
2330       DU_LOG("\n ERROR  -->  DU APP : Memory alloc failed at duBuildAndSendUeCreateReqToRlc()");
2331       ret = RFAILED;
2332    }
2333    return ret;
2334 }
2335
2336 /*******************************************************************
2337  *
2338  * @brief Processes UE create Rsp received from RLC UL
2339  *
2340  * @details
2341  *
2342  
2343  *    Function : DuProcRlcUeCfgRsp
2344  *
2345  *    Functionality: 
2346  *     Processes UE create Rsp received from RLC UL
2347  * 
2348  *  @params[in]  Post structure
2349  *               Pointer to RlcCfgCfm
2350  *  @return ROK     - success
2351  *          RFAILED - failure
2352  * 
2353  *****************************************************************/
2354 uint8_t DuProcRlcUeCfgRsp(Pst *pst, RlcUeCfgRsp *cfgRsp)
2355 {
2356    uint8_t ret = ROK;
2357
2358    if(cfgRsp)
2359    {
2360       if(cfgRsp->result == RLC_DU_APP_RSP_OK)
2361       {
2362          if(pst->event == EVENT_RLC_UE_CREATE_RSP)
2363          {
2364             DU_LOG("\nINFO   -->  DU_APP: RLC UE Create Response : SUCCESS [UE IDX:%d]", cfgRsp->ueIdx);
2365             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueIdx -1].\
2366                rlcUeCfg.rlcUeCfgState = UE_CREATE_COMPLETE;
2367          }
2368          else if(pst->event == EVENT_RLC_UE_RECONFIG_RSP)
2369          {
2370             DU_LOG("\nINFO   -->  DU_APP: RLC UE Reconfig Response : SUCCESS [UE IDX:%d]", cfgRsp->ueIdx);
2371             duCb.actvCellLst[cfgRsp->cellId -1]->ueCb[cfgRsp->ueIdx -1].\
2372                rlcUeCfg.rlcUeCfgState = UE_RECFG_COMPLETE;
2373             if((ret = duUpdateDuUeCbCfg(cfgRsp->ueIdx, cfgRsp->cellId)) == ROK)
2374             {
2375                BuildAndSendUeCtxtRsp(cfgRsp->cellId, cfgRsp->ueIdx);
2376             }   
2377          }
2378       }
2379       else
2380       {
2381          DU_LOG("\nERROR  -->  DU_APP: RLC UE CFG Response for EVENT[%d] : FAILED [UE IDX : %d, REASON :%d]",\
2382                pst->event, cfgRsp->ueIdx, cfgRsp->reason);
2383          if((pst->event == EVENT_RLC_UE_RECONFIG_RSP))
2384          {
2385             //TODO: update failure case in ue Context setup Response
2386          }
2387          ret = RFAILED;
2388       }
2389       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(RlcUeCfgRsp));
2390    }
2391    else
2392    {
2393       DU_LOG("\nERROR  -->  DU_APP: Received RLC Ue Config Response is NULL at DuProcRlcUeCfgRsp()");
2394       ret = RFAILED;
2395    }
2396    return ret;
2397 }
2398
2399 /*******************************************************************
2400  *
2401  * @brief Builds and Send Ue Reconfig Req to RLC
2402  *
2403  * @details
2404  *
2405  *    Function : duBuildAndSendUeReCfgReqToRLC
2406  *
2407  *    Functionality: Builds and Send Ue Reconfig Req to RLC
2408  *
2409  * @params[in] cellId, crnti
2410  *             DuUeCfg *ueCfgDb
2411  *             RlcUeCfg *rlcUeCfg
2412  * @return ROK     - success
2413  *         RFAILED - failure
2414  *
2415  * ****************************************************************/
2416
2417 uint8_t duBuildAndSendUeReCfgReqToRlc(uint8_t cellId, uint8_t crnti, DuUeCfg *ueCfgDb)
2418 {
2419    uint8_t ret = ROK, ueIdx = 0;
2420    RlcUeCfg *rlcUeCfg = NULLP;
2421
2422    GET_UE_IDX(crnti, ueIdx);
2423    DU_ALLOC_SHRABL_BUF(rlcUeCfg, sizeof(RlcUeCfg));
2424    if(rlcUeCfg)
2425    {
2426       memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
2427       ret = fillRlcUeCfg(cellId, ueIdx, ueCfgDb, rlcUeCfg);
2428       if(ret == RFAILED)
2429          DU_LOG("\nERROR  -->  DU APP : Failed at duBuildAndSendUeReCfgReqToRlc()");
2430       else
2431          ret = sendUeReCfgReqToRlc(rlcUeCfg);
2432    }
2433    else
2434    {
2435       DU_LOG("\nERROR  -->  DU APP : Memory Alloc failed at duBuildAndSendUeReCfgReqToRlc()");
2436       ret = RFAILED;
2437    }
2438    return ret;
2439 }
2440
2441 /*******************************************************************
2442  *
2443  * @brief Builds and Send Ue Reconfig Req to MAC
2444  *
2445  * @details
2446  *
2447  *    Function : duBuildAndSendUeReCfgReqToMac
2448  *
2449  *    Functionality: Builds and Send Ue Reconfig Req to MAC
2450  *
2451  * @params[in] CellGroupConfigRrc_t *macCellGrpCfg
2452  *             DuUeCfg *ueCfgDb
2453  *             MacUeCfg    *macUeCfg
2454  * @return ROK     - success
2455  *         RFAILED - failure
2456  *
2457  * ****************************************************************/
2458
2459 uint8_t duBuildAndSendUeReCfgReqToMac(uint8_t cellId, uint8_t crnti, DuUeCfg *ueCfgDb)
2460 {
2461    uint8_t ret, ueIdx = 0;
2462    MacUeCfg *macUeCfg = NULLP;
2463
2464    ret = ROK;
2465    GET_UE_IDX(crnti, ueIdx);
2466
2467    DU_ALLOC_SHRABL_BUF(macUeCfg, sizeof(MacUeCfg));
2468    if(macUeCfg)
2469    {
2470       memset(macUeCfg, 0, sizeof(MacUeCfg));
2471       ret = fillMacUeCfg(cellId, ueIdx, crnti, ueCfgDb, macUeCfg);
2472       if(ret == RFAILED)
2473          DU_LOG("\nERROR  -->  DU APP : Failed to fill Mac Ue Cfg at duBuildAndSendUeReCfgReqToMac()");
2474       else
2475          ret = sendUeReCfgReqToMac(macUeCfg);
2476    }
2477    else
2478    {
2479       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed for macUeCfg at duBuildAndSendUeReCfgReqToMac()");
2480       ret = RFAILED;
2481    }
2482    return ret;
2483 }
2484
2485 /*******************************************************************
2486  *
2487  * @brief Build and Send Ue context setup request
2488  *
2489  * @details
2490  *
2491  
2492  *    Function : duBuildAndSendUeContextSetupReq
2493  *
2494  *    Functionality: 
2495  *     Build and Send Ue context setup request
2496  * 
2497  *  @params[in]  cellId, crnti, DuUeCfg pointer
2498  *  @return ROK     - success
2499  *          RFAILED - failure
2500  * 
2501  *****************************************************************/
2502
2503 uint8_t duBuildAndSendUeContextSetupReq(uint16_t cellId, uint16_t crnti, DuUeCfg *duUeCfg)
2504 {
2505    uint8_t ret = ROK;
2506
2507    DU_LOG("\nDEBUG   -->  DU_APP: Processing Ue Context Setup Request for cellId [%d]", cellId);
2508    /* Filling RLC Ue Reconfig */ 
2509    ret = duBuildAndSendUeReCfgReqToRlc(cellId, crnti, duUeCfg);
2510    if(ret == RFAILED)
2511       DU_LOG("\nERROR  -->  DU APP : Failed to build ctxt setup req for RLC at duBuildAndSendUeContextSetupReq()");
2512    
2513    /* Filling MAC Ue Reconfig */
2514    ret = duBuildAndSendUeReCfgReqToMac(cellId, crnti, duUeCfg);
2515    if(ret == RFAILED)
2516       DU_LOG("\nERROR  -->  DU APP : Failed at build ctxt setup req for MAC at duBuildAndSendUeContextSetupReq()");
2517
2518    return ret;
2519 }
2520
2521 /*******************************************************************
2522  *
2523  * @brief Processes DL Rsp received from RLC DL
2524  *
2525  * @details
2526  *
2527  
2528  *    Function : DuProcRlcDlRrcMsgRsp
2529  *
2530  *    Functionality: 
2531  *     Processes UE Rsp received from RLC DL
2532  * 
2533  *  @params[in]  Post structure
2534  *               Pointer to RlcCfgCfm
2535  *  @return ROK     - success
2536  *          RFAILED - failure
2537  * 
2538  *****************************************************************/
2539 uint8_t DuProcRlcDlRrcMsgRsp(Pst *pst, RlcDlRrcMsgRsp *dlRrcMsg)
2540 {
2541    uint8_t ret = ROK, ueIdx = 0;
2542    uint16_t cellId, crnti;
2543    DuUeCb *ueCb = NULLP;
2544    DlMsgState state;
2545
2546    state = dlRrcMsg->state;
2547    cellId = dlRrcMsg->cellId;
2548    crnti = dlRrcMsg->crnti;
2549    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlRrcMsg, sizeof(RlcDlRrcMsgRsp));
2550
2551    if(state == TRANSMISSION_COMPLETE)
2552    {
2553       GET_UE_IDX(crnti, ueIdx);
2554       ueCb = &duCb.actvCellLst[cellId -1]->ueCb[ueIdx -1];
2555
2556       if(ueCb->f1UeDb && ueCb->f1UeDb->dlRrcMsgPres)
2557       {
2558          if(ueCb->f1UeDb->actionType == UE_CTXT_SETUP)
2559          {
2560             ret = duBuildAndSendUeContextSetupReq(cellId, crnti, &ueCb->f1UeDb->duUeCfg);
2561             if(ret == RFAILED)
2562                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Setup Request in DuProcRlcDlRrcMsgRsp()");
2563          }
2564          
2565          if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
2566          {
2567             ret = duBuildAndSendUeContextModReq(cellId, crnti, &ueCb->f1UeDb->duUeCfg);
2568             if(ret == RFAILED)
2569                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Mod Request in DuProcRlcDlRrcMsgRsp()");
2570          }
2571
2572          if(ueCb->f1UeDb->actionType == UE_CTXT_RELEASE && ueCb->ueState == UE_ACTIVE)
2573          {
2574             ret = duBuildAndSendUeDeleteReq(cellId, crnti);
2575             if(ret == RFAILED)
2576             {
2577                DU_LOG("\nERROR  -->  DU APP : Failed to process UE Context Release Request in DuProcRlcDlRrcMsgRsp()");
2578             }
2579          }
2580       }
2581    }
2582    else
2583       DU_LOG("\nERROR  -->  DU APP : Failed to transmit DL RRC Msg");
2584
2585    return ret;
2586 }
2587 /*******************************************************************
2588  *
2589  * @brief Process UE context setup request from CU
2590  *
2591  * @details
2592  *
2593  *    Function : duProcUeContextSetupRequest 
2594  *
2595  *    Functionality: Process UE context setup request from CU
2596  *
2597  * @params[in] F1AP message
2598  * @return ROK     - success
2599  *         RFAILED - failure
2600  *
2601  * ****************************************************************/
2602
2603 uint8_t duProcUeContextSetupRequest(DuUeCb *ueCb)
2604 {
2605    uint8_t ret, cellId;
2606
2607    ret = ROK;
2608    if(ueCb)
2609    {
2610       cellId = duCb.actvCellLst[ueCb->f1UeDb->cellIdx]->cellId;
2611       /* Send DL RRC msg for security Mode */
2612       if(ueCb->f1UeDb->dlRrcMsg)
2613       {
2614          if(ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
2615          {
2616             /* Sending DL RRC Message to RLC */
2617             ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->rlcUeCfg, ueCb->f1UeDb->dlRrcMsg);
2618             if(ret == RFAILED)
2619             {
2620                DU_LOG("\nERROR  -->  DU APP : Failed to send DL RRC msg in duProcUeContextSetupRequest()");
2621                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
2622                      ueCb->f1UeDb->dlRrcMsg->rrcMsgSize);
2623                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
2624             }
2625          }
2626       }
2627       else if(ueCb->f1UeDb->actionType == UE_CTXT_SETUP)
2628       {
2629          ret = duBuildAndSendUeContextSetupReq(cellId, ueCb->crnti, &ueCb->f1UeDb->duUeCfg);
2630          if(ret == RFAILED)
2631          {
2632             DU_LOG("\nERROR  -->  DU APP : Failed to build ue context setup Req in duProcUeContextSetupRequest()");
2633          }
2634       }
2635    }
2636    else
2637    {
2638       //TODO: To send the failure cause in UeContextSetupRsp
2639       DU_LOG("ERROR  -->  DU APP : Failed to process UE CNTXT SETUP REQ at duProcUeContextSetupRequest()");
2640    }
2641    return ret;
2642 }
2643
2644 /*******************************************************************
2645  *
2646  * @brief Build and Send Ue context mod request
2647  *
2648  * @details
2649  *
2650  *
2651  *    Function : duBuildAndSendUeContextModReq
2652  *
2653  *    Functionality: 
2654  *     Build and Send Ue context mod request
2655  * 
2656  *  @params[in]  cellId, crnti, DuUeCfg pointer
2657  *  @return ROK     - success
2658  *          RFAILED - failure
2659  * 
2660  *****************************************************************/
2661
2662 uint8_t duBuildAndSendUeContextModReq(uint16_t cellId, uint16_t crnti, DuUeCfg *duUeCfg)
2663 {
2664    uint8_t ret = ROK;
2665
2666    DU_LOG("\nDEBUG   -->  DU_APP: Processing Ue Context Mod Request for cellId [%d]", cellId);
2667    /* Filling RLC Ue Reconfig */ 
2668    ret = duBuildAndSendUeReCfgReqToRlc(cellId, crnti, duUeCfg);
2669    if(ret == RFAILED)
2670       DU_LOG("\nERROR  -->  DU APP : Failed to build ctxt setup req for RLC at duBuildAndSendUeContextModReq()");
2671    
2672    /* Filling MAC Ue Reconfig */
2673    ret = duBuildAndSendUeReCfgReqToMac(cellId, crnti, duUeCfg);
2674    if(ret == RFAILED)
2675       DU_LOG("\nERROR  -->  DU APP : Failed at build ctxt setup req for MAC at duBuildAndSendUeContextModReq()");
2676
2677    return ret;
2678 }
2679 /*******************************************************************
2680  *
2681  * @brief Processing Ue context mod request
2682  *
2683  * @details
2684  *
2685  *
2686  *    Function : duProcUeContextModReq 
2687  *
2688  *    Functionality:
2689  *        Processing  Ue context mod request
2690  *
2691  *  @params[in] DuUeCb *ueCb 
2692  *  @return ROK     - success
2693  *          RFAILED - failure
2694  *
2695  *****************************************************************/
2696
2697 uint8_t duProcUeContextModReq(DuUeCb *ueCb)
2698 {
2699    uint8_t ret, cellId;
2700
2701    ret = ROK;
2702    if(ueCb)
2703    {
2704       cellId = duCb.actvCellLst[ueCb->f1UeDb->cellIdx]->cellId;
2705       /* Send DL RRC msg for security Mode */
2706       if(ueCb->f1UeDb->dlRrcMsg)
2707       {
2708          if(ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
2709          {
2710             /* Sending DL RRC Message to RLC */
2711             ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->rlcUeCfg, ueCb->f1UeDb->dlRrcMsg);
2712             if(ret == RFAILED)
2713             {
2714                DU_LOG("\nERROR  -->  DU APP : Failed to send DL RRC msg in duProcUeContextModReq()");
2715                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
2716                      ueCb->f1UeDb->dlRrcMsg->rrcMsgSize);
2717                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
2718             }
2719          }
2720       }
2721       else
2722       {
2723          ret = duBuildAndSendUeContextModReq(cellId, ueCb->crnti, &ueCb->f1UeDb->duUeCfg);
2724          if(ret == RFAILED)
2725          {
2726             DU_LOG("\nERROR  -->  DU APP : Failed to build ue context setup Req in duProcUeContextModReq()");
2727          }
2728       }
2729    }
2730    else
2731    {
2732       //TODO: To send the failure cause in UeContextModRsp
2733       DU_LOG("ERROR  -->  DU APP : Failed to process UE CNTXT MOD REQ at duProcUeContextModReq()");
2734    }
2735    return ROK;
2736 }
2737
2738 /*******************************************************************
2739 *
2740 * @brief Function to delete Pdsch ServCellCfg
2741 *
2742 * @details
2743 *
2744 *    Function : deletePdschServCellCfg
2745 *
2746 *    Functionality: Function to delete Pdsch ServCellCfg
2747 *
2748 * @params[in] PdschServCellCfg *pdschServCellCfg
2749 * @return void
2750 *
2751 * ****************************************************************/
2752
2753 void deletePdschServCellCfg(PdschServCellCfg *pdschServCellCfg)
2754 {
2755    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
2756    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
2757    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
2758    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,pdschServCellCfg->xOverhead, sizeof(PdschXOverhead));
2759 }
2760
2761 /*******************************************************************
2762  *
2763 * @brief delete MacUeCfg from duCb
2764 *
2765 * @details
2766 *
2767 *    Function : deleteMacUeCfg 
2768 *
2769 *    Functionality: delete MacUeCfg from duCb
2770 *
2771 * @params[in] Pointer to MacUeCfg 
2772 * @return ROK     - success
2773 *         RFAILED - failure
2774 *
2775 *******************************************************************/
2776
2777 void deleteMacUeCfg(MacUeCfg *ueCfg)
2778 {
2779    uint8_t lcCfgIdx=0;
2780    
2781    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,ueCfg->ambrCfg, sizeof(AmbrCfg));
2782    if(ueCfg->spCellCfgPres)
2783    {
2784       freeUeReCfgCellGrpInfo(ueCfg);
2785    }
2786    for(lcCfgIdx=0; lcCfgIdx< ueCfg->numLcs; lcCfgIdx++)
2787    {
2788       freeMacLcCfg(&ueCfg->lcCfgList[lcCfgIdx]);
2789    }
2790    memset(ueCfg, 0, sizeof(MacUeCfg));
2791 }
2792
2793 /*******************************************************************
2794 *
2795 * @brief delete UE Configuration of a particular UE
2796 *
2797 * @details
2798 *
2799 *    Function : deleteUeCfg 
2800 *
2801 *    Functionality: delete UE Configuration of a particular UE 
2802 *
2803 * @params[in] uint16_t cellIdx, uint8_t ueIdx
2804 * @return ROK     - success
2805 *         RFAILED - failure
2806 *
2807 * ****************************************************************/
2808 uint8_t  deleteUeCfg(uint16_t cellIdx, uint8_t ueIdx)
2809 {
2810    uint8_t tnlIdx = 0;
2811    DuUeCb *ueCb = NULLP;
2812    
2813    if(duCb.actvCellLst[cellIdx] != NULLP)
2814    {
2815       if((duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg.macUeCfgState == UE_DELETE_COMPLETE)\
2816             &&(duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg.rlcUeCfgState == UE_DELETE_COMPLETE))
2817       {
2818          ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1];
2819          deleteMacUeCfg(&ueCb->macUeCfg);
2820          deleteRlcUeCfg(&ueCb->rlcUeCfg);
2821          if(ueCb->f1UeDb !=NULLP)
2822          {
2823             freeF1UeDb(ueCb->f1UeDb);
2824          }
2825          for(tnlIdx = 0; tnlIdx < duCb.numDrb; )
2826          {
2827             if(duCb.upTnlCfg[tnlIdx]->ueIdx == ueIdx)
2828             {
2829                duCb.upTnlCfg[tnlIdx]->configType = CONFIG_DEL;
2830                duProcEgtpTunnelCfg(tnlIdx, duCb.upTnlCfg[tnlIdx], duCb.upTnlCfg[tnlIdx]);
2831             }
2832             else
2833                tnlIdx++;
2834          }
2835          duCb.actvCellLst[cellIdx]->numActvUes--;
2836          memset(ueCb, 0, sizeof(DuUeCb));
2837       }
2838       else
2839       {
2840          return RFAILED;
2841       }
2842    }
2843    else
2844    {
2845       DU_LOG("\nERROR  --> DU APP : deleteUeCfg(): CellIdx[%d] is not found", cellIdx);
2846       return RFAILED;
2847    }
2848    return ROK;
2849 }
2850
2851
2852 /*******************************************************************
2853 *
2854 * @brief Handle UE delete response from MAC
2855 *
2856 * @details
2857 *
2858 *    Function : DuProcMacUeDeleteRsp
2859 *
2860 *    Functionality: Handle UE delete response from MAC
2861 *
2862 * @params[in] Pointer to MacUeDeleteRsp and Pst
2863 * @return ROK     - success
2864 *         RFAILED - failure
2865 *
2866 * ****************************************************************/
2867
2868 uint8_t DuProcMacUeDeleteRsp(Pst *pst, MacUeDeleteRsp *deleteRsp)
2869 {
2870    uint8_t  ret =ROK,ueId=0;
2871    uint16_t cellIdx=0;
2872    uint32_t gnbCuUeF1apId =0 , gnbDuUeF1apId =0;
2873    
2874    if(deleteRsp)
2875    {
2876       if(deleteRsp->result == SUCCESS)
2877       {
2878          DU_LOG("\nINFO   -->  DU APP : MAC UE Delete Response : SUCCESS [UE IDX : %d]", deleteRsp->ueId);
2879          GET_CELL_IDX(deleteRsp->cellId, cellIdx);
2880          if(duCb.actvCellLst[cellIdx])
2881          {
2882             duCb.actvCellLst[cellIdx]->ueCb[deleteRsp->ueId -1].macUeCfg.macUeCfgState = UE_DELETE_COMPLETE;
2883             ueId = deleteRsp->ueId;
2884             gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
2885             gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
2886             if(deleteUeCfg(cellIdx, ueId) == ROK)
2887             {
2888                ret = BuildAndSendUeContextReleaseComplete(deleteRsp->cellId, gnbCuUeF1apId, gnbDuUeF1apId);
2889                if(ret != ROK)
2890                {
2891                   DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): failed to send UE context release complete");
2892                }
2893             }
2894
2895          }
2896       }
2897       else
2898       {
2899          DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): MAC UE Delete Response : FAILURE [UE IDX : %d]",\
2900          deleteRsp->ueId);
2901          ret =  RFAILED;
2902       }
2903       DU_FREE_SHRABL_BUF(pst->region, pst->pool, deleteRsp, sizeof(MacUeDeleteRsp));
2904    }
2905    else
2906    {
2907       DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp(): MAC UE Delete Response is null");
2908       ret = RFAILED;
2909    }
2910    return ret;
2911 }
2912
2913 /*******************************************************************
2914  *
2915  * @brief Processes UE Delete Rsp received from RLC 
2916  *
2917  * @details
2918  *
2919  *    Function : DuProcRlcUeDeleteRsp
2920  *
2921  *    Functionality:
2922  *     Processes UE Delete Rsp received from RLC 
2923  *
2924  *  @params[in]  Post structure
2925  *               Pointer to RlcUeDeleteRsp
2926  *  @return ROK     - success
2927  *          RFAILED - failure
2928  *
2929  * *****************************************************************/
2930
2931 uint8_t DuProcRlcUeDeleteRsp(Pst *pst, RlcUeDeleteRsp *delRsp)
2932 {
2933    uint8_t  ueId = 0, ret = ROK;
2934    uint16_t cellIdx = 0,crnti=0;
2935
2936    if(delRsp)
2937    {
2938       ueId = delRsp->ueId;
2939       GET_CELL_IDX(delRsp->cellId, cellIdx);
2940
2941       if(delRsp->result == SUCCESSFUL)
2942       {
2943          DU_LOG("\nINFO   -->  DU_APP: RLC UE Delete Response : SUCCESS [UE IDX:%d]", ueId);
2944          if(duCb.actvCellLst[cellIdx]!=NULLP)
2945          {
2946             duCb.actvCellLst[cellIdx]->ueCb[ueId-1].rlcUeCfg.rlcUeCfgState = UE_DELETE_COMPLETE;
2947             GET_CRNTI(crnti, ueId);
2948             if(sendUeDeleteReqToMac(delRsp->cellId, ueId, crnti) == RFAILED)
2949             {
2950                DU_LOG("\nERROR  -->  DU APP : duBuildAndSendUeDeleteReq(): Failed to build UE  delete req for MAC ");
2951                return RFAILED;
2952             }
2953
2954          }
2955       }
2956       else
2957       {
2958          DU_LOG("\nERROR   -->  DU_APP: RLC UE Delete Response : FAILED [UE IDX:%d]", ueId);
2959          ret = RFAILED;
2960       }
2961       DU_FREE_SHRABL_BUF(pst->region, pst->pool, delRsp, sizeof(RlcUeDeleteRsp));
2962
2963    }
2964    return ret;
2965 }
2966
2967 /*******************************************************************
2968  *
2969  * @brief Sending UE Delete Req To Mac
2970 *
2971 * @details
2972 *
2973 *    Function : sendUeDeleteReqToMac
2974 *
2975 *    Functionality:
2976 *     sending UE Delete Req To Mac
2977 *
2978 *  @params[in]    cellId, ueId, crnti 
2979 *  @return ROK     - success
2980 *          RFAILED - failure
2981 *
2982 *****************************************************************/
2983
2984 uint8_t sendUeDeleteReqToMac(uint16_t cellId, uint8_t ueId, uint16_t crnti)
2985 {
2986    Pst pst;
2987    uint8_t ret=ROK;
2988    MacUeDelete *ueDelete = NULLP;
2989
2990    DU_ALLOC_SHRABL_BUF(ueDelete, sizeof(MacUeDelete));
2991    if(ueDelete)
2992    {
2993       ueDelete->cellId = cellId;
2994       ueDelete->ueId   = ueId;
2995       ueDelete->crnti  = crnti;
2996       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_DELETE_REQ);
2997
2998       DU_LOG("\nDEBUG  -->  DU_APP: Sending UE delete Request to MAC ");
2999       ret = (*packMacUeDeleteReqOpts[pst.selector])(&pst, ueDelete);
3000       if(ret == RFAILED)
3001       {
3002          DU_LOG("\nERROR  -->  DU_APP: sendUeDeleteReqToMac(): Failed to send UE delete Req to MAC");
3003          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueDelete, sizeof(MacUeDelete));
3004       }
3005    }
3006    else
3007    {
3008       DU_LOG("\nERROR  -->   DU_APP: sendUeDeleteReqToMac(): Failed to allocate memory"); 
3009       ret = RFAILED;
3010    }
3011    return ret;
3012 }
3013
3014 /*******************************************************************
3015  *
3016  * @brief Sending UE Delete Req To Rlc
3017  *
3018  * @details
3019  *
3020  *    Function : sendUeDeleteReqToRlc
3021  *
3022  *    Functionality:
3023  *     Sending UE Delete Req To Rlc
3024  *
3025  *  @params[in]  cellId, ueId 
3026  *  @return ROK     - success
3027  *          RFAILED - failure
3028  *
3029  *****************************************************************/
3030
3031 uint8_t sendUeDeleteReqToRlc(uint16_t cellId, uint8_t ueId)
3032 {
3033    uint8_t ret;
3034    Pst pst;
3035    RlcUeDelete *ueDelete;
3036
3037    DU_ALLOC_SHRABL_BUF(ueDelete, sizeof(RlcUeDelete));
3038    if(ueDelete !=NULLP)
3039    {
3040       ueDelete->cellId = cellId;
3041       ueDelete->ueId = ueId;
3042       FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_DELETE_REQ);
3043
3044       ret = (*packRlcUeDeleteReqOpts[pst.selector])(&pst, ueDelete);
3045       if(ret == RFAILED)
3046       {
3047          DU_LOG("\nERROR  -->  DU_APP : sendUeDeleteReqToRlc():Failed to send UE Delete  Req to RLC"); 
3048          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueDelete, sizeof(RlcUeDelete));
3049       }
3050    }
3051    else
3052    {
3053       DU_LOG("\nERROR  -->   DU_APP: sendUeDeleteReqToRlc():Memory allocation failed");
3054       ret = RFAILED;
3055    }
3056    return ret;
3057 }
3058
3059 /*******************************************************************
3060  *
3061  * @brief DU processes UE delete req from CU and sends to MAC and RLC 
3062  *
3063  * @details
3064  *
3065  *    Function : duBuildAndSendUeDeleteReq
3066  *
3067  *    Functionality: DU processes UE delete req from CU and sends to MAC 
3068  *                   and RLC 
3069  *
3070  * @params[in] cellId, crnti 
3071  * @return ROK     - success
3072  *         RFAILED - failure
3073  *
3074  * ****************************************************************/
3075
3076 uint8_t duBuildAndSendUeDeleteReq(uint16_t cellId, uint16_t crnti)
3077 {
3078    uint8_t  ueId =0;
3079    uint16_t cellIdx = 0;
3080
3081    DU_LOG("\nDEBUG  -->  DU_APP: Processing UE Delete Request ");
3082    GET_CELL_IDX(cellId, cellIdx);
3083    GET_UE_IDX(crnti, ueId);
3084
3085    if(duCb.actvCellLst[cellIdx] != NULLP)
3086    {
3087       if(crnti != duCb.actvCellLst[cellIdx]->ueCb[ueId - 1].crnti)
3088       {
3089          DU_LOG("\nERROR  -->  DU APP : duBuildAndSendUeDeleteReq(): CRNTI [%d] not found", crnti);
3090          return RFAILED;
3091       }
3092
3093       duCb.actvCellLst[cellIdx]->ueCb[ueId - 1].ueState = UE_DELETION_IN_PROGRESS; 
3094       if(sendUeDeleteReqToRlc(cellId, ueId) == RFAILED)
3095       {
3096          DU_LOG("\nERROR  -->  DU APP : DuProcMacUeDeleteRsp():Failed to build UE  delete req for RLC ");
3097          return RFAILED;
3098       }
3099    }
3100    else
3101    {
3102       DU_LOG("\nERROR  -->  DU APP : duBuildAndSendUeDeleteReq(): Cell Id is not found");
3103       return RFAILED;
3104    }
3105
3106    return ROK;
3107 }
3108
3109 /*******************************************************************
3110  *
3111  * @brief delete RlcUeCfg from duCb
3112  *
3113  * @details
3114  *
3115  *    Function : deleteRlcUeCfg
3116  *
3117  *    Functionality:
3118  *       delete  RlcUeCfg from duCb
3119  *
3120  *  @params[in] RlcUeCfg *ueCfg 
3121  *               
3122  *  @return ROK     - success
3123  *          RFAILED - failure
3124  *
3125  *****************************************************************/
3126
3127 void deleteRlcUeCfg(RlcUeCfg *ueCfg)
3128 {
3129    uint8_t lcIdx = 0;
3130    RlcBearerCfg *lcCfg= NULLP;
3131    if(ueCfg)
3132    {
3133       for(lcIdx =0 ; lcIdx < ueCfg->numLcs ; lcIdx++)
3134       {
3135          lcCfg = &ueCfg->rlcLcCfg[lcIdx];
3136          switch(lcCfg->rlcMode)
3137          {
3138             case RLC_AM :
3139                {
3140                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
3141                   break;
3142                }
3143             case RLC_UM_BI_DIRECTIONAL :
3144                {
3145                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
3146                   break;
3147                }
3148             case RLC_UM_UNI_DIRECTIONAL_UL :
3149                {
3150                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
3151                   break;
3152                }
3153             case RLC_UM_UNI_DIRECTIONAL_DL :
3154                {
3155                   DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
3156                   break;
3157                }
3158          }
3159       }
3160       memset(ueCfg, 0, sizeof(RlcUeCfg));
3161    }
3162 }
3163
3164 /*******************************************************************
3165 *
3166 * @brief Du process Ue Context Release Command
3167 *
3168 * @details
3169 *
3170 *    Function : duProcUeContextReleaseCommand 
3171 *
3172 *    Functionality: Du process Ue Context Release Command 
3173 *
3174 * @params[in] DuUeCb *duUeCb 
3175 * @return ROK     - success
3176 *         RFAILED - failure
3177 *
3178 * ****************************************************************/
3179 uint8_t duProcUeContextReleaseCommand(DuUeCb *duUeCb)
3180 {
3181    uint8_t ret =ROK, ueIdx=0;
3182    uint16_t cellId=0,crnti =0;
3183    if(duUeCb == NULLP)
3184    {
3185       DU_LOG("\nERROR  -->  DU APP : duProcUeContextReleaseCommand() : duUeCb is null");
3186       return RFAILED;
3187    }
3188    if(duUeCb->f1UeDb == NULLP)
3189    {
3190       DU_LOG("\nERROR  -->  DU APP : duProcUeContextReleaseCommand() : f1UeDb is null");
3191       return RFAILED;
3192    }
3193    
3194    cellId = duCb.actvCellLst[duUeCb->f1UeDb->cellIdx]->cellId;
3195    crnti = duUeCb->crnti;
3196    /* Send DL RRC msg for RRC release */
3197    if(duUeCb->f1UeDb->dlRrcMsg)
3198    {
3199       if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu != NULLP)
3200       {
3201          ret = duBuildAndSendDlRrcMsgToRlc(cellId, duCb.actvCellLst[duUeCb->f1UeDb->cellIdx]->ueCb[ueIdx].rlcUeCfg,\
3202                duUeCb->f1UeDb->dlRrcMsg);
3203          if(ret == RFAILED)
3204          {
3205             DU_LOG("\nERROR  -->  DU APP : duProcUeContextReleaseCommand() : Failed to send DL RRC msg");
3206             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
3207                   duUeCb->f1UeDb->dlRrcMsg->rrcMsgSize);
3208             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
3209          }
3210       }
3211    }
3212    else
3213    {
3214       ret = duBuildAndSendUeDeleteReq(cellId,crnti);
3215       if(ret == RFAILED)
3216       {
3217          DU_LOG("\nERROR  -->  DU APP : duProcUeContextReleaseCommand(): Failed to build and send Ue Delete request");
3218       }
3219    }
3220
3221    return ret;
3222 }
3223
3224 /**********************************************************************
3225   End of file
3226 ***********************************************************************/