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 /********************************************************************20**
21 Name: NR RLC Layer - Upper Interface Functions
25 Desc: Source code for RLC Upper Interface Module
26 This file contains following functions
39 **********************************************************************/
41 * @file rlc_upr_inf_mgr.c
42 * @brief RLC Upper Interface Module
45 #define RLC_MODULE RLC_DBGMASK_INF
48 /* header (.h) include files */
49 #include "common_def.h"
50 #include "lkw.h" /* LKW defines */
51 #include "ckw.h" /* CKW defines */
52 #include "kwu.h" /* KWU defines */
53 #include "rgu.h" /* RGU defines */
54 #include "rlc_env.h" /* RLC environment options */
58 /* extern (.x) include files */
59 #include "lkw.x" /* LKW */
60 #include "ckw.x" /* CKW */
61 #include "kwu.x" /* KWU */
62 #include "rgu.x" /* RGU */
64 #include "rlc_utils.h" /* RLC defines */
65 #include "rlc_dl_ul_inf.h"
68 /*****************************************************************************
70 ****************************************************************************/
74 * Handler for binding the RLC upper layer service user with
78 * This function is used by RLC user to request for binding to
79 * RLC. This function is called by the CKW interface to bind
80 * RLC's SAP (identified by spId) with the service user's
81 * SAP (identified by suId).
83 * @param[in] pst Post structure
84 * @param[in] suId Service User ID
85 * @param[in] spId Service provider ID
102 #if (ERRCLASS & ERRCLS_INT_PAR)
103 if (pst->dstInst >= MAX_RLC_INSTANCES)
109 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
111 DU_LOG("\nDEBUG --> RLC_UL : spId(%d), suId(%d)", spId, suId);
112 ckwSap = &(tRlcCb->u.ulCb->ckwSap);
113 /* Take action based on the current state of the SAP */
114 switch(ckwSap->state)
116 /* SAP is configured but not bound */
120 /* copy bind configuration parameters in SSAP sap */
122 ckwSap->pst.dstProcId = pst->srcProcId;
123 ckwSap->pst.dstEnt = pst->srcEnt;
124 ckwSap->pst.dstInst = pst->srcInst;
126 /* Update the State */
127 ckwSap->state = RLC_SAP_BND;
129 DU_LOG("\nDEBUG --> RLC_UL : RlcUiCkwBndReq: state (%d)", ckwSap->state);
134 /* Sap is already bound check source, destination Entity and
136 if (ckwSap->pst.dstProcId != pst->srcProcId ||
137 ckwSap->pst.dstEnt != pst->srcEnt ||
138 ckwSap->pst.dstInst != pst->srcInst ||
139 ckwSap->suId != suId)
141 RLC_SEND_SAPID_ALARM(tRlcCb,
143 LKW_EVENT_CKW_BND_REQ,
144 LCM_CAUSE_INV_PAR_VAL);
146 DU_LOG("\nERROR --> RLC_UL : CKW SAP already Bound");
147 RlcUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_NOK);
154 #if (ERRCLASS & ERRCLS_INT_PAR)
155 DU_LOG("\nERROR --> RLC_UL : Invalid CKW SAP State in Bind Req");
156 RLC_SEND_SAPID_ALARM(tRlcCb,
158 LKW_EVENT_CKW_BND_REQ,
159 LCM_CAUSE_INV_STATE);
160 #endif /* ERRCLASS & ERRCLS_INT_PAR */
161 RlcUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_NOK);
167 RlcUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_OK);
174 * Handler for unbinding the RLC upper layer service user CKW with
178 * This function is used by RLC user to request for unbinding
179 * with RLC.This function is called by the CKW interface to
182 * @param[in] pst Post structure
183 * @param[in] spId Service provider SAP ID
184 * @param[in] reason Reason for Unbinding
199 #if (ERRCLASS & ERRCLS_INT_PAR)
200 if (pst->dstInst >= MAX_RLC_INSTANCES)
204 #endif /* ERRCLASS & ERRCLS_INT_PAR */
205 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
207 DU_LOG("\nDEBUG --> RLC_UL : spId(%d), reason(%d)",
213 #if (ERRCLASS & ERRCLS_INT_PAR)
214 RLC_GET_AND_VALIDATE_CKWSAP(tRlcCb,
215 (&(tRlcCb->u.ulCb->ckwSap)),
218 #endif /* ERRCLASS & ERRCLS_INT_PAR */
220 /* disable upper sap (CKW) */
221 tRlcCb->u.ulCb->ckwSap.state = RLC_SAP_CFG;
227 * Handler for configuring RLC entities.
230 * This function is used by RRC to configure(add/delete/modify)
231 * one or more RLC entities.
233 * @param[in] pst - Post structure
234 * @param[in] spId - Serive Provider ID
235 * @param[in] cfg - Configuration information for one or more RLC entities.
248 RlcUlCfgTmpData *cfgTmpData;
250 static uint32_t transCount;
252 #if (ERRCLASS & ERRCLS_INT_PAR)
253 if (pst->dstInst >= MAX_RLC_INSTANCES)
255 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
259 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
261 RLC_ALLOC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
263 if (cfgTmpData == NULLP)
265 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
269 cfgTmpData->uprLyrTransId = cfg->transId; /*Save User TransId*/
270 cfgTmpData->transId = ++transCount; /*Generate new TransId*/
271 cfg->transId = cfgTmpData->transId;
272 cfgTmpData->cfgInfo = cfg;
275 tRlcCb->u.ulCb->rlcUlUdxEventType = pst->event;
276 if (rlcDbmAddUlTransaction(tRlcCb, cfgTmpData) != ROK)
278 DU_LOG("\nERROR --> RLC_UL : Addition to UL transId Lst Failed");
279 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
284 rlcUlHdlCfgReq(tRlcCb, cfgTmpData, cfg);
285 rlcUlUdxCfgReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),RLC_GET_UDX_SAP(tRlcCb)->spId,cfg);
292 * Handler to change the UeId
295 * This primitive is used by RRC to change the UeId for the existing UE
298 * @param[in] pst - Point to the pst structure
299 * @param[in] spId - The ID of the service provider SAP in the RLC layer
300 * @param[in] transId - Transaction ID. This field uniquily identifies
301 * transaction between RRC and RLC
302 * @param[in] ueInfo - Old UE Id Info for which the change request has come
303 * @param[in] newUeInfo - New UE Id Info for existing UE context
309 S16 RlcUiCkwUeIdChgReq
320 RlcUlCfgTmpData *cfgTmpData = NULLP;
324 #if (ERRCLASS & ERRCLS_INT_PAR)
325 if (pst->dstInst >= MAX_RLC_INSTANCES)
332 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
334 DU_LOG("\nDEBUG --> RLC_UL : RlcUiCkwUeIdChgReq(pst, spId(%d), transId(%ld))",
338 DU_LOG("\nDEBUG --> RLC_UL : RlcUiCkwUeIdChgReq(pst, spId(%d), transId(%d))\n",
342 RLC_ALLOC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
349 cfgTmpData->transId = transId;
350 cfgTmpData->ueInfo = ueInfo;
351 cfgTmpData->newUeInfo = newUeInfo;
353 if (rlcDbmAddUlTransaction(tRlcCb, cfgTmpData))
355 DU_LOG("\nERROR --> RLC_UL : Addition to UL transId Lst Failed");
363 /* there was an error in the processing, free up all the memory
364 * that was passed and could have been allocated in this function
366 /* Freeing from proper region */
367 RLC_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CkwUeInfo));
368 RLC_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CkwUeInfo));
372 RLC_FREE(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
377 if(ROK != rlcCfgValidateUeIdChng(tRlcCb,ueInfo,newUeInfo,cfgTmpData))
379 DU_LOG("\nERROR --> RLC_UL : Validation Failure for UeId change");
382 rlcUlUdxUeIdChgReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),
383 RLC_GET_UDX_SAP(tRlcCb)->spId,
394 * Handler for Configuration Request
396 * @param[in] gCb RLC Instance Control Block
397 * @param[in] cfgTmpData Configuration stored in Transaction Block
398 * @param[in] cfg Configuration block
407 RlcUlCfgTmpData *cfgTmpData,
413 cfgTmpData->ueId = cfg->ueId;
414 cfgTmpData->cellId = cfg->cellId;
415 for (idx = 0; idx < cfg->numEnt; idx++)
417 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_OK;
418 cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbId = cfg->entCfg[idx].rbId;
419 cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbType = cfg->entCfg[idx].rbType;
420 switch(cfg->entCfg[idx].cfgType)
427 if(cfg->entCfg[idx].dir & RLC_DIR_UL)
429 /* Configuration is for UL , thus validating */
430 if(ROK != rlcCfgValidateUlRb(gCb,
432 &cfgTmpData->cfgEntData[idx],
435 DU_LOG("\nERROR --> RLC_UL : CELLID [%u]:Validation Failure for UL RB [%d]",
436 cfg->cellId,cfg->entCfg[idx].rbId);
437 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
438 /*Validation is getting failed so no need to do configuration at DL.
439 *Set dir as UL, so that no configuration is done at DL */
440 cfg->entCfg[idx].dir = RLC_DIR_UL;
443 if(cfg->entCfg[idx].dir == RLC_DIR_UL)
445 /*If the configuration is for UL only then apply it */
446 if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
450 &cfgTmpData->cfgEntData[idx],
456 case CKW_CFG_REESTABLISH:
458 if(cfg->entCfg[idx].dir & RLC_DIR_UL)
460 if(ROK != rlcCfgValidateReEstRb(gCb,
464 &cfgTmpData->cfgEntData[idx]))
466 DU_LOG("\nERROR --> RLC_UL : CellID [%u]:Validation Failure for Reest UL RB [%d]",
467 cfg->cellId,cfg->entCfg[idx].rbId);
468 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
469 /* Setting dir as UL, so that no configuration is done at DL */
470 cfg->entCfg[idx].dir = RLC_DIR_UL;
474 if(cfg->entCfg[idx].dir == RLC_DIR_UL)
476 /*If the configuration is for UL only then apply it */
477 if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
479 rlcCfgApplyReEstUlRb(gCb,
483 &cfgTmpData->cfgEntData[idx]);
488 case CKW_CFG_DELETE_UE :
490 if(ROK != rlcCfgValidateDelUlUe(gCb,
492 &cfgTmpData->cfgEntData[idx],
495 DU_LOG("\nERROR --> RLC_UL : UL UEID [%d]:Validation Failure",
497 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
498 /* Setting dir as UL, so that no configuration is done at DL */
499 cfg->entCfg[idx].dir = RLC_DIR_UL;
503 case CKW_CFG_DELETE_CELL :
505 if(ROK != rlcCfgValidateDelUlCell(gCb,
508 &cfgTmpData->cfgEntData[idx],
511 DU_LOG("\nERROR --> RLC_UL : Del UL Cell Validation Failure");
512 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
513 /* Setting dir as UL, so that no configuration is done at DL */
514 cfg->entCfg[idx].dir = RLC_DIR_UL;
524 /*****************************************************************************
526 ****************************************************************************/
529 * Handler for binding the RLC upper layer service user with
533 * This function is used by RLC user to request for binding to
534 * RLC.This function is called by the KWU interface to bind
535 * RLC's SAP (identified by spId) with the service user's
536 * SAP (identified by suId).
538 * @param[in] pst Post structure
539 * @param[in] suId Service user SAP ID
540 * @param[in] spId Service provider ID
554 RlcKwuSapCb *rlckwuSap; /* SAP Config Block */
557 #if (ERRCLASS & ERRCLS_INT_PAR)
558 if (pst->dstInst >= MAX_RLC_INSTANCES)
563 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
564 DU_LOG("\nDEBUG --> RLC_UL : RlcUiKwuBndReq(pst, spId(%d), suId(%d))", spId, suId);
566 /* Validation of input parameters */
567 #if (ERRCLASS & ERRCLS_INT_PAR)
568 if(!((spId < (S16) tRlcCb->genCfg.maxKwuSaps) && (spId >=0)))
570 DU_LOG("\nERROR --> RLC_UL : Invalid spId");
571 RLC_SEND_SAPID_ALARM(tRlcCb,spId, LKW_EVENT_KWU_BND_REQ, LCM_CAUSE_INV_SAP);
576 /* Get Sap control block */
577 rlckwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
578 (tRlcCb->u.dlCb->rlcKwuDlSap + spId):
579 (tRlcCb->u.ulCb->rlcKwuUlSap + spId);
581 /* Take action based on the current state of the SAP */
582 switch(rlckwuSap->state)
584 /* SAP is configured but not bound */
588 /* copy bind configuration parameters in sap */
589 rlckwuSap->suId = suId;
590 rlckwuSap->pst.dstProcId = pst->srcProcId;
591 rlckwuSap->pst.dstEnt = pst->srcEnt;
592 rlckwuSap->pst.dstInst = pst->srcInst;
594 /* Update the State */
595 rlckwuSap->state = RLC_SAP_BND;
597 DU_LOG("\nDEBUG --> RLC_UL : RlcUiKwuBndReq: state (%d)", rlckwuSap->state);
602 /* Sap is already bound check source, destination Entity and Proc Id */
603 if (rlckwuSap->pst.dstProcId != pst->srcProcId ||
604 rlckwuSap->pst.dstEnt != pst->srcEnt ||
605 rlckwuSap->pst.dstInst != pst->srcInst ||
606 rlckwuSap->suId != suId)
608 RLC_SEND_SAPID_ALARM(tRlcCb,
610 LKW_EVENT_KWU_BND_REQ,
611 LCM_CAUSE_INV_PAR_VAL);
612 DU_LOG("\nERROR --> RLC_UL : RLC Mode [%d] : KWU SAP already Bound",
613 tRlcCb->genCfg.rlcMode);
614 RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_NOK);
622 #if (ERRCLASS & ERRCLS_INT_PAR)
623 DU_LOG("\nERROR --> RLC_UL : RLC Mode [%d]:Invalid KWU SAP State in Bind Req",
624 tRlcCb->genCfg.rlcMode);
625 RLC_SEND_SAPID_ALARM(tRlcCb,
627 LKW_EVENT_KWU_BND_REQ,
628 LCM_CAUSE_INV_STATE);
629 #endif /* ERRCLASS & ERRCLS_INT_PAR */
630 RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_NOK);
634 RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_OK);
641 * Handler for unbinding the RLC upper layer service user with
645 * This function is used by RLC user to request for unbinding
646 * with RLC.This function is called by the KWU interface to
649 * @param[in] pst Post structure
650 * @param[in] spId Service provider SAP ID
651 * @param[in] reason Reason for Unbinding
664 RlcKwuSapCb *rlckwuSap; /* KWU SAP control block */
667 #if (ERRCLASS & ERRCLS_INT_PAR)
668 if ((pst->dstInst >= MAX_RLC_INSTANCES) ||
669 (spId >= (S16) rlcCb[pst->dstInst]->genCfg.maxKwuSaps) ||
676 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
678 DU_LOG("\nDEBUG --> RLC_UL : spId(%d), reason(%d)",
682 /* Get Sap control block */
683 rlckwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
684 (tRlcCb->u.dlCb->rlcKwuDlSap + spId):
685 (tRlcCb->u.ulCb->rlcKwuUlSap + spId);
687 rlckwuSap->state = RLC_SAP_CFG;
693 * @brief Handler for receiving the data(SDU) from upper layer.
696 * This function is used by RLC service user (PDCP) to
697 * transfer data (SDU) to RLC.
699 * @param[in] pst Post structure
700 * @param[in] spId Service Provider SAP ID
701 * @param[in] datreq Data Request Information
702 * @param[in] mBuf Data Buffer (SDU)
708 uint8_t rlcProcDlData(Pst *pst, RlcDatReqInfo *datReq, Buffer *mBuf)
710 uint8_t ret = ROK; /* Return Value */
711 RlcDlRbCb *rbCb; /* RB Control Block */
714 DU_LOG("\nDEBUG --> RLC_DL : Received DL Data");
716 #if (ERRCLASS & ERRCLS_INT_PAR)
717 if(pst->dstInst >= MAX_RLC_INSTANCES)
719 ODU_PUT_MSG_BUF(mBuf);
724 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
727 rlcDbmFetchDlRbCbByRbId(tRlcCb, &datReq->rlcId, &rbCb);
730 DU_LOG("\nERROR --> RLC_DL : CellId[%u]:DL RbId [%d] not found",
731 datReq->rlcId.cellId,datReq->rlcId.rbId);
732 ODU_PUT_MSG_BUF(mBuf);
737 /* Dispatch according to mode of the rbCb */
742 /* Verify the user */
743 if (pst->srcEnt != ENTNH)
745 /* kw002.201 Freeing from proper region */
746 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, datReq,
747 sizeof(RlcDatReqInfo));
748 ODU_PUT_MSG_BUF(mBuf);
753 rlcTmmQSdu(tRlcCb,rbCb, datReq, mBuf);
758 rlcUmmQSdu(tRlcCb,rbCb, datReq, mBuf);
763 rlcAmmQSdu(tRlcCb,rbCb, mBuf, datReq);
768 DU_LOG("\nERROR --> RLC_DL : Invalid RB Mode");
778 * Handler for discarding a SDU.
781 * This function is used by RLC AM and RLC UM entities.
782 * This function is called by the service user to discard a particular
783 * RLC SDU if it is present in the SDU queue of the RB control block
784 * and if it is not mapped to any PDU.
786 * @param[in] pst Post structure
787 * @param[in] spId Service Provider SAP ID
788 * @param[in] discSdu SDU discard Information
794 S16 RlcUiKwuDiscSduReq
798 KwuDiscSduInfo *discSdu
801 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, discSdu, sizeof(KwuDiscSduInfo));
805 /********************************************************************30**
807 **********************************************************************/