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 /* Function pointer for sending short BSR from MAC to SCH */
61 MacSchBsrFunc macSchBsrOpts[]=
68 /* Function pointer for sending SR Uci ind from MAC to SCH */
69 MacSchSrUciIndFunc macSchSrUciIndOpts[]=
76 /*******************************************************************
78 * @brief Sends DL BO Info to SCH
82 * Function : sendDlRlcBoInfoMacToSch
85 * Sends DL BO Info to SCH
88 * @return ROK - success
91 ****************************************************************/
92 uint8_t sendDlRlcBoInfoMacToSch(DlRlcBOInfo *dlBoInfo)
96 FILL_PST_MAC_TO_SCH(pst, EVENT_DL_RLC_BO_INFO_TO_SCH);
97 return(*macSchDlRlcBoInfoOpts[pst.selector])(&pst, dlBoInfo);
100 /*******************************************************************
102 * @brief Sends CRC Indication to SCH
106 * Function : sendCrcIndMacToSch
109 * Sends CRC Indication to SCH
112 * @return ROK - success
115 ****************************************************************/
116 uint8_t sendCrcIndMacToSch(CrcIndInfo *crcInd)
120 FILL_PST_MAC_TO_SCH(pst, EVENT_CRC_IND_TO_SCH);
121 return(*macSchCrcIndOpts[pst.selector])(&pst, crcInd);
124 /*******************************************************************
126 * @brief Processes CRC Indication from PHY
130 * Function : fapiMacCrcInd
133 * Processes CRC Indication from PHY
135 * @params[in] Post Structure Pointer
136 * Crc Indication Pointer
137 * @return ROK - success
140 * ****************************************************************/
141 uint8_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
144 CrcIndInfo crcIndInfo;
146 DU_LOG("\nMAC : Received CRC indication");
148 GET_CELL_IDX(crcInd->cellId, cellIdx);
149 /* Considering one pdu and one preamble */
150 crcIndInfo.cellId = macCb.macCell[cellIdx]->cellId;;
151 crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
152 crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
153 crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
154 crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
155 crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
157 return(sendCrcIndMacToSch(&crcIndInfo));
160 /*******************************************************************
162 * @brief Process Rx Data Ind at MAC
166 * Function : fapiMacRxDataInd
169 * Process Rx Data Ind at MAC
171 * @params[in] Post structure
173 * @return ROK - success
176 * ****************************************************************/
177 uint8_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
181 DU_LOG("\nMAC : Received Rx Data indication");
183 /* TODO : compare the handle received in RxDataInd with handle send in PUSCH
184 * PDU, which is stored in raCb */
186 for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
188 unpackRxData(rxDataInd->cellId, rxDataInd->timingInfo, &rxDataInd->pdus[pduIdx]);
193 /*******************************************************************
195 * @brief Processes DL data from RLC
199 * Function : MacRlcProcDlData
202 * Processes DL data from RLC
204 * @params[in] Post structure
206 * @return ROK - success
209 * ****************************************************************/
210 uint16_t MacRlcProcDlData(Pst* pst, SpId spId, RlcMacData *dlData)
215 /*******************************************************************
217 * @brief Builds and Sends UL Data to RLC
221 * Function : macProcUlData
223 * Functionality: Builds and Sends UL Data to RLC
228 * LC Id on which payload was received
229 * Pointer to the payload
231 * @return ROK - success
234 * ****************************************************************/
235 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotIndInfo slotInfo, \
236 uint8_t lcId, uint16_t pduLen, uint8_t *pdu)
241 /* Filling RLC Ul Data*/
242 MAC_ALLOC_SHRABL_BUF(ulData, sizeof(RlcMacData));
245 DU_LOG("\nMAC : Memory allocation failed while sending UL data to RLC");
248 memset(ulData, 0, sizeof(RlcMacData));
249 ulData->cellId = cellId;
251 memcpy(&ulData->slotInfo, &slotInfo, sizeof(SlotIndInfo));
252 ulData->slotInfo.cellId = cellId;
254 /* Filling pdu info */
255 if(lcId == SRB1_LCID || lcId == SRB2_LCID)
257 ulData->pduInfo[ulData->numPdu].commCh = true;
259 ulData->pduInfo[ulData->numPdu].lcId = lcId;
260 ulData->pduInfo[ulData->numPdu].pduBuf = pdu;
261 ulData->pduInfo[ulData->numPdu].pduLen = pduLen;
264 /* Filling Post and send to RLC */
265 memset(&pst, 0, sizeof(Pst));
266 FILL_PST_MAC_TO_RLC(pst, 0, EVTRLCULDAT);
267 MacSendUlDataToRlc(&pst, ulData);
273 /*******************************************************************
275 * @brief Processes BO status from RLC
279 * Function : MacRlcProcBOStatus
282 * Processes BO status from RLC
284 * @params[in] Post structure
286 * @return ROK - success
289 * ****************************************************************/
290 uint16_t MacRlcProcBOStatus(Pst* pst, SpId spId, RlcMacBOStatus* boStatus)
296 /*******************************************************************
298 * @brief Handles cell start reuqest from DU APP
302 * Function : MacProcCellStartReq
305 * Handles cell start reuqest from DU APP
307 * @params[in] Post structure pointer
308 * Cell Start Request info pointer
309 * @return ROK - success
312 * ****************************************************************/
313 uint8_t MacProcCellStartReq(Pst *pst, MacCellStartInfo *cellStartInfo)
315 DU_LOG("\nMAC : Handling cell start request");
316 sendToLowerMac(START_REQUEST, 0, cellStartInfo);
318 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStartInfo, \
319 sizeof(MacCellStartInfo));
324 /*******************************************************************
326 * @brief Handles cell stop request from DU APP
330 * Function : MacProcCellStartReq
333 * Handles cell stop request from DU APP
335 * @params[in] Post structure pointer
336 * Mac Cell stop information
337 * @return ROK - success
340 * ****************************************************************/
341 uint8_t MacProcCellStopReq(Pst *pst, MacCellStopInfo *cellStopInfo)
344 DU_LOG("\nMAC : Sending cell stop request to Lower Mac");
345 sendToLowerMac(FAPI_STOP_REQUEST, 0, cellStopInfo);
348 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStopInfo, \
349 sizeof(MacCellStopInfo));
354 /*******************************************************************
356 * @brief Handles DL CCCH Ind from DU APP
360 * Function : MacProcDlCcchInd
363 * Handles DL CCCH Ind from DU APP
365 * @params[in] Post structure pointer
366 * DL CCCH Ind pointer
367 * @return ROK - success
370 * ****************************************************************/
371 uint8_t MacProcDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
375 DlRlcBOInfo dlBoInfo;
376 memset(&dlBoInfo, 0, sizeof(DlRlcBOInfo));
378 DU_LOG("\nMAC : Handling DL CCCH IND");
380 GET_CELL_IDX(dlCcchIndInfo->cellId, cellIdx);
382 dlBoInfo.cellId = dlCcchIndInfo->cellId;
383 dlBoInfo.crnti = dlCcchIndInfo->crnti;
386 if(dlCcchIndInfo->msgType == RRC_SETUP)
388 dlBoInfo.boInfo[dlBoInfo.numLc].lcId = SRB_ID_0; // SRB ID 0 for msg4
389 dlBoInfo.boInfo[SRB_ID_0].dataVolume = \
390 dlCcchIndInfo->dlCcchMsgLen;
393 /* storing Msg4 Pdu in raCb */
394 if(macCb.macCell[cellIdx]->macRaCb[0].crnti == dlCcchIndInfo->crnti)
396 macCb.macCell[cellIdx]->macRaCb[0].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
397 MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[0].msg4Pdu, \
398 macCb.macCell[cellIdx]->macRaCb[0].msg4PduLen);
399 if(macCb.macCell[cellIdx]->macRaCb[0].msg4Pdu)
401 for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
403 macCb.macCell[cellIdx]->macRaCb[0].msg4Pdu[idx] =\
404 dlCcchIndInfo->dlCcchMsg[idx];
409 sendDlRlcBoInfoMacToSch(&dlBoInfo);
411 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
412 dlCcchIndInfo->dlCcchMsgLen);
413 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
418 /*******************************************************************
420 * @brief Sends UL CCCH Ind to DU APP
424 * Function : macProcUlCcchInd
427 * MAC sends UL CCCH Ind to DU APP
429 * @params[in] Post structure pointer
431 * @return ROK - success
434 * ****************************************************************/
435 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer)
439 UlCcchIndInfo *ulCcchIndInfo = NULLP;
441 MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
444 DU_LOG("\nMAC: Memory failed in macProcUlCcchInd");
448 ulCcchIndInfo->cellId = cellId;
449 ulCcchIndInfo->crnti = crnti;
450 ulCcchIndInfo->ulCcchMsgLen = rrcContSize;
451 ulCcchIndInfo->ulCcchMsg = rrcContainer;
454 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_UL_CCCH_IND);
456 if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
458 DU_LOG("\nMAC: Failed to send UL CCCH Ind to DU APP");
459 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
460 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
466 /*******************************************************************
468 * @brief Processes received short BSR
472 * Function : macProcShortBsr
475 * MAC sends Short BSR to SCH
477 * @params[in] cell ID
483 * ****************************************************************/
484 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize)
487 UlBufferStatusRptInd bsrInd;
489 memset(&pst, 0, sizeof(Pst));
490 memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
492 bsrInd.cellId = cellId;
493 bsrInd.crnti = crnti;
494 bsrInd.bsrType = SHORT_BSR;
495 bsrInd.numLcg = 1; /* short bsr reports one lcg at a time */
496 bsrInd.dataVolInfo[0].lcgId = lcgId;
497 bsrInd.dataVolInfo[0].dataVol = bufferSize;
499 FILL_PST_MAC_TO_SCH(pst, EVENT_SHORT_BSR);
500 return(*macSchBsrOpts[pst.selector])(&pst, &bsrInd);
503 /*******************************************************************
505 * @brief Builds and send SR UCI Indication to SCH
509 * Function : buildAndSendSrInd
512 * Builds and send SR UCI Indication to SCH
514 * @params[in] SrUciIndInfo Pointer
516 * @return ROK - success
519 * ****************************************************************/
520 uint8_t buildAndSendSrInd(UciInd *macUciInd, uint8_t crnti)
524 SrUciIndInfo srUciInd;
525 memset(&pst, 0, sizeof(Pst));
526 memset(&srUciInd, 0, sizeof(SrUciIndInfo));
528 GET_CELL_IDX(macUciInd->cellId, cellIdx);
529 srUciInd.cellId = macCb.macCell[cellIdx]->cellId;;
530 srUciInd.crnti = crnti;
531 srUciInd.slotInd.sfn = macUciInd->slotInd.sfn;
532 srUciInd.slotInd.slot = macUciInd->slotInd.slot;
533 srUciInd.numSrBits++;
534 memset(srUciInd.srPayload, 0, MAX_SR_BITS_IN_BYTES);
537 FILL_PST_MAC_TO_SCH(pst, EVENT_UCI_IND_TO_SCH);
539 return(*macSchSrUciIndOpts[pst.selector])(&pst, &srUciInd);
542 /*******************************************************************
544 * @brief Processes UCI Indication from PHY
548 * Function : fapiMacUciInd
551 * Processes UCI Indication from PHY
553 * @params[in] Post Structure Pointer
554 * UCI Indication Pointer
555 * @return ROK - success
558 * ****************************************************************/
559 uint8_t FapiMacUciInd(Pst *pst, UciInd *macUciInd)
568 nPdus = macUciInd->numUcis;
571 switch(macUciInd->pdus[pduIdx].pduType)
575 case UCI_IND_PUCCH_F0F1:
576 if(macUciInd->pdus[pduIdx].uci.uciPucchF0F1.srInfo.srIndPres)
578 DU_LOG("\nMAC : Received SR UCI indication");
579 crnti = macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti;
580 ret = buildAndSendSrInd(macUciInd, crnti);
583 case UCI_IND_PUCCH_F2F3F4:
586 DU_LOG("\nMAC: Invalid Pdu Type %d at FapiMacUciInd", macUciInd->pdus[pduIdx].pduType);
596 DU_LOG("\nMAC: Received Uci Ind is NULL at FapiMacUciInd()");
603 /**********************************************************************
605 **********************************************************************/