Merge branch 'next' into 16bit_avx_viterbi

master
Ismael Gomez 7 years ago
commit e16839d7a7

@ -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];

@ -151,6 +151,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

@ -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);

@ -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;
}
@ -245,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) {
if (ch_mode == SRSLTE_SF_MBSFN) {
nref /= 4;
} else {
nref /= 2;
}
}
/* Substract noisy pilot estimates */
@ -336,11 +351,19 @@ static void interpolate_pilots(srslte_chest_dl_t *q, cf_t *pilot_estimates, cf_t
&ce[srslte_refsignal_mbsfn_nsymbol(l - 1) * q->cell.nof_prb * SRSLTE_NRE],
fidx_offset, SRSLTE_NRE/6-fidx_offset);
}
} else {
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 / 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);
&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 +440,31 @@ 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) {
if (ch_mode == SRSLTE_SF_MBSFN) {
for (int l = 1; l < nsymbols; l++) {
srslte_vec_sum_ccc(&input[l * nref], input, input, nref);
}
srslte_vec_sc_prod_cfc(input, 1.0/((float) nsymbols), input, nref);
srslte_vec_sc_prod_cfc(input, 1.0f / ((float) nsymbols), input, nref);
nsymbols = 1;
} else {
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);
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);
}
}
nref *= 2;
srslte_vec_sc_prod_cfc(temp, 2.0f / (float) nsymbols, input, nref);
nsymbols = 1;
}
}
// Average in the frequency domain
@ -482,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);

@ -420,3 +420,11 @@ void srslte_vec_quant_sus(const int16_t *in, uint16_t *out, const float gain, co
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);
}

@ -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];
}
}

@ -26,6 +26,9 @@ 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)

@ -25,35 +25,37 @@
*/
#include <iostream>
#include <assert.h>
#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, 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 };
uint32_t PDU1_LEN = 104;
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;
#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;
}

Loading…
Cancel
Save