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 ueId = 0; /* UE Identity */
50 uint8_t ueIdx = 0; /* Iterator for UE list */
51 uint8_t lcId = 0; /* LC ID of a sub pdu */
52 uint8_t fBit = 0; /* Value of F Bit in MAC sub-header */
53 uint8_t rxPduIdx = 0; /* Iterator for received PDU */
54 uint16_t length = 0; /* Length of payload in a sub-PDU */
55 uint8_t *pdu = NULLP; /* Payload in sub-PDU */
56 uint16_t pduLen = 0; /* Length of undecoded PDU */
57 uint8_t *rxDataPdu = NULLP; /* Received PDU in Rx Data Ind */
58 uint16_t cellIdx = 0; /* Cell Index */
61 GET_CELL_IDX(cellId, cellIdx);
63 if(rxDataIndPdu == NULLP)
65 DU_LOG("\nERROR --> MAC: Rx Data is empty");
69 if(macCb.macCell[cellIdx] == NULLP)
71 DU_LOG("\nERROR --> CellId :%d is not created, as CellCB is empty", cellId);
74 pduLen = rxDataIndPdu->pduLength;
75 rxDataPdu = rxDataIndPdu->pduData;
76 GET_UE_ID(rxDataIndPdu->rnti, ueId);
81 /* MSB in 1st octet is Reserved bit. Hence not decoding it.
82 2nd MSB in 1st octet is R/F bit depending upon type of payload */
83 fBit = (1 << 7) & rxDataPdu[rxPduIdx];
85 /* LC id is the 6 LSB in 1st octet */
86 lcId = (~((~0) << 6)) & rxDataPdu[rxPduIdx];
95 /* for UL CCCH,fixed length of MAC SDU */
98 /* Allocating sharable memory to send ul ccch msg to du app*/
99 MAC_ALLOC_SHRABL_BUF(pdu, length);
102 DU_LOG("\nERROR --> MAC : UL CCCH PDU memory allocation failed");
106 memcpy(pdu, &rxDataPdu[rxPduIdx], length);
108 rxPduIdx = rxPduIdx + length;
110 /* store msg3 pdu in macRaCb for CRI value */
111 memcpy(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg3Pdu, pdu, length);
113 /* Send UL-CCCH Indication to DU APP */
114 ret = macProcUlCcchInd(macCb.macCell[cellIdx]->cellId, rxDataIndPdu->rnti, length, pdu);
118 case MAC_LCID_MIN ... MAC_LCID_MAX :
120 DU_LOG("\nINFO --> MAC : PDU received for LC ID %d", lcId);
124 length = rxDataPdu[rxPduIdx];
129 length = (length << 8) & rxDataPdu[rxPduIdx];
133 /* Copying the payload to send to RLC */
134 MAC_ALLOC_SHRABL_BUF(pdu, length);
137 DU_LOG("\nERROR --> MAC : Memory allocation failed while demuxing Rx Data PDU");
142 memcpy(pdu, &rxDataPdu[rxPduIdx], length);
144 rxPduIdx = rxPduIdx + length;
146 /* Send UL Data to RLC */
147 ret = macProcUlData(cellId, rxDataIndPdu->rnti, slotInfo, lcId, length, pdu);
151 case MAC_LCID_RESERVED_MIN ... MAC_LCID_RESERVED_MAX :
154 case MAC_LCID_CCCH_48BIT :
157 case MAC_LCID_BIT_RATE_QUERY :
160 case MAC_LCID_MULT_PHR_FOUR_OCT :
163 case MAC_LCID_CFG_GRANT_CFM :
166 case MAC_LCID_MULT_PHR_ONE_OCT:
169 case MAC_LCID_SINGLE_PHR :
172 case MAC_LCID_CRNTI :
175 case MAC_LCID_SHORT_TRUNC_BSR :
178 case MAC_LCID_LONG_TRUNC_BSR :
181 case MAC_LCID_SHORT_BSR :
184 uint8_t bufferSizeIdx = 0;
186 uint32_t bufferSize = 0;
191 crnti = rxDataIndPdu->rnti;
192 /* 5 LSB bits in pdu represent buffer size */
193 bufferSizeIdx = (~((~0) << 5)) & rxDataPdu[rxPduIdx];
194 /* first 3 MSB bits in pdu represent LCGID */
195 lcgId = (rxDataPdu[rxPduIdx]) >> 5;
196 /* determine actual number of bytes requested */
197 bufferSize = shortBsrBytesTable[bufferSizeIdx];
198 ret = macProcShortBsr(macCb.macCell[cellIdx]->cellId, crnti, lcgId, bufferSize);
205 case MAC_LCID_LONG_BSR :
207 DataVolInfo dataVolInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS];
208 memset(dataVolInfo, 0,MAX_NUM_LOGICAL_CHANNEL_GROUPS * sizeof(DataVolInfo));
212 uint8_t lcgIdxPos = 0;
215 rxPduIdx++;/*To reach the Octet where lcgIdx will be present*/
216 crnti = rxDataIndPdu->rnti;
218 lcgIdxPos = rxPduIdx;
221 rxPduIdx++;/*To reach the Octet where bsrIdx starts*/
222 for(lcgIdx = 0; lcgIdx < MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
224 if(rxDataPdu[lcgIdxPos] & (1 << lcgIdx))
226 if(rxDataPdu[rxPduIdx] > 0 && rxDataPdu[rxPduIdx] < MAX_LONG_BSR_TABLE_ENTRIES)
228 dataVolInfo[numLcg].dataVol = longBsrBytesTable[rxDataPdu[rxPduIdx]];
229 dataVolInfo[numLcg].lcgId = lcgIdx;
234 DU_LOG("\nERROR --> MAC: Invalid BsrIdx:%d rcvd for lcgIdx:%d",lcgIdx,rxDataPdu[rxPduIdx]);
242 ret = macProcLongBsr(macCb.macCell[cellIdx]->cellId, crnti, numLcg, dataVolInfo);
247 case MAC_LCID_PADDING :
252 DU_LOG("\nERROR --> MAC : Invalid LC Id %d", lcId);
255 } /* End of switch */
257 if(lcId == MAC_LCID_PADDING)
264 } /* End of unpackRxData */
266 /**********************************************************************
268 **********************************************************************/