implementation of RLC UE delete req and rsp JIRA-ID : ODUHIGH-43
[o-du/l2.git] / src / 5gnrrlc / rlc_msg_hdl.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
19 /* header include files (.h) */
20 #include "common_def.h"
21 #include "rgu.h"           /* RGU interface includes*/
22 #include "lkw.h"           /* LKW defines */
23 #include "ckw.h"           /* CKW defines */
24 #include "kwu.h"           /* KWU defines */
25 #include "kw_env.h"        /* RLC environment options */
26 #include "kw.h"            /* RLC defines */
27 #include "kw_udx.h"
28 #include "kw_ul.h"
29 #include "kw_dl.h"
30
31 /* header/extern include files (.x) */
32 #include "rgu.x"           
33 #include "lkw.x"           /* LKW */
34 #include "ckw.x"           /* CKW */
35 #include "kwu.x"           /* KWU */
36 #include "kw_err.h"
37 #include "kw.x"
38 #include "kw_udx.x"
39 #include "kw_dl.x"
40 #include "kw_ul.x"
41
42 #include "rlc_mac_inf.h"
43 #include "du_app_rlc_inf.h"
44 #include "rlc_utils.h"
45 #include "rlc_upr_inf_api.h"
46
47 /*******************************************************************
48  *
49  * @brief Fills RLC UL UE Cfg Rsp from RlcCRsp 
50  *
51  * @details
52  *
53  *    Function : fillRlcUeCfgRsp
54  *
55  *    Functionality: 
56  *     Fills RLC UL UE Cfg Rsp from RlcCRsp
57  * 
58  *  @params[in]  Pointer to RlcCfgCfm
59  *               Pointer to RlcUeCfgRsp
60  *
61  *  @return ROK/RFAILED
62  * 
63  *****************************************************************/
64
65 uint8_t fillRlcUeCfgRsp(RlcUeCfgRsp *rlcCfgRsp, RlcCfgCfmInfo *rlcCRsp)
66 {
67    uint8_t idx;
68    uint8_t ret = ROK;
69  
70    rlcCfgRsp->cellId = rlcCRsp->cellId;
71    rlcCfgRsp->ueIdx  = rlcCRsp->ueId;
72    for(idx = 0; idx < rlcCRsp->numEnt; idx++)
73    {
74       if(rlcCRsp->entCfgCfm[idx].status.status == CKW_CFG_CFM_OK)
75       {
76          rlcCfgRsp->result = RLC_DU_APP_RSP_OK;
77          rlcCfgRsp->reason = rlcCRsp->entCfgCfm[idx].status.reason;
78          ret = ROK;
79       }
80       else
81       {
82          rlcCfgRsp->result = RLC_DU_APP_RSP_NOK;
83          rlcCfgRsp->reason = rlcCRsp->entCfgCfm[idx].status.reason;
84          ret = RFAILED;
85          break;
86       }
87    }
88    return ret;
89 }
90
91 /*******************************************************************
92  *
93  * @brief Fills the entity mode and direction compiling to seed code
94  *
95  * @details
96  *
97  *    Function : fillEntModeAndDir
98  *
99  *    Functionality:
100  *      Fills the entity mode and direction compiling to seed code
101  *
102  * @params[in] Pointer to entMode
103  *             Pointer to direction
104  *             RlcMode Param 
105  * @return void
106  * ****************************************************************/
107
108 void fillEntModeAndDir(uint8_t *entMode, uint8_t *direction, RlcMode rlcMode)
109 {
110    switch(rlcMode)
111    {
112       case RLC_AM:
113          *entMode   = RLC_MODE_AM;
114          *direction = RLC_CFG_DIR_BOTH;
115          break;
116       case RLC_UM_BI_DIRECTIONAL:
117          *entMode = RLC_MODE_UM;
118          *direction = RLC_CFG_DIR_BOTH;
119          break;
120       case RLC_UM_UNI_DIRECTIONAL_UL:
121          *entMode = RLC_MODE_UM;
122          *direction = RLC_CFG_DIR_UL;
123          break;
124       case RLC_UM_UNI_DIRECTIONAL_DL:
125          *entMode = RLC_MODE_UM;
126          *direction = RLC_CFG_DIR_DL;
127          break;
128       default : 
129          DU_LOG("\nERROR  -->  RLC: Rlc Mode invalid %d", rlcMode);
130     break;
131    }
132 }
133
134 /*******************************************************************
135  *
136  * @brief fills LC Cfgs to be Added in RLC
137  *
138  * @details
139  *
140  *    Function : fillLcCfg
141  *
142  *    Functionality:
143  *      fills LC Cfgs to be Added in RLC
144  *
145  * @params[in] 
146  *             RlcEntCfgInfo pointer
147  *             RlcBearerCfg pointer
148  *             Config Type 
149  * @return void
150  *
151  * ****************************************************************/
152 void fillLcCfg(RlcEntCfgInfo *rlcUeCfg, RlcBearerCfg *duRlcUeCfg, uint8_t cfgType)
153 {
154    uint8_t lChRbIdx = 0;
155
156    rlcUeCfg->rbId                  = duRlcUeCfg->rbId;
157    rlcUeCfg->rbType                = duRlcUeCfg->rbType;   // SRB or DRB
158    rlcUeCfg->lCh[lChRbIdx].lChId   = duRlcUeCfg->lcId;   
159    rlcUeCfg->lCh[lChRbIdx].type    = duRlcUeCfg->lcType;
160    fillEntModeAndDir(&rlcUeCfg->entMode, &rlcUeCfg->dir, duRlcUeCfg->rlcMode);
161    rlcUeCfg->cfgType               = cfgType;
162    switch(rlcUeCfg->entMode)
163    {
164
165       case RLC_MODE_AM:
166          {
167             /* DL AM INFO */
168             rlcUeCfg->m.amInfo.dl.snLen       = duRlcUeCfg->u.amCfg->dlAmCfg.snLenDl; 
169             rlcUeCfg->m.amInfo.dl.pollRetxTmr = duRlcUeCfg->u.amCfg->dlAmCfg.pollRetxTmr;
170             rlcUeCfg->m.amInfo.dl.pollPdu     = duRlcUeCfg->u.amCfg->dlAmCfg.pollPdu; 
171             rlcUeCfg->m.amInfo.dl.pollByte    = duRlcUeCfg->u.amCfg->dlAmCfg.pollByte; 
172             rlcUeCfg->m.amInfo.dl.maxRetx     = duRlcUeCfg->u.amCfg->dlAmCfg.maxRetxTh;
173
174             /* UL AM INFO */
175             lChRbIdx++;   //lChRbIdx = 1, indicates UL AM
176             rlcUeCfg->lCh[lChRbIdx].lChId    = duRlcUeCfg->lcId;   
177             rlcUeCfg->lCh[lChRbIdx].type     = duRlcUeCfg->lcType;
178             rlcUeCfg->m.amInfo.ul.snLen      = duRlcUeCfg->u.amCfg->ulAmCfg.snLenUl; 
179             rlcUeCfg->m.amInfo.ul.staProhTmr = duRlcUeCfg->u.amCfg->ulAmCfg.statProhTmr;
180             rlcUeCfg->m.amInfo.ul.reAsmblTmr   = duRlcUeCfg->u.amCfg->ulAmCfg.reAssemTmr * RLC_REASSEMBLY_TMR_BASE;
181             break;
182          }
183       case RLC_MODE_UM:
184          {
185             /* UL UM CONFIG */
186             rlcUeCfg->m.umInfo.ul.snLen      = duRlcUeCfg->u.umBiDirCfg->ulUmCfg.snLenUlUm; 
187             rlcUeCfg->m.umInfo.ul.reAsmblTmr = duRlcUeCfg->u.umBiDirCfg->ulUmCfg.reAssemTmr * RLC_REASSEMBLY_TMR_BASE;
188
189             /* DL UM CONFIG */
190             rlcUeCfg->m.umInfo.dl.snLen = duRlcUeCfg->u.umBiDirCfg->dlUmCfg.snLenDlUm; 
191             break;
192          }
193       default:
194          break;
195    }/* End of switch(entMode) */
196 }
197
198 /*******************************************************************
199  *
200  * @brief fills LC Cfgs to be Added in RLC
201  *
202  * @details
203  *
204  *    Function : fillRlcCfg
205  *
206  *    Functionality:
207  *      fills LC Cfgs to be Add/Mod/Del in RLC
208  *
209  * @params[in] 
210  *             RlcEntCfgInfo pointer
211  *             RlcBearerCfg pointer
212  * @return void
213  *
214  ******************************************************************/
215
216 void fillRlcCfg(RlcCfgInfo *rlcUeCfg, RlcUeCfg *ueCfg)
217 {
218    uint8_t lcIdx;
219    
220    rlcUeCfg->ueId    = ueCfg->ueIdx;
221    rlcUeCfg->cellId  = ueCfg->cellId;
222    rlcUeCfg->numEnt  = ueCfg->numLcs;
223    rlcUeCfg->transId = getTransId();
224
225    for(lcIdx = 0; lcIdx < rlcUeCfg->numEnt; lcIdx++)
226    {
227       fillLcCfg(&rlcUeCfg->entCfg[lcIdx], &ueCfg->rlcLcCfg[lcIdx], ueCfg->rlcLcCfg[lcIdx].configType);
228    }
229 }
230
231 /*******************************************************************
232  *
233  * @brief Handles Ue Create Request from DU APP
234  *
235  * @details
236  *
237  *    Function : RlcProcUeCreateReq
238  *
239  *    Functionality:
240  *      Handles Ue create Request from DU APP
241  *
242  * @params[in] Post structure pointer
243  *             RlcUeCfg pointer 
244  * @return ROK     - success
245  *         RFAILED - failure
246  *
247  * ****************************************************************/
248 uint8_t RlcProcUeCreateReq(Pst *pst, RlcUeCfg *ueCfg)
249 {
250    uint8_t ret = ROK;
251    RlcCfgInfo *rlcUeCfg = NULLP;
252
253    RlcCb *rlcUeCb = NULLP;
254    rlcUeCb = RLC_GET_RLCCB(pst->dstInst);
255    RLC_ALLOC(rlcUeCb, rlcUeCfg, sizeof(RlcCfgInfo));
256    if(rlcUeCfg == NULLP)
257    {
258       DU_LOG("\nERROR  -->  RLC: Failed to allocate memory at RlcProcUeCreateReq()");
259       ret = RFAILED;
260    }
261    else
262    {
263       memset(rlcUeCfg, 0, sizeof(RlcCfgInfo));
264       fillRlcCfg(rlcUeCfg, ueCfg); 
265       ret = RlcProcCfgReq(pst, rlcUeCfg);
266       if(ret != ROK)
267          DU_LOG("\nERROR  -->  RLC: Failed to configure Add/Mod/Del entities at RlcProcUeCreateReq()");
268
269    }
270    RLC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(RlcUeCfg));
271    return ret;
272 }
273
274 /*******************************************************************
275 *
276 * @brief filling the structure of rrc delivery msg info
277 *
278 * @details
279 *
280 *    Function : BuildAndSendRrcDeliveryReportToDu
281 *
282 *    Functionality: filling the structure of rrc delivery msg info
283 *
284 * @return ROK     - success
285 *         RFAILED - failure
286 *
287 * ****************************************************************/
288 uint8_t BuildAndSendRrcDeliveryReportToDu( RlcDlRrcMsgInfo *dlRrcMsgInfo )
289 {
290     Pst             pst;
291     RrcDeliveryReport *rrcDelivery;
292
293     DU_LOG("\nINFO  -->  RLC : Filling RRC Delivery Report");
294     RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_UL, RLC_POOL, rrcDelivery, sizeof(RrcDeliveryReport));
295
296     if(rrcDelivery)
297     {
298        rrcDelivery->cellId = dlRrcMsgInfo->cellId;
299        rrcDelivery->ueIdx  = dlRrcMsgInfo->ueIdx;
300        rrcDelivery->srbId  = dlRrcMsgInfo->lcId ;
301        rrcDelivery->rrcDeliveryStatus.deliveryStatus    = PDCP_SN;
302        rrcDelivery->rrcDeliveryStatus.triggeringMessage = PDCP_SN;
303
304        /* Sending UL RRC Message transfeer to DU APP */
305        memset(&pst, 0, sizeof(Pst));
306        FILL_PST_RLC_TO_DUAPP(pst, RLC_UL_INST, EVENT_RRC_DELIVERY_MSG_TRANS_TO_DU);
307        rlcSendRrcDeliveryReportToDu(&pst, rrcDelivery);
308     }
309     else
310     {
311        DU_LOG("\nERROR  -->  RLC : Memory allocation failed");
312     }
313
314    return ROK;
315 }
316 /* ****************************************************************
317  *
318  * @brief Process the DL RRC Message from DU APP
319  *
320  * @details
321  *
322  *    Function : RlcProcDlRrcMsgTransfer
323  *
324  *    Functionality: Process the DL RRC Message from DU APP
325  *
326  * @params[in] Post structure
327  *             DL RRC Message info
328  * @return ROK     - success
329  *         RFAILED - failure
330  *
331  * ****************************************************************/
332 uint8_t RlcProcDlRrcMsgTransfer(Pst *pst, RlcDlRrcMsgInfo *dlRrcMsgInfo)
333 {
334    Buffer        *mBuf;
335    RlcDatReqInfo *datReqInfo;
336
337    RLC_SHRABL_STATIC_BUF_ALLOC(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(RlcDatReqInfo));
338    if(!datReqInfo)
339    {
340       DU_LOG("\nERROR  -->  RLC : Memory allocation failed in RlcProcDlRrcMsgTransfer");
341       RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlRrcMsgInfo->rrcMsg, dlRrcMsgInfo->msgLen);
342       RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
343       return RFAILED;
344    }
345
346    datReqInfo->rlcId.rbType = dlRrcMsgInfo->rbType;
347    datReqInfo->rlcId.rbId = dlRrcMsgInfo->rbId;
348    datReqInfo->rlcId.ueId = dlRrcMsgInfo->ueIdx;
349    datReqInfo->rlcId.cellId = dlRrcMsgInfo->cellId;
350    datReqInfo->lcType = dlRrcMsgInfo->lcType;
351    datReqInfo->sduId = ++(rlcCb[pst->dstInst]->dlSduId);
352
353    /* Copy fixed buffer to message */
354    if(ODU_GET_MSG_BUF(RLC_MEM_REGION_UL, RLC_POOL, &mBuf) != ROK)
355    {
356       DU_LOG("\nERROR  -->  RLC : Memory allocation failed at RlcMacProcUlData");
357       RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(RlcDatReqInfo));
358       RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlRrcMsgInfo->rrcMsg, dlRrcMsgInfo->msgLen);
359       RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
360       return RFAILED;
361    }
362    oduCpyFixBufToMsg(dlRrcMsgInfo->rrcMsg, mBuf, dlRrcMsgInfo->msgLen);
363
364    if(rlcProcDlData(pst, datReqInfo, mBuf) != ROK)
365    {
366       return RFAILED;
367    }
368
369    /* RRC Delivery report is only send when RRC Delivery status report is true in DL RRC Message */
370    if(dlRrcMsgInfo->deliveryStaRpt)
371    {
372       BuildAndSendRrcDeliveryReportToDu(dlRrcMsgInfo);
373    }
374
375    /* Free memory allocated by du app */
376    RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(RlcDatReqInfo));
377    RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlRrcMsgInfo->rrcMsg, dlRrcMsgInfo->msgLen);
378    RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
379    return ROK;
380 }
381
382 /*******************************************************************
383  *
384  * @brief Process UL data from UE
385  *
386  * @details
387  *
388  *    Function : RlcProcUlData
389  *
390  *    Functionality:
391  *       This function receives the PDU from MAC.
392  *       seggregates common and dedicated logical channel
393  *       PDU and call respective handler.
394  *
395  * @params[in]
396  * @return ROK     - success
397  *         RFAILED - failure
398  *
399  * ****************************************************************/
400 uint8_t RlcProcUlData(Pst *pst, RlcData *ulData)
401 {
402    uint8_t         ret = ROK;
403    uint8_t         idx, pduIdx;
404    uint8_t         lcId;                    /* Logical Channel */
405    uint8_t         numDLch = 0;             /* Number of dedicated logical channel */
406    bool            dLchPduPres;             /* PDU received on dedicated logical channel */
407    RguLchDatInd    dLchData[MAX_NUM_LC];    /* PDU info on dedicated logical channel */
408    RguDDatIndInfo  *dLchUlDat;              /* UL data on dedicated logical channel */
409    RguCDatIndInfo  *cLchUlDat;              /* UL data on common logical channel */
410
411    /* Initializing dedicated logical channel Database */
412    DU_LOG("\nDEBUG  -->  RLC: Received UL Data request from MAC");
413    for(idx = 0; idx < MAX_NUM_LC; idx++)
414    {
415       dLchData[idx].lcId = idx;
416       dLchData[idx].pdu.numPdu = 0;
417    }
418    dLchPduPres = FALSE;
419
420    /* Seggregate PDUs received on common and dedicated channels
421     * and call common channel's handler */
422    for(idx = 0; idx< ulData->numPdu; idx++)
423    {
424       if(ulData->pduInfo[idx].commCh)
425       {
426          RLC_SHRABL_STATIC_BUF_ALLOC(RLC_MEM_REGION_UL, RLC_POOL, cLchUlDat, \
427             sizeof(RguCDatIndInfo));
428          if(!cLchUlDat)
429          {
430             DU_LOG("\nERROR  -->  RLC : Memory allocation failed at RlcProcUlData");
431             ret = RFAILED;
432             break;
433          }
434          memset(cLchUlDat, 0, sizeof(RguCDatIndInfo));
435
436          cLchUlDat->cellId = ulData->cellId;
437          GET_UE_IDX(ulData->rnti, cLchUlDat->rnti);
438          cLchUlDat->lcId   = ulData->pduInfo[idx].lcId;
439
440          /* Copy fixed buffer to message */
441          if(ODU_GET_MSG_BUF(RLC_MEM_REGION_UL, RLC_POOL, &cLchUlDat->pdu) != ROK)
442          {
443             DU_LOG("\nERROR  -->  RLC : Memory allocation failed at RlcProcUlData");
444             RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_UL, RLC_POOL, cLchUlDat, \
445                sizeof(RguCDatIndInfo));
446             ret = RFAILED;
447             break;
448          }
449          oduCpyFixBufToMsg(ulData->pduInfo[idx].pduBuf, cLchUlDat->pdu, \
450             ulData->pduInfo[idx].pduLen);
451
452          rlcProcCommLcUlData(pst, 0, cLchUlDat);
453       }
454       else
455       {
456          if(!dLchPduPres)
457          {
458             RLC_SHRABL_STATIC_BUF_ALLOC(RLC_MEM_REGION_UL, RLC_POOL, dLchUlDat, \
459                sizeof(RguDDatIndInfo));
460             if(!dLchUlDat)
461             {
462                DU_LOG("\nERROR  -->  RLC : Memory allocation failed at RlcMacProcUlData");
463                ret = RFAILED;
464                break;
465             }
466             dLchPduPres = TRUE;
467          }
468
469          /* Copy fixed buffer to message */
470          lcId = ulData->pduInfo[idx].lcId;
471          if(ODU_GET_MSG_BUF(RLC_MEM_REGION_UL, RLC_POOL, \
472                   &dLchData[lcId].pdu.mBuf[dLchData[lcId].pdu.numPdu]) != ROK)
473          {
474             DU_LOG("\nERROR  -->  RLC : Memory allocation failed at RlcMacProcUlData");
475             for(pduIdx=0; pduIdx < dLchData[lcId].pdu.numPdu; pduIdx++)
476             {
477                ODU_PUT_MSG_BUF(dLchData[lcId].pdu.mBuf[dLchData[lcId].pdu.numPdu]);
478             }
479             RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_UL, RLC_POOL, dLchUlDat, \
480                sizeof(RguDDatIndInfo));
481             ret = RFAILED;
482             break;
483          }
484          oduCpyFixBufToMsg(ulData->pduInfo[idx].pduBuf, \
485                dLchData[lcId].pdu.mBuf[dLchData[lcId].pdu.numPdu],\
486                ulData->pduInfo[idx].pduLen);
487
488          dLchData[lcId].pdu.numPdu++;
489       }
490    }
491
492    /* If any PDU received on dedicated logical channel, copy into RguDDatIndInfo
493     * and call its handler */
494    if(ret == ROK)
495    {
496       if(dLchPduPres)
497       {
498          dLchUlDat->cellId = ulData->cellId;
499          GET_UE_IDX(ulData->rnti, dLchUlDat->rnti);
500
501          for(idx = 0; idx < MAX_NUM_LC; idx++)
502          {
503             if(dLchData[idx].pdu.numPdu)
504             {
505                memcpy(&dLchUlDat->lchData[numDLch], &dLchData[idx], sizeof(RguLchDatInd));
506                numDLch++;
507             }
508          }
509          dLchUlDat->numLch = numDLch;
510          rlcProcDedLcUlData(pst, 0, dLchUlDat);
511       }
512    }
513
514    for(pduIdx = 0; pduIdx < ulData->numPdu; pduIdx++)
515    {
516       RLC_FREE_SHRABL_BUF(pst->region, pst->pool, ulData->pduInfo[pduIdx].pduBuf, \
517          ulData->pduInfo[pduIdx].pduLen);
518    }
519    RLC_FREE_SHRABL_BUF(pst->region, pst->pool, ulData, sizeof(RlcData));
520    return ROK;
521
522 }/* End of RlcProcUlData */
523
524 /*******************************************************************
525  *
526  * @brief Handler for extracting common and dedicated channel
527  *      Scheduling result report.
528  *
529  * @details
530  *
531  *    Function : RlcProcSchedResultRpt
532  *
533  *    Functionality:
534  *     Handler for extracting common and dedicated channel
535  *      Scheduling result report
536  *
537  * @params[in]
538  * @return ROK     - success
539  *         RFAILED - failure
540  *
541  * ****************************************************************/
542 uint8_t RlcProcSchedResultRpt(Pst *pst, RlcSchedResultRpt *schRep)
543 {
544    uint8_t ret = ROK;
545    uint8_t idx;                     /* Iterator */
546    uint8_t nmbDLch = 0;                 /* Number of dedicated logical channles */
547    RguCStaIndInfo   *cLchSchInfo;    /* Common logical channel scheduling result */
548    RguDStaIndInfo   *dLchSchInfo;  /* Dedicated logical channel scheduling result */
549
550    DU_LOG("\nDEBUG  -->  RLC : Received scheduling report from MAC");
551    for(idx=0; idx < schRep->numLc; idx++)
552    {
553       /* If it is common channel, fill status indication information
554        * and trigger the handler for each common lch separately */
555       if(schRep->lcSch[idx].commCh)
556       {
557           RLC_SHRABL_STATIC_BUF_ALLOC(RLC_MEM_REGION_DL, RLC_POOL, cLchSchInfo, \
558              sizeof(RguCStaIndInfo));
559           if(!cLchSchInfo)
560           {
561              DU_LOG("\nERROR  -->  RLC: RlcProcSchedResultRpt: Memory allocation failed for cLchSchInfo");
562              ret = RFAILED;
563              break;
564           }
565           memset(cLchSchInfo, 0, sizeof(RguCStaIndInfo));
566
567           cLchSchInfo->cellId  = schRep->cellId;
568           cLchSchInfo->lcId    = schRep->lcSch[idx].lcId;
569           cLchSchInfo->transId = schRep->slotInfo.sfn;
570           cLchSchInfo->transId = (cLchSchInfo->transId << 16) | schRep->slotInfo.slot;
571           cLchSchInfo->rnti = schRep->rnti;
572           rlcProcCommLcSchedRpt(pst, 0, cLchSchInfo);
573
574       }
575       else
576       {
577           /* Fill status info structure if at least one dedicated channel
578            * scheduling report is received */
579           if(nmbDLch == 0)
580           {
581              RLC_SHRABL_STATIC_BUF_ALLOC(RLC_MEM_REGION_DL, RLC_POOL, dLchSchInfo, \
582                 sizeof(RguDStaIndInfo));
583              if(!dLchSchInfo)
584              {
585                 DU_LOG("\nERROR  -->  RLC: RlcProcSchedResultRpt: Memory allocation failed for dLchSchInfo");
586                 ret = RFAILED;
587                 break;
588              }
589
590              dLchSchInfo->cellId = schRep->cellId;
591              dLchSchInfo->nmbOfUeGrantPerTti = 1;
592              /* MAC sends Scheduling report for one UE at a time. Hence filling
593              only the 0th index of staInd */
594              dLchSchInfo->staInd[0].rnti = schRep->rnti;
595
596              /* Storing sfn/slot into a single 32-bit variable to be used later*/
597              dLchSchInfo->staInd[0].transId = schRep->slotInfo.sfn;
598              dLchSchInfo->staInd[0].transId = \
599                 (dLchSchInfo->staInd[0].transId << 16) | schRep->slotInfo.slot; 
600              dLchSchInfo->staInd[0].nmbOfTbs = 1;
601              dLchSchInfo->staInd[0].fillCtrlPdu = true; 
602           }
603
604           /* Fill logical channel scheduling info */
605           dLchSchInfo->staInd[0].staIndTb[0].lchStaInd[nmbDLch].lcId = \
606              schRep->lcSch[idx].lcId;
607           dLchSchInfo->staInd[0].staIndTb[0].lchStaInd[nmbDLch].totBufSize = \
608              schRep->lcSch[idx].bufSize;
609           nmbDLch++;
610       }
611    }
612
613    /* Calling handler for all dedicated channels scheduling*/
614    if(ret == ROK)
615    {
616       if(nmbDLch)
617       {
618          dLchSchInfo->staInd[0].staIndTb[0].nmbLch = nmbDLch;
619          rlcProcDedLcSchedRpt(pst, 0, dLchSchInfo);
620       }
621    }
622
623    RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, schRep, sizeof(RlcSchedResultRpt));
624    return ret;
625 }
626
627
628 /*******************************************************************
629  *
630  * @brief Handles Ue Reconfig Request from DU APP
631  *
632  * @details
633  *
634  *    Function : RlcProcUeReconfigReq
635  *
636  *    Functionality:
637  *      Handles Ue Reconfig Request from DU APP
638  *
639  * @params[in] Post structure pointer
640  *             RlcUeCfg pointer 
641  * @return ROK     - success
642  *         RFAILED - failure
643  *
644  * ****************************************************************/
645 uint8_t RlcProcUeReconfigReq(Pst *pst, RlcUeCfg *ueCfg)
646 {
647    uint8_t ret = ROK;
648    RlcCfgInfo *rlcUeCfg = NULLP; //Seed code Rlc cfg struct
649    RlcCb *rlcUeCb = NULLP;
650     
651    DU_LOG("\nDEBUG  -->  RLC: UE reconfig request received. CellID[%d] UEIDX[%d]",ueCfg->cellId, ueCfg->ueIdx);
652
653    rlcUeCb = RLC_GET_RLCCB(pst->dstInst);
654    RLC_ALLOC(rlcUeCb, rlcUeCfg, sizeof(RlcCfgInfo));
655    if(rlcUeCfg == NULLP)
656    {
657       DU_LOG("\nERROR  -->  RLC: Failed to allocate memory at RlcProcUeReconfigReq()");
658       ret = RFAILED;
659    }
660    else
661    {
662       memset(rlcUeCfg, 0, sizeof(RlcCfgInfo));
663       fillRlcCfg(rlcUeCfg, ueCfg);
664       ret = RlcProcCfgReq(pst, rlcUeCfg);
665       if(ret != ROK)
666          DU_LOG("\nERROR  -->  RLC: Failed to configure Add/Mod/Del entities at RlcProcUeReconfigReq()");
667    }
668    
669    RLC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(RlcUeCfg));
670    return ret;
671 }
672
673 /* ****************************************************************
674  *
675  * @brief Process the DL Data transfer from DU APP
676  *
677  * @details
678  *
679  *    Function : RlcProcDlUserDataTransfer
680  *
681  *    Functionality: Process the DL transfer from DU APP
682  *
683  * @params[in] Post structure
684  *             DL RRC Message info
685  * @return ROK     - success
686  *         RFAILED - failure
687  *
688  * ****************************************************************/
689 uint8_t RlcProcDlUserDataTransfer(Pst *pst, RlcDlUserDataInfo *dlDataMsgInfo)
690 {
691    Buffer        *mBuf = NULLP;
692    RlcDatReqInfo *datReqInfo = NULLP;
693
694    if(dlDataMsgInfo->dlMsg == NULLP)
695    {
696       DU_LOG("\nERROR  -->  RLC_DL : Received DL message is NULLP in RlcProcDlUserDataTransfer()");
697       return RFAILED;
698    }
699    RLC_SHRABL_STATIC_BUF_ALLOC(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(RlcDatReqInfo));
700    if(!datReqInfo)
701    {
702       DU_LOG("\nERROR  -->  RLC_DL : Memory allocation failed for DatReq in RlcProcDlUserDataTransfer()");
703       RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlDataMsgInfo->dlMsg, dlDataMsgInfo->msgLen);
704       RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlDataMsgInfo, sizeof(RlcDlUserDataInfo));
705       return RFAILED;
706    }
707
708    datReqInfo->rlcId.rbType = RB_TYPE_DRB;
709    datReqInfo->rlcId.rbId   = dlDataMsgInfo->rbId;
710    datReqInfo->rlcId.ueId   = dlDataMsgInfo->ueIdx;
711    datReqInfo->rlcId.cellId = dlDataMsgInfo->cellId;
712    datReqInfo->lcType       = LCH_DTCH;
713    datReqInfo->sduId        = ++(rlcCb[pst->dstInst]->dlSduId);
714    mBuf = dlDataMsgInfo->dlMsg;
715    if(rlcProcDlData(pst, datReqInfo, mBuf) != ROK)
716    {
717       return RFAILED;
718    }
719     
720    /* Free memory allocated by du app */
721    RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(RlcDatReqInfo));
722    RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlDataMsgInfo, sizeof(RlcDlUserDataInfo));
723    return ROK;
724 }
725
726 /*******************************************************************
727  *
728  * @brief sending UE delete response to DU 
729  *
730  * @details
731  *
732  *    Function : sendRlcUeDeleteRspToDu 
733  *
734  *    Functionality:
735  *      sending UE delete response to DU 
736  *
737  * @params[in] uint8_t ueIdx, uint8_t cellId, UeDeleteResult result 
738  *
739  * @return ROK     - success
740  *         RFAILED - failure
741  *
742  * ****************************************************************/
743 uint8_t sendRlcUeDeleteRspToDu(uint8_t ueIdx, uint16_t cellId, UeDeleteResult result)
744 {
745    Pst pst;  
746    RlcUeDeleteRsp *ueDeleteRsp = NULLP;
747    
748    FILL_PST_RLC_TO_DUAPP(pst, RLC_UL_INST, EVENT_RLC_UE_DELETE_RSP);
749
750    RLC_ALLOC_SHRABL_BUF(pst.region, pst.pool, ueDeleteRsp, sizeof(RlcUeDeleteRsp));
751    if(!ueDeleteRsp)
752    {
753       DU_LOG("\nERROR  -->  RLC: sendRlcUeDeleteRspToDu(): Memory allocation failed ");
754       return RFAILED;
755    }
756    else
757    {
758       ueDeleteRsp->cellId = cellId;
759       ueDeleteRsp->ueIdx = ueIdx;
760       ueDeleteRsp->result = result;
761   
762       if(rlcSendUeDeleteRspToDu(&pst, ueDeleteRsp) == ROK)
763       {
764          DU_LOG("\nDEBUG  -->  RLC: UE Delete response send successfully");
765       }
766       else
767       {
768          DU_LOG("\nERROR  -->  RLC: SendRlcUeDeleteRspToDu():Failed to send UE Delete response to DU");
769          RLC_FREE_SHRABL_BUF(pst.region, pst.pool, ueDeleteRsp, sizeof(RlcUeDeleteRsp));
770          return RFAILED;
771       }
772    }
773    return ROK;
774 }
775
776 /* ****************************************************************
777 *
778 * @brief filling RLC UE delete configuration  
779 *
780 * @details
781 *
782 *    Function : fillRlcCfgInfo 
783 *
784 *    Functionality: filling RLC UE delete configuration
785 *
786 * @params[in] RlcUlUeCb *ueCb, RlcCfgInfo *rlcUeCfg
787 *
788 * @return void
789 *
790 * ****************************************************************/
791
792 void fillRlcUeDelInfo(RlcUlUeCb *ueCb, RlcCfgInfo *rlcUeCfg)
793 {
794    uint8_t lcIdx;
795    
796    rlcUeCfg->ueId    = ueCb->ueId;
797    rlcUeCfg->cellId  = ueCb->cellId;
798    rlcUeCfg->numEnt = 0;
799    for(lcIdx=0; lcIdx<RLC_MAX_LCH_PER_UE && rlcUeCfg->numEnt < 1; lcIdx++)
800    {
801       if(ueCb->lCh[lcIdx].ulRbCb != NULLP)
802       {
803          rlcUeCfg->entCfg[rlcUeCfg->numEnt].rbId    = 0;
804          rlcUeCfg->entCfg[rlcUeCfg->numEnt].rbType  = 0;
805          rlcUeCfg->entCfg[rlcUeCfg->numEnt].cfgType = CKW_CFG_DELETE_UE;
806          rlcUeCfg->numEnt++;
807       }
808    }
809 }
810
811 /*******************************************************************
812 *
813 * @brief Handles Ue delete Request from DU APP
814 *
815 * @details
816 *
817 *    Function : RlcProcUeDeleteReq
818 *
819 *    Functionality:
820 *      Handles Ue delete Request from DU APP
821 *
822 * @params[in] Post structure pointer
823 *             RlcUeDelete pointer
824 * @return ROK     - success
825 *         RFAILED - failure
826 *
827 * ****************************************************************/
828
829 uint8_t RlcProcUeDeleteReq(Pst *pst, RlcUeDelete *ueDelete)
830 {
831    uint8_t ret = ROK;
832    RlcCb *gRlcCb = NULLP;
833    RlcCfgInfo *rlcUeCfg = NULLP;
834    RlcUlUeCb *ueCb = NULLP;
835    UeDeleteResult result=SUCCESSFUL;
836
837    DU_LOG("\nDEBUG  -->  RLC: UE Delete request received. CellID[%d] UEIDX[%d]",ueDelete->cellId, ueDelete->ueIdx);
838
839    if(ueDelete != NULLP)
840    {
841       gRlcCb = RLC_GET_RLCCB(pst->dstInst);
842       rlcDbmFetchUlUeCb(gRlcCb,ueDelete->ueIdx, ueDelete->cellId, &ueCb);
843       if(ueCb != NULLP)
844       {
845          if(ueDelete->cellId == ueCb->cellId)
846          {
847             RLC_ALLOC(gRlcCb, rlcUeCfg, sizeof(RlcCfgInfo));
848             if(rlcUeCfg == NULLP)
849             {
850                DU_LOG("\nERROR  -->  RLC: deleteRlcUeCb(): Failed to allocate memory");
851                ret = RFAILED;
852             }
853             else
854             {
855                memset(rlcUeCfg, 0, sizeof(RlcCfgInfo));
856                fillRlcUeDelInfo(ueCb, rlcUeCfg);
857                if(RlcProcCfgReq(pst, rlcUeCfg) != ROK)
858                {
859                   DU_LOG("\nERROR  -->  RLC: deleteRlcUeCb(): Failed to delete UE information");
860                   result = INVALID_UEID;
861                }
862             }
863          }
864          else
865          {
866             result = INVALID_CELLID;
867          }
868       }
869       else
870       {
871          result = INVALID_UEID;
872       }
873
874       if(result != SUCCESSFUL)
875       {
876          ret = sendRlcUeDeleteRspToDu(ueDelete->ueIdx, ueDelete->cellId, result);
877          if(ret != ROK)
878          {
879             DU_LOG("\nERROR  -->  RLC: RlcProcUeDeleteReq():Failed to send UE Delete response to DU");
880          }
881       }
882       RLC_FREE_SHRABL_BUF(pst->region, pst->pool, ueDelete, sizeof(RlcUeDelete));
883    }
884    else
885    {
886       DU_LOG("\nERROR  -->  RLC: RlcProcUeDeleteReq(): Recieved NULL pointer UE Delete ");
887       ret = RFAILED;
888    }
889    return ret;
890 }
891
892 /**********************************************************************
893          End of file
894 **********************************************************************/