From 93053701a40ecbb6b983d8b444934b13cdc0e7d6 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 8 Jan 2018 10:47:20 +0100 Subject: [PATCH 1/6] fix and enable NAS test --- srsue/test/upper/CMakeLists.txt | 5 +- srsue/test/upper/nas_test.cc | 197 +++++++++++++++++++------------- 2 files changed, 120 insertions(+), 82 deletions(-) diff --git a/srsue/test/upper/CMakeLists.txt b/srsue/test/upper/CMakeLists.txt index cbffe1cc8..00fb54576 100644 --- a/srsue/test/upper/CMakeLists.txt +++ b/srsue/test/upper/CMakeLists.txt @@ -26,7 +26,10 @@ add_executable(rrc_reconfig_test rrc_reconfig_test.cc) target_link_libraries(rrc_reconfig_test srsue_upper srslte_upper srslte_phy) add_test(rrc_reconfig_test rrc_reconfig_test) - +add_executable(nas_test nas_test.cc) +target_link_libraries(nas_test srsue_upper srslte_upper srslte_phy) +add_test(nas_test nas_test) + ######################################################################## # Option to run command after build (useful for remote builds) ######################################################################## diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index 6aa9f29e5..3e8cfaccb 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -25,35 +25,37 @@ */ #include +#include #include "upper/usim.h" #include "upper/nas.h" #include "srslte/upper/rlc.h" #include "upper/rrc.h" #include "mac/mac.h" +#include "srslte/common/log_filter.h" #include "srslte/upper/pdcp_entity.h" #include "srslte/upper/pdcp.h" -#include "srslte/common/log_stdout.h" #include "srslte/interfaces/ue_interfaces.h" +#include "srslte/common/bcd_helpers.h" -using namespace srsue; +using namespace srsue; +#define LCID 1 -uint8_t pdu1[] = { -0x03, 0x22, 0x16, 0x15, 0xe8 , 0x00 , 0x00 , 0x03 , 0x13 , 0xb0 , 0x00 , 0x02 , 0x90 , 0x08, -0x79, 0xf0, 0x00, 0x00, 0x40 , 0xb5 , 0x01 , 0x25 , 0x40 , 0xcc , 0x1d , 0x08 , 0x04 , 0x3c , 0x18 , 0x00, -0x4c, 0x02, 0x20, 0x0f, 0xa8 , 0x00 , 0x65 , 0x48 , 0x07 , 0x04 , 0x04 , 0x24 , 0x1c , 0x19 , 0x05 , 0x41, -0x39, 0x39, 0x4d, 0x38, 0x14 , 0x04 , 0x28 , 0xd1 , 0x5e , 0x6d , 0x78 , 0x13 , 0xfb , 0xf9 , 0x01 , 0xb1, -0x40, 0x2f, 0xd8, 0x4c, 0x02 , 0x20 , 0x00 , 0x5b , 0x78 , 0x00 , 0x07 , 0xa1 , 0x25 , 0xa9 , 0xc1 , 0x3f, -0xd9, 0x40, 0x41, 0xf5, 0x1b , 0x58 , 0x2f , 0x27 , 0x28 , 0xa0 , 0xed , 0xde , 0x54 , 0x43 , 0x48 , 0xc0, -0x56, 0xcc, 0x00, 0x02, 0x84 , 0x00 , 0x42 , 0x0a , 0xf1 , 0x63 }; +uint8_t auth_request_pdu[] = { 0x07, 0x52, 0x01, 0x17, 0xf2, 0x2b, 0x2b, 0xaa, 0x2c, 0x53, + 0x52, 0xf1, 0xaf, 0x2e, 0x2f, 0x6f, 0x72, 0xd0, 0x54, 0x10, + 0x18, 0xee, 0x79, 0x35, 0x25, 0x3b, 0x90, 0x01, 0x17, 0xe3, + 0x09, 0x18, 0xee, 0x3b, 0xa5, 0x24 }; -uint32_t PDU1_LEN = 104; +uint8_t sec_mode_command_pdu[] = { 0x37, 0x45, 0x62, 0x29, 0xdf, 0x00, 0x07, 0x5d, 0x02, 0x01, + 0x02, 0x80, 0xe0, 0xc1 }; +uint16 mcc = 61441; +uint16 mnc = 65281; -#define LCID 3 +using namespace srslte; -namespace srsue { +namespace srslte { // fake classes class pdcp_dummy : public rrc_interface_pdcp @@ -63,121 +65,154 @@ public: void write_pdu_bcch_bch(byte_buffer_t *pdu) {} void write_pdu_bcch_dlsch(byte_buffer_t *pdu) {} void write_pdu_pcch(byte_buffer_t *pdu) {} + std::string get_rb_name(uint32_t lcid) { return std::string("lcid"); } }; - - class rrc_dummy : public rrc_interface_nas { public: void write_sdu(uint32_t lcid, byte_buffer_t *sdu) { - + printf("NAS generated SDU (len=%d):\n", sdu->N_bytes); + last_sdu_len = sdu->N_bytes; + srslte_vec_fprint_byte(stdout, sdu->msg, sdu->N_bytes); } + std::string get_rb_name(uint32_t lcid) { return std::string("lcid"); } + uint32_t get_last_sdu_len() { return last_sdu_len; } - uint16_t get_mcc() { return 0x11; } - uint16_t get_mnc() { return 0xff; } - void enable_capabilities() { + void plmn_search() {}; + void plmn_select(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id) {}; - } + uint16_t get_mcc() { return mcc; } + uint16_t get_mnc() { return mnc; } + void enable_capabilities() {} + +private: + uint32_t last_sdu_len; }; class gw_dummy : public gw_interface_nas, public gw_interface_pdcp { - error_t setup_if_addr(uint32_t ip_addr, char *err_str) {} + error_t setup_if_addr(uint32_t ip_addr, char *err_str) { return ERROR_NONE; } void write_pdu(uint32_t lcid, byte_buffer_t *pdu) {} }; } -class usim_dummy : public usim_interface_nas -{ - void get_imsi_vec(uint8_t* imsi_, uint32_t n){ - - } - void get_imei_vec(uint8_t* imei_, uint32_t n){ - - } - void generate_authentication_response(uint8_t *rand, - uint8_t *autn_enb, - uint16_t mcc, - uint16_t mnc, - bool *net_valid, - uint8_t *res){ - - } - - - void generate_nas_keys(uint8_t *k_nas_enc, - uint8_t *k_nas_int, - CIPHERING_ALGORITHM_ID_ENUM cipher_algo, - INTEGRITY_ALGORITHM_ID_ENUM integ_algo){ - - } -}; - - - - -int main(int argc, char **argv) +int security_command_test() { - srslte::log_stdout nas_log("NAS"); - srslte::log_stdout pdcp_entity_log("PDCP"); - srslte::log_stdout rrc_log("RRC"); - srslte::log_stdout mac_log("MAC"); - + int ret = SRSLTE_ERROR; + srslte::log_filter nas_log("NAS"); + srslte::log_filter rrc_log("RRC"); + srslte::log_filter mac_log("MAC"); + srslte::log_filter usim_log("USIM"); nas_log.set_level(srslte::LOG_LEVEL_DEBUG); - pdcp_entity_log.set_level(srslte::LOG_LEVEL_DEBUG); rrc_log.set_level(srslte::LOG_LEVEL_DEBUG); - nas_log.set_hex_limit(100000); rrc_log.set_hex_limit(100000); - usim_dummy usim; rrc_dummy rrc_dummy; gw_dummy gw; - pdcp_dummy pdcp_dummy; - + usim_args_t args; + args.algo = "xor"; + args.amf = "9001"; + args.imei = "353490069873319"; + args.imsi = "001010123456789"; + args.k = "00112233445566778899aabbccddeeff"; + args.op = "63BFA50EE6523365FF14C1F45F88737D"; + // init USIM + srsue::usim usim; + bool net_valid; + uint8_t res[16]; + usim.init(&args, &usim_log); - buffer_pool *pool; - pool = buffer_pool::get_instance(); + srslte::byte_buffer_pool *pool; + pool = byte_buffer_pool::get_instance(); srsue::nas nas; - nas.init(&usim, &rrc_dummy, &gw, &nas_log); + srslte_nas_config_t cfg; + nas.init(&usim, &rrc_dummy, &gw, &nas_log, cfg); + // push auth request PDU to NAS to generate security context + byte_buffer_t* tmp = pool->allocate(); + memcpy(tmp->msg, auth_request_pdu, sizeof(auth_request_pdu)); + tmp->N_bytes = sizeof(auth_request_pdu); + nas.write_pdu(LCID, tmp); + // TODO: add check for authentication response + // reuse buffer for security mode command + memcpy(tmp->msg, sec_mode_command_pdu, sizeof(sec_mode_command_pdu)); + tmp->N_bytes = sizeof(sec_mode_command_pdu); + nas.write_pdu(LCID, tmp); - byte_buffer_t* tmp = pool_allocate; - memcpy(tmp->msg, &pdu1[0], PDU1_LEN); - tmp->N_bytes = PDU1_LEN; + // check length of generated NAS SDU + if (rrc_dummy.get_last_sdu_len() > 3) { + ret = SRSLTE_SUCCESS; + } - //byte_buffer_t tmp2; - //memcpy(tmp2.msg, &pdu1[0], PDU1_LEN); - //tmp2.N_bytes = PDU1_LEN; + pool->cleanup(); - //srsue::mac mac; - //mac.init(NULL, NULL, NULL, &mac_log); + return ret; +} - srsue::rrc rrc; - rrc.init(NULL, NULL, NULL, NULL, &nas, NULL, NULL, &rrc_log); - //rrc.init(&phy, &mac, &rlc, &pdcp, &nas, &usim, &mac, &rrc_log); +int mme_attach_request_test() +{ + int ret = SRSLTE_ERROR; + srslte::log_filter nas_log("NAS"); + srslte::log_filter rrc_log("RRC"); + srslte::log_filter mac_log("MAC"); + srslte::log_filter usim_log("USIM"); - srsue::pdcp_entity pdcp_entity; - pdcp_entity.init(NULL, &rrc, &gw, &pdcp_entity_log, RB_ID_SRB1, NULL); + nas_log.set_level(srslte::LOG_LEVEL_DEBUG); + rrc_log.set_level(srslte::LOG_LEVEL_DEBUG); + nas_log.set_hex_limit(100000); + rrc_log.set_hex_limit(100000); - pdcp_entity.write_pdu(tmp); + rrc_dummy rrc_dummy; + gw_dummy gw; + srsue::usim usim; + usim_args_t args; + args.algo = "xor"; + args.amf = "9001"; + args.imei = "353490069873319"; + args.imsi = "001010123456789"; + args.k = "00112233445566778899aabbccddeeff"; + args.op = "63BFA50EE6523365FF14C1F45F88737D"; + usim.init(&args, &usim_log); + + srslte_nas_config_t nas_cfg; + srsue::nas nas; + nas.init(&usim, &rrc_dummy, &gw, &nas_log, nas_cfg); + + nas.attach_request(); + nas.notify_connection_setup(); - //rrc.write_sdu(RB_ID_SRB2, tmp); + // check length of generated NAS SDU + if (rrc_dummy.get_last_sdu_len() > 3) { + ret = SRSLTE_SUCCESS; + } + return ret; +} - //nas.write_pdu(LCID, tmp); - pool->cleanup(); +int main(int argc, char **argv) +{ + if (security_command_test()) { + printf("Security command test failed.\n"); + return -1; + } + + if (mme_attach_request_test()) { + printf("Attach request test failed.\n"); + return -1; + } + return 0; } From a01c5ea08f010e9da2b196c2cb7421adc2abc482 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Mon, 8 Jan 2018 12:04:39 +0100 Subject: [PATCH 2/6] Fixes #119: channel estimation subframe averaging --- .../srslte/phy/ch_estimation/chest_dl.h | 1 + lib/include/srslte/phy/utils/vector.h | 4 + lib/include/srslte/phy/utils/vector_simd.h | 3 + lib/src/phy/ch_estimation/chest_dl.c | 46 ++++++++-- lib/src/phy/utils/vector.c | 8 ++ lib/src/phy/utils/vector_simd.c | 86 +++++++++++++++++++ 6 files changed, 141 insertions(+), 7 deletions(-) diff --git a/lib/include/srslte/phy/ch_estimation/chest_dl.h b/lib/include/srslte/phy/ch_estimation/chest_dl.h index 0bd6e9afe..c1f5579a1 100644 --- a/lib/include/srslte/phy/ch_estimation/chest_dl.h +++ b/lib/include/srslte/phy/ch_estimation/chest_dl.h @@ -79,6 +79,7 @@ typedef struct { srslte_interp_linsrslte_vec_t srslte_interp_linvec; srslte_interp_lin_t srslte_interp_lin; + srslte_interp_lin_t srslte_interp_lin_3; srslte_interp_lin_t srslte_interp_lin_mbsfn; float rssi[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; float rsrp[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; diff --git a/lib/include/srslte/phy/utils/vector.h b/lib/include/srslte/phy/utils/vector.h index a4028e495..210d3eef0 100644 --- a/lib/include/srslte/phy/utils/vector.h +++ b/lib/include/srslte/phy/utils/vector.h @@ -150,6 +150,10 @@ SRSLTE_API void srslte_vec_abs_square_cf(const cf_t *x, float *abs_square, const /* Copy 256 bit aligned vector */ SRSLTE_API void srs_vec_cf_cpy(const cf_t *src, cf_t *dst, const int len); +SRSLTE_API void srslte_vec_interleave(const cf_t *x, const cf_t *y, cf_t *z, const int len); + +SRSLTE_API void srslte_vec_interleave_add(const cf_t *x, const cf_t *y, cf_t *z, const int len); + #ifdef __cplusplus } #endif diff --git a/lib/include/srslte/phy/utils/vector_simd.h b/lib/include/srslte/phy/utils/vector_simd.h index 54ac55f98..31725edb3 100644 --- a/lib/include/srslte/phy/utils/vector_simd.h +++ b/lib/include/srslte/phy/utils/vector_simd.h @@ -122,6 +122,9 @@ SRSLTE_API void srslte_vec_convert_fi_simd(const float *x, int16_t *z, const flo SRSLTE_API void srslte_vec_cp_simd(const cf_t *src, cf_t *dst, int len); +SRSLTE_API void srslte_vec_interleave_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len); + +SRSLTE_API void srslte_vec_interleave_add_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len); /* SIMD Find Max functions */ SRSLTE_API uint32_t srslte_vec_max_fi_simd(const float *x, const int len); diff --git a/lib/src/phy/ch_estimation/chest_dl.c b/lib/src/phy/ch_estimation/chest_dl.c index 113870cc9..b8d6de649 100644 --- a/lib/src/phy/ch_estimation/chest_dl.c +++ b/lib/src/phy/ch_estimation/chest_dl.c @@ -141,6 +141,11 @@ int srslte_chest_dl_init(srslte_chest_dl_t *q, uint32_t max_prb) goto clean_exit; } + if (srslte_interp_linear_init(&q->srslte_interp_lin_3, 4*max_prb, SRSLTE_NRE/4)) { + fprintf(stderr, "Error initializing interpolator\n"); + goto clean_exit; + } + if (srslte_interp_linear_init(&q->srslte_interp_lin_mbsfn, 6*max_prb, SRSLTE_NRE/6)) { fprintf(stderr, "Error initializing interpolator\n"); goto clean_exit; @@ -185,6 +190,7 @@ void srslte_chest_dl_free(srslte_chest_dl_t *q) } srslte_interp_linear_vector_free(&q->srslte_interp_linvec); srslte_interp_linear_free(&q->srslte_interp_lin); + srslte_interp_linear_free(&q->srslte_interp_lin_3); srslte_interp_linear_free(&q->srslte_interp_lin_mbsfn); if (q->pilot_estimates) { free(q->pilot_estimates); @@ -238,6 +244,11 @@ int srslte_chest_dl_set_cell(srslte_chest_dl_t *q, srslte_cell_t cell) return SRSLTE_ERROR; } + if (srslte_interp_linear_resize(&q->srslte_interp_lin_3, 4 * q->cell.nof_prb, SRSLTE_NRE / 4)) { + fprintf(stderr, "Error initializing interpolator\n"); + return SRSLTE_ERROR; + } + } ret = SRSLTE_SUCCESS; } @@ -338,9 +349,15 @@ static void interpolate_pilots(srslte_chest_dl_t *q, cf_t *pilot_estimates, cf_t } } else { fidx_offset = srslte_refsignal_cs_fidx(q->cell, l, port_id, 0); - srslte_interp_linear_offset(&q->srslte_interp_lin, &pilot_estimates[2*q->cell.nof_prb*l], - &ce[srslte_refsignal_cs_nsymbol(l,q->cell.cp, port_id) * q->cell.nof_prb * SRSLTE_NRE], - fidx_offset, SRSLTE_NRE/2-fidx_offset); + if (q->average_subframe) { + srslte_interp_linear_offset(&q->srslte_interp_lin_3, &pilot_estimates[q->cell.nof_prb * l], + &ce[srslte_refsignal_cs_nsymbol(l, q->cell.cp, port_id) * q->cell.nof_prb + * SRSLTE_NRE], fidx_offset, SRSLTE_NRE / 2 - fidx_offset); + } else { + srslte_interp_linear_offset(&q->srslte_interp_lin, &pilot_estimates[2 * q->cell.nof_prb * l], + &ce[srslte_refsignal_cs_nsymbol(l, q->cell.cp, port_id) * q->cell.nof_prb + * SRSLTE_NRE], fidx_offset, SRSLTE_NRE / 2 - fidx_offset); + } } } @@ -417,11 +434,26 @@ static void average_pilots(srslte_chest_dl_t *q, cf_t *input, cf_t *output, uint // Average in the time domain if enabled if (q->average_subframe) { - for (int l=1;lsmooth_filter, output, 2 * nref, q->smooth_filter_len); + + nsymbols = 1; + return; } - srslte_vec_sc_prod_cfc(input, 1.0/((float) nsymbols), input, nref); - nsymbols = 1; } // Average in the frequency domain diff --git a/lib/src/phy/utils/vector.c b/lib/src/phy/utils/vector.c index 35457fcb5..6f5bc48e5 100644 --- a/lib/src/phy/utils/vector.c +++ b/lib/src/phy/utils/vector.c @@ -394,3 +394,11 @@ void srslte_vec_quant_suc(const int16_t *in, uint8_t *out, const float gain, con void srs_vec_cf_cpy(const cf_t *dst, cf_t *src, int len) { srslte_vec_cp_simd(dst, src, len); } + +void srslte_vec_interleave(const cf_t *x, const cf_t *y, cf_t *z, const int len) { + srslte_vec_interleave_simd(x, y, z, len); +} + +void srslte_vec_interleave_add(const cf_t *x, const cf_t *y, cf_t *z, const int len) { + srslte_vec_interleave_add_simd(x, y, z, len); +} \ No newline at end of file diff --git a/lib/src/phy/utils/vector_simd.c b/lib/src/phy/utils/vector_simd.c index 78286a81a..6bf8ddc1d 100644 --- a/lib/src/phy/utils/vector_simd.c +++ b/lib/src/phy/utils/vector_simd.c @@ -1131,3 +1131,89 @@ uint32_t srslte_vec_max_ci_simd(const cf_t *x, const int len) { return max_index; } + +void srslte_vec_interleave_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len) { + uint32_t i = 0, k = 0; + +#ifdef LV_HAVE_SSE + if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(y) && SRSLTE_IS_ALIGNED(z)) { + for (; i < len - 2 + 1; i += 2) { + __m128i a = _mm_load_si128((__m128i *) &x[i]); + __m128i b = _mm_load_si128((__m128i *) &y[i]); + + __m128i r1 = _mm_unpacklo_epi64(a, b); + _mm_store_si128((__m128i *) &z[k], r1); + k += 2; + + __m128i r2 = _mm_unpackhi_epi64(a, b); + _mm_store_si128((__m128i *) &z[k], r2); + k += 2; + } + } else { + for (; i < len - 2 + 1; i += 2) { + __m128i a = _mm_loadu_si128((__m128i *) &x[i]); + __m128i b = _mm_loadu_si128((__m128i *) &y[i]); + + __m128i r1 = _mm_unpacklo_epi64(a, b); + _mm_storeu_si128((__m128i *) &z[k], r1); + k += 2; + + __m128i r2 = _mm_unpackhi_epi64(a, b); + _mm_storeu_si128((__m128i *) &z[k], r2); + k += 2; + } + } +#endif /* LV_HAVE_SSE */ + + for (;i < len; i++) { + z[k++] = x[i]; + z[k++] = y[i]; + } +} + +void srslte_vec_interleave_add_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len) { + uint32_t i = 0, k = 0; + +#ifdef LV_HAVE_SSE + if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(y) && SRSLTE_IS_ALIGNED(z)) { + for (; i < len - 2 + 1; i += 2) { + __m128i a = _mm_load_si128((__m128i *) &x[i]); + __m128i b = _mm_load_si128((__m128i *) &y[i]); + + __m128 r1 = (__m128) _mm_unpacklo_epi64(a, b); + __m128 z1 = _mm_load_ps((float *) &z[k]); + r1 = _mm_add_ps((__m128) r1, z1); + _mm_store_ps((float *) &z[k], r1); + k += 2; + + __m128 r2 = (__m128) _mm_unpackhi_epi64(a, b); + __m128 z2 = _mm_load_ps((float *) &z[k]); + r2 = _mm_add_ps((__m128) r2, z2); + _mm_store_ps((float *) &z[k], r2); + k += 2; + } + } else { + for (; i < len - 2 + 1; i += 2) { + __m128i a = _mm_loadu_si128((__m128i *) &x[i]); + __m128i b = _mm_loadu_si128((__m128i *) &y[i]); + + __m128 r1 = (__m128) _mm_unpacklo_epi64(a, b); + __m128 z1 = _mm_loadu_ps((float *) &z[k]); + r1 = _mm_add_ps((__m128) r1, z1); + _mm_storeu_ps((float *) &z[k], r1); + k += 2; + + __m128 r2 = (__m128) _mm_unpackhi_epi64(a, b); + __m128 z2 = _mm_loadu_ps((float *) &z[k]); + r2 = _mm_add_ps((__m128) r2, z2); + _mm_storeu_ps((float *) &z[k], r2); + k += 2; + } + } +#endif /* LV_HAVE_SSE */ + + for (;i < len; i++) { + z[k++] += x[i]; + z[k++] += y[i]; + } +} \ No newline at end of file From 6b04152c186b2e1aeb034ccc692bf88613e8ea7b Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Mon, 8 Jan 2018 12:45:58 +0100 Subject: [PATCH 3/6] Fixed channel estimator for fidx_offset > 3 --- lib/src/phy/ch_estimation/chest_dl.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/src/phy/ch_estimation/chest_dl.c b/lib/src/phy/ch_estimation/chest_dl.c index b8d6de649..3859d74c8 100644 --- a/lib/src/phy/ch_estimation/chest_dl.c +++ b/lib/src/phy/ch_estimation/chest_dl.c @@ -348,12 +348,14 @@ static void interpolate_pilots(srslte_chest_dl_t *q, cf_t *pilot_estimates, cf_t fidx_offset, SRSLTE_NRE/6-fidx_offset); } } else { - fidx_offset = srslte_refsignal_cs_fidx(q->cell, l, port_id, 0); if (q->average_subframe) { + fidx_offset = SRSLTE_MIN(srslte_refsignal_cs_fidx(q->cell, 0, port_id, 0), + srslte_refsignal_cs_fidx(q->cell, 1, port_id, 0)); srslte_interp_linear_offset(&q->srslte_interp_lin_3, &pilot_estimates[q->cell.nof_prb * l], &ce[srslte_refsignal_cs_nsymbol(l, q->cell.cp, port_id) * q->cell.nof_prb - * SRSLTE_NRE], fidx_offset, SRSLTE_NRE / 2 - fidx_offset); + * SRSLTE_NRE], fidx_offset, SRSLTE_NRE / 4 - fidx_offset); } else { + fidx_offset = srslte_refsignal_cs_fidx(q->cell, l, port_id, 0); srslte_interp_linear_offset(&q->srslte_interp_lin, &pilot_estimates[2 * q->cell.nof_prb * l], &ce[srslte_refsignal_cs_nsymbol(l, q->cell.cp, port_id) * q->cell.nof_prb * SRSLTE_NRE], fidx_offset, SRSLTE_NRE / 2 - fidx_offset); @@ -444,9 +446,16 @@ static void average_pilots(srslte_chest_dl_t *q, cf_t *input, cf_t *output, uint cf_t *temp = &output[nref * 2]; bzero(temp, sizeof(cf_t) * nref * 2); - srslte_vec_interleave(input, &input[nref], temp, nref); - for (int l = 2; l < nsymbols - 1; l += 2) { - srslte_vec_interleave_add(&input[l * nref], &input[(l + 1) * nref], temp, nref); + if (srslte_refsignal_cs_fidx(q->cell, 0, port_id, 0) < 3) { + srslte_vec_interleave(input, &input[nref], temp, nref); + for (int l = 2; l < nsymbols - 1; l += 2) { + srslte_vec_interleave_add(&input[l * nref], &input[(l + 1) * nref], temp, nref); + } + } else { + srslte_vec_interleave(&input[nref], input, temp, nref); + for (int l = 2; l < nsymbols - 1; l += 2) { + srslte_vec_interleave_add(&input[(l + 1) * nref], &input[l * nref], temp, nref); + } } srslte_vec_sc_prod_cfc(temp, 2.0f / (float) nsymbols, temp, 2 * nref); srslte_conv_same_cf(temp, q->smooth_filter, output, 2 * nref, q->smooth_filter_len); From f5f9963807b2429b5dc99a1627b9186381acfd2c Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 8 Jan 2018 15:25:51 +0100 Subject: [PATCH 4/6] fix NAS test PDU contents --- srsue/test/upper/nas_test.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index 3e8cfaccb..f328d77df 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -42,13 +42,13 @@ using namespace srsue; #define LCID 1 -uint8_t auth_request_pdu[] = { 0x07, 0x52, 0x01, 0x17, 0xf2, 0x2b, 0x2b, 0xaa, 0x2c, 0x53, - 0x52, 0xf1, 0xaf, 0x2e, 0x2f, 0x6f, 0x72, 0xd0, 0x54, 0x10, - 0x18, 0xee, 0x79, 0x35, 0x25, 0x3b, 0x90, 0x01, 0x17, 0xe3, - 0x09, 0x18, 0xee, 0x3b, 0xa5, 0x24 }; +uint8_t auth_request_pdu[] = { 0x07, 0x52, 0x01, 0x0c, 0x63, 0xa8, 0x54, 0x13, 0xe6, 0xa4, + 0xce, 0xd9, 0x86, 0xfb, 0xe5, 0xce, 0x9b, 0x62, 0x5e, 0x10, + 0x67, 0x57, 0xb3, 0xc2, 0xb9, 0x70, 0x90, 0x01, 0x0c, 0x72, + 0x8a, 0x67, 0x57, 0x92, 0x52, 0xb8 }; -uint8_t sec_mode_command_pdu[] = { 0x37, 0x45, 0x62, 0x29, 0xdf, 0x00, 0x07, 0x5d, 0x02, 0x01, - 0x02, 0x80, 0xe0, 0xc1 }; +uint8_t sec_mode_command_pdu[] = { 0x37, 0x37, 0xc7, 0x67, 0xae, 0x00, 0x07, 0x5d, 0x02, 0x01, + 0x02, 0xe0, 0x60, 0xc1 }; uint16 mcc = 61441; uint16 mnc = 65281; From 9aea12152859baf7b38f869f4dedfc6ce353ca43 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Tue, 9 Jan 2018 09:25:36 +0100 Subject: [PATCH 5/6] Removed redundant bzero in chest_dl.c --- lib/src/phy/ch_estimation/chest_dl.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/src/phy/ch_estimation/chest_dl.c b/lib/src/phy/ch_estimation/chest_dl.c index 3859d74c8..f26c0d7f4 100644 --- a/lib/src/phy/ch_estimation/chest_dl.c +++ b/lib/src/phy/ch_estimation/chest_dl.c @@ -444,7 +444,6 @@ static void average_pilots(srslte_chest_dl_t *q, cf_t *input, cf_t *output, uint nsymbols = 1; } else { cf_t *temp = &output[nref * 2]; - bzero(temp, sizeof(cf_t) * nref * 2); if (srslte_refsignal_cs_fidx(q->cell, 0, port_id, 0) < 3) { srslte_vec_interleave(input, &input[nref], temp, nref); @@ -460,7 +459,6 @@ static void average_pilots(srslte_chest_dl_t *q, cf_t *input, cf_t *output, uint srslte_vec_sc_prod_cfc(temp, 2.0f / (float) nsymbols, temp, 2 * nref); srslte_conv_same_cf(temp, q->smooth_filter, output, 2 * nref, q->smooth_filter_len); - nsymbols = 1; return; } } From 2f08a135049b5da20319ad994e8d2a2aab13927a Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Tue, 9 Jan 2018 12:17:52 +0100 Subject: [PATCH 6/6] Fixed channel estimator noise estimation --- lib/src/phy/ch_estimation/chest_dl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/src/phy/ch_estimation/chest_dl.c b/lib/src/phy/ch_estimation/chest_dl.c index f26c0d7f4..d63933ced 100644 --- a/lib/src/phy/ch_estimation/chest_dl.c +++ b/lib/src/phy/ch_estimation/chest_dl.c @@ -256,12 +256,16 @@ int srslte_chest_dl_set_cell(srslte_chest_dl_t *q, srslte_cell_t cell) } /* Uses the difference between the averaged and non-averaged pilot estimates */ -static float estimate_noise_pilots(srslte_chest_dl_t *q, uint32_t port_id) +static float estimate_noise_pilots(srslte_chest_dl_t *q, uint32_t port_id, srslte_sf_t ch_mode) { int nref=SRSLTE_REFSIGNAL_NUM_SF(q->cell.nof_prb, port_id); if (q->average_subframe) { - nref /= 4; + if (ch_mode == SRSLTE_SF_MBSFN) { + nref /= 4; + } else { + nref /= 2; + } } /* Substract noisy pilot estimates */ @@ -443,7 +447,7 @@ static void average_pilots(srslte_chest_dl_t *q, cf_t *input, cf_t *output, uint srslte_vec_sc_prod_cfc(input, 1.0f / ((float) nsymbols), input, nref); nsymbols = 1; } else { - cf_t *temp = &output[nref * 2]; + cf_t *temp = output; // Use ouput as temporal buffer if (srslte_refsignal_cs_fidx(q->cell, 0, port_id, 0) < 3) { srslte_vec_interleave(input, &input[nref], temp, nref); @@ -456,10 +460,10 @@ static void average_pilots(srslte_chest_dl_t *q, cf_t *input, cf_t *output, uint srslte_vec_interleave_add(&input[(l + 1) * nref], &input[l * nref], temp, nref); } } - srslte_vec_sc_prod_cfc(temp, 2.0f / (float) nsymbols, temp, 2 * nref); - srslte_conv_same_cf(temp, q->smooth_filter, output, 2 * nref, q->smooth_filter_len); + nref *= 2; + srslte_vec_sc_prod_cfc(temp, 2.0f / (float) nsymbols, input, nref); - return; + nsymbols = 1; } } @@ -521,7 +525,7 @@ void chest_interpolate_noise_est(srslte_chest_dl_t *q, cf_t *input, cf_t *ce, ui /* Estimate noise power */ if (q->noise_alg == SRSLTE_NOISE_ALG_REFS && q->smooth_filter_len > 0) { - q->noise_estimate[rxant_id][port_id] = estimate_noise_pilots(q, port_id); + q->noise_estimate[rxant_id][port_id] = estimate_noise_pilots(q, port_id, ch_mode); } else if (q->noise_alg == SRSLTE_NOISE_ALG_PSS) { if (sf_idx == 0 || sf_idx == 5) { q->noise_estimate[rxant_id][port_id] = estimate_noise_pss(q, input, ce);