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 /* header include files -- defines (.h) */
20 #include "common_def.h"
21 #include "lrg.h" /* Layer manager interface includes*/
22 #include "lrg.x" /* layer management typedefs for MAC */
23 #include "du_app_mac_inf.h"
24 #include "mac_sch_interface.h"
25 #include "lwr_mac_upr_inf.h"
27 #include "mac_utils.h"
30 /*******************************************************************
32 * @brief De-mux of MAC-Sub PDUs from Rx Data Ind Pdu
36 * Function : unpackRxData
39 * De-mux of MAC-Sub PDUs from Rx Data Ind Pdu
41 * @params[in] Pointer to PDU received
46 * ****************************************************************/
47 uint8_t unpackRxData(uint16_t cellId, SlotTimingInfo slotInfo, RxDataIndPdu *rxDataIndPdu)
49 uint8_t ueIdx = 0; /* Iterator for UE list */
50 uint8_t lcId = 0; /* LC ID of a sub pdu */
51 uint8_t fBit = 0; /* Value of F Bit in MAC sub-header */
52 uint8_t rxPduIdx = 0; /* Iterator for received PDU */
53 uint16_t length = 0; /* Length of payload in a sub-PDU */
54 uint8_t *pdu = NULLP; /* Payload in sub-PDU */
55 uint16_t pduLen = 0; /* Length of undecoded PDU */
56 uint8_t *rxDataPdu = NULLP; /* Received PDU in Rx Data Ind */
57 uint16_t cellIdx = 0; /* Cell Index */
60 GET_CELL_IDX(cellId, cellIdx);
62 if(rxDataIndPdu == NULLP)
64 DU_LOG("\nERROR --> MAC: Rx Data is empty");
68 if(macCb.macCell[cellIdx] == NULLP)
70 DU_LOG("\nERROR --> CellId :%d is not created, as CellCB is empty", cellId);
73 pduLen = rxDataIndPdu->pduLength;
74 rxDataPdu = rxDataIndPdu->pduData;
75 GET_UE_IDX(rxDataIndPdu->rnti, ueIdx);
80 /* MSB in 1st octet is Reserved bit. Hence not decoding it.
81 2nd MSB in 1st octet is R/F bit depending upon type of payload */
82 fBit = (1 << 7) & rxDataPdu[rxPduIdx];
84 /* LC id is the 6 LSB in 1st octet */
85 lcId = (~((~0) << 6)) & rxDataPdu[rxPduIdx];
94 /* for UL CCCH,fixed length of MAC SDU */
97 /* Allocating sharable memory to send ul ccch msg to du app*/
98 MAC_ALLOC_SHRABL_BUF(pdu, length);
101 DU_LOG("\nERROR --> MAC : UL CCCH PDU memory allocation failed");
105 memcpy(pdu, &rxDataPdu[rxPduIdx], length);
107 rxPduIdx = rxPduIdx + length;
109 /* store msg3 pdu in macRaCb for CRI value */
110 memcpy(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg3Pdu, pdu, length);
112 /* Send UL-CCCH Indication to DU APP */
113 ret = macProcUlCcchInd(macCb.macCell[cellIdx]->cellId, rxDataIndPdu->rnti, length, pdu);
117 case MAC_LCID_MIN ... MAC_LCID_MAX :
119 DU_LOG("\nINFO --> MAC : PDU received for LC ID %d", lcId);
123 length = rxDataPdu[rxPduIdx];
128 length = (length << 8) & rxDataPdu[rxPduIdx];
132 /* Copying the payload to send to RLC */
133 MAC_ALLOC_SHRABL_BUF(pdu, length);
136 DU_LOG("\nERROR --> MAC : Memory allocation failed while demuxing Rx Data PDU");
141 memcpy(pdu, &rxDataPdu[rxPduIdx], length);
143 rxPduIdx = rxPduIdx + length;
145 /* Delete RA cb once RRC setup complete received */
146 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == rxDataIndPdu->rnti)
148 MAC_FREE(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
149 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
150 MAC_FREE(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, \
151 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize - TX_PAYLOAD_HDR_LEN);
152 memset(&macCb.macCell[cellIdx]->macRaCb[ueIdx], 0, sizeof(MacRaCbInfo));
155 /* Send UL Data to RLC */
156 ret = macProcUlData(cellId, rxDataIndPdu->rnti, slotInfo, lcId, length, pdu);
160 case MAC_LCID_RESERVED_MIN ... MAC_LCID_RESERVED_MAX :
163 case MAC_LCID_CCCH_48BIT :
166 case MAC_LCID_BIT_RATE_QUERY :
169 case MAC_LCID_MULT_PHR_FOUR_OCT :
172 case MAC_LCID_CFG_GRANT_CFM :
175 case MAC_LCID_MULT_PHR_ONE_OCT:
178 case MAC_LCID_SINGLE_PHR :
181 case MAC_LCID_CRNTI :
184 case MAC_LCID_SHORT_TRUNC_BSR :
187 case MAC_LCID_LONG_TRUNC_BSR :
190 case MAC_LCID_SHORT_BSR :
193 uint8_t bufferSizeIdx = 0;
195 uint32_t bufferSize = 0;
200 crnti = rxDataIndPdu->rnti;
201 /* 5 LSB bits in pdu represent buffer size */
202 bufferSizeIdx = (~((~0) << 5)) & rxDataPdu[rxPduIdx];
203 /* first 3 MSB bits in pdu represent LCGID */
204 lcgId = (rxDataPdu[rxPduIdx]) >> 5;
205 /* determine actual number of bytes requested */
206 bufferSize = shortBsrBytesTable[bufferSizeIdx];
207 ret = macProcShortBsr(macCb.macCell[cellIdx]->cellId, crnti, lcgId, bufferSize);
214 case MAC_LCID_LONG_BSR :
216 DataVolInfo dataVolInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS];
217 memset(dataVolInfo, 0,MAX_NUM_LOGICAL_CHANNEL_GROUPS * sizeof(DataVolInfo));
221 uint8_t lcgIdxPos = 0;
224 rxPduIdx++;/*To reach the Octet where lcgIdx will be present*/
225 crnti = rxDataIndPdu->rnti;
227 lcgIdxPos = rxPduIdx;
230 rxPduIdx++;/*To reach the Octet where bsrIdx starts*/
231 for(lcgIdx = 0; lcgIdx < MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
233 if(rxDataPdu[lcgIdxPos] & (1 << lcgIdx))
235 if(rxDataPdu[rxPduIdx] > 0 && rxDataPdu[rxPduIdx] < MAX_LONG_BSR_TABLE_ENTRIES)
237 dataVolInfo[numLcg].dataVol = longBsrBytesTable[rxDataPdu[rxPduIdx]];
238 dataVolInfo[numLcg].lcgId = lcgIdx;
243 DU_LOG("\nERROR --> MAC: Invalid BsrIdx:%d rcvd for lcgIdx:%d",lcgIdx,rxDataPdu[rxPduIdx]);
251 ret = macProcLongBsr(macCb.macCell[cellIdx]->cellId, crnti, numLcg, dataVolInfo);
256 case MAC_LCID_PADDING :
261 DU_LOG("\nERROR --> MAC : Invalid LC Id %d", lcId);
264 } /* End of switch */
266 if(lcId == MAC_LCID_PADDING)
273 } /* End of unpackRxData */
275 /**********************************************************************
277 **********************************************************************/