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 "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
101 PUBLIC S16 KwUiCkwBndReq
108 PUBLIC S16 KwUiCkwBndReq (pst, suId, spId)
119 #if (ERRCLASS & ERRCLS_INT_PAR)
120 if (pst->dstInst >= MAX_RLC_INSTANCES)
126 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
128 RLOG2(L_DEBUG, "spId(%d), suId(%d)", spId, suId);
129 ckwSap = &(tRlcCb->u.ulCb->ckwSap);
130 /* Take action based on the current state of the SAP */
131 switch(ckwSap->state)
133 /* SAP is configured but not bound */
137 /* copy bind configuration parameters in SSAP sap */
139 ckwSap->pst.dstProcId = pst->srcProcId;
140 ckwSap->pst.dstEnt = pst->srcEnt;
141 ckwSap->pst.dstInst = pst->srcInst;
143 /* Update the State */
144 ckwSap->state = KW_SAP_BND;
146 RLOG1(L_DEBUG, "KwUiCkwBndReq: state (%d)", ckwSap->state);
151 /* Sap is already bound check source, destination Entity and
153 if (ckwSap->pst.dstProcId != pst->srcProcId ||
154 ckwSap->pst.dstEnt != pst->srcEnt ||
155 ckwSap->pst.dstInst != pst->srcInst ||
156 ckwSap->suId != suId)
158 KW_SEND_SAPID_ALARM(tRlcCb,
160 LKW_EVENT_CKW_BND_REQ,
161 LCM_CAUSE_INV_PAR_VAL);
163 RLOG0(L_ERROR, "CKW SAP already Bound");
164 KwUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_NOK);
171 #if (ERRCLASS & ERRCLS_INT_PAR)
172 RLOG0(L_ERROR, "Invalid CKW SAP State in Bind Req");
173 KW_SEND_SAPID_ALARM(tRlcCb,
175 LKW_EVENT_CKW_BND_REQ,
176 LCM_CAUSE_INV_STATE);
177 #endif /* ERRCLASS & ERRCLS_INT_PAR */
178 KwUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_NOK);
184 KwUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_OK);
191 * Handler for unbinding the RLC upper layer service user CKW with
195 * This function is used by RLC user to request for unbinding
196 * with RLC.This function is called by the CKW interface to
199 * @param[in] pst Post structure
200 * @param[in] spId Service provider SAP ID
201 * @param[in] reason Reason for Unbinding
208 PUBLIC S16 KwUiCkwUbndReq
215 PUBLIC S16 KwUiCkwUbndReq(pst, spId, reason)
225 #if (ERRCLASS & ERRCLS_INT_PAR)
226 if (pst->dstInst >= MAX_RLC_INSTANCES)
230 #endif /* ERRCLASS & ERRCLS_INT_PAR */
231 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
233 RLOG2(L_DEBUG,"spId(%d), reason(%d)",
239 #if (ERRCLASS & ERRCLS_INT_PAR)
240 KW_GET_AND_VALIDATE_CKWSAP(tRlcCb,
241 (&(tRlcCb->u.ulCb->ckwSap)),
244 #endif /* ERRCLASS & ERRCLS_INT_PAR */
246 /* disable upper sap (CKW) */
247 tRlcCb->u.ulCb->ckwSap.state = KW_SAP_CFG;
253 * Handler for configuring RLC entities.
256 * This function is used by RRC to configure(add/delete/modify)
257 * one or more RLC entities.
259 * @param[in] pst - Post structure
260 * @param[in] spId - Serive Provider ID
261 * @param[in] cfg - Configuration information for one or more RLC entities.
268 PUBLIC S16 RlcProcCfgReq
274 PUBLIC S16 RlcProcCfgReq(pst, cfg)
280 RlcUlCfgTmpData *cfgTmpData;
282 static U32 transCount;
287 #if (ERRCLASS & ERRCLS_INT_PAR)
288 if (pst->dstInst >= MAX_RLC_INSTANCES)
290 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
294 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
296 RLC_ALLOC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
298 if (cfgTmpData == NULLP)
300 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
304 cfgTmpData->uprLyrTransId = cfg->transId; /*Save User TransId*/
305 cfgTmpData->transId = ++transCount; /*Generate new TransId*/
306 cfg->transId = cfgTmpData->transId;
307 cfgTmpData->cfgInfo = cfg;
310 if (kwDbmAddUlTransaction(tRlcCb, cfgTmpData) != ROK)
312 RLOG0(L_ERROR, "Addition to UL transId Lst Failed");
313 RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
318 rlcUlHdlCfgReq(tRlcCb, cfgTmpData, cfg);
319 rlcUlUdxCfgReq(&(KW_GET_UDX_SAP(tRlcCb)->pst),KW_GET_UDX_SAP(tRlcCb)->spId,cfg);
326 * Handler to change the UeId
329 * This primitive is used by RRC to change the UeId for the existing UE
332 * @param[in] pst - Point to the pst structure
333 * @param[in] spId - The ID of the service provider SAP in the RLC layer
334 * @param[in] transId - Transaction ID. This field uniquily identifies
335 * transaction between RRC and RLC
336 * @param[in] ueInfo - Old UE Id Info for which the change request has come
337 * @param[in] newUeInfo - New UE Id Info for existing UE context
344 PUBLIC S16 KwUiCkwUeIdChgReq
353 PUBLIC S16 KwUiCkwUeIdChgReq(pst, spId, transId, ueInfo, newUeInfo)
358 CkwUeInfo *newUeInfo;
363 RlcUlCfgTmpData *cfgTmpData = NULLP;
365 TRC3(KwUiCkwUeIdChgReq)
369 #if (ERRCLASS & ERRCLS_INT_PAR)
370 if (pst->dstInst >= MAX_RLC_INSTANCES)
377 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
379 RLOG_ARG2(L_DEBUG,DBG_CELLID,newUeInfo->cellId,
380 "KwUiCkwUeIdChgReq(pst, spId(%d), transId(%ld))",
384 RLOG_ARG2(L_DEBUG,DBG_CELLID,newUeInfo->cellId,
385 "KwUiCkwUeIdChgReq(pst, spId(%d), transId(%d))\n",
390 RLC_ALLOC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
397 cfgTmpData->transId = transId;
398 cfgTmpData->ueInfo = ueInfo;
399 cfgTmpData->newUeInfo = newUeInfo;
401 if (kwDbmAddUlTransaction(tRlcCb, cfgTmpData))
403 RLOG0(L_ERROR, "Addition to UL transId Lst Failed");
411 /* there was an error in the processing, free up all the memory
412 * that was passed and could have been allocated in this function
414 /* Freeing from proper region */
415 RLC_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CkwUeInfo));
416 RLC_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CkwUeInfo));
420 RLC_FREE(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
425 if(ROK != rlcCfgValidateUeIdChng(tRlcCb,ueInfo,newUeInfo,cfgTmpData))
427 RLOG_ARG0(L_ERROR,DBG_CELLID,cfgTmpData->ueInfo->cellId,
428 "Validation Failure for UeId change");
431 rlcUlUdxUeIdChgReq(&(KW_GET_UDX_SAP(tRlcCb)->pst),
432 KW_GET_UDX_SAP(tRlcCb)->spId,
443 * Handler for Configuration Request
445 * @param[in] gCb RLC Instance Control Block
446 * @param[in] cfgTmpData Configuration stored in Transaction Block
447 * @param[in] cfg Configuration block
454 PUBLIC Void rlcUlHdlCfgReq
457 RlcUlCfgTmpData *cfgTmpData,
461 PUBLIC Void rlcUlHdlCfgReq(gCb, cfgTmpData, cfg)
463 RlcUlCfgTmpData *cfgTmpData;
471 cfgTmpData->ueId = cfg->ueId;
472 cfgTmpData->cellId = cfg->cellId;
473 for (idx = 0; idx < cfg->numEnt; idx++)
475 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_OK;
476 cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbId = cfg->entCfg[idx].rbId;
477 cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbType = cfg->entCfg[idx].rbType;
478 switch(cfg->entCfg[idx].cfgType)
485 if(cfg->entCfg[idx].dir & KW_DIR_UL)
487 /* Configuration is for UL , thus validating */
488 if(ROK != rlcCfgValidateUlRb(gCb,
490 &cfgTmpData->cfgEntData[idx],
493 RLOG_ARG2(L_ERROR,DBG_UEID, cfgTmpData->ueId,
494 "CELLID [%u]:Validation Failure for UL RB [%d]",
495 cfg->cellId,cfg->entCfg[idx].rbId);
496 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
497 /*Validation is getting failed so no need to do configuration at DL.
498 *Set dir as UL, so that no configuration is done at DL */
499 cfg->entCfg[idx].dir = KW_DIR_UL;
502 if(cfg->entCfg[idx].dir == KW_DIR_UL)
504 /*If the configuration is for UL only then apply it */
505 if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
509 &cfgTmpData->cfgEntData[idx],
515 case CKW_CFG_REESTABLISH:
517 if(cfg->entCfg[idx].dir & KW_DIR_UL)
519 if(ROK != rlcCfgValidateReEstRb(gCb,
523 &cfgTmpData->cfgEntData[idx]))
525 RLOG_ARG2(L_ERROR,DBG_UEID,cfg->ueId,
526 "CellID [%u]:Validation Failure for Reest UL RB [%d]",
527 cfg->cellId,cfg->entCfg[idx].rbId);
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 = KW_DIR_UL;
534 if(cfg->entCfg[idx].dir == KW_DIR_UL)
536 /*If the configuration is for UL only then apply it */
537 if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
539 rlcCfgApplyReEstUlRb(gCb,
543 &cfgTmpData->cfgEntData[idx]);
548 case CKW_CFG_DELETE_UE :
550 if(ROK != rlcCfgValidateDelUlUe(gCb,
552 &cfgTmpData->cfgEntData[idx],
555 RLOG_ARG1(L_ERROR,DBG_CELLID,cfg->cellId,
556 "UL UEID [%d]:Validation Failure",
558 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
559 /* Setting dir as UL, so that no configuration is done at DL */
560 cfg->entCfg[idx].dir = KW_DIR_UL;
564 case CKW_CFG_DELETE_CELL :
566 if(ROK != rlcCfgValidateDelUlCell(gCb,
569 &cfgTmpData->cfgEntData[idx],
572 RLOG_ARG0(L_ERROR,DBG_CELLID,cfg->cellId,
573 "Del UL Cell Validation Failure");
574 cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
575 /* Setting dir as UL, so that no configuration is done at DL */
576 cfg->entCfg[idx].dir = KW_DIR_UL;
586 /*****************************************************************************
588 ****************************************************************************/
591 * Handler for binding the RLC upper layer service user with
595 * This function is used by RLC user to request for binding to
596 * RLC.This function is called by the KWU interface to bind
597 * RLC's SAP (identified by spId) with the service user's
598 * SAP (identified by suId).
600 * @param[in] pst Post structure
601 * @param[in] suId Service user SAP ID
602 * @param[in] spId Service provider ID
610 PUBLIC S16 KwUiKwuBndReq
617 PUBLIC S16 KwUiKwuBndReq (pst, suId, spId)
623 KwKwuSapCb *kwuSap; /* SAP Config Block */
628 #if (ERRCLASS & ERRCLS_INT_PAR)
629 if (pst->dstInst >= MAX_RLC_INSTANCES)
634 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
635 RLOG2(L_DEBUG, "KwUiKwuBndReq(pst, spId(%d), suId(%d))", spId, suId);
637 /* Validation of input parameters */
638 #if (ERRCLASS & ERRCLS_INT_PAR)
639 if(!((spId < (S16) tRlcCb->genCfg.maxKwuSaps) && (spId >=0)))
641 RLOG0(L_ERROR,"Invalid spId");
642 KW_SEND_SAPID_ALARM(tRlcCb,spId, LKW_EVENT_KWU_BND_REQ, LCM_CAUSE_INV_SAP);
647 /* Get Sap control block */
648 kwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
649 (tRlcCb->u.dlCb->kwuDlSap + spId):
650 (tRlcCb->u.ulCb->kwuUlSap + spId);
652 /* Take action based on the current state of the SAP */
653 switch(kwuSap->state)
655 /* SAP is configured but not bound */
659 /* copy bind configuration parameters in sap */
661 kwuSap->pst.dstProcId = pst->srcProcId;
662 kwuSap->pst.dstEnt = pst->srcEnt;
663 kwuSap->pst.dstInst = pst->srcInst;
665 /* Update the State */
666 kwuSap->state = KW_SAP_BND;
668 RLOG1(L_DEBUG, "KwUiKwuBndReq: state (%d)", kwuSap->state);
673 /* Sap is already bound check source, destination Entity and Proc Id */
674 if (kwuSap->pst.dstProcId != pst->srcProcId ||
675 kwuSap->pst.dstEnt != pst->srcEnt ||
676 kwuSap->pst.dstInst != pst->srcInst ||
677 kwuSap->suId != suId)
679 KW_SEND_SAPID_ALARM(tRlcCb,
681 LKW_EVENT_KWU_BND_REQ,
682 LCM_CAUSE_INV_PAR_VAL);
683 RLOG1(L_ERROR,"RLC Mode [%d] : KWU SAP already Bound",
684 tRlcCb->genCfg.rlcMode);
685 KwUiKwuBndCfm(&(kwuSap->pst), kwuSap->suId, CM_BND_NOK);
693 #if (ERRCLASS & ERRCLS_INT_PAR)
694 RLOG1(L_ERROR,"RLC Mode [%d]:Invalid KWU SAP State in Bind Req",
695 tRlcCb->genCfg.rlcMode);
696 KW_SEND_SAPID_ALARM(tRlcCb,
698 LKW_EVENT_KWU_BND_REQ,
699 LCM_CAUSE_INV_STATE);
700 #endif /* ERRCLASS & ERRCLS_INT_PAR */
701 KwUiKwuBndCfm(&(kwuSap->pst), kwuSap->suId, CM_BND_NOK);
705 KwUiKwuBndCfm(&(kwuSap->pst), kwuSap->suId, CM_BND_OK);
712 * Handler for unbinding the RLC upper layer service user with
716 * This function is used by RLC user to request for unbinding
717 * with RLC.This function is called by the KWU interface to
720 * @param[in] pst Post structure
721 * @param[in] spId Service provider SAP ID
722 * @param[in] reason Reason for Unbinding
729 PUBLIC S16 KwUiKwuUbndReq
736 PUBLIC S16 KwUiKwuUbndReq(pst, spId, reason)
742 KwKwuSapCb *kwuSap; /* KWU SAP control block */
747 #if (ERRCLASS & ERRCLS_INT_PAR)
748 if ((pst->dstInst >= MAX_RLC_INSTANCES) ||
749 (spId >= (S16) rlcCb[pst->dstInst]->genCfg.maxKwuSaps) ||
756 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
758 RLOG2(L_DEBUG, "spId(%d), reason(%d)",
762 /* Get Sap control block */
763 kwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
764 (tRlcCb->u.dlCb->kwuDlSap + spId):
765 (tRlcCb->u.ulCb->kwuUlSap + spId);
767 kwuSap->state = KW_SAP_CFG;
773 * @brief Handler for receiving the data(SDU) from upper layer.
776 * This function is used by RLC service user (PDCP) to
777 * transfer data (SDU) to RLC.
779 * @param[in] pst Post structure
780 * @param[in] spId Service Provider SAP ID
781 * @param[in] datreq Data Request Information
782 * @param[in] mBuf Data Buffer (SDU)
789 PUBLIC S16 KwUiKwuDatReq
792 KwuDatReqInfo *datReq,
796 PUBLIC S16 KwUiKwuDatReq(pst, datReq, mBuf)
798 KwuDatReqInfo *datReq;
802 S16 ret = ROK; /* Return Value */
803 RlcDlRbCb *rbCb; /* RB Control Block */
808 DU_LOG("\nRLC : Received DL Data");
810 #if (ERRCLASS & ERRCLS_INT_PAR)
811 if(pst->dstInst >= MAX_RLC_INSTANCES)
818 tRlcCb = RLC_GET_RLCCB(pst->dstInst);
821 kwDbmFetchDlRbCbByRbId(tRlcCb, &datReq->rlcId, &rbCb);
824 RLOG_ARG2(L_WARNING, DBG_UEID,datReq->rlcId.ueId, "CellId[%u]:DL RbId [%d] not found",
825 datReq->rlcId.cellId,datReq->rlcId.rbId);
831 /* Dispatch according to mode of the rbCb */
836 /* Verify the user */
837 if (pst->srcEnt != ENTNH)
839 /* kw002.201 Freeing from proper region */
840 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, datReq,
841 sizeof(KwuDatReqInfo));
847 kwTmmQSdu(tRlcCb,rbCb, datReq, mBuf);
852 kwUmmQSdu(tRlcCb,rbCb, datReq, mBuf);
858 kwAmmQSdu(tRlcCb,rbCb, mBuf, datReq);
863 RLOG0(L_ERROR, "Invalid RB Mode");
873 * Handler for discarding a SDU.
876 * This function is used by RLC AM and RLC UM entities.
877 * This function is called by the service user to discard a particular
878 * RLC SDU if it is present in the SDU queue of the RB control block
879 * and if it is not mapped to any PDU.
881 * @param[in] pst Post structure
882 * @param[in] spId Service Provider SAP ID
883 * @param[in] discSdu SDU discard Information
890 PUBLIC S16 KwUiKwuDiscSduReq
894 KwuDiscSduInfo *discSdu
897 PUBLIC S16 KwUiKwuDiscSduReq(pst, spId, discSdu)
900 KwuDiscSduInfo *discSdu;
903 RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, discSdu, sizeof(KwuDiscSduInfo));
907 /********************************************************************30**
909 **********************************************************************/