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"
23 #include "rg_sch_inf.h"
31 /* header/extern include files (.x) */
34 #include "rg_sch_inf.x"
38 #include "du_app_mac_inf.h"
39 #include "mac_upr_inf_api.h"
41 #include "lwr_mac_fsm.h"
44 /* This file contains message handling functionality for MAC */
48 extern void sendToLowerMac(uint16_t msgType, uint32_t msgLen, void *msg);
49 uint16_t buildMacPdu(RlcMacData *dlData);
51 /* Function pointer for sending crc ind from MAC to SCH */
52 MacSchCrcIndFunc macSchCrcIndOpts[]=
59 /* Function pointer for sending DL RLC BO Info from MAC to SCH */
60 MacSchDlRlcBoInfoFunc macSchDlRlcBoInfoOpts[]=
62 packMacSchDlRlcBoInfo,
67 /*******************************************************************
69 * @brief Sends DL BO Info to SCH
73 * Function : sendDlRlcBoInfoMacToSch
76 * Sends DL BO Info to SCH
79 * @return ROK - success
82 ****************************************************************/
83 int sendDlRlcBoInfoMacToSch(DlRlcBOInfo *dlBoInfo)
87 fillMacToSchPst(&pst);
88 pst.event = EVENT_DL_RLC_BO_INFO_TO_SCH;
90 return(*macSchDlRlcBoInfoOpts[pst.selector])(&pst, dlBoInfo);
93 /*******************************************************************
95 * @brief Sends CRC Indication to SCH
99 * Function : sendCrcIndMacToSch
102 * Sends CRC Indication to SCH
105 * @return ROK - success
108 ****************************************************************/
109 int sendCrcIndMacToSch(CrcIndInfo *crcInd)
113 fillMacToSchPst(&pst);
114 pst.event = EVENT_CRC_IND_TO_SCH;
116 return(*macSchCrcIndOpts[pst.selector])(&pst, crcInd);
119 /*******************************************************************
121 * @brief Processes CRC Indication from PHY
125 * Function : fapiMacCrcInd
128 * Processes CRC Indication from PHY
130 * @params[in] Post Structure Pointer
131 * Crc Indication Pointer
132 * @return ROK - success
135 * ****************************************************************/
136 uint16_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
138 CrcIndInfo crcIndInfo;
140 DU_LOG("\nMAC : Received CRC indication");
142 /* Considering one pdu and one preamble */
143 crcIndInfo.cellId = macCb.macCell->cellId;;
144 crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
145 crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
146 crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
147 crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
148 crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
150 return(sendCrcIndMacToSch(&crcIndInfo));
153 /*******************************************************************
155 * @brief Process Rx Data Ind at MAC
159 * Function : fapiMacRxDataInd
162 * Process Rx Data Ind at MAC
164 * @params[in] Post structure
166 * @return ROK - success
169 * ****************************************************************/
170 uint16_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
174 DU_LOG("\nMAC : Received Rx Data indication");
176 /* TODO : compare the handle received in RxDataInd with handle send in PUSCH
177 * PDU, which is stored in raCb */
179 for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
181 unpackRxData(&rxDataInd->pdus[pduIdx]);
186 /*******************************************************************
188 * @brief Processes DL data from RLC
192 * Function : MacRlcProcDlData
195 * Processes DL data from RLC
197 * @params[in] Post structure
199 * @return ROK - success
202 * ****************************************************************/
203 uint16_t MacRlcProcDlData(Pst* pst, SpId spId, RlcMacData *dlData)
208 /*******************************************************************
210 * @brief Processes BO status from RLC
214 * Function : MacRlcProcBOStatus
217 * Processes BO status from RLC
219 * @params[in] Post structure
221 * @return ROK - success
224 * ****************************************************************/
225 uint16_t MacRlcProcBOStatus(Pst* pst, SpId spId, RlcMacBOStatus* boStatus)
231 /*******************************************************************
233 * @brief Handles cell start reuqest from DU APP
237 * Function : MacHdlCellStartReq
240 * Handles cell start reuqest from DU APP
242 * @params[in] Post structure pointer
243 * Cell Start Request info pointer
244 * @return ROK - success
247 * ****************************************************************/
248 uint16_t MacHdlCellStartReq(Pst *pst, MacCellStartInfo *cellStartInfo)
250 DU_LOG("\nMAC : Handling cell start request");
251 sendToLowerMac(START_REQUEST, 0, cellStartInfo);
253 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStartInfo, \
254 sizeof(MacCellStartInfo));
259 /*******************************************************************
261 * @brief Handles cell stop request from DU APP
265 * Function : MacHdlCellStartReq
268 * Handles cell stop request from DU APP
270 * @params[in] Post structure pointer
271 * Mac Cell stop information
272 * @return ROK - success
275 * ****************************************************************/
276 uint16_t MacHdlCellStopReq(Pst *pst, MacCellStopInfo *cellStopInfo)
279 DU_LOG("\nMAC : Sending cell stop request to Lower Mac");
280 sendToLowerMac(FAPI_STOP_REQUEST, 0, cellStopInfo);
283 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStopInfo, \
284 sizeof(MacCellStopInfo));
289 /*******************************************************************
291 * @brief Handles DL CCCH Ind from DU APP
295 * Function : MacHdlDlCcchInd
298 * Handles DL CCCH Ind from DU APP
300 * @params[in] Post structure pointer
301 * DL CCCH Ind pointer
302 * @return ROK - success
305 * ****************************************************************/
306 uint16_t MacHdlDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
309 DlRlcBOInfo dlBoInfo;
310 memset(&dlBoInfo, 0, sizeof(DlRlcBOInfo));
312 DU_LOG("\nMAC : Handling DL CCCH IND");
314 /* TODO : Fill DL RLC Buffer status info */
315 dlBoInfo.cellId = dlCcchIndInfo->cellId;
316 dlBoInfo.crnti = dlCcchIndInfo->crnti;
319 if(dlCcchIndInfo->msgType == RRC_SETUP)
321 dlBoInfo.boInfo[dlBoInfo.numLc].lcId = SRB_ID_0; // SRB ID 0 for msg4
322 dlBoInfo.boInfo[SRB_ID_0].dataVolume = \
323 dlCcchIndInfo->dlCcchMsgLen;
326 /* storing Msg4 Pdu in raCb */
327 if(macCb.macCell->macRaCb[0].crnti == dlCcchIndInfo->crnti)
329 macCb.macCell->macRaCb[0].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
330 MAC_ALLOC(macCb.macCell->macRaCb[0].msg4Pdu, macCb.macCell->macRaCb[0]\
332 if(macCb.macCell->macRaCb[0].msg4Pdu)
334 for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
336 macCb.macCell->macRaCb[0].msg4Pdu[idx] =\
337 dlCcchIndInfo->dlCcchMsg[idx];
342 sendDlRlcBoInfoMacToSch(&dlBoInfo);
344 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
345 dlCcchIndInfo->dlCcchMsgLen);
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 = ODU_SELECTOR_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 * @brief Handles Ue Create Request from DU APP
417 * Function : MacHdlUeCreateReq
420 * Handles Ue create Request from DU APP
422 * @params[in] Post structure pointer
424 * @return ROK - success
427 * ****************************************************************/
428 uint8_t MacHdlUeCreateReq(Pst *pst, MacUeCfg *ueCfg)
430 /* TODO : Create MAC UE Context.
431 Copy Tx Pdu from raCb
433 Send MacUeContext to SCH */
434 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(MacUeCfg));
438 /**********************************************************************
440 **********************************************************************/