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 /************************************************************************
25 Desc: C source code for Entry point fucntions
29 **********************************************************************/
32 @brief This module handles de-multiplexing of the data recieved at MAC.
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_FILE_ID=176;
37 static int RLOG_MODULE_ID=4096;
38 /* header include files -- defines (.h) */
39 #include "common_def.h"
41 #include "rg_env.h" /* MAC Environment Defines */
42 #include "tfu.h" /* CRG Interface defines */
43 #include "crg.h" /* CRG Interface defines */
44 #include "rg_sch_inf.h" /* RGR Interface defines */
45 #include "rgu.h" /* RGU Interface defines */
46 #include "lrg.h" /* LRG Interface defines */
48 #include "rg.h" /* MAC defines */
49 #include "rg_err.h" /* MAC error defines */
51 /* header/extern include files (.x) */
53 #include "rgu.x" /* RGU types */
54 #include "tfu.x" /* CRG Interface includes */
55 #include "crg.x" /* CRG Interface includes */
56 #include "rg_sch_inf.x" /* SCH Interface includes */
57 #include "rg_prg.x" /* PRG interface includes */
58 #include "rgu.x" /* RGU Interface includes */
59 #include "lrg.x" /* LRG Interface includes */
61 #include "du_app_mac_inf.h"
62 #include "rg.x" /* MAC includes */
70 /* forward references */
72 #define RG_DUX_ALLOC(_pdu, _size, _dataPtr, _ret) {\
73 _ret = cmGetMem((Ptr)&_pdu->memCp, _size, (Ptr *)&_dataPtr); \
76 #define RG_INIT_SDU(_sdu, _lcId, _len) {\
77 (_sdu)->lcId = (_lcId); \
78 (_sdu)->len = (_len); \
79 (_sdu)->mBuf = NULLP; \
80 (_sdu)->sduLstEnt.next = NULLP; \
81 (_sdu)->sduLstEnt.prev = NULLP; \
82 (_sdu)->sduLstEnt.node = (PTR)(_sdu); \
85 #define RG_EXT_BS(_bsr, _bs1, _bs2, _bs3, _bs4) {\
86 _bs1 = _bsr[0] >> 2; \
87 _bs2 = (((_bsr[0] & 0x3) << 4) | (_bsr[1] >> 4)); \
88 _bs3 = (((_bsr[1] & 0x0F) << 2) | (_bsr[2] >> 6)); \
89 _bs4 = _bsr[2] & 0x3F; \
92 #define RG_UNPACK_LONG_BSR(_bsr, _mBuf, _ret) {\
93 _ret = SRemPreMsgMult((_bsr), 3, (_mBuf)); \
96 #define RG_UNPACK_SHORT_BSR(_bsr, _mBuf, _ret) {\
97 _ret = oduPackUInt8((_bsr), (_mBuf)); \
100 #define RG_UNPACK_TRUNC_BSR(_bsr, _mBuf, _ret) {\
101 _ret = oduPackUInt8((_bsr), (_mBuf)); \
104 #define RG_UNPACK_PHR(_phr, _mBuf, _ret) {\
105 _ret = oduPackUInt8((_phr), (_mBuf)); \
108 #define RG_UNPACK_CRNTI(_rnti, _mBuf, _ret) {\
111 _ret = SRemPreMsgMult(_unpkArray, (MsgLen) 2, _mBuf);\
114 *_rnti = (uint16_t) PutHiByte(*_rnti, (uint8_t) _unpkArray[0]);\
115 *_rnti = (uint16_t) PutLoByte(*_rnti, (uint8_t) _unpkArray[1]);\
119 /* For EXT PHR DEMUX */
120 #define RG_UNPACK_EXT_PHR_CI(_ci, _mBuf, _ret) {\
121 _ret = oduPackUInt8((_ci), (_mBuf)); \
124 #define RG_UNPACK_EXT_PHR(_extPhr, _mBuf, _ret) {\
125 _ret = oduPackUInt8((_extPhr), (_mBuf)); \
131 * @brief Handles the insertion of SDU in to PDU.
135 * Function: rgDUXInsSdu
137 * This API handles the insertion of SDU in to PDU.
140 * - Append the sdu to the sduLst of pdu.
142 * @param[in] Inst inst
151 static S16 rgDUXInsSdu(Inst inst, RgMacPdu *pdu, RgMacSdu **sdu, uint8_t lcId, uint16_t sduLen, RgErrInfo *err)
154 RgMacSdu *sduAloc = NULLP;
157 RG_DUX_ALLOC(pdu, sizeof(RgMacSdu), sduAloc, ret);
160 RLOG1(L_ERROR, "Allocation of RgSubHdr failed for LCID:%d",lcId);
161 err->errCause = RGERR_DUX_MEM_EXHAUST;
165 RG_INIT_SDU(sduAloc, lcId, sduLen);
166 cmLListAdd2Tail(&pdu->sduLst, &sduAloc->sduLstEnt);
171 * @brief Handles extracting the CE sub headers from the MAC PDU.
175 * Function: rgDUXExtSubHdr
177 * This API handles extracting the sub headers from the MAC PDU.
180 * - Extract the each sub header.
182 * @param[in] Inst inst
192 static S16 rgDUXExtSubHdr(Inst inst, RgMacPdu *pdu, Buffer *mBuf, uint8_t *lcId, uint16_t *len, RgErrInfo *err)
199 if(oduPackUInt8(&byte,mBuf) != ROK)
201 RLOG0(L_ERROR, "oduPackUInt8 failed");
202 err->errCause = RGERR_DUX_UNPACK_FAILURE;
205 /* Extract the lcid */
206 RG_EXT_LCID(*lcId, byte);
208 /*note: RG_EXT_PHR_LCID currently not considered */
209 if(*lcId <= RG_DEDLC_MAX_LCID)
210 { /* variable size MAC Sub PDU */
211 RG_EXT_FORMT_BIT(fmt,byte);
212 if(oduPackUInt8(&byte, mBuf) != ROK)
214 RLOG0(L_ERROR, "oduPackUInt8 failed");
215 err->errCause = RGERR_DUX_UNPACK_FAILURE;
221 if(oduPackUInt8(&byte,mBuf) != ROK)
223 RLOG0(L_ERROR, "oduPackUInt8 failed");
224 err->errCause = RGERR_DUX_UNPACK_FAILURE;
227 *len = (*len << 8) | byte;
231 } /* rgDUXExtSubHdr */
234 * @brief Handles extracting the CEs from the MAC PDU.
238 * Function: rgDUXExtCe
240 * This API handles extracting the CEs from the MAC PDU.
243 * - Based on the ce sub header extract the ce.
245 * @param[in] Inst inst
246 * @param[in,out] *pdu
247 * @param[out] *ceInfo
250 * @param[in] subPduLen
256 static S16 rgDUXExtCe(Inst inst, RgMacPdu *pdu, RgInfCeInfo *ceInfo, Buffer *mBuf, uint8_t lcId, uint16_t subPduLen,\
264 case RG_EXT_PHR_LCID:
270 RgInfExtPhrCEInfo *extPhr;
272 RG_UNPACK_EXT_PHR_CI(&Ci,mBuf,ret);
275 RLOG1(L_ERROR,"Unpacking of EXT PHR failed LCID:%d",lcId);
276 err->errCause = RGERR_DUX_UNPACK_FAILURE;
280 /* Not handling Type 2 PHR report as simultaneous PUSCH/PUCCH
281 is not supported as of now */
282 extPhr = &ceInfo->ces.extPhr;
283 extPhr->numServCells = 0;
285 /* Setting first BIT as PCELL field even though reserved is always
288 for (sCellIdx = 0; (Ci && sCellIdx < CM_LTE_MAX_CELLS); sCellIdx++)
292 extPhr->servCellPhr[extPhr->numServCells].sCellIdx = sCellIdx;
293 RG_UNPACK_EXT_PHR(&extPhrOctet,mBuf,ret);
296 RLOG1(L_ERROR,"Unpacking of EXT PHR failed LCID:%d",lcId);
297 err->errCause = RGERR_DUX_UNPACK_FAILURE;
301 /* extPhrOctet: Bits : 7 6 5 4 3 2 1 0
305 /* P : P Back off applied or not */
306 extPhr->servCellPhr[extPhr->numServCells].phr = (extPhrOctet & 0x3F);
307 extPhr->servCellPhr[extPhr->numServCells].pBackOff =
308 ((extPhrOctet >> 7) & 0x01);
310 /* V: Virtual PCMAX or Real Tx PCMAX */
311 if (extPhrOctet & 0x40)
313 extPhr->servCellPhr[extPhr->numServCells].pCmax = RG_REF_PCMAX;
317 RG_UNPACK_EXT_PHR(&extPhrPCmax,mBuf,ret);
320 RLOG1(L_ERROR,"Unpacking of EXT PHR failed LCID:%d",lcId);
321 err->errCause = RGERR_DUX_UNPACK_FAILURE;
324 extPhr->servCellPhr[extPhr->numServCells].pCmax = (extPhrPCmax & 0x3F);
326 extPhr->numServCells++;
331 ceInfo->bitMask |= RG_EXT_PHR_CE_PRSNT;
337 RG_UNPACK_PHR(&ceInfo->ces.phr,mBuf,ret);
340 RLOG1(L_ERROR,"Unpacking of PHR failed LCID:%d",lcId);
341 err->errCause = RGERR_DUX_UNPACK_FAILURE;
344 ceInfo->bitMask |= RG_PHR_CE_PRSNT;
347 case RG_TRUNC_BSR_LCID:
349 RG_UNPACK_TRUNC_BSR(&ceInfo->ces.bsr.truncBsr,mBuf,ret);
352 RLOG1(L_ERROR,"Unpacking of Trunc BSR failed LCID:%d",lcId);
353 err->errCause = RGERR_DUX_UNPACK_FAILURE;
356 ceInfo->bitMask |= RG_TRUNC_BSR_CE_PRSNT;
359 case RG_SHORT_BSR_LCID:
361 RG_UNPACK_SHORT_BSR(&ceInfo->ces.bsr.shortBsr,mBuf,ret);
364 RLOG1(L_ERROR,"Unpacking of Short BSR failed LCID:%d",lcId);
365 err->errCause = RGERR_DUX_UNPACK_FAILURE;
368 ceInfo->bitMask |= RG_SHORT_BSR_CE_PRSNT;
371 case RG_LONG_BSR_LCID:
373 uint8_t longBsr[3] = {0}; /* KW_FIXX */
374 RG_UNPACK_LONG_BSR(longBsr,mBuf,ret);
377 RLOG1(L_ERROR,"Unpacking of Long BSR failed LCID:%d",lcId);
378 err->errCause = RGERR_DUX_UNPACK_FAILURE;
382 ceInfo->ces.bsr.longBsr.bs1,
383 ceInfo->ces.bsr.longBsr.bs2,
384 ceInfo->ces.bsr.longBsr.bs3,
385 ceInfo->ces.bsr.longBsr.bs4);
386 ceInfo->bitMask |= RG_LONG_BSR_CE_PRSNT;
391 RG_UNPACK_CRNTI(&ceInfo->ces.cRnti,mBuf,ret);
394 RLOG1(L_ERROR,"Unpacking of C-RNTI failed LCID:%d",lcId);
395 err->errCause = RGERR_DUX_UNPACK_FAILURE;
398 ceInfo->bitMask |= RG_CRNTI_CE_PRSNT;
402 RLOG1(L_ERROR, "Invalid LCID:%u received",lcId);
403 err->errCause = RGERR_DUX_INV_LCID_RX;
411 * @brief Handles extracting the SDU from the MAC PDU.
415 * Function: rgDUXExtSdu
417 * This API handles extracting the SDU corresponding to a logical channel.
420 * - Based on the length stored in the sub header extract the SDU.
422 * @param[in] Inst inst
423 * @param[in,out] *pdu
424 * @param[out] *ceInfo
427 * @param[in] subPduLen
433 static S16 rgDUXExtSdu(Inst inst, RgMacPdu *pdu, RgInfCeInfo *ceInfo, Buffer **mBuf, uint8_t lcId, uint16_t subPduLen,\
438 Buffer *tmpBuf2 = NULLP;
442 if(lcId == RG_CCCH_LCID)
444 ceInfo->bitMask |= RG_CCCH_SDU_PRSNT;
447 if(rgDUXInsSdu(inst,pdu, &sdu,lcId, subPduLen, err) != ROK)
455 ret = SSegMsg(tmpBuf1,subPduLen,&tmpBuf2);
456 if((ret != ROK) && (!((ret == ROKDNA) )))
458 RG_FREE_MSG(tmpBuf1);
459 RLOG0(L_ERROR,"SSegMsg failed");
460 err->errCause = RGERR_DUX_RLC_PDU_CREAT_FAIL;
470 * @brief Handles de-multiplexing of the data recieved at MAC.
474 * Function: rgDUXDemuxData
476 * This API handles de-multiplexing of the data recieved at MAC.
478 * Invoked by: rgTOMTfuDatInd of TOM
481 * - De-multiplex the mBuf
483 * @param[in] Inst inst
491 S16 rgDUXDemuxData(Inst inst, RgMacPdu *pdu, RgInfCeInfo *ceInfo, Buffer **mBuf, RgErrInfo *err)
497 ceInfo->bitMask = 0x0000;
499 /* Initialize the sdu list */
500 cmLListInit(&pdu->sduLst);
504 RLOG0(L_ERROR, "Null Buffer Recevived");
509 /* UL Message format order :
510 PduSubHdr+SubPDU,PduSubHdr+SubPDU,...CeSubHdr+Ce,CeSubPdu+Ce,...,PADSubHdr+PAD */
511 /* Extract the Sub headers */
512 if(rgDUXExtSubHdr(inst,pdu, *mBuf, &lcId,
513 &subPduLen, err) != ROK)
516 RLOG0(L_ERROR, "Failed to extract pad sub headers");
519 if(lcId == RG_PAD_LCID)
520 { /*at end of MAC PDU, Padding started */
524 if(lcId <= RG_DEDLC_MAX_LCID)
526 /* Extract the sdus */
527 if(rgDUXExtSdu(inst,pdu,ceInfo, mBuf,lcId,subPduLen, err) != ROK)
529 /* Fix : syed rgDUXExtSdu would have segmented mBuf and hence
530 * will be responsible for freeing mBuf */
532 RLOG0(L_ERROR, "failed to Extract the sdus");
535 if(*mBuf == NULLP) /* if message read completes then return */
542 /* Extract the ces */
543 if(rgDUXExtCe(inst,pdu,ceInfo,*mBuf, lcId,subPduLen, err) != ROK)
546 RLOG0(L_ERROR, " failed to Extract the ces");
550 if(SFndLenMsg(*mBuf,&len) != ROK)
553 RLOG0(L_ERROR,"mBuf length check failed");
554 err->errCause = RGERR_DUX_UNPACK_FAILURE;
561 } /* rgDUXDemuxData */
563 /**********************************************************************
566 **********************************************************************/