+ uint8_t ret = ROK;
+ uint8_t ssb_rep, ueIdx, lcgIdx;
+ uint16_t slot, sfnSlot = 0;
+ DlSchedInfo dlSchedInfo;
+ DlBrdcstAlloc *dlBrdcstAlloc = NULLP;
+ RarAlloc *rarAlloc = NULLP;
+ DlMsgAlloc *msg4Alloc = NULLP;
+ DlMsgAlloc *dlMsgAlloc = NULLP;
+ SchCellCb *cell = NULLP;
+
+ memset(&dlSchedInfo,0,sizeof(DlSchedInfo));
+ schCalcSlotValues(*slotInd, &dlSchedInfo.schSlotValue);
+ dlBrdcstAlloc = &dlSchedInfo.brdcstAlloc;
+ dlBrdcstAlloc->ssbTrans = NO_SSB;
+ dlBrdcstAlloc->sib1Trans = NO_SIB1;
+
+ cell = schCb[schInst].cells[schInst];
+ ssb_rep = cell->cellCfg.ssbSchCfg.ssbPeriod;
+ memcpy(&cell->slotInfo, slotInd, sizeof(SlotIndInfo));
+ dlBrdcstAlloc->ssbIdxSupported = 1;
+
+ sfnSlot = ((dlSchedInfo.schSlotValue.broadcastTime.sfn * 10) +
+ dlSchedInfo.schSlotValue.broadcastTime.slot);
+
+ slot = dlSchedInfo.schSlotValue.currentTime.slot;
+
+ dlSchedInfo.cellId = cell->cellId;
+
+ /* Identify SSB ocassion*/
+ if (sfnSlot % SCH_MIB_TRANS == 0)
+ {
+ dlBrdcstAlloc->ssbTrans = SSB_TRANSMISSION;
+ }
+ else if (sfnSlot % ssb_rep == 0)
+ {
+ dlBrdcstAlloc->ssbTrans = SSB_REPEAT;
+ }
+ else
+ {
+ /* not SSB occassion */
+ }
+
+ /* Identify SIB1 occasions */
+ if(sfnSlot % cell->cellCfg.sib1SchCfg.sib1NewTxPeriod == 0)
+ {
+ dlBrdcstAlloc->sib1Trans = SIB1_TRANSMISSION;
+ }
+ else if (sfnSlot % cell->cellCfg.sib1SchCfg.sib1RepetitionPeriod == 0)
+ {
+ dlBrdcstAlloc->sib1Trans = SIB1_REPITITION;
+ }
+ else
+ {
+ /* not SIB1 occassion */
+ }
+
+ if(dlBrdcstAlloc->ssbTrans || dlBrdcstAlloc->sib1Trans)
+ {
+ dlSchedInfo.isBroadcastPres = true;
+ slot = dlSchedInfo.schSlotValue.broadcastTime.slot;
+ ret = schBroadcastAlloc(cell,dlBrdcstAlloc,slot);
+ if(ret != ROK)
+ {
+ DU_LOG("\nschBroadcastAlloc failed");
+ return (ret);
+ }
+ }
+
+ /* check for RAR */
+ if(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.rarTime.slot]->rarInfo != NULLP)
+ {
+ slot = dlSchedInfo.schSlotValue.rarTime.slot;
+ SCH_ALLOC(rarAlloc, sizeof(RarAlloc));
+ if(!rarAlloc)
+ {
+ DU_LOG("\nMAC: Memory Allocation failed for RAR alloc");
+ return RFAILED;
+ }
+
+ dlSchedInfo.rarAlloc = rarAlloc;
+
+ /* RAR info is copied, this was earlier filled in schProcessRachInd */
+ memcpy(&rarAlloc->rarInfo,cell->schDlSlotInfo[slot]->rarInfo, sizeof(RarInfo));
+
+ /* pdcch and pdsch data is filled */
+ schFillRar(rarAlloc,
+ cell->schDlSlotInfo[slot]->rarInfo->raRnti,
+ cell->cellCfg.phyCellId,
+ cell->cellCfg.ssbSchCfg.ssbOffsetPointA);
+
+ SCH_FREE(cell->schDlSlotInfo[slot]->rarInfo,sizeof(RarAlloc));
+ cell->schDlSlotInfo[slot]->rarInfo = NULLP;
+ }
+
+ /* check for MSG4 */
+ if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
+ (cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
+ {
+ slot = dlSchedInfo.schSlotValue.dlMsgTime.slot;
+
+ SCH_ALLOC(msg4Alloc, sizeof(DlMsgAlloc));
+ if(!msg4Alloc)
+ {
+ DU_LOG("\nMAC: Memory Allocation failed for msg4 alloc");
+ return RFAILED;
+ }
+
+ dlSchedInfo.dlMsgAlloc = msg4Alloc;
+
+ /* Msg4 info is copied, this was earlier filled in macSchDlRlcBoInfo */
+ memcpy(&msg4Alloc->dlMsgInfo, cell->schDlSlotInfo[slot]->dlMsgInfo, \
+ sizeof(DlMsgInfo));
+
+ /* pdcch and pdsch data is filled */
+ schDlRsrcAllocMsg4(msg4Alloc, cell, dlSchedInfo.schSlotValue.dlMsgTime.slot);
+
+ /* PUCCH resource */
+ schAllocPucchResource(cell, msg4Alloc->dlMsgInfo.crnti, dlSchedInfo.schSlotValue.dlMsgTime.slot);
+
+ SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
+ cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo = NULL;
+ }
+ /* check if UL grant must be sent in this slot for a SR/BSR that had been received */
+ for(ueIdx=0; ueIdx<cell->numActvUe; ueIdx++)
+ {
+ uint32_t totDataReq = 0; /* in bytes */
+ DciInfo *dciInfo = NULLP;
+ SchUeCb *ueCb = NULLP;
+
+ ueCb = &cell->ueCb[ueIdx];
+ /* check for SR */
+ if(ueCb->srRcvd)
+ {
+ totDataReq = UL_GRANT_SIZE; /*fixing so that all control msgs can be handled in SR */
+ ueCb->srRcvd = false;
+ }
+ /* check for BSR */
+ for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
+ {
+ totDataReq+= ueCb->bsrInfo[lcgIdx].dataVol;
+ ueCb->bsrInfo[lcgIdx].dataVol = 0;
+ }
+ if(totDataReq > 0) /* UL grant must be provided for this UE in this slot */
+ {
+ SchPuschInfo schPuschInfo;
+ memset(&schPuschInfo, 0, sizeof(SchPuschInfo));
+
+ SCH_ALLOC(dciInfo, sizeof(DciInfo));
+ if(!dciInfo)
+ {
+ DU_LOG("\nMAC: Memory Allocation failed for dciInfo alloc");
+ return RFAILED;
+ }
+ memset(dciInfo,0,sizeof(DciInfo));
+ /* update the SFN and SLOT */
+ memcpy(&dlSchedInfo.schSlotValue.ulDciTime, slotInd, sizeof(SlotIndInfo));
+ slot = dlSchedInfo.schSlotValue.ulDciTime.slot;
+ /* Update PUSCH allocation */
+ schFillPuschAlloc(ueCb, slot, totDataReq, &schPuschInfo);
+ /* Fill DCI for UL grant */
+ schFillUlDci(ueCb, schPuschInfo, dciInfo);
+ memcpy(&dciInfo->slotIndInfo, &dlSchedInfo.schSlotValue.ulDciTime, sizeof(SlotIndInfo));
+ dlSchedInfo.ulGrant = dciInfo;
+ }
+ }
+
+ /* Check for pending BO grant for LC */
+ if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
+ (!cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
+ {
+ schFillBoGrantDlSchedInfo(cell, &dlSchedInfo, dlMsgAlloc);
+ }
+
+ /* send msg to MAC */
+ ret = sendDlAllocToMac(&dlSchedInfo, schInst);