+ /* Calculating time frame to send RAR PDSCH */
+ ADD_DELTA_TO_TIME(dciTime, rarTime, k0, cell->numSlots);
+ rarSlot = rarTime.slot;
+
+ /* If PDSCH is already scheduled on this slot, cannot schedule PDSCH for another UE here. */
+ if(cell->schDlSlotInfo[rarSlot]->pdschUe != 0)
+ continue;
+
+ /* If Contention-FREE RA is in progress, allocate resources for
+ * PUCCH for next UL message */
+ if(cell->raReq[ueId-1]->isCFRA)
+ {
+ numK1 = k0K1InfoTbl->k0k1TimingInfo[dciTime.slot].k0Indexes[k0TblIdx].k1TimingInfo.numK1;
+ for(k1TblIdx = 0; k1TblIdx < numK1; k1TblIdx++)
+ {
+ k1Index = k0K1InfoTbl->k0k1TimingInfo[dciTime.slot].k0Indexes[k0TblIdx].k1TimingInfo.k1Indexes[k1TblIdx];
+ if(cell->raReq[ueId-1]->ueCb->ueCfg.spCellCfg.servCellRecfg.initUlBwp.pucchCfg.dlDataToUlAck)
+ {
+ k1 = cell->raReq[ueId-1]->ueCb->ueCfg.spCellCfg.servCellRecfg.initUlBwp.pucchCfg.dlDataToUlAck->\
+ dlDataToUlAckList[k1Index];
+ }
+ else
+ {
+ k1 = defaultUlAckTbl[k1Index];
+ }
+
+ ADD_DELTA_TO_TIME(rarTime, pucchTime, k1, cell->numSlots);
+#ifdef NR_TDD
+ if(schGetSlotSymbFrmt(pucchTime.slot, cell->slotFrmtBitMap) == DL_SLOT)
+ continue;
+#endif
+ if(cell->schUlSlotInfo[pucchTime.slot]->pucchUe != 0)
+ continue;
+ k1Found = true;
+ break;
+ }
+ }
+ else
+ {
+ /* Else if contention-based RA is in progress, allocate resources for MSG3 */
+ for(k2TblIdx = 0; k2TblIdx < msg3K2InfoTbl->k2TimingInfo[rarSlot].numK2; k2TblIdx++)
+ {
+ k2Index = msg3K2InfoTbl->k2TimingInfo[rarSlot].k2Indexes[k2TblIdx];
+ k2 = cell->cellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].k2;
+
+ /* Delta is added to the slot allocation for msg3 based on 38.214 section 6.1.2.1 */
+ k2 = k2 + msg3Delta;
+ if(k2 >= msg3MinSchTime)
+ {
+ ADD_DELTA_TO_TIME(rarTime, msg3Time, k2, cell->numSlots);
+#ifdef NR_TDD
+ if(schGetSlotSymbFrmt(msg3Time.slot % totalCfgSlot, cell->slotFrmtBitMap) == DL_SLOT)
+ continue;
+#endif
+ /* If PUSCH is already scheduled on this slot, another PUSCH
+ * pdu cannot be scheduled here */
+ if(cell->schUlSlotInfo[msg3Time.slot]->puschUe != 0)
+ continue;
+
+ k2Found = true;
+ break;
+ }
+ }
+ }
+ if(k1Found || k2Found)
+ break;
+ }
+ }
+ else if(windowStatus == WINDOW_EXPIRED)
+ {
+ SCH_FREE(cell->raReq[ueId-1]->rachInd, sizeof(RachIndInfo));
+ SCH_FREE(cell->raReq[ueId-1], sizeof(SchRaReq));
+ return false;
+ }
+
+ /* If K0-K2 and K0-K1 combination not found, no scheduling happens */
+ if(!k1Found && !k2Found)
+ return false;
+
+ /* Allocate memory for RAR PDCCH slot, pointer will be checked at schProcessSlotInd() */
+ SCH_ALLOC(dciSlotAlloc, sizeof(RarAlloc));
+ if(dciSlotAlloc == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciSlotAlloc");
+ return false;
+ }
+ cell->schDlSlotInfo[dciSlot]->rarAlloc[ueId-1] = dciSlotAlloc;
+
+ /* Fill PDCCH and PDSCH scheduling information for RAR */
+ if((schFillRar(cell, rarTime, ueId, dciSlotAlloc, k0Index)) != ROK)
+ {
+ DU_LOG("\nERROR --> SCH: Scheduling of RAR failed in slot [%d]", rarSlot);
+ if(!dciSlotAlloc->rarPdschCfg)
+ {
+ SCH_FREE(dciSlotAlloc, sizeof(RarAlloc));
+ cell->schDlSlotInfo[dciSlot]->rarAlloc[ueId-1] = NULLP;
+ }
+ return false;
+ }
+
+ /* Fill RAR info */
+ dciSlotAlloc->raRnti = cell->raReq[ueId-1]->raRnti;
+ dciSlotAlloc->rarInfo.tcrnti = cell->raReq[ueId-1]->rachInd->crnti;
+ dciSlotAlloc->rarInfo.RAPID = cell->raReq[ueId-1]->rachInd->preambleIdx;
+ dciSlotAlloc->rarInfo.ta = cell->raReq[ueId-1]->rachInd->timingAdv;
+
+ if(cell->raReq[ueId-1]->isCFRA)
+ {
+ /* Allocate resources for PUCCH */
+ schAllocPucchResource(cell, pucchTime, cell->raReq[ueId-1]->rachInd->crnti,NULLP, FALSE, NULLP);
+ }
+ else
+ {
+ /* Allocate resources for msg3 */
+ msg3PuschInfo = schAllocMsg3Pusch(schInst, cell->raReq[ueId-1]->rachInd->crnti, k2Index, msg3Time, &(cell->raCb[ueId-1].msg3HqProc), FALSE);
+ if(msg3PuschInfo)
+ {
+ dciSlotAlloc->rarInfo.ulGrant.bwpSize = cell->cellCfg.ulCfgCommon.schInitialUlBwp.bwp.freqAlloc.numPrb;
+ /* Spec 38.213, section 8.2, 0 : MSG3 PUSCH will be transmitted without frequency hopping */
+ dciSlotAlloc->rarInfo.ulGrant.freqHopFlag = 0;
+ dciSlotAlloc->rarInfo.ulGrant.msg3FreqAlloc.startPrb = msg3PuschInfo->fdAlloc.resAlloc.type1.startPrb;
+ dciSlotAlloc->rarInfo.ulGrant.msg3FreqAlloc.numPrb = msg3PuschInfo->fdAlloc.resAlloc.type1.numPrb;
+ dciSlotAlloc->rarInfo.ulGrant.k2Index = k2Index;
+ dciSlotAlloc->rarInfo.ulGrant.mcs = msg3PuschInfo->tbInfo.mcs;
+ dciSlotAlloc->rarInfo.ulGrant.tpc = 3; /* TODO : Check appropriate value to be filled */
+ /* Spec 38.213, section 8.2 : In a contention based random access
+ * procedure, the CSI request field is reserved. */
+ dciSlotAlloc->rarInfo.ulGrant.csiReq = 0;
+ }
+ }
+
+ /* Check if both DCI and RAR are sent in the same slot.
+ * If not, allocate memory RAR PDSCH slot to store RAR info
+ */
+ if(dciSlot == rarSlot)
+ {
+ SCH_ALLOC(dciSlotAlloc->rarPdschCfg, sizeof(PdschCfg));
+ if(dciSlotAlloc->rarPdschCfg)
+ {
+ memcpy(dciSlotAlloc->rarPdschCfg, &dciSlotAlloc->rarPdcchCfg->dci.pdschCfg, sizeof(PdschCfg));
+ }
+ else
+ {
+ SCH_FREE(dciSlotAlloc->rarPdcchCfg, sizeof(PdcchCfg));
+ SCH_FREE(dciSlotAlloc, sizeof(RarAlloc));
+ cell->schDlSlotInfo[dciSlot]->rarAlloc[ueId-1] = NULLP;
+ DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciSlotAlloc->rarPdschCfg");
+ return false;
+ }
+
+ }
+ else
+ {
+ /* Allocate memory to schedule rarSlot to send RAR, pointer will be checked at schProcessSlotInd() */
+ SCH_ALLOC(rarSlotAlloc, sizeof(RarAlloc));
+ if(rarSlotAlloc == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH : Memory Allocation failed for rarSlotAlloc");
+ SCH_FREE(dciSlotAlloc->rarPdcchCfg, sizeof(PdcchCfg));
+ if(!dciSlotAlloc->rarPdschCfg)
+ {
+ SCH_FREE(dciSlotAlloc, sizeof(RarAlloc));
+ cell->schDlSlotInfo[dciSlot]->rarAlloc[ueId-1] = NULLP;
+ }
+ return false;
+ }
+ cell->schDlSlotInfo[rarSlot]->rarAlloc[ueId-1] = rarSlotAlloc;
+
+ /* Copy all RAR info */
+ rarSlotAlloc->raRnti = dciSlotAlloc->raRnti;
+ rarSlotAlloc->bwp = dciSlotAlloc->bwp;
+ SCH_ALLOC(rarSlotAlloc->rarPdschCfg, sizeof(PdschCfg));
+ if(rarSlotAlloc->rarPdschCfg)
+ {
+ memcpy(rarSlotAlloc->rarPdschCfg, &dciSlotAlloc->rarPdcchCfg->dci.pdschCfg,sizeof(PdschCfg));
+ }
+ else
+ {
+ DU_LOG("\nERROR --> SCH : Memory Allocation failed for rarSlotAlloc->rarPdschCfg");
+ SCH_FREE(dciSlotAlloc->rarPdcchCfg, sizeof(PdcchCfg));
+ if(!dciSlotAlloc->rarPdschCfg)
+ {
+ SCH_FREE(dciSlotAlloc, sizeof(RarAlloc));
+ cell->schDlSlotInfo[dciSlot]->rarAlloc[ueId-1] = NULLP;
+ }
+ SCH_FREE(rarSlotAlloc, sizeof(RarAlloc));
+ cell->schDlSlotInfo[rarSlot]->rarAlloc[ueId-1] = NULLP;
+ return false;
+ }
+ }
+
+ cell->schDlSlotInfo[dciSlot]->pdcchUe = ueId;
+ cell->schDlSlotInfo[rarSlot]->pdschUe = ueId;
+ if(cell->raReq[ueId-1]->isCFRA)
+ cell->schUlSlotInfo[pucchTime.slot]->pucchUe = ueId;
+ else
+ cell->schUlSlotInfo[msg3Time.slot]->puschUe = ueId;
+
+ /* Create raCb at SCH */
+ createSchRaCb(ueId, cell->raReq[ueId-1], schInst);
+
+ /* Remove RachInd from pending RA request list */
+ SCH_FREE(cell->raReq[ueId-1]->rachInd, sizeof(RachIndInfo));
+ SCH_FREE(cell->raReq[ueId-1], sizeof(SchRaReq));
+
+ return true;
+ }
+ return false;
+}
+
+/**
+ * @brief process rach indication function.
+ *
+ * @details
+ *
+ * Function : SchProcRachInd
+ *
+ * This function process rach indication
+ *
+ * @param[in] rachInd parameters
+ * @param[in] shed instance
+ * @return ROK
+ **/
+uint8_t SchProcRachInd(Pst *pst, RachIndInfo *rachInd)
+{
+ SchRaReq *raReq = NULLP;
+ float slotDuration;
+ uint8_t winNumSlots;
+ uint8_t ueId;
+ Inst schInst = pst->dstInst-SCH_INST_START;
+ SchCellCb *cell = schCb[schInst].cells[schInst];
+
+ DU_LOG("\nINFO --> SCH : Received Rach indication");
+
+ if(cell == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH: Failed to find cell in SchProcRachInd");
+ return RFAILED;
+ }
+
+ /* Storing RA request in cellCb */
+ GET_UE_ID(rachInd->crnti, ueId);
+ if(ueId <= 0)
+ {
+ DU_LOG("\nERROR --> SCH: Invalid CRNTI [%d]", rachInd->crnti);
+ return RFAILED;
+ }
+
+ SCH_ALLOC(raReq, sizeof(SchRaReq));
+ if(!raReq)
+ {
+ DU_LOG("\nERROR --> SCH : Memory allocation failure in SchProcRachInd");
+ SCH_FREE(rachInd, sizeof(RachIndInfo));
+ return RFAILED;
+ }
+
+ /* calculate the ra-rnti value */
+ raReq->raRnti = calculateRaRnti(rachInd->symbolIdx, rachInd->slotIdx, rachInd->freqIdx);
+ raReq->rachInd = rachInd;
+ if((cell->ueCb[ueId-1].crnti == rachInd->crnti) && (cell->ueCb[ueId-1].state == SCH_UE_HANDIN_IN_PROGRESS))
+ {
+ raReq->isCFRA = true;
+ raReq->ueCb = &cell->ueCb[ueId-1];
+ }
+ else
+ raReq->isCFRA = false;
+ raReq->winStartTime.sfn = rachInd->timingInfo.sfn;
+ raReq->winStartTime.slot = rachInd->timingInfo.slot;
+
+ /* Converting window size from ms to number of slots */
+ slotDuration = (1 / pow(2, cell->numerology));
+ winNumSlots = (float)cell->cellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.raRspWindow / slotDuration;
+
+ /* Adding window size to window start time to get window end time */
+ ADD_DELTA_TO_TIME(raReq->winStartTime, raReq->winEndTime, winNumSlots, cell->numSlots);
+ cell->raReq[ueId -1] = raReq;
+
+ /* Adding UE Id to list of pending UEs to be scheduled */
+ cell->api->SchRachInd(cell, ueId);