Addes SIB1 packing/unpacking to RRC

master
ismagom 10 years ago
parent e3ae38c30e
commit 2de8610ccf

@ -36,6 +36,7 @@
#include <assert.h> #include <assert.h>
#include <signal.h> #include <signal.h>
#include "liblte/rrc/rrc.h"
#include "liblte/phy/phy.h" #include "liblte/phy/phy.h"
#include "liblte/cuhd/cuhd.h" #include "liblte/cuhd/cuhd.h"
#include "cell_search_utils.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 */ /* 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) { int cuhd_recv_wrapper(void *h, void *data, uint32_t nsamples) {
DEBUG(" ---- Receive %d samples ---- \n", nsamples); DEBUG(" ---- Receive %d samples ---- \n", nsamples);
@ -121,7 +122,8 @@ int main(int argc, char **argv) {
int64_t sf_cnt; int64_t sf_cnt;
ue_sync_t ue_sync; ue_sync_t ue_sync;
void *uhd; void *uhd;
ue_dl_t ue_dl;
parse_args(&prog_args, argc, argv); parse_args(&prog_args, argc, argv);
printf("Opening UHD device...\n"); printf("Opening UHD device...\n");
@ -148,7 +150,12 @@ int main(int argc, char **argv) {
fprintf(stderr, "Error initiating ue_sync\n"); fprintf(stderr, "Error initiating ue_sync\n");
exit(-1); 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 */ /* Initialize subframe counter */
sf_cnt = 0; sf_cnt = 0;
@ -168,6 +175,9 @@ int main(int argc, char **argv) {
cf_t *sf_symbols = vec_malloc(sf_re * sizeof(cf_t)); cf_t *sf_symbols = vec_malloc(sf_re * sizeof(cf_t));
uint32_t nframes=0; uint32_t nframes=0;
bool sib1_decoded = false;
int n;
/* Main loop */ /* Main loop */
while (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1) { 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 */ /* iodev_receive returns 1 if successfully read 1 aligned subframe */
if (ret == 1) { 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 */ /* Run FFT for all subframe data */
lte_fft_run_sf(&fft, sf_buffer, sf_symbols); lte_fft_run_sf(&fft, sf_buffer, sf_symbols);
chest_measure_sf(&chest, sf_symbols, ue_sync_get_sfidx(&ue_sync)); chest_measure_sf(&chest, sf_symbols, ue_sync_get_sfidx(&ue_sync));
rssi = VEC_CMA(chest_rssi_sf(&chest, sf_symbols),rssi,nframes); 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); 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); rsrp = VEC_CMA(chest_rsrp_sf(&chest, ue_sync_get_sfidx(&ue_sync)),rsrp,nframes);
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));
}
// 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) { } else if (ret == 0) {
printf("Finding PSS... Peak: %8.1f, FrameCnt: %d, State: %d\r", printf("Finding PSS... Peak: %8.1f, FrameCnt: %d, State: %d\r",
sync_get_peak_value(&ue_sync.sfind), sync_get_peak_value(&ue_sync.sfind),

@ -38,7 +38,7 @@
#define SLOT_SZ(q) (q->nof_symbols * q->symbol_sz) #define SLOT_SZ(q) (q->nof_symbols * q->symbol_sz)
#define SF_SZ(q) (2 * SLOT_SZ(q)) #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) { void chest_fprint(chest_t *q, FILE *stream, uint32_t nslot, uint32_t port_id) {
chest_ref_fprint(q, stream, nslot, port_id); chest_ref_fprint(q, stream, nslot, port_id);

@ -31,6 +31,8 @@ int get_asn1c_environment_version(void); /* Run-time version */
#define asn_debug_indent 0 #define asn_debug_indent 0
#define ASN_DEBUG_INDENT_ADD(i) do{}while(0) #define ASN_DEBUG_INDENT_ADD(i) do{}while(0)
#define EMIT_ASN_DEBUG 1
/* /*
* A macro for debugging the ASN.1 internals. * A macro for debugging the ASN.1 internals.
* You may enable or override it. * You may enable or override it.

@ -20,7 +20,7 @@ struct asn_TYPE_descriptor_s; /* Forward declaration */
* Unaligned PER decoder of a "complete encoding" as per X.691#10.1. * 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. * 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 */ struct asn_TYPE_descriptor_s *type_descriptor, /* Type to decode */
void **struct_ptr, /* Pointer to a target structure's pointer */ void **struct_ptr, /* Pointer to a target structure's pointer */
const void *buffer, /* Data to be decoded */ const void *buffer, /* Data to be decoded */

@ -28,5 +28,6 @@
#define EMIT_ASN_DEBUG 1 #define EMIT_ASN_DEBUG 1
#include "MasterInformationBlock.h" #include "MasterInformationBlock.h"
#include "SystemInformationBlockType1.h"
#include "per_encoder.h" #include "per_encoder.h"
#include "xer_encoder.h" #include "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. * -1: Problem printing the structure.
* WARNING: No sensible errno value is returned. * 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. * Type of the generic XER encoder.

@ -45,4 +45,9 @@ LIBLTE_API int bcch_bch_mib_unpack(uint8_t *buffer,
lte_cell_t *cell, lte_cell_t *cell,
uint32_t *sfn); 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_ #endif // AGC_

@ -31,6 +31,7 @@
#include "liblte/rrc/rrc_msg/bcch.h" #include "liblte/rrc/rrc_msg/bcch.h"
#include "liblte/phy/utils/bit.h" #include "liblte/phy/utils/bit.h"
#include "rrc_asn.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) { 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; 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;
}

@ -24,6 +24,11 @@
######################################################################## ########################################################################
ADD_EXECUTABLE(bcch_bch_test bcch_bch_test.c) 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_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)

@ -47,4 +47,5 @@ int main(int argc, char **argv) {
cell.phich_length = PHICH_NORM; cell.phich_length = PHICH_NORM;
cell.phich_resources = 1; cell.phich_resources = 1;
bcch_bch_mib_pack(&cell, 123, buffer, 1024); bcch_bch_mib_pack(&cell, 123, buffer, 1024);
} }

Loading…
Cancel
Save