1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 *******************************************************************************/
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 */
31 /* header/extern include files (.x) */
33 #include "lkw.x" /* LKW */
34 #include "ckw.x" /* CKW */
35 #include "kwu.x" /* KWU */
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 /*******************************************************************
48 * @brief Fills RLC UL UE Cfg Rsp from RlcCRsp
52 * Function : fillRlcUeCfgRsp
55 * Fills RLC UL UE Cfg Rsp from RlcCRsp
57 * @params[in] Pointer to RlcCfgCfm
58 * Pointer to RlcUeCfgRsp
62 *****************************************************************/
64 uint8_t fillRlcUeCfgRsp(RlcUeCfgRsp *rlcCfgRsp, RlcCfgCfmInfo *rlcCRsp)
69 rlcCfgRsp->cellId = rlcCRsp->cellId;
70 rlcCfgRsp->ueIdx = rlcCRsp->ueId;
71 for(idx = 0; idx < rlcCRsp->numEnt; idx++)
73 if(rlcCRsp->entCfgCfm[idx].status.status == CKW_CFG_CFM_OK)
75 rlcCfgRsp->result = RLC_DU_APP_RSP_OK;
76 rlcCfgRsp->reason = rlcCRsp->entCfgCfm[idx].status.reason;
81 rlcCfgRsp->result = RLC_DU_APP_RSP_NOK;
82 rlcCfgRsp->reason = rlcCRsp->entCfgCfm[idx].status.reason;
90 /*******************************************************************
92 * @brief Fills the entity mode and direction compiling to seed code
96 * Function : fillEntModeAndDir
99 * Fills the entity mode and direction compiling to seed code
101 * @params[in] Pointer to entMode
102 * Pointer to direction
105 * ****************************************************************/
107 void fillEntModeAndDir(uint8_t *entMode, uint8_t *direction, RlcMode rlcMode)
112 *entMode = CM_LTE_MODE_AM;
113 *direction = RLC_CFG_DIR_BOTH;
115 case RLC_UM_BI_DIRECTIONAL:
116 *entMode = CM_LTE_MODE_UM;
117 *direction = RLC_CFG_DIR_BOTH;
119 case RLC_UM_UNI_DIRECTIONAL_UL:
120 *entMode = CM_LTE_MODE_UM;
121 *direction = RLC_CFG_DIR_UL;
123 case RLC_UM_UNI_DIRECTIONAL_DL:
124 *entMode = CM_LTE_MODE_UM;
125 *direction = RLC_CFG_DIR_DL;
128 DU_LOG("\nRLC: Rlc Mode invalid %d", rlcMode);
133 /*******************************************************************
135 * @brief fills LC Cfgs to be Added in RLC
139 * Function : fillLcCfg
142 * fills LC Cfgs to be Added in RLC
145 * RlcEntCfgInfo pointer
146 * RlcBearerCfg pointer
150 * ****************************************************************/
151 void fillLcCfg(RlcEntCfgInfo *rlcUeCfg, RlcBearerCfg *duRlcUeCfg, uint8_t cfgType)
153 uint8_t lChRbIdx = 0;
155 rlcUeCfg->rbId = duRlcUeCfg->rbId;
156 rlcUeCfg->rbType = duRlcUeCfg->rbType; // SRB or DRB
157 rlcUeCfg->lCh[lChRbIdx].lChId = duRlcUeCfg->lcId;
158 rlcUeCfg->lCh[lChRbIdx].type = duRlcUeCfg->lcType;
159 fillEntModeAndDir(&rlcUeCfg->entMode, &rlcUeCfg->dir, duRlcUeCfg->rlcMode);
160 rlcUeCfg->cfgType = cfgType;
161 switch(rlcUeCfg->entMode)
167 rlcUeCfg->m.amInfo.dl.snLen = duRlcUeCfg->u.amCfg->dlAmCfg.snLenDl;
168 rlcUeCfg->m.amInfo.dl.pollRetxTmr = duRlcUeCfg->u.amCfg->dlAmCfg.pollRetxTmr;
169 rlcUeCfg->m.amInfo.dl.pollPdu = duRlcUeCfg->u.amCfg->dlAmCfg.pollPdu;
170 rlcUeCfg->m.amInfo.dl.pollByte = duRlcUeCfg->u.amCfg->dlAmCfg.pollByte;
171 rlcUeCfg->m.amInfo.dl.maxRetx = duRlcUeCfg->u.amCfg->dlAmCfg.maxRetxTh;
174 lChRbIdx++; //lChRbIdx = 1, indicates UL AM
175 rlcUeCfg->lCh[lChRbIdx].lChId = duRlcUeCfg->lcId;
176 rlcUeCfg->lCh[lChRbIdx].type = duRlcUeCfg->lcType;
177 rlcUeCfg->m.amInfo.ul.snLen = duRlcUeCfg->u.amCfg->ulAmCfg.snLenUl;
178 rlcUeCfg->m.amInfo.ul.staProhTmr = duRlcUeCfg->u.amCfg->ulAmCfg.statProhTmr;
179 rlcUeCfg->m.amInfo.ul.reOrdTmr = duRlcUeCfg->u.amCfg->ulAmCfg.reAssemTmr;
185 rlcUeCfg->m.umInfo.ul.snLen = duRlcUeCfg->u.umBiDirCfg->ulUmCfg.snLenUlUm;
186 rlcUeCfg->m.umInfo.ul.reOrdTmr = duRlcUeCfg->u.umBiDirCfg->ulUmCfg.reAssemTmr;
189 rlcUeCfg->m.umInfo.dl.snLen = duRlcUeCfg->u.umBiDirCfg->dlUmCfg.snLenDlUm;
194 }/* End of switch(entMode) */
197 /*******************************************************************
199 * @brief fills LC Cfgs to be Added in RLC
203 * Function : fillRlcCfg
206 * fills LC Cfgs to be Add/Mod/Del in RLC
209 * RlcEntCfgInfo pointer
210 * RlcBearerCfg pointer
213 ******************************************************************/
215 void fillRlcCfg(RlcCfgInfo *rlcUeCfg, RlcUeCfg *ueCfg)
219 rlcUeCfg->ueId = ueCfg->ueIdx;
220 rlcUeCfg->cellId = ueCfg->cellId;
221 rlcUeCfg->numEnt = ueCfg->numLcs;
222 rlcUeCfg->transId = getTransId();
224 for(lcIdx = 0; lcIdx < rlcUeCfg->numEnt; lcIdx++)
226 fillLcCfg(&rlcUeCfg->entCfg[lcIdx], &ueCfg->rlcLcCfg[lcIdx], ueCfg->rlcLcCfg[lcIdx].configType);
230 /*******************************************************************
232 * @brief Handles Ue Create Request from DU APP
236 * Function : RlcProcUeCreateReq
239 * Handles Ue create Request from DU APP
241 * @params[in] Post structure pointer
243 * @return ROK - success
246 * ****************************************************************/
247 uint8_t RlcProcUeCreateReq(Pst *pst, RlcUeCfg *ueCfg)
250 RlcCfgInfo *rlcUeCfg = NULLP;
252 RlcCb *rlcUeCb = NULLP;
253 rlcUeCb = RLC_GET_RLCCB(pst->dstInst);
254 RLC_ALLOC(rlcUeCb, rlcUeCfg, sizeof(RlcCfgInfo));
255 if(rlcUeCfg == NULLP)
257 DU_LOG("\nRLC: Failed to allocate memory at RlcProcUeCreateReq()");
262 memset(rlcUeCfg, 0, sizeof(RlcCfgInfo));
263 fillRlcCfg(rlcUeCfg, ueCfg);
264 ret = RlcProcCfgReq(pst, rlcUeCfg);
266 DU_LOG("\nRLC: Failed to configure Add/Mod/Del entities at RlcProcUeCreateReq()");
269 RLC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(RlcUeCfg));
273 /*******************************************************************
275 * @brief filling the structure of rrc delivery msg info
279 * Function : BuildAndSendRrcDeliveryReportToDu
281 * Functionality: filling the structure of rrc delivery msg info
283 * @return ROK - success
286 * ****************************************************************/
287 uint8_t BuildAndSendRrcDeliveryReportToDu( RlcDlRrcMsgInfo *dlRrcMsgInfo )
290 RrcDeliveryReport *rrcDelivery;
292 DU_LOG("\nRLC : Filling the RRC Delivery Report");
293 RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_UL, RLC_POOL, rrcDelivery, sizeof(RrcDeliveryReport));
297 rrcDelivery->cellId = dlRrcMsgInfo->cellId;
298 rrcDelivery->ueIdx = dlRrcMsgInfo->ueIdx;
299 rrcDelivery->srbId = dlRrcMsgInfo->lcId ;
300 rrcDelivery->rrcDeliveryStatus.deliveryStatus = PDCP_SN;
301 rrcDelivery->rrcDeliveryStatus.triggeringMessage = PDCP_SN;
303 /* Sending UL RRC Message transfeer to DU APP */
304 memset(&pst, 0, sizeof(Pst));
305 FILL_PST_RLC_TO_DUAPP(pst, RLC_UL_INST, EVENT_RRC_DELIVERY_MSG_TRANS_TO_DU);
306 rlcSendRrcDeliveryReportToDu(&pst, rrcDelivery);
310 DU_LOG("\nRLC : Memory allocation failed");
315 /* ****************************************************************
317 * @brief Process the DL RRC Message from DU APP
321 * Function : RlcProcDlRrcMsgTransfer
323 * Functionality: Process the DL RRC Message from DU APP
325 * @params[in] Post structure
326 * DL RRC Message info
327 * @return ROK - success
330 * ****************************************************************/
331 uint8_t RlcProcDlRrcMsgTransfer(Pst *pst, RlcDlRrcMsgInfo *dlRrcMsgInfo)
334 KwuDatReqInfo *datReqInfo;
336 RLC_SHRABL_STATIC_BUF_ALLOC(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(KwuDatReqInfo));
339 DU_LOG("\nRLC : Memory allocation failed in RlcProcDlRrcMsgTransfer");
340 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlRrcMsgInfo->rrcMsg, dlRrcMsgInfo->msgLen);
341 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
345 datReqInfo->rlcId.rbType = dlRrcMsgInfo->rbType;
346 datReqInfo->rlcId.rbId = dlRrcMsgInfo->rbId;
347 datReqInfo->rlcId.ueId = dlRrcMsgInfo->ueIdx;
348 datReqInfo->rlcId.cellId = dlRrcMsgInfo->cellId;
349 datReqInfo->lcType = dlRrcMsgInfo->lcType;
350 datReqInfo->sduId = ++(rlcCb[pst->dstInst]->dlSduId);
352 /* Copy fixed buffer to message */
353 if(ODU_GET_MSG_BUF(RLC_MEM_REGION_UL, RLC_POOL, &mBuf) != ROK)
355 DU_LOG("\nRLC : Memory allocation failed at RlcMacProcUlData");
356 RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(KwuDatReqInfo));
357 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlRrcMsgInfo->rrcMsg, dlRrcMsgInfo->msgLen);
358 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
361 oduCpyFixBufToMsg(dlRrcMsgInfo->rrcMsg, mBuf, dlRrcMsgInfo->msgLen);
363 rlcProcDlData(pst, datReqInfo, mBuf);
365 /* RRC Delivery report is only send when RRC Delivery status report is true in DL RRC Message */
366 if(dlRrcMsgInfo->deliveryStaRpt)
368 BuildAndSendRrcDeliveryReportToDu(dlRrcMsgInfo);
371 /* Free memory allocated by du app */
372 RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(KwuDatReqInfo));
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));
378 /*******************************************************************
380 * @brief Process UL data from UE
384 * Function : RlcProcUlData
387 * This function receives the PDU from MAC.
388 * seggregates common and dedicated logical channel
389 * PDU and call respective handler.
392 * @return ROK - success
395 * ****************************************************************/
396 uint8_t RlcProcUlData(Pst *pst, RlcData *ulData)
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 */
407 /* Initializing dedicated logical channel Database */
408 DU_LOG("\nRLC: Received UL Data request from MAC");
409 for(idx = 0; idx < MAX_NUM_LC; idx++)
411 dLchData[idx].lcId = idx;
412 dLchData[idx].pdu.numPdu = 0;
416 /* Seggregate PDUs received on common and dedicated channels
417 * and call common channel's handler */
418 for(idx = 0; idx< ulData->numPdu; idx++)
420 if(ulData->pduInfo[idx].commCh)
422 RLC_SHRABL_STATIC_BUF_ALLOC(RLC_MEM_REGION_UL, RLC_POOL, cLchUlDat, \
423 sizeof(RguCDatIndInfo));
426 DU_LOG("\nRLC : Memory allocation failed at RlcProcUlData");
430 memset(cLchUlDat, 0, sizeof(RguCDatIndInfo));
432 cLchUlDat->cellId = ulData->cellId;
433 GET_UE_IDX(ulData->rnti, cLchUlDat->rnti);
434 cLchUlDat->lcId = ulData->pduInfo[idx].lcId;
436 /* Copy fixed buffer to message */
437 if(ODU_GET_MSG_BUF(RLC_MEM_REGION_UL, RLC_POOL, &cLchUlDat->pdu) != ROK)
439 DU_LOG("\nRLC : Memory allocation failed at RlcProcUlData");
440 RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_UL, RLC_POOL, cLchUlDat, \
441 sizeof(RguCDatIndInfo));
445 oduCpyFixBufToMsg(ulData->pduInfo[idx].pduBuf, cLchUlDat->pdu, \
446 ulData->pduInfo[idx].pduLen);
448 rlcProcCommLcUlData(pst, 0, cLchUlDat);
454 RLC_SHRABL_STATIC_BUF_ALLOC(RLC_MEM_REGION_UL, RLC_POOL, dLchUlDat, \
455 sizeof(RguDDatIndInfo));
458 DU_LOG("\nRLC : Memory allocation failed at RlcMacProcUlData");
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)
470 DU_LOG("\nRLC : Memory allocation failed at RlcMacProcUlData");
471 for(pduIdx=0; pduIdx < dLchData[lcId].pdu.numPdu; pduIdx++)
473 ODU_PUT_MSG_BUF(dLchData[lcId].pdu.mBuf[dLchData[lcId].pdu.numPdu]);
475 RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_UL, RLC_POOL, dLchUlDat, \
476 sizeof(RguDDatIndInfo));
480 oduCpyFixBufToMsg(ulData->pduInfo[idx].pduBuf, \
481 dLchData[lcId].pdu.mBuf[dLchData[lcId].pdu.numPdu],\
482 ulData->pduInfo[idx].pduLen);
484 dLchData[lcId].pdu.numPdu++;
488 /* If any PDU received on dedicated logical channel, copy into RguDDatIndInfo
489 * and call its handler */
494 dLchUlDat->cellId = ulData->cellId;
495 dLchUlDat->rnti = ulData->rnti;
497 for(idx = 0; idx < MAX_NUM_LC; idx++)
499 if(dLchData[idx].pdu.numPdu)
501 memcpy(&dLchUlDat->lchData[numDLch], &dLchData[idx], sizeof(RguLchDatInd));
505 dLchUlDat->numLch = numDLch;
506 rlcProcDedLcUlData(pst, 0, dLchUlDat);
510 for(pduIdx = 0; pduIdx < ulData->numPdu; pduIdx++)
512 RLC_FREE_SHRABL_BUF(pst->region, pst->pool, ulData->pduInfo[pduIdx].pduBuf, \
513 ulData->pduInfo[pduIdx].pduLen);
515 RLC_FREE_SHRABL_BUF(pst->region, pst->pool, ulData, sizeof(RlcData));
518 }/* End of RlcProcUlData */
520 /*******************************************************************
522 * @brief Handler for extracting common and dedicated channel
523 * Scheduling result report.
527 * Function : RlcProcSchedResultRpt
530 * Handler for extracting common and dedicated channel
531 * Scheduling result report
534 * @return ROK - success
537 * ****************************************************************/
538 uint8_t RlcProcSchedResultRpt(Pst *pst, RlcSchedResultRpt *schRep)
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 */
546 DU_LOG("\nRLC : Received scheduling report from MAC");
547 for(idx=0; idx < schRep->numLc; idx++)
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)
553 RLC_SHRABL_STATIC_BUF_ALLOC(RLC_MEM_REGION_DL, RLC_POOL, cLchSchInfo, \
554 sizeof(RguCStaIndInfo));
557 DU_LOG("\nRLC: RlcProcSchedResultRpt: Memory allocation failed for cLchSchInfo");
561 memset(cLchSchInfo, 0, sizeof(RguCStaIndInfo));
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);
573 /* Fill status info structure if at least one dedicated channel
574 * scheduling report is received */
577 RLC_SHRABL_STATIC_BUF_ALLOC(RLC_MEM_REGION_DL, RLC_POOL, dLchSchInfo, \
578 sizeof(RguDStaIndInfo));
581 DU_LOG("\nRLC: RlcProcSchedResultRpt: Memory allocation failed for dLchSchInfo");
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;
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;
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;
609 /* Calling handler for all dedicated channels scheduling*/
614 dLchSchInfo->staInd[0].staIndTb[0].nmbLch = nmbDLch;
615 rlcProcDedLcSchedRpt(pst, 0, dLchSchInfo);
619 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, schRep, sizeof(RlcSchedResultRpt));
624 /*******************************************************************
626 * @brief Handles Ue Reconfig Request from DU APP
630 * Function : RlcProcUeReconfigReq
633 * Handles Ue Reconfig Request from DU APP
635 * @params[in] Post structure pointer
637 * @return ROK - success
640 * ****************************************************************/
641 uint8_t RlcProcUeReconfigReq(Pst *pst, RlcUeCfg *ueCfg)
644 RlcCfgInfo *rlcUeCfg = NULLP; //Seed code Rlc cfg struct
645 RlcCb *rlcUeCb = NULLP;
647 DU_LOG("\nRLC: UE reconfig request received. CellID[%d] UEIDX[%d]",ueCfg->cellId, ueCfg->ueIdx);
649 rlcUeCb = RLC_GET_RLCCB(pst->dstInst);
650 RLC_ALLOC(rlcUeCb, rlcUeCfg, sizeof(RlcCfgInfo));
651 if(rlcUeCfg == NULLP)
653 DU_LOG("\nRLC: Failed to allocate memory at RlcProcUeReconfigReq()");
658 memset(rlcUeCfg, 0, sizeof(RlcCfgInfo));
659 fillRlcCfg(rlcUeCfg, ueCfg);
660 ret = RlcProcCfgReq(pst, rlcUeCfg);
662 DU_LOG("\nRLC: Failed to configure Add/Mod/Del entities at RlcProcUeReconfigReq()");
665 RLC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(RlcUeCfg));
669 /**********************************************************************
671 **********************************************************************/