From 87cf3cf2e5f6c9e623b9fc61e3dc3f92d0411830 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Wed, 28 Apr 2021 10:30:38 +0200 Subject: [PATCH] Fix coverity warnings under lib/src/phy/phch --- lib/include/srsran/phy/phch/csi.h | 8 ++++++ lib/src/phy/phch/csi.c | 12 +++++++++ lib/src/phy/phch/dci.c | 8 +++--- lib/src/phy/phch/pdcch.c | 2 +- lib/src/phy/phch/pdsch.c | 32 ++++++---------------- lib/src/phy/phch/pdsch_nr.c | 6 ++--- lib/src/phy/phch/pucch.c | 10 +++++++ lib/src/phy/phch/pucch_nr.c | 18 ++++++++----- lib/src/phy/phch/pusch_nr.c | 13 +++++---- lib/src/phy/phch/ra_dl.c | 12 ++++----- lib/src/phy/phch/ra_nr.c | 45 ++++++++++++++++--------------- lib/src/phy/phch/ra_sl.c | 7 +++-- lib/src/phy/phch/ra_ul_nr.c | 2 +- lib/src/phy/phch/sch.c | 33 ++++++++++++++++++----- lib/src/phy/phch/sch_nr.c | 6 ++++- lib/src/phy/phch/uci.c | 5 ++++ lib/src/phy/phch/uci_nr.c | 4 +-- 17 files changed, 137 insertions(+), 86 deletions(-) diff --git a/lib/include/srsran/phy/phch/csi.h b/lib/include/srsran/phy/phch/csi.h index 2d55f220f..f8b024b0e 100644 --- a/lib/include/srsran/phy/phch/csi.h +++ b/lib/include/srsran/phy/phch/csi.h @@ -37,6 +37,14 @@ SRSRAN_API int srsran_csi_generate_reports(const srsran_csi_hl_cfg_t* cfg, */ SRSRAN_API int srsran_csi_part1_nof_bits(const srsran_csi_report_cfg_t* report_list, uint32_t nof_reports); +/** + * @brief Compute number of CSI bits necessary to transmit all the CSI part 2 reports for a PUCCH transmission + * @param report_list Provides the CSI report list + * @param nof_reports Number of CSI reports in the list + * @return The number of bits if the provided list is valid, SRSRAN_ERROR code otherwise + */ +SRSRAN_API int srsran_csi_part2_nof_bits(const srsran_csi_report_cfg_t* report_list, uint32_t nof_reports); + /** * @brief Checks if the report list contains part 2 CSI report * @param report_list Report list diff --git a/lib/src/phy/phch/csi.c b/lib/src/phy/phch/csi.c index 474ac4300..f8f4599b1 100644 --- a/lib/src/phy/phch/csi.c +++ b/lib/src/phy/phch/csi.c @@ -215,6 +215,18 @@ int srsran_csi_part1_nof_bits(const srsran_csi_report_cfg_t* report_list, uint32 return (int)count; } +int srsran_csi_part2_nof_bits(const srsran_csi_report_cfg_t* report_list, uint32_t nof_reports) +{ + uint32_t count = 0; + + // Check input pointer + if (report_list == NULL) { + return SRSRAN_ERROR_INVALID_INPUTS; + } + + return (int)count; +} + bool srsran_csi_has_part2(const srsran_csi_report_cfg_t* report_list, uint32_t nof_reports) { if (report_list == NULL || nof_reports == 0) { diff --git a/lib/src/phy/phch/dci.c b/lib/src/phy/phch/dci.c index e672d21a2..6c1cfd3d7 100644 --- a/lib/src/phy/phch/dci.c +++ b/lib/src/phy/phch/dci.c @@ -1636,12 +1636,12 @@ uint32_t srsran_dci_dl_info(const srsran_dci_dl_t* dci_dl, char* info_str, uint3 n = srsran_print_check(info_str, len, n, ", pid=%d", dci_dl->pid); - n = srsran_print_check(info_str, len, n, ", mcs={", 0); + n = srsran_print_check(info_str, len, n, ", mcs={"); n = print_multi(info_str, n, len, dci_dl, 0); - n = srsran_print_check(info_str, len, n, "}", 0); - n = srsran_print_check(info_str, len, n, ", ndi={", 0); + n = srsran_print_check(info_str, len, n, "}"); + n = srsran_print_check(info_str, len, n, ", ndi={"); n = print_multi(info_str, n, len, dci_dl, 2); - n = srsran_print_check(info_str, len, n, "}", 0); + n = srsran_print_check(info_str, len, n, "}"); if (dci_dl->format == SRSRAN_DCI_FORMAT1 || dci_dl->format == SRSRAN_DCI_FORMAT1A || dci_dl->format == SRSRAN_DCI_FORMAT1B || dci_dl->format == SRSRAN_DCI_FORMAT2 || diff --git a/lib/src/phy/phch/pdcch.c b/lib/src/phy/phch/pdcch.c index f7a4acf74..eaffc0aa8 100644 --- a/lib/src/phy/phch/pdcch.c +++ b/lib/src/phy/phch/pdcch.c @@ -403,7 +403,7 @@ int srsran_pdcch_decode_msg(srsran_pdcch_t* q, srsran_dl_sf_cfg_t* sf, srsran_dc INFO("Skipping DCI: nCCE=%d, L=%d, msg_len=%d, mean=%f", msg->location.ncce, msg->location.L, nof_bits, mean); } } - } else { + } else if (msg != NULL) { ERROR("Invalid parameters, location=%d,%d", msg->location.ncce, msg->location.L); } return ret; diff --git a/lib/src/phy/phch/pdsch.c b/lib/src/phy/phch/pdsch.c index fcfb32b02..2873f726f 100644 --- a/lib/src/phy/phch/pdsch.c +++ b/lib/src/phy/phch/pdsch.c @@ -513,25 +513,9 @@ static float apply_power_allocation(srsran_pdsch_t* q, srsran_pdsch_cfg_t* cfg, static void csi_correction(srsran_pdsch_t* q, srsran_pdsch_cfg_t* cfg, uint32_t codeword_idx, uint32_t tb_idx, void* e) { - uint32_t qm = 0; - switch (cfg->grant.tb[tb_idx].mod) { - case SRSRAN_MOD_BPSK: - qm = 1; - break; - case SRSRAN_MOD_QPSK: - qm = 2; - break; - case SRSRAN_MOD_16QAM: - qm = 4; - break; - case SRSRAN_MOD_64QAM: - qm = 6; - break; - case SRSRAN_MOD_256QAM: - qm = 8; - break; - default: - ERROR("No modulation"); + uint32_t qm = srsran_mod_bits_x_symbol(cfg->grant.tb[tb_idx].mod); + if (qm == 0) { + return; } const uint32_t csi_max_idx = srsran_vec_max_fi(q->csi[codeword_idx], cfg->grant.tb[tb_idx].nof_bits / qm); @@ -1180,18 +1164,18 @@ uint32_t srsran_pdsch_grant_rx_info(srsran_pdsch_grant_t* grant, { uint32_t len = srsran_ra_dl_info(grant, str, str_len); - len = srsran_print_check(str, str_len, len, ", crc={", 0); + len = srsran_print_check(str, str_len, len, ", crc={"); for (uint32_t i = 0; i < SRSRAN_MAX_CODEWORDS; i++) { if (grant->tb[i].enabled) { len = srsran_print_check(str, str_len, len, "%s", res[i].crc ? "OK" : "KO"); if (i < SRSRAN_MAX_CODEWORDS - 1) { if (grant->tb[i + 1].enabled) { - len = srsran_print_check(str, str_len, len, "/", 0); + len = srsran_print_check(str, str_len, len, "/"); } } } } - len = srsran_print_check(str, str_len, len, "}", 0); + len = srsran_print_check(str, str_len, len, "}"); // Average iterations between nof TB and divide by 2 to get full decoder iterations len = srsran_print_check( @@ -1207,7 +1191,7 @@ srsran_pdsch_rx_info(srsran_pdsch_cfg_t* cfg, srsran_pdsch_res_t res[SRSRAN_MAX_ len += srsran_pdsch_grant_rx_info(&cfg->grant, res, &str[len], str_len - len); if (cfg->meas_evm_en) { - len = srsran_print_check(str, str_len, len, ", evm={", 0); + len = srsran_print_check(str, str_len, len, ", evm={"); for (uint32_t i = 0; i < SRSRAN_MAX_CODEWORDS; i++) { if (cfg->grant.tb[i].enabled && !isnan(res[i].evm)) { len = srsran_print_check(str, str_len, len, "%.2f", res[i].evm); @@ -1218,7 +1202,7 @@ srsran_pdsch_rx_info(srsran_pdsch_cfg_t* cfg, srsran_pdsch_res_t res[SRSRAN_MAX_ } } } - len = srsran_print_check(str, str_len, len, "}", 0); + len = srsran_print_check(str, str_len, len, "}"); } if (cfg->meas_time_en) { diff --git a/lib/src/phy/phch/pdsch_nr.c b/lib/src/phy/phch/pdsch_nr.c index 307c57a38..65964d4e0 100644 --- a/lib/src/phy/phch/pdsch_nr.c +++ b/lib/src/phy/phch/pdsch_nr.c @@ -479,7 +479,7 @@ int srsran_pdsch_nr_decode(srsran_pdsch_nr_t* q, const srsran_sch_grant_nr_t* grant, srsran_chest_dl_res_t* channel, cf_t* sf_symbols[SRSRAN_MAX_PORTS], - srsran_pdsch_res_nr_t data[SRSRAN_MAX_TB]) + srsran_pdsch_res_nr_t* data) { // Check input pointers if (!q || !cfg || !grant || !data || !sf_symbols) { @@ -538,9 +538,7 @@ int srsran_pdsch_nr_decode(srsran_pdsch_nr_t* q, // SCH decode for (uint32_t tb = 0; tb < SRSRAN_MAX_TB; tb++) { - nof_cw += grant->tb[tb].enabled ? 1 : 0; - - if (pdsch_nr_decode_codeword(q, cfg, &grant->tb[tb], &data[tb], grant->rnti) < SRSRAN_SUCCESS) { + if (pdsch_nr_decode_codeword(q, cfg, &grant->tb[tb], data, grant->rnti) < SRSRAN_SUCCESS) { ERROR("Error encoding TB %d", tb); return SRSRAN_ERROR; } diff --git a/lib/src/phy/phch/pucch.c b/lib/src/phy/phch/pucch.c index 225730341..86fae4141 100644 --- a/lib/src/phy/phch/pucch.c +++ b/lib/src/phy/phch/pucch.c @@ -451,6 +451,11 @@ static int encode_signal_format3(srsran_pucch_t* q, uint32_t N_sf_0 = get_N_sf(cfg->format, 0, sf->shortened); uint32_t N_sf_1 = get_N_sf(cfg->format, 1, sf->shortened); + if (N_sf_1 == 0) { + ERROR("Invalid N_sf_1"); + return SRSRAN_ERROR; + } + uint32_t n_oc_0 = cfg->n_pucch % N_sf_1; uint32_t n_oc_1 = (N_sf_1 == 5) ? ((3 * cfg->n_pucch) % N_sf_1) : (n_oc_0 % N_sf_1); @@ -498,6 +503,11 @@ static int decode_signal_format3(srsran_pucch_t* q, uint32_t N_sf_0 = get_N_sf(cfg->format, 0, sf->shortened); uint32_t N_sf_1 = get_N_sf(cfg->format, 1, sf->shortened); + if (N_sf_1 == 0) { + ERROR("Invalid N_sf_1"); + return SRSRAN_ERROR; + } + uint32_t n_oc_0 = cfg->n_pucch % N_sf_1; uint32_t n_oc_1 = (N_sf_1 == 5) ? ((3 * cfg->n_pucch) % N_sf_1) : (n_oc_0 % N_sf_1); diff --git a/lib/src/phy/phch/pucch_nr.c b/lib/src/phy/phch/pucch_nr.c index 6c9e214e9..6dfb055eb 100644 --- a/lib/src/phy/phch/pucch_nr.c +++ b/lib/src/phy/phch/pucch_nr.c @@ -76,8 +76,7 @@ int srsran_pucch_nr_alpha_idx(const srsran_carrier_nr_t* carrier, // Generate pseudo-random sequence uint32_t cinit = cfg->hopping_id_present ? cfg->hopping_id : carrier->pci; uint8_t cs[SRSRAN_NSYMB_PER_SLOT_NR * SRSRAN_NSLOTS_PER_FRAME_NR(SRSRAN_NR_MAX_NUMEROLOGY) * 8U] = {}; - srsran_sequence_apply_bit( - cs, cs, SRSRAN_NSYMB_PER_SLOT_NR * SRSRAN_NSLOTS_PER_FRAME_NR(carrier->scs) * 8, cinit); + srsran_sequence_apply_bit(cs, cs, SRSRAN_NSYMB_PER_SLOT_NR * SRSRAN_NSLOTS_PER_FRAME_NR(carrier->scs) * 8, cinit); // Create n_cs parameter uint32_t n_cs = 0; @@ -391,11 +390,11 @@ int srsran_pucch_nr_format1_encode(const srsran_pucch_nr_t* q, } // Modulate d - cf_t d = 0; + cf_t d[1] = {}; if (nof_bits == 1) { - srsran_mod_modulate(&q->bpsk, b, &d, nof_bits); + srsran_mod_modulate(&q->bpsk, b, d, 1); } else { - srsran_mod_modulate(&q->qpsk, b, &d, nof_bits); + srsran_mod_modulate(&q->qpsk, b, d, 2); } // Get group sequence @@ -430,7 +429,7 @@ int srsran_pucch_nr_format1_encode(const srsran_pucch_nr_t* q, // Compute y = d(0) * r_uv cf_t y[SRSRAN_NRE]; - srsran_vec_sc_prod_ccc(r_uv, d, y, SRSRAN_NRE); + srsran_vec_sc_prod_ccc(r_uv, d[0], y, SRSRAN_NRE); // Get w_i_m cf_t w_i_m = srsran_pucch_nr_format1_w(q, n_pucch, resource->time_domain_occ, m); @@ -555,7 +554,12 @@ static int pucch_nr_format2_encode(srsran_pucch_nr_t* q, } // Calculate number of encoded symbols - uint32_t E = srsran_uci_nr_pucch_format_2_3_4_E(resource); + int e = srsran_uci_nr_pucch_format_2_3_4_E(resource); + if (e < SRSRAN_SUCCESS) { + ERROR("Error selecting E"); + return SRSRAN_ERROR; + } + uint32_t E = (uint32_t)e; // 6.3.2.5.1 Scrambling uint32_t cinit = pucch_nr_format2_cinit(carrier, cfg, uci_cfg); diff --git a/lib/src/phy/phch/pusch_nr.c b/lib/src/phy/phch/pusch_nr.c index 6a5cc2169..8b5d395b2 100644 --- a/lib/src/phy/phch/pusch_nr.c +++ b/lib/src/phy/phch/pusch_nr.c @@ -909,7 +909,7 @@ int srsran_pusch_nr_decode(srsran_pusch_nr_t* q, const srsran_sch_grant_nr_t* grant, srsran_chest_dl_res_t* channel, cf_t* sf_symbols[SRSRAN_MAX_PORTS], - srsran_pusch_res_nr_t data[SRSRAN_MAX_TB]) + srsran_pusch_res_nr_t* data) { // Check input pointers if (!q || !cfg || !grant || !data || !sf_symbols) { @@ -938,7 +938,12 @@ int srsran_pusch_nr_decode(srsran_pusch_nr_t* q, nof_cw += grant->tb[tb].enabled ? 1 : 0; } - uint32_t nof_re = srsran_ra_dl_nr_slot_nof_re(cfg, grant); + int e = srsran_ra_dl_nr_slot_nof_re(cfg, grant); + if (e < SRSRAN_SUCCESS) { + ERROR("Getting number of RE"); + return SRSRAN_ERROR; + } + uint32_t nof_re = (uint32_t)e; if (channel->nof_re != nof_re) { ERROR("Inconsistent number of RE (%d!=%d)", channel->nof_re, nof_re); @@ -974,9 +979,7 @@ int srsran_pusch_nr_decode(srsran_pusch_nr_t* q, // SCH decode for (uint32_t tb = 0; tb < SRSRAN_MAX_TB; tb++) { - nof_cw += grant->tb[tb].enabled ? 1 : 0; - - if (pusch_nr_decode_codeword(q, cfg, &grant->tb[tb], &data[tb], grant->rnti) < SRSRAN_SUCCESS) { + if (pusch_nr_decode_codeword(q, cfg, &grant->tb[tb], data, grant->rnti) < SRSRAN_SUCCESS) { ERROR("Error encoding TB %d", tb); return SRSRAN_ERROR; } diff --git a/lib/src/phy/phch/ra_dl.c b/lib/src/phy/phch/ra_dl.c index ae40ca1bb..999c6e4ee 100644 --- a/lib/src/phy/phch/ra_dl.c +++ b/lib/src/phy/phch/ra_dl.c @@ -702,15 +702,15 @@ uint32_t srsran_ra_dl_info(srsran_pdsch_grant_t* grant, char* info_str, uint32_t n = srsran_print_check(info_str, len, n, ", nof_prb=%d, nof_re=%d", grant->nof_prb, grant->nof_re); - n = srsran_print_check(info_str, len, n, ", tbs={", 0); + n = srsran_print_check(info_str, len, n, ", tbs={"); n = print_multi(info_str, n, len, grant, 1); - n = srsran_print_check(info_str, len, n, "}", 0); - n = srsran_print_check(info_str, len, n, ", mod={", 0); + n = srsran_print_check(info_str, len, n, "}"); + n = srsran_print_check(info_str, len, n, ", mod={"); n = print_multi(info_str, n, len, grant, 2); - n = srsran_print_check(info_str, len, n, "}", 0); - n = srsran_print_check(info_str, len, n, ", rv={", 0); + n = srsran_print_check(info_str, len, n, "}"); + n = srsran_print_check(info_str, len, n, ", rv={"); n = print_multi(info_str, n, len, grant, 0); - n = srsran_print_check(info_str, len, n, "}", 0); + n = srsran_print_check(info_str, len, n, "}"); if (grant->tx_scheme != SRSRAN_TXSCHEME_PORT0) { n = srsran_print_check(info_str, diff --git a/lib/src/phy/phch/ra_nr.c b/lib/src/phy/phch/ra_nr.c index f3137cce8..8a34ab4f7 100644 --- a/lib/src/phy/phch/ra_nr.c +++ b/lib/src/phy/phch/ra_nr.c @@ -125,7 +125,7 @@ static const float ra_nr_beta_offset_ack_table[RA_NR_BETA_OFFSET_HARQACK_SIZE] = /** * TS 38.213 V15.10.0 Table 9.3-2: Mapping of beta_offset values for CSI and the index signalled by higher layers */ -static const float ra_nr_beta_offset_csi_table[RA_NR_BETA_OFFSET_HARQACK_SIZE] = { +static const float ra_nr_beta_offset_csi_table[RA_NR_BETA_OFFSET_CSI_SIZE] = { 1.125f, 1.250f, 1.375f, 1.625f, 1.750f, 2.000f, 2.250f, 2.500f, 2.875f, 3.125f, 3.500f, 4.000f, 5.000f, 6.250f, 8.000f, 10.000f, 12.625f, 15.875f, 20.000f, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN}; @@ -138,8 +138,7 @@ static ra_nr_table_t ra_nr_select_table_pusch_noprecoding(srsran_mcs_table_t srsran_rnti_type_t rnti_type) { // Non-implemented parameters - bool mcs_c_rnti = false; - srsran_mcs_table_t configured_grant_table = srsran_mcs_table_64qam; + bool mcs_c_rnti = false; // - if mcs-Table in pusch-Config is set to 'qam256', and // - PUSCH is scheduled by a PDCCH with DCI format 0_1 with @@ -169,18 +168,18 @@ static ra_nr_table_t ra_nr_select_table_pusch_noprecoding(srsran_mcs_table_t // - mcs-Table in configuredGrantConfig is set to 'qam256', // - if PUSCH is scheduled by a PDCCH with CRC scrambled by CS-RNTI or // - if PUSCH is transmitted with configured grant - if (configured_grant_table == srsran_mcs_table_256qam && - (rnti_type == srsran_rnti_type_cs || dci_format == srsran_dci_format_nr_cg)) { - return ra_nr_table_2; - } + // if (configured_grant_table == srsran_mcs_table_256qam && + // (rnti_type == srsran_rnti_type_cs || dci_format == srsran_dci_format_nr_cg)) { + // return ra_nr_table_2; + // } // - mcs-Table in configuredGrantConfig is set to 'qam64LowSE' // - if PUSCH is scheduled by a PDCCH with CRC scrambled by CS-RNTI or // - if PUSCH is transmitted with configured grant, - if (configured_grant_table == srsran_mcs_table_qam64LowSE && - (rnti_type == srsran_rnti_type_cs || dci_format == srsran_dci_format_nr_cg)) { - return ra_nr_table_3; - } + // if (configured_grant_table == srsran_mcs_table_qam64LowSE && + // (rnti_type == srsran_rnti_type_cs || dci_format == srsran_dci_format_nr_cg)) { + // return ra_nr_table_3; + // } return ra_nr_table_1; } @@ -191,8 +190,8 @@ static ra_nr_table_t ra_nr_select_table_pdsch(srsran_mcs_table_t mcs_tab srsran_rnti_type_t rnti_type) { // Non-implemented parameters - bool sps_config_mcs_table_present = false; - bool is_pdcch_sps = false; + bool sps_config_mcs_table_present = false; + bool is_pdcch_sps = false; // - the higher layer parameter mcs-Table given by PDSCH-Config is set to 'qam256', and // - the PDSCH is scheduled by a PDCCH with DCI format 1_1 with @@ -460,8 +459,6 @@ int srsran_ra_nr_fill_tb(const srsran_sch_cfg_nr_t* pdsch_cfg, uint32_t mcs_idx, srsran_sch_tb_t* tb) { - uint32_t cw_idx = 0; - // Get target Rate double R = srsran_ra_nr_R_from_mcs( pdsch_cfg->sch_cfg.mcs_table, grant->dci_format, grant->dci_search_space, grant->rnti_type, mcs_idx); @@ -505,11 +502,10 @@ int srsran_ra_nr_fill_tb(const srsran_sch_cfg_nr_t* pdsch_cfg, return SRSRAN_ERROR; } - // Calculate number of layers accordingly + // Calculate number of layers accordingly, assumes first codeword only uint32_t nof_cw = grant->nof_layers < 5 ? 1 : 2; uint32_t nof_layers_cw1 = grant->nof_layers / nof_cw; - uint32_t nof_layers_cw2 = grant->nof_layers - nof_layers_cw1; - tb->N_L = (cw_idx == 0) ? nof_layers_cw1 : nof_layers_cw2; + tb->N_L = nof_layers_cw1; // Check DMRS and CSI-RS collision according to TS 38.211 7.4.1.5.3 Mapping to physical resources // If there was a collision, the number of RE in the grant would be wrong @@ -825,7 +821,7 @@ static float ra_ul_beta_offset_ack_semistatic(const srsran_beta_offsets_t* beta_ } // Protect table boundary - if (beta_offset_index > RA_NR_BETA_OFFSET_HARQACK_SIZE) { + if (beta_offset_index >= RA_NR_BETA_OFFSET_HARQACK_SIZE) { ERROR("Beta offset index for HARQ-ACK (%d) for O_ack=%d exceeds table size (%d)", beta_offset_index, uci_cfg->o_ack, @@ -850,8 +846,15 @@ static float ra_ul_beta_offset_csi_semistatic(const srsran_beta_offsets_t* beta_ return fix_beta_offset; } + int O_csi1 = srsran_csi_part1_nof_bits(uci_cfg->csi, uci_cfg->nof_csi); + int O_csi2 = srsran_csi_part2_nof_bits(uci_cfg->csi, uci_cfg->nof_csi); + if (O_csi1 < SRSRAN_SUCCESS || O_csi2 < SRSRAN_SUCCESS) { + ERROR("Invalid O_csi1 (%d) or O_csi2(%d)", O_csi1, O_csi2); + return NAN; + } + // Calculate number of CSI bits; CSI part 2 is not supported. - uint32_t O_csi = part2 ? 0 : srsran_csi_part1_nof_bits(uci_cfg->csi, uci_cfg->nof_csi); + uint32_t O_csi = (uint32_t)(part2 ? O_csi2 : O_csi1); // Select Beta Offset index from the number of HARQ-ACK bits uint32_t beta_offset_index = part2 ? beta_offsets->csi2_index1 : beta_offsets->csi1_index1; @@ -860,7 +863,7 @@ static float ra_ul_beta_offset_csi_semistatic(const srsran_beta_offsets_t* beta_ } // Protect table boundary - if (beta_offset_index > RA_NR_BETA_OFFSET_CSI_SIZE) { + if (beta_offset_index >= RA_NR_BETA_OFFSET_CSI_SIZE) { ERROR("Beta offset index for CSI (%d) for O_csi=%d exceeds table size (%d)", beta_offset_index, O_csi, diff --git a/lib/src/phy/phch/ra_sl.c b/lib/src/phy/phch/ra_sl.c index f597d266a..b2f17d30e 100644 --- a/lib/src/phy/phch/ra_sl.c +++ b/lib/src/phy/phch/ra_sl.c @@ -43,7 +43,7 @@ int srsran_pscch_resources(uint32_t prb_num, } } - if (L == 0) { + if (L < 2) { // ERROR("Invalid PSCCH subframe bitmap"); return SRSRAN_ERROR; } @@ -121,7 +121,7 @@ int srsran_ra_sl_pssch_allowed_sf(uint32_t pssch_sf_idx, uint32_t trp_idx, uint3 int srsran_sci_generate_trp_idx(uint32_t duplex_mode, uint32_t tdd_config, uint32_t k_TRP) { - int retval = SRSRAN_ERROR; + int retval = SRSRAN_ERROR; struct timeval tv; gettimeofday(&tv, NULL); srsran_random_t random = srsran_random_init(tv.tv_usec); @@ -190,8 +190,7 @@ int srsran_sci_generate_trp_idx(uint32_t duplex_mode, uint32_t tdd_config, uint3 retval = srsran_sl_N_TRP_6_k_6[srsran_random_uniform_int_dist(random, 0, sizeof(srsran_sl_N_TRP_6_k_6) - 1)]; break; } - } - else { + } else { retval = SRSRAN_SUCCESS; } diff --git a/lib/src/phy/phch/ra_ul_nr.c b/lib/src/phy/phch/ra_ul_nr.c index 72f42e509..5be5f7681 100644 --- a/lib/src/phy/phch/ra_ul_nr.c +++ b/lib/src/phy/phch/ra_ul_nr.c @@ -51,7 +51,7 @@ int srsran_ra_ul_nr_pusch_time_resource_default_A(uint32_t scs_cfg, uint32_t m, return SRSRAN_ERROR_INVALID_INPUTS; } - if (scs_cfg > 4) { + if (scs_cfg >= 4) { ERROR("Invalid numerology (%d)", scs_cfg); return SRSRAN_ERROR; } diff --git a/lib/src/phy/phch/sch.c b/lib/src/phy/phch/sch.c index 46f1b8f76..0968ac41a 100644 --- a/lib/src/phy/phch/sch.c +++ b/lib/src/phy/phch/sch.c @@ -249,7 +249,12 @@ static int encode_tb_off(srsran_sch_t* q, if (cb_segm->C > softbuffer->max_cb) { ERROR("Error number of CB to encode (%d) exceeds soft buffer size (%d CBs)", cb_segm->C, softbuffer->max_cb); - return -1; + return SRSRAN_ERROR; + } + + if (Qm == 0) { + ERROR("Invalid Qm"); + return SRSRAN_ERROR; } uint32_t Gp = nof_e_bits / Qm; @@ -499,7 +504,7 @@ static int decode_tb(srsran_sch_t* q, int16_t* e_bits, uint8_t* data) { - if (q != NULL && data != NULL && softbuffer != NULL && e_bits != NULL && cb_segm != NULL) { + if (q != NULL && data != NULL && softbuffer != NULL && e_bits != NULL && cb_segm != NULL && Qm != 0) { if (cb_segm->tbs == 0 || cb_segm->C == 0) { return SRSRAN_SUCCESS; } @@ -547,11 +552,12 @@ static int decode_tb(srsran_sch_t* q, return SRSRAN_ERROR; } } else { - ERROR("Missing inputs: data=%d, softbuffer=%d, e_bits=%d, cb_segm=%d", + ERROR("Missing inputs: data=%d, softbuffer=%d, e_bits=%d, cb_segm=%d Qm=%d", data != 0, softbuffer != 0, e_bits != 0, - cb_segm != 0); + cb_segm != 0, + Qm); return SRSRAN_ERROR_INVALID_INPUTS; } } @@ -1018,6 +1024,11 @@ static int uci_decode_ri_ack(srsran_sch_t* q, uint32_t nb_q = cfg->grant.tb.nof_bits; uint32_t Qm = srsran_mod_bits_x_symbol(cfg->grant.tb.mod); + if (Qm == 0) { + ERROR("Invalid modulation %s", srsran_mod_string(cfg->grant.tb.mod)); + return SRSRAN_ERROR; + } + // If there is RI and CQI, assume RI = 1 for the purpose of RI/ACK decoding (3GPP 36.212 Clause 5.2.4.1. ) if (cfg->uci_cfg.cqi.data_enable) { if (cfg->uci_cfg.cqi.type == SRSRAN_CQI_TYPE_SUBBAND_HL && cfg->uci_cfg.cqi.ri_len) { @@ -1031,7 +1042,12 @@ static int uci_decode_ri_ack(srsran_sch_t* q, if (srsran_uci_cfg_total_ack(&cfg->uci_cfg) > 0) { float beta = get_beta_harq_offset(cfg->uci_offset.I_offset_ack); if (cfg->grant.tb.tbs == 0) { - beta /= get_beta_cqi_offset(cfg->uci_offset.I_offset_cqi); + float beta_cqi = get_beta_cqi_offset(cfg->uci_offset.I_offset_cqi); + if (!isnormal(beta_cqi)) { + ERROR("Invalid beta_cqi (%d, %f)", cfg->uci_offset.I_offset_cqi, beta_cqi); + return SRSRAN_ERROR; + } + beta /= beta_cqi; } ret = srsran_uci_decode_ack_ri(cfg, q_bits, @@ -1059,7 +1075,12 @@ static int uci_decode_ri_ack(srsran_sch_t* q, if (cfg->uci_cfg.cqi.ri_len > 0) { float beta = get_beta_ri_offset(cfg->uci_offset.I_offset_ri); if (cfg->grant.tb.tbs == 0) { - beta /= get_beta_cqi_offset(cfg->uci_offset.I_offset_cqi); + float beta_cqi = get_beta_cqi_offset(cfg->uci_offset.I_offset_cqi); + if (!isnormal(beta_cqi)) { + ERROR("Invalid beta_cqi (%d, %f)", cfg->uci_offset.I_offset_cqi, beta_cqi); + return SRSRAN_ERROR; + } + beta /= beta_cqi; } ret = srsran_uci_decode_ack_ri(cfg, q_bits, diff --git a/lib/src/phy/phch/sch_nr.c b/lib/src/phy/phch/sch_nr.c index 06ec1284f..fd86f0b3b 100644 --- a/lib/src/phy/phch/sch_nr.c +++ b/lib/src/phy/phch/sch_nr.c @@ -680,7 +680,11 @@ static int sch_nr_decode(srsran_sch_nr_t* q, } // Set average number of iterations - res->avg_iter = (float)nof_iter_sum / (float)cfg.C; + if (cfg.C > 0) { + res->avg_iter = (float)nof_iter_sum / (float)cfg.C; + } else { + res->avg_iter = NAN; + } if (SRSRAN_DEBUG_ENABLED && srsran_verbose >= SRSRAN_VERBOSE_DEBUG && !handler_registered) { DEBUG("Decode: "); diff --git a/lib/src/phy/phch/uci.c b/lib/src/phy/phch/uci.c index 503c9df33..f2545fb1e 100644 --- a/lib/src/phy/phch/uci.c +++ b/lib/src/phy/phch/uci.c @@ -424,6 +424,11 @@ static uint32_t Q_prime_ri_ack(srsran_pusch_cfg_t* cfg, uint32_t O, uint32_t O_c } } + if (K == 0) { + ERROR("K is zero!"); + return 0; + } + uint32_t x = (uint32_t)ceilf((float)O * cfg->grant.L_prb * SRSRAN_NRE * cfg->grant.nof_symb * beta / K); uint32_t Q_prime = SRSRAN_MIN(x, 4 * cfg->grant.L_prb * SRSRAN_NRE); diff --git a/lib/src/phy/phch/uci_nr.c b/lib/src/phy/phch/uci_nr.c index b587a45d9..2968d173d 100644 --- a/lib/src/phy/phch/uci_nr.c +++ b/lib/src/phy/phch/uci_nr.c @@ -1097,13 +1097,13 @@ int srsran_uci_nr_decode_pusch_ack(srsran_uci_nr_t* q, int8_t* llr, srsran_uci_value_nr_t* value) { - int A = cfg->o_ack; - // Check inputs if (q == NULL || cfg == NULL || llr == NULL || value == NULL) { return SRSRAN_ERROR_INVALID_INPUTS; } + int A = cfg->o_ack; + // 6.3.2.1 UCI bit sequence generation // 6.3.2.1.1 HARQ-ACK bool has_csi_part2 = srsran_csi_has_part2(cfg->csi, cfg->nof_csi);