PBCH decoding assumes number of ports when they are known

master
ismagom 10 years ago
parent cb05db2bd1
commit 94f2e84f09

@ -145,7 +145,7 @@ int main(int argc, char **argv) {
uint32_t nof_trials = 0; uint32_t nof_trials = 0;
uint32_t sfn = 0; // system frame number uint32_t sfn = 0; // system frame number
int n; int n;
uint8_t bch_payload[BCH_PAYLOAD_LEN]; uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
uint32_t sfn_offset; uint32_t sfn_offset;
float rssi_utra=0,rssi=0, rsrp=0, rsrq=0, snr=0; float rssi_utra=0,rssi=0, rsrp=0, rsrq=0, snr=0;
cf_t *ce[SRSLTE_MAX_PORTS]; cf_t *ce[SRSLTE_MAX_PORTS];

@ -53,7 +53,7 @@ int cuhd_recv_wrapper_cs(void *h, void *data, uint32_t nsamples, srslte_timestam
int cuhd_mib_decoder(void *uhd, uint32_t max_nof_frames, srslte_cell_t *cell) { int cuhd_mib_decoder(void *uhd, uint32_t max_nof_frames, srslte_cell_t *cell) {
int ret = SRSLTE_ERROR; int ret = SRSLTE_ERROR;
srslte_ue_mib_sync_t ue_mib; srslte_ue_mib_sync_t ue_mib;
uint8_t bch_payload[BCH_PAYLOAD_LEN]; uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
if (srslte_ue_mib_sync_init(&ue_mib, cell->id, cell->cp, cuhd_recv_wrapper_cs, uhd)) { if (srslte_ue_mib_sync_init(&ue_mib, cell->id, cell->cp, cuhd_recv_wrapper_cs, uhd)) {
fprintf(stderr, "Error initiating srslte_ue_mib_sync\n"); fprintf(stderr, "Error initiating srslte_ue_mib_sync\n");

@ -442,7 +442,7 @@ int main(int argc, char **argv) {
cf_t pss_signal[SRSLTE_PSS_LEN]; cf_t pss_signal[SRSLTE_PSS_LEN];
float sss_signal0[SRSLTE_SSS_LEN]; // for subframe 0 float sss_signal0[SRSLTE_SSS_LEN]; // for subframe 0
float sss_signal5[SRSLTE_SSS_LEN]; // for subframe 5 float sss_signal5[SRSLTE_SSS_LEN]; // for subframe 5
uint8_t bch_payload[BCH_PAYLOAD_LEN]; uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
int i; int i;
cf_t *sf_symbols[SRSLTE_MAX_PORTS]; cf_t *sf_symbols[SRSLTE_MAX_PORTS];
cf_t *slot1_symbols[SRSLTE_MAX_PORTS]; cf_t *slot1_symbols[SRSLTE_MAX_PORTS];

@ -247,7 +247,7 @@ int main(int argc, char **argv) {
#endif #endif
uint32_t nof_trials = 0; uint32_t nof_trials = 0;
int n; int n;
uint8_t bch_payload[BCH_PAYLOAD_LEN]; uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
uint32_t sfn_offset; uint32_t sfn_offset;
parse_args(&prog_args, argc, argv); parse_args(&prog_args, argc, argv);
@ -369,6 +369,7 @@ int main(int argc, char **argv) {
bool decode_pdsch; bool decode_pdsch;
int pdcch_tx=0; int pdcch_tx=0;
INFO("\nEntering main loop...\n\n", 0);
/* Main loop */ /* Main loop */
while (!go_exit && (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1)) { while (!go_exit && (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1)) {
@ -389,7 +390,7 @@ int main(int argc, char **argv) {
exit(-1); exit(-1);
} else if (n == SRSLTE_UE_MIB_FOUND) { } else if (n == SRSLTE_UE_MIB_FOUND) {
srslte_pbch_mib_unpack(bch_payload, &cell, &sfn); srslte_pbch_mib_unpack(bch_payload, &cell, &sfn);
srslte_pbch_mib_fprint(stdout, &cell, sfn, cell.id); srslte_cell_fprint(stdout, &cell, sfn);
printf("Decoded MIB. SFN: %d, offset: %d\n", sfn, sfn_offset); printf("Decoded MIB. SFN: %d, offset: %d\n", sfn, sfn_offset);
sfn = (sfn + sfn_offset)%1024; sfn = (sfn + sfn_offset)%1024;
state = DECODE_PDSCH; state = DECODE_PDSCH;

@ -295,7 +295,7 @@ int main(int argc, char **argv) {
srslte_ue_mib_t ue_mib; srslte_ue_mib_t ue_mib;
void *uhd; void *uhd;
int n; int n;
uint8_t bch_payload[BCH_PAYLOAD_LEN]; uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
uint32_t sfn_offset; uint32_t sfn_offset;
rar_msg_t rar_msg; rar_msg_t rar_msg;
srslte_ra_pusch_t ra_pusch; srslte_ra_pusch_t ra_pusch;
@ -476,7 +476,7 @@ int main(int argc, char **argv) {
exit(-1); exit(-1);
} else if (n == SRSLTE_UE_MIB_FOUND) { } else if (n == SRSLTE_UE_MIB_FOUND) {
srslte_pbch_mib_unpack(bch_payload, &cell, &sfn); srslte_pbch_mib_unpack(bch_payload, &cell, &sfn);
srslte_pbch_mib_fprint(stdout, &cell, sfn, cell.id); srslte_cell_fprint(stdout, &cell, sfn);
printf("Decoded MIB. SFN: %d, offset: %d\n", sfn, sfn_offset); printf("Decoded MIB. SFN: %d, offset: %d\n", sfn, sfn_offset);
sfn = (sfn + sfn_offset)%1024; sfn = (sfn + sfn_offset)%1024;
state = SEND_PRACH; state = SEND_PRACH;

@ -182,7 +182,8 @@ enum band_geographical_area {
SRSLTE_API bool srslte_cell_isvalid(srslte_cell_t *cell); SRSLTE_API bool srslte_cell_isvalid(srslte_cell_t *cell);
SRSLTE_API void srslte_cell_fprint(FILE *stream, SRSLTE_API void srslte_cell_fprint(FILE *stream,
srslte_cell_t *cell); srslte_cell_t *cell,
uint32_t sfn);
SRSLTE_API bool srslte_cellid_isvalid(uint32_t cell_id); SRSLTE_API bool srslte_cellid_isvalid(uint32_t cell_id);

@ -28,7 +28,9 @@
/****************************************************************************** /******************************************************************************
* File: pbch.h * File: pbch.h
* *
* Description: Physical broadcast channel. * Description: Physical broadcast channel. If cell.nof_ports = 0, the number
* of ports is blindly determined using the CRC of the received
* codeword for 1, 2 and 4 ports
* *
* Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.6 * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.6
*****************************************************************************/ *****************************************************************************/
@ -48,12 +50,9 @@
#include "srslte/fec/viterbi.h" #include "srslte/fec/viterbi.h"
#include "srslte/fec/crc.h" #include "srslte/fec/crc.h"
#define BCH_PAYLOAD_LEN 24 #define SRSLTE_BCH_PAYLOAD_LEN 24
#define BCH_PAYLOADCRC_LEN (BCH_PAYLOAD_LEN+16) #define SRSLTE_BCH_PAYLOADCRC_LEN (SRSLTE_BCH_PAYLOAD_LEN+16)
#define BCH_ENCODED_LEN 3*(BCH_PAYLOADCRC_LEN) #define SRSLTE_BCH_ENCODED_LEN 3*(SRSLTE_BCH_PAYLOADCRC_LEN)
#define PBCH_RE_SRSLTE_CP_NORM 240
#define PBCH_RE_SRSLTE_CP_EXT 216
/* PBCH object */ /* PBCH object */
typedef struct SRSLTE_API { typedef struct SRSLTE_API {
@ -68,10 +67,10 @@ typedef struct SRSLTE_API {
cf_t *d; cf_t *d;
float *llr; float *llr;
float *temp; float *temp;
float rm_f[BCH_ENCODED_LEN]; float rm_f[SRSLTE_BCH_ENCODED_LEN];
uint8_t *rm_b; uint8_t *rm_b;
uint8_t data[BCH_PAYLOADCRC_LEN]; uint8_t data[SRSLTE_BCH_PAYLOADCRC_LEN];
uint8_t data_enc[BCH_ENCODED_LEN]; uint8_t data_enc[SRSLTE_BCH_ENCODED_LEN];
uint32_t frame_idx; uint32_t frame_idx;
@ -83,6 +82,7 @@ typedef struct SRSLTE_API {
srslte_crc_t crc; srslte_crc_t crc;
srslte_convcoder_t encoder; srslte_convcoder_t encoder;
srslte_precoding_t precoding; srslte_precoding_t precoding;
bool search_all_ports;
} srslte_pbch_t; } srslte_pbch_t;
@ -94,12 +94,12 @@ SRSLTE_API int srslte_pbch_decode(srslte_pbch_t *q,
cf_t *slot1_symbols, cf_t *slot1_symbols,
cf_t *ce_slot1[SRSLTE_MAX_PORTS], cf_t *ce_slot1[SRSLTE_MAX_PORTS],
float noise_estimate, float noise_estimate,
uint8_t bch_payload[BCH_PAYLOAD_LEN], uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN],
uint32_t *nof_tx_ports, uint32_t *nof_tx_ports,
uint32_t *sfn_offset); uint32_t *sfn_offset);
SRSLTE_API int srslte_pbch_encode(srslte_pbch_t *q, SRSLTE_API int srslte_pbch_encode(srslte_pbch_t *q,
uint8_t bch_payload[BCH_PAYLOAD_LEN], uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN],
cf_t *slot1_symbols[SRSLTE_MAX_PORTS]); cf_t *slot1_symbols[SRSLTE_MAX_PORTS]);
SRSLTE_API void srslte_pbch_decode_reset(srslte_pbch_t *q); SRSLTE_API void srslte_pbch_decode_reset(srslte_pbch_t *q);
@ -112,9 +112,4 @@ SRSLTE_API void srslte_pbch_mib_pack(srslte_cell_t *cell,
uint32_t sfn, uint32_t sfn,
uint8_t *msg); uint8_t *msg);
SRSLTE_API void srslte_pbch_mib_fprint(FILE *stream,
srslte_cell_t *cell,
uint32_t sfn,
uint32_t cell_id);
#endif // PBCH_ #endif // PBCH_

@ -36,7 +36,7 @@
* *
* The function uses the sync_t object to find the PSS sequence and * The function uses the sync_t object to find the PSS sequence and
* decode the PBCH to obtain the MIB. * decode the PBCH to obtain the MIB.
* *
* The function returns 0 until the MIB is decoded. * The function returns 0 until the MIB is decoded.
* *
* See ue_cell_detect.c for an example. * See ue_cell_detect.c for an example.
@ -57,7 +57,6 @@
#include "srslte/dft/ofdm.h" #include "srslte/dft/ofdm.h"
#define SRSLTE_UE_MIB_MAX_PORTS 4
#define SRSLTE_UE_MIB_NOF_PRB 6 #define SRSLTE_UE_MIB_NOF_PRB 6
#define SRSLTE_UE_MIB_FOUND 1 #define SRSLTE_UE_MIB_FOUND 1
@ -67,13 +66,13 @@ typedef struct SRSLTE_API {
srslte_sync_t sfind; srslte_sync_t sfind;
cf_t *sf_symbols; cf_t *sf_symbols;
cf_t *ce[SRSLTE_UE_MIB_MAX_PORTS]; cf_t *ce[SRSLTE_MAX_PORTS];
srslte_ofdm_t fft; srslte_ofdm_t fft;
srslte_chest_dl_t chest; srslte_chest_dl_t chest;
srslte_pbch_t pbch; srslte_pbch_t pbch;
uint8_t bch_payload[BCH_PAYLOAD_LEN]; uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
uint32_t nof_tx_ports; uint32_t nof_tx_ports;
uint32_t sfn_offset; uint32_t sfn_offset;
@ -89,13 +88,15 @@ SRSLTE_API void srslte_ue_mib_reset(srslte_ue_mib_t * q);
SRSLTE_API int srslte_ue_mib_decode(srslte_ue_mib_t * q, SRSLTE_API int srslte_ue_mib_decode(srslte_ue_mib_t * q,
cf_t *input, cf_t *input,
uint8_t bch_payload[BCH_PAYLOAD_LEN], uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN],
uint32_t *nof_tx_ports, uint32_t *nof_tx_ports,
uint32_t *sfn_offset); uint32_t *sfn_offset);
/* This interface uses ue_mib and ue_sync to first get synchronized subframes /* This interface uses ue_mib and ue_sync to first get synchronized subframes
* and then decode MIB * and then decode MIB
*
* This object calls the pbch object with nof_ports=0 for blind nof_ports determination
*/ */
typedef struct { typedef struct {
srslte_ue_mib_t ue_mib; srslte_ue_mib_t ue_mib;
@ -114,7 +115,7 @@ SRSLTE_API void srslte_ue_mib_sync_reset(srslte_ue_mib_sync_t * q);
SRSLTE_API int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t * q, SRSLTE_API int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t * q,
uint32_t max_frames_timeout, uint32_t max_frames_timeout,
uint8_t bch_payload[BCH_PAYLOAD_LEN], uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN],
uint32_t *nof_tx_ports, uint32_t *nof_tx_ports,
uint32_t *sfn_offset); uint32_t *sfn_offset);

@ -75,8 +75,31 @@ bool srslte_cell_isvalid(srslte_cell_t *cell) {
srslte_nofprb_isvalid(cell->nof_prb); srslte_nofprb_isvalid(cell->nof_prb);
} }
void srslte_cell_fprint(FILE *stream, srslte_cell_t *cell) { void srslte_cell_fprint(FILE *stream, srslte_cell_t *cell, uint32_t sfn) {
fprintf(stream, "PCI: %d, CP: %s, PRB: %d, Ports: %d\n", cell->id, srslte_cp_string(cell->cp), cell->nof_prb, cell->nof_ports); fprintf(stream, " - Cell ID: %d\n", cell->id);
fprintf(stream, " - Nof ports: %d\n", cell->nof_ports);
fprintf(stream, " - CP: %s\n", srslte_cp_string(cell->cp));
fprintf(stream, " - PRB: %d\n", cell->nof_prb);
fprintf(stream, " - PHICH Length: %s\n",
cell->phich_length == SRSLTE_PHICH_EXT ? "Extended" : "Normal");
fprintf(stream, " - PHICH Resources: ");
switch (cell->phich_resources) {
case SRSLTE_PHICH_SRSLTE_PHICH_R_1_6:
fprintf(stream, "1/6");
break;
case SRSLTE_PHICH_SRSLTE_PHICH_R_1_2:
fprintf(stream, "1/2");
break;
case SRSLTE_PHICH_R_1:
fprintf(stream, "1");
break;
case SRSLTE_PHICH_R_2:
fprintf(stream, "2");
break;
}
fprintf(stream, "\n");
fprintf(stream, " - SFN: %d\n", sfn);
} }
bool srslte_sfidx_isvalid(uint32_t sf_idx) { bool srslte_sfidx_isvalid(uint32_t sf_idx) {

@ -41,6 +41,10 @@
#include "srslte/utils/vector.h" #include "srslte/utils/vector.h"
#include "srslte/utils/debug.h" #include "srslte/utils/debug.h"
#define PBCH_RE_CP_NORM 240
#define PBCH_RE_CP_EXT 216
const uint8_t srslte_crc_mask[4][16] = { const uint8_t srslte_crc_mask[4][16] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
@ -137,8 +141,16 @@ int srslte_pbch_init(srslte_pbch_t *q, srslte_cell_t cell) {
ret = SRSLTE_ERROR; ret = SRSLTE_ERROR;
bzero(q, sizeof(srslte_pbch_t)); bzero(q, sizeof(srslte_pbch_t));
if (cell.nof_ports == 0) {
q->search_all_ports = true;
cell.nof_ports = SRSLTE_MAX_PORTS;
} else {
q->search_all_ports = false;
}
q->cell = cell; q->cell = cell;
q->nof_symbols = (SRSLTE_CP_ISNORM(q->cell.cp)) ? PBCH_RE_SRSLTE_CP_NORM : PBCH_RE_SRSLTE_CP_EXT; q->nof_symbols = (SRSLTE_CP_ISNORM(q->cell.cp)) ? PBCH_RE_CP_NORM : PBCH_RE_CP_EXT;
if (srslte_precoding_init(&q->precoding, SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp))) { if (srslte_precoding_init(&q->precoding, SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp))) {
fprintf(stderr, "Error initializing precoding\n"); fprintf(stderr, "Error initializing precoding\n");
@ -326,32 +338,6 @@ void srslte_pbch_mib_pack(srslte_cell_t *cell, uint32_t sfn, uint8_t *msg) {
srslte_bit_pack(sfn >> 2, &msg, 8); srslte_bit_pack(sfn >> 2, &msg, 8);
} }
void srslte_pbch_mib_fprint(FILE *stream, srslte_cell_t *cell, uint32_t sfn, uint32_t cell_id) {
printf(" - Cell ID: %d\n", cell_id);
printf(" - Nof ports: %d\n", cell->nof_ports);
printf(" - PRB: %d\n", cell->nof_prb);
printf(" - PHICH Length: %s\n",
cell->phich_length == SRSLTE_PHICH_EXT ? "Extended" : "Normal");
printf(" - PHICH Resources: ");
switch (cell->phich_resources) {
case SRSLTE_PHICH_SRSLTE_PHICH_R_1_6:
printf("1/6");
break;
case SRSLTE_PHICH_SRSLTE_PHICH_R_1_2:
printf("1/2");
break;
case SRSLTE_PHICH_R_1:
printf("1");
break;
case SRSLTE_PHICH_R_2:
printf("2");
break;
}
printf("\n");
printf(" - SFN: %d\n", sfn);
}
void srslte_pbch_decode_reset(srslte_pbch_t *q) { void srslte_pbch_decode_reset(srslte_pbch_t *q) {
q->frame_idx = 0; q->frame_idx = 0;
} }
@ -359,9 +345,8 @@ void srslte_pbch_decode_reset(srslte_pbch_t *q) {
void srslte_crc_set_mask(uint8_t *data, int nof_ports) { void srslte_crc_set_mask(uint8_t *data, int nof_ports) {
int i; int i;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
data[BCH_PAYLOAD_LEN + i] = (data[BCH_PAYLOAD_LEN + i] + srslte_crc_mask[nof_ports - 1][i]) % 2; data[SRSLTE_BCH_PAYLOAD_LEN + i] = (data[SRSLTE_BCH_PAYLOAD_LEN + i] + srslte_crc_mask[nof_ports - 1][i]) % 2;
} }
} }
/* Checks CRC after applying the mask for the given number of ports. /* Checks CRC after applying the mask for the given number of ports.
@ -371,13 +356,13 @@ void srslte_crc_set_mask(uint8_t *data, int nof_ports) {
* Returns 0 if the data is correct, -1 otherwise * Returns 0 if the data is correct, -1 otherwise
*/ */
uint32_t srslte_pbch_crc_check(srslte_pbch_t *q, uint8_t *bits, uint32_t nof_ports) { uint32_t srslte_pbch_crc_check(srslte_pbch_t *q, uint8_t *bits, uint32_t nof_ports) {
uint8_t data[BCH_PAYLOADCRC_LEN]; uint8_t data[SRSLTE_BCH_PAYLOADCRC_LEN];
memcpy(data, bits, BCH_PAYLOADCRC_LEN * sizeof(uint8_t)); memcpy(data, bits, SRSLTE_BCH_PAYLOADCRC_LEN * sizeof(uint8_t));
srslte_crc_set_mask(data, nof_ports); srslte_crc_set_mask(data, nof_ports);
int ret = srslte_crc_checksum(&q->crc, data, BCH_PAYLOADCRC_LEN); int ret = srslte_crc_checksum(&q->crc, data, SRSLTE_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;i++) { for (int i=0;i<SRSLTE_BCH_PAYLOAD_LEN;i++) {
chkzeros += data[i]; chkzeros += data[i];
} }
if (chkzeros) { if (chkzeros) {
@ -411,10 +396,10 @@ int decode_frame(srslte_pbch_t *q, uint32_t src, uint32_t dst, uint32_t n,
} }
/* unrate matching */ /* unrate matching */
srslte_rm_conv_rx(q->temp, 4 * nof_bits, q->rm_f, BCH_ENCODED_LEN); srslte_rm_conv_rx(q->temp, 4 * nof_bits, q->rm_f, SRSLTE_BCH_ENCODED_LEN);
/* decode */ /* decode */
srslte_viterbi_decode_f(&q->decoder, q->rm_f, q->data, BCH_PAYLOADCRC_LEN); srslte_viterbi_decode_f(&q->decoder, q->rm_f, q->data, SRSLTE_BCH_PAYLOADCRC_LEN);
if (!srslte_pbch_crc_check(q, q->data, nof_ports)) { if (!srslte_pbch_crc_check(q, q->data, nof_ports)) {
return 1; return 1;
@ -432,7 +417,7 @@ int decode_frame(srslte_pbch_t *q, uint32_t src, uint32_t dst, uint32_t n,
* Returns 1 if successfully decoded MIB, 0 if not and -1 on error * Returns 1 if successfully decoded MIB, 0 if not and -1 on error
*/ */
int srslte_pbch_decode(srslte_pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[SRSLTE_MAX_PORTS], float noise_estimate, int srslte_pbch_decode(srslte_pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[SRSLTE_MAX_PORTS], float noise_estimate,
uint8_t bch_payload[BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, uint32_t *sfn_offset) uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, uint32_t *sfn_offset)
{ {
uint32_t src, dst, nb; uint32_t src, dst, nb;
uint32_t nant; uint32_t nant;
@ -478,7 +463,12 @@ int srslte_pbch_decode(srslte_pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[SRS
ret = 0; ret = 0;
/* Try decoding for 1 to cell.nof_ports antennas */ /* Try decoding for 1 to cell.nof_ports antennas */
for (nant = 1; nant <= q->cell.nof_ports && !ret; nant++) { if (q->search_all_ports) {
nant = 1;
} else {
nant = q->cell.nof_ports;
}
do {
if (nant != 3) { if (nant != 3) {
DEBUG("Trying %d TX antennas with %d frames\n", nant, q->frame_idx); DEBUG("Trying %d TX antennas with %d frames\n", nant, q->frame_idx);
@ -517,15 +507,16 @@ int srslte_pbch_decode(srslte_pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[SRS
*nof_tx_ports = nant; *nof_tx_ports = nant;
} }
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) * SRSLTE_BCH_PAYLOAD_LEN);
} }
} }
} }
} }
} }
} }
} nant++;
} while(nant <= q->cell.nof_ports && !ret);
/* If not found, make room for the next packet of radio frame symbols */ /* If not found, make room for the next packet of radio frame symbols */
if (q->frame_idx == 4) { if (q->frame_idx == 4) {
memmove(q->llr, &q->llr[nof_bits], nof_bits * 3 * sizeof(float)); memmove(q->llr, &q->llr[nof_bits], nof_bits * 3 * sizeof(float));
@ -537,7 +528,7 @@ int srslte_pbch_decode(srslte_pbch_t *q, cf_t *slot1_symbols, cf_t *ce_slot1[SRS
/** Converts the MIB message to symbols mapped to SLOT #1 ready for transmission /** Converts the MIB message to symbols mapped to SLOT #1 ready for transmission
*/ */
int srslte_pbch_encode(srslte_pbch_t *q, uint8_t bch_payload[BCH_PAYLOAD_LEN], cf_t *slot1_symbols[SRSLTE_MAX_PORTS]) { int srslte_pbch_encode(srslte_pbch_t *q, uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], cf_t *slot1_symbols[SRSLTE_MAX_PORTS]) {
int i; int i;
int nof_bits; int nof_bits;
cf_t *x[SRSLTE_MAX_LAYERS]; cf_t *x[SRSLTE_MAX_LAYERS];
@ -560,15 +551,15 @@ int srslte_pbch_encode(srslte_pbch_t *q, uint8_t bch_payload[BCH_PAYLOAD_LEN], c
memset(&x[q->cell.nof_ports], 0, sizeof(cf_t*) * (SRSLTE_MAX_LAYERS - q->cell.nof_ports)); memset(&x[q->cell.nof_ports], 0, sizeof(cf_t*) * (SRSLTE_MAX_LAYERS - q->cell.nof_ports));
if (q->frame_idx == 0) { if (q->frame_idx == 0) {
memcpy(q->data, bch_payload, sizeof(uint8_t) * BCH_PAYLOAD_LEN); memcpy(q->data, bch_payload, sizeof(uint8_t) * SRSLTE_BCH_PAYLOAD_LEN);
/* encode & modulate */ /* encode & modulate */
srslte_crc_attach(&q->crc, q->data, BCH_PAYLOAD_LEN); srslte_crc_attach(&q->crc, q->data, SRSLTE_BCH_PAYLOAD_LEN);
srslte_crc_set_mask(q->data, q->cell.nof_ports); srslte_crc_set_mask(q->data, q->cell.nof_ports);
srslte_convcoder_encode(&q->encoder, q->data, q->data_enc, BCH_PAYLOADCRC_LEN); srslte_convcoder_encode(&q->encoder, q->data, q->data_enc, SRSLTE_BCH_PAYLOADCRC_LEN);
srslte_rm_conv_tx(q->data_enc, BCH_ENCODED_LEN, q->rm_b, 4 * nof_bits); srslte_rm_conv_tx(q->data_enc, SRSLTE_BCH_ENCODED_LEN, q->rm_b, 4 * nof_bits);
} }
srslte_scrambling_b_offset(&q->seq, &q->rm_b[q->frame_idx * nof_bits], srslte_scrambling_b_offset(&q->seq, &q->rm_b[q->frame_idx * nof_bits],

@ -47,7 +47,7 @@ srslte_cell_t cell = {
int nof_frames = 1; int nof_frames = 1;
uint8_t bch_payload_file[BCH_PAYLOAD_LEN] = {0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t bch_payload_file[SRSLTE_BCH_PAYLOAD_LEN] = {0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
#define FLEN (10*SRSLTE_SF_LEN(srslte_symbol_sz(cell.nof_prb))) #define FLEN (10*SRSLTE_SF_LEN(srslte_symbol_sz(cell.nof_prb)))
@ -171,7 +171,7 @@ void base_free() {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
uint8_t bch_payload[BCH_PAYLOAD_LEN]; uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
int n; int n;
uint32_t nof_tx_ports, sfn_offset; uint32_t nof_tx_ports, sfn_offset;
cf_t *ce_slot1[SRSLTE_MAX_PORTS]; cf_t *ce_slot1[SRSLTE_MAX_PORTS];
@ -231,8 +231,8 @@ int main(int argc, char **argv) {
exit(-1); exit(-1);
} else { } else {
printf("MIB decoded OK. Nof ports: %d. SFN offset: %d Payload: ", nof_tx_ports, sfn_offset); printf("MIB decoded OK. Nof ports: %d. SFN offset: %d Payload: ", nof_tx_ports, sfn_offset);
srslte_vec_fprint_hex(stdout, bch_payload, BCH_PAYLOAD_LEN); srslte_vec_fprint_hex(stdout, bch_payload, SRSLTE_BCH_PAYLOAD_LEN);
if (nof_tx_ports == 2 && sfn_offset == 0 && !memcmp(bch_payload, bch_payload_file, BCH_PAYLOAD_LEN)) { if (nof_tx_ports == 2 && sfn_offset == 0 && !memcmp(bch_payload, bch_payload_file, SRSLTE_BCH_PAYLOAD_LEN)) {
printf("This is the signal.1.92M.dat file\n"); printf("This is the signal.1.92M.dat file\n");
exit(0); exit(0);
} else { } else {

@ -77,7 +77,7 @@ void parse_args(int argc, char **argv) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
srslte_pbch_t pbch; srslte_pbch_t pbch;
uint8_t bch_payload_tx[BCH_PAYLOAD_LEN], bch_payload_rx[BCH_PAYLOAD_LEN]; uint8_t bch_payload_tx[SRSLTE_BCH_PAYLOAD_LEN], bch_payload_rx[SRSLTE_BCH_PAYLOAD_LEN];
int i, j; int i, j;
cf_t *ce[SRSLTE_MAX_PORTS]; cf_t *ce[SRSLTE_MAX_PORTS];
int nof_re; int nof_re;
@ -111,7 +111,7 @@ int main(int argc, char **argv) {
} }
srand(time(NULL)); srand(time(NULL));
for (i=0;i<BCH_PAYLOAD_LEN;i++) { for (i=0;i<SRSLTE_BCH_PAYLOAD_LEN;i++) {
bch_payload_tx[i] = rand()%2; bch_payload_tx[i] = rand()%2;
} }
@ -138,11 +138,11 @@ int main(int argc, char **argv) {
} }
printf("Tx ports: %d - Rx ports: %d\n", cell.nof_ports, nof_rx_ports); printf("Tx ports: %d - Rx ports: %d\n", cell.nof_ports, nof_rx_ports);
printf("Tx payload: "); printf("Tx payload: ");
srslte_vec_fprint_hex(stdout, bch_payload_tx, BCH_PAYLOAD_LEN); srslte_vec_fprint_hex(stdout, bch_payload_tx, SRSLTE_BCH_PAYLOAD_LEN);
printf("Rx payload: "); printf("Rx payload: ");
srslte_vec_fprint_hex(stdout, bch_payload_rx, BCH_PAYLOAD_LEN); srslte_vec_fprint_hex(stdout, bch_payload_rx, SRSLTE_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) * SRSLTE_BCH_PAYLOAD_LEN)) {
printf("OK\n"); printf("OK\n");
exit(0); exit(0);
} else { } else {

@ -37,17 +37,26 @@
#include "srslte/utils/vector.h" #include "srslte/utils/vector.h"
int srslte_ue_mib_init(srslte_ue_mib_t * q, int srslte_ue_mib_init(srslte_ue_mib_t * q,
srslte_cell_t cell) srslte_cell_t cell)
{ {
int ret = SRSLTE_ERROR_INVALID_INPUTS; int ret = SRSLTE_ERROR_INVALID_INPUTS;
if (q != NULL && if (q != NULL &&
cell.nof_ports <= SRSLTE_UE_MIB_MAX_PORTS) cell.nof_ports <= SRSLTE_MAX_PORTS)
{ {
ret = SRSLTE_ERROR; ret = SRSLTE_ERROR;
bzero(q, sizeof(srslte_ue_mib_t)); bzero(q, sizeof(srslte_ue_mib_t));
if (srslte_pbch_init(&q->pbch, cell)) {
fprintf(stderr, "Error initiating PBCH\n");
goto clean_exit;
}
if (cell.nof_ports == 0) {
cell.nof_ports = SRSLTE_MAX_PORTS;
}
q->sf_symbols = srslte_vec_malloc(SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t)); q->sf_symbols = srslte_vec_malloc(SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
if (!q->sf_symbols) { if (!q->sf_symbols) {
perror("malloc"); perror("malloc");
@ -70,10 +79,6 @@ int srslte_ue_mib_init(srslte_ue_mib_t * q,
fprintf(stderr, "Error initializing reference signal\n"); fprintf(stderr, "Error initializing reference signal\n");
goto clean_exit; goto clean_exit;
} }
if (srslte_pbch_init(&q->pbch, cell)) {
fprintf(stderr, "Error initiating PBCH\n");
goto clean_exit;
}
srslte_ue_mib_reset(q); srslte_ue_mib_reset(q);
ret = SRSLTE_SUCCESS; ret = SRSLTE_SUCCESS;
@ -91,7 +96,7 @@ void srslte_ue_mib_free(srslte_ue_mib_t * q)
if (q->sf_symbols) { if (q->sf_symbols) {
free(q->sf_symbols); free(q->sf_symbols);
} }
for (int i=0;i<SRSLTE_UE_MIB_MAX_PORTS;i++) { for (int i=0;i<SRSLTE_MAX_PORTS;i++) {
if (q->ce[i]) { if (q->ce[i]) {
free(q->ce[i]); free(q->ce[i]);
} }
@ -113,7 +118,7 @@ void srslte_ue_mib_reset(srslte_ue_mib_t * q)
} }
int srslte_ue_mib_decode(srslte_ue_mib_t * q, cf_t *input, int srslte_ue_mib_decode(srslte_ue_mib_t * q, cf_t *input,
uint8_t bch_payload[BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, uint32_t *sfn_offset) uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, uint32_t *sfn_offset)
{ {
int ret = SRSLTE_SUCCESS; int ret = SRSLTE_SUCCESS;
cf_t *ce_slot1[SRSLTE_MAX_PORTS]; cf_t *ce_slot1[SRSLTE_MAX_PORTS];
@ -163,7 +168,8 @@ int srslte_ue_mib_sync_init(srslte_ue_mib_sync_t *q,
void *stream_handler) void *stream_handler)
{ {
srslte_cell_t cell; srslte_cell_t cell;
cell.nof_ports = SRSLTE_UE_MIB_MAX_PORTS; // If the ports are set to 0, ue_mib goes through 1, 2 and 4 ports to blindly detect nof_ports
cell.nof_ports = 0;
cell.id = cell_id; cell.id = cell_id;
cell.cp = cp; cell.cp = cp;
cell.nof_prb = SRSLTE_UE_MIB_NOF_PRB; cell.nof_prb = SRSLTE_UE_MIB_NOF_PRB;
@ -193,7 +199,7 @@ void srslte_ue_mib_sync_reset(srslte_ue_mib_sync_t * q) {
int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t * q, int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t * q,
uint32_t max_frames_timeout, uint32_t max_frames_timeout,
uint8_t bch_payload[BCH_PAYLOAD_LEN], uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN],
uint32_t *nof_tx_ports, uint32_t *nof_tx_ports,
uint32_t *sfn_offset) uint32_t *sfn_offset)
{ {

@ -247,7 +247,7 @@ int main(int argc, char **argv) {
#endif #endif
uint32_t nof_trials = 0; uint32_t nof_trials = 0;
int n; int n;
uint8_t bch_payload[BCH_PAYLOAD_LEN]; uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
uint32_t sfn_offset; uint32_t sfn_offset;
parse_args(&prog_args, argc, argv); parse_args(&prog_args, argc, argv);
@ -393,7 +393,7 @@ int main(int argc, char **argv) {
exit(-1); exit(-1);
} else if (n == SRSLTE_UE_MIB_FOUND) { } else if (n == SRSLTE_UE_MIB_FOUND) {
srslte_pbch_mib_unpack(bch_payload, &cell, &sfn); srslte_pbch_mib_unpack(bch_payload, &cell, &sfn);
srslte_pbch_mib_fprint(stdout, &cell, sfn, cell.id); srslte_cell_fprint(stdout, &cell, sfn);
printf("Decoded MIB. SFN: %d, offset: %d\n", sfn, sfn_offset); printf("Decoded MIB. SFN: %d, offset: %d\n", sfn, sfn_offset);
sfn = (sfn + sfn_offset)%1024; sfn = (sfn + sfn_offset)%1024;
state = DECODE_PDSCH; state = DECODE_PDSCH;

Loading…
Cancel
Save