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 "envopt.h" /* environment options */
21 #include "envdep.h" /* environment dependent */
22 #include "envind.h" /* environment independent */
23 #include "gen.h" /* general layer */
24 #include "ssi.h" /* system services */
25 #include "cm5.h" /* common timers defines */
26 #include "cm_hash.h" /* common hash list defines */
27 #include "cm_llist.h" /* common linked list defines */
28 #include "cm_mblk.h" /* memory management */
29 #include "cm_tkns.h" /* common tokens */
30 #include "cm_lte.h" /* common tokens */
33 #include "rg_sch_inf.h"
41 /* header/extern include files (.x) */
42 #include "gen.x" /* general layer typedefs */
43 #include "ssi.x" /* system services typedefs */
44 #include "cm5.x" /* common timers */
45 #include "cm_hash.x" /* common hash list */
46 #include "cm_lib.x" /* common library */
47 #include "cm_llist.x" /* common linked list */
48 #include "cm_mblk.x" /* memory management */
49 #include "cm_tkns.x" /* common tokens */
50 #include "cm_lte.x" /* common tokens */
53 #include "rg_sch_inf.x"
57 #include "du_app_mac_inf.h"
58 #include "mac_upr_inf_api.h"
60 #include "lwr_mac_fsm.h"
63 /* This file contains message handling functionality for MAC */
67 extern void sendToLowerMac(uint16_t msgType, uint32_t msgLen, void *msg);
69 /* Function pointer for sending crc ind from MAC to SCH */
70 MacSchCrcIndFunc macSchCrcIndOpts[]=
77 /* Function pointer for sending DL RLC BO Info from MAC to SCH */
78 MacSchDlRlcBoInfoFunc macSchDlRlcBoInfoOpts[]=
80 packMacSchDlRlcBoInfo,
85 /*******************************************************************
87 * @brief Sends DL BO Info to SCH
91 * Function : sendDlRlcBoInfoMacToSch
94 * Sends DL BO Info to SCH
97 * @return ROK - success
100 ****************************************************************/
101 int sendDlRlcBoInfoMacToSch(DlRlcBOInfo *dlBoInfo)
105 fillMacToSchPst(&pst);
106 pst.event = EVENT_DL_RLC_BO_INFO_TO_SCH;
108 return(*macSchDlRlcBoInfoOpts[pst.selector])(&pst, dlBoInfo);
111 /*******************************************************************
113 * @brief Sends CRC Indication to SCH
117 * Function : sendCrcIndMacToSch
120 * Sends CRC Indication to SCH
123 * @return ROK - success
126 ****************************************************************/
127 int sendCrcIndMacToSch(CrcIndInfo *crcInd)
131 fillMacToSchPst(&pst);
132 pst.event = EVENT_CRC_IND_TO_SCH;
134 return(*macSchCrcIndOpts[pst.selector])(&pst, crcInd);
137 /*******************************************************************
139 * @brief Processes CRC Indication from PHY
143 * Function : fapiMacCrcInd
146 * Processes CRC Indication from PHY
148 * @params[in] Post Structure Pointer
149 * Crc Indication Pointer
150 * @return ROK - success
153 * ****************************************************************/
154 uint16_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
156 CrcIndInfo crcIndInfo;
158 DU_LOG("\nMAC : Received CRC indication");
160 /* Considering one pdu and one preamble */
161 crcIndInfo.cellId = macCb.macCell->cellId;;
162 crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
163 crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
164 crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
165 crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
166 crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
168 return(sendCrcIndMacToSch(&crcIndInfo));
171 /*******************************************************************
173 * @brief Process Rx Data Ind at MAC
177 * Function : fapiMacRxDataInd
180 * Process Rx Data Ind at MAC
182 * @params[in] Post structure
184 * @return ROK - success
187 * ****************************************************************/
188 uint16_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
192 DU_LOG("\nMAC : Received Rx Data indication");
193 for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
195 unpackRxData(rxDataInd->timingInfo, &rxDataInd->pdus[pduIdx]);
200 /*******************************************************************
202 * @brief Processes DL data from RLC
206 * Function : MacRlcProcDlData
209 * Processes DL data from RLC
211 * @params[in] Post structure
213 * @return ROK - success
216 * ****************************************************************/
217 uint16_t MacRlcProcDlData(Pst* pst, SpId spId, RlcMacData *dlData)
222 /*******************************************************************
224 * @brief Processes BO status from RLC
228 * Function : MacRlcProcBOStatus
231 * Processes BO status from RLC
233 * @params[in] Post structure
235 * @return ROK - success
238 * ****************************************************************/
239 uint16_t MacRlcProcBOStatus(Pst* pst, SpId spId, RlcMacBOStatus* boStatus)
245 /*******************************************************************
247 * @brief Handles cell start reuqest from DU APP
251 * Function : MacHdlCellStartReq
254 * Handles cell start reuqest from DU APP
256 * @params[in] Post structure pointer
257 * Cell Start Request info pointer
258 * @return ROK - success
261 * ****************************************************************/
262 uint16_t MacHdlCellStartReq(Pst *pst, MacCellStartInfo *cellStartInfo)
264 DU_LOG("\nMAC : Handling cell start request");
265 sendToLowerMac(START_REQUEST, 0, cellStartInfo);
267 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStartInfo, \
268 sizeof(MacCellStartInfo));
273 /*******************************************************************
275 * @brief Handles cell stop request from DU APP
279 * Function : MacHdlCellStartReq
282 * Handles cell stop request from DU APP
284 * @params[in] Post structure pointer
285 * Mac Cell stop information
286 * @return ROK - success
289 * ****************************************************************/
290 uint16_t MacHdlCellStopReq(Pst *pst, MacCellStopInfo *cellStopInfo)
293 DU_LOG("\nMAC : Sending cell stop request to Lower Mac");
294 sendToLowerMac(FAPI_STOP_REQUEST, 0, cellStopInfo);
297 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStopInfo, \
298 sizeof(MacCellStopInfo));
303 /*******************************************************************
305 * @brief Handles DL CCCH Ind from DU APP
309 * Function : MacHdlDlCcchInd
312 * Handles DL CCCH Ind from DU APP
314 * @params[in] Post structure pointer
315 * DL CCCH Ind pointer
316 * @return ROK - success
319 * ****************************************************************/
320 uint16_t MacHdlDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
322 DlRlcBOInfo dlBoInfo;
324 DU_LOG("\nMAC : Handling DL CCCH IND");
326 /* TODO : Fill DL RLC Buffer status info */
327 dlBoInfo.cellId = dlCcchIndInfo->cellId;
328 dlBoInfo.crnti = dlCcchIndInfo->crnti;
331 if(dlCcchIndInfo->msgType == RRC_SETUP)
334 dlBoInfo.boInfo[dlBoInfo.numLc].lcId = 0; // SRB 0 for msg4
335 dlBoInfo.boInfo[dlBoInfo.numLc].dataVolume = \
336 strlen((const char*)dlCcchIndInfo->dlCcchMsg);
339 /* TODO: Store dlCcchMsg in raCb */
341 sendDlRlcBoInfoMacToSch(&dlBoInfo);
344 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
345 strlen((const char*)dlCcchIndInfo->dlCcchMsg));
346 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
351 /*******************************************************************
353 * @brief Sends UL CCCH Ind to DU APP
357 * Function : macSendUlCcchInd
360 * MAC sends UL CCCH Ind to DU APP
362 * @params[in] Post structure pointer
364 * @return ROK - success
367 * ****************************************************************/
368 uint16_t macSendUlCcchInd(uint8_t *rrcContainer, uint16_t cellId, uint16_t crnti)
372 UlCcchIndInfo *ulCcchIndInfo = NULLP;
374 MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
377 DU_LOG("\nMAC: Memory failed in macSendUlCcchInd");
381 ulCcchIndInfo->cellId = cellId;
382 ulCcchIndInfo->crnti = crnti;
383 ulCcchIndInfo->ulCcchMsg = rrcContainer;
386 pst.selector = DU_MAC_LWLC;
388 pst.dstEnt = ENTDUAPP;
390 pst.srcInst = macCb.macInst;
391 pst.dstProcId = rgCb[pst.srcInst].rgInit.procId;
392 pst.srcProcId = rgCb[pst.srcInst].rgInit.procId;
393 pst.region = MAC_MEM_REGION;
395 pst.event = EVENT_MAC_UL_CCCH_IND;
400 if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
402 DU_LOG("\nMAC: Failed to send UL CCCH Ind to DU APP");
403 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg,
404 strlen((const char*)ulCcchIndInfo->ulCcchMsg));
405 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
411 /**********************************************************************
413 **********************************************************************/