diff --git a/lib/src/phy/phch/ra.c b/lib/src/phy/phch/ra.c index 4e9ba46af..a73c5d2e9 100644 --- a/lib/src/phy/phch/ra.c +++ b/lib/src/phy/phch/ra.c @@ -314,9 +314,10 @@ int srslte_ra_dl_dci_to_grant_prb_allocation(srslte_ra_dl_dci_t *dci, srslte_ra_ break; case SRSLTE_RA_ALLOC_TYPE1: n_rb_type1 = srslte_ra_type1_N_rb(nof_prb); - if (dci->type1_alloc.rbg_subset < (nof_prb / P) % P) { + uint32_t temp = ((nof_prb - 1) / P) % P; + if (dci->type1_alloc.rbg_subset < temp) { n_rb_rbg_subset = ((nof_prb - 1) / (P * P)) * P + P; - } else if (dci->type1_alloc.rbg_subset == ((nof_prb / P) % P)) { + } else if (dci->type1_alloc.rbg_subset == temp) { n_rb_rbg_subset = ((nof_prb - 1) / (P * P)) * P + ((nof_prb - 1) % P) + 1; } else { n_rb_rbg_subset = ((nof_prb - 1) / (P * P)) * P; @@ -325,10 +326,9 @@ int srslte_ra_dl_dci_to_grant_prb_allocation(srslte_ra_dl_dci_t *dci, srslte_ra_ bitmask = dci->type1_alloc.vrb_bitmask; for (i = 0; i < n_rb_type1; i++) { if (bitmask & (1 << (n_rb_type1 - i - 1))) { - if ((((i + shift) / P) - * P * P + dci->type1_alloc.rbg_subset * P + (i + shift) % P) < nof_prb) { - grant->prb_idx[0][((i + shift) / P) - * P * P + dci->type1_alloc.rbg_subset * P + (i + shift) % P] = true; + uint32_t idx = (((i + shift) / P) * P * P + dci->type1_alloc.rbg_subset * P + (i + shift) % P); + if (idx < nof_prb) { + grant->prb_idx[0][idx] = true; grant->nof_prb++; } else { return SRSLTE_ERROR;