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 KW_MODULE KW_DBGMASK_INF
52 /* header (.h) include files */
53 #include "envopt.h" /* environment options */
54 #include "envdep.h" /* environment dependent */
55 #include "envind.h" /* environment independent */
57 #include "gen.h" /* general */
58 #include "ssi.h" /* system services */
59 #include "cm5.h" /* common timer defines */
60 #include "cm_tkns.h" /* common tokens defines */
61 #include "cm_mblk.h" /* common memory allocation library defines */
62 #include "cm_llist.h" /* common link list defines */
63 #include "cm_hash.h" /* common hash list defines */
64 #include "cm_lte.h" /* common LTE defines */
65 #include "lkw.h" /* LKW defines */
66 #include "ckw.h" /* CKW defines */
67 #include "kwu.h" /* KWU defines */
68 #include "rgu.h" /* RGU defines */
69 #include "kw_env.h" /* RLC environment options */
70 #include "kw.h" /* RLC defines */
75 /* extern (.x) include files */
76 #include "gen.x" /* general */
77 #include "ssi.x" /* system services */
79 #include "cm5.x" /* common timer library */
80 #include "cm_tkns.x" /* common tokens */
81 #include "cm_mblk.x" /* common memory allocation */
82 #include "cm_llist.x" /* common link list */
83 #include "cm_hash.x" /* common hash list */
84 #include "cm_lte.x" /* common LTE includes */
85 #include "cm_lib.x" /* common memory allocation library */
86 #include "lkw.x" /* LKW */
87 #include "ckw.x" /* CKW */
88 #include "kwu.x" /* KWU */
89 #include "rgu.x" /* RGU */
97 /*****************************************************************************
99 ****************************************************************************/
103 * Handler for binding the RLC upper layer service user with
107 * This function is used by RLC user to request for binding to
108 * RLC. This function is called by the CKW interface to bind
109 * RLC's SAP (identified by spId) with the service user's
110 * SAP (identified by suId).
112 * @param[in] pst Post structure
113 * @param[in] suId Service User ID
114 * @param[in] spId Service provider ID
122 PUBLIC S16 KwUiCkwBndReq
129 PUBLIC S16 KwUiCkwBndReq (pst, suId, spId)
140 #if (ERRCLASS & ERRCLS_INT_PAR)
141 if (pst->dstInst >= KW_MAX_RLC_INSTANCES)
147 tKwCb = KW_GET_KWCB(pst->dstInst);
149 RLOG2(L_DEBUG, "spId(%d), suId(%d)", spId, suId);
150 ckwSap = &(tKwCb->u.ulCb->ckwSap);
151 /* Take action based on the current state of the SAP */
152 switch(ckwSap->state)
154 /* SAP is configured but not bound */
158 /* copy bind configuration parameters in SSAP sap */
160 ckwSap->pst.dstProcId = pst->srcProcId;
161 ckwSap->pst.dstEnt = pst->srcEnt;
162 ckwSap->pst.dstInst = pst->srcInst;
164 /* Update the State */
165 ckwSap->state = KW_SAP_BND;
167 RLOG1(L_DEBUG, "KwUiCkwBndReq: state (%d)", ckwSap->state);
172 /* Sap is already bound check source, destination Entity and
174 if (ckwSap->pst.dstProcId != pst->srcProcId ||
175 ckwSap->pst.dstEnt != pst->srcEnt ||
176 ckwSap->pst.dstInst != pst->srcInst ||
177 ckwSap->suId != suId)
179 KW_SEND_SAPID_ALARM(tKwCb,
181 LKW_EVENT_CKW_BND_REQ,
182 LCM_CAUSE_INV_PAR_VAL);
184 RLOG0(L_ERROR, "CKW SAP already Bound");
185 KwUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_NOK);
192 #if (ERRCLASS & ERRCLS_INT_PAR)
193 RLOG0(L_ERROR, "Invalid CKW SAP State in Bind Req");
194 KW_SEND_SAPID_ALARM(tKwCb,
196 LKW_EVENT_CKW_BND_REQ,
197 LCM_CAUSE_INV_STATE);
198 #endif /* ERRCLASS & ERRCLS_INT_PAR */
199 KwUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_NOK);
205 KwUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_OK);
212 * Handler for unbinding the RLC upper layer service user CKW with
216 * This function is used by RLC user to request for unbinding
217 * with RLC.This function is called by the CKW interface to
220 * @param[in] pst Post structure
221 * @param[in] spId Service provider SAP ID
222 * @param[in] reason Reason for Unbinding
229 PUBLIC S16 KwUiCkwUbndReq
236 PUBLIC S16 KwUiCkwUbndReq(pst, spId, reason)
246 #if (ERRCLASS & ERRCLS_INT_PAR)
247 if (pst->dstInst >= KW_MAX_RLC_INSTANCES)
251 #endif /* ERRCLASS & ERRCLS_INT_PAR */
252 tKwCb = KW_GET_KWCB(pst->dstInst);
254 RLOG2(L_DEBUG,"spId(%d), reason(%d)",
260 #if (ERRCLASS & ERRCLS_INT_PAR)
261 KW_GET_AND_VALIDATE_CKWSAP(tKwCb,
262 (&(tKwCb->u.ulCb->ckwSap)),
265 #endif /* ERRCLASS & ERRCLS_INT_PAR */
267 /* disable upper sap (CKW) */
268 tKwCb->u.ulCb->ckwSap.state = KW_SAP_CFG;
272 /*******************************************************************
274 * @brief Handler for UE create request
278 * Function : RlcDuappProcUeCreateReq
281 * Handler for UE create request
283 * @params[in] pst - Post Structure
284 * cfg - Configuration information for one or more RLC entities
285 * @return ROK - success
288 * ****************************************************************/
289 PUBLIC S16 RlcDuappProcUeCreateReq(Pst *pst, CkwCfgInfo *ueCfg)
296 for(idx = 0; idx < ueCfg->numEnt; idx++)
298 ueCfg->entCfg[idx].cfgType = CKW_CFG_ADD;
301 ret = KwUiCkwCfgReq(pst, ueCfg);
304 } /* RlcDuappUeCreateReq */
309 * Handler for configuring RLC entities.
312 * This function is used by RRC to configure(add/delete/modify)
313 * one or more RLC entities.
315 * @param[in] pst - Post structure
316 * @param[in] spId - Serive Provider ID
317 * @param[in] cfg - Configuration information for one or more RLC entities.
324 PUBLIC S16 KwUiCkwCfgReq
331 //PUBLIC S16 KwUiCkwCfgReq(pst, spId, cfg)
332 PUBLIC S16 KwUiCkwCfgReq(pst, cfg)
339 KwUlCfgTmpData *cfgTmpData;
341 static U32 transCount;
346 #if (ERRCLASS & ERRCLS_INT_PAR)
347 if (pst->dstInst >= KW_MAX_RLC_INSTANCES)
349 KW_PST_FREE(pst->region, pst->pool, cfg, sizeof(CkwCfgInfo));
353 tKwCb = KW_GET_KWCB(pst->dstInst);
355 KW_ALLOC(tKwCb, cfgTmpData, sizeof (KwUlCfgTmpData));
357 if (cfgTmpData == NULLP)
359 KW_PST_FREE(pst->region, pst->pool, cfg, sizeof(CkwCfgInfo));
364 cfgTmpData->uprLyrTransId = cfg->transId; /*Save User TransId*/
365 cfgTmpData->transId = ++transCount; /*Generate new TransId*/
366 cfg->transId = cfgTmpData->transId;
367 cfgTmpData->cfgInfo = cfg;
369 if (kwDbmAddUlTransaction(tKwCb, cfgTmpData) != ROK)
371 RLOG0(L_ERROR, "Addition to UL transId Lst Failed");
372 KW_PST_FREE(pst->region, pst->pool, cfg, sizeof(CkwCfgInfo));
377 kwHdlUiCkwUlCfgReq(tKwCb, cfgTmpData, cfg);
379 KwUlUdxCfgReq(&(KW_GET_UDX_SAP(tKwCb)->pst),KW_GET_UDX_SAP(tKwCb)->spId,cfg);
386 * Handler to change the UeId
389 * This primitive is used by RRC to change the UeId for the existing UE
392 * @param[in] pst - Point to the pst structure
393 * @param[in] spId - The ID of the service provider SAP in the RLC layer
394 * @param[in] transId - Transaction ID. This field uniquily identifies
395 * transaction between RRC and RLC
396 * @param[in] ueInfo - Old UE Id Info for which the change request has come
397 * @param[in] newUeInfo - New UE Id Info for existing UE context
404 PUBLIC S16 KwUiCkwUeIdChgReq
413 PUBLIC S16 KwUiCkwUeIdChgReq(pst, spId, transId, ueInfo, newUeInfo)
418 CkwUeInfo *newUeInfo;
423 KwUlCfgTmpData *cfgTmpData = NULLP;
425 TRC3(KwUiCkwUeIdChgReq)
429 #if (ERRCLASS & ERRCLS_INT_PAR)
430 if (pst->dstInst >= KW_MAX_RLC_INSTANCES)
437 tKwCb = KW_GET_KWCB(pst->dstInst);
439 RLOG_ARG2(L_DEBUG,DBG_CELLID,newUeInfo->cellId,
440 "KwUiCkwUeIdChgReq(pst, spId(%d), transId(%ld))",
444 RLOG_ARG2(L_DEBUG,DBG_CELLID,newUeInfo->cellId,
445 "KwUiCkwUeIdChgReq(pst, spId(%d), transId(%d))\n",
450 KW_ALLOC(tKwCb, cfgTmpData, sizeof (KwUlCfgTmpData));
457 cfgTmpData->transId = transId;
458 cfgTmpData->ueInfo = ueInfo;
459 cfgTmpData->newUeInfo = newUeInfo;
461 if (kwDbmAddUlTransaction(tKwCb, cfgTmpData))
463 RLOG0(L_ERROR, "Addition to UL transId Lst Failed");
471 /* there was an error in the processing, free up all the memory
472 * that was passed and could have been allocated in this function
474 /* Freeing from proper region */
475 KW_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CkwUeInfo));
476 KW_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CkwUeInfo));
480 KW_FREE(tKwCb, cfgTmpData, sizeof (KwUlCfgTmpData));
485 if(ROK != kwCfgValidateUeIdChng(tKwCb,ueInfo,newUeInfo,cfgTmpData))
487 RLOG_ARG0(L_ERROR,DBG_CELLID,cfgTmpData->ueInfo->cellId,
488 "Validation Failure for UeId change");
491 KwUlUdxUeIdChgReq(&(KW_GET_UDX_SAP(tKwCb)->pst),
492 KW_GET_UDX_SAP(tKwCb)->spId,
503 * Handler for Configuration Request
505 * @param[in] gCb RLC Instance Control Block
506 * @param[in] cfgTmpData Configuration stored in Transaction Block
507 * @param[in] cfg Configuration block
514 PUBLIC Void kwHdlUiCkwUlCfgReq
517 KwUlCfgTmpData *cfgTmpData,
521 PUBLIC Void kwHdlUiCkwUlCfgReq(gCb, cfgTmpData, cfg)
523 KwUlCfgTmpData *cfgTmpData;
529 TRC3(kwHdlUiCkwUlCfgReq)
531 cfgTmpData->ueId = cfg->ueId;
532 cfgTmpData->cellId = cfg->cellId;
533 for (idx = 0; idx < cfg->numEnt; idx++)
535 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_OK;
536 cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbId = cfg->entCfg[idx].rbId;
537 cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbType = cfg->entCfg[idx].rbType;
538 switch(cfg->entCfg[idx].cfgType)
545 if(cfg->entCfg[idx].dir & KW_DIR_UL)
547 /* Configuration is for UL , thus validating */
548 if(ROK != kwCfgValidateUlRb(gCb,
550 &cfgTmpData->cfgEntData[idx],
553 RLOG_ARG2(L_ERROR,DBG_UEID, cfgTmpData->ueId,
554 "CELLID [%u]:Validation Failure for UL RB [%d]",
555 cfg->cellId,cfg->entCfg[idx].rbId);
556 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
557 /*Validation is getting failed so no need to do configuration at DL.
558 *Set dir as UL, so that no configuration is done at DL */
559 cfg->entCfg[idx].dir = KW_DIR_UL;
562 if(cfg->entCfg[idx].dir == KW_DIR_UL)
564 /*If the configuration is for UL only then apply it */
565 if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
569 &cfgTmpData->cfgEntData[idx],
575 case CKW_CFG_REESTABLISH:
577 if(cfg->entCfg[idx].dir & KW_DIR_UL)
579 if(ROK != kwCfgValidateReEstRb(gCb,
583 &cfgTmpData->cfgEntData[idx]))
585 RLOG_ARG2(L_ERROR,DBG_UEID,cfg->ueId,
586 "CellID [%u]:Validation Failure for Reest UL RB [%d]",
587 cfg->cellId,cfg->entCfg[idx].rbId);
588 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
589 /* Setting dir as UL, so that no configuration is done at DL */
590 cfg->entCfg[idx].dir = KW_DIR_UL;
594 if(cfg->entCfg[idx].dir == KW_DIR_UL)
596 /*If the configuration is for UL only then apply it */
597 if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
599 kwCfgApplyReEstUlRb(gCb,
603 &cfgTmpData->cfgEntData[idx]);
608 case CKW_CFG_DELETE_UE :
610 if(ROK != kwCfgValidateDelUlUe(gCb,
612 &cfgTmpData->cfgEntData[idx],
615 RLOG_ARG1(L_ERROR,DBG_CELLID,cfg->cellId,
616 "UL UEID [%d]:Validation Failure",
618 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
619 /* Setting dir as UL, so that no configuration is done at DL */
620 cfg->entCfg[idx].dir = KW_DIR_UL;
624 case CKW_CFG_DELETE_CELL :
626 if(ROK != kwCfgValidateDelUlCell(gCb,
629 &cfgTmpData->cfgEntData[idx],
632 RLOG_ARG0(L_ERROR,DBG_CELLID,cfg->cellId,
633 "Del UL Cell Validation Failure");
634 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
635 /* Setting dir as UL, so that no configuration is done at DL */
636 cfg->entCfg[idx].dir = KW_DIR_UL;
646 /*****************************************************************************
648 ****************************************************************************/
651 * Handler for binding the RLC upper layer service user with
655 * This function is used by RLC user to request for binding to
656 * RLC.This function is called by the KWU interface to bind
657 * RLC's SAP (identified by spId) with the service user's
658 * SAP (identified by suId).
660 * @param[in] pst Post structure
661 * @param[in] suId Service user SAP ID
662 * @param[in] spId Service provider ID
670 PUBLIC S16 KwUiKwuBndReq
677 PUBLIC S16 KwUiKwuBndReq (pst, suId, spId)
683 KwKwuSapCb *kwuSap; /* SAP Config Block */
688 #if (ERRCLASS & ERRCLS_INT_PAR)
689 if (pst->dstInst >= KW_MAX_RLC_INSTANCES)
694 tKwCb = KW_GET_KWCB(pst->dstInst);
695 RLOG2(L_DEBUG, "KwUiKwuBndReq(pst, spId(%d), suId(%d))", spId, suId);
697 /* Validation of input parameters */
698 #if (ERRCLASS & ERRCLS_INT_PAR)
699 if(!((spId < (S16) tKwCb->genCfg.maxKwuSaps) && (spId >=0)))
701 RLOG0(L_ERROR,"Invalid spId");
702 KW_SEND_SAPID_ALARM(tKwCb,spId, LKW_EVENT_KWU_BND_REQ, LCM_CAUSE_INV_SAP);
707 /* Get Sap control block */
708 kwuSap = (tKwCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
709 (tKwCb->u.dlCb->kwuDlSap + spId):
710 (tKwCb->u.ulCb->kwuUlSap + spId);
712 /* Take action based on the current state of the SAP */
713 switch(kwuSap->state)
715 /* SAP is configured but not bound */
719 /* copy bind configuration parameters in sap */
721 kwuSap->pst.dstProcId = pst->srcProcId;
722 kwuSap->pst.dstEnt = pst->srcEnt;
723 kwuSap->pst.dstInst = pst->srcInst;
725 /* Update the State */
726 kwuSap->state = KW_SAP_BND;
728 RLOG1(L_DEBUG, "KwUiKwuBndReq: state (%d)", kwuSap->state);
733 /* Sap is already bound check source, destination Entity and Proc Id */
734 if (kwuSap->pst.dstProcId != pst->srcProcId ||
735 kwuSap->pst.dstEnt != pst->srcEnt ||
736 kwuSap->pst.dstInst != pst->srcInst ||
737 kwuSap->suId != suId)
739 KW_SEND_SAPID_ALARM(tKwCb,
741 LKW_EVENT_KWU_BND_REQ,
742 LCM_CAUSE_INV_PAR_VAL);
743 RLOG1(L_ERROR,"RLC Mode [%d] : KWU SAP already Bound",
744 tKwCb->genCfg.rlcMode);
745 KwUiKwuBndCfm(&(kwuSap->pst), kwuSap->suId, CM_BND_NOK);
753 #if (ERRCLASS & ERRCLS_INT_PAR)
754 RLOG1(L_ERROR,"RLC Mode [%d]:Invalid KWU SAP State in Bind Req",
755 tKwCb->genCfg.rlcMode);
756 KW_SEND_SAPID_ALARM(tKwCb,
758 LKW_EVENT_KWU_BND_REQ,
759 LCM_CAUSE_INV_STATE);
760 #endif /* ERRCLASS & ERRCLS_INT_PAR */
761 KwUiKwuBndCfm(&(kwuSap->pst), kwuSap->suId, CM_BND_NOK);
765 KwUiKwuBndCfm(&(kwuSap->pst), kwuSap->suId, CM_BND_OK);
772 * Handler for unbinding the RLC upper layer service user with
776 * This function is used by RLC user to request for unbinding
777 * with RLC.This function is called by the KWU interface to
780 * @param[in] pst Post structure
781 * @param[in] spId Service provider SAP ID
782 * @param[in] reason Reason for Unbinding
789 PUBLIC S16 KwUiKwuUbndReq
796 PUBLIC S16 KwUiKwuUbndReq(pst, spId, reason)
802 KwKwuSapCb *kwuSap; /* KWU SAP control block */
807 #if (ERRCLASS & ERRCLS_INT_PAR)
808 if ((pst->dstInst >= KW_MAX_RLC_INSTANCES) ||
809 (spId >= (S16) kwCb[pst->dstInst]->genCfg.maxKwuSaps) ||
816 tKwCb = KW_GET_KWCB(pst->dstInst);
818 RLOG2(L_DEBUG, "spId(%d), reason(%d)",
822 /* Get Sap control block */
823 kwuSap = (tKwCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
824 (tKwCb->u.dlCb->kwuDlSap + spId):
825 (tKwCb->u.ulCb->kwuUlSap + spId);
827 kwuSap->state = KW_SAP_CFG;
833 * @brief Handler for receiving the data(SDU) from upper layer.
836 * This function is used by RLC service user (PDCP) to
837 * transfer data (SDU) to RLC.
839 * @param[in] pst Post structure
840 * @param[in] spId Service Provider SAP ID
841 * @param[in] datreq Data Request Information
842 * @param[in] mBuf Data Buffer (SDU)
849 PUBLIC S16 KwUiKwuDatReq
853 KwuDatReqInfo *datReq,
857 PUBLIC S16 KwUiKwuDatReq(pst, spId, datReq, mBuf)
860 KwuDatReqInfo *datReq;
864 S16 ret = ROK; /* Return Value */
865 KwDlRbCb *rbCb; /* RB Control Block */
866 KwKwuSapCb *kwuSap; /* SAP Config Block */
871 #if (ERRCLASS & ERRCLS_INT_PAR)
872 if ((pst->dstInst >= KW_MAX_RLC_INSTANCES) ||
873 (spId >= (S16) kwCb[pst->dstInst]->genCfg.maxKwuSaps) ||
881 tKwCb = KW_GET_KWCB(pst->dstInst);
883 /* Get Sap control block */
884 kwuSap = tKwCb->u.dlCb->kwuDlSap + spId;
886 /* Validate SAP ID under ERRORCLS */
887 KW_VALDATE_SAP(tKwCb,spId, kwuSap, ret);
895 kwDbmFetchDlRbCbByRbId(tKwCb, &datReq->rlcId, &rbCb);
898 RLOG_ARG2(L_WARNING, DBG_UEID,datReq->rlcId.ueId, "CellId[%u]:DL RbId [%d] not found",
899 datReq->rlcId.cellId,datReq->rlcId.rbId);
905 /* kw005.201 update the spId received in datReq to update statistics */
906 rbCb->kwuSapId = spId;
907 /* Dispatch according to mode of the rbCb */
912 /* Verify the user */
913 if (pst->srcEnt != ENTNH)
915 /* kw002.201 Freeing from proper region */
916 KW_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, datReq,
917 sizeof(KwuDatReqInfo));
923 kwTmmQSdu(tKwCb,rbCb, datReq, mBuf);
924 /* kw005.201 ccpu00117318, updated statistics */
930 kwUmmQSdu(tKwCb,rbCb, datReq, mBuf);
932 /* kw005.201 ccpu00117318, updated statistics */
938 kwAmmQSdu(tKwCb,rbCb, mBuf, datReq);
939 /* kw005.201 ccpu00117318, updated statistics */
945 RLOG0(L_ERROR, "Invalid RB Mode");
955 * Handler for discarding a SDU.
958 * This function is used by RLC AM and RLC UM entities.
959 * This function is called by the service user to discard a particular
960 * RLC SDU if it is present in the SDU queue of the RB control block
961 * and if it is not mapped to any PDU.
963 * @param[in] pst Post structure
964 * @param[in] spId Service Provider SAP ID
965 * @param[in] discSdu SDU discard Information
972 PUBLIC S16 KwUiKwuDiscSduReq
976 KwuDiscSduInfo *discSdu
979 PUBLIC S16 KwUiKwuDiscSduReq(pst, spId, discSdu)
982 KwuDiscSduInfo *discSdu;
985 KW_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, discSdu, sizeof(KwuDiscSduInfo));
989 /********************************************************************30**
991 **********************************************************************/