From 0299e9aae129dcc8a6636042e43df2952ce4d05a Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Wed, 31 Jan 2018 10:18:04 +0100 Subject: [PATCH 1/2] Fixed Aperiodic reporting RM31 for TM4 (Amarisoft proof) --- lib/include/srslte/phy/phch/cqi.h | 1 + lib/src/phy/phch/cqi.c | 10 ++++- srsenb/src/phy/phch_worker.cc | 4 +- srsue/src/phy/phch_worker.cc | 61 ++++++++++++++++++------------- 4 files changed, 47 insertions(+), 29 deletions(-) diff --git a/lib/include/srslte/phy/phch/cqi.h b/lib/include/srslte/phy/phch/cqi.h index f1f7eb03c..b8cc80ece 100644 --- a/lib/include/srslte/phy/phch/cqi.h +++ b/lib/include/srslte/phy/phch/cqi.h @@ -43,6 +43,7 @@ #define SRSLTE_CQI_MAX_BITS 64 #define SRSLTE_DIF_CQI_MAX_BITS 3 #define SRSLTE_PMI_MAX_BITS 4 +#define SRSLTE_CQI_STR_MAX_CHAR 32 typedef struct { bool configured; diff --git a/lib/src/phy/phch/cqi.c b/lib/src/phy/phch/cqi.c index a115bcd28..3d8c3e27d 100644 --- a/lib/src/phy/phch/cqi.c +++ b/lib/src/phy/phch/cqi.c @@ -456,8 +456,16 @@ int srslte_cqi_hl_get_no_subbands(int nof_prb) void srslte_cqi_to_str(const uint8_t *cqi_value, int cqi_len, char *str, int str_len) { int i = 0; - for (i = 0; i < cqi_len && i < (str_len - 1); i++) { + + for (i = 0; i < cqi_len && i < (str_len - 5); i++) { str[i] = (cqi_value[i] == 0)?(char)'0':(char)'1'; } + + if (i == (str_len - 5)) { + str[i++] = '.'; + str[i++] = '.'; + str[i++] = '.'; + str[i++] = (cqi_value[cqi_len - 1] == 0)?(char)'0':(char)'1'; + } str[i] = '\0'; } diff --git a/srsenb/src/phy/phch_worker.cc b/srsenb/src/phy/phch_worker.cc index cffc02d22..11c80ca8d 100644 --- a/srsenb/src/phy/phch_worker.cc +++ b/srsenb/src/phy/phch_worker.cc @@ -551,7 +551,7 @@ int phch_worker::decode_pusch(srslte_enb_ul_pusch_t *grants, uint32_t nof_pusch) ue_db[rnti].phich_info.n_prb_lowest = enb_ul.pusch_cfg.grant.n_prb_tilde[0]; ue_db[rnti].phich_info.n_dmrs = phy_grant.ncs_dmrs; - char cqi_str[64]; + char cqi_str[SRSLTE_CQI_STR_MAX_CHAR]; if (cqi_enabled) { if (ue_db[rnti].cqi_en) { wideband_cqi_value = cqi_value.wideband.wideband_cqi; @@ -578,7 +578,7 @@ int phch_worker::decode_pusch(srslte_enb_ul_pusch_t *grants, uint32_t nof_pusch) cqi_value.subband_hl.wideband_cqi_cw0, cqi_value.subband_hl.N); } } - srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, 64); + srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); //snprintf(cqi_str, 64, ", cqi=%s", wideband_cqi_value); } diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index df0d3f458..b4ff72132 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -399,13 +399,14 @@ void phch_worker::compute_ri(uint8_t *ri, uint8_t *pmi, float *sinr) { Debug("TM3 RI select %d layers, κ=%fdB\n", (*ri) + 1, cn); } else { /* If only one receiving antenna, force RI for 1 layer */ - uci_data.uci_ri = 0; + if (ri) { + *ri = 0; + } } uci_data.uci_ri_len = 1; } else if (phy->config->dedicated.antenna_info_explicit_value.tx_mode == LIBLTE_RRC_TRANSMISSION_MODE_4) { srslte_ue_dl_ri_pmi_select(&ue_dl, ri, pmi, sinr); Debug("TM4 ri=%d; pmi=%d; SINR=%.1fdB\n", ue_dl.ri, ue_dl.pmi[ue_dl.ri], 10*log10f(ue_dl.sinr[ue_dl.ri][ue_dl.pmi[ue_dl.ri]])); - uci_data.uci_ri_len = 1; } } @@ -906,11 +907,11 @@ void phch_worker::set_uci_aperiodic_cqi() { uint8_t ri = (uint8_t) ue_dl.ri; uint8_t pmi = (uint8_t) ue_dl.pmi[ri]; - float sinr = ue_dl.sinr[ri][pmi]; + float sinr_db = ue_dl.sinr[ri][pmi]; if (phy->config->dedicated.cqi_report_cnfg.report_mode_aperiodic_present) { /* Compute RI, PMI and SINR */ - compute_ri(&ri, &pmi, &sinr); + compute_ri(&ri, &pmi, &sinr_db); switch(phy->config->dedicated.cqi_report_cnfg.report_mode_aperiodic) { case LIBLTE_RRC_CQI_REPORT_MODE_APERIODIC_RM30: @@ -930,18 +931,24 @@ void phch_worker::set_uci_aperiodic_cqi() // TODO: implement subband CQI properly cqi_report.subband_hl.subband_diff_cqi_cw0 = 0; // Always report zero offset on all subbands - cqi_report.subband_hl.N = (cell.nof_prb > 7) ? srslte_cqi_hl_get_no_subbands(cell.nof_prb) : 0; + cqi_report.subband_hl.N = (cell.nof_prb > 7) ? (uint32_t) srslte_cqi_hl_get_no_subbands(cell.nof_prb) : 0; - uci_data.uci_cqi_len = srslte_cqi_value_pack(&cqi_report, uci_data.uci_cqi); + int cqi_len = srslte_cqi_value_pack(&cqi_report, uci_data.uci_cqi); + if (cqi_len < 0) { + Error("Error packing CQI value (Aperiodic reporting mode RM31)."); + return; + } + uci_data.uci_cqi_len = (uint32_t) cqi_len; - char cqi_str[64] = {0}; - srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, 64); + char cqi_str[SRSLTE_CQI_STR_MAX_CHAR] = {0}; + srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); - Info("PUSCH: Aperiodic CQI=%s, SNR=%.1f dB, for %d subbands\n", cqi_str, phy->avg_snr_db, cqi_report.subband_hl.N); + /* Set RI = 1 */ + uci_data.uci_ri = ri; + uci_data.uci_ri_len = 1; - /* Fake RI = 1 */ - uci_data.uci_ri = 0; - uci_data.uci_ri_len = 0; + Info("PUSCH: Aperiodic RM30 ri%s, CQI=%s, SNR=%.1f dB, for %d subbands\n", + (uci_data.uci_ri == 0)?"=1":"~1", cqi_str, phy->avg_snr_db, cqi_report.subband_hl.N); } break; case LIBLTE_RRC_CQI_REPORT_MODE_APERIODIC_RM31: @@ -957,11 +964,6 @@ void phch_worker::set_uci_aperiodic_cqi() other transmission modes they are reported conditioned on rank 1. */ if (rnti_is_set) { - /* Select RI, PMI and SINR */ - uint32_t ri = ue_dl.ri; // Select RI (0: 1 layer, 1: 2 layer, otherwise: not implemented) - uint32_t pmi = ue_dl.pmi[ri]; // Select PMI - float sinr_db = 10 * log10(ue_dl.sinr[ri][pmi]); - /* Fill CQI Report */ srslte_cqi_value_t cqi_report = {0}; cqi_report.type = SRSLTE_CQI_TYPE_SUBBAND_HL; @@ -982,17 +984,24 @@ void phch_worker::set_uci_aperiodic_cqi() // TODO: implement subband CQI properly cqi_report.subband_hl.N = (uint32_t) ((cell.nof_prb > 7) ? srslte_cqi_hl_get_no_subbands(cell.nof_prb) : 0); - uci_data.uci_cqi_len = srslte_cqi_value_pack(&cqi_report, uci_data.uci_cqi); + int cqi_len = srslte_cqi_value_pack(&cqi_report, uci_data.uci_cqi); + if (cqi_len < 0) { + Error("Error packing CQI value (Aperiodic reporting mode RM31)."); + return; + } + uci_data.uci_cqi_len = (uint32_t) cqi_len; + uci_data.uci_ri_len = 1; + uci_data.uci_ri = ri; - char cqi_str[64] = {0}; - srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, 64); + char cqi_str[SRSLTE_CQI_STR_MAX_CHAR] = {0}; + srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); if (cqi_report.subband_hl.rank_is_not_one) { - Info("PUSCH: Aperiodic ri~1, CQI=%02d/%02d, SINR=%2.1f/%2.1fdB, pmi=%d for %d subbands\n", + Info("PUSCH: Aperiodic RM31 ri~1, CQI=%02d/%02d, SINR=%2.1f/%2.1fdB, pmi=%d for %d subbands\n", cqi_report.subband_hl.wideband_cqi_cw0, cqi_report.subband_hl.wideband_cqi_cw1, sinr_db, sinr_db, pmi, cqi_report.subband_hl.N); } else { - Info("PUSCH: Aperiodic ri=1, CQI=%02d, SINR=%2.1f, pmi=%d for %d subbands\n", + Info("PUSCH: Aperiodic RM31 ri=1, CQI=%02d, SINR=%2.1f, pmi=%d for %d subbands\n", cqi_report.subband_hl.wideband_cqi_cw0, sinr_db, pmi, cqi_report.subband_hl.N); } @@ -1060,8 +1069,8 @@ void phch_worker::encode_pusch(srslte_ra_ul_grant_t *grant, uint8_t *payload, ui snprintf(timestr, 64, ", tot_time=%4d us", (int) logtime_start[0].tv_usec); #endif - char cqi_str[32] = ""; - srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, 32); + char cqi_str[SRSLTE_CQI_STR_MAX_CHAR] = ""; + srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); uint8_t dummy[2] = {0,0}; log_h->info("PUSCH: tti_tx=%d, alloc=(%d,%d), tbs=%d, mcs=%d, rv=%d%s%s%s, cfo=%.1f KHz%s%s%s\n", @@ -1114,8 +1123,8 @@ void phch_worker::encode_pucch() float tx_power = srslte_ue_ul_pucch_power(&ue_ul, phy->pathloss, ue_ul.last_pucch_format, uci_data.uci_cqi_len, uci_data.uci_ack_len); float gain = set_power(tx_power); - char str_cqi[32] = ""; - srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, str_cqi, 32); + char str_cqi[SRSLTE_CQI_STR_MAX_CHAR] = ""; + srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, str_cqi, SRSLTE_CQI_STR_MAX_CHAR); Info("PUCCH: tti_tx=%d, n_pucch=%d, n_prb=%d, ack=%s%s%s%s%s, sr=%s, cfo=%.1f KHz%s\n", (tti + 4) % 10240, From c4247c7aca16e6337acb698d57c0958ae88db755 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Wed, 31 Jan 2018 10:44:52 +0100 Subject: [PATCH 2/2] Fix coverity for complex 16bit --- lib/include/srslte/config.h | 3 +++ lib/include/srslte/phy/utils/simd.h | 5 ++++- lib/include/srslte/phy/utils/vector_simd.h | 2 ++ lib/src/phy/utils/vector_simd.c | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/include/srslte/config.h b/lib/include/srslte/config.h index 8a988a971..1e9d27aac 100644 --- a/lib/include/srslte/config.h +++ b/lib/include/srslte/config.h @@ -59,6 +59,9 @@ // cf_t definition typedef _Complex float cf_t; + +#ifdef ENABLE_C16 typedef _Complex short int c16_t; +#endif /* ENABLE_C16 */ #endif // CONFIG_H diff --git a/lib/include/srslte/phy/utils/simd.h b/lib/include/srslte/phy/utils/simd.h index 7ea203290..e22a9ef09 100644 --- a/lib/include/srslte/phy/utils/simd.h +++ b/lib/include/srslte/phy/utils/simd.h @@ -150,7 +150,10 @@ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ - +#ifndef ENABLE_C16 +#undef SRSLTE_SIMD_C16_SIZE +#define SRSLTE_SIMD_C16_SIZE 0 +#endif /* ENABLE_C16 */ #if SRSLTE_SIMD_F_SIZE diff --git a/lib/include/srslte/phy/utils/vector_simd.h b/lib/include/srslte/phy/utils/vector_simd.h index 31725edb3..49268ca43 100644 --- a/lib/include/srslte/phy/utils/vector_simd.h +++ b/lib/include/srslte/phy/utils/vector_simd.h @@ -106,7 +106,9 @@ SRSLTE_API cf_t srslte_vec_dot_prod_conj_ccc_simd(const cf_t *x, const cf_t *y, SRSLTE_API cf_t srslte_vec_dot_prod_ccc_simd(const cf_t *x, const cf_t *y, const int len); +#ifdef ENABLE_C16 SRSLTE_API c16_t srslte_vec_dot_prod_ccc_c16i_simd(const c16_t *x, const c16_t *y, const int len); +#endif /* ENABLE_C16 */ SRSLTE_API int srslte_vec_dot_prod_sss_simd(const int16_t *x, const int16_t *y, const int len); diff --git a/lib/src/phy/utils/vector_simd.c b/lib/src/phy/utils/vector_simd.c index 024b3849f..df8a1ea4e 100644 --- a/lib/src/phy/utils/vector_simd.c +++ b/lib/src/phy/utils/vector_simd.c @@ -433,6 +433,7 @@ cf_t srslte_vec_dot_prod_ccc_simd(const cf_t *x, const cf_t *y, const int len) { return result; } +#ifdef ENABLE_C16 c16_t srslte_vec_dot_prod_ccc_c16i_simd(const c16_t *x, const c16_t *y, const int len) { int i = 0; c16_t result = 0; @@ -460,6 +461,7 @@ c16_t srslte_vec_dot_prod_ccc_c16i_simd(const c16_t *x, const c16_t *y, const in return result; } +#endif /* ENABLE_C16 */ cf_t srslte_vec_dot_prod_conj_ccc_simd(const cf_t *x, const cf_t *y, const int len) { @@ -620,6 +622,7 @@ void srslte_vec_prod_ccc_split_simd(const float *a_re, const float *a_im, const } } +#ifdef ENABLE_C16 void srslte_vec_prod_ccc_c16_simd(const int16_t *a_re, const int16_t *a_im, const int16_t *b_re, const int16_t *b_im, int16_t *r_re, int16_t *r_im, const int len) { int i = 0; @@ -652,6 +655,7 @@ void srslte_vec_prod_ccc_c16_simd(const int16_t *a_re, const int16_t *a_im, cons r_im[i] = a_re[i]*b_im[i] + a_im[i]*b_re[i]; } } +#endif /* ENABLE_C16 */ void srslte_vec_prod_conj_ccc_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len) { int i = 0;