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 "du_app_mac_inf.h"
24 #include "mac_sch_interface.h"
25 #include "rlc_mac_inf.h"
26 #include "mac_upr_inf_api.h"
29 #include "fapi_interface.h"
31 #include "lwr_mac_fsm.h"
32 #include "lwr_mac_upr_inf.h"
34 #include "mac_utils.h"
35 #include "mac_harq_dl.h"
37 /* This file contains message handling functionality for MAC */
41 MacDuStatsIndFunc macDuStatsIndOpts[] =
43 packDuMacStatsInd, /* packing for loosely coupled */
44 DuProcMacStatsInd, /* packing for tightly coupled */
45 packDuMacStatsInd /* packing for light weight loosly coupled */
49 /*******************************************************************
51 * @brief Sends DL BO Info to SCH
55 * Function : sendDlRlcBoInfoToSch
58 * Sends DL BO Info to SCH
61 * @return ROK - success
64 ****************************************************************/
65 uint8_t sendDlRlcBoInfoToSch(DlRlcBoInfo *dlBoInfo)
69 FILL_PST_MAC_TO_SCH(pst, EVENT_DL_RLC_BO_INFO_TO_SCH);
70 return(SchMessageRouter(&pst, (void *)dlBoInfo));
73 /*******************************************************************
75 * @brief Sends CRC Indication to SCH
79 * Function : sendCrcIndMacToSch
82 * Sends CRC Indication to SCH
85 * @return ROK - success
88 ****************************************************************/
89 uint8_t sendCrcIndMacToSch(CrcIndInfo *crcInd)
93 FILL_PST_MAC_TO_SCH(pst, EVENT_CRC_IND_TO_SCH);
94 return(SchMessageRouter(&pst, (void *)crcInd));
97 /*******************************************************************
99 * @brief Sends UL CQI Indication to SCH
103 * Function : sendUlCqiIndMacToSch
106 * Sends Ul Cqi Indication to SCH
109 * @return ROK - success
112 ****************************************************************/
113 uint8_t sendUlCqiIndMacToSch(SchUlCqiInd *ulCqiInd)
117 FILL_PST_MAC_TO_SCH(pst, EVENT_UL_CQI_TO_SCH);
118 return(SchMessageRouter(&pst, (void *)ulCqiInd));
121 /*******************************************************************
123 * @brief Sends DL CQI Indication to SCH
127 * Function : sendDlCqiIndMacToSch
130 * Sends Dl Cqi Indication to SCH
133 * @return ROK - success
136 ****************************************************************/
137 uint8_t sendDlCqiIndMacToSch(SchDlCqiInd *dlCqiInd)
141 FILL_PST_MAC_TO_SCH(pst, EVENT_DL_CQI_TO_SCH);
142 return(SchMessageRouter(&pst, (void *)dlCqiInd));
145 /*******************************************************************
147 * @brief Sends Power Headroom Indication to SCH
151 * Function : sendPhrIndToSch
154 * Sends Phr Indication to SCH
157 * @return ROK - success
160 ****************************************************************/
161 uint8_t sendPhrIndToSch(SchPwrHeadroomInd *macPhrInd)
165 FILL_PST_MAC_TO_SCH(pst, EVENT_PHR_IND_TO_SCH);
166 return(SchMessageRouter(&pst, (void *)macPhrInd));
169 /*******************************************************************
171 * @brief Processes CRC Indication from PHY
175 * Function : fapiMacCrcInd
178 * Processes CRC Indication from PHY
180 * @params[in] Post Structure Pointer
181 * Crc Indication Pointer
182 * @return ROK - success
185 * ****************************************************************/
186 uint8_t fapiMacCrcInd(Pst *pst, CrcInd *crcInd)
189 CrcIndInfo crcIndInfo;
190 DU_LOG("\nDEBUG --> MAC : Received CRC indication");
191 GET_CELL_IDX(crcInd->cellId, cellIdx);
192 /* Considering one pdu and one preamble */
193 crcIndInfo.cellId = macCb.macCell[cellIdx]->cellId;
194 crcIndInfo.crnti = crcInd->crcInfo[0].rnti;
195 crcIndInfo.timingInfo.sfn = crcInd->timingInfo.sfn;
196 crcIndInfo.timingInfo.slot = crcInd->timingInfo.slot;
197 crcIndInfo.numCrcInd = crcInd->crcInfo[0].numCb;
198 crcIndInfo.crcInd[0] = crcInd->crcInfo[0].cbCrcStatus[0];
200 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, crcInd, sizeof(CrcInd));
201 return(sendCrcIndMacToSch(&crcIndInfo));
204 /*******************************************************************
206 * @brief Process Rx Data Ind at MAC
210 * Function : fapiMacRxDataInd
213 * Process Rx Data Ind at MAC
215 * @params[in] Post structure
217 * @return ROK - success
220 * ****************************************************************/
221 uint8_t fapiMacRxDataInd(Pst *pst, RxDataInd *rxDataInd)
224 uint16_t pduIdx, cellIdx = 0;
225 DU_LOG("\nDEBUG --> MAC : Received Rx Data indication");
226 /* TODO : compare the handle received in RxDataInd with handle send in PUSCH
227 * PDU, which is stored in raCb */
229 for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
232 GET_CELL_IDX(rxDataInd->cellId, cellIdx);
233 GET_UE_ID(rxDataInd->pdus[pduIdx].rnti, ueId);
235 if(macCb.macCell[cellIdx] && macCb.macCell[cellIdx]->ueCb[ueId -1].transmissionAction == STOP_TRANSMISSION)
237 DU_LOG("\nINFO --> MAC : UL data transmission not allowed for UE %d", macCb.macCell[cellIdx]->ueCb[ueId -1].ueId);
241 unpackRxData(rxDataInd->cellId, rxDataInd->timingInfo, &rxDataInd->pdus[pduIdx]);
243 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rxDataInd->pdus[pduIdx].pduData,\
244 rxDataInd->pdus[pduIdx].pduLength);
246 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, rxDataInd, sizeof(RxDataInd));
250 /*******************************************************************
252 * @brief Processes DL data from RLC
256 * Function : MacProcRlcDlData
259 * Processes DL data from RLC
261 * @params[in] Post structure
263 * @return ROK - success
266 * ****************************************************************/
267 uint8_t MacProcRlcDlData(Pst* pstInfo, RlcDlData *dlData)
272 uint8_t *txPdu = NULLP;
273 uint16_t cellIdx = 0, txPduLen = 0;
275 MacDlSlot *currDlSlot = NULLP;
276 DlRlcBoInfo dlBoInfo;
278 memset(&macDlData , 0, sizeof(MacDlData));
279 DU_LOG("\nDEBUG --> MAC: Received DL data for sfn=%d slot=%d numPdu= %d", \
280 dlData->slotInfo.sfn, dlData->slotInfo.slot, dlData->numPdu);
282 GET_UE_ID(dlData->rnti, ueId);
284 /* Copy the pdus to be muxed into mac Dl data */
285 macDlData.ueId = ueId;
286 macDlData.numPdu = dlData->numPdu;
287 for(pduIdx = 0; pduIdx < dlData->numPdu; pduIdx++)
289 macDlData.pduInfo[pduIdx].lcId = dlData->pduInfo[pduIdx].lcId;
290 macDlData.pduInfo[pduIdx].pduLen = dlData->pduInfo[pduIdx].pduLen;
291 macDlData.pduInfo[pduIdx].dlPdu = dlData->pduInfo[pduIdx].pduBuf;
294 GET_CELL_IDX(dlData->cellId, cellIdx);
295 /* Store DL data in the scheduled slot */
296 if(macCb.macCell[cellIdx] ==NULLP)
298 DU_LOG("\nERROR --> MAC : MacProcRlcDlData(): macCell does not exists");
301 currDlSlot = &macCb.macCell[cellIdx]->dlSlot[dlData->slotInfo.slot];
302 if(currDlSlot->dlInfo.dlMsgAlloc[ueId-1])
304 if(currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgPdschCfg)
306 txPduLen = currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgPdschCfg->codeword[0].tbSize\
307 - TX_PAYLOAD_HDR_LEN;
308 MAC_ALLOC(txPdu, txPduLen);
311 DU_LOG("\nERROR --> MAC : Memory allocation failed in MacProcRlcDlData");
314 macMuxPdu(&macDlData, NULLP, txPdu, txPduLen);
316 currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgPduLen = txPduLen;
317 currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgPdu = txPdu;
318 /* Add muxed TB to DL HARQ Proc CB. This will be used if retranmission of
319 * TB is requested in future. */
320 updateNewTbInDlHqProcCb(dlData->slotInfo, &macCb.macCell[cellIdx]->ueCb[ueId -1], \
321 currDlSlot->dlInfo.dlMsgAlloc[ueId-1]->dlMsgPdschCfg->codeword[0].tbSize, txPdu);
325 for(lcIdx = 0; lcIdx < dlData->numLc; lcIdx++)
327 if(dlData->boStatus[lcIdx].bo)
329 memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
330 dlBoInfo.cellId = dlData->boStatus[lcIdx].cellId;
331 GET_CRNTI(dlBoInfo.crnti, dlData->boStatus[lcIdx].ueId);
332 dlBoInfo.lcId = dlData->boStatus[lcIdx].lcId;
333 dlBoInfo.dataVolume = dlData->boStatus[lcIdx].bo;
334 sendDlRlcBoInfoToSch(&dlBoInfo);
339 for(pduIdx = 0; pduIdx < dlData->numPdu; pduIdx++)
341 MAC_FREE_SHRABL_BUF(pstInfo->region, pstInfo->pool, dlData->pduInfo[pduIdx].pduBuf,\
342 dlData->pduInfo[pduIdx].pduLen);
344 if(pstInfo->selector == ODU_SELECTOR_LWLC)
346 MAC_FREE_SHRABL_BUF(pstInfo->region, pstInfo->pool, dlData, sizeof(RlcDlData));
351 /*******************************************************************
353 * @brief Builds and Sends UL Data to RLC
357 * Function : macProcUlData
359 * Functionality: Builds and Sends UL Data to RLC
364 * LC Id on which payload was received
365 * Pointer to the payload
367 * @return ROK - success
370 * ****************************************************************/
371 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotTimingInfo slotInfo, \
372 uint8_t lcId, uint16_t pduLen, uint8_t *pdu)
377 /* Filling RLC Ul Data*/
378 MAC_ALLOC_SHRABL_BUF(ulData, sizeof(RlcUlData));
381 DU_LOG("\nERROR --> MAC : Memory allocation failed while sending UL data to RLC");
384 memset(ulData, 0, sizeof(RlcUlData));
385 ulData->cellId = cellId;
387 memcpy(&ulData->slotInfo, &slotInfo, sizeof(SlotTimingInfo));
388 ulData->slotInfo.cellId = cellId;
390 /* Filling pdu info */
391 ulData->pduInfo[ulData->numPdu].lcId = lcId;
392 ulData->pduInfo[ulData->numPdu].pduBuf = pdu;
393 ulData->pduInfo[ulData->numPdu].pduLen = pduLen;
396 /* Filling Post and send to RLC */
397 memset(&pst, 0, sizeof(Pst));
398 FILL_PST_MAC_TO_RLC(pst, 0, EVENT_UL_DATA_TO_RLC);
399 MacSendUlDataToRlc(&pst, ulData);
405 /*******************************************************************
407 * @brief Processes BO status from RLC
411 * Function : MacProcRlcBOStatus
414 * Processes BO status from RLC
416 * @params[in] Post structure
418 * @return ROK - success
421 * ****************************************************************/
422 uint8_t MacProcRlcBoStatus(Pst* pst, RlcBoStatus* boStatus)
424 DlRlcBoInfo dlBoInfo;
426 dlBoInfo.cellId = boStatus->cellId;
427 GET_CRNTI(dlBoInfo.crnti, boStatus->ueId);
428 dlBoInfo.lcId = boStatus->lcId;
429 dlBoInfo.dataVolume = boStatus->bo;
431 sendDlRlcBoInfoToSch(&dlBoInfo);
433 if(pst->selector == ODU_SELECTOR_LWLC)
435 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, boStatus, sizeof(RlcBoStatus));
441 /*******************************************************************
443 * @brief Send LC schedule result report to RLC
447 * Function : sendSchRptToRlc
449 * Functionality: Send LC schedule result report to RLC
452 * @return ROK - success
455 * ****************************************************************/
456 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotTimingInfo slotInfo, uint8_t ueIdx, uint8_t schInfoIdx)
460 RlcSchedResultRpt *schedRpt = NULLP;
462 MAC_ALLOC_SHRABL_BUF(schedRpt, sizeof(RlcSchedResultRpt));
465 DU_LOG("\nERROR --> MAC: Memory allocation failure in sendSchResultRepToRlc");
469 DU_LOG("\nDEBUG --> MAC: Send scheduled result report for sfn %d slot %d", slotInfo.sfn, slotInfo.slot);
470 schedRpt->cellId = dlInfo.cellId;
471 schedRpt->slotInfo.sfn = slotInfo.sfn;
472 schedRpt->slotInfo.slot = slotInfo.slot;
474 if(dlInfo.dlMsgAlloc[ueIdx])
476 schedRpt->rnti = dlInfo.dlMsgAlloc[ueIdx]->crnti;
477 schedRpt->numLc = dlInfo.dlMsgAlloc[ueIdx]->transportBlock[0].numLc;
478 for(lcIdx = 0; lcIdx < schedRpt->numLc; lcIdx++)
480 schedRpt->lcSch[lcIdx].lcId = dlInfo.dlMsgAlloc[ueIdx]->transportBlock[0].lcSchInfo[lcIdx].lcId;
481 schedRpt->lcSch[lcIdx].bufSize = dlInfo.dlMsgAlloc[ueIdx]->transportBlock[0].lcSchInfo[lcIdx].schBytes;
486 FILL_PST_MAC_TO_RLC(pst, RLC_DL_INST, EVENT_SCHED_RESULT_TO_RLC);
487 if(MacSendSchedResultRptToRlc(&pst, schedRpt) != ROK)
489 DU_LOG("\nERROR --> MAC: Failed to send Schedule result report to RLC");
490 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, schedRpt, sizeof(RlcSchedResultRpt));
497 /*******************************************************************
499 * @brief Handles cell start reuqest from DU APP
503 * Function : MacProcCellStart
506 * Handles cell start reuqest from DU APP
508 * @params[in] Post structure pointer
510 * @return ROK - success
513 * ****************************************************************/
514 uint8_t MacProcCellStart(Pst *pst, CellStartInfo *cellStart)
516 DU_LOG("\nINFO --> MAC : Handling cell start request");
517 gConfigInfo.gSlotCount = 0;
518 sendToLowerMac(START_REQUEST, 0, cellStart);
520 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStart, \
521 sizeof(CellStartInfo));
526 /*******************************************************************
528 * @brief Handles cell stop from DU APP
532 * Function : MacProcCellStop
535 * Handles cell stop from DU APP
537 * @params[in] Post structure pointer
539 * @return ROK - success
542 * ****************************************************************/
543 uint8_t MacProcCellStop(Pst *pst, CellStopInfo *cellStop)
548 DU_LOG("\nINFO --> MAC : Sending cell stop request to Lower Mac");
549 GET_CELL_IDX(cellStop->cellId, cellIdx);
550 if(macCb.macCell[cellIdx])
552 macCb.macCell[cellIdx]->state = CELL_TO_BE_STOPPED;
556 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellStop, \
557 sizeof(CellStopInfo));
562 /*******************************************************************
564 * @brief Handles DL CCCH Ind from DU APP
568 * Function : MacProcDlCcchInd
571 * Handles DL CCCH Ind from DU APP
573 * @params[in] Post structure pointer
574 * DL CCCH Ind pointer
575 * @return ROK - success
578 * ****************************************************************/
579 uint8_t MacProcDlCcchInd(Pst *pst, DlCcchIndInfo *dlCcchIndInfo)
581 uint8_t ueId = 0, ueIdx = 0;
584 DlRlcBoInfo dlBoInfo;
585 memset(&dlBoInfo, 0, sizeof(DlRlcBoInfo));
587 DU_LOG("\nDEBUG --> MAC : Handling DL CCCH IND");
589 GET_CELL_IDX(dlCcchIndInfo->cellId, cellIdx);
591 dlBoInfo.cellId = dlCcchIndInfo->cellId;
592 dlBoInfo.crnti = dlCcchIndInfo->crnti;
594 if(dlCcchIndInfo->msgType == RRC_SETUP)
596 dlBoInfo.lcId = SRB0_LCID; // SRB ID 0 for msg4
597 /* (MSG4 pdu + 3 bytes sub-header) + (Contention resolution id MAC CE + 1 byte sub-header) */
598 dlBoInfo.dataVolume = (dlCcchIndInfo->dlCcchMsgLen + 3) + (MAX_CRI_SIZE + 1);
600 /* storing Msg4 Pdu in raCb */
601 GET_UE_ID(dlBoInfo.crnti, ueId);
603 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == dlCcchIndInfo->crnti)
605 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen = dlCcchIndInfo->dlCcchMsgLen;
606 MAC_ALLOC(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
607 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
608 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu)
610 for(idx = 0; idx < dlCcchIndInfo->dlCcchMsgLen; idx++)
612 macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu[idx] =\
613 dlCcchIndInfo->dlCcchMsg[idx];
618 sendDlRlcBoInfoToSch(&dlBoInfo);
620 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo->dlCcchMsg, \
621 dlCcchIndInfo->dlCcchMsgLen);
622 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlCcchIndInfo, sizeof(DlCcchIndInfo));
627 /*******************************************************************
629 * @brief Sends UL CCCH Ind to DU APP
633 * Function : macProcUlCcchInd
636 * MAC sends UL CCCH Ind to DU APP
638 * @params[in] Post structure pointer
640 * @return ROK - success
643 * ****************************************************************/
644 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer)
648 UlCcchIndInfo *ulCcchIndInfo = NULLP;
650 MAC_ALLOC_SHRABL_BUF(ulCcchIndInfo, sizeof(UlCcchIndInfo));
653 DU_LOG("\nERROR --> MAC: Memory failed in macProcUlCcchInd");
657 ulCcchIndInfo->cellId = cellId;
658 ulCcchIndInfo->crnti = crnti;
659 ulCcchIndInfo->ulCcchMsgLen = rrcContSize;
660 ulCcchIndInfo->ulCcchMsg = rrcContainer;
663 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_UL_CCCH_IND);
665 if(MacDuAppUlCcchInd(&pst, ulCcchIndInfo) != ROK)
667 DU_LOG("\nERROR --> MAC: Failed to send UL CCCH Ind to DU APP");
668 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
669 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
675 /*******************************************************************
677 * @brief Processes received short BSR
681 * Function : macProcShortBsr
684 * MAC sends Short BSR to SCH
686 * @params[in] cell ID
691 * @return ROK - success
694 * ****************************************************************/
695 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize)
698 UlBufferStatusRptInd bsrInd;
700 memset(&pst, 0, sizeof(Pst));
701 memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
703 bsrInd.cellId = cellId;
704 bsrInd.crnti = crnti;
705 bsrInd.bsrType = SHORT_BSR;
706 bsrInd.numLcg = 1; /* short bsr reports one lcg at a time */
707 bsrInd.dataVolInfo[0].lcgId = lcgId;
708 bsrInd.dataVolInfo[0].dataVol = bufferSize;
710 FILL_PST_MAC_TO_SCH(pst, EVENT_SHORT_BSR);
711 return(SchMessageRouter(&pst, (void *)&bsrInd));
714 /*******************************************************************
716 * @brief Processes received short BSR
720 * Function : macProcShortBsr
723 * MAC sends Short BSR to SCH
725 * @params[in] cell ID
730 * @return ROK - success
733 * ****************************************************************/
734 uint8_t macProcLongBsr(uint16_t cellId, uint16_t crnti,uint8_t numLcg,\
735 DataVolInfo dataVolInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
738 UlBufferStatusRptInd bsrInd;
741 memset(&pst, 0, sizeof(Pst));
742 memset(&bsrInd, 0, sizeof(UlBufferStatusRptInd));
744 bsrInd.cellId = cellId;
745 bsrInd.crnti = crnti;
746 bsrInd.bsrType = LONG_BSR;
747 bsrInd.numLcg = numLcg;
749 for(lcgIdx = 0; lcgIdx < numLcg; lcgIdx++)
750 memcpy(&(bsrInd.dataVolInfo[lcgIdx]), &(dataVolInfo[lcgIdx]), sizeof(DataVolInfo));
752 FILL_PST_MAC_TO_SCH(pst, EVENT_LONG_BSR);
753 return(SchMessageRouter(&pst, (void *)&bsrInd));
756 /*******************************************************************
758 * @brief Builds and send DL HARQ Indication to SCH
762 * Function : buildAndSendHarqInd
765 * Builds and send HARQ UCI Indication to SCH
767 * @params[in] harqInfo Pointer
771 * @return ROK - success
774 * ****************************************************************/
775 uint8_t buildAndSendHarqInd(HarqInfoF0F1 *harqInfo, uint16_t crnti, uint16_t cellIdx, SlotTimingInfo *slotInd)
777 uint16_t harqCounter=0;
780 memset(&pst, 0, sizeof(Pst));
781 memset(&dlHarqInd, 0, sizeof(DlHarqInd));
783 dlHarqInd.cellId = macCb.macCell[cellIdx]->cellId;
784 dlHarqInd.crnti = crnti;
785 dlHarqInd.slotInd.sfn = slotInd->sfn;
786 dlHarqInd.slotInd.slot = slotInd->slot;
787 dlHarqInd.numHarq = harqInfo->numHarq;
788 memset(dlHarqInd.harqPayload, 0, MAX_SR_BITS_IN_BYTES);
789 for(harqCounter = 0; harqCounter < harqInfo->numHarq; harqCounter++)
791 dlHarqInd.harqPayload[harqCounter] = harqInfo->harqValue[harqCounter];
795 FILL_PST_MAC_TO_SCH(pst, EVENT_DL_HARQ_IND_TO_SCH);
797 return SchMessageRouter(&pst, (void *)&dlHarqInd);
801 /*******************************************************************
803 * @brief Builds and send SR UCI Indication to SCH
807 * Function : buildAndSendSrInd
810 * Builds and send SR UCI Indication to SCH
812 * @params[in] SrUciIndInfo Pointer
814 * @return ROK - success
817 * ****************************************************************/
818 uint8_t buildAndSendSrInd(UciInd *macUciInd, uint16_t crnti)
822 SrUciIndInfo srUciInd;
823 memset(&pst, 0, sizeof(Pst));
824 memset(&srUciInd, 0, sizeof(SrUciIndInfo));
826 GET_CELL_IDX(macUciInd->cellId, cellIdx);
827 srUciInd.cellId = macCb.macCell[cellIdx]->cellId;
828 srUciInd.crnti = crnti;
829 srUciInd.slotInd.sfn = macUciInd->slotInd.sfn;
830 srUciInd.slotInd.slot = macUciInd->slotInd.slot;
831 srUciInd.numSrBits++;
832 memset(srUciInd.srPayload, 0, MAX_SR_BITS_IN_BYTES);
835 FILL_PST_MAC_TO_SCH(pst, EVENT_UCI_IND_TO_SCH);
837 return(SchMessageRouter(&pst, (void *)&srUciInd));
840 /*******************************************************************
842 * @brief Processes UCI Indication from PHY
846 * Function : fapiMacUciInd
849 * Processes UCI Indication from PHY
851 * @params[in] Post Structure Pointer
852 * UCI Indication Pointer
853 * @return ROK - success
856 * ****************************************************************/
857 uint8_t FapiMacUciInd(Pst *pst, UciInd *macUciInd)
859 uint8_t pduIdx = 0, ret = ROK;
860 uint16_t nPdus = 0, crnti = 0, cellIdx = 0;
864 nPdus = macUciInd->numUcis;
867 switch(macUciInd->pdus[pduIdx].pduType)
871 case UCI_IND_PUCCH_F0F1:
874 DU_LOG("\nDEBUG --> MAC : Received HARQ UCI Indication\n");
875 GET_CELL_IDX(macUciInd->cellId, cellIdx);
876 buildAndSendHarqInd(&macUciInd->pdus[pduIdx].uci.uciPucchF0F1.harqInfo, macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti, cellIdx, &macUciInd->slotInd);
878 if(macUciInd->pdus[pduIdx].uci.uciPucchF0F1.srInfo.srIndPres)
880 DU_LOG("\nDEBUG --> MAC : Received SR UCI indication");
881 crnti = macUciInd->pdus[pduIdx].uci.uciPucchF0F1.crnti;
882 ret = buildAndSendSrInd(macUciInd, crnti);
886 case UCI_IND_PUCCH_F2F3F4:
889 DU_LOG("\nERROR --> MAC: Invalid Pdu Type %d at FapiMacUciInd", macUciInd->pdus[pduIdx].pduType);
899 DU_LOG("\nERROR --> MAC: Received Uci Ind is NULL at FapiMacUciInd()");
902 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macUciInd, sizeof(UciInd));
906 /*******************************************************************
908 * @brief fill Slice Cfg Request info in shared structre
912 * Function : fillSliceCfgInfo
915 * fill Slice Cfg Request info in shared structre
917 * @params[in] SchSliceCfgReq *schSliceCfgReq
918 * MacSliceCfgReq *macSliceCfgReq;
919 * @return ROK - success
922 **********************************************************************/
923 uint8_t fillSliceCfgInfo(SchSliceCfgReq *schSliceCfgReq, MacSliceCfgReq *macSliceCfgReq)
925 uint8_t rrmPolicyIdx= 0,cfgIdx = 0, memberListIdx = 0, totalSliceCfgRecvd = 0;
927 if(macSliceCfgReq->listOfRrmPolicy)
929 for(cfgIdx = 0; cfgIdx<macSliceCfgReq->numOfRrmPolicy; cfgIdx++)
931 totalSliceCfgRecvd += macSliceCfgReq->listOfRrmPolicy[cfgIdx]->numOfRrmPolicyMem;
934 schSliceCfgReq->numOfConfiguredSlice = totalSliceCfgRecvd;
935 MAC_ALLOC(schSliceCfgReq->listOfSlices, schSliceCfgReq->numOfConfiguredSlice *sizeof(SchRrmPolicyOfSlice*));
936 if(schSliceCfgReq->listOfSlices == NULLP)
938 DU_LOG("\nERROR --> MAC : Memory allocation failed in fillSliceCfgInfo");
943 for(rrmPolicyIdx = 0; rrmPolicyIdx<macSliceCfgReq->numOfRrmPolicy; rrmPolicyIdx++)
945 for(memberListIdx = 0; memberListIdx<macSliceCfgReq->listOfRrmPolicy[rrmPolicyIdx]->numOfRrmPolicyMem; memberListIdx++)
947 if(macSliceCfgReq->listOfRrmPolicy[rrmPolicyIdx]->rRMPolicyMemberList[memberListIdx])
950 MAC_ALLOC(schSliceCfgReq->listOfSlices[cfgIdx], sizeof(SchRrmPolicyOfSlice));
951 if(schSliceCfgReq->listOfSlices[cfgIdx] == NULLP)
953 DU_LOG("\nERROR --> MAC : Memory allocation failed in fillSliceCfgInfo");
957 memcpy(&schSliceCfgReq->listOfSlices[cfgIdx]->snssai, &macSliceCfgReq->listOfRrmPolicy[rrmPolicyIdx]->rRMPolicyMemberList[memberListIdx]->snssai, sizeof(Snssai));
959 schSliceCfgReq->listOfSlices[cfgIdx]->rrmPolicyRatioInfo.maxRatio = macSliceCfgReq->listOfRrmPolicy[rrmPolicyIdx]->policyRatio.maxRatio;
960 schSliceCfgReq->listOfSlices[cfgIdx]->rrmPolicyRatioInfo.minRatio = macSliceCfgReq->listOfRrmPolicy[rrmPolicyIdx]->policyRatio.minRatio;
961 schSliceCfgReq->listOfSlices[cfgIdx]->rrmPolicyRatioInfo.dedicatedRatio = macSliceCfgReq->listOfRrmPolicy[rrmPolicyIdx]->policyRatio.dedicatedRatio;
970 /*******************************************************************
972 * @brief Processes Slice Cfg Request recived from DU
976 * Function : MacProcSliceCfgReq
979 * Processes Processes Slice Cfg Request recived from DU
981 * @params[in] Post Structure Pointer
982 * MacSliceCfgReq *macSliceCfgReq;
983 * @return ROK - success
986 **********************************************************************/
987 uint8_t MacProcSliceCfgReq(Pst *pst, MacSliceCfgReq *macSliceCfgReq)
991 SchSliceCfgReq *schSliceCfgReq;
993 DU_LOG("\nINFO --> MAC : Received Slice Cfg request from DU APP");
996 MAC_ALLOC(schSliceCfgReq, sizeof(SchSliceCfgReq));
997 if(schSliceCfgReq == NULLP)
999 DU_LOG("\nERROR --> MAC : Memory allocation failed in MacProcSliceCfgReq");
1004 if(fillSliceCfgInfo(schSliceCfgReq, macSliceCfgReq) == ROK)
1006 FILL_PST_MAC_TO_SCH(schPst, EVENT_SLICE_CFG_REQ_TO_SCH);
1007 ret = SchMessageRouter(&schPst, (void *)schSliceCfgReq);
1010 freeMacSliceCfgReq(macSliceCfgReq, pst);
1014 DU_LOG("\nINFO --> MAC : Received MacSliceCfgReq is NULL");
1019 /*******************************************************************
1021 * @brief Processes Slice ReCfg Request recived from DU
1025 * Function : MacProcSliceRecfgReq
1028 * Processes Processes Slice ReCfg Request recived from DU
1030 * @params[in] Post Structure Pointer
1031 * MacSliceCfgReq *macSliceRecfgReq;
1032 * @return ROK - success
1035 **********************************************************************/
1036 uint8_t MacProcSliceRecfgReq(Pst *pst, MacSliceRecfgReq *macSliceRecfgReq)
1040 SchSliceRecfgReq *schSliceRecfgReq;
1042 DU_LOG("\nINFO --> MAC : Received Slice ReCfg request from DU APP");
1043 if(macSliceRecfgReq)
1045 MAC_ALLOC(schSliceRecfgReq, sizeof(SchSliceRecfgReq));
1046 if(schSliceRecfgReq == NULLP)
1048 DU_LOG("\nERROR --> MAC : Memory allocation failed in MacProcSliceRecfgReq");
1053 if(fillSliceCfgInfo(schSliceRecfgReq, macSliceRecfgReq) == ROK)
1055 FILL_PST_MAC_TO_SCH(schPst, EVENT_SLICE_RECFG_REQ_TO_SCH);
1056 ret = SchMessageRouter(&schPst, (void *)schSliceRecfgReq);
1059 freeMacSliceCfgReq(macSliceRecfgReq, pst);
1063 DU_LOG("\nINFO --> MAC : Received MacSliceRecfgReq is NULL");
1069 * @brief Mac process the statistics indication received from sch.
1073 * Function : MacProcSchStatsInd
1075 * This function process the statistics indication received from sch
1077 * @param[in] Pst *pst
1078 * @param[in] SchStatsInd *schStatsInd
1082 uint8_t MacProcSchStatsInd(Pst *pst, SchStatsInd *schStatsInd)
1084 uint8_t statsIdx = 0;
1086 MacStatsInd *macStatsInd;
1089 DU_LOG("\nDEBUG --> MAC : MacProcSchStatsInd: Received Statistics Indication from SCH");
1092 if(schStatsInd == NULLP)
1094 DU_LOG("\nERROR --> MAC : MacProcSchStatsInd: NULL pointer :schStatsInd");
1098 MAC_ALLOC_SHRABL_BUF(macStatsInd, sizeof(MacStatsInd));
1099 if(macStatsInd == NULLP)
1101 DU_LOG("\nERROR --> MAC : Failed to allocate memory in MacProcSchStatsInd");
1105 macStatsInd->subscriptionId = schStatsInd->subscriptionId;
1106 macStatsInd->groupId = schStatsInd->groupId;
1108 for(statsIdx = 0; statsIdx < schStatsInd->numStats; statsIdx++)
1110 switch(schStatsInd->measuredStatsList[statsIdx].type)
1112 case SCH_DL_TOTAL_PRB_USAGE:
1114 macStatsInd->measuredStatsList[statsIdx].type = MAC_DL_TOTAL_PRB_USAGE;
1117 case SCH_UL_TOTAL_PRB_USAGE:
1119 macStatsInd->measuredStatsList[statsIdx].type = MAC_UL_TOTAL_PRB_USAGE;
1124 DU_LOG("\nERROR --> MAC : MacProcSchStatsInd: Invalid measurement type [%d]", \
1125 schStatsInd->measuredStatsList[statsIdx].type);
1126 MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, macStatsInd, sizeof(MacStatsInd));
1130 macStatsInd->measuredStatsList[statsIdx].value = schStatsInd->measuredStatsList[statsIdx].value;
1132 macStatsInd->numStats = schStatsInd->numStats;
1134 memset(&indPst, 0, sizeof(Pst));
1135 FILL_PST_MAC_TO_DUAPP(indPst, EVENT_MAC_STATISTICS_IND);
1136 return (*macDuStatsIndOpts[indPst.selector])(&indPst, macStatsInd);
1139 /**********************************************************************
1141 **********************************************************************/