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"
25 #include "du_app_mac_inf.h"
26 #include "mac_sch_interface.h"
27 #include "mac_upr_inf_api.h"
30 #include "fapi_interface.h"
32 #include "lwr_mac_fsm.h"
33 #include "lwr_mac_upr_inf.h"
35 #include "mac_utils.h"
37 /* This file contains message handling functionality for MAC */
41 extern void sendToLowerMac(uint16_t msgType, uint32_t msgLen, void *msg);
42 uint16_t buildMacPdu(RlcMacData *dlData);
44 /* Function pointer for sending crc ind from MAC to SCH */
45 MacSchCrcIndFunc macSchCrcIndOpts[]=
52 /* Function pointer for sending DL RLC BO Info from MAC to SCH */
53 MacSchDlRlcBoInfoFunc macSchDlRlcBoInfoOpts[]=
55 packMacSchDlRlcBoInfo,
60 /*******************************************************************
62 * @brief Sends DL BO Info to SCH
66 * Function : sendDlRlcBoInfoMacToSch
69 * Sends DL BO Info to SCH
72 * @return ROK - success
75 ****************************************************************/
76 uint8_t sendDlRlcBoInfoMacToSch(DlRlcBOInfo *dlBoInfo)
80 FILL_PST_MAC_TO_SCH(pst, EVENT_DL_RLC_BO_INFO_TO_SCH);
81 return(*macSchDlRlcBoInfoOpts[pst.selector])(&pst, dlBoInfo);
84 /*******************************************************************
86 * @brief Sends CRC Indication to SCH
90 * Function : sendCrcIndMacToSch
93 * Sends CRC Indication to SCH
96 * @return ROK - success
99 ****************************************************************/
100 uint8_t sendCrcIndMacToSch(CrcIndInfo *crcInd)
104 FILL_PST_MAC_TO_SCH(pst, EVENT_CRC_IND_TO_SCH);
105 return(*macSchCrcIndOpts[pst.selector])(&pst, crcInd);
108 /*******************************************************************
110 * @brief Processes CRC Indication from PHY
114 * Function : fapiMacCrcInd
117 * Processes CRC Indication from PHY
119 * @params[in] Post Structure Pointer
120 * Crc Indication Pointer
121 * @return ROK - success
124 * ****************************************************************/
125 uint8_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
128 CrcIndInfo crcIndInfo;
130 DU_LOG("\nMAC : Received CRC indication");
132 GET_CELL_IDX(crcInd->cellId, cellIdx);
133 /* Considering one pdu and one preamble */
134 crcIndInfo.cellId = macCb.macCell[cellIdx]->cellId;;
135 crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
136 crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
137 crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
138 crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
139 crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
141 return(sendCrcIndMacToSch(&crcIndInfo));
144 /*******************************************************************
146 * @brief Process Rx Data Ind at MAC
150 * Function : fapiMacRxDataInd
153 * Process Rx Data Ind at MAC
155 * @params[in] Post structure
157 * @return ROK - success
160 * ****************************************************************/
161 uint8_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
165 DU_LOG("\nMAC : Received Rx Data indication");
167 /* TODO : compare the handle received in RxDataInd with handle send in PUSCH
168 * PDU, which is stored in raCb */
170 for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
172 unpackRxData(rxDataInd->cellId, &rxDataInd->pdus[pduIdx]);
177 /*******************************************************************
179 * @brief Processes DL data from RLC
183 * Function : MacRlcProcDlData
186 * Processes DL data from RLC
188 * @params[in] Post structure
190 * @return ROK - success
193 * ****************************************************************/
194 uint16_t MacRlcProcDlData(Pst* pst, SpId spId, RlcMacData *dlData)
199 /*******************************************************************
201 * @brief Processes BO status from RLC
205 * Function : MacRlcProcBOStatus
208 * Processes BO status from RLC
210 * @params[in] Post structure
212 * @return ROK - success
215 * ****************************************************************/
216 uint16_t MacRlcProcBOStatus(Pst* pst, SpId spId, RlcMacBOStatus* boStatus)
222 /*******************************************************************
224 * @brief Handles cell start reuqest from DU APP
228 * Function : MacProcCellStartReq
231 * Handles cell start reuqest from DU APP
233 * @params[in] Post structure pointer
234 * Cell Start Request info pointer
235 * @return ROK - success
238 * ****************************************************************/
239 uint8_t MacProcCellStartReq(Pst *pst, MacCellStartInfo *cellStartInfo)
241 DU_LOG("\nMAC : Handling cell start request");
242 sendToLowerMac(START_REQUEST, 0, cellStartInfo);
244 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStartInfo, \
245 sizeof(MacCellStartInfo));
250 /*******************************************************************
252 * @brief Handles cell stop request from DU APP
256 * Function : MacProcCellStartReq
259 * Handles cell stop request from DU APP
261 * @params[in] Post structure pointer
262 * Mac Cell stop information
263 * @return ROK - success
266 * ****************************************************************/
267 uint8_t MacProcCellStopReq(Pst *pst, MacCellStopInfo *cellStopInfo)
270 DU_LOG("\nMAC : Sending cell stop request to Lower Mac");
271 sendToLowerMac(FAPI_STOP_REQUEST, 0, cellStopInfo);
274 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStopInfo, \
275 sizeof(MacCellStopInfo));
280 /*******************************************************************
282 * @brief Handles DL CCCH Ind from DU APP
286 * Function : MacProcDlCcchInd
289 * Handles DL CCCH Ind from DU APP
291 * @params[in] Post structure pointer
292 * DL CCCH Ind pointer
293 * @return ROK - success
296 * ****************************************************************/
297 uint8_t MacProcDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
301 DlRlcBOInfo dlBoInfo;
302 memset(&dlBoInfo, 0, sizeof(DlRlcBOInfo));
304 DU_LOG("\nMAC : Handling DL CCCH IND");
306 GET_CELL_IDX(dlCcchIndInfo->cellId, cellIdx);
308 dlBoInfo.cellId = dlCcchIndInfo->cellId;
309 dlBoInfo.crnti = dlCcchIndInfo->crnti;
312 if(dlCcchIndInfo->msgType == RRC_SETUP)
314 dlBoInfo.boInfo[dlBoInfo.numLc].lcId = SRB_ID_0; // SRB ID 0 for msg4
315 dlBoInfo.boInfo[SRB_ID_0].dataVolume = \
316 dlCcchIndInfo->dlCcchMsgLen;
319 /* storing Msg4 Pdu in raCb */
320 if(macCb.macCell[cellIdx]->macRaCb[0].crnti == dlCcchIndInfo->crnti)
322 macCb.macCell[cellIdx]->macRaCb[0].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
323 MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[0].msg4Pdu, \
324 macCb.macCell[cellIdx]->macRaCb[0].msg4PduLen);
325 if(macCb.macCell[cellIdx]->macRaCb[0].msg4Pdu)
327 for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
329 macCb.macCell[cellIdx]->macRaCb[0].msg4Pdu[idx] =\
330 dlCcchIndInfo->dlCcchMsg[idx];
335 sendDlRlcBoInfoMacToSch(&dlBoInfo);
337 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
338 dlCcchIndInfo->dlCcchMsgLen);
339 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
344 /*******************************************************************
346 * @brief Sends UL CCCH Ind to DU APP
350 * Function : macSendUlCcchInd
353 * MAC sends UL CCCH Ind to DU APP
355 * @params[in] Post structure pointer
357 * @return ROK - success
360 * ****************************************************************/
361 uint8_t macSendUlCcchInd(uint8_t *rrcContainer, uint16_t cellId, uint16_t crnti)
365 UlCcchIndInfo *ulCcchIndInfo = NULLP;
367 MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
370 DU_LOG("\nMAC: Memory failed in macSendUlCcchInd");
374 ulCcchIndInfo->cellId = cellId;
375 ulCcchIndInfo->crnti = crnti;
376 ulCcchIndInfo->ulCcchMsg = rrcContainer;
379 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_UL_CCCH_IND);
381 if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
383 DU_LOG("\nMAC: Failed to send UL CCCH Ind to DU APP");
384 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg,
385 strlen((const char*)ulCcchIndInfo->ulCcchMsg));
386 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
392 /**********************************************************************
394 **********************************************************************/