mirror of https://github.com/pvnis/srsRAN_4G.git
adding NPDCCH
parent
073c57dc3d
commit
81b46723f6
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @file dci_nbiot.h
|
||||
*
|
||||
* @brief Downlink control information (DCI) for NB-IoT.
|
||||
*
|
||||
* Packing/Unpacking functions to convert between bit streams
|
||||
* and packed DCI UL/DL grants defined in ra_nbiot.h
|
||||
*
|
||||
* Reference: 3GPP TS 36.212 version 13.2.0 Release 13 Sec. 6.4.3
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_DCI_NBIOT_H
|
||||
#define SRSLTE_DCI_NBIOT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "srslte/config.h"
|
||||
#include "srslte/phy/common/phy_common.h"
|
||||
#include "srslte/phy/phch/dci.h"
|
||||
#include "srslte/phy/phch/ra_nbiot.h"
|
||||
|
||||
#define SRSLTE_DCI_MAX_BITS 128
|
||||
#define SRSLTE_NBIOT_RAR_GRANT_LEN 15
|
||||
|
||||
SRSLTE_API void srslte_nbiot_dci_rar_grant_unpack(srslte_nbiot_dci_rar_grant_t* rar,
|
||||
const uint8_t grant[SRSLTE_NBIOT_RAR_GRANT_LEN]);
|
||||
|
||||
SRSLTE_API int srslte_nbiot_dci_msg_to_dl_grant(const srslte_dci_msg_t* msg,
|
||||
const uint16_t msg_rnti,
|
||||
srslte_ra_nbiot_dl_dci_t* dl_dci,
|
||||
srslte_ra_nbiot_dl_grant_t* grant,
|
||||
const uint32_t sfn,
|
||||
const uint32_t sf_idx,
|
||||
const uint32_t r_max,
|
||||
const srslte_nbiot_mode_t mode);
|
||||
|
||||
SRSLTE_API int srslte_nbiot_dci_msg_to_ul_grant(const srslte_dci_msg_t* msg,
|
||||
srslte_ra_nbiot_ul_dci_t* ul_dci,
|
||||
srslte_ra_nbiot_ul_grant_t* grant,
|
||||
const uint32_t rx_tti,
|
||||
const srslte_npusch_sc_spacing_t spacing);
|
||||
|
||||
SRSLTE_API int
|
||||
srslte_nbiot_dci_rar_to_ul_grant(srslte_nbiot_dci_rar_grant_t* rar, srslte_ra_nbiot_ul_grant_t* grant, uint32_t rx_tti);
|
||||
|
||||
SRSLTE_API bool srslte_nbiot_dci_location_isvalid(const srslte_dci_location_t* c);
|
||||
|
||||
SRSLTE_API int srslte_dci_msg_pack_npdsch(const srslte_ra_nbiot_dl_dci_t* data,
|
||||
const srslte_dci_format_t format,
|
||||
srslte_dci_msg_t* msg,
|
||||
const bool crc_is_crnti);
|
||||
|
||||
SRSLTE_API int
|
||||
srslte_dci_msg_unpack_npdsch(const srslte_dci_msg_t* msg, srslte_ra_nbiot_dl_dci_t* data, const bool crc_is_crnti);
|
||||
|
||||
SRSLTE_API int srslte_dci_msg_unpack_npusch(const srslte_dci_msg_t* msg, srslte_ra_nbiot_ul_dci_t* data);
|
||||
|
||||
SRSLTE_API uint32_t srslte_dci_nbiot_format_sizeof(srslte_dci_format_t format);
|
||||
|
||||
#endif // SRSLTE_DCI_NBIOT_H
|
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_NPDCCH_H
|
||||
#define SRSLTE_NPDCCH_H
|
||||
|
||||
#include "srslte/config.h"
|
||||
#include "srslte/phy/common/phy_common.h"
|
||||
#include "srslte/phy/fec/convcoder.h"
|
||||
#include "srslte/phy/fec/crc.h"
|
||||
#include "srslte/phy/fec/rm_conv.h"
|
||||
#include "srslte/phy/fec/viterbi.h"
|
||||
#include "srslte/phy/mimo/layermap.h"
|
||||
#include "srslte/phy/mimo/precoding.h"
|
||||
#include "srslte/phy/modem/demod_soft.h"
|
||||
#include "srslte/phy/modem/mod.h"
|
||||
#include "srslte/phy/phch/dci.h"
|
||||
#include "srslte/phy/phch/regs.h"
|
||||
#include "srslte/phy/scrambling/scrambling.h"
|
||||
|
||||
#define SRSLTE_RARNTI_END_NBIOT 0x0100
|
||||
#define SRSLTE_NBIOT_NUM_NRS_SYMS 8
|
||||
#define SRSLTE_NPDCCH_MAX_RE (SRSLTE_NRE * SRSLTE_CP_NORM_SF_NSYMB - SRSLTE_NBIOT_NUM_NRS_SYMS)
|
||||
|
||||
#define SRSLTE_NBIOT_DCI_MAX_SIZE 23
|
||||
#define SRSLTE_AL_REPETITION_USS 64 // Higher layer configured parameter al-Repetition-USS
|
||||
|
||||
typedef enum SRSLTE_API {
|
||||
SRSLTE_NPDCCH_FORMAT1 = 0,
|
||||
SRSLTE_NPDCCH_FORMAT0_LOWER_HALF,
|
||||
SRSLTE_NPDCCH_FORMAT0_UPPER_HALF,
|
||||
SRSLTE_NPDCCH_FORMAT_NITEMS
|
||||
} srslte_npdcch_format_t;
|
||||
static const char srslte_npdcch_format_text[SRSLTE_NPDCCH_FORMAT_NITEMS][30] = {"Format 1",
|
||||
"Format 0 (Lower Half)",
|
||||
"Format 0 (Upper Half)"};
|
||||
|
||||
/**
|
||||
* @brief Narrowband Physical downlink control channel (NPDCCH)
|
||||
*
|
||||
* Reference: 3GPP TS 36.211 version 13.2.0 Release 11 Sec. 6.8 and 10.2.5
|
||||
*/
|
||||
typedef struct SRSLTE_API {
|
||||
srslte_nbiot_cell_t cell;
|
||||
uint32_t nof_cce;
|
||||
uint32_t ncce_bits;
|
||||
uint32_t max_bits;
|
||||
uint32_t i_n_start; /// start of the first OFDM symbol (signalled through NB-SIB1)
|
||||
uint32_t nof_nbiot_refs; /// number of NRS symbols per OFDM symbol
|
||||
uint32_t nof_lte_refs; /// number of CRS symbols per OFDM symbol
|
||||
uint32_t num_decoded_symbols;
|
||||
|
||||
/* buffers */
|
||||
cf_t* ce[SRSLTE_MAX_PORTS];
|
||||
cf_t* symbols[SRSLTE_MAX_PORTS];
|
||||
cf_t* x[SRSLTE_MAX_PORTS];
|
||||
cf_t* d;
|
||||
uint8_t* e;
|
||||
float rm_f[3 * (SRSLTE_DCI_MAX_BITS + 16)];
|
||||
float* llr[2]; // Two layers of LLRs for Format0 and Format1 NPDCCH
|
||||
|
||||
/* tx & rx objects */
|
||||
srslte_modem_table_t mod;
|
||||
srslte_sequence_t seq[SRSLTE_NOF_SF_X_FRAME];
|
||||
srslte_viterbi_t decoder;
|
||||
srslte_crc_t crc;
|
||||
|
||||
} srslte_npdcch_t;
|
||||
|
||||
SRSLTE_API int srslte_npdcch_init(srslte_npdcch_t* q);
|
||||
|
||||
SRSLTE_API void srslte_npdcch_free(srslte_npdcch_t* q);
|
||||
|
||||
SRSLTE_API int srslte_npdcch_set_cell(srslte_npdcch_t* q, srslte_nbiot_cell_t cell);
|
||||
|
||||
/// Encoding function
|
||||
SRSLTE_API int srslte_npdcch_encode(srslte_npdcch_t* q,
|
||||
srslte_dci_msg_t* msg,
|
||||
srslte_dci_location_t location,
|
||||
uint16_t rnti,
|
||||
cf_t* sf_symbols[SRSLTE_MAX_PORTS],
|
||||
uint32_t nsubframe);
|
||||
|
||||
/// Decoding functions: Extract the LLRs and save them in the srslte_npdcch_t object
|
||||
SRSLTE_API int srslte_npdcch_extract_llr(srslte_npdcch_t* q,
|
||||
cf_t* sf_symbols,
|
||||
cf_t* ce[SRSLTE_MAX_PORTS],
|
||||
float noise_estimate,
|
||||
uint32_t sf_idx);
|
||||
|
||||
/// Decoding functions: Try to decode a DCI message after calling srslte_npdcch_extract_llr
|
||||
SRSLTE_API int srslte_npdcch_decode_msg(srslte_npdcch_t* q,
|
||||
srslte_dci_msg_t* msg,
|
||||
srslte_dci_location_t* location,
|
||||
srslte_dci_format_t format,
|
||||
uint16_t* crc_rem);
|
||||
|
||||
SRSLTE_API int
|
||||
srslte_npdcch_dci_decode(srslte_npdcch_t* q, float* e, uint8_t* data, uint32_t E, uint32_t nof_bits, uint16_t* crc);
|
||||
|
||||
SRSLTE_API int
|
||||
srslte_npdcch_dci_encode(srslte_npdcch_t* q, uint8_t* data, uint8_t* e, uint32_t nof_bits, uint32_t E, uint16_t rnti);
|
||||
|
||||
SRSLTE_API void
|
||||
srslte_npdcch_dci_encode_conv(srslte_npdcch_t* q, uint8_t* data, uint32_t nof_bits, uint8_t* coded_data, uint16_t rnti);
|
||||
|
||||
SRSLTE_API uint32_t srslte_npdcch_ue_locations(srslte_dci_location_t* c, uint32_t max_candidates);
|
||||
|
||||
SRSLTE_API uint32_t srslte_npdcch_common_locations(srslte_dci_location_t* c, uint32_t max_candidates);
|
||||
|
||||
int srslte_npdcch_cp(srslte_npdcch_t* q, cf_t* input, cf_t* output, bool put, srslte_npdcch_format_t format);
|
||||
int srslte_npdcch_put(srslte_npdcch_t* q, cf_t* symbols, cf_t* sf_symbols, srslte_npdcch_format_t format);
|
||||
int srslte_npdcch_get(srslte_npdcch_t* q, cf_t* symbols, cf_t* sf_symbols, srslte_npdcch_format_t format);
|
||||
|
||||
#endif // SRSLTE_NPDCCH_H
|
@ -0,0 +1,800 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include "prb_dl.h"
|
||||
#include "srslte/phy/common/phy_common.h"
|
||||
#include "srslte/phy/phch/dci_nbiot.h"
|
||||
#include "srslte/phy/phch/npdcch.h"
|
||||
#include "srslte/phy/utils/bit.h"
|
||||
#include "srslte/phy/utils/debug.h"
|
||||
#include "srslte/phy/utils/vector.h"
|
||||
|
||||
#define DUMP_SIGNALS 0
|
||||
#define RE_EXT_DEBUG 0
|
||||
|
||||
/** Initializes the NPDCCH transmitter and receiver */
|
||||
int srslte_npdcch_init(srslte_npdcch_t* q)
|
||||
{
|
||||
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||||
|
||||
if (q != NULL) {
|
||||
ret = SRSLTE_ERROR;
|
||||
bzero(q, sizeof(srslte_npdcch_t));
|
||||
q->nof_cce = 2; // One Format1 NPDCCH occupying both NCCEs
|
||||
|
||||
// Allocate memory for the maximum number of NPDCCH bits, i.e. one full PRB
|
||||
q->max_bits = SRSLTE_CP_NORM_SF_NSYMB * SRSLTE_NRE * 2;
|
||||
q->ncce_bits = q->max_bits / 2;
|
||||
|
||||
INFO("Init NPDCCH: Max bits: %d, %d ports.\n", q->max_bits, q->cell.nof_ports);
|
||||
|
||||
if (srslte_modem_table_lte(&q->mod, SRSLTE_MOD_QPSK)) {
|
||||
goto clean;
|
||||
}
|
||||
if (srslte_crc_init(&q->crc, SRSLTE_LTE_CRC16, 16)) {
|
||||
goto clean;
|
||||
}
|
||||
|
||||
int poly[3] = {0x6D, 0x4F, 0x57};
|
||||
if (srslte_viterbi_init(&q->decoder, SRSLTE_VITERBI_37, poly, SRSLTE_NBIOT_DCI_MAX_SIZE + 16, true)) {
|
||||
goto clean;
|
||||
}
|
||||
|
||||
q->e = srslte_vec_malloc(sizeof(uint8_t) * q->max_bits);
|
||||
if (!q->e) {
|
||||
goto clean;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
q->llr[i] = srslte_vec_malloc(sizeof(float) * q->max_bits);
|
||||
if (!q->llr[i]) {
|
||||
goto clean;
|
||||
}
|
||||
bzero(q->llr[i], sizeof(float) * q->max_bits);
|
||||
}
|
||||
|
||||
q->d = srslte_vec_malloc(sizeof(cf_t) * q->max_bits / 2);
|
||||
if (!q->d) {
|
||||
goto clean;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < SRSLTE_MAX_PORTS; i++) {
|
||||
q->ce[i] = srslte_vec_malloc(sizeof(cf_t) * q->max_bits / 2);
|
||||
if (!q->ce[i]) {
|
||||
goto clean;
|
||||
}
|
||||
for (uint32_t k = 0; k < q->max_bits / 2; k++) {
|
||||
q->ce[i][k] = 1;
|
||||
}
|
||||
q->x[i] = srslte_vec_malloc(sizeof(cf_t) * q->max_bits / 2);
|
||||
if (!q->x[i]) {
|
||||
goto clean;
|
||||
}
|
||||
q->symbols[i] = srslte_vec_malloc(sizeof(cf_t) * q->max_bits / 2);
|
||||
if (!q->symbols[i]) {
|
||||
goto clean;
|
||||
}
|
||||
memset(q->symbols[i], 0, sizeof(cf_t) * q->max_bits / 2);
|
||||
}
|
||||
|
||||
ret = SRSLTE_SUCCESS;
|
||||
}
|
||||
clean:
|
||||
if (ret == SRSLTE_ERROR) {
|
||||
srslte_npdcch_free(q);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void srslte_npdcch_free(srslte_npdcch_t* q)
|
||||
{
|
||||
if (q->e) {
|
||||
free(q->e);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < 2; i++) {
|
||||
if (q->llr[i]) {
|
||||
free(q->llr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (q->d) {
|
||||
free(q->d);
|
||||
}
|
||||
for (uint32_t i = 0; i < SRSLTE_MAX_PORTS; i++) {
|
||||
if (q->ce[i]) {
|
||||
free(q->ce[i]);
|
||||
}
|
||||
if (q->x[i]) {
|
||||
free(q->x[i]);
|
||||
}
|
||||
if (q->symbols[i]) {
|
||||
free(q->symbols[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < SRSLTE_NOF_SF_X_FRAME; i++) {
|
||||
srslte_sequence_free(&q->seq[i]);
|
||||
}
|
||||
|
||||
srslte_modem_table_free(&q->mod);
|
||||
srslte_viterbi_free(&q->decoder);
|
||||
|
||||
bzero(q, sizeof(srslte_npdcch_t));
|
||||
}
|
||||
|
||||
int srslte_npdcch_set_cell(srslte_npdcch_t* q, srslte_nbiot_cell_t cell)
|
||||
{
|
||||
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||||
|
||||
if (q != NULL && srslte_nbiot_cell_isvalid(&cell)) {
|
||||
ret = SRSLTE_ERROR;
|
||||
|
||||
if (q->cell.n_id_ncell != cell.n_id_ncell || q->cell.base.nof_prb == 0) {
|
||||
q->cell = cell;
|
||||
|
||||
if (q->cell.mode == SRSLTE_NBIOT_MODE_INBAND_SAME_PCI || q->cell.mode == SRSLTE_NBIOT_MODE_INBAND_DIFFERENT_PCI) {
|
||||
q->i_n_start = 3;
|
||||
} else {
|
||||
q->i_n_start = 0;
|
||||
}
|
||||
|
||||
// FIXME: Add case for LTE cell with 4 ports
|
||||
if (q->cell.nof_ports == 1) {
|
||||
q->nof_nbiot_refs = 2;
|
||||
} else {
|
||||
q->nof_nbiot_refs = 4;
|
||||
}
|
||||
|
||||
if (q->cell.base.nof_ports == 1) {
|
||||
q->nof_lte_refs = 2;
|
||||
} else {
|
||||
q->nof_lte_refs = 4;
|
||||
}
|
||||
|
||||
// Update the maximum number of NPDCCH bits, i.e. one PRB minus the starting offset minus the reference symbols
|
||||
q->max_bits = srslte_ra_nbiot_dl_grant_nof_re(q->cell, q->i_n_start) * 2;
|
||||
q->ncce_bits = q->max_bits / 2;
|
||||
|
||||
for (int i = 0; i < SRSLTE_NOF_SF_X_FRAME; i++) {
|
||||
if (srslte_sequence_npdcch(&q->seq[i], 2 * i, q->cell.n_id_ncell, q->max_bits)) {
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret = SRSLTE_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int srslte_npdcch_dci_decode(srslte_npdcch_t* q, float* e, uint8_t* data, uint32_t E, uint32_t nof_bits, uint16_t* crc)
|
||||
{
|
||||
uint16_t p_bits, crc_res;
|
||||
uint8_t* x;
|
||||
|
||||
if (q != NULL) {
|
||||
if (data != NULL && E <= q->max_bits && nof_bits <= SRSLTE_DCI_MAX_BITS) {
|
||||
bzero(q->rm_f, sizeof(float) * 3 * (SRSLTE_DCI_MAX_BITS + 16));
|
||||
|
||||
uint32_t coded_len = 3 * (nof_bits + 16);
|
||||
|
||||
// unrate matching
|
||||
srslte_rm_conv_rx(e, E, q->rm_f, coded_len);
|
||||
|
||||
// viterbi decoder
|
||||
srslte_viterbi_decode_f(&q->decoder, q->rm_f, data, nof_bits + 16);
|
||||
|
||||
x = &data[nof_bits];
|
||||
p_bits = (uint16_t)srslte_bit_pack(&x, 16);
|
||||
crc_res = ((uint16_t)srslte_crc_checksum(&q->crc, data, nof_bits) & 0xffff);
|
||||
|
||||
if (crc) {
|
||||
*crc = p_bits ^ crc_res;
|
||||
}
|
||||
|
||||
return SRSLTE_SUCCESS;
|
||||
} else {
|
||||
fprintf(stderr, "Invalid parameters: E: %d, max_bits: %d, nof_bits: %d\n", E, q->max_bits, nof_bits);
|
||||
return SRSLTE_ERROR_INVALID_INPUTS;
|
||||
}
|
||||
} else {
|
||||
return SRSLTE_ERROR_INVALID_INPUTS;
|
||||
}
|
||||
}
|
||||
|
||||
/** Tries to decode a DCI message from the LLRs stored in the srslte_npdcch_t structure by the function
|
||||
* srslte_npdcch_extract_llr(). This function can be called multiple times.
|
||||
* The decoded message is stored in msg and the CRC remainder in crc_rem pointer
|
||||
*
|
||||
*/
|
||||
int srslte_npdcch_decode_msg(srslte_npdcch_t* q,
|
||||
srslte_dci_msg_t* msg,
|
||||
srslte_dci_location_t* location,
|
||||
srslte_dci_format_t format,
|
||||
uint16_t* crc_rem)
|
||||
{
|
||||
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||||
int num_decoded_symbols = 0;
|
||||
if (q != NULL && msg != NULL && srslte_nbiot_dci_location_isvalid(location)) {
|
||||
uint32_t nof_bits = (format == SRSLTE_DCI_FORMATN2) ? 15 : 23;
|
||||
uint32_t e_bits = q->ncce_bits * location->L;
|
||||
|
||||
// Get the right softbits for this aggregation level
|
||||
float* llr = (location->L == 1) ? q->llr[0] : q->llr[1];
|
||||
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
||||
DEBUG("LLR:\n");
|
||||
srslte_vec_fprint_f(stdout, llr, q->max_bits);
|
||||
}
|
||||
|
||||
double mean = 0;
|
||||
for (int i = 0; i < e_bits; i++) {
|
||||
mean += fabsf(llr[location->ncce * q->ncce_bits + i]);
|
||||
}
|
||||
mean /= e_bits;
|
||||
if (mean > 0.3) {
|
||||
ret = srslte_npdcch_dci_decode(q, &llr[location->ncce * q->ncce_bits], msg->payload, e_bits, nof_bits, crc_rem);
|
||||
if (ret == SRSLTE_SUCCESS) {
|
||||
num_decoded_symbols = e_bits / 2;
|
||||
msg->nof_bits = nof_bits;
|
||||
// Check format differentiation
|
||||
if (format == SRSLTE_DCI_FORMATN0 || format == SRSLTE_DCI_FORMATN1) {
|
||||
msg->format = (msg->payload[0] == 0) ? SRSLTE_DCI_FORMATN0 : SRSLTE_DCI_FORMATN1;
|
||||
} else {
|
||||
msg->format = format;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Error calling npdcch_dci_decode\n");
|
||||
}
|
||||
if (crc_rem) {
|
||||
DEBUG("Decoded DCI: nCCE=%d, L=%d, format=%s, msg_len=%d, mean=%f, crc_rem=0x%x\n",
|
||||
location->ncce,
|
||||
location->L,
|
||||
srslte_dci_format_string(msg->format),
|
||||
nof_bits,
|
||||
mean,
|
||||
*crc_rem);
|
||||
}
|
||||
} else {
|
||||
DEBUG("Skipping DCI: nCCE=%d, L=%d, msg_len=%d, mean=%f\n", location->ncce, location->L, nof_bits, mean);
|
||||
}
|
||||
ret = SRSLTE_SUCCESS;
|
||||
} else {
|
||||
fprintf(stderr, "Invalid parameters, location=%d,%d\n", location->ncce, location->L);
|
||||
}
|
||||
|
||||
q->num_decoded_symbols = num_decoded_symbols;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Extracts the LLRs from srslte_dci_location_t location of the subframe and stores them in the srslte_npdcch_t
|
||||
* structure. DCI messages can be extracted from this location calling the function srslte_npdcch_decode_msg(). Every
|
||||
* time this function is called (with a different location), the last demodulated symbols are overwritten and new
|
||||
* messages from other locations can be decoded
|
||||
*/
|
||||
int srslte_npdcch_extract_llr(srslte_npdcch_t* q,
|
||||
cf_t* sf_symbols,
|
||||
cf_t* ce[SRSLTE_MAX_PORTS],
|
||||
float noise_estimate,
|
||||
uint32_t sf_idx)
|
||||
{
|
||||
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||||
|
||||
/* Set pointers for layermapping & precoding */
|
||||
uint32_t num_symbols, e_bits;
|
||||
float* llr;
|
||||
cf_t* x[SRSLTE_MAX_LAYERS];
|
||||
|
||||
if (q != NULL && sf_idx < 10) {
|
||||
ret = SRSLTE_ERROR;
|
||||
|
||||
for (int i = 0; i < SRSLTE_NPDCCH_FORMAT_NITEMS; i++) {
|
||||
// set parameters according to NPDCCH format
|
||||
switch (i) {
|
||||
case SRSLTE_NPDCCH_FORMAT0_LOWER_HALF:
|
||||
e_bits = q->ncce_bits;
|
||||
llr = q->llr[0];
|
||||
break;
|
||||
case SRSLTE_NPDCCH_FORMAT0_UPPER_HALF:
|
||||
e_bits = q->ncce_bits;
|
||||
llr = &q->llr[0][q->ncce_bits];
|
||||
break;
|
||||
case SRSLTE_NPDCCH_FORMAT1:
|
||||
e_bits = q->ncce_bits * 2;
|
||||
llr = q->llr[1];
|
||||
break;
|
||||
default:
|
||||
return ret;
|
||||
}
|
||||
num_symbols = e_bits / 2;
|
||||
|
||||
DEBUG("Extracting LLRs for NPDCCH %s: E: %d, SF: %d\n", srslte_npdcch_format_text[i], e_bits, sf_idx);
|
||||
|
||||
if (i != SRSLTE_NPDCCH_FORMAT0_UPPER_HALF) {
|
||||
// don't overwrite lower half LLRs
|
||||
bzero(llr, sizeof(float) * q->max_bits);
|
||||
}
|
||||
|
||||
// number of layers equals number of ports
|
||||
for (int f = 0; f < q->cell.nof_ports; f++) {
|
||||
x[f] = q->x[f];
|
||||
}
|
||||
memset(&x[q->cell.nof_ports], 0, sizeof(cf_t*) * (SRSLTE_MAX_LAYERS - q->cell.nof_ports));
|
||||
|
||||
// extract symbols
|
||||
int n = srslte_npdcch_get(q, sf_symbols, q->symbols[0], i);
|
||||
if (num_symbols != n) {
|
||||
fprintf(stderr, "Expected %d NPDCCH symbols but got %d symbols\n", num_symbols, n);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if DUMP_SIGNALS
|
||||
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
||||
DEBUG("SAVED FILE npdcch_rx_mapping_output.bin: NPDCCH after extracting symbols\n");
|
||||
srslte_vec_save_file("npdcch_rx_mapping_output.bin", q->symbols[0], n * sizeof(cf_t));
|
||||
}
|
||||
#endif
|
||||
|
||||
// extract channel estimates
|
||||
for (int p = 0; p < q->cell.nof_ports; p++) {
|
||||
n = srslte_npdcch_get(q, ce[p], q->ce[p], i);
|
||||
if (num_symbols != n) {
|
||||
fprintf(stderr, "Expected %d NPDCCH symbols but got %d symbols\n", num_symbols, n);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
// in control channels, only diversity is supported
|
||||
if (q->cell.nof_ports == 1) {
|
||||
// no need for layer demapping
|
||||
srslte_predecoding_single(q->symbols[0], q->ce[0], q->d, NULL, num_symbols, 1.0, noise_estimate);
|
||||
} else {
|
||||
srslte_predecoding_diversity(q->symbols[0], q->ce, x, q->cell.nof_ports, num_symbols, 1.0);
|
||||
srslte_layerdemap_diversity(x, q->d, q->cell.nof_ports, num_symbols / q->cell.nof_ports);
|
||||
}
|
||||
|
||||
#if DUMP_SIGNALS
|
||||
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
||||
DEBUG("SAVED FILE npdcch_rx_predecode_output.bin: NPDCCH after predecoding symbols\n");
|
||||
srslte_vec_save_file("npdcch_rx_predecode_output.bin", q->d, q->num_decoded_symbols * sizeof(cf_t));
|
||||
}
|
||||
#endif
|
||||
|
||||
// demodulate symbols
|
||||
srslte_demod_soft_demodulate(SRSLTE_MOD_QPSK, q->d, llr, num_symbols);
|
||||
|
||||
// descramble
|
||||
srslte_scrambling_f_offset(&q->seq[sf_idx], llr, 0, e_bits);
|
||||
|
||||
#if DUMP_SIGNALS
|
||||
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
||||
DEBUG("SAVED FILE npdcch_rx_descramble_output.bin: NPDCCH after de-scrambling\n");
|
||||
srslte_vec_save_file("npdcch_rx_descramble_output.bin", llr, e_bits);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ret = SRSLTE_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void crc_set_mask_rnti(uint8_t* crc, uint16_t rnti)
|
||||
{
|
||||
uint8_t mask[16] = {};
|
||||
uint8_t* r = mask;
|
||||
|
||||
DEBUG("Mask CRC with RNTI 0x%x\n", rnti);
|
||||
|
||||
srslte_bit_unpack(rnti, &r, 16);
|
||||
for (uint32_t i = 0; i < 16; i++) {
|
||||
crc[i] = (crc[i] + mask[i]) % 2;
|
||||
}
|
||||
}
|
||||
|
||||
void srslte_npdcch_dci_encode_conv(srslte_npdcch_t* q,
|
||||
uint8_t* data,
|
||||
uint32_t nof_bits,
|
||||
uint8_t* coded_data,
|
||||
uint16_t rnti)
|
||||
{
|
||||
srslte_convcoder_t encoder;
|
||||
int poly[3] = {0x6D, 0x4F, 0x57};
|
||||
encoder.K = 7;
|
||||
encoder.R = 3;
|
||||
encoder.tail_biting = true;
|
||||
memcpy(encoder.poly, poly, 3 * sizeof(int));
|
||||
|
||||
srslte_crc_attach(&q->crc, data, nof_bits);
|
||||
crc_set_mask_rnti(&data[nof_bits], rnti);
|
||||
|
||||
#if DUMP_SIGNALS
|
||||
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
||||
DEBUG("SAVED FILE npdcch_tx_convcoder_input.bin: NPDCCH before convolution coding\n");
|
||||
srslte_vec_save_file("npdcch_tx_convcoder_input.bin", data, nof_bits + 16);
|
||||
}
|
||||
#endif
|
||||
|
||||
srslte_convcoder_encode(&encoder, data, coded_data, nof_bits + 16);
|
||||
}
|
||||
|
||||
/** 36.212 5.3.3.2 to 5.3.3.4
|
||||
* TODO: UE transmit antenna selection CRC mask
|
||||
*/
|
||||
int srslte_npdcch_dci_encode(srslte_npdcch_t* q,
|
||||
uint8_t* data,
|
||||
uint8_t* e,
|
||||
uint32_t nof_bits,
|
||||
uint32_t E,
|
||||
uint16_t rnti)
|
||||
{
|
||||
uint8_t tmp[3 * (SRSLTE_DCI_MAX_BITS + 16)];
|
||||
|
||||
if (q != NULL && data != NULL && e != NULL && nof_bits < SRSLTE_DCI_MAX_BITS && E <= q->max_bits) {
|
||||
srslte_npdcch_dci_encode_conv(q, data, nof_bits, tmp, rnti);
|
||||
|
||||
DEBUG("CConv output: ");
|
||||
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
||||
srslte_vec_fprint_b(stdout, tmp, 3 * (nof_bits + 16));
|
||||
}
|
||||
|
||||
srslte_rm_conv_tx(tmp, 3 * (nof_bits + 16), e, E);
|
||||
|
||||
return SRSLTE_SUCCESS;
|
||||
} else {
|
||||
return SRSLTE_ERROR_INVALID_INPUTS;
|
||||
}
|
||||
}
|
||||
|
||||
int srslte_npdcch_encode(srslte_npdcch_t* q,
|
||||
srslte_dci_msg_t* msg,
|
||||
srslte_dci_location_t location,
|
||||
uint16_t rnti,
|
||||
cf_t* sf_symbols[SRSLTE_MAX_PORTS],
|
||||
uint32_t nsubframe)
|
||||
{
|
||||
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||||
|
||||
if (q != NULL && sf_symbols != NULL && nsubframe < 10 && srslte_nbiot_dci_location_isvalid(&location)) {
|
||||
ret = SRSLTE_ERROR;
|
||||
uint32_t e_bits = q->nof_cce * q->ncce_bits;
|
||||
uint32_t nof_symbols = e_bits / 2;
|
||||
|
||||
if (msg->nof_bits < SRSLTE_DCI_MAX_BITS - 16) {
|
||||
DEBUG("Encoding DCI: Nbits: %d, E: %d, nCCE: %d, L: %d, RNTI: 0x%x, sf_idx: %d\n",
|
||||
msg->nof_bits,
|
||||
e_bits,
|
||||
location.ncce,
|
||||
location.L,
|
||||
rnti,
|
||||
nsubframe);
|
||||
|
||||
if (srslte_npdcch_dci_encode(q, msg->payload, q->e, msg->nof_bits, e_bits, rnti) != SRSLTE_SUCCESS) {
|
||||
fprintf(stderr, "Error encoding DCI\n");
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
|
||||
// number of layers equals number of ports
|
||||
cf_t* x[SRSLTE_MAX_LAYERS] = {NULL};
|
||||
for (int i = 0; i < q->cell.nof_ports; i++) {
|
||||
x[i] = q->x[i];
|
||||
}
|
||||
memset(&x[q->cell.nof_ports], 0, sizeof(cf_t*) * (SRSLTE_MAX_LAYERS - q->cell.nof_ports));
|
||||
|
||||
#if DUMP_SIGNALS
|
||||
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
||||
DEBUG("SAVED FILE npdcch_tx_scramble_input.bin: NPDCCH before scrambling\n");
|
||||
srslte_vec_save_file("npdcch_tx_scramble_input.bin", q->e, e_bits);
|
||||
}
|
||||
#endif
|
||||
|
||||
srslte_scrambling_b_offset(&q->seq[nsubframe], q->e, 72 * location.ncce, e_bits);
|
||||
|
||||
#if DUMP_SIGNALS
|
||||
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
||||
DEBUG("SAVED FILE npdcch_tx_mod_input.bin: NPDCCH before modulation\n");
|
||||
srslte_vec_save_file("npdcch_tx_mod_input.bin", q->e, e_bits);
|
||||
}
|
||||
#endif
|
||||
|
||||
srslte_mod_modulate(&q->mod, q->e, q->d, e_bits);
|
||||
|
||||
#if DUMP_SIGNALS
|
||||
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
||||
DEBUG("SAVED FILE npdcch_tx_precode_input.bin: NPDCCH before precoding symbols\n");
|
||||
srslte_vec_save_file("npdcch_tx_precode_input.bin", q->d, nof_symbols * sizeof(cf_t));
|
||||
}
|
||||
#endif
|
||||
|
||||
// layer mapping & precoding
|
||||
if (q->cell.nof_ports > 1) {
|
||||
srslte_layermap_diversity(q->d, x, q->cell.nof_ports, nof_symbols);
|
||||
srslte_precoding_diversity(x, q->symbols, q->cell.nof_ports, nof_symbols / q->cell.nof_ports, 1.0);
|
||||
} else {
|
||||
memcpy(q->symbols[0], q->d, nof_symbols * sizeof(cf_t));
|
||||
}
|
||||
|
||||
#if DUMP_SIGNALS
|
||||
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
||||
DEBUG("SAVED FILE npdcch_tx_mapping_input.bin: NPDCCH before mapping to resource elements\n");
|
||||
srslte_vec_save_file("npdcch_tx_mapping_input.bin", q->symbols[0], nof_symbols * sizeof(cf_t));
|
||||
}
|
||||
#endif
|
||||
|
||||
// mapping to resource elements
|
||||
for (int i = 0; i < q->cell.nof_ports; i++) {
|
||||
srslte_npdcch_put(q, q->symbols[i], sf_symbols[i], SRSLTE_NPDCCH_FORMAT1);
|
||||
}
|
||||
|
||||
ret = SRSLTE_SUCCESS;
|
||||
} else {
|
||||
fprintf(stderr, "Illegal DCI message nCCE: %d, L: %d, nof_cce: %d\n", location.ncce, location.L, q->nof_cce);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Invalid parameters: L=%d, nCCE=%d\n", location.L, location.ncce);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** 36.213 v9.1.1
|
||||
* Computes up to max_candidates UE-specific candidates for DCI messages and saves them
|
||||
* in the structure pointed by c.
|
||||
* Returns the number of candidates saved in the array c.
|
||||
*/
|
||||
uint32_t srslte_npdcch_ue_locations(srslte_dci_location_t* c, uint32_t max_candidates)
|
||||
{
|
||||
// NPDCCH format 1 takes both NCCE
|
||||
c[0].L = 2;
|
||||
c[0].ncce = 0;
|
||||
|
||||
// NPDCCH format 0 only takes one NCCE so two of them may be transmitted in one subframe
|
||||
c[1].L = 1;
|
||||
c[1].ncce = 0;
|
||||
|
||||
c[2].L = 1;
|
||||
c[2].ncce = 1;
|
||||
|
||||
return max_candidates;
|
||||
}
|
||||
|
||||
uint32_t srslte_npdcch_common_locations(srslte_dci_location_t* c, uint32_t max_candidates)
|
||||
{
|
||||
return srslte_npdcch_ue_locations(c, max_candidates);
|
||||
}
|
||||
|
||||
int srslte_npdcch_cp(srslte_npdcch_t* q, cf_t* input, cf_t* output, bool put, srslte_npdcch_format_t format)
|
||||
{
|
||||
// sanity check
|
||||
if (q == NULL || input == NULL || output == NULL) {
|
||||
return SRSLTE_ERROR_INVALID_INPUTS;
|
||||
}
|
||||
|
||||
#if RE_EXT_DEBUG
|
||||
int num_extracted = 0;
|
||||
#endif
|
||||
|
||||
cf_t *in_ptr = input, *out_ptr = output;
|
||||
bool skip_crs = false;
|
||||
|
||||
if (put) {
|
||||
out_ptr += (q->i_n_start * q->cell.base.nof_prb * SRSLTE_NRE) + q->cell.nbiot_prb * SRSLTE_NRE;
|
||||
} else {
|
||||
in_ptr += (q->i_n_start * q->cell.base.nof_prb * SRSLTE_NRE) + q->cell.nbiot_prb * SRSLTE_NRE;
|
||||
}
|
||||
|
||||
if (q->cell.mode == SRSLTE_NBIOT_MODE_INBAND_SAME_PCI || q->cell.mode == SRSLTE_NBIOT_MODE_INBAND_DIFFERENT_PCI) {
|
||||
skip_crs = true;
|
||||
}
|
||||
|
||||
// start mapping at specified OFDM symbol
|
||||
for (int l = q->i_n_start; l < SRSLTE_CP_NORM_SF_NSYMB; l++) {
|
||||
uint32_t delta = (q->cell.base.nof_prb - 1) * SRSLTE_NRE; // the number of REs skipped in each OFDM symbol
|
||||
uint32_t offset = 0; // the number of REs left out before start of the REF signal RE
|
||||
if (l == 5 || l == 6 || l == 12 || l == 13) {
|
||||
// always skip NRS
|
||||
if (q->nof_nbiot_refs == 2) {
|
||||
if (l == 5 || l == 12) {
|
||||
offset = q->cell.n_id_ncell % 6;
|
||||
delta = q->cell.n_id_ncell % 6 == 5 ? 1 : 0;
|
||||
} else {
|
||||
offset = (q->cell.n_id_ncell + 3) % 6;
|
||||
delta = (q->cell.n_id_ncell + 3) % 6 == 5 ? 1 : 0;
|
||||
}
|
||||
} else if (q->nof_nbiot_refs == 4) {
|
||||
offset = q->cell.n_id_ncell % 3;
|
||||
delta = (q->cell.n_id_ncell + ((q->cell.n_id_ncell >= 5) ? 0 : 3)) % 6 == 5 ? 1 : 0;
|
||||
} else {
|
||||
// FIXME: not handled right now
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
|
||||
switch (format) {
|
||||
case SRSLTE_NPDCCH_FORMAT0_LOWER_HALF:
|
||||
prb_cp_ref(&in_ptr, &out_ptr, offset, q->nof_nbiot_refs, q->nof_nbiot_refs, put);
|
||||
// we have copied too much, rewind ptr
|
||||
if (put) {
|
||||
in_ptr -= (SRSLTE_NRE - q->nof_nbiot_refs) / 2;
|
||||
} else {
|
||||
out_ptr -= (SRSLTE_NRE - q->nof_nbiot_refs) / 2;
|
||||
}
|
||||
break;
|
||||
case SRSLTE_NPDCCH_FORMAT0_UPPER_HALF:
|
||||
// FIXME: this causes valgrind to detect an invalid memory access
|
||||
#if 0
|
||||
// skip lower half
|
||||
if (put) {
|
||||
out_ptr += SRSLTE_NRE / 2;
|
||||
} else {
|
||||
in_ptr += SRSLTE_NRE / 2;
|
||||
}
|
||||
#endif
|
||||
// copy REs
|
||||
prb_cp_ref(&in_ptr, &out_ptr, offset, q->nof_nbiot_refs, q->nof_nbiot_refs, put);
|
||||
// we have copied too much, rewind ptr
|
||||
if (put) {
|
||||
in_ptr -= (SRSLTE_NRE - q->nof_nbiot_refs) / 2;
|
||||
} else {
|
||||
out_ptr -= (SRSLTE_NRE - q->nof_nbiot_refs) / 2;
|
||||
}
|
||||
break;
|
||||
case SRSLTE_NPDCCH_FORMAT1:
|
||||
prb_cp_ref(&in_ptr, &out_ptr, offset, q->nof_nbiot_refs, q->nof_nbiot_refs, put);
|
||||
break;
|
||||
default:
|
||||
printf("Wrong NPDCCH format!\n");
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
} else if ((l == 0 || l == 4 || l == 7 || l == 11) && skip_crs) {
|
||||
// skip LTE's CRS (FIXME: use base cell ID?)
|
||||
if (q->nof_lte_refs == 2) {
|
||||
if (l == 0 || l == 7) {
|
||||
offset = q->cell.base.id % 6;
|
||||
delta = (q->cell.base.id + 3) % 6 == 2 ? 1 : 0;
|
||||
} else if (l == 4 || l == 11) {
|
||||
offset = (q->cell.base.id + 3) % 6;
|
||||
delta = (q->cell.base.id + ((q->cell.base.id <= 5) ? 3 : 0)) % 6 == 5 ? 1 : 0;
|
||||
}
|
||||
} else {
|
||||
offset = q->cell.base.id % 3;
|
||||
delta = q->cell.base.id % 3 == 2 ? 1 : 0;
|
||||
}
|
||||
|
||||
switch (format) {
|
||||
case SRSLTE_NPDCCH_FORMAT0_LOWER_HALF:
|
||||
prb_cp_ref(&in_ptr, &out_ptr, offset, q->nof_lte_refs, q->nof_lte_refs, put);
|
||||
// we have copied too much, rewind ptr
|
||||
if (put) {
|
||||
in_ptr -= (SRSLTE_NRE - q->nof_lte_refs) / 2;
|
||||
} else {
|
||||
out_ptr -= (SRSLTE_NRE - q->nof_lte_refs) / 2;
|
||||
}
|
||||
break;
|
||||
case SRSLTE_NPDCCH_FORMAT0_UPPER_HALF:
|
||||
// skip lower half
|
||||
if (put) {
|
||||
out_ptr += SRSLTE_NRE / 2;
|
||||
} else {
|
||||
in_ptr += SRSLTE_NRE / 2;
|
||||
}
|
||||
// copy REs
|
||||
prb_cp_ref(&in_ptr, &out_ptr, offset, q->nof_lte_refs, q->nof_lte_refs, put);
|
||||
// we have copied too much, rewind ptr
|
||||
if (put) {
|
||||
in_ptr -= (SRSLTE_NRE - q->nof_lte_refs) / 2;
|
||||
} else {
|
||||
out_ptr -= (SRSLTE_NRE - q->nof_lte_refs) / 2;
|
||||
}
|
||||
break;
|
||||
case SRSLTE_NPDCCH_FORMAT1:
|
||||
prb_cp_ref(&in_ptr, &out_ptr, offset, q->nof_lte_refs, q->nof_lte_refs, put);
|
||||
break;
|
||||
default:
|
||||
printf("Wrong NPDCCH format!\n");
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
} else {
|
||||
switch (format) {
|
||||
case SRSLTE_NPDCCH_FORMAT0_LOWER_HALF:
|
||||
prb_cp_half(&in_ptr, &out_ptr, 1);
|
||||
// skip upper half
|
||||
if (put) {
|
||||
out_ptr += SRSLTE_NRE / 2;
|
||||
} else {
|
||||
in_ptr += SRSLTE_NRE / 2;
|
||||
}
|
||||
break;
|
||||
case SRSLTE_NPDCCH_FORMAT0_UPPER_HALF:
|
||||
// skip lower half
|
||||
if (put) {
|
||||
out_ptr += SRSLTE_NRE / 2;
|
||||
} else {
|
||||
in_ptr += SRSLTE_NRE / 2;
|
||||
}
|
||||
prb_cp_half(&in_ptr, &out_ptr, 1);
|
||||
break;
|
||||
case SRSLTE_NPDCCH_FORMAT1:
|
||||
// occupy entire symbol
|
||||
prb_cp(&in_ptr, &out_ptr, 1);
|
||||
break;
|
||||
default:
|
||||
printf("Wrong NPDCCH format!\n");
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (put) {
|
||||
out_ptr += delta;
|
||||
} else {
|
||||
in_ptr += delta;
|
||||
}
|
||||
|
||||
#if RE_EXT_DEBUG
|
||||
printf("\nl=%d, delta=%d offset=%d\n", l, delta, offset);
|
||||
uint32_t num_extracted_this_sym = abs((int)(output - out_ptr)) - num_extracted;
|
||||
printf(" - extracted total of %d RE after symbol %d (this symbol=%d)\n",
|
||||
abs((int)(output - out_ptr)),
|
||||
l,
|
||||
num_extracted_this_sym);
|
||||
srslte_vec_fprint_c(stdout, &output[num_extracted], num_extracted_this_sym);
|
||||
num_extracted = abs((int)(output - out_ptr));
|
||||
#endif
|
||||
}
|
||||
|
||||
int r;
|
||||
if (put) {
|
||||
r = abs((int)(input - in_ptr));
|
||||
} else {
|
||||
r = abs((int)(output - out_ptr));
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts NPDCCH in the subframe
|
||||
*
|
||||
* Returns the number of symbols written to sf_symbols
|
||||
*
|
||||
* 36.211 10.3 section 6.3.5
|
||||
*/
|
||||
int srslte_npdcch_put(srslte_npdcch_t* q, cf_t* symbols, cf_t* sf_symbols, srslte_npdcch_format_t format)
|
||||
{
|
||||
return srslte_npdcch_cp(q, symbols, sf_symbols, true, format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts NPDCCH from the subframe
|
||||
*
|
||||
* Returns the number of symbols read
|
||||
*
|
||||
* 36.211 10.3 section 6.3.5
|
||||
*/
|
||||
int srslte_npdcch_get(srslte_npdcch_t* q, cf_t* sf_symbols, cf_t* symbols, srslte_npdcch_format_t format)
|
||||
{
|
||||
return srslte_npdcch_cp(q, sf_symbols, symbols, false, format);
|
||||
}
|
@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "srslte/phy/ch_estimation/chest_dl_nbiot.h"
|
||||
#include "srslte/phy/dft/ofdm.h"
|
||||
#include "srslte/phy/io/filesource.h"
|
||||
#include "srslte/phy/phch/dci_nbiot.h"
|
||||
#include "srslte/phy/phch/npdcch.h"
|
||||
#include "srslte/phy/phch/ra_nbiot.h"
|
||||
#include "srslte/phy/utils/debug.h"
|
||||
#include "srslte/phy/utils/vector.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char* input_file_name = NULL;
|
||||
srslte_dci_format_t dci_format = SRSLTE_DCI_FORMATN0;
|
||||
uint16_t rnti = 0;
|
||||
uint32_t tti = 0;
|
||||
int nof_frames = 1;
|
||||
srslte_dci_location_t dci_location = {};
|
||||
|
||||
srslte_nbiot_cell_t cell = {.base = {.nof_prb = 1, .nof_ports = 1, .cp = SRSLTE_CP_NORM, .id = 0},
|
||||
.nbiot_prb = 0,
|
||||
.n_id_ncell = 0,
|
||||
.nof_ports = 1,
|
||||
.mode = SRSLTE_NBIOT_MODE_STANDALONE};
|
||||
|
||||
void usage(char* prog)
|
||||
{
|
||||
printf("Usage: %s [cprndv] -i input_file\n", prog);
|
||||
printf("\t-c cell id [Default %d]\n", cell.base.id);
|
||||
printf("\t-p cell.nof_ports [Default %d]\n", cell.base.nof_ports);
|
||||
printf("\t-o DCI Format [Default %s]\n", srslte_dci_format_string(dci_format));
|
||||
printf("\t-L DCI location L value [Default %d]\n", dci_location.L);
|
||||
printf("\t-l DCI location ncee value [Default %d]\n", dci_location.ncce);
|
||||
printf("\t-r rnti [Default %d]\n", rnti);
|
||||
printf("\t-t tti [Default %d]\n", tti);
|
||||
printf("\t-v [set srslte_verbose to debug, default none]\n");
|
||||
}
|
||||
|
||||
void parse_args(int argc, char** argv)
|
||||
{
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "icplLrontv")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i':
|
||||
input_file_name = argv[optind];
|
||||
break;
|
||||
case 'p':
|
||||
cell.base.nof_ports = (uint32_t)strtol(argv[optind], NULL, 10);
|
||||
break;
|
||||
case 'c':
|
||||
cell.base.id = (uint32_t)strtol(argv[optind], NULL, 10);
|
||||
break;
|
||||
case 'l':
|
||||
dci_location.ncce = (uint32_t)strtol(argv[optind], NULL, 10);
|
||||
break;
|
||||
case 'L':
|
||||
dci_location.L = (uint32_t)strtol(argv[optind], NULL, 10);
|
||||
break;
|
||||
case 'r':
|
||||
rnti = (uint32_t)strtol(argv[optind], NULL, 10);
|
||||
break;
|
||||
case 'o':
|
||||
dci_format = srslte_dci_format_from_string(argv[optind]);
|
||||
if (dci_format == SRSLTE_DCI_NOF_FORMATS) {
|
||||
ERROR("Error unsupported format %s\n", argv[optind]);
|
||||
exit(-1);
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
tti = (uint32_t)strtol(argv[optind], NULL, 10);
|
||||
break;
|
||||
case 'v':
|
||||
srslte_verbose++;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
if (!input_file_name) {
|
||||
usage(argv[0]);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
cf_t * input_buffer = NULL, *fft_buffer = NULL, *ce[SRSLTE_MAX_PORTS] = {NULL};
|
||||
srslte_filesource_t fsrc;
|
||||
srslte_chest_dl_nbiot_t chest;
|
||||
srslte_ofdm_t fft;
|
||||
srslte_npdcch_t npdcch = {};
|
||||
srslte_dci_msg_t dci_rx = {};
|
||||
int ret = SRSLTE_ERROR;
|
||||
int frame_cnt = 0;
|
||||
int nof_decoded_dcis = 0;
|
||||
int nread = 0;
|
||||
|
||||
parse_args(argc, argv);
|
||||
|
||||
// we need to allocate RE's for a full 6 PRB cell
|
||||
int nof_re = 6 * SRSLTE_SF_LEN_RE(cell.base.nof_prb, cell.base.cp);
|
||||
|
||||
// init memory
|
||||
for (int i = 0; i < SRSLTE_MAX_PORTS; i++) {
|
||||
ce[i] = srslte_vec_cf_malloc(nof_re);
|
||||
if (!ce[i]) {
|
||||
perror("malloc");
|
||||
goto quit;
|
||||
}
|
||||
for (int j = 0; j < nof_re; j++) {
|
||||
ce[i][j] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (srslte_filesource_init(&fsrc, input_file_name, SRSLTE_COMPLEX_FLOAT_BIN)) {
|
||||
fprintf(stderr, "Error opening file %s\n", input_file_name);
|
||||
goto quit;
|
||||
}
|
||||
|
||||
uint32_t sf_len = SRSLTE_SF_LEN(srslte_symbol_sz(cell.base.nof_prb));
|
||||
|
||||
input_buffer = srslte_vec_cf_malloc(sf_len);
|
||||
if (!input_buffer) {
|
||||
perror("malloc");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
fft_buffer = srslte_vec_cf_malloc(sf_len);
|
||||
if (!fft_buffer) {
|
||||
perror("malloc");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
if (srslte_chest_dl_nbiot_init(&chest, SRSLTE_NBIOT_MAX_PRB)) {
|
||||
fprintf(stderr, "Error initializing equalizer\n");
|
||||
goto quit;
|
||||
}
|
||||
if (srslte_chest_dl_nbiot_set_cell(&chest, cell) != SRSLTE_SUCCESS) {
|
||||
fprintf(stderr, "Error setting equalizer cell configuration\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
if (srslte_ofdm_rx_init(&fft, cell.base.cp, input_buffer, fft_buffer, cell.base.nof_prb)) {
|
||||
fprintf(stderr, "Error initializing FFT\n");
|
||||
goto quit;
|
||||
}
|
||||
srslte_ofdm_set_freq_shift(&fft, SRSLTE_NBIOT_FREQ_SHIFT_FACTOR);
|
||||
|
||||
if (srslte_npdcch_init(&npdcch)) {
|
||||
fprintf(stderr, "Error creating NPDCCH object\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
if (srslte_npdcch_set_cell(&npdcch, cell)) {
|
||||
fprintf(stderr, "Error configuring NPDCCH object\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
do {
|
||||
nread = srslte_filesource_read(&fsrc, input_buffer, sf_len);
|
||||
|
||||
if (nread == sf_len) {
|
||||
// Run FFT and estimate channel
|
||||
srslte_ofdm_rx_sf(&fft);
|
||||
|
||||
INFO("%d.%d: Estimating channel.\n", frame_cnt, tti % 10);
|
||||
srslte_chest_dl_nbiot_estimate(&chest, fft_buffer, ce, tti % 10);
|
||||
|
||||
// Extract LLR
|
||||
float noise_est = srslte_chest_dl_nbiot_get_noise_estimate(&chest);
|
||||
if (srslte_npdcch_extract_llr(&npdcch, fft_buffer, ce, noise_est, tti % 10)) {
|
||||
fprintf(stderr, "Error extracting LLRs\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
uint16_t crc_rem = 0;
|
||||
if (srslte_npdcch_decode_msg(&npdcch, &dci_rx, &dci_location, dci_format, &crc_rem)) {
|
||||
fprintf(stderr, "Error decoding DCI message\n");
|
||||
goto quit;
|
||||
}
|
||||
if (crc_rem != rnti) {
|
||||
printf("Received invalid DCI CRC 0x%x\n", crc_rem);
|
||||
goto quit;
|
||||
} else {
|
||||
if (dci_format == SRSLTE_DCI_FORMATN0) {
|
||||
// process as UL grant
|
||||
srslte_ra_nbiot_ul_dci_t dci_unpacked;
|
||||
srslte_ra_nbiot_ul_grant_t grant;
|
||||
// Creates the UL NPUSCH resource allocation grant from a DCI format N0 message
|
||||
if (srslte_nbiot_dci_msg_to_ul_grant(&dci_rx, &dci_unpacked, &grant, tti, SRSLTE_NPUSCH_SC_SPACING_15000)) {
|
||||
fprintf(stderr, "Error unpacking DCI\n");
|
||||
goto quit;
|
||||
}
|
||||
} else {
|
||||
// process as DL grant
|
||||
srslte_ra_nbiot_dl_dci_t dci_unpacked;
|
||||
srslte_ra_nbiot_dl_grant_t grant;
|
||||
if (srslte_nbiot_dci_msg_to_dl_grant(
|
||||
&dci_rx, rnti, &dci_unpacked, &grant, tti / 10, tti % 10, 64 /* TODO: remove */, cell.mode)) {
|
||||
fprintf(stderr, "Error unpacking DCI\n");
|
||||
goto quit;
|
||||
}
|
||||
}
|
||||
nof_decoded_dcis++;
|
||||
}
|
||||
|
||||
tti++;
|
||||
if (tti == 10240) {
|
||||
tti = 0;
|
||||
frame_cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
} while (nread > 0 && frame_cnt < nof_frames);
|
||||
|
||||
quit:
|
||||
srslte_npdcch_free(&npdcch);
|
||||
srslte_filesource_free(&fsrc);
|
||||
free(input_buffer);
|
||||
free(fft_buffer);
|
||||
srslte_chest_dl_nbiot_free(&chest);
|
||||
srslte_ofdm_rx_free(&fft);
|
||||
|
||||
for (int i = 0; i < SRSLTE_MAX_PORTS; i++) {
|
||||
if (ce[i]) {
|
||||
free(ce[i]);
|
||||
}
|
||||
}
|
||||
if (nof_decoded_dcis > 0) {
|
||||
printf("Ok\n");
|
||||
ret = SRSLTE_SUCCESS;
|
||||
} else {
|
||||
printf("Error\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "srslte/phy/phch/dci_nbiot.h"
|
||||
#include "srslte/phy/phch/npdcch.h"
|
||||
#include "srslte/phy/phch/ra_nbiot.h"
|
||||
#include "srslte/phy/utils/debug.h"
|
||||
#include "srslte/phy/utils/vector.h"
|
||||
|
||||
#define RNTI (0x1234)
|
||||
#define HAVE_OFDM 0
|
||||
|
||||
srslte_dci_format_t dci_format = SRSLTE_DCI_FORMATN0;
|
||||
|
||||
srslte_nbiot_cell_t cell = {.base = {.nof_prb = 1, .nof_ports = 1, .cp = SRSLTE_CP_NORM, .id = 0},
|
||||
.nbiot_prb = 0,
|
||||
.n_id_ncell = 0,
|
||||
.nof_ports = 1,
|
||||
.mode = SRSLTE_NBIOT_MODE_STANDALONE};
|
||||
|
||||
void usage(char* prog)
|
||||
{
|
||||
printf("Usage: %s [cpndv]\n", prog);
|
||||
printf("\t-c cell id [Default %d]\n", cell.base.id);
|
||||
printf("\t-o DCI Format [Default %s]\n", srslte_dci_format_string(dci_format));
|
||||
printf("\t-p cell.nof_ports [Default %d]\n", cell.base.nof_ports);
|
||||
printf("\t-n cell.nof_prb [Default %d]\n", cell.base.nof_prb);
|
||||
printf("\t-v [set srslte_verbose to debug, default none]\n");
|
||||
}
|
||||
|
||||
void parse_args(int argc, char** argv)
|
||||
{
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "cpnov")) != -1) {
|
||||
switch (opt) {
|
||||
case 'p':
|
||||
cell.base.nof_ports = (uint32_t)strtol(argv[optind], NULL, 10);
|
||||
break;
|
||||
case 'n':
|
||||
cell.base.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10);
|
||||
break;
|
||||
case 'c':
|
||||
cell.base.id = (uint32_t)strtol(argv[optind], NULL, 10);
|
||||
break;
|
||||
case 'o':
|
||||
dci_format = srslte_dci_format_from_string(argv[optind]);
|
||||
if (dci_format == SRSLTE_DCI_NOF_FORMATS) {
|
||||
ERROR("Error unsupported format %s\n", argv[optind]);
|
||||
exit(-1);
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
srslte_verbose++;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
srslte_npdcch_t npdcch = {};
|
||||
srslte_dci_msg_t dci_tx = {}, dci_rx = {};
|
||||
srslte_dci_location_t dci_location = {};
|
||||
|
||||
uint32_t tti = 6521;
|
||||
uint16_t rnti = 0x1234;
|
||||
|
||||
cf_t* ce[SRSLTE_MAX_PORTS] = {NULL};
|
||||
cf_t* slot_symbols[SRSLTE_MAX_PORTS] = {NULL};
|
||||
int ret = SRSLTE_ERROR;
|
||||
|
||||
parse_args(argc, argv);
|
||||
|
||||
// we need to allocate RE's for a full 6 PRB cell
|
||||
int nof_re = 6 * SRSLTE_SF_LEN_RE(cell.base.nof_prb, cell.base.cp);
|
||||
|
||||
// init memory
|
||||
for (int i = 0; i < SRSLTE_MAX_PORTS; i++) {
|
||||
ce[i] = malloc(sizeof(cf_t) * nof_re);
|
||||
if (!ce[i]) {
|
||||
perror("malloc");
|
||||
exit(-1);
|
||||
}
|
||||
for (int j = 0; j < nof_re; j++) {
|
||||
ce[i][j] = 1;
|
||||
}
|
||||
slot_symbols[i] = malloc(sizeof(cf_t) * nof_re);
|
||||
if (!slot_symbols[i]) {
|
||||
perror("malloc");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
#if HAVE_OFDM
|
||||
cf_t td_signal[nof_re * 2];
|
||||
#endif
|
||||
|
||||
if (srslte_npdcch_init(&npdcch)) {
|
||||
fprintf(stderr, "Error creating NPDCCH object\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (srslte_npdcch_set_cell(&npdcch, cell)) {
|
||||
fprintf(stderr, "Error configuring NPDCCH object\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (dci_format == SRSLTE_DCI_FORMATN0) {
|
||||
// UL grant
|
||||
srslte_ra_nbiot_ul_dci_t dci = {};
|
||||
dci.format = dci_format;
|
||||
|
||||
srslte_ra_nbiot_ul_grant_t grant;
|
||||
if (srslte_ra_nbiot_ul_dci_to_grant(&dci, &grant, tti, SRSLTE_NPUSCH_SC_SPACING_15000)) {
|
||||
fprintf(stderr, "Error converting DCI message\n");
|
||||
}
|
||||
|
||||
fprintf(stderr, "FormatN0 packing not supported\n");
|
||||
return SRSLTE_ERROR;
|
||||
} else if (dci_format == SRSLTE_DCI_FORMATN1) {
|
||||
// DL grant
|
||||
srslte_ra_nbiot_dl_dci_t ra_dl = {};
|
||||
ra_dl.mcs_idx = 5;
|
||||
ra_dl.ndi = 0;
|
||||
ra_dl.rv_idx = 0;
|
||||
|
||||
// NB-IoT specific fields
|
||||
ra_dl.alloc.has_sib1 = false;
|
||||
ra_dl.alloc.is_ra = false;
|
||||
ra_dl.alloc.i_delay = 4;
|
||||
ra_dl.alloc.i_sf = 0;
|
||||
ra_dl.alloc.i_rep = 0;
|
||||
ra_dl.alloc.harq_ack = 1;
|
||||
ra_dl.alloc.i_n_start = 0;
|
||||
srslte_nbiot_dl_dci_fprint(stdout, &ra_dl);
|
||||
|
||||
// pack DCI
|
||||
srslte_dci_msg_pack_npdsch(&ra_dl, dci_format, &dci_tx, false);
|
||||
srslte_dci_location_set(&dci_location, 2, 0);
|
||||
} else {
|
||||
fprintf(stderr, "FormatN2 packing not supported\n");
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
|
||||
if (srslte_npdcch_encode(&npdcch, &dci_tx, dci_location, RNTI, slot_symbols, 0)) {
|
||||
fprintf(stderr, "Error encoding DCI message\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
// combine outputs
|
||||
for (int i = 1; i < cell.base.nof_ports; i++) {
|
||||
for (int j = 0; j < nof_re; j++) {
|
||||
slot_symbols[0][j] += slot_symbols[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
#if HAVE_OFDM
|
||||
srslte_ofdm_t ofdm_tx;
|
||||
srslte_ofdm_t ofdm_rx;
|
||||
|
||||
if (srslte_ofdm_tx_init(&ofdm_tx, SRSLTE_CP_NORM, slot_symbols[0], td_signal, cell.base.nof_prb)) {
|
||||
fprintf(stderr, "Error creating iFFT object\n");
|
||||
exit(-1);
|
||||
}
|
||||
// srslte_ofdm_set_normalize(&ofdm_tx, true);
|
||||
|
||||
if (srslte_ofdm_rx_init(&ofdm_rx, SRSLTE_CP_NORM, td_signal, slot_symbols[0], cell.base.nof_prb)) {
|
||||
fprintf(stderr, "Error initializing FFT\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// transfer into time doamin and back
|
||||
srslte_ofdm_tx_sf(&ofdm_tx);
|
||||
srslte_ofdm_rx_sf(&ofdm_rx);
|
||||
|
||||
srslte_ofdm_tx_free(&ofdm_tx);
|
||||
srslte_ofdm_rx_free(&ofdm_rx);
|
||||
#endif
|
||||
|
||||
if (srslte_npdcch_extract_llr(&npdcch, slot_symbols[0], ce, 0, 0)) {
|
||||
fprintf(stderr, "Error extracting LLRs\n");
|
||||
goto quit;
|
||||
}
|
||||
uint16_t crc_rem = 0;
|
||||
if (srslte_npdcch_decode_msg(&npdcch, &dci_rx, &dci_location, dci_format, &crc_rem)) {
|
||||
fprintf(stderr, "Error decoding DCI message\n");
|
||||
goto quit;
|
||||
}
|
||||
if (crc_rem != RNTI) {
|
||||
printf("Received invalid DCI CRC 0x%x\n", crc_rem);
|
||||
goto quit;
|
||||
}
|
||||
|
||||
// compare DCIs
|
||||
if (memcmp(dci_tx.payload, dci_rx.payload, dci_tx.nof_bits)) {
|
||||
printf("Error in DCI: Received data does not match\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
if (dci_format == SRSLTE_DCI_FORMATN0) {
|
||||
// UL grant
|
||||
// ..
|
||||
} else {
|
||||
// DL grant
|
||||
srslte_ra_nbiot_dl_dci_t dci_unpacked;
|
||||
srslte_ra_nbiot_dl_grant_t grant;
|
||||
if (srslte_nbiot_dci_msg_to_dl_grant(
|
||||
&dci_rx, rnti, &dci_unpacked, &grant, tti / 10, tti % 10, 64 /* fixme: remove */, cell.mode)) {
|
||||
fprintf(stderr, "Error unpacking DCI\n");
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
srslte_nbiot_dl_dci_fprint(stdout, &dci_unpacked);
|
||||
}
|
||||
|
||||
ret = SRSLTE_SUCCESS;
|
||||
|
||||
quit:
|
||||
srslte_npdcch_free(&npdcch);
|
||||
|
||||
for (int i = 0; i < SRSLTE_MAX_PORTS; i++) {
|
||||
if (ce[i]) {
|
||||
free(ce[i]);
|
||||
}
|
||||
if (slot_symbols[i]) {
|
||||
free(slot_symbols[i]);
|
||||
}
|
||||
}
|
||||
if (ret) {
|
||||
printf("Error\n");
|
||||
} else {
|
||||
printf("Ok\n");
|
||||
}
|
||||
exit(ret);
|
||||
}
|
Loading…
Reference in New Issue