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;
176 RG_DUX_ALLOC(pdu, sizeof(RgMacSdu), sduAloc, ret);
179 RLOG1(L_ERROR, "Allocation of RgSubHdr failed for LCID:%d",lcId);
180 err->errCause = RGERR_DUX_MEM_EXHAUST;
184 RG_INIT_SDU(sduAloc, lcId, sduLen);
185 cmLListAdd2Tail(&pdu->sduLst, &sduAloc->sduLstEnt);
190 * @brief Handles extracting the CE sub headers from the MAC PDU.
194 * Function: rgDUXExtSubHdr
196 * This API handles extracting the sub headers from the MAC PDU.
199 * - Extract the each sub header.
201 * @param[in] Inst inst
212 PRIVATE S16 rgDUXExtSubHdr
222 PRIVATE S16 rgDUXExtSubHdr(inst,pdu, mBuf, lcId,
238 if(oduPackUInt8(&byte,mBuf) != ROK)
240 RLOG0(L_ERROR, "oduPackUInt8 failed");
241 err->errCause = RGERR_DUX_UNPACK_FAILURE;
244 /* Extract the lcid */
245 RG_EXT_LCID(*lcId, byte);
247 /*note: RG_EXT_PHR_LCID currently not considered */
248 if(*lcId <= RG_DEDLC_MAX_LCID)
249 { /* variable size MAC Sub PDU */
250 RG_EXT_FORMT_BIT(fmt,byte);
251 if(oduPackUInt8(&byte, mBuf) != ROK)
253 RLOG0(L_ERROR, "oduPackUInt8 failed");
254 err->errCause = RGERR_DUX_UNPACK_FAILURE;
260 if(oduPackUInt8(&byte,mBuf) != ROK)
262 RLOG0(L_ERROR, "oduPackUInt8 failed");
263 err->errCause = RGERR_DUX_UNPACK_FAILURE;
266 *len = (*len << 8) | byte;
270 } /* rgDUXExtSubHdr */
273 * @brief Handles extracting the CEs from the MAC PDU.
277 * Function: rgDUXExtCe
279 * This API handles extracting the CEs from the MAC PDU.
282 * - Based on the ce sub header extract the ce.
284 * @param[in] Inst inst
285 * @param[in,out] *pdu
286 * @param[out] *ceInfo
289 * @param[in] subPduLen
296 PRIVATE S16 rgDUXExtCe
307 PRIVATE S16 rgDUXExtCe(inst,pdu, ceInfo, mBuf,lcId,subPduLen, err)
323 case RG_EXT_PHR_LCID:
329 RgInfExtPhrCEInfo *extPhr;
331 RG_UNPACK_EXT_PHR_CI(&Ci,mBuf,ret);
334 RLOG1(L_ERROR,"Unpacking of EXT PHR failed LCID:%d",lcId);
335 err->errCause = RGERR_DUX_UNPACK_FAILURE;
339 /* Not handling Type 2 PHR report as simultaneous PUSCH/PUCCH
340 is not supported as of now */
341 extPhr = &ceInfo->ces.extPhr;
342 extPhr->numServCells = 0;
344 /* Setting first BIT as PCELL field even though reserved is always
347 for (sCellIdx = 0; (Ci && sCellIdx < CM_LTE_MAX_CELLS); sCellIdx++)
351 extPhr->servCellPhr[extPhr->numServCells].sCellIdx = sCellIdx;
352 RG_UNPACK_EXT_PHR(&extPhrOctet,mBuf,ret);
355 RLOG1(L_ERROR,"Unpacking of EXT PHR failed LCID:%d",lcId);
356 err->errCause = RGERR_DUX_UNPACK_FAILURE;
360 /* extPhrOctet: Bits : 7 6 5 4 3 2 1 0
364 /* P : P Back off applied or not */
365 extPhr->servCellPhr[extPhr->numServCells].phr = (extPhrOctet & 0x3F);
366 extPhr->servCellPhr[extPhr->numServCells].pBackOff =
367 ((extPhrOctet >> 7) & 0x01);
369 /* V: Virtual PCMAX or Real Tx PCMAX */
370 if (extPhrOctet & 0x40)
372 extPhr->servCellPhr[extPhr->numServCells].pCmax = RG_REF_PCMAX;
376 RG_UNPACK_EXT_PHR(&extPhrPCmax,mBuf,ret);
379 RLOG1(L_ERROR,"Unpacking of EXT PHR failed LCID:%d",lcId);
380 err->errCause = RGERR_DUX_UNPACK_FAILURE;
383 extPhr->servCellPhr[extPhr->numServCells].pCmax = (extPhrPCmax & 0x3F);
385 extPhr->numServCells++;
390 ceInfo->bitMask |= RG_EXT_PHR_CE_PRSNT;
396 RG_UNPACK_PHR(&ceInfo->ces.phr,mBuf,ret);
399 RLOG1(L_ERROR,"Unpacking of PHR failed LCID:%d",lcId);
400 err->errCause = RGERR_DUX_UNPACK_FAILURE;
403 ceInfo->bitMask |= RG_PHR_CE_PRSNT;
406 case RG_TRUNC_BSR_LCID:
408 RG_UNPACK_TRUNC_BSR(&ceInfo->ces.bsr.truncBsr,mBuf,ret);
411 RLOG1(L_ERROR,"Unpacking of Trunc BSR failed LCID:%d",lcId);
412 err->errCause = RGERR_DUX_UNPACK_FAILURE;
415 ceInfo->bitMask |= RG_TRUNC_BSR_CE_PRSNT;
418 case RG_SHORT_BSR_LCID:
420 RG_UNPACK_SHORT_BSR(&ceInfo->ces.bsr.shortBsr,mBuf,ret);
423 RLOG1(L_ERROR,"Unpacking of Short BSR failed LCID:%d",lcId);
424 err->errCause = RGERR_DUX_UNPACK_FAILURE;
427 ceInfo->bitMask |= RG_SHORT_BSR_CE_PRSNT;
430 case RG_LONG_BSR_LCID:
432 U8 longBsr[3] = {0}; /* KW_FIXX */
433 RG_UNPACK_LONG_BSR(longBsr,mBuf,ret);
436 RLOG1(L_ERROR,"Unpacking of Long BSR failed LCID:%d",lcId);
437 err->errCause = RGERR_DUX_UNPACK_FAILURE;
441 ceInfo->ces.bsr.longBsr.bs1,
442 ceInfo->ces.bsr.longBsr.bs2,
443 ceInfo->ces.bsr.longBsr.bs3,
444 ceInfo->ces.bsr.longBsr.bs4);
445 ceInfo->bitMask |= RG_LONG_BSR_CE_PRSNT;
450 RG_UNPACK_CRNTI(&ceInfo->ces.cRnti,mBuf,ret);
453 RLOG1(L_ERROR,"Unpacking of C-RNTI failed LCID:%d",lcId);
454 err->errCause = RGERR_DUX_UNPACK_FAILURE;
457 ceInfo->bitMask |= RG_CRNTI_CE_PRSNT;
461 RLOG1(L_ERROR, "Invalid LCID:%u received",lcId);
462 err->errCause = RGERR_DUX_INV_LCID_RX;
470 * @brief Handles extracting the SDU from the MAC PDU.
474 * Function: rgDUXExtSdu
476 * This API handles extracting the SDU corresponding to a logical channel.
479 * - Based on the length stored in the sub header extract the SDU.
481 * @param[in] Inst inst
482 * @param[in,out] *pdu
483 * @param[out] *ceInfo
486 * @param[in] subPduLen
493 PRIVATE S16 rgDUXExtSdu
504 PRIVATE S16 rgDUXExtSdu(inst,pdu, ceInfo,mBuf,lcId,subPduLen,err)
516 Buffer *tmpBuf2 = NULLP;
521 if(lcId == RG_CCCH_LCID)
523 ceInfo->bitMask |= RG_CCCH_SDU_PRSNT;
526 if(rgDUXInsSdu(inst,pdu, &sdu,lcId, subPduLen, err) != ROK)
534 ret = SSegMsg(tmpBuf1,subPduLen,&tmpBuf2);
535 if((ret != ROK) && (!((ret == ROKDNA) )))
537 RG_FREE_MSG(tmpBuf1);
538 RLOG0(L_ERROR,"SSegMsg failed");
539 err->errCause = RGERR_DUX_RLC_PDU_CREAT_FAIL;
549 * @brief Handles de-multiplexing of the data recieved at MAC.
553 * Function: rgDUXDemuxData
555 * This API handles de-multiplexing of the data recieved at MAC.
557 * Invoked by: rgTOMTfuDatInd of TOM
560 * - De-multiplex the mBuf
562 * @param[in] Inst inst
580 S16 rgDUXDemuxData(inst,pdu, ceInfo, mBuf, err)
593 ceInfo->bitMask = 0x0000;
595 /* Initialize the sdu list */
596 cmLListInit(&pdu->sduLst);
600 RLOG0(L_ERROR, "Null Buffer Recevived");
605 /* UL Message format order :
606 PduSubHdr+SubPDU,PduSubHdr+SubPDU,...CeSubHdr+Ce,CeSubPdu+Ce,...,PADSubHdr+PAD */
607 /* Extract the Sub headers */
608 if(rgDUXExtSubHdr(inst,pdu, *mBuf, &lcId,
609 &subPduLen, err) != ROK)
612 RLOG0(L_ERROR, "Failed to extract pad sub headers");
615 if(lcId == RG_PAD_LCID)
616 { /*at end of MAC PDU, Padding started */
620 if(lcId <= RG_DEDLC_MAX_LCID)
622 /* Extract the sdus */
623 if(rgDUXExtSdu(inst,pdu,ceInfo, mBuf,lcId,subPduLen, err) != ROK)
625 /* Fix : syed rgDUXExtSdu would have segmented mBuf and hence
626 * will be responsible for freeing mBuf */
628 RLOG0(L_ERROR, "failed to Extract the sdus");
631 if(*mBuf == NULLP) /* if message read completes then return */
638 /* Extract the ces */
639 if(rgDUXExtCe(inst,pdu,ceInfo,*mBuf, lcId,subPduLen, err) != ROK)
642 RLOG0(L_ERROR, " failed to Extract the ces");
646 if(SFndLenMsg(*mBuf,&len) != ROK)
649 RLOG0(L_ERROR,"mBuf length check failed");
650 err->errCause = RGERR_DUX_UNPACK_FAILURE;
657 } /* rgDUXDemuxData */
659 /**********************************************************************
662 **********************************************************************/