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, SlotIndInfo 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 idx = 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);
61 pduLen = rxDataIndPdu->pduLength;
62 rxDataPdu = rxDataIndPdu->pduData;
63 GET_UE_IDX(rxDataIndPdu->rnti, ueIdx);
68 /* MSB in 1st octet is Reserved bit. Hence not decoding it.
69 2nd MSB in 1st octet is R/F bit depending upon type of payload */
70 fBit = (1 << 7) & rxDataPdu[idx];
72 /* LC id is the 6 LSB in 1st octet */
73 lcId = (~((~0) << 6)) & rxDataPdu[idx];
81 /* for UL CCCH,fixed length of MAC SDU */
84 /* Allocating sharable memory to send ul ccch msg to du app*/
85 MAC_ALLOC_SHRABL_BUF(pdu, length);
88 DU_LOG("\nERROR --> MAC : UL CCCH PDU memory allocation failed");
92 memcpy(pdu, &rxDataPdu[idx], length);
96 /* store msg3 pdu in macRaCb for CRI value */
97 memcpy(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg3Pdu, pdu, length);
99 /* Send UL-CCCH Indication to DU APP */
100 ret = macProcUlCcchInd(macCb.macCell[cellIdx]->cellId, rxDataIndPdu->rnti, length, pdu);
104 case MAC_LCID_MIN ... MAC_LCID_MAX :
106 DU_LOG("\nINFO --> MAC : PDU received for LC ID %d", lcId);
110 length = rxDataPdu[idx];
115 length = (length << 8) & rxDataPdu[idx];
118 /* Copying the payload to send to RLC */
119 MAC_ALLOC_SHRABL_BUF(pdu, length);
122 DU_LOG("\nERROR --> MAC : Memory allocation failed while demuxing Rx Data PDU");
127 memcpy(pdu, &rxDataPdu[idx], length);
131 /* Delete RA cb once RRC setup complete received */
132 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == rxDataIndPdu->rnti)
134 MAC_FREE(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
135 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
136 MAC_FREE(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, \
137 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize);
138 memset(&macCb.macCell[cellIdx]->macRaCb[ueIdx], 0, sizeof(MacRaCbInfo));
141 /* Send UL Data to RLC */
142 ret = macProcUlData(cellId, rxDataIndPdu->rnti, slotInfo, lcId, length, pdu);
146 case MAC_LCID_RESERVED_MIN ... MAC_LCID_RESERVED_MAX :
149 case MAC_LCID_CCCH_48BIT :
152 case MAC_LCID_BIT_RATE_QUERY :
155 case MAC_LCID_MULT_PHR_FOUR_OCT :
158 case MAC_LCID_CFG_GRANT_CFM :
161 case MAC_LCID_MULT_PHR_ONE_OCT:
164 case MAC_LCID_SINGLE_PHR :
167 case MAC_LCID_CRNTI :
170 case MAC_LCID_SHORT_TRUNC_BSR :
173 case MAC_LCID_LONG_TRUNC_BSR :
176 case MAC_LCID_SHORT_BSR :
179 uint8_t bufferSizeIdx = 0;
181 uint32_t bufferSize = 0;
186 crnti = rxDataIndPdu->rnti;
187 /* 5 LSB bits in pdu represent buffer size */
188 bufferSizeIdx = (~((~0) << 5)) & rxDataPdu[idx];
189 /* first 3 MSB bits in pdu represent LCGID */
190 lcgId = (rxDataPdu[idx]) >> 5;
191 /* determine actual number of bytes requested */
192 bufferSize = shortBsrBytesTable[bufferSizeIdx];
193 ret = macProcShortBsr(macCb.macCell[cellIdx]->cellId, crnti, lcgId, bufferSize);
200 case MAC_LCID_LONG_BSR :
203 case MAC_LCID_PADDING :
208 DU_LOG("\nERROR --> MAC : Invalid LC Id %d", lcId);
211 } /* End of switch */
213 if(lcId == MAC_LCID_PADDING)
220 } /* End of unpackRxData */
222 /**********************************************************************
224 **********************************************************************/