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 = (U16) PutHiByte(*_rnti, (U8) _unpkArray[0]);\
115 *_rnti = (U16) PutLoByte(*_rnti, (U8) _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
152 PRIVATE S16 rgDUXInsSdu
162 PRIVATE S16 rgDUXInsSdu(inst,pdu, sdu, lcId, sduLen, err)
172 RgMacSdu *sduAloc = NULLP;
175 RG_DUX_ALLOC(pdu, sizeof(RgMacSdu), sduAloc, ret);
178 RLOG1(L_ERROR, "Allocation of RgSubHdr failed for LCID:%d",lcId);
179 err->errCause = RGERR_DUX_MEM_EXHAUST;
183 RG_INIT_SDU(sduAloc, lcId, sduLen);
184 cmLListAdd2Tail(&pdu->sduLst, &sduAloc->sduLstEnt);
189 * @brief Handles extracting the CE sub headers from the MAC PDU.
193 * Function: rgDUXExtSubHdr
195 * This API handles extracting the sub headers from the MAC PDU.
198 * - Extract the each sub header.
200 * @param[in] Inst inst
211 PRIVATE S16 rgDUXExtSubHdr
221 PRIVATE S16 rgDUXExtSubHdr(inst,pdu, mBuf, lcId,
236 if(oduPackUInt8(&byte,mBuf) != ROK)
238 RLOG0(L_ERROR, "oduPackUInt8 failed");
239 err->errCause = RGERR_DUX_UNPACK_FAILURE;
242 /* Extract the lcid */
243 RG_EXT_LCID(*lcId, byte);
245 /*note: RG_EXT_PHR_LCID currently not considered */
246 if(*lcId <= RG_DEDLC_MAX_LCID)
247 { /* variable size MAC Sub PDU */
248 RG_EXT_FORMT_BIT(fmt,byte);
249 if(oduPackUInt8(&byte, mBuf) != ROK)
251 RLOG0(L_ERROR, "oduPackUInt8 failed");
252 err->errCause = RGERR_DUX_UNPACK_FAILURE;
258 if(oduPackUInt8(&byte,mBuf) != ROK)
260 RLOG0(L_ERROR, "oduPackUInt8 failed");
261 err->errCause = RGERR_DUX_UNPACK_FAILURE;
264 *len = (*len << 8) | byte;
268 } /* rgDUXExtSubHdr */
271 * @brief Handles extracting the CEs from the MAC PDU.
275 * Function: rgDUXExtCe
277 * This API handles extracting the CEs from the MAC PDU.
280 * - Based on the ce sub header extract the ce.
282 * @param[in] Inst inst
283 * @param[in,out] *pdu
284 * @param[out] *ceInfo
287 * @param[in] subPduLen
294 PRIVATE S16 rgDUXExtCe
305 PRIVATE S16 rgDUXExtCe(inst,pdu, ceInfo, mBuf,lcId,subPduLen, err)
320 case RG_EXT_PHR_LCID:
326 RgInfExtPhrCEInfo *extPhr;
328 RG_UNPACK_EXT_PHR_CI(&Ci,mBuf,ret);
331 RLOG1(L_ERROR,"Unpacking of EXT PHR failed LCID:%d",lcId);
332 err->errCause = RGERR_DUX_UNPACK_FAILURE;
336 /* Not handling Type 2 PHR report as simultaneous PUSCH/PUCCH
337 is not supported as of now */
338 extPhr = &ceInfo->ces.extPhr;
339 extPhr->numServCells = 0;
341 /* Setting first BIT as PCELL field even though reserved is always
344 for (sCellIdx = 0; (Ci && sCellIdx < CM_LTE_MAX_CELLS); sCellIdx++)
348 extPhr->servCellPhr[extPhr->numServCells].sCellIdx = sCellIdx;
349 RG_UNPACK_EXT_PHR(&extPhrOctet,mBuf,ret);
352 RLOG1(L_ERROR,"Unpacking of EXT PHR failed LCID:%d",lcId);
353 err->errCause = RGERR_DUX_UNPACK_FAILURE;
357 /* extPhrOctet: Bits : 7 6 5 4 3 2 1 0
361 /* P : P Back off applied or not */
362 extPhr->servCellPhr[extPhr->numServCells].phr = (extPhrOctet & 0x3F);
363 extPhr->servCellPhr[extPhr->numServCells].pBackOff =
364 ((extPhrOctet >> 7) & 0x01);
366 /* V: Virtual PCMAX or Real Tx PCMAX */
367 if (extPhrOctet & 0x40)
369 extPhr->servCellPhr[extPhr->numServCells].pCmax = RG_REF_PCMAX;
373 RG_UNPACK_EXT_PHR(&extPhrPCmax,mBuf,ret);
376 RLOG1(L_ERROR,"Unpacking of EXT PHR failed LCID:%d",lcId);
377 err->errCause = RGERR_DUX_UNPACK_FAILURE;
380 extPhr->servCellPhr[extPhr->numServCells].pCmax = (extPhrPCmax & 0x3F);
382 extPhr->numServCells++;
387 ceInfo->bitMask |= RG_EXT_PHR_CE_PRSNT;
393 RG_UNPACK_PHR(&ceInfo->ces.phr,mBuf,ret);
396 RLOG1(L_ERROR,"Unpacking of PHR failed LCID:%d",lcId);
397 err->errCause = RGERR_DUX_UNPACK_FAILURE;
400 ceInfo->bitMask |= RG_PHR_CE_PRSNT;
403 case RG_TRUNC_BSR_LCID:
405 RG_UNPACK_TRUNC_BSR(&ceInfo->ces.bsr.truncBsr,mBuf,ret);
408 RLOG1(L_ERROR,"Unpacking of Trunc BSR failed LCID:%d",lcId);
409 err->errCause = RGERR_DUX_UNPACK_FAILURE;
412 ceInfo->bitMask |= RG_TRUNC_BSR_CE_PRSNT;
415 case RG_SHORT_BSR_LCID:
417 RG_UNPACK_SHORT_BSR(&ceInfo->ces.bsr.shortBsr,mBuf,ret);
420 RLOG1(L_ERROR,"Unpacking of Short BSR failed LCID:%d",lcId);
421 err->errCause = RGERR_DUX_UNPACK_FAILURE;
424 ceInfo->bitMask |= RG_SHORT_BSR_CE_PRSNT;
427 case RG_LONG_BSR_LCID:
429 U8 longBsr[3] = {0}; /* KW_FIXX */
430 RG_UNPACK_LONG_BSR(longBsr,mBuf,ret);
433 RLOG1(L_ERROR,"Unpacking of Long BSR failed LCID:%d",lcId);
434 err->errCause = RGERR_DUX_UNPACK_FAILURE;
438 ceInfo->ces.bsr.longBsr.bs1,
439 ceInfo->ces.bsr.longBsr.bs2,
440 ceInfo->ces.bsr.longBsr.bs3,
441 ceInfo->ces.bsr.longBsr.bs4);
442 ceInfo->bitMask |= RG_LONG_BSR_CE_PRSNT;
447 RG_UNPACK_CRNTI(&ceInfo->ces.cRnti,mBuf,ret);
450 RLOG1(L_ERROR,"Unpacking of C-RNTI failed LCID:%d",lcId);
451 err->errCause = RGERR_DUX_UNPACK_FAILURE;
454 ceInfo->bitMask |= RG_CRNTI_CE_PRSNT;
458 RLOG1(L_ERROR, "Invalid LCID:%u received",lcId);
459 err->errCause = RGERR_DUX_INV_LCID_RX;
467 * @brief Handles extracting the SDU from the MAC PDU.
471 * Function: rgDUXExtSdu
473 * This API handles extracting the SDU corresponding to a logical channel.
476 * - Based on the length stored in the sub header extract the SDU.
478 * @param[in] Inst inst
479 * @param[in,out] *pdu
480 * @param[out] *ceInfo
483 * @param[in] subPduLen
490 PRIVATE S16 rgDUXExtSdu
501 PRIVATE S16 rgDUXExtSdu(inst,pdu, ceInfo,mBuf,lcId,subPduLen,err)
513 Buffer *tmpBuf2 = NULLP;
517 if(lcId == RG_CCCH_LCID)
519 ceInfo->bitMask |= RG_CCCH_SDU_PRSNT;
522 if(rgDUXInsSdu(inst,pdu, &sdu,lcId, subPduLen, err) != ROK)
530 ret = SSegMsg(tmpBuf1,subPduLen,&tmpBuf2);
531 if((ret != ROK) && (!((ret == ROKDNA) )))
533 RG_FREE_MSG(tmpBuf1);
534 RLOG0(L_ERROR,"SSegMsg failed");
535 err->errCause = RGERR_DUX_RLC_PDU_CREAT_FAIL;
545 * @brief Handles de-multiplexing of the data recieved at MAC.
549 * Function: rgDUXDemuxData
551 * This API handles de-multiplexing of the data recieved at MAC.
553 * Invoked by: rgTOMTfuDatInd of TOM
556 * - De-multiplex the mBuf
558 * @param[in] Inst inst
576 S16 rgDUXDemuxData(inst,pdu, ceInfo, mBuf, err)
588 ceInfo->bitMask = 0x0000;
590 /* Initialize the sdu list */
591 cmLListInit(&pdu->sduLst);
595 RLOG0(L_ERROR, "Null Buffer Recevived");
600 /* UL Message format order :
601 PduSubHdr+SubPDU,PduSubHdr+SubPDU,...CeSubHdr+Ce,CeSubPdu+Ce,...,PADSubHdr+PAD */
602 /* Extract the Sub headers */
603 if(rgDUXExtSubHdr(inst,pdu, *mBuf, &lcId,
604 &subPduLen, err) != ROK)
607 RLOG0(L_ERROR, "Failed to extract pad sub headers");
610 if(lcId == RG_PAD_LCID)
611 { /*at end of MAC PDU, Padding started */
615 if(lcId <= RG_DEDLC_MAX_LCID)
617 /* Extract the sdus */
618 if(rgDUXExtSdu(inst,pdu,ceInfo, mBuf,lcId,subPduLen, err) != ROK)
620 /* Fix : syed rgDUXExtSdu would have segmented mBuf and hence
621 * will be responsible for freeing mBuf */
623 RLOG0(L_ERROR, "failed to Extract the sdus");
626 if(*mBuf == NULLP) /* if message read completes then return */
633 /* Extract the ces */
634 if(rgDUXExtCe(inst,pdu,ceInfo,*mBuf, lcId,subPduLen, err) != ROK)
637 RLOG0(L_ERROR, " failed to Extract the ces");
641 if(SFndLenMsg(*mBuf,&len) != ROK)
644 RLOG0(L_ERROR,"mBuf length check failed");
645 err->errCause = RGERR_DUX_UNPACK_FAILURE;
652 } /* rgDUXDemuxData */
654 /**********************************************************************
657 **********************************************************************/