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