diff --git a/lte/examples/cell_measurement.c b/lte/examples/cell_measurement.c index ba1a1961f..c959f31d4 100644 --- a/lte/examples/cell_measurement.c +++ b/lte/examples/cell_measurement.c @@ -36,6 +36,7 @@ #include #include +#include "liblte/rrc/rrc.h" #include "liblte/phy/phy.h" #include "liblte/cuhd/cuhd.h" #include "cell_search_utils.h" @@ -105,7 +106,7 @@ void parse_args(prog_args_t *args, int argc, char **argv) { /**********************************************************************/ /* TODO: Do something with the output data */ -uint8_t data[10000]; +uint8_t data[10000], data_unpacked[1000]; int cuhd_recv_wrapper(void *h, void *data, uint32_t nsamples) { DEBUG(" ---- Receive %d samples ---- \n", nsamples); @@ -121,7 +122,8 @@ int main(int argc, char **argv) { int64_t sf_cnt; ue_sync_t ue_sync; void *uhd; - + ue_dl_t ue_dl; + parse_args(&prog_args, argc, argv); printf("Opening UHD device...\n"); @@ -148,7 +150,12 @@ int main(int argc, char **argv) { fprintf(stderr, "Error initiating ue_sync\n"); exit(-1); } - + if (ue_dl_init(&ue_dl, cell, 1234)) { + fprintf(stderr, "Error initiating UE downlink processing module\n"); + exit(-1); + } + pdsch_set_rnti(&ue_dl.pdsch, SIRNTI); + /* Initialize subframe counter */ sf_cnt = 0; @@ -168,6 +175,9 @@ int main(int argc, char **argv) { cf_t *sf_symbols = vec_malloc(sf_re * sizeof(cf_t)); uint32_t nframes=0; + bool sib1_decoded = false; + int n; + /* Main loop */ while (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1) { @@ -181,24 +191,38 @@ int main(int argc, char **argv) { /* iodev_receive returns 1 if successfully read 1 aligned subframe */ if (ret == 1) { + if (!sib1_decoded) { + n = ue_dl_decode(&ue_dl, sf_buffer, data, ue_sync_get_sfidx(&ue_sync), SIRNTI); + if (n < 0) { + fprintf(stderr, "\nError running receiver\n");fflush(stdout); + exit(-1); + } else if (n > 0) { + printf("\n\nDecoded SIB1 Message Len %d: ",n); + vec_fprint_hex(stdout, data, n); + bit_unpack_vector(data, data_unpacked, n); + bcch_dlsch_sib1_unpack(data_unpacked, n); + printf("\n");fflush(stdout); + sib1_decoded = true; + } + } else { /* Run FFT for all subframe data */ - lte_fft_run_sf(&fft, sf_buffer, sf_symbols); - - chest_measure_sf(&chest, sf_symbols, ue_sync_get_sfidx(&ue_sync)); - rssi = VEC_CMA(chest_rssi_sf(&chest, sf_symbols),rssi,nframes); - rsrq = VEC_CMA(chest_rsrq_sf(&chest, sf_symbols, ue_sync_get_sfidx(&ue_sync)),rsrq,nframes); - rsrp = VEC_CMA(chest_rsrp_sf(&chest, ue_sync_get_sfidx(&ue_sync)),rsrp,nframes); - nframes++; - - // Plot and Printf - if ((nframes%10) == 0) { - printf("CFO: %+6.4f KHz, SFO: %+6.4f Khz, RSSI: %+5.2f dBm, RSRP: %+4.2f dBm, RSRQ: %4.2f dB\r", - ue_sync_get_cfo(&ue_sync)/1000, ue_sync_get_sfo(&ue_sync)/1000, - 10*log10(rssi*1000/4/cell.nof_prb/12/2)-prog_args.uhd_gain, - 10*log10(rsrp*1000)-prog_args.uhd_gain, - 10*log10(rsrq)); - } + lte_fft_run_sf(&fft, sf_buffer, sf_symbols); + + chest_measure_sf(&chest, sf_symbols, ue_sync_get_sfidx(&ue_sync)); + rssi = VEC_CMA(chest_rssi_sf(&chest, sf_symbols),rssi,nframes); + rsrq = VEC_CMA(chest_rsrq_sf(&chest, sf_symbols, ue_sync_get_sfidx(&ue_sync)),rsrq,nframes); + rsrp = VEC_CMA(chest_rsrp_sf(&chest, ue_sync_get_sfidx(&ue_sync)),rsrp,nframes); + nframes++; + // Plot and Printf + if ((nframes%10) == 0) { + printf("CFO: %+6.4f KHz, SFO: %+6.4f Khz, RSSI: %+5.2f dBm, RSRP: %+4.2f dBm, RSRQ: %4.2f dB\r", + ue_sync_get_cfo(&ue_sync)/1000, ue_sync_get_sfo(&ue_sync)/1000, + 10*log10(rssi*1000/4/cell.nof_prb/12/2)-prog_args.uhd_gain, + 10*log10(rsrp*1000)-prog_args.uhd_gain, + 10*log10(rsrq)); + } + } } else if (ret == 0) { printf("Finding PSS... Peak: %8.1f, FrameCnt: %d, State: %d\r", sync_get_peak_value(&ue_sync.sfind), diff --git a/lte/phy/lib/ch_estimation/src/chest.c b/lte/phy/lib/ch_estimation/src/chest.c index b34471122..417695899 100644 --- a/lte/phy/lib/ch_estimation/src/chest.c +++ b/lte/phy/lib/ch_estimation/src/chest.c @@ -38,7 +38,7 @@ #define SLOT_SZ(q) (q->nof_symbols * q->symbol_sz) #define SF_SZ(q) (2 * SLOT_SZ(q)) -//#define VOLK_INTERP +#define VOLK_INTERP void chest_fprint(chest_t *q, FILE *stream, uint32_t nslot, uint32_t port_id) { chest_ref_fprint(q, stream, nslot, port_id); diff --git a/lte/rrc/asn/asn_internal.h b/lte/rrc/asn/asn_internal.h index 7e0f71be0..e29e4d5f7 100644 --- a/lte/rrc/asn/asn_internal.h +++ b/lte/rrc/asn/asn_internal.h @@ -31,6 +31,8 @@ int get_asn1c_environment_version(void); /* Run-time version */ #define asn_debug_indent 0 #define ASN_DEBUG_INDENT_ADD(i) do{}while(0) +#define EMIT_ASN_DEBUG 1 + /* * A macro for debugging the ASN.1 internals. * You may enable or override it. diff --git a/lte/rrc/asn/per_decoder.h b/lte/rrc/asn/per_decoder.h index 3b99c07ee..253745426 100644 --- a/lte/rrc/asn/per_decoder.h +++ b/lte/rrc/asn/per_decoder.h @@ -20,7 +20,7 @@ struct asn_TYPE_descriptor_s; /* Forward declaration */ * Unaligned PER decoder of a "complete encoding" as per X.691#10.1. * On success, this call always returns (.consumed >= 1), as per X.691#10.1.3. */ - asn_dec_rval_t uper_decode_complete(struct asn_codec_ctx_s *opt_codec_ctx, + LIBLTE_API asn_dec_rval_t uper_decode_complete(struct asn_codec_ctx_s *opt_codec_ctx, struct asn_TYPE_descriptor_s *type_descriptor, /* Type to decode */ void **struct_ptr, /* Pointer to a target structure's pointer */ const void *buffer, /* Data to be decoded */ diff --git a/lte/rrc/asn/rrc_asn.h b/lte/rrc/asn/rrc_asn.h index 2feb85e25..766d8da61 100644 --- a/lte/rrc/asn/rrc_asn.h +++ b/lte/rrc/asn/rrc_asn.h @@ -28,5 +28,6 @@ #define EMIT_ASN_DEBUG 1 #include "MasterInformationBlock.h" +#include "SystemInformationBlockType1.h" #include "per_encoder.h" #include "xer_encoder.h" diff --git a/lte/rrc/asn/xer_encoder.h b/lte/rrc/asn/xer_encoder.h index 055e73c0c..3068aa65d 100644 --- a/lte/rrc/asn/xer_encoder.h +++ b/lte/rrc/asn/xer_encoder.h @@ -38,7 +38,7 @@ asn_enc_rval_t xer_encode(struct asn_TYPE_descriptor_s *type_descriptor, * -1: Problem printing the structure. * WARNING: No sensible errno value is returned. */ -int xer_fprint(FILE *stream, struct asn_TYPE_descriptor_s *td, void *sptr); +LIBLTE_API int xer_fprint(FILE *stream, struct asn_TYPE_descriptor_s *td, void *sptr); /* * Type of the generic XER encoder. diff --git a/lte/rrc/include/liblte/rrc/rrc_msg/bcch.h b/lte/rrc/include/liblte/rrc/rrc_msg/bcch.h index 193c5e4f6..339333074 100644 --- a/lte/rrc/include/liblte/rrc/rrc_msg/bcch.h +++ b/lte/rrc/include/liblte/rrc/rrc_msg/bcch.h @@ -45,4 +45,9 @@ LIBLTE_API int bcch_bch_mib_unpack(uint8_t *buffer, lte_cell_t *cell, uint32_t *sfn); +LIBLTE_API int bcch_dlsch_sib1_pack(uint8_t *buffer, + uint32_t buffer_size_bytes); + +LIBLTE_API int bcch_dlsch_sib1_unpack(uint8_t *buffer, + uint32_t msg_nof_bits); #endif // AGC_ diff --git a/lte/rrc/lib/rrc_msg/src/bcch.c b/lte/rrc/lib/rrc_msg/src/bcch.c index afb571591..aefa3665a 100644 --- a/lte/rrc/lib/rrc_msg/src/bcch.c +++ b/lte/rrc/lib/rrc_msg/src/bcch.c @@ -31,6 +31,7 @@ #include "liblte/rrc/rrc_msg/bcch.h" #include "liblte/phy/utils/bit.h" #include "rrc_asn.h" +#include "sib.h" int bcch_bch_mib_pack(lte_cell_t *cell, uint32_t sfn, uint8_t *buffer, uint32_t buffer_size_bytes) { @@ -155,3 +156,43 @@ int bcch_bch_mib_unpack(uint8_t *buffer, uint32_t msg_nof_bits, lte_cell_t *cell } return LIBLTE_SUCCESS; } + + +int bcch_dlsch_sib1_pack(uint8_t *buffer, uint32_t buffer_size_bytes) { + SystemInformationBlockType1_t req; + + MCC_MNC_Digit_t mcc[3] = {1,0,1}; + MCC_MNC_Digit_t mnc[2] = {2,3}; + uint8_t tac_val[2] = {0x10,0x20}; + uint8_t cid_val[4] = {0x3,0x4,0x5,0x6}; + printf("calling create\n"); + sib1_create_default(&req, mcc, mnc, tac_val, cid_val, 6); + printf("calling encode\n"); + asn_enc_rval_t n = uper_encode_to_buffer(&asn_DEF_SystemInformationBlockType1, (void*) &req, buffer, 200); + if (n.encoded == -1) { + printf("Encoding failed.\n"); + printf("Failed to encode element %s\n", n.failed_type ? n.failed_type->name : ""); + return LIBLTE_ERROR; + } + asn_fprint(stdout, &asn_DEF_MasterInformationBlock, &req); + return LIBLTE_SUCCESS; +} + +int bcch_dlsch_sib1_unpack(uint8_t *buffer, uint32_t msg_nof_bits) { + SystemInformationBlockType1_t *req = calloc(1, sizeof(SystemInformationBlockType1_t)); + if (!req) { + perror("calloc"); + return LIBLTE_ERROR; + } + asn_dec_rval_t n = uper_decode(NULL, &asn_DEF_SystemInformationBlockType1, + (void**) &req, buffer, msg_nof_bits/8,0,msg_nof_bits%8); + if (n.consumed == -1) { + printf("Decoding failed.\n"); + return LIBLTE_ERROR; + } else { + printf("Decoding OK consumed: %d bits\n", n.consumed); + } + asn_fprint(stdout, &asn_DEF_SystemInformationBlockType1, req); + + return LIBLTE_SUCCESS; +} diff --git a/lte/rrc/lib/rrc_msg/test/CMakeLists.txt b/lte/rrc/lib/rrc_msg/test/CMakeLists.txt index 4d89fa392..6f0c6a3ed 100644 --- a/lte/rrc/lib/rrc_msg/test/CMakeLists.txt +++ b/lte/rrc/lib/rrc_msg/test/CMakeLists.txt @@ -24,6 +24,11 @@ ######################################################################## ADD_EXECUTABLE(bcch_bch_test bcch_bch_test.c) -TARGET_LINK_LIBRARIES(bcch_bch_test lte_rrc) +TARGET_LINK_LIBRARIES(bcch_bch_test lte_rrc rrc_asn ) ADD_TEST(bcch_bch_test_1 bcch_bch_test) + +ADD_EXECUTABLE(bcch_dlsch_test bcch_dlsch_test.c) +TARGET_LINK_LIBRARIES(bcch_dlsch_test lte_rrc rrc_asn ) + +ADD_TEST(bcch_dlsch_test_1 bcch_dlsch_test) diff --git a/lte/rrc/lib/rrc_msg/test/bcch_bch_test.c b/lte/rrc/lib/rrc_msg/test/bcch_bch_test.c index 6b403920b..be5d6e6af 100644 --- a/lte/rrc/lib/rrc_msg/test/bcch_bch_test.c +++ b/lte/rrc/lib/rrc_msg/test/bcch_bch_test.c @@ -47,4 +47,5 @@ int main(int argc, char **argv) { cell.phich_length = PHICH_NORM; cell.phich_resources = 1; bcch_bch_mib_pack(&cell, 123, buffer, 1024); -} \ No newline at end of file +} +