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 uint32_t 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 tRlcCb->u.ulCb->rlcUlUdxEventType = pst->event;
304 if (rlcDbmAddUlTransaction(tRlcCb, cfgTmpData) != ROK)
306 RLOG0(L_ERROR, "Addition to UL transId Lst Failed");
307 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
312 rlcUlHdlCfgReq(tRlcCb, cfgTmpData, cfg);
313 rlcUlUdxCfgReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),RLC_GET_UDX_SAP(tRlcCb)->spId,cfg);
320 * Handler to change the UeId
323 * This primitive is used by RRC to change the UeId for the existing UE
326 * @param[in] pst - Point to the pst structure
327 * @param[in] spId - The ID of the service provider SAP in the RLC layer
328 * @param[in] transId - Transaction ID. This field uniquily identifies
329 * transaction between RRC and RLC
330 * @param[in] ueInfo - Old UE Id Info for which the change request has come
331 * @param[in] newUeInfo - New UE Id Info for existing UE context
338 S16 RlcUiCkwUeIdChgReq
347 S16 RlcUiCkwUeIdChgReq(pst, spId, transId, ueInfo, newUeInfo)
352 CkwUeInfo *newUeInfo;
357 RlcUlCfgTmpData *cfgTmpData = NULLP;
361 #if (ERRCLASS & ERRCLS_INT_PAR)
362 if (pst->dstInst >= MAX_RLC_INSTANCES)
369 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
371 RLOG_ARG2(L_DEBUG,DBG_CELLID,newUeInfo->cellId,
372 "RlcUiCkwUeIdChgReq(pst, spId(%d), transId(%ld))",
376 RLOG_ARG2(L_DEBUG,DBG_CELLID,newUeInfo->cellId,
377 "RlcUiCkwUeIdChgReq(pst, spId(%d), transId(%d))\n",
382 RLC_ALLOC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
389 cfgTmpData->transId = transId;
390 cfgTmpData->ueInfo = ueInfo;
391 cfgTmpData->newUeInfo = newUeInfo;
393 if (rlcDbmAddUlTransaction(tRlcCb, cfgTmpData))
395 RLOG0(L_ERROR, "Addition to UL transId Lst Failed");
403 /* there was an error in the processing, free up all the memory
404 * that was passed and could have been allocated in this function
406 /* Freeing from proper region */
407 RLC_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CkwUeInfo));
408 RLC_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CkwUeInfo));
412 RLC_FREE(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
417 if(ROK != rlcCfgValidateUeIdChng(tRlcCb,ueInfo,newUeInfo,cfgTmpData))
419 RLOG_ARG0(L_ERROR,DBG_CELLID,cfgTmpData->ueInfo->cellId,
420 "Validation Failure for UeId change");
423 rlcUlUdxUeIdChgReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),
424 RLC_GET_UDX_SAP(tRlcCb)->spId,
435 * Handler for Configuration Request
437 * @param[in] gCb RLC Instance Control Block
438 * @param[in] cfgTmpData Configuration stored in Transaction Block
439 * @param[in] cfg Configuration block
449 RlcUlCfgTmpData *cfgTmpData,
453 Void rlcUlHdlCfgReq(gCb, cfgTmpData, cfg)
455 RlcUlCfgTmpData *cfgTmpData;
461 cfgTmpData->ueId = cfg->ueId;
462 cfgTmpData->cellId = cfg->cellId;
463 for (idx = 0; idx < cfg->numEnt; idx++)
465 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_OK;
466 cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbId = cfg->entCfg[idx].rbId;
467 cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbType = cfg->entCfg[idx].rbType;
468 switch(cfg->entCfg[idx].cfgType)
475 if(cfg->entCfg[idx].dir & RLC_DIR_UL)
477 /* Configuration is for UL , thus validating */
478 if(ROK != rlcCfgValidateUlRb(gCb,
480 &cfgTmpData->cfgEntData[idx],
483 RLOG_ARG2(L_ERROR,DBG_UEID, cfgTmpData->ueId,
484 "CELLID [%u]:Validation Failure for UL RB [%d]",
485 cfg->cellId,cfg->entCfg[idx].rbId);
486 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
487 /*Validation is getting failed so no need to do configuration at DL.
488 *Set dir as UL, so that no configuration is done at DL */
489 cfg->entCfg[idx].dir = RLC_DIR_UL;
492 if(cfg->entCfg[idx].dir == RLC_DIR_UL)
494 /*If the configuration is for UL only then apply it */
495 if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
499 &cfgTmpData->cfgEntData[idx],
505 case CKW_CFG_REESTABLISH:
507 if(cfg->entCfg[idx].dir & RLC_DIR_UL)
509 if(ROK != rlcCfgValidateReEstRb(gCb,
513 &cfgTmpData->cfgEntData[idx]))
515 RLOG_ARG2(L_ERROR,DBG_UEID,cfg->ueId,
516 "CellID [%u]:Validation Failure for Reest UL RB [%d]",
517 cfg->cellId,cfg->entCfg[idx].rbId);
518 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
519 /* Setting dir as UL, so that no configuration is done at DL */
520 cfg->entCfg[idx].dir = RLC_DIR_UL;
524 if(cfg->entCfg[idx].dir == RLC_DIR_UL)
526 /*If the configuration is for UL only then apply it */
527 if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
529 rlcCfgApplyReEstUlRb(gCb,
533 &cfgTmpData->cfgEntData[idx]);
538 case CKW_CFG_DELETE_UE :
540 if(ROK != rlcCfgValidateDelUlUe(gCb,
542 &cfgTmpData->cfgEntData[idx],
545 RLOG_ARG1(L_ERROR,DBG_CELLID,cfg->cellId,
546 "UL UEID [%d]:Validation Failure",
548 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
549 /* Setting dir as UL, so that no configuration is done at DL */
550 cfg->entCfg[idx].dir = RLC_DIR_UL;
554 case CKW_CFG_DELETE_CELL :
556 if(ROK != rlcCfgValidateDelUlCell(gCb,
559 &cfgTmpData->cfgEntData[idx],
562 RLOG_ARG0(L_ERROR,DBG_CELLID,cfg->cellId,
563 "Del UL Cell Validation Failure");
564 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
565 /* Setting dir as UL, so that no configuration is done at DL */
566 cfg->entCfg[idx].dir = RLC_DIR_UL;
576 /*****************************************************************************
578 ****************************************************************************/
581 * Handler for binding the RLC upper layer service user with
585 * This function is used by RLC user to request for binding to
586 * RLC.This function is called by the KWU interface to bind
587 * RLC's SAP (identified by spId) with the service user's
588 * SAP (identified by suId).
590 * @param[in] pst Post structure
591 * @param[in] suId Service user SAP ID
592 * @param[in] spId Service provider ID
607 S16 RlcUiKwuBndReq (pst, suId, spId)
613 RlcKwuSapCb *rlckwuSap; /* SAP Config Block */
616 #if (ERRCLASS & ERRCLS_INT_PAR)
617 if (pst->dstInst >= MAX_RLC_INSTANCES)
622 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
623 RLOG2(L_DEBUG, "RlcUiKwuBndReq(pst, spId(%d), suId(%d))", spId, suId);
625 /* Validation of input parameters */
626 #if (ERRCLASS & ERRCLS_INT_PAR)
627 if(!((spId < (S16) tRlcCb->genCfg.maxKwuSaps) && (spId >=0)))
629 RLOG0(L_ERROR,"Invalid spId");
630 RLC_SEND_SAPID_ALARM(tRlcCb,spId, LKW_EVENT_KWU_BND_REQ, LCM_CAUSE_INV_SAP);
635 /* Get Sap control block */
636 rlckwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
637 (tRlcCb->u.dlCb->rlcKwuDlSap + spId):
638 (tRlcCb->u.ulCb->rlcKwuUlSap + spId);
640 /* Take action based on the current state of the SAP */
641 switch(rlckwuSap->state)
643 /* SAP is configured but not bound */
647 /* copy bind configuration parameters in sap */
648 rlckwuSap->suId = suId;
649 rlckwuSap->pst.dstProcId = pst->srcProcId;
650 rlckwuSap->pst.dstEnt = pst->srcEnt;
651 rlckwuSap->pst.dstInst = pst->srcInst;
653 /* Update the State */
654 rlckwuSap->state = RLC_SAP_BND;
656 RLOG1(L_DEBUG, "RlcUiKwuBndReq: state (%d)", rlckwuSap->state);
661 /* Sap is already bound check source, destination Entity and Proc Id */
662 if (rlckwuSap->pst.dstProcId != pst->srcProcId ||
663 rlckwuSap->pst.dstEnt != pst->srcEnt ||
664 rlckwuSap->pst.dstInst != pst->srcInst ||
665 rlckwuSap->suId != suId)
667 RLC_SEND_SAPID_ALARM(tRlcCb,
669 LKW_EVENT_KWU_BND_REQ,
670 LCM_CAUSE_INV_PAR_VAL);
671 RLOG1(L_ERROR,"RLC Mode [%d] : KWU SAP already Bound",
672 tRlcCb->genCfg.rlcMode);
673 RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_NOK);
681 #if (ERRCLASS & ERRCLS_INT_PAR)
682 RLOG1(L_ERROR,"RLC Mode [%d]:Invalid KWU SAP State in Bind Req",
683 tRlcCb->genCfg.rlcMode);
684 RLC_SEND_SAPID_ALARM(tRlcCb,
686 LKW_EVENT_KWU_BND_REQ,
687 LCM_CAUSE_INV_STATE);
688 #endif /* ERRCLASS & ERRCLS_INT_PAR */
689 RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_NOK);
693 RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_OK);
700 * Handler for unbinding the RLC upper layer service user with
704 * This function is used by RLC user to request for unbinding
705 * with RLC.This function is called by the KWU interface to
708 * @param[in] pst Post structure
709 * @param[in] spId Service provider SAP ID
710 * @param[in] reason Reason for Unbinding
724 S16 RlcUiKwuUbndReq(pst, spId, reason)
730 RlcKwuSapCb *rlckwuSap; /* KWU SAP control block */
733 #if (ERRCLASS & ERRCLS_INT_PAR)
734 if ((pst->dstInst >= MAX_RLC_INSTANCES) ||
735 (spId >= (S16) rlcCb[pst->dstInst]->genCfg.maxKwuSaps) ||
742 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
744 RLOG2(L_DEBUG, "spId(%d), reason(%d)",
748 /* Get Sap control block */
749 rlckwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
750 (tRlcCb->u.dlCb->rlcKwuDlSap + spId):
751 (tRlcCb->u.ulCb->rlcKwuUlSap + spId);
753 rlckwuSap->state = RLC_SAP_CFG;
759 * @brief Handler for receiving the data(SDU) from upper layer.
762 * This function is used by RLC service user (PDCP) to
763 * transfer data (SDU) to RLC.
765 * @param[in] pst Post structure
766 * @param[in] spId Service Provider SAP ID
767 * @param[in] datreq Data Request Information
768 * @param[in] mBuf Data Buffer (SDU)
774 uint8_t rlcProcDlData(Pst *pst, KwuDatReqInfo *datReq, Buffer *mBuf)
776 uint8_t ret = ROK; /* Return Value */
777 RlcDlRbCb *rbCb; /* RB Control Block */
780 DU_LOG("\nRLC : Received DL Data");
782 #if (ERRCLASS & ERRCLS_INT_PAR)
783 if(pst->dstInst >= MAX_RLC_INSTANCES)
785 ODU_PUT_MSG_BUF(mBuf);
790 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
793 rlcDbmFetchDlRbCbByRbId(tRlcCb, &datReq->rlcId, &rbCb);
796 DU_LOG("\nRLC : CellId[%u]:DL RbId [%d] not found",
797 datReq->rlcId.cellId,datReq->rlcId.rbId);
803 /* Dispatch according to mode of the rbCb */
808 /* Verify the user */
809 if (pst->srcEnt != ENTNH)
811 /* kw002.201 Freeing from proper region */
812 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, datReq,
813 sizeof(KwuDatReqInfo));
819 rlcTmmQSdu(tRlcCb,rbCb, datReq, mBuf);
824 rlcUmmQSdu(tRlcCb,rbCb, datReq, mBuf);
830 rlcAmmQSdu(tRlcCb,rbCb, mBuf, datReq);
835 DU_LOG("\nRLC : Invalid RB Mode");
845 * Handler for discarding a SDU.
848 * This function is used by RLC AM and RLC UM entities.
849 * This function is called by the service user to discard a particular
850 * RLC SDU if it is present in the SDU queue of the RB control block
851 * and if it is not mapped to any PDU.
853 * @param[in] pst Post structure
854 * @param[in] spId Service Provider SAP ID
855 * @param[in] discSdu SDU discard Information
862 S16 RlcUiKwuDiscSduReq
866 KwuDiscSduInfo *discSdu
869 S16 RlcUiKwuDiscSduReq(pst, spId, discSdu)
872 KwuDiscSduInfo *discSdu;
875 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, discSdu, sizeof(KwuDiscSduInfo));
879 /********************************************************************30**
881 **********************************************************************/