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: LTE-RLC Layer - Upper Interface Functions
25 Desc: Source code for RLC Upper Interface Module
26 This file contains following functions
39 **********************************************************************/
40 static const char* RLOG_MODULE_NAME="UIM";
41 static int RLOG_MODULE_ID=2048;
42 static int RLOG_FILE_ID=205;
46 * @brief RLC Upper Interface Module
49 #define RLC_MODULE RLC_DBGMASK_INF
52 /* header (.h) include files */
53 #include "common_def.h"
54 #include "lkw.h" /* LKW defines */
55 #include "ckw.h" /* CKW defines */
56 #include "kwu.h" /* KWU defines */
57 #include "rgu.h" /* RGU defines */
58 #include "kw_env.h" /* RLC environment options */
59 #include "kw.h" /* RLC defines */
64 /* extern (.x) include files */
65 #include "lkw.x" /* LKW */
66 #include "ckw.x" /* CKW */
67 #include "kwu.x" /* KWU */
68 #include "rgu.x" /* RGU */
76 /*****************************************************************************
78 ****************************************************************************/
82 * Handler for binding the RLC upper layer service user with
86 * This function is used by RLC user to request for binding to
87 * RLC. This function is called by the CKW interface to bind
88 * RLC's SAP (identified by spId) with the service user's
89 * SAP (identified by suId).
91 * @param[in] pst Post structure
92 * @param[in] suId Service User ID
93 * @param[in] spId Service provider ID
108 S16 RlcUiCkwBndReq (pst, suId, spId)
117 #if (ERRCLASS & ERRCLS_INT_PAR)
118 if (pst->dstInst >= MAX_RLC_INSTANCES)
124 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
126 RLOG2(L_DEBUG, "spId(%d), suId(%d)", spId, suId);
127 ckwSap = &(tRlcCb->u.ulCb->ckwSap);
128 /* Take action based on the current state of the SAP */
129 switch(ckwSap->state)
131 /* SAP is configured but not bound */
135 /* copy bind configuration parameters in SSAP sap */
137 ckwSap->pst.dstProcId = pst->srcProcId;
138 ckwSap->pst.dstEnt = pst->srcEnt;
139 ckwSap->pst.dstInst = pst->srcInst;
141 /* Update the State */
142 ckwSap->state = RLC_SAP_BND;
144 RLOG1(L_DEBUG, "RlcUiCkwBndReq: state (%d)", ckwSap->state);
149 /* Sap is already bound check source, destination Entity and
151 if (ckwSap->pst.dstProcId != pst->srcProcId ||
152 ckwSap->pst.dstEnt != pst->srcEnt ||
153 ckwSap->pst.dstInst != pst->srcInst ||
154 ckwSap->suId != suId)
156 RLC_SEND_SAPID_ALARM(tRlcCb,
158 LKW_EVENT_CKW_BND_REQ,
159 LCM_CAUSE_INV_PAR_VAL);
161 RLOG0(L_ERROR, "CKW SAP already Bound");
162 RlcUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_NOK);
169 #if (ERRCLASS & ERRCLS_INT_PAR)
170 RLOG0(L_ERROR, "Invalid CKW SAP State in Bind Req");
171 RLC_SEND_SAPID_ALARM(tRlcCb,
173 LKW_EVENT_CKW_BND_REQ,
174 LCM_CAUSE_INV_STATE);
175 #endif /* ERRCLASS & ERRCLS_INT_PAR */
176 RlcUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_NOK);
182 RlcUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_OK);
189 * Handler for unbinding the RLC upper layer service user CKW with
193 * This function is used by RLC user to request for unbinding
194 * with RLC.This function is called by the CKW interface to
197 * @param[in] pst Post structure
198 * @param[in] spId Service provider SAP ID
199 * @param[in] reason Reason for Unbinding
213 S16 RlcUiCkwUbndReq(pst, spId, reason)
221 #if (ERRCLASS & ERRCLS_INT_PAR)
222 if (pst->dstInst >= MAX_RLC_INSTANCES)
226 #endif /* ERRCLASS & ERRCLS_INT_PAR */
227 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
229 RLOG2(L_DEBUG,"spId(%d), reason(%d)",
235 #if (ERRCLASS & ERRCLS_INT_PAR)
236 RLC_GET_AND_VALIDATE_CKWSAP(tRlcCb,
237 (&(tRlcCb->u.ulCb->ckwSap)),
240 #endif /* ERRCLASS & ERRCLS_INT_PAR */
242 /* disable upper sap (CKW) */
243 tRlcCb->u.ulCb->ckwSap.state = RLC_SAP_CFG;
249 * Handler for configuring RLC entities.
252 * This function is used by RRC to configure(add/delete/modify)
253 * one or more RLC entities.
255 * @param[in] pst - Post structure
256 * @param[in] spId - Serive Provider ID
257 * @param[in] cfg - Configuration information for one or more RLC entities.
270 S16 RlcProcCfgReq(pst, cfg)
276 RlcUlCfgTmpData *cfgTmpData;
278 static U32 transCount;
280 #if (ERRCLASS & ERRCLS_INT_PAR)
281 if (pst->dstInst >= MAX_RLC_INSTANCES)
283 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
287 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
289 RLC_ALLOC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
291 if (cfgTmpData == NULLP)
293 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
297 cfgTmpData->uprLyrTransId = cfg->transId; /*Save User TransId*/
298 cfgTmpData->transId = ++transCount; /*Generate new TransId*/
299 cfg->transId = cfgTmpData->transId;
300 cfgTmpData->cfgInfo = cfg;
303 if (rlcDbmAddUlTransaction(tRlcCb, cfgTmpData) != ROK)
305 RLOG0(L_ERROR, "Addition to UL transId Lst Failed");
306 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
311 rlcUlHdlCfgReq(tRlcCb, cfgTmpData, cfg);
312 rlcUlUdxCfgReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),RLC_GET_UDX_SAP(tRlcCb)->spId,cfg);
319 * Handler to change the UeId
322 * This primitive is used by RRC to change the UeId for the existing UE
325 * @param[in] pst - Point to the pst structure
326 * @param[in] spId - The ID of the service provider SAP in the RLC layer
327 * @param[in] transId - Transaction ID. This field uniquily identifies
328 * transaction between RRC and RLC
329 * @param[in] ueInfo - Old UE Id Info for which the change request has come
330 * @param[in] newUeInfo - New UE Id Info for existing UE context
337 S16 RlcUiCkwUeIdChgReq
346 S16 RlcUiCkwUeIdChgReq(pst, spId, transId, ueInfo, newUeInfo)
351 CkwUeInfo *newUeInfo;
356 RlcUlCfgTmpData *cfgTmpData = NULLP;
360 #if (ERRCLASS & ERRCLS_INT_PAR)
361 if (pst->dstInst >= MAX_RLC_INSTANCES)
368 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
370 RLOG_ARG2(L_DEBUG,DBG_CELLID,newUeInfo->cellId,
371 "RlcUiCkwUeIdChgReq(pst, spId(%d), transId(%ld))",
375 RLOG_ARG2(L_DEBUG,DBG_CELLID,newUeInfo->cellId,
376 "RlcUiCkwUeIdChgReq(pst, spId(%d), transId(%d))\n",
381 RLC_ALLOC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
388 cfgTmpData->transId = transId;
389 cfgTmpData->ueInfo = ueInfo;
390 cfgTmpData->newUeInfo = newUeInfo;
392 if (rlcDbmAddUlTransaction(tRlcCb, cfgTmpData))
394 RLOG0(L_ERROR, "Addition to UL transId Lst Failed");
402 /* there was an error in the processing, free up all the memory
403 * that was passed and could have been allocated in this function
405 /* Freeing from proper region */
406 RLC_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CkwUeInfo));
407 RLC_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CkwUeInfo));
411 RLC_FREE(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
416 if(ROK != rlcCfgValidateUeIdChng(tRlcCb,ueInfo,newUeInfo,cfgTmpData))
418 RLOG_ARG0(L_ERROR,DBG_CELLID,cfgTmpData->ueInfo->cellId,
419 "Validation Failure for UeId change");
422 rlcUlUdxUeIdChgReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),
423 RLC_GET_UDX_SAP(tRlcCb)->spId,
434 * Handler for Configuration Request
436 * @param[in] gCb RLC Instance Control Block
437 * @param[in] cfgTmpData Configuration stored in Transaction Block
438 * @param[in] cfg Configuration block
448 RlcUlCfgTmpData *cfgTmpData,
452 Void rlcUlHdlCfgReq(gCb, cfgTmpData, cfg)
454 RlcUlCfgTmpData *cfgTmpData;
460 cfgTmpData->ueId = cfg->ueId;
461 cfgTmpData->cellId = cfg->cellId;
462 for (idx = 0; idx < cfg->numEnt; idx++)
464 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_OK;
465 cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbId = cfg->entCfg[idx].rbId;
466 cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbType = cfg->entCfg[idx].rbType;
467 switch(cfg->entCfg[idx].cfgType)
474 if(cfg->entCfg[idx].dir & RLC_DIR_UL)
476 /* Configuration is for UL , thus validating */
477 if(ROK != rlcCfgValidateUlRb(gCb,
479 &cfgTmpData->cfgEntData[idx],
482 RLOG_ARG2(L_ERROR,DBG_UEID, cfgTmpData->ueId,
483 "CELLID [%u]:Validation Failure for UL RB [%d]",
484 cfg->cellId,cfg->entCfg[idx].rbId);
485 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
486 /*Validation is getting failed so no need to do configuration at DL.
487 *Set dir as UL, so that no configuration is done at DL */
488 cfg->entCfg[idx].dir = RLC_DIR_UL;
491 if(cfg->entCfg[idx].dir == RLC_DIR_UL)
493 /*If the configuration is for UL only then apply it */
494 if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
498 &cfgTmpData->cfgEntData[idx],
504 case CKW_CFG_REESTABLISH:
506 if(cfg->entCfg[idx].dir & RLC_DIR_UL)
508 if(ROK != rlcCfgValidateReEstRb(gCb,
512 &cfgTmpData->cfgEntData[idx]))
514 RLOG_ARG2(L_ERROR,DBG_UEID,cfg->ueId,
515 "CellID [%u]:Validation Failure for Reest UL RB [%d]",
516 cfg->cellId,cfg->entCfg[idx].rbId);
517 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
518 /* Setting dir as UL, so that no configuration is done at DL */
519 cfg->entCfg[idx].dir = RLC_DIR_UL;
523 if(cfg->entCfg[idx].dir == RLC_DIR_UL)
525 /*If the configuration is for UL only then apply it */
526 if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
528 rlcCfgApplyReEstUlRb(gCb,
532 &cfgTmpData->cfgEntData[idx]);
537 case CKW_CFG_DELETE_UE :
539 if(ROK != rlcCfgValidateDelUlUe(gCb,
541 &cfgTmpData->cfgEntData[idx],
544 RLOG_ARG1(L_ERROR,DBG_CELLID,cfg->cellId,
545 "UL UEID [%d]:Validation Failure",
547 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
548 /* Setting dir as UL, so that no configuration is done at DL */
549 cfg->entCfg[idx].dir = RLC_DIR_UL;
553 case CKW_CFG_DELETE_CELL :
555 if(ROK != rlcCfgValidateDelUlCell(gCb,
558 &cfgTmpData->cfgEntData[idx],
561 RLOG_ARG0(L_ERROR,DBG_CELLID,cfg->cellId,
562 "Del UL Cell Validation Failure");
563 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
564 /* Setting dir as UL, so that no configuration is done at DL */
565 cfg->entCfg[idx].dir = RLC_DIR_UL;
575 /*****************************************************************************
577 ****************************************************************************/
580 * Handler for binding the RLC upper layer service user with
584 * This function is used by RLC user to request for binding to
585 * RLC.This function is called by the KWU interface to bind
586 * RLC's SAP (identified by spId) with the service user's
587 * SAP (identified by suId).
589 * @param[in] pst Post structure
590 * @param[in] suId Service user SAP ID
591 * @param[in] spId Service provider ID
606 S16 RlcUiKwuBndReq (pst, suId, spId)
612 RlcKwuSapCb *rlckwuSap; /* SAP Config Block */
615 #if (ERRCLASS & ERRCLS_INT_PAR)
616 if (pst->dstInst >= MAX_RLC_INSTANCES)
621 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
622 RLOG2(L_DEBUG, "RlcUiKwuBndReq(pst, spId(%d), suId(%d))", spId, suId);
624 /* Validation of input parameters */
625 #if (ERRCLASS & ERRCLS_INT_PAR)
626 if(!((spId < (S16) tRlcCb->genCfg.maxKwuSaps) && (spId >=0)))
628 RLOG0(L_ERROR,"Invalid spId");
629 RLC_SEND_SAPID_ALARM(tRlcCb,spId, LKW_EVENT_KWU_BND_REQ, LCM_CAUSE_INV_SAP);
634 /* Get Sap control block */
635 rlckwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
636 (tRlcCb->u.dlCb->rlcKwuDlSap + spId):
637 (tRlcCb->u.ulCb->rlcKwuUlSap + spId);
639 /* Take action based on the current state of the SAP */
640 switch(rlckwuSap->state)
642 /* SAP is configured but not bound */
646 /* copy bind configuration parameters in sap */
647 rlckwuSap->suId = suId;
648 rlckwuSap->pst.dstProcId = pst->srcProcId;
649 rlckwuSap->pst.dstEnt = pst->srcEnt;
650 rlckwuSap->pst.dstInst = pst->srcInst;
652 /* Update the State */
653 rlckwuSap->state = RLC_SAP_BND;
655 RLOG1(L_DEBUG, "RlcUiKwuBndReq: state (%d)", rlckwuSap->state);
660 /* Sap is already bound check source, destination Entity and Proc Id */
661 if (rlckwuSap->pst.dstProcId != pst->srcProcId ||
662 rlckwuSap->pst.dstEnt != pst->srcEnt ||
663 rlckwuSap->pst.dstInst != pst->srcInst ||
664 rlckwuSap->suId != suId)
666 RLC_SEND_SAPID_ALARM(tRlcCb,
668 LKW_EVENT_KWU_BND_REQ,
669 LCM_CAUSE_INV_PAR_VAL);
670 RLOG1(L_ERROR,"RLC Mode [%d] : KWU SAP already Bound",
671 tRlcCb->genCfg.rlcMode);
672 RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_NOK);
680 #if (ERRCLASS & ERRCLS_INT_PAR)
681 RLOG1(L_ERROR,"RLC Mode [%d]:Invalid KWU SAP State in Bind Req",
682 tRlcCb->genCfg.rlcMode);
683 RLC_SEND_SAPID_ALARM(tRlcCb,
685 LKW_EVENT_KWU_BND_REQ,
686 LCM_CAUSE_INV_STATE);
687 #endif /* ERRCLASS & ERRCLS_INT_PAR */
688 RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_NOK);
692 RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_OK);
699 * Handler for unbinding the RLC upper layer service user with
703 * This function is used by RLC user to request for unbinding
704 * with RLC.This function is called by the KWU interface to
707 * @param[in] pst Post structure
708 * @param[in] spId Service provider SAP ID
709 * @param[in] reason Reason for Unbinding
723 S16 RlcUiKwuUbndReq(pst, spId, reason)
729 RlcKwuSapCb *rlckwuSap; /* KWU SAP control block */
732 #if (ERRCLASS & ERRCLS_INT_PAR)
733 if ((pst->dstInst >= MAX_RLC_INSTANCES) ||
734 (spId >= (S16) rlcCb[pst->dstInst]->genCfg.maxKwuSaps) ||
741 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
743 RLOG2(L_DEBUG, "spId(%d), reason(%d)",
747 /* Get Sap control block */
748 rlckwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
749 (tRlcCb->u.dlCb->rlcKwuDlSap + spId):
750 (tRlcCb->u.ulCb->rlcKwuUlSap + spId);
752 rlckwuSap->state = RLC_SAP_CFG;
758 * @brief Handler for receiving the data(SDU) from upper layer.
761 * This function is used by RLC service user (PDCP) to
762 * transfer data (SDU) to RLC.
764 * @param[in] pst Post structure
765 * @param[in] spId Service Provider SAP ID
766 * @param[in] datreq Data Request Information
767 * @param[in] mBuf Data Buffer (SDU)
773 uint8_t rlcProcDlData(Pst *pst, KwuDatReqInfo *datReq, Buffer *mBuf)
775 uint8_t ret = ROK; /* Return Value */
776 RlcDlRbCb *rbCb; /* RB Control Block */
779 DU_LOG("\nRLC : Received DL Data");
781 #if (ERRCLASS & ERRCLS_INT_PAR)
782 if(pst->dstInst >= MAX_RLC_INSTANCES)
784 ODU_PUT_MSG_BUF(mBuf);
789 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
792 rlcDbmFetchDlRbCbByRbId(tRlcCb, &datReq->rlcId, &rbCb);
795 DU_LOG("\nRLC : CellId[%u]:DL RbId [%d] not found",
796 datReq->rlcId.cellId,datReq->rlcId.rbId);
802 /* Dispatch according to mode of the rbCb */
807 /* Verify the user */
808 if (pst->srcEnt != ENTNH)
810 /* kw002.201 Freeing from proper region */
811 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, datReq,
812 sizeof(KwuDatReqInfo));
818 rlcTmmQSdu(tRlcCb,rbCb, datReq, mBuf);
823 rlcUmmQSdu(tRlcCb,rbCb, datReq, mBuf);
829 rlcAmmQSdu(tRlcCb,rbCb, mBuf, datReq);
834 DU_LOG("\nRLC : Invalid RB Mode");
844 * Handler for discarding a SDU.
847 * This function is used by RLC AM and RLC UM entities.
848 * This function is called by the service user to discard a particular
849 * RLC SDU if it is present in the SDU queue of the RB control block
850 * and if it is not mapped to any PDU.
852 * @param[in] pst Post structure
853 * @param[in] spId Service Provider SAP ID
854 * @param[in] discSdu SDU discard Information
861 S16 RlcUiKwuDiscSduReq
865 KwuDiscSduInfo *discSdu
868 S16 RlcUiKwuDiscSduReq(pst, spId, discSdu)
871 KwuDiscSduInfo *discSdu;
874 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, discSdu, sizeof(KwuDiscSduInfo));
878 /********************************************************************30**
880 **********************************************************************/