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
110 #if (ERRCLASS & ERRCLS_INT_PAR)
111 if (pst->dstInst >= MAX_RLC_INSTANCES)
117 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
119 RLOG2(L_DEBUG, "spId(%d), suId(%d)", spId, suId);
120 ckwSap = &(tRlcCb->u.ulCb->ckwSap);
121 /* Take action based on the current state of the SAP */
122 switch(ckwSap->state)
124 /* SAP is configured but not bound */
128 /* copy bind configuration parameters in SSAP sap */
130 ckwSap->pst.dstProcId = pst->srcProcId;
131 ckwSap->pst.dstEnt = pst->srcEnt;
132 ckwSap->pst.dstInst = pst->srcInst;
134 /* Update the State */
135 ckwSap->state = RLC_SAP_BND;
137 RLOG1(L_DEBUG, "RlcUiCkwBndReq: state (%d)", ckwSap->state);
142 /* Sap is already bound check source, destination Entity and
144 if (ckwSap->pst.dstProcId != pst->srcProcId ||
145 ckwSap->pst.dstEnt != pst->srcEnt ||
146 ckwSap->pst.dstInst != pst->srcInst ||
147 ckwSap->suId != suId)
149 RLC_SEND_SAPID_ALARM(tRlcCb,
151 LKW_EVENT_CKW_BND_REQ,
152 LCM_CAUSE_INV_PAR_VAL);
154 RLOG0(L_ERROR, "CKW SAP already Bound");
155 RlcUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_NOK);
162 #if (ERRCLASS & ERRCLS_INT_PAR)
163 RLOG0(L_ERROR, "Invalid CKW SAP State in Bind Req");
164 RLC_SEND_SAPID_ALARM(tRlcCb,
166 LKW_EVENT_CKW_BND_REQ,
167 LCM_CAUSE_INV_STATE);
168 #endif /* ERRCLASS & ERRCLS_INT_PAR */
169 RlcUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_NOK);
175 RlcUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_OK);
182 * Handler for unbinding the RLC upper layer service user CKW with
186 * This function is used by RLC user to request for unbinding
187 * with RLC.This function is called by the CKW interface to
190 * @param[in] pst Post structure
191 * @param[in] spId Service provider SAP ID
192 * @param[in] reason Reason for Unbinding
207 #if (ERRCLASS & ERRCLS_INT_PAR)
208 if (pst->dstInst >= MAX_RLC_INSTANCES)
212 #endif /* ERRCLASS & ERRCLS_INT_PAR */
213 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
215 RLOG2(L_DEBUG,"spId(%d), reason(%d)",
221 #if (ERRCLASS & ERRCLS_INT_PAR)
222 RLC_GET_AND_VALIDATE_CKWSAP(tRlcCb,
223 (&(tRlcCb->u.ulCb->ckwSap)),
226 #endif /* ERRCLASS & ERRCLS_INT_PAR */
228 /* disable upper sap (CKW) */
229 tRlcCb->u.ulCb->ckwSap.state = RLC_SAP_CFG;
235 * Handler for configuring RLC entities.
238 * This function is used by RRC to configure(add/delete/modify)
239 * one or more RLC entities.
241 * @param[in] pst - Post structure
242 * @param[in] spId - Serive Provider ID
243 * @param[in] cfg - Configuration information for one or more RLC entities.
256 RlcUlCfgTmpData *cfgTmpData;
258 static uint32_t transCount;
260 #if (ERRCLASS & ERRCLS_INT_PAR)
261 if (pst->dstInst >= MAX_RLC_INSTANCES)
263 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
267 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
269 RLC_ALLOC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
271 if (cfgTmpData == NULLP)
273 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
277 cfgTmpData->uprLyrTransId = cfg->transId; /*Save User TransId*/
278 cfgTmpData->transId = ++transCount; /*Generate new TransId*/
279 cfg->transId = cfgTmpData->transId;
280 cfgTmpData->cfgInfo = cfg;
283 tRlcCb->u.ulCb->rlcUlUdxEventType = pst->event;
284 if (rlcDbmAddUlTransaction(tRlcCb, cfgTmpData) != ROK)
286 RLOG0(L_ERROR, "Addition to UL transId Lst Failed");
287 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
292 rlcUlHdlCfgReq(tRlcCb, cfgTmpData, cfg);
293 rlcUlUdxCfgReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),RLC_GET_UDX_SAP(tRlcCb)->spId,cfg);
300 * Handler to change the UeId
303 * This primitive is used by RRC to change the UeId for the existing UE
306 * @param[in] pst - Point to the pst structure
307 * @param[in] spId - The ID of the service provider SAP in the RLC layer
308 * @param[in] transId - Transaction ID. This field uniquily identifies
309 * transaction between RRC and RLC
310 * @param[in] ueInfo - Old UE Id Info for which the change request has come
311 * @param[in] newUeInfo - New UE Id Info for existing UE context
317 S16 RlcUiCkwUeIdChgReq
328 RlcUlCfgTmpData *cfgTmpData = NULLP;
332 #if (ERRCLASS & ERRCLS_INT_PAR)
333 if (pst->dstInst >= MAX_RLC_INSTANCES)
340 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
342 RLOG_ARG2(L_DEBUG,DBG_CELLID,newUeInfo->cellId,
343 "RlcUiCkwUeIdChgReq(pst, spId(%d), transId(%ld))",
347 RLOG_ARG2(L_DEBUG,DBG_CELLID,newUeInfo->cellId,
348 "RlcUiCkwUeIdChgReq(pst, spId(%d), transId(%d))\n",
353 RLC_ALLOC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
360 cfgTmpData->transId = transId;
361 cfgTmpData->ueInfo = ueInfo;
362 cfgTmpData->newUeInfo = newUeInfo;
364 if (rlcDbmAddUlTransaction(tRlcCb, cfgTmpData))
366 RLOG0(L_ERROR, "Addition to UL transId Lst Failed");
374 /* there was an error in the processing, free up all the memory
375 * that was passed and could have been allocated in this function
377 /* Freeing from proper region */
378 RLC_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CkwUeInfo));
379 RLC_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CkwUeInfo));
383 RLC_FREE(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
388 if(ROK != rlcCfgValidateUeIdChng(tRlcCb,ueInfo,newUeInfo,cfgTmpData))
390 RLOG_ARG0(L_ERROR,DBG_CELLID,cfgTmpData->ueInfo->cellId,
391 "Validation Failure for UeId change");
394 rlcUlUdxUeIdChgReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),
395 RLC_GET_UDX_SAP(tRlcCb)->spId,
406 * Handler for Configuration Request
408 * @param[in] gCb RLC Instance Control Block
409 * @param[in] cfgTmpData Configuration stored in Transaction Block
410 * @param[in] cfg Configuration block
419 RlcUlCfgTmpData *cfgTmpData,
425 cfgTmpData->ueId = cfg->ueId;
426 cfgTmpData->cellId = cfg->cellId;
427 for (idx = 0; idx < cfg->numEnt; idx++)
429 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_OK;
430 cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbId = cfg->entCfg[idx].rbId;
431 cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbType = cfg->entCfg[idx].rbType;
432 switch(cfg->entCfg[idx].cfgType)
439 if(cfg->entCfg[idx].dir & RLC_DIR_UL)
441 /* Configuration is for UL , thus validating */
442 if(ROK != rlcCfgValidateUlRb(gCb,
444 &cfgTmpData->cfgEntData[idx],
447 RLOG_ARG2(L_ERROR,DBG_UEID, cfgTmpData->ueId,
448 "CELLID [%u]:Validation Failure for UL RB [%d]",
449 cfg->cellId,cfg->entCfg[idx].rbId);
450 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
451 /*Validation is getting failed so no need to do configuration at DL.
452 *Set dir as UL, so that no configuration is done at DL */
453 cfg->entCfg[idx].dir = RLC_DIR_UL;
456 if(cfg->entCfg[idx].dir == RLC_DIR_UL)
458 /*If the configuration is for UL only then apply it */
459 if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
463 &cfgTmpData->cfgEntData[idx],
469 case CKW_CFG_REESTABLISH:
471 if(cfg->entCfg[idx].dir & RLC_DIR_UL)
473 if(ROK != rlcCfgValidateReEstRb(gCb,
477 &cfgTmpData->cfgEntData[idx]))
479 RLOG_ARG2(L_ERROR,DBG_UEID,cfg->ueId,
480 "CellID [%u]:Validation Failure for Reest UL RB [%d]",
481 cfg->cellId,cfg->entCfg[idx].rbId);
482 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
483 /* Setting dir as UL, so that no configuration is done at DL */
484 cfg->entCfg[idx].dir = RLC_DIR_UL;
488 if(cfg->entCfg[idx].dir == RLC_DIR_UL)
490 /*If the configuration is for UL only then apply it */
491 if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
493 rlcCfgApplyReEstUlRb(gCb,
497 &cfgTmpData->cfgEntData[idx]);
502 case CKW_CFG_DELETE_UE :
504 if(ROK != rlcCfgValidateDelUlUe(gCb,
506 &cfgTmpData->cfgEntData[idx],
509 RLOG_ARG1(L_ERROR,DBG_CELLID,cfg->cellId,
510 "UL UEID [%d]: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;
518 case CKW_CFG_DELETE_CELL :
520 if(ROK != rlcCfgValidateDelUlCell(gCb,
523 &cfgTmpData->cfgEntData[idx],
526 RLOG_ARG0(L_ERROR,DBG_CELLID,cfg->cellId,
527 "Del UL Cell Validation Failure");
528 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
529 /* Setting dir as UL, so that no configuration is done at DL */
530 cfg->entCfg[idx].dir = RLC_DIR_UL;
540 /*****************************************************************************
542 ****************************************************************************/
545 * Handler for binding the RLC upper layer service user with
549 * This function is used by RLC user to request for binding to
550 * RLC.This function is called by the KWU interface to bind
551 * RLC's SAP (identified by spId) with the service user's
552 * SAP (identified by suId).
554 * @param[in] pst Post structure
555 * @param[in] suId Service user SAP ID
556 * @param[in] spId Service provider ID
570 RlcKwuSapCb *rlckwuSap; /* SAP Config Block */
573 #if (ERRCLASS & ERRCLS_INT_PAR)
574 if (pst->dstInst >= MAX_RLC_INSTANCES)
579 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
580 RLOG2(L_DEBUG, "RlcUiKwuBndReq(pst, spId(%d), suId(%d))", spId, suId);
582 /* Validation of input parameters */
583 #if (ERRCLASS & ERRCLS_INT_PAR)
584 if(!((spId < (S16) tRlcCb->genCfg.maxKwuSaps) && (spId >=0)))
586 RLOG0(L_ERROR,"Invalid spId");
587 RLC_SEND_SAPID_ALARM(tRlcCb,spId, LKW_EVENT_KWU_BND_REQ, LCM_CAUSE_INV_SAP);
592 /* Get Sap control block */
593 rlckwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
594 (tRlcCb->u.dlCb->rlcKwuDlSap + spId):
595 (tRlcCb->u.ulCb->rlcKwuUlSap + spId);
597 /* Take action based on the current state of the SAP */
598 switch(rlckwuSap->state)
600 /* SAP is configured but not bound */
604 /* copy bind configuration parameters in sap */
605 rlckwuSap->suId = suId;
606 rlckwuSap->pst.dstProcId = pst->srcProcId;
607 rlckwuSap->pst.dstEnt = pst->srcEnt;
608 rlckwuSap->pst.dstInst = pst->srcInst;
610 /* Update the State */
611 rlckwuSap->state = RLC_SAP_BND;
613 RLOG1(L_DEBUG, "RlcUiKwuBndReq: state (%d)", rlckwuSap->state);
618 /* Sap is already bound check source, destination Entity and Proc Id */
619 if (rlckwuSap->pst.dstProcId != pst->srcProcId ||
620 rlckwuSap->pst.dstEnt != pst->srcEnt ||
621 rlckwuSap->pst.dstInst != pst->srcInst ||
622 rlckwuSap->suId != suId)
624 RLC_SEND_SAPID_ALARM(tRlcCb,
626 LKW_EVENT_KWU_BND_REQ,
627 LCM_CAUSE_INV_PAR_VAL);
628 RLOG1(L_ERROR,"RLC Mode [%d] : KWU SAP already Bound",
629 tRlcCb->genCfg.rlcMode);
630 RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_NOK);
638 #if (ERRCLASS & ERRCLS_INT_PAR)
639 RLOG1(L_ERROR,"RLC Mode [%d]:Invalid KWU SAP State in Bind Req",
640 tRlcCb->genCfg.rlcMode);
641 RLC_SEND_SAPID_ALARM(tRlcCb,
643 LKW_EVENT_KWU_BND_REQ,
644 LCM_CAUSE_INV_STATE);
645 #endif /* ERRCLASS & ERRCLS_INT_PAR */
646 RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_NOK);
650 RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_OK);
657 * Handler for unbinding the RLC upper layer service user with
661 * This function is used by RLC user to request for unbinding
662 * with RLC.This function is called by the KWU interface to
665 * @param[in] pst Post structure
666 * @param[in] spId Service provider SAP ID
667 * @param[in] reason Reason for Unbinding
680 RlcKwuSapCb *rlckwuSap; /* KWU SAP control block */
683 #if (ERRCLASS & ERRCLS_INT_PAR)
684 if ((pst->dstInst >= MAX_RLC_INSTANCES) ||
685 (spId >= (S16) rlcCb[pst->dstInst]->genCfg.maxKwuSaps) ||
692 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
694 RLOG2(L_DEBUG, "spId(%d), reason(%d)",
698 /* Get Sap control block */
699 rlckwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
700 (tRlcCb->u.dlCb->rlcKwuDlSap + spId):
701 (tRlcCb->u.ulCb->rlcKwuUlSap + spId);
703 rlckwuSap->state = RLC_SAP_CFG;
709 * @brief Handler for receiving the data(SDU) from upper layer.
712 * This function is used by RLC service user (PDCP) to
713 * transfer data (SDU) to RLC.
715 * @param[in] pst Post structure
716 * @param[in] spId Service Provider SAP ID
717 * @param[in] datreq Data Request Information
718 * @param[in] mBuf Data Buffer (SDU)
724 uint8_t rlcProcDlData(Pst *pst, KwuDatReqInfo *datReq, Buffer *mBuf)
726 uint8_t ret = ROK; /* Return Value */
727 RlcDlRbCb *rbCb; /* RB Control Block */
730 DU_LOG("\nRLC : Received DL Data");
732 #if (ERRCLASS & ERRCLS_INT_PAR)
733 if(pst->dstInst >= MAX_RLC_INSTANCES)
735 ODU_PUT_MSG_BUF(mBuf);
740 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
743 rlcDbmFetchDlRbCbByRbId(tRlcCb, &datReq->rlcId, &rbCb);
746 DU_LOG("\nRLC : CellId[%u]:DL RbId [%d] not found",
747 datReq->rlcId.cellId,datReq->rlcId.rbId);
748 ODU_PUT_MSG_BUF(mBuf);
753 /* Dispatch according to mode of the rbCb */
758 /* Verify the user */
759 if (pst->srcEnt != ENTNH)
761 /* kw002.201 Freeing from proper region */
762 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, datReq,
763 sizeof(KwuDatReqInfo));
764 ODU_PUT_MSG_BUF(mBuf);
769 rlcTmmQSdu(tRlcCb,rbCb, datReq, mBuf);
774 rlcUmmQSdu(tRlcCb,rbCb, datReq, mBuf);
780 rlcAmmQSdu(tRlcCb,rbCb, mBuf, datReq);
785 DU_LOG("\nRLC : Invalid RB Mode");
795 * Handler for discarding a SDU.
798 * This function is used by RLC AM and RLC UM entities.
799 * This function is called by the service user to discard a particular
800 * RLC SDU if it is present in the SDU queue of the RB control block
801 * and if it is not mapped to any PDU.
803 * @param[in] pst Post structure
804 * @param[in] spId Service Provider SAP ID
805 * @param[in] discSdu SDU discard Information
811 S16 RlcUiKwuDiscSduReq
815 KwuDiscSduInfo *discSdu
818 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, discSdu, sizeof(KwuDiscSduInfo));
822 /********************************************************************30**
824 **********************************************************************/