diff --git a/lib/include/srslte/phy/phch/pusch.h b/lib/include/srslte/phy/phch/pusch.h index 7ec881066..10c3e08a5 100644 --- a/lib/include/srslte/phy/phch/pusch.h +++ b/lib/include/srslte/phy/phch/pusch.h @@ -112,6 +112,13 @@ SRSLTE_API int srslte_pusch_set_rnti(srslte_pusch_t* q, uint16_t rnti); SRSLTE_API void srslte_pusch_free_rnti(srslte_pusch_t* q, uint16_t rnti); +/** + * Asserts PUSCH grant attributes are in range + * @param grant Pointer to PUSCH grant + * @return it returns SRSLTE_SUCCESS if the grant is correct, otherwise it returns a SRSLTE_ERROR code + */ +SRSLTE_API int srslte_pusch_assert_grant(const srslte_pusch_grant_t* grant); + /* These functions do not modify the state and run in real-time */ SRSLTE_API int srslte_pusch_encode(srslte_pusch_t* q, srslte_ul_sf_cfg_t* sf, diff --git a/lib/src/phy/phch/pusch.c b/lib/src/phy/phch/pusch.c index 864e6cf67..26b85bbb9 100644 --- a/lib/src/phy/phch/pusch.c +++ b/lib/src/phy/phch/pusch.c @@ -340,6 +340,23 @@ static srslte_sequence_t* get_user_sequence(srslte_pusch_t* q, uint16_t rnti, ui } } +int srslte_pusch_assert_grant(const srslte_pusch_grant_t* grant) +{ + if (!srslte_dft_precoding_valid_prb(grant->L_prb)) { + return SRSLTE_ERROR_INVALID_INPUTS; + } + + if (grant->tb.rv < 0 || grant->tb.rv > 3) { + return SRSLTE_ERROR_OUT_OF_BOUNDS; + } + + if (grant->tb.tbs < 0) { + return SRSLTE_ERROR_OUT_OF_BOUNDS; + } + + return SRSLTE_SUCCESS; +} + /** Converts the PUSCH data bits to symbols mapped to the slot ready for transmission */ int srslte_pusch_encode(srslte_pusch_t* q, @@ -368,19 +385,9 @@ int srslte_pusch_encode(srslte_pusch_t* q, return SRSLTE_ERROR_INVALID_INPUTS; } - if (!srslte_dft_precoding_valid_prb(cfg->grant.L_prb)) { - ERROR("Error encoding PUSCH: invalid L_prb=%d\n", cfg->grant.L_prb); - return -1; - } - - if (cfg->grant.tb.rv < 0 || cfg->grant.tb.rv > 3) { - ERROR("Error encoding PUSCH: invalid rv=%d\n", cfg->grant.tb.rv); - return -1; - } - - if (cfg->grant.tb.tbs < 0) { - ERROR("Error encoding PUSCH: invalid tbs=%d\n", cfg->grant.tb.tbs); - return -1; + int err = srslte_pusch_assert_grant(&cfg->grant); + if (err != SRSLTE_SUCCESS) { + return err; } INFO("Encoding PUSCH SF: %d, Mod %s, RNTI: %d, TBS: %d, NofRE: %d, NofSymbols=%d, NofBitsE: %d, rv_idx: %d\n", diff --git a/lib/src/phy/ue/ue_ul.c b/lib/src/phy/ue/ue_ul.c index b2cb1c8d1..bc826ff58 100644 --- a/lib/src/phy/ue/ue_ul.c +++ b/lib/src/phy/ue/ue_ul.c @@ -212,21 +212,21 @@ int srslte_ue_ul_dci_to_pusch_grant(srslte_ue_ul_t* q, srslte_dci_ul_t* dci, srslte_pusch_grant_t* grant) { + // Convert DCI to Grant if (srslte_ra_ul_dci_to_grant(&q->cell, sf, &cfg->ul_cfg.hopping, dci, grant)) { - char str[128]; - srslte_dci_ul_info(dci, str, sizeof(str)); - ERROR("Converting DCI to UL grant from %s\n", str); return SRSLTE_ERROR; } // Update shortened before computing grant srslte_refsignal_srs_pusch_shortened(&q->signals, sf, &cfg->ul_cfg.srs, &cfg->ul_cfg.pusch); - /* Update RE assuming if shortened is true */ + // Update RE assuming if shortened is true if (sf->shortened) { srslte_ra_ul_compute_nof_re(grant, q->cell.cp, true); } - return SRSLTE_SUCCESS; + + // Assert Grant is valid + return srslte_pusch_assert_grant(grant); } void srslte_ue_ul_pusch_hopping(srslte_ue_ul_t* q, diff --git a/srsue/src/phy/cc_worker.cc b/srsue/src/phy/cc_worker.cc index 44635048d..8d0c831f8 100644 --- a/srsue/src/phy/cc_worker.cc +++ b/srsue/src/phy/cc_worker.cc @@ -674,7 +674,11 @@ bool cc_worker::work_ul(srslte_uci_data_t* uci_data) // Generate PHY grant if (srslte_ue_ul_dci_to_pusch_grant(&ue_ul, &sf_cfg_ul, &ue_ul_cfg, &dci_ul, &ue_ul_cfg.ul_cfg.pusch.grant)) { - Error("Converting DCI message to UL dci\n"); + if (log_h->get_level() >= srslte::LOG_LEVEL_ERROR) { + char str[128]; + srslte_dci_ul_info(&dci_ul, str, sizeof(str)); + Error("Converting DCI message to UL grant %s\n", str); + } ul_grant_available = false; } else if (ue_ul_cfg.ul_cfg.pusch.grant.tb.mod == SRSLTE_MOD_BPSK) { Error("UL retransmission without valid stored grant.\n");