Fixed MIB decoding through ASN

master
ismagom 10 years ago
parent 956a9d61dd
commit 83316aeb9a

@ -214,7 +214,7 @@ int cell_search(void *uhd, int force_N_id_2, lte_cell_t *cell)
{
int ret;
uint32_t nof_tx_ports;
uint8_t bch_payload[BCH_PAYLOAD_LEN], bch_payload_packed[BCH_PAYLOAD_LEN];
uint8_t bch_payload[BCH_PAYLOAD_LEN], bch_payload_unpacked[BCH_PAYLOAD_LEN];
ue_celldetect_result_t found_cells[3];
bzero(found_cells, 3*sizeof(ue_celldetect_result_t));
@ -257,8 +257,8 @@ int cell_search(void *uhd, int force_N_id_2, lte_cell_t *cell)
cell->id = found_cells[max_peak_cell].cell_id;
cell->nof_ports = nof_tx_ports;
bit_pack_vector(bch_payload, bch_payload_packed, BCH_PAYLOAD_LEN);
bcch_bch_mib_unpack(bch_payload_packed, BCH_PAYLOAD_LEN, cell, NULL);
bit_unpack_vector(bch_payload, bch_payload_unpacked, BCH_PAYLOAD_LEN);
bcch_bch_mib_unpack(bch_payload_unpacked, BCH_PAYLOAD_LEN, cell, NULL);
/* set sampling frequency */
int srate = lte_sampling_freq_hz(cell->nof_prb);

@ -253,13 +253,13 @@ uint32_t pbch_crc_check(pbch_t *q, uint8_t *bits, uint32_t nof_ports) {
int ret = crc_checksum(&q->crc, data, BCH_PAYLOADCRC_LEN);
if (ret == 0) {
uint32_t chkzeros=0;
for (int i=0;i<BCH_PAYLOAD_LEN && !chkzeros;i++) {
for (int i=0;i<BCH_PAYLOAD_LEN;i++) {
chkzeros += data[i];
}
if (chkzeros) {
return 0;
} else {
return -1;
return LIBLTE_ERROR;
}
} else {
return ret;
@ -290,7 +290,7 @@ int pbch_decode_frame(pbch_t *q, uint32_t src, uint32_t dst, uint32_t n,
/* FIXME: If channel estimates are zero, received LLR are NaN. Check and return error */
for (j = 0; j < BCH_ENCODED_LEN; j++) {
if (isnan(q->pbch_rm_f[j]) || isinf(q->pbch_rm_f[j])) {
return 0;
return LIBLTE_ERROR;
}
}
@ -412,6 +412,7 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[MAX_PORTS],
}
if (bch_payload) {
memcpy(bch_payload, q->data, sizeof(uint8_t) * BCH_PAYLOAD_LEN);
vec_fprint_hex(stdout, bch_payload, BCH_PAYLOAD_LEN);
}
}
return ret;

@ -30,6 +30,7 @@
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <time.h>
#include "liblte/phy/phy.h"
@ -109,6 +110,7 @@ int main(int argc, char **argv) {
exit(-1);
}
srand(time(NULL));
for (i=0;i<BCH_PAYLOAD_LEN;i++) {
bch_payload_tx[i] = rand()%2;
}
@ -134,17 +136,17 @@ int main(int argc, char **argv) {
free(ce[i]);
free(slot1_symbols[i]);
}
printf("Tx ports: %d - Rx ports: %d\n", cell.nof_ports, nof_rx_ports);
printf("Tx payload: ");
vec_fprint_hex(stdout, bch_payload_tx, BCH_PAYLOAD_LEN);
printf("Rx payload: ");
vec_fprint_hex(stdout, bch_payload_rx, BCH_PAYLOAD_LEN);
if (nof_rx_ports == cell.nof_ports && !memcmp(bch_payload_rx, bch_payload_tx, sizeof(uint8_t) * BCH_PAYLOAD_LEN)) {
printf("OK\n");
exit(0);
} else {
printf("Error\n");
printf("Tx ports: %d - Rx ports: %d\n", cell.nof_ports, nof_rx_ports);
printf("Tx payload: ");
vec_fprint_hex(stdout, bch_payload_tx, BCH_PAYLOAD_LEN);
printf("Rx payload: ");
vec_fprint_hex(stdout, bch_payload_rx, BCH_PAYLOAD_LEN);
exit(-1);
}
}

@ -31,16 +31,15 @@
#include "liblte/phy/utils/bit.h"
void bit_pack_vector(uint8_t *bit_unpacked, uint8_t *bits_packed, int nof_bits)
void bit_pack_vector(uint8_t *bits_unpacked, uint8_t *bits_packed, int nof_bits)
{
uint32_t i, nbytes;
nbytes = nof_bits/8;
for (i=0;i<nbytes;i++) {
bit_pack(bits_packed[i], &bits_packed, 8);
bit_pack(bits_unpacked[i], &bits_packed, 8);
}
if (nof_bits%8) {
bit_pack(bits_packed[i], &bits_packed, nof_bits%8);
bit_pack(bits_unpacked[i], &bits_packed, nof_bits%8);
}
}
@ -54,15 +53,15 @@ void bit_pack(uint32_t value, uint8_t **bits, int nof_bits)
*bits += nof_bits;
}
void bit_unpack_vector(uint8_t *bits_packed, uint8_t *bit_unpacked, int nof_bits)
void bit_unpack_vector(uint8_t *bits_packed, uint8_t *bits_unpacked, int nof_bits)
{
uint32_t i, nbytes;
nbytes = nof_bits/8;
for (i=0;i<nbytes;i++) {
bits_packed[i] = bit_unpack(&bit_unpacked, 8);
bits_unpacked[i] = bit_unpack(&bits_packed, 8);
}
if (nof_bits%8) {
bits_packed[i] = bit_unpack(&bit_unpacked, nof_bits%8);
bits_unpacked[i] = bit_unpack(&bits_packed, nof_bits%8);
}
}

@ -92,8 +92,6 @@ int bcch_bch_mib_pack(lte_cell_t *cell, uint32_t sfn, uint8_t *buffer, uint32_t
printf("Encoding failed.\n");
printf("Failed to encode element %s\n", n.failed_type ? n.failed_type->name : "");
return LIBLTE_ERROR;
} else {
printf("Encoding ok\n");
}
asn_fprint(stdout, &asn_DEF_MasterInformationBlock, &req);
return LIBLTE_SUCCESS;
@ -106,12 +104,11 @@ int bcch_bch_mib_unpack(uint8_t *buffer, uint32_t msg_nof_bits, lte_cell_t *cell
perror("calloc");
return LIBLTE_ERROR;
}
asn_dec_rval_t n = uper_decode(opt_codec_ctx, &asn_DEF_MasterInformationBlock, (void**) &req, &buffer, msg_nof_bits/8,0,msg_nof_bits%8);
asn_dec_rval_t n = uper_decode(opt_codec_ctx, &asn_DEF_MasterInformationBlock,
(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\n");
}
asn_fprint(stdout, &asn_DEF_MasterInformationBlock, req);

Loading…
Cancel
Save