mirror of https://github.com/PentHertz/srsLTE.git
Fixed MIB decoding through ASN
This commit is contained in:
parent
956a9d61dd
commit
83316aeb9a
|
@ -214,7 +214,7 @@ int cell_search(void *uhd, int force_N_id_2, lte_cell_t *cell)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
uint32_t nof_tx_ports;
|
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];
|
ue_celldetect_result_t found_cells[3];
|
||||||
bzero(found_cells, 3*sizeof(ue_celldetect_result_t));
|
bzero(found_cells, 3*sizeof(ue_celldetect_result_t));
|
||||||
|
@ -256,9 +256,9 @@ int cell_search(void *uhd, int force_N_id_2, lte_cell_t *cell)
|
||||||
cell->cp = found_cells[max_peak_cell].cp;
|
cell->cp = found_cells[max_peak_cell].cp;
|
||||||
cell->id = found_cells[max_peak_cell].cell_id;
|
cell->id = found_cells[max_peak_cell].cell_id;
|
||||||
cell->nof_ports = nof_tx_ports;
|
cell->nof_ports = nof_tx_ports;
|
||||||
|
|
||||||
bit_pack_vector(bch_payload, bch_payload_packed, BCH_PAYLOAD_LEN);
|
bit_unpack_vector(bch_payload, bch_payload_unpacked, BCH_PAYLOAD_LEN);
|
||||||
bcch_bch_mib_unpack(bch_payload_packed, BCH_PAYLOAD_LEN, cell, NULL);
|
bcch_bch_mib_unpack(bch_payload_unpacked, BCH_PAYLOAD_LEN, cell, NULL);
|
||||||
|
|
||||||
/* set sampling frequency */
|
/* set sampling frequency */
|
||||||
int srate = lte_sampling_freq_hz(cell->nof_prb);
|
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);
|
int ret = crc_checksum(&q->crc, data, BCH_PAYLOADCRC_LEN);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
uint32_t chkzeros=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];
|
chkzeros += data[i];
|
||||||
}
|
}
|
||||||
if (chkzeros) {
|
if (chkzeros) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return LIBLTE_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -290,10 +290,10 @@ 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 */
|
/* FIXME: If channel estimates are zero, received LLR are NaN. Check and return error */
|
||||||
for (j = 0; j < BCH_ENCODED_LEN; j++) {
|
for (j = 0; j < BCH_ENCODED_LEN; j++) {
|
||||||
if (isnan(q->pbch_rm_f[j]) || isinf(q->pbch_rm_f[j])) {
|
if (isnan(q->pbch_rm_f[j]) || isinf(q->pbch_rm_f[j])) {
|
||||||
return 0;
|
return LIBLTE_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* decode */
|
/* decode */
|
||||||
viterbi_decode_f(&q->decoder, q->pbch_rm_f, q->data, BCH_PAYLOADCRC_LEN);
|
viterbi_decode_f(&q->decoder, q->pbch_rm_f, q->data, BCH_PAYLOADCRC_LEN);
|
||||||
|
|
||||||
|
@ -412,6 +412,7 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[MAX_PORTS],
|
||||||
}
|
}
|
||||||
if (bch_payload) {
|
if (bch_payload) {
|
||||||
memcpy(bch_payload, q->data, sizeof(uint8_t) * BCH_PAYLOAD_LEN);
|
memcpy(bch_payload, q->data, sizeof(uint8_t) * BCH_PAYLOAD_LEN);
|
||||||
|
vec_fprint_hex(stdout, bch_payload, BCH_PAYLOAD_LEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "liblte/phy/phy.h"
|
#include "liblte/phy/phy.h"
|
||||||
|
|
||||||
|
@ -109,6 +110,7 @@ int main(int argc, char **argv) {
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
for (i=0;i<BCH_PAYLOAD_LEN;i++) {
|
for (i=0;i<BCH_PAYLOAD_LEN;i++) {
|
||||||
bch_payload_tx[i] = rand()%2;
|
bch_payload_tx[i] = rand()%2;
|
||||||
}
|
}
|
||||||
|
@ -134,17 +136,17 @@ int main(int argc, char **argv) {
|
||||||
free(ce[i]);
|
free(ce[i]);
|
||||||
free(slot1_symbols[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)) {
|
if (nof_rx_ports == cell.nof_ports && !memcmp(bch_payload_rx, bch_payload_tx, sizeof(uint8_t) * BCH_PAYLOAD_LEN)) {
|
||||||
printf("OK\n");
|
printf("OK\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
printf("Error\n");
|
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);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,16 +31,15 @@
|
||||||
|
|
||||||
#include "liblte/phy/utils/bit.h"
|
#include "liblte/phy/utils/bit.h"
|
||||||
|
|
||||||
|
void bit_pack_vector(uint8_t *bits_unpacked, uint8_t *bits_packed, int nof_bits)
|
||||||
void bit_pack_vector(uint8_t *bit_unpacked, uint8_t *bits_packed, int nof_bits)
|
|
||||||
{
|
{
|
||||||
uint32_t i, nbytes;
|
uint32_t i, nbytes;
|
||||||
nbytes = nof_bits/8;
|
nbytes = nof_bits/8;
|
||||||
for (i=0;i<nbytes;i++) {
|
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) {
|
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;
|
*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;
|
uint32_t i, nbytes;
|
||||||
nbytes = nof_bits/8;
|
nbytes = nof_bits/8;
|
||||||
for (i=0;i<nbytes;i++) {
|
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) {
|
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,9 +92,7 @@ int bcch_bch_mib_pack(lte_cell_t *cell, uint32_t sfn, uint8_t *buffer, uint32_t
|
||||||
printf("Encoding failed.\n");
|
printf("Encoding failed.\n");
|
||||||
printf("Failed to encode element %s\n", n.failed_type ? n.failed_type->name : "");
|
printf("Failed to encode element %s\n", n.failed_type ? n.failed_type->name : "");
|
||||||
return LIBLTE_ERROR;
|
return LIBLTE_ERROR;
|
||||||
} else {
|
}
|
||||||
printf("Encoding ok\n");
|
|
||||||
}
|
|
||||||
asn_fprint(stdout, &asn_DEF_MasterInformationBlock, &req);
|
asn_fprint(stdout, &asn_DEF_MasterInformationBlock, &req);
|
||||||
return LIBLTE_SUCCESS;
|
return LIBLTE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -106,13 +104,12 @@ int bcch_bch_mib_unpack(uint8_t *buffer, uint32_t msg_nof_bits, lte_cell_t *cell
|
||||||
perror("calloc");
|
perror("calloc");
|
||||||
return LIBLTE_ERROR;
|
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) {
|
if (n.consumed == -1) {
|
||||||
printf("Decoding failed.\n");
|
printf("Decoding failed.\n");
|
||||||
return LIBLTE_ERROR;
|
return LIBLTE_ERROR;
|
||||||
} else {
|
}
|
||||||
printf("Decoding ok\n");
|
|
||||||
}
|
|
||||||
asn_fprint(stdout, &asn_DEF_MasterInformationBlock, req);
|
asn_fprint(stdout, &asn_DEF_MasterInformationBlock, req);
|
||||||
|
|
||||||
switch(req->dl_Bandwidth) {
|
switch(req->dl_Bandwidth) {
|
||||||
|
|
Loading…
Reference in New Issue