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 "envopt.h" /* environment options */
40 #include "envdep.h" /* environment dependent */
41 #include "envind.h" /* environment independent */
43 #include "gen.h" /* general */
44 #include "ssi.h" /* system services */
46 #include "cm_lte.h" /* Common LTE */
47 #include "cm_tkns.h" /* Common Token Defines */
48 #include "cm_llist.h" /* Common Link List Defines */
49 #include "cm_hash.h" /* Common Hash List Defines */
50 #include "cm_mblk.h" /* common memory link list library */
52 #include "rg_env.h" /* MAC Environment Defines */
53 #include "tfu.h" /* CRG Interface defines */
54 #include "crg.h" /* CRG Interface defines */
55 #include "rg_sch_inf.h" /* RGR Interface defines */
56 #include "rgu.h" /* RGU Interface defines */
57 #include "lrg.h" /* LRG Interface defines */
59 #include "rg.h" /* MAC defines */
60 #include "rg_err.h" /* MAC error defines */
62 /* header/extern include files (.x) */
63 #include "gen.x" /* general */
64 #include "ssi.x" /* system services */
65 #include "cm5.x" /* common timers */
66 #include "cm_lib.x" /* common library */
67 #include "cm_lte.x" /* Common LTE */
68 #include "cm_tkns.x" /* Common Token Definitions */
69 #include "cm_llist.x" /* Common Link List Definitions */
70 #include "cm_lib.x" /* Common Library Definitions */
71 #include "cm_hash.x" /* Common Hash List Definitions */
72 #include "cm_mblk.x" /* common memory link list library */
74 #include "rgu.x" /* RGU types */
75 #include "tfu.x" /* CRG Interface includes */
76 #include "crg.x" /* CRG Interface includes */
77 #include "rg_sch_inf.x" /* SCH Interface includes */
78 #include "rg_prg.x" /* PRG interface includes */
79 #include "rgu.x" /* RGU Interface includes */
80 #include "lrg.x" /* LRG Interface includes */
82 #include "rg.x" /* MAC includes */
90 /* forward references */
92 #define RG_DUX_ALLOC(_pdu, _size, _dataPtr, _ret) {\
93 _ret = cmGetMem((Ptr)&_pdu->memCp, _size, (Ptr *)&_dataPtr); \
96 #define RG_INIT_SDU(_sdu, _lcId, _len) {\
97 (_sdu)->lcId = (_lcId); \
98 (_sdu)->len = (_len); \
99 (_sdu)->mBuf = NULLP; \
100 (_sdu)->sduLstEnt.next = NULLP; \
101 (_sdu)->sduLstEnt.prev = NULLP; \
102 (_sdu)->sduLstEnt.node = (PTR)(_sdu); \
105 #define RG_EXT_BS(_bsr, _bs1, _bs2, _bs3, _bs4) {\
106 _bs1 = _bsr[0] >> 2; \
107 _bs2 = (((_bsr[0] & 0x3) << 4) | (_bsr[1] >> 4)); \
108 _bs3 = (((_bsr[1] & 0x0F) << 2) | (_bsr[2] >> 6)); \
109 _bs4 = _bsr[2] & 0x3F; \
112 #define RG_UNPACK_LONG_BSR(_bsr, _mBuf, _ret) {\
113 _ret = SRemPreMsgMult((_bsr), 3, (_mBuf)); \
116 #define RG_UNPACK_SHORT_BSR(_bsr, _mBuf, _ret) {\
117 _ret = SUnpkU8((_bsr), (_mBuf)); \
120 #define RG_UNPACK_TRUNC_BSR(_bsr, _mBuf, _ret) {\
121 _ret = SUnpkU8((_bsr), (_mBuf)); \
124 #define RG_UNPACK_PHR(_phr, _mBuf, _ret) {\
125 _ret = SUnpkU8((_phr), (_mBuf)); \
128 #define RG_UNPACK_CRNTI(_rnti, _mBuf, _ret) {\
131 _ret = SRemPreMsgMult(_unpkArray, (MsgLen) 2, _mBuf);\
134 *_rnti = (U16) PutHiByte(*_rnti, (U8) _unpkArray[0]);\
135 *_rnti = (U16) PutLoByte(*_rnti, (U8) _unpkArray[1]);\
139 /* For EXT PHR DEMUX */
140 #define RG_UNPACK_EXT_PHR_CI(_ci, _mBuf, _ret) {\
141 _ret = SUnpkU8((_ci), (_mBuf)); \
144 #define RG_UNPACK_EXT_PHR(_extPhr, _mBuf, _ret) {\
145 _ret = SUnpkU8((_extPhr), (_mBuf)); \
151 * @brief Handles the insertion of SDU in to PDU.
155 * Function: rgDUXInsSdu
157 * This API handles the insertion of SDU in to PDU.
160 * - Append the sdu to the sduLst of pdu.
162 * @param[in] Inst inst
172 PRIVATE S16 rgDUXInsSdu
182 PRIVATE S16 rgDUXInsSdu(inst,pdu, sdu, lcId, sduLen, err)
192 RgMacSdu *sduAloc = NULLP;
196 RG_DUX_ALLOC(pdu, sizeof(RgMacSdu), sduAloc, ret);
199 RLOG1(L_ERROR, "Allocation of RgSubHdr failed for LCID:%d",lcId);
200 err->errCause = RGERR_DUX_MEM_EXHAUST;
204 RG_INIT_SDU(sduAloc, lcId, sduLen);
205 cmLListAdd2Tail(&pdu->sduLst, &sduAloc->sduLstEnt);
210 * @brief Handles extracting the CE sub headers from the MAC PDU.
214 * Function: rgDUXExtSubHdr
216 * This API handles extracting the sub headers from the MAC PDU.
219 * - Extract the each sub header.
221 * @param[in] Inst inst
232 PRIVATE S16 rgDUXExtSubHdr
242 PRIVATE S16 rgDUXExtSubHdr(inst,pdu, mBuf, lcId,
258 if(SUnpkU8(&byte,mBuf) != ROK)
260 RLOG0(L_ERROR, "SUnpkU8 failed");
261 err->errCause = RGERR_DUX_UNPACK_FAILURE;
264 /* Extract the lcid */
265 RG_EXT_LCID(*lcId, byte);
267 /*note: RG_EXT_PHR_LCID currently not considered */
268 if(*lcId <= RG_DEDLC_MAX_LCID)
269 { /* variable size MAC Sub PDU */
270 RG_EXT_FORMT_BIT(fmt,byte);
271 if(SUnpkU8(&byte, mBuf) != ROK)
273 RLOG0(L_ERROR, "SUnpkU8 failed");
274 err->errCause = RGERR_DUX_UNPACK_FAILURE;
280 if(SUnpkU8(&byte,mBuf) != ROK)
282 RLOG0(L_ERROR, "SUnpkU8 failed");
283 err->errCause = RGERR_DUX_UNPACK_FAILURE;
286 *len = (*len << 8) | byte;
290 } /* rgDUXExtSubHdr */
293 * @brief Handles extracting the CEs from the MAC PDU.
297 * Function: rgDUXExtCe
299 * This API handles extracting the CEs from the MAC PDU.
302 * - Based on the ce sub header extract the ce.
304 * @param[in] Inst inst
305 * @param[in,out] *pdu
306 * @param[out] *ceInfo
309 * @param[in] subPduLen
316 PRIVATE S16 rgDUXExtCe
327 PRIVATE S16 rgDUXExtCe(inst,pdu, ceInfo, mBuf,lcId,subPduLen, err)
343 case RG_EXT_PHR_LCID:
349 RgInfExtPhrCEInfo *extPhr;
351 RG_UNPACK_EXT_PHR_CI(&Ci,mBuf,ret);
354 RLOG1(L_ERROR,"Unpacking of EXT PHR failed LCID:%d",lcId);
355 err->errCause = RGERR_DUX_UNPACK_FAILURE;
359 /* Not handling Type 2 PHR report as simultaneous PUSCH/PUCCH
360 is not supported as of now */
361 extPhr = &ceInfo->ces.extPhr;
362 extPhr->numServCells = 0;
364 /* Setting first BIT as PCELL field even though reserved is always
367 for (sCellIdx = 0; (Ci && sCellIdx < CM_LTE_MAX_CELLS); sCellIdx++)
371 extPhr->servCellPhr[extPhr->numServCells].sCellIdx = sCellIdx;
372 RG_UNPACK_EXT_PHR(&extPhrOctet,mBuf,ret);
375 RLOG1(L_ERROR,"Unpacking of EXT PHR failed LCID:%d",lcId);
376 err->errCause = RGERR_DUX_UNPACK_FAILURE;
380 /* extPhrOctet: Bits : 7 6 5 4 3 2 1 0
384 /* P : P Back off applied or not */
385 extPhr->servCellPhr[extPhr->numServCells].phr = (extPhrOctet & 0x3F);
386 extPhr->servCellPhr[extPhr->numServCells].pBackOff =
387 ((extPhrOctet >> 7) & 0x01);
389 /* V: Virtual PCMAX or Real Tx PCMAX */
390 if (extPhrOctet & 0x40)
392 extPhr->servCellPhr[extPhr->numServCells].pCmax = RG_REF_PCMAX;
396 RG_UNPACK_EXT_PHR(&extPhrPCmax,mBuf,ret);
399 RLOG1(L_ERROR,"Unpacking of EXT PHR failed LCID:%d",lcId);
400 err->errCause = RGERR_DUX_UNPACK_FAILURE;
403 extPhr->servCellPhr[extPhr->numServCells].pCmax = (extPhrPCmax & 0x3F);
405 extPhr->numServCells++;
410 ceInfo->bitMask |= RG_EXT_PHR_CE_PRSNT;
416 RG_UNPACK_PHR(&ceInfo->ces.phr,mBuf,ret);
419 RLOG1(L_ERROR,"Unpacking of PHR failed LCID:%d",lcId);
420 err->errCause = RGERR_DUX_UNPACK_FAILURE;
423 ceInfo->bitMask |= RG_PHR_CE_PRSNT;
426 case RG_TRUNC_BSR_LCID:
428 RG_UNPACK_TRUNC_BSR(&ceInfo->ces.bsr.truncBsr,mBuf,ret);
431 RLOG1(L_ERROR,"Unpacking of Trunc BSR failed LCID:%d",lcId);
432 err->errCause = RGERR_DUX_UNPACK_FAILURE;
435 ceInfo->bitMask |= RG_TRUNC_BSR_CE_PRSNT;
438 case RG_SHORT_BSR_LCID:
440 RG_UNPACK_SHORT_BSR(&ceInfo->ces.bsr.shortBsr,mBuf,ret);
443 RLOG1(L_ERROR,"Unpacking of Short BSR failed LCID:%d",lcId);
444 err->errCause = RGERR_DUX_UNPACK_FAILURE;
447 ceInfo->bitMask |= RG_SHORT_BSR_CE_PRSNT;
450 case RG_LONG_BSR_LCID:
452 U8 longBsr[3] = {0}; /* KW_FIXX */
453 RG_UNPACK_LONG_BSR(longBsr,mBuf,ret);
456 RLOG1(L_ERROR,"Unpacking of Long BSR failed LCID:%d",lcId);
457 err->errCause = RGERR_DUX_UNPACK_FAILURE;
461 ceInfo->ces.bsr.longBsr.bs1,
462 ceInfo->ces.bsr.longBsr.bs2,
463 ceInfo->ces.bsr.longBsr.bs3,
464 ceInfo->ces.bsr.longBsr.bs4);
465 ceInfo->bitMask |= RG_LONG_BSR_CE_PRSNT;
470 RG_UNPACK_CRNTI(&ceInfo->ces.cRnti,mBuf,ret);
473 RLOG1(L_ERROR,"Unpacking of C-RNTI failed LCID:%d",lcId);
474 err->errCause = RGERR_DUX_UNPACK_FAILURE;
477 ceInfo->bitMask |= RG_CRNTI_CE_PRSNT;
481 RLOG1(L_ERROR, "Invalid LCID:%u received",lcId);
482 err->errCause = RGERR_DUX_INV_LCID_RX;
490 * @brief Handles extracting the SDU from the MAC PDU.
494 * Function: rgDUXExtSdu
496 * This API handles extracting the SDU corresponding to a logical channel.
499 * - Based on the length stored in the sub header extract the SDU.
501 * @param[in] Inst inst
502 * @param[in,out] *pdu
503 * @param[out] *ceInfo
506 * @param[in] subPduLen
513 PRIVATE S16 rgDUXExtSdu
524 PRIVATE S16 rgDUXExtSdu(inst,pdu, ceInfo,mBuf,lcId,subPduLen,err)
536 Buffer *tmpBuf2 = NULLP;
541 if(lcId == RG_CCCH_LCID)
543 ceInfo->bitMask |= RG_CCCH_SDU_PRSNT;
546 if(rgDUXInsSdu(inst,pdu, &sdu,lcId, subPduLen, err) != ROK)
554 ret = SSegMsg(tmpBuf1,subPduLen,&tmpBuf2);
555 if((ret != ROK) && (!((ret == ROKDNA) )))
557 RG_FREE_MSG(tmpBuf1);
558 RLOG0(L_ERROR,"SSegMsg failed");
559 err->errCause = RGERR_DUX_RLC_PDU_CREAT_FAIL;
569 * @brief Handles de-multiplexing of the data recieved at MAC.
573 * Function: rgDUXDemuxData
575 * This API handles de-multiplexing of the data recieved at MAC.
577 * Invoked by: rgTOMTfuDatInd of TOM
580 * - De-multiplex the mBuf
582 * @param[in] Inst inst
591 PUBLIC S16 rgDUXDemuxData
600 PUBLIC S16 rgDUXDemuxData(inst,pdu, ceInfo, mBuf, err)
613 ceInfo->bitMask = 0x0000;
615 /* Initialize the sdu list */
616 cmLListInit(&pdu->sduLst);
620 RLOG0(L_ERROR, "Null Buffer Recevived");
625 /* UL Message format order :
626 PduSubHdr+SubPDU,PduSubHdr+SubPDU,...CeSubHdr+Ce,CeSubPdu+Ce,...,PADSubHdr+PAD */
627 /* Extract the Sub headers */
628 if(rgDUXExtSubHdr(inst,pdu, *mBuf, &lcId,
629 &subPduLen, err) != ROK)
632 RLOG0(L_ERROR, "Failed to extract pad sub headers");
635 if(lcId == RG_PAD_LCID)
636 { /*at end of MAC PDU, Padding started */
640 if(lcId <= RG_DEDLC_MAX_LCID)
642 /* Extract the sdus */
643 if(rgDUXExtSdu(inst,pdu,ceInfo, mBuf,lcId,subPduLen, err) != ROK)
645 /* Fix : syed rgDUXExtSdu would have segmented mBuf and hence
646 * will be responsible for freeing mBuf */
648 RLOG0(L_ERROR, "failed to Extract the sdus");
651 if(*mBuf == NULLP) /* if message read completes then return */
658 /* Extract the ces */
659 if(rgDUXExtCe(inst,pdu,ceInfo,*mBuf, lcId,subPduLen, err) != ROK)
662 RLOG0(L_ERROR, " failed to Extract the ces");
666 if(SFndLenMsg(*mBuf,&len) != ROK)
669 RLOG0(L_ERROR,"mBuf length check failed");
670 err->errCause = RGERR_DUX_UNPACK_FAILURE;
677 } /* rgDUXDemuxData */
679 /**********************************************************************
682 **********************************************************************/