+/*******************************************************************
+ *
+ * @brief sch Process pending Msg4 Req
+ *
+ * @details
+ *
+ * Function : schProcessMsg4Req
+ *
+ * Functionality:
+ * sch Process pending Msg4 Req
+ *
+ * @params[in] SchCellCb *cell, SlotTimingInfo currTime
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ *******************************************************************/
+
+uint8_t schProcessMsg4Req(SchCellCb *cell, SlotTimingInfo currTime)
+{
+ bool k1Found = FALSE;
+ uint16_t pdcchSlot = 0, pdschSlot = 0;
+ uint8_t ueIdx = 0, numK0 = 0, k0TblIdx = 0, k0Index = 0, k0Val = 0;
+ uint8_t k1TblIdx = 0, k1Index = 0, k1Val = 0, numK1 = 0;
+ SchK0K1TimingInfoTbl *k0K1InfoTbl;
+ SlotTimingInfo pdcchTime, pdschTime, pucchTime;
+ DlMsgAlloc *dciSlotAlloc = NULLP; /* Stores info for transmission of PDCCH for Msg4 */
+ DlMsgAlloc *msg4SlotAlloc = NULLP; /* Stores info for transmission of PDSCH for Msg4 */
+
+ if(cell == NULL)
+ {
+ DU_LOG("\nERROR --> SCH: schDlRsrcAllocMsg4() : Cell is NULL");
+ return RFAILED;
+ }
+
+ while(ueIdx < MAX_NUM_UE)
+ {
+ if(cell->raCb[ueIdx].msg4recvd == FALSE)
+ {
+ ueIdx++;
+ continue;
+ }
+
+ ADD_DELTA_TO_TIME(currTime, pdcchTime, PHY_DELTA_DL + SCHED_DELTA);
+ pdcchSlot = pdcchTime.slot;
+#ifdef NR_TDD
+ if(schGetSlotSymbFrmt(pdcchSlot, cell->slotFrmtBitMap) != DL_SLOT)
+ {
+ continue;
+ }
+#endif
+ k0K1InfoTbl = &cell->cellCfg.schInitialDlBwp.k0K1InfoTbl;
+ numK0 = k0K1InfoTbl->k0k1TimingInfo[pdcchSlot].numK0;
+ for(k0TblIdx = 0; k0TblIdx < numK0; k0TblIdx++)
+ {
+ k0Index = k0K1InfoTbl->k0k1TimingInfo[pdcchSlot].k0Indexes[k0TblIdx].k0Index;
+ k0Val = cell->cellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[k0Index].k0;
+
+ ADD_DELTA_TO_TIME(pdcchTime, pdschTime, k0Val);
+ pdschSlot = pdschTime.slot;
+#ifdef NR_TDD
+ if(schGetSlotSymbFrmt(pdschSlot, cell->slotFrmtBitMap) != DL_SLOT)
+ {
+ continue;
+ }
+#endif
+ numK1 = k0K1InfoTbl->k0k1TimingInfo[pdcchSlot].k0Indexes[k0TblIdx].k1TimingInfo.numK1;
+ for(k1TblIdx = 0; k1TblIdx < numK1; k1TblIdx++)
+ {
+ k1Index = k0K1InfoTbl->k0k1TimingInfo[pdcchSlot].k0Indexes[k0TblIdx].k1TimingInfo.k1Indexes[k1TblIdx];
+ k1Val = defaultUlAckTbl[k1Index];
+
+ ADD_DELTA_TO_TIME(pdschTime, pucchTime, k1Val);
+#ifdef NR_TDD
+ if(schGetSlotSymbFrmt(pucchTime.slot, cell->slotFrmtBitMap) == DL_SLOT)
+ {
+ continue;
+ }
+#endif
+ k1Found = true;
+ break;
+ }
+ if(k1Found)
+ break;
+ }
+
+ /* If K0-K1 combination not found, no scheduling happens */
+ if(!k1Found)
+ {
+ ueIdx++;
+ continue;
+ }
+
+ SCH_ALLOC(dciSlotAlloc, sizeof(DlMsgAlloc));
+ if(dciSlotAlloc == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH : Memory Allocation failed for dciSlotAlloc");
+ return RFAILED;
+ }
+ cell->schDlSlotInfo[pdcchSlot]->dlMsgAlloc = dciSlotAlloc;
+
+ /* Fill PDCCH and PDSCH scheduling information for Msg4 */
+ if((schDlRsrcAllocMsg4(cell, pdschTime, ueIdx, dciSlotAlloc, k0Index)) != ROK)
+ {
+ DU_LOG("\nERROR --> SCH: Scheduling of Msg4 failed in slot [%d]", pdschSlot);
+ SCH_FREE(dciSlotAlloc, sizeof(DlMsgAlloc));
+ cell->schDlSlotInfo[pdcchSlot]->dlMsgAlloc = NULLP;
+ return RFAILED;
+ }
+ /* Check if both DCI and RAR are sent in the same slot.
+ * If not, allocate memory RAR PDSCH slot to store RAR info
+ */
+ if(pdcchSlot == pdschSlot)
+ dciSlotAlloc->pduPres = BOTH;
+ else
+ {
+ /* Allocate memory to schedule rarSlot to send RAR, pointer will be checked at schProcessSlotInd() */
+ SCH_ALLOC(msg4SlotAlloc, sizeof(DlMsgAlloc));
+ if(msg4SlotAlloc == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH : Memory Allocation failed for msg4SlotAlloc");
+ SCH_FREE(dciSlotAlloc, sizeof(DlMsgAlloc));
+ cell->schDlSlotInfo[pdcchSlot]->rarAlloc = NULLP;
+ return RFAILED;
+ }
+ cell->schDlSlotInfo[pdschSlot]->dlMsgAlloc = msg4SlotAlloc;
+
+ /* Copy all RAR info */
+ memcpy(msg4SlotAlloc, dciSlotAlloc, sizeof(DlMsgAlloc));
+ msg4SlotAlloc->dlMsgPdcchCfg.dci.pdschCfg = &msg4SlotAlloc->dlMsgPdschCfg;
+
+ /* Assign correct PDU types in corresponding slots */
+ msg4SlotAlloc->pduPres = PDSCH_PDU;
+ dciSlotAlloc->pduPres = PDCCH_PDU;
+ dciSlotAlloc->pdschSlot = pdschSlot;
+ }
+
+ /* PUCCH resource */
+ schAllocPucchResource(cell, pucchTime, cell->raCb[ueIdx].tcrnti);
+ cell->raCb[ueIdx].msg4recvd = FALSE;
+ ueIdx++;
+ }
+ return ROK;
+}