From c5979f59eb69c98fa7116ec5ab642a8a0c7d99dd Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 16 Dec 2019 15:04:22 +0000 Subject: [PATCH] Clang format UE, eNB and lib (#850) * Clang-formated UE, eNB and lib. * Fixed compiling errors from clang-format. * Fix linking issues introduced by clang-format * Fix poor formating in initializing arrays of arrays. * Fix mistake in conflict resolution on rm_turbo.c * Re-apply clang format to gtpc_ies.h --- cmake/modules/CheckFunctionExists.c | 21 +- lib/examples/cell_search.c | 151 +- lib/examples/pdsch_enodeb.c | 513 +++--- lib/examples/pdsch_ue.c | 321 ++-- lib/examples/synch_file.c | 178 ++- lib/examples/usrp_capture.c | 118 +- lib/examples/usrp_capture_sync.c | 165 +- lib/examples/usrp_capture_sync_nbiot.c | 4 +- lib/examples/usrp_txrx.c | 168 +- lib/examples/zmq_remote_rx.c | 73 +- lib/include/srslte/asn1/gtpc.h | 5 +- lib/include/srslte/asn1/gtpc_ies.h | 436 +++-- lib/include/srslte/asn1/gtpc_msg.h | 41 +- lib/include/srslte/asn1/liblte_m2ap.h | 28 +- lib/include/srslte/asn1/liblte_mme.h | 156 +- lib/include/srslte/asn1/liblte_s1ap.h | 292 ++-- lib/include/srslte/common/bcd_helpers.h | 70 +- lib/include/srslte/common/block_queue.h | 93 +- lib/include/srslte/common/buffer_pool.h | 120 +- lib/include/srslte/common/common.h | 6 +- lib/include/srslte/common/config_file.h | 6 +- lib/include/srslte/common/crash_handler.h | 4 +- lib/include/srslte/common/gen_mch_tables.h | 11 +- lib/include/srslte/common/liblte_security.h | 92 +- lib/include/srslte/common/log_filter.h | 41 +- lib/include/srslte/common/logger_file.h | 24 +- lib/include/srslte/common/logger_stdout.h | 12 +- lib/include/srslte/common/mac_nr_pdu.h | 12 +- lib/include/srslte/common/mac_pcap.h | 28 +- lib/include/srslte/common/metrics_hub.h | 37 +- lib/include/srslte/common/nas_pcap.h | 26 +- lib/include/srslte/common/pcap.h | 551 ++++--- lib/include/srslte/common/pdu.h | 29 +- lib/include/srslte/common/pdu_queue.h | 52 +- lib/include/srslte/common/rlc_pcap.h | 37 +- lib/include/srslte/common/s1ap_pcap.h | 21 +- lib/include/srslte/common/security.h | 149 +- lib/include/srslte/common/snow_3g.h | 98 +- lib/include/srslte/common/thread_pool.h | 81 +- lib/include/srslte/common/threads.h | 92 +- lib/include/srslte/common/timeout.h | 78 +- lib/include/srslte/common/trace.h | 63 +- lib/include/srslte/common/tti_sync.h | 63 +- lib/include/srslte/common/tti_sync_cv.h | 30 +- lib/include/srslte/config.h | 29 +- .../srslte/interfaces/common_interfaces.h | 8 +- .../srslte/interfaces/epc_interfaces.h | 10 +- lib/include/srslte/interfaces/ue_interfaces.h | 18 +- lib/include/srslte/phy/agc/agc.h | 55 +- .../srslte/phy/ch_estimation/chest_common.h | 10 +- .../srslte/phy/ch_estimation/chest_dl.h | 28 +- .../srslte/phy/ch_estimation/chest_ul.h | 50 +- .../srslte/phy/ch_estimation/refsignal_dl.h | 45 +- .../srslte/phy/ch_estimation/refsignal_ul.h | 46 +- lib/include/srslte/phy/channel/ch_awgn.h | 14 +- lib/include/srslte/phy/channel/delay.h | 7 +- lib/include/srslte/phy/channel/fading.h | 7 +- lib/include/srslte/phy/channel/rlf.h | 7 +- lib/include/srslte/phy/common/phy_common.h | 185 +-- lib/include/srslte/phy/common/sequence.h | 86 +- lib/include/srslte/phy/common/timestamp.h | 8 +- lib/include/srslte/phy/dft/dft.h | 134 +- lib/include/srslte/phy/dft/dft_precoding.h | 27 +- lib/include/srslte/phy/dft/ofdm.h | 139 +- lib/include/srslte/phy/enb/enb_dl.h | 26 +- lib/include/srslte/phy/enb/enb_ul.h | 16 +- lib/include/srslte/phy/fec/cbsegm.h | 16 +- lib/include/srslte/phy/fec/convcoder.h | 14 +- lib/include/srslte/phy/fec/crc.h | 41 +- lib/include/srslte/phy/fec/rm_conv.h | 18 +- lib/include/srslte/phy/fec/rm_turbo.h | 58 +- lib/include/srslte/phy/fec/softbuffer.h | 48 +- lib/include/srslte/phy/fec/tc_interl.h | 18 +- lib/include/srslte/phy/fec/turbocoder.h | 36 +- lib/include/srslte/phy/fec/turbodecoder.h | 87 +- lib/include/srslte/phy/fec/turbodecoder_gen.h | 21 +- .../srslte/phy/fec/turbodecoder_impl.h | 21 +- .../srslte/phy/fec/turbodecoder_iter.h | 76 +- lib/include/srslte/phy/fec/turbodecoder_sse.h | 20 +- lib/include/srslte/phy/fec/turbodecoder_win.h | 812 ++++++---- lib/include/srslte/phy/fec/viterbi.h | 130 +- lib/include/srslte/phy/io/binsource.h | 33 +- lib/include/srslte/phy/io/filesink.h | 17 +- lib/include/srslte/phy/io/filesource.h | 20 +- lib/include/srslte/phy/io/format.h | 12 +- lib/include/srslte/phy/io/netsink.h | 34 +- lib/include/srslte/phy/io/netsource.h | 40 +- lib/include/srslte/phy/mimo/layermap.h | 40 +- lib/include/srslte/phy/mimo/precoding.h | 100 +- lib/include/srslte/phy/modem/demod_hard.h | 15 +- lib/include/srslte/phy/modem/demod_soft.h | 18 +- lib/include/srslte/phy/modem/mod.h | 12 +- lib/include/srslte/phy/modem/modem_table.h | 29 +- lib/include/srslte/phy/phch/cqi.h | 47 +- lib/include/srslte/phy/phch/dci.h | 54 +- lib/include/srslte/phy/phch/pbch.h | 55 +- lib/include/srslte/phy/phch/pcfich.h | 27 +- lib/include/srslte/phy/phch/pdcch.h | 110 +- lib/include/srslte/phy/phch/pdsch.h | 36 +- lib/include/srslte/phy/phch/pdsch_cfg.h | 4 +- lib/include/srslte/phy/phch/phich.h | 30 +- lib/include/srslte/phy/phch/pmch.h | 26 +- lib/include/srslte/phy/phch/prach.h | 114 +- lib/include/srslte/phy/phch/pucch.h | 28 +- lib/include/srslte/phy/phch/pusch.h | 62 +- lib/include/srslte/phy/phch/ra.h | 21 +- lib/include/srslte/phy/phch/ra_dl.h | 5 +- lib/include/srslte/phy/phch/regs.h | 121 +- lib/include/srslte/phy/phch/sch.h | 48 +- lib/include/srslte/phy/phch/uci.h | 83 +- lib/include/srslte/phy/resampling/decim.h | 11 +- lib/include/srslte/phy/resampling/interp.h | 116 +- .../srslte/phy/resampling/resample_arb.h | 31 +- lib/include/srslte/phy/rf/rf.h | 194 +-- lib/include/srslte/phy/rf/rf_utils.h | 43 +- .../srslte/phy/scrambling/scrambling.h | 43 +- lib/include/srslte/phy/sync/cfo.h | 28 +- lib/include/srslte/phy/sync/cp.h | 22 +- lib/include/srslte/phy/sync/npss.h | 7 +- lib/include/srslte/phy/sync/nsss.h | 7 +- lib/include/srslte/phy/sync/pss.h | 110 +- .../srslte/phy/sync/refsignal_dl_sync.h | 8 +- lib/include/srslte/phy/sync/sfo.h | 9 +- lib/include/srslte/phy/sync/sss.h | 105 +- lib/include/srslte/phy/sync/sync.h | 170 +- lib/include/srslte/phy/ue/ue_dl.h | 23 +- lib/include/srslte/phy/ue/ue_phy.h | 126 +- lib/include/srslte/phy/ue/ue_ul.h | 27 +- lib/include/srslte/phy/utils/bit.h | 120 +- lib/include/srslte/phy/utils/cexptab.h | 20 +- lib/include/srslte/phy/utils/convolution.h | 71 +- lib/include/srslte/phy/utils/debug.h | 29 +- lib/include/srslte/phy/utils/filter.h | 34 +- lib/include/srslte/phy/utils/mat.h | 215 +-- lib/include/srslte/phy/utils/phy_logger.h | 17 +- lib/include/srslte/phy/utils/ringbuffer.h | 16 +- lib/include/srslte/phy/utils/simd.h | 1014 ++++++------ lib/include/srslte/phy/utils/vector.h | 152 +- lib/include/srslte/phy/utils/vector_simd.h | 107 +- lib/include/srslte/radio/radio.h | 169 +- lib/include/srslte/radio/radio_base.h | 2 +- lib/include/srslte/radio/radio_multi.h | 8 +- lib/include/srslte/srslte.h | 24 +- lib/include/srslte/upper/gtpu.h | 58 +- lib/include/srslte/upper/rlc.h | 20 +- lib/include/srslte/upper/rlc_am_lte.h | 66 +- lib/include/srslte/upper/rlc_tm.h | 18 +- lib/include/srslte/upper/rlc_tx_queue.h | 31 +- lib/include/srslte/upper/rlc_um_base.h | 12 +- lib/include/srslte/upper/rlc_um_lte.h | 2 +- lib/include/srslte/upper/rlc_um_nr.h | 2 +- lib/src/asn1/gtpc.cc | 2 +- lib/src/asn1/liblte_m2ap.cc | 6 +- lib/src/asn1/liblte_mme.cc | 69 +- lib/src/common/arch_select.cc | 24 +- lib/src/common/buffer_pool.cc | 13 +- lib/src/common/crash_handler.c | 20 +- lib/src/common/gen_mch_tables.c | 21 +- lib/src/common/liblte_security.cc | 80 +- lib/src/common/log_filter.cc | 84 +- lib/src/common/logger_file.cc | 30 +- lib/src/common/mac_nr_pdu.cc | 2 +- lib/src/common/mac_pcap.cc | 42 +- lib/src/common/nas_pcap.cc | 24 +- lib/src/common/pdu.cc | 2 +- lib/src/common/pdu_queue.cc | 44 +- lib/src/common/rlc_pcap.cc | 69 +- lib/src/common/s1ap_pcap.cc | 23 +- lib/src/common/security.cc | 230 ++- lib/src/common/snow_3g.cc | 788 +++++---- lib/src/common/thread_pool.cc | 170 +- lib/src/common/threads.c | 103 +- lib/src/common/tti_sync_cv.cc | 99 +- lib/src/common/version.c | 17 +- lib/src/phy/agc/agc.c | 103 +- lib/src/phy/ch_estimation/chest_common.c | 49 +- lib/src/phy/ch_estimation/chest_dl.c | 201 +-- lib/src/phy/ch_estimation/chest_ul.c | 195 ++- lib/src/phy/ch_estimation/refsignal_dl.c | 94 +- .../phy/ch_estimation/refsignal_dl_nbiot.c | 21 +- lib/src/phy/ch_estimation/refsignal_ul.c | 518 +++--- .../ch_estimation/test/chest_nbiot_test_dl.c | 2 +- .../phy/ch_estimation/test/chest_test_dl.c | 64 +- .../phy/ch_estimation/test/chest_test_ul.c | 154 +- .../ch_estimation/test/refsignal_ul_test.c | 105 +- lib/src/phy/ch_estimation/ul_rs_tables.h | 138 +- lib/src/phy/channel/ch_awgn.c | 15 +- lib/src/phy/channel/delay.c | 11 +- lib/src/phy/channel/fading.c | 14 +- lib/src/phy/channel/gauss.c | 17 +- lib/src/phy/channel/gauss.h | 2 +- lib/src/phy/channel/hst.c | 7 +- lib/src/phy/channel/rlf.c | 7 +- lib/src/phy/channel/test/delay_channel_test.c | 8 +- .../phy/channel/test/fading_channel_test.c | 4 +- lib/src/phy/common/phy_common.c | 341 ++-- lib/src/phy/common/sequence.c | 42 +- lib/src/phy/common/timestamp.c | 40 +- lib/src/phy/dft/dft_fftw.c | 267 ++-- lib/src/phy/dft/dft_precoding.c | 67 +- lib/src/phy/dft/ofdm.c | 335 ++-- lib/src/phy/dft/test/ofdm_test.c | 117 +- lib/src/phy/enb/enb_dl.c | 61 +- lib/src/phy/enb/enb_ul.c | 14 +- lib/src/phy/fec/cbsegm.c | 103 +- lib/src/phy/fec/convcoder.c | 28 +- lib/src/phy/fec/crc.c | 65 +- lib/src/phy/fec/parity.c | 9 +- lib/src/phy/fec/parity.h | 18 +- lib/src/phy/fec/rm_conv.c | 39 +- lib/src/phy/fec/rm_turbo.c | 673 ++++---- lib/src/phy/fec/softbuffer.c | 107 +- lib/src/phy/fec/tc_interl_lte.c | 82 +- lib/src/phy/fec/tc_interl_umts.c | 123 +- lib/src/phy/fec/test/crc_test.c | 60 +- lib/src/phy/fec/test/crc_test.h | 30 +- lib/src/phy/fec/test/rm_conv_test.c | 51 +- lib/src/phy/fec/test/rm_turbo_test.c | 142 +- lib/src/phy/fec/test/turbocoder_test.c | 91 +- lib/src/phy/fec/test/turbodecoder_test.c | 174 +- lib/src/phy/fec/test/turbodecoder_test.h | 197 +-- lib/src/phy/fec/test/viterbi_test.c | 143 +- lib/src/phy/fec/test/viterbi_test.h | 89 +- lib/src/phy/fec/turbocoder.c | 217 +-- lib/src/phy/fec/turbodecoder.c | 254 ++- lib/src/phy/fec/turbodecoder_gen.c | 107 +- lib/src/phy/fec/turbodecoder_sse.c | 723 +++++---- lib/src/phy/fec/viterbi.c | 412 ++--- lib/src/phy/fec/viterbi37.h | 105 +- lib/src/phy/fec/viterbi37_avx2.c | 348 ++-- lib/src/phy/fec/viterbi37_avx2_16bit.c | 372 +++-- lib/src/phy/fec/viterbi37_neon.c | 337 ++-- lib/src/phy/fec/viterbi37_port.c | 172 +- lib/src/phy/fec/viterbi37_sse.c | 285 ++-- lib/src/phy/io/binsource.c | 59 +- lib/src/phy/io/filesink.c | 135 +- lib/src/phy/io/filesource.c | 110 +- lib/src/phy/io/netsink.c | 80 +- lib/src/phy/io/netsource.c | 91 +- lib/src/phy/mimo/layermap.c | 65 +- lib/src/phy/mimo/precoding.c | 1421 +++++++++-------- lib/src/phy/mimo/test/layermap_test.c | 75 +- lib/src/phy/mimo/test/pmi_select_test.c | 47 +- lib/src/phy/mimo/test/pmi_select_test.h | 388 +++-- lib/src/phy/mimo/test/precoder_test.c | 140 +- lib/src/phy/modem/demod_hard.c | 60 +- lib/src/phy/modem/demod_soft.c | 725 +++++---- lib/src/phy/modem/hard_demod_lte.c | 81 +- lib/src/phy/modem/hard_demod_lte.h | 20 +- lib/src/phy/modem/lte_tables.c | 179 ++- lib/src/phy/modem/lte_tables.h | 8 +- lib/src/phy/modem/mod.c | 131 +- lib/src/phy/modem/modem_table.c | 158 +- lib/src/phy/modem/test/modem_test.c | 113 +- lib/src/phy/modem/test/soft_demod_test.c | 160 +- lib/src/phy/phch/cqi.c | 114 +- lib/src/phy/phch/dci.c | 169 +- lib/src/phy/phch/pbch.c | 243 +-- lib/src/phy/phch/pcfich.c | 110 +- lib/src/phy/phch/pdcch.c | 282 ++-- lib/src/phy/phch/pdsch.c | 157 +- lib/src/phy/phch/phich.c | 127 +- lib/src/phy/phch/pmch.c | 125 +- lib/src/phy/phch/prach.c | 175 +- lib/src/phy/phch/prach_tables.h | 541 +++++-- lib/src/phy/phch/prb_dl.c | 37 +- lib/src/phy/phch/prb_dl.h | 10 +- lib/src/phy/phch/pucch.c | 99 +- lib/src/phy/phch/pusch.c | 144 +- lib/src/phy/phch/ra.c | 32 +- lib/src/phy/phch/ra_ul.c | 15 +- lib/src/phy/phch/regs.c | 498 +++--- lib/src/phy/phch/sch.c | 476 +++--- lib/src/phy/phch/sequences.c | 83 +- lib/src/phy/phch/tbs_tables.h | 15 +- lib/src/phy/phch/test/npbch_file_test.c | 2 +- lib/src/phy/phch/test/pbch_file_test.c | 92 +- lib/src/phy/phch/test/pbch_test.c | 60 +- lib/src/phy/phch/test/pcfich_file_test.c | 86 +- lib/src/phy/phch/test/pcfich_test.c | 60 +- lib/src/phy/phch/test/pdcch_file_test.c | 125 +- lib/src/phy/phch/test/pdcch_test.c | 164 +- lib/src/phy/phch/test/pdsch_pdcch_file_test.c | 131 +- lib/src/phy/phch/test/pdsch_test.c | 152 +- lib/src/phy/phch/test/phich_file_test.c | 127 +- lib/src/phy/phch/test/phich_test.c | 118 +- lib/src/phy/phch/test/pmch_file_test.c | 98 +- lib/src/phy/phch/test/pmch_test.c | 165 +- lib/src/phy/phch/test/prach_test.c | 35 +- lib/src/phy/phch/test/prach_test_multi.c | 73 +- lib/src/phy/phch/test/prach_test_usrp.c | 198 +-- lib/src/phy/phch/test/pucch_test.c | 102 +- lib/src/phy/phch/test/pusch_test.c | 97 +- lib/src/phy/phch/uci.c | 395 ++--- lib/src/phy/resampling/decim.c | 20 +- lib/src/phy/resampling/interp.c | 211 +-- lib/src/phy/resampling/resample_arb.c | 90 +- .../phy/resampling/test/resample_arb_bench.c | 34 +- .../phy/resampling/test/resample_arb_test.c | 56 +- lib/src/phy/rf/rf_blade_imp.c | 276 ++-- lib/src/phy/rf/rf_blade_imp.h | 105 +- lib/src/phy/rf/rf_dev.h | 123 +- lib/src/phy/rf/rf_helper.h | 16 +- lib/src/phy/rf/rf_imp.c | 270 ++-- lib/src/phy/rf/rf_soapy_imp.c | 352 ++-- lib/src/phy/rf/rf_soapy_imp.h | 94 +- lib/src/phy/rf/rf_uhd_imp.c | 8 +- lib/src/phy/rf/rf_uhd_imp.h | 95 +- lib/src/phy/rf/rf_utils.c | 118 +- lib/src/phy/rf/rf_zmq_imp.c | 37 +- lib/src/phy/rf/rf_zmq_imp.h | 18 +- lib/src/phy/rf/rf_zmq_imp_rx.c | 14 +- lib/src/phy/rf/rf_zmq_imp_trx.h | 9 +- lib/src/phy/rf/rf_zmq_imp_tx.c | 8 +- lib/src/phy/rf/rf_zmq_test.c | 10 +- lib/src/phy/rf/uhd_c_api.h | 12 +- lib/src/phy/scrambling/scrambling.c | 85 +- lib/src/phy/scrambling/test/scrambling_test.c | 108 +- lib/src/phy/sync/cfo.c | 39 +- lib/src/phy/sync/cp.c | 41 +- lib/src/phy/sync/find_sss.c | 153 +- lib/src/phy/sync/gen_sss.c | 55 +- lib/src/phy/sync/npss.c | 7 +- lib/src/phy/sync/nsss.c | 7 +- lib/src/phy/sync/pss.c | 302 ++-- lib/src/phy/sync/refsignal_dl_sync.c | 8 +- lib/src/phy/sync/sfo.c | 28 +- lib/src/phy/sync/sss.c | 57 +- lib/src/phy/sync/sync.c | 329 ++-- lib/src/phy/sync/test/cfo_test.c | 51 +- lib/src/phy/sync/test/nsss_test.c | 4 +- lib/src/phy/sync/test/nsss_usrp.c | 6 +- lib/src/phy/sync/test/pss_file.c | 318 ++-- lib/src/phy/sync/test/pss_usrp.c | 236 +-- lib/src/phy/sync/test/sync_nbiot_test.c | 2 +- lib/src/phy/sync/test/sync_test.c | 111 +- .../phy/ue/test/ue_mib_sync_test_nbiot_usrp.c | 4 +- lib/src/phy/ue/test/ue_sync_test_nbiot_usrp.c | 8 +- lib/src/phy/ue/ue_cell_search.c | 187 ++- lib/src/phy/ue/ue_cell_search_nbiot.c | 4 +- lib/src/phy/ue/ue_dl.c | 15 +- lib/src/phy/ue/ue_mib.c | 79 +- lib/src/phy/ue/ue_mib_nbiot.c | 4 +- lib/src/phy/ue/ue_sync.c | 455 +++--- lib/src/phy/ue/ue_sync_nbiot.c | 6 +- lib/src/phy/ue/ue_ul.c | 99 +- lib/src/phy/utils/bit.c | 701 ++++---- lib/src/phy/utils/cexptab.c | 35 +- lib/src/phy/utils/convolution.c | 173 +- lib/src/phy/utils/debug.c | 9 +- lib/src/phy/utils/filter.c | 88 +- lib/src/phy/utils/mat.c | 175 +- lib/src/phy/utils/phy_logger.c | 20 +- lib/src/phy/utils/ringbuffer.c | 37 +- lib/src/phy/utils/test/dft_test.c | 108 +- lib/src/phy/utils/test/mat_test.c | 389 +++-- lib/src/phy/utils/test/vector_test.c | 1123 ++++++------- lib/src/phy/utils/vector.c | 391 +++-- lib/src/phy/utils/vector_simd.c | 577 ++++--- lib/src/radio/radio.cc | 143 +- lib/src/radio/radio_multi.cc | 6 +- lib/src/radio/test/benchmark_radio.cc | 19 +- lib/src/upper/gtpu.cc | 74 +- lib/src/upper/pdcp_entity_nr.cc | 4 +- lib/src/upper/rlc.cc | 53 +- lib/src/upper/rlc_am_lte.cc | 658 ++++---- lib/src/upper/rlc_tm.cc | 28 +- lib/src/upper/rlc_um_base.cc | 7 +- lib/src/upper/rlc_um_lte.cc | 12 +- lib/src/upper/rlc_um_nr.cc | 9 +- lib/test/asn1/s1ap_test.cc | 22 +- lib/test/asn1/srslte_asn1_m2ap_test.cc | 80 +- lib/test/asn1/srslte_asn1_rrc_dl_ccch_test.cc | 4 +- lib/test/asn1/srslte_asn1_rrc_mcch_test.cc | 7 +- lib/test/asn1/srslte_asn1_rrc_meas_test.cc | 4 +- lib/test/asn1/srslte_asn1_rrc_ul_dcch_test.cc | 2 +- lib/test/common/bcd_helpers_test.cc | 12 +- lib/test/common/log_filter_test.cc | 59 +- lib/test/common/logger_test.cc | 64 +- lib/test/common/msg_queue_test.cc | 26 +- lib/test/common/pdu_test.cc | 18 +- lib/test/common/test_eea1.cc | 558 +++---- lib/test/common/test_eea2.cc | 560 +++---- lib/test/common/test_eia1.cc | 42 +- lib/test/common/test_f12345.cc | 89 +- lib/test/common/timeout_test.cc | 67 +- lib/test/phy/phy_dl_test.c | 84 +- lib/test/upper/rlc_am_control_test.cc | 13 +- lib/test/upper/rlc_am_data_test.cc | 8 +- lib/test/upper/rlc_am_test.cc | 340 ++-- lib/test/upper/rlc_stress_test.cc | 35 +- lib/test/upper/rlc_um_data_test.cc | 23 +- lib/test/upper/rlc_um_nr_pdu_test.cc | 10 +- lib/test/upper/rlc_um_test.cc | 66 +- srsenb/hdr/cfg_parser.h | 4 +- srsenb/hdr/enb.h | 23 +- srsenb/hdr/metrics_csv.h | 8 +- srsenb/hdr/metrics_stdout.h | 6 +- srsenb/hdr/phy/phy.h | 12 +- srsenb/hdr/phy/phy_common.h | 41 +- srsenb/hdr/phy/phy_metrics.h | 20 +- srsenb/hdr/phy/prach_worker.h | 21 +- srsenb/hdr/phy/sf_worker.h | 11 +- srsenb/hdr/phy/txrx.h | 8 +- srsenb/hdr/stack/enb_stack_base.h | 10 +- srsenb/hdr/stack/mac/mac.h | 50 +- srsenb/hdr/stack/mac/mac_metrics.h | 34 +- srsenb/hdr/stack/mac/ue.h | 56 +- srsenb/hdr/stack/rrc/rrc_metrics.h | 12 +- srsenb/hdr/stack/upper/common_enb.h | 27 +- srsenb/hdr/stack/upper/s1ap_metrics.h | 8 +- srsenb/src/main.cc | 87 +- srsenb/src/metrics_csv.cc | 27 +- srsenb/src/metrics_stdout.cc | 73 +- srsenb/src/phy/cc_worker.cc | 8 +- srsenb/src/phy/phy.cc | 89 +- srsenb/src/phy/phy_common.cc | 94 +- srsenb/src/phy/prach_worker.cc | 54 +- srsenb/src/phy/sf_worker.cc | 3 +- srsenb/src/phy/txrx.cc | 51 +- srsenb/src/stack/mac/mac.cc | 131 +- srsenb/src/stack/mac/ue.cc | 221 +-- srsenb/src/stack/upper/gtpu.cc | 68 +- srsenb/test/mac/scheduler_test.cc | 87 +- srsenb/test/upper/plmn_test.cc | 2 +- srsue/hdr/metrics_csv.h | 8 +- srsue/hdr/metrics_stdout.h | 6 +- srsue/hdr/phy/phy.h | 18 +- srsue/hdr/phy/phy_common.h | 7 +- srsue/hdr/phy/phy_metrics.h | 12 +- srsue/hdr/phy/prach.h | 81 +- srsue/hdr/phy/scell/async_scell_recv.h | 10 +- srsue/hdr/phy/sf_worker.h | 7 +- srsue/hdr/phy/ue_phy_base.h | 2 +- srsue/hdr/stack/mac/demux.h | 20 +- srsue/hdr/stack/mac/dl_harq.h | 24 +- srsue/hdr/stack/mac/dl_sps.h | 13 +- srsue/hdr/stack/mac/mac.h | 18 +- srsue/hdr/stack/mac/mac_metrics.h | 18 +- srsue/hdr/stack/mac/mux.h | 32 +- srsue/hdr/stack/mac/proc.h | 24 +- srsue/hdr/stack/mac/proc_bsr.h | 18 +- srsue/hdr/stack/mac/proc_phr.h | 6 +- srsue/hdr/stack/mac/proc_ra.h | 20 +- srsue/hdr/stack/mac/proc_sr.h | 23 +- srsue/hdr/stack/mac/ul_harq.h | 17 +- srsue/hdr/stack/mac/ul_sps.h | 15 +- srsue/hdr/stack/rrc/rrc_common.h | 5 +- srsue/hdr/stack/rrc/rrc_procedures.h | 2 +- srsue/hdr/stack/ue_stack_base.h | 6 +- srsue/hdr/stack/upper/gw.h | 26 +- srsue/hdr/stack/upper/gw_metrics.h | 4 +- srsue/hdr/stack/upper/nas.h | 50 +- srsue/hdr/stack/upper/nas_common.h | 7 +- srsue/hdr/stack/upper/pcsc_usim.h | 288 ++-- srsue/hdr/stack/upper/tft_packet_filter.h | 2 +- srsue/hdr/stack/upper/usim.h | 91 +- srsue/hdr/stack/upper/usim_base.h | 80 +- srsue/hdr/ue.h | 6 +- srsue/hdr/ue_metrics_interface.h | 6 +- srsue/src/main.cc | 38 +- srsue/src/metrics_csv.cc | 24 +- srsue/src/metrics_stdout.cc | 54 +- srsue/src/phy/cc_worker.cc | 18 +- srsue/src/phy/phy.cc | 140 +- srsue/src/phy/phy_common.cc | 27 +- srsue/src/phy/prach.cc | 66 +- srsue/src/phy/scell/intra_measure.cc | 4 +- srsue/src/phy/scell/scell_recv.cc | 7 +- srsue/src/phy/sf_worker.cc | 20 +- srsue/src/phy/sync.cc | 194 ++- srsue/src/set_net_admin_caps.cc | 27 +- srsue/src/stack/mac/demux.cc | 87 +- srsue/src/stack/mac/mac.cc | 19 +- srsue/src/stack/mac/mux.cc | 67 +- srsue/src/stack/mac/proc_bsr.cc | 61 +- srsue/src/stack/mac/proc_phr.cc | 11 +- srsue/src/stack/mac/proc_ra.cc | 63 +- srsue/src/stack/mac/proc_sr.cc | 55 +- srsue/src/stack/rrc/rrc.cc | 424 ++--- srsue/src/stack/upper/gw.cc | 203 ++- srsue/src/stack/upper/nas.cc | 507 +++--- srsue/src/stack/upper/pcsc_usim.cc | 407 +++-- srsue/src/stack/upper/tft_packet_filter.cc | 12 +- srsue/src/stack/upper/usim.cc | 323 ++-- srsue/src/stack/upper/usim_base.cc | 6 +- srsue/src/ue.cc | 5 +- srsue/test/mac_test.cc | 20 +- srsue/test/metrics_test.cc | 19 +- srsue/test/phy/scell_search_test.cc | 16 +- srsue/test/ttcn3/hdr/ttcn3_interfaces.h | 18 +- srsue/test/ttcn3/hdr/ttcn3_syssim.h | 28 +- srsue/test/ttcn3/hdr/ttcn3_ue.h | 8 +- srsue/test/ttcn3/src/lte_ttcn3_phy.cc | 2 +- srsue/test/upper/nas_test.cc | 41 +- srsue/test/upper/pcsc_usim_test.cc | 11 +- srsue/test/upper/rrc_reconfig_test.cc | 50 +- srsue/test/upper/tft_test.cc | 55 +- srsue/test/upper/usim_test.cc | 18 +- 499 files changed, 25007 insertions(+), 24286 deletions(-) diff --git a/cmake/modules/CheckFunctionExists.c b/cmake/modules/CheckFunctionExists.c index 5877a6ab9..1cfa7c3b4 100644 --- a/cmake/modules/CheckFunctionExists.c +++ b/cmake/modules/CheckFunctionExists.c @@ -23,24 +23,25 @@ char CHECK_FUNCTION_EXISTS(); #ifdef __CLASSIC_C__ -int main(){ - int ac; - char*av[]; +int main() +{ + int ac; + char* av[]; #else -int main(int ac, char*av[]){ - +int main(int ac, char* av[]) +{ + #endif float ac2 = sqrtf(rand()); CHECK_FUNCTION_EXISTS(); - if(ac2 * ac > 1000) - { + if (ac2 * ac > 1000) { return *av[0]; - } + } return 0; } -#else /* CHECK_FUNCTION_EXISTS */ +#else /* CHECK_FUNCTION_EXISTS */ -# error "CHECK_FUNCTION_EXISTS has to specify the function" +#error "CHECK_FUNCTION_EXISTS has to specify the function" #endif /* CHECK_FUNCTION_EXISTS */ diff --git a/lib/examples/cell_search.c b/lib/examples/cell_search.c index 7565c8736..63cd23b68 100644 --- a/lib/examples/cell_search.c +++ b/lib/examples/cell_search.c @@ -19,37 +19,35 @@ * */ +#include +#include #include #include #include #include -#include -#include #include -#include +#include #include #include "srslte/srslte.h" -#include "srslte/phy/rf/rf_utils.h" #include "srslte/common/crash_handler.h" - +#include "srslte/phy/rf/rf_utils.h" #ifndef DISABLE_RF #include "srslte/phy/rf/rf.h" #endif -#define MHZ 1000000 -#define SAMP_FREQ 1920000 -#define FLEN 9600 -#define FLEN_PERIOD 0.005 +#define MHZ 1000000 +#define SAMP_FREQ 1920000 +#define FLEN 9600 +#define FLEN_PERIOD 0.005 #define MAX_EARFCN 1000 - -int band = -1; -int earfcn_start=-1, earfcn_end = -1; +int band = -1; +int earfcn_start = -1, earfcn_end = -1; cell_search_cfg_t cell_detect_config = {.max_frames_pbch = SRSLTE_DEFAULT_MAX_FRAMES_PBCH, .max_frames_pss = SRSLTE_DEFAULT_MAX_FRAMES_PSS, @@ -61,14 +59,15 @@ struct cells { srslte_cell_t cell; float freq; int dl_earfcn; - float power; + float power; }; -struct cells results[1024]; +struct cells results[1024]; float rf_gain = 70.0; -char *rf_args=""; +char* rf_args = ""; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [agsendtvb] -b band\n", prog); printf("\t-a RF args [Default %s]\n", rf_args); printf("\t-g RF gain [Default %.2f dB]\n", rf_gain); @@ -78,34 +77,35 @@ void usage(char *prog) { printf("\t-v [set srslte_verbose to debug, default none]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "agsendvb")) != -1) { - switch(opt) { - case 'a': - rf_args = argv[optind]; - break; - case 'b': - band = (int)strtol(argv[optind], NULL, 10); - break; - case 's': - earfcn_start = (int)strtol(argv[optind], NULL, 10); - break; - case 'e': - earfcn_end = (int)strtol(argv[optind], NULL, 10); - break; - case 'n': - cell_detect_config.max_frames_pss = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'g': - rf_gain = strtof(argv[optind], NULL); - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + switch (opt) { + case 'a': + rf_args = argv[optind]; + break; + case 'b': + band = (int)strtol(argv[optind], NULL, 10); + break; + case 's': + earfcn_start = (int)strtol(argv[optind], NULL, 10); + break; + case 'e': + earfcn_end = (int)strtol(argv[optind], NULL, 10); + break; + case 'n': + cell_detect_config.max_frames_pss = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'g': + rf_gain = strtof(argv[optind], NULL); + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } if (band == -1) { @@ -132,28 +132,29 @@ void sig_int_handler(int signo) float srslte_rf_set_rx_gain_wrapper(void* h, float f) { - return srslte_rf_set_rx_gain((srslte_rf_t*) h, f); + return srslte_rf_set_rx_gain((srslte_rf_t*)h, f); } -int main(int argc, char **argv) { - int n; - srslte_rf_t rf; - srslte_ue_cellsearch_t cs; - srslte_ue_cellsearch_result_t found_cells[3]; - int nof_freqs; - srslte_earfcn_t channels[MAX_EARFCN]; - uint32_t freq; - uint32_t n_found_cells=0; - +int main(int argc, char** argv) +{ + int n; + srslte_rf_t rf; + srslte_ue_cellsearch_t cs; + srslte_ue_cellsearch_result_t found_cells[3]; + int nof_freqs; + srslte_earfcn_t channels[MAX_EARFCN]; + uint32_t freq; + uint32_t n_found_cells = 0; + srslte_debug_handle_crash(argc, argv); parse_args(argc, argv); - + printf("Opening RF device...\n"); if (srslte_rf_open(&rf, rf_args)) { ERROR("Error opening rf\n"); exit(-1); - } + } if (!cell_detect_config.init_agc) { srslte_rf_set_rx_gain(&rf, rf_gain); } else { @@ -162,12 +163,12 @@ int main(int argc, char **argv) { ERROR("Error opening rf\n"); exit(-1); } - srslte_rf_set_rx_gain(&rf, 50); + srslte_rf_set_rx_gain(&rf, 50); } // Supress RF messages srslte_rf_suppress_stdout(&rf); - + nof_freqs = srslte_band_get_fd_band(band, channels, earfcn_start, earfcn_end, MAX_EARFCN); if (nof_freqs < 0) { ERROR("Error getting EARFCN list\n"); @@ -189,7 +190,7 @@ int main(int argc, char **argv) { srslte_ue_cellsearch_set_nof_valid_frames(&cs, cell_detect_config.nof_valid_pss_frames); } if (cell_detect_config.init_agc) { - srslte_rf_info_t *rf_info = srslte_rf_get_info(&rf); + srslte_rf_info_t* rf_info = srslte_rf_get_info(&rf); srslte_ue_sync_start_agc(&cs.ue_sync, srslte_rf_set_rx_gain_wrapper, rf_info->min_rx_gain, @@ -197,11 +198,11 @@ int main(int argc, char **argv) { cell_detect_config.init_agc); } - for (freq=0;freq 0) { - for (int i=0;i<3;i++) { + for (int i = 0; i < 3; i++) { if (found_cells[i].psr > 2.0) { srslte_cell_t cell; - cell.id = found_cells[i].cell_id; - cell.cp = found_cells[i].cp; + cell.id = found_cells[i].cell_id; + cell.cp = found_cells[i].cp; int ret = rf_mib_decoder(&rf, 1, &cell_detect_config, &cell, NULL); if (ret < 0) { ERROR("Error decoding MIB\n"); @@ -237,19 +238,19 @@ int main(int argc, char **argv) { printf("Found CELL ID %d. %d PRB, %d ports\n", cell.id, cell.nof_prb, cell.nof_ports); if (cell.nof_ports > 0) { results[n_found_cells].cell = cell; - results[n_found_cells].freq = channels[freq].fd; + results[n_found_cells].freq = channels[freq].fd; results[n_found_cells].dl_earfcn = channels[freq].id; - results[n_found_cells].power = found_cells[i].peak; + results[n_found_cells].power = found_cells[i].peak; n_found_cells++; } } } } - } + } } printf("\n\nFound %d cells\n", n_found_cells); - for (int i=0;i +#include +#include #include #include #include #include -#include #include -#include -#include -#include -#include "srslte/common/crash_handler.h" -#include "srslte/common/gen_mch_tables.h" -#include "srslte/srslte.h" - +#include #define UE_CRNTI 0x1234 #define M_CRNTI 0xFFFD #ifndef DISABLE_RF -#include "srslte/phy/rf/rf.h" #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/rf/rf.h" srslte_rf_t rf; #else #pragma message "Compiling pdsch_ue with no RF support" #endif -char *output_file_name = NULL; +char* output_file_name = NULL; -#define LEFT_KEY 68 +#define LEFT_KEY 68 #define RIGHT_KEY 67 -#define UP_KEY 65 -#define DOWN_KEY 66 +#define UP_KEY 65 +#define DOWN_KEY 66 srslte_cell_t cell = { 25, // nof_prb @@ -63,67 +62,65 @@ srslte_cell_t cell = { }; uint16_t c = -1; - + int net_port = -1; // -1 generates random dataThat means there is some problem sending samples to the device -uint32_t cfi = 2; +uint32_t cfi = 2; uint32_t mcs_idx = 1, last_mcs_idx = 1; -int nof_frames = -1; +int nof_frames = -1; srslte_tm_t transmission_mode = SRSLTE_TM1; -uint32_t nof_tb = 1; -uint32_t multiplex_pmi = 0; -uint32_t multiplex_nof_layers = 1; -uint8_t mbsfn_sf_mask = 32; -int mbsfn_area_id = -1; -char *rf_args = ""; -char *rf_dev = ""; -float rf_amp = 0.8, rf_gain = 60.0, rf_freq = 2400000000; +uint32_t nof_tb = 1; +uint32_t multiplex_pmi = 0; +uint32_t multiplex_nof_layers = 1; +uint8_t mbsfn_sf_mask = 32; +int mbsfn_area_id = -1; +char* rf_args = ""; +char* rf_dev = ""; +float rf_amp = 0.8, rf_gain = 60.0, rf_freq = 2400000000; static bool enable_256qam = false; float output_file_snr = +INFINITY; -bool null_file_sink=false; -srslte_filesink_t fsink; -srslte_ofdm_t ifft[SRSLTE_MAX_PORTS]; -srslte_ofdm_t ifft_mbsfn; -srslte_pbch_t pbch; -srslte_pcfich_t pcfich; -srslte_pdcch_t pdcch; -srslte_pdsch_t pdsch; -srslte_pdsch_cfg_t pdsch_cfg; -srslte_pmch_t pmch; +bool null_file_sink = false; +srslte_filesink_t fsink; +srslte_ofdm_t ifft[SRSLTE_MAX_PORTS]; +srslte_ofdm_t ifft_mbsfn; +srslte_pbch_t pbch; +srslte_pcfich_t pcfich; +srslte_pdcch_t pdcch; +srslte_pdsch_t pdsch; +srslte_pdsch_cfg_t pdsch_cfg; +srslte_pmch_t pmch; srslte_pmch_cfg_t pmch_cfg; -srslte_softbuffer_tx_t *softbuffers[SRSLTE_MAX_CODEWORDS]; -srslte_regs_t regs; +srslte_softbuffer_tx_t* softbuffers[SRSLTE_MAX_CODEWORDS]; +srslte_regs_t regs; srslte_dci_dl_t dci_dl; -int rvidx[SRSLTE_MAX_CODEWORDS] = {0, 0}; - -cf_t *sf_buffer[SRSLTE_MAX_PORTS] = {NULL}, *output_buffer [SRSLTE_MAX_PORTS] = {NULL}; +int rvidx[SRSLTE_MAX_CODEWORDS] = {0, 0}; +cf_t *sf_buffer[SRSLTE_MAX_PORTS] = {NULL}, *output_buffer[SRSLTE_MAX_PORTS] = {NULL}; int sf_n_re, sf_n_samples; -pthread_t net_thread; -void *net_thread_fnc(void *arg); -sem_t net_sem; -bool net_packet_ready = false; -srslte_netsource_t net_source; -srslte_netsink_t net_sink; - +pthread_t net_thread; +void* net_thread_fnc(void* arg); +sem_t net_sem; +bool net_packet_ready = false; +srslte_netsource_t net_source; +srslte_netsink_t net_sink; -int prbset_num = 1, last_prbset_num = 1; -int prbset_orig = 0; +int prbset_num = 1, last_prbset_num = 1; +int prbset_orig = 0; //#define DATA_BUFF_SZ 1024*128 -//uint8_t data[8*DATA_BUFF_SZ], data2[DATA_BUFF_SZ]; -//uint8_t data_tmp[DATA_BUFF_SZ]; +// uint8_t data[8*DATA_BUFF_SZ], data2[DATA_BUFF_SZ]; +// uint8_t data_tmp[DATA_BUFF_SZ]; - -#define DATA_BUFF_SZ 1024*1024 +#define DATA_BUFF_SZ 1024 * 1024 uint8_t *data_mbms, *data[2], data2[DATA_BUFF_SZ]; -uint8_t data_tmp[DATA_BUFF_SZ]; +uint8_t data_tmp[DATA_BUFF_SZ]; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [Iagmfoncvpuxb]\n", prog); #ifndef DISABLE_RF printf("\t-I RF device [Default %s]\n", rf_dev); @@ -143,7 +140,9 @@ void usage(char *prog) { printf("\t-x Transmission mode [1-4] [Default %d]\n", transmission_mode + 1); printf("\t-b Precoding Matrix Index (multiplex mode only)* [Default %d]\n", multiplex_pmi); printf("\t-w Number of codewords/layers (multiplex mode only)* [Default %d]\n", multiplex_nof_layers); - printf("\t-u listen TCP/UDP port for input data (if mbsfn is active then the stream is over mbsfn only) (-1 is random) [Default %d]\n", net_port); + printf("\t-u listen TCP/UDP port for input data (if mbsfn is active then the stream is over mbsfn only) (-1 is " + "random) [Default %d]\n", + net_port); printf("\t-v [set srslte_verbose to debug, default none]\n"); printf("\t-s output file SNR [Default %f]\n", output_file_snr); printf("\t-q Enable/Disable 256QAM modulation (default %s)\n", enable_256qam ? "enabled" : "disabled"); @@ -151,71 +150,72 @@ void usage(char *prog) { printf("\t*: See 3GPP 36.212 Table 5.3.3.1.5-4 for more information\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "IadglfmoncpqvutxbwMsB")) != -1) { switch (opt) { - case 'I': - rf_dev = argv[optind]; - break; - case 'a': - rf_args = argv[optind]; - break; - case 'g': - rf_gain = strtof(argv[optind], NULL); - break; - case 'l': - rf_amp = strtof(argv[optind], NULL); - break; - case 'f': - rf_freq = strtof(argv[optind], NULL); - break; - case 'o': - output_file_name = argv[optind]; - break; - case 'm': - mcs_idx = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'u': - net_port = (int)strtol(argv[optind], NULL, 10); - break; - case 'n': - nof_frames = (int)strtol(argv[optind], NULL, 10); - break; - case 'p': - cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'c': - cell.id = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'x': - transmission_mode = (srslte_tm_t)(strtol(argv[optind], NULL, 10) - 1); - break; - case 'b': - multiplex_pmi = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'w': - multiplex_nof_layers = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'M': - mbsfn_area_id = (int)strtol(argv[optind], NULL, 10); - break; - case 'v': - srslte_verbose++; - break; - case 's': - output_file_snr = strtof(argv[optind], NULL); - break; - case 'B': - mbsfn_sf_mask = (uint8_t)strtol(argv[optind], NULL, 10); - break; - case 'q': - enable_256qam ^= true; - break; - default: - usage(argv[0]); - exit(-1); + case 'I': + rf_dev = argv[optind]; + break; + case 'a': + rf_args = argv[optind]; + break; + case 'g': + rf_gain = strtof(argv[optind], NULL); + break; + case 'l': + rf_amp = strtof(argv[optind], NULL); + break; + case 'f': + rf_freq = strtof(argv[optind], NULL); + break; + case 'o': + output_file_name = argv[optind]; + break; + case 'm': + mcs_idx = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'u': + net_port = (int)strtol(argv[optind], NULL, 10); + break; + case 'n': + nof_frames = (int)strtol(argv[optind], NULL, 10); + break; + case 'p': + cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'c': + cell.id = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'x': + transmission_mode = (srslte_tm_t)(strtol(argv[optind], NULL, 10) - 1); + break; + case 'b': + multiplex_pmi = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'w': + multiplex_nof_layers = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'M': + mbsfn_area_id = (int)strtol(argv[optind], NULL, 10); + break; + case 'v': + srslte_verbose++; + break; + case 's': + output_file_snr = strtof(argv[optind], NULL); + break; + case 'B': + mbsfn_sf_mask = (uint8_t)strtol(argv[optind], NULL, 10); + break; + case 'q': + enable_256qam ^= true; + break; + default: + usage(argv[0]); + exit(-1); } } #ifdef DISABLE_RF @@ -225,8 +225,9 @@ void parse_args(int argc, char **argv) { } #endif } - -void base_init() { + +void base_init() +{ int i; /* Configure cell and PDSCH in function of the transmission mode */ @@ -245,7 +246,7 @@ void base_init() { } /* Allocate memory */ - for(i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { + for (i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { data[i] = srslte_vec_malloc(sizeof(uint8_t) * SOFTBUFFER_SIZE); if (!data[i]) { perror("malloc"); @@ -254,7 +255,6 @@ void base_init() { bzero(data[i], sizeof(uint8_t) * SOFTBUFFER_SIZE); } data_mbms = srslte_vec_malloc(sizeof(uint8_t) * SOFTBUFFER_SIZE); - /* init memory */ for (i = 0; i < SRSLTE_MAX_PORTS; i++) { @@ -274,17 +274,16 @@ void base_init() { bzero(output_buffer[i], sizeof(cf_t) * sf_n_samples); } - /* open file or USRP */ if (output_file_name) { if (strcmp(output_file_name, "NULL")) { if (srslte_filesink_init(&fsink, output_file_name, SRSLTE_COMPLEX_FLOAT_BIN)) { ERROR("Error opening file %s\n", output_file_name); exit(-1); - } - null_file_sink = false; + } + null_file_sink = false; } else { - null_file_sink = true; + null_file_sink = true; } } else { #ifndef DISABLE_RF @@ -298,17 +297,17 @@ void base_init() { exit(-1); #endif } - + if (net_port > 0) { if (srslte_netsource_init(&net_source, "127.0.0.1", net_port, SRSLTE_NETSOURCE_UDP)) { ERROR("Error creating input UDP socket at port %d\n", net_port); exit(-1); } if (null_file_sink) { - if (srslte_netsink_init(&net_sink, "127.0.0.1", net_port+1, SRSLTE_NETSINK_TCP)) { + if (srslte_netsink_init(&net_sink, "127.0.0.1", net_port + 1, SRSLTE_NETSINK_TCP)) { ERROR("Error sink\n"); exit(-1); - } + } } if (sem_init(&net_sem, 0, 1)) { perror("sem_init"); @@ -332,7 +331,7 @@ void base_init() { } srslte_ofdm_set_non_mbsfn_region(&ifft_mbsfn, 2); srslte_ofdm_set_normalize(&ifft_mbsfn, true); - + if (srslte_pbch_init(&pbch)) { ERROR("Error creating PBCH object\n"); exit(-1); @@ -341,9 +340,6 @@ void base_init() { ERROR("Error creating PBCH object\n"); exit(-1); } - - - if (srslte_regs_init(®s, cell)) { ERROR("Error initiating regs\n"); @@ -378,14 +374,13 @@ void base_init() { srslte_pdsch_set_rnti(&pdsch, UE_CRNTI); - - if(mbsfn_area_id > -1){ + if (mbsfn_area_id > -1) { if (srslte_pmch_init(&pmch, cell.nof_prb, 1)) { ERROR("Error creating PMCH object\n"); } srslte_pmch_set_area_id(&pmch, mbsfn_area_id); } - + for (i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { softbuffers[i] = calloc(sizeof(srslte_softbuffer_tx_t), 1); if (!softbuffers[i]) { @@ -400,8 +395,8 @@ void base_init() { } } - -void base_free() { +void base_free() +{ int i; for (i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { srslte_softbuffer_tx_free(softbuffers[i]); @@ -413,8 +408,8 @@ void base_free() { srslte_pdcch_free(&pdcch); srslte_regs_free(®s); srslte_pbch_free(&pbch); - if(mbsfn_area_id > -1){ - srslte_pmch_free(&pmch); + if (mbsfn_area_id > -1) { + srslte_pmch_free(&pmch); } srslte_ofdm_tx_free(&ifft_mbsfn); for (i = 0; i < cell.nof_ports; i++) { @@ -438,22 +433,21 @@ void base_free() { } if (output_file_name) { if (!null_file_sink) { - srslte_filesink_free(&fsink); + srslte_filesink_free(&fsink); } } else { #ifndef DISABLE_RF srslte_rf_close(&rf); #endif } - + if (net_port > 0) { srslte_netsource_free(&net_source); sem_close(&net_sem); - } + } } - -bool go_exit = false; +bool go_exit = false; void sig_int_handler(int signo) { printf("SIGINT received. Exiting...\n"); @@ -462,31 +456,29 @@ void sig_int_handler(int signo) } } - - -unsigned int -reverse(register unsigned int x) +unsigned int reverse(register unsigned int x) { - x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); - x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); - x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); - x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); - return((x >> 16) | (x << 16)); - + x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); + x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); + x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); + x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); + return ((x >> 16) | (x << 16)); } -uint32_t prbset_to_bitmask() { - uint32_t mask=0; - int nb = (int) ceilf((float) cell.nof_prb / srslte_ra_type0_P(cell.nof_prb)); - for (int i=0;i= prbset_orig && i < prbset_orig + prbset_num) { - mask = mask | (0x1<>(32-nb); + return reverse(mask) >> (32 - nb); } -int update_radl() { +int update_radl() +{ ZERO_OBJECT(dci_dl); @@ -494,16 +486,16 @@ int update_radl() { switch (transmission_mode) { case SRSLTE_TM1: case SRSLTE_TM2: - nof_tb = 1; + nof_tb = 1; dci_dl.format = SRSLTE_DCI_FORMAT1; break; case SRSLTE_TM3: dci_dl.format = SRSLTE_DCI_FORMAT2A; - nof_tb = 2; + nof_tb = 2; break; case SRSLTE_TM4: dci_dl.format = SRSLTE_DCI_FORMAT2; - nof_tb = multiplex_nof_layers; + nof_tb = multiplex_nof_layers; if (multiplex_nof_layers == 1) { dci_dl.pinfo = (uint8_t)(multiplex_pmi + 1); } else { @@ -548,29 +540,30 @@ int update_radl() { } fflush(stdout); - return 0; + return 0; } /* Read new MCS from stdin */ -int update_control() { +int update_control() +{ char input[128]; - - fd_set set; + + fd_set set; FD_ZERO(&set); FD_SET(0, &set); - - struct timeval to; - to.tv_sec = 0; - to.tv_usec = 0; + + struct timeval to; + to.tv_sec = 0; + to.tv_usec = 0; int n = select(1, &set, NULL, NULL, &to); if (n == 1) { // stdin ready if (fgets(input, sizeof(input), stdin)) { - if(input[0] == 27) { - switch(input[2]) { + if (input[0] == 27) { + switch (input[2]) { case RIGHT_KEY: - if (prbset_orig + prbset_num < (int) ceilf((float) cell.nof_prb / srslte_ra_type0_P(cell.nof_prb))) + if (prbset_orig + prbset_num < (int)ceilf((float)cell.nof_prb / srslte_ra_type0_P(cell.nof_prb))) prbset_orig++; break; case LEFT_KEY: @@ -578,14 +571,14 @@ int update_control() { prbset_orig--; break; case UP_KEY: - if (prbset_num < (int) ceilf((float) cell.nof_prb / srslte_ra_type0_P(cell.nof_prb))) + if (prbset_num < (int)ceilf((float)cell.nof_prb / srslte_ra_type0_P(cell.nof_prb))) prbset_num++; break; case DOWN_KEY: last_prbset_num = prbset_num; if (prbset_num > 0) - prbset_num--; - break; + prbset_num--; + break; } } else { switch (input[0]) { @@ -630,32 +623,32 @@ int update_control() { mcs_idx = strtol(input, NULL, 10); } } - bzero(input,sizeof(input)); + bzero(input, sizeof(input)); if (update_radl()) { printf("Trying with last known MCS index\n"); - mcs_idx = last_mcs_idx; - prbset_num = last_prbset_num; + mcs_idx = last_mcs_idx; + prbset_num = last_prbset_num; return update_radl(); } } - return 0; + return 0; } else if (n < 0) { // error perror("select"); - return -1; + return -1; } else { - return 0; + return 0; } } - /** Function run in a separate thread to receive UDP data */ -void *net_thread_fnc(void *arg) { - int n; - int rpm = 0, wpm=0; - +void* net_thread_fnc(void* arg) +{ + int n; + int rpm = 0, wpm = 0; + do { - n = srslte_netsource_read(&net_source, &data2[rpm], DATA_BUFF_SZ-rpm); + n = srslte_netsource_read(&net_source, &data2[rpm], DATA_BUFF_SZ - rpm); if (n > 0) { // FIXME: I assume that both transport blocks have same size in case of 2 tb are active @@ -663,23 +656,22 @@ void *net_thread_fnc(void *arg) { : (pdsch_cfg.grant.tb[0].tbs + pdsch_cfg.grant.tb[1].tbs)) - 1) / 8; - rpm += n; - INFO("received %d bytes. rpm=%d/%d\n",n,rpm,nbytes); - wpm = 0; + rpm += n; + INFO("received %d bytes. rpm=%d/%d\n", n, rpm, nbytes); + wpm = 0; while (rpm >= nbytes) { // wait for packet to be transmitted sem_wait(&net_sem); - if(mbsfn_area_id > -1){ + if (mbsfn_area_id > -1) { memcpy(data_mbms, &data2[wpm], nbytes); - } - else{ - memcpy(data[0], &data2[wpm], nbytes / (size_t) 2); - memcpy(data[1], &data2[wpm], nbytes / (size_t) 2); + } else { + memcpy(data[0], &data2[wpm], nbytes / (size_t)2); + memcpy(data[1], &data2[wpm], nbytes / (size_t)2); } INFO("Sent %d/%d bytes ready\n", nbytes, rpm); - rpm -= nbytes; - wpm += nbytes; - net_packet_ready = true; + rpm -= nbytes; + wpm += nbytes; + net_packet_ready = true; } if (wpm > 0) { INFO("%d bytes left in buffer for next packet\n", rpm); @@ -690,25 +682,25 @@ void *net_thread_fnc(void *arg) { } else { ERROR("Error receiving from network\n"); exit(-1); - } - } while(n >= 0); + } + } while (n >= 0); return NULL; } - -int main(int argc, char **argv) { - int nf=0, sf_idx=0, N_id_2=0; - cf_t pss_signal[SRSLTE_PSS_LEN]; - float sss_signal0[SRSLTE_SSS_LEN]; // for subframe 0 - float sss_signal5[SRSLTE_SSS_LEN]; // for subframe 5 - uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; - int i; +int main(int argc, char** argv) +{ + int nf = 0, sf_idx = 0, N_id_2 = 0; + cf_t pss_signal[SRSLTE_PSS_LEN]; + float sss_signal0[SRSLTE_SSS_LEN]; // for subframe 0 + float sss_signal5[SRSLTE_SSS_LEN]; // for subframe 5 + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; + int i; cf_t* sf_symbols[SRSLTE_MAX_PORTS]; - srslte_dci_msg_t dci_msg; + srslte_dci_msg_t dci_msg; srslte_dci_location_t locations[SRSLTE_NOF_SF_X_FRAME][30]; - uint32_t sfn; - srslte_refsignal_t csr_refs; - srslte_refsignal_t mbsfn_refs; + uint32_t sfn; + srslte_refsignal_t csr_refs; + srslte_refsignal_t mbsfn_refs; srslte_debug_handle_crash(argc, argv); @@ -722,21 +714,21 @@ int main(int argc, char **argv) { parse_args(argc, argv); uint8_t mch_table[10]; - bzero(&mch_table[0], sizeof(uint8_t)*10); - if(mbsfn_area_id > -1) { + bzero(&mch_table[0], sizeof(uint8_t) * 10); + if (mbsfn_area_id > -1) { generate_mcch_table(mch_table, mbsfn_sf_mask); } - N_id_2 = cell.id % 3; - sf_n_re = 2 * SRSLTE_CP_NORM_NSYMB * cell.nof_prb * SRSLTE_NRE; + N_id_2 = cell.id % 3; + sf_n_re = 2 * SRSLTE_CP_NORM_NSYMB * cell.nof_prb * SRSLTE_NRE; sf_n_samples = 2 * SRSLTE_SLOT_LEN(srslte_symbol_sz(cell.nof_prb)); - cell.phich_length = SRSLTE_PHICH_NORM; + cell.phich_length = SRSLTE_PHICH_NORM; cell.phich_resources = SRSLTE_PHICH_R_1; - sfn = 0; + sfn = 0; + + prbset_num = (int)ceilf((float)cell.nof_prb / srslte_ra_type0_P(cell.nof_prb)); + last_prbset_num = prbset_num; - prbset_num = (int) ceilf((float) cell.nof_prb / srslte_ra_type0_P(cell.nof_prb)); - last_prbset_num = prbset_num; - /* this *must* be called after setting slot_len_* */ base_init(); @@ -745,12 +737,12 @@ int main(int argc, char **argv) { srslte_sss_generate(sss_signal0, sss_signal5, cell.id); /* Generate reference signals */ - if(srslte_refsignal_cs_init(&csr_refs, cell.nof_prb)) { + if (srslte_refsignal_cs_init(&csr_refs, cell.nof_prb)) { ERROR("Error initializing equalizer\n"); exit(-1); } if (mbsfn_area_id > -1) { - if(srslte_refsignal_mbsfn_init(&mbsfn_refs, cell.nof_prb)) { + if (srslte_refsignal_mbsfn_init(&mbsfn_refs, cell.nof_prb)) { ERROR("Error initializing equalizer\n"); exit(-1); } @@ -758,23 +750,19 @@ int main(int argc, char **argv) { ERROR("Error initializing MBSFNR signal\n"); exit(-1); } - } - if(srslte_refsignal_cs_set_cell(&csr_refs, cell)){ + if (srslte_refsignal_cs_set_cell(&csr_refs, cell)) { ERROR("Error setting cell\n"); exit(-1); } - - + for (i = 0; i < SRSLTE_MAX_PORTS; i++) { - sf_symbols[i] = sf_buffer[i%cell.nof_ports]; + sf_symbols[i] = sf_buffer[i % cell.nof_ports]; } - #ifndef DISABLE_RF - sigset_t sigset; sigemptyset(&sigset); sigaddset(&sigset, SIGINT); @@ -782,10 +770,10 @@ int main(int argc, char **argv) { signal(SIGINT, sig_int_handler); if (!output_file_name) { - - int srate = srslte_sampling_freq_hz(cell.nof_prb); - if (srate != -1) { - printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000); + + int srate = srslte_sampling_freq_hz(cell.nof_prb); + if (srate != -1) { + printf("Setting sampling rate %.2f MHz\n", (float)srate / 1000000); float srate_rf = srslte_rf_set_tx_srate(&rf, (double)srate); if (srate_rf != srate) { ERROR("Could not set sampling rate\n"); @@ -803,7 +791,7 @@ int main(int argc, char **argv) { if (update_radl()) { exit(-1); } - + if (net_port > 0) { if (pthread_create(&net_thread, NULL, net_thread_fnc, NULL)) { perror("pthread_create"); @@ -821,15 +809,14 @@ int main(int argc, char **argv) { dl_sf.tti = i; srslte_pdcch_ue_locations(&pdcch, &dl_sf, locations[i], 30, UE_CRNTI); } - + nf = 0; - - bool send_data = false; + + bool send_data = false; for (i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { srslte_softbuffer_tx_reset(softbuffers[i]); } - #ifndef DISABLE_RF bool start_of_burst = true; #endif @@ -847,13 +834,11 @@ int main(int argc, char **argv) { /* Set Antenna port resource elements to zero */ bzero(sf_symbols[0], sizeof(cf_t) * sf_n_re); - if (sf_idx == 0 || sf_idx == 5) { srslte_pss_put_slot(pss_signal, sf_symbols[0], cell.nof_prb, SRSLTE_CP_NORM); - srslte_sss_put_slot(sf_idx ? sss_signal5 : sss_signal0, sf_symbols[0], cell.nof_prb, - SRSLTE_CP_NORM); + srslte_sss_put_slot(sf_idx ? sss_signal5 : sss_signal0, sf_symbols[0], cell.nof_prb, SRSLTE_CP_NORM); } - + /* Copy zeros, SSS, PSS into the rest of antenna ports */ for (i = 1; i < cell.nof_ports; i++) { memcpy(sf_symbols[i], sf_symbols[0], sizeof(cf_t) * sf_n_re); @@ -882,10 +867,10 @@ int main(int argc, char **argv) { if (update_control()) { ERROR("Error updating parameters from control port\n"); } - + /* Transmit PDCCH + PDSCH only when there is data to send */ if ((net_port > 0) && (mch_table[sf_idx] == 1 && mbsfn_area_id > -1)) { - send_data = net_packet_ready; + send_data = net_packet_ready; if (net_packet_ready) { INFO("Transmitting packet from port\n"); } @@ -894,15 +879,15 @@ int main(int argc, char **argv) { for (uint32_t tb = 0; tb < SRSLTE_MAX_CODEWORDS; tb++) { if (pdsch_cfg.grant.tb[tb].enabled) { for (i = 0; i < pdsch_cfg.grant.tb[tb].tbs / 8; i++) { - data[tb][i] = (uint8_t) rand(); + data[tb][i] = (uint8_t)rand(); } } } /* Uncomment this to transmit on sf 0 and 5 only */ if (sf_idx != 0 && sf_idx != 5) { - send_data = true; + send_data = true; } else { - send_data = false; + send_data = false; } } if (send_data) { @@ -929,7 +914,7 @@ int main(int argc, char **argv) { if (srslte_pdsch_encode(&pdsch, &dl_sf, &pdsch_cfg, data, sf_symbols)) { ERROR("Error encoding PDSCH\n"); exit(-1); - } + } if (net_port > 0 && net_packet_ready) { if (null_file_sink) { for (uint32_t tb = 0; tb < SRSLTE_MAX_CODEWORDS; tb++) { @@ -939,8 +924,8 @@ int main(int argc, char **argv) { } } } - if(mbsfn_area_id < 0){ - net_packet_ready = false; + if (mbsfn_area_id < 0) { + net_packet_ready = false; sem_post(&net_sem); } } @@ -992,8 +977,7 @@ int main(int argc, char **argv) { } else { srslte_ofdm_tx_sf(&ifft_mbsfn); } - - + /* send to file or usrp */ if (output_file_name) { if (!null_file_sink) { @@ -1004,17 +988,18 @@ int main(int argc, char **argv) { srslte_ch_awgn_c(output_buffer[k], output_buffer[k], var, sf_n_samples); } } - srslte_filesink_write_multi(&fsink, (void**) output_buffer, sf_n_samples, cell.nof_ports); + srslte_filesink_write_multi(&fsink, (void**)output_buffer, sf_n_samples, cell.nof_ports); } usleep(1000); } else { -#ifndef DISABLE_RF - float norm_factor = (float) cell.nof_prb/15/sqrtf(pdsch_cfg.grant.nof_prb); - for (i = 0; i < cell.nof_ports; i++) { - srslte_vec_sc_prod_cfc(output_buffer[i], rf_amp * norm_factor, output_buffer[i], SRSLTE_SF_LEN_PRB(cell.nof_prb)); - } - srslte_rf_send_multi(&rf, (void**) output_buffer, sf_n_samples, true, start_of_burst, false); - start_of_burst=false; +#ifndef DISABLE_RF + float norm_factor = (float)cell.nof_prb / 15 / sqrtf(pdsch_cfg.grant.nof_prb); + for (i = 0; i < cell.nof_ports; i++) { + srslte_vec_sc_prod_cfc( + output_buffer[i], rf_amp * norm_factor, output_buffer[i], SRSLTE_SF_LEN_PRB(cell.nof_prb)); + } + srslte_rf_send_multi(&rf, (void**)output_buffer, sf_n_samples, true, start_of_burst, false); + start_of_burst = false; #endif } } @@ -1027,5 +1012,3 @@ int main(int argc, char **argv) { printf("Done\n"); exit(0); } - - diff --git a/lib/examples/pdsch_ue.c b/lib/examples/pdsch_ue.c index e5acb4b51..eb47e842b 100644 --- a/lib/examples/pdsch_ue.c +++ b/lib/examples/pdsch_ue.c @@ -19,21 +19,20 @@ * */ +#include +#include +#include +#include +#include #include #include #include #include -#include -#include #include #include -#include -#include -#include -#include -#include "srslte/common/gen_mch_tables.h" #include "srslte/common/crash_handler.h" +#include "srslte/common/gen_mch_tables.h" #include "srslte/phy/io/filesink.h" #include "srslte/srslte.h" @@ -77,40 +76,40 @@ char* output_file_name; * Program arguments processing ***********************************************************************/ typedef struct { - int nof_subframes; - int cpu_affinity; - bool disable_plots; - bool disable_plots_except_constellation; + int nof_subframes; + int cpu_affinity; + bool disable_plots; + bool disable_plots_except_constellation; bool disable_cfo; uint32_t time_offset; - int force_N_id_2; + int force_N_id_2; uint16_t rnti; - char *input_file_name; + char* input_file_name; int file_offset_time; - float file_offset_freq; + float file_offset_freq; uint32_t file_nof_prb; uint32_t file_nof_ports; uint32_t file_cell_id; - bool enable_cfo_ref; - bool average_subframe; - char *rf_dev; + bool enable_cfo_ref; + bool average_subframe; + char* rf_dev; char* rf_args; uint32_t rf_nof_rx_ant; double rf_freq; - float rf_gain; + float rf_gain; int net_port; char* net_address; int net_port_signal; - char *net_address_signal; - int decimate; - int32_t mbsfn_area_id; + char* net_address_signal; + int decimate; + int32_t mbsfn_area_id; uint8_t non_mbsfn_region; uint8_t mbsfn_sf_mask; int tdd_special_sf; int sf_config; - int verbose; + int verbose; bool enable_256qam; -}prog_args_t; +} prog_args_t; void args_default(prog_args_t* args) { @@ -145,14 +144,15 @@ void args_default(prog_args_t* args) args->net_address = "127.0.0.1"; args->net_port_signal = -1; args->net_address_signal = "127.0.0.1"; - args->decimate = 0; + args->decimate = 0; args->cpu_affinity = -1; - args->mbsfn_area_id = -1; + args->mbsfn_area_id = -1; args->non_mbsfn_region = 2; - args->mbsfn_sf_mask = 32; + args->mbsfn_sf_mask = 32; } -void usage(prog_args_t *args, char *prog) { +void usage(prog_args_t* args, char* prog) +{ printf("Usage: %s [adgpPoOcildFRDnruMNvTG] -f rx_frequency (in Hz) | -i input_file\n", prog); #ifndef DISABLE_RF printf("\t-I RF dev [Default %s]\n", args->rf_dev); @@ -198,118 +198,119 @@ void usage(prog_args_t *args, char *prog) { printf("\t-v [set srslte_verbose to debug, default none]\n"); } -void parse_args(prog_args_t *args, int argc, char **argv) { +void parse_args(prog_args_t* args, int argc, char** argv) +{ int opt; args_default(args); while ((opt = getopt(argc, argv, "adAogliIpPcOCtdDFRqnvrfuUsSZyWMNBTG")) != -1) { switch (opt) { - case 'i': - args->input_file_name = argv[optind]; - break; - case 'p': - args->file_nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'P': - args->file_nof_ports = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'o': - args->file_offset_freq = strtof(argv[optind], NULL); - break; - case 'O': - args->file_offset_time = (int)strtol(argv[optind], NULL, 10); - break; - case 'c': - args->file_cell_id = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'I': - args->rf_dev = argv[optind]; - break; - case 'a': - args->rf_args = argv[optind]; - break; - case 'A': - args->rf_nof_rx_ant = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'g': - args->rf_gain = strtof(argv[optind], NULL); - break; - case 'C': - args->disable_cfo = true; - break; - case 'F': - args->enable_cfo_ref = true; - break; - case 'R': - args->average_subframe = true; - break; - case 't': - args->time_offset = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'f': - args->rf_freq = strtod(argv[optind], NULL); - break; - case 'T': - args->tdd_special_sf = (int)strtol(argv[optind], NULL, 10); - break; - case 'G': - args->sf_config = (int)strtol(argv[optind], NULL, 10); - break; - case 'n': - args->nof_subframes = (int)strtol(argv[optind], NULL, 10); - break; - case 'r': - args->rnti = strtol(argv[optind], NULL, 16); - break; - case 'l': - args->force_N_id_2 = (int)strtol(argv[optind], NULL, 10); - break; - case 'u': - args->net_port = (int)strtol(argv[optind], NULL, 10); - break; - case 'U': - args->net_address = argv[optind]; - break; - case 's': - args->net_port_signal = (int)strtol(argv[optind], NULL, 10); - break; - case 'S': - args->net_address_signal = argv[optind]; - break; - case 'd': - args->disable_plots = true; - break; - case 'D': - args->disable_plots_except_constellation = true; - break; - case 'v': - srslte_verbose++; - args->verbose = srslte_verbose; - break; - case 'Z': - args->decimate = (int)strtol(argv[optind], NULL, 10); - break; - case 'y': - args->cpu_affinity = (int)strtol(argv[optind], NULL, 10); - break; - case 'W': - output_file_name = argv[optind]; - break; - case 'M': - args->mbsfn_area_id = (int32_t)strtol(argv[optind], NULL, 10); - break; - case 'N': - args->non_mbsfn_region = (uint8_t)strtol(argv[optind], NULL, 10); - break; - case 'B': - args->mbsfn_sf_mask = (uint8_t)strtol(argv[optind], NULL, 10); - break; - case 'q': - args->enable_256qam ^= true; - break; - default: - usage(args, argv[0]); - exit(-1); + case 'i': + args->input_file_name = argv[optind]; + break; + case 'p': + args->file_nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'P': + args->file_nof_ports = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'o': + args->file_offset_freq = strtof(argv[optind], NULL); + break; + case 'O': + args->file_offset_time = (int)strtol(argv[optind], NULL, 10); + break; + case 'c': + args->file_cell_id = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'I': + args->rf_dev = argv[optind]; + break; + case 'a': + args->rf_args = argv[optind]; + break; + case 'A': + args->rf_nof_rx_ant = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'g': + args->rf_gain = strtof(argv[optind], NULL); + break; + case 'C': + args->disable_cfo = true; + break; + case 'F': + args->enable_cfo_ref = true; + break; + case 'R': + args->average_subframe = true; + break; + case 't': + args->time_offset = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'f': + args->rf_freq = strtod(argv[optind], NULL); + break; + case 'T': + args->tdd_special_sf = (int)strtol(argv[optind], NULL, 10); + break; + case 'G': + args->sf_config = (int)strtol(argv[optind], NULL, 10); + break; + case 'n': + args->nof_subframes = (int)strtol(argv[optind], NULL, 10); + break; + case 'r': + args->rnti = strtol(argv[optind], NULL, 16); + break; + case 'l': + args->force_N_id_2 = (int)strtol(argv[optind], NULL, 10); + break; + case 'u': + args->net_port = (int)strtol(argv[optind], NULL, 10); + break; + case 'U': + args->net_address = argv[optind]; + break; + case 's': + args->net_port_signal = (int)strtol(argv[optind], NULL, 10); + break; + case 'S': + args->net_address_signal = argv[optind]; + break; + case 'd': + args->disable_plots = true; + break; + case 'D': + args->disable_plots_except_constellation = true; + break; + case 'v': + srslte_verbose++; + args->verbose = srslte_verbose; + break; + case 'Z': + args->decimate = (int)strtol(argv[optind], NULL, 10); + break; + case 'y': + args->cpu_affinity = (int)strtol(argv[optind], NULL, 10); + break; + case 'W': + output_file_name = argv[optind]; + break; + case 'M': + args->mbsfn_area_id = (int32_t)strtol(argv[optind], NULL, 10); + break; + case 'N': + args->non_mbsfn_region = (uint8_t)strtol(argv[optind], NULL, 10); + break; + case 'B': + args->mbsfn_sf_mask = (uint8_t)strtol(argv[optind], NULL, 10); + break; + case 'q': + args->enable_256qam ^= true; + break; + default: + usage(args, argv[0]); + exit(-1); } } if (args->rf_freq < 0 && args->input_file_name == NULL) { @@ -320,7 +321,7 @@ void parse_args(prog_args_t *args, int argc, char **argv) { /**********************************************************************/ -uint8_t *data[SRSLTE_MAX_CODEWORDS]; +uint8_t* data[SRSLTE_MAX_CODEWORDS]; bool go_exit = false; @@ -334,8 +335,7 @@ void sig_int_handler(int signo) } } -cf_t *sf_buffer[SRSLTE_MAX_PORTS] = {NULL}; - +cf_t* sf_buffer[SRSLTE_MAX_PORTS] = {NULL}; #ifndef DISABLE_RF @@ -379,10 +379,13 @@ srslte_netsink_t net_sink, net_sink_signal; #define PRINT_LINE(_fmt, ...) \ printf("\033[K" _fmt "\n", ##__VA_ARGS__); \ this_nof_lines++ -#define PRINT_LINE_RESET_CURSOR() printf("\033[%dA", this_nof_lines); prev_nof_lines = this_nof_lines +#define PRINT_LINE_RESET_CURSOR() \ + printf("\033[%dA", this_nof_lines); \ + prev_nof_lines = this_nof_lines #define PRINT_LINE_ADVANCE_CURSOR() printf("\033[%dB", prev_nof_lines + 1) -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ int ret; #ifndef DISABLE_RF @@ -500,7 +503,7 @@ int main(int argc, char **argv) { int srate = srslte_sampling_freq_hz(cell.nof_prb); if (srate != -1) { printf("Setting sampling rate %.2f MHz\n", (float)srate / 1000000); - float srate_rf = srslte_rf_set_rx_srate(&rf, (double) srate); + float srate_rf = srslte_rf_set_rx_srate(&rf, (double)srate); if (srate_rf != srate) { ERROR("Could not set sampling rate\n"); exit(-1); @@ -519,7 +522,7 @@ int main(int argc, char **argv) { /* preset cell configuration */ cell.id = prog_args.file_cell_id; cell.cp = SRSLTE_CP_NORM; - cell.phich_length = SRSLTE_PHICH_NORM; + cell.phich_length = SRSLTE_PHICH_NORM; cell.phich_resources = SRSLTE_PHICH_R_1; cell.nof_ports = prog_args.file_nof_ports; cell.nof_prb = prog_args.file_nof_prb; @@ -600,16 +603,16 @@ int main(int argc, char **argv) { } srslte_chest_dl_cfg_t chest_pdsch_cfg = {}; - chest_pdsch_cfg.cfo_estimate_enable = prog_args.enable_cfo_ref; - chest_pdsch_cfg.cfo_estimate_sf_mask = 1023; - chest_pdsch_cfg.interpolate_subframe = !prog_args.average_subframe; + chest_pdsch_cfg.cfo_estimate_enable = prog_args.enable_cfo_ref; + chest_pdsch_cfg.cfo_estimate_sf_mask = 1023; + chest_pdsch_cfg.interpolate_subframe = !prog_args.average_subframe; // Special configuration for MBSFN channel estimation srslte_chest_dl_cfg_t chest_mbsfn_cfg = {}; - chest_mbsfn_cfg.filter_type = SRSLTE_CHEST_FILTER_TRIANGLE; - chest_mbsfn_cfg.filter_coef[0] = 0.1; - chest_mbsfn_cfg.interpolate_subframe = true; - chest_mbsfn_cfg.noise_alg = SRSLTE_NOISE_ALG_PSS; + chest_mbsfn_cfg.filter_type = SRSLTE_CHEST_FILTER_TRIANGLE; + chest_mbsfn_cfg.filter_coef[0] = 0.1; + chest_mbsfn_cfg.interpolate_subframe = true; + chest_mbsfn_cfg.noise_alg = SRSLTE_NOISE_ALG_PSS; // Allocate softbuffer buffers srslte_softbuffer_rx_t rx_softbuffers[SRSLTE_MAX_CODEWORDS]; @@ -644,7 +647,7 @@ int main(int argc, char **argv) { #ifndef DISABLE_RF if (prog_args.rf_gain < 0 && !prog_args.input_file_name) { - srslte_rf_info_t *rf_info = srslte_rf_get_info(&rf); + srslte_rf_info_t* rf_info = srslte_rf_get_info(&rf); srslte_ue_sync_start_agc(&ue_sync, srslte_rf_set_rx_gain_th_wrapper_, rf_info->min_rx_gain, @@ -686,12 +689,12 @@ int main(int argc, char **argv) { FD_SET(0, &set); struct timeval to; - to.tv_sec = 0; + to.tv_sec = 0; to.tv_usec = 0; /* Set default verbose level */ srslte_verbose = prog_args.verbose; - int n = select(1, &set, NULL, NULL, &to); + int n = select(1, &set, NULL, NULL, &to); if (n == 1) { /* If a new line is detected set verbose level to Debug */ if (fgets(input, sizeof(input), stdin)) { @@ -699,7 +702,7 @@ int main(int argc, char **argv) { pkt_errors = 0; pkt_total = 0; nof_detected = 0; - nof_trials = 0; + nof_trials = 0; } } @@ -779,9 +782,9 @@ int main(int argc, char **argv) { n = 0; for (uint32_t tm = 0; tm < 4 && !n; tm++) { - dl_sf.tti = tti; - dl_sf.sf_type = sf_type; - ue_dl_cfg.cfg.tm = (srslte_tm_t)tm; + dl_sf.tti = tti; + dl_sf.sf_type = sf_type; + ue_dl_cfg.cfg.tm = (srslte_tm_t)tm; ue_dl_cfg.cfg.pdsch.use_tbs_index_alt = prog_args.enable_256qam; if ((ue_dl_cfg.cfg.tm == SRSLTE_TM1 && cell.nof_ports == 1) || @@ -919,7 +922,6 @@ int main(int argc, char **argv) { PRINT_LINE("Press enter maximum printing debug log of 1 subframe."); PRINT_LINE(""); PRINT_LINE_RESET_CURSOR(); - } break; } @@ -998,14 +1000,15 @@ int main(int argc, char **argv) { ***********************************************************************/ #ifdef ENABLE_GUI -plot_real_t p_sync, pce; +plot_real_t p_sync, pce; plot_scatter_t pscatequal, pscatequal_pdcch, pscatequal_pmch; float tmp_plot[110 * 15 * 2048]; float tmp_plot2[110 * 15 * 2048]; float tmp_plot3[110 * 15 * 2048]; -void *plot_thread_run(void *arg) { +void* plot_thread_run(void* arg) +{ int i; uint32_t nof_re = SRSLTE_SF_LEN_RE(ue_dl.cell.nof_prb, ue_dl.cell.cp); @@ -1115,7 +1118,7 @@ void init_plots() exit(-1); } - pthread_attr_t attr; + pthread_attr_t attr; struct sched_param param; param.sched_priority = 0; pthread_attr_init(&attr); diff --git a/lib/examples/synch_file.c b/lib/examples/synch_file.c index 71fd6a273..76b00f804 100644 --- a/lib/examples/synch_file.c +++ b/lib/examples/synch_file.c @@ -22,21 +22,22 @@ #include #include #include -#include #include +#include #include "srslte/srslte.h" -char *input_file_name; -char *output_file_name="abs_corr.txt"; -int nof_frames=100, frame_length=9600, symbol_sz=128; -float corr_peak_threshold=25.0; -int out_N_id_2 = 0, force_N_id_2=-1; +char* input_file_name; +char* output_file_name = "abs_corr.txt"; +int nof_frames = 100, frame_length = 9600, symbol_sz = 128; +float corr_peak_threshold = 25.0; +int out_N_id_2 = 0, force_N_id_2 = -1; -#define CFO_AUTO -9999.0 +#define CFO_AUTO -9999.0 float force_cfo = CFO_AUTO; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [olntsNfcv] -i input_file\n", prog); printf("\t-o output_file [Default %s]\n", output_file_name); printf("\t-l frame_length [Default %d]\n", frame_length); @@ -49,43 +50,44 @@ void usage(char *prog) { printf("\t-v srslte_verbose\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "ionltsNfcv")) != -1) { - switch(opt) { - case 'i': - input_file_name = argv[optind]; - break; - case 'o': - output_file_name = argv[optind]; - break; - case 'n': - nof_frames = (int)strtol(argv[optind], NULL, 10); - break; - case 'l': - frame_length = (int)strtol(argv[optind], NULL, 10); - break; - case 't': - corr_peak_threshold = strtof(argv[optind], NULL); - break; - case 's': - symbol_sz = (int)strtol(argv[optind], NULL, 10); - break; - case 'N': - out_N_id_2 = (int)strtol(argv[optind], NULL, 10); - break; - case 'f': - force_N_id_2 = (int)strtol(argv[optind], NULL, 10); - break; - case 'c': - force_cfo = strtof(argv[optind], NULL); - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + switch (opt) { + case 'i': + input_file_name = argv[optind]; + break; + case 'o': + output_file_name = argv[optind]; + break; + case 'n': + nof_frames = (int)strtol(argv[optind], NULL, 10); + break; + case 'l': + frame_length = (int)strtol(argv[optind], NULL, 10); + break; + case 't': + corr_peak_threshold = strtof(argv[optind], NULL); + break; + case 's': + symbol_sz = (int)strtol(argv[optind], NULL, 10); + break; + case 'N': + out_N_id_2 = (int)strtol(argv[optind], NULL, 10); + break; + case 'f': + force_N_id_2 = (int)strtol(argv[optind], NULL, 10); + break; + case 'c': + force_cfo = strtof(argv[optind], NULL); + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } if (!input_file_name) { @@ -94,33 +96,35 @@ void parse_args(int argc, char **argv) { } } -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ srslte_filesource_t fsrc; - srslte_filesink_t fsink; - srslte_pss_t pss[3]; // One for each N_id_2 - srslte_sss_t sss[3]; // One for each N_id_2 - srslte_cfo_t cfocorr; - int peak_pos[3]; - float *cfo; - float peak_value[3]; - int frame_cnt; - cf_t *input; - uint32_t m0, m1; - float m0_value, m1_value; - uint32_t N_id_2; - int sss_idx; - struct timeval tdata[3]; - int *exec_time; + srslte_filesink_t fsink; + srslte_pss_t pss[3]; // One for each N_id_2 + srslte_sss_t sss[3]; // One for each N_id_2 + srslte_cfo_t cfocorr; + int peak_pos[3]; + float* cfo; + float peak_value[3]; + int frame_cnt; + cf_t* input; + uint32_t m0, m1; + float m0_value, m1_value; + uint32_t N_id_2; + int sss_idx; + struct timeval tdata[3]; + int* exec_time; if (argc < 3) { usage(argv[0]); exit(-1); } - parse_args(argc,argv); + parse_args(argc, argv); gettimeofday(&tdata[1], NULL); - printf("Initializing...");fflush(stdout); + printf("Initializing..."); + fflush(stdout); if (srslte_filesource_init(&fsrc, input_file_name, SRSLTE_COMPLEX_FLOAT_BIN)) { ERROR("Error opening file %s\n", input_file_name); @@ -131,17 +135,17 @@ int main(int argc, char **argv) { exit(-1); } - input = malloc(frame_length*sizeof(cf_t)); + input = malloc(frame_length * sizeof(cf_t)); if (!input) { perror("malloc"); exit(-1); } - cfo = malloc(nof_frames*sizeof(float)); + cfo = malloc(nof_frames * sizeof(float)); if (!cfo) { perror("malloc"); exit(-1); } - exec_time = malloc(nof_frames*sizeof(int)); + exec_time = malloc(nof_frames * sizeof(int)); if (!exec_time) { perror("malloc"); exit(-1); @@ -157,7 +161,7 @@ int main(int argc, char **argv) { * b) We create 1 pss object which scans for each N_id_2 one after another. * a) requries more memory but has less latency and is paralellizable. */ - for (N_id_2=0;N_id_2<3;N_id_2++) { + for (N_id_2 = 0; N_id_2 < 3; N_id_2++) { if (srslte_pss_init_fft(&pss[N_id_2], frame_length, symbol_sz)) { ERROR("Error initializing PSS object\n"); exit(-1); @@ -177,35 +181,34 @@ int main(int argc, char **argv) { } gettimeofday(&tdata[2], NULL); get_time_interval(tdata); - printf("done in %ld s %ld ms\n", tdata[0].tv_sec, tdata[0].tv_usec/1000); + printf("done in %ld s %ld ms\n", tdata[0].tv_sec, tdata[0].tv_usec / 1000); printf("\n\tFr.Cnt\tN_id_2\tN_id_1\tSubf\tPSS Peak/Avg\tIdx\tm0\tm1\tCFO\n"); printf("\t===============================================================================\n"); /* read all file or nof_frames */ frame_cnt = 0; - while (frame_length == srslte_filesource_read(&fsrc, input, frame_length) - && frame_cnt < nof_frames) { + while (frame_length == srslte_filesource_read(&fsrc, input, frame_length) && frame_cnt < nof_frames) { gettimeofday(&tdata[1], NULL); if (force_cfo != CFO_AUTO) { - srslte_cfo_correct(&cfocorr, input, input, force_cfo/128); + srslte_cfo_correct(&cfocorr, input, input, force_cfo / 128); } if (force_N_id_2 != -1) { - N_id_2 = force_N_id_2; + N_id_2 = force_N_id_2; peak_pos[N_id_2] = srslte_pss_find_pss(&pss[N_id_2], input, &peak_value[N_id_2]); } else { - for (N_id_2=0;N_id_2<3;N_id_2++) { + for (N_id_2 = 0; N_id_2 < 3; N_id_2++) { peak_pos[N_id_2] = srslte_pss_find_pss(&pss[N_id_2], input, &peak_value[N_id_2]); } - float max_value=-99999; - N_id_2=-1; + float max_value = -99999; + N_id_2 = -1; int i; - for (i=0;i<3;i++) { + for (i = 0; i < 3; i++) { if (peak_value[i] > max_value) { max_value = peak_value[i]; - N_id_2 = i; + N_id_2 = i; } } } @@ -213,12 +216,11 @@ int main(int argc, char **argv) { /* If peak detected */ if (peak_value[N_id_2] > corr_peak_threshold) { - sss_idx = peak_pos[N_id_2]-2*(symbol_sz+SRSLTE_CP_LEN(symbol_sz,SRSLTE_CP_NORM_LEN)); + sss_idx = peak_pos[N_id_2] - 2 * (symbol_sz + SRSLTE_CP_LEN(symbol_sz, SRSLTE_CP_NORM_LEN)); if (sss_idx >= 0) { - srslte_sss_m0m1_diff(&sss[N_id_2], &input[sss_idx], - &m0, &m0_value, &m1, &m1_value); + srslte_sss_m0m1_diff(&sss[N_id_2], &input[sss_idx], &m0, &m0_value, &m1, &m1_value); - cfo[frame_cnt] = srslte_pss_cfo_compute(&pss[N_id_2], &input[peak_pos[N_id_2]-128]); + cfo[frame_cnt] = srslte_pss_cfo_compute(&pss[N_id_2], &input[peak_pos[N_id_2] - 128]); printf("\t%d\t%d\t%d\t%d\t%.3f\t\t%3d\t%d\t%d\t%.3f\n", frame_cnt, N_id_2, @@ -237,23 +239,25 @@ int main(int argc, char **argv) { frame_cnt++; } - int i; - float avg_time=0; - for (i=0;i +#include #include +#include #include #include #include -#include -#include #include +#include #include -#include "srslte/srslte.h" -#include "srslte/phy/rf/rf.h" #include "srslte/phy/io/filesink.h" +#include "srslte/phy/rf/rf.h" +#include "srslte/srslte.h" static bool keep_running = true; -char *output_file_name; -char *rf_args=""; -float rf_gain=40.0, rf_freq=-1.0, rf_rate=0.96e6; -int nof_samples = -1; -int nof_rx_antennas = 1; - -void int_handler(int dummy) { +char* output_file_name; +char* rf_args = ""; +float rf_gain = 40.0, rf_freq = -1.0, rf_rate = 0.96e6; +int nof_samples = -1; +int nof_rx_antennas = 1; + +void int_handler(int dummy) +{ keep_running = false; } -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [agrnv] -f rx_frequency_hz -o output_file\n", prog); printf("\t-a RF args [Default %s]\n", rf_args); printf("\t-g RF Gain [Default %.2f dB]\n", rf_gain); @@ -55,37 +57,38 @@ void usage(char *prog) { printf("\t-v srslte_verbose\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "agrnvfoA")) != -1) { switch (opt) { - case 'o': - output_file_name = argv[optind]; - break; - case 'a': - rf_args = argv[optind]; - break; - case 'g': - rf_gain = strtof(argv[optind], NULL); - break; - case 'r': - rf_rate = strtof(argv[optind], NULL); - break; - case 'f': - rf_freq = strtof(argv[optind], NULL); - break; - case 'n': - nof_samples = (int)strtol(argv[optind], NULL, 10); - break; - case 'A': - nof_rx_antennas = (int)strtol(argv[optind], NULL, 10); - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + case 'o': + output_file_name = argv[optind]; + break; + case 'a': + rf_args = argv[optind]; + break; + case 'g': + rf_gain = strtof(argv[optind], NULL); + break; + case 'r': + rf_rate = strtof(argv[optind], NULL); + break; + case 'f': + rf_freq = strtof(argv[optind], NULL); + break; + case 'n': + nof_samples = (int)strtol(argv[optind], NULL, 10); + break; + case 'A': + nof_rx_antennas = (int)strtol(argv[optind], NULL, 10); + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } if (rf_freq < 0) { @@ -94,18 +97,19 @@ void parse_args(int argc, char **argv) { } } -int main(int argc, char **argv) { - cf_t *buffer[SRSLTE_MAX_PORTS]; - int sample_count, n; - srslte_rf_t rf; +int main(int argc, char** argv) +{ + cf_t* buffer[SRSLTE_MAX_PORTS]; + int sample_count, n; + srslte_rf_t rf; srslte_filesink_t sink; - uint32_t buflen; + uint32_t buflen; signal(SIGINT, int_handler); parse_args(argc, argv); - - buflen = 4800; + + buflen = 4800; sample_count = 0; for (int i = 0; i < nof_rx_antennas; i++) { @@ -131,7 +135,7 @@ int main(int argc, char **argv) { printf("Set RX freq: %.2f MHz\n", srslte_rf_set_rx_freq(&rf, nof_rx_antennas, rf_freq) / 1000000); printf("Set RX gain: %.2f dB\n", srslte_rf_set_rx_gain(&rf, rf_gain)); - float srate = srslte_rf_set_rx_srate(&rf, rf_rate); + float srate = srslte_rf_set_rx_srate(&rf, rf_rate); if (srate != rf_rate) { srate = srslte_rf_set_rx_srate(&rf, rf_rate); if (srate != rf_rate) { @@ -140,22 +144,20 @@ int main(int argc, char **argv) { } } - printf("Correctly RX rate: %.2f MHz\n", srate*1e-6); + printf("Correctly RX rate: %.2f MHz\n", srate * 1e-6); srslte_rf_start_rx_stream(&rf, false); - - - while((sample_count < nof_samples || nof_samples == -1) - && keep_running){ - n = srslte_rf_recv_with_time_multi(&rf, (void**) buffer, buflen, true, NULL, NULL); + + while ((sample_count < nof_samples || nof_samples == -1) && keep_running) { + n = srslte_rf_recv_with_time_multi(&rf, (void**)buffer, buflen, true, NULL, NULL); if (n < 0) { ERROR("Error receiving samples\n"); exit(-1); } - - srslte_filesink_write_multi(&sink, (void**) buffer, buflen, nof_rx_antennas); + + srslte_filesink_write_multi(&sink, (void**)buffer, buflen, nof_rx_antennas); sample_count += buflen; } - + for (int i = 0; i < nof_rx_antennas; i++) { if (buffer[i]) { free(buffer[i]); diff --git a/lib/examples/usrp_capture_sync.c b/lib/examples/usrp_capture_sync.c index cf417e1f8..8ee85c0bf 100644 --- a/lib/examples/usrp_capture_sync.c +++ b/lib/examples/usrp_capture_sync.c @@ -19,34 +19,36 @@ * */ -#include +#include #include +#include #include #include #include -#include -#include #include +#include #include -#include "srslte/srslte.h" #include "srslte/phy/rf/rf.h" +#include "srslte/srslte.h" -static bool keep_running = true; -char *output_file_name = NULL; -char *rf_args=""; -float rf_gain=60.0, rf_freq=-1.0; -int nof_prb = 6; -int nof_subframes = -1; -int N_id_2 = -1; -uint32_t nof_rx_antennas = 1; +static bool keep_running = true; +char* output_file_name = NULL; +char* rf_args = ""; +float rf_gain = 60.0, rf_freq = -1.0; +int nof_prb = 6; +int nof_subframes = -1; +int N_id_2 = -1; +uint32_t nof_rx_antennas = 1; -void int_handler(int dummy) { +void int_handler(int dummy) +{ keep_running = false; } -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [agrnv] -l N_id_2 -f rx_frequency_hz -o output_file\n", prog); printf("\t-a RF args [Default %s]\n", rf_args); printf("\t-g RF Gain [Default %.2f dB]\n", rf_gain); @@ -56,40 +58,41 @@ void usage(char *prog) { printf("\t-v verbose\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "agpnvfolA")) != -1) { switch (opt) { - case 'o': - output_file_name = argv[optind]; - break; - case 'a': - rf_args = argv[optind]; - break; - case 'g': - rf_gain = strtof(argv[optind], NULL); - break; - case 'p': - nof_prb = (int)strtol(argv[optind], NULL, 10); - break; - case 'f': - rf_freq = strtof(argv[optind], NULL); - break; - case 'n': - nof_subframes = (int)strtol(argv[optind], NULL, 10); - break; - case 'l': - N_id_2 = (int)strtol(argv[optind], NULL, 10); - break; - case 'A': - nof_rx_antennas = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + case 'o': + output_file_name = argv[optind]; + break; + case 'a': + rf_args = argv[optind]; + break; + case 'g': + rf_gain = strtof(argv[optind], NULL); + break; + case 'p': + nof_prb = (int)strtol(argv[optind], NULL, 10); + break; + case 'f': + rf_freq = strtof(argv[optind], NULL); + break; + case 'n': + nof_subframes = (int)strtol(argv[optind], NULL, 10); + break; + case 'l': + N_id_2 = (int)strtol(argv[optind], NULL, 10); + break; + case 'A': + nof_rx_antennas = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } if (&rf_freq < 0 || N_id_2 == -1 || output_file_name == NULL) { @@ -108,18 +111,19 @@ int srslte_rf_recv_wrapper(void* h, cf_t* data_[SRSLTE_MAX_PORTS], uint32_t nsam return srslte_rf_recv_with_time_multi(h, ptr, nsamples, true, NULL, NULL); } -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ cf_t* buffer[SRSLTE_MAX_PORTS] = {NULL}; - int n; - srslte_rf_t rf; + int n; + srslte_rf_t rf; srslte_filesink_t sink; - srslte_ue_sync_t ue_sync; - srslte_cell_t cell; + srslte_ue_sync_t ue_sync; + srslte_cell_t cell; signal(SIGINT, int_handler); parse_args(argc, argv); - + srslte_filesink_init(&sink, output_file_name, SRSLTE_COMPLEX_FLOAT_BIN); printf("Opening RF device...\n"); @@ -131,7 +135,7 @@ int main(int argc, char **argv) { for (int i = 0; i < nof_rx_antennas; i++) { buffer[i] = srslte_vec_malloc(3 * sizeof(cf_t) * SRSLTE_SF_LEN_PRB(100)); } - + sigset_t sigset; sigemptyset(&sigset); sigaddset(&sigset, SIGINT); @@ -139,28 +143,29 @@ int main(int argc, char **argv) { printf("Set RX freq: %.6f MHz\n", srslte_rf_set_rx_freq(&rf, nof_rx_antennas, rf_freq) / 1000000); printf("Set RX gain: %.1f dB\n", srslte_rf_set_rx_gain(&rf, rf_gain)); - int srate = srslte_sampling_freq_hz(nof_prb); - if (srate != -1) { - printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000); - float srate_rf = srslte_rf_set_rx_srate(&rf, (double) srate); - if (srate_rf != srate) { - ERROR("Could not set sampling rate\n"); - exit(-1); - } - } else { - ERROR("Invalid number of PRB %d\n", nof_prb); + int srate = srslte_sampling_freq_hz(nof_prb); + if (srate != -1) { + printf("Setting sampling rate %.2f MHz\n", (float)srate / 1000000); + float srate_rf = srslte_rf_set_rx_srate(&rf, (double)srate); + if (srate_rf != srate) { + ERROR("Could not set sampling rate\n"); exit(-1); } + } else { + ERROR("Invalid number of PRB %d\n", nof_prb); + exit(-1); + } srslte_rf_start_rx_stream(&rf, false); - cell.cp = SRSLTE_CP_NORM; - cell.id = N_id_2; - cell.nof_prb = nof_prb; - cell.nof_ports = 1; - - if (srslte_ue_sync_init_multi(&ue_sync, cell.nof_prb, cell.id==1000, srslte_rf_recv_wrapper, nof_rx_antennas, (void*) &rf)) { + cell.cp = SRSLTE_CP_NORM; + cell.id = N_id_2; + cell.nof_prb = nof_prb; + cell.nof_ports = 1; + + if (srslte_ue_sync_init_multi( + &ue_sync, cell.nof_prb, cell.id == 1000, srslte_rf_recv_wrapper, nof_rx_antennas, (void*)&rf)) { fprintf(stderr, "Error initiating ue_sync\n"); - exit(-1); + exit(-1); } if (srslte_ue_sync_set_cell(&ue_sync, cell)) { ERROR("Error initiating ue_sync\n"); @@ -168,11 +173,9 @@ int main(int argc, char **argv) { } uint32_t subframe_count = 0; - bool start_capture = false; - bool stop_capture = false; - while((subframe_count < nof_subframes || nof_subframes == -1) - && !stop_capture) - { + bool start_capture = false; + bool stop_capture = false; + while ((subframe_count < nof_subframes || nof_subframes == -1) && !stop_capture) { n = srslte_ue_sync_zerocopy(&ue_sync, buffer); if (n < 0) { ERROR("Error receiving samples\n"); @@ -181,21 +184,21 @@ int main(int argc, char **argv) { if (n == 1) { if (!start_capture) { if (srslte_ue_sync_get_sfidx(&ue_sync) == 9) { - start_capture = true; - } + start_capture = true; + } } else { printf("Writing to file %6d subframes...\r", subframe_count); - srslte_filesink_write_multi(&sink, (void**) buffer, SRSLTE_SF_LEN_PRB(nof_prb),nof_rx_antennas); - subframe_count++; - } + srslte_filesink_write_multi(&sink, (void**)buffer, SRSLTE_SF_LEN_PRB(nof_prb), nof_rx_antennas); + subframe_count++; + } } if (!keep_running) { if (!start_capture || (start_capture && srslte_ue_sync_get_sfidx(&ue_sync) == 9)) { - stop_capture = true; + stop_capture = true; } } } - + srslte_filesink_free(&sink); srslte_rf_close(&rf); srslte_ue_sync_free(&ue_sync); diff --git a/lib/examples/usrp_capture_sync_nbiot.c b/lib/examples/usrp_capture_sync_nbiot.c index a46f8543e..9cd21479d 100644 --- a/lib/examples/usrp_capture_sync_nbiot.c +++ b/lib/examples/usrp_capture_sync_nbiot.c @@ -134,8 +134,8 @@ int main(int argc, char** argv) srslte_rf_start_rx_stream(&rf, false); srslte_nbiot_cell_t cell = {}; - cell.base.nof_prb = nof_prb; - cell.base.nof_ports = 1; + cell.base.nof_prb = nof_prb; + cell.base.nof_ports = 1; cf_t* buff_ptrs[SRSLTE_MAX_PORTS] = {NULL, NULL, NULL, NULL}; buff_ptrs[0] = srslte_vec_malloc(sizeof(cf_t) * SRSLTE_SF_LEN_PRB_NBIOT * 10); diff --git a/lib/examples/usrp_txrx.c b/lib/examples/usrp_txrx.c index f47105712..91e1ba55c 100644 --- a/lib/examples/usrp_txrx.c +++ b/lib/examples/usrp_txrx.c @@ -19,77 +19,79 @@ * */ +#include +#include #include #include #include -#include -#include #include -#include +#include #include "srslte/phy/rf/rf.h" #include "srslte/srslte.h" uint32_t nof_prb = 25; -uint32_t nof_frames = 20; +uint32_t nof_frames = 20; -int time_adv_samples = 0; -float tone_offset_hz = 1e6; -float rf_rx_gain=40, srslte_rf_tx_gain=40, rf_freq=2.4e9; -char *rf_args=""; -char *output_filename = NULL; -char *input_filename = NULL; +int time_adv_samples = 0; +float tone_offset_hz = 1e6; +float rf_rx_gain = 40, srslte_rf_tx_gain = 40, rf_freq = 2.4e9; +char* rf_args = ""; +char* output_filename = NULL; +char* input_filename = NULL; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s -o [rx_signal_file]\n", prog); printf("\t-a RF args [Default %s]\n", rf_args); - printf("\t-f RF TX/RX frequency [Default %.2f MHz]\n", rf_freq/1e6); + printf("\t-f RF TX/RX frequency [Default %.2f MHz]\n", rf_freq / 1e6); printf("\t-g RF RX gain [Default %.1f dB]\n", rf_rx_gain); printf("\t-G RF TX gain [Default %.1f dB]\n", srslte_rf_tx_gain); printf("\t-t Single tone offset (Hz) [Default %f]\n", tone_offset_hz); - printf("\t-T Time advance samples [Default %d]\n", time_adv_samples); + printf("\t-T Time advance samples [Default %d]\n", time_adv_samples); printf("\t-i File name to read signal from [Default single tone]\n"); - printf("\t-p Number of UL RB [Default %d]\n", nof_prb); + printf("\t-p Number of UL RB [Default %d]\n", nof_prb); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "ioafgGptT")) != -1) { switch (opt) { - case 'a': - rf_args = argv[optind]; - break; - case 'o': - output_filename = argv[optind]; - break; - case 'i': - input_filename = argv[optind]; - break; - case 't': - tone_offset_hz = strtof(argv[optind], NULL); - break; - case 'T': - time_adv_samples = (int)strtol(argv[optind], NULL, 10); - break; - case 'f': - rf_freq = strtof(argv[optind], NULL); - break; - case 'g': - rf_rx_gain = strtof(argv[optind], NULL); - break; - case 'G': - srslte_rf_tx_gain = strtof(argv[optind], NULL); - break; - case 'p': - nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - if (!srslte_nofprb_isvalid(nof_prb)) { - ERROR("Invalid number of UL RB %d\n", nof_prb); + case 'a': + rf_args = argv[optind]; + break; + case 'o': + output_filename = argv[optind]; + break; + case 'i': + input_filename = argv[optind]; + break; + case 't': + tone_offset_hz = strtof(argv[optind], NULL); + break; + case 'T': + time_adv_samples = (int)strtol(argv[optind], NULL, 10); + break; + case 'f': + rf_freq = strtof(argv[optind], NULL); + break; + case 'g': + rf_rx_gain = strtof(argv[optind], NULL); + break; + case 'G': + srslte_rf_tx_gain = strtof(argv[optind], NULL); + break; + case 'p': + nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + if (!srslte_nofprb_isvalid(nof_prb)) { + ERROR("Invalid number of UL RB %d\n", nof_prb); + exit(-1); + } + break; + default: + usage(argv[0]); exit(-1); - } - break; - default: - usage(argv[0]); - exit(-1); } } if (!output_filename) { @@ -103,34 +105,35 @@ void parse_args(int argc, char **argv) { } } -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ parse_args(argc, argv); - - uint32_t flen = srslte_sampling_freq_hz(nof_prb)/1000; - - cf_t *rx_buffer = malloc(sizeof(cf_t)*flen*nof_frames); + + uint32_t flen = srslte_sampling_freq_hz(nof_prb) / 1000; + + cf_t* rx_buffer = malloc(sizeof(cf_t) * flen * nof_frames); if (!rx_buffer) { perror("malloc"); exit(-1); } - cf_t *tx_buffer = malloc(sizeof(cf_t)*(flen+time_adv_samples)); + cf_t* tx_buffer = malloc(sizeof(cf_t) * (flen + time_adv_samples)); if (!tx_buffer) { perror("malloc"); exit(-1); } - bzero(tx_buffer, sizeof(cf_t)*(flen+time_adv_samples)); - - cf_t *zeros = calloc(sizeof(cf_t),flen); + bzero(tx_buffer, sizeof(cf_t) * (flen + time_adv_samples)); + + cf_t* zeros = calloc(sizeof(cf_t), flen); if (!zeros) { perror("calloc"); exit(-1); } - float time_adv_sec = (float) time_adv_samples/srslte_sampling_freq_hz(nof_prb); - - // Send through RF - srslte_rf_t rf; + float time_adv_sec = (float)time_adv_samples / srslte_sampling_freq_hz(nof_prb); + + // Send through RF + srslte_rf_t rf; printf("Opening RF device...\n"); if (srslte_rf_open(&rf, rf_args)) { ERROR("Error opening rf\n"); @@ -138,48 +141,45 @@ int main(int argc, char **argv) { } int srate = srslte_sampling_freq_hz(nof_prb); - srslte_rf_set_rx_srate(&rf, (double) srate); - srslte_rf_set_tx_srate(&rf, (double) srate); - - + srslte_rf_set_rx_srate(&rf, (double)srate); + srslte_rf_set_tx_srate(&rf, (double)srate); + printf("Subframe len: %d samples\n", flen); - printf("Time advance: %f us\n",time_adv_sec*1e6); - printf("Set TX/RX rate: %.2f MHz\n", (float) srate / 1000000); + printf("Time advance: %f us\n", time_adv_sec * 1e6); + printf("Set TX/RX rate: %.2f MHz\n", (float)srate / 1000000); printf("Set RX gain: %.1f dB\n", srslte_rf_set_rx_gain(&rf, rf_rx_gain)); printf("Set TX gain: %.1f dB\n", srslte_rf_set_tx_gain(&rf, srslte_rf_tx_gain)); printf("Set TX/RX freq: %.2f MHz\n", srslte_rf_set_rx_freq(&rf, 0, rf_freq) / 1000000); srslte_rf_set_tx_freq(&rf, 0, rf_freq); sleep(1); - + if (input_filename) { - srslte_vec_load_file(input_filename, &tx_buffer[time_adv_samples], flen*sizeof(cf_t)); + srslte_vec_load_file(input_filename, &tx_buffer[time_adv_samples], flen * sizeof(cf_t)); } else { - for (int i=0;i +#include #include +#include #include #include #include -#include -#include #include +#include #include #include -#include "srslte/srslte.h" #include "srslte/phy/rf/rf.h" +#include "srslte/srslte.h" -static bool keep_running = true; -static uint32_t nof_rx_antennas = 1; +static bool keep_running = true; +static uint32_t nof_rx_antennas = 1; static const uint32_t max_rx_antennas = 1; static void int_handler(int dummy); -static void usage(char *prog); -static void parse_args(int argc, char **argv); -static int init_radio(uint32_t *buf_len); -static int rx_radio(void **buffer, uint32_t buff_len); +static void usage(char* prog); +static void parse_args(int argc, char** argv); +static int init_radio(uint32_t* buf_len); +static int rx_radio(void** buffer, uint32_t buff_len); static void close_radio(); /* Example function to initialize ZMQ socket */ -static void *zmq_ctx = NULL; -static void *zmq_sock = NULL; -static const char *zmq_args = "tcp://*:5550"; -static int init_zmq() +static void* zmq_ctx = NULL; +static void* zmq_sock = NULL; +static const char* zmq_args = "tcp://*:5550"; +static int init_zmq() { zmq_ctx = zmq_ctx_new(); @@ -69,7 +69,7 @@ static int init_zmq() } /* Example function to write samples to ZMQ socket */ -static int tx_zmq(void **buffer, uint32_t buffer_len) +static int tx_zmq(void** buffer, uint32_t buffer_len) { // wait for request uint8_t dummy; @@ -77,10 +77,11 @@ static int tx_zmq(void **buffer, uint32_t buffer_len) return zmq_send(zmq_sock, buffer[0], buffer_len, 0); } -int main(int argc, char **argv) { - void *buffer[max_rx_antennas]; - int n = 0; - uint32_t buflen = 0; // in samples +int main(int argc, char** argv) +{ + void* buffer[max_rx_antennas]; + int n = 0; + uint32_t buflen = 0; // in samples uint32_t sample_size = 8; // Sets signal handlers @@ -105,9 +106,9 @@ int main(int argc, char **argv) { } // Initializes memory for input buffer - bzero(buffer, sizeof(void*)*max_rx_antennas); + bzero(buffer, sizeof(void*) * max_rx_antennas); for (int i = 0; i < nof_rx_antennas; i++) { - buffer[i] = malloc(buflen*sizeof(cf_t)); + buffer[i] = malloc(buflen * sizeof(cf_t)); if (!buffer[i]) { perror("malloc"); exit(-1); @@ -116,7 +117,7 @@ int main(int argc, char **argv) { printf("Streaming samples...\n"); uint32_t print_cnt = 0; - while(keep_running) { + while (keep_running) { n = rx_radio(buffer, buflen); if (n < 0) { ERROR("Error receiving samples\n"); @@ -126,7 +127,7 @@ int main(int argc, char **argv) { printf("Received %d samples from radio\n", n); } - n = tx_zmq((void**) buffer, n*sample_size); + n = tx_zmq((void**)buffer, n * sample_size); if (n == -1) { print_cnt++; @@ -156,11 +157,11 @@ int main(int argc, char **argv) { /* Example function to initialize the Radio frontend. In this case, we use srsLTE RF API to open a device, * which automatically picks UHD, bladeRF, limeSDR, etc. */ -static srslte_rf_t rf = {}; -static char *rf_args = "fastpath"; -static float rf_gain = 40.0, rf_freq = -1.0, rf_rate = 11.52e6; -static uint32_t rf_recv_frame_size_ms = 1; -static int init_radio(uint32_t *buffer_len) +static srslte_rf_t rf = {}; +static char* rf_args = "fastpath"; +static float rf_gain = 40.0, rf_freq = -1.0, rf_rate = 11.52e6; +static uint32_t rf_recv_frame_size_ms = 1; +static int init_radio(uint32_t* buffer_len) { // Uses srsLTE RF API to open a device, could use other code here printf("Opening RF device...\n"); @@ -178,17 +179,17 @@ static int init_radio(uint32_t *buffer_len) } if (buffer_len) { - *buffer_len = srate*rf_recv_frame_size_ms*1e-3; + *buffer_len = srate * rf_recv_frame_size_ms * 1e-3; } - printf("Set RX rate: %.2f MHz\n", srate*1e-6); + printf("Set RX rate: %.2f MHz\n", srate * 1e-6); srslte_rf_start_rx_stream(&rf, false); return 0; } /* Example implementation to receive from Radio frontend. In this case we use srsLTE */ -static int rx_radio(void **buffer, uint32_t buf_len) +static int rx_radio(void** buffer, uint32_t buf_len) { return srslte_rf_recv_with_time_multi(&rf, buffer, buf_len, true, NULL, NULL); } @@ -198,11 +199,13 @@ static void close_radio() srslte_rf_close(&rf); } -static void int_handler(int dummy) { +static void int_handler(int dummy) +{ keep_running = false; } -static void usage(char *prog) { +static void usage(char* prog) +{ printf("Usage: %s [agrAzv] -f rx_frequency_hz\n", prog); printf("\t-a RF args [Default %s]\n", rf_args); printf("\t-g RF Gain [Default %.2f dB]\n", rf_gain); @@ -213,7 +216,8 @@ static void usage(char *prog) { printf("\t-v srslte_verbose\n"); } -static void parse_args(int argc, char **argv) { +static void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "agrfvmzA")) != -1) { switch (opt) { @@ -256,4 +260,3 @@ static void parse_args(int argc, char **argv) { exit(-1); } } - diff --git a/lib/include/srslte/asn1/gtpc.h b/lib/include/srslte/asn1/gtpc.h index c50b1bcda..89ab92d10 100644 --- a/lib/include/srslte/asn1/gtpc.h +++ b/lib/include/srslte/asn1/gtpc.h @@ -21,11 +21,10 @@ #ifndef SRSLTE_GTPC_H #define SRSLTE_GTPC_H -#include #include "srslte/asn1/gtpc_msg.h" +#include - -namespace srslte{ +namespace srslte { /*GTP-C Version*/ const uint8_t GTPC_V2 = 2; diff --git a/lib/include/srslte/asn1/gtpc_ies.h b/lib/include/srslte/asn1/gtpc_ies.h index 264045c87..b92b37f2e 100644 --- a/lib/include/srslte/asn1/gtpc_ies.h +++ b/lib/include/srslte/asn1/gtpc_ies.h @@ -24,8 +24,7 @@ #include "srslte/phy/io/netsource.h" -namespace srslte -{ +namespace srslte { /**************************************************************** * @@ -33,111 +32,110 @@ namespace srslte * Ref: TS 29.274 v10.14.0 Table 8.1-1 * ****************************************************************/ -enum gtpc_ie_type -{ -//const uint8_t GTPC_IE_TYPE_RESERVED = 0; - GTPC_IE_TYPE_IMSI = 1, - GTPC_IE_TYPE_CAUSE = 2, +enum gtpc_ie_type { + // const uint8_t GTPC_IE_TYPE_RESERVED = 0; + GTPC_IE_TYPE_IMSI = 1, + GTPC_IE_TYPE_CAUSE = 2, GTPC_IE_TYPE_RECOVERY = 3, -//4 to 50 RESERVED_FOR_S101_INTERFACE + // 4 to 50 RESERVED_FOR_S101_INTERFACE GTPC_IE_TYPE_STN_SR = 51, -//52 to 70 RESERVED_FOR_SV_INTERFACE - GTPC_IE_TYPE_APN = 71, - GTPC_IE_TYPE_AMBR = 72, - GTPC_IE_TYPE_EBI = 73, - GTPC_IE_TYPE_IP_ADDRESS = 74, - GTPC_IE_TYPE_MEI = 75, - GTPC_IE_TYPE_MSISDN = 76, - GTPC_IE_TYPE_INDICATION = 77, - GTPC_IE_TYPE_PCO = 78, - GTPC_IE_TYPE_PDN_ADDRESS_ALLOCATION = 79, - GTPC_IE_TYPE_BEARER_QOS = 80, - GTPC_IE_TYPE_FLOW_QOS = 81, - GTPC_IE_TYPE_RAT_TYPE = 82, - GTPC_IE_TYPE_SERVING_NETWORK = 83, - GTPC_IE_TYPE_BEARER_TFT = 84, - GTPC_IE_TYPE_TAD = 85, - GTPC_IE_TYPE_ULI = 86, - GTPC_IE_TYPE_F_TEID = 87, - GTPC_IE_TYPE_TMSI = 88, - GTPC_IE_TYPE_GLOBAL_CN_ID = 89, + // 52 to 70 RESERVED_FOR_SV_INTERFACE + GTPC_IE_TYPE_APN = 71, + GTPC_IE_TYPE_AMBR = 72, + GTPC_IE_TYPE_EBI = 73, + GTPC_IE_TYPE_IP_ADDRESS = 74, + GTPC_IE_TYPE_MEI = 75, + GTPC_IE_TYPE_MSISDN = 76, + GTPC_IE_TYPE_INDICATION = 77, + GTPC_IE_TYPE_PCO = 78, + GTPC_IE_TYPE_PDN_ADDRESS_ALLOCATION = 79, + GTPC_IE_TYPE_BEARER_QOS = 80, + GTPC_IE_TYPE_FLOW_QOS = 81, + GTPC_IE_TYPE_RAT_TYPE = 82, + GTPC_IE_TYPE_SERVING_NETWORK = 83, + GTPC_IE_TYPE_BEARER_TFT = 84, + GTPC_IE_TYPE_TAD = 85, + GTPC_IE_TYPE_ULI = 86, + GTPC_IE_TYPE_F_TEID = 87, + GTPC_IE_TYPE_TMSI = 88, + GTPC_IE_TYPE_GLOBAL_CN_ID = 89, GTPC_IE_TYPE_S103_PDN_DATA_FORWARDING_INFO = 90, - GTPC_IE_TYPE_S1_U_DATA_FORWARDING_INFO = 91, - GTPC_IE_TYPE_DELAY_VALUE = 92, - GTPC_IE_TYPE_BEARER_CONTEXT = 93, - GTPC_IE_TYPE_CHARGING_ID = 94, - GTPC_IE_TYPE_CHARGING_CHARACTERISTICS = 95, - GTPC_IE_TYPE_TRACE_INFORMATION = 96, - GTPC_IE_TYPE_BEARER_FLAGS = 97, -//98 Reserved - GTPC_IE_TYPE_PDN_TYPE = 99, + GTPC_IE_TYPE_S1_U_DATA_FORWARDING_INFO = 91, + GTPC_IE_TYPE_DELAY_VALUE = 92, + GTPC_IE_TYPE_BEARER_CONTEXT = 93, + GTPC_IE_TYPE_CHARGING_ID = 94, + GTPC_IE_TYPE_CHARGING_CHARACTERISTICS = 95, + GTPC_IE_TYPE_TRACE_INFORMATION = 96, + GTPC_IE_TYPE_BEARER_FLAGS = 97, + // 98 Reserved + GTPC_IE_TYPE_PDN_TYPE = 99, GTPC_IE_TYPE_PROCEDURE_TRANSACTION_ID = 100, - GTPC_IE_TYPE_DRX_PARAMETER = 101, -//102 Reserved - GTPC_IE_TYPE_MM_CONTEXT_GSM_KEY_AND_TRIPLETS = 103, - GTPC_IE_TYPE_MM_CONTEXT_UMTS_KEY_USED_CIPHER_AND_QUINTUPLETS = 104, - GTPC_IE_TYPE_MM_CONTEXT_GSM_KEY_USED_CIPHER_AND_QUINTUPLETS = 105, - GTPC_IE_TYPE_MM_CONTEXT_UMTS_KEY_AND_QUINTUPLETS = 106, + GTPC_IE_TYPE_DRX_PARAMETER = 101, + // 102 Reserved + GTPC_IE_TYPE_MM_CONTEXT_GSM_KEY_AND_TRIPLETS = 103, + GTPC_IE_TYPE_MM_CONTEXT_UMTS_KEY_USED_CIPHER_AND_QUINTUPLETS = 104, + GTPC_IE_TYPE_MM_CONTEXT_GSM_KEY_USED_CIPHER_AND_QUINTUPLETS = 105, + GTPC_IE_TYPE_MM_CONTEXT_UMTS_KEY_AND_QUINTUPLETS = 106, GTPC_IE_TYPE_MM_CONTEXT_EPS_SECURITY_CONTEXT_QUADRUPLETS_AND_QUINTUPLETS = 107, - GTPC_IE_TYPE_MM_CONTEXT_UMTS_KEY_QUADRUPLETS_AND_QUINTUPLETS = 108, - GTPC_IE_TYPE_PDN_CONNECTION = 109, - GTPC_IE_TYPE_PDU_NUMBERS = 110, - GTPC_IE_TYPE_P_TMSI = 111, - GTPC_IE_TYPE_P_TMSI_SIGNATURE = 112, - GTPC_IE_TYPE_HOP_COUNTER = 113, - GTPC_IE_TYPE_UE_TIME_ZONE = 114, - GTPC_IE_TYPE_TRACE_REFERENCE = 115, - GTPC_IE_TYPE_COMPLETE_REQUEST_MESSAGE = 116, - GTPC_IE_TYPE_GUTI = 117, - GTPC_IE_TYPE_F_CONTAINER = 118, - GTPC_IE_TYPE_F_CAUSE = 119, - GTPC_IE_TYPE_SELECTED_PLMN_ID = 120, - GTPC_IE_TYPE_TARGET_IDENTIFICATION = 121, -//122 Reserved - GTPC_IE_TYPE_PACKET_FLOW_ID = 123, - GTPC_IE_TYPE_RAB_CONTEXT = 124, + GTPC_IE_TYPE_MM_CONTEXT_UMTS_KEY_QUADRUPLETS_AND_QUINTUPLETS = 108, + GTPC_IE_TYPE_PDN_CONNECTION = 109, + GTPC_IE_TYPE_PDU_NUMBERS = 110, + GTPC_IE_TYPE_P_TMSI = 111, + GTPC_IE_TYPE_P_TMSI_SIGNATURE = 112, + GTPC_IE_TYPE_HOP_COUNTER = 113, + GTPC_IE_TYPE_UE_TIME_ZONE = 114, + GTPC_IE_TYPE_TRACE_REFERENCE = 115, + GTPC_IE_TYPE_COMPLETE_REQUEST_MESSAGE = 116, + GTPC_IE_TYPE_GUTI = 117, + GTPC_IE_TYPE_F_CONTAINER = 118, + GTPC_IE_TYPE_F_CAUSE = 119, + GTPC_IE_TYPE_SELECTED_PLMN_ID = 120, + GTPC_IE_TYPE_TARGET_IDENTIFICATION = 121, + // 122 Reserved + GTPC_IE_TYPE_PACKET_FLOW_ID = 123, + GTPC_IE_TYPE_RAB_CONTEXT = 124, GTPC_IE_TYPE_SOURCE_RNC_PDCP_CONTEXT_INFO = 125, - GTPC_IE_TYPE_UDP_SOURCE_PORT_NUMBER = 126, - GTPC_IE_TYPE_APN_RESTRICTION = 127, - GTPC_IE_TYPE_SELECTION_MODE = 128, - GTPC_IE_TYPE_SOURCE_IDENTIFICATION = 129, -//130 RESERVED - GTPC_IE_TYPE_CHANGE_REPORTING_ACTION = 131, - GTPC_IE_TYPE_FQ_CSID = 132, - GTPC_IE_TYPE_CHANNEL_NEEDED = 133, - GTPC_IE_TYPE_EMLPP_PRIORITY = 134, - GTPC_IE_TYPE_NODE_TYPE = 135, - GTPC_IE_TYPE_FQDN = 136, - GTPC_IE_TYPE_TI = 137, - GTPC_IE_TYPE_MBMS_SESSION_DURATION = 138, - GTPC_IE_TYPE_MBMS_SERVICE_AREA = 139, - GTPC_IE_TYPE_MBMS_SESSION_IDENTIFIER = 140, - GTPC_IE_TYPE_MBMS_FLOW_IDENTIFIER = 141, - GTPC_IE_TYPE_MBMS_IP_MULTICAST_DISTRIBUTION = 142, - GTPC_IE_TYPE_MBMS_DISTRIBUTION_ACKNOWLEDGE = 143, - GTPC_IE_TYPE_RFSP_INDEX = 144, - GTPC_IE_TYPE_UCI = 145, + GTPC_IE_TYPE_UDP_SOURCE_PORT_NUMBER = 126, + GTPC_IE_TYPE_APN_RESTRICTION = 127, + GTPC_IE_TYPE_SELECTION_MODE = 128, + GTPC_IE_TYPE_SOURCE_IDENTIFICATION = 129, + // 130 RESERVED + GTPC_IE_TYPE_CHANGE_REPORTING_ACTION = 131, + GTPC_IE_TYPE_FQ_CSID = 132, + GTPC_IE_TYPE_CHANNEL_NEEDED = 133, + GTPC_IE_TYPE_EMLPP_PRIORITY = 134, + GTPC_IE_TYPE_NODE_TYPE = 135, + GTPC_IE_TYPE_FQDN = 136, + GTPC_IE_TYPE_TI = 137, + GTPC_IE_TYPE_MBMS_SESSION_DURATION = 138, + GTPC_IE_TYPE_MBMS_SERVICE_AREA = 139, + GTPC_IE_TYPE_MBMS_SESSION_IDENTIFIER = 140, + GTPC_IE_TYPE_MBMS_FLOW_IDENTIFIER = 141, + GTPC_IE_TYPE_MBMS_IP_MULTICAST_DISTRIBUTION = 142, + GTPC_IE_TYPE_MBMS_DISTRIBUTION_ACKNOWLEDGE = 143, + GTPC_IE_TYPE_RFSP_INDEX = 144, + GTPC_IE_TYPE_UCI = 145, GTPC_IE_TYPE_CSG_INFORMATION_REPORTING_ACTION = 146, - GTPC_IE_TYPE_CSG_ID = 147, - GTPC_IE_TYPE_CMI = 148, - GTPC_IE_TYPE_SERVICE_INDICATOR = 149, - GTPC_IE_TYPE_DETACH_TYPE = 150, - GTPC_IE_TYPE_LDN = 151, - GTPC_IE_TYPE_NODE_FEATURES = 152, - GTPC_IE_TYPE_MBMS_TIME_TO_DATA_TRANSFER = 153, - GTPC_IE_TYPE_THROTTLING =154, - GTPC_IE_TYPE_ARP = 155, - GTPC_IE_TYPE_EPC_TIMER = 156, - GTPC_IE_TYPE_SIGNALLING_PRIORITY_INDICATION = 157, - GTPC_IE_TYPE_TMGI = 158, - GTPC_IE_TYPE_ADDITIONAL_MM_CONTEXT_FOR_SRVCC = 159, - GTPC_IE_TYPE_ADDITIONAL_FLAGS_FOR_SRVCC = 160, -//161 RESERVED + GTPC_IE_TYPE_CSG_ID = 147, + GTPC_IE_TYPE_CMI = 148, + GTPC_IE_TYPE_SERVICE_INDICATOR = 149, + GTPC_IE_TYPE_DETACH_TYPE = 150, + GTPC_IE_TYPE_LDN = 151, + GTPC_IE_TYPE_NODE_FEATURES = 152, + GTPC_IE_TYPE_MBMS_TIME_TO_DATA_TRANSFER = 153, + GTPC_IE_TYPE_THROTTLING = 154, + GTPC_IE_TYPE_ARP = 155, + GTPC_IE_TYPE_EPC_TIMER = 156, + GTPC_IE_TYPE_SIGNALLING_PRIORITY_INDICATION = 157, + GTPC_IE_TYPE_TMGI = 158, + GTPC_IE_TYPE_ADDITIONAL_MM_CONTEXT_FOR_SRVCC = 159, + GTPC_IE_TYPE_ADDITIONAL_FLAGS_FOR_SRVCC = 160, + // 161 RESERVED GTPC_IE_TYPE_MDT_CONFIGURATION = 162, - GTPC_IE_TYPE_APCO = 163, -//164 RESERVED + GTPC_IE_TYPE_APCO = 163, + // 164 RESERVED GTPC_IE_TYPE_CHANGE_TO_REPORT_FLAGS = 165, -//168 TO 254 SPARE. FOR FUTURE USE. + // 168 TO 254 SPARE. FOR FUTURE USE. GTPC_IE_TYPE_PRIVATE_EXTENSION = 255 }; @@ -149,7 +147,7 @@ enum gtpc_ie_type ****************************************************************/ /* * The IMSI should be kept as an uint64_t. - * The responsibility to convert from uint64_t to BCD coded is on + * The responsibility to convert from uint64_t to BCD coded is on * the pack_imsi_ie function */ @@ -159,91 +157,89 @@ enum gtpc_ie_type * Ref: 3GPP TS 29.274 v10.14.0 Figure 8.4-1 and Table 8.4-1 * ***************************************************************************/ -enum gtpc_cause_value -{ - //Reserved - GTPC_CAUSE_VALUE_LOCAL_DETACH = 2, - GTPC_CAUSE_VALUE_COMPLETE_DETACH = 3, - GTPC_CAUSE_VALUE_RAT_CHANGED_FROM_3GPP_TO_NON_3GPP = 4, - GTPC_CAUSE_VALUE_ISR_DEACTIVATION = 5, +enum gtpc_cause_value { + // Reserved + GTPC_CAUSE_VALUE_LOCAL_DETACH = 2, + GTPC_CAUSE_VALUE_COMPLETE_DETACH = 3, + GTPC_CAUSE_VALUE_RAT_CHANGED_FROM_3GPP_TO_NON_3GPP = 4, + GTPC_CAUSE_VALUE_ISR_DEACTIVATION = 5, GTPC_CAUSE_VALUE_ERROR_INDICATION_RECEIVED_FROM_RNC_ENODEB_S4_SGSN = 6, - GTPC_CAUSE_VALUE_IMSI_DETACH_ONLY = 7, - GTPC_CAUSE_VALUE_REACTIVATION_REQUESTED = 8, - GTPC_CAUSE_VALUE_PDN_RECONNECTION_TO_THIS_APN_DISALLOWED = 9, - GTPC_CAUSE_VALUE_ACCESS_CHANGED_FROM_NON_3GPP_TO_3GPP = 10, - GTPC_CAUSE_VALUE_PDN_CONNECTION_INACTIVITY_TIMER_EXPIRES = 11, - //Spare. This value range shall be used by Cause values in an initial/request message. - GTPC_CAUSE_VALUE_REQUEST_ACCEPTED = 16, - GTPC_CAUSE_VALUE_REQUEST_ACCEPTED_PARTIALLY = 17, - GTPC_CAUSE_VALUE_NEW_PDN_TYPE_DUE_TO_NETWORK_PREFERENCE = 18, + GTPC_CAUSE_VALUE_IMSI_DETACH_ONLY = 7, + GTPC_CAUSE_VALUE_REACTIVATION_REQUESTED = 8, + GTPC_CAUSE_VALUE_PDN_RECONNECTION_TO_THIS_APN_DISALLOWED = 9, + GTPC_CAUSE_VALUE_ACCESS_CHANGED_FROM_NON_3GPP_TO_3GPP = 10, + GTPC_CAUSE_VALUE_PDN_CONNECTION_INACTIVITY_TIMER_EXPIRES = 11, + // Spare. This value range shall be used by Cause values in an initial/request message. + GTPC_CAUSE_VALUE_REQUEST_ACCEPTED = 16, + GTPC_CAUSE_VALUE_REQUEST_ACCEPTED_PARTIALLY = 17, + GTPC_CAUSE_VALUE_NEW_PDN_TYPE_DUE_TO_NETWORK_PREFERENCE = 18, GTPC_CAUSE_VALUE_NEW_PDN_TYPE_DUE_TO_SINGLE_ADDRESS_BEARER_ONLY = 19, - //20-63 Spare. - GTPC_CAUSE_VALUE_CONTEXT_NOT_FOUND = 64, - GTPC_CAUSE_VALUE_INVALID_MESSAGE_FORMAT = 65, + // 20-63 Spare. + GTPC_CAUSE_VALUE_CONTEXT_NOT_FOUND = 64, + GTPC_CAUSE_VALUE_INVALID_MESSAGE_FORMAT = 65, GTPC_CAUSE_VALUE_VERSION_NOT_SUPPORTED_BY_NEXT_PEER = 66, - GTPC_CAUSE_VALUE_INVALID_LENGTH = 67, - GTPC_CAUSE_VALUE_SERVICE_NOT_SUPPORTED = 68, - GTPC_CAUSE_VALUE_MANDATORY_IE_INCORRECT = 69, - GTPC_CAUSE_VALUE_MANDATORY_IE_MISSING = 70, - //71 Shall not be used. - GTPC_CAUSE_VALUE_SYSTEM_FAILURE = 72, - GTPC_CAUSE_VALUE_NO_RESOURCES_AVAILABLE = 73, - GTPC_CAUSE_VALUE_SEMANTIC_ERROR_IN_THE_TFT_OPERATION = 74, + GTPC_CAUSE_VALUE_INVALID_LENGTH = 67, + GTPC_CAUSE_VALUE_SERVICE_NOT_SUPPORTED = 68, + GTPC_CAUSE_VALUE_MANDATORY_IE_INCORRECT = 69, + GTPC_CAUSE_VALUE_MANDATORY_IE_MISSING = 70, + // 71 Shall not be used. + GTPC_CAUSE_VALUE_SYSTEM_FAILURE = 72, + GTPC_CAUSE_VALUE_NO_RESOURCES_AVAILABLE = 73, + GTPC_CAUSE_VALUE_SEMANTIC_ERROR_IN_THE_TFT_OPERATION = 74, GTPC_CAUSE_VALUE_SYNTACTIC_ERROR_IN_THE_TFT_OPERATION = 75, - GTPC_CAUSE_VALUE_SEMANTIC_ERRORS_IN_PACKET_FILTER = 76, - GTPC_CAUSE_VALUE_SYNTACTIC_ERRORS_IN_PACKET_FILTER = 77, - GTPC_CAUSE_VALUE_MISSING_OR_UNKNOWN_APN = 78, - //79 Shall not be used. - GTPC_CAUSE_VALUE_GRE_KEY_NOT_FOUND = 80, - GTPC_CAUSE_VALUE_RELOCATION_FAILURE = 81, - GTPC_CAUSE_VALUE_DENIED_IN_RAT = 82, - GTPC_CAUSE_VALUE_PREFERRED_PDN_TYPE_NOT_SUPPORTED = 83, - GTPC_CAUSE_VALUE_ALL_DYNAMIC_ADDRESSES_ARE_OCCUPIED = 84, + GTPC_CAUSE_VALUE_SEMANTIC_ERRORS_IN_PACKET_FILTER = 76, + GTPC_CAUSE_VALUE_SYNTACTIC_ERRORS_IN_PACKET_FILTER = 77, + GTPC_CAUSE_VALUE_MISSING_OR_UNKNOWN_APN = 78, + // 79 Shall not be used. + GTPC_CAUSE_VALUE_GRE_KEY_NOT_FOUND = 80, + GTPC_CAUSE_VALUE_RELOCATION_FAILURE = 81, + GTPC_CAUSE_VALUE_DENIED_IN_RAT = 82, + GTPC_CAUSE_VALUE_PREFERRED_PDN_TYPE_NOT_SUPPORTED = 83, + GTPC_CAUSE_VALUE_ALL_DYNAMIC_ADDRESSES_ARE_OCCUPIED = 84, GTPC_CAUSE_VALUE_UE_CONTEXT_WITHOUT_TFT_ALREADY_ACTIVATED = 85, - GTPC_CAUSE_VALUE_PROTOCOL_TYPE_NOT_SUPPORTED = 86, - GTPC_CAUSE_VALUE_UE_NOT_RESPONDING = 87, - GTPC_CAUSE_VALUE_UE_REFUSES = 88, - GTPC_CAUSE_VALUE_SERVICE_DENIED = 89, - GTPC_CAUSE_VALUE_UNABLE_TO_PAGE_UE = 90, - GTPC_CAUSE_VALUE_NO_MEMORY_AVAILABLE = 91, - GTPC_CAUSE_VALUE_USER_AUTHENTICATION_FAILED = 92, - GTPC_CAUSE_VALUE_APN_ACCESS_DENIED_NO_SUBSCRIPTION = 93, - GTPC_CAUSE_VALUE_REQUEST_REJECTED = 94, - GTPC_CAUSE_VALUE_P_TMSI_SIGNATURE_MISMATCH = 95, - GTPC_CAUSE_VALUE_IMSI_IMEI_NOT_KNOWN = 96, - GTPC_CAUSE_VALUE_SEMANTIC_ERROR_IN_THE_TAD_OPERATION = 97, - GTPC_CAUSE_VALUE_SYNTACTIC_ERROR_IN_THE_TAD_OPERATION = 98, - //99 Shall not be used. - GTPC_CAUSE_VALUE_REMOTE_PEER_NOT_RESPONDING = 100, - GTPC_CAUSE_VALUE_COLLISION_WITH_NETWORK_INITIATED_REQUEST = 101, - GTPC_CAUSE_VALUE_UNABLE_TO_PAGE_UE_DUE_TO_SUSPENSION = 102, - GTPC_CAUSE_VALUE_CONDITIONAL_IE_MISSING = 103, - GTPC_CAUSE_VALUE_APN_RESTRICTION_TYPE_INCOMPATIBLE_WITH_CURRENTLY_ACTIVE_PDN_CONNECTION = 104, + GTPC_CAUSE_VALUE_PROTOCOL_TYPE_NOT_SUPPORTED = 86, + GTPC_CAUSE_VALUE_UE_NOT_RESPONDING = 87, + GTPC_CAUSE_VALUE_UE_REFUSES = 88, + GTPC_CAUSE_VALUE_SERVICE_DENIED = 89, + GTPC_CAUSE_VALUE_UNABLE_TO_PAGE_UE = 90, + GTPC_CAUSE_VALUE_NO_MEMORY_AVAILABLE = 91, + GTPC_CAUSE_VALUE_USER_AUTHENTICATION_FAILED = 92, + GTPC_CAUSE_VALUE_APN_ACCESS_DENIED_NO_SUBSCRIPTION = 93, + GTPC_CAUSE_VALUE_REQUEST_REJECTED = 94, + GTPC_CAUSE_VALUE_P_TMSI_SIGNATURE_MISMATCH = 95, + GTPC_CAUSE_VALUE_IMSI_IMEI_NOT_KNOWN = 96, + GTPC_CAUSE_VALUE_SEMANTIC_ERROR_IN_THE_TAD_OPERATION = 97, + GTPC_CAUSE_VALUE_SYNTACTIC_ERROR_IN_THE_TAD_OPERATION = 98, + // 99 Shall not be used. + GTPC_CAUSE_VALUE_REMOTE_PEER_NOT_RESPONDING = 100, + GTPC_CAUSE_VALUE_COLLISION_WITH_NETWORK_INITIATED_REQUEST = 101, + GTPC_CAUSE_VALUE_UNABLE_TO_PAGE_UE_DUE_TO_SUSPENSION = 102, + GTPC_CAUSE_VALUE_CONDITIONAL_IE_MISSING = 103, + GTPC_CAUSE_VALUE_APN_RESTRICTION_TYPE_INCOMPATIBLE_WITH_CURRENTLY_ACTIVE_PDN_CONNECTION = 104, GTPC_CAUSE_VALUE_INVALID_OVERALL_LENGTH_OF_THE_TRIGGERED_RESPONSE_MSG_AND_A_PIGGYBACKED_INITIAL_MSG = 105, - GTPC_CAUSE_VALUE_DATA_FORWARDING_NOT_SUPPORTED = 106, - GTPC_CAUSE_VALUE_INVALID_REPLY_FROM_REMOTE_PEER = 107, - GTPC_CAUSE_VALUE_FALLBACK_TO_GTPV1 = 108, - GTPC_CAUSE_VALUE_INVALID_PEER = 109, - GTPC_CAUSE_VALUE_TEMPORARILY_REJECTED_DUE_TO_HANDOVER_PROCEDURE_IN_PROGRESS = 110, - GTPC_CAUSE_VALUE_MODIFICATIONS_NOT_LIMITED_TO_S1_U_BEARERS = 111, - GTPC_CAUSE_VALUE_REQUEST_REJECTED_FOR_A_PMIPV6_REASON = 112, - GTPC_CAUSE_VALUE_APN_CONGESTION = 113, - GTPC_CAUSE_VALUE_BEARER_HANDLING_NOT_SUPPORTED = 114, - GTPC_CAUSE_VALUE_UE_ALREADY_RE_ATTACHED = 115, - GTPC_CAUSE_VALUE_MULTIPLE_PDN_CONNECTIONS_FOR_A_GIVEN_APN_NOT_ALLOWED = 116 - //117-239 Spare. For future use in a triggered/response message. - //240-255 Spare. For future use in an initial/request message. + GTPC_CAUSE_VALUE_DATA_FORWARDING_NOT_SUPPORTED = 106, + GTPC_CAUSE_VALUE_INVALID_REPLY_FROM_REMOTE_PEER = 107, + GTPC_CAUSE_VALUE_FALLBACK_TO_GTPV1 = 108, + GTPC_CAUSE_VALUE_INVALID_PEER = 109, + GTPC_CAUSE_VALUE_TEMPORARILY_REJECTED_DUE_TO_HANDOVER_PROCEDURE_IN_PROGRESS = 110, + GTPC_CAUSE_VALUE_MODIFICATIONS_NOT_LIMITED_TO_S1_U_BEARERS = 111, + GTPC_CAUSE_VALUE_REQUEST_REJECTED_FOR_A_PMIPV6_REASON = 112, + GTPC_CAUSE_VALUE_APN_CONGESTION = 113, + GTPC_CAUSE_VALUE_BEARER_HANDLING_NOT_SUPPORTED = 114, + GTPC_CAUSE_VALUE_UE_ALREADY_RE_ATTACHED = 115, + GTPC_CAUSE_VALUE_MULTIPLE_PDN_CONNECTIONS_FOR_A_GIVEN_APN_NOT_ALLOWED = 116 + // 117-239 Spare. For future use in a triggered/response message. + // 240-255 Spare. For future use in an initial/request message. }; -struct gtpc_cause_ie -{ +struct gtpc_cause_ie { enum gtpc_cause_value cause_value; - bool pce; - bool bce; - bool cs; - enum gtpc_ie_type offending_ie_type; - uint16_t length_of_offending_ie; - uint8_t offending_ie_instance; + bool pce; + bool bce; + bool cs; + enum gtpc_ie_type offending_ie_type; + uint16_t length_of_offending_ie; + uint8_t offending_ie_instance; }; /**************************************************************************** @@ -274,8 +270,7 @@ struct gtpc_cause_ie * Ref: 3GPP TS 29.274 v10.14.0 Table 8.7-1 * ***************************************************************************/ -struct gtpc_ambr_ie -{ +struct gtpc_ambr_ie { uint32_t apn_ambr_uplink; uint32_t apn_ambr_downlink; }; @@ -301,9 +296,9 @@ struct gtpc_ambr_ie * and IPv6 addresses. */ -//TODO -//TODO IEs between 8.10 and 8.13 missing -//TODO +// TODO +// TODO IEs between 8.10 and 8.13 missing +// TODO /**************************************************************************** * @@ -311,20 +306,14 @@ struct gtpc_ambr_ie * Ref: 3GPP TS 29.274 v10.14.0 Figure 8.14-1 * ***************************************************************************/ -enum gtpc_pdn_type -{ - GTPC_PDN_TYPE_IPV4 = 1, - GTPC_PDN_TYPE_IPV6 = 2, - GTPC_PDN_TYPE_IPV4V6 = 3 -}; +enum gtpc_pdn_type { GTPC_PDN_TYPE_IPV4 = 1, GTPC_PDN_TYPE_IPV6 = 2, GTPC_PDN_TYPE_IPV4V6 = 3 }; -struct gtpc_pdn_address_allocation_ie -{ +struct gtpc_pdn_address_allocation_ie { enum gtpc_pdn_type pdn_type; - bool ipv4_present; - bool ipv6_present; - in_addr_t ipv4; - struct in6_addr ipv6; + bool ipv4_present; + bool ipv6_present; + in_addr_t ipv4; + struct in6_addr ipv6; }; /**************************************************************************** @@ -333,8 +322,7 @@ struct gtpc_pdn_address_allocation_ie * Ref: 3GPP TS 29.274 v10.14.0 Figure 8.15-1 * ***************************************************************************/ -struct gtpc_bearer_qos_ie -{ +struct gtpc_bearer_qos_ie { struct { uint8_t pvi : 1; uint8_t spare : 1; @@ -349,9 +337,9 @@ struct gtpc_bearer_qos_ie uint8_t gbr_dl; }; -//TODO -//TODO IEs between 8.16 and 8.17 missing -//TODO +// TODO +// TODO IEs between 8.16 and 8.17 missing +// TODO /**************************************************************************** * @@ -360,20 +348,11 @@ struct gtpc_bearer_qos_ie * ***************************************************************************/ -enum gtpc_rat_type -{ - UTRAN = 1, - GERAN, - WLAN, - GAN, - HSPA_EVOLUTION, - EUTRAN, - Virtual -}; +enum gtpc_rat_type { UTRAN = 1, GERAN, WLAN, GAN, HSPA_EVOLUTION, EUTRAN, Virtual }; -//TODO -//TODO IEs between 8.17 and 8.22 missing -//TODO +// TODO +// TODO IEs between 8.17 and 8.22 missing +// TODO /**************************************************************************** * @@ -381,8 +360,7 @@ enum gtpc_rat_type * Ref: 3GPP TS 29.274 v10.14.0 Figure 8.22-1 * ***************************************************************************/ -enum gtpc_interface_type -{ +enum gtpc_interface_type { S1_U_ENODEB_GTP_U_INTERFACE, S1_U_SGW_GTP_U_INTERFACE, S12_RNC_GTP_U_INTERFACE, @@ -391,8 +369,10 @@ enum gtpc_interface_type S5_S8_PGW_GTP_U_INTERFACE, S5_S8_SGW_GTP_C_INTERFACE, S5_S8_PGW_GTP_C_INTERFACE, - S5_S8_SGW_PMIPV6_INTERFACE, //(the 32 bit GRE key is encoded in 32 bit TEID field and since alternate CoA is not used the control plane and user plane addresses are the same for PMIPv6) - S5_S8_PGW_PMIPV6_INTERFACE, //(the 32 bit GRE key is encoded in 32 bit TEID field and the control plane and user plane addresses are the same for PMIPv6) + S5_S8_SGW_PMIPV6_INTERFACE, //(the 32 bit GRE key is encoded in 32 bit TEID field and since alternate CoA is not used + // the control plane and user plane addresses are the same for PMIPv6) + S5_S8_PGW_PMIPV6_INTERFACE, //(the 32 bit GRE key is encoded in 32 bit TEID field and the control plane and user plane + // addresses are the same for PMIPv6) S11_MME_GTP_C_INTERFACE, S11_S4_SGW_GTP_C_INTERFACE, S10_MME_GTP_C_INTERFACE, @@ -419,20 +399,18 @@ enum gtpc_interface_type S2B_U_PGW_GTP_U_INTERFACE }; - -typedef struct gtpc_f_teid_ie -{ - bool ipv4_present; - bool ipv6_present; +typedef struct gtpc_f_teid_ie { + bool ipv4_present; + bool ipv6_present; enum gtpc_interface_type interface_type; - uint32_t teid; - in_addr_t ipv4; - struct in6_addr ipv6; //FIXME + uint32_t teid; + in_addr_t ipv4; + struct in6_addr ipv6; // FIXME } gtp_fteid_t; -//TODO -//TODO IEs between 8.22 and 8.28 missing -//TODO +// TODO +// TODO IEs between 8.22 and 8.28 missing +// TODO /**************************************************************************** * @@ -440,9 +418,9 @@ typedef struct gtpc_f_teid_ie * Ref: 3GPP TS 29.274 v10.14.0 Table 8.28-1 * ***************************************************************************/ -//The usage of this grouped IE is specific to the GTP-C message being sent. -//As such, each GTP-C message will define it's bearer context structures -//locally, according to the rules of TS 29.274 v10.14.0 Section 7. +// The usage of this grouped IE is specific to the GTP-C message being sent. +// As such, each GTP-C message will define it's bearer context structures +// locally, according to the rules of TS 29.274 v10.14.0 Section 7. -} //namespace +} // namespace srslte #endif // SRSLTE_GTPC_IES_H diff --git a/lib/include/srslte/asn1/gtpc_msg.h b/lib/include/srslte/asn1/gtpc_msg.h index 0ee64d9c4..22dffb389 100644 --- a/lib/include/srslte/asn1/gtpc_msg.h +++ b/lib/include/srslte/asn1/gtpc_msg.h @@ -168,7 +168,7 @@ struct gtpc_create_session_request { bool pgw_addr_present; struct gtpc_f_teid_ie pgw_addr; // C - char apn[MAX_APN_LENGTH]; // M + char apn[MAX_APN_LENGTH]; // M // bool selection_mode_present; // enum selection_mode_ selection_mode; // C/CO // bool pdn_type_present; @@ -384,11 +384,11 @@ struct gtpc_delete_session_request { }; /**************************************************************************** - * - * GTP-C v2 Delete Session Response - * Ref: 3GPP TS 29.274 v10.14.0 Table 7.2.10.1-1 - * - ***************************************************************************/ + * + * GTP-C v2 Delete Session Response + * Ref: 3GPP TS 29.274 v10.14.0 Table 7.2.10.1-1 + * + ***************************************************************************/ struct gtpc_delete_session_response { struct gtpc_cause_ie cause; // Recovery @@ -402,17 +402,16 @@ struct gtpc_delete_session_response { * Ref: 3GPP TS 29.274 v10.14.0 Table 7.2.11.1-1 * ***************************************************************************/ -struct gtpc_downlink_data_notification -{ - bool cause_present; +struct gtpc_downlink_data_notification { + bool cause_present; struct gtpc_cause_ie cause; - bool eps_bearer_id_present; - uint8_t eps_bearer_id; - bool allocation_retention_priority_present; + bool eps_bearer_id_present; + uint8_t eps_bearer_id; + bool allocation_retention_priority_present; // struct gtpc_allocation_rention_priority_ie - bool imsi_present; + bool imsi_present; uint64_t imsi; - //Private extension + // Private extension }; /**************************************************************************** @@ -421,12 +420,11 @@ struct gtpc_downlink_data_notification * Ref: 3GPP TS 29.274 v10.14.0 Table 7.2.11.2-1 * ***************************************************************************/ -struct gtpc_downlink_data_notification_acknowledge -{ +struct gtpc_downlink_data_notification_acknowledge { struct gtpc_cause_ie cause; - //Data Notification Delay - //Recovery - //Private extension + // Data Notification Delay + // Recovery + // Private extension }; /**************************************************************************** @@ -435,10 +433,9 @@ struct gtpc_downlink_data_notification_acknowledge * Ref: 3GPP TS 29.274 v10.14.0 Table 7.2.11.3-1 * ***************************************************************************/ -struct gtpc_downlink_data_notification_failure_indication -{ +struct gtpc_downlink_data_notification_failure_indication { struct gtpc_cause_ie cause; - //Private extension + // Private extension }; /**************************************************************************** diff --git a/lib/include/srslte/asn1/liblte_m2ap.h b/lib/include/srslte/asn1/liblte_m2ap.h index bf7db0eba..8c8955c19 100644 --- a/lib/include/srslte/asn1/liblte_m2ap.h +++ b/lib/include/srslte/asn1/liblte_m2ap.h @@ -383,7 +383,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_protocolie_singlecontainer(uint8_t** *******************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_M2AP_PROTOCOLEXTENSIONFIELD_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_M2AP_PROTOCOLEXTENSIONCONTAINER_STRUCT; @@ -532,7 +532,7 @@ typedef struct { *******************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_M2AP_CRITICALITYDIAGNOSTICS_IE_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_M2AP_CRITICALITYDIAGNOSTICS_IE_LIST_STRUCT; @@ -628,7 +628,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_unpack_mbmsservicearea(uint8_t** ptr, LIBLTE_M2AP_ * ProtocolIE MBMS-Service-Area-Id-List SEQUENCE *******************************************************************************/ typedef struct { - uint8_t len; + uint8_t len; LIBLTE_M2AP_MBMS_SERVICE_AREA_STRUCT buffer[32]; // Waring: Artificial limit to reduce memory footprint } LIBLTE_M2AP_MBMS_SERVICE_AREA_ID_LIST_STRUCT; @@ -664,9 +664,11 @@ typedef struct { } LIBLTE_M2AP_ENB_MBMS_CONFIGURATION_DATA_CONFIGUPDATE_ITEM_STRUCT; LIBLTE_ERROR_ENUM liblte_m2ap_pack_enbmbmsconfigurationdataconfigupdateitem( - LIBLTE_M2AP_ENB_MBMS_CONFIGURATION_DATA_CONFIGUPDATE_ITEM_STRUCT* ie, uint8_t** ptr); + LIBLTE_M2AP_ENB_MBMS_CONFIGURATION_DATA_CONFIGUPDATE_ITEM_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_m2ap_unpack_enbmbmsconfigurationdataconfigupdateitem( - uint8_t** ptr, LIBLTE_M2AP_ENB_MBMS_CONFIGURATION_DATA_CONFIGUPDATE_ITEM_STRUCT* ie); + uint8_t** ptr, + LIBLTE_M2AP_ENB_MBMS_CONFIGURATION_DATA_CONFIGUPDATE_ITEM_STRUCT* ie); /******************************************************************************* * ProtocolIE ENB-MBMS-M2AP-ID INTEGER @@ -761,9 +763,11 @@ typedef struct { } LIBLTE_M2AP_MBMS_SERVICE_ASSOCIATEDLOGICALM2_CONNECTIONITEM_STRUCT; LIBLTE_ERROR_ENUM liblte_m2ap_pack_mbmsserviceassociatedlogicalm2connectionitem( - LIBLTE_M2AP_MBMS_SERVICE_ASSOCIATEDLOGICALM2_CONNECTIONITEM_STRUCT* ie, uint8_t** ptr); + LIBLTE_M2AP_MBMS_SERVICE_ASSOCIATEDLOGICALM2_CONNECTIONITEM_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_m2ap_unpack_mbmsserviceassociatedlogicalm2connectionitem( - uint8_t** ptr, LIBLTE_M2AP_MBMS_SERVICE_ASSOCIATEDLOGICALM2_CONNECTIONITEM_STRUCT* ie); + uint8_t** ptr, + LIBLTE_M2AP_MBMS_SERVICE_ASSOCIATEDLOGICALM2_CONNECTIONITEM_STRUCT* ie); /******************************************************************************* * ProtocolIE MBMS-Session-Id STATIC OCTET STRING @@ -1001,9 +1005,11 @@ typedef struct { } LIBLTE_M2AP_MCCH_RELATED_BCCH_CONFIG_PER_MBSFN_AREA_ITEM_STRUCT; LIBLTE_ERROR_ENUM liblte_m2ap_pack_mcchrelatedbcchconfigpermbsfnareaitem( - LIBLTE_M2AP_MCCH_RELATED_BCCH_CONFIG_PER_MBSFN_AREA_ITEM_STRUCT* ie, uint8_t** ptr); + LIBLTE_M2AP_MCCH_RELATED_BCCH_CONFIG_PER_MBSFN_AREA_ITEM_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_m2ap_unpack_mcchrelatedbcchconfigpermbsfnareaitem( - uint8_t** ptr, LIBLTE_M2AP_MCCH_RELATED_BCCH_CONFIG_PER_MBSFN_AREA_ITEM_STRUCT* ie); + uint8_t** ptr, + LIBLTE_M2AP_MCCH_RELATED_BCCH_CONFIG_PER_MBSFN_AREA_ITEM_STRUCT* ie); /******************************************************************************* * ProtocolIE MCCHrelatedBCCH-ConfigPerMBSFNArea DYNAMIC SEQUENCE @@ -1200,7 +1206,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_unpack_tnlinformation(uint8_t** ptr, LIBLTE_M2AP_T *******************************************************************************/ // lb:1;ub:maxnofCells (256) typedef struct { - uint8_t len; + uint8_t len; LIBLTE_M2AP_ENB_MBMS_CONFIGURATION_DATA_ITEM_STRUCT buffer[32]; // Waring: Artificial limit to reduce memory footprint } LIBLTE_M2AP_ENB_MBMS_CONFIGURATION_DATA_LIST_STRUCT; @@ -1229,7 +1235,7 @@ LIBLTE_ERROR_ENUM liblte_m2ap_unpack_mbsfnareaconfigurationitem(uint8_t** *******************************************************************************/ // lb:1;ub:maxnofCells (256) typedef struct { - uint8_t len; + uint8_t len; LIBLTE_M2AP_MBSFN_AREA_CONFIGURATION_ITEM_STRUCT buffer[32]; // Waring: Artificial limit to reduce memory footprint } LIBLTE_M2AP_MBSFN_AREA_CONFIGURATION_LIST_STRUCT; diff --git a/lib/include/srslte/asn1/liblte_mme.h b/lib/include/srslte/asn1/liblte_mme.h index abf275a16..70b3e813a 100644 --- a/lib/include/srslte/asn1/liblte_mme.h +++ b/lib/include/srslte/asn1/liblte_mme.h @@ -97,11 +97,12 @@ typedef enum { LIBLTE_MME_DEVICE_PROPERTIES_N_ITEMS, } LIBLTE_MME_DEVICE_PROPERTIES_ENUM; static const char liblte_mme_device_properties_text[LIBLTE_MME_DEVICE_PROPERTIES_N_ITEMS][50] = { - "Not configured for low priority", "Configured for low priority"}; + "Not configured for low priority", + "Configured for low priority"}; // Structs // Functions LIBLTE_ERROR_ENUM - liblte_mme_pack_device_properties_ie(LIBLTE_MME_DEVICE_PROPERTIES_ENUM device_props, uint8 bit_offset, uint8** ie_ptr); +liblte_mme_pack_device_properties_ie(LIBLTE_MME_DEVICE_PROPERTIES_ENUM device_props, uint8 bit_offset, uint8** ie_ptr); LIBLTE_ERROR_ENUM liblte_mme_unpack_device_properties_ie(uint8** ie_ptr, uint8 bit_offset, LIBLTE_MME_DEVICE_PROPERTIES_ENUM* device_props); @@ -194,8 +195,10 @@ typedef enum { LIBLTE_MME_REVISION_LEVEL_RESERVED, LIBLTE_MME_REVISION_LEVEL_N_ITEMS, } LIBLTE_MME_REVISION_LEVEL_ENUM; -static const char liblte_mme_revision_level_text[LIBLTE_MME_REVISION_LEVEL_N_ITEMS][20] = { - "GSM Phase 1", "GSM Phase 2", "R99", "RESERVED"}; +static const char liblte_mme_revision_level_text[LIBLTE_MME_REVISION_LEVEL_N_ITEMS][20] = {"GSM Phase 1", + "GSM Phase 2", + "R99", + "RESERVED"}; typedef enum { LIBLTE_MME_RF_POWER_CAPABILITY_CLASS_1 = 0, LIBLTE_MME_RF_POWER_CAPABILITY_CLASS_2, @@ -204,8 +207,11 @@ typedef enum { LIBLTE_MME_RF_POWER_CAPABILITY_CLASS_5, LIBLTE_MME_RF_POWER_CAPABILITY_N_ITEMS, } LIBLTE_MME_RF_POWER_CAPABILITY_ENUM; -static const char liblte_mme_rf_power_capability_text[LIBLTE_MME_RF_POWER_CAPABILITY_N_ITEMS][20] = { - "Class 1", "Class 2", "Class 3", "Class 4", "Class 5"}; +static const char liblte_mme_rf_power_capability_text[LIBLTE_MME_RF_POWER_CAPABILITY_N_ITEMS][20] = {"Class 1", + "Class 2", + "Class 3", + "Class 4", + "Class 5"}; typedef enum { LIBLTE_MME_SS_SCREEN_INDICATOR_0 = 0, LIBLTE_MME_SS_SCREEN_INDICATOR_1, @@ -213,8 +219,8 @@ typedef enum { LIBLTE_MME_SS_SCREEN_INDICATOR_3, LIBLTE_MME_SS_SCREEN_INDICATOR_N_ITEMS, } LIBLTE_MME_SS_SCREEN_INDICATOR_ENUM; -static const char liblte_mme_ss_screen_indicator_text[LIBLTE_MME_SS_SCREEN_INDICATOR_N_ITEMS][100] = { - "Default Phase 1", "Ellipsis Notation Phase 2", "RESERVED", "RESERVED"}; +static const char liblte_mme_ss_screen_indicator_text[LIBLTE_MME_SS_SCREEN_INDICATOR_N_ITEMS][100] = + {"Default Phase 1", "Ellipsis Notation Phase 2", "RESERVED", "RESERVED"}; // Structs typedef struct { LIBLTE_MME_REVISION_LEVEL_ENUM rev_lev; @@ -300,8 +306,8 @@ typedef enum { LIBLTE_MME_TYPE_OF_INTEGRITY_ALGORITHM_EIA7, LIBLTE_MME_TYPE_OF_INTEGRITY_ALGORITHM_N_ITEMS, } LIBLTE_MME_TYPE_OF_INTEGRITY_ALGORITHM_ENUM; -static const char liblte_mme_type_of_integrity_algorithm_text[LIBLTE_MME_TYPE_OF_INTEGRITY_ALGORITHM_N_ITEMS][20] = { - "EIA0", "128-EIA1", "128-EIA2", "EIA3", "EIA4", "EIA5", "EIA6", "EIA7"}; +static const char liblte_mme_type_of_integrity_algorithm_text[LIBLTE_MME_TYPE_OF_INTEGRITY_ALGORITHM_N_ITEMS][20] = + {"EIA0", "128-EIA1", "128-EIA2", "EIA3", "EIA4", "EIA5", "EIA6", "EIA7"}; typedef enum { LIBLTE_MME_TYPE_OF_CIPHERING_ALGORITHM_EEA0 = 0, LIBLTE_MME_TYPE_OF_CIPHERING_ALGORITHM_128_EEA1, @@ -313,8 +319,8 @@ typedef enum { LIBLTE_MME_TYPE_OF_CIPHERING_ALGORITHM_EEA7, LIBLTE_MME_TYPE_OF_CIPHERING_ALGORITHM_N_ITEMS, } LIBLTE_MME_TYPE_OF_CIPHERING_ALGORITHM_ENUM; -static const char liblte_mme_type_of_ciphering_algorithm_text[LIBLTE_MME_TYPE_OF_CIPHERING_ALGORITHM_N_ITEMS][20] = { - "EEA0", "128-EEA1", "128-EEA2", "EEA3", "EEA4", "EEA5", "EEA6", "EEA7"}; +static const char liblte_mme_type_of_ciphering_algorithm_text[LIBLTE_MME_TYPE_OF_CIPHERING_ALGORITHM_N_ITEMS][20] = + {"EEA0", "128-EEA1", "128-EEA2", "EEA3", "EEA4", "EEA5", "EEA6", "EEA7"}; typedef enum { LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE = 0, LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_MAPPED, @@ -418,8 +424,8 @@ typedef enum { LIBLTE_MME_ADDITIONAL_UPDATE_RESULT_RESERVED, LIBLTE_MME_ADDITIONAL_UPDATE_RESULT_N_ITEMS, } LIBLTE_MME_ADDITIONAL_UPDATE_RESULT_ENUM; -static const char liblte_mme_additional_update_result_text[LIBLTE_MME_ADDITIONAL_UPDATE_RESULT_N_ITEMS][100] = { - "No Additional Information", "CS Fallback Not Preferred", "SMS Only", "RESERVED"}; +static const char liblte_mme_additional_update_result_text[LIBLTE_MME_ADDITIONAL_UPDATE_RESULT_N_ITEMS][100] = + {"No Additional Information", "CS Fallback Not Preferred", "SMS Only", "RESERVED"}; // Structs // Functions LIBLTE_ERROR_ENUM liblte_mme_pack_additional_update_result_ie(LIBLTE_MME_ADDITIONAL_UPDATE_RESULT_ENUM result, @@ -446,11 +452,12 @@ typedef enum { LIBLTE_MME_ADDITIONAL_UPDATE_TYPE_N_ITEMS, } LIBLTE_MME_ADDITIONAL_UPDATE_TYPE_ENUM; static const char liblte_mme_additional_update_type_text[LIBLTE_MME_ADDITIONAL_UPDATE_TYPE_N_ITEMS][20] = { - "No additional info", "SMS Only"}; + "No additional info", + "SMS Only"}; // Structs // Functions LIBLTE_ERROR_ENUM - liblte_mme_pack_additional_update_type_ie(LIBLTE_MME_ADDITIONAL_UPDATE_TYPE_ENUM aut, uint8 bit_offset, uint8** ie_ptr); +liblte_mme_pack_additional_update_type_ie(LIBLTE_MME_ADDITIONAL_UPDATE_TYPE_ENUM aut, uint8 bit_offset, uint8** ie_ptr); LIBLTE_ERROR_ENUM liblte_mme_unpack_additional_update_type_ie(uint8** ie_ptr, uint8 bit_offset, LIBLTE_MME_ADDITIONAL_UPDATE_TYPE_ENUM* aut); @@ -575,8 +582,10 @@ typedef enum { LIBLTE_MME_DAYLIGHT_SAVING_TIME_RESERVED, LIBLTE_MME_DAYLIGHT_SAVING_TIME_N_ITEMS, } LIBLTE_MME_DAYLIGHT_SAVING_TIME_ENUM; -static const char liblte_mme_daylight_saving_time_text[LIBLTE_MME_DAYLIGHT_SAVING_TIME_N_ITEMS][20] = { - "No Adjustment", "+1 Hour", "+2 Hours", "RESERVED"}; +static const char liblte_mme_daylight_saving_time_text[LIBLTE_MME_DAYLIGHT_SAVING_TIME_N_ITEMS][20] = {"No Adjustment", + "+1 Hour", + "+2 Hours", + "RESERVED"}; // Structs // Functions LIBLTE_ERROR_ENUM liblte_mme_pack_daylight_saving_time_ie(LIBLTE_MME_DAYLIGHT_SAVING_TIME_ENUM dst, uint8** ie_ptr); @@ -781,8 +790,10 @@ typedef enum { LIBLTE_MME_CS_LCS_RESERVED, LIBLTE_MME_CS_LCS_N_ITEMS, } LIBLTE_MME_CS_LCS_ENUM; -static const char liblte_mme_cs_lcs_text[LIBLTE_MME_CS_LCS_N_ITEMS][100] = { - "No Information Available", "Not Supported", "Supported", "RESERVED"}; +static const char liblte_mme_cs_lcs_text[LIBLTE_MME_CS_LCS_N_ITEMS][100] = {"No Information Available", + "Not Supported", + "Supported", + "RESERVED"}; // Structs typedef struct { LIBLTE_MME_CS_LCS_ENUM cs_lcs; @@ -834,8 +845,8 @@ typedef enum { LIBLTE_MME_EPS_UPDATE_TYPE_PERIODIC_UPDATING, LIBLTE_MME_EPS_UPDATE_TYPE_N_ITEMS, } LIBLTE_MME_EPS_UPDATE_TYPE_ENUM; -static const char liblte_mme_eps_update_type_text[LIBLTE_MME_EPS_UPDATE_TYPE_N_ITEMS][100] = { - "TA Updating", "Combined TA/LA Updating", "Combined TA/LA Updating With IMSI Attach", "Periodic Updating"}; +static const char liblte_mme_eps_update_type_text[LIBLTE_MME_EPS_UPDATE_TYPE_N_ITEMS][100] = + {"TA Updating", "Combined TA/LA Updating", "Combined TA/LA Updating With IMSI Attach", "Periodic Updating"}; // Structs typedef struct { LIBLTE_MME_EPS_UPDATE_TYPE_ENUM type; @@ -1013,8 +1024,8 @@ typedef enum { LIBLTE_MME_SS_SCREENING_INDICATOR_RESERVED_2, LIBLTE_MME_SS_SCREENING_INDICATOR_N_ITEMS, } LIBLTE_MME_SS_SCREENING_INDICATOR_ENUM; -static const char liblte_mme_ss_screening_indicator_text[LIBLTE_MME_SS_SCREENING_INDICATOR_N_ITEMS][20] = { - "Phase 1", "Phase 2", "Reserved 1", "Reserved 2"}; +static const char liblte_mme_ss_screening_indicator_text[LIBLTE_MME_SS_SCREENING_INDICATOR_N_ITEMS][20] = + {"Phase 1", "Phase 2", "Reserved 1", "Reserved 2"}; // Structs typedef struct { LIBLTE_MME_SS_SCREENING_INDICATOR_ENUM ss_screening; @@ -1306,9 +1317,10 @@ typedef enum { LIBLTE_MME_TRACKING_AREA_IDENTITY_LIST_TYPE_DIFFERENT_PLMNS, LIBLTE_MME_TRACKING_AREA_IDENTITY_LIST_TYPE_N_ITEMS, } LIBLTE_MME_TRACKING_AREA_IDENTITY_LIST_TYPE_ENUM; -static const char - liblte_mme_tracking_area_identity_list_type_text[LIBLTE_MME_TRACKING_AREA_IDENTITY_LIST_TYPE_N_ITEMS][100] = { - "One PLMN, Non-Consecutive TACs", "One PLMN, Consecutive TACs", "Different PLMNs"}; +static const char liblte_mme_tracking_area_identity_list_type_text[LIBLTE_MME_TRACKING_AREA_IDENTITY_LIST_TYPE_N_ITEMS] + [100] = {"One PLMN, Non-Consecutive TACs", + "One PLMN, Consecutive TACs", + "Different PLMNs"}; // Structs typedef struct { LIBLTE_MME_TRACKING_AREA_ID_STRUCT tai[LIBLTE_MME_TRACKING_AREA_IDENTITY_LIST_MAX_SIZE]; @@ -1569,8 +1581,10 @@ typedef enum { LIBLTE_MME_VOICE_DOMAIN_PREF_PS_PREFFERED, LIBLTE_MME_VOICE_DOMAIN_PREF_N_ITEMS, } LIBLTE_MME_VOICE_DOMAIN_PREF_ENUM; -static const char liblte_mme_voice_domain_pref_text[LIBLTE_MME_VOICE_DOMAIN_PREF_N_ITEMS][20] = { - "CS Only", "PS Only", "CS Preffered", "PS Preffered"}; +static const char liblte_mme_voice_domain_pref_text[LIBLTE_MME_VOICE_DOMAIN_PREF_N_ITEMS][20] = {"CS Only", + "PS Only", + "CS Preffered", + "PS Preffered"}; // Structs typedef struct { LIBLTE_MME_UE_USAGE_SETTING_ENUM ue_usage_setting; @@ -1578,9 +1592,11 @@ typedef struct { } LIBLTE_MME_VOICE_DOMAIN_PREF_AND_UE_USAGE_SETTING_STRUCT; // Functions LIBLTE_ERROR_ENUM liblte_mme_pack_voice_domain_pref_and_ue_usage_setting_ie( - LIBLTE_MME_VOICE_DOMAIN_PREF_AND_UE_USAGE_SETTING_STRUCT* voice_domain_pref_and_ue_usage_setting, uint8** ie_ptr); + LIBLTE_MME_VOICE_DOMAIN_PREF_AND_UE_USAGE_SETTING_STRUCT* voice_domain_pref_and_ue_usage_setting, + uint8** ie_ptr); LIBLTE_ERROR_ENUM liblte_mme_unpack_voice_domain_pref_and_ue_usage_setting_ie( - uint8** ie_ptr, LIBLTE_MME_VOICE_DOMAIN_PREF_AND_UE_USAGE_SETTING_STRUCT* voice_domain_pref_and_ue_usage_setting); + uint8** ie_ptr, + LIBLTE_MME_VOICE_DOMAIN_PREF_AND_UE_USAGE_SETTING_STRUCT* voice_domain_pref_and_ue_usage_setting); /********************************************************************* IE Name: GUTI Type @@ -1779,13 +1795,18 @@ typedef enum { LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_N_ITEMS, } LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_ENUM; static const char liblte_mme_esm_info_transfer_flag_text[LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_N_ITEMS][20] = { - "Not Required", "Required"}; + "Not Required", + "Required"}; // Structs // Functions -LIBLTE_ERROR_ENUM liblte_mme_pack_esm_info_transfer_flag_ie( - LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_ENUM esm_info_transfer_flag, uint8 bit_offset, uint8** ie_ptr); -LIBLTE_ERROR_ENUM liblte_mme_unpack_esm_info_transfer_flag_ie( - uint8** ie_ptr, uint8 bit_offset, LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_ENUM* esm_info_transfer_flag); +LIBLTE_ERROR_ENUM +liblte_mme_pack_esm_info_transfer_flag_ie(LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_ENUM esm_info_transfer_flag, + uint8 bit_offset, + uint8** ie_ptr); +LIBLTE_ERROR_ENUM +liblte_mme_unpack_esm_info_transfer_flag_ie(uint8** ie_ptr, + uint8 bit_offset, + LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_ENUM* esm_info_transfer_flag); /********************************************************************* IE Name: Linked EPS Bearer Identity @@ -2229,8 +2250,8 @@ typedef enum { LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_BIDIRECTIONAL, LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_N_ITEMS, } LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_ENUM; -static const char liblte_mme_tft_packet_filter_direction_text[LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_N_ITEMS][100] = { - "Pre Rel-7 TFT Filter", "Downlink Only", "Uplink Only", "Bidirectional"}; +static const char liblte_mme_tft_packet_filter_direction_text[LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_N_ITEMS][100] = + {"Pre Rel-7 TFT Filter", "Downlink Only", "Uplink Only", "Bidirectional"}; // Structs typedef struct { LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_ENUM dir; @@ -2895,12 +2916,13 @@ typedef struct { } LIBLTE_MME_GUTI_REALLOCATION_COMPLETE_MSG_STRUCT; // Functions LIBLTE_ERROR_ENUM - liblte_mme_pack_guti_reallocation_complete_msg(LIBLTE_MME_GUTI_REALLOCATION_COMPLETE_MSG_STRUCT* guti_realloc_complete, - uint8 sec_hdr_type, - uint32 count, - LIBLTE_BYTE_MSG_STRUCT* msg); +liblte_mme_pack_guti_reallocation_complete_msg(LIBLTE_MME_GUTI_REALLOCATION_COMPLETE_MSG_STRUCT* guti_realloc_complete, + uint8 sec_hdr_type, + uint32 count, + LIBLTE_BYTE_MSG_STRUCT* msg); LIBLTE_ERROR_ENUM liblte_mme_unpack_guti_reallocation_complete_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_GUTI_REALLOCATION_COMPLETE_MSG_STRUCT* guti_realloc_complete); + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_GUTI_REALLOCATION_COMPLETE_MSG_STRUCT* guti_realloc_complete); /********************************************************************* Message Name: Identity Request @@ -3150,7 +3172,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_tracking_area_update_complete_msg( uint32 count, LIBLTE_BYTE_MSG_STRUCT* msg); LIBLTE_ERROR_ENUM liblte_mme_unpack_tracking_area_update_complete_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_TRACKING_AREA_UPDATE_COMPLETE_MSG_STRUCT* ta_update_complete); + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_TRACKING_AREA_UPDATE_COMPLETE_MSG_STRUCT* ta_update_complete); /********************************************************************* Message Name: Tracking Area Update Reject @@ -3239,7 +3262,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_downlink_generic_nas_transport_msg( uint32 count, LIBLTE_BYTE_MSG_STRUCT* msg); LIBLTE_ERROR_ENUM liblte_mme_unpack_downlink_generic_nas_transport_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_DOWNLINK_GENERIC_NAS_TRANSPORT_MSG_STRUCT* dl_generic_nas_transport); + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_DOWNLINK_GENERIC_NAS_TRANSPORT_MSG_STRUCT* dl_generic_nas_transport); /********************************************************************* Message Name: Uplink Generic NAS Transport @@ -3265,7 +3289,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_uplink_generic_nas_transport_msg( uint32 count, LIBLTE_BYTE_MSG_STRUCT* msg); LIBLTE_ERROR_ENUM liblte_mme_unpack_uplink_generic_nas_transport_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_UPLINK_GENERIC_NAS_TRANSPORT_MSG_STRUCT* ul_generic_nas_transport); + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_UPLINK_GENERIC_NAS_TRANSPORT_MSG_STRUCT* ul_generic_nas_transport); /********************************************************************* Message Name: Activate Dedicated EPS Bearer Context Accept @@ -3489,9 +3514,11 @@ typedef struct { } LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REJECT_MSG_STRUCT; // Functions LIBLTE_ERROR_ENUM liblte_mme_pack_bearer_resource_allocation_reject_msg( - LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REJECT_MSG_STRUCT* bearer_res_alloc_rej, LIBLTE_BYTE_MSG_STRUCT* msg); + LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REJECT_MSG_STRUCT* bearer_res_alloc_rej, + LIBLTE_BYTE_MSG_STRUCT* msg); LIBLTE_ERROR_ENUM liblte_mme_unpack_bearer_resource_allocation_reject_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REJECT_MSG_STRUCT* bearer_res_alloc_rej); + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REJECT_MSG_STRUCT* bearer_res_alloc_rej); /********************************************************************* Message Name: Bearer Resource Allocation Request @@ -3518,9 +3545,11 @@ typedef struct { } LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REQUEST_MSG_STRUCT; // Functions LIBLTE_ERROR_ENUM liblte_mme_pack_bearer_resource_allocation_request_msg( - LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REQUEST_MSG_STRUCT* bearer_res_alloc_req, LIBLTE_BYTE_MSG_STRUCT* msg); + LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REQUEST_MSG_STRUCT* bearer_res_alloc_req, + LIBLTE_BYTE_MSG_STRUCT* msg); LIBLTE_ERROR_ENUM liblte_mme_unpack_bearer_resource_allocation_request_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REQUEST_MSG_STRUCT* bearer_res_alloc_req); + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REQUEST_MSG_STRUCT* bearer_res_alloc_req); /********************************************************************* Message Name: Bearer Resource Modification Reject @@ -3544,9 +3573,11 @@ typedef struct { } LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REJECT_MSG_STRUCT; // Functions LIBLTE_ERROR_ENUM liblte_mme_pack_bearer_resource_modification_reject_msg( - LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REJECT_MSG_STRUCT* bearer_res_mod_rej, LIBLTE_BYTE_MSG_STRUCT* msg); + LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REJECT_MSG_STRUCT* bearer_res_mod_rej, + LIBLTE_BYTE_MSG_STRUCT* msg); LIBLTE_ERROR_ENUM liblte_mme_unpack_bearer_resource_modification_reject_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REJECT_MSG_STRUCT* bearer_res_mod_rej); + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REJECT_MSG_STRUCT* bearer_res_mod_rej); /********************************************************************* Message Name: Bearer Resource Modification Request @@ -3577,9 +3608,11 @@ typedef struct { } LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REQUEST_MSG_STRUCT; // Functions LIBLTE_ERROR_ENUM liblte_mme_pack_bearer_resource_modification_request_msg( - LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REQUEST_MSG_STRUCT* bearer_res_mod_req, LIBLTE_BYTE_MSG_STRUCT* msg); + LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REQUEST_MSG_STRUCT* bearer_res_mod_req, + LIBLTE_BYTE_MSG_STRUCT* msg); LIBLTE_ERROR_ENUM liblte_mme_unpack_bearer_resource_modification_request_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REQUEST_MSG_STRUCT* bearer_res_mod_req); + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REQUEST_MSG_STRUCT* bearer_res_mod_req); /********************************************************************* Message Name: Deactivate EPS Bearer Context Accept @@ -3744,7 +3777,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_modify_eps_bearer_context_accept_msg( uint32 count, LIBLTE_BYTE_MSG_STRUCT* msg); LIBLTE_ERROR_ENUM liblte_mme_unpack_modify_eps_bearer_context_accept_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_ACCEPT_MSG_STRUCT* mod_eps_bearer_context_accept); + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_ACCEPT_MSG_STRUCT* mod_eps_bearer_context_accept); /********************************************************************* Message Name: Modify EPS Bearer Context Reject @@ -3766,9 +3800,11 @@ typedef struct { } LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REJECT_MSG_STRUCT; // Functions LIBLTE_ERROR_ENUM liblte_mme_pack_modify_eps_bearer_context_reject_msg( - LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REJECT_MSG_STRUCT* mod_eps_bearer_context_rej, LIBLTE_BYTE_MSG_STRUCT* msg); + LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REJECT_MSG_STRUCT* mod_eps_bearer_context_rej, + LIBLTE_BYTE_MSG_STRUCT* msg); LIBLTE_ERROR_ENUM liblte_mme_unpack_modify_eps_bearer_context_reject_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REJECT_MSG_STRUCT* mod_eps_bearer_context_rej); + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REJECT_MSG_STRUCT* mod_eps_bearer_context_rej); /********************************************************************* Message Name: Modify EPS Bearer Context Request @@ -3805,9 +3841,11 @@ typedef struct { } LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT; // Functions LIBLTE_ERROR_ENUM liblte_mme_pack_modify_eps_bearer_context_request_msg( - LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT* mod_eps_bearer_context_req, LIBLTE_BYTE_MSG_STRUCT* msg); + LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT* mod_eps_bearer_context_req, + LIBLTE_BYTE_MSG_STRUCT* msg); LIBLTE_ERROR_ENUM liblte_mme_unpack_modify_eps_bearer_context_request_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT* mod_eps_bearer_context_req); + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT* mod_eps_bearer_context_req); /********************************************************************* Message Name: Notification diff --git a/lib/include/srslte/asn1/liblte_s1ap.h b/lib/include/srslte/asn1/liblte_s1ap.h index ce1ac04cf..8edf7b74d 100644 --- a/lib/include/srslte/asn1/liblte_s1ap.h +++ b/lib/include/srslte/asn1/liblte_s1ap.h @@ -746,7 +746,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_protocolie_fieldpair(uint8_t** ptr, LIBLTE_ ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_PROTOCOLEXTENSIONFIELD_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_PROTOCOLEXTENSIONCONTAINER_STRUCT; @@ -760,7 +760,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_protocolextensioncontainer(uint8_t** ********************************************************************************/ // lb:0, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_PROTOCOLIE_FIELDPAIR_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_PROTOCOLIE_CONTAINERPAIR_STRUCT; @@ -774,7 +774,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_protocolie_containerpair(uint8_t** ********************************************************************************/ // lb:None, ub:None typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_PROTOCOLIE_CONTAINERPAIR_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_PROTOCOLIE_CONTAINERPAIRLIST_STRUCT; @@ -814,7 +814,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_protocolie_singlecontainer(uint8_t** ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_PRIVATEIE_FIELD_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_PRIVATEIE_CONTAINER_STRUCT; @@ -1921,9 +1921,11 @@ typedef struct { } LIBLTE_S1AP_SOURCERNC_TOTARGETRNC_TRANSPARENTCONTAINER_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_sourcernc_totargetrnc_transparentcontainer( - LIBLTE_S1AP_SOURCERNC_TOTARGETRNC_TRANSPARENTCONTAINER_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_SOURCERNC_TOTARGETRNC_TRANSPARENTCONTAINER_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_sourcernc_totargetrnc_transparentcontainer( - uint8_t** ptr, LIBLTE_S1AP_SOURCERNC_TOTARGETRNC_TRANSPARENTCONTAINER_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_SOURCERNC_TOTARGETRNC_TRANSPARENTCONTAINER_STRUCT* ie); /******************************************************************************* /* ProtocolIE SubscriberProfileIDforRFP INTEGER @@ -1969,9 +1971,11 @@ typedef struct { } LIBLTE_S1AP_TARGETRNC_TOSOURCERNC_TRANSPARENTCONTAINER_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_targetrnc_tosourcernc_transparentcontainer( - LIBLTE_S1AP_TARGETRNC_TOSOURCERNC_TRANSPARENTCONTAINER_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_TARGETRNC_TOSOURCERNC_TRANSPARENTCONTAINER_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_targetrnc_tosourcernc_transparentcontainer( - uint8_t** ptr, LIBLTE_S1AP_TARGETRNC_TOSOURCERNC_TRANSPARENTCONTAINER_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_TARGETRNC_TOSOURCERNC_TRANSPARENTCONTAINER_STRUCT* ie); /******************************************************************************* /* ProtocolIE Threshold_RSRQ INTEGER @@ -2255,7 +2259,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_datacodingscheme(uint8_t** ptr, LIBLTE_S1AP ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_EMERGENCYAREAID_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_EMERGENCYAREAIDLIST_STRUCT; @@ -2267,7 +2271,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_emergencyareaidlist(uint8_t** ptr, LIBLTE_S ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_EMERGENCYAREAID_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_EMERGENCYAREAIDLISTFORRESTART_STRUCT; @@ -2333,7 +2337,7 @@ liblte_s1ap_unpack_eutranroundtripdelayestimationinfo(uint8_t** ********************************************************************************/ // lb:1, ub:4096 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_LAC_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_FORBIDDENLACS_STRUCT; @@ -2774,9 +2778,11 @@ typedef struct { } LIBLTE_S1AP_SOURCEBSS_TOTARGETBSS_TRANSPARENTCONTAINER_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_sourcebss_totargetbss_transparentcontainer( - LIBLTE_S1AP_SOURCEBSS_TOTARGETBSS_TRANSPARENTCONTAINER_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_SOURCEBSS_TOTARGETBSS_TRANSPARENTCONTAINER_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_sourcebss_totargetbss_transparentcontainer( - uint8_t** ptr, LIBLTE_S1AP_SOURCEBSS_TOTARGETBSS_TRANSPARENTCONTAINER_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_SOURCEBSS_TOTARGETBSS_TRANSPARENTCONTAINER_STRUCT* ie); /******************************************************************************* /* ProtocolIE SRVCCOperationPossible ENUMERATED @@ -2804,7 +2810,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_srvccoperationpossible(uint8_t** ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_MME_GROUP_ID_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_SERVEDGROUPIDS_STRUCT; @@ -2838,7 +2844,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_tac(uint8_t** ptr, LIBLTE_S1AP_TAC_STRUCT* ********************************************************************************/ // lb:1, ub:8 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TAC_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_TALISTFORMDT_STRUCT; @@ -2890,9 +2896,11 @@ typedef struct { } LIBLTE_S1AP_TIME_UE_STAYEDINCELL_ENHANCEDGRANULARITY_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_time_ue_stayedincell_enhancedgranularity( - LIBLTE_S1AP_TIME_UE_STAYEDINCELL_ENHANCEDGRANULARITY_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_TIME_UE_STAYEDINCELL_ENHANCEDGRANULARITY_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_time_ue_stayedincell_enhancedgranularity( - uint8_t** ptr, LIBLTE_S1AP_TIME_UE_STAYEDINCELL_ENHANCEDGRANULARITY_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_TIME_UE_STAYEDINCELL_ENHANCEDGRANULARITY_STRUCT* ie); /******************************************************************************* /* ProtocolIE E_UTRAN_Trace_ID STATIC OCTET STRING @@ -3021,7 +3029,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_warningsecurityinfo(uint8_t** ptr, LIBLTE_S ********************************************************************************/ // lb:1, ub:16 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TRANSPORTLAYERADDRESS_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_ENBX2GTPTLAS_STRUCT; @@ -3137,7 +3145,7 @@ liblte_s1ap_unpack_criticalitydiagnostics_ie_item(uint8_t** ptr, LIBLTE_S1AP_CRI ********************************************************************************/ // lb:1, ub:2 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TRANSPORTLAYERADDRESS_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_ENBX2TLAS_STRUCT; @@ -3161,7 +3169,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_extendedrepetitionperiod(uint8_t** ********************************************************************************/ // lb:1, ub:4096 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TAC_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_FORBIDDENTACS_STRUCT; @@ -3383,7 +3391,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_securitycontext(uint8_t** ptr, LIBLTE_S1AP_ ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_MME_CODE_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_SERVEDMMECS_STRUCT; @@ -3444,9 +3452,11 @@ typedef struct { } LIBLTE_S1AP_TARGETENB_TOSOURCEENB_TRANSPARENTCONTAINER_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_targetenb_tosourceenb_transparentcontainer( - LIBLTE_S1AP_TARGETENB_TOSOURCEENB_TRANSPARENTCONTAINER_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_TARGETENB_TOSOURCEENB_TRANSPARENTCONTAINER_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_targetenb_tosourceenb_transparentcontainer( - uint8_t** ptr, LIBLTE_S1AP_TARGETENB_TOSOURCEENB_TRANSPARENTCONTAINER_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_TARGETENB_TOSOURCEENB_TRANSPARENTCONTAINER_STRUCT* ie); /******************************************************************************* /* ProtocolIE M1ThresholdEventA2 SEQUENCE @@ -3536,7 +3546,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_enbx2exttla(uint8_t** ptr, LIBLTE_S1AP_ENBX ********************************************************************************/ // lb:1, ub:6 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TBCD_STRING_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_BPLMNS_STRUCT; @@ -3630,7 +3640,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_countvalueextended(uint8_t** ptr, LIBLTE_S1 ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_CRITICALITYDIAGNOSTICS_IE_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_CRITICALITYDIAGNOSTICS_IE_LIST_STRUCT; @@ -3658,7 +3668,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_global_enb_id(uint8_t** ptr, LIBLTE_S1AP_GL ********************************************************************************/ // lb:1, ub:15 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TBCD_STRING_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_EPLMNS_STRUCT; @@ -3754,7 +3764,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_m4configuration(uint8_t** ptr, LIBLTE_S1AP_ ********************************************************************************/ // lb:1, ub:16 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TBCD_STRING_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_MDTPLMNLIST_STRUCT; @@ -3830,7 +3840,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_prioritylevel(uint8_t** ptr, LIBLTE_S1AP_PR ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_EUTRAN_CGI_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_ECGILISTFORRESTART_STRUCT; @@ -3855,7 +3865,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_sourceenb_id(uint8_t** ptr, LIBLTE_S1AP_SOU ********************************************************************************/ // lb:1, ub:32 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TBCD_STRING_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_SERVEDPLMNS_STRUCT; @@ -3881,7 +3891,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_supportedtas_item(uint8_t** ptr, LIBLTE_S1A ********************************************************************************/ // lb:1, ub:8 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TAI_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_TAILISTFORMDT_STRUCT; @@ -3927,16 +3937,18 @@ typedef struct { } LIBLTE_S1AP_TARGETBSS_TOSOURCEBSS_TRANSPARENTCONTAINER_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_targetbss_tosourcebss_transparentcontainer( - LIBLTE_S1AP_TARGETBSS_TOSOURCEBSS_TRANSPARENTCONTAINER_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_TARGETBSS_TOSOURCEBSS_TRANSPARENTCONTAINER_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_targetbss_tosourcebss_transparentcontainer( - uint8_t** ptr, LIBLTE_S1AP_TARGETBSS_TOSOURCEBSS_TRANSPARENTCONTAINER_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_TARGETBSS_TOSOURCEBSS_TRANSPARENTCONTAINER_STRUCT* ie); /******************************************************************************* /* ProtocolIE TAIListForRestart DYNAMIC SEQUENCE OF ********************************************************************************/ // lb:1, ub:2048 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TAI_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_TAILISTFORRESTART_STRUCT; @@ -3964,7 +3976,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_userlocationinformation(uint8_t** ********************************************************************************/ // lb:1, ub:16 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_ENBX2EXTTLA_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_ENBX2EXTTLAS_STRUCT; @@ -4052,7 +4064,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_cellid_cancelled_item(uint8_t** ptr, LIBLTE ********************************************************************************/ // lb:1, ub:32 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_EUTRAN_CGI_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_CELLIDLISTFORMDT_STRUCT; @@ -4128,7 +4140,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_completedcellineai_item(uint8_t** ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABINFORMATIONLISTITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABINFORMATIONLIST_STRUCT; @@ -4140,7 +4152,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_e_rabinformationlist(uint8_t** ptr, LIBLTE_ ********************************************************************************/ // lb:1, ub:16 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_FORBIDDENTAS_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_FORBIDDENTAS_STRUCT; @@ -4254,7 +4266,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_s_tmsi(uint8_t** ptr, LIBLTE_S1AP_S_TMSI_ST ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TAI_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_TAILISTFORWARNING_STRUCT; @@ -4266,7 +4278,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_tailistforwarning(uint8_t** ptr, LIBLTE_S1A ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_COMPLETEDCELLINTAI_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_COMPLETEDCELLINTAI_STRUCT; @@ -4364,7 +4376,7 @@ liblte_s1ap_unpack_bearers_subjecttostatustransfer_item(uint8_t** ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_CANCELLEDCELLINEAI_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_CANCELLEDCELLINEAI_STRUCT; @@ -4376,7 +4388,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_cancelledcellineai(uint8_t** ptr, LIBLTE_S1 ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_CELLID_BROADCAST_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_CELLID_BROADCAST_STRUCT; @@ -4401,7 +4413,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_cellbasedmdt(uint8_t** ptr, LIBLTE_S1AP_CEL ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_CSG_IDLIST_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_CSG_IDLIST_STRUCT; @@ -4413,7 +4425,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_csg_idlist(uint8_t** ptr, LIBLTE_S1AP_CSG_I ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_EUTRAN_CGI_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_ECGILIST_STRUCT; @@ -4456,7 +4468,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_geran_cell_id(uint8_t** ptr, LIBLTE_S1AP_GE ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABLIST_STRUCT; @@ -4468,7 +4480,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_e_rablist(uint8_t** ptr, LIBLTE_S1AP_E_RABL ********************************************************************************/ // lb:1, ub:16 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_FORBIDDENLAS_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_FORBIDDENLAS_STRUCT; @@ -4547,7 +4559,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_rimroutingaddress(uint8_t** ptr, LIBLTE_S1A ********************************************************************************/ // lb:1, ub:8 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_SERVEDGUMMEISITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_SERVEDGUMMEIS_STRUCT; @@ -4681,7 +4693,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_areascopeofmdt(uint8_t** ptr, LIBLTE_S1AP_A ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_CANCELLEDCELLINTAI_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_CANCELLEDCELLINTAI_STRUCT; @@ -4706,7 +4718,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_celltype(uint8_t** ptr, LIBLTE_S1AP_CELLTYP ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_EMERGENCYAREAID_CANCELLED_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_EMERGENCYAREAID_CANCELLED_STRUCT; @@ -4720,7 +4732,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_emergencyareaid_cancelled(uint8_t** ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_GUMMEI_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_GUMMEILIST_STRUCT; @@ -4784,7 +4796,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_rimtransfer(uint8_t** ptr, LIBLTE_S1AP_RIMT ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_SUPPORTEDTAS_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_SUPPORTEDTAS_STRUCT; @@ -4826,7 +4838,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_x2tnlconfigurationinfo(uint8_t** typedef struct { uint32_t len; LIBLTE_S1AP_BEARERS_SUBJECTTOSTATUSTRANSFER_ITEM_STRUCT - buffer[32]; // WARNING: Artificial limit to reduce memory footprint + buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_BEARERS_SUBJECTTOSTATUSTRANSFERLIST_STRUCT; LIBLTE_ERROR_ENUM @@ -4841,7 +4853,7 @@ liblte_s1ap_unpack_bearers_subjecttostatustransferlist(uint8_t** ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_CELLID_CANCELLED_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_CELLID_CANCELLED_STRUCT; @@ -4853,7 +4865,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_cellid_cancelled(uint8_t** ptr, LIBLTE_S1AP ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_COMPLETEDCELLINEAI_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_COMPLETEDCELLINEAI_STRUCT; @@ -4932,7 +4944,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_soninformationreply(uint8_t** ptr, LIBLTE_S ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TAI_BROADCAST_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_TAI_BROADCAST_STRUCT; @@ -5080,16 +5092,18 @@ typedef struct { } LIBLTE_S1AP_SOURCEENB_TOTARGETENB_TRANSPARENTCONTAINER_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_sourceenb_totargetenb_transparentcontainer( - LIBLTE_S1AP_SOURCEENB_TOTARGETENB_TRANSPARENTCONTAINER_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_SOURCEENB_TOTARGETENB_TRANSPARENTCONTAINER_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_sourceenb_totargetenb_transparentcontainer( - uint8_t** ptr, LIBLTE_S1AP_SOURCEENB_TOTARGETENB_TRANSPARENTCONTAINER_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_SOURCEENB_TOTARGETENB_TRANSPARENTCONTAINER_STRUCT* ie); /******************************************************************************* /* ProtocolIE EmergencyAreaID_Broadcast DYNAMIC SEQUENCE OF ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_EMERGENCYAREAID_BROADCAST_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_EMERGENCYAREAID_BROADCAST_STRUCT; @@ -5118,7 +5132,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_mdt_configuration(uint8_t** ptr, LIBLTE_S1A ********************************************************************************/ // lb:1, ub:65535 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TAI_CANCELLED_ITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_TAI_CANCELLED_STRUCT; @@ -5169,10 +5183,11 @@ typedef struct { } LIBLTE_S1AP_ENB_STATUSTRANSFER_TRANSPARENTCONTAINER_STRUCT; LIBLTE_ERROR_ENUM - liblte_s1ap_pack_enb_statustransfer_transparentcontainer(LIBLTE_S1AP_ENB_STATUSTRANSFER_TRANSPARENTCONTAINER_STRUCT* ie, - uint8_t** ptr); +liblte_s1ap_pack_enb_statustransfer_transparentcontainer(LIBLTE_S1AP_ENB_STATUSTRANSFER_TRANSPARENTCONTAINER_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_enb_statustransfer_transparentcontainer( - uint8_t** ptr, LIBLTE_S1AP_ENB_STATUSTRANSFER_TRANSPARENTCONTAINER_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_ENB_STATUSTRANSFER_TRANSPARENTCONTAINER_STRUCT* ie); /******************************************************************************* /* ProtocolIE TraceActivation SEQUENCE @@ -5320,7 +5335,7 @@ liblte_s1ap_unpack_inter_systeminformationtransfertype(uint8_t** ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_PROTOCOLIE_CONTAINERPAIR_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RAB_IE_CONTAINERPAIRLIST_STRUCT; @@ -5585,13 +5600,15 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_taiitem(uint8_t** ptr, LIBLTE_S1AP_TAIITEM_ typedef struct { uint32_t len; LIBLTE_S1AP_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEM_STRUCT - buffer[32]; // WARNING: Artificial limit to reduce memory footprint + buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_UE_ASSOCIATEDLOGICALS1_CONNECTIONLISTRES_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_ue_associatedlogicals1_connectionlistres( - LIBLTE_S1AP_UE_ASSOCIATEDLOGICALS1_CONNECTIONLISTRES_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_UE_ASSOCIATEDLOGICALS1_CONNECTIONLISTRES_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_ue_associatedlogicals1_connectionlistres( - uint8_t** ptr, LIBLTE_S1AP_UE_ASSOCIATEDLOGICALS1_CONNECTIONLISTRES_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_UE_ASSOCIATEDLOGICALS1_CONNECTIONLISTRES_STRUCT* ie); /******************************************************************************* /* Protocol Container List UE_associatedLogicalS1_ConnectionListResAck DYNAMIC SEQUENCE OF @@ -5600,13 +5617,15 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_ue_associatedlogicals1_connectionlistres( typedef struct { uint32_t len; LIBLTE_S1AP_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEM_STRUCT - buffer[32]; // WARNING: Artificial limit to reduce memory footprint + buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_UE_ASSOCIATEDLOGICALS1_CONNECTIONLISTRESACK_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_ue_associatedlogicals1_connectionlistresack( - LIBLTE_S1AP_UE_ASSOCIATEDLOGICALS1_CONNECTIONLISTRESACK_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_UE_ASSOCIATEDLOGICALS1_CONNECTIONLISTRESACK_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_ue_associatedlogicals1_connectionlistresack( - uint8_t** ptr, LIBLTE_S1AP_UE_ASSOCIATEDLOGICALS1_CONNECTIONLISTRESACK_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_UE_ASSOCIATEDLOGICALS1_CONNECTIONLISTRESACK_STRUCT* ie); /******************************************************************************* /* ProtocolIE PrivateMessage SEQUENCE @@ -5651,7 +5670,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_resettype(uint8_t** ptr, LIBLTE_S1AP_RESETT ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABDATAFORWARDINGITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABSUBJECTTODATAFORWARDINGLIST_STRUCT; @@ -5667,7 +5686,7 @@ liblte_s1ap_unpack_e_rabsubjecttodataforwardinglist(uint8_t** ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABTOBESETUPITEMHOREQ_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABTOBESETUPLISTHOREQ_STRUCT; @@ -5681,7 +5700,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_e_rabtobesetuplisthoreq(uint8_t** ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABADMITTEDITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABADMITTEDLIST_STRUCT; @@ -5693,7 +5712,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_e_rabadmittedlist(uint8_t** ptr, LIBLTE_S1A ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABTOBESWITCHEDDLITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABTOBESWITCHEDDLLIST_STRUCT; @@ -5707,7 +5726,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_e_rabtobeswitcheddllist(uint8_t** ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABTOBESWITCHEDULITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABTOBESWITCHEDULLIST_STRUCT; @@ -5721,7 +5740,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_e_rabtobeswitchedullist(uint8_t** ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABTOBESETUPITEMBEARERSUREQ_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABTOBESETUPLISTBEARERSUREQ_STRUCT; @@ -5735,7 +5754,7 @@ liblte_s1ap_unpack_e_rabtobesetuplistbearersureq(uint8_t** ptr, LIBLTE_S1AP_E_RA ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABSETUPITEMBEARERSURES_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABSETUPLISTBEARERSURES_STRUCT; @@ -5751,7 +5770,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_e_rabsetuplistbearersures(uint8_t** typedef struct { uint32_t len; LIBLTE_S1AP_E_RABTOBEMODIFIEDITEMBEARERMODREQ_STRUCT - buffer[32]; // WARNING: Artificial limit to reduce memory footprint + buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABTOBEMODIFIEDLISTBEARERMODREQ_STRUCT; LIBLTE_ERROR_ENUM @@ -5766,7 +5785,7 @@ liblte_s1ap_unpack_e_rabtobemodifiedlistbearermodreq(uint8_t** ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABMODIFYITEMBEARERMODRES_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABMODIFYLISTBEARERMODRES_STRUCT; @@ -5780,7 +5799,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_e_rabmodifylistbearermodres(uint8_t** ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABRELEASEITEMBEARERRELCOMP_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABRELEASELISTBEARERRELCOMP_STRUCT; @@ -5794,7 +5813,7 @@ liblte_s1ap_unpack_e_rabreleaselistbearerrelcomp(uint8_t** ptr, LIBLTE_S1AP_E_RA ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABTOBESETUPLISTCTXTSUREQ_STRUCT; @@ -5808,7 +5827,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_e_rabtobesetuplistctxtsureq(uint8_t** ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABSETUPITEMCTXTSURES_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABSETUPLISTCTXTSURES_STRUCT; @@ -5822,7 +5841,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_e_rabsetuplistctxtsures(uint8_t** ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_TAIITEM_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_TAILIST_STRUCT; @@ -5834,7 +5853,7 @@ LIBLTE_ERROR_ENUM liblte_s1ap_unpack_tailist(uint8_t** ptr, LIBLTE_S1AP_TAILIST_ ********************************************************************************/ // lb:1, ub:256 typedef struct { - uint32_t len; + uint32_t len; LIBLTE_S1AP_E_RABFAILEDTOSETUPITEMHOREQACK_STRUCT buffer[32]; // WARNING: Artificial limit to reduce memory footprint } LIBLTE_S1AP_E_RABFAILEDTOSETUPLISTHOREQACK_STRUCT; @@ -5851,10 +5870,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_ALLOCATIONANDRETENTIONPRIORITY_EXT_STRUCT; LIBLTE_ERROR_ENUM - liblte_s1ap_pack_allocationandretentionpriority_ext(LIBLTE_S1AP_MESSAGE_ALLOCATIONANDRETENTIONPRIORITY_EXT_STRUCT* ie, - uint8_t** ptr); +liblte_s1ap_pack_allocationandretentionpriority_ext(LIBLTE_S1AP_MESSAGE_ALLOCATIONANDRETENTIONPRIORITY_EXT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_allocationandretentionpriority_ext( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_ALLOCATIONANDRETENTIONPRIORITY_EXT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_ALLOCATIONANDRETENTIONPRIORITY_EXT_STRUCT* ie); /******************************************************************************* /* Protocol Message CancelledCellinEAI_Item_Ext STRUCT @@ -6002,10 +6022,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_CRITICALITYDIAGNOSTICS_IE_ITEM_EXT_STRUCT; LIBLTE_ERROR_ENUM - liblte_s1ap_pack_criticalitydiagnostics_ie_item_ext(LIBLTE_S1AP_MESSAGE_CRITICALITYDIAGNOSTICS_IE_ITEM_EXT_STRUCT* ie, - uint8_t** ptr); +liblte_s1ap_pack_criticalitydiagnostics_ie_item_ext(LIBLTE_S1AP_MESSAGE_CRITICALITYDIAGNOSTICS_IE_ITEM_EXT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_criticalitydiagnostics_ie_item_ext( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_CRITICALITYDIAGNOSTICS_IE_ITEM_EXT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_CRITICALITYDIAGNOSTICS_IE_ITEM_EXT_STRUCT* ie); /******************************************************************************* /* Protocol Message EmergencyAreaID_Broadcast_Item_Ext STRUCT @@ -6015,10 +6036,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_EMERGENCYAREAID_BROADCAST_ITEM_EXT_STRUCT; LIBLTE_ERROR_ENUM - liblte_s1ap_pack_emergencyareaid_broadcast_item_ext(LIBLTE_S1AP_MESSAGE_EMERGENCYAREAID_BROADCAST_ITEM_EXT_STRUCT* ie, - uint8_t** ptr); +liblte_s1ap_pack_emergencyareaid_broadcast_item_ext(LIBLTE_S1AP_MESSAGE_EMERGENCYAREAID_BROADCAST_ITEM_EXT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_emergencyareaid_broadcast_item_ext( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_EMERGENCYAREAID_BROADCAST_ITEM_EXT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_EMERGENCYAREAID_BROADCAST_ITEM_EXT_STRUCT* ie); /******************************************************************************* /* Protocol Message EmergencyAreaID_Cancelled_Item_Ext STRUCT @@ -6028,10 +6050,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_EMERGENCYAREAID_CANCELLED_ITEM_EXT_STRUCT; LIBLTE_ERROR_ENUM - liblte_s1ap_pack_emergencyareaid_cancelled_item_ext(LIBLTE_S1AP_MESSAGE_EMERGENCYAREAID_CANCELLED_ITEM_EXT_STRUCT* ie, - uint8_t** ptr); +liblte_s1ap_pack_emergencyareaid_cancelled_item_ext(LIBLTE_S1AP_MESSAGE_EMERGENCYAREAID_CANCELLED_ITEM_EXT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_emergencyareaid_cancelled_item_ext( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_EMERGENCYAREAID_CANCELLED_ITEM_EXT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_EMERGENCYAREAID_CANCELLED_ITEM_EXT_STRUCT* ie); /******************************************************************************* /* Protocol Message CompletedCellinEAI_Item_Ext STRUCT @@ -6074,9 +6097,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_ENB_STATUSTRANSFER_TRANSPARENTCONTAINER_EXT_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_enb_statustransfer_transparentcontainer_ext( - LIBLTE_S1AP_MESSAGE_ENB_STATUSTRANSFER_TRANSPARENTCONTAINER_EXT_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_MESSAGE_ENB_STATUSTRANSFER_TRANSPARENTCONTAINER_EXT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_enb_statustransfer_transparentcontainer_ext( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_ENB_STATUSTRANSFER_TRANSPARENTCONTAINER_EXT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_ENB_STATUSTRANSFER_TRANSPARENTCONTAINER_EXT_STRUCT* ie); /******************************************************************************* /* Protocol Message E_RABInformationListItem_Ext STRUCT @@ -6435,9 +6460,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_TARGETENB_TOSOURCEENB_TRANSPARENTCONTAINER_EXT_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_targetenb_tosourceenb_transparentcontainer_ext( - LIBLTE_S1AP_MESSAGE_TARGETENB_TOSOURCEENB_TRANSPARENTCONTAINER_EXT_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_MESSAGE_TARGETENB_TOSOURCEENB_TRANSPARENTCONTAINER_EXT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_targetenb_tosourceenb_transparentcontainer_ext( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_TARGETENB_TOSOURCEENB_TRANSPARENTCONTAINER_EXT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_TARGETENB_TOSOURCEENB_TRANSPARENTCONTAINER_EXT_STRUCT* ie); /******************************************************************************* /* Protocol Message M1ThresholdEventA2_Ext STRUCT @@ -6497,9 +6524,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEMEXT_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_ue_associatedlogicals1_connectionitemext( - LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEMEXT_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEMEXT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_ue_associatedlogicals1_connectionitemext( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEMEXT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEMEXT_STRUCT* ie); /******************************************************************************* /* Protocol Message UESecurityCapabilities_Ext STRUCT @@ -6546,9 +6575,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_SOURCEENB_TOTARGETENB_TRANSPARENTCONTAINER_EXT_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_sourceenb_totargetenb_transparentcontainer_ext( - LIBLTE_S1AP_MESSAGE_SOURCEENB_TOTARGETENB_TRANSPARENTCONTAINER_EXT_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_MESSAGE_SOURCEENB_TOTARGETENB_TRANSPARENTCONTAINER_EXT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_sourceenb_totargetenb_transparentcontainer_ext( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_SOURCEENB_TOTARGETENB_TRANSPARENTCONTAINER_EXT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_SOURCEENB_TOTARGETENB_TRANSPARENTCONTAINER_EXT_STRUCT* ie); /******************************************************************************* /* Protocol Message E_RABInformationList STRUCT @@ -6575,9 +6606,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_LASTVISITEDEUTRANCELLINFORMATION_EXT_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_lastvisitedeutrancellinformation_ext( - LIBLTE_S1AP_MESSAGE_LASTVISITEDEUTRANCELLINFORMATION_EXT_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_MESSAGE_LASTVISITEDEUTRANCELLINFORMATION_EXT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_lastvisitedeutrancellinformation_ext( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_LASTVISITEDEUTRANCELLINFORMATION_EXT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_LASTVISITEDEUTRANCELLINFORMATION_EXT_STRUCT* ie); /******************************************************************************* /* Protocol Message SONInformationReply_Ext STRUCT @@ -6607,9 +6640,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_BEARERS_SUBJECTTOSTATUSTRANSFER_ITEMEXT_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_bearers_subjecttostatustransfer_itemext( - LIBLTE_S1AP_MESSAGE_BEARERS_SUBJECTTOSTATUSTRANSFER_ITEMEXT_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_MESSAGE_BEARERS_SUBJECTTOSTATUSTRANSFER_ITEMEXT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_bearers_subjecttostatustransfer_itemext( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_BEARERS_SUBJECTTOSTATUSTRANSFER_ITEMEXT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_BEARERS_SUBJECTTOSTATUSTRANSFER_ITEMEXT_STRUCT* ie); /******************************************************************************* /* Protocol Message E_RABItem STRUCT @@ -6659,9 +6694,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_BEARERS_SUBJECTTOSTATUSTRANSFER_ITEM_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_bearers_subjecttostatustransfer_item( - LIBLTE_S1AP_MESSAGE_BEARERS_SUBJECTTOSTATUSTRANSFER_ITEM_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_MESSAGE_BEARERS_SUBJECTTOSTATUSTRANSFER_ITEM_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_bearers_subjecttostatustransfer_item( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_BEARERS_SUBJECTTOSTATUSTRANSFER_ITEM_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_BEARERS_SUBJECTTOSTATUSTRANSFER_ITEM_STRUCT* ie); /******************************************************************************* /* Protocol Message ImmediateMDT_Ext STRUCT @@ -6960,10 +6997,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_E_RABTOBEMODIFYITEMBEARERMODREQEXT_STRUCT; LIBLTE_ERROR_ENUM - liblte_s1ap_pack_e_rabtobemodifyitembearermodreqext(LIBLTE_S1AP_MESSAGE_E_RABTOBEMODIFYITEMBEARERMODREQEXT_STRUCT* ie, - uint8_t** ptr); +liblte_s1ap_pack_e_rabtobemodifyitembearermodreqext(LIBLTE_S1AP_MESSAGE_E_RABTOBEMODIFYITEMBEARERMODREQEXT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_e_rabtobemodifyitembearermodreqext( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_E_RABTOBEMODIFYITEMBEARERMODREQEXT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_E_RABTOBEMODIFYITEMBEARERMODREQEXT_STRUCT* ie); /******************************************************************************* /* Protocol Message E_RABModifyItemBearerModResExt STRUCT @@ -7342,9 +7380,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEM_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_ue_associatedlogicals1_connectionitem( - LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEM_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEM_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_ue_associatedlogicals1_connectionitem( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEM_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEM_STRUCT* ie); /******************************************************************************* /* Protocol Message UE_associatedLogicalS1_ConnectionItemRes STRUCT @@ -7355,9 +7395,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEMRES_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_ue_associatedlogicals1_connectionitemres( - LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEMRES_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEMRES_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_ue_associatedlogicals1_connectionitemres( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEMRES_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_UE_ASSOCIATEDLOGICALS1_CONNECTIONITEMRES_STRUCT* ie); /******************************************************************************* /* Protocol Message ErrorIndication STRUCT @@ -7686,10 +7728,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_LOCATIONREPORTINGFAILUREINDICATION_STRUCT; LIBLTE_ERROR_ENUM - liblte_s1ap_pack_locationreportingfailureindication(LIBLTE_S1AP_MESSAGE_LOCATIONREPORTINGFAILUREINDICATION_STRUCT* ie, - uint8_t** ptr); +liblte_s1ap_pack_locationreportingfailureindication(LIBLTE_S1AP_MESSAGE_LOCATIONREPORTINGFAILUREINDICATION_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_locationreportingfailureindication( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_LOCATIONREPORTINGFAILUREINDICATION_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_LOCATIONREPORTINGFAILUREINDICATION_STRUCT* ie); /******************************************************************************* /* Protocol Message LocationReport STRUCT @@ -7930,9 +7973,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_DOWNLINKNONUEASSOCIATEDLPPATRANSPORT_STRUCT; LIBLTE_ERROR_ENUM liblte_s1ap_pack_downlinknonueassociatedlppatransport( - LIBLTE_S1AP_MESSAGE_DOWNLINKNONUEASSOCIATEDLPPATRANSPORT_STRUCT* ie, uint8_t** ptr); + LIBLTE_S1AP_MESSAGE_DOWNLINKNONUEASSOCIATEDLPPATRANSPORT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_downlinknonueassociatedlppatransport( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_DOWNLINKNONUEASSOCIATEDLPPATRANSPORT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_DOWNLINKNONUEASSOCIATEDLPPATRANSPORT_STRUCT* ie); /******************************************************************************* /* Protocol Message UplinkNonUEAssociatedLPPaTransport STRUCT @@ -7944,10 +7989,11 @@ typedef struct { } LIBLTE_S1AP_MESSAGE_UPLINKNONUEASSOCIATEDLPPATRANSPORT_STRUCT; LIBLTE_ERROR_ENUM - liblte_s1ap_pack_uplinknonueassociatedlppatransport(LIBLTE_S1AP_MESSAGE_UPLINKNONUEASSOCIATEDLPPATRANSPORT_STRUCT* ie, - uint8_t** ptr); +liblte_s1ap_pack_uplinknonueassociatedlppatransport(LIBLTE_S1AP_MESSAGE_UPLINKNONUEASSOCIATEDLPPATRANSPORT_STRUCT* ie, + uint8_t** ptr); LIBLTE_ERROR_ENUM liblte_s1ap_unpack_uplinknonueassociatedlppatransport( - uint8_t** ptr, LIBLTE_S1AP_MESSAGE_UPLINKNONUEASSOCIATEDLPPATRANSPORT_STRUCT* ie); + uint8_t** ptr, + LIBLTE_S1AP_MESSAGE_UPLINKNONUEASSOCIATEDLPPATRANSPORT_STRUCT* ie); /******************************************************************************* /* Protocol Message ENBDirectInformationTransfer STRUCT diff --git a/lib/include/srslte/common/bcd_helpers.h b/lib/include/srslte/common/bcd_helpers.h index cb907827a..48e9a1854 100644 --- a/lib/include/srslte/common/bcd_helpers.h +++ b/lib/include/srslte/common/bcd_helpers.h @@ -33,25 +33,25 @@ namespace srslte { * Digits are represented by 4-bit nibbles. Unused nibbles are filled with 0xF. * MCC 001 results in 0xF001 *****************************************************************************/ -inline bool string_to_mcc(std::string str, uint16_t *mcc) +inline bool string_to_mcc(std::string str, uint16_t* mcc) { uint32_t len = (uint32_t)str.size(); - if(len != 3) { + if (len != 3) { return false; } - if(!isdigit(str[0]) || !isdigit(str[1]) || !isdigit(str[2])) { + if (!isdigit(str[0]) || !isdigit(str[1]) || !isdigit(str[2])) { return false; } *mcc = 0xF000; - *mcc |= ((uint8_t)(str[0]-'0') << 8); - *mcc |= ((uint8_t)(str[1]-'0') << 4); - *mcc |= ((uint8_t)(str[2]-'0')); + *mcc |= ((uint8_t)(str[0] - '0') << 8); + *mcc |= ((uint8_t)(str[1] - '0') << 4); + *mcc |= ((uint8_t)(str[2] - '0')); return true; } -inline bool mcc_to_string(uint16_t mcc, std::string *str) +inline bool mcc_to_string(uint16_t mcc, std::string* str) { - if((mcc & 0xF000) != 0xF000) { + if ((mcc & 0xF000) != 0xF000) { return false; } *str = ""; @@ -104,40 +104,40 @@ inline std::string mcc_bytes_to_string(uint8_t* mcc_bytes) * MNC 001 results in 0xF001 * MNC 01 results in 0xFF01 *****************************************************************************/ -inline bool string_to_mnc(std::string str, uint16_t *mnc) +inline bool string_to_mnc(std::string str, uint16_t* mnc) { uint32_t len = str.size(); - if(len != 3 && len != 2) { + if (len != 3 && len != 2) { return false; } - if(len == 3) { - if(!isdigit(str[0]) || !isdigit(str[1]) || !isdigit(str[2])) { + if (len == 3) { + if (!isdigit(str[0]) || !isdigit(str[1]) || !isdigit(str[2])) { return false; } *mnc = 0xF000; - *mnc |= ((uint8_t)(str[0]-'0') << 8); - *mnc |= ((uint8_t)(str[1]-'0') << 4); - *mnc |= ((uint8_t)(str[2]-'0')); + *mnc |= ((uint8_t)(str[0] - '0') << 8); + *mnc |= ((uint8_t)(str[1] - '0') << 4); + *mnc |= ((uint8_t)(str[2] - '0')); } - if(len == 2) { - if(!isdigit(str[0]) || !isdigit(str[1])) { + if (len == 2) { + if (!isdigit(str[0]) || !isdigit(str[1])) { return false; } *mnc = 0xFF00; - *mnc |= ((uint8_t)(str[0]-'0') << 4); - *mnc |= ((uint8_t)(str[1]-'0')); + *mnc |= ((uint8_t)(str[0] - '0') << 4); + *mnc |= ((uint8_t)(str[1] - '0')); } return true; } -inline bool mnc_to_string(uint16_t mnc, std::string *str) +inline bool mnc_to_string(uint16_t mnc, std::string* str) { - if((mnc & 0xF000) != 0xF000) { + if ((mnc & 0xF000) != 0xF000) { return false; } *str = ""; - if((mnc & 0xFF00) != 0xFF00) { + if ((mnc & 0xFF00) != 0xFF00) { *str += ((mnc & 0x0F00) >> 8) + '0'; } *str += ((mnc & 0x00F0) >> 4) + '0'; @@ -220,7 +220,7 @@ std::string mnc_bytes_to_string(Vec mnc_bytes) * MNC 01 represented as 0xFF01 * PLMN encoded as per TS 36.413 sec 9.2.3.8 *****************************************************************************/ -inline void s1ap_plmn_to_mccmnc(uint32_t plmn, uint16_t *mcc, uint16_t *mnc) +inline void s1ap_plmn_to_mccmnc(uint32_t plmn, uint16_t* mcc, uint16_t* mnc) { uint8_t nibbles[6]; nibbles[0] = (plmn & 0xF00000) >> 20; @@ -232,20 +232,20 @@ inline void s1ap_plmn_to_mccmnc(uint32_t plmn, uint16_t *mcc, uint16_t *mnc) *mcc = 0xF000; *mnc = 0xF000; - *mcc |= nibbles[1] << 8; // MCC digit 1 - *mcc |= nibbles[0] << 4; // MCC digit 2 - *mcc |= nibbles[3]; // MCC digit 3 + *mcc |= nibbles[1] << 8; // MCC digit 1 + *mcc |= nibbles[0] << 4; // MCC digit 2 + *mcc |= nibbles[3]; // MCC digit 3 - if(nibbles[2] == 0xF) { + if (nibbles[2] == 0xF) { // 2-digit MNC - *mnc |= 0x0F00; // MNC digit 1 - *mnc |= nibbles[5] << 4; // MNC digit 2 - *mnc |= nibbles[4]; // MNC digit 3 + *mnc |= 0x0F00; // MNC digit 1 + *mnc |= nibbles[5] << 4; // MNC digit 2 + *mnc |= nibbles[4]; // MNC digit 3 } else { // 3-digit MNC - *mnc |= nibbles[2] << 8; // MNC digit 1 - *mnc |= nibbles[5] << 4; // MNC digit 2 - *mnc |= nibbles[4] ; // MNC digit 3 + *mnc |= nibbles[2] << 8; // MNC digit 1 + *mnc |= nibbles[5] << 4; // MNC digit 2 + *mnc |= nibbles[4]; // MNC digit 3 } } @@ -256,14 +256,14 @@ inline void s1ap_plmn_to_mccmnc(uint32_t plmn, uint16_t *mcc, uint16_t *mnc) * MNC 01 represented as 0xFF01 * PLMN encoded as per TS 36.413 sec 9.2.3.8 *****************************************************************************/ -inline void s1ap_mccmnc_to_plmn(uint16_t mcc, uint16_t mnc, uint32_t *plmn) +inline void s1ap_mccmnc_to_plmn(uint16_t mcc, uint16_t mnc, uint32_t* plmn) { uint8_t nibbles[6]; nibbles[1] = (mcc & 0x0F00) >> 8; // MCC digit 1 nibbles[0] = (mcc & 0x00F0) >> 4; // MCC digit 2 nibbles[3] = (mcc & 0x000F); // MCC digit 3 - if((mnc & 0xFF00) == 0xFF00) { + if ((mnc & 0xFF00) == 0xFF00) { // 2-digit MNC nibbles[2] = 0x0F; // MNC digit 1 nibbles[5] = (mnc & 0x00F0) >> 4; // MNC digit 2 diff --git a/lib/include/srslte/common/block_queue.h b/lib/include/srslte/common/block_queue.h index 241ffb52a..4ca9e7bc4 100644 --- a/lib/include/srslte/common/block_queue.h +++ b/lib/include/srslte/common/block_queue.h @@ -26,28 +26,28 @@ * operations in both push and pop *****************************************************************************/ - #ifndef SRSLTE_BLOCK_QUEUE_H #define SRSLTE_BLOCK_QUEUE_H -#include #include -#include #include -#include +#include #include -#include +#include #include +#include +#include namespace srslte { -template -class block_queue { +template +class block_queue +{ public: - // Callback functions for mutexed operations inside pop/push methods - class call_mutexed_itf { + class call_mutexed_itf + { public: virtual void popping(const myobj& obj) = 0; virtual void pushing(const myobj& obj) = 0; @@ -60,10 +60,11 @@ public: pthread_cond_init(&cv_full, NULL); capacity = capacity_; mutexed_callback = NULL; - enable = true; - num_threads = 0; + enable = true; + num_threads = 0; } - ~block_queue() { + ~block_queue() + { // Unlock threads waiting at push or pop pthread_mutex_lock(&mutex); enable = false; @@ -72,10 +73,10 @@ public: pthread_mutex_unlock(&mutex); // Wait threads blocked in push/pop to exit - while(num_threads>0) { + while (num_threads > 0) { usleep(100); } - + // Wait them to exit and destroy cv and mutex pthread_mutex_lock(&mutex); pthread_cond_destroy(&cv_full); @@ -83,56 +84,48 @@ public: pthread_mutex_unlock(&mutex); pthread_mutex_destroy(&mutex); } - void set_mutexed_itf(call_mutexed_itf *itf) { - mutexed_callback = itf; - } - void resize(int new_capacity) { - capacity = new_capacity; - } + void set_mutexed_itf(call_mutexed_itf* itf) { mutexed_callback = itf; } + void resize(int new_capacity) { capacity = new_capacity; } - void push(const myobj& value) { - push_(value, true); - } + void push(const myobj& value) { push_(value, true); } void push(myobj&& value) { push_(std::move(value), true); } - bool try_push(const myobj& value) { - return push_(value, false); - } + bool try_push(const myobj& value) { return push_(value, false); } std::pair try_push(myobj&& value) { return push_(std::move(value), false); } - bool try_pop(myobj *value) { - return pop_(value, false); - } + bool try_pop(myobj* value) { return pop_(value, false); } - myobj wait_pop() { // blocking pop + myobj wait_pop() + { // blocking pop myobj value = myobj(); pop_(&value, true); return value; } - bool empty() { // queue is empty? + bool empty() + { // queue is empty? pthread_mutex_lock(&mutex); bool ret = q.empty(); pthread_mutex_unlock(&mutex); return ret; } - void clear() { // remove all items - myobj *item = NULL; - while (try_pop(item)); + void clear() + { // remove all items + myobj* item = NULL; + while (try_pop(item)) + ; } const myobj& front() const { return q.front(); } - size_t size() { - return q.size(); - } + size_t size() { return q.size(); } private: - - bool pop_(myobj *value, bool block) { + bool pop_(myobj* value, bool block) + { if (!enable) { return false; } @@ -169,14 +162,14 @@ private: bool ret = false; if (capacity > 0) { if (block) { - while(q.size() >= (uint32_t) capacity && enable) { + while (q.size() >= (uint32_t)capacity && enable) { pthread_cond_wait(&cv_full, &mutex); } if (!enable) { num_threads--; return false; } - } else if (q.size() >= (uint32_t) capacity) { + } else if (q.size() >= (uint32_t)capacity) { num_threads--; return false; } @@ -221,16 +214,16 @@ private: return ret; } - std::queue q; - pthread_mutex_t mutex; - pthread_cond_t cv_empty; - pthread_cond_t cv_full; - call_mutexed_itf *mutexed_callback; - int capacity; - bool enable; - uint32_t num_threads; + std::queue q; + pthread_mutex_t mutex; + pthread_cond_t cv_empty; + pthread_cond_t cv_full; + call_mutexed_itf* mutexed_callback; + int capacity; + bool enable; + uint32_t num_threads; }; -} +} // namespace srslte #endif // SRSLTE_BLOCK_QUEUE_H diff --git a/lib/include/srslte/common/buffer_pool.h b/lib/include/srslte/common/buffer_pool.h index 9ee042664..97b4c7a1f 100644 --- a/lib/include/srslte/common/buffer_pool.h +++ b/lib/include/srslte/common/buffer_pool.h @@ -22,19 +22,19 @@ #ifndef SRSLTE_BUFFER_POOL_H #define SRSLTE_BUFFER_POOL_H +#include +#include #include -#include #include -#include #include -#include +#include /******************************************************************************* INCLUDES *******************************************************************************/ -#include "srslte/common/log.h" #include "srslte/common/common.h" +#include "srslte/common/log.h" namespace srslte { @@ -43,33 +43,34 @@ namespace srslte { * * Preallocates a large number of buffer_t and provides allocate and * deallocate functions. Provides quick object creation and deletion as well - * as object reuse. + * as object reuse. * Singleton class of byte_buffer_t (but other pools of different type can be created) *****************************************************************************/ template -class buffer_pool{ +class buffer_pool +{ public: - // non-static methods buffer_pool(int capacity_ = -1) { uint32_t nof_buffers = POOL_SIZE; if (capacity_ > 0) { - nof_buffers = (uint32_t) capacity_; + nof_buffers = (uint32_t)capacity_; } pthread_mutex_init(&mutex, NULL); pthread_cond_init(&cv_not_empty, NULL); - for(uint32_t i=0;i buffer_cnt; - for (uint32_t i=0;idebug_name)?used[i]->debug_name:"Undefined"]++; + for (uint32_t i = 0; i < used.size(); i++) { + buffer_cnt[strlen(used[i]->debug_name) ? used[i]->debug_name : "Undefined"]++; } std::map::iterator it; for (it = buffer_cnt.begin(); it != buffer_cnt.end(); it++) { @@ -96,17 +97,14 @@ public: #endif } - uint32_t nof_available_pdus() { - return available.size(); - } + uint32_t nof_available_pdus() { return available.size(); } - bool is_almost_empty() { - return available.size() < capacity/20; - } + bool is_almost_empty() { return available.size() < capacity / 20; } - buffer_t* allocate(const char *debug_name = NULL, bool blocking = false) { + buffer_t* allocate(const char* debug_name = NULL, bool blocking = false) + { pthread_mutex_lock(&mutex); - buffer_t *b = NULL; + buffer_t* b = NULL; if (available.size() > 0) { b = available.top(); @@ -114,7 +112,7 @@ public: available.pop(); if (is_almost_empty()) { - printf("Warning buffer pool capacity is %f %%\n", (float) 100 * available.size() / capacity); + printf("Warning buffer pool capacity is %f %%\n", (float)100 * available.size() / capacity); } #ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED if (debug_name) { @@ -124,7 +122,7 @@ public: #endif } else if (blocking) { // blocking allocation - while(available.size() == 0) { + while (available.size() == 0) { pthread_cond_wait(&cv_not_empty, &mutex); } @@ -134,10 +132,9 @@ public: available.pop(); // do not print any warning - } - else { + } else { printf("Error - buffer pool is empty\n"); - + #ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED print_all_buffers(); #endif @@ -146,56 +143,54 @@ public: pthread_mutex_unlock(&mutex); return b; } - - bool deallocate(buffer_t *b) + + bool deallocate(buffer_t* b) { - bool ret = false; + bool ret = false; pthread_mutex_lock(&mutex); typename std::vector::iterator elem = std::find(used.begin(), used.end(), b); if (elem != used.end()) { - used.erase(elem); + used.erase(elem); available.push(b); - ret = true; + ret = true; } pthread_cond_signal(&cv_not_empty); pthread_mutex_unlock(&mutex); - return ret; + return ret; } - -private: +private: static const int POOL_SIZE = 4096; std::stack available; - std::vector used; + std::vector used; pthread_mutex_t mutex; pthread_cond_t cv_not_empty; - uint32_t capacity; + uint32_t capacity; }; - -class byte_buffer_pool { -public: +class byte_buffer_pool +{ +public: // Singleton static methods - static byte_buffer_pool *instance; - static byte_buffer_pool* get_instance(int capacity = -1); - static void cleanup(void); - byte_buffer_pool(int capacity = -1) { - log = NULL; + static byte_buffer_pool* instance; + static byte_buffer_pool* get_instance(int capacity = -1); + static void cleanup(void); + byte_buffer_pool(int capacity = -1) + { + log = NULL; pool = new buffer_pool(capacity); } byte_buffer_pool(const byte_buffer_pool& other) = delete; byte_buffer_pool& operator=(const byte_buffer_pool& other) = delete; - ~byte_buffer_pool() { - delete pool; - } - byte_buffer_t* allocate(const char *debug_name = NULL, bool blocking = false) { + ~byte_buffer_pool() { delete pool; } + byte_buffer_t* allocate(const char* debug_name = NULL, bool blocking = false) + { return pool->allocate(debug_name, blocking); } - void set_log(srslte::log *log) { - this->log = log; - } - void deallocate(byte_buffer_t *b) { - if(!b) { + void set_log(srslte::log* log) { this->log = log; } + void deallocate(byte_buffer_t* b) + { + if (!b) { return; } b->clear(); @@ -216,12 +211,11 @@ public: } b = NULL; } - void print_all_buffers() { - pool->print_all_buffers(); - } + void print_all_buffers() { pool->print_all_buffers(); } + private: - srslte::log *log; - buffer_pool *pool; + srslte::log* log; + buffer_pool* pool; }; inline void byte_buffer_deleter::operator()(byte_buffer_t* buf) const diff --git a/lib/include/srslte/common/common.h b/lib/include/srslte/common/common.h index 2fd9d6dbf..023736009 100644 --- a/lib/include/srslte/common/common.h +++ b/lib/include/srslte/common/common.h @@ -46,14 +46,14 @@ #define MSG3_DELAY_MS 2 // Delay added to TX_DELAY #define TTI_SUB(a, b) ((((a) + 10240) - (b)) % 10240) -#define TTI_ADD(a, b) (((a) + (b)) % 10240) +#define TTI_ADD(a, b) (((a) + (b)) % 10240) #define TTI_TX(tti) TTI_ADD(tti, TX_DELAY) // Use only in FDD mode!! #define FDD_HARQ_DELAY_MS 4 -#define TTI_RX(tti) (TTI_SUB(tti, FDD_HARQ_DELAY_MS)) -#define TTI_RX_ACK(tti) (TTI_ADD(tti, FDD_HARQ_DELAY_MS + TX_DELAY)) +#define TTI_RX(tti) (TTI_SUB(tti, FDD_HARQ_DELAY_MS)) +#define TTI_RX_ACK(tti) (TTI_ADD(tti, FDD_HARQ_DELAY_MS + TX_DELAY)) #define TTIMOD_SZ 20 #define TTIMOD(tti) (tti % TTIMOD_SZ) diff --git a/lib/include/srslte/common/config_file.h b/lib/include/srslte/common/config_file.h index 820e1f483..93e6f7543 100644 --- a/lib/include/srslte/common/config_file.h +++ b/lib/include/srslte/common/config_file.h @@ -22,17 +22,17 @@ #ifndef SRSLTE_CONFIG_FILE_H #define SRSLTE_CONFIG_FILE_H +#include "common.h" #include #include -#include "common.h" -bool config_exists(std::string &filename, std::string default_name) +bool config_exists(std::string& filename, std::string default_name) { std::ifstream conf(filename.c_str(), std::ios::in); if (conf.fail()) { // try config folder instead const char* homedir = NULL; - char full_path[256]; + char full_path[256]; ZERO_OBJECT(full_path); if ((homedir = getenv("HOME")) == NULL) { homedir = getpwuid(getuid())->pw_dir; diff --git a/lib/include/srslte/common/crash_handler.h b/lib/include/srslte/common/crash_handler.h index e4edf5909..1afd1ac20 100644 --- a/lib/include/srslte/common/crash_handler.h +++ b/lib/include/srslte/common/crash_handler.h @@ -30,14 +30,14 @@ #ifndef SRSLTE_CRASH_HANDLER_H #define SRSLTE_CRASH_HANDLER_H -#include #include "srslte/config.h" +#include #ifdef __cplusplus extern "C" { #endif // __cplusplus -void srslte_debug_handle_crash(int argc, char **argv); +void srslte_debug_handle_crash(int argc, char** argv); #ifdef __cplusplus } diff --git a/lib/include/srslte/common/gen_mch_tables.h b/lib/include/srslte/common/gen_mch_tables.h index 3f343e864..1cfd749b9 100644 --- a/lib/include/srslte/common/gen_mch_tables.h +++ b/lib/include/srslte/common/gen_mch_tables.h @@ -26,22 +26,19 @@ * Common mch table generation - used in phch_common of UE and ENB for MBMS *****************************************************************************/ #include -#include #include - +#include #ifdef __cplusplus extern "C" { #endif // __cplusplus - -void generate_frame_mch_table(uint8_t *table, uint8_t alloc); -void generate_mch_table(uint8_t *table, uint32_t sf_alloc, uint8_t num_frames); -void generate_mcch_table(uint8_t *table, uint32_t sf_alloc); +void generate_frame_mch_table(uint8_t* table, uint8_t alloc); +void generate_mch_table(uint8_t* table, uint32_t sf_alloc, uint8_t num_frames); +void generate_mcch_table(uint8_t* table, uint32_t sf_alloc); #ifdef __cplusplus } #endif // __cplusplus - #endif // SECURITY_H diff --git a/lib/include/srslte/common/liblte_security.h b/lib/include/srslte/common/liblte_security.h index f7d2ad8c5..28a206d06 100644 --- a/lib/include/srslte/common/liblte_security.h +++ b/lib/include/srslte/common/liblte_security.h @@ -107,7 +107,9 @@ typedef enum { LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_N_ITEMS, } LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM; static const char liblte_security_ciphering_algorithm_id_text[LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_N_ITEMS][20] = { - "EEA0", "128-EEA1", "128-EEA2"}; + "EEA0", + "128-EEA1", + "128-EEA2"}; typedef enum { LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_EIA0 = 0, LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_128_EIA1, @@ -116,7 +118,9 @@ typedef enum { LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_N_ITEMS, } LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM; static const char liblte_security_integrity_algorithm_id_text[LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_N_ITEMS][20] = { - "EIA0", "128-EIA1", "128-EIA2"}; + "EIA0", + "128-EIA1", + "128-EIA2"}; // Structs // Functions LIBLTE_ERROR_ENUM liblte_security_generate_k_nas(uint8* k_asme, @@ -175,12 +179,26 @@ LIBLTE_ERROR_ENUM liblte_security_generate_k_up(uint8* // Enums // Structs // Functions -LIBLTE_ERROR_ENUM liblte_security_128_eia2( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* mac); -LIBLTE_ERROR_ENUM liblte_security_128_eia2( - uint8* key, uint32 count, uint8 bearer, uint8 direction, LIBLTE_BIT_MSG_STRUCT* msg, uint8* mac); -LIBLTE_ERROR_ENUM liblte_security_128_eia3( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* mac); +LIBLTE_ERROR_ENUM liblte_security_128_eia2(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* msg, + uint32 msg_len, + uint8* mac); +LIBLTE_ERROR_ENUM liblte_security_128_eia2(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + LIBLTE_BIT_MSG_STRUCT* msg, + uint8* mac); +LIBLTE_ERROR_ENUM liblte_security_128_eia3(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* msg, + uint32 msg_len, + uint8* mac); /********************************************************************* Name: liblte_security_encryption_eea1 @@ -192,8 +210,13 @@ LIBLTE_ERROR_ENUM liblte_security_128_eia3( Specification of the 3GPP Confidentiality and Integrity Algorithms UEA2 & UIA2 D1 v2.1 *********************************************************************/ -LIBLTE_ERROR_ENUM liblte_security_encryption_eea1( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* out); +LIBLTE_ERROR_ENUM liblte_security_encryption_eea1(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* msg, + uint32 msg_len, + uint8* out); /********************************************************************* Name: liblte_security_decryption_eea1 @@ -205,8 +228,13 @@ LIBLTE_ERROR_ENUM liblte_security_encryption_eea1( Specification of the 3GPP Confidentiality and Integrity Algorithms UEA2 & UIA2 D1 v2.1 *********************************************************************/ -LIBLTE_ERROR_ENUM liblte_security_decryption_eea1( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* ct, uint32 ct_len, uint8* out); +LIBLTE_ERROR_ENUM liblte_security_decryption_eea1(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* ct, + uint32 ct_len, + uint8* out); /********************************************************************* Name: liblte_security_encryption_eea2 @@ -215,8 +243,13 @@ LIBLTE_ERROR_ENUM liblte_security_decryption_eea1( Document Reference: 33.401 v13.1.0 Annex B.1.3 *********************************************************************/ -LIBLTE_ERROR_ENUM liblte_security_encryption_eea2( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* out); +LIBLTE_ERROR_ENUM liblte_security_encryption_eea2(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* msg, + uint32 msg_len, + uint8* out); /********************************************************************* Name: liblte_security_decryption_eea2 @@ -225,14 +258,29 @@ LIBLTE_ERROR_ENUM liblte_security_encryption_eea2( Document Reference: 33.401 v13.1.0 Annex B.1.3 *********************************************************************/ -LIBLTE_ERROR_ENUM liblte_security_decryption_eea2( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* ct, uint32 ct_len, uint8* out); - -LIBLTE_ERROR_ENUM liblte_security_encryption_eea3( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* out); - -LIBLTE_ERROR_ENUM liblte_security_decryption_eea3( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* out); +LIBLTE_ERROR_ENUM liblte_security_decryption_eea2(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* ct, + uint32 ct_len, + uint8* out); + +LIBLTE_ERROR_ENUM liblte_security_encryption_eea3(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* msg, + uint32 msg_len, + uint8* out); + +LIBLTE_ERROR_ENUM liblte_security_decryption_eea3(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* msg, + uint32 msg_len, + uint8* out); /********************************************************************* Name: liblte_security_milenage_f1 diff --git a/lib/include/srslte/common/log_filter.h b/lib/include/srslte/common/log_filter.h index 8cde2b96d..50a59d35e 100644 --- a/lib/include/srslte/common/log_filter.h +++ b/lib/include/srslte/common/log_filter.h @@ -33,10 +33,10 @@ #include #include -#include "srslte/phy/common/timestamp.h" #include "srslte/common/log.h" #include "srslte/common/logger.h" #include "srslte/common/logger_stdout.h" +#include "srslte/phy/common/timestamp.h" namespace srslte { @@ -45,48 +45,45 @@ typedef std::string* str_ptr; class log_filter : public srslte::log { public: - log_filter(); log_filter(std::string layer); - log_filter(std::string layer, logger *logger_, bool tti=false); + log_filter(std::string layer, logger* logger_, bool tti = false); ~log_filter(); - void init(std::string layer, logger *logger_, bool tti=false); + void init(std::string layer, logger* logger_, bool tti = false); - void console(const char * message, ...) __attribute__ ((format (printf, 2, 3))); - void error(const char * message, ...) __attribute__ ((format (printf, 2, 3))); - void warning(const char * message, ...) __attribute__ ((format (printf, 2, 3))); - void info(const char * message, ...) __attribute__ ((format (printf, 2, 3))); + void console(const char* message, ...) __attribute__((format(printf, 2, 3))); + void error(const char* message, ...) __attribute__((format(printf, 2, 3))); + void warning(const char* message, ...) __attribute__((format(printf, 2, 3))); + void info(const char* message, ...) __attribute__((format(printf, 2, 3))); void info_long(const char* message, ...) __attribute__((format(printf, 2, 3))); - void debug(const char * message, ...) __attribute__ ((format (printf, 2, 3))); + void debug(const char* message, ...) __attribute__((format(printf, 2, 3))); void debug_long(const char* message, ...) __attribute__((format(printf, 2, 3))); - void error_hex(const uint8_t *hex, int size, const char * message, ...) __attribute__((format (printf, 4, 5))); - void warning_hex(const uint8_t *hex, int size, const char * message, ...) __attribute__((format (printf, 4, 5))); - void info_hex(const uint8_t *hex, int size, const char * message, ...) __attribute__((format (printf, 4, 5))); - void debug_hex(const uint8_t *hex, int size, const char * message, ...) __attribute__((format (printf, 4, 5))); + void error_hex(const uint8_t* hex, int size, const char* message, ...) __attribute__((format(printf, 4, 5))); + void warning_hex(const uint8_t* hex, int size, const char* message, ...) __attribute__((format(printf, 4, 5))); + void info_hex(const uint8_t* hex, int size, const char* message, ...) __attribute__((format(printf, 4, 5))); + void debug_hex(const uint8_t* hex, int size, const char* message, ...) __attribute__((format(printf, 4, 5))); srslte::LOG_LEVEL_ENUM get_level(std::string l); - class time_itf { + class time_itf + { public: virtual srslte_timestamp_t get_time() = 0; }; - typedef enum { - TIME, - EPOCH - } time_format_t; + typedef enum { TIME, EPOCH } time_format_t; - void set_time_src(time_itf *source, time_format_t format); + void set_time_src(time_itf* source, time_format_t format); protected: - logger *logger_h; + logger* logger_h; bool do_tti; static const int char_buff_size = logger::preallocated_log_str_size - 64 * 3; - time_itf *time_src; + time_itf* time_src; time_format_t time_format; logger_stdout def_logger_stdout; @@ -99,7 +96,7 @@ protected: bool long_msg = false); void now_time(char* buffer, const uint32_t buffer_len); void get_tti_str(const uint32_t tti_, char* buffer, const uint32_t buffer_len); - std::string hex_string(const uint8_t *hex, int size); + std::string hex_string(const uint8_t* hex, int size); }; } // namespace srslte diff --git a/lib/include/srslte/common/logger_file.h b/lib/include/srslte/common/logger_file.h index ed4457659..8e3462947 100644 --- a/lib/include/srslte/common/logger_file.h +++ b/lib/include/srslte/common/logger_file.h @@ -30,11 +30,11 @@ #ifndef SRSLTE_LOGGER_FILE_H #define SRSLTE_LOGGER_FILE_H -#include -#include -#include #include "srslte/common/logger.h" #include "srslte/common/threads.h" +#include +#include +#include namespace srslte { @@ -52,17 +52,17 @@ public: void log(unique_log_str_t msg); private: - void run_thread(); + void run_thread(); void flush(); - uint32_t name_idx; - int64_t max_length; - int64_t cur_length; - FILE* logfile; - bool is_running; - std::string filename; - pthread_cond_t not_empty; - pthread_mutex_t mutex; + uint32_t name_idx; + int64_t max_length; + int64_t cur_length; + FILE* logfile; + bool is_running; + std::string filename; + pthread_cond_t not_empty; + pthread_mutex_t mutex; std::deque buffer; }; diff --git a/lib/include/srslte/common/logger_stdout.h b/lib/include/srslte/common/logger_stdout.h index 04055eaf7..bae86d5cb 100644 --- a/lib/include/srslte/common/logger_stdout.h +++ b/lib/include/srslte/common/logger_stdout.h @@ -27,17 +27,17 @@ #ifndef SRSLTE_LOGGER_STDOUT_H #define SRSLTE_LOGGER_STDOUT_H +#include "srslte/common/logger.h" #include #include -#include "srslte/common/logger.h" namespace srslte { - class logger_stdout : public logger - { - public: - void log(unique_log_str_t log_str) { fprintf(stdout, "%s", log_str->str()); } - }; +class logger_stdout : public logger +{ +public: + void log(unique_log_str_t log_str) { fprintf(stdout, "%s", log_str->str()); } +}; } // namespace srslte diff --git a/lib/include/srslte/common/mac_nr_pdu.h b/lib/include/srslte/common/mac_nr_pdu.h index 434100e3a..b423cf1a2 100644 --- a/lib/include/srslte/common/mac_nr_pdu.h +++ b/lib/include/srslte/common/mac_nr_pdu.h @@ -94,11 +94,11 @@ class mac_nr_sch_pdu public: mac_nr_sch_pdu(bool ulsch_ = false) : ulsch(ulsch_) {} - void pack(); - void unpack(const uint8_t* payload, const uint32_t& len); - uint32_t get_num_subpdus(); + void pack(); + void unpack(const uint8_t* payload, const uint32_t& len); + uint32_t get_num_subpdus(); const mac_nr_sch_subpdu& get_subpdu(const uint32_t& index); - bool is_ulsch(); + bool is_ulsch(); void init_tx(byte_buffer_t* buffer_, uint32_t pdu_len_, bool is_ulsch_ = false); @@ -109,8 +109,8 @@ public: private: uint32_t size_header_sdu(const uint32_t lcid_, const uint32_t nbytes); - bool ulsch = false; - std::vector subpdus; + bool ulsch = false; + std::vector subpdus; byte_buffer_t* buffer = nullptr; uint32_t pdu_len = 0; diff --git a/lib/include/srslte/common/mac_pcap.h b/lib/include/srslte/common/mac_pcap.h index fa6e5a967..92a83977b 100644 --- a/lib/include/srslte/common/mac_pcap.h +++ b/lib/include/srslte/common/mac_pcap.h @@ -22,8 +22,8 @@ #ifndef SRSLTE_MAC_PCAP_H #define SRSLTE_MAC_PCAP_H -#include #include "srslte/common/pcap.h" +#include namespace srslte { @@ -33,20 +33,20 @@ public: mac_pcap(); ~mac_pcap(); void enable(bool en); - void open(const char *filename, uint32_t ue_id = 0); + void open(const char* filename, uint32_t ue_id = 0); void close(); void set_ue_id(uint16_t ue_id); - void write_ul_crnti(uint8_t *pdu, uint32_t pdu_len_bytes, uint16_t crnti, uint32_t reTX, uint32_t tti); - void write_dl_crnti(uint8_t *pdu, uint32_t pdu_len_bytes, uint16_t crnti, bool crc_ok, uint32_t tti); - void write_dl_ranti(uint8_t *pdu, uint32_t pdu_len_bytes, uint16_t ranti, bool crc_ok, uint32_t tti); + void write_ul_crnti(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t crnti, uint32_t reTX, uint32_t tti); + void write_dl_crnti(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t crnti, bool crc_ok, uint32_t tti); + void write_dl_ranti(uint8_t* pdu, uint32_t pdu_len_bytes, uint16_t ranti, bool crc_ok, uint32_t tti); // SI and BCH only for DL - void write_dl_sirnti(uint8_t *pdu, uint32_t pdu_len_bytes, bool crc_ok, uint32_t tti); - void write_dl_bch(uint8_t *pdu, uint32_t pdu_len_bytes, bool crc_ok, uint32_t tti); - void write_dl_pch(uint8_t *pdu, uint32_t pdu_len_bytes, bool crc_ok, uint32_t tti); - void write_dl_mch(uint8_t *pdu, uint32_t pdu_len_bytes, bool crc_ok, uint32_t tti); + void write_dl_sirnti(uint8_t* pdu, uint32_t pdu_len_bytes, bool crc_ok, uint32_t tti); + void write_dl_bch(uint8_t* pdu, uint32_t pdu_len_bytes, bool crc_ok, uint32_t tti); + void write_dl_pch(uint8_t* pdu, uint32_t pdu_len_bytes, bool crc_ok, uint32_t tti); + void write_dl_mch(uint8_t* pdu, uint32_t pdu_len_bytes, bool crc_ok, uint32_t tti); void write_ul_rrc_pdu(const uint8_t* input, const int32_t input_len); @@ -54,8 +54,14 @@ private: bool enable_write; FILE* pcap_file; uint32_t ue_id; - void pack_and_write(uint8_t* pdu, uint32_t pdu_len_bytes, uint32_t reTX, bool crc_ok, uint32_t tti, - uint16_t crnti_, uint8_t direction, uint8_t rnti_type); + void pack_and_write(uint8_t* pdu, + uint32_t pdu_len_bytes, + uint32_t reTX, + bool crc_ok, + uint32_t tti, + uint16_t crnti_, + uint8_t direction, + uint8_t rnti_type); }; } // namespace srslte diff --git a/lib/include/srslte/common/metrics_hub.h b/lib/include/srslte/common/metrics_hub.h index 47b45881f..520d5861c 100644 --- a/lib/include/srslte/common/metrics_hub.h +++ b/lib/include/srslte/common/metrics_hub.h @@ -22,7 +22,7 @@ /****************************************************************************** * File: metrics_hub.h * Description: Centralizes metrics interfaces to allow different metrics clients - * to get metrics + * to get metrics *****************************************************************************/ #ifndef SRSLTE_METRICS_HUB_H @@ -35,22 +35,22 @@ namespace srslte { -template -class metrics_interface +template +class metrics_interface { public: virtual bool get_metrics(metrics_t* m) = 0; -}; +}; -template +template class metrics_listener { -public: - virtual void set_metrics(metrics_t &m, const uint32_t period_usec) = 0; - virtual void stop() = 0; +public: + virtual void set_metrics(metrics_t& m, const uint32_t period_usec) = 0; + virtual void stop() = 0; }; -template +template class metrics_hub : public periodic_thread { public: @@ -59,23 +59,22 @@ public: { m = m_; // Start with user-default priority - start_periodic(report_period_secs_*1e6, -2); + start_periodic(report_period_secs_ * 1e6, -2); return true; } - void stop() { + void stop() + { stop_thread(); // stop all listeners - for (uint32_t i=0;istop(); } thread_cancel(); wait_thread_finish(); } - - void add_listener(metrics_listener *listener) { - listeners.push_back(listener); - } - + + void add_listener(metrics_listener* listener) { listeners.push_back(listener); } + private: void run_period() { @@ -86,14 +85,14 @@ private: if (m) { metrics_t metric; m->get_metrics(&metric); - for (uint32_t i=0;iset_metrics(metric, period_usec.count()); } } // store start of sleep period sleep_start = std::chrono::steady_clock::now(); } - metrics_interface *m; + metrics_interface* m; std::vector*> listeners; std::chrono::steady_clock::time_point sleep_start; }; diff --git a/lib/include/srslte/common/nas_pcap.h b/lib/include/srslte/common/nas_pcap.h index 3eaf01afc..b594571b1 100644 --- a/lib/include/srslte/common/nas_pcap.h +++ b/lib/include/srslte/common/nas_pcap.h @@ -29,18 +29,24 @@ namespace srslte { class nas_pcap { public: - nas_pcap() {enable_write=false; ue_id=0; pcap_file = NULL; } - void enable(); - void open(const char *filename, uint32_t ue_id=0); - void close(); - void write_nas(uint8_t *pdu, uint32_t pdu_len_bytes); + nas_pcap() + { + enable_write = false; + ue_id = 0; + pcap_file = NULL; + } + void enable(); + void open(const char* filename, uint32_t ue_id = 0); + void close(); + void write_nas(uint8_t* pdu, uint32_t pdu_len_bytes); + private: - bool enable_write; - FILE *pcap_file; - uint32_t ue_id; - void pack_and_write(uint8_t* pdu, uint32_t pdu_len_bytes); + bool enable_write; + FILE* pcap_file; + uint32_t ue_id; + void pack_and_write(uint8_t* pdu, uint32_t pdu_len_bytes); }; -} //namespace srslte +} // namespace srslte #endif // SRSLTE_NAS_PCAP_H diff --git a/lib/include/srslte/common/pcap.h b/lib/include/srslte/common/pcap.h index 03c721f46..eb89e6196 100644 --- a/lib/include/srslte/common/pcap.h +++ b/lib/include/srslte/common/pcap.h @@ -22,79 +22,76 @@ #ifndef SRSLTE_PCAP_H #define SRSLTE_PCAP_H +#include #include #include -#include #include -#define MAC_LTE_DLT 147 -#define NAS_LTE_DLT 148 +#define MAC_LTE_DLT 147 +#define NAS_LTE_DLT 148 #define UDP_DLT 149 // UDP needs to be selected as protocol -#define S1AP_LTE_DLT 150 +#define S1AP_LTE_DLT 150 /* This structure gets written to the start of the file */ typedef struct pcap_hdr_s { - unsigned int magic_number; /* magic number */ - unsigned short version_major; /* major version number */ - unsigned short version_minor; /* minor version number */ - unsigned int thiszone; /* GMT to local correction */ - unsigned int sigfigs; /* accuracy of timestamps */ - unsigned int snaplen; /* max length of captured packets, in octets */ - unsigned int network; /* data link type */ + unsigned int magic_number; /* magic number */ + unsigned short version_major; /* major version number */ + unsigned short version_minor; /* minor version number */ + unsigned int thiszone; /* GMT to local correction */ + unsigned int sigfigs; /* accuracy of timestamps */ + unsigned int snaplen; /* max length of captured packets, in octets */ + unsigned int network; /* data link type */ } pcap_hdr_t; /* This structure precedes each packet */ typedef struct pcaprec_hdr_s { - unsigned int ts_sec; /* timestamp seconds */ - unsigned int ts_usec; /* timestamp microseconds */ - unsigned int incl_len; /* number of octets of packet saved in file */ - unsigned int orig_len; /* actual length of packet */ + unsigned int ts_sec; /* timestamp seconds */ + unsigned int ts_usec; /* timestamp microseconds */ + unsigned int incl_len; /* number of octets of packet saved in file */ + unsigned int orig_len; /* actual length of packet */ } pcaprec_hdr_t; - /* radioType */ #define FDD_RADIO 1 #define TDD_RADIO 2 /* Direction */ -#define DIRECTION_UPLINK 0 +#define DIRECTION_UPLINK 0 #define DIRECTION_DOWNLINK 1 /* rntiType */ -#define NO_RNTI 0 /* Used for BCH-BCH */ -#define P_RNTI 1 -#define RA_RNTI 2 -#define C_RNTI 3 -#define SI_RNTI 4 +#define NO_RNTI 0 /* Used for BCH-BCH */ +#define P_RNTI 1 +#define RA_RNTI 2 +#define C_RNTI 3 +#define SI_RNTI 4 #define SPS_RNTI 5 -#define M_RNTI 6 - -#define MAC_LTE_START_STRING "mac-lte" -#define MAC_LTE_PAYLOAD_TAG 0x01 -#define MAC_LTE_RNTI_TAG 0x02 -#define MAC_LTE_UEID_TAG 0x03 -#define MAC_LTE_FRAME_SUBFRAME_TAG 0x04 -#define MAC_LTE_PREDFINED_DATA_TAG 0x05 -#define MAC_LTE_RETX_TAG 0x06 -#define MAC_LTE_CRC_STATUS_TAG 0x07 -#define MAC_LTE_NB_MODE_TAG 0x0F - - +#define M_RNTI 6 + +#define MAC_LTE_START_STRING "mac-lte" +#define MAC_LTE_PAYLOAD_TAG 0x01 +#define MAC_LTE_RNTI_TAG 0x02 +#define MAC_LTE_UEID_TAG 0x03 +#define MAC_LTE_FRAME_SUBFRAME_TAG 0x04 +#define MAC_LTE_PREDFINED_DATA_TAG 0x05 +#define MAC_LTE_RETX_TAG 0x06 +#define MAC_LTE_CRC_STATUS_TAG 0x07 +#define MAC_LTE_NB_MODE_TAG 0x0F /* Context information for every MAC PDU that will be logged */ typedef struct MAC_Context_Info_t { - unsigned short radioType; - unsigned char direction; - unsigned char rntiType; - unsigned short rnti; - unsigned short ueid; - unsigned char isRetx; - unsigned char crcStatusOK; - - unsigned short sysFrameNumber; - unsigned short subFrameNumber; - - unsigned char nbiotMode; + unsigned short radioType; + unsigned char direction; + unsigned char rntiType; + unsigned short rnti; + unsigned short ueid; + unsigned char isRetx; + unsigned char crcStatusOK; + + unsigned short sysFrameNumber; + unsigned short subFrameNumber; + + unsigned char nbiotMode; } MAC_Context_Info_t; /* Context information for every NAS PDU that will be logged */ @@ -128,7 +125,7 @@ typedef struct { #define RLC_TM_MODE 1 #define RLC_UM_MODE 2 #define RLC_AM_MODE 4 -#define RLC_PREDEF 8 +#define RLC_PREDEF 8 /* priority ? */ @@ -149,10 +146,7 @@ typedef struct { #define AM_SN_LENGTH_16_BITS 16 /* Narrow band mode */ -typedef enum { - rlc_no_nb_mode = 0, - rlc_nb_mode = 1 -} rlc_lte_nb_mode; +typedef enum { rlc_no_nb_mode = 0, rlc_nb_mode = 1 } rlc_lte_nb_mode; /* Context information for every RLC PDU that will be logged */ typedef struct { @@ -168,19 +162,17 @@ typedef struct { rlc_lte_nb_mode nbMode; } RLC_Context_Info_t; - // See Wireshark's packet-rlc-lte.h for details #define RLC_LTE_START_STRING "rlc-lte" -#define RLC_LTE_SN_LENGTH_TAG 0x02 -#define RLC_LTE_DIRECTION_TAG 0x03 -#define RLC_LTE_PRIORITY_TAG 0x04 -#define RLC_LTE_UEID_TAG 0x05 +#define RLC_LTE_SN_LENGTH_TAG 0x02 +#define RLC_LTE_DIRECTION_TAG 0x03 +#define RLC_LTE_PRIORITY_TAG 0x04 +#define RLC_LTE_UEID_TAG 0x05 #define RLC_LTE_CHANNEL_TYPE_TAG 0x06 -#define RLC_LTE_CHANNEL_ID_TAG 0x07 +#define RLC_LTE_CHANNEL_ID_TAG 0x07 #define RLC_LTE_EXT_LI_FIELD_TAG 0x08 -#define RLC_LTE_NB_MODE_TAG 0x09 -#define RLC_LTE_PAYLOAD_TAG 0x01 - +#define RLC_LTE_NB_MODE_TAG 0x09 +#define RLC_LTE_PAYLOAD_TAG 0x01 /* Context information for every S1AP PDU that will be logged */ typedef struct S1AP_Context_Info_s { @@ -192,235 +184,227 @@ typedef struct S1AP_Context_Info_s { **************************************************************************/ /* Open the file and write file header */ -inline FILE *LTE_PCAP_Open(uint32_t DLT, const char *fileName) +inline FILE* LTE_PCAP_Open(uint32_t DLT, const char* fileName) { - pcap_hdr_t file_header = - { - 0xa1b2c3d4, /* magic number */ - 2, 4, /* version number is 2.4 */ - 0, /* timezone */ - 0, /* sigfigs - apparently all tools do this */ - 65535, /* snaplen - this should be long enough */ - DLT /* Data Link Type (DLT). Set as unused value 147 for now */ - }; - - FILE *fd = fopen(fileName, "w"); - if (fd == NULL) { - printf("Failed to open file \"%s\" for writing\n", fileName); - return NULL; - } - - /* Write the file header */ - fwrite(&file_header, sizeof(pcap_hdr_t), 1, fd); - - return fd; + pcap_hdr_t file_header = { + 0xa1b2c3d4, /* magic number */ + 2, + 4, /* version number is 2.4 */ + 0, /* timezone */ + 0, /* sigfigs - apparently all tools do this */ + 65535, /* snaplen - this should be long enough */ + DLT /* Data Link Type (DLT). Set as unused value 147 for now */ + }; + + FILE* fd = fopen(fileName, "w"); + if (fd == NULL) { + printf("Failed to open file \"%s\" for writing\n", fileName); + return NULL; + } + + /* Write the file header */ + fwrite(&file_header, sizeof(pcap_hdr_t), 1, fd); + + return fd; } /* Close the PCAP file */ -inline void LTE_PCAP_Close(FILE *fd) +inline void LTE_PCAP_Close(FILE* fd) { - if(fd) + if (fd) fclose(fd); } - /************************************************************************** * API functions for writing MAC-LTE PCAP files * **************************************************************************/ /* Write an individual PDU (PCAP packet header + mac-context + mac-pdu) */ -inline int LTE_PCAP_MAC_WritePDU(FILE *fd, MAC_Context_Info_t *context, - const unsigned char *PDU, unsigned int length) +inline int LTE_PCAP_MAC_WritePDU(FILE* fd, MAC_Context_Info_t* context, const unsigned char* PDU, unsigned int length) { - pcaprec_hdr_t packet_header; - char context_header[256]; - int offset = 0; - uint16_t tmp16; - - /* Can't write if file wasn't successfully opened */ - if (fd == NULL) { - printf("Error: Can't write to empty file handle\n"); - return 0; - } - - /*****************************************************************/ - /* Context information (same as written by UDP heuristic clients */ - context_header[offset++] = context->radioType; - context_header[offset++] = context->direction; - context_header[offset++] = context->rntiType; - - /* RNTI */ - context_header[offset++] = MAC_LTE_RNTI_TAG; - tmp16 = htons(context->rnti); - memcpy(context_header+offset, &tmp16, 2); - offset += 2; - - /* UEId */ - context_header[offset++] = MAC_LTE_UEID_TAG; - tmp16 = htons(context->ueid); - memcpy(context_header+offset, &tmp16, 2); - offset += 2; - - /* Subframe Number and System Frame Number */ - /* SFN is stored in 12 MSB and SF in 4 LSB */ - context_header[offset++] = MAC_LTE_FRAME_SUBFRAME_TAG; - tmp16 = (context->sysFrameNumber << 4) | context->subFrameNumber; - tmp16 = htons(tmp16); - memcpy(context_header+offset, &tmp16, 2); - offset += 2; - - /* CRC Status */ - context_header[offset++] = MAC_LTE_CRC_STATUS_TAG; - context_header[offset++] = context->crcStatusOK; - - /* NB-IoT mode tag */ - context_header[offset++] = MAC_LTE_NB_MODE_TAG; - context_header[offset++] = context->nbiotMode; - - /* Data tag immediately preceding PDU */ - context_header[offset++] = MAC_LTE_PAYLOAD_TAG; - - - /****************************************************************/ - /* PCAP Header */ - struct timeval t; - gettimeofday(&t, NULL); - packet_header.ts_sec = t.tv_sec; - packet_header.ts_usec = t.tv_usec; - packet_header.incl_len = offset + length; - packet_header.orig_len = offset + length; - - /***************************************************************/ - /* Now write everything to the file */ - fwrite(&packet_header, sizeof(pcaprec_hdr_t), 1, fd); - fwrite(context_header, 1, offset, fd); - fwrite(PDU, 1, length, fd); - - return 1; -} + pcaprec_hdr_t packet_header; + char context_header[256]; + int offset = 0; + uint16_t tmp16; + + /* Can't write if file wasn't successfully opened */ + if (fd == NULL) { + printf("Error: Can't write to empty file handle\n"); + return 0; + } + + /*****************************************************************/ + /* Context information (same as written by UDP heuristic clients */ + context_header[offset++] = context->radioType; + context_header[offset++] = context->direction; + context_header[offset++] = context->rntiType; + + /* RNTI */ + context_header[offset++] = MAC_LTE_RNTI_TAG; + tmp16 = htons(context->rnti); + memcpy(context_header + offset, &tmp16, 2); + offset += 2; + + /* UEId */ + context_header[offset++] = MAC_LTE_UEID_TAG; + tmp16 = htons(context->ueid); + memcpy(context_header + offset, &tmp16, 2); + offset += 2; + + /* Subframe Number and System Frame Number */ + /* SFN is stored in 12 MSB and SF in 4 LSB */ + context_header[offset++] = MAC_LTE_FRAME_SUBFRAME_TAG; + tmp16 = (context->sysFrameNumber << 4) | context->subFrameNumber; + tmp16 = htons(tmp16); + memcpy(context_header + offset, &tmp16, 2); + offset += 2; + /* CRC Status */ + context_header[offset++] = MAC_LTE_CRC_STATUS_TAG; + context_header[offset++] = context->crcStatusOK; + /* NB-IoT mode tag */ + context_header[offset++] = MAC_LTE_NB_MODE_TAG; + context_header[offset++] = context->nbiotMode; + + /* Data tag immediately preceding PDU */ + context_header[offset++] = MAC_LTE_PAYLOAD_TAG; + + /****************************************************************/ + /* PCAP Header */ + struct timeval t; + gettimeofday(&t, NULL); + packet_header.ts_sec = t.tv_sec; + packet_header.ts_usec = t.tv_usec; + packet_header.incl_len = offset + length; + packet_header.orig_len = offset + length; + + /***************************************************************/ + /* Now write everything to the file */ + fwrite(&packet_header, sizeof(pcaprec_hdr_t), 1, fd); + fwrite(context_header, 1, offset, fd); + fwrite(PDU, 1, length, fd); + + return 1; +} /************************************************************************** * API functions for writing NAS-EPS PCAP files * **************************************************************************/ /* Write an individual PDU (PCAP packet header + nas-context + nas-pdu) */ -inline int LTE_PCAP_NAS_WritePDU(FILE *fd, NAS_Context_Info_t *context, - const unsigned char *PDU, unsigned int length) +inline int LTE_PCAP_NAS_WritePDU(FILE* fd, NAS_Context_Info_t* context, const unsigned char* PDU, unsigned int length) { - pcaprec_hdr_t packet_header; - - /* Can't write if file wasn't successfully opened */ - if (fd == NULL) { - printf("Error: Can't write to empty file handle\n"); - return 0; - } - - /****************************************************************/ - /* PCAP Header */ - struct timeval t; - gettimeofday(&t, NULL); - packet_header.ts_sec = t.tv_sec; - packet_header.ts_usec = t.tv_usec; - packet_header.incl_len = length; - packet_header.orig_len = length; - - /***************************************************************/ - /* Now write everything to the file */ - fwrite(&packet_header, sizeof(pcaprec_hdr_t), 1, fd); - fwrite(PDU, 1, length, fd); - - return 1; -} + pcaprec_hdr_t packet_header; + + /* Can't write if file wasn't successfully opened */ + if (fd == NULL) { + printf("Error: Can't write to empty file handle\n"); + return 0; + } + /****************************************************************/ + /* PCAP Header */ + struct timeval t; + gettimeofday(&t, NULL); + packet_header.ts_sec = t.tv_sec; + packet_header.ts_usec = t.tv_usec; + packet_header.incl_len = length; + packet_header.orig_len = length; + + /***************************************************************/ + /* Now write everything to the file */ + fwrite(&packet_header, sizeof(pcaprec_hdr_t), 1, fd); + fwrite(PDU, 1, length, fd); + + return 1; +} /************************************************************************** * API functions for writing RLC-LTE PCAP files * **************************************************************************/ /* Write an individual RLC PDU (PCAP packet header + UDP header + rlc-context + rlc-pdu) */ -inline int LTE_PCAP_RLC_WritePDU(FILE *fd, RLC_Context_Info_t *context, - const unsigned char *PDU, unsigned int length) +inline int LTE_PCAP_RLC_WritePDU(FILE* fd, RLC_Context_Info_t* context, const unsigned char* PDU, unsigned int length) { - pcaprec_hdr_t packet_header; - char context_header[256]; - int offset = 0; - uint16_t tmp16; - - /* Can't write if file wasn't successfully opened */ - if (fd == NULL) { - printf("Error: Can't write to empty file handle\n"); - return 0; - } - - /*****************************************************************/ - - // Add dummy UDP header, start with src and dest port - context_header[offset++] = 0xde; - context_header[offset++] = 0xad; - context_header[offset++] = 0xbe; - context_header[offset++] = 0xef; - // length - tmp16 = length + 12; - memcpy(context_header+offset, &tmp16, 2); - offset += 2; - // dummy CRC - context_header[offset++] = 0xde; - context_header[offset++] = 0xad; - - // Start magic string - memcpy(&context_header[offset], RLC_LTE_START_STRING, strlen(RLC_LTE_START_STRING)); - offset += strlen(RLC_LTE_START_STRING); - - // Fixed field RLC mode - context_header[offset++] = context->rlcMode; - - // Conditional fields - if (context->rlcMode == RLC_UM_MODE) { - context_header[offset++] = RLC_LTE_SN_LENGTH_TAG; - context_header[offset++] = context->sequenceNumberLength; - } - - // Optional fields - context_header[offset++] = RLC_LTE_DIRECTION_TAG; - context_header[offset++] = context->direction; - - context_header[offset++] = RLC_LTE_PRIORITY_TAG; - context_header[offset++] = context->priority; - - context_header[offset++] = RLC_LTE_UEID_TAG; - tmp16 = htons(context->ueid); - memcpy(context_header+offset, &tmp16, 2); - offset += 2; - - context_header[offset++] = RLC_LTE_CHANNEL_TYPE_TAG; - tmp16 = htons(context->channelType); - memcpy(context_header+offset, &tmp16, 2); - offset += 2; - - context_header[offset++] = RLC_LTE_CHANNEL_ID_TAG; - tmp16 = htons(context->channelId); - memcpy(context_header+offset, &tmp16, 2); - offset += 2; - - // Now the actual PDU - context_header[offset++] = RLC_LTE_PAYLOAD_TAG; - - // PCAP header - struct timeval t; - gettimeofday(&t, NULL); - packet_header.ts_sec = t.tv_sec; - packet_header.ts_usec = t.tv_usec; - packet_header.incl_len = offset + length; - packet_header.orig_len = offset + length; - - // Write everything to file - fwrite(&packet_header, sizeof(pcaprec_hdr_t), 1, fd); - fwrite(context_header, 1, offset, fd); - fwrite(PDU, 1, length, fd); - - return 1; + pcaprec_hdr_t packet_header; + char context_header[256]; + int offset = 0; + uint16_t tmp16; + + /* Can't write if file wasn't successfully opened */ + if (fd == NULL) { + printf("Error: Can't write to empty file handle\n"); + return 0; + } + + /*****************************************************************/ + + // Add dummy UDP header, start with src and dest port + context_header[offset++] = 0xde; + context_header[offset++] = 0xad; + context_header[offset++] = 0xbe; + context_header[offset++] = 0xef; + // length + tmp16 = length + 12; + memcpy(context_header + offset, &tmp16, 2); + offset += 2; + // dummy CRC + context_header[offset++] = 0xde; + context_header[offset++] = 0xad; + + // Start magic string + memcpy(&context_header[offset], RLC_LTE_START_STRING, strlen(RLC_LTE_START_STRING)); + offset += strlen(RLC_LTE_START_STRING); + + // Fixed field RLC mode + context_header[offset++] = context->rlcMode; + + // Conditional fields + if (context->rlcMode == RLC_UM_MODE) { + context_header[offset++] = RLC_LTE_SN_LENGTH_TAG; + context_header[offset++] = context->sequenceNumberLength; + } + + // Optional fields + context_header[offset++] = RLC_LTE_DIRECTION_TAG; + context_header[offset++] = context->direction; + + context_header[offset++] = RLC_LTE_PRIORITY_TAG; + context_header[offset++] = context->priority; + + context_header[offset++] = RLC_LTE_UEID_TAG; + tmp16 = htons(context->ueid); + memcpy(context_header + offset, &tmp16, 2); + offset += 2; + + context_header[offset++] = RLC_LTE_CHANNEL_TYPE_TAG; + tmp16 = htons(context->channelType); + memcpy(context_header + offset, &tmp16, 2); + offset += 2; + + context_header[offset++] = RLC_LTE_CHANNEL_ID_TAG; + tmp16 = htons(context->channelId); + memcpy(context_header + offset, &tmp16, 2); + offset += 2; + + // Now the actual PDU + context_header[offset++] = RLC_LTE_PAYLOAD_TAG; + + // PCAP header + struct timeval t; + gettimeofday(&t, NULL); + packet_header.ts_sec = t.tv_sec; + packet_header.ts_usec = t.tv_usec; + packet_header.incl_len = offset + length; + packet_header.orig_len = offset + length; + + // Write everything to file + fwrite(&packet_header, sizeof(pcaprec_hdr_t), 1, fd); + fwrite(context_header, 1, offset, fd); + fwrite(PDU, 1, length, fd); + + return 1; } /************************************************************************** @@ -428,32 +412,31 @@ inline int LTE_PCAP_RLC_WritePDU(FILE *fd, RLC_Context_Info_t *context, **************************************************************************/ /* Write an individual PDU (PCAP packet header + s1ap-context + s1ap-pdu) */ -inline int LTE_PCAP_S1AP_WritePDU(FILE *fd, S1AP_Context_Info_t *context, - const unsigned char *PDU, unsigned int length) +inline int LTE_PCAP_S1AP_WritePDU(FILE* fd, S1AP_Context_Info_t* context, const unsigned char* PDU, unsigned int length) { - pcaprec_hdr_t packet_header; - - /* Can't write if file wasn't successfully opened */ - if (fd == NULL) { - printf("Error: Can't write to empty file handle\n"); - return 0; - } - - /****************************************************************/ - /* PCAP Header */ - struct timeval t; - gettimeofday(&t, NULL); - packet_header.ts_sec = t.tv_sec; - packet_header.ts_usec = t.tv_usec; - packet_header.incl_len = length; - packet_header.orig_len = length; - - /***************************************************************/ - /* Now write everything to the file */ - fwrite(&packet_header, sizeof(pcaprec_hdr_t), 1, fd); - fwrite(PDU, 1, length, fd); - - return 1; + pcaprec_hdr_t packet_header; + + /* Can't write if file wasn't successfully opened */ + if (fd == NULL) { + printf("Error: Can't write to empty file handle\n"); + return 0; + } + + /****************************************************************/ + /* PCAP Header */ + struct timeval t; + gettimeofday(&t, NULL); + packet_header.ts_sec = t.tv_sec; + packet_header.ts_usec = t.tv_usec; + packet_header.incl_len = length; + packet_header.orig_len = length; + + /***************************************************************/ + /* Now write everything to the file */ + fwrite(&packet_header, sizeof(pcaprec_hdr_t), 1, fd); + fwrite(PDU, 1, length, fd); + + return 1; } /************************************************************************** diff --git a/lib/include/srslte/common/pdu.h b/lib/include/srslte/common/pdu.h index d57bee899..c281a958d 100644 --- a/lib/include/srslte/common/pdu.h +++ b/lib/include/srslte/common/pdu.h @@ -120,10 +120,7 @@ public: uint8_t* get_current_sdu_ptr() { return &buffer_tx->msg[buffer_tx->N_bytes]; } - void add_sdu(uint32_t sdu_sz) - { - buffer_tx->N_bytes += sdu_sz; - } + void add_sdu(uint32_t sdu_sz) { buffer_tx->N_bytes += sdu_sz; } // Section 6.1.2 void parse_packet(uint8_t* ptr) @@ -167,12 +164,12 @@ protected: /* Prepares the PDU for parsing or writing by setting the number of subheaders to 0 and the pdu length */ virtual void init_(byte_buffer_t* buffer_tx_, uint32_t pdu_len_bytes, bool is_ulsch) { - nof_subheaders = 0; - pdu_len = pdu_len_bytes; - rem_len = pdu_len; - pdu_is_ul = is_ulsch; - buffer_tx = buffer_tx_; - last_sdu_idx = -1; + nof_subheaders = 0; + pdu_len = pdu_len_bytes; + rem_len = pdu_len; + pdu_is_ul = is_ulsch; + buffer_tx = buffer_tx_; + last_sdu_idx = -1; reset(); for (uint32_t i = 0; i < max_subheaders; i++) { subheaders[i].parent = this; @@ -391,12 +388,12 @@ private: /* Prepares the PDU for parsing or writing by setting the number of subheaders to 0 and the pdu length */ virtual void init_(byte_buffer_t* buffer_tx_, uint32_t pdu_len_bytes, bool is_ulsch) { - nof_subheaders = 0; - pdu_len = pdu_len_bytes; - rem_len = pdu_len; - pdu_is_ul = is_ulsch; - buffer_tx = buffer_tx_; - last_sdu_idx = -1; + nof_subheaders = 0; + pdu_len = pdu_len_bytes; + rem_len = pdu_len; + pdu_is_ul = is_ulsch; + buffer_tx = buffer_tx_; + last_sdu_idx = -1; reset(); for (uint32_t i = 0; i < max_subheaders; i++) { subheaders[i].set_type(MCH_SUBH_TYPE); diff --git a/lib/include/srslte/common/pdu_queue.h b/lib/include/srslte/common/pdu_queue.h index b8b64969d..a03049ecd 100644 --- a/lib/include/srslte/common/pdu_queue.h +++ b/lib/include/srslte/common/pdu_queue.h @@ -22,64 +22,56 @@ #ifndef SRSLTE_PDU_QUEUE_H #define SRSLTE_PDU_QUEUE_H -#include "srslte/common/log.h" #include "srslte/common/block_queue.h" #include "srslte/common/buffer_pool.h" -#include "srslte/common/timers.h" +#include "srslte/common/log.h" #include "srslte/common/pdu.h" +#include "srslte/common/timers.h" -/* Logical Channel Demultiplexing and MAC CE dissassemble */ - +/* Logical Channel Demultiplexing and MAC CE dissassemble */ namespace srslte { class pdu_queue { public: - typedef enum { - DCH, - BCH, - MCH - } channel_t; + typedef enum { DCH, BCH, MCH } channel_t; class process_callback { - public: - virtual void process_pdu(uint8_t* buff, uint32_t len, channel_t channel) = 0; + public: + virtual void process_pdu(uint8_t* buff, uint32_t len, channel_t channel) = 0; }; pdu_queue(uint32_t pool_size = DEFAULT_POOL_SIZE) : pool(pool_size), callback(NULL), log_h(NULL) {} - void init(process_callback *callback, log* log_h_); + void init(process_callback* callback, log* log_h_); uint8_t* request(uint32_t len); void deallocate(uint8_t* pdu); void push(uint8_t* ptr, uint32_t len, channel_t channel = DCH); - bool process_pdus(); + bool process_pdus(); private: - const static int DEFAULT_POOL_SIZE = 64; // Number of PDU buffers in total - const static int MAX_PDU_LEN = 150*1024/8; // ~ 150 Mbps + const static int DEFAULT_POOL_SIZE = 64; // Number of PDU buffers in total + const static int MAX_PDU_LEN = 150 * 1024 / 8; // ~ 150 Mbps - typedef struct { - uint8_t ptr[MAX_PDU_LEN]; - uint32_t len; + typedef struct { + uint8_t ptr[MAX_PDU_LEN]; + uint32_t len; channel_t channel; - #ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED - char debug_name[128]; - #endif +#ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED + char debug_name[128]; +#endif - } pdu_t; - - block_queue pdu_q; + } pdu_t; + + block_queue pdu_q; buffer_pool pool; - - process_callback *callback; - log *log_h; + + process_callback* callback; + log* log_h; }; } // namespace srslte #endif // SRSLTE_PDU_QUEUE_H - - - diff --git a/lib/include/srslte/common/rlc_pcap.h b/lib/include/srslte/common/rlc_pcap.h index dffa01b50..70ad6de66 100644 --- a/lib/include/srslte/common/rlc_pcap.h +++ b/lib/include/srslte/common/rlc_pcap.h @@ -22,37 +22,42 @@ #ifndef RLCPCAP_H #define RLCPCAP_H -#include #include "srslte/common/pcap.h" +#include namespace srslte { class rlc_pcap { -public: - rlc_pcap() {enable_write=false; ue_id=0; pcap_file = NULL; }; +public: + rlc_pcap() + { + enable_write = false; + ue_id = 0; + pcap_file = NULL; + }; void enable(bool en); - void open(const char *filename, uint32_t ue_id = 0); + void open(const char* filename, uint32_t ue_id = 0); void close(); void set_ue_id(uint16_t ue_id); void write_dl_am_ccch(uint8_t* pdu, uint32_t pdu_len_bytes); void write_ul_am_ccch(uint8_t* pdu, uint32_t pdu_len_bytes); - + private: - bool enable_write; - FILE *pcap_file; + bool enable_write; + FILE* pcap_file; uint32_t ue_id; - void pack_and_write(uint8_t* pdu, - uint32_t pdu_len_bytes, - uint8_t mode, - uint8_t direction, - uint8_t priority, - uint8_t seqnumberlength, - uint16_t ueid, - uint16_t channel_type, - uint16_t channel_id); + void pack_and_write(uint8_t* pdu, + uint32_t pdu_len_bytes, + uint8_t mode, + uint8_t direction, + uint8_t priority, + uint8_t seqnumberlength, + uint16_t ueid, + uint16_t channel_type, + uint16_t channel_id); }; } // namespace srslte diff --git a/lib/include/srslte/common/s1ap_pcap.h b/lib/include/srslte/common/s1ap_pcap.h index daf3ba67f..43b84bcf4 100644 --- a/lib/include/srslte/common/s1ap_pcap.h +++ b/lib/include/srslte/common/s1ap_pcap.h @@ -29,16 +29,21 @@ namespace srslte { class s1ap_pcap { public: - s1ap_pcap() {enable_write=false; pcap_file = NULL; } - void enable(); - void open(const char *filename); - void close(); - void write_s1ap(uint8_t *pdu, uint32_t pdu_len_bytes); + s1ap_pcap() + { + enable_write = false; + pcap_file = NULL; + } + void enable(); + void open(const char* filename); + void close(); + void write_s1ap(uint8_t* pdu, uint32_t pdu_len_bytes); + private: - bool enable_write; - FILE *pcap_file; + bool enable_write; + FILE* pcap_file; }; -} //namespace srslte +} // namespace srslte #endif // SRSLTE_NAS_PCAP_H diff --git a/lib/include/srslte/common/security.h b/lib/include/srslte/common/security.h index 37c7ac24c..a9e0e5c1a 100644 --- a/lib/include/srslte/common/security.h +++ b/lib/include/srslte/common/security.h @@ -26,7 +26,6 @@ * Common security header - wraps ciphering/integrity check algorithms. *****************************************************************************/ - #include "srslte/common/common.h" namespace srslte { @@ -38,8 +37,10 @@ typedef enum { CIPHERING_ALGORITHM_ID_128_EEA3, CIPHERING_ALGORITHM_ID_N_ITEMS, } CIPHERING_ALGORITHM_ID_ENUM; -static const char ciphering_algorithm_id_text[CIPHERING_ALGORITHM_ID_N_ITEMS][20] = { - "EEA0", "128-EEA1", "128-EEA2", "128-EEA3"}; +static const char ciphering_algorithm_id_text[CIPHERING_ALGORITHM_ID_N_ITEMS][20] = {"EEA0", + "128-EEA1", + "128-EEA2", + "128-EEA3"}; typedef enum { INTEGRITY_ALGORITHM_ID_EIA0 = 0, @@ -48,8 +49,10 @@ typedef enum { INTEGRITY_ALGORITHM_ID_128_EIA3, INTEGRITY_ALGORITHM_ID_N_ITEMS, } INTEGRITY_ALGORITHM_ID_ENUM; -static const char integrity_algorithm_id_text[INTEGRITY_ALGORITHM_ID_N_ITEMS][20] = { - "EIA0", "128-EIA1", "128-EIA2", "128-EIA3"}; +static const char integrity_algorithm_id_text[INTEGRITY_ALGORITHM_ID_N_ITEMS][20] = {"EIA0", + "128-EIA1", + "128-EIA2", + "128-EIA3"}; typedef enum { SECURITY_DIRECTION_UPLINK = 0, @@ -61,70 +64,93 @@ static const char security_direction_text[INTEGRITY_ALGORITHM_ID_N_ITEMS][20] = /****************************************************************************** * Key Generation *****************************************************************************/ -uint8_t security_generate_k_asme( uint8_t *ck, - uint8_t *ik, - uint8_t *ak, - uint8_t *sqn, - uint16_t mcc, - uint16_t mnc, - uint8_t *k_asme); - -uint8_t security_generate_k_enb( uint8_t *k_asme, - uint32_t nas_count, - uint8_t *k_enb); - -uint8_t security_generate_k_enb_star( uint8_t *k_enb, - uint32_t pci, - uint32_t earfcn, - uint8_t *k_enb_star); - -uint8_t security_generate_nh( uint8_t *k_asme, - uint8_t *sync, - uint8_t *nh); - -uint8_t security_generate_k_nas( uint8_t *k_asme, - CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, - INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, - uint8_t *k_nas_enc, - uint8_t *k_nas_int); - -uint8_t security_generate_k_rrc( uint8_t *k_enb, - CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, - INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int); - -uint8_t security_generate_k_up( uint8_t *k_enb, - CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, - INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, - uint8_t *k_up_enc, - uint8_t *k_up_int); +uint8_t security_generate_k_asme(uint8_t* ck, + uint8_t* ik, + uint8_t* ak, + uint8_t* sqn, + uint16_t mcc, + uint16_t mnc, + uint8_t* k_asme); + +uint8_t security_generate_k_enb(uint8_t* k_asme, uint32_t nas_count, uint8_t* k_enb); + +uint8_t security_generate_k_enb_star(uint8_t* k_enb, uint32_t pci, uint32_t earfcn, uint8_t* k_enb_star); + +uint8_t security_generate_nh(uint8_t* k_asme, uint8_t* sync, uint8_t* nh); + +uint8_t security_generate_k_nas(uint8_t* k_asme, + CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, + INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, + uint8_t* k_nas_enc, + uint8_t* k_nas_int); + +uint8_t security_generate_k_rrc(uint8_t* k_enb, + CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, + INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int); + +uint8_t security_generate_k_up(uint8_t* k_enb, + CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, + INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, + uint8_t* k_up_enc, + uint8_t* k_up_int); /****************************************************************************** * Integrity Protection *****************************************************************************/ -uint8_t security_128_eia1( - uint8_t* key, uint32_t count, uint32_t bearer, uint8_t direction, uint8_t* msg, uint32_t msg_len, uint8_t* mac); - -uint8_t security_128_eia2( - uint8_t* key, uint32_t count, uint32_t bearer, uint8_t direction, uint8_t* msg, uint32_t msg_len, uint8_t* mac); - -uint8_t security_128_eia3( - uint8_t* key, uint32_t count, uint32_t bearer, uint8_t direction, uint8_t* msg, uint32_t msg_len, uint8_t* mac); +uint8_t security_128_eia1(uint8_t* key, + uint32_t count, + uint32_t bearer, + uint8_t direction, + uint8_t* msg, + uint32_t msg_len, + uint8_t* mac); + +uint8_t security_128_eia2(uint8_t* key, + uint32_t count, + uint32_t bearer, + uint8_t direction, + uint8_t* msg, + uint32_t msg_len, + uint8_t* mac); + +uint8_t security_128_eia3(uint8_t* key, + uint32_t count, + uint32_t bearer, + uint8_t direction, + uint8_t* msg, + uint32_t msg_len, + uint8_t* mac); uint8_t security_md5(const uint8_t* input, size_t len, uint8_t* output); /****************************************************************************** * Encryption / Decryption *****************************************************************************/ -uint8_t security_128_eea1( - uint8_t* key, uint32_t count, uint8_t bearer, uint8_t direction, uint8_t* msg, uint32_t msg_len, uint8_t* msg_out); - -uint8_t security_128_eea2( - uint8_t* key, uint32_t count, uint8_t bearer, uint8_t direction, uint8_t* msg, uint32_t msg_len, uint8_t* msg_out); - -uint8_t security_128_eea3( - uint8_t* key, uint32_t count, uint8_t bearer, uint8_t direction, uint8_t* msg, uint32_t msg_len, uint8_t* msg_out); +uint8_t security_128_eea1(uint8_t* key, + uint32_t count, + uint8_t bearer, + uint8_t direction, + uint8_t* msg, + uint32_t msg_len, + uint8_t* msg_out); + +uint8_t security_128_eea2(uint8_t* key, + uint32_t count, + uint8_t bearer, + uint8_t direction, + uint8_t* msg, + uint32_t msg_len, + uint8_t* msg_out); + +uint8_t security_128_eea3(uint8_t* key, + uint32_t count, + uint8_t bearer, + uint8_t direction, + uint8_t* msg, + uint32_t msg_len, + uint8_t* msg_out); /****************************************************************************** * Authentication @@ -138,10 +164,7 @@ uint8_t security_milenage_f1_star(uint8_t* k, uint8_t* op, uint8_t* rand, uint8_ uint8_t security_milenage_f2345(uint8_t* k, uint8_t* op, uint8_t* rand, uint8_t* res, uint8_t* ck, uint8_t* ik, uint8_t* ak); -uint8_t security_milenage_f5_star( uint8_t *k, - uint8_t *op, - uint8_t *rand, - uint8_t *ak); +uint8_t security_milenage_f5_star(uint8_t* k, uint8_t* op, uint8_t* rand, uint8_t* ak); } // namespace srslte #endif // SRSLTE_SECURITY_H diff --git a/lib/include/srslte/common/snow_3g.h b/lib/include/srslte/common/snow_3g.h index d4c742bb7..7053621e2 100644 --- a/lib/include/srslte/common/snow_3g.h +++ b/lib/include/srslte/common/snow_3g.h @@ -1,74 +1,72 @@ /*--------------------------------------------------------- -* snow_3g.h -* -* Adapted from ETSI/SAGE specifications: -* "Specification of the 3GPP Confidentiality and -* Integrity Algorithms UEA2 & UIA2. -* Document 1: UEA2 and UIA2 Specification" -* "Specification of the 3GPP Confidentiality -* and Integrity Algorithms UEA2 & UIA2. -* Document 2: SNOW 3G Specification" -*---------------------------------------------------------*/ + * snow_3g.h + * + * Adapted from ETSI/SAGE specifications: + * "Specification of the 3GPP Confidentiality and + * Integrity Algorithms UEA2 & UIA2. + * Document 1: UEA2 and UIA2 Specification" + * "Specification of the 3GPP Confidentiality + * and Integrity Algorithms UEA2 & UIA2. + * Document 2: SNOW 3G Specification" + *---------------------------------------------------------*/ #ifndef SRSLTE_SNOW_3G_H #define SRSLTE_SNOW_3G_H +#include #include #include #include -#include -typedef unsigned char u8; -typedef unsigned int u32; +typedef unsigned char u8; +typedef unsigned int u32; typedef unsigned long long u64; /* Initialization. -* Input k[4]: Four 32-bit words making up 128-bit key. -* Input IV[4]: Four 32-bit words making 128-bit initialization variable. -* Output: All the LFSRs and FSM are initialized for key generation. -* See Section 4.1. -*/ + * Input k[4]: Four 32-bit words making up 128-bit key. + * Input IV[4]: Four 32-bit words making 128-bit initialization variable. + * Output: All the LFSRs and FSM are initialized for key generation. + * See Section 4.1. + */ void snow3g_initialize(u32 k[4], u32 IV[4]); /* Generation of Keystream. -* input n: number of 32-bit words of keystream. -* input z: space for the generated keystream, assumes -* memory is allocated already. -* output: generated keystream which is filled in z -* See section 4.2. -*/ + * input n: number of 32-bit words of keystream. + * input z: space for the generated keystream, assumes + * memory is allocated already. + * output: generated keystream which is filled in z + * See section 4.2. + */ -void snow3g_generate_keystream(u32 n, u32 *z); +void snow3g_generate_keystream(u32 n, u32* z); /* f8. -* Input key: 128 bit Confidentiality Key. -* Input count:32-bit Count, Frame dependent input. -* Input bearer: 5-bit Bearer identity (in the LSB side). -* Input dir:1 bit, direction of transmission. -* Input data: length number of bits, input bit stream. -* Input length: 32 bit Length, i.e., the number of bits to be encrypted or -* decrypted. -* Output data: Output bit stream. Assumes data is suitably memory -* allocated. -* Encrypts/decrypts blocks of data between 1 and 2^32 bits in length as -* defined in Section 3. -*/ + * Input key: 128 bit Confidentiality Key. + * Input count:32-bit Count, Frame dependent input. + * Input bearer: 5-bit Bearer identity (in the LSB side). + * Input dir:1 bit, direction of transmission. + * Input data: length number of bits, input bit stream. + * Input length: 32 bit Length, i.e., the number of bits to be encrypted or + * decrypted. + * Output data: Output bit stream. Assumes data is suitably memory + * allocated. + * Encrypts/decrypts blocks of data between 1 and 2^32 bits in length as + * defined in Section 3. + */ -void snow3g_f8( u8 *key, u32 count, u32 bearer, u32 dir, \ - u8 *data, u32 length ); +void snow3g_f8(u8* key, u32 count, u32 bearer, u32 dir, u8* data, u32 length); /* f9. -* Input key: 128 bit Integrity Key. -* Input count:32-bit Count, Frame dependent input. -* Input fresh: 32-bit Random number. -* Input dir:1 bit, direction of transmission (in the LSB). -* Input data: length number of bits, input bit stream. -* Input length: 64 bit Length, i.e., the number of bits to be MAC'd. -* Output : 32 bit block used as MAC -* Generates 32-bit MAC using UIA2 algorithm as defined in Section 4. -*/ + * Input key: 128 bit Integrity Key. + * Input count:32-bit Count, Frame dependent input. + * Input fresh: 32-bit Random number. + * Input dir:1 bit, direction of transmission (in the LSB). + * Input data: length number of bits, input bit stream. + * Input length: 64 bit Length, i.e., the number of bits to be MAC'd. + * Output : 32 bit block used as MAC + * Generates 32-bit MAC using UIA2 algorithm as defined in Section 4. + */ -u8* snow3g_f9( u8* key, u32 count, u32 fresh, u32 dir, \ - u8 *data, u64 length); +u8* snow3g_f9(u8* key, u32 count, u32 fresh, u32 dir, u8* data, u64 length); #endif // SRSLTE_SNOW_3G_H \ No newline at end of file diff --git a/lib/include/srslte/common/thread_pool.h b/lib/include/srslte/common/thread_pool.h index 595ae6935..3851b09ad 100644 --- a/lib/include/srslte/common/thread_pool.h +++ b/lib/include/srslte/common/thread_pool.h @@ -21,8 +21,8 @@ /****************************************************************************** * File: thread_pool.h - * Description: Implements a pool of threads. Pending tasks to execute are - * identified by a pointer. + * Description: Implements a pool of threads. Pending tasks to execute are + * identified by a pointer. * Reference: *****************************************************************************/ @@ -46,58 +46,51 @@ namespace srslte { class thread_pool { public: - class worker : public thread { public: worker(); - void setup(uint32_t id, thread_pool *parent, uint32_t prio=0, uint32_t mask = 255); + void setup(uint32_t id, thread_pool* parent, uint32_t prio = 0, uint32_t mask = 255); virtual void stop(); - uint32_t get_id(); - void release(); - protected: + uint32_t get_id(); + void release(); + + protected: virtual void work_imp() = 0; - private: - uint32_t my_id; - thread_pool *my_parent; - bool running; - void run_thread(); - void wait_to_start(); - void finished(); + + private: + uint32_t my_id; + thread_pool* my_parent; + bool running; + void run_thread(); + void wait_to_start(); + void finished(); }; - - - thread_pool(uint32_t nof_workers); - void init_worker(uint32_t id, worker*, uint32_t prio = 0, uint32_t mask = 255); - void stop(); - worker* wait_worker(); - worker* wait_worker(uint32_t tti); - worker* wait_worker_nb(uint32_t tti); - void start_worker(worker*); - void start_worker(uint32_t id); - worker* get_worker(uint32_t id); + + thread_pool(uint32_t nof_workers); + void init_worker(uint32_t id, worker*, uint32_t prio = 0, uint32_t mask = 255); + void stop(); + worker* wait_worker(); + worker* wait_worker(uint32_t tti); + worker* wait_worker_nb(uint32_t tti); + void start_worker(worker*); + void start_worker(uint32_t id); + worker* get_worker(uint32_t id); uint32_t get_nof_workers(); - private: - - bool find_finished_worker(uint32_t tti, uint32_t *id); - - typedef enum { - IDLE, - START_WORK, - WORKER_READY, - WORKING - }worker_status; - - std::vector workers; - uint32_t nof_workers; - uint32_t max_workers; - bool running; - pthread_cond_t cvar_queue; - pthread_mutex_t mutex_queue; - std::vector status; - std::vector cvar; + bool find_finished_worker(uint32_t tti, uint32_t* id); + + typedef enum { IDLE, START_WORK, WORKER_READY, WORKING } worker_status; + + std::vector workers; + uint32_t nof_workers; + uint32_t max_workers; + bool running; + pthread_cond_t cvar_queue; + pthread_mutex_t mutex_queue; + std::vector status; + std::vector cvar; std::vector mutex; std::stack available_workers; }; diff --git a/lib/include/srslte/common/threads.h b/lib/include/srslte/common/threads.h index cd1a9afc6..d931814e5 100644 --- a/lib/include/srslte/common/threads.h +++ b/lib/include/srslte/common/threads.h @@ -24,25 +24,25 @@ #include #include +#include #include #include -#include // Default priority for all threads below UHD threads #define DEFAULT_PRIORITY 60 #ifdef __cplusplus - extern "C" { +extern "C" { #endif // __cplusplus - bool threads_new_rt(pthread_t *thread, void *(*start_routine) (void*), void *arg); - bool threads_new_rt_prio(pthread_t *thread, void *(*start_routine) (void*), void *arg, int prio_offset); - bool threads_new_rt_cpu(pthread_t *thread, void *(*start_routine) (void*), void *arg, int cpu, int prio_offset); - bool threads_new_rt_mask(pthread_t *thread, void *(*start_routine) (void*), void *arg, int mask, int prio_offset); - void threads_print_self(); +bool threads_new_rt(pthread_t* thread, void* (*start_routine)(void*), void* arg); +bool threads_new_rt_prio(pthread_t* thread, void* (*start_routine)(void*), void* arg, int prio_offset); +bool threads_new_rt_cpu(pthread_t* thread, void* (*start_routine)(void*), void* arg, int cpu, int prio_offset); +bool threads_new_rt_mask(pthread_t* thread, void* (*start_routine)(void*), void* arg, int mask, int prio_offset); +void threads_print_self(); #ifdef __cplusplus - } +} #include @@ -62,7 +62,7 @@ public: thread& operator=(thread&&) noexcept = delete; bool start(int prio = -1) { return threads_new_rt_prio(&_thread, thread_function_entry, this, prio); } bool start_cpu(int prio, int cpu) { return threads_new_rt_cpu(&_thread, thread_function_entry, this, cpu, prio); } - bool start_cpu_mask(int prio, int mask) + bool start_cpu_mask(int prio, int mask) { return threads_new_rt_mask(&_thread, thread_function_entry, this, mask, prio); } @@ -72,12 +72,8 @@ public: name = name_; pthread_setname_np(pthread_self(), name.c_str()); } - void wait_thread_finish() { - pthread_join(_thread, NULL); - } - void thread_cancel() { - pthread_cancel(_thread); - } + void wait_thread_finish() { pthread_join(_thread, NULL); } + void thread_cancel() { pthread_cancel(_thread); } static std::string get_name() { @@ -104,56 +100,62 @@ private: std::string name; }; -class periodic_thread : public thread +class periodic_thread : public thread { public: periodic_thread(const std::string name_) : thread(name_) {} - void start_periodic(int period_us_, int priority = -1) { + void start_periodic(int period_us_, int priority = -1) + { run_enable = true; - period_us = period_us_; + period_us = period_us_; start(priority); } - void stop_thread() { + void stop_thread() + { run_enable = false; wait_thread_finish(); } -protected: - virtual void run_period() = 0; + +protected: + virtual void run_period() = 0; + private: - int wakeups_missed; - int timer_fd; - int period_us; + int wakeups_missed; + int timer_fd; + int period_us; bool run_enable; - void run_thread() { + void run_thread() + { if (make_periodic()) { return; } - while(run_enable) { + while (run_enable) { run_period(); if (run_enable) { wait_period(); } } } - int make_periodic() { - int ret = -1; - unsigned int ns; - unsigned int sec; + int make_periodic() + { + int ret = -1; + unsigned int ns; + unsigned int sec; struct itimerspec itval; /* Create the timer */ - ret = timerfd_create (CLOCK_MONOTONIC, 0); + ret = timerfd_create(CLOCK_MONOTONIC, 0); wakeups_missed = 0; - timer_fd = ret; + timer_fd = ret; if (ret > 0) { /* Make the timer periodic */ - sec = period_us/1e6; - ns = (period_us - (sec * 1000000)) * 1000; - itval.it_interval.tv_sec = sec; + sec = period_us / 1e6; + ns = (period_us - (sec * 1000000)) * 1000; + itval.it_interval.tv_sec = sec; itval.it_interval.tv_nsec = ns; - itval.it_value.tv_sec = sec; - itval.it_value.tv_nsec = ns; - ret = timerfd_settime (timer_fd, 0, &itval, NULL); + itval.it_value.tv_sec = sec; + itval.it_value.tv_nsec = ns; + ret = timerfd_settime(timer_fd, 0, &itval, NULL); if (ret < 0) { perror("timerfd_settime"); } @@ -162,16 +164,16 @@ private: } return ret; } - void wait_period() { + void wait_period() + { unsigned long long missed; - int ret; + int ret; /* Wait for the next timer event. If we have missed any the number is written to "missed" */ - ret = read (timer_fd, &missed, sizeof (missed)); - if (ret == -1) - { - perror ("read timer"); + ret = read(timer_fd, &missed, sizeof(missed)); + if (ret == -1) { + perror("read timer"); return; } @@ -180,7 +182,7 @@ private: wakeups_missed += (missed - 1); } } -}; +}; #endif // __cplusplus diff --git a/lib/include/srslte/common/timeout.h b/lib/include/srslte/common/timeout.h index 0ef03992e..0e45f0d54 100644 --- a/lib/include/srslte/common/timeout.h +++ b/lib/include/srslte/common/timeout.h @@ -29,32 +29,32 @@ #ifndef SRSLTE_TIMEOUT_H #define SRSLTE_TIMEOUT_H -#include +#include "srslte/srslte.h" #include -#include +#include #include -#include "srslte/srslte.h" +#include namespace srslte { - + class timeout_callback { - public: - virtual void timeout_expired(uint32_t timeout_id) = 0; -}; - +public: + virtual void timeout_expired(uint32_t timeout_id) = 0; +}; + class timeout { public: - timeout():running(false),callback(NULL), thread(0), timeout_id(0) {} + timeout() : running(false), callback(NULL), thread(0), timeout_id(0) {} ~timeout() { - if(running && callback) + if (running && callback) pthread_join(thread, NULL); } - void start(int duration_msec_, uint32_t timeout_id_=0,timeout_callback *callback_=NULL) + void start(int duration_msec_, uint32_t timeout_id_ = 0, timeout_callback* callback_ = NULL) { - if(duration_msec_ < 0) + if (duration_msec_ < 0) return; reset(); gettimeofday(&start_time[1], NULL); @@ -62,65 +62,63 @@ public: running = true; timeout_id = timeout_id_; callback = callback_; - if(callback) + if (callback) pthread_create(&thread, NULL, &thread_start, this); } void reset() { - if(callback) + if (callback) pthread_cancel(thread); running = false; } - static void* thread_start(void *t_) + static void* thread_start(void* t_) { - timeout *t = (timeout*)t_; + timeout* t = (timeout*)t_; t->thread_func(); - return NULL; + return NULL; } void thread_func() { // substract time elapsed until now from timer duration - gettimeofday(&start_time[2], NULL); + gettimeofday(&start_time[2], NULL); get_time_interval(start_time); - - int32_t usec = duration_msec*1000-start_time[0].tv_usec; - if(usec > 0) + + int32_t usec = duration_msec * 1000 - start_time[0].tv_usec; + if (usec > 0) usleep(usec); - if(callback && running) - callback->timeout_expired(timeout_id); + if (callback && running) + callback->timeout_expired(timeout_id); } bool expired() { - if(running) { - gettimeofday(&start_time[2], NULL); - get_time_interval(start_time); - return start_time[0].tv_usec > duration_msec*1000; + if (running) { + gettimeofday(&start_time[2], NULL); + get_time_interval(start_time); + return start_time[0].tv_usec > duration_msec * 1000; } else { return false; } } - int32_t get_msec_to_expire() { + int32_t get_msec_to_expire() + { if (running) { gettimeofday(&start_time[2], NULL); get_time_interval(start_time); - return (duration_msec*1000 - start_time[0].tv_usec)/1000; + return (duration_msec * 1000 - start_time[0].tv_usec) / 1000; } return 0; } - bool is_running() - { - return running; - } + bool is_running() { return running; } private: - struct timeval start_time[3]; - pthread_t thread; - uint32_t timeout_id; - timeout_callback *callback; - bool running; - int duration_msec; + struct timeval start_time[3]; + pthread_t thread; + uint32_t timeout_id; + timeout_callback* callback; + bool running; + int duration_msec; }; } // namespace srslte - + #endif // SRSLTE_TIMEOUT_H diff --git a/lib/include/srslte/common/trace.h b/lib/include/srslte/common/trace.h index f910bffe4..4839fac16 100644 --- a/lib/include/srslte/common/trace.h +++ b/lib/include/srslte/common/trace.h @@ -34,64 +34,67 @@ #include namespace srslte { - -template + +template class trace { public: - - trace(uint32_t nof_elems_) : tti(nof_elems_), data(nof_elems_) { - rpm=0; - nof_elems=nof_elems_; - wrapped = false; + trace(uint32_t nof_elems_) : tti(nof_elems_), data(nof_elems_) + { + rpm = 0; + nof_elems = nof_elems_; + wrapped = false; }; - void push_cur_time_us(uint32_t cur_tti) { - struct timeval t; - gettimeofday(&t, NULL); - elemType us = t.tv_sec*1e6+t.tv_usec; + void push_cur_time_us(uint32_t cur_tti) + { + struct timeval t; + gettimeofday(&t, NULL); + elemType us = t.tv_sec * 1e6 + t.tv_usec; push(cur_tti, us); } - void push(uint32_t value_tti, elemType value) { + void push(uint32_t value_tti, elemType value) + { tti[rpm] = value_tti; data[rpm] = value; rpm++; if (rpm >= nof_elems) { - rpm = 0; + rpm = 0; wrapped = true; } } - bool writeToBinary(std::string filename) { - FILE *f = fopen(filename.c_str(), "w"); + bool writeToBinary(std::string filename) + { + FILE* f = fopen(filename.c_str(), "w"); if (f != NULL) { - uint32_t st=wrapped?(rpm+1):0; + uint32_t st = wrapped ? (rpm + 1) : 0; do { - writeToBinaryValue(f, st++); + writeToBinaryValue(f, st++); if (st >= nof_elems) { - st=0; + st = 0; } - } while(st!=rpm); + } while (st != rpm); fclose(f); - return true; + return true; } else { perror("fopen"); - return false; + return false; } } - + private: std::vector tti; std::vector data; - uint32_t rpm; - uint32_t nof_elems; - bool wrapped; - - void writeToBinaryValue(FILE *f, uint32_t idx) { - fwrite(&tti[idx], 1, sizeof(uint32_t), f); + uint32_t rpm; + uint32_t nof_elems; + bool wrapped; + + void writeToBinaryValue(FILE* f, uint32_t idx) + { + fwrite(&tti[idx], 1, sizeof(uint32_t), f); fwrite(&data[idx], 1, sizeof(elemType), f); } - }; } // namespace srslte - + #endif // SRSLTE_TRACE_H diff --git a/lib/include/srslte/common/tti_sync.h b/lib/include/srslte/common/tti_sync.h index 1f91dcf75..8781597df 100644 --- a/lib/include/srslte/common/tti_sync.h +++ b/lib/include/srslte/common/tti_sync.h @@ -34,40 +34,39 @@ #include namespace srslte { - + class tti_sync { - public: - tti_sync(uint32_t modulus_) - { - modulus = modulus_; - increment = 1; - init_counters(0); - } - virtual void increase() = 0; - virtual void increase(uint32_t cnt) = 0; - virtual void resync() = 0; - virtual uint32_t wait() = 0; - virtual void set_producer_cntr(uint32_t) = 0; - uint32_t get_producer_cntr() { return producer_cntr; } - uint32_t get_consumer_cntr() { return consumer_cntr; } - void set_increment(uint32_t increment_) { - increment = increment_; - } - protected: - void increase_producer() { producer_cntr = (producer_cntr + increment)%modulus; } - void increase_producer(uint32_t cnt) { producer_cntr = cnt%modulus; } - void increase_consumer() { consumer_cntr = (consumer_cntr + increment)%modulus; } - bool wait_condition() { return producer_cntr == consumer_cntr; } - void init_counters(uint32_t val) - { - consumer_cntr = val; - producer_cntr = val; - } - uint32_t increment; - uint32_t modulus; - uint32_t producer_cntr; - uint32_t consumer_cntr; +public: + tti_sync(uint32_t modulus_) + { + modulus = modulus_; + increment = 1; + init_counters(0); + } + virtual void increase() = 0; + virtual void increase(uint32_t cnt) = 0; + virtual void resync() = 0; + virtual uint32_t wait() = 0; + virtual void set_producer_cntr(uint32_t) = 0; + uint32_t get_producer_cntr() { return producer_cntr; } + uint32_t get_consumer_cntr() { return consumer_cntr; } + void set_increment(uint32_t increment_) { increment = increment_; } + +protected: + void increase_producer() { producer_cntr = (producer_cntr + increment) % modulus; } + void increase_producer(uint32_t cnt) { producer_cntr = cnt % modulus; } + void increase_consumer() { consumer_cntr = (consumer_cntr + increment) % modulus; } + bool wait_condition() { return producer_cntr == consumer_cntr; } + void init_counters(uint32_t val) + { + consumer_cntr = val; + producer_cntr = val; + } + uint32_t increment; + uint32_t modulus; + uint32_t producer_cntr; + uint32_t consumer_cntr; }; } // namespace srslte diff --git a/lib/include/srslte/common/tti_sync_cv.h b/lib/include/srslte/common/tti_sync_cv.h index 7cb49b7d5..9a3bd8cdf 100644 --- a/lib/include/srslte/common/tti_sync_cv.h +++ b/lib/include/srslte/common/tti_sync_cv.h @@ -28,26 +28,26 @@ #ifndef SRSLTE_TTI_SYNC_CV_H #define SRSLTE_TTI_SYNC_CV_H -#include #include "srslte/common/tti_sync.h" +#include namespace srslte { - + class tti_sync_cv : public tti_sync { - public: - tti_sync_cv(uint32_t modulus = 10240); - ~tti_sync_cv(); - void increase(); - void increase(uint32_t cnt); - uint32_t wait(); - void resync(); - void set_producer_cntr(uint32_t producer_cntr); - - private: - pthread_cond_t cond; - pthread_mutex_t mutex; -}; +public: + tti_sync_cv(uint32_t modulus = 10240); + ~tti_sync_cv(); + void increase(); + void increase(uint32_t cnt); + uint32_t wait(); + void resync(); + void set_producer_cntr(uint32_t producer_cntr); + +private: + pthread_cond_t cond; + pthread_mutex_t mutex; +}; } // namespace srslte diff --git a/lib/include/srslte/config.h b/lib/include/srslte/config.h index dd5dd3538..795435744 100644 --- a/lib/include/srslte/config.h +++ b/lib/include/srslte/config.h @@ -24,32 +24,31 @@ // Generic helper definitions for shared library support #if defined _WIN32 || defined __CYGWIN__ - #define SRSLTE_IMPORT __declspec(dllimport) - #define SRSLTE_EXPORT __declspec(dllexport) - #define SRSLTE_LOCAL +#define SRSLTE_IMPORT __declspec(dllimport) +#define SRSLTE_EXPORT __declspec(dllexport) +#define SRSLTE_LOCAL #else - #if __GNUC__ >= 4 - #define SRSLTE_IMPORT __attribute__ ((visibility ("default"))) - #define SRSLTE_EXPORT __attribute__ ((visibility ("default"))) - #else - #define SRSLTE_IMPORT - #define SRSLTE_EXPORT - #define SRSLTE_LOCAL - #endif +#if __GNUC__ >= 4 +#define SRSLTE_IMPORT __attribute__((visibility("default"))) +#define SRSLTE_EXPORT __attribute__((visibility("default"))) +#else +#define SRSLTE_IMPORT +#define SRSLTE_EXPORT +#define SRSLTE_LOCAL +#endif #endif // Define SRSLTE_API // SRSLTE_API is used for the public API symbols. #ifdef SRSLTE_DLL_EXPORTS // defined if we are building the SRSLTE DLL (instead of using it) - #define SRSLTE_API SRSLTE_EXPORT +#define SRSLTE_API SRSLTE_EXPORT #else - #define SRSLTE_API SRSLTE_IMPORT +#define SRSLTE_API SRSLTE_IMPORT #endif - // Useful macros for templates #define CONCAT(a, b) a##b -#define CONCAT2(a, b) CONCAT(a,b) +#define CONCAT2(a, b) CONCAT(a, b) #define STRING2(x) #x #define STRING(x) STRING2(x) diff --git a/lib/include/srslte/interfaces/common_interfaces.h b/lib/include/srslte/interfaces/common_interfaces.h index 0d6538ec4..4caf18717 100644 --- a/lib/include/srslte/interfaces/common_interfaces.h +++ b/lib/include/srslte/interfaces/common_interfaces.h @@ -51,10 +51,10 @@ public: virtual void set_tx_freq(const uint32_t& radio_idx, const uint32_t& channel_idx, const double& freq) = 0; virtual void set_rx_freq(const uint32_t& radio_idx, const uint32_t& channel_idx, const double& freq) = 0; - virtual float set_rx_gain_th(const float& gain) = 0; - virtual void set_rx_gain(const uint32_t& radio_idx, const float& gain) = 0; - virtual void set_tx_srate(const uint32_t& radio_idx, const double& srate) = 0; - virtual void set_rx_srate(const uint32_t& radio_idx, const double& srate) = 0; + virtual float set_rx_gain_th(const float& gain) = 0; + virtual void set_rx_gain(const uint32_t& radio_idx, const float& gain) = 0; + virtual void set_tx_srate(const uint32_t& radio_idx, const double& srate) = 0; + virtual void set_rx_srate(const uint32_t& radio_idx, const double& srate) = 0; // getter virtual float get_rx_gain(const uint32_t& radio_idx) = 0; diff --git a/lib/include/srslte/interfaces/epc_interfaces.h b/lib/include/srslte/interfaces/epc_interfaces.h index f08a00150..6567a6a92 100644 --- a/lib/include/srslte/interfaces/epc_interfaces.h +++ b/lib/include/srslte/interfaces/epc_interfaces.h @@ -82,7 +82,7 @@ public: virtual bool resync_sqn(uint64_t imsi, uint8_t* auts) = 0; }; -class mme_interface_nas //NAS -> MME +class mme_interface_nas // NAS -> MME { public: virtual bool add_nas_timer(int timer_fd, enum nas_timer_type type, uint64_t imsi) = 0; @@ -90,7 +90,7 @@ public: virtual bool remove_nas_timer(enum nas_timer_type type, uint64_t imsi) = 0; }; -class s1ap_interface_mme //MME -> S1AP +class s1ap_interface_mme // MME -> S1AP { public: virtual bool expire_nas_timer(enum nas_timer_type type, uint64_t imsi) = 0; @@ -111,11 +111,11 @@ public: std::queue& pkt_queue) = 0; }; -class gtpc_interface_gtpu //GTP-U -> GTP-C +class gtpc_interface_gtpu // GTP-U -> GTP-C { public: - virtual bool queue_downlink_packet(uint32_t spgw_ctr_teid, srslte::byte_buffer_t *msg) = 0; - virtual bool send_downlink_data_notification(uint32_t spgw_ctr_teid) = 0; + virtual bool queue_downlink_packet(uint32_t spgw_ctr_teid, srslte::byte_buffer_t* msg) = 0; + virtual bool send_downlink_data_notification(uint32_t spgw_ctr_teid) = 0; }; } // namespace srsepc diff --git a/lib/include/srslte/interfaces/ue_interfaces.h b/lib/include/srslte/interfaces/ue_interfaces.h index f2fec0796..da2750a06 100644 --- a/lib/include/srslte/interfaces/ue_interfaces.h +++ b/lib/include/srslte/interfaces/ue_interfaces.h @@ -218,25 +218,25 @@ public: class pdcp_interface_rrc { public: - virtual void reestablish() = 0; - virtual void reestablish(uint32_t lcid) = 0; - virtual void reset() = 0; + virtual void reestablish() = 0; + virtual void reestablish(uint32_t lcid) = 0; + virtual void reset() = 0; virtual void write_sdu(uint32_t lcid, srslte::unique_byte_buffer_t sdu, bool blocking = false) = 0; - virtual void add_bearer(uint32_t lcid, srslte::pdcp_config_t cnfg) = 0; - virtual void change_lcid(uint32_t old_lcid, uint32_t new_lcid) = 0; + virtual void add_bearer(uint32_t lcid, srslte::pdcp_config_t cnfg) = 0; + virtual void change_lcid(uint32_t old_lcid, uint32_t new_lcid) = 0; virtual void config_security(uint32_t lcid, uint8_t* k_rrc_enc_, uint8_t* k_rrc_int_, uint8_t* k_up_enc_, srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo_, - srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo_) = 0; + srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo_) = 0; virtual void config_security_all(uint8_t* k_rrc_enc_, uint8_t* k_rrc_int_, uint8_t* k_up_enc_, srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo_, - srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo_) = 0; - virtual void enable_integrity(uint32_t lcid) = 0; - virtual void enable_encryption(uint32_t lcid) = 0; + srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo_) = 0; + virtual void enable_integrity(uint32_t lcid) = 0; + virtual void enable_encryption(uint32_t lcid) = 0; }; // PDCP interface for RLC diff --git a/lib/include/srslte/phy/agc/agc.h b/lib/include/srslte/phy/agc/agc.h index 4f0a88d58..fff8cf80d 100644 --- a/lib/include/srslte/phy/agc/agc.h +++ b/lib/include/srslte/phy/agc/agc.h @@ -31,40 +31,37 @@ #ifndef SRSLTE_AGC_H #define SRSLTE_AGC_H +#include #include #include -#include #include "srslte/config.h" #define SRSLTE_AGC_DEFAULT_TARGET 0.3 -#define SRSLTE_AGC_DEFAULT_BW 0.7 +#define SRSLTE_AGC_DEFAULT_BW 0.7 -typedef enum SRSLTE_API { - SRSLTE_AGC_MODE_ENERGY = 0, - SRSLTE_AGC_MODE_PEAK_AMPLITUDE -} srslte_agc_mode_t; +typedef enum SRSLTE_API { SRSLTE_AGC_MODE_ENERGY = 0, SRSLTE_AGC_MODE_PEAK_AMPLITUDE } srslte_agc_mode_t; -typedef struct SRSLTE_API{ +typedef struct SRSLTE_API { float bandwidth; float gain; float min_gain_db; float max_gain_db; float y_out; - bool lock; + bool lock; bool isfirst; void* uhd_handler; float (*set_gain_callback)(void*, float); - srslte_agc_mode_t mode; - float target; - uint32_t nof_frames; - uint32_t frame_cnt; - float *y_tmp; + srslte_agc_mode_t mode; + float target; + uint32_t nof_frames; + uint32_t frame_cnt; + float* y_tmp; } srslte_agc_t; -SRSLTE_API int srslte_agc_init(srslte_agc_t *q, srslte_agc_mode_t mode); +SRSLTE_API int srslte_agc_init(srslte_agc_t* q, srslte_agc_mode_t mode); -SRSLTE_API int srslte_agc_init_acc(srslte_agc_t *q, srslte_agc_mode_t mode, uint32_t nof_frames); +SRSLTE_API int srslte_agc_init_acc(srslte_agc_t* q, srslte_agc_mode_t mode, uint32_t nof_frames); SRSLTE_API int srslte_agc_init_uhd(srslte_agc_t* q, srslte_agc_mode_t mode, @@ -72,32 +69,26 @@ SRSLTE_API int srslte_agc_init_uhd(srslte_agc_t* q, float(set_gain_callback)(void*, float), void* uhd_handler); -SRSLTE_API void srslte_agc_free(srslte_agc_t *q); +SRSLTE_API void srslte_agc_free(srslte_agc_t* q); -SRSLTE_API void srslte_agc_reset(srslte_agc_t *q); +SRSLTE_API void srslte_agc_reset(srslte_agc_t* q); -SRSLTE_API void srslte_agc_set_gain_range(srslte_agc_t *q, float min_gain_db, float max_gain_db); +SRSLTE_API void srslte_agc_set_gain_range(srslte_agc_t* q, float min_gain_db, float max_gain_db); -SRSLTE_API void srslte_agc_set_bandwidth(srslte_agc_t *q, - float bandwidth); +SRSLTE_API void srslte_agc_set_bandwidth(srslte_agc_t* q, float bandwidth); -SRSLTE_API void srslte_agc_set_target(srslte_agc_t *q, - float target); +SRSLTE_API void srslte_agc_set_target(srslte_agc_t* q, float target); -SRSLTE_API float srslte_agc_get_rssi(srslte_agc_t *q); +SRSLTE_API float srslte_agc_get_rssi(srslte_agc_t* q); -SRSLTE_API float srslte_agc_get_output_level(srslte_agc_t *q); +SRSLTE_API float srslte_agc_get_output_level(srslte_agc_t* q); -SRSLTE_API float srslte_agc_get_gain(srslte_agc_t *q); +SRSLTE_API float srslte_agc_get_gain(srslte_agc_t* q); -SRSLTE_API void srslte_agc_set_gain(srslte_agc_t *q, - float init_gain_value_db); +SRSLTE_API void srslte_agc_set_gain(srslte_agc_t* q, float init_gain_value_db); -SRSLTE_API void srslte_agc_lock(srslte_agc_t *q, - bool enable); +SRSLTE_API void srslte_agc_lock(srslte_agc_t* q, bool enable); -SRSLTE_API void srslte_agc_process(srslte_agc_t *q, - cf_t *signal, - uint32_t len); +SRSLTE_API void srslte_agc_process(srslte_agc_t* q, cf_t* signal, uint32_t len); #endif // SRSLTE_AGC_H diff --git a/lib/include/srslte/phy/ch_estimation/chest_common.h b/lib/include/srslte/phy/ch_estimation/chest_common.h index 33c1a90e4..67918b406 100644 --- a/lib/include/srslte/phy/ch_estimation/chest_common.h +++ b/lib/include/srslte/phy/ch_estimation/chest_common.h @@ -22,8 +22,8 @@ #ifndef SRSLTE_CHEST_COMMON_H #define SRSLTE_CHEST_COMMON_H -#include #include "srslte/config.h" +#include #define SRSLTE_CHEST_MAX_SMOOTH_FIL_LEN 64 @@ -33,8 +33,12 @@ typedef enum SRSLTE_API { SRSLTE_CHEST_FILTER_NONE } srslte_chest_filter_t; -SRSLTE_API void srslte_chest_average_pilots( - cf_t* input, cf_t* output, float* filter, uint32_t nof_ref, uint32_t nof_symbols, uint32_t filter_len); +SRSLTE_API void srslte_chest_average_pilots(cf_t* input, + cf_t* output, + float* filter, + uint32_t nof_ref, + uint32_t nof_symbols, + uint32_t filter_len); SRSLTE_API uint32_t srslte_chest_set_smooth_filter3_coeff(float* smooth_filter, float w); diff --git a/lib/include/srslte/phy/ch_estimation/chest_dl.h b/lib/include/srslte/phy/ch_estimation/chest_dl.h index 6bbc33925..ad2829ae8 100644 --- a/lib/include/srslte/phy/ch_estimation/chest_dl.h +++ b/lib/include/srslte/phy/ch_estimation/chest_dl.h @@ -41,9 +41,9 @@ #include "srslte/config.h" #include "srslte/phy/ch_estimation/chest_common.h" -#include "srslte/phy/resampling/interp.h" #include "srslte/phy/ch_estimation/refsignal_dl.h" #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/resampling/interp.h" #include "srslte/phy/sync/pss.h" typedef struct SRSLTE_API { @@ -77,25 +77,25 @@ typedef struct SRSLTE_API { uint32_t nof_rx_antennas; srslte_refsignal_t csr_refs; - srslte_refsignal_t **mbsfn_refs; + srslte_refsignal_t** mbsfn_refs; - cf_t *pilot_estimates; - cf_t *pilot_estimates_average; - cf_t *pilot_recv_signal; - cf_t *tmp_noise; - cf_t *tmp_cfo_estimate; + cf_t* pilot_estimates; + cf_t* pilot_estimates_average; + cf_t* pilot_recv_signal; + cf_t* tmp_noise; + cf_t* tmp_cfo_estimate; -#ifdef FREQ_SEL_SNR +#ifdef FREQ_SEL_SNR float snr_vector[12000]; float pilot_power[12000]; #endif - srslte_interp_linsrslte_vec_t srslte_interp_linvec; - srslte_interp_lin_t srslte_interp_lin; - srslte_interp_lin_t srslte_interp_lin_3; - srslte_interp_lin_t srslte_interp_lin_mbsfn; + srslte_interp_linsrslte_vec_t srslte_interp_linvec; + srslte_interp_lin_t srslte_interp_lin; + srslte_interp_lin_t srslte_interp_lin_3; + srslte_interp_lin_t srslte_interp_lin_mbsfn; - float rssi[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; + float rssi[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; float rsrp[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; float rsrp_corr[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; float noise_estimate[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; @@ -106,7 +106,7 @@ typedef struct SRSLTE_API { cf_t pss_signal[SRSLTE_PSS_LEN]; cf_t tmp_pss[SRSLTE_PSS_LEN]; cf_t tmp_pss_noisy[SRSLTE_PSS_LEN]; - + } srslte_chest_dl_t; typedef struct SRSLTE_API { diff --git a/lib/include/srslte/phy/ch_estimation/chest_ul.h b/lib/include/srslte/phy/ch_estimation/chest_ul.h index 667de147d..0915870e8 100644 --- a/lib/include/srslte/phy/ch_estimation/chest_ul.h +++ b/lib/include/srslte/phy/ch_estimation/chest_ul.h @@ -56,34 +56,32 @@ typedef struct SRSLTE_API { } srslte_chest_ul_res_t; typedef struct { - srslte_cell_t cell; - + srslte_cell_t cell; + srslte_refsignal_ul_t dmrs_signal; - srslte_refsignal_ul_dmrs_pregen_t dmrs_pregen; - bool dmrs_signal_configured; - - cf_t *pilot_estimates; - cf_t *pilot_estimates_tmp[4]; - cf_t *pilot_recv_signal; - cf_t *pilot_known_signal; - cf_t *tmp_noise; - -#ifdef FREQ_SEL_SNR + srslte_refsignal_ul_dmrs_pregen_t dmrs_pregen; + bool dmrs_signal_configured; + + cf_t* pilot_estimates; + cf_t* pilot_estimates_tmp[4]; + cf_t* pilot_recv_signal; + cf_t* pilot_known_signal; + cf_t* tmp_noise; + +#ifdef FREQ_SEL_SNR float snr_vector[12000]; float pilot_power[12000]; #endif - uint32_t smooth_filter_len; - float smooth_filter[SRSLTE_CHEST_MAX_SMOOTH_FIL_LEN]; + uint32_t smooth_filter_len; + float smooth_filter[SRSLTE_CHEST_MAX_SMOOTH_FIL_LEN]; srslte_interp_linsrslte_vec_t srslte_interp_linvec; } srslte_chest_ul_t; +SRSLTE_API int srslte_chest_ul_init(srslte_chest_ul_t* q, uint32_t max_prb); -SRSLTE_API int srslte_chest_ul_init(srslte_chest_ul_t *q, - uint32_t max_prb); - -SRSLTE_API void srslte_chest_ul_free(srslte_chest_ul_t *q); +SRSLTE_API void srslte_chest_ul_free(srslte_chest_ul_t* q); SRSLTE_API int srslte_chest_ul_res_init(srslte_chest_ul_res_t* q, uint32_t max_prb); @@ -95,10 +93,16 @@ SRSLTE_API int srslte_chest_ul_set_cell(srslte_chest_ul_t* q, srslte_cell_t cell SRSLTE_API void srslte_chest_ul_pregen(srslte_chest_ul_t* q, srslte_refsignal_dmrs_pusch_cfg_t* cfg); -SRSLTE_API int srslte_chest_ul_estimate_pusch( - srslte_chest_ul_t* q, srslte_ul_sf_cfg_t* sf, srslte_pusch_cfg_t* cfg, cf_t* input, srslte_chest_ul_res_t* res); - -SRSLTE_API int srslte_chest_ul_estimate_pucch( - srslte_chest_ul_t* q, srslte_ul_sf_cfg_t* sf, srslte_pucch_cfg_t* cfg, cf_t* input, srslte_chest_ul_res_t* res); +SRSLTE_API int srslte_chest_ul_estimate_pusch(srslte_chest_ul_t* q, + srslte_ul_sf_cfg_t* sf, + srslte_pusch_cfg_t* cfg, + cf_t* input, + srslte_chest_ul_res_t* res); + +SRSLTE_API int srslte_chest_ul_estimate_pucch(srslte_chest_ul_t* q, + srslte_ul_sf_cfg_t* sf, + srslte_pucch_cfg_t* cfg, + cf_t* input, + srslte_chest_ul_res_t* res); #endif // SRSLTE_CHEST_UL_H diff --git a/lib/include/srslte/phy/ch_estimation/refsignal_dl.h b/lib/include/srslte/phy/ch_estimation/refsignal_dl.h index 98daa4476..e074a0496 100644 --- a/lib/include/srslte/phy/ch_estimation/refsignal_dl.h +++ b/lib/include/srslte/phy/ch_estimation/refsignal_dl.h @@ -34,16 +34,14 @@ #include "srslte/phy/common/phy_common.h" // Number of references in a subframe: there are 2 symbols for port_id=0,1 x 2 slots x 2 refs per prb -#define SRSLTE_REFSIGNAL_NUM_SF_MBSFN(nof_prb, port_id) ((2 + 18)*(nof_prb)) +#define SRSLTE_REFSIGNAL_NUM_SF_MBSFN(nof_prb, port_id) ((2 + 18) * (nof_prb)) #define SRSLTE_REFSIGNAL_MAX_NUM_SF(nof_prb) (8 * nof_prb) -#define SRSLTE_REFSIGNAL_MAX_NUM_SF_MBSFN(nof_prb) SRSLTE_REFSIGNAL_NUM_SF_MBSFN(nof_prb,0) - -#define SRSLTE_REFSIGNAL_PILOT_IDX(i,l,cell) (2*cell.nof_prb*(l)+(i)) - -#define SRSLTE_REFSIGNAL_PILOT_IDX_MBSFN(i,l,cell) ((6*cell.nof_prb*(l)+(i))) +#define SRSLTE_REFSIGNAL_MAX_NUM_SF_MBSFN(nof_prb) SRSLTE_REFSIGNAL_NUM_SF_MBSFN(nof_prb, 0) +#define SRSLTE_REFSIGNAL_PILOT_IDX(i, l, cell) (2 * cell.nof_prb * (l) + (i)) +#define SRSLTE_REFSIGNAL_PILOT_IDX_MBSFN(i, l, cell) ((6 * cell.nof_prb * (l) + (i))) /** Cell-Specific Reference Signal */ typedef struct SRSLTE_API { @@ -53,26 +51,24 @@ typedef struct SRSLTE_API { uint16_t mbsfn_area_id; } srslte_refsignal_t; +SRSLTE_API int srslte_refsignal_cs_init(srslte_refsignal_t* q, uint32_t max_prb); -SRSLTE_API int srslte_refsignal_cs_init(srslte_refsignal_t *q, - uint32_t max_prb); +SRSLTE_API int srslte_refsignal_cs_set_cell(srslte_refsignal_t* q, srslte_cell_t cell); -SRSLTE_API int srslte_refsignal_cs_set_cell(srslte_refsignal_t * q, - srslte_cell_t cell); - -SRSLTE_API void srslte_refsignal_free(srslte_refsignal_t *q); +SRSLTE_API void srslte_refsignal_free(srslte_refsignal_t* q); SRSLTE_API int srslte_refsignal_cs_put_sf(srslte_refsignal_t* q, srslte_dl_sf_cfg_t* sf, uint32_t port_id, cf_t* sf_symbols); -SRSLTE_API int srslte_refsignal_cs_get_sf( - srslte_refsignal_t* q, srslte_dl_sf_cfg_t* sf, uint32_t port_id, cf_t* sf_symbols, cf_t* pilots); +SRSLTE_API int srslte_refsignal_cs_get_sf(srslte_refsignal_t* q, + srslte_dl_sf_cfg_t* sf, + uint32_t port_id, + cf_t* sf_symbols, + cf_t* pilots); SRSLTE_API uint32_t srslte_refsignal_cs_fidx(srslte_cell_t cell, uint32_t l, uint32_t port_id, uint32_t m); -SRSLTE_API uint32_t srslte_refsignal_cs_nsymbol(uint32_t l, - srslte_cp_t cp, - uint32_t port_id); +SRSLTE_API uint32_t srslte_refsignal_cs_nsymbol(uint32_t l, srslte_cp_t cp, uint32_t port_id); SRSLTE_API uint32_t srslte_refsignal_cs_v(uint32_t port_id, uint32_t ref_symbol_idx); @@ -80,7 +76,7 @@ SRSLTE_API uint32_t srslte_refsignal_cs_nof_symbols(srslte_refsignal_t* q, srslt SRSLTE_API uint32_t srslte_refsignal_cs_nof_re(srslte_refsignal_t* q, srslte_dl_sf_cfg_t* sf, uint32_t port_id); -SRSLTE_API int srslte_refsignal_mbsfn_init(srslte_refsignal_t *q, uint32_t max_prb); +SRSLTE_API int srslte_refsignal_mbsfn_init(srslte_refsignal_t* q, uint32_t max_prb); SRSLTE_API int srslte_refsignal_mbsfn_set_cell(srslte_refsignal_t* q, srslte_cell_t cell, uint16_t mbsfn_area_id); @@ -93,14 +89,11 @@ SRSLTE_API uint32_t srslte_refsignal_mbsfn_fidx(uint32_t l); SRSLTE_API uint32_t srslte_refsignal_mbsfn_nof_symbols(); SRSLTE_API int srslte_refsignal_mbsfn_put_sf(srslte_cell_t cell, - uint32_t port_id, - cf_t *cs_pilots, - cf_t *mbsfn_pilots, - cf_t *sf_symbols); - -SRSLTE_API int srslte_refsignal_mbsfn_gen_seq(srslte_refsignal_t * q, - srslte_cell_t cell, - uint32_t N_mbsfn_id); + uint32_t port_id, + cf_t* cs_pilots, + cf_t* mbsfn_pilots, + cf_t* sf_symbols); +SRSLTE_API int srslte_refsignal_mbsfn_gen_seq(srslte_refsignal_t* q, srslte_cell_t cell, uint32_t N_mbsfn_id); #endif // SRSLTE_REFSIGNAL_DL_H diff --git a/lib/include/srslte/phy/ch_estimation/refsignal_ul.h b/lib/include/srslte/phy/ch_estimation/refsignal_ul.h index 37f1a6b97..79998d2b9 100644 --- a/lib/include/srslte/phy/ch_estimation/refsignal_ul.h +++ b/lib/include/srslte/phy/ch_estimation/refsignal_ul.h @@ -35,18 +35,18 @@ #include "srslte/phy/phch/pucch_cfg.h" #include "srslte/phy/phch/pusch_cfg.h" -#define SRSLTE_NOF_GROUPS_U 30 +#define SRSLTE_NOF_GROUPS_U 30 #define SRSLTE_NOF_SEQUENCES_U 2 -#define SRSLTE_NOF_DELTA_SS 30 -#define SRSLTE_NOF_CSHIFT 8 +#define SRSLTE_NOF_DELTA_SS 30 +#define SRSLTE_NOF_CSHIFT 8 -#define SRSLTE_REFSIGNAL_UL_L(ns_idx, cp) ((ns_idx+1)*SRSLTE_CP_NSYMB(cp)-4) +#define SRSLTE_REFSIGNAL_UL_L(ns_idx, cp) ((ns_idx + 1) * SRSLTE_CP_NSYMB(cp) - 4) /* PUSCH DMRS common configuration (received in SIB2) */ typedef struct SRSLTE_API { - uint32_t cyclic_shift; - uint32_t delta_ss; - bool group_hopping_en; + uint32_t cyclic_shift; + uint32_t delta_ss; + bool group_hopping_en; bool sequence_hopping_en; } srslte_refsignal_dmrs_pusch_cfg_t; @@ -57,12 +57,12 @@ typedef struct SRSLTE_API { uint32_t bw_cfg; bool simul_ack; - // Dedicated configuration - uint32_t B; - uint32_t b_hop; - uint32_t n_srs; - uint32_t I_srs; - uint32_t k_tc; + // Dedicated configuration + uint32_t B; + uint32_t b_hop; + uint32_t n_srs; + uint32_t I_srs; + uint32_t k_tc; uint32_t n_rrc; bool dedicated_enabled; bool common_enabled; @@ -75,8 +75,9 @@ typedef struct SRSLTE_API { float* tmp_arg; - uint32_t n_cs_cell[SRSLTE_NSLOTS_X_FRAME][SRSLTE_CP_NORM_NSYMB]; - uint32_t n_prs_pusch[SRSLTE_NOF_DELTA_SS][SRSLTE_NSLOTS_X_FRAME]; // We precompute n_prs needed for cyclic shift alpha at srslte_refsignal_dl_init() + uint32_t n_cs_cell[SRSLTE_NSLOTS_X_FRAME][SRSLTE_CP_NORM_NSYMB]; + uint32_t n_prs_pusch[SRSLTE_NOF_DELTA_SS][SRSLTE_NSLOTS_X_FRAME]; // We precompute n_prs needed for cyclic shift alpha + // at srslte_refsignal_dl_init() uint32_t f_gh[SRSLTE_NSLOTS_X_FRAME]; uint32_t u_pucch[SRSLTE_NSLOTS_X_FRAME]; uint32_t v_pusch[SRSLTE_NSLOTS_X_FRAME][SRSLTE_NOF_DELTA_SS]; @@ -90,13 +91,11 @@ typedef struct { cf_t* r[SRSLTE_NOF_SF_X_FRAME]; } srslte_refsignal_srs_pregen_t; -SRSLTE_API int srslte_refsignal_ul_init(srslte_refsignal_ul_t *q, - uint32_t max_prb); +SRSLTE_API int srslte_refsignal_ul_init(srslte_refsignal_ul_t* q, uint32_t max_prb); -SRSLTE_API int srslte_refsignal_ul_set_cell(srslte_refsignal_ul_t *q, - srslte_cell_t cell); +SRSLTE_API int srslte_refsignal_ul_set_cell(srslte_refsignal_ul_t* q, srslte_cell_t cell); -SRSLTE_API void srslte_refsignal_ul_free(srslte_refsignal_ul_t *q); +SRSLTE_API void srslte_refsignal_ul_free(srslte_refsignal_ul_t* q); SRSLTE_API void srslte_refsignal_r_uv_arg_1prb(float* arg, uint32_t u); @@ -166,8 +165,11 @@ SRSLTE_API int srslte_refsignal_srs_gen(srslte_refsignal_ul_t* q, uint32_t sf_idx, cf_t* r_srs); -SRSLTE_API int srslte_refsignal_srs_put( - srslte_refsignal_ul_t* q, srslte_refsignal_srs_cfg_t* cfg, uint32_t tti, cf_t* r_srs, cf_t* sf_symbols); +SRSLTE_API int srslte_refsignal_srs_put(srslte_refsignal_ul_t* q, + srslte_refsignal_srs_cfg_t* cfg, + uint32_t tti, + cf_t* r_srs, + cf_t* sf_symbols); SRSLTE_API void srslte_refsignal_srs_pusch_shortened(srslte_refsignal_ul_t* q, srslte_ul_sf_cfg_t* sf, diff --git a/lib/include/srslte/phy/channel/ch_awgn.h b/lib/include/srslte/phy/channel/ch_awgn.h index 83fe9b417..31b407589 100644 --- a/lib/include/srslte/phy/channel/ch_awgn.h +++ b/lib/include/srslte/phy/channel/ch_awgn.h @@ -35,18 +35,10 @@ #ifndef SRSLTE_CH_AWGN_H #define SRSLTE_CH_AWGN_H -SRSLTE_API void srslte_ch_awgn_c(const cf_t* input, - cf_t* output, - float variance, - uint32_t len); +SRSLTE_API void srslte_ch_awgn_c(const cf_t* input, cf_t* output, float variance, uint32_t len); -SRSLTE_API void srslte_ch_awgn_f(const float* x, - float* y, - float variance, - uint32_t len); - -SRSLTE_API float srslte_ch_awgn_get_variance(float ebno_db, - float rate); +SRSLTE_API void srslte_ch_awgn_f(const float* x, float* y, float variance, uint32_t len); +SRSLTE_API float srslte_ch_awgn_get_variance(float ebno_db, float rate); #endif // SRSLTE_CH_AWGN_H diff --git a/lib/include/srslte/phy/channel/delay.h b/lib/include/srslte/phy/channel/delay.h index d6130c4b9..4a49591d2 100644 --- a/lib/include/srslte/phy/channel/delay.h +++ b/lib/include/srslte/phy/channel/delay.h @@ -53,8 +53,11 @@ SRSLTE_API void srslte_channel_delay_update_srate(srslte_channel_delay_t* q, uin SRSLTE_API void srslte_channel_delay_free(srslte_channel_delay_t* q); -SRSLTE_API void srslte_channel_delay_execute( - srslte_channel_delay_t* q, const cf_t* in, cf_t* out, uint32_t len, const srslte_timestamp_t* ts); +SRSLTE_API void srslte_channel_delay_execute(srslte_channel_delay_t* q, + const cf_t* in, + cf_t* out, + uint32_t len, + const srslte_timestamp_t* ts); #ifdef __cplusplus } diff --git a/lib/include/srslte/phy/channel/fading.h b/lib/include/srslte/phy/channel/fading.h index fda3b26d3..ef653c3a7 100644 --- a/lib/include/srslte/phy/channel/fading.h +++ b/lib/include/srslte/phy/channel/fading.h @@ -66,8 +66,11 @@ SRSLTE_API int srslte_channel_fading_init(srslte_channel_fading_t* q, double sra SRSLTE_API void srslte_channel_fading_free(srslte_channel_fading_t* q); -SRSLTE_API double srslte_channel_fading_execute( - srslte_channel_fading_t* q, const cf_t* in, cf_t* out, uint32_t nof_samples, double init_time); +SRSLTE_API double srslte_channel_fading_execute(srslte_channel_fading_t* q, + const cf_t* in, + cf_t* out, + uint32_t nof_samples, + double init_time); #ifdef __cplusplus } diff --git a/lib/include/srslte/phy/channel/rlf.h b/lib/include/srslte/phy/channel/rlf.h index 48b1e7f45..51bbb678e 100644 --- a/lib/include/srslte/phy/channel/rlf.h +++ b/lib/include/srslte/phy/channel/rlf.h @@ -35,8 +35,11 @@ extern "C" { SRSLTE_API void srslte_channel_rlf_init(srslte_channel_rlf_t* q, uint32_t t_on_ms, uint32_t t_off_ms); -SRSLTE_API void srslte_channel_rlf_execute( - srslte_channel_rlf_t* q, const cf_t* in, cf_t* out, uint32_t nsamples, const srslte_timestamp_t* ts); +SRSLTE_API void srslte_channel_rlf_execute(srslte_channel_rlf_t* q, + const cf_t* in, + cf_t* out, + uint32_t nsamples, + const srslte_timestamp_t* ts); SRSLTE_API void srslte_channel_rlf_free(srslte_channel_rlf_t* q); diff --git a/lib/include/srslte/phy/common/phy_common.h b/lib/include/srslte/phy/common/phy_common.h index c747a4448..74a947b83 100644 --- a/lib/include/srslte/phy/common/phy_common.h +++ b/lib/include/srslte/phy/common/phy_common.h @@ -30,10 +30,10 @@ #ifndef SRSLTE_PHY_COMMON_H #define SRSLTE_PHY_COMMON_H -#include -#include -#include #include +#include +#include +#include #include "srslte/config.h" @@ -41,39 +41,39 @@ #define SRSLTE_NOF_SLOTS_PER_SF 2 #define SRSLTE_NSLOTS_X_FRAME (SRSLTE_NOF_SLOTS_PER_SF * SRSLTE_NOF_SF_X_FRAME) -#define SRSLTE_NSOFT_BITS 250368 // Soft buffer size for Category 1 UE +#define SRSLTE_NSOFT_BITS 250368 // Soft buffer size for Category 1 UE -#define SRSLTE_PC_MAX 23 // Maximum TX power for Category 1 UE (in dBm) +#define SRSLTE_PC_MAX 23 // Maximum TX power for Category 1 UE (in dBm) #define SRSLTE_MAX_RADIOS 3 // Maximum number of supported RF devices #define SRSLTE_MAX_CARRIERS 5 // Maximum number of supported simultaneous carriers -#define SRSLTE_MAX_PORTS 4 -#define SRSLTE_MAX_LAYERS 4 +#define SRSLTE_MAX_PORTS 4 +#define SRSLTE_MAX_LAYERS 4 #define SRSLTE_MAX_CODEWORDS 2 -#define SRSLTE_MAX_TB SRSLTE_MAX_CODEWORDS +#define SRSLTE_MAX_TB SRSLTE_MAX_CODEWORDS #define SRSLTE_MAX_CODEBLOCKS 32 #define SRSLTE_MAX_CODEBOOKS 4 -#define SRSLTE_LTE_CRC24A 0x1864CFB -#define SRSLTE_LTE_CRC24B 0X1800063 -#define SRSLTE_LTE_CRC16 0x11021 -#define SRSLTE_LTE_CRC8 0x19B +#define SRSLTE_LTE_CRC24A 0x1864CFB +#define SRSLTE_LTE_CRC24B 0X1800063 +#define SRSLTE_LTE_CRC16 0x11021 +#define SRSLTE_LTE_CRC8 0x19B #define SRSLTE_MAX_MBSFN_AREA_IDS 256 -#define SRSLTE_PMCH_RV 0 +#define SRSLTE_PMCH_RV 0 typedef enum { SRSLTE_CP_NORM = 0, SRSLTE_CP_EXT } srslte_cp_t; typedef enum { SRSLTE_SF_NORM = 0, SRSLTE_SF_MBSFN } srslte_sf_t; -#define SRSLTE_CRNTI_START 0x000B -#define SRSLTE_CRNTI_END 0xFFF3 +#define SRSLTE_CRNTI_START 0x000B +#define SRSLTE_CRNTI_END 0xFFF3 #define SRSLTE_RARNTI_START 0x0001 -#define SRSLTE_RARNTI_END 0x000A -#define SRSLTE_SIRNTI 0xFFFF -#define SRSLTE_PRNTI 0xFFFE -#define SRSLTE_MRNTI 0xFFFD +#define SRSLTE_RARNTI_END 0x000A +#define SRSLTE_SIRNTI 0xFFFF +#define SRSLTE_PRNTI 0xFFFE +#define SRSLTE_MRNTI 0xFFFD #define SRSLTE_RNTI_ISRAR(rnti) (rnti >= SRSLTE_RARNTI_START && rnti <= SRSLTE_RARNTI_END) #define SRSLTE_RNTI_ISUSER(rnti) (rnti >= SRSLTE_CRNTI_START && rnti <= SRSLTE_CRNTI_END) @@ -84,30 +84,31 @@ typedef enum { SRSLTE_SF_NORM = 0, SRSLTE_SF_MBSFN } srslte_sf_t; #define SRSLTE_CELL_ID_UNKNOWN 1000 -#define SRSLTE_MAX_NSYMB 7 +#define SRSLTE_MAX_NSYMB 7 -#define SRSLTE_MAX_PRB 110 -#define SRSLTE_NRE 12 +#define SRSLTE_MAX_PRB 110 +#define SRSLTE_NRE 12 -#define SRSLTE_SYMBOL_SZ_MAX 2048 +#define SRSLTE_SYMBOL_SZ_MAX 2048 -#define SRSLTE_CP_NORM_NSYMB 7 -#define SRSLTE_CP_NORM_SF_NSYMB (2*SRSLTE_CP_NORM_NSYMB) -#define SRSLTE_CP_NORM_0_LEN 160 -#define SRSLTE_CP_NORM_LEN 144 +#define SRSLTE_CP_NORM_NSYMB 7 +#define SRSLTE_CP_NORM_SF_NSYMB (2 * SRSLTE_CP_NORM_NSYMB) +#define SRSLTE_CP_NORM_0_LEN 160 +#define SRSLTE_CP_NORM_LEN 144 -#define SRSLTE_CP_EXT_NSYMB 6 -#define SRSLTE_CP_EXT_SF_NSYMB (2*SRSLTE_CP_EXT_NSYMB) -#define SRSLTE_CP_EXT_LEN 512 -#define SRSLTE_CP_EXT_7_5_LEN 1024 +#define SRSLTE_CP_EXT_NSYMB 6 +#define SRSLTE_CP_EXT_SF_NSYMB (2 * SRSLTE_CP_EXT_NSYMB) +#define SRSLTE_CP_EXT_LEN 512 +#define SRSLTE_CP_EXT_7_5_LEN 1024 -#define SRSLTE_CP_ISNORM(cp) (cp==SRSLTE_CP_NORM) -#define SRSLTE_CP_ISEXT(cp) (cp==SRSLTE_CP_EXT) -#define SRSLTE_CP_NSYMB(cp) (SRSLTE_CP_ISNORM(cp)?SRSLTE_CP_NORM_NSYMB:SRSLTE_CP_EXT_NSYMB) +#define SRSLTE_CP_ISNORM(cp) (cp == SRSLTE_CP_NORM) +#define SRSLTE_CP_ISEXT(cp) (cp == SRSLTE_CP_EXT) +#define SRSLTE_CP_NSYMB(cp) (SRSLTE_CP_ISNORM(cp) ? SRSLTE_CP_NORM_NSYMB : SRSLTE_CP_EXT_NSYMB) -#define SRSLTE_CP_LEN(symbol_sz, c) ((int) ceilf((((float) (c)*(symbol_sz))/2048.0f))) -#define SRSLTE_CP_LEN_NORM(symbol, symbol_sz) (((symbol)==0)?SRSLTE_CP_LEN((symbol_sz),SRSLTE_CP_NORM_0_LEN):SRSLTE_CP_LEN((symbol_sz),SRSLTE_CP_NORM_LEN)) -#define SRSLTE_CP_LEN_EXT(symbol_sz) (SRSLTE_CP_LEN((symbol_sz),SRSLTE_CP_EXT_LEN)) +#define SRSLTE_CP_LEN(symbol_sz, c) ((int)ceilf((((float)(c) * (symbol_sz)) / 2048.0f))) +#define SRSLTE_CP_LEN_NORM(symbol, symbol_sz) \ + (((symbol) == 0) ? SRSLTE_CP_LEN((symbol_sz), SRSLTE_CP_NORM_0_LEN) : SRSLTE_CP_LEN((symbol_sz), SRSLTE_CP_NORM_LEN)) +#define SRSLTE_CP_LEN_EXT(symbol_sz) (SRSLTE_CP_LEN((symbol_sz), SRSLTE_CP_EXT_LEN)) #define SRSLTE_CP_SZ(symbol_sz, cp) \ (SRSLTE_CP_LEN(symbol_sz, (SRSLTE_CP_ISNORM(cp) ? SRSLTE_CP_NORM_LEN : SRSLTE_CP_EXT_LEN))) @@ -116,52 +117,52 @@ typedef enum { SRSLTE_SF_NORM = 0, SRSLTE_SF_MBSFN } srslte_sf_t; #define SRSLTE_SF_LEN(symbol_sz) (symbol_sz * 15) #define SRSLTE_SF_LEN_MAX (SRSLTE_SF_LEN(SRSLTE_SYMBOL_SZ_MAX)) -#define SRSLTE_SLOT_LEN_PRB(nof_prb) (SRSLTE_SLOT_LEN(srslte_symbol_sz(nof_prb))) -#define SRSLTE_SF_LEN_PRB(nof_prb) (SRSLTE_SF_LEN(srslte_symbol_sz(nof_prb))) +#define SRSLTE_SLOT_LEN_PRB(nof_prb) (SRSLTE_SLOT_LEN(srslte_symbol_sz(nof_prb))) +#define SRSLTE_SF_LEN_PRB(nof_prb) (SRSLTE_SF_LEN(srslte_symbol_sz(nof_prb))) -#define SRSLTE_SLOT_LEN_RE(nof_prb, cp) (nof_prb*SRSLTE_NRE*SRSLTE_CP_NSYMB(cp)) -#define SRSLTE_SF_LEN_RE(nof_prb, cp) (2*SRSLTE_SLOT_LEN_RE(nof_prb, cp)) +#define SRSLTE_SLOT_LEN_RE(nof_prb, cp) (nof_prb * SRSLTE_NRE * SRSLTE_CP_NSYMB(cp)) +#define SRSLTE_SF_LEN_RE(nof_prb, cp) (2 * SRSLTE_SLOT_LEN_RE(nof_prb, cp)) #define SRSLTE_NOF_RE(cell) (2 * SRSLTE_SLOT_LEN_RE(cell.nof_prb, cell.cp)) -#define SRSLTE_TA_OFFSET (10e-6) +#define SRSLTE_TA_OFFSET (10e-6) -#define SRSLTE_LTE_TS 1.0/(15000.0*2048) +#define SRSLTE_LTE_TS 1.0 / (15000.0 * 2048) -#define SRSLTE_SLOT_IDX_CPNORM(symbol_idx, symbol_sz) (symbol_idx==0?0:(symbol_sz + SRSLTE_CP_LEN(symbol_sz, SRSLTE_CP_NORM_0_LEN) + \ - (symbol_idx-1)*(symbol_sz+SRSLTE_CP_LEN(symbol_sz, SRSLTE_CP_NORM_LEN)))) -#define SRSLTE_SLOT_IDX_CPEXT(idx, symbol_sz) (idx*(symbol_sz+SRSLTE_CP(symbol_sz, SRSLTE_CP_EXT_LEN))) +#define SRSLTE_SLOT_IDX_CPNORM(symbol_idx, symbol_sz) \ + (symbol_idx == 0 ? 0 \ + : (symbol_sz + SRSLTE_CP_LEN(symbol_sz, SRSLTE_CP_NORM_0_LEN) + \ + (symbol_idx - 1) * (symbol_sz + SRSLTE_CP_LEN(symbol_sz, SRSLTE_CP_NORM_LEN)))) +#define SRSLTE_SLOT_IDX_CPEXT(idx, symbol_sz) (idx * (symbol_sz + SRSLTE_CP(symbol_sz, SRSLTE_CP_EXT_LEN))) -#define SRSLTE_RE_IDX(nof_prb, symbol_idx, sample_idx) ((symbol_idx)*(nof_prb)*(SRSLTE_NRE) + sample_idx) +#define SRSLTE_RE_IDX(nof_prb, symbol_idx, sample_idx) ((symbol_idx) * (nof_prb) * (SRSLTE_NRE) + sample_idx) -#define SRSLTE_RS_VSHIFT(cell_id) (cell_id%6) +#define SRSLTE_RS_VSHIFT(cell_id) (cell_id % 6) -#define SRSLTE_GUARD_RE(nof_prb) ((srslte_symbol_sz(nof_prb)-nof_prb*SRSLTE_NRE)/2) +#define SRSLTE_GUARD_RE(nof_prb) ((srslte_symbol_sz(nof_prb) - nof_prb * SRSLTE_NRE) / 2) -#define SRSLTE_SYMBOL_HAS_REF(l, cp, nof_ports) ((l == 1 && nof_ports == 4) \ - || l == 0 \ - || l == SRSLTE_CP_NSYMB(cp) - 3) +#define SRSLTE_SYMBOL_HAS_REF(l, cp, nof_ports) ((l == 1 && nof_ports == 4) || l == 0 || l == SRSLTE_CP_NSYMB(cp) - 3) #define SRSLTE_NOF_CTRL_SYMBOLS(cell, cfi) (cfi + (cell.nof_prb < 10 ? 1 : 0)) #define SRSLTE_SYMBOL_HAS_REF_MBSFN(l, s) ((l == 2 && s == 0) || (l == 0 && s == 1) || (l == 4 && s == 1)) -#define SRSLTE_NON_MBSFN_REGION_GUARD_LENGTH(non_mbsfn_region,symbol_sz) ((non_mbsfn_region == 1)?(SRSLTE_CP_LEN_EXT(symbol_sz) - SRSLTE_CP_LEN_NORM(0, symbol_sz)):(2*SRSLTE_CP_LEN_EXT(symbol_sz) - SRSLTE_CP_LEN_NORM(0, symbol_sz)- SRSLTE_CP_LEN_NORM(1, symbol_sz))) +#define SRSLTE_NON_MBSFN_REGION_GUARD_LENGTH(non_mbsfn_region, symbol_sz) \ + ((non_mbsfn_region == 1) \ + ? (SRSLTE_CP_LEN_EXT(symbol_sz) - SRSLTE_CP_LEN_NORM(0, symbol_sz)) \ + : (2 * SRSLTE_CP_LEN_EXT(symbol_sz) - SRSLTE_CP_LEN_NORM(0, symbol_sz) - SRSLTE_CP_LEN_NORM(1, symbol_sz))) #define SRSLTE_FDD_NOF_HARQ (TX_DELAY + FDD_HARQ_DELAY_MS) #define SRSLTE_MAX_HARQ_PROC 15 #define SRSLTE_NOF_LTE_BANDS 58 -#define SRSLTE_DEFAULT_MAX_FRAMES_PBCH 500 -#define SRSLTE_DEFAULT_MAX_FRAMES_PSS 10 +#define SRSLTE_DEFAULT_MAX_FRAMES_PBCH 500 +#define SRSLTE_DEFAULT_MAX_FRAMES_PSS 10 #define SRSLTE_DEFAULT_NOF_VALID_PSS_FRAMES 10 #define ZERO_OBJECT(x) memset(&(x), 0x0, sizeof((x))) -typedef enum SRSLTE_API { - SRSLTE_PHICH_NORM = 0, - SRSLTE_PHICH_EXT -} srslte_phich_length_t; +typedef enum SRSLTE_API { SRSLTE_PHICH_NORM = 0, SRSLTE_PHICH_EXT } srslte_phich_length_t; typedef enum SRSLTE_API { SRSLTE_PHICH_R_1_6 = 0, @@ -278,12 +279,12 @@ typedef struct SRSLTE_API { } srslte_earfcn_t; enum band_geographical_area { - SRSLTE_BAND_GEO_AREA_ALL, - SRSLTE_BAND_GEO_AREA_NAR, - SRSLTE_BAND_GEO_AREA_APAC, - SRSLTE_BAND_GEO_AREA_EMEA, - SRSLTE_BAND_GEO_AREA_JAPAN, - SRSLTE_BAND_GEO_AREA_CALA, + SRSLTE_BAND_GEO_AREA_ALL, + SRSLTE_BAND_GEO_AREA_NAR, + SRSLTE_BAND_GEO_AREA_APAC, + SRSLTE_BAND_GEO_AREA_EMEA, + SRSLTE_BAND_GEO_AREA_JAPAN, + SRSLTE_BAND_GEO_AREA_CALA, SRSLTE_BAND_GEO_AREA_NA }; @@ -328,11 +329,9 @@ typedef struct SRSLTE_API { #define SRSLTE_NBIOT_NPBCH_NOF_BITS_SF \ (SRSLTE_NBIOT_NPBCH_NOF_TOTAL_BITS / 8) ///< The NPBCH is transmitted in 8 blocks (See 36.211 Sec 10.2.4.4) -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_cell_t *cell, - uint32_t sfn); +SRSLTE_API void srslte_cell_fprint(FILE* stream, srslte_cell_t* cell, uint32_t sfn); SRSLTE_API bool srslte_cellid_isvalid(uint32_t cell_id); @@ -358,43 +357,35 @@ SRSLTE_API bool srslte_N_id_2_isvalid(uint32_t N_id_2); SRSLTE_API bool srslte_N_id_1_isvalid(uint32_t N_id_1); -SRSLTE_API bool srslte_symbol_sz_isvalid(uint32_t symbol_sz); +SRSLTE_API bool srslte_symbol_sz_isvalid(uint32_t symbol_sz); SRSLTE_API int srslte_symbol_sz(uint32_t nof_prb); -SRSLTE_API int srslte_symbol_sz_power2(uint32_t nof_prb); +SRSLTE_API int srslte_symbol_sz_power2(uint32_t nof_prb); SRSLTE_API int srslte_nof_prb(uint32_t symbol_sz); SRSLTE_API int srslte_sampling_freq_hz(uint32_t nof_prb); -SRSLTE_API void srslte_use_standard_symbol_size(bool enabled); +SRSLTE_API void srslte_use_standard_symbol_size(bool enabled); -SRSLTE_API uint32_t srslte_re_x_prb(uint32_t ns, - uint32_t symbol, - uint32_t nof_ports, - uint32_t nof_symbols); +SRSLTE_API uint32_t srslte_re_x_prb(uint32_t ns, uint32_t symbol, uint32_t nof_ports, uint32_t nof_symbols); -SRSLTE_API uint32_t srslte_voffset(uint32_t symbol_id, - uint32_t cell_id, - uint32_t nof_ports); +SRSLTE_API uint32_t srslte_voffset(uint32_t symbol_id, uint32_t cell_id, uint32_t nof_ports); -SRSLTE_API int srslte_group_hopping_f_gh(uint32_t f_gh[SRSLTE_NSLOTS_X_FRAME], - uint32_t cell_id); +SRSLTE_API int srslte_group_hopping_f_gh(uint32_t f_gh[SRSLTE_NSLOTS_X_FRAME], uint32_t cell_id); SRSLTE_API uint32_t srslte_N_ta_new_rar(uint32_t ta); -SRSLTE_API uint32_t srslte_N_ta_new(uint32_t N_ta_old, - uint32_t ta); +SRSLTE_API uint32_t srslte_N_ta_new(uint32_t N_ta_old, uint32_t ta); -SRSLTE_API float srslte_coderate(uint32_t tbs, - uint32_t nof_re); +SRSLTE_API float srslte_coderate(uint32_t tbs, uint32_t nof_re); -SRSLTE_API char *srslte_cp_string(srslte_cp_t cp); +SRSLTE_API char* srslte_cp_string(srslte_cp_t cp); -SRSLTE_API srslte_mod_t srslte_str2mod (char * mod_str); +SRSLTE_API srslte_mod_t srslte_str2mod(char* mod_str); -SRSLTE_API char *srslte_mod_string(srslte_mod_t mod); +SRSLTE_API char* srslte_mod_string(srslte_mod_t mod); SRSLTE_API uint32_t srslte_mod_bits_x_symbol(srslte_mod_t mod); @@ -406,21 +397,15 @@ SRSLTE_API float srslte_band_fd(uint32_t dl_earfcn); SRSLTE_API float srslte_band_fu(uint32_t ul_earfcn); -SRSLTE_API uint32_t srslte_band_ul_earfcn(uint32_t dl_earfcn); +SRSLTE_API uint32_t srslte_band_ul_earfcn(uint32_t dl_earfcn); -SRSLTE_API int srslte_band_get_fd_band(uint32_t band, - srslte_earfcn_t *earfcn, - int earfcn_start, - int earfcn_end, - uint32_t max_elems); +SRSLTE_API int +srslte_band_get_fd_band(uint32_t band, srslte_earfcn_t* earfcn, int earfcn_start, int earfcn_end, uint32_t max_elems); -SRSLTE_API int srslte_band_get_fd_band_all(uint32_t band, - srslte_earfcn_t *earfcn, - uint32_t max_nelems); +SRSLTE_API int srslte_band_get_fd_band_all(uint32_t band, srslte_earfcn_t* earfcn, uint32_t max_nelems); -SRSLTE_API int srslte_band_get_fd_region(enum band_geographical_area region, - srslte_earfcn_t *earfcn, - uint32_t max_elems); +SRSLTE_API int +srslte_band_get_fd_region(enum band_geographical_area region, srslte_earfcn_t* earfcn, uint32_t max_elems); SRSLTE_API int srslte_str2mimotype(char* mimo_type_str, srslte_tx_scheme_t* type); diff --git a/lib/include/srslte/phy/common/sequence.h b/lib/include/srslte/phy/common/sequence.h index f909fbae9..e43930b76 100644 --- a/lib/include/srslte/phy/common/sequence.h +++ b/lib/include/srslte/phy/common/sequence.h @@ -35,66 +35,40 @@ #include "srslte/phy/common/phy_common.h" typedef struct SRSLTE_API { - uint8_t *c; - uint8_t *c_bytes; - float *c_float; - short *c_short; - int8_t *c_char; + uint8_t* c; + uint8_t* c_bytes; + float* c_float; + short* c_short; + int8_t* c_char; uint32_t cur_len; uint32_t max_len; } srslte_sequence_t; -SRSLTE_API int srslte_sequence_init(srslte_sequence_t *q, uint32_t len); - -SRSLTE_API void srslte_sequence_free(srslte_sequence_t *q); - -SRSLTE_API int srslte_sequence_LTE_pr(srslte_sequence_t *q, - uint32_t len, - uint32_t seed); - -SRSLTE_API int srslte_sequence_set_LTE_pr(srslte_sequence_t *q, - uint32_t len, - uint32_t seed); - -SRSLTE_API int srslte_sequence_pbch(srslte_sequence_t *seq, - srslte_cp_t cp, - uint32_t cell_id); - -SRSLTE_API int srslte_sequence_pcfich(srslte_sequence_t *seq, - uint32_t nslot, - uint32_t cell_id); - -SRSLTE_API int srslte_sequence_phich(srslte_sequence_t *seq, - uint32_t nslot, - uint32_t cell_id); - -SRSLTE_API int srslte_sequence_pdcch(srslte_sequence_t *seq, - uint32_t nslot, - uint32_t cell_id, - uint32_t len); - -SRSLTE_API int srslte_sequence_pdsch(srslte_sequence_t *seq, - uint16_t rnti, - int q, - uint32_t nslot, - uint32_t cell_id, - uint32_t len); - -SRSLTE_API int srslte_sequence_pusch(srslte_sequence_t *seq, - uint16_t rnti, - uint32_t nslot, - uint32_t cell_id, - uint32_t len); - -SRSLTE_API int srslte_sequence_pucch(srslte_sequence_t *seq, - uint16_t rnti, - uint32_t nslot, - uint32_t cell_id); - -SRSLTE_API int srslte_sequence_pmch(srslte_sequence_t *seq, - uint32_t nslot, - uint32_t mbsfn_id, - uint32_t len); +SRSLTE_API int srslte_sequence_init(srslte_sequence_t* q, uint32_t len); + +SRSLTE_API void srslte_sequence_free(srslte_sequence_t* q); + +SRSLTE_API int srslte_sequence_LTE_pr(srslte_sequence_t* q, uint32_t len, uint32_t seed); + +SRSLTE_API int srslte_sequence_set_LTE_pr(srslte_sequence_t* q, uint32_t len, uint32_t seed); + +SRSLTE_API int srslte_sequence_pbch(srslte_sequence_t* seq, srslte_cp_t cp, uint32_t cell_id); + +SRSLTE_API int srslte_sequence_pcfich(srslte_sequence_t* seq, uint32_t nslot, uint32_t cell_id); + +SRSLTE_API int srslte_sequence_phich(srslte_sequence_t* seq, uint32_t nslot, uint32_t cell_id); + +SRSLTE_API int srslte_sequence_pdcch(srslte_sequence_t* seq, uint32_t nslot, uint32_t cell_id, uint32_t len); + +SRSLTE_API int +srslte_sequence_pdsch(srslte_sequence_t* seq, uint16_t rnti, int q, uint32_t nslot, uint32_t cell_id, uint32_t len); + +SRSLTE_API int +srslte_sequence_pusch(srslte_sequence_t* seq, uint16_t rnti, uint32_t nslot, uint32_t cell_id, uint32_t len); + +SRSLTE_API int srslte_sequence_pucch(srslte_sequence_t* seq, uint16_t rnti, uint32_t nslot, uint32_t cell_id); + +SRSLTE_API int srslte_sequence_pmch(srslte_sequence_t* seq, uint32_t nslot, uint32_t mbsfn_id, uint32_t len); SRSLTE_API int srslte_sequence_npbch(srslte_sequence_t* seq, srslte_cp_t cp, uint32_t cell_id); diff --git a/lib/include/srslte/phy/common/timestamp.h b/lib/include/srslte/phy/common/timestamp.h index cd0cb1883..322172222 100644 --- a/lib/include/srslte/phy/common/timestamp.h +++ b/lib/include/srslte/phy/common/timestamp.h @@ -37,10 +37,10 @@ #include #include -typedef struct SRSLTE_API{ +typedef struct SRSLTE_API { time_t full_secs; double frac_secs; -}srslte_timestamp_t; +} srslte_timestamp_t; #ifdef __cplusplus extern "C" { @@ -58,11 +58,11 @@ SRSLTE_API int srslte_timestamp_add(srslte_timestamp_t* t, time_t full_secs, dou SRSLTE_API int srslte_timestamp_sub(srslte_timestamp_t* t, time_t full_secs, double frac_secs); -SRSLTE_API double srslte_timestamp_real(srslte_timestamp_t *t); +SRSLTE_API double srslte_timestamp_real(srslte_timestamp_t* t); SRSLTE_API bool srslte_timestamp_iszero(const srslte_timestamp_t* t); -SRSLTE_API uint32_t srslte_timestamp_uint32(srslte_timestamp_t *t); +SRSLTE_API uint32_t srslte_timestamp_uint32(srslte_timestamp_t* t); SRSLTE_API uint64_t srslte_timestamp_uint64(const srslte_timestamp_t* t, double srate); diff --git a/lib/include/srslte/phy/dft/dft.h b/lib/include/srslte/phy/dft/dft.h index 88ce4872d..b645b5a98 100644 --- a/lib/include/srslte/phy/dft/dft.h +++ b/lib/include/srslte/phy/dft/dft.h @@ -21,9 +21,9 @@ #ifndef SRSLTE_DFT_H #define SRSLTE_DFT_H - -#include + #include "srslte/config.h" +#include /********************************************************************************************** * File: dft.h @@ -43,113 +43,85 @@ * Reference: *********************************************************************************************/ -typedef enum { - SRSLTE_DFT_COMPLEX, SRSLTE_REAL -}srslte_dft_mode_t; +typedef enum { SRSLTE_DFT_COMPLEX, SRSLTE_REAL } srslte_dft_mode_t; -typedef enum { - SRSLTE_DFT_FORWARD, SRSLTE_DFT_BACKWARD -}srslte_dft_dir_t; +typedef enum { SRSLTE_DFT_FORWARD, SRSLTE_DFT_BACKWARD } srslte_dft_dir_t; typedef struct SRSLTE_API { - int init_size; // DFT length used in the first initialization - int size; // DFT length - void *in; // Input buffer - void *out; // Output buffer - void *p; // DFT plan - bool is_guru; - bool forward; // Forward transform? - bool mirror; // Shift negative and positive frequencies? - bool db; // Provide output in dB? - bool norm; // Normalize output? - bool dc; // Handle insertion/removal of null DC carrier internally? - srslte_dft_dir_t dir; // Forward/Backward - srslte_dft_mode_t mode; // Complex/Real -}srslte_dft_plan_t; + int init_size; // DFT length used in the first initialization + int size; // DFT length + void* in; // Input buffer + void* out; // Output buffer + void* p; // DFT plan + bool is_guru; + bool forward; // Forward transform? + bool mirror; // Shift negative and positive frequencies? + bool db; // Provide output in dB? + bool norm; // Normalize output? + bool dc; // Handle insertion/removal of null DC carrier internally? + srslte_dft_dir_t dir; // Forward/Backward + srslte_dft_mode_t mode; // Complex/Real +} srslte_dft_plan_t; SRSLTE_API void srslte_dft_load(); SRSLTE_API void srslte_dft_exit(); -SRSLTE_API int srslte_dft_plan(srslte_dft_plan_t *plan, - int dft_points, - srslte_dft_dir_t dir, - srslte_dft_mode_t type); +SRSLTE_API int srslte_dft_plan(srslte_dft_plan_t* plan, int dft_points, srslte_dft_dir_t dir, srslte_dft_mode_t type); -SRSLTE_API int srslte_dft_plan_c(srslte_dft_plan_t *plan, - int dft_points, - srslte_dft_dir_t dir); +SRSLTE_API int srslte_dft_plan_c(srslte_dft_plan_t* plan, int dft_points, srslte_dft_dir_t dir); -SRSLTE_API int srslte_dft_plan_guru_c(srslte_dft_plan_t *plan, - int dft_points, - srslte_dft_dir_t dir, - cf_t *in_buffer, - cf_t *out_buffer, - int istride, - int ostride, - int how_many, - int idist, - int odist); +SRSLTE_API int srslte_dft_plan_guru_c(srslte_dft_plan_t* plan, + int dft_points, + srslte_dft_dir_t dir, + cf_t* in_buffer, + cf_t* out_buffer, + int istride, + int ostride, + int how_many, + int idist, + int odist); -SRSLTE_API int srslte_dft_plan_r(srslte_dft_plan_t *plan, - int dft_points, - srslte_dft_dir_t dir); +SRSLTE_API int srslte_dft_plan_r(srslte_dft_plan_t* plan, int dft_points, srslte_dft_dir_t dir); -SRSLTE_API int srslte_dft_replan(srslte_dft_plan_t *plan, - const int new_dft_points); +SRSLTE_API int srslte_dft_replan(srslte_dft_plan_t* plan, const int new_dft_points); -SRSLTE_API int srslte_dft_replan_guru_c(srslte_dft_plan_t *plan, - const int new_dft_points, - cf_t *in_buffer, - cf_t *out_buffer, - int istride, - int ostride, - int how_many, - int idist, - int odist); +SRSLTE_API int srslte_dft_replan_guru_c(srslte_dft_plan_t* plan, + const int new_dft_points, + cf_t* in_buffer, + cf_t* out_buffer, + int istride, + int ostride, + int how_many, + int idist, + int odist); -SRSLTE_API int srslte_dft_replan_c(srslte_dft_plan_t *plan, - int new_dft_points); +SRSLTE_API int srslte_dft_replan_c(srslte_dft_plan_t* plan, int new_dft_points); -SRSLTE_API int srslte_dft_replan_r(srslte_dft_plan_t *plan, - int new_dft_points); +SRSLTE_API int srslte_dft_replan_r(srslte_dft_plan_t* plan, int new_dft_points); - -SRSLTE_API void srslte_dft_plan_free(srslte_dft_plan_t *plan); +SRSLTE_API void srslte_dft_plan_free(srslte_dft_plan_t* plan); /* Set options */ -SRSLTE_API void srslte_dft_plan_set_mirror(srslte_dft_plan_t *plan, - bool val); +SRSLTE_API void srslte_dft_plan_set_mirror(srslte_dft_plan_t* plan, bool val); -SRSLTE_API void srslte_dft_plan_set_db(srslte_dft_plan_t *plan, - bool val); +SRSLTE_API void srslte_dft_plan_set_db(srslte_dft_plan_t* plan, bool val); -SRSLTE_API void srslte_dft_plan_set_norm(srslte_dft_plan_t *plan, - bool val); +SRSLTE_API void srslte_dft_plan_set_norm(srslte_dft_plan_t* plan, bool val); -SRSLTE_API void srslte_dft_plan_set_dc(srslte_dft_plan_t *plan, - bool val); +SRSLTE_API void srslte_dft_plan_set_dc(srslte_dft_plan_t* plan, bool val); /* Compute DFT */ -SRSLTE_API void srslte_dft_run(srslte_dft_plan_t *plan, - const void *in, - void *out); +SRSLTE_API void srslte_dft_run(srslte_dft_plan_t* plan, const void* in, void* out); -SRSLTE_API void srslte_dft_run_c_zerocopy(srslte_dft_plan_t *plan, - const cf_t *in, - cf_t *out); +SRSLTE_API void srslte_dft_run_c_zerocopy(srslte_dft_plan_t* plan, const cf_t* in, cf_t* out); -SRSLTE_API void srslte_dft_run_c(srslte_dft_plan_t *plan, - const cf_t *in, - cf_t *out); +SRSLTE_API void srslte_dft_run_c(srslte_dft_plan_t* plan, const cf_t* in, cf_t* out); -SRSLTE_API void srslte_dft_run_guru_c(srslte_dft_plan_t *plan); +SRSLTE_API void srslte_dft_run_guru_c(srslte_dft_plan_t* plan); -SRSLTE_API void srslte_dft_run_r(srslte_dft_plan_t *plan, - const float *in, - float *out); +SRSLTE_API void srslte_dft_run_r(srslte_dft_plan_t* plan, const float* in, float* out); #endif // SRSLTE_DFT_H - diff --git a/lib/include/srslte/phy/dft/dft_precoding.h b/lib/include/srslte/phy/dft/dft_precoding.h index 32ad4e47d..5c2dbcaa4 100644 --- a/lib/include/srslte/phy/dft/dft_precoding.h +++ b/lib/include/srslte/phy/dft/dft_precoding.h @@ -38,29 +38,22 @@ /* DFT-based Transform Precoding object */ typedef struct SRSLTE_API { - uint32_t max_prb; - srslte_dft_plan_t dft_plan[SRSLTE_MAX_PRB+1]; + uint32_t max_prb; + srslte_dft_plan_t dft_plan[SRSLTE_MAX_PRB + 1]; -}srslte_dft_precoding_t; +} srslte_dft_precoding_t; -SRSLTE_API int srslte_dft_precoding_init(srslte_dft_precoding_t *q, - uint32_t max_prb, - bool is_tx); +SRSLTE_API int srslte_dft_precoding_init(srslte_dft_precoding_t* q, uint32_t max_prb, bool is_tx); -SRSLTE_API int srslte_dft_precoding_init_tx(srslte_dft_precoding_t *q, - uint32_t max_prb); +SRSLTE_API int srslte_dft_precoding_init_tx(srslte_dft_precoding_t* q, uint32_t max_prb); -SRSLTE_API int srslte_dft_precoding_init_rx(srslte_dft_precoding_t *q, - uint32_t max_prb); +SRSLTE_API int srslte_dft_precoding_init_rx(srslte_dft_precoding_t* q, uint32_t max_prb); -SRSLTE_API void srslte_dft_precoding_free(srslte_dft_precoding_t *q); +SRSLTE_API void srslte_dft_precoding_free(srslte_dft_precoding_t* q); -SRSLTE_API bool srslte_dft_precoding_valid_prb(uint32_t nof_prb); +SRSLTE_API bool srslte_dft_precoding_valid_prb(uint32_t nof_prb); -SRSLTE_API int srslte_dft_precoding(srslte_dft_precoding_t *q, - cf_t *input, - cf_t *output, - uint32_t nof_prb, - uint32_t nof_symbols); +SRSLTE_API int +srslte_dft_precoding(srslte_dft_precoding_t* q, cf_t* input, cf_t* output, uint32_t nof_prb, uint32_t nof_symbols); #endif // SRSLTE_DFT_PRECODING_H diff --git a/lib/include/srslte/phy/dft/ofdm.h b/lib/include/srslte/phy/dft/ofdm.h index 5da102885..85cc4cfa0 100644 --- a/lib/include/srslte/phy/dft/ofdm.h +++ b/lib/include/srslte/phy/dft/ofdm.h @@ -31,125 +31,94 @@ * Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6 *********************************************************************************************/ -#include #include +#include #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" #include "srslte/phy/dft/dft.h" /* This is common for both directions */ -typedef struct SRSLTE_API{ +typedef struct SRSLTE_API { srslte_dft_plan_t fft_plan; srslte_dft_plan_t fft_plan_sf[2]; - uint32_t max_prb; - uint32_t nof_symbols; - uint32_t symbol_sz; - uint32_t nof_guards; - uint32_t nof_re; - uint32_t slot_sz; - uint32_t sf_sz; - srslte_cp_t cp; - cf_t *tmp; // for removing zero padding - cf_t *in_buffer; - cf_t *out_buffer; - + uint32_t max_prb; + uint32_t nof_symbols; + uint32_t symbol_sz; + uint32_t nof_guards; + uint32_t nof_re; + uint32_t slot_sz; + uint32_t sf_sz; + srslte_cp_t cp; + cf_t* tmp; // for removing zero padding + cf_t* in_buffer; + cf_t* out_buffer; + bool mbsfn_subframe; uint32_t mbsfn_guard_len; uint32_t nof_symbols_mbsfn; uint8_t non_mbsfn_region; - - bool freq_shift; + bool freq_shift; float freq_shift_f; - cf_t *shift_buffer; -}srslte_ofdm_t; - -SRSLTE_API int srslte_ofdm_init_(srslte_ofdm_t *q, - srslte_cp_t cp, - cf_t *in_buffer, - cf_t *out_buffer, - int symbol_sz, - int nof_prb, + cf_t* shift_buffer; +} srslte_ofdm_t; + +SRSLTE_API int srslte_ofdm_init_(srslte_ofdm_t* q, + srslte_cp_t cp, + cf_t* in_buffer, + cf_t* out_buffer, + int symbol_sz, + int nof_prb, srslte_dft_dir_t dir); -SRSLTE_API int srslte_ofdm_init_mbsfn_(srslte_ofdm_t *q, - srslte_cp_t cp, - cf_t *in_buffer, - cf_t *out_buffer, - int symbol_sz, - int nof_prb, - srslte_dft_dir_t dir, - srslte_sf_t sf_type); - -SRSLTE_API int srslte_ofdm_rx_init_mbsfn(srslte_ofdm_t *q, - srslte_cp_t cp_type, - cf_t *in_buffer, - cf_t *out_buffer, - uint32_t max_prb); - -SRSLTE_API int srslte_ofdm_rx_init(srslte_ofdm_t *q, - srslte_cp_t cp_type, - cf_t *in_buffer, - cf_t *out_buffer, - uint32_t max_prb); - -SRSLTE_API int srslte_ofdm_tx_set_prb(srslte_ofdm_t *q, - srslte_cp_t cp, - uint32_t nof_prb); +SRSLTE_API int srslte_ofdm_init_mbsfn_(srslte_ofdm_t* q, + srslte_cp_t cp, + cf_t* in_buffer, + cf_t* out_buffer, + int symbol_sz, + int nof_prb, + srslte_dft_dir_t dir, + srslte_sf_t sf_type); -SRSLTE_API int srslte_ofdm_rx_set_prb(srslte_ofdm_t *q, - srslte_cp_t cp, - uint32_t nof_prb); +SRSLTE_API int +srslte_ofdm_rx_init_mbsfn(srslte_ofdm_t* q, srslte_cp_t cp_type, cf_t* in_buffer, cf_t* out_buffer, uint32_t max_prb); -SRSLTE_API void srslte_ofdm_rx_free(srslte_ofdm_t *q); +SRSLTE_API int +srslte_ofdm_rx_init(srslte_ofdm_t* q, srslte_cp_t cp_type, cf_t* in_buffer, cf_t* out_buffer, uint32_t max_prb); -SRSLTE_API void srslte_ofdm_rx_slot(srslte_ofdm_t *q, - int slot_in_sf); +SRSLTE_API int srslte_ofdm_tx_set_prb(srslte_ofdm_t* q, srslte_cp_t cp, uint32_t nof_prb); -SRSLTE_API void srslte_ofdm_rx_slot_ng(srslte_ofdm_t *q, - cf_t *input, - cf_t *output); +SRSLTE_API int srslte_ofdm_rx_set_prb(srslte_ofdm_t* q, srslte_cp_t cp, uint32_t nof_prb); -SRSLTE_API void srslte_ofdm_rx_sf(srslte_ofdm_t *q); +SRSLTE_API void srslte_ofdm_rx_free(srslte_ofdm_t* q); -SRSLTE_API void srslte_ofdm_rx_sf_ng(srslte_ofdm_t *q, - cf_t *input, - cf_t *output); +SRSLTE_API void srslte_ofdm_rx_slot(srslte_ofdm_t* q, int slot_in_sf); -SRSLTE_API int srslte_ofdm_tx_init(srslte_ofdm_t *q, - srslte_cp_t cp_type, - cf_t *in_buffer, - cf_t *out_buffer, - uint32_t nof_prb); +SRSLTE_API void srslte_ofdm_rx_slot_ng(srslte_ofdm_t* q, cf_t* input, cf_t* output); -SRSLTE_API int srslte_ofdm_tx_init_mbsfn(srslte_ofdm_t *q, - srslte_cp_t cp, - cf_t *in_buffer, - cf_t *out_buffer, - uint32_t nof_prb); +SRSLTE_API void srslte_ofdm_rx_sf(srslte_ofdm_t* q); +SRSLTE_API void srslte_ofdm_rx_sf_ng(srslte_ofdm_t* q, cf_t* input, cf_t* output); -SRSLTE_API void srslte_ofdm_tx_free(srslte_ofdm_t *q); +SRSLTE_API int +srslte_ofdm_tx_init(srslte_ofdm_t* q, srslte_cp_t cp_type, cf_t* in_buffer, cf_t* out_buffer, uint32_t nof_prb); -SRSLTE_API void srslte_ofdm_tx_slot(srslte_ofdm_t *q, - int slot_in_sf); +SRSLTE_API int +srslte_ofdm_tx_init_mbsfn(srslte_ofdm_t* q, srslte_cp_t cp, cf_t* in_buffer, cf_t* out_buffer, uint32_t nof_prb); -SRSLTE_API void srslte_ofdm_tx_slot_mbsfn(srslte_ofdm_t *q, - cf_t *input, - cf_t *output); +SRSLTE_API void srslte_ofdm_tx_free(srslte_ofdm_t* q); +SRSLTE_API void srslte_ofdm_tx_slot(srslte_ofdm_t* q, int slot_in_sf); -SRSLTE_API void srslte_ofdm_tx_sf(srslte_ofdm_t *q); +SRSLTE_API void srslte_ofdm_tx_slot_mbsfn(srslte_ofdm_t* q, cf_t* input, cf_t* output); -SRSLTE_API int srslte_ofdm_set_freq_shift(srslte_ofdm_t *q, - float freq_shift); +SRSLTE_API void srslte_ofdm_tx_sf(srslte_ofdm_t* q); -SRSLTE_API void srslte_ofdm_set_normalize(srslte_ofdm_t *q, - bool normalize_enable); +SRSLTE_API int srslte_ofdm_set_freq_shift(srslte_ofdm_t* q, float freq_shift); -SRSLTE_API void srslte_ofdm_set_non_mbsfn_region(srslte_ofdm_t *q, - uint8_t non_mbsfn_region); +SRSLTE_API void srslte_ofdm_set_normalize(srslte_ofdm_t* q, bool normalize_enable); +SRSLTE_API void srslte_ofdm_set_non_mbsfn_region(srslte_ofdm_t* q, uint8_t non_mbsfn_region); #endif // SRSLTE_OFDM_H diff --git a/lib/include/srslte/phy/enb/enb_dl.h b/lib/include/srslte/phy/enb/enb_dl.h index 641325955..b619d10d4 100644 --- a/lib/include/srslte/phy/enb/enb_dl.h +++ b/lib/include/srslte/phy/enb/enb_dl.h @@ -54,8 +54,8 @@ #include "srslte/phy/enb/enb_ul.h" #include "srslte/phy/ue/ue_dl.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" #include "srslte/config.h" @@ -66,8 +66,8 @@ typedef struct SRSLTE_API { cf_t* sf_symbols[SRSLTE_MAX_PORTS]; - srslte_ofdm_t ifft[SRSLTE_MAX_PORTS]; - srslte_ofdm_t ifft_mbsfn; + srslte_ofdm_t ifft[SRSLTE_MAX_PORTS]; + srslte_ofdm_t ifft_mbsfn; srslte_pbch_t pbch; srslte_pcfich_t pcfich; @@ -75,8 +75,8 @@ typedef struct SRSLTE_API { srslte_pdcch_t pdcch; srslte_pdsch_t pdsch; srslte_pmch_t pmch; - srslte_phich_t phich; - + srslte_phich_t phich; + srslte_refsignal_t csr_signal; srslte_refsignal_t mbsfnr_signal; @@ -93,14 +93,11 @@ typedef struct { } srslte_enb_dl_phich_t; /* This function shall be called just after the initial synchronization */ -SRSLTE_API int srslte_enb_dl_init(srslte_enb_dl_t *q, - cf_t *out_buffer[SRSLTE_MAX_PORTS], - uint32_t max_prb); +SRSLTE_API int srslte_enb_dl_init(srslte_enb_dl_t* q, cf_t* out_buffer[SRSLTE_MAX_PORTS], uint32_t max_prb); -SRSLTE_API void srslte_enb_dl_free(srslte_enb_dl_t *q); +SRSLTE_API void srslte_enb_dl_free(srslte_enb_dl_t* q); -SRSLTE_API int srslte_enb_dl_set_cell(srslte_enb_dl_t *q, - srslte_cell_t cell); +SRSLTE_API int srslte_enb_dl_set_cell(srslte_enb_dl_t* q, srslte_cell_t cell); SRSLTE_API int srslte_enb_dl_add_rnti(srslte_enb_dl_t* q, uint16_t rnti); @@ -121,8 +118,11 @@ SRSLTE_API int srslte_enb_dl_put_pmch(srslte_enb_dl_t* q, srslte_pmch_cfg_t* pmc SRSLTE_API void srslte_enb_dl_gen_signal(srslte_enb_dl_t* q); -SRSLTE_API bool srslte_enb_dl_gen_cqi_periodic( - srslte_cell_t* cell, srslte_dl_cfg_t* dl_cfg, uint32_t tti, uint32_t ri, srslte_cqi_cfg_t* cqi_cfg); +SRSLTE_API bool srslte_enb_dl_gen_cqi_periodic(srslte_cell_t* cell, + srslte_dl_cfg_t* dl_cfg, + uint32_t tti, + uint32_t ri, + srslte_cqi_cfg_t* cqi_cfg); SRSLTE_API bool srslte_enb_dl_gen_cqi_aperiodic(srslte_cell_t* cell, srslte_dl_cfg_t* dl_cfg, uint32_t ri, srslte_cqi_cfg_t* cqi_cfg); diff --git a/lib/include/srslte/phy/enb/enb_ul.h b/lib/include/srslte/phy/enb/enb_ul.h index 835fe801d..bc296d6f4 100644 --- a/lib/include/srslte/phy/enb/enb_ul.h +++ b/lib/include/srslte/phy/enb/enb_ul.h @@ -44,8 +44,8 @@ #include "srslte/phy/phch/pusch_cfg.h" #include "srslte/phy/phch/ra.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" #include "srslte/config.h" @@ -63,22 +63,18 @@ typedef struct SRSLTE_API { } srslte_enb_ul_t; /* This function shall be called just after the initial synchronization */ -SRSLTE_API int srslte_enb_ul_init(srslte_enb_ul_t *q, - cf_t *in_buffer, - uint32_t max_prb); +SRSLTE_API int srslte_enb_ul_init(srslte_enb_ul_t* q, cf_t* in_buffer, uint32_t max_prb); -SRSLTE_API void srslte_enb_ul_free(srslte_enb_ul_t *q); +SRSLTE_API void srslte_enb_ul_free(srslte_enb_ul_t* q); SRSLTE_API int srslte_enb_ul_set_cell(srslte_enb_ul_t* q, srslte_cell_t cell, srslte_refsignal_dmrs_pusch_cfg_t* pusch_cfg); -SRSLTE_API int srslte_enb_ul_add_rnti(srslte_enb_ul_t *q, - uint16_t rnti); +SRSLTE_API int srslte_enb_ul_add_rnti(srslte_enb_ul_t* q, uint16_t rnti); -SRSLTE_API void srslte_enb_ul_rem_rnti(srslte_enb_ul_t *q, - uint16_t rnti); +SRSLTE_API void srslte_enb_ul_rem_rnti(srslte_enb_ul_t* q, uint16_t rnti); -SRSLTE_API void srslte_enb_ul_fft(srslte_enb_ul_t *q); +SRSLTE_API void srslte_enb_ul_fft(srslte_enb_ul_t* q); SRSLTE_API int srslte_enb_ul_get_pucch(srslte_enb_ul_t* q, srslte_ul_sf_cfg_t* ul_sf, diff --git a/lib/include/srslte/phy/fec/cbsegm.h b/lib/include/srslte/phy/fec/cbsegm.h index f0ae1ebd1..31bb71cb1 100644 --- a/lib/include/srslte/phy/fec/cbsegm.h +++ b/lib/include/srslte/phy/fec/cbsegm.h @@ -19,8 +19,8 @@ * */ -#include #include +#include #include "srslte/config.h" @@ -29,8 +29,7 @@ #define SRSLTE_NOF_TC_CB_SIZES 188 - - typedef struct SRSLTE_API { +typedef struct SRSLTE_API { uint32_t F; uint32_t C; uint32_t K1; @@ -39,16 +38,15 @@ uint32_t K2_idx; uint32_t C1; uint32_t C2; - uint32_t tbs; + uint32_t tbs; } srslte_cbsegm_t; -SRSLTE_API int srslte_cbsegm(srslte_cbsegm_t *s, - uint32_t tbs); +SRSLTE_API int srslte_cbsegm(srslte_cbsegm_t* s, uint32_t tbs); -SRSLTE_API int srslte_cbsegm_cbsize(uint32_t index); +SRSLTE_API int srslte_cbsegm_cbsize(uint32_t index); -SRSLTE_API bool srslte_cbsegm_cbsize_isvalid(uint32_t size); +SRSLTE_API bool srslte_cbsegm_cbsize_isvalid(uint32_t size); -SRSLTE_API int srslte_cbsegm_cbindex(uint32_t long_cb); +SRSLTE_API int srslte_cbsegm_cbindex(uint32_t long_cb); #endif // SRSLTE_CBSEGM_H diff --git a/lib/include/srslte/phy/fec/convcoder.h b/lib/include/srslte/phy/fec/convcoder.h index b08ffcfdd..54234b34b 100644 --- a/lib/include/srslte/phy/fec/convcoder.h +++ b/lib/include/srslte/phy/fec/convcoder.h @@ -32,20 +32,16 @@ #ifndef SRSLTE_CONVCODER_H #define SRSLTE_CONVCODER_H -#include #include "srslte/config.h" +#include typedef struct SRSLTE_API { uint32_t R; uint32_t K; - int poly[3]; - bool tail_biting; -}srslte_convcoder_t; - -SRSLTE_API int srslte_convcoder_encode(srslte_convcoder_t *q, - uint8_t *input, - uint8_t *output, - uint32_t frame_length); + int poly[3]; + bool tail_biting; +} srslte_convcoder_t; +SRSLTE_API int srslte_convcoder_encode(srslte_convcoder_t* q, uint8_t* input, uint8_t* output, uint32_t frame_length); #endif // SRSLTE_CONVCODER_H diff --git a/lib/include/srslte/phy/fec/crc.h b/lib/include/srslte/phy/fec/crc.h index aefa790eb..f5fa413cb 100644 --- a/lib/include/srslte/phy/fec/crc.h +++ b/lib/include/srslte/phy/fec/crc.h @@ -37,49 +37,40 @@ typedef struct SRSLTE_API { uint64_t table[256]; - int polynom; - int order; - uint64_t crcinit; + int polynom; + int order; + uint64_t crcinit; uint64_t crcmask; uint64_t crchighbit; uint32_t srslte_crc_out; } srslte_crc_t; -SRSLTE_API int srslte_crc_init(srslte_crc_t *h, - uint32_t srslte_crc_poly, - int srslte_crc_order); +SRSLTE_API int srslte_crc_init(srslte_crc_t* h, uint32_t srslte_crc_poly, int srslte_crc_order); -SRSLTE_API int srslte_crc_set_init(srslte_crc_t *h, - uint64_t init_value); +SRSLTE_API int srslte_crc_set_init(srslte_crc_t* h, uint64_t init_value); -SRSLTE_API uint32_t srslte_crc_attach(srslte_crc_t *h, - uint8_t *data, - int len); +SRSLTE_API uint32_t srslte_crc_attach(srslte_crc_t* h, uint8_t* data, int len); -SRSLTE_API uint32_t srslte_crc_attach_byte(srslte_crc_t *h, - uint8_t *data, - int len); +SRSLTE_API uint32_t srslte_crc_attach_byte(srslte_crc_t* h, uint8_t* data, int len); -static inline void srslte_crc_checksum_put_byte(srslte_crc_t *h, uint8_t byte) { +static inline void srslte_crc_checksum_put_byte(srslte_crc_t* h, uint8_t byte) +{ // Polynom order 8, 16, 24 or 32 only. - int ord = h->order - 8; + int ord = h->order - 8; uint64_t crc = h->crcinit; - crc = (crc << 8) ^ h->table[((crc >> (ord)) & 0xff) ^ byte]; + crc = (crc << 8) ^ h->table[((crc >> (ord)) & 0xff) ^ byte]; h->crcinit = crc; } -static inline uint64_t srslte_crc_checksum_get(srslte_crc_t *h) { - return (h->crcinit & h->crcmask); +static inline uint64_t srslte_crc_checksum_get(srslte_crc_t* h) +{ + return (h->crcinit & h->crcmask); } -SRSLTE_API uint32_t srslte_crc_checksum_byte(srslte_crc_t *h, - uint8_t *data, - int len); +SRSLTE_API uint32_t srslte_crc_checksum_byte(srslte_crc_t* h, uint8_t* data, int len); -SRSLTE_API uint32_t srslte_crc_checksum(srslte_crc_t *h, - uint8_t *data, - int len); +SRSLTE_API uint32_t srslte_crc_checksum(srslte_crc_t* h, uint8_t* data, int len); #endif // SRSLTE_CRC_H diff --git a/lib/include/srslte/phy/fec/rm_conv.h b/lib/include/srslte/phy/fec/rm_conv.h index 5bbdeb3d4..53234bfde 100644 --- a/lib/include/srslte/phy/fec/rm_conv.h +++ b/lib/include/srslte/phy/fec/rm_conv.h @@ -40,22 +40,12 @@ #ifndef SRSLTE_TX_NULL #define SRSLTE_TX_NULL 100 #endif -SRSLTE_API int srslte_rm_conv_tx(uint8_t *input, - uint32_t in_len, - uint8_t *output, - uint32_t out_len); +SRSLTE_API int srslte_rm_conv_tx(uint8_t* input, uint32_t in_len, uint8_t* output, uint32_t out_len); -SRSLTE_API int srslte_rm_conv_rx(float *input, - uint32_t in_len, - float *output, - uint32_t out_len); +SRSLTE_API int srslte_rm_conv_rx(float* input, uint32_t in_len, float* output, uint32_t out_len); +/************* FIX THIS. MOVE ALL PROCESSING TO INT16 AND HAVE ONLY 1 IMPLEMENTATION ******/ -/************* FIX THIS. MOVE ALL PROCESSING TO INT16 AND HAVE ONLY 1 IMPLEMENTATION ******/ - -SRSLTE_API int srslte_rm_conv_rx_s(int16_t *input, - uint32_t in_len, - int16_t *output, - uint32_t out_len); +SRSLTE_API int srslte_rm_conv_rx_s(int16_t* input, uint32_t in_len, int16_t* output, uint32_t out_len); #endif // SRSLTE_RM_CONV_H diff --git a/lib/include/srslte/phy/fec/rm_turbo.h b/lib/include/srslte/phy/fec/rm_turbo.h index 4c1173011..97d034197 100644 --- a/lib/include/srslte/phy/fec/rm_turbo.h +++ b/lib/include/srslte/phy/fec/rm_turbo.h @@ -43,53 +43,47 @@ #include "srslte/config.h" -SRSLTE_API int srslte_rm_turbo_tx(uint8_t *w_buff, - uint32_t buff_len, - uint8_t *input, - uint32_t in_len, - uint8_t *output, - uint32_t out_len, +SRSLTE_API int srslte_rm_turbo_tx(uint8_t* w_buff, + uint32_t buff_len, + uint8_t* input, + uint32_t in_len, + uint8_t* output, + uint32_t out_len, uint32_t rv_idx); -SRSLTE_API void srslte_rm_turbo_gentables(); +SRSLTE_API void srslte_rm_turbo_gentables(); SRSLTE_API void srslte_rm_turbo_free_tables(); -SRSLTE_API int srslte_rm_turbo_tx_lut(uint8_t *w_buff, - uint8_t *systematic, - uint8_t *parity, - uint8_t *output, - uint32_t cb_idx, - uint32_t out_len, +SRSLTE_API int srslte_rm_turbo_tx_lut(uint8_t* w_buff, + uint8_t* systematic, + uint8_t* parity, + uint8_t* output, + uint32_t cb_idx, + uint32_t out_len, uint32_t w_offset, uint32_t rv_idx); -SRSLTE_API int srslte_rm_turbo_rx(float *w_buff, - uint32_t buff_len, - float *input, +SRSLTE_API int srslte_rm_turbo_rx(float* w_buff, + uint32_t buff_len, + float* input, uint32_t in_len, - float *output, - uint32_t out_len, - uint32_t rv_idx, + float* output, + uint32_t out_len, + uint32_t rv_idx, uint32_t nof_filler_bits); -SRSLTE_API int srslte_rm_turbo_rx_lut(int16_t *input, - int16_t *output, - uint32_t in_len, - uint32_t cb_idx, - uint32_t rv_idx); +SRSLTE_API int +srslte_rm_turbo_rx_lut(int16_t* input, int16_t* output, uint32_t in_len, uint32_t cb_idx, uint32_t rv_idx); -SRSLTE_API int srslte_rm_turbo_rx_lut_(int16_t *input, - int16_t *output, +SRSLTE_API int srslte_rm_turbo_rx_lut_(int16_t* input, + int16_t* output, uint32_t in_len, uint32_t cb_idx, uint32_t rv_idx, - bool enable_input_tdec); + bool enable_input_tdec); -SRSLTE_API int srslte_rm_turbo_rx_lut_8bit(int8_t *input, - int8_t *output, - uint32_t in_len, - uint32_t cb_idx, - uint32_t rv_idx); +SRSLTE_API int +srslte_rm_turbo_rx_lut_8bit(int8_t* input, int8_t* output, uint32_t in_len, uint32_t cb_idx, uint32_t rv_idx); #endif // SRSLTE_RM_TURBO_H diff --git a/lib/include/srslte/phy/fec/softbuffer.h b/lib/include/srslte/phy/fec/softbuffer.h index 4a9146d1c..d73496e35 100644 --- a/lib/include/srslte/phy/fec/softbuffer.h +++ b/lib/include/srslte/phy/fec/softbuffer.h @@ -22,8 +22,8 @@ /****************************************************************************** * File: softbuffer.h * - * Description: Buffer for RX and TX soft bits. This should be provided by MAC. - * Provided here basically for the examples. + * Description: Buffer for RX and TX soft bits. This should be provided by MAC. + * Provided here basically for the examples. * * Reference: *****************************************************************************/ @@ -35,46 +35,38 @@ #include "srslte/phy/common/phy_common.h" typedef struct SRSLTE_API { - uint32_t max_cb; - int16_t **buffer_f; - uint8_t **data; - bool *cb_crc; - bool tb_crc; + uint32_t max_cb; + int16_t** buffer_f; + uint8_t** data; + bool* cb_crc; + bool tb_crc; } srslte_softbuffer_rx_t; typedef struct SRSLTE_API { - uint32_t max_cb; - uint8_t **buffer_b; + uint32_t max_cb; + uint8_t** buffer_b; } srslte_softbuffer_tx_t; -#define SOFTBUFFER_SIZE 18600 +#define SOFTBUFFER_SIZE 18600 -SRSLTE_API int srslte_softbuffer_rx_init(srslte_softbuffer_rx_t * q, - uint32_t nof_prb); +SRSLTE_API int srslte_softbuffer_rx_init(srslte_softbuffer_rx_t* q, uint32_t nof_prb); -SRSLTE_API void srslte_softbuffer_rx_reset(srslte_softbuffer_rx_t *p); +SRSLTE_API void srslte_softbuffer_rx_reset(srslte_softbuffer_rx_t* p); -SRSLTE_API void srslte_softbuffer_rx_reset_tbs(srslte_softbuffer_rx_t *q, - uint32_t tbs); +SRSLTE_API void srslte_softbuffer_rx_reset_tbs(srslte_softbuffer_rx_t* q, uint32_t tbs); -SRSLTE_API void srslte_softbuffer_rx_reset_cb(srslte_softbuffer_rx_t *q, - uint32_t nof_cb); +SRSLTE_API void srslte_softbuffer_rx_reset_cb(srslte_softbuffer_rx_t* q, uint32_t nof_cb); -SRSLTE_API void srslte_softbuffer_rx_free(srslte_softbuffer_rx_t *p); +SRSLTE_API void srslte_softbuffer_rx_free(srslte_softbuffer_rx_t* p); -SRSLTE_API int srslte_softbuffer_tx_init(srslte_softbuffer_tx_t * q, - uint32_t nof_prb); +SRSLTE_API int srslte_softbuffer_tx_init(srslte_softbuffer_tx_t* q, uint32_t nof_prb); -SRSLTE_API void srslte_softbuffer_tx_reset(srslte_softbuffer_tx_t *p); +SRSLTE_API void srslte_softbuffer_tx_reset(srslte_softbuffer_tx_t* p); -SRSLTE_API void srslte_softbuffer_tx_reset_tbs(srslte_softbuffer_tx_t *q, - uint32_t tbs); - -SRSLTE_API void srslte_softbuffer_tx_reset_cb(srslte_softbuffer_tx_t *q, - uint32_t nof_cb); - -SRSLTE_API void srslte_softbuffer_tx_free(srslte_softbuffer_tx_t *p); +SRSLTE_API void srslte_softbuffer_tx_reset_tbs(srslte_softbuffer_tx_t* q, uint32_t tbs); +SRSLTE_API void srslte_softbuffer_tx_reset_cb(srslte_softbuffer_tx_t* q, uint32_t nof_cb); +SRSLTE_API void srslte_softbuffer_tx_free(srslte_softbuffer_tx_t* p); #endif // SRSLTE_SOFTBUFFER_H diff --git a/lib/include/srslte/phy/fec/tc_interl.h b/lib/include/srslte/phy/fec/tc_interl.h index 81125ce44..bd3edfe76 100644 --- a/lib/include/srslte/phy/fec/tc_interl.h +++ b/lib/include/srslte/phy/fec/tc_interl.h @@ -34,21 +34,17 @@ #include typedef struct SRSLTE_API { - uint16_t *forward; - uint16_t *reverse; - uint32_t max_long_cb; + uint16_t* forward; + uint16_t* reverse; + uint32_t max_long_cb; } srslte_tc_interl_t; -SRSLTE_API int srslte_tc_interl_LTE_gen(srslte_tc_interl_t *h, - uint32_t long_cb); +SRSLTE_API int srslte_tc_interl_LTE_gen(srslte_tc_interl_t* h, uint32_t long_cb); -SRSLTE_API int srslte_tc_interl_LTE_gen_interl(srslte_tc_interl_t *h, - uint32_t long_cb, - uint32_t interl_win); +SRSLTE_API int srslte_tc_interl_LTE_gen_interl(srslte_tc_interl_t* h, uint32_t long_cb, uint32_t interl_win); -SRSLTE_API int srslte_tc_interl_init(srslte_tc_interl_t *h, - uint32_t max_long_cb); +SRSLTE_API int srslte_tc_interl_init(srslte_tc_interl_t* h, uint32_t max_long_cb); -SRSLTE_API void srslte_tc_interl_free(srslte_tc_interl_t *h); +SRSLTE_API void srslte_tc_interl_free(srslte_tc_interl_t* h); #endif // SRSLTE_TC_INTERL_H diff --git a/lib/include/srslte/phy/fec/turbocoder.h b/lib/include/srslte/phy/fec/turbocoder.h index 132d710c4..cb0b716e9 100644 --- a/lib/include/srslte/phy/fec/turbocoder.h +++ b/lib/include/srslte/phy/fec/turbocoder.h @@ -34,10 +34,10 @@ #define SRSLTE_TURBOCODER_H #include "srslte/config.h" -#include "srslte/phy/fec/tc_interl.h" #include "srslte/phy/fec/crc.h" +#include "srslte/phy/fec/tc_interl.h" -#define SRSLTE_TCOD_MAX_LEN_CB_BYTES (6144/8) +#define SRSLTE_TCOD_MAX_LEN_CB_BYTES (6144 / 8) #ifndef SRSLTE_TX_NULL #define SRSLTE_TX_NULL 100 @@ -45,34 +45,28 @@ typedef struct SRSLTE_API { uint32_t max_long_cb; - uint8_t *temp; + uint8_t* temp; } srslte_tcod_t; - -/* This structure is used as an output for the LUT version of the encoder. +/* This structure is used as an output for the LUT version of the encoder. * The encoder produces parity bits only and rate matching will interleave them * with the systematic bits */ -SRSLTE_API int srslte_tcod_init(srslte_tcod_t *h, - uint32_t max_long_cb); +SRSLTE_API int srslte_tcod_init(srslte_tcod_t* h, uint32_t max_long_cb); -SRSLTE_API void srslte_tcod_free(srslte_tcod_t *h); +SRSLTE_API void srslte_tcod_free(srslte_tcod_t* h); -SRSLTE_API int srslte_tcod_encode(srslte_tcod_t *h, - uint8_t *input, - uint8_t *output, - uint32_t long_cb); +SRSLTE_API int srslte_tcod_encode(srslte_tcod_t* h, uint8_t* input, uint8_t* output, uint32_t long_cb); -SRSLTE_API int srslte_tcod_encode_lut(srslte_tcod_t *h, - srslte_crc_t *crc_tb, - srslte_crc_t *crc_cb, - uint8_t *input, - uint8_t *parity, - uint32_t cblen_idx, - bool last_cb); +SRSLTE_API int srslte_tcod_encode_lut(srslte_tcod_t* h, + srslte_crc_t* crc_tb, + srslte_crc_t* crc_cb, + uint8_t* input, + uint8_t* parity, + uint32_t cblen_idx, + bool last_cb); -SRSLTE_API void srslte_tcod_gentable(); +SRSLTE_API void srslte_tcod_gentable(); #endif // SRSLTE_TURBOCODER_H - diff --git a/lib/include/srslte/phy/fec/turbodecoder.h b/lib/include/srslte/phy/fec/turbodecoder.h index c31c619c9..c00a79272 100644 --- a/lib/include/srslte/phy/fec/turbodecoder.h +++ b/lib/include/srslte/phy/fec/turbodecoder.h @@ -35,13 +35,13 @@ #define SRSLTE_TURBODECODER_H #include "srslte/config.h" -#include "srslte/phy/fec/tc_interl.h" #include "srslte/phy/fec/cbsegm.h" +#include "srslte/phy/fec/tc_interl.h" #define SRSLTE_TCOD_RATE 3 #define SRSLTE_TCOD_TOTALTAIL 12 -#define SRSLTE_TCOD_MAX_LEN_CB 6144 +#define SRSLTE_TCOD_MAX_LEN_CB 6144 // Expect the input to be aligned for sub-block window processing. #define SRSLTE_TDEC_EXPECT_INPUT_SB 1 @@ -55,84 +55,69 @@ #include "srslte/phy/fec/turbodecoder_impl.h" #undef LLR_IS_16BIT -#define SRSLTE_TDEC_NOF_AUTO_MODES_8 2 +#define SRSLTE_TDEC_NOF_AUTO_MODES_8 2 #define SRSLTE_TDEC_NOF_AUTO_MODES_16 3 -typedef enum {SRSLTE_TDEC_8, SRSLTE_TDEC_16} srslte_tdec_llr_type_t; +typedef enum { SRSLTE_TDEC_8, SRSLTE_TDEC_16 } srslte_tdec_llr_type_t; typedef struct SRSLTE_API { uint32_t max_long_cb; - void *dec8_hdlr[SRSLTE_TDEC_NOF_AUTO_MODES_8]; - void *dec16_hdlr[SRSLTE_TDEC_NOF_AUTO_MODES_16]; - srslte_tdec_8bit_impl_t *dec8[SRSLTE_TDEC_NOF_AUTO_MODES_8]; - srslte_tdec_16bit_impl_t *dec16[SRSLTE_TDEC_NOF_AUTO_MODES_16]; - int nof_blocks8[SRSLTE_TDEC_NOF_AUTO_MODES_8]; - int nof_blocks16[SRSLTE_TDEC_NOF_AUTO_MODES_16]; + void* dec8_hdlr[SRSLTE_TDEC_NOF_AUTO_MODES_8]; + void* dec16_hdlr[SRSLTE_TDEC_NOF_AUTO_MODES_16]; + srslte_tdec_8bit_impl_t* dec8[SRSLTE_TDEC_NOF_AUTO_MODES_8]; + srslte_tdec_16bit_impl_t* dec16[SRSLTE_TDEC_NOF_AUTO_MODES_16]; + int nof_blocks8[SRSLTE_TDEC_NOF_AUTO_MODES_8]; + int nof_blocks16[SRSLTE_TDEC_NOF_AUTO_MODES_16]; // Declare as void types as can be int8 or int16 - void *app1; - void *app2; - void *ext1; - void *ext2; - void *syst0; - void *parity0; - void *parity1; + void* app1; + void* app2; + void* ext1; + void* ext2; + void* syst0; + void* parity0; + void* parity1; - void *input_conv; + void* input_conv; bool force_not_sb; srslte_tdec_impl_type_t dec_type; srslte_tdec_llr_type_t current_llr_type; - uint32_t current_dec; - uint32_t current_long_cb; - uint32_t current_inter_idx; - int current_cbidx; - srslte_tc_interl_t interleaver[4][SRSLTE_NOF_TC_CB_SIZES]; - int n_iter; + uint32_t current_dec; + uint32_t current_long_cb; + uint32_t current_inter_idx; + int current_cbidx; + srslte_tc_interl_t interleaver[4][SRSLTE_NOF_TC_CB_SIZES]; + int n_iter; } srslte_tdec_t; -SRSLTE_API int srslte_tdec_init(srslte_tdec_t * h, - uint32_t max_long_cb); +SRSLTE_API int srslte_tdec_init(srslte_tdec_t* h, uint32_t max_long_cb); -SRSLTE_API int srslte_tdec_init_manual(srslte_tdec_t * h, - uint32_t max_long_cb, - srslte_tdec_impl_type_t dec_type); +SRSLTE_API int srslte_tdec_init_manual(srslte_tdec_t* h, uint32_t max_long_cb, srslte_tdec_impl_type_t dec_type); -SRSLTE_API void srslte_tdec_free(srslte_tdec_t * h); +SRSLTE_API void srslte_tdec_free(srslte_tdec_t* h); -SRSLTE_API void srslte_tdec_force_not_sb(srslte_tdec_t *h); +SRSLTE_API void srslte_tdec_force_not_sb(srslte_tdec_t* h); -SRSLTE_API int srslte_tdec_new_cb(srslte_tdec_t * h, - uint32_t long_cb); +SRSLTE_API int srslte_tdec_new_cb(srslte_tdec_t* h, uint32_t long_cb); -SRSLTE_API int srslte_tdec_get_nof_iterations(srslte_tdec_t * h); +SRSLTE_API int srslte_tdec_get_nof_iterations(srslte_tdec_t* h); SRSLTE_API uint32_t srslte_tdec_autoimp_get_subblocks(uint32_t long_cb); SRSLTE_API uint32_t srslte_tdec_autoimp_get_subblocks_8bit(uint32_t long_cb); -SRSLTE_API void srslte_tdec_iteration(srslte_tdec_t * h, - int16_t* input, - uint8_t *output); - -SRSLTE_API int srslte_tdec_run_all(srslte_tdec_t * h, - int16_t * input, - uint8_t *output, - uint32_t nof_iterations, - uint32_t long_cb); +SRSLTE_API void srslte_tdec_iteration(srslte_tdec_t* h, int16_t* input, uint8_t* output); -SRSLTE_API void srslte_tdec_iteration_8bit(srslte_tdec_t * h, - int8_t* input, - uint8_t *output); +SRSLTE_API int +srslte_tdec_run_all(srslte_tdec_t* h, int16_t* input, uint8_t* output, uint32_t nof_iterations, uint32_t long_cb); -SRSLTE_API int srslte_tdec_run_all_8bit(srslte_tdec_t * h, - int8_t * input, - uint8_t *output, - uint32_t nof_iterations, - uint32_t long_cb); +SRSLTE_API void srslte_tdec_iteration_8bit(srslte_tdec_t* h, int8_t* input, uint8_t* output); +SRSLTE_API int +srslte_tdec_run_all_8bit(srslte_tdec_t* h, int8_t* input, uint8_t* output, uint32_t nof_iterations, uint32_t long_cb); #endif // SRSLTE_TURBODECODER_H diff --git a/lib/include/srslte/phy/fec/turbodecoder_gen.h b/lib/include/srslte/phy/fec/turbodecoder_gen.h index 649916609..c84860b0e 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_gen.h +++ b/lib/include/srslte/phy/fec/turbodecoder_gen.h @@ -35,23 +35,28 @@ #define SRSLTE_TURBODECODER_GEN_H #include "srslte/config.h" -#include "srslte/phy/fec/tc_interl.h" #include "srslte/phy/fec/cbsegm.h" +#include "srslte/phy/fec/tc_interl.h" #define SRSLTE_TCOD_RATE 3 #define SRSLTE_TCOD_TOTALTAIL 12 -#define SRSLTE_TCOD_MAX_LEN_CB 6144 +#define SRSLTE_TCOD_MAX_LEN_CB 6144 typedef struct SRSLTE_API { uint32_t max_long_cb; - int16_t *beta; + int16_t* beta; } tdec_gen_t; -int tdec_gen_init(void **h, uint32_t max_long_cb); -void tdec_gen_free(void *h); -void tdec_gen_dec(void *h, int16_t * input, int16_t *app, int16_t * parity, int16_t *output, uint32_t long_cb); -void tdec_gen_extract_input(int16_t *input, int16_t *syst, int16_t *parity0, int16_t *parity1, int16_t *app2, uint32_t long_cb); -void tdec_gen_decision_byte(int16_t *app1, uint8_t *output, uint32_t long_cb); +int tdec_gen_init(void** h, uint32_t max_long_cb); +void tdec_gen_free(void* h); +void tdec_gen_dec(void* h, int16_t* input, int16_t* app, int16_t* parity, int16_t* output, uint32_t long_cb); +void tdec_gen_extract_input(int16_t* input, + int16_t* syst, + int16_t* parity0, + int16_t* parity1, + int16_t* app2, + uint32_t long_cb); +void tdec_gen_decision_byte(int16_t* app1, uint8_t* output, uint32_t long_cb); #endif // SRSLTE_TURBODECODER_GEN_H diff --git a/lib/include/srslte/phy/fec/turbodecoder_impl.h b/lib/include/srslte/phy/fec/turbodecoder_impl.h index 82402efc3..eadfc9e9a 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_impl.h +++ b/lib/include/srslte/phy/fec/turbodecoder_impl.h @@ -43,21 +43,20 @@ typedef enum SRSLTE_API { #define llr_t int8_t #define type_name srslte_tdec_8bit_impl_t #else - #ifdef LLR_IS_16BIT - #define llr_t int16_t +#ifdef LLR_IS_16BIT +#define llr_t int16_t #define type_name srslte_tdec_16bit_impl_t - #else - #error "Unsupported LLR mode" - #endif +#else +#error "Unsupported LLR mode" +#endif #endif - typedef struct SRSLTE_API { - int (*tdec_init)(void **h, uint32_t max_long_cb); - void (*tdec_free)(void *h); - void (*tdec_dec)(void *h, llr_t * input, llr_t *app, llr_t * parity, llr_t *output, uint32_t long_cb); - void (*tdec_extract_input)(llr_t *input, llr_t *syst, llr_t *parity0, llr_t *parity1, llr_t *app2, uint32_t long_cb); - void (*tdec_decision_byte)(llr_t *app1, uint8_t *output, uint32_t long_cb); + int (*tdec_init)(void** h, uint32_t max_long_cb); + void (*tdec_free)(void* h); + void (*tdec_dec)(void* h, llr_t* input, llr_t* app, llr_t* parity, llr_t* output, uint32_t long_cb); + void (*tdec_extract_input)(llr_t* input, llr_t* syst, llr_t* parity0, llr_t* parity1, llr_t* app2, uint32_t long_cb); + void (*tdec_decision_byte)(llr_t* app1, uint8_t* output, uint32_t long_cb); } type_name; #undef llr_t diff --git a/lib/include/srslte/phy/fec/turbodecoder_iter.h b/lib/include/srslte/phy/fec/turbodecoder_iter.h index 4b0748abd..7d66d4429 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_iter.h +++ b/lib/include/srslte/phy/fec/turbodecoder_iter.h @@ -21,9 +21,9 @@ #include "srslte/config.h" -#define MAKE_CALL(a) CONCAT2(a,type_name) -#define MAKE_VEC(a) CONCAT2(a,vec_suffix) -#define PRINT CONCAT2(srslte_vec_fprint,print_suffix) +#define MAKE_CALL(a) CONCAT2(a, type_name) +#define MAKE_VEC(a) CONCAT2(a, vec_suffix) +#define PRINT CONCAT2(srslte_vec_fprint, print_suffix) #ifdef LLR_IS_8BIT #define llr_t int8_t @@ -35,59 +35,63 @@ #define input_is_interleaved 1 #else #ifdef LLR_IS_16BIT - #define llr_t int16_t - #define vec_suffix _sss - #define print_suffix _s - #define decptr h->dec16[h->current_dec] - #define dechdlr h->dec16_hdlr[h->current_dec] - #define input_is_interleaved (h->current_dec > 0) +#define llr_t int16_t +#define vec_suffix _sss +#define print_suffix _s +#define decptr h->dec16[h->current_dec] +#define dechdlr h->dec16_hdlr[h->current_dec] +#define input_is_interleaved (h->current_dec > 0) #define type_name _16bit - #else +#else #pragma message "Unsupported LLR mode" #endif #endif #define debug_enabled_iter 0 -#define debug_len 20 - -#define debug_vec(a) if (debug_enabled_iter) {printf("%s it=%d: ", STRING(a), n_iter);PRINT(stdout, a, debug_len);} +#define debug_len 20 +#define debug_vec(a) \ + if (debug_enabled_iter) { \ + printf("%s it=%d: ", STRING(a), n_iter); \ + PRINT(stdout, a, debug_len); \ + } -static void MAKE_CALL(extract_input_tail_sb)(llr_t *input, llr_t *syst, llr_t *app2, llr_t *parity0, llr_t *parity1, uint32_t long_cb) +static void MAKE_CALL( + extract_input_tail_sb)(llr_t* input, llr_t* syst, llr_t* app2, llr_t* parity0, llr_t* parity1, uint32_t long_cb) { for (int i = long_cb; i < long_cb + 3; i++) { - syst[i] = input[3*(long_cb+32) + 2*(i - long_cb)]; - parity0[i] = input[3*(long_cb+32)+ 2*(i - long_cb) + 1]; + syst[i] = input[3 * (long_cb + 32) + 2 * (i - long_cb)]; + parity0[i] = input[3 * (long_cb + 32) + 2 * (i - long_cb) + 1]; - app2[i] = input[3*(long_cb+32) + 6 + 2*(i - long_cb)]; - parity1[i] = input[3*(long_cb+32) + 6 + 2*(i - long_cb) + 1]; + app2[i] = input[3 * (long_cb + 32) + 6 + 2 * (i - long_cb)]; + parity1[i] = input[3 * (long_cb + 32) + 6 + 2 * (i - long_cb) + 1]; } } /* Runs 1 turbo decoder iteration */ -void MAKE_CALL(run_tdec_iteration)(srslte_tdec_t * h, llr_t * input) +void MAKE_CALL(run_tdec_iteration)(srslte_tdec_t* h, llr_t* input) { if (h->current_cbidx >= 0) { - uint16_t *inter = h->interleaver[h->current_inter_idx][h->current_cbidx].forward; - uint16_t *deinter = h->interleaver[h->current_inter_idx][h->current_cbidx].reverse; - llr_t *syst = (llr_t*) h->syst0; - llr_t *parity0 = (llr_t*) h->parity0; - llr_t *parity1 = (llr_t*) h->parity1; + uint16_t* inter = h->interleaver[h->current_inter_idx][h->current_cbidx].forward; + uint16_t* deinter = h->interleaver[h->current_inter_idx][h->current_cbidx].reverse; + llr_t* syst = (llr_t*)h->syst0; + llr_t* parity0 = (llr_t*)h->parity0; + llr_t* parity1 = (llr_t*)h->parity1; - llr_t *app1 = (llr_t*) h->app1; - llr_t *app2 = (llr_t*) h->app2; - llr_t *ext1 = (llr_t*) h->ext1; - llr_t *ext2 = (llr_t*) h->ext2; + llr_t* app1 = (llr_t*)h->app1; + llr_t* app2 = (llr_t*)h->app2; + llr_t* ext1 = (llr_t*)h->ext1; + llr_t* ext2 = (llr_t*)h->ext2; uint32_t long_cb = h->current_long_cb; uint32_t n_iter = h->n_iter; - + if (SRSLTE_TDEC_EXPECT_INPUT_SB && !h->force_not_sb && input_is_interleaved) { syst = input; // align to 32 bytes (warning: must be same alignment as in rm_turbo.c) - parity0 = &input[long_cb+32]; - parity1 = &input[2*(long_cb+32)]; + parity0 = &input[long_cb + 32]; + parity1 = &input[2 * (long_cb + 32)]; if (n_iter == 0) { MAKE_CALL(extract_input_tail_sb)(input, syst, app2, parity0, parity1, long_cb); } @@ -96,8 +100,8 @@ void MAKE_CALL(run_tdec_iteration)(srslte_tdec_t * h, llr_t * input) decptr->tdec_extract_input(input, syst, app2, parity0, parity1, long_cb); } } - - if ((n_iter%2) == 0) { + + if ((n_iter % 2) == 0) { // Add apriori information to decoder 1 if (n_iter) { @@ -106,10 +110,9 @@ void MAKE_CALL(run_tdec_iteration)(srslte_tdec_t * h, llr_t * input) // Run MAP DEC #1 decptr->tdec_dec(dechdlr, syst, n_iter ? app1 : NULL, parity0, ext1, long_cb); - } // Interleave extrinsic output of DEC1 to form apriori info for decoder 2 - if (n_iter%2) { + if (n_iter % 2) { // Convert aposteriori information into extrinsic information if (n_iter > 1) { MAKE_VEC(srslte_vec_sub)(ext1, app1, ext1, long_cb); @@ -121,8 +124,7 @@ void MAKE_CALL(run_tdec_iteration)(srslte_tdec_t * h, llr_t * input) decptr->tdec_dec(dechdlr, app2, NULL, parity1, ext2, long_cb); // Deinterleaved extrinsic bits become apriori info for decoder 1 - MAKE_VEC(srslte_vec_lut)(ext2, inter, app1, long_cb); - + MAKE_VEC(srslte_vec_lut)(ext2, inter, app1, long_cb); } if (h->n_iter == 0) { diff --git a/lib/include/srslte/phy/fec/turbodecoder_sse.h b/lib/include/srslte/phy/fec/turbodecoder_sse.h index 820199eaf..63ea2eb10 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_sse.h +++ b/lib/include/srslte/phy/fec/turbodecoder_sse.h @@ -26,15 +26,19 @@ typedef struct SRSLTE_API { uint32_t max_long_cb; - int16_t *alpha; - int16_t *branch; + int16_t* alpha; + int16_t* branch; } tdec_sse_t; -int tdec_sse_init(void **h, uint32_t max_long_cb); -void tdec_sse_free(void *h); -void tdec_sse_dec(void *h, int16_t * input, int16_t *app, int16_t * parity, - int16_t *output, uint32_t long_cb); -void tdec_sse_extract_input(int16_t *input, int16_t *syst, int16_t *parity0, int16_t *parity1, int16_t *app2, uint32_t long_cb); -void tdec_sse_decision_byte(int16_t *app1, uint8_t *output, uint32_t long_cb); +int tdec_sse_init(void** h, uint32_t max_long_cb); +void tdec_sse_free(void* h); +void tdec_sse_dec(void* h, int16_t* input, int16_t* app, int16_t* parity, int16_t* output, uint32_t long_cb); +void tdec_sse_extract_input(int16_t* input, + int16_t* syst, + int16_t* parity0, + int16_t* parity1, + int16_t* app2, + uint32_t long_cb); +void tdec_sse_decision_byte(int16_t* app1, uint8_t* output, uint32_t long_cb); #endif // SRSLTE_TURBODECODER_SSE_H diff --git a/lib/include/srslte/phy/fec/turbodecoder_win.h b/lib/include/srslte/phy/fec/turbodecoder_win.h index aceb0a07f..7579cca47 100644 --- a/lib/include/srslte/phy/fec/turbodecoder_win.h +++ b/lib/include/srslte/phy/fec/turbodecoder_win.h @@ -21,37 +21,37 @@ #include "srslte/config.h" -#define MAKE_FUNC(a) CONCAT2(CONCAT2(tdec_win,WINIMP),CONCAT2(_,a)) -#define MAKE_TYPE CONCAT2(CONCAT2(tdec_win_,WINIMP),_t) +#define MAKE_FUNC(a) CONCAT2(CONCAT2(tdec_win, WINIMP), CONCAT2(_, a)) +#define MAKE_TYPE CONCAT2(CONCAT2(tdec_win_, WINIMP), _t) #ifdef WINIMP_IS_SSE16 - #ifndef LV_HAVE_SSE - #error "Selected SSE window decoder but instruction set not supported" - #endif +#ifndef LV_HAVE_SSE +#error "Selected SSE window decoder but instruction set not supported" +#endif - #include +#include - #define WINIMP sse16 - #define nof_blocks 8 +#define WINIMP sse16 +#define nof_blocks 8 - #define llr_t int16_t +#define llr_t int16_t - #define simd_type_t __m128i - #define simd_load _mm_load_si128 - #define simd_store _mm_store_si128 - #define simd_add _mm_adds_epi16 - #define simd_sub _mm_subs_epi16 - #define simd_max _mm_max_epi16 - #define simd_set1 _mm_set1_epi16 - #define simd_insert _mm_insert_epi16 - #define simd_shuffle _mm_shuffle_epi8 - #define move_right _mm_set_epi8(15,14,15,14,13,12,11,10,9,8,7,6,5,4,3,2) - #define move_left _mm_set_epi8(13,12,11,10,9,8,7,6,5,4,3,2,1,0,1,0) - #define simd_rb_shift _mm_srai_epi16 +#define simd_type_t __m128i +#define simd_load _mm_load_si128 +#define simd_store _mm_store_si128 +#define simd_add _mm_adds_epi16 +#define simd_sub _mm_subs_epi16 +#define simd_max _mm_max_epi16 +#define simd_set1 _mm_set1_epi16 +#define simd_insert _mm_insert_epi16 +#define simd_shuffle _mm_shuffle_epi8 +#define move_right _mm_set_epi8(15, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2) +#define move_left _mm_set_epi8(13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 0) +#define simd_rb_shift _mm_srai_epi16 - #define normalize_period 2 - #define win_overlap_len 40 +#define normalize_period 2 +#define win_overlap_len 40 #define divide_output 1 @@ -60,151 +60,275 @@ #else #ifdef WINIMP_IS_AVX16 - #ifndef LV_HAVE_AVX2 - #error "Selected AVX2 window decoder but instruction set not supported" - #endif - - #include - - #define WINIMP avx16 - #define nof_blocks 16 - - #define llr_t int16_t - - #define simd_type_t __m256i - #define simd_load _mm256_load_si256 - #define simd_store _mm256_store_si256 - #define simd_add _mm256_adds_epi16 - #define simd_sub _mm256_subs_epi16 - #define simd_max _mm256_max_epi16 - #define simd_set1 _mm256_set1_epi16 - #define simd_insert _mm256_insert_epi16 - #define simd_shuffle _mm256_shuffle_epi8 - #define move_right _mm256_set_epi8(31,30,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2) - #define move_left _mm256_set_epi8(29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,1,0) +#ifndef LV_HAVE_AVX2 +#error "Selected AVX2 window decoder but instruction set not supported" +#endif - #define normalize_period 2 - #define win_overlap_len 40 +#include + +#define WINIMP avx16 +#define nof_blocks 16 + +#define llr_t int16_t + +#define simd_type_t __m256i +#define simd_load _mm256_load_si256 +#define simd_store _mm256_store_si256 +#define simd_add _mm256_adds_epi16 +#define simd_sub _mm256_subs_epi16 +#define simd_max _mm256_max_epi16 +#define simd_set1 _mm256_set1_epi16 +#define simd_insert _mm256_insert_epi16 +#define simd_shuffle _mm256_shuffle_epi8 +#define move_right \ + _mm256_set_epi8(31, \ + 30, \ + 31, \ + 30, \ + 29, \ + 28, \ + 27, \ + 26, \ + 25, \ + 24, \ + 23, \ + 22, \ + 21, \ + 20, \ + 19, \ + 18, \ + 17, \ + 16, \ + 15, \ + 14, \ + 13, \ + 12, \ + 11, \ + 10, \ + 9, \ + 8, \ + 7, \ + 6, \ + 5, \ + 4, \ + 3, \ + 2) +#define move_left \ + _mm256_set_epi8(29, \ + 28, \ + 27, \ + 26, \ + 25, \ + 24, \ + 23, \ + 22, \ + 21, \ + 20, \ + 19, \ + 18, \ + 17, \ + 16, \ + 15, \ + 14, \ + 13, \ + 12, \ + 11, \ + 10, \ + 9, \ + 8, \ + 7, \ + 6, \ + 5, \ + 4, \ + 3, \ + 2, \ + 1, \ + 0, \ + 1, \ + 0) + +#define normalize_period 2 +#define win_overlap_len 40 - #define INF 10000 +#define INF 10000 #else #ifdef WINIMP_IS_SSE8 - #ifndef LV_HAVE_SSE - #error "Selected SSE window decoder but instruction set not supported" - #endif - - #include - - #define WINIMP sse8 - #define nof_blocks 16 - - #define llr_t int8_t - - #define simd_type_t __m128i - #define simd_load _mm_load_si128 - #define simd_store _mm_store_si128 - #define simd_add _mm_adds_epi8 - #define simd_sub _mm_subs_epi8 - #define simd_max _mm_max_epi8 - #define simd_set1 _mm_set1_epi8 - #define simd_insert _mm_insert_epi8 - #define simd_shuffle _mm_shuffle_epi8 - #define move_right _mm_set_epi8(15,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1) - #define move_left _mm_set_epi8(14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,0) - #define simd_rb_shift simd_rb_shift_128 - - #define normalize_max - #define normalize_period 1 - #define win_overlap_len 40 - #define use_saturated_add - #define divide_output 1 - - #define INF 0 - - inline static simd_type_t simd_rb_shift_128(simd_type_t v, const int l) { - __m128i low = _mm_srai_epi16(_mm_slli_epi16(v,8), l+8); - __m128i hi = _mm_srai_epi16(v,l); - return _mm_blendv_epi8(hi, low, _mm_set1_epi32(0x00FF00FF)); - } +#ifndef LV_HAVE_SSE +#error "Selected SSE window decoder but instruction set not supported" +#endif + +#include + +#define WINIMP sse8 +#define nof_blocks 16 + +#define llr_t int8_t + +#define simd_type_t __m128i +#define simd_load _mm_load_si128 +#define simd_store _mm_store_si128 +#define simd_add _mm_adds_epi8 +#define simd_sub _mm_subs_epi8 +#define simd_max _mm_max_epi8 +#define simd_set1 _mm_set1_epi8 +#define simd_insert _mm_insert_epi8 +#define simd_shuffle _mm_shuffle_epi8 +#define move_right _mm_set_epi8(15, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) +#define move_left _mm_set_epi8(14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0) +#define simd_rb_shift simd_rb_shift_128 + +#define normalize_max +#define normalize_period 1 +#define win_overlap_len 40 +#define use_saturated_add +#define divide_output 1 +#define INF 0 + +inline static simd_type_t simd_rb_shift_128(simd_type_t v, const int l) +{ + __m128i low = _mm_srai_epi16(_mm_slli_epi16(v, 8), l + 8); + __m128i hi = _mm_srai_epi16(v, l); + return _mm_blendv_epi8(hi, low, _mm_set1_epi32(0x00FF00FF)); +} #else #ifdef WINIMP_IS_AVX8 - #ifndef LV_HAVE_AVX2 - #error "Selected AVX2 window decoder but instruction set not supported" - #endif - - #include - - #define WINIMP avx8 - #define nof_blocks 32 - - #define llr_t int8_t - - #define simd_type_t __m256i - #define simd_load _mm256_load_si256 - #define simd_store _mm256_store_si256 - #define simd_add _mm256_adds_epi8 - #define simd_sub _mm256_subs_epi8 - #define simd_max _mm256_max_epi8 - #define simd_set1 _mm256_set1_epi8 - #define simd_insert _mm256_insert_epi8 - #define simd_shuffle _mm256_shuffle_epi8 - #define move_right _mm256_set_epi8(31,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1) - #define move_left _mm256_set_epi8(30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,0) - #define simd_rb_shift simd_rb_shift_256 - - #define INF 0 - - #define normalize_max - #define normalize_period 1 - #define win_overlap_len 40 - #define use_saturated_add - #define divide_output 1 - - inline static simd_type_t simd_rb_shift_256(simd_type_t v, const int l) { - __m256i low = _mm256_srai_epi16(_mm256_slli_epi16(v,8), l+8); - __m256i hi = _mm256_srai_epi16(v,l); - return _mm256_blendv_epi8(hi, low, _mm256_set1_epi32(0x00FF00FF)); - } +#ifndef LV_HAVE_AVX2 +#error "Selected AVX2 window decoder but instruction set not supported" +#endif +#include + +#define WINIMP avx8 +#define nof_blocks 32 + +#define llr_t int8_t + +#define simd_type_t __m256i +#define simd_load _mm256_load_si256 +#define simd_store _mm256_store_si256 +#define simd_add _mm256_adds_epi8 +#define simd_sub _mm256_subs_epi8 +#define simd_max _mm256_max_epi8 +#define simd_set1 _mm256_set1_epi8 +#define simd_insert _mm256_insert_epi8 +#define simd_shuffle _mm256_shuffle_epi8 +#define move_right \ + _mm256_set_epi8(31, \ + 31, \ + 30, \ + 29, \ + 28, \ + 27, \ + 26, \ + 25, \ + 24, \ + 23, \ + 22, \ + 21, \ + 20, \ + 19, \ + 18, \ + 17, \ + 16, \ + 15, \ + 14, \ + 13, \ + 12, \ + 11, \ + 10, \ + 9, \ + 8, \ + 7, \ + 6, \ + 5, \ + 4, \ + 3, \ + 2, \ + 1) +#define move_left \ + _mm256_set_epi8(30, \ + 29, \ + 28, \ + 27, \ + 26, \ + 25, \ + 24, \ + 23, \ + 22, \ + 21, \ + 20, \ + 19, \ + 18, \ + 17, \ + 16, \ + 15, \ + 14, \ + 13, \ + 12, \ + 11, \ + 10, \ + 9, \ + 8, \ + 7, \ + 6, \ + 5, \ + 4, \ + 3, \ + 2, \ + 1, \ + 0, \ + 0) +#define simd_rb_shift simd_rb_shift_256 + +#define INF 0 + +#define normalize_max +#define normalize_period 1 +#define win_overlap_len 40 +#define use_saturated_add +#define divide_output 1 + +inline static simd_type_t simd_rb_shift_256(simd_type_t v, const int l) +{ + __m256i low = _mm256_srai_epi16(_mm256_slli_epi16(v, 8), l + 8); + __m256i hi = _mm256_srai_epi16(v, l); + return _mm256_blendv_epi8(hi, low, _mm256_set1_epi32(0x00FF00FF)); +} #else #ifdef WINIMP_IS_NEON16 - #include +#include + +#define WINIMP arm16 +#define nof_blocks 8 - #define WINIMP arm16 - #define nof_blocks 8 +#define llr_t int16_t - #define llr_t int16_t +#define v_insert_s16(a, b, imm) ({ (vsetq_lane_s16((b), (a), (imm))); }) - - - #define v_insert_s16(a, b, imm) \ - ({ \ - (vsetq_lane_s16((b), (a), (imm))); \ - }) +#define int8x16_to_8x8x2(v) ((int8x8x2_t){{vget_low_s8(v), vget_high_s8(v)}}) // TODO - #define int8x16_to_8x8x2(v) ((int8x8x2_t) {{ vget_low_s8(v), vget_high_s8(v) }})// TODO +static inline int movemask_neon(uint8x16_t movemask_low_in) +{ -static inline int movemask_neon(uint8x16_t movemask_low_in) { - - uint8x8_t mask_and = vdup_n_u8(0x80); + uint8x8_t mask_and = vdup_n_u8(0x80); int8_t __attribute__((aligned(16))) xr[8]; - for(int i = 0; i <8;i++) - xr[i] = i-7; - - int8x8_t mask_shift = vld1_s8(xr); - uint8x8_t lo = vget_low_u8(movemask_low_in); - uint8x8_t hi = vget_high_u8(movemask_low_in); - lo = vand_u8(lo, mask_and); - lo = vshl_u8(lo, mask_shift); - hi = vand_u8(hi, mask_and); - hi = vshl_u8(hi, mask_shift); + for (int i = 0; i < 8; i++) + xr[i] = i - 7; + + int8x8_t mask_shift = vld1_s8(xr); + uint8x8_t lo = vget_low_u8(movemask_low_in); + uint8x8_t hi = vget_high_u8(movemask_low_in); + lo = vand_u8(lo, mask_and); + lo = vshl_u8(lo, mask_shift); + hi = vand_u8(hi, mask_and); + hi = vshl_u8(hi, mask_shift); lo = vpadd_u8(lo, lo); lo = vpadd_u8(lo, lo); @@ -216,56 +340,71 @@ static inline int movemask_neon(uint8x16_t movemask_low_in) { return ((hi[0] << 8) | (lo[0] & 0xFF)); } - inline static int16x8_t vshuff_s8(int16x8_t in, uint8x16_t mask) +inline static int16x8_t vshuff_s8(int16x8_t in, uint8x16_t mask) { - int8x8x2_t x = int8x16_to_8x8x2((int8x16_t)in); - int8x8_t u = (int8x8_t)vget_low_u8(mask); - int8x8_t eq = vtbl2_s8(x,u); - - int8x8x2_t x2 = int8x16_to_8x8x2((int8x16_t)in); - int8x8_t u2 = (int8x8_t)vget_high_u8(mask); - int8x8_t eq2 = vtbl2_s8(x2,u2); - return (int16x8_t)vcombine_s8(eq,eq2); + int8x8x2_t x = int8x16_to_8x8x2((int8x16_t)in); + int8x8_t u = (int8x8_t)vget_low_u8(mask); + int8x8_t eq = vtbl2_s8(x, u); + + int8x8x2_t x2 = int8x16_to_8x8x2((int8x16_t)in); + int8x8_t u2 = (int8x8_t)vget_high_u8(mask); + int8x8_t eq2 = vtbl2_s8(x2, u2); + return (int16x8_t)vcombine_s8(eq, eq2); } - static inline int16x8_t v_packs_s16(int16x8_t a, int16x8_t b) +static inline int16x8_t v_packs_s16(int16x8_t a, int16x8_t b) { - return (int16x8_t)(vcombine_s8(vqmovn_s16((a)), vqmovn_s16((b)))); + return (int16x8_t)(vcombine_s8(vqmovn_s16((a)), vqmovn_s16((b)))); } - -inline static int16x8_t v_srai_s16(const int16x8_t a, const int count) { - int16x8_t b = vmovq_n_s16(-count); - return vshlq_s16(a,b); +inline static int16x8_t v_srai_s16(const int16x8_t a, const int count) +{ + int16x8_t b = vmovq_n_s16(-count); + return vshlq_s16(a, b); } -inline static uint8x16_t v_load_s8(int i15, int i14, int i13, int i12, int i11, int i10, int i9, int i8, int i7, int i6, int i5, int i4, int i3, int i2, int i1, int i0) +inline static uint8x16_t v_load_s8(int i15, + int i14, + int i13, + int i12, + int i11, + int i10, + int i9, + int i8, + int i7, + int i6, + int i5, + int i4, + int i3, + int i2, + int i1, + int i0) { - uint8_t __attribute__((aligned(16))) data[16] = {i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15}; - return vld1q_u8(data); + uint8_t __attribute__((aligned(16))) + data[16] = {i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15}; + return vld1q_u8(data); } - - - #define simd_type_t int16x8_t - #define simd_load(x) vld1q_s16((int16_t*)x) - #define simd_store(x,y) vst1q_s16((int16_t*)x,y) - #define simd_add vaddq_s16 - #define simd_sub vsubq_s16 - #define simd_max vmaxq_s16 - #define simd_set1 vdupq_n_s16 - #define simd_insert v_insert_s16 - #define simd_shuffle vshuff_s8 - #define move_right v_load_s8(15,14,15,14,13,12,11,10,9,8,7,6,5,4,3,2) - #define move_left v_load_s8(13,12,11,10,9,8,7,6,5,4,3,2,1,0,1,0) - #define simd_rb_shift v_srai_s16 - - #define normalize_period 2 - #define win_overlap_len 40 + +#define simd_type_t int16x8_t +#define simd_load(x) vld1q_s16((int16_t*)x) +#define simd_store(x, y) vst1q_s16((int16_t*)x, y) +#define simd_add vaddq_s16 +#define simd_sub vsubq_s16 +#define simd_max vmaxq_s16 +#define simd_set1 vdupq_n_s16 +#define simd_insert v_insert_s16 +#define simd_shuffle vshuff_s8 +#define move_right v_load_s8(15, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2) +#define move_left v_load_s8(13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 0) +#define simd_rb_shift v_srai_s16 + +#define normalize_period 2 +#define win_overlap_len 40 #define divide_output 1 #define INF 10000 - + #else - #error "Unknown WINIMP value" +#error "Unknown WINIMP value" #endif #endif @@ -275,36 +414,48 @@ inline static uint8x16_t v_load_s8(int i15, int i14, int i13, int i12, int i11, typedef struct SRSLTE_API { uint32_t max_long_cb; - llr_t *beta; + llr_t* beta; } MAKE_TYPE; - -#define long_sb (long_cb/nof_blocks) - - +#define long_sb (long_cb / nof_blocks) #define debug_enabled_win 0 #if debug_enabled_win -#define debug_state(d) printf("k=%5d, in=%5d, pa=%3d, out=%5d, alpha=[", d*long_sb+k+1, MAKE_FUNC(get_simd)(x,d), MAKE_FUNC(get_simd)(y,d), MAKE_FUNC(get_simd)(out,d)); \ - for (int j=0;j<8;j++) printf("%5d, ", MAKE_FUNC(get_simd)(old[j],d)); \ - printf("], beta=["); \ - for (int j=0;j<8;j++) printf("%5d, ", MAKE_FUNC(get_simd)(beta_save[j], d));printf("\n"); - -#define debug_state_pre(d) printf("pre-window k=%5d, in=%5d, pa=%3d, alpha=[", (d+1)*long_sb-loop_len+k+1, MAKE_FUNC(get_simd)(x,d), MAKE_FUNC(get_simd)(y,d)); \ - for (int j=0;j<8;j++) printf("%5d, ", MAKE_FUNC(get_simd)(old[j],d)); \ - printf("]\n"); +#define debug_state(d) \ + printf("k=%5d, in=%5d, pa=%3d, out=%5d, alpha=[", \ + d* long_sb + k + 1, \ + MAKE_FUNC(get_simd)(x, d), \ + MAKE_FUNC(get_simd)(y, d), \ + MAKE_FUNC(get_simd)(out, d)); \ + for (int j = 0; j < 8; j++) \ + printf("%5d, ", MAKE_FUNC(get_simd)(old[j], d)); \ + printf("], beta=["); \ + for (int j = 0; j < 8; j++) \ + printf("%5d, ", MAKE_FUNC(get_simd)(beta_save[j], d)); \ + printf("\n"); + +#define debug_state_pre(d) \ + printf("pre-window k=%5d, in=%5d, pa=%3d, alpha=[", \ + (d + 1) * long_sb - loop_len + k + 1, \ + MAKE_FUNC(get_simd)(x, d), \ + MAKE_FUNC(get_simd)(y, d)); \ + for (int j = 0; j < 8; j++) \ + printf("%5d, ", MAKE_FUNC(get_simd)(old[j], d)); \ + printf("]\n"); -#define debug_state_beta(d) printf("k=%5d, in=%5d, pa=%3d, beta=[", d*long_sb+k, MAKE_FUNC(get_simd)(x,d), MAKE_FUNC(get_simd)(y,d)); \ - for (int j=0;j<8;j++) printf("%5d, ", MAKE_FUNC(get_simd)(old[j],d));\ - printf("\n"); +#define debug_state_beta(d) \ + printf("k=%5d, in=%5d, pa=%3d, beta=[", d* long_sb + k, MAKE_FUNC(get_simd)(x, d), MAKE_FUNC(get_simd)(y, d)); \ + for (int j = 0; j < 8; j++) \ + printf("%5d, ", MAKE_FUNC(get_simd)(old[j], d)); \ + printf("\n"); -static llr_t MAKE_FUNC(get_simd)(simd_type_t x, uint32_t pos) { - llr_t *s = (llr_t*) &x; +static llr_t MAKE_FUNC(get_simd)(simd_type_t x, uint32_t pos) +{ + llr_t* s = (llr_t*)&x; return s[pos]; } - #else #define debug_state(a) #define debug_state_pre(a) @@ -320,23 +471,25 @@ static void MAKE_FUNC(print_simd)(simd_type_t x) { printf("]\n"); }*/ -inline static llr_t MAKE_FUNC(sadd)(llr_t x, llr_t y) { +inline static llr_t MAKE_FUNC(sadd)(llr_t x, llr_t y) +{ #ifndef use_saturated_add - return x+y; + return x + y; #else - int16_t z = (int16_t) x+y; - return z>127?127:(int8_t) z; + int16_t z = (int16_t)x + y; + return z > 127 ? 127 : (int8_t)z; #endif } -inline static void MAKE_FUNC(normalize)(uint32_t k, simd_type_t old[8]) { +inline static void MAKE_FUNC(normalize)(uint32_t k, simd_type_t old[8]) +{ if ((k % normalize_period) == 0 && k != 0) { #ifdef normalize_max - simd_type_t m = simd_max(old[0],old[1]); - for (int i=2;i<8;i++) { - m = simd_max(m,old[i]); + simd_type_t m = simd_max(old[0], old[1]); + for (int i = 2; i < 8; i++) { + m = simd_max(m, old[i]); } - for (int i=0;i<8;i++) { + for (int i = 0; i < 8; i++) { old[i] = simd_sub(old[i], m); } #else @@ -348,7 +501,7 @@ inline static void MAKE_FUNC(normalize)(uint32_t k, simd_type_t old[8]) { } } -static void MAKE_FUNC(beta_trellis)(llr_t *input, llr_t *parity, uint32_t long_cb, llr_t old[8]) +static void MAKE_FUNC(beta_trellis)(llr_t* input, llr_t* parity, uint32_t long_cb, llr_t old[8]) { llr_t m_b[8], new[8]; llr_t x, y, xy; @@ -358,13 +511,13 @@ static void MAKE_FUNC(beta_trellis)(llr_t *input, llr_t *parity, uint32_t long_c for (int i = 1; i < 8; i++) { old[i] = -INF; } - for (int k=long_cb+2;k >= long_cb; k--) { + for (int k = long_cb + 2; k >= long_cb; k--) { x = input[k]; y = parity[k]; xy = MAKE_FUNC(sadd)(x, y); - m_b[0] = MAKE_FUNC(sadd)(old[4],xy); + m_b[0] = MAKE_FUNC(sadd)(old[4], xy); m_b[1] = old[4]; m_b[2] = MAKE_FUNC(sadd)(old[5], y); m_b[3] = MAKE_FUNC(sadd)(old[5], x); @@ -383,7 +536,11 @@ static void MAKE_FUNC(beta_trellis)(llr_t *input, llr_t *parity, uint32_t long_c new[7] = old[3]; #if debug_enabled_win - printf("trellis: k=%d, in=%d, pa=%d, beta: ", k, x, y); for (int i=0;i<8;i++) {printf("%d,", old[i]);} printf("\n"); + printf("trellis: k=%d, in=%d, pa=%d, beta: ", k, x, y); + for (int i = 0; i < 8; i++) { + printf("%d,", old[i]); + } + printf("\n"); #endif for (int i = 0; i < 8; i++) { @@ -395,15 +552,15 @@ static void MAKE_FUNC(beta_trellis)(llr_t *input, llr_t *parity, uint32_t long_c } /* Computes beta values */ -static void MAKE_FUNC(beta)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *parity, uint32_t long_cb) +static void MAKE_FUNC(beta)(MAKE_TYPE* s, llr_t* input, llr_t* app, llr_t* parity, uint32_t long_cb) { simd_type_t m_b[8], new[8], old[8]; simd_type_t x, y, xy, ap; - simd_type_t *inputPtr; - simd_type_t *appPtr; - simd_type_t *parityPtr; - simd_type_t *betaPtr = (simd_type_t*) s->beta; + simd_type_t* inputPtr; + simd_type_t* appPtr; + simd_type_t* parityPtr; + simd_type_t* betaPtr = (simd_type_t*)s->beta; // Inititialize old state for (int i = 0; i < 8; i++) { @@ -411,10 +568,10 @@ static void MAKE_FUNC(beta)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *pari } uint32_t loop_len; - for (int j=0;j<2;j++) { + for (int j = 0; j < 2; j++) { // First run L states to find initial state for all sub-blocks after first - if (j==0) { + if (j == 0) { loop_len = win_overlap_len; } else { loop_len = long_sb; @@ -444,7 +601,7 @@ static void MAKE_FUNC(beta)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *pari llr_t trellis_old[8]; MAKE_FUNC(beta_trellis)(input, parity, long_cb, trellis_old); for (int i = 0; i < 8; i++) { - old[i] = simd_insert(old[i], trellis_old[i], nof_blocks-1); + old[i] = simd_insert(old[i], trellis_old[i], nof_blocks - 1); } #ifdef WINIMP_IS_AVX16 @@ -458,12 +615,12 @@ static void MAKE_FUNC(beta)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *pari } #endif - inputPtr = (simd_type_t*) &input[long_cb-nof_blocks]; - appPtr = (simd_type_t*) &app[long_cb-nof_blocks]; - parityPtr = (simd_type_t*) &parity[long_cb-nof_blocks]; + inputPtr = (simd_type_t*)&input[long_cb - nof_blocks]; + appPtr = (simd_type_t*)&app[long_cb - nof_blocks]; + parityPtr = (simd_type_t*)&parity[long_cb - nof_blocks]; for (int i = 0; i < 8; i++) { - simd_store(&betaPtr[8*long_sb + i], old[i]); + simd_store(&betaPtr[8 * long_sb + i], old[i]); } } else { @@ -471,9 +628,9 @@ static void MAKE_FUNC(beta)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *pari for (int i = 0; i < 8; i++) { old[i] = simd_set1(-INF); } - inputPtr = (simd_type_t*) &input[nof_blocks*(loop_len-1)]; - appPtr = (simd_type_t*) &app[nof_blocks*(loop_len-1)]; - parityPtr = (simd_type_t*) &parity[nof_blocks*(loop_len-1)]; + inputPtr = (simd_type_t*)&input[nof_blocks * (loop_len - 1)]; + appPtr = (simd_type_t*)&app[nof_blocks * (loop_len - 1)]; + parityPtr = (simd_type_t*)&parity[nof_blocks * (loop_len - 1)]; } for (int k = loop_len - 1; k >= 0; k--) { @@ -482,7 +639,7 @@ static void MAKE_FUNC(beta)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *pari if (app) { ap = simd_load(appPtr--); - x = simd_add(ap, x); + x = simd_add(ap, x); } xy = simd_add(x, y); @@ -512,10 +669,10 @@ static void MAKE_FUNC(beta)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *pari // Store metric only when doing the final pass if (loop_len == long_sb) { for (int i = 0; i < 8; i++) { - simd_store(&betaPtr[8*k + i], old[i]); + simd_store(&betaPtr[8 * k + i], old[i]); } } - if (loop_len!=long_sb) { + if (loop_len != long_sb) { debug_state_beta(0); } else { debug_state_beta(0); @@ -528,31 +685,31 @@ static void MAKE_FUNC(beta)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *pari } /* Computes alpha metrics */ -static void MAKE_FUNC(alpha)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *parity, llr_t * output, uint32_t long_cb) +static void MAKE_FUNC(alpha)(MAKE_TYPE* s, llr_t* input, llr_t* app, llr_t* parity, llr_t* output, uint32_t long_cb) { simd_type_t m_b[8], new[8], old[8], max1[8], max0[8]; simd_type_t x, y, xy, ap; simd_type_t m1, m0; - simd_type_t *inputPtr; - simd_type_t *appPtr; - simd_type_t *parityPtr; - simd_type_t *betaPtr = (simd_type_t*) s->beta; - simd_type_t *outputPtr = (simd_type_t*) output; + simd_type_t* inputPtr; + simd_type_t* appPtr; + simd_type_t* parityPtr; + simd_type_t* betaPtr = (simd_type_t*)s->beta; + simd_type_t* outputPtr = (simd_type_t*)output; #if debug_enabled_win simd_type_t beta_save[8]; #endif // Skip state 0 - betaPtr+=8; + betaPtr += 8; uint32_t loop_len; - for (int j=0;j<2;j++) { + for (int j = 0; j < 2; j++) { // First run L states to find initial state for all sub-blocks after first - if (j==0) { + if (j == 0) { loop_len = win_overlap_len; } else { loop_len = long_sb; @@ -563,13 +720,13 @@ static void MAKE_FUNC(alpha)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *par #ifdef WINIMP_IS_AVX16 llr_t tmp[8]; - for (int i=0;i<8;i++) { + for (int i = 0; i < 8; i++) { tmp[i] = _mm256_extract_epi16(old[i], 7); } #endif #ifdef WINIMP_IS_AVX8 llr_t tmp[8]; - for (int i=0;i<8;i++) { + for (int i = 0; i < 8; i++) { tmp[i] = _mm256_extract_epi8(old[i], 15); } #endif @@ -577,12 +734,12 @@ static void MAKE_FUNC(alpha)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *par old[i] = simd_shuffle(old[i], move_left); } #ifdef WINIMP_IS_AVX16 - for (int i=0;i<8;i++) { + for (int i = 0; i < 8; i++) { old[i] = _mm256_insert_epi16(old[i], tmp[i], 8); } #endif #ifdef WINIMP_IS_AVX8 - for (int i=0;i<8;i++) { + for (int i = 0; i < 8; i++) { old[i] = _mm256_insert_epi8(old[i], tmp[i], 16); } #endif @@ -598,9 +755,9 @@ static void MAKE_FUNC(alpha)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *par } } - inputPtr = (simd_type_t*) &input[nof_blocks*(long_sb-loop_len)]; - appPtr = (simd_type_t*) &app[nof_blocks*(long_sb-loop_len)]; - parityPtr = (simd_type_t*) &parity[nof_blocks*(long_sb-loop_len)]; + inputPtr = (simd_type_t*)&input[nof_blocks * (long_sb - loop_len)]; + appPtr = (simd_type_t*)&app[nof_blocks * (long_sb - loop_len)]; + parityPtr = (simd_type_t*)&parity[nof_blocks * (long_sb - loop_len)]; for (int k = 0; k < loop_len; k++) { x = simd_load(inputPtr++); @@ -608,10 +765,10 @@ static void MAKE_FUNC(alpha)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *par if (app) { ap = simd_load(appPtr++); - x = simd_add(ap, x); + x = simd_add(ap, x); } - xy = simd_add(x,y); + xy = simd_add(x, y); m_b[0] = old[0]; m_b[1] = simd_add(old[3], y); @@ -635,7 +792,7 @@ static void MAKE_FUNC(alpha)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *par if (loop_len == long_sb) { simd_type_t beta; for (int i = 0; i < 8; i++) { - beta = simd_load(betaPtr++); + beta = simd_load(betaPtr++); max0[i] = simd_add(beta, m_b[i]); max1[i] = simd_add(beta, new[i]); @@ -678,11 +835,11 @@ static void MAKE_FUNC(alpha)(MAKE_TYPE * s, llr_t *input, llr_t *app, llr_t *par } } -int MAKE_FUNC(init)(void **hh, uint32_t max_long_cb) +int MAKE_FUNC(init)(void** hh, uint32_t max_long_cb) { *hh = calloc(1, sizeof(MAKE_TYPE)); - MAKE_TYPE *h = (MAKE_TYPE*) *hh; + MAKE_TYPE* h = (MAKE_TYPE*)*hh; h->beta = srslte_vec_malloc(sizeof(llr_t) * 8 * max_long_cb * nof_blocks); if (!h->beta) { @@ -693,9 +850,9 @@ int MAKE_FUNC(init)(void **hh, uint32_t max_long_cb) return nof_blocks; } -void MAKE_FUNC(free)(void *hh) +void MAKE_FUNC(free)(void* hh) { - MAKE_TYPE *h = (MAKE_TYPE*) hh; + MAKE_TYPE* h = (MAKE_TYPE*)hh; if (h) { if (h->beta) { free(h->beta); @@ -704,9 +861,9 @@ void MAKE_FUNC(free)(void *hh) } } -void MAKE_FUNC(dec)(void *hh, llr_t *input, llr_t *app, llr_t *parity, llr_t *output, uint32_t long_cb) +void MAKE_FUNC(dec)(void* hh, llr_t* input, llr_t* app, llr_t* parity, llr_t* output, uint32_t long_cb) { - MAKE_TYPE *h = (MAKE_TYPE*) hh; + MAKE_TYPE* h = (MAKE_TYPE*)hh; MAKE_FUNC(beta)(h, input, app, parity, long_cb); MAKE_FUNC(alpha)(h, input, app, parity, output, long_cb); #if debug_enabled_win @@ -714,130 +871,131 @@ void MAKE_FUNC(dec)(void *hh, llr_t *input, llr_t *app, llr_t *parity, llr_t *ou #endif } -#define INSERT8_INPUT(reg, st, off) reg = simd_insert(reg, input[3*(i+(st+0)*long_sb)+off], st+0);\ - reg = simd_insert(reg, input[3*(i+(st+1)*long_sb)+off], st+1);\ - reg = simd_insert(reg, input[3*(i+(st+2)*long_sb)+off], st+2);\ - reg = simd_insert(reg, input[3*(i+(st+3)*long_sb)+off], st+3);\ - reg = simd_insert(reg, input[3*(i+(st+4)*long_sb)+off], st+4);\ - reg = simd_insert(reg, input[3*(i+(st+5)*long_sb)+off], st+5);\ - reg = simd_insert(reg, input[3*(i+(st+6)*long_sb)+off], st+6);\ - reg = simd_insert(reg, input[3*(i+(st+7)*long_sb)+off], st+7); - - -void MAKE_FUNC(extract_input)(llr_t *input, llr_t *systematic, llr_t *app2, llr_t *parity_0, llr_t *parity_1, uint32_t long_cb) +#define INSERT8_INPUT(reg, st, off) \ + reg = simd_insert(reg, input[3 * (i + (st + 0) * long_sb) + off], st + 0); \ + reg = simd_insert(reg, input[3 * (i + (st + 1) * long_sb) + off], st + 1); \ + reg = simd_insert(reg, input[3 * (i + (st + 2) * long_sb) + off], st + 2); \ + reg = simd_insert(reg, input[3 * (i + (st + 3) * long_sb) + off], st + 3); \ + reg = simd_insert(reg, input[3 * (i + (st + 4) * long_sb) + off], st + 4); \ + reg = simd_insert(reg, input[3 * (i + (st + 5) * long_sb) + off], st + 5); \ + reg = simd_insert(reg, input[3 * (i + (st + 6) * long_sb) + off], st + 6); \ + reg = simd_insert(reg, input[3 * (i + (st + 7) * long_sb) + off], st + 7); + +void MAKE_FUNC( + extract_input)(llr_t* input, llr_t* systematic, llr_t* app2, llr_t* parity_0, llr_t* parity_1, uint32_t long_cb) { - simd_type_t *systPtr = (simd_type_t*) systematic; - simd_type_t *parity0Ptr = (simd_type_t*) parity_0; - simd_type_t *parity1Ptr = (simd_type_t*) parity_1; + simd_type_t* systPtr = (simd_type_t*)systematic; + simd_type_t* parity0Ptr = (simd_type_t*)parity_0; + simd_type_t* parity1Ptr = (simd_type_t*)parity_1; simd_type_t syst = simd_set1(0); simd_type_t parity0 = simd_set1(0); simd_type_t parity1 = simd_set1(0); - for (int i=0;i= 16 - INSERT8_INPUT(syst, 8, 0); + INSERT8_INPUT(syst, 8, 0); INSERT8_INPUT(parity0, 8, 1); INSERT8_INPUT(parity1, 8, 2); #endif #if nof_blocks >= 32 - INSERT8_INPUT(syst, 16, 0); + INSERT8_INPUT(syst, 16, 0); INSERT8_INPUT(parity0, 16, 1); INSERT8_INPUT(parity1, 16, 2); - INSERT8_INPUT(syst, 24, 0); + INSERT8_INPUT(syst, 24, 0); INSERT8_INPUT(parity0, 24, 1); INSERT8_INPUT(parity1, 24, 2); #endif - simd_store(systPtr++, syst); + simd_store(systPtr++, syst); simd_store(parity0Ptr++, parity0); simd_store(parity1Ptr++, parity1); } for (int i = long_cb; i < long_cb + 3; i++) { - systematic[i] = input[3*long_cb + 2*(i - long_cb)]; - parity_0[i] = input[3*long_cb + 2*(i - long_cb) + 1]; + systematic[i] = input[3 * long_cb + 2 * (i - long_cb)]; + parity_0[i] = input[3 * long_cb + 2 * (i - long_cb) + 1]; - app2[i] = input[3*long_cb + 6 + 2*(i - long_cb)]; - parity_1[i] = input[3*long_cb + 6 + 2*(i - long_cb) + 1]; + app2[i] = input[3 * long_cb + 6 + 2 * (i - long_cb)]; + parity_1[i] = input[3 * long_cb + 6 + 2 * (i - long_cb) + 1]; } } -#define deinter(x,win) ((x%(long_cb/win))*(win)+x/(long_cb/win)) - -#define reset_cnt(a,b) if(!((a+1)%b)) { \ - k+=b*nof_blocks; \ - if (k >= long_cb) { \ - k -= (long_cb-1);\ - }\ - } - +#define deinter(x, win) ((x % (long_cb / win)) * (win) + x / (long_cb / win)) +#define reset_cnt(a, b) \ + if (!((a + 1) % b)) { \ + k += b * nof_blocks; \ + if (k >= long_cb) { \ + k -= (long_cb - 1); \ + } \ + } #ifdef WINIMP_IS_NEON16 -#define insert_bit(a,b) ap = v_insert_s16(ap, app1[k+(a%b)*nof_blocks], 7-a); \ - reset_cnt(a,b); +#define insert_bit(a, b) \ + ap = v_insert_s16(ap, app1[k + (a % b) * nof_blocks], 7 - a); \ + reset_cnt(a, b); #else -#define insert_bit(a,b) ap = _mm_insert_epi16(ap, app1[k+(a%b)*nof_blocks], 7-a); \ - reset_cnt(a,b); +#define insert_bit(a, b) \ + ap = _mm_insert_epi16(ap, app1[k + (a % b) * nof_blocks], 7 - a); \ + reset_cnt(a, b); #endif - - #ifndef WINIMP_IS_NEON16 -#define decide_for(b) for (uint32_t i = 0; i < long_cb/8; i++) { \ - insert_bit(0,b);\ - insert_bit(1,b);\ - insert_bit(2,b);\ - insert_bit(3,b);\ - insert_bit(4,b);\ - insert_bit(5,b);\ - insert_bit(6,b);\ - insert_bit(7,b);\ - output[i] = (uint8_t) _mm_movemask_epi8(_mm_cmpgt_epi8(_mm_packs_epi16(ap,zeros),zeros));\ - } +#define decide_for(b) \ + for (uint32_t i = 0; i < long_cb / 8; i++) { \ + insert_bit(0, b); \ + insert_bit(1, b); \ + insert_bit(2, b); \ + insert_bit(3, b); \ + insert_bit(4, b); \ + insert_bit(5, b); \ + insert_bit(6, b); \ + insert_bit(7, b); \ + output[i] = (uint8_t)_mm_movemask_epi8(_mm_cmpgt_epi8(_mm_packs_epi16(ap, zeros), zeros)); \ + } #else -#define decide_for(b) for (uint32_t i = 0; i < long_cb/8; i++) { \ - insert_bit(0,b);\ - insert_bit(1,b);\ - insert_bit(2,b);\ - insert_bit(3,b);\ - insert_bit(4,b);\ - insert_bit(5,b);\ - insert_bit(6,b);\ - insert_bit(7,b);\ - output[i] = (uint8_t) movemask_neon((uint8x16_t)vcgtq_s8((int8x16_t)v_packs_s16(ap,(int16x8_t)zeros),zeros));\ - } +#define decide_for(b) \ + for (uint32_t i = 0; i < long_cb / 8; i++) { \ + insert_bit(0, b); \ + insert_bit(1, b); \ + insert_bit(2, b); \ + insert_bit(3, b); \ + insert_bit(4, b); \ + insert_bit(5, b); \ + insert_bit(6, b); \ + insert_bit(7, b); \ + output[i] = (uint8_t)movemask_neon((uint8x16_t)vcgtq_s8((int8x16_t)v_packs_s16(ap, (int16x8_t)zeros), zeros)); \ + } #endif /* No improvement to use AVX here */ -void MAKE_FUNC(decision_byte)(llr_t *app1, uint8_t *output, uint32_t long_cb) +void MAKE_FUNC(decision_byte)(llr_t* app1, uint8_t* output, uint32_t long_cb) { - uint32_t k=0; + uint32_t k = 0; #ifdef WINIMP_IS_NEON16 - int8_t z = 0; - int8x16_t zeros = vld1q_dup_s8(&z); + int8_t z = 0; + int8x16_t zeros = vld1q_dup_s8(&z); int16x8_t ap; #else __m128i zeros = _mm_setzero_si128(); __m128i ap; #endif - if ((long_cb%(nof_blocks*8)) == 0) { + if ((long_cb % (nof_blocks * 8)) == 0) { decide_for(8); - } else if ((long_cb%(nof_blocks*4)) == 0) { + } else if ((long_cb % (nof_blocks * 4)) == 0) { decide_for(4); - } else if ((long_cb%(nof_blocks*2)) == 0) { + } else if ((long_cb % (nof_blocks * 2)) == 0) { decide_for(2); } else { decide_for(1); } } - #undef WINIMP #undef nof_blocks #undef llr_t diff --git a/lib/include/srslte/phy/fec/viterbi.h b/lib/include/srslte/phy/fec/viterbi.h index 7528e3269..11861e2e6 100644 --- a/lib/include/srslte/phy/fec/viterbi.h +++ b/lib/include/srslte/phy/fec/viterbi.h @@ -31,87 +31,65 @@ #ifndef SRSLTE_VITERBI_H #define SRSLTE_VITERBI_H -#include #include "srslte/config.h" +#include +typedef enum { SRSLTE_VITERBI_27 = 0, SRSLTE_VITERBI_29, SRSLTE_VITERBI_37, SRSLTE_VITERBI_39 } srslte_viterbi_type_t; - -typedef enum { - SRSLTE_VITERBI_27 = 0, - SRSLTE_VITERBI_29, - SRSLTE_VITERBI_37, - SRSLTE_VITERBI_39 -}srslte_viterbi_type_t; - -typedef struct SRSLTE_API{ - void *ptr; +typedef struct SRSLTE_API { + void* ptr; uint32_t R; uint32_t K; uint32_t framebits; - bool tail_biting; - float gain_quant; - int16_t gain_quant_s; - int (*decode) (void*, uint8_t*, uint8_t*, uint32_t); - int (*decode_s) (void*, uint16_t*, uint8_t*, uint32_t); - int (*decode_f) (void*, float*, uint8_t*, uint32_t); - void (*free) (void*); - uint8_t *tmp; - uint16_t *tmp_s; - uint8_t *symbols_uc; - uint16_t *symbols_us; -}srslte_viterbi_t; - -SRSLTE_API int srslte_viterbi_init(srslte_viterbi_t *q, - srslte_viterbi_type_t type, - int poly[3], - uint32_t max_frame_length, - bool tail_bitting); - -SRSLTE_API void srslte_viterbi_set_gain_quant(srslte_viterbi_t *q, - float gain_quant); - -SRSLTE_API void srslte_viterbi_set_gain_quant_s(srslte_viterbi_t *q, - int16_t gain_quant); - -SRSLTE_API void srslte_viterbi_free(srslte_viterbi_t *q); - -SRSLTE_API int srslte_viterbi_decode_f(srslte_viterbi_t *q, - float *symbols, - uint8_t *data, - uint32_t frame_length); - -SRSLTE_API int srslte_viterbi_decode_s(srslte_viterbi_t *q, - int16_t *symbols, - uint8_t *data, - uint32_t frame_length); - -SRSLTE_API int srslte_viterbi_decode_us(srslte_viterbi_t *q, uint16_t *symbols, uint8_t *data, uint32_t frame_length); - -SRSLTE_API int srslte_viterbi_decode_uc(srslte_viterbi_t *q, - uint8_t *symbols, - uint8_t *data, - uint32_t frame_length); - - - -SRSLTE_API int srslte_viterbi_init_sse(srslte_viterbi_t *q, - srslte_viterbi_type_t type, - int poly[3], - uint32_t max_frame_length, - bool tail_bitting); - -SRSLTE_API int srslte_viterbi_init_neon(srslte_viterbi_t *q, - srslte_viterbi_type_t type, - int poly[3], - uint32_t max_frame_length, - bool tail_bitting); - -SRSLTE_API int srslte_viterbi_init_avx2(srslte_viterbi_t *q, - srslte_viterbi_type_t type, - int poly[3], - uint32_t max_frame_length, - bool tail_bitting); - - + bool tail_biting; + float gain_quant; + int16_t gain_quant_s; + int (*decode)(void*, uint8_t*, uint8_t*, uint32_t); + int (*decode_s)(void*, uint16_t*, uint8_t*, uint32_t); + int (*decode_f)(void*, float*, uint8_t*, uint32_t); + void (*free)(void*); + uint8_t* tmp; + uint16_t* tmp_s; + uint8_t* symbols_uc; + uint16_t* symbols_us; +} srslte_viterbi_t; + +SRSLTE_API int srslte_viterbi_init(srslte_viterbi_t* q, + srslte_viterbi_type_t type, + int poly[3], + uint32_t max_frame_length, + bool tail_bitting); + +SRSLTE_API void srslte_viterbi_set_gain_quant(srslte_viterbi_t* q, float gain_quant); + +SRSLTE_API void srslte_viterbi_set_gain_quant_s(srslte_viterbi_t* q, int16_t gain_quant); + +SRSLTE_API void srslte_viterbi_free(srslte_viterbi_t* q); + +SRSLTE_API int srslte_viterbi_decode_f(srslte_viterbi_t* q, float* symbols, uint8_t* data, uint32_t frame_length); + +SRSLTE_API int srslte_viterbi_decode_s(srslte_viterbi_t* q, int16_t* symbols, uint8_t* data, uint32_t frame_length); + +SRSLTE_API int srslte_viterbi_decode_us(srslte_viterbi_t* q, uint16_t* symbols, uint8_t* data, uint32_t frame_length); + +SRSLTE_API int srslte_viterbi_decode_uc(srslte_viterbi_t* q, uint8_t* symbols, uint8_t* data, uint32_t frame_length); + +SRSLTE_API int srslte_viterbi_init_sse(srslte_viterbi_t* q, + srslte_viterbi_type_t type, + int poly[3], + uint32_t max_frame_length, + bool tail_bitting); + +SRSLTE_API int srslte_viterbi_init_neon(srslte_viterbi_t* q, + srslte_viterbi_type_t type, + int poly[3], + uint32_t max_frame_length, + bool tail_bitting); + +SRSLTE_API int srslte_viterbi_init_avx2(srslte_viterbi_t* q, + srslte_viterbi_type_t type, + int poly[3], + uint32_t max_frame_length, + bool tail_bitting); #endif // SRSLTE_VITERBI_H diff --git a/lib/include/srslte/phy/io/binsource.h b/lib/include/srslte/phy/io/binsource.h index d03915061..57d4e97e8 100644 --- a/lib/include/srslte/phy/io/binsource.h +++ b/lib/include/srslte/phy/io/binsource.h @@ -30,37 +30,30 @@ #ifndef SRSLTE_BINSOURCE_H #define SRSLTE_BINSOURCE_H - -#include #include "srslte/config.h" +#include /* Low-level API */ -typedef struct SRSLTE_API{ - uint32_t seed; - uint32_t *seq_buff; - int seq_buff_nwords; - int seq_cache_nbits; - int seq_cache_rp; -}srslte_binsource_t; +typedef struct SRSLTE_API { + uint32_t seed; + uint32_t* seq_buff; + int seq_buff_nwords; + int seq_cache_nbits; + int seq_cache_rp; +} srslte_binsource_t; SRSLTE_API void srslte_binsource_init(srslte_binsource_t* q); SRSLTE_API void srslte_binsource_free(srslte_binsource_t* q); -SRSLTE_API void srslte_binsource_seed_set(srslte_binsource_t* q, - uint32_t seed); +SRSLTE_API void srslte_binsource_seed_set(srslte_binsource_t* q, uint32_t seed); -SRSLTE_API void srslte_binsource_seed_time(srslte_binsource_t *q); +SRSLTE_API void srslte_binsource_seed_time(srslte_binsource_t* q); -SRSLTE_API int srslte_binsource_cache_gen(srslte_binsource_t* q, - int nbits); +SRSLTE_API int srslte_binsource_cache_gen(srslte_binsource_t* q, int nbits); -SRSLTE_API void srslte_binsource_cache_cpy(srslte_binsource_t* q, - uint8_t *bits, - int nbits); +SRSLTE_API void srslte_binsource_cache_cpy(srslte_binsource_t* q, uint8_t* bits, int nbits); -SRSLTE_API int srslte_binsource_generate(srslte_binsource_t* q, - uint8_t *bits, - int nbits); +SRSLTE_API int srslte_binsource_generate(srslte_binsource_t* q, uint8_t* bits, int nbits); #endif // SRSLTE_BINSOURCE_H diff --git a/lib/include/srslte/phy/io/filesink.h b/lib/include/srslte/phy/io/filesink.h index b18ba967b..7c35a82fe 100644 --- a/lib/include/srslte/phy/io/filesink.h +++ b/lib/include/srslte/phy/io/filesink.h @@ -41,23 +41,16 @@ /* Low-level API */ typedef struct SRSLTE_API { - FILE *f; + FILE* f; srslte_datatype_t type; } srslte_filesink_t; -SRSLTE_API int srslte_filesink_init(srslte_filesink_t *q, - char *filename, - srslte_datatype_t type); +SRSLTE_API int srslte_filesink_init(srslte_filesink_t* q, char* filename, srslte_datatype_t type); -SRSLTE_API void srslte_filesink_free(srslte_filesink_t *q); +SRSLTE_API void srslte_filesink_free(srslte_filesink_t* q); -SRSLTE_API int srslte_filesink_write(srslte_filesink_t *q, - void *buffer, - int nsamples); +SRSLTE_API int srslte_filesink_write(srslte_filesink_t* q, void* buffer, int nsamples); -SRSLTE_API int srslte_filesink_write_multi(srslte_filesink_t *q, - void **buffer, - int nsamples, - int nchannels); +SRSLTE_API int srslte_filesink_write_multi(srslte_filesink_t* q, void** buffer, int nsamples, int nchannels); #endif // SRSLTE_FILESINK_H diff --git a/lib/include/srslte/phy/io/filesource.h b/lib/include/srslte/phy/io/filesource.h index cd5618589..2e8e91ed3 100644 --- a/lib/include/srslte/phy/io/filesource.h +++ b/lib/include/srslte/phy/io/filesource.h @@ -40,26 +40,18 @@ /* Low-level API */ typedef struct SRSLTE_API { - FILE *f; + FILE* f; srslte_datatype_t type; } srslte_filesource_t; -SRSLTE_API int srslte_filesource_init(srslte_filesource_t *q, - char *filename, - srslte_datatype_t type); +SRSLTE_API int srslte_filesource_init(srslte_filesource_t* q, char* filename, srslte_datatype_t type); -SRSLTE_API void srslte_filesource_free(srslte_filesource_t *q); +SRSLTE_API void srslte_filesource_free(srslte_filesource_t* q); -SRSLTE_API void srslte_filesource_seek(srslte_filesource_t *q, - int pos); +SRSLTE_API void srslte_filesource_seek(srslte_filesource_t* q, int pos); -SRSLTE_API int srslte_filesource_read(srslte_filesource_t *q, - void *buffer, - int nsamples); +SRSLTE_API int srslte_filesource_read(srslte_filesource_t* q, void* buffer, int nsamples); -SRSLTE_API int srslte_filesource_read_multi(srslte_filesource_t *q, - void **buffer, - int nsamples, - int nof_channels); +SRSLTE_API int srslte_filesource_read_multi(srslte_filesource_t* q, void** buffer, int nsamples, int nof_channels); #endif // SRSLTE_FILESOURCE_H diff --git a/lib/include/srslte/phy/io/format.h b/lib/include/srslte/phy/io/format.h index e273e31e7..72a6be946 100644 --- a/lib/include/srslte/phy/io/format.h +++ b/lib/include/srslte/phy/io/format.h @@ -24,12 +24,12 @@ typedef enum { SRSLTE_TEXT, - SRSLTE_FLOAT, - SRSLTE_COMPLEX_FLOAT, - SRSLTE_COMPLEX_SHORT, - SRSLTE_FLOAT_BIN, - SRSLTE_COMPLEX_FLOAT_BIN, - SRSLTE_COMPLEX_SHORT_BIN + SRSLTE_FLOAT, + SRSLTE_COMPLEX_FLOAT, + SRSLTE_COMPLEX_SHORT, + SRSLTE_FLOAT_BIN, + SRSLTE_COMPLEX_FLOAT_BIN, + SRSLTE_COMPLEX_SHORT_BIN } srslte_datatype_t; #endif // SRSLTE_FORMAT_H diff --git a/lib/include/srslte/phy/io/netsink.h b/lib/include/srslte/phy/io/netsink.h index 52c88bbac..c628dbadf 100644 --- a/lib/include/srslte/phy/io/netsink.h +++ b/lib/include/srslte/phy/io/netsink.h @@ -31,39 +31,31 @@ #ifndef SRSLTE_NETSINK_H #define SRSLTE_NETSINK_H -#include -#include #include +#include +#include #include #include -#include +#include #include "srslte/config.h" -typedef enum { - SRSLTE_NETSINK_UDP, - SRSLTE_NETSINK_TCP -} srslte_netsink_type_t; +typedef enum { SRSLTE_NETSINK_UDP, SRSLTE_NETSINK_TCP } srslte_netsink_type_t; /* Low-level API */ typedef struct SRSLTE_API { - int sockfd; - bool connected; - srslte_netsink_type_t type; - struct sockaddr_in servaddr; -}srslte_netsink_t; + int sockfd; + bool connected; + srslte_netsink_type_t type; + struct sockaddr_in servaddr; +} srslte_netsink_t; -SRSLTE_API int srslte_netsink_init(srslte_netsink_t *q, - const char *address, - uint16_t port, - srslte_netsink_type_t type); +SRSLTE_API int srslte_netsink_init(srslte_netsink_t* q, const char* address, uint16_t port, srslte_netsink_type_t type); -SRSLTE_API void srslte_netsink_free(srslte_netsink_t *q); +SRSLTE_API void srslte_netsink_free(srslte_netsink_t* q); -SRSLTE_API int srslte_netsink_write(srslte_netsink_t *q, - void *buffer, - int nof_bytes); +SRSLTE_API int srslte_netsink_write(srslte_netsink_t* q, void* buffer, int nof_bytes); -SRSLTE_API int srslte_netsink_set_nonblocking(srslte_netsink_t *q); +SRSLTE_API int srslte_netsink_set_nonblocking(srslte_netsink_t* q); #endif // SRSLTE_NETSINK_H diff --git a/lib/include/srslte/phy/io/netsource.h b/lib/include/srslte/phy/io/netsource.h index 5ce3d29e5..a56a6056c 100644 --- a/lib/include/srslte/phy/io/netsource.h +++ b/lib/include/srslte/phy/io/netsource.h @@ -31,45 +31,37 @@ #ifndef SRSLTE_NETSOURCE_H #define SRSLTE_NETSOURCE_H -#include -#include #include -#include +#include #include +#include #include +#include #include "srslte/config.h" -typedef enum { - SRSLTE_NETSOURCE_UDP, - SRSLTE_NETSOURCE_TCP -} srslte_netsource_type_t; +typedef enum { SRSLTE_NETSOURCE_UDP, SRSLTE_NETSOURCE_TCP } srslte_netsource_type_t; /* Low-level API */ typedef struct SRSLTE_API { - int sockfd; - int connfd; - struct sockaddr_in servaddr; - srslte_netsource_type_t type; - struct sockaddr_in cliaddr; -}srslte_netsource_t; + int sockfd; + int connfd; + struct sockaddr_in servaddr; + srslte_netsource_type_t type; + struct sockaddr_in cliaddr; +} srslte_netsource_t; -SRSLTE_API int srslte_netsource_init(srslte_netsource_t *q, - const char *address, - uint16_t port, - srslte_netsource_type_t type); +SRSLTE_API int +srslte_netsource_init(srslte_netsource_t* q, const char* address, uint16_t port, srslte_netsource_type_t type); -SRSLTE_API void srslte_netsource_free(srslte_netsource_t *q); +SRSLTE_API void srslte_netsource_free(srslte_netsource_t* q); -SRSLTE_API int srslte_netsource_set_nonblocking(srslte_netsource_t *q); +SRSLTE_API int srslte_netsource_set_nonblocking(srslte_netsource_t* q); -SRSLTE_API int srslte_netsource_read(srslte_netsource_t *q, - void *buffer, - int nof_bytes); +SRSLTE_API int srslte_netsource_read(srslte_netsource_t* q, void* buffer, int nof_bytes); SRSLTE_API int srslte_netsource_write(srslte_netsource_t* q, void* buffer, int nbytes); -SRSLTE_API int srslte_netsource_set_timeout(srslte_netsource_t *q, - uint32_t microseconds); +SRSLTE_API int srslte_netsource_set_timeout(srslte_netsource_t* q, uint32_t microseconds); #endif // SRSLTE_NETSOURCE_H diff --git a/lib/include/srslte/phy/mimo/layermap.h b/lib/include/srslte/phy/mimo/layermap.h index 26c61b4de..9d9f11d74 100644 --- a/lib/include/srslte/phy/mimo/layermap.h +++ b/lib/include/srslte/phy/mimo/layermap.h @@ -37,20 +37,15 @@ /* Generates the vector of layer-mapped symbols "x" based on the vector of data symbols "d" */ -SRSLTE_API int srslte_layermap_single(cf_t *d, - cf_t *x, - int nof_symbols); +SRSLTE_API int srslte_layermap_single(cf_t* d, cf_t* x, int nof_symbols); -SRSLTE_API int srslte_layermap_diversity(cf_t *d, - cf_t *x[SRSLTE_MAX_LAYERS], - int nof_layers, - int nof_symbols); +SRSLTE_API int srslte_layermap_diversity(cf_t* d, cf_t* x[SRSLTE_MAX_LAYERS], int nof_layers, int nof_symbols); -SRSLTE_API int srslte_layermap_multiplex(cf_t *d[SRSLTE_MAX_CODEWORDS], - cf_t *x[SRSLTE_MAX_LAYERS], - int nof_cw, - int nof_layers, - int nof_symbols[SRSLTE_MAX_CODEWORDS]); +SRSLTE_API int srslte_layermap_multiplex(cf_t* d[SRSLTE_MAX_CODEWORDS], + cf_t* x[SRSLTE_MAX_LAYERS], + int nof_cw, + int nof_layers, + int nof_symbols[SRSLTE_MAX_CODEWORDS]); SRSLTE_API int srslte_layermap_type(cf_t* d[SRSLTE_MAX_CODEWORDS], cf_t* x[SRSLTE_MAX_LAYERS], @@ -61,21 +56,16 @@ SRSLTE_API int srslte_layermap_type(cf_t* d[SRSLTE_MAX_CODEWORDS], /* Generates the vector of data symbols "d" based on the vector of layer-mapped symbols "x" */ -SRSLTE_API int srslte_layerdemap_single(cf_t *x, - cf_t *d, - int nof_symbols); +SRSLTE_API int srslte_layerdemap_single(cf_t* x, cf_t* d, int nof_symbols); -SRSLTE_API int srslte_layerdemap_diversity(cf_t *x[SRSLTE_MAX_LAYERS], - cf_t *d, - int nof_layers, - int nof_layer_symbols); +SRSLTE_API int srslte_layerdemap_diversity(cf_t* x[SRSLTE_MAX_LAYERS], cf_t* d, int nof_layers, int nof_layer_symbols); -SRSLTE_API int srslte_layerdemap_multiplex(cf_t *x[SRSLTE_MAX_LAYERS], - cf_t *d[SRSLTE_MAX_CODEWORDS], - int nof_layers, - int nof_cw, - int nof_layer_symbols, - int nof_symbols[SRSLTE_MAX_CODEWORDS]); +SRSLTE_API int srslte_layerdemap_multiplex(cf_t* x[SRSLTE_MAX_LAYERS], + cf_t* d[SRSLTE_MAX_CODEWORDS], + int nof_layers, + int nof_cw, + int nof_layer_symbols, + int nof_symbols[SRSLTE_MAX_CODEWORDS]); SRSLTE_API int srslte_layerdemap_type(cf_t* x[SRSLTE_MAX_LAYERS], cf_t* d[SRSLTE_MAX_CODEWORDS], diff --git a/lib/include/srslte/phy/mimo/precoding.h b/lib/include/srslte/phy/mimo/precoding.h index 903ea369b..de1f1e8ab 100644 --- a/lib/include/srslte/phy/mimo/precoding.h +++ b/lib/include/srslte/phy/mimo/precoding.h @@ -39,25 +39,21 @@ * resources on each of the antenna ports. */ - /* Generates the vector "y" from the input vector "x" */ -SRSLTE_API int srslte_precoding_single(cf_t *x, - cf_t *y, - int nof_symbols, - float scaling); - -SRSLTE_API int srslte_precoding_diversity(cf_t *x[SRSLTE_MAX_LAYERS], - cf_t *y[SRSLTE_MAX_PORTS], - int nof_ports, - int nof_symbols, +SRSLTE_API int srslte_precoding_single(cf_t* x, cf_t* y, int nof_symbols, float scaling); + +SRSLTE_API int srslte_precoding_diversity(cf_t* x[SRSLTE_MAX_LAYERS], + cf_t* y[SRSLTE_MAX_PORTS], + int nof_ports, + int nof_symbols, float scaling); -SRSLTE_API int srslte_precoding_cdd(cf_t *x[SRSLTE_MAX_LAYERS], - cf_t *y[SRSLTE_MAX_PORTS], - int nof_layers, - int nof_ports, - int nof_symbols, +SRSLTE_API int srslte_precoding_cdd(cf_t* x[SRSLTE_MAX_LAYERS], + cf_t* y[SRSLTE_MAX_PORTS], + int nof_layers, + int nof_ports, + int nof_symbols, float scaling); SRSLTE_API int srslte_precoding_type(cf_t* x[SRSLTE_MAX_LAYERS], @@ -71,40 +67,35 @@ SRSLTE_API int srslte_precoding_type(cf_t* x[SRSLTE_MAX_LAYERS], /* Estimates the vector "x" based on the received signal "y" and the channel estimates "h" */ -SRSLTE_API int srslte_predecoding_single(cf_t *y, - cf_t *h, - cf_t *x, - float *csi, - int nof_symbols, - float scaling, - float noise_estimate); - -SRSLTE_API int srslte_predecoding_single_multi(cf_t *y[SRSLTE_MAX_PORTS], - cf_t *h[SRSLTE_MAX_PORTS], - cf_t *x, - float *csi[SRSLTE_MAX_CODEWORDS], - int nof_rxant, - int nof_symbols, - float scaling, - float noise_estimate); - -SRSLTE_API int srslte_predecoding_diversity(cf_t *y, - cf_t *h[SRSLTE_MAX_PORTS], - cf_t *x[SRSLTE_MAX_LAYERS], - int nof_ports, - int nof_symbols, +SRSLTE_API int +srslte_predecoding_single(cf_t* y, cf_t* h, cf_t* x, float* csi, int nof_symbols, float scaling, float noise_estimate); + +SRSLTE_API int srslte_predecoding_single_multi(cf_t* y[SRSLTE_MAX_PORTS], + cf_t* h[SRSLTE_MAX_PORTS], + cf_t* x, + float* csi[SRSLTE_MAX_CODEWORDS], + int nof_rxant, + int nof_symbols, + float scaling, + float noise_estimate); + +SRSLTE_API int srslte_predecoding_diversity(cf_t* y, + cf_t* h[SRSLTE_MAX_PORTS], + cf_t* x[SRSLTE_MAX_LAYERS], + int nof_ports, + int nof_symbols, float scaling); -SRSLTE_API int srslte_predecoding_diversity_multi(cf_t *y[SRSLTE_MAX_PORTS], - cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], - cf_t *x[SRSLTE_MAX_LAYERS], - float *csi[SRSLTE_MAX_LAYERS], - int nof_rxant, - int nof_ports, - int nof_symbols, - float scaling); +SRSLTE_API int srslte_predecoding_diversity_multi(cf_t* y[SRSLTE_MAX_PORTS], + cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + cf_t* x[SRSLTE_MAX_LAYERS], + float* csi[SRSLTE_MAX_LAYERS], + int nof_rxant, + int nof_ports, + int nof_symbols, + float scaling); -SRSLTE_API void srslte_predecoding_set_mimo_decoder (srslte_mimo_decoder_t _mimo_decoder); +SRSLTE_API void srslte_predecoding_set_mimo_decoder(srslte_mimo_decoder_t _mimo_decoder); SRSLTE_API int srslte_predecoding_type(cf_t* y[SRSLTE_MAX_PORTS], cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], @@ -119,18 +110,17 @@ SRSLTE_API int srslte_predecoding_type(cf_t* y[SRSLTE_MAX_PORTS], float scaling, float noise_estimate); -SRSLTE_API int srslte_precoding_pmi_select(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], - uint32_t nof_symbols, - float noise_estimate, - int nof_layers, - uint32_t *pmi, - float sinr[SRSLTE_MAX_CODEBOOKS]); +SRSLTE_API int srslte_precoding_pmi_select(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + uint32_t nof_symbols, + float noise_estimate, + int nof_layers, + uint32_t* pmi, + float sinr[SRSLTE_MAX_CODEBOOKS]); -SRSLTE_API int srslte_precoding_cn(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], +SRSLTE_API int srslte_precoding_cn(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t nof_tx_antennas, uint32_t nof_rx_antennas, uint32_t nof_symbols, - float *cn); - + float* cn); #endif // SRSLTE_PRECODING_H diff --git a/lib/include/srslte/phy/modem/demod_hard.h b/lib/include/srslte/phy/modem/demod_hard.h index 2d6f9e4c5..fe601c3d3 100644 --- a/lib/include/srslte/phy/modem/demod_hard.h +++ b/lib/include/srslte/phy/modem/demod_hard.h @@ -33,22 +33,19 @@ #include -#include "srslte/config.h" #include "modem_table.h" +#include "srslte/config.h" + +typedef _Complex float cf_t; typedef struct SRSLTE_API { srslte_mod_t mod; /* In this implementation, mapping table is hard-coded */ -}srslte_demod_hard_t; - +} srslte_demod_hard_t; SRSLTE_API void srslte_demod_hard_init(srslte_demod_hard_t* q); -SRSLTE_API void srslte_demod_hard_table_set(srslte_demod_hard_t* q, - srslte_mod_t mod); +SRSLTE_API void srslte_demod_hard_table_set(srslte_demod_hard_t* q, srslte_mod_t mod); -SRSLTE_API int srslte_demod_hard_demodulate(srslte_demod_hard_t* q, - cf_t* symbols, - uint8_t *bits, - uint32_t nsymbols); +SRSLTE_API int srslte_demod_hard_demodulate(srslte_demod_hard_t* q, cf_t* symbols, uint8_t* bits, uint32_t nsymbols); #endif // SRSLTE_DEMOD_HARD_H diff --git a/lib/include/srslte/phy/modem/demod_soft.h b/lib/include/srslte/phy/modem/demod_soft.h index 9f69fc14b..9c1cfabec 100644 --- a/lib/include/srslte/phy/modem/demod_soft.h +++ b/lib/include/srslte/phy/modem/demod_soft.h @@ -33,23 +33,13 @@ #include -#include "srslte/config.h" #include "modem_table.h" +#include "srslte/config.h" +SRSLTE_API int srslte_demod_soft_demodulate(srslte_mod_t modulation, const cf_t* symbols, float* llr, int nsymbols); -SRSLTE_API int srslte_demod_soft_demodulate(srslte_mod_t modulation, - const cf_t* symbols, - float* llr, - int nsymbols); - -SRSLTE_API int srslte_demod_soft_demodulate_s(srslte_mod_t modulation, - const cf_t* symbols, - short* llr, - int nsymbols); +SRSLTE_API int srslte_demod_soft_demodulate_s(srslte_mod_t modulation, const cf_t* symbols, short* llr, int nsymbols); -SRSLTE_API int srslte_demod_soft_demodulate_b(srslte_mod_t modulation, - const cf_t* symbols, - int8_t* llr, - int nsymbols); +SRSLTE_API int srslte_demod_soft_demodulate_b(srslte_mod_t modulation, const cf_t* symbols, int8_t* llr, int nsymbols); #endif // SRSLTE_DEMOD_SOFT_H diff --git a/lib/include/srslte/phy/modem/mod.h b/lib/include/srslte/phy/modem/mod.h index 288958b56..14f7695e9 100644 --- a/lib/include/srslte/phy/modem/mod.h +++ b/lib/include/srslte/phy/modem/mod.h @@ -33,17 +33,11 @@ #include -#include "srslte/config.h" #include "modem_table.h" +#include "srslte/config.h" -SRSLTE_API int srslte_mod_modulate(srslte_modem_table_t* table, - uint8_t *bits, - cf_t* symbols, - uint32_t nbits); +SRSLTE_API int srslte_mod_modulate(srslte_modem_table_t* table, uint8_t* bits, cf_t* symbols, uint32_t nbits); -SRSLTE_API int srslte_mod_modulate_bytes(srslte_modem_table_t* q, - uint8_t *bits, - cf_t* symbols, - uint32_t nbits); +SRSLTE_API int srslte_mod_modulate_bytes(srslte_modem_table_t* q, uint8_t* bits, cf_t* symbols, uint32_t nbits); #endif // SRSLTE_MOD_H diff --git a/lib/include/srslte/phy/modem/modem_table.h b/lib/include/srslte/phy/modem/modem_table.h index 5b5593513..692ac95a5 100644 --- a/lib/include/srslte/phy/modem/modem_table.h +++ b/lib/include/srslte/phy/modem/modem_table.h @@ -34,8 +34,8 @@ #include #include -#include "srslte/phy/common/phy_common.h" #include "srslte/config.h" +#include "srslte/phy/common/phy_common.h" typedef struct { cf_t symbol[8]; @@ -54,17 +54,16 @@ typedef struct { } qam256_packed_t; typedef struct SRSLTE_API { - cf_t* symbol_table; // bit-to-symbol mapping - uint32_t nsymbols; // number of modulation symbols - uint32_t nbits_x_symbol; // number of bits per symbol - - bool byte_tables_init; - bpsk_packed_t *symbol_table_bpsk; - qpsk_packed_t *symbol_table_qpsk; + cf_t* symbol_table; // bit-to-symbol mapping + uint32_t nsymbols; // number of modulation symbols + uint32_t nbits_x_symbol; // number of bits per symbol + + bool byte_tables_init; + bpsk_packed_t* symbol_table_bpsk; + qpsk_packed_t* symbol_table_qpsk; qam16_packed_t* symbol_table_16qam; qam256_packed_t* symbol_table_256qam; -}srslte_modem_table_t; - +} srslte_modem_table_t; SRSLTE_API void srslte_modem_table_init(srslte_modem_table_t* q); @@ -72,14 +71,10 @@ SRSLTE_API void srslte_modem_table_free(srslte_modem_table_t* q); SRSLTE_API void srslte_modem_table_reset(srslte_modem_table_t* q); -SRSLTE_API int srslte_modem_table_set(srslte_modem_table_t* q, - cf_t* table, - uint32_t nsymbols, - uint32_t nbits_x_symbol); +SRSLTE_API int srslte_modem_table_set(srslte_modem_table_t* q, cf_t* table, uint32_t nsymbols, uint32_t nbits_x_symbol); -SRSLTE_API int srslte_modem_table_lte(srslte_modem_table_t* q, - srslte_mod_t modulation); +SRSLTE_API int srslte_modem_table_lte(srslte_modem_table_t* q, srslte_mod_t modulation); -SRSLTE_API void srslte_modem_table_bytes(srslte_modem_table_t* q); +SRSLTE_API void srslte_modem_table_bytes(srslte_modem_table_t* q); #endif // SRSLTE_MODEM_TABLE_H diff --git a/lib/include/srslte/phy/phch/cqi.h b/lib/include/srslte/phy/phch/cqi.h index 24abb6222..7fbe0eee9 100644 --- a/lib/include/srslte/phy/phch/cqi.h +++ b/lib/include/srslte/phy/phch/cqi.h @@ -56,7 +56,7 @@ typedef struct { bool periodic_configured; bool aperiodic_configured; uint32_t pmi_idx; - uint32_t ri_idx; + uint32_t ri_idx; bool ri_idx_present; bool format_is_subband; uint32_t subband_size; @@ -72,11 +72,11 @@ typedef struct { reports (transmission mode 4, transmission mode 5 and transmission mode 6). */ typedef struct SRSLTE_API { - uint8_t wideband_cqi_cw0; // 4-bit width - uint32_t subband_diff_cqi_cw0; // 2N-bit width - uint8_t wideband_cqi_cw1; // if RI > 1 then 4-bit width otherwise 0-bit width - uint32_t subband_diff_cqi_cw1; // if RI > 1 then 2N-bit width otherwise 0-bit width - uint32_t pmi; // if RI > 1 then 2-bit width otherwise 1-bit width + uint8_t wideband_cqi_cw0; // 4-bit width + uint32_t subband_diff_cqi_cw0; // 2N-bit width + uint8_t wideband_cqi_cw1; // if RI > 1 then 4-bit width otherwise 0-bit width + uint32_t subband_diff_cqi_cw1; // if RI > 1 then 2N-bit width otherwise 0-bit width + uint32_t pmi; // if RI > 1 then 2-bit width otherwise 1-bit width } srslte_cqi_hl_subband_t; /* Table 5.2.2.6.3-1: Fields for channel quality information feedback for UE selected subband CQI @@ -84,14 +84,14 @@ reports (transmission mode 1, transmission mode 2, transmission mode 3, transmission mode 7 and transmission mode 8 configured without PMI/RI reporting). */ typedef struct SRSLTE_API { - uint8_t wideband_cqi; // 4-bit width + uint8_t wideband_cqi; // 4-bit width uint8_t subband_diff_cqi; // 2-bit width uint32_t position_subband; // L-bit width } srslte_cqi_ue_subband_t; /* Table 5.2.3.3.1-1: Fields for channel quality information feedback for wideband CQI reports (transmission mode 1, transmission mode 2, transmission mode 3, transmission mode 7 and -transmission mode 8 configured without PMI/RI reporting). +transmission mode 8 configured without PMI/RI reporting). This is for PUCCH Format 2 reports */ @@ -101,14 +101,14 @@ This is for PUCCH Format 2 reports */ typedef struct SRSLTE_API { - uint8_t wideband_cqi; // 4-bit width - uint8_t spatial_diff_cqi; // If Rank==1 then it is 0-bit width otherwise it is 3-bit width - uint8_t pmi; + uint8_t wideband_cqi; // 4-bit width + uint8_t spatial_diff_cqi; // If Rank==1 then it is 0-bit width otherwise it is 3-bit width + uint8_t pmi; } srslte_cqi_format2_wideband_t; typedef struct SRSLTE_API { - uint8_t subband_cqi; // 4-bit width - uint8_t subband_label; // 1- or 2-bit width + uint8_t subband_cqi; // 4-bit width + uint8_t subband_label; // 1- or 2-bit width } srslte_cqi_format2_subband_t; typedef enum { @@ -134,7 +134,7 @@ typedef struct SRSLTE_API { typedef struct { union { srslte_cqi_format2_wideband_t wideband; - srslte_cqi_format2_subband_t subband; + srslte_cqi_format2_subband_t subband; srslte_cqi_ue_subband_t subband_ue; srslte_cqi_hl_subband_t subband_hl; }; @@ -145,20 +145,17 @@ SRSLTE_API int srslte_cqi_size(srslte_cqi_cfg_t* cfg); SRSLTE_API int srslte_cqi_value_pack(srslte_cqi_cfg_t* cfg, srslte_cqi_value_t* value, uint8_t* buff); -SRSLTE_API int srslte_cqi_value_unpack(srslte_cqi_cfg_t* cfg, - uint8_t buff[SRSLTE_CQI_MAX_BITS], - srslte_cqi_value_t* value); +SRSLTE_API int +srslte_cqi_value_unpack(srslte_cqi_cfg_t* cfg, uint8_t buff[SRSLTE_CQI_MAX_BITS], srslte_cqi_value_t* value); -SRSLTE_API int srslte_cqi_value_tostring(srslte_cqi_cfg_t* cfg, - srslte_cqi_value_t* value, - char* buff, - uint32_t buff_len); +SRSLTE_API int +srslte_cqi_value_tostring(srslte_cqi_cfg_t* cfg, srslte_cqi_value_t* value, char* buff, uint32_t buff_len); -SRSLTE_API bool srslte_cqi_periodic_send(srslte_cqi_report_cfg_t* periodic_cfg,uint32_t tti, srslte_frame_type_t frame_type); +SRSLTE_API bool +srslte_cqi_periodic_send(srslte_cqi_report_cfg_t* periodic_cfg, uint32_t tti, srslte_frame_type_t frame_type); -SRSLTE_API bool srslte_cqi_periodic_ri_send(srslte_cqi_report_cfg_t* periodic_cfg, - uint32_t tti, - srslte_frame_type_t frame_type); +SRSLTE_API bool +srslte_cqi_periodic_ri_send(srslte_cqi_report_cfg_t* periodic_cfg, uint32_t tti, srslte_frame_type_t frame_type); SRSLTE_API int srslte_cqi_hl_get_no_subbands(int nof_prb); diff --git a/lib/include/srslte/phy/phch/dci.h b/lib/include/srslte/phy/phch/dci.h index aa9dd56ae..270036bd6 100644 --- a/lib/include/srslte/phy/phch/dci.h +++ b/lib/include/srslte/phy/phch/dci.h @@ -22,8 +22,8 @@ /****************************************************************************** * File: dci.h * - * Description: Downlink control information (DCI). - * Packing/Unpacking functions to convert between bit streams + * Description: Downlink control information (DCI). + * Packing/Unpacking functions to convert between bit streams * and packed DCI UL/DL grants defined in ra.h * * Reference: 3GPP TS 36.212 version 10.0.0 Release 10 Sec. 5.3.3 @@ -38,7 +38,7 @@ #include "srslte/phy/common/phy_common.h" #include "srslte/phy/phch/ra.h" -#define SRSLTE_DCI_MAX_BITS 128 +#define SRSLTE_DCI_MAX_BITS 128 #define SRSLTE_RAR_GRANT_LEN 20 #define SRSLTE_DCI_IS_TB_EN(tb) (!(tb.mcs_idx == 0 && tb.rv == 1)) @@ -180,7 +180,7 @@ typedef struct SRSLTE_API { uint32_t rba; uint32_t trunc_mcs; uint32_t tpc_pusch; - bool ul_delay; + bool ul_delay; bool cqi_request; bool hopping_flag; } srslte_dci_rar_grant_t; @@ -191,44 +191,40 @@ SRSLTE_API void srslte_dci_rar_pack(srslte_dci_rar_grant_t* rar, uint8_t payload SRSLTE_API int srslte_dci_rar_to_ul_dci(srslte_cell_t* cell, srslte_dci_rar_grant_t* rar, srslte_dci_ul_t* dci_ul); -SRSLTE_API int srslte_dci_msg_pack_pusch(srslte_cell_t* cell, +SRSLTE_API int srslte_dci_msg_pack_pusch(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, - srslte_dci_cfg_t* cfg, - srslte_dci_ul_t* dci, - srslte_dci_msg_t* msg); + srslte_dci_cfg_t* cfg, + srslte_dci_ul_t* dci, + srslte_dci_msg_t* msg); -SRSLTE_API int srslte_dci_msg_unpack_pusch(srslte_cell_t* cell, +SRSLTE_API int srslte_dci_msg_unpack_pusch(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, - srslte_dci_cfg_t* cfg, - srslte_dci_msg_t* msg, - srslte_dci_ul_t* dci); + srslte_dci_cfg_t* cfg, + srslte_dci_msg_t* msg, + srslte_dci_ul_t* dci); -SRSLTE_API int srslte_dci_msg_pack_pdsch(srslte_cell_t* cell, +SRSLTE_API int srslte_dci_msg_pack_pdsch(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, - srslte_dci_cfg_t* cfg, srslte_dci_dl_t* dci, srslte_dci_msg_t* msg); + srslte_dci_cfg_t* cfg, + srslte_dci_dl_t* dci, + srslte_dci_msg_t* msg); -SRSLTE_API int srslte_dci_msg_unpack_pdsch(srslte_cell_t* cell, +SRSLTE_API int srslte_dci_msg_unpack_pdsch(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, - srslte_dci_cfg_t* cfg, - srslte_dci_msg_t* msg, - srslte_dci_dl_t* dci); + srslte_dci_cfg_t* cfg, + srslte_dci_msg_t* msg, + srslte_dci_dl_t* dci); SRSLTE_API uint32_t srslte_dci_format_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_format_t format); -SRSLTE_API void srslte_dci_dl_fprint(FILE* f, - srslte_dci_dl_t* dci, - uint32_t nof_prb); +SRSLTE_API void srslte_dci_dl_fprint(FILE* f, srslte_dci_dl_t* dci, uint32_t nof_prb); -SRSLTE_API uint32_t srslte_dci_dl_info(srslte_dci_dl_t* dci_dl, - char* str, - uint32_t str_len); +SRSLTE_API uint32_t srslte_dci_dl_info(srslte_dci_dl_t* dci_dl, char* str, uint32_t str_len); -SRSLTE_API uint32_t srslte_dci_ul_info(srslte_dci_ul_t* dci_ul, - char* info_str, - uint32_t len); +SRSLTE_API uint32_t srslte_dci_ul_info(srslte_dci_ul_t* dci_ul, char* info_str, uint32_t len); SRSLTE_API srslte_dci_format_t srslte_dci_format_from_string(char* str); @@ -236,9 +232,7 @@ SRSLTE_API char* srslte_dci_format_string(srslte_dci_format_t format); SRSLTE_API char* srslte_dci_format_string_short(srslte_dci_format_t format); -SRSLTE_API int srslte_dci_location_set(srslte_dci_location_t* c, - uint32_t L, - uint32_t nCCE); +SRSLTE_API int srslte_dci_location_set(srslte_dci_location_t* c, uint32_t L, uint32_t nCCE); SRSLTE_API bool srslte_dci_location_isvalid(srslte_dci_location_t* c); diff --git a/lib/include/srslte/phy/phch/pbch.h b/lib/include/srslte/phy/phch/pbch.h index 16ea75618..f4cc2e189 100644 --- a/lib/include/srslte/phy/phch/pbch.h +++ b/lib/include/srslte/phy/phch/pbch.h @@ -22,9 +22,9 @@ /****************************************************************************** * File: pbch.h * - * 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 + * 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 *****************************************************************************/ @@ -45,48 +45,47 @@ #include "srslte/phy/modem/mod.h" #include "srslte/phy/scrambling/scrambling.h" -#define SRSLTE_BCH_PAYLOAD_LEN 24 -#define SRSLTE_BCH_PAYLOADCRC_LEN (SRSLTE_BCH_PAYLOAD_LEN+16) -#define SRSLTE_BCH_ENCODED_LEN 3*(SRSLTE_BCH_PAYLOADCRC_LEN) +#define SRSLTE_BCH_PAYLOAD_LEN 24 +#define SRSLTE_BCH_PAYLOADCRC_LEN (SRSLTE_BCH_PAYLOAD_LEN + 16) +#define SRSLTE_BCH_ENCODED_LEN 3 * (SRSLTE_BCH_PAYLOADCRC_LEN) #define SRSLTE_PBCH_MAX_RE 256 // make it avx2-aligned /* PBCH object */ typedef struct SRSLTE_API { srslte_cell_t cell; - + uint32_t nof_symbols; /* buffers */ - cf_t *ce[SRSLTE_MAX_PORTS]; - cf_t *symbols[SRSLTE_MAX_PORTS]; - cf_t *x[SRSLTE_MAX_PORTS]; - cf_t *d; - float *llr; - float *temp; - float rm_f[SRSLTE_BCH_ENCODED_LEN]; - uint8_t *rm_b; - uint8_t data[SRSLTE_BCH_PAYLOADCRC_LEN]; - uint8_t data_enc[SRSLTE_BCH_ENCODED_LEN]; + cf_t* ce[SRSLTE_MAX_PORTS]; + cf_t* symbols[SRSLTE_MAX_PORTS]; + cf_t* x[SRSLTE_MAX_PORTS]; + cf_t* d; + float* llr; + float* temp; + float rm_f[SRSLTE_BCH_ENCODED_LEN]; + uint8_t* rm_b; + uint8_t data[SRSLTE_BCH_PAYLOADCRC_LEN]; + uint8_t data_enc[SRSLTE_BCH_ENCODED_LEN]; uint32_t frame_idx; /* tx & rx objects */ srslte_modem_table_t mod; - srslte_sequence_t seq; - srslte_viterbi_t decoder; - srslte_crc_t crc; - srslte_convcoder_t encoder; - bool search_all_ports; - + srslte_sequence_t seq; + srslte_viterbi_t decoder; + srslte_crc_t crc; + srslte_convcoder_t encoder; + bool search_all_ports; + } srslte_pbch_t; -SRSLTE_API int srslte_pbch_init(srslte_pbch_t *q); +SRSLTE_API int srslte_pbch_init(srslte_pbch_t* q); -SRSLTE_API void srslte_pbch_free(srslte_pbch_t *q); +SRSLTE_API void srslte_pbch_free(srslte_pbch_t* q); -SRSLTE_API int srslte_pbch_set_cell(srslte_pbch_t *q, - srslte_cell_t cell); +SRSLTE_API int srslte_pbch_set_cell(srslte_pbch_t* q, srslte_cell_t cell); SRSLTE_API int srslte_pbch_decode(srslte_pbch_t* q, srslte_chest_dl_res_t* channel, @@ -100,7 +99,7 @@ SRSLTE_API int srslte_pbch_encode(srslte_pbch_t* q, cf_t* sf_symbols[SRSLTE_MAX_PORTS], uint32_t frame_idx); -SRSLTE_API void srslte_pbch_decode_reset(srslte_pbch_t *q); +SRSLTE_API void srslte_pbch_decode_reset(srslte_pbch_t* q); SRSLTE_API void srslte_pbch_mib_unpack(uint8_t* msg, srslte_cell_t* cell, uint32_t* sfn); diff --git a/lib/include/srslte/phy/phch/pcfich.h b/lib/include/srslte/phy/phch/pcfich.h index 88794f1e9..808652c8b 100644 --- a/lib/include/srslte/phy/phch/pcfich.h +++ b/lib/include/srslte/phy/phch/pcfich.h @@ -40,33 +40,33 @@ #include "srslte/phy/phch/regs.h" #include "srslte/phy/scrambling/scrambling.h" -#define PCFICH_CFI_LEN 32 -#define PCFICH_RE PCFICH_CFI_LEN/2 +#define PCFICH_CFI_LEN 32 +#define PCFICH_RE PCFICH_CFI_LEN / 2 /* PCFICH object */ typedef struct SRSLTE_API { srslte_cell_t cell; - int nof_symbols; - - uint32_t nof_rx_antennas; + int nof_symbols; + + uint32_t nof_rx_antennas; /* handler to REGs resource mapper */ - srslte_regs_t *regs; + srslte_regs_t* regs; /* buffers */ cf_t ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS][PCFICH_RE]; cf_t symbols[SRSLTE_MAX_PORTS][PCFICH_RE]; cf_t x[SRSLTE_MAX_PORTS][PCFICH_RE]; cf_t d[PCFICH_RE]; - - // cfi table in floats + + // cfi table in floats float cfi_table_float[3][PCFICH_CFI_LEN]; /* bit message */ uint8_t data[PCFICH_CFI_LEN]; /* received soft bits */ - float data_f[PCFICH_CFI_LEN]; + float data_f[PCFICH_CFI_LEN]; /* tx & rx objects */ srslte_modem_table_t mod; @@ -74,14 +74,11 @@ typedef struct SRSLTE_API { } srslte_pcfich_t; -SRSLTE_API int srslte_pcfich_init(srslte_pcfich_t *q, - uint32_t nof_rx_antennas); +SRSLTE_API int srslte_pcfich_init(srslte_pcfich_t* q, uint32_t nof_rx_antennas); -SRSLTE_API int srslte_pcfich_set_cell(srslte_pcfich_t *q, - srslte_regs_t *regs, - srslte_cell_t cell); +SRSLTE_API int srslte_pcfich_set_cell(srslte_pcfich_t* q, srslte_regs_t* regs, srslte_cell_t cell); -SRSLTE_API void srslte_pcfich_free(srslte_pcfich_t *q); +SRSLTE_API void srslte_pcfich_free(srslte_pcfich_t* q); SRSLTE_API int srslte_pcfich_decode(srslte_pcfich_t* q, srslte_dl_sf_cfg_t* sf, diff --git a/lib/include/srslte/phy/phch/pdcch.h b/lib/include/srslte/phy/phch/pdcch.h index 8f0afff9e..93fd6f9ac 100644 --- a/lib/include/srslte/phy/phch/pdcch.h +++ b/lib/include/srslte/phy/phch/pdcch.h @@ -45,56 +45,47 @@ #include "srslte/phy/phch/regs.h" #include "srslte/phy/scrambling/scrambling.h" -typedef enum SRSLTE_API { - SEARCH_UE, SEARCH_COMMON -} srslte_pdcch_search_mode_t; - +typedef enum SRSLTE_API { SEARCH_UE, SEARCH_COMMON } srslte_pdcch_search_mode_t; /* PDCCH object */ typedef struct SRSLTE_API { srslte_cell_t cell; - uint32_t nof_regs[3]; - uint32_t nof_cce[3]; - uint32_t max_bits; - uint32_t nof_rx_antennas; - bool is_ue; - - srslte_regs_t *regs; + uint32_t nof_regs[3]; + uint32_t nof_cce[3]; + uint32_t max_bits; + uint32_t nof_rx_antennas; + bool is_ue; + + srslte_regs_t* regs; /* buffers */ - cf_t *ce[SRSLTE_MAX_PORTS][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; + cf_t* ce[SRSLTE_MAX_PORTS][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; /* tx & rx objects */ srslte_modem_table_t mod; srslte_sequence_t seq[SRSLTE_NOF_SF_X_FRAME]; - srslte_viterbi_t decoder; + srslte_viterbi_t decoder; srslte_crc_t crc; } srslte_pdcch_t; -SRSLTE_API int srslte_pdcch_init_ue(srslte_pdcch_t *q, - uint32_t max_prb, - uint32_t nof_rx_antennas); +SRSLTE_API int srslte_pdcch_init_ue(srslte_pdcch_t* q, uint32_t max_prb, uint32_t nof_rx_antennas); -SRSLTE_API int srslte_pdcch_init_enb(srslte_pdcch_t *q, - uint32_t max_prb); +SRSLTE_API int srslte_pdcch_init_enb(srslte_pdcch_t* q, uint32_t max_prb); -SRSLTE_API int srslte_pdcch_set_cell(srslte_pdcch_t *q, - srslte_regs_t *regs, - srslte_cell_t cell); +SRSLTE_API int srslte_pdcch_set_cell(srslte_pdcch_t* q, srslte_regs_t* regs, srslte_cell_t cell); SRSLTE_API void srslte_pdcch_set_regs(srslte_pdcch_t* q, srslte_regs_t* regs); SRSLTE_API void srslte_pdcch_free(srslte_pdcch_t* q); -SRSLTE_API float srslte_pdcch_coderate(uint32_t nof_bits, - uint32_t l); +SRSLTE_API float srslte_pdcch_coderate(uint32_t nof_bits, uint32_t l); /* Encoding function */ SRSLTE_API int srslte_pdcch_encode(srslte_pdcch_t* q, @@ -110,50 +101,37 @@ SRSLTE_API int srslte_pdcch_extract_llr(srslte_pdcch_t* q, cf_t* sf_symbols[SRSLTE_MAX_PORTS]); /* Decoding functions: Try to decode a DCI message after calling srslte_pdcch_extract_llr */ -SRSLTE_API int srslte_pdcch_decode_msg(srslte_pdcch_t* q, - srslte_dl_sf_cfg_t* sf, - srslte_dci_cfg_t* dci_cfg, - srslte_dci_msg_t* msg); - -SRSLTE_API int srslte_pdcch_dci_decode(srslte_pdcch_t* q, - float* e, - uint8_t* data, - uint32_t E, - uint32_t nof_bits, - uint16_t* crc); - -SRSLTE_API int srslte_pdcch_dci_encode(srslte_pdcch_t *q, - uint8_t *data, - uint8_t *e, - uint32_t nof_bits, - uint32_t E, - uint16_t rnti); - -SRSLTE_API void srslte_pdcch_dci_encode_conv(srslte_pdcch_t *q, - uint8_t *data, - uint32_t nof_bits, - uint8_t *coded_data, - uint16_t rnti); +SRSLTE_API int +srslte_pdcch_decode_msg(srslte_pdcch_t* q, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* dci_cfg, srslte_dci_msg_t* msg); + +SRSLTE_API int +srslte_pdcch_dci_decode(srslte_pdcch_t* q, float* e, uint8_t* data, uint32_t E, uint32_t nof_bits, uint16_t* crc); + +SRSLTE_API int +srslte_pdcch_dci_encode(srslte_pdcch_t* q, uint8_t* data, uint8_t* e, uint32_t nof_bits, uint32_t E, uint16_t rnti); + +SRSLTE_API void +srslte_pdcch_dci_encode_conv(srslte_pdcch_t* q, uint8_t* data, uint32_t nof_bits, uint8_t* coded_data, uint16_t rnti); /* Function for generation of UE-specific search space DCI locations */ -SRSLTE_API uint32_t srslte_pdcch_ue_locations(srslte_pdcch_t* q, - srslte_dl_sf_cfg_t* sf, +SRSLTE_API uint32_t srslte_pdcch_ue_locations(srslte_pdcch_t* q, + srslte_dl_sf_cfg_t* sf, srslte_dci_location_t* locations, - uint32_t max_locations, - uint16_t rnti); + uint32_t max_locations, + uint16_t rnti); -SRSLTE_API uint32_t srslte_pdcch_ue_locations_ncce(uint32_t nof_cce, +SRSLTE_API uint32_t srslte_pdcch_ue_locations_ncce(uint32_t nof_cce, srslte_dci_location_t* c, - uint32_t max_candidates, - uint32_t sf_idx, - uint16_t rnti); + uint32_t max_candidates, + uint32_t sf_idx, + uint16_t rnti); -SRSLTE_API uint32_t srslte_pdcch_ue_locations_ncce_L(uint32_t nof_cce, +SRSLTE_API uint32_t srslte_pdcch_ue_locations_ncce_L(uint32_t nof_cce, srslte_dci_location_t* c, - uint32_t max_candidates, - uint32_t sf_idx, - uint16_t rnti, - int L); + uint32_t max_candidates, + uint32_t sf_idx, + uint16_t rnti, + int L); /* Function for generation of common search space DCI locations */ SRSLTE_API uint32_t srslte_pdcch_common_locations(srslte_pdcch_t* q, diff --git a/lib/include/srslte/phy/phch/pdsch.h b/lib/include/srslte/phy/phch/pdsch.h index c0818c662..9d1138f5e 100644 --- a/lib/include/srslte/phy/phch/pdsch.h +++ b/lib/include/srslte/phy/phch/pdsch.h @@ -45,43 +45,43 @@ typedef struct { srslte_sequence_t seq[SRSLTE_MAX_CODEWORDS][SRSLTE_NOF_SF_X_FRAME]; - uint32_t cell_id; - bool sequence_generated; + uint32_t cell_id; + bool sequence_generated; } srslte_pdsch_user_t; /* PDSCH object */ typedef struct SRSLTE_API { srslte_cell_t cell; - + uint32_t nof_rx_antennas; uint32_t max_re; uint16_t ue_rnti; - bool is_ue; + bool is_ue; bool llr_is_8bit; /* buffers */ // void buffers are shared for tx and rx - cf_t *ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; /* Channel estimation (Rx only) */ - cf_t *symbols[SRSLTE_MAX_PORTS]; /* PDSCH Encoded/Decoded Symbols */ - cf_t *x[SRSLTE_MAX_LAYERS]; /* Layer mapped */ - cf_t *d[SRSLTE_MAX_CODEWORDS]; /* Modulated/Demodulated codewords */ - void *e[SRSLTE_MAX_CODEWORDS]; + cf_t* ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; /* Channel estimation (Rx only) */ + cf_t* symbols[SRSLTE_MAX_PORTS]; /* PDSCH Encoded/Decoded Symbols */ + cf_t* x[SRSLTE_MAX_LAYERS]; /* Layer mapped */ + cf_t* d[SRSLTE_MAX_CODEWORDS]; /* Modulated/Demodulated codewords */ + void* e[SRSLTE_MAX_CODEWORDS]; - float *csi[SRSLTE_MAX_CODEWORDS]; /* Channel Strengh Indicator */ + float* csi[SRSLTE_MAX_CODEWORDS]; /* Channel Strengh Indicator */ /* tx & rx objects */ srslte_modem_table_t mod[5]; // This is to generate the scrambling seq for multiple CRNTIs - srslte_pdsch_user_t **users; + srslte_pdsch_user_t** users; srslte_sequence_t tmp_seq; srslte_sch_t dl_sch; - void *coworker_ptr; + void* coworker_ptr; } srslte_pdsch_t; @@ -91,22 +91,18 @@ typedef struct { float avg_iterations_block; } srslte_pdsch_res_t; -SRSLTE_API int srslte_pdsch_init_ue(srslte_pdsch_t *q, - uint32_t max_prb, - uint32_t nof_rx_antennas); +SRSLTE_API int srslte_pdsch_init_ue(srslte_pdsch_t* q, uint32_t max_prb, uint32_t nof_rx_antennas); -SRSLTE_API int srslte_pdsch_init_enb(srslte_pdsch_t *q, - uint32_t max_prb); +SRSLTE_API int srslte_pdsch_init_enb(srslte_pdsch_t* q, uint32_t max_prb); -SRSLTE_API void srslte_pdsch_free(srslte_pdsch_t *q); +SRSLTE_API void srslte_pdsch_free(srslte_pdsch_t* q); /* These functions modify the state of the object and may take some time */ SRSLTE_API int srslte_pdsch_enable_coworker(srslte_pdsch_t* q); SRSLTE_API int srslte_pdsch_set_cell(srslte_pdsch_t* q, srslte_cell_t cell); -SRSLTE_API int srslte_pdsch_set_rnti(srslte_pdsch_t *q, - uint16_t rnti); +SRSLTE_API int srslte_pdsch_set_rnti(srslte_pdsch_t* q, uint16_t rnti); SRSLTE_API void srslte_pdsch_free_rnti(srslte_pdsch_t* q, uint16_t rnti); diff --git a/lib/include/srslte/phy/phch/pdsch_cfg.h b/lib/include/srslte/phy/phch/pdsch_cfg.h index f70ada223..e1995e222 100644 --- a/lib/include/srslte/phy/phch/pdsch_cfg.h +++ b/lib/include/srslte/phy/phch/pdsch_cfg.h @@ -30,9 +30,9 @@ #ifndef SRSLTE_PDSCH_CFG_H #define SRSLTE_PDSCH_CFG_H -#include "srslte/phy/phch/ra.h" -#include "srslte/phy/fec/softbuffer.h" #include "srslte/phy/fec/cbsegm.h" +#include "srslte/phy/fec/softbuffer.h" +#include "srslte/phy/phch/ra.h" typedef struct SRSLTE_API { diff --git a/lib/include/srslte/phy/phch/phich.h b/lib/include/srslte/phy/phch/phich.h index 025f8d454..99f32a9f1 100644 --- a/lib/include/srslte/phy/phch/phich.h +++ b/lib/include/srslte/phy/phch/phich.h @@ -40,17 +40,17 @@ #include "srslte/phy/modem/mod.h" #include "srslte/phy/scrambling/scrambling.h" -#define SRSLTE_PHICH_NORM_NSEQUENCES 8 -#define SRSLTE_PHICH_EXT_NSEQUENCES 4 -#define SRSLTE_PHICH_NBITS 3 - -#define SRSLTE_PHICH_NORM_MSYMB SRSLTE_PHICH_NBITS * 4 -#define SRSLTE_PHICH_EXT_MSYMB SRSLTE_PHICH_NBITS * 2 -#define SRSLTE_PHICH_MAX_NSYMB SRSLTE_PHICH_NORM_MSYMB -#define SRSLTE_PHICH_NORM_C 1 -#define SRSLTE_PHICH_EXT_C 2 -#define SRSLTE_PHICH_NORM_NSF 4 -#define SRSLTE_PHICH_EXT_NSF 2 +#define SRSLTE_PHICH_NORM_NSEQUENCES 8 +#define SRSLTE_PHICH_EXT_NSEQUENCES 4 +#define SRSLTE_PHICH_NBITS 3 + +#define SRSLTE_PHICH_NORM_MSYMB SRSLTE_PHICH_NBITS * 4 +#define SRSLTE_PHICH_EXT_MSYMB SRSLTE_PHICH_NBITS * 2 +#define SRSLTE_PHICH_MAX_NSYMB SRSLTE_PHICH_NORM_MSYMB +#define SRSLTE_PHICH_NORM_C 1 +#define SRSLTE_PHICH_EXT_C 2 +#define SRSLTE_PHICH_NORM_NSF 4 +#define SRSLTE_PHICH_EXT_NSF 2 /* phich object */ typedef struct SRSLTE_API { @@ -71,7 +71,7 @@ typedef struct SRSLTE_API { /* bit message */ uint8_t data[SRSLTE_PHICH_NBITS]; - float data_rx[SRSLTE_PHICH_NBITS]; + float data_rx[SRSLTE_PHICH_NBITS]; /* tx & rx objects */ srslte_modem_table_t mod; @@ -97,11 +97,9 @@ typedef struct SRSLTE_API { SRSLTE_API int srslte_phich_init(srslte_phich_t* q, uint32_t nof_rx_antennas); -SRSLTE_API void srslte_phich_free(srslte_phich_t *q); +SRSLTE_API void srslte_phich_free(srslte_phich_t* q); -SRSLTE_API int srslte_phich_set_cell(srslte_phich_t *q, - srslte_regs_t *regs, - srslte_cell_t cell); +SRSLTE_API int srslte_phich_set_cell(srslte_phich_t* q, srslte_regs_t* regs, srslte_cell_t cell); SRSLTE_API void srslte_phich_set_regs(srslte_phich_t* q, srslte_regs_t* regs); diff --git a/lib/include/srslte/phy/phch/pmch.h b/lib/include/srslte/phy/phch/pmch.h index 2adf8d8a4..0677356b7 100644 --- a/lib/include/srslte/phy/phch/pmch.h +++ b/lib/include/srslte/phy/phch/pmch.h @@ -39,10 +39,10 @@ #include "srslte/phy/modem/mod.h" #include "srslte/phy/phch/dci.h" #include "srslte/phy/phch/pdsch.h" +#include "srslte/phy/phch/ra_dl.h" #include "srslte/phy/phch/regs.h" #include "srslte/phy/phch/sch.h" #include "srslte/phy/scrambling/scrambling.h" -#include "srslte/phy/phch/ra_dl.h" typedef struct { srslte_sequence_t seq[SRSLTE_NOF_SF_X_FRAME]; } srslte_pmch_seq_t; @@ -55,27 +55,27 @@ typedef struct SRSLTE_API { /* PMCH object */ typedef struct SRSLTE_API { srslte_cell_t cell; - + uint32_t nof_rx_antennas; - + uint32_t max_re; - + /* buffers */ // void buffers are shared for tx and rx - cf_t *ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; - cf_t *symbols[SRSLTE_MAX_PORTS]; - cf_t *x[SRSLTE_MAX_PORTS]; - cf_t *d; - void *e; + cf_t* ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; + cf_t* symbols[SRSLTE_MAX_PORTS]; + cf_t* x[SRSLTE_MAX_PORTS]; + cf_t* d; + void* e; /* tx & rx objects */ srslte_modem_table_t mod[4]; - + // This is to generate the scrambling seq for multiple MBSFN Area IDs - srslte_pmch_seq_t **seqs; - + srslte_pmch_seq_t** seqs; + srslte_sch_t dl_sch; - + } srslte_pmch_t; SRSLTE_API int srslte_pmch_init(srslte_pmch_t* q, uint32_t max_prb, uint32_t nof_rx_antennas); diff --git a/lib/include/srslte/phy/phch/prach.h b/lib/include/srslte/phy/phch/prach.h index 5faa26030..88ce0b793 100644 --- a/lib/include/srslte/phy/phch/prach.h +++ b/lib/include/srslte/phy/phch/prach.h @@ -30,16 +30,15 @@ #ifndef SRSLTE_PRACH_H #define SRSLTE_PRACH_H -#include -#include -#include -#include #include "srslte/config.h" -#include "srslte/phy/dft/dft.h" #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/dft/dft.h" +#include +#include +#include +#include - -#define SRSLTE_PRACH_MAX_LEN (2*24576+21024) // Maximum Tcp + Tseq +#define SRSLTE_PRACH_MAX_LEN (2 * 24576 + 21024) // Maximum Tcp + Tseq /** Generation and detection of RACH signals for uplink. * Currently only supports preamble formats 0-3. @@ -49,13 +48,13 @@ typedef struct SRSLTE_API { // Parameters from higher layers (extracted from SIB2) - uint32_t config_idx; - uint32_t f; // preamble format - uint32_t rsi; // rootSequenceIndex - bool hs; // highSpeedFlag - uint32_t zczc; // zeroCorrelationZoneConfig - uint32_t N_ifft_ul; // IFFT size for uplink - uint32_t N_ifft_prach; // IFFT size for PRACH generation + uint32_t config_idx; + uint32_t f; // preamble format + uint32_t rsi; // rootSequenceIndex + bool hs; // highSpeedFlag + uint32_t zczc; // zeroCorrelationZoneConfig + uint32_t N_ifft_ul; // IFFT size for uplink + uint32_t N_ifft_prach; // IFFT size for PRACH generation uint32_t max_N_ifft_ul; @@ -68,17 +67,17 @@ typedef struct SRSLTE_API { uint32_t N_cp; // Cyclic prefix length // Generated tables - cf_t seqs[64][839]; // Our set of 64 preamble sequences - cf_t dft_seqs[64][839]; // DFT-precoded seqs + cf_t seqs[64][839]; // Our set of 64 preamble sequences + cf_t dft_seqs[64][839]; // DFT-precoded seqs uint32_t root_seqs_idx[64]; // Indices of root seqs in seqs table uint32_t N_roots; // Number of root sequences used in this configuration - + // Containers - cf_t *ifft_in; - cf_t *ifft_out; - cf_t *prach_bins; - cf_t *corr_spec; - float *corr; + cf_t* ifft_in; + cf_t* ifft_out; + cf_t* prach_bins; + cf_t* corr_spec; + float* corr; // PRACH IFFT srslte_dft_plan_t fft; @@ -87,11 +86,11 @@ typedef struct SRSLTE_API { // ZC-sequence FFT and IFFT srslte_dft_plan_t zc_fft; srslte_dft_plan_t zc_ifft; - - cf_t *signal_fft; - float detect_factor; - - uint32_t deadzone; + + cf_t* signal_fft; + float detect_factor; + + uint32_t deadzone; float peak_values[65]; uint32_t peak_offsets[65]; @@ -101,20 +100,20 @@ typedef struct SRSLTE_API { } srslte_prach_t; typedef struct SRSLTE_API { - int nof_sf; + int nof_sf; uint32_t sf[5]; } srslte_prach_sf_config_t; typedef enum SRSLTE_API { SRSLTE_PRACH_SFN_EVEN = 0, - SRSLTE_PRACH_SFN_ANY, + SRSLTE_PRACH_SFN_ANY, } srslte_prach_sfn_t; typedef struct { - uint32_t config_idx; - uint32_t root_seq_idx; - uint32_t zero_corr_zone; - uint32_t freq_offset; + uint32_t config_idx; + uint32_t root_seq_idx; + uint32_t zero_corr_zone; + uint32_t freq_offset; bool hs_flag; srslte_tdd_config_t tdd_config; } srslte_prach_cfg_t; @@ -135,13 +134,10 @@ SRSLTE_API uint32_t srslte_prach_get_preamble_format(uint32_t config_idx); SRSLTE_API srslte_prach_sfn_t srslte_prach_get_sfn(uint32_t config_idx); -SRSLTE_API bool srslte_prach_tti_opportunity(srslte_prach_t *p, - uint32_t current_tti, - int allowed_subframe); +SRSLTE_API bool srslte_prach_tti_opportunity(srslte_prach_t* p, uint32_t current_tti, int allowed_subframe); -SRSLTE_API bool srslte_prach_tti_opportunity_config_fdd(uint32_t config_idx, - uint32_t current_tti, - int allowed_subframe); +SRSLTE_API bool +srslte_prach_tti_opportunity_config_fdd(uint32_t config_idx, uint32_t current_tti, int allowed_subframe); SRSLTE_API bool srslte_prach_tti_opportunity_config_tdd(uint32_t config_idx, uint32_t tdd_ul_dl_config, @@ -183,25 +179,25 @@ SRSLTE_API int srslte_prach_set_cfg(srslte_prach_t* p, srslte_prach_cfg_t* cfg, SRSLTE_API int srslte_prach_gen(srslte_prach_t* p, uint32_t seq_index, uint32_t freq_offset, cf_t* signal); SRSLTE_API int srslte_prach_detect(srslte_prach_t* p, - uint32_t freq_offset, - cf_t* signal, - uint32_t sig_len, - uint32_t* indices, - uint32_t* ind_len); - -SRSLTE_API int srslte_prach_detect_offset(srslte_prach_t *p, - uint32_t freq_offset, - cf_t *signal, - uint32_t sig_len, - uint32_t *indices, - float *t_offsets, - float *peak_to_avg, - uint32_t *ind_len); - -SRSLTE_API void srslte_prach_set_detect_factor(srslte_prach_t *p, float factor); - -SRSLTE_API int srslte_prach_free(srslte_prach_t *p); - -SRSLTE_API int srslte_prach_print_seqs(srslte_prach_t *p); + uint32_t freq_offset, + cf_t* signal, + uint32_t sig_len, + uint32_t* indices, + uint32_t* ind_len); + +SRSLTE_API int srslte_prach_detect_offset(srslte_prach_t* p, + uint32_t freq_offset, + cf_t* signal, + uint32_t sig_len, + uint32_t* indices, + float* t_offsets, + float* peak_to_avg, + uint32_t* ind_len); + +SRSLTE_API void srslte_prach_set_detect_factor(srslte_prach_t* p, float factor); + +SRSLTE_API int srslte_prach_free(srslte_prach_t* p); + +SRSLTE_API int srslte_prach_print_seqs(srslte_prach_t* p); #endif // SRSLTE_PRACH_H diff --git a/lib/include/srslte/phy/phch/pucch.h b/lib/include/srslte/phy/phch/pucch.h index c0dcc01dd..b3605619b 100644 --- a/lib/include/srslte/phy/phch/pucch.h +++ b/lib/include/srslte/phy/phch/pucch.h @@ -69,9 +69,9 @@ typedef struct SRSLTE_API { uint32_t f_gh[SRSLTE_NSLOTS_X_FRAME]; float tmp_arg[SRSLTE_PUCCH_N_SEQ]; - cf_t *z; - cf_t *z_tmp; - cf_t *ce; + cf_t* z; + cf_t* z_tmp; + cf_t* ce; } srslte_pucch_t; @@ -81,11 +81,11 @@ typedef struct SRSLTE_API { bool detected; } srslte_pucch_res_t; -SRSLTE_API int srslte_pucch_init_ue(srslte_pucch_t *q); +SRSLTE_API int srslte_pucch_init_ue(srslte_pucch_t* q); -SRSLTE_API int srslte_pucch_init_enb(srslte_pucch_t *q); +SRSLTE_API int srslte_pucch_init_enb(srslte_pucch_t* q); -SRSLTE_API void srslte_pucch_free(srslte_pucch_t *q); +SRSLTE_API void srslte_pucch_free(srslte_pucch_t* q); /* These functions modify the state of the object and may take some time */ SRSLTE_API int srslte_pucch_set_cell(srslte_pucch_t* q, srslte_cell_t cell); @@ -97,11 +97,11 @@ SRSLTE_API void srslte_pucch_free_rnti(srslte_pucch_t* q, uint16_t rnti); /* These functions do not modify the state and run in real-time */ SRSLTE_API void srslte_pucch_uci_gen_cfg(srslte_pucch_t* q, srslte_pucch_cfg_t* cfg, srslte_uci_data_t* uci_data); -SRSLTE_API int srslte_pucch_encode(srslte_pucch_t* q, +SRSLTE_API int srslte_pucch_encode(srslte_pucch_t* q, srslte_ul_sf_cfg_t* sf, srslte_pucch_cfg_t* cfg, srslte_uci_value_t* uci_data, - cf_t* sf_symbols); + cf_t* sf_symbols); SRSLTE_API int srslte_pucch_decode(srslte_pucch_t* q, srslte_ul_sf_cfg_t* sf, @@ -138,15 +138,11 @@ SRSLTE_API char* srslte_pucch_format_text(srslte_pucch_format_t format); SRSLTE_API char* srslte_pucch_format_text_short(srslte_pucch_format_t format); -SRSLTE_API void srslte_pucch_tx_info(srslte_pucch_cfg_t* cfg, - srslte_uci_value_t* uci_data, - char* str, - uint32_t str_len); +SRSLTE_API void +srslte_pucch_tx_info(srslte_pucch_cfg_t* cfg, srslte_uci_value_t* uci_data, char* str, uint32_t str_len); -SRSLTE_API void srslte_pucch_rx_info(srslte_pucch_cfg_t* cfg, - srslte_uci_value_t* uci_data, - char* str, - uint32_t str_len); +SRSLTE_API void +srslte_pucch_rx_info(srslte_pucch_cfg_t* cfg, srslte_uci_value_t* uci_data, char* str, uint32_t str_len); SRSLTE_API bool srslte_pucch_cfg_isvalid(srslte_pucch_cfg_t* cfg, uint32_t nof_prb); diff --git a/lib/include/srslte/phy/phch/pusch.h b/lib/include/srslte/phy/phch/pusch.h index cdbf1f7c5..5f0563588 100644 --- a/lib/include/srslte/phy/phch/pusch.h +++ b/lib/include/srslte/phy/phch/pusch.h @@ -31,18 +31,18 @@ #define SRSLTE_PUSCH_H #include "srslte/config.h" +#include "srslte/phy/ch_estimation/refsignal_ul.h" #include "srslte/phy/common/phy_common.h" -#include "srslte/phy/mimo/precoding.h" +#include "srslte/phy/dft/dft_precoding.h" #include "srslte/phy/mimo/layermap.h" -#include "srslte/phy/modem/mod.h" +#include "srslte/phy/mimo/precoding.h" #include "srslte/phy/modem/demod_soft.h" -#include "srslte/phy/scrambling/scrambling.h" -#include "srslte/phy/phch/regs.h" +#include "srslte/phy/modem/mod.h" #include "srslte/phy/phch/dci.h" -#include "srslte/phy/phch/sch.h" #include "srslte/phy/phch/pusch_cfg.h" -#include "srslte/phy/dft/dft_precoding.h" -#include "srslte/phy/ch_estimation/refsignal_ul.h" +#include "srslte/phy/phch/regs.h" +#include "srslte/phy/phch/sch.h" +#include "srslte/phy/scrambling/scrambling.h" typedef struct { srslte_sequence_t seq[SRSLTE_NOF_SF_X_FRAME]; @@ -60,24 +60,24 @@ typedef struct SRSLTE_API { bool llr_is_8bit; - srslte_dft_precoding_t dft_precoding; - + srslte_dft_precoding_t dft_precoding; + /* buffers */ // void buffers are shared for tx and rx - cf_t *ce; - cf_t *z; - cf_t *d; + cf_t* ce; + cf_t* z; + cf_t* d; - void *q; - void *g; + void* q; + void* g; /* tx & rx objects */ srslte_modem_table_t mod[4]; srslte_sch_t ul_sch; // This is to generate the scrambling seq for multiple CRNTIs - srslte_pusch_user_t **users; - srslte_sequence_t tmp_seq; + srslte_pusch_user_t** users; + srslte_sequence_t tmp_seq; } srslte_pusch_t; @@ -93,29 +93,25 @@ typedef struct SRSLTE_API { float avg_iterations_block; } srslte_pusch_res_t; -SRSLTE_API int srslte_pusch_init_ue(srslte_pusch_t *q, - uint32_t max_prb); +SRSLTE_API int srslte_pusch_init_ue(srslte_pusch_t* q, uint32_t max_prb); -SRSLTE_API int srslte_pusch_init_enb(srslte_pusch_t *q, - uint32_t max_prb); +SRSLTE_API int srslte_pusch_init_enb(srslte_pusch_t* q, uint32_t max_prb); -SRSLTE_API void srslte_pusch_free(srslte_pusch_t *q); +SRSLTE_API void srslte_pusch_free(srslte_pusch_t* q); /* These functions modify the state of the object and may take some time */ -SRSLTE_API int srslte_pusch_set_cell(srslte_pusch_t *q, - srslte_cell_t cell); +SRSLTE_API int srslte_pusch_set_cell(srslte_pusch_t* q, srslte_cell_t cell); SRSLTE_API int srslte_pusch_set_rnti(srslte_pusch_t* q, uint16_t rnti); -SRSLTE_API void srslte_pusch_free_rnti(srslte_pusch_t *q, - uint16_t rnti); +SRSLTE_API void srslte_pusch_free_rnti(srslte_pusch_t* q, uint16_t rnti); /* These functions do not modify the state and run in real-time */ -SRSLTE_API int srslte_pusch_encode(srslte_pusch_t* q, - srslte_ul_sf_cfg_t* sf, - srslte_pusch_cfg_t* cfg, +SRSLTE_API int srslte_pusch_encode(srslte_pusch_t* q, + srslte_ul_sf_cfg_t* sf, + srslte_pusch_cfg_t* cfg, srslte_pusch_data_t* data, - cf_t* sf_symbols); + cf_t* sf_symbols); SRSLTE_API int srslte_pusch_decode(srslte_pusch_t* q, srslte_ul_sf_cfg_t* sf, @@ -125,10 +121,10 @@ SRSLTE_API int srslte_pusch_decode(srslte_pusch_t* q, srslte_pusch_res_t* data); SRSLTE_API uint32_t srslte_pusch_grant_tx_info(srslte_pusch_grant_t* grant, - srslte_uci_cfg_t* uci_cfg, - srslte_uci_value_t* uci_data, - char* str, - uint32_t str_len); + srslte_uci_cfg_t* uci_cfg, + srslte_uci_value_t* uci_data, + char* str, + uint32_t str_len); SRSLTE_API uint32_t srslte_pusch_tx_info(srslte_pusch_cfg_t* cfg, srslte_uci_value_t* uci_data, diff --git a/lib/include/srslte/phy/phch/ra.h b/lib/include/srslte/phy/phch/ra.h index 3a11295dc..7d1debef3 100644 --- a/lib/include/srslte/phy/phch/ra.h +++ b/lib/include/srslte/phy/phch/ra.h @@ -30,8 +30,8 @@ #ifndef SRSLTE_RA_H #define SRSLTE_RA_H -#include #include +#include #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -70,15 +70,9 @@ typedef struct SRSLTE_API { typedef struct SRSLTE_API { uint32_t riv; // if L_crb==0, DCI message packer will take this value directly - enum { - SRSLTE_RA_TYPE2_NPRB1A_2 = 0, SRSLTE_RA_TYPE2_NPRB1A_3 = 1 - } n_prb1a; - enum { - SRSLTE_RA_TYPE2_NG1 = 0, SRSLTE_RA_TYPE2_NG2 = 1 - } n_gap; - enum { - SRSLTE_RA_TYPE2_LOC = 0, SRSLTE_RA_TYPE2_DIST = 1 - } mode; + enum { SRSLTE_RA_TYPE2_NPRB1A_2 = 0, SRSLTE_RA_TYPE2_NPRB1A_3 = 1 } n_prb1a; + enum { SRSLTE_RA_TYPE2_NG1 = 0, SRSLTE_RA_TYPE2_NG2 = 1 } n_gap; + enum { SRSLTE_RA_TYPE2_LOC = 0, SRSLTE_RA_TYPE2_DIST = 1 } mode; } srslte_ra_type2_t; SRSLTE_API uint32_t srslte_ra_type0_P(uint32_t nof_prb); @@ -93,11 +87,8 @@ SRSLTE_API uint32_t srslte_ra_type1_N_rb(uint32_t nof_prb); SRSLTE_API uint32_t srslte_ra_type2_to_riv(uint32_t L_crb, uint32_t RB_start, uint32_t nof_prb); -SRSLTE_API void srslte_ra_type2_from_riv(uint32_t riv, - uint32_t* L_crb, - uint32_t* RB_start, - uint32_t nof_prb, - uint32_t nof_vrb); +SRSLTE_API void +srslte_ra_type2_from_riv(uint32_t riv, uint32_t* L_crb, uint32_t* RB_start, uint32_t nof_prb, uint32_t nof_vrb); SRSLTE_API int srslte_ra_tbs_idx_from_mcs(uint32_t mcs, bool is_ul); diff --git a/lib/include/srslte/phy/phch/ra_dl.h b/lib/include/srslte/phy/phch/ra_dl.h index 4144d993b..ca56a6027 100644 --- a/lib/include/srslte/phy/phch/ra_dl.h +++ b/lib/include/srslte/phy/phch/ra_dl.h @@ -51,9 +51,8 @@ SRSLTE_API int srslte_ra_dl_dci_to_grant(srslte_cell_t* cell, srslte_dci_dl_t* dci, srslte_pdsch_grant_t* grant); -SRSLTE_API int srslte_ra_dl_grant_to_grant_prb_allocation(srslte_dci_dl_t* dci, - srslte_pdsch_grant_t* grant, - uint32_t nof_prb); +SRSLTE_API int +srslte_ra_dl_grant_to_grant_prb_allocation(srslte_dci_dl_t* dci, srslte_pdsch_grant_t* grant, uint32_t nof_prb); /** Functions used by the eNodeB scheduler */ SRSLTE_API uint32_t srslte_ra_dl_approx_nof_re(srslte_cell_t* cell, uint32_t nof_prb, uint32_t nof_ctrl_symbols); diff --git a/lib/include/srslte/phy/phch/regs.h b/lib/include/srslte/phy/phch/regs.h index 6973b55c4..b6854a439 100644 --- a/lib/include/srslte/phy/phch/regs.h +++ b/lib/include/srslte/phy/phch/regs.h @@ -30,114 +30,93 @@ #ifndef SRSLTE_REGS_H #define SRSLTE_REGS_H -#include #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" +#include -#define REGS_PHICH_NSYM 12 -#define REGS_PHICH_REGS_X_GROUP 3 - -#define REGS_PCFICH_NSYM 16 -#define REGS_PCFICH_NREGS 4 +#define REGS_PHICH_NSYM 12 +#define REGS_PHICH_REGS_X_GROUP 3 -#define REGS_RE_X_REG 4 +#define REGS_PCFICH_NSYM 16 +#define REGS_PCFICH_NREGS 4 +#define REGS_RE_X_REG 4 typedef struct SRSLTE_API { uint32_t k[4]; uint32_t k0; uint32_t l; - bool assigned; -}srslte_regs_reg_t; + bool assigned; +} srslte_regs_reg_t; typedef struct SRSLTE_API { - uint32_t nof_regs; - srslte_regs_reg_t **regs; -}srslte_regs_ch_t; + uint32_t nof_regs; + srslte_regs_reg_t** regs; +} srslte_regs_ch_t; typedef struct SRSLTE_API { srslte_cell_t cell; - uint32_t max_ctrl_symbols; - uint32_t ngroups_phich; + uint32_t max_ctrl_symbols; + uint32_t ngroups_phich; uint32_t ngroups_phich_m1; srslte_phich_r_t phich_res; srslte_phich_length_t phich_len; - - srslte_regs_ch_t pcfich; - srslte_regs_ch_t *phich; // there are several phich - srslte_regs_ch_t pdcch[3]; /* PDCCH indexing, permutation and interleaving is computed for - the three possible CFI value */ + + srslte_regs_ch_t pcfich; + srslte_regs_ch_t* phich; // there are several phich + srslte_regs_ch_t pdcch[3]; /* PDCCH indexing, permutation and interleaving is computed for + the three possible CFI value */ uint32_t phich_mi; - uint32_t nof_regs; - srslte_regs_reg_t *regs; -}srslte_regs_t; + uint32_t nof_regs; + srslte_regs_reg_t* regs; +} srslte_regs_t; -SRSLTE_API int srslte_regs_init(srslte_regs_t *h, - srslte_cell_t cell); +SRSLTE_API int srslte_regs_init(srslte_regs_t* h, srslte_cell_t cell); SRSLTE_API int srslte_regs_init_opts(srslte_regs_t* h, srslte_cell_t cell, uint32_t phich_mi, bool mbsfn_or_sf1_6_tdd); SRSLTE_API void srslte_regs_free(srslte_regs_t* h); -SRSLTE_API int srslte_regs_pdcch_nregs(srslte_regs_t *h, - uint32_t cfi); +SRSLTE_API int srslte_regs_pdcch_nregs(srslte_regs_t* h, uint32_t cfi); -SRSLTE_API int srslte_regs_pdcch_ncce(srslte_regs_t *h, - uint32_t cfi); +SRSLTE_API int srslte_regs_pdcch_ncce(srslte_regs_t* h, uint32_t cfi); -SRSLTE_API int srslte_regs_pcfich_put(srslte_regs_t *h, - cf_t symbols[REGS_PCFICH_NSYM], - cf_t *slot_symbols); +SRSLTE_API int srslte_regs_pcfich_put(srslte_regs_t* h, cf_t symbols[REGS_PCFICH_NSYM], cf_t* slot_symbols); -SRSLTE_API int srslte_regs_pcfich_get(srslte_regs_t *h, - cf_t *slot_symbols, - cf_t symbols[REGS_PCFICH_NSYM]); +SRSLTE_API int srslte_regs_pcfich_get(srslte_regs_t* h, cf_t* slot_symbols, cf_t symbols[REGS_PCFICH_NSYM]); -SRSLTE_API uint32_t srslte_regs_phich_nregs(srslte_regs_t *h); +SRSLTE_API uint32_t srslte_regs_phich_nregs(srslte_regs_t* h); -SRSLTE_API int srslte_regs_phich_add(srslte_regs_t *h, - cf_t symbols[REGS_PHICH_NSYM], - uint32_t ngroup, - cf_t *slot_symbols); +SRSLTE_API int +srslte_regs_phich_add(srslte_regs_t* h, cf_t symbols[REGS_PHICH_NSYM], uint32_t ngroup, cf_t* slot_symbols); -SRSLTE_API int srslte_regs_phich_get(srslte_regs_t *h, - cf_t *slot_symbols, - cf_t symbols[REGS_PHICH_NSYM], - uint32_t ngroup); +SRSLTE_API int +srslte_regs_phich_get(srslte_regs_t* h, cf_t* slot_symbols, cf_t symbols[REGS_PHICH_NSYM], uint32_t ngroup); -SRSLTE_API uint32_t srslte_regs_phich_ngroups(srslte_regs_t *h); +SRSLTE_API uint32_t srslte_regs_phich_ngroups(srslte_regs_t* h); SRSLTE_API uint32_t srslte_regs_phich_ngroups_m1(srslte_regs_t* h); -SRSLTE_API int srslte_regs_phich_reset(srslte_regs_t *h, - cf_t *slot_symbols); - -SRSLTE_API int srslte_regs_pdcch_put(srslte_regs_t *h, - uint32_t cfi, - cf_t *d, - cf_t *slot_symbols); - -SRSLTE_API int srslte_regs_pdcch_put_offset(srslte_regs_t *h, - uint32_t cfi, - cf_t *d, - cf_t *slot_symbols, - uint32_t start_reg, - uint32_t nof_regs); - -SRSLTE_API int srslte_regs_pdcch_get(srslte_regs_t *h, - uint32_t cfi, - cf_t *slot_symbols, - cf_t *d); - -SRSLTE_API int srslte_regs_pdcch_get_offset(srslte_regs_t *h, - uint32_t cfi, - cf_t *slot_symbols, - cf_t *d, - uint32_t start_reg, - uint32_t nof_regs); +SRSLTE_API int srslte_regs_phich_reset(srslte_regs_t* h, cf_t* slot_symbols); -#endif // SRSLTE_REGS_H +SRSLTE_API int srslte_regs_pdcch_put(srslte_regs_t* h, uint32_t cfi, cf_t* d, cf_t* slot_symbols); + +SRSLTE_API int srslte_regs_pdcch_put_offset(srslte_regs_t* h, + uint32_t cfi, + cf_t* d, + cf_t* slot_symbols, + uint32_t start_reg, + uint32_t nof_regs); +SRSLTE_API int srslte_regs_pdcch_get(srslte_regs_t* h, uint32_t cfi, cf_t* slot_symbols, cf_t* d); +SRSLTE_API int srslte_regs_pdcch_get_offset(srslte_regs_t* h, + uint32_t cfi, + cf_t* slot_symbols, + cf_t* d, + uint32_t start_reg, + uint32_t nof_regs); + +#endif // SRSLTE_REGS_H diff --git a/lib/include/srslte/phy/phch/sch.h b/lib/include/srslte/phy/phch/sch.h index 00428128b..4888e41ab 100644 --- a/lib/include/srslte/phy/phch/sch.h +++ b/lib/include/srslte/phy/phch/sch.h @@ -32,10 +32,10 @@ #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/fec/crc.h" #include "srslte/phy/fec/rm_turbo.h" #include "srslte/phy/fec/turbocoder.h" #include "srslte/phy/fec/turbodecoder.h" -#include "srslte/phy/fec/crc.h" #include "srslte/phy/phch/pdsch_cfg.h" #include "srslte/phy/phch/pusch_cfg.h" #include "srslte/phy/phch/uci.h" @@ -50,32 +50,32 @@ /* DL-SCH AND UL-SCH common functions */ typedef struct SRSLTE_API { - + uint32_t max_iterations; float avg_iterations; bool llr_is_8bit; /* buffers */ - uint8_t *cb_in; - uint8_t *parity_bits; - void *e; - uint8_t *temp_g_bits; - uint32_t *ul_interleaver; + uint8_t* cb_in; + uint8_t* parity_bits; + void* e; + uint8_t* temp_g_bits; + uint32_t* ul_interleaver; srslte_uci_bit_t ack_ri_bits[57600]; // 4*M_sc*Qm_max for RI and ACK srslte_tcod_t encoder; - srslte_tdec_t decoder; - srslte_crc_t crc_tb; - srslte_crc_t crc_cb; - + srslte_tdec_t decoder; + srslte_crc_t crc_tb; + srslte_crc_t crc_cb; + srslte_uci_cqi_pusch_t uci_cqi; - + } srslte_sch_t; -SRSLTE_API int srslte_sch_init(srslte_sch_t *q); +SRSLTE_API int srslte_sch_init(srslte_sch_t* q); -SRSLTE_API void srslte_sch_free(srslte_sch_t *q); +SRSLTE_API void srslte_sch_free(srslte_sch_t* q); SRSLTE_API void srslte_sch_set_max_noi(srslte_sch_t* q, uint32_t max_iterations); @@ -83,21 +83,21 @@ SRSLTE_API float srslte_sch_last_noi(srslte_sch_t* q); SRSLTE_API int srslte_dlsch_encode(srslte_sch_t* q, srslte_pdsch_cfg_t* cfg, uint8_t* data, uint8_t* e_bits); -SRSLTE_API int srslte_dlsch_encode2(srslte_sch_t* q, +SRSLTE_API int srslte_dlsch_encode2(srslte_sch_t* q, srslte_pdsch_cfg_t* cfg, - uint8_t* data, - uint8_t* e_bits, - int codeword_idx, - uint32_t nof_layers); + uint8_t* data, + uint8_t* e_bits, + int codeword_idx, + uint32_t nof_layers); SRSLTE_API int srslte_dlsch_decode(srslte_sch_t* q, srslte_pdsch_cfg_t* cfg, int16_t* e_bits, uint8_t* data); -SRSLTE_API int srslte_dlsch_decode2(srslte_sch_t* q, +SRSLTE_API int srslte_dlsch_decode2(srslte_sch_t* q, srslte_pdsch_cfg_t* cfg, - int16_t* e_bits, - uint8_t* data, - int codeword_idx, - uint32_t nof_layers); + int16_t* e_bits, + uint8_t* data, + int codeword_idx, + uint32_t nof_layers); SRSLTE_API int srslte_ulsch_encode(srslte_sch_t* q, srslte_pusch_cfg_t* cfg, diff --git a/lib/include/srslte/phy/phch/uci.h b/lib/include/srslte/phy/phch/uci.h index 9ee92a93b..2b600bda5 100644 --- a/lib/include/srslte/phy/phch/uci.h +++ b/lib/include/srslte/phy/phch/uci.h @@ -37,38 +37,37 @@ #include "srslte/phy/phch/pusch_cfg.h" #include "srslte/phy/phch/uci_cfg.h" -#define SRSLTE_UCI_MAX_CQI_LEN_PUSCH 512 -#define SRSLTE_UCI_MAX_CQI_LEN_PUCCH 13 -#define SRSLTE_UCI_CQI_CODED_PUCCH_B 20 +#define SRSLTE_UCI_MAX_CQI_LEN_PUSCH 512 +#define SRSLTE_UCI_MAX_CQI_LEN_PUCCH 13 +#define SRSLTE_UCI_CQI_CODED_PUCCH_B 20 #define SRSLTE_UCI_STR_MAX_CHAR 32 typedef struct SRSLTE_API { - srslte_crc_t crc; - srslte_viterbi_t viterbi; - uint8_t tmp_cqi[SRSLTE_UCI_MAX_CQI_LEN_PUSCH]; - uint8_t encoded_cqi[3*SRSLTE_UCI_MAX_CQI_LEN_PUSCH]; - int16_t encoded_cqi_s[3*SRSLTE_UCI_MAX_CQI_LEN_PUSCH]; - uint8_t *cqi_table[11]; - int16_t *cqi_table_s[11]; + srslte_crc_t crc; + srslte_viterbi_t viterbi; + uint8_t tmp_cqi[SRSLTE_UCI_MAX_CQI_LEN_PUSCH]; + uint8_t encoded_cqi[3 * SRSLTE_UCI_MAX_CQI_LEN_PUSCH]; + int16_t encoded_cqi_s[3 * SRSLTE_UCI_MAX_CQI_LEN_PUSCH]; + uint8_t* cqi_table[11]; + int16_t* cqi_table_s[11]; } srslte_uci_cqi_pusch_t; typedef struct SRSLTE_API { - uint8_t **cqi_table; - int16_t **cqi_table_s; + uint8_t** cqi_table; + int16_t** cqi_table_s; } srslte_uci_cqi_pucch_t; -SRSLTE_API void srslte_uci_cqi_pucch_init(srslte_uci_cqi_pucch_t *q); +SRSLTE_API void srslte_uci_cqi_pucch_init(srslte_uci_cqi_pucch_t* q); -SRSLTE_API void srslte_uci_cqi_pucch_free(srslte_uci_cqi_pucch_t *q); +SRSLTE_API void srslte_uci_cqi_pucch_free(srslte_uci_cqi_pucch_t* q); -SRSLTE_API int srslte_uci_encode_cqi_pucch(uint8_t *cqi_data, - uint32_t cqi_len, - uint8_t b_bits[SRSLTE_UCI_CQI_CODED_PUCCH_B]); +SRSLTE_API int +srslte_uci_encode_cqi_pucch(uint8_t* cqi_data, uint32_t cqi_len, uint8_t b_bits[SRSLTE_UCI_CQI_CODED_PUCCH_B]); -SRSLTE_API int srslte_uci_encode_cqi_pucch_from_table(srslte_uci_cqi_pucch_t *q, - uint8_t *cqi_data, - uint32_t cqi_len, - uint8_t b_bits[SRSLTE_UCI_CQI_CODED_PUCCH_B]); +SRSLTE_API int srslte_uci_encode_cqi_pucch_from_table(srslte_uci_cqi_pucch_t* q, + uint8_t* cqi_data, + uint32_t cqi_len, + uint8_t b_bits[SRSLTE_UCI_CQI_CODED_PUCCH_B]); SRSLTE_API int16_t srslte_uci_decode_cqi_pucch(srslte_uci_cqi_pucch_t* q, int16_t b_bits[SRSLTE_CQI_MAX_BITS], // aligned for simd @@ -79,24 +78,24 @@ SRSLTE_API void srslte_uci_encode_ack_sr_pucch3(uint8_t* data, uint32_t nof_bits SRSLTE_API int srslte_uci_cqi_init(srslte_uci_cqi_pusch_t* q); -SRSLTE_API void srslte_uci_cqi_free(srslte_uci_cqi_pusch_t *q); - -SRSLTE_API int srslte_uci_encode_cqi_pusch(srslte_uci_cqi_pusch_t *q, - srslte_pusch_cfg_t *cfg, - uint8_t *cqi_data, - uint32_t cqi_len, - float beta, - uint32_t Q_prime_ri, - uint8_t *q_bits); - -SRSLTE_API int srslte_uci_decode_cqi_pusch(srslte_uci_cqi_pusch_t *q, - srslte_pusch_cfg_t *cfg, - int16_t *q_bits, - float beta, - uint32_t Q_prime_ri, - uint32_t cqi_len, - uint8_t *cqi_data, - bool *cqi_ack); +SRSLTE_API void srslte_uci_cqi_free(srslte_uci_cqi_pusch_t* q); + +SRSLTE_API int srslte_uci_encode_cqi_pusch(srslte_uci_cqi_pusch_t* q, + srslte_pusch_cfg_t* cfg, + uint8_t* cqi_data, + uint32_t cqi_len, + float beta, + uint32_t Q_prime_ri, + uint8_t* q_bits); + +SRSLTE_API int srslte_uci_decode_cqi_pusch(srslte_uci_cqi_pusch_t* q, + srslte_pusch_cfg_t* cfg, + int16_t* q_bits, + float beta, + uint32_t Q_prime_ri, + uint32_t cqi_len, + uint8_t* cqi_data, + bool* cqi_ack); SRSLTE_API int srslte_uci_encode_ack(srslte_pusch_cfg_t* cfg, uint8_t acks[2], @@ -131,9 +130,7 @@ SRSLTE_API uint32_t srslte_uci_cfg_total_ack(srslte_uci_cfg_t* uci_cfg); SRSLTE_API void srslte_uci_data_reset(srslte_uci_data_t* uci_data); -SRSLTE_API int srslte_uci_data_info(srslte_uci_cfg_t* uci_cfg, - srslte_uci_value_t* uci_data, - char* str, - uint32_t maxlen); +SRSLTE_API int +srslte_uci_data_info(srslte_uci_cfg_t* uci_cfg, srslte_uci_value_t* uci_data, char* str, uint32_t maxlen); #endif // SRSLTE_UCI_H diff --git a/lib/include/srslte/phy/resampling/decim.h b/lib/include/srslte/phy/resampling/decim.h index d89879b4a..df6c8cd1e 100644 --- a/lib/include/srslte/phy/resampling/decim.h +++ b/lib/include/srslte/phy/resampling/decim.h @@ -32,15 +32,8 @@ #include "srslte/config.h" +SRSLTE_API void srslte_decim_c(cf_t* input, cf_t* output, int M, int len); -SRSLTE_API void srslte_decim_c(cf_t *input, - cf_t *output, - int M, - int len); - -SRSLTE_API void srslte_decim_f(float *input, - float *output, - int M, - int len); +SRSLTE_API void srslte_decim_f(float* input, float* output, int M, int len); #endif // SRSLTE_DECIM_H diff --git a/lib/include/srslte/phy/resampling/interp.h b/lib/include/srslte/phy/resampling/interp.h index 66554be0d..a147b7c67 100644 --- a/lib/include/srslte/phy/resampling/interp.h +++ b/lib/include/srslte/phy/resampling/interp.h @@ -30,102 +30,84 @@ #ifndef SRSLTE_INTERP_H #define SRSLTE_INTERP_H -#include #include +#include #include "srslte/config.h" - /************* STATIC LINEAR INTERPOLATION FUNCTIONS */ -SRSLTE_API cf_t srslte_interp_linear_onesample(cf_t input0, - cf_t input1); +SRSLTE_API cf_t srslte_interp_linear_onesample(cf_t input0, cf_t input1); -SRSLTE_API cf_t srslte_interp_linear_onesample_cabs(cf_t input0, - cf_t input1); +SRSLTE_API cf_t srslte_interp_linear_onesample_cabs(cf_t input0, cf_t input1); -SRSLTE_API void srslte_interp_linear_offset_cabs(cf_t *input, - cf_t *output, - uint32_t M, - uint32_t len, - uint32_t off_st, +SRSLTE_API void srslte_interp_linear_offset_cabs(cf_t* input, + cf_t* output, + uint32_t M, + uint32_t len, + uint32_t off_st, uint32_t off_end); -SRSLTE_API void srslte_interp_linear_f(float *input, - float *output, - uint32_t M, - uint32_t len); - - +SRSLTE_API void srslte_interp_linear_f(float* input, float* output, uint32_t M, uint32_t len); /* Interpolation between vectors */ typedef struct { - cf_t *diff_vec; + cf_t* diff_vec; uint32_t vector_len; uint32_t max_vector_len; } srslte_interp_linsrslte_vec_t; -SRSLTE_API int srslte_interp_linear_vector_init(srslte_interp_linsrslte_vec_t *q, - uint32_t vector_len); - -SRSLTE_API void srslte_interp_linear_vector_free(srslte_interp_linsrslte_vec_t *q); - -SRSLTE_API int srslte_interp_linear_vector_resize(srslte_interp_linsrslte_vec_t *q, - uint32_t vector_len); - -SRSLTE_API void srslte_interp_linear_vector(srslte_interp_linsrslte_vec_t *q, - cf_t *in0, - cf_t *in1, - cf_t *between, - uint32_t in1_in0_d, - uint32_t M); - -SRSLTE_API void srslte_interp_linear_vector2(srslte_interp_linsrslte_vec_t *q, - cf_t *in0, - cf_t *in1, - cf_t *start, - cf_t *between, - uint32_t in1_in0_d, - uint32_t M); - -SRSLTE_API void srslte_interp_linear_vector3(srslte_interp_linsrslte_vec_t *q, - cf_t *in0, - cf_t *in1, - cf_t *start, - cf_t *between, - uint32_t in1_in0_d, - uint32_t M, - bool to_right, - uint32_t len); +SRSLTE_API int srslte_interp_linear_vector_init(srslte_interp_linsrslte_vec_t* q, uint32_t vector_len); + +SRSLTE_API void srslte_interp_linear_vector_free(srslte_interp_linsrslte_vec_t* q); + +SRSLTE_API int srslte_interp_linear_vector_resize(srslte_interp_linsrslte_vec_t* q, uint32_t vector_len); + +SRSLTE_API void srslte_interp_linear_vector(srslte_interp_linsrslte_vec_t* q, + cf_t* in0, + cf_t* in1, + cf_t* between, + uint32_t in1_in0_d, + uint32_t M); + +SRSLTE_API void srslte_interp_linear_vector2(srslte_interp_linsrslte_vec_t* q, + cf_t* in0, + cf_t* in1, + cf_t* start, + cf_t* between, + uint32_t in1_in0_d, + uint32_t M); + +SRSLTE_API void srslte_interp_linear_vector3(srslte_interp_linsrslte_vec_t* q, + cf_t* in0, + cf_t* in1, + cf_t* start, + cf_t* between, + uint32_t in1_in0_d, + uint32_t M, + bool to_right, + uint32_t len); /* Interpolation within a vector */ typedef struct { - cf_t *diff_vec; - cf_t *diff_vec2; - float *ramp; - uint32_t vector_len; + cf_t* diff_vec; + cf_t* diff_vec2; + float* ramp; + uint32_t vector_len; uint32_t M; uint32_t max_vector_len; uint32_t max_M; } srslte_interp_lin_t; -SRSLTE_API int srslte_interp_linear_init(srslte_interp_lin_t *q, - uint32_t vector_len, - uint32_t M); - -SRSLTE_API void srslte_interp_linear_free(srslte_interp_lin_t *q); +SRSLTE_API int srslte_interp_linear_init(srslte_interp_lin_t* q, uint32_t vector_len, uint32_t M); -SRSLTE_API int srslte_interp_linear_resize(srslte_interp_lin_t *q, - uint32_t vector_len, - uint32_t M); +SRSLTE_API void srslte_interp_linear_free(srslte_interp_lin_t* q); -SRSLTE_API void srslte_interp_linear_offset(srslte_interp_lin_t *q, - cf_t *input, - cf_t *output, - uint32_t off_st, - uint32_t off_end); +SRSLTE_API int srslte_interp_linear_resize(srslte_interp_lin_t* q, uint32_t vector_len, uint32_t M); +SRSLTE_API void +srslte_interp_linear_offset(srslte_interp_lin_t* q, cf_t* input, cf_t* output, uint32_t off_st, uint32_t off_end); #endif // SRSLTE_INTERP_H diff --git a/lib/include/srslte/phy/resampling/resample_arb.h b/lib/include/srslte/phy/resampling/resample_arb.h index b13fe6fba..a9c4a4fe4 100644 --- a/lib/include/srslte/phy/resampling/resample_arb.h +++ b/lib/include/srslte/phy/resampling/resample_arb.h @@ -32,32 +32,27 @@ #ifndef SRSLTE_RESAMPLE_ARB_H #define SRSLTE_RESAMPLE_ARB_H -#include -#include #include +#include +#include #include "srslte/config.h" - -#define SRSLTE_RESAMPLE_ARB_N_35 35 -#define SRSLTE_RESAMPLE_ARB_N 32 // Polyphase filter rows -#define SRSLTE_RESAMPLE_ARB_M 8 // Polyphase filter columns +#define SRSLTE_RESAMPLE_ARB_N_35 35 +#define SRSLTE_RESAMPLE_ARB_N 32 // Polyphase filter rows +#define SRSLTE_RESAMPLE_ARB_M 8 // Polyphase filter columns typedef struct SRSLTE_API { - float rate; // Resample rate - float step; // Step increment through filter - float acc; // Index into filter - bool interpolate; - cf_t reg[SRSLTE_RESAMPLE_ARB_M]; // Our window of samples - + float rate; // Resample rate + float step; // Step increment through filter + float acc; // Index into filter + bool interpolate; + cf_t reg[SRSLTE_RESAMPLE_ARB_M]; // Our window of samples + } srslte_resample_arb_t; -SRSLTE_API void srslte_resample_arb_init(srslte_resample_arb_t *q, - float rate, bool interpolate); +SRSLTE_API void srslte_resample_arb_init(srslte_resample_arb_t* q, float rate, bool interpolate); -SRSLTE_API int srslte_resample_arb_compute(srslte_resample_arb_t *q, - cf_t *input, - cf_t *output, - int n_in); +SRSLTE_API int srslte_resample_arb_compute(srslte_resample_arb_t* q, cf_t* input, cf_t* output, int n_in); #endif // SRSLTE_RESAMPLE_ARB_ diff --git a/lib/include/srslte/phy/rf/rf.h b/lib/include/srslte/phy/rf/rf.h index 260558802..6aaed5e01 100644 --- a/lib/include/srslte/phy/rf/rf.h +++ b/lib/include/srslte/phy/rf/rf.h @@ -19,29 +19,29 @@ * */ -#ifndef SRSLTE_RF_H +#ifndef SRSLTE_RF_H #define SRSLTE_RF_H -#include +#include #include #include -#include +#include #include "srslte/config.h" typedef struct { - void *handler; - void *dev; - - // The following variables are for threaded RX gain control - bool thread_gain_run; - pthread_t thread_gain; - pthread_cond_t cond; - pthread_mutex_t mutex; - double cur_rx_gain; - double new_rx_gain; - bool tx_gain_same_rx; - float tx_rx_gain_offset; + void* handler; + void* dev; + + // The following variables are for threaded RX gain control + bool thread_gain_run; + pthread_t thread_gain; + pthread_cond_t cond; + pthread_mutex_t mutex; + double cur_rx_gain; + double new_rx_gain; + bool tx_gain_same_rx; + float tx_rx_gain_offset; } srslte_rf_t; typedef struct { @@ -52,96 +52,76 @@ typedef struct { } srslte_rf_info_t; typedef struct { - enum { + enum { SRSLTE_RF_ERROR_LATE, SRSLTE_RF_ERROR_UNDERFLOW, SRSLTE_RF_ERROR_OVERFLOW, SRSLTE_RF_ERROR_RX, SRSLTE_RF_ERROR_OTHER } type; - int opt; - const char *msg; + int opt; + const char* msg; } srslte_rf_error_t; typedef void (*srslte_rf_error_handler_t)(srslte_rf_error_t error); -SRSLTE_API int srslte_rf_open(srslte_rf_t *h, - char *args); +SRSLTE_API int srslte_rf_open(srslte_rf_t* h, char* args); -SRSLTE_API int srslte_rf_open_multi(srslte_rf_t *h, - char *args, - uint32_t nof_channels); +SRSLTE_API int srslte_rf_open_multi(srslte_rf_t* h, char* args, uint32_t nof_channels); -SRSLTE_API int srslte_rf_open_devname(srslte_rf_t *h, - char *devname, - char *args, - uint32_t nof_channels); +SRSLTE_API int srslte_rf_open_devname(srslte_rf_t* h, char* devname, char* args, uint32_t nof_channels); -SRSLTE_API const char *srslte_rf_name(srslte_rf_t *h); +SRSLTE_API const char* srslte_rf_name(srslte_rf_t* h); -SRSLTE_API int srslte_rf_start_gain_thread(srslte_rf_t *rf, - bool tx_gain_same_rx); +SRSLTE_API int srslte_rf_start_gain_thread(srslte_rf_t* rf, bool tx_gain_same_rx); -SRSLTE_API int srslte_rf_close(srslte_rf_t *h); +SRSLTE_API int srslte_rf_close(srslte_rf_t* h); -SRSLTE_API int srslte_rf_start_rx_stream(srslte_rf_t *h, bool now); +SRSLTE_API int srslte_rf_start_rx_stream(srslte_rf_t* h, bool now); -SRSLTE_API int srslte_rf_stop_rx_stream(srslte_rf_t *h); +SRSLTE_API int srslte_rf_stop_rx_stream(srslte_rf_t* h); -SRSLTE_API void srslte_rf_flush_buffer(srslte_rf_t *h); +SRSLTE_API void srslte_rf_flush_buffer(srslte_rf_t* h); -SRSLTE_API bool srslte_rf_has_rssi(srslte_rf_t *h); +SRSLTE_API bool srslte_rf_has_rssi(srslte_rf_t* h); SRSLTE_API float srslte_rf_get_rssi(srslte_rf_t* h); SRSLTE_API double srslte_rf_set_rx_srate(srslte_rf_t* h, double freq); -SRSLTE_API double srslte_rf_set_rx_gain(srslte_rf_t *h, - double gain); +SRSLTE_API double srslte_rf_set_rx_gain(srslte_rf_t* h, double gain); -SRSLTE_API void srslte_rf_set_tx_rx_gain_offset(srslte_rf_t *h, - double offset); +SRSLTE_API void srslte_rf_set_tx_rx_gain_offset(srslte_rf_t* h, double offset); -SRSLTE_API double srslte_rf_set_rx_gain_th(srslte_rf_t *h, - double gain); +SRSLTE_API double srslte_rf_set_rx_gain_th(srslte_rf_t* h, double gain); -SRSLTE_API double srslte_rf_get_rx_gain(srslte_rf_t *h); +SRSLTE_API double srslte_rf_get_rx_gain(srslte_rf_t* h); -SRSLTE_API double srslte_rf_get_tx_gain(srslte_rf_t *h); +SRSLTE_API double srslte_rf_get_tx_gain(srslte_rf_t* h); -SRSLTE_API srslte_rf_info_t *srslte_rf_get_info(srslte_rf_t *h); +SRSLTE_API srslte_rf_info_t* srslte_rf_get_info(srslte_rf_t* h); -SRSLTE_API void srslte_rf_suppress_stdout(srslte_rf_t *h); +SRSLTE_API void srslte_rf_suppress_stdout(srslte_rf_t* h); -SRSLTE_API void srslte_rf_register_error_handler(srslte_rf_t *h, - srslte_rf_error_handler_t error_handler); +SRSLTE_API void srslte_rf_register_error_handler(srslte_rf_t* h, srslte_rf_error_handler_t error_handler); SRSLTE_API double srslte_rf_set_rx_freq(srslte_rf_t* h, uint32_t ch, double freq); -SRSLTE_API int srslte_rf_recv(srslte_rf_t *h, - void *data, - uint32_t nsamples, - bool blocking); +SRSLTE_API int srslte_rf_recv(srslte_rf_t* h, void* data, uint32_t nsamples, bool blocking); -SRSLTE_API int srslte_rf_recv_with_time(srslte_rf_t *h, - void *data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs); +SRSLTE_API int +srslte_rf_recv_with_time(srslte_rf_t* h, void* data, uint32_t nsamples, bool blocking, time_t* secs, double* frac_secs); -SRSLTE_API int srslte_rf_recv_with_time_multi(srslte_rf_t *h, - void **data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs); +SRSLTE_API int srslte_rf_recv_with_time_multi(srslte_rf_t* h, + void** data, + uint32_t nsamples, + bool blocking, + time_t* secs, + double* frac_secs); -SRSLTE_API double srslte_rf_set_tx_srate(srslte_rf_t *h, - double freq); +SRSLTE_API double srslte_rf_set_tx_srate(srslte_rf_t* h, double freq); -SRSLTE_API double srslte_rf_set_tx_gain(srslte_rf_t *h, - double gain); +SRSLTE_API double srslte_rf_set_tx_gain(srslte_rf_t* h, double gain); SRSLTE_API double srslte_rf_set_tx_freq(srslte_rf_t* h, uint32_t ch, double freq); @@ -149,53 +129,37 @@ SRSLTE_API void srslte_rf_get_time(srslte_rf_t* h, time_t* secs, double* frac_se SRSLTE_API int srslte_rf_sync(srslte_rf_t* rf); -SRSLTE_API int srslte_rf_send(srslte_rf_t *h, - void *data, - uint32_t nsamples, - bool blocking); - -SRSLTE_API int srslte_rf_send2(srslte_rf_t *h, - void *data, - uint32_t nsamples, - bool blocking, - bool start_of_burst, - bool end_of_burst); - -SRSLTE_API int srslte_rf_send(srslte_rf_t *h, - void *data, - uint32_t nsamples, - bool blocking); - - -SRSLTE_API int srslte_rf_send_timed(srslte_rf_t *h, - void *data, - int nsamples, - time_t secs, - double frac_secs); - -SRSLTE_API int srslte_rf_send_timed2(srslte_rf_t *h, - void *data, - int nsamples, - time_t secs, - double frac_secs, - bool is_start_of_burst, - bool is_end_of_burst); - -SRSLTE_API int srslte_rf_send_timed_multi(srslte_rf_t *rf, - void *data[4], - int nsamples, - time_t secs, - double frac_secs, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst); - -SRSLTE_API int srslte_rf_send_multi(srslte_rf_t *rf, - void *data[4], - int nsamples, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst); +SRSLTE_API int srslte_rf_send(srslte_rf_t* h, void* data, uint32_t nsamples, bool blocking); -#endif // SRSLTE_RF_H +SRSLTE_API int +srslte_rf_send2(srslte_rf_t* h, void* data, uint32_t nsamples, bool blocking, bool start_of_burst, bool end_of_burst); + +SRSLTE_API int srslte_rf_send(srslte_rf_t* h, void* data, uint32_t nsamples, bool blocking); +SRSLTE_API int srslte_rf_send_timed(srslte_rf_t* h, void* data, int nsamples, time_t secs, double frac_secs); + +SRSLTE_API int srslte_rf_send_timed2(srslte_rf_t* h, + void* data, + int nsamples, + time_t secs, + double frac_secs, + bool is_start_of_burst, + bool is_end_of_burst); + +SRSLTE_API int srslte_rf_send_timed_multi(srslte_rf_t* rf, + void* data[4], + int nsamples, + time_t secs, + double frac_secs, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst); + +SRSLTE_API int srslte_rf_send_multi(srslte_rf_t* rf, + void* data[4], + int nsamples, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst); + +#endif // SRSLTE_RF_H diff --git a/lib/include/srslte/phy/rf/rf_utils.h b/lib/include/srslte/phy/rf/rf_utils.h index 4443499fb..c7b1ac2f7 100644 --- a/lib/include/srslte/phy/rf/rf_utils.h +++ b/lib/include/srslte/phy/rf/rf_utils.h @@ -19,11 +19,11 @@ * */ -#ifndef SRSLTE_RF_UTILS_H +#ifndef SRSLTE_RF_UTILS_H #define SRSLTE_RF_UTILS_H -#include "srslte/srslte.h" #include "srslte/phy/rf/rf.h" +#include "srslte/srslte.h" typedef struct SRSLTE_API { uint32_t max_frames_pbch; // timeout in number of 5ms frames for MIB decoding @@ -33,32 +33,23 @@ typedef struct SRSLTE_API { bool force_tdd; } cell_search_cfg_t; -SRSLTE_API int rf_rssi_scan(srslte_rf_t *rf, - float *freqs, - float *rssi, - int nof_bands, - double fs, - int nsamp); +SRSLTE_API int rf_rssi_scan(srslte_rf_t* rf, float* freqs, float* rssi, int nof_bands, double fs, int nsamp); -SRSLTE_API int rf_mib_decoder(srslte_rf_t *rf, - uint32_t nof_rx_antennas, - cell_search_cfg_t *config, - srslte_cell_t *cell, - float *cfo); +SRSLTE_API int +rf_mib_decoder(srslte_rf_t* rf, uint32_t nof_rx_antennas, cell_search_cfg_t* config, srslte_cell_t* cell, float* cfo); -SRSLTE_API int rf_cell_search(srslte_rf_t *rf, - uint32_t nof_rx_antennas, - cell_search_cfg_t *config, - int force_N_id_2, - srslte_cell_t *cell, - float *cfo); +SRSLTE_API int rf_cell_search(srslte_rf_t* rf, + uint32_t nof_rx_antennas, + cell_search_cfg_t* config, + int force_N_id_2, + srslte_cell_t* cell, + float* cfo); -SRSLTE_API int rf_search_and_decode_mib(srslte_rf_t *rf, - uint32_t nof_rx_antennas, - cell_search_cfg_t *config, - int force_N_id_2, - srslte_cell_t *cell, - float *cfo); +SRSLTE_API int rf_search_and_decode_mib(srslte_rf_t* rf, + uint32_t nof_rx_antennas, + cell_search_cfg_t* config, + int force_N_id_2, + srslte_cell_t* cell, + float* cfo); #endif // SRSLTE_RF_UTILS_H - diff --git a/lib/include/srslte/phy/scrambling/scrambling.h b/lib/include/srslte/phy/scrambling/scrambling.h index 790a23eda..dce495328 100644 --- a/lib/include/srslte/phy/scrambling/scrambling.h +++ b/lib/include/srslte/phy/scrambling/scrambling.h @@ -31,49 +31,28 @@ #define SRSLTE_SCRAMBLING_H #include "srslte/config.h" -#include "srslte/phy/common/sequence.h" #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/common/sequence.h" /* Scrambling has no state */ -SRSLTE_API void srslte_scrambling_b(srslte_sequence_t *s, - uint8_t *data); +SRSLTE_API void srslte_scrambling_b(srslte_sequence_t* s, uint8_t* data); -SRSLTE_API void srslte_scrambling_b_offset(srslte_sequence_t *s, - uint8_t *data, - int offset, - int len); +SRSLTE_API void srslte_scrambling_b_offset(srslte_sequence_t* s, uint8_t* data, int offset, int len); -SRSLTE_API void srslte_scrambling_bytes(srslte_sequence_t *s, - uint8_t *data, - int len); +SRSLTE_API void srslte_scrambling_bytes(srslte_sequence_t* s, uint8_t* data, int len); -SRSLTE_API void srslte_scrambling_f(srslte_sequence_t *s, - float *data); +SRSLTE_API void srslte_scrambling_f(srslte_sequence_t* s, float* data); -SRSLTE_API void srslte_scrambling_f_offset(srslte_sequence_t *s, - float *data, - int offset, - int len); +SRSLTE_API void srslte_scrambling_f_offset(srslte_sequence_t* s, float* data, int offset, int len); -SRSLTE_API void srslte_scrambling_s(srslte_sequence_t *s, - short *data); +SRSLTE_API void srslte_scrambling_s(srslte_sequence_t* s, short* data); -SRSLTE_API void srslte_scrambling_s_offset(srslte_sequence_t *s, - short *data, - int offset, - int len); +SRSLTE_API void srslte_scrambling_s_offset(srslte_sequence_t* s, short* data, int offset, int len); -SRSLTE_API void srslte_scrambling_sb_offset(srslte_sequence_t *s, - int8_t *data, - int offset, - int len); +SRSLTE_API void srslte_scrambling_sb_offset(srslte_sequence_t* s, int8_t* data, int offset, int len); -SRSLTE_API void srslte_scrambling_c(srslte_sequence_t *s, - cf_t *data); +SRSLTE_API void srslte_scrambling_c(srslte_sequence_t* s, cf_t* data); -SRSLTE_API void srslte_scrambling_c_offset(srslte_sequence_t *s, - cf_t *data, - int offset, - int len); +SRSLTE_API void srslte_scrambling_c_offset(srslte_sequence_t* s, cf_t* data, int offset, int len); #endif // SRSLTE_SCRAMBLING_H diff --git a/lib/include/srslte/phy/sync/cfo.h b/lib/include/srslte/phy/sync/cfo.h index 729e1c6a6..56856d599 100644 --- a/lib/include/srslte/phy/sync/cfo.h +++ b/lib/include/srslte/phy/sync/cfo.h @@ -38,29 +38,23 @@ #define SRSLTE_CFO_CEXPTAB_SIZE 4096 typedef struct SRSLTE_API { - float last_freq; - float tol; - int nsamples; - int max_samples; + float last_freq; + float tol; + int nsamples; + int max_samples; srslte_cexptab_t tab; - cf_t *cur_cexp; -}srslte_cfo_t; + cf_t* cur_cexp; +} srslte_cfo_t; -SRSLTE_API int srslte_cfo_init(srslte_cfo_t *h, - uint32_t nsamples); +SRSLTE_API int srslte_cfo_init(srslte_cfo_t* h, uint32_t nsamples); -SRSLTE_API void srslte_cfo_free(srslte_cfo_t *h); +SRSLTE_API void srslte_cfo_free(srslte_cfo_t* h); -SRSLTE_API int srslte_cfo_resize(srslte_cfo_t *h, - uint32_t samples); +SRSLTE_API int srslte_cfo_resize(srslte_cfo_t* h, uint32_t samples); -SRSLTE_API void srslte_cfo_set_tol(srslte_cfo_t *h, - float tol); +SRSLTE_API void srslte_cfo_set_tol(srslte_cfo_t* h, float tol); -SRSLTE_API void srslte_cfo_correct(srslte_cfo_t *h, - const cf_t *input, - cf_t *output, - float freq); +SRSLTE_API void srslte_cfo_correct(srslte_cfo_t* h, const cf_t* input, cf_t* output, float freq); SRSLTE_API void srslte_cfo_correct_offset(srslte_cfo_t* h, const cf_t* input, cf_t* output, float freq, int cexp_offset, int nsamples); diff --git a/lib/include/srslte/phy/sync/cp.h b/lib/include/srslte/phy/sync/cp.h index 200b5e1a7..a42f5f2c0 100644 --- a/lib/include/srslte/phy/sync/cp.h +++ b/lib/include/srslte/phy/sync/cp.h @@ -22,32 +22,26 @@ #ifndef SRSLTE_CP_H #define SRSLTE_CP_H -#include #include +#include #include "srslte/config.h" typedef struct { - cf_t *corr; + cf_t* corr; uint32_t symbol_sz; uint32_t max_symbol_sz; } srslte_cp_synch_t; -SRSLTE_API int srslte_cp_synch_init(srslte_cp_synch_t *q, - uint32_t symbol_sz); +SRSLTE_API int srslte_cp_synch_init(srslte_cp_synch_t* q, uint32_t symbol_sz); -SRSLTE_API void srslte_cp_synch_free(srslte_cp_synch_t *q); +SRSLTE_API void srslte_cp_synch_free(srslte_cp_synch_t* q); -SRSLTE_API int srslte_cp_synch_resize(srslte_cp_synch_t *q, - uint32_t symbol_sz); +SRSLTE_API int srslte_cp_synch_resize(srslte_cp_synch_t* q, uint32_t symbol_sz); -SRSLTE_API uint32_t srslte_cp_synch(srslte_cp_synch_t *q, - const cf_t *input, - uint32_t max_offset, - uint32_t nof_symbols, - uint32_t cp_len); +SRSLTE_API uint32_t + srslte_cp_synch(srslte_cp_synch_t* q, const cf_t* input, uint32_t max_offset, uint32_t nof_symbols, uint32_t cp_len); -SRSLTE_API cf_t srslte_cp_synch_corr_output(srslte_cp_synch_t *q, - uint32_t offset); +SRSLTE_API cf_t srslte_cp_synch_corr_output(srslte_cp_synch_t* q, uint32_t offset); #endif // SRSLTE_CP_H diff --git a/lib/include/srslte/phy/sync/npss.h b/lib/include/srslte/phy/sync/npss.h index 58fa1dfc7..48fb1c793 100644 --- a/lib/include/srslte/phy/sync/npss.h +++ b/lib/include/srslte/phy/sync/npss.h @@ -117,7 +117,10 @@ SRSLTE_API int srslte_npss_corr_init(cf_t* npss_signal_time, uint32_t fft_size, SRSLTE_API int srslte_npss_generate(cf_t* signal); -SRSLTE_API void srslte_npss_put_subframe( - srslte_npss_synch_t* q, cf_t* npss_signal, cf_t* sf, const uint32_t nof_prb, const uint32_t nbiot_prb_offset); +SRSLTE_API void srslte_npss_put_subframe(srslte_npss_synch_t* q, + cf_t* npss_signal, + cf_t* sf, + const uint32_t nof_prb, + const uint32_t nbiot_prb_offset); #endif // SRSLTE_NPSS_H diff --git a/lib/include/srslte/phy/sync/nsss.h b/lib/include/srslte/phy/sync/nsss.h index fb7582ccc..1c1f46b85 100644 --- a/lib/include/srslte/phy/sync/nsss.h +++ b/lib/include/srslte/phy/sync/nsss.h @@ -97,8 +97,11 @@ SRSLTE_API void srslte_nsss_synch_free(srslte_nsss_synch_t* q); SRSLTE_API int srslte_nsss_synch_resize(srslte_nsss_synch_t* q, uint32_t fft_size); -SRSLTE_API int srslte_nsss_sync_find( - srslte_nsss_synch_t* q, cf_t* input, float* corr_peak_value, uint32_t* cell_id, uint32_t* sfn_partial); +SRSLTE_API int srslte_nsss_sync_find(srslte_nsss_synch_t* q, + cf_t* input, + float* corr_peak_value, + uint32_t* cell_id, + uint32_t* sfn_partial); void srslte_nsss_sync_find_pci(srslte_nsss_synch_t* q, cf_t* input, uint32_t cell_id); diff --git a/lib/include/srslte/phy/sync/pss.h b/lib/include/srslte/phy/sync/pss.h index 4bb283d4f..1d27310d1 100644 --- a/lib/include/srslte/phy/sync/pss.h +++ b/lib/include/srslte/phy/sync/pss.h @@ -40,8 +40,8 @@ #ifndef SRSLTE_PSS_H #define SRSLTE_PSS_H -#include #include +#include #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" @@ -50,23 +50,22 @@ #define CONVOLUTION_FFT -#define SRSLTE_PSS_LEN 62 -#define SRSLTE_PSS_RE (6*12) - +#define SRSLTE_PSS_LEN 62 +#define SRSLTE_PSS_RE (6 * 12) /* PSS processing options */ -#define SRSLTE_PSS_ACCUMULATE_ABS // If enabled, accumulates the correlation absolute value on consecutive calls to srslte_pss_find_pss - -#define SRSLTE_PSS_RETURN_PSR // If enabled returns peak to side-lobe ratio, otherwise returns absolute peak value +#define SRSLTE_PSS_ACCUMULATE_ABS // If enabled, accumulates the correlation absolute value on consecutive calls to + // srslte_pss_find_pss +#define SRSLTE_PSS_RETURN_PSR // If enabled returns peak to side-lobe ratio, otherwise returns absolute peak value /* Low-level API */ typedef struct SRSLTE_API { #ifdef CONVOLUTION_FFT srslte_conv_fft_cc_t conv_fft; - srslte_filt_cc_t filter; + srslte_filt_cc_t filter; #endif int decimate; @@ -77,98 +76,69 @@ typedef struct SRSLTE_API { uint32_t frame_size; uint32_t N_id_2; uint32_t fft_size; - cf_t *pss_signal_freq_full[3]; + cf_t* pss_signal_freq_full[3]; - cf_t *pss_signal_time[3]; - cf_t *pss_signal_time_scale[3]; + cf_t* pss_signal_time[3]; + cf_t* pss_signal_time_scale[3]; - cf_t pss_signal_freq[3][SRSLTE_PSS_LEN]; // One sequence for each N_id_2 - cf_t *tmp_input; - cf_t *conv_output; - float *conv_output_abs; - float ema_alpha; - float *conv_output_avg; - float peak_value; + cf_t pss_signal_freq[3][SRSLTE_PSS_LEN]; // One sequence for each N_id_2 + cf_t* tmp_input; + cf_t* conv_output; + float* conv_output_abs; + float ema_alpha; + float* conv_output_avg; + float peak_value; - bool filter_pss_enable; + bool filter_pss_enable; srslte_dft_plan_t dftp_input; srslte_dft_plan_t idftp_input; - cf_t tmp_fft[SRSLTE_SYMBOL_SZ_MAX]; - cf_t tmp_fft2[SRSLTE_SYMBOL_SZ_MAX]; + cf_t tmp_fft[SRSLTE_SYMBOL_SZ_MAX]; + cf_t tmp_fft2[SRSLTE_SYMBOL_SZ_MAX]; cf_t tmp_ce[SRSLTE_PSS_LEN]; bool chest_on_filter; -}srslte_pss_t; +} srslte_pss_t; typedef enum { PSS_TX, PSS_RX } pss_direction_t; /* Basic functionality */ -SRSLTE_API int srslte_pss_init_fft(srslte_pss_t *q, - uint32_t frame_size, - uint32_t fft_size); +SRSLTE_API int srslte_pss_init_fft(srslte_pss_t* q, uint32_t frame_size, uint32_t fft_size); -SRSLTE_API int srslte_pss_init_fft_offset(srslte_pss_t *q, - uint32_t frame_size, - uint32_t fft_size, - int cfo_i); +SRSLTE_API int srslte_pss_init_fft_offset(srslte_pss_t* q, uint32_t frame_size, uint32_t fft_size, int cfo_i); -SRSLTE_API int srslte_pss_init_fft_offset_decim(srslte_pss_t *q, - uint32_t frame_size, - uint32_t fft_size, - int cfo_i, - int decimate); +SRSLTE_API int +srslte_pss_init_fft_offset_decim(srslte_pss_t* q, uint32_t frame_size, uint32_t fft_size, int cfo_i, int decimate); -SRSLTE_API int srslte_pss_resize(srslte_pss_t *q, uint32_t frame_size, - uint32_t fft_size, - int offset); +SRSLTE_API int srslte_pss_resize(srslte_pss_t* q, uint32_t frame_size, uint32_t fft_size, int offset); -SRSLTE_API int srslte_pss_init(srslte_pss_t *q, - uint32_t frame_size); +SRSLTE_API int srslte_pss_init(srslte_pss_t* q, uint32_t frame_size); -SRSLTE_API void srslte_pss_free(srslte_pss_t *q); +SRSLTE_API void srslte_pss_free(srslte_pss_t* q); -SRSLTE_API void srslte_pss_reset(srslte_pss_t *q); +SRSLTE_API void srslte_pss_reset(srslte_pss_t* q); -SRSLTE_API void srslte_pss_filter_enable(srslte_pss_t *q, - bool enable); +SRSLTE_API void srslte_pss_filter_enable(srslte_pss_t* q, bool enable); -SRSLTE_API void srslte_pss_sic(srslte_pss_t *q, - cf_t *input); +SRSLTE_API void srslte_pss_sic(srslte_pss_t* q, cf_t* input); -SRSLTE_API void srslte_pss_filter(srslte_pss_t *q, - const cf_t *input, - cf_t *output); +SRSLTE_API void srslte_pss_filter(srslte_pss_t* q, const cf_t* input, cf_t* output); -SRSLTE_API int srslte_pss_generate(cf_t *signal, - uint32_t N_id_2); +SRSLTE_API int srslte_pss_generate(cf_t* signal, uint32_t N_id_2); -SRSLTE_API void srslte_pss_get_slot(cf_t *slot, - cf_t *pss_signal, - uint32_t nof_prb, - srslte_cp_t cp); +SRSLTE_API void srslte_pss_get_slot(cf_t* slot, cf_t* pss_signal, uint32_t nof_prb, srslte_cp_t cp); -SRSLTE_API void srslte_pss_put_slot(cf_t *pss_signal, - cf_t *slot, - uint32_t nof_prb, - srslte_cp_t cp); +SRSLTE_API void srslte_pss_put_slot(cf_t* pss_signal, cf_t* slot, uint32_t nof_prb, srslte_cp_t cp); -SRSLTE_API void srslte_pss_set_ema_alpha(srslte_pss_t *q, - float alpha); +SRSLTE_API void srslte_pss_set_ema_alpha(srslte_pss_t* q, float alpha); -SRSLTE_API int srslte_pss_set_N_id_2(srslte_pss_t *q, - uint32_t N_id_2); +SRSLTE_API int srslte_pss_set_N_id_2(srslte_pss_t* q, uint32_t N_id_2); -SRSLTE_API int srslte_pss_find_pss(srslte_pss_t *q, - const cf_t *input, - float *corr_peak_value); +SRSLTE_API int srslte_pss_find_pss(srslte_pss_t* q, const cf_t* input, float* corr_peak_value); -SRSLTE_API int srslte_pss_chest(srslte_pss_t *q, - const cf_t *input, - cf_t ce[SRSLTE_PSS_LEN]); +SRSLTE_API int srslte_pss_chest(srslte_pss_t* q, const cf_t* input, cf_t ce[SRSLTE_PSS_LEN]); -SRSLTE_API float srslte_pss_cfo_compute(srslte_pss_t* q, - const cf_t *pss_recv); +SRSLTE_API float srslte_pss_cfo_compute(srslte_pss_t* q, const cf_t* pss_recv); #endif // SRSLTE_PSS_H diff --git a/lib/include/srslte/phy/sync/refsignal_dl_sync.h b/lib/include/srslte/phy/sync/refsignal_dl_sync.h index 368e8776e..108fb90ad 100644 --- a/lib/include/srslte/phy/sync/refsignal_dl_sync.h +++ b/lib/include/srslte/phy/sync/refsignal_dl_sync.h @@ -52,7 +52,11 @@ SRSLTE_API void srslte_refsignal_dl_sync_free(srslte_refsignal_dl_sync_t* q); SRSLTE_API void srslte_refsignal_dl_sync_run(srslte_refsignal_dl_sync_t* q, cf_t* buffer, uint32_t nsamples); -SRSLTE_API void srslte_refsignal_dl_sync_measure_sf( - srslte_refsignal_dl_sync_t* q, cf_t* buffer, uint32_t sf_idx, float* rsrp, float* rssi, float* cfo); +SRSLTE_API void srslte_refsignal_dl_sync_measure_sf(srslte_refsignal_dl_sync_t* q, + cf_t* buffer, + uint32_t sf_idx, + float* rsrp, + float* rssi, + float* cfo); #endif // SRSLTE_REFSIGNAL_DL_SYNC_H_ diff --git a/lib/include/srslte/phy/sync/sfo.h b/lib/include/srslte/phy/sync/sfo.h index 7e63c6c9c..2a8e41ce7 100644 --- a/lib/include/srslte/phy/sync/sfo.h +++ b/lib/include/srslte/phy/sync/sfo.h @@ -32,13 +32,8 @@ #include "srslte/config.h" -SRSLTE_API float srslte_sfo_estimate(int *t0, - int len, - float period); +SRSLTE_API float srslte_sfo_estimate(int* t0, int len, float period); -SRSLTE_API float srslte_sfo_estimate_period(int *t0, - int *t, - int len, - float period); +SRSLTE_API float srslte_sfo_estimate_period(int* t0, int* t, int len, float period); #endif // SRSLTE_SFO_H diff --git a/lib/include/srslte/phy/sync/sss.h b/lib/include/srslte/phy/sync/sss.h index 2ed8066ee..5fd68bcae 100644 --- a/lib/include/srslte/phy/sync/sss.h +++ b/lib/include/srslte/phy/sync/sss.h @@ -31,22 +31,21 @@ #ifndef SRSLTE_SSS_H #define SRSLTE_SSS_H -#include #include +#include #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" #include "srslte/phy/dft/dft.h" - -#define SRSLTE_SSS_N 31 -#define SRSLTE_SSS_LEN 2*SRSLTE_SSS_N +#define SRSLTE_SSS_N 31 +#define SRSLTE_SSS_LEN 2 * SRSLTE_SSS_N typedef struct SRSLTE_API { int z1[SRSLTE_SSS_N][SRSLTE_SSS_N]; int c[2][SRSLTE_SSS_N]; int s[SRSLTE_SSS_N][SRSLTE_SSS_N]; -}srslte_sss_tables_t; +} srslte_sss_tables_t; /* Allocate 32 complex to make it multiple of 32-byte AVX instructions alignment requirement. * Should use srslte_vec_malloc() to make it platform agnostic. @@ -55,97 +54,75 @@ typedef struct SRSLTE_API { float z1[SRSLTE_SSS_N][SRSLTE_SSS_N]; float c[2][SRSLTE_SSS_N]; float s[SRSLTE_SSS_N][SRSLTE_SSS_N]; - float sd[SRSLTE_SSS_N][SRSLTE_SSS_N-1]; -}srslte_sss_fc_tables_t; - + float sd[SRSLTE_SSS_N][SRSLTE_SSS_N - 1]; +} srslte_sss_fc_tables_t; /* Low-level API */ typedef struct SRSLTE_API { srslte_dft_plan_t dftp_input; - + uint32_t fft_size; uint32_t max_fft_size; - float corr_peak_threshold; + float corr_peak_threshold; uint32_t symbol_sz; uint32_t subframe_sz; uint32_t N_id_2; - - uint32_t N_id_1_table[30][30]; + + uint32_t N_id_1_table[30][30]; srslte_sss_fc_tables_t fc_tables[3]; // one for each N_id_2 float corr_output_m0[SRSLTE_SSS_N]; float corr_output_m1[SRSLTE_SSS_N]; -}srslte_sss_t; - +} srslte_sss_t; /* Basic functionality */ -SRSLTE_API int srslte_sss_init(srslte_sss_t *q, - uint32_t fft_size); +SRSLTE_API int srslte_sss_init(srslte_sss_t* q, uint32_t fft_size); -SRSLTE_API int srslte_sss_resize(srslte_sss_t *q, - uint32_t fft_size); +SRSLTE_API int srslte_sss_resize(srslte_sss_t* q, uint32_t fft_size); -SRSLTE_API void srslte_sss_free(srslte_sss_t *q); +SRSLTE_API void srslte_sss_free(srslte_sss_t* q); -SRSLTE_API void srslte_sss_generate(float *signal0, - float *signal5, - uint32_t cell_id); +SRSLTE_API void srslte_sss_generate(float* signal0, float* signal5, uint32_t cell_id); -SRSLTE_API void srslte_sss_put_slot(float *sss, - cf_t *symbol, - uint32_t nof_prb, - srslte_cp_t cp); +SRSLTE_API void srslte_sss_put_slot(float* sss, cf_t* symbol, uint32_t nof_prb, srslte_cp_t cp); SRSLTE_API void srslte_sss_put_symbol(float* sss, cf_t* symbol, uint32_t nof_prb); SRSLTE_API int srslte_sss_set_N_id_2(srslte_sss_t* q, uint32_t N_id_2); -SRSLTE_API int srslte_sss_m0m1_partial(srslte_sss_t *q, - const cf_t *input, - uint32_t M, - cf_t ce[2*SRSLTE_SSS_N], - uint32_t *m0, - float *m0_value, - uint32_t *m1, - float *m1_value); - -SRSLTE_API int srslte_sss_m0m1_diff_coh(srslte_sss_t *q, - const cf_t *input, - cf_t ce[2*SRSLTE_SSS_N], - uint32_t *m0, - float *m0_value, - uint32_t *m1, - float *m1_value); - -SRSLTE_API int srslte_sss_m0m1_diff(srslte_sss_t *q, - const cf_t *input, - uint32_t *m0, - float *m0_value, - uint32_t *m1, - float *m1_value); - - -SRSLTE_API uint32_t srslte_sss_subframe(uint32_t m0, - uint32_t m1); +SRSLTE_API int srslte_sss_m0m1_partial(srslte_sss_t* q, + const cf_t* input, + uint32_t M, + cf_t ce[2 * SRSLTE_SSS_N], + uint32_t* m0, + float* m0_value, + uint32_t* m1, + float* m1_value); + +SRSLTE_API int srslte_sss_m0m1_diff_coh(srslte_sss_t* q, + const cf_t* input, + cf_t ce[2 * SRSLTE_SSS_N], + uint32_t* m0, + float* m0_value, + uint32_t* m1, + float* m1_value); + +SRSLTE_API int +srslte_sss_m0m1_diff(srslte_sss_t* q, const cf_t* input, uint32_t* m0, float* m0_value, uint32_t* m1, float* m1_value); + +SRSLTE_API uint32_t srslte_sss_subframe(uint32_t m0, uint32_t m1); SRSLTE_API int srslte_sss_N_id_1(srslte_sss_t* q, uint32_t m0, uint32_t m1, float corr); -SRSLTE_API int srslte_sss_frame(srslte_sss_t *q, - cf_t *input, - uint32_t *subframe_idx, - uint32_t *N_id_1); +SRSLTE_API int srslte_sss_frame(srslte_sss_t* q, cf_t* input, uint32_t* subframe_idx, uint32_t* N_id_1); -SRSLTE_API void srslte_sss_set_threshold(srslte_sss_t *q, - float threshold); +SRSLTE_API void srslte_sss_set_threshold(srslte_sss_t* q, float threshold); -SRSLTE_API void srslte_sss_set_symbol_sz(srslte_sss_t *q, - uint32_t symbol_sz); +SRSLTE_API void srslte_sss_set_symbol_sz(srslte_sss_t* q, uint32_t symbol_sz); -SRSLTE_API void srslte_sss_set_subframe_sz(srslte_sss_t *q, - uint32_t subframe_sz); +SRSLTE_API void srslte_sss_set_subframe_sz(srslte_sss_t* q, uint32_t subframe_sz); #endif // SRSLTE_SSS_H - diff --git a/lib/include/srslte/phy/sync/sync.h b/lib/include/srslte/phy/sync/sync.h index 27bcf3fbf..9eb0c502c 100644 --- a/lib/include/srslte/phy/sync/sync.h +++ b/lib/include/srslte/phy/sync/sync.h @@ -40,49 +40,49 @@ #ifndef SRSLTE_SYNC_H #define SRSLTE_SYNC_H -#include #include +#include #include "srslte/config.h" -#include "srslte/phy/sync/pss.h" -#include "srslte/phy/sync/sss.h" #include "srslte/phy/sync/cfo.h" #include "srslte/phy/sync/cp.h" +#include "srslte/phy/sync/pss.h" +#include "srslte/phy/sync/sss.h" -#define SRSLTE_SYNC_FFT_SZ_MIN 64 -#define SRSLTE_SYNC_FFT_SZ_MAX 2048 +#define SRSLTE_SYNC_FFT_SZ_MIN 64 +#define SRSLTE_SYNC_FFT_SZ_MAX 2048 -typedef enum {SSS_DIFF=0, SSS_PARTIAL_3=2, SSS_FULL=1} sss_alg_t; +typedef enum { SSS_DIFF = 0, SSS_PARTIAL_3 = 2, SSS_FULL = 1 } sss_alg_t; typedef struct SRSLTE_API { - srslte_pss_t pss; - srslte_pss_t pss_i[2]; - srslte_sss_t sss; + srslte_pss_t pss; + srslte_pss_t pss_i[2]; + srslte_sss_t sss; srslte_cp_synch_t cp_synch; - cf_t *cfo_i_corr[2]; - int decimate; - float threshold; - float peak_value; - uint32_t N_id_2; - uint32_t N_id_1; - uint32_t sf_idx; - uint32_t fft_size; - uint32_t frame_size; - uint32_t max_offset; - uint32_t nof_symbols; - uint32_t cp_len; - float current_cfo_tol; - sss_alg_t sss_alg; - bool detect_cp; - bool sss_en; - srslte_cp_t cp; - uint32_t m0; - uint32_t m1; - float m0_value; - float m1_value; - float M_norm_avg; - float M_ext_avg; - cf_t *temp; + cf_t* cfo_i_corr[2]; + int decimate; + float threshold; + float peak_value; + uint32_t N_id_2; + uint32_t N_id_1; + uint32_t sf_idx; + uint32_t fft_size; + uint32_t frame_size; + uint32_t max_offset; + uint32_t nof_symbols; + uint32_t cp_len; + float current_cfo_tol; + sss_alg_t sss_alg; + bool detect_cp; + bool sss_en; + srslte_cp_t cp; + uint32_t m0; + uint32_t m1; + float m0_value; + float m1_value; + float M_norm_avg; + float M_ext_avg; + cf_t* temp; uint32_t max_frame_size; @@ -123,105 +123,80 @@ typedef struct SRSLTE_API { cf_t sss_recv[SRSLTE_SYMBOL_SZ_MAX]; cf_t sss_signal[2][SRSLTE_SYMBOL_SZ_MAX]; -}srslte_sync_t; +} srslte_sync_t; typedef enum { - SRSLTE_SYNC_FOUND = 1, - SRSLTE_SYNC_FOUND_NOSPACE = 2, - SRSLTE_SYNC_NOFOUND = 0, - SRSLTE_SYNC_ERROR = -1 -} srslte_sync_find_ret_t; - + SRSLTE_SYNC_FOUND = 1, + SRSLTE_SYNC_FOUND_NOSPACE = 2, + SRSLTE_SYNC_NOFOUND = 0, + SRSLTE_SYNC_ERROR = -1 +} srslte_sync_find_ret_t; -SRSLTE_API int srslte_sync_init(srslte_sync_t *q, - uint32_t frame_size, - uint32_t max_offset, - uint32_t fft_size); +SRSLTE_API int srslte_sync_init(srslte_sync_t* q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size); -SRSLTE_API int srslte_sync_init_decim(srslte_sync_t *q, - uint32_t frame_size, - uint32_t max_offset, - uint32_t fft_size, - int decimate); +SRSLTE_API int +srslte_sync_init_decim(srslte_sync_t* q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size, int decimate); +SRSLTE_API void srslte_sync_free(srslte_sync_t* q); -SRSLTE_API void srslte_sync_free(srslte_sync_t *q); +SRSLTE_API int srslte_sync_resize(srslte_sync_t* q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size); -SRSLTE_API int srslte_sync_resize(srslte_sync_t *q, - uint32_t frame_size, - uint32_t max_offset, - uint32_t fft_size); - -SRSLTE_API void srslte_sync_reset(srslte_sync_t *q); +SRSLTE_API void srslte_sync_reset(srslte_sync_t* q); /* Finds a correlation peak in the input signal around position find_offset */ -SRSLTE_API srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, - const cf_t *input, - uint32_t find_offset, - uint32_t *peak_position); +SRSLTE_API srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t* q, + const cf_t* input, + uint32_t find_offset, + uint32_t* peak_position); /* Estimates the CP length */ -SRSLTE_API srslte_cp_t srslte_sync_detect_cp(srslte_sync_t *q, - const cf_t *input, - uint32_t peak_pos); +SRSLTE_API srslte_cp_t srslte_sync_detect_cp(srslte_sync_t* q, const cf_t* input, uint32_t peak_pos); /* Sets the threshold for peak comparison */ -SRSLTE_API void srslte_sync_set_threshold(srslte_sync_t *q, - float threshold); +SRSLTE_API void srslte_sync_set_threshold(srslte_sync_t* q, float threshold); /* Gets the subframe idx (0 or 5) */ -SRSLTE_API uint32_t srslte_sync_get_sf_idx(srslte_sync_t *q); +SRSLTE_API uint32_t srslte_sync_get_sf_idx(srslte_sync_t* q); /* Gets the peak value */ -SRSLTE_API float srslte_sync_get_peak_value(srslte_sync_t *q); +SRSLTE_API float srslte_sync_get_peak_value(srslte_sync_t* q); /* Choose SSS detection algorithm */ -SRSLTE_API void srslte_sync_set_sss_algorithm(srslte_sync_t *q, - sss_alg_t alg); +SRSLTE_API void srslte_sync_set_sss_algorithm(srslte_sync_t* q, sss_alg_t alg); /* Sets PSS exponential averaging alpha weight */ -SRSLTE_API void srslte_sync_set_em_alpha(srslte_sync_t *q, - float alpha); +SRSLTE_API void srslte_sync_set_em_alpha(srslte_sync_t* q, float alpha); /* Sets the N_id_2 to search for */ -SRSLTE_API int srslte_sync_set_N_id_2(srslte_sync_t *q, - uint32_t N_id_2); +SRSLTE_API int srslte_sync_set_N_id_2(srslte_sync_t* q, uint32_t N_id_2); SRSLTE_API int srslte_sync_set_N_id_1(srslte_sync_t* q, uint32_t N_id_1); /* Gets the Physical CellId from the last call to synch_run() */ -SRSLTE_API int srslte_sync_get_cell_id(srslte_sync_t *q); +SRSLTE_API int srslte_sync_get_cell_id(srslte_sync_t* q); /* Enables/disables filtering of the central PRBs before PSS CFO estimation or SSS correlation*/ -SRSLTE_API void srslte_sync_set_pss_filt_enable(srslte_sync_t *q, - bool enable); +SRSLTE_API void srslte_sync_set_pss_filt_enable(srslte_sync_t* q, bool enable); -SRSLTE_API void srslte_sync_set_sss_eq_enable(srslte_sync_t *q, - bool enable); +SRSLTE_API void srslte_sync_set_sss_eq_enable(srslte_sync_t* q, bool enable); /* Gets the CFO estimation from the last call to synch_run() */ -SRSLTE_API float srslte_sync_get_cfo(srslte_sync_t *q); +SRSLTE_API float srslte_sync_get_cfo(srslte_sync_t* q); /* Resets internal CFO state */ -SRSLTE_API void srslte_sync_cfo_reset(srslte_sync_t *q); +SRSLTE_API void srslte_sync_cfo_reset(srslte_sync_t* q); /* Copies CFO internal state from another object to avoid long transients */ -SRSLTE_API void srslte_sync_copy_cfo(srslte_sync_t *q, - srslte_sync_t *src_obj); +SRSLTE_API void srslte_sync_copy_cfo(srslte_sync_t* q, srslte_sync_t* src_obj); /* Enable different CFO estimation stages */ -SRSLTE_API void srslte_sync_set_cfo_i_enable(srslte_sync_t *q, - bool enable); -SRSLTE_API void srslte_sync_set_cfo_cp_enable(srslte_sync_t *q, - bool enable, - uint32_t nof_symbols); +SRSLTE_API void srslte_sync_set_cfo_i_enable(srslte_sync_t* q, bool enable); +SRSLTE_API void srslte_sync_set_cfo_cp_enable(srslte_sync_t* q, bool enable, uint32_t nof_symbols); -SRSLTE_API void srslte_sync_set_cfo_pss_enable(srslte_sync_t *q, - bool enable); +SRSLTE_API void srslte_sync_set_cfo_pss_enable(srslte_sync_t* q, bool enable); /* Sets CFO correctors tolerance (in Hz) */ -SRSLTE_API void srslte_sync_set_cfo_tol(srslte_sync_t *q, - float tol); +SRSLTE_API void srslte_sync_set_cfo_tol(srslte_sync_t* q, float tol); SRSLTE_API void srslte_sync_set_frame_type(srslte_sync_t* q, srslte_frame_type_t frame_type); @@ -229,19 +204,17 @@ SRSLTE_API void srslte_sync_set_frame_type(srslte_sync_t* q, srslte_frame_type_t SRSLTE_API void srslte_sync_set_cfo_ema_alpha(srslte_sync_t* q, float alpha); /* Gets the CP length estimation from the last call to synch_run() */ -SRSLTE_API srslte_cp_t srslte_sync_get_cp(srslte_sync_t *q); +SRSLTE_API srslte_cp_t srslte_sync_get_cp(srslte_sync_t* q); /* Sets the CP length estimation (must do it if disabled) */ -SRSLTE_API void srslte_sync_set_cp(srslte_sync_t *q, - srslte_cp_t cp); +SRSLTE_API void srslte_sync_set_cp(srslte_sync_t* q, srslte_cp_t cp); /* Enables/Disables SSS detection */ -SRSLTE_API void srslte_sync_sss_en(srslte_sync_t *q, - bool enabled); +SRSLTE_API void srslte_sync_sss_en(srslte_sync_t* q, bool enabled); -SRSLTE_API srslte_pss_t* srslte_sync_get_cur_pss_obj(srslte_sync_t *q); +SRSLTE_API srslte_pss_t* srslte_sync_get_cur_pss_obj(srslte_sync_t* q); -SRSLTE_API bool srslte_sync_sss_detected(srslte_sync_t *q); +SRSLTE_API bool srslte_sync_sss_detected(srslte_sync_t* q); SRSLTE_API float srslte_sync_sss_correlation_peak(srslte_sync_t* q); @@ -251,4 +224,3 @@ SRSLTE_API bool srslte_sync_sss_available(srslte_sync_t* q); SRSLTE_API void srslte_sync_cp_en(srslte_sync_t* q, bool enabled); #endif // SRSLTE_SYNC_H - diff --git a/lib/include/srslte/phy/ue/ue_dl.h b/lib/include/srslte/phy/ue/ue_dl.h index ed43ab149..39a71d75a 100644 --- a/lib/include/srslte/phy/ue/ue_dl.h +++ b/lib/include/srslte/phy/ue/ue_dl.h @@ -36,28 +36,27 @@ #include #include "srslte/phy/ch_estimation/chest_dl.h" -#include "srslte/phy/dft/ofdm.h" #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/dft/ofdm.h" #include "srslte/phy/phch/dci.h" #include "srslte/phy/phch/pcfich.h" #include "srslte/phy/phch/pdcch.h" #include "srslte/phy/phch/pdsch.h" -#include "srslte/phy/phch/pmch.h" #include "srslte/phy/phch/pdsch_cfg.h" #include "srslte/phy/phch/phich.h" +#include "srslte/phy/phch/pmch.h" #include "srslte/phy/phch/ra.h" #include "srslte/phy/phch/regs.h" #include "srslte/phy/sync/cfo.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" #include "srslte/config.h" - -#define MAX_CANDIDATES_UE 16 // From 36.213 Table 9.1.1-1 +#define MAX_CANDIDATES_UE 16 // From 36.213 Table 9.1.1-1 #define MAX_CANDIDATES_COM 6 // From 36.213 Table 9.1.1-1 #define MAX_CANDIDATES (MAX_CANDIDATES_UE + MAX_CANDIDATES_COM) @@ -67,9 +66,9 @@ #define SRSLTE_MAX_DCI_MSG SRSLTE_MAX_CARRIERS typedef struct SRSLTE_API { - srslte_dci_format_t format; + srslte_dci_format_t format; srslte_dci_location_t loc[MAX_CANDIDATES]; - uint32_t nof_locations; + uint32_t nof_locations; } dci_blind_search_t; typedef struct SRSLTE_API { @@ -165,8 +164,7 @@ SRSLTE_API void srslte_ue_dl_set_rnti(srslte_ue_dl_t* q, uint16_t rnti); SRSLTE_API int srslte_ue_dl_set_mbsfn_area_id(srslte_ue_dl_t* q, uint16_t mbsfn_area_id); -SRSLTE_API void srslte_ue_dl_set_non_mbsfn_region(srslte_ue_dl_t *q, - uint8_t non_mbsfn_region_length); +SRSLTE_API void srslte_ue_dl_set_non_mbsfn_region(srslte_ue_dl_t* q, uint8_t non_mbsfn_region_length); SRSLTE_API void srslte_ue_dl_set_mi_manual(srslte_ue_dl_t* q, uint32_t mi_idx); @@ -218,8 +216,11 @@ SRSLTE_API int srslte_ue_dl_decode_phich(srslte_ue_dl_t* q, SRSLTE_API int srslte_ue_dl_select_ri(srslte_ue_dl_t* q, uint32_t* ri, float* cn); -SRSLTE_API void srslte_ue_dl_gen_cqi_periodic( - srslte_ue_dl_t* q, srslte_ue_dl_cfg_t* cfg, uint32_t wideband_value, uint32_t tti, srslte_uci_data_t* uci_data); +SRSLTE_API void srslte_ue_dl_gen_cqi_periodic(srslte_ue_dl_t* q, + srslte_ue_dl_cfg_t* cfg, + uint32_t wideband_value, + uint32_t tti, + srslte_uci_data_t* uci_data); SRSLTE_API void srslte_ue_dl_gen_cqi_aperiodic(srslte_ue_dl_t* q, srslte_ue_dl_cfg_t* cfg, diff --git a/lib/include/srslte/phy/ue/ue_phy.h b/lib/include/srslte/phy/ue/ue_phy.h index e6bf0dbb5..b997487f6 100644 --- a/lib/include/srslte/phy/ue/ue_phy.h +++ b/lib/include/srslte/phy/ue/ue_phy.h @@ -27,25 +27,24 @@ * Reference: *****************************************************************************/ -#include "srslte/srslte.h" #include "srslte/phy/utils/queue.h" +#include "srslte/srslte.h" #ifndef SRSLTE_UE_PHY_H #define SRSLTE_UE_PHY_H -#define SYNC_MODE_CV 0 +#define SYNC_MODE_CV 0 #define SYNC_MODE_CALLBACK 1 -#define SYNC_MODE SYNC_MODE_CV +#define SYNC_MODE SYNC_MODE_CV namespace srslte { -typedef _Complex float cf_t; +typedef _Complex float cf_t; class ue_phy { public: - - typedef enum {DOWNLINK, UPLINK} direction_t; + typedef enum { DOWNLINK, UPLINK } direction_t; typedef enum { PDCCH_UL_SEARCH_CRNTI = 0, @@ -66,98 +65,99 @@ public: } pdcch_dl_search_t; /* Uplink/Downlink scheduling dci generated by a successfully decoded PDCCH */ - class sched_grant { + class sched_grant + { public: uint16_t get_rnti(); uint32_t get_rv(); void set_rv(uint32_t rv); bool get_ndi(); bool get_cqi_request(); - uint32_t get_harq_process(); - private: + uint32_t get_harq_process(); + + private: union { srslte_ra_ul_grant_t ul_grant; srslte_ra_dl_grant_t dl_grant; - }; - direction_t dir; + }; + direction_t dir; }; - - /* Uplink scheduling assignment. The MAC instructs the PHY to prepare an UL packet (PUSCH or PUCCH) + /* Uplink scheduling assignment. The MAC instructs the PHY to prepare an UL packet (PUSCH or PUCCH) * for transmission. The MAC must call generate_pusch() to set the packet ready for transmission */ - class ul_buffer : public queue::element { - public: - ul_buffer(srslte_cell_t cell); - void generate_pusch(sched_grant pusch_grant, uint8_t *payload, srslte_uci_data_t uci_data); - void generate_pucch(srslte_uci_data_t uci_data); - private: - srslte_ue_ul_t ue_ul; - bool signal_generated = false; + class ul_buffer : public queue::element + { + public: + ul_buffer(srslte_cell_t cell); + void generate_pusch(sched_grant pusch_grant, uint8_t* payload, srslte_uci_data_t uci_data); + void generate_pucch(srslte_uci_data_t uci_data); + + private: + srslte_ue_ul_t ue_ul; + bool signal_generated = false; cf_t* signal_buffer = NULL; - uint32_t tti = 0; + uint32_t tti = 0; }; - /* Class for the processing of Downlink buffers. The MAC obtains a buffer for a given TTI and then - * gets ul/dl scheduling grants and/or processes phich/pdsch channels + /* Class for the processing of Downlink buffers. The MAC obtains a buffer for a given TTI and then + * gets ul/dl scheduling grants and/or processes phich/pdsch channels */ - class dl_buffer : public queue::element { + class dl_buffer : public queue::element + { public: - dl_buffer(srslte_cell_t cell); - sched_grant get_ul_grant(pdcch_ul_search_t mode, uint32_t rnti); - sched_grant get_dl_grant(pdcch_dl_search_t mode, uint32_t rnti); - bool decode_phich(sched_grant pusch_grant); - bool decode_pdsch(sched_grant pdsch_grant, uint8_t *payload); // returns true or false for CRC OK/KO - private: - srslte_ue_dl_t ue_dl; - srslte_phich_t phich; - cf_t *signal_buffer = NULL; - bool sf_symbols_and_ce_done = false; - bool pdcch_llr_extracted = false; - uint32_t tti = 0; + dl_buffer(srslte_cell_t cell); + sched_grant get_ul_grant(pdcch_ul_search_t mode, uint32_t rnti); + sched_grant get_dl_grant(pdcch_dl_search_t mode, uint32_t rnti); + bool decode_phich(sched_grant pusch_grant); + bool decode_pdsch(sched_grant pdsch_grant, uint8_t* payload); // returns true or false for CRC OK/KO + private: + srslte_ue_dl_t ue_dl; + srslte_phich_t phich; + cf_t* signal_buffer = NULL; + bool sf_symbols_and_ce_done = false; + bool pdcch_llr_extracted = false; + uint32_t tti = 0; }; - - -#if SYNC_MODE==SYNC_MODE_CALLBACK - typedef (*ue_phy_tti_clock_fcn_t) (void); + +#if SYNC_MODE == SYNC_MODE_CALLBACK + typedef (*ue_phy_tti_clock_fcn_t)(void); ue_phy(ue_phy_tti_clock_fcn_t tti_clock_callback); #else ue_phy(); #endif ~ue_phy(); - - void measure(); // TBD - void dl_bch(); + + void measure(); // TBD + void dl_bch(); void start_rxtx(); void stop_rxtx(); void init_prach(); - void send_prach(/* prach_cfg_t in prach.h with power, seq idx, etc */); - void set_param(); + void send_prach(/* prach_cfg_t in prach.h with power, seq idx, etc */); + void set_param(); - uint32_t get_tti(); -#if SYNC_MODE==SYNC_MODE_CV - std::condition_variable tti_cv; - std::mutex tti_mutex; + uint32_t get_tti(); +#if SYNC_MODE == SYNC_MODE_CV + std::condition_variable tti_cv; + std::mutex tti_mutex; #endif - + ul_buffer get_ul_buffer(uint32_t tti); dl_buffer get_dl_buffer(uint32_t tti); - + private: - enum { - IDLE, MEASURE, RX_BCH, RXTX - } phy_state; + enum { IDLE, MEASURE, RX_BCH, RXTX } phy_state; - bool prach_initiated = false; - bool prach_ready_to_send = false; - srslte_prach_t prach; + bool prach_initiated = false; + bool prach_ready_to_send = false; + srslte_prach_t prach; queue ul_buffer_queue; - queue dl_buffer_queue; - - pthread_t radio_thread; - void *radio_handler; + queue dl_buffer_queue; + + pthread_t radio_thread; + void* radio_handler; }; -} +} // namespace srslte #endif // SRSLTE_UE_PHY_H diff --git a/lib/include/srslte/phy/ue/ue_ul.h b/lib/include/srslte/phy/ue/ue_ul.h index aca92c3b9..875ec74f0 100644 --- a/lib/include/srslte/phy/ue/ue_ul.h +++ b/lib/include/srslte/phy/ue/ue_ul.h @@ -33,16 +33,16 @@ #ifndef SRSLTE_UE_UL_H #define SRSLTE_UE_UL_H -#include "srslte/phy/common/phy_common.h" #include "srslte/phy/ch_estimation/chest_dl.h" -#include "srslte/phy/dft/ofdm.h" #include "srslte/phy/ch_estimation/refsignal_ul.h" -#include "srslte/phy/phch/pusch.h" +#include "srslte/phy/common/phy_common.h" +#include "srslte/phy/dft/ofdm.h" #include "srslte/phy/phch/dci.h" +#include "srslte/phy/phch/pusch.h" #include "srslte/phy/phch/ra.h" #include "srslte/phy/sync/cfo.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" #include "srslte/config.h" @@ -54,13 +54,13 @@ typedef struct { float p0_nominal_pucch; float delta_f_pucch[5]; float delta_preamble_msg3; - + // Dedicated configuration float p0_ue_pusch; bool delta_mcs_based; bool acc_enabled; float p0_ue_pucch; - float p_srs_offset; + float p_srs_offset; } srslte_ue_ul_powerctrl_t; typedef struct SRSLTE_API { @@ -85,10 +85,10 @@ typedef struct SRSLTE_API { uint32_t cc_idx; srslte_ue_ul_normalize_mode_t normalize_mode; - float force_peak_amplitude; - bool cfo_en; - float cfo_tol; - float cfo_value; + float force_peak_amplitude; + bool cfo_en; + float cfo_tol; + float cfo_value; } srslte_ue_ul_cfg_t; @@ -151,7 +151,10 @@ SRSLTE_API void srslte_ue_ul_pucch_resource_selection(srslte_cell_t* cell, srslte_uci_cfg_t* uci_cfg, srslte_uci_value_t* uci_data); -SRSLTE_API bool srslte_ue_ul_info( - srslte_ue_ul_cfg_t* cfg, srslte_ul_sf_cfg_t* sf, srslte_uci_value_t* uci_data, char* str, uint32_t str_len); +SRSLTE_API bool srslte_ue_ul_info(srslte_ue_ul_cfg_t* cfg, + srslte_ul_sf_cfg_t* sf, + srslte_uci_value_t* uci_data, + char* str, + uint32_t str_len); #endif // SRSLTE_UE_UL_H diff --git a/lib/include/srslte/phy/utils/bit.h b/lib/include/srslte/phy/utils/bit.h index f1d9f7879..e8b3ec292 100644 --- a/lib/include/srslte/phy/utils/bit.h +++ b/lib/include/srslte/phy/utils/bit.h @@ -36,83 +36,55 @@ #include "srslte/config.h" typedef struct { - uint32_t nof_bits; - uint16_t *interleaver; - uint16_t *byte_idx; - uint8_t *bit_mask; - uint8_t n_128; + uint32_t nof_bits; + uint16_t* interleaver; + uint16_t* byte_idx; + uint8_t* bit_mask; + uint8_t n_128; } srslte_bit_interleaver_t; -SRSLTE_API void srslte_bit_interleaver_init(srslte_bit_interleaver_t *q, - uint16_t *interleaver, - uint32_t nof_bits); - -SRSLTE_API void srslte_bit_interleaver_free(srslte_bit_interleaver_t *q); - -SRSLTE_API void srslte_bit_interleaver_run(srslte_bit_interleaver_t *q, - uint8_t *input, - uint8_t *output, - uint16_t w_offset); - -SRSLTE_API void srslte_bit_interleave(uint8_t *input, - uint8_t *output, - uint16_t *interleaver, - uint32_t nof_bits); - -SRSLTE_API void srslte_bit_copy(uint8_t *dst, - uint32_t dst_offset, - uint8_t *src, - uint32_t src_offset, - uint32_t nof_bits); - -SRSLTE_API void srslte_bit_interleave_i(uint8_t *input, - uint8_t *output, - uint32_t *interleaver, - uint32_t nof_bits); - -SRSLTE_API void srslte_bit_interleave_i_w_offset(uint8_t *input, - uint8_t *output, - uint32_t *interleaver, - uint32_t nof_bits, - uint32_t w_offset); - -SRSLTE_API void srslte_bit_interleave_w_offset(uint8_t *input, - uint8_t *output, - uint16_t *interleaver, - uint32_t nof_bits, - uint32_t w_offset); - -SRSLTE_API void srslte_bit_unpack_vector(uint8_t *packed, - uint8_t *unpacked, - int nof_bits); - -SRSLTE_API void srslte_bit_pack_vector(uint8_t *unpacked, - uint8_t *packed, - int nof_bits); - -SRSLTE_API uint32_t srslte_bit_pack(uint8_t **bits, - int nof_bits); - -SRSLTE_API uint64_t srslte_bit_pack_l(uint8_t **bits, - int nof_bits); - -SRSLTE_API void srslte_bit_unpack_l(uint64_t value, - uint8_t **bits, - int nof_bits); - -SRSLTE_API void srslte_bit_unpack(uint32_t value, - uint8_t **bits, - int nof_bits); - -SRSLTE_API void srslte_bit_fprint(FILE *stream, - uint8_t *bits, - int nof_bits); - -SRSLTE_API uint32_t srslte_bit_diff(uint8_t *x, - uint8_t *y, - int nbits); +SRSLTE_API void srslte_bit_interleaver_init(srslte_bit_interleaver_t* q, uint16_t* interleaver, uint32_t nof_bits); + +SRSLTE_API void srslte_bit_interleaver_free(srslte_bit_interleaver_t* q); + +SRSLTE_API void +srslte_bit_interleaver_run(srslte_bit_interleaver_t* q, uint8_t* input, uint8_t* output, uint16_t w_offset); + +SRSLTE_API void srslte_bit_interleave(uint8_t* input, uint8_t* output, uint16_t* interleaver, uint32_t nof_bits); + +SRSLTE_API void +srslte_bit_copy(uint8_t* dst, uint32_t dst_offset, uint8_t* src, uint32_t src_offset, uint32_t nof_bits); + +SRSLTE_API void srslte_bit_interleave_i(uint8_t* input, uint8_t* output, uint32_t* interleaver, uint32_t nof_bits); + +SRSLTE_API void srslte_bit_interleave_i_w_offset(uint8_t* input, + uint8_t* output, + uint32_t* interleaver, + uint32_t nof_bits, + uint32_t w_offset); + +SRSLTE_API void srslte_bit_interleave_w_offset(uint8_t* input, + uint8_t* output, + uint16_t* interleaver, + uint32_t nof_bits, + uint32_t w_offset); + +SRSLTE_API void srslte_bit_unpack_vector(uint8_t* packed, uint8_t* unpacked, int nof_bits); + +SRSLTE_API void srslte_bit_pack_vector(uint8_t* unpacked, uint8_t* packed, int nof_bits); + +SRSLTE_API uint32_t srslte_bit_pack(uint8_t** bits, int nof_bits); + +SRSLTE_API uint64_t srslte_bit_pack_l(uint8_t** bits, int nof_bits); + +SRSLTE_API void srslte_bit_unpack_l(uint64_t value, uint8_t** bits, int nof_bits); + +SRSLTE_API void srslte_bit_unpack(uint32_t value, uint8_t** bits, int nof_bits); + +SRSLTE_API void srslte_bit_fprint(FILE* stream, uint8_t* bits, int nof_bits); + +SRSLTE_API uint32_t srslte_bit_diff(uint8_t* x, uint8_t* y, int nbits); SRSLTE_API uint32_t srslte_bit_count(uint32_t n); #endif // SRSLTE_BIT_H - diff --git a/lib/include/srslte/phy/utils/cexptab.h b/lib/include/srslte/phy/utils/cexptab.h index 64bbda05a..5a4404f4b 100644 --- a/lib/include/srslte/phy/utils/cexptab.h +++ b/lib/include/srslte/phy/utils/cexptab.h @@ -30,28 +30,22 @@ #ifndef SRSLTE_CEXPTAB_H #define SRSLTE_CEXPTAB_H +#include "srslte/config.h" #include #include -#include "srslte/config.h" typedef struct SRSLTE_API { uint32_t size; - cf_t *tab; -}srslte_cexptab_t; + cf_t* tab; +} srslte_cexptab_t; -SRSLTE_API int srslte_cexptab_init(srslte_cexptab_t *nco, - uint32_t size); +SRSLTE_API int srslte_cexptab_init(srslte_cexptab_t* nco, uint32_t size); -SRSLTE_API void srslte_cexptab_free(srslte_cexptab_t *nco); +SRSLTE_API void srslte_cexptab_free(srslte_cexptab_t* nco); -SRSLTE_API void srslte_cexptab_gen(srslte_cexptab_t *nco, - cf_t *x, - float freq, - uint32_t len); +SRSLTE_API void srslte_cexptab_gen(srslte_cexptab_t* nco, cf_t* x, float freq, uint32_t len); -SRSLTE_API void srslte_cexptab_gen_direct(cf_t *x, - float freq, - uint32_t len); +SRSLTE_API void srslte_cexptab_gen_direct(cf_t* x, float freq, uint32_t len); SRSLTE_API void srslte_cexptab_gen_sf(cf_t* x, float freq, uint32_t fft_size); diff --git a/lib/include/srslte/phy/utils/convolution.h b/lib/include/srslte/phy/utils/convolution.h index 041b7b8e5..0897cfb00 100644 --- a/lib/include/srslte/phy/utils/convolution.h +++ b/lib/include/srslte/phy/utils/convolution.h @@ -34,32 +34,28 @@ #include "srslte/phy/dft/dft.h" typedef struct SRSLTE_API { - cf_t *input_fft; - cf_t *filter_fft; - cf_t *output_fft; - cf_t *output_fft2; - uint32_t input_len; - uint32_t filter_len; - uint32_t output_len; - uint32_t max_input_len; - uint32_t max_filter_len; + cf_t* input_fft; + cf_t* filter_fft; + cf_t* output_fft; + cf_t* output_fft2; + uint32_t input_len; + uint32_t filter_len; + uint32_t output_len; + uint32_t max_input_len; + uint32_t max_filter_len; srslte_dft_plan_t input_plan; srslte_dft_plan_t filter_plan; srslte_dft_plan_t output_plan; - //cf_t *pss_signal_time_fft[3]; // One sequence for each N_id_2 - //cf_t *pss_signal_time[3]; - -}srslte_conv_fft_cc_t; + // cf_t *pss_signal_time_fft[3]; // One sequence for each N_id_2 + // cf_t *pss_signal_time[3]; -SRSLTE_API int srslte_conv_fft_cc_init(srslte_conv_fft_cc_t *q, - uint32_t input_len, - uint32_t filter_len); +} srslte_conv_fft_cc_t; -SRSLTE_API int srslte_conv_fft_cc_replan(srslte_conv_fft_cc_t *q, - uint32_t input_len, - uint32_t filter_len); +SRSLTE_API int srslte_conv_fft_cc_init(srslte_conv_fft_cc_t* q, uint32_t input_len, uint32_t filter_len); -SRSLTE_API void srslte_conv_fft_cc_free(srslte_conv_fft_cc_t *q); +SRSLTE_API int srslte_conv_fft_cc_replan(srslte_conv_fft_cc_t* q, uint32_t input_len, uint32_t filter_len); + +SRSLTE_API void srslte_conv_fft_cc_free(srslte_conv_fft_cc_t* q); SRSLTE_API uint32_t srslte_corr_fft_cc_run(srslte_conv_fft_cc_t* q, cf_t* input, cf_t* filter, cf_t* output); @@ -70,27 +66,18 @@ SRSLTE_API uint32_t srslte_conv_fft_cc_run(srslte_conv_fft_cc_t* q, const cf_t* filter, cf_t* output); -SRSLTE_API uint32_t srslte_conv_fft_cc_run_opt(srslte_conv_fft_cc_t *q, - const cf_t *input, - const cf_t *filter_freq, - cf_t *output); - -SRSLTE_API uint32_t srslte_conv_cc(const cf_t *input, - const cf_t *filter, - cf_t *output, - uint32_t input_len, - uint32_t filter_len); - -SRSLTE_API uint32_t srslte_conv_same_cf(cf_t *input, - float *filter, - cf_t *output, - uint32_t input_len, - uint32_t filter_len); - -SRSLTE_API uint32_t srslte_conv_same_cc(cf_t *input, - cf_t *filter, - cf_t *output, - uint32_t input_len, - uint32_t filter_len); +SRSLTE_API uint32_t srslte_conv_fft_cc_run_opt(srslte_conv_fft_cc_t* q, + const cf_t* input, + const cf_t* filter_freq, + cf_t* output); + +SRSLTE_API uint32_t + srslte_conv_cc(const cf_t* input, const cf_t* filter, cf_t* output, uint32_t input_len, uint32_t filter_len); + +SRSLTE_API uint32_t + srslte_conv_same_cf(cf_t* input, float* filter, cf_t* output, uint32_t input_len, uint32_t filter_len); + +SRSLTE_API uint32_t + srslte_conv_same_cc(cf_t* input, cf_t* filter, cf_t* output, uint32_t input_len, uint32_t filter_len); #endif // SRSLTE_CONVOLUTION_H diff --git a/lib/include/srslte/phy/utils/debug.h b/lib/include/srslte/phy/utils/debug.h index 3075578c8..6f25e4ee2 100644 --- a/lib/include/srslte/phy/utils/debug.h +++ b/lib/include/srslte/phy/utils/debug.h @@ -35,24 +35,24 @@ #include #define SRSLTE_VERBOSE_DEBUG 2 -#define SRSLTE_VERBOSE_INFO 1 -#define SRSLTE_VERBOSE_NONE 0 +#define SRSLTE_VERBOSE_INFO 1 +#define SRSLTE_VERBOSE_NONE 0 #include -SRSLTE_API void get_time_interval(struct timeval * tdata); +SRSLTE_API void get_time_interval(struct timeval* tdata); #define SRSLTE_DEBUG_ENABLED 1 SRSLTE_API extern int srslte_verbose; SRSLTE_API extern int handler_registered; -#define SRSLTE_VERBOSE_ISINFO() (srslte_verbose>=SRSLTE_VERBOSE_INFO) -#define SRSLTE_VERBOSE_ISDEBUG() (srslte_verbose>=SRSLTE_VERBOSE_DEBUG) -#define SRSLTE_VERBOSE_ISNONE() (srslte_verbose==SRSLTE_VERBOSE_NONE) +#define SRSLTE_VERBOSE_ISINFO() (srslte_verbose >= SRSLTE_VERBOSE_INFO) +#define SRSLTE_VERBOSE_ISDEBUG() (srslte_verbose >= SRSLTE_VERBOSE_DEBUG) +#define SRSLTE_VERBOSE_ISNONE() (srslte_verbose == SRSLTE_VERBOSE_NONE) -#define PRINT_DEBUG srslte_verbose=SRSLTE_VERBOSE_DEBUG -#define PRINT_INFO srslte_verbose=SRSLTE_VERBOSE_INFO -#define PRINT_NONE srslte_verbose=SRSLTE_VERBOSE_NONE +#define PRINT_DEBUG srslte_verbose = SRSLTE_VERBOSE_DEBUG +#define PRINT_INFO srslte_verbose = SRSLTE_VERBOSE_INFO +#define PRINT_NONE srslte_verbose = SRSLTE_VERBOSE_NONE #define DEBUG(_fmt, ...) \ do { \ @@ -72,7 +72,7 @@ SRSLTE_API extern int handler_registered; } \ } while (0) -#if CMAKE_BUILD_TYPE==Debug +#if CMAKE_BUILD_TYPE == Debug /* In debug mode, it prints out the */ #define ERROR(_fmt, ...) \ do { \ @@ -83,9 +83,12 @@ SRSLTE_API extern int handler_registered; } \ } while (0) #else -#define ERROR(_fmt, ...) if (!handler_registered)\ - { fprintf(stderr, "[ERROR in %s]:" _fmt "\n", __FUNCTION__, ##__VA_ARGS__);}\ - else{srslte_phy_log_print(LOG_LEVEL_ERROR, _fmt, ##__VA_ARGS__);} // +#define ERROR(_fmt, ...) \ + if (!handler_registered) { \ + fprintf(stderr, "[ERROR in %s]:" _fmt "\n", __FUNCTION__, ##__VA_ARGS__); \ + } else { \ + srslte_phy_log_print(LOG_LEVEL_ERROR, _fmt, ##__VA_ARGS__); \ + } // #endif /* CMAKE_BUILD_TYPE==Debug */ #endif // SRSLTE_DEBUG_H diff --git a/lib/include/srslte/phy/utils/filter.h b/lib/include/srslte/phy/utils/filter.h index 3e2eaed45..a213b4c65 100644 --- a/lib/include/srslte/phy/utils/filter.h +++ b/lib/include/srslte/phy/utils/filter.h @@ -30,27 +30,27 @@ #ifndef SRSLTE_FILTER_H #define SRSLTE_FILTER_H -#include -#include #include "srslte/config.h" -#include #include "srslte/phy/utils/vector.h" -typedef struct SRSLTE_API{ - cf_t *filter_input; - cf_t *downsampled_input; - cf_t *filter_output; - bool is_decimator; - int factor; - int num_taps; - float *taps; - -}srslte_filt_cc_t; +#include +#include +#include +typedef struct SRSLTE_API { + cf_t* filter_input; + cf_t* downsampled_input; + cf_t* filter_output; + bool is_decimator; + int factor; + int num_taps; + float* taps; + +} srslte_filt_cc_t; -void srslte_filt_decim_cc_init(srslte_filt_cc_t *q, int factor, int order); +void srslte_filt_decim_cc_init(srslte_filt_cc_t* q, int factor, int order); -void srslte_filt_decim_cc_free(srslte_filt_cc_t *q); +void srslte_filt_decim_cc_free(srslte_filt_cc_t* q); -void srslte_filt_decim_cc_execute(srslte_filt_cc_t *q, cf_t *input, cf_t *downsampled_input, cf_t *output, int size); +void srslte_filt_decim_cc_execute(srslte_filt_cc_t* q, cf_t* input, cf_t* downsampled_input, cf_t* output, int size); -void srslte_downsample_cc(cf_t *input, cf_t *output, int M, int size) ; +void srslte_downsample_cc(cf_t* input, cf_t* output, int M, int size); #endif // SRSLTE_FILTER_H \ No newline at end of file diff --git a/lib/include/srslte/phy/utils/mat.h b/lib/include/srslte/phy/utils/mat.h index fad5a1fce..4c1002aa6 100644 --- a/lib/include/srslte/phy/utils/mat.h +++ b/lib/include/srslte/phy/utils/mat.h @@ -32,32 +32,39 @@ SRSLTE_API cf_t srslte_mat_cf_recip_gen(cf_t a); SRSLTE_API cf_t srslte_mat_2x2_det_gen(cf_t a00, cf_t a01, cf_t a10, cf_t a11); /* Generic implementation for 2x2 Matrix Inversion */ -SRSLTE_API void srslte_mat_2x2_inv_gen(cf_t a00, cf_t a01, cf_t a10, cf_t a11, - cf_t *r00, cf_t *r01, cf_t *r10, cf_t *r11); +SRSLTE_API void +srslte_mat_2x2_inv_gen(cf_t a00, cf_t a01, cf_t a10, cf_t a11, cf_t* r00, cf_t* r01, cf_t* r10, cf_t* r11); /* Generic implementation for Zero Forcing (ZF) solver */ -SRSLTE_API void srslte_mat_2x2_zf_gen(cf_t y0, cf_t y1, - cf_t h00, cf_t h01, cf_t h10, cf_t h11, - cf_t *x0, cf_t *x1, - float norm); +SRSLTE_API void +srslte_mat_2x2_zf_gen(cf_t y0, cf_t y1, cf_t h00, cf_t h01, cf_t h10, cf_t h11, cf_t* x0, cf_t* x1, float norm); /* Generic implementation for Minimum Mean Squared Error (MMSE) solver */ -SRSLTE_API void srslte_mat_2x2_mmse_gen(cf_t y0, cf_t y1, - cf_t h00, cf_t h01, cf_t h10, cf_t h11, - cf_t *x0, cf_t *x1, +SRSLTE_API void srslte_mat_2x2_mmse_gen(cf_t y0, + cf_t y1, + cf_t h00, + cf_t h01, + cf_t h10, + cf_t h11, + cf_t* x0, + cf_t* x1, float noise_estimate, float norm); -SRSLTE_API void srslte_mat_2x2_mmse_csi_gen(cf_t y0, cf_t y1, - cf_t h00, cf_t h01, cf_t h10, cf_t h11, - cf_t *x0, cf_t *x1, float *csi0, float *csi1, - float noise_estimate, - float norm); - -SRSLTE_API float srslte_mat_2x2_cn(cf_t h00, - cf_t h01, - cf_t h10, - cf_t h11); +SRSLTE_API void srslte_mat_2x2_mmse_csi_gen(cf_t y0, + cf_t y1, + cf_t h00, + cf_t h01, + cf_t h10, + cf_t h11, + cf_t* x0, + cf_t* x1, + float* csi0, + float* csi1, + float noise_estimate, + float norm); + +SRSLTE_API float srslte_mat_2x2_cn(cf_t h00, cf_t h01, cf_t h10, cf_t h11); #ifdef LV_HAVE_SSE @@ -68,16 +75,27 @@ SRSLTE_API __m128 srslte_mat_cf_recip_sse(__m128 a); SRSLTE_API __m128 srslte_mat_2x2_det_sse(__m128 a00, __m128 a01, __m128 a10, __m128 a11); /* SSE implementation for Zero Forcing (ZF) solver */ -SRSLTE_API void srslte_mat_2x2_zf_sse(__m128 y0, __m128 y1, - __m128 h00, __m128 h01, __m128 h10, __m128 h11, - __m128 *x0, __m128 *x1, - float norm); +SRSLTE_API void srslte_mat_2x2_zf_sse(__m128 y0, + __m128 y1, + __m128 h00, + __m128 h01, + __m128 h10, + __m128 h11, + __m128* x0, + __m128* x1, + float norm); /* SSE implementation for Minimum Mean Squared Error (MMSE) solver */ -SRSLTE_API void srslte_mat_2x2_mmse_sse(__m128 y0, __m128 y1, - __m128 h00, __m128 h01, __m128 h10, __m128 h11, - __m128 *x0, __m128 *x1, - float noise_estimate, float norm); +SRSLTE_API void srslte_mat_2x2_mmse_sse(__m128 y0, + __m128 y1, + __m128 h00, + __m128 h01, + __m128 h10, + __m128 h11, + __m128* x0, + __m128* x1, + float noise_estimate, + float norm); #endif /* LV_HAVE_SSE */ @@ -90,39 +108,52 @@ SRSLTE_API __m256 srslte_mat_cf_recip_avx(__m256 a); SRSLTE_API __m256 srslte_mat_2x2_det_avx(__m256 a00, __m256 a01, __m256 a10, __m256 a11); /* AVX implementation for Zero Forcing (ZF) solver */ -SRSLTE_API void srslte_mat_2x2_zf_avx(__m256 y0, __m256 y1, - __m256 h00, __m256 h01, __m256 h10, __m256 h11, - __m256 *x0, __m256 *x1, - float norm); +SRSLTE_API void srslte_mat_2x2_zf_avx(__m256 y0, + __m256 y1, + __m256 h00, + __m256 h01, + __m256 h10, + __m256 h11, + __m256* x0, + __m256* x1, + float norm); /* AVX implementation for Minimum Mean Squared Error (MMSE) solver */ -SRSLTE_API void srslte_mat_2x2_mmse_avx(__m256 y0, __m256 y1, - __m256 h00, __m256 h01, __m256 h10, __m256 h11, - __m256 *x0, __m256 *x1, - float noise_estimate, float norm); +SRSLTE_API void srslte_mat_2x2_mmse_avx(__m256 y0, + __m256 y1, + __m256 h00, + __m256 h01, + __m256 h10, + __m256 h11, + __m256* x0, + __m256* x1, + float noise_estimate, + float norm); #endif /* LV_HAVE_AVX */ #if SRSLTE_SIMD_CF_SIZE != 0 /* Generic SIMD implementation for 2x2 determinant */ -static inline simd_cf_t srslte_mat_2x2_det_simd(simd_cf_t a00, simd_cf_t a01, simd_cf_t a10, simd_cf_t a11) { +static inline simd_cf_t srslte_mat_2x2_det_simd(simd_cf_t a00, simd_cf_t a01, simd_cf_t a10, simd_cf_t a11) +{ return srslte_simd_cf_sub(srslte_simd_cf_prod(a00, a11), srslte_simd_cf_prod(a01, a10)); } /* Generic SIMD implementation for Zero Forcing (ZF) solver */ -static inline void srslte_mat_2x2_zf_csi_simd(simd_cf_t y0, - simd_cf_t y1, - simd_cf_t h00, - simd_cf_t h01, - simd_cf_t h10, - simd_cf_t h11, - simd_cf_t *x0, - simd_cf_t *x1, - simd_f_t *csi0, - simd_f_t *csi1, - float norm) { - simd_cf_t det = srslte_mat_2x2_det_simd(h00, h01, h10, h11); +static inline void srslte_mat_2x2_zf_csi_simd(simd_cf_t y0, + simd_cf_t y1, + simd_cf_t h00, + simd_cf_t h01, + simd_cf_t h10, + simd_cf_t h11, + simd_cf_t* x0, + simd_cf_t* x1, + simd_f_t* csi0, + simd_f_t* csi1, + float norm) +{ + simd_cf_t det = srslte_mat_2x2_det_simd(h00, h01, h10, h11); simd_cf_t detrec = srslte_simd_cf_mul(srslte_simd_cf_rcp(det), srslte_simd_f_set1(norm)); *x0 = srslte_simd_cf_prod(srslte_simd_cf_sub(srslte_simd_cf_prod(h11, y0), srslte_simd_cf_prod(h01, y1)), detrec); @@ -132,61 +163,60 @@ static inline void srslte_mat_2x2_zf_csi_simd(simd_cf_t y0, *csi1 = srslte_simd_f_set1(1.0f); } -static inline void srslte_mat_2x2_zf_simd(simd_cf_t y0, - simd_cf_t y1, - simd_cf_t h00, - simd_cf_t h01, - simd_cf_t h10, - simd_cf_t h11, - simd_cf_t *x0, - simd_cf_t *x1, - float norm) { +static inline void srslte_mat_2x2_zf_simd(simd_cf_t y0, + simd_cf_t y1, + simd_cf_t h00, + simd_cf_t h01, + simd_cf_t h10, + simd_cf_t h11, + simd_cf_t* x0, + simd_cf_t* x1, + float norm) +{ simd_f_t csi1, csi2; srslte_mat_2x2_zf_csi_simd(y0, y1, h00, h01, h10, h11, x0, x1, &csi1, &csi2, norm); } /* Generic SIMD implementation for Minimum Mean Squared Error (MMSE) solver */ -static inline void srslte_mat_2x2_mmse_csi_simd(simd_cf_t y0, - simd_cf_t y1, - simd_cf_t h00, - simd_cf_t h01, - simd_cf_t h10, - simd_cf_t h11, - simd_cf_t *x0, - simd_cf_t *x1, - simd_f_t *csi0, - simd_f_t *csi1, - float noise_estimate, - float norm) { +static inline void srslte_mat_2x2_mmse_csi_simd(simd_cf_t y0, + simd_cf_t y1, + simd_cf_t h00, + simd_cf_t h01, + simd_cf_t h10, + simd_cf_t h11, + simd_cf_t* x0, + simd_cf_t* x1, + simd_f_t* csi0, + simd_f_t* csi1, + float noise_estimate, + float norm) +{ simd_cf_t _noise_estimate; - simd_f_t _norm = srslte_simd_f_set1(norm); + simd_f_t _norm = srslte_simd_f_set1(norm); #if HAVE_NEON _noise_estimate.val[0] = srslte_simd_f_set1(noise_estimate); _noise_estimate.val[1] = srslte_simd_f_zero(); -#else /* HAVE_NEON */ +#else /* HAVE_NEON */ _noise_estimate.re = srslte_simd_f_set1(noise_estimate); _noise_estimate.im = srslte_simd_f_zero(); #endif /* HAVE_NEON */ /* 1. A = H' x H + No*/ - simd_cf_t a00 = - srslte_simd_cf_add(srslte_simd_cf_add(srslte_simd_cf_conjprod(h00, h00), srslte_simd_cf_conjprod(h10, h10)), - _noise_estimate); + simd_cf_t a00 = srslte_simd_cf_add( + srslte_simd_cf_add(srslte_simd_cf_conjprod(h00, h00), srslte_simd_cf_conjprod(h10, h10)), _noise_estimate); simd_cf_t a01 = srslte_simd_cf_add(srslte_simd_cf_conjprod(h01, h00), srslte_simd_cf_conjprod(h11, h10)); simd_cf_t a10 = srslte_simd_cf_add(srslte_simd_cf_conjprod(h00, h01), srslte_simd_cf_conjprod(h10, h11)); - simd_cf_t a11 = - srslte_simd_cf_add(srslte_simd_cf_add(srslte_simd_cf_conjprod(h01, h01), srslte_simd_cf_conjprod(h11, h11)), - _noise_estimate); + simd_cf_t a11 = srslte_simd_cf_add( + srslte_simd_cf_add(srslte_simd_cf_conjprod(h01, h01), srslte_simd_cf_conjprod(h11, h11)), _noise_estimate); simd_cf_t a_det_rcp = srslte_simd_cf_rcp(srslte_mat_2x2_det_simd(a00, a01, a10, a11)); /* 2. B = inv(H' x H + No) = inv(A) */ simd_cf_t _norm2 = srslte_simd_cf_mul(a_det_rcp, _norm); - simd_cf_t b00 = srslte_simd_cf_prod(a11, _norm2); - simd_cf_t b01 = srslte_simd_cf_prod(srslte_simd_cf_neg(a01), _norm2); - simd_cf_t b10 = srslte_simd_cf_prod(srslte_simd_cf_neg(a10), _norm2); - simd_cf_t b11 = srslte_simd_cf_prod(a00, _norm2); - + simd_cf_t b00 = srslte_simd_cf_prod(a11, _norm2); + simd_cf_t b01 = srslte_simd_cf_prod(srslte_simd_cf_neg(a01), _norm2); + simd_cf_t b10 = srslte_simd_cf_prod(srslte_simd_cf_neg(a10), _norm2); + simd_cf_t b11 = srslte_simd_cf_prod(a00, _norm2); /* 3. W = inv(H' x H + No) x H' = B x H' */ simd_cf_t w00 = srslte_simd_cf_add(srslte_simd_cf_conjprod(b00, h00), srslte_simd_cf_conjprod(b01, h01)); @@ -203,16 +233,17 @@ static inline void srslte_mat_2x2_mmse_csi_simd(simd_cf_t y0, *csi1 = srslte_simd_f_rcp(srslte_simd_cf_re(b11)); } -static inline void srslte_mat_2x2_mmse_simd(simd_cf_t y0, - simd_cf_t y1, - simd_cf_t h00, - simd_cf_t h01, - simd_cf_t h10, - simd_cf_t h11, - simd_cf_t *x0, - simd_cf_t *x1, - float noise_estimate, - float norm) { +static inline void srslte_mat_2x2_mmse_simd(simd_cf_t y0, + simd_cf_t y1, + simd_cf_t h00, + simd_cf_t h01, + simd_cf_t h10, + simd_cf_t h11, + simd_cf_t* x0, + simd_cf_t* x1, + float noise_estimate, + float norm) +{ simd_f_t csi0, csi1; srslte_mat_2x2_mmse_csi_simd(y0, y1, h00, h01, h10, h11, x0, x1, &csi0, &csi1, noise_estimate, norm); } diff --git a/lib/include/srslte/phy/utils/phy_logger.h b/lib/include/srslte/phy/utils/phy_logger.h index 9e5ca621d..2a0246eb5 100644 --- a/lib/include/srslte/phy/utils/phy_logger.h +++ b/lib/include/srslte/phy/utils/phy_logger.h @@ -27,27 +27,26 @@ #ifndef SRSLTE_PHY_LOGGER_H #define SRSLTE_PHY_LOGGER_H -#include -#include #include #include -#include #include +#include +#include #include #ifdef __cplusplus - extern "C" { +extern "C" { #endif // __cplusplus - typedef enum { LOG_LEVEL_INFO_S, LOG_LEVEL_DEBUG_S, LOG_LEVEL_ERROR_S } phy_logger_level_t; +typedef enum { LOG_LEVEL_INFO_S, LOG_LEVEL_DEBUG_S, LOG_LEVEL_ERROR_S } phy_logger_level_t; - typedef void (*phy_log_handler_t)(phy_logger_level_t log_level, void* ctx, char* str); +typedef void (*phy_log_handler_t)(phy_logger_level_t log_level, void* ctx, char* str); - void srslte_phy_log_register_handler(void* ctx, phy_log_handler_t handler); +void srslte_phy_log_register_handler(void* ctx, phy_log_handler_t handler); - void srslte_phy_log_print(phy_logger_level_t log_level, const char* format, ...); +void srslte_phy_log_print(phy_logger_level_t log_level, const char* format, ...); #ifdef __cplusplus } -#endif // C++ +#endif // C++ #endif // SRSLTE_PHY_LOGGER_H diff --git a/lib/include/srslte/phy/utils/ringbuffer.h b/lib/include/srslte/phy/utils/ringbuffer.h index 247369a04..5d2ae61ad 100644 --- a/lib/include/srslte/phy/utils/ringbuffer.h +++ b/lib/include/srslte/phy/utils/ringbuffer.h @@ -24,12 +24,12 @@ #include "srslte/config.h" #include -#include #include +#include typedef struct { - uint8_t *buffer; - bool active; + uint8_t* buffer; + bool active; int capacity; int count; int wpm; @@ -45,13 +45,13 @@ extern "C" { SRSLTE_API int srslte_ringbuffer_init(srslte_ringbuffer_t* q, int capacity); -SRSLTE_API void srslte_ringbuffer_free(srslte_ringbuffer_t *q); +SRSLTE_API void srslte_ringbuffer_free(srslte_ringbuffer_t* q); -SRSLTE_API void srslte_ringbuffer_reset(srslte_ringbuffer_t *q); +SRSLTE_API void srslte_ringbuffer_reset(srslte_ringbuffer_t* q); SRSLTE_API int srslte_ringbuffer_status(srslte_ringbuffer_t* q); -SRSLTE_API int srslte_ringbuffer_space(srslte_ringbuffer_t *q); +SRSLTE_API int srslte_ringbuffer_space(srslte_ringbuffer_t* q); SRSLTE_API int srslte_ringbuffer_write(srslte_ringbuffer_t* q, void* ptr, int nof_bytes); @@ -65,12 +65,10 @@ SRSLTE_API int srslte_ringbuffer_read_convert_conj(srslte_ringbuffer_t* q, cf_t* SRSLTE_API int srslte_ringbuffer_read_block(srslte_ringbuffer_t* q, void** p, int nof_bytes); -SRSLTE_API void srslte_ringbuffer_stop(srslte_ringbuffer_t *q); +SRSLTE_API void srslte_ringbuffer_stop(srslte_ringbuffer_t* q); #ifdef __cplusplus } #endif #endif // SRSLTE_RINGBUFFER_H - - diff --git a/lib/include/srslte/phy/utils/simd.h b/lib/include/srslte/phy/utils/simd.h index a1cfe9c08..589acf6b0 100644 --- a/lib/include/srslte/phy/utils/simd.h +++ b/lib/include/srslte/phy/utils/simd.h @@ -22,6 +22,8 @@ #ifndef SRSLTE_SIMD_H #define SRSLTE_SIMD_H +typedef _Complex float cf_t; + #ifdef LV_HAVE_SSE /* AVX, AVX2, FMA, AVX512 are in this group */ #ifndef __OPTIMIZE__ #define __OPTIMIZE__ @@ -38,13 +40,13 @@ * SSE Macros */ #ifdef LV_HAVE_SSE -#define _MM_SWAP(X) ((__m128)_mm_shuffle_ps(X, X, _MM_SHUFFLE(2,3,0,1))) -#define _MM_PERM(X) ((__m128)_mm_shuffle_ps(X, X, _MM_SHUFFLE(2,1,3,0))) +#define _MM_SWAP(X) ((__m128)_mm_shuffle_ps(X, X, _MM_SHUFFLE(2, 3, 0, 1))) +#define _MM_PERM(X) ((__m128)_mm_shuffle_ps(X, X, _MM_SHUFFLE(2, 1, 3, 0))) #define _MM_MULJ_PS(X) _MM_SWAP(_MM_CONJ_PS(X)) #define _MM_CONJ_PS(X) (_mm_xor_ps(X, _mm_set_ps(-0.0f, 0.0f, -0.0f, 0.0f))) -#define _MM_SQMOD_PS(X) _MM_PERM(_mm_hadd_ps(_mm_mul_ps(X,X), _mm_set_ps(0.0f, 0.0f, 0.0f, 0.0f))) -#define _MM_PROD_PS(a, b) _mm_addsub_ps(_mm_mul_ps(a,_mm_moveldup_ps(b)),_mm_mul_ps(\ - _mm_shuffle_ps(a,a,0xB1),_mm_movehdup_ps(b))) +#define _MM_SQMOD_PS(X) _MM_PERM(_mm_hadd_ps(_mm_mul_ps(X, X), _mm_set_ps(0.0f, 0.0f, 0.0f, 0.0f))) +#define _MM_PROD_PS(a, b) \ + _mm_addsub_ps(_mm_mul_ps(a, _mm_moveldup_ps(b)), _mm_mul_ps(_mm_shuffle_ps(a, a, 0xB1), _mm_movehdup_ps(b))) #endif /* LV_HAVE_SSE */ @@ -57,91 +59,97 @@ #define _MM256_CONJ_PS(X) (_mm256_xor_ps(X, _mm256_set_ps(-0.0f, 0.0f, -0.0f, 0.0f, -0.0f, 0.0f, -0.0f, 0.0f))) #ifdef LV_HAVE_FMA -#define _MM256_SQMOD_PS(A, B) _mm256_permute_ps(_mm256_hadd_ps(_mm256_fmadd_ps(A, A, _mm256_mul_ps(B,B)), \ - _mm256_set_ps(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)), 0b11011100) -#define _MM256_PROD_PS(a, b) _mm256_fmaddsub_ps(a,_mm256_moveldup_ps(b),\ - _mm256_mul_ps(_mm256_shuffle_ps(a,a,0xB1),_mm256_movehdup_ps(b))) +#define _MM256_SQMOD_PS(A, B) \ + _mm256_permute_ps(_mm256_hadd_ps(_mm256_fmadd_ps(A, A, _mm256_mul_ps(B, B)), \ + _mm256_set_ps(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)), \ + 0b11011100) +#define _MM256_PROD_PS(a, b) \ + _mm256_fmaddsub_ps(a, _mm256_moveldup_ps(b), _mm256_mul_ps(_mm256_shuffle_ps(a, a, 0xB1), _mm256_movehdup_ps(b))) #else -#define _MM256_SQMOD_PS(A, B) _mm256_permute_ps(_mm256_hadd_ps(_mm256_add_ps(_mm256_mul_ps(A,A), _mm256_mul_ps(B,B)), \ - _mm256_set_ps(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)), 0b11011100) -#define _MM256_PROD_PS(a, b) _mm256_addsub_ps(_mm256_mul_ps(a,_mm256_moveldup_ps(b)),\ - _mm256_mul_ps(_mm256_shuffle_ps(a,a,0xB1),_mm256_movehdup_ps(b))) +#define _MM256_SQMOD_PS(A, B) \ + _mm256_permute_ps(_mm256_hadd_ps(_mm256_add_ps(_mm256_mul_ps(A, A), _mm256_mul_ps(B, B)), \ + _mm256_set_ps(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)), \ + 0b11011100) +#define _MM256_PROD_PS(a, b) \ + _mm256_addsub_ps(_mm256_mul_ps(a, _mm256_moveldup_ps(b)), \ + _mm256_mul_ps(_mm256_shuffle_ps(a, a, 0xB1), _mm256_movehdup_ps(b))) #endif /* LV_HAVE_FMA */ #endif /* LV_HAVE_AVX */ - /* * AVX extension with FMA Macros */ #ifdef LV_HAVE_FMA -#define _MM256_SQMOD_ADD_PS(A, B, C) _mm256_permute_ps(_mm256_hadd_ps(_mm256_fmadd_ps(A, A, _mm256_fmadd_ps(B, B, C)),\ - _mm256_set_ps(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)), 0b11011100) +#define _MM256_SQMOD_ADD_PS(A, B, C) \ + _mm256_permute_ps(_mm256_hadd_ps(_mm256_fmadd_ps(A, A, _mm256_fmadd_ps(B, B, C)), \ + _mm256_set_ps(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)), \ + 0b11011100) -#define _MM256_PROD_ADD_PS(A, B, C) _mm256_fmaddsub_ps(A,_mm256_moveldup_ps(B),\ - _mm256_fmaddsub_ps(_mm256_shuffle_ps(A,A,0xB1),_mm256_movehdup_ps(B), C)) +#define _MM256_PROD_ADD_PS(A, B, C) \ + _mm256_fmaddsub_ps( \ + A, _mm256_moveldup_ps(B), _mm256_fmaddsub_ps(_mm256_shuffle_ps(A, A, 0xB1), _mm256_movehdup_ps(B), C)) -#define _MM256_PROD_SUB_PS(A, B, C) _mm256_fmaddsub_ps(A,_mm256_moveldup_ps(B),\ - _mm256_fmsubadd_ps(_mm256_shuffle_ps(A,A,0xB1),_mm256_movehdup_ps(B), C)) +#define _MM256_PROD_SUB_PS(A, B, C) \ + _mm256_fmaddsub_ps( \ + A, _mm256_moveldup_ps(B), _mm256_fmsubadd_ps(_mm256_shuffle_ps(A, A, 0xB1), _mm256_movehdup_ps(B), C)) #endif /* LV_HAVE_FMA */ - - /* Memory Sizes for Single Floating Point and fixed point */ #ifdef LV_HAVE_AVX512 -#define SRSLTE_SIMD_F_SIZE 16 -#define SRSLTE_SIMD_CF_SIZE 16 +#define SRSLTE_SIMD_F_SIZE 16 +#define SRSLTE_SIMD_CF_SIZE 16 -#define SRSLTE_SIMD_I_SIZE 16 +#define SRSLTE_SIMD_I_SIZE 16 -#define SRSLTE_SIMD_B_SIZE 64 -#define SRSLTE_SIMD_S_SIZE 32 -#define SRSLTE_SIMD_C16_SIZE 0 +#define SRSLTE_SIMD_B_SIZE 64 +#define SRSLTE_SIMD_S_SIZE 32 +#define SRSLTE_SIMD_C16_SIZE 0 #else #ifdef LV_HAVE_AVX2 -#define SRSLTE_SIMD_F_SIZE 8 -#define SRSLTE_SIMD_CF_SIZE 8 +#define SRSLTE_SIMD_F_SIZE 8 +#define SRSLTE_SIMD_CF_SIZE 8 -#define SRSLTE_SIMD_I_SIZE 8 +#define SRSLTE_SIMD_I_SIZE 8 -#define SRSLTE_SIMD_B_SIZE 32 -#define SRSLTE_SIMD_S_SIZE 16 -#define SRSLTE_SIMD_C16_SIZE 16 +#define SRSLTE_SIMD_B_SIZE 32 +#define SRSLTE_SIMD_S_SIZE 16 +#define SRSLTE_SIMD_C16_SIZE 16 #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE -#define SRSLTE_SIMD_F_SIZE 4 -#define SRSLTE_SIMD_CF_SIZE 4 +#define SRSLTE_SIMD_F_SIZE 4 +#define SRSLTE_SIMD_CF_SIZE 4 -#define SRSLTE_SIMD_I_SIZE 4 +#define SRSLTE_SIMD_I_SIZE 4 -#define SRSLTE_SIMD_B_SIZE 16 -#define SRSLTE_SIMD_S_SIZE 8 -#define SRSLTE_SIMD_C16_SIZE 8 +#define SRSLTE_SIMD_B_SIZE 16 +#define SRSLTE_SIMD_S_SIZE 8 +#define SRSLTE_SIMD_C16_SIZE 8 #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON -#define SRSLTE_SIMD_F_SIZE 4 -#define SRSLTE_SIMD_CF_SIZE 4 +#define SRSLTE_SIMD_F_SIZE 4 +#define SRSLTE_SIMD_CF_SIZE 4 -#define SRSLTE_SIMD_I_SIZE 4 -#define SRSLTE_SIMD_B_SIZE 16 -#define SRSLTE_SIMD_S_SIZE 8 -#define SRSLTE_SIMD_C16_SIZE 8 +#define SRSLTE_SIMD_I_SIZE 4 +#define SRSLTE_SIMD_B_SIZE 16 +#define SRSLTE_SIMD_S_SIZE 8 +#define SRSLTE_SIMD_C16_SIZE 8 #else /* HAVE_NEON */ -#define SRSLTE_SIMD_F_SIZE 0 -#define SRSLTE_SIMD_CF_SIZE 0 +#define SRSLTE_SIMD_F_SIZE 0 +#define SRSLTE_SIMD_CF_SIZE 0 -#define SRSLTE_SIMD_I_SIZE 0 -#define SRSLTE_SIMD_B_SIZE 0 -#define SRSLTE_SIMD_S_SIZE 0 -#define SRSLTE_SIMD_C16_SIZE 0 +#define SRSLTE_SIMD_I_SIZE 0 +#define SRSLTE_SIMD_B_SIZE 0 +#define SRSLTE_SIMD_S_SIZE 0 +#define SRSLTE_SIMD_C16_SIZE 0 #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ @@ -173,7 +181,8 @@ typedef float32x4_t simd_f_t; #endif /* LV_HAVE_AVX512 */ /* Single precision Floating point functions */ -static inline simd_f_t srslte_simd_f_load(const float *ptr) { +static inline simd_f_t srslte_simd_f_load(const float* ptr) +{ #ifdef LV_HAVE_AVX512 return _mm512_load_ps(ptr); #else /* LV_HAVE_AVX512 */ @@ -191,7 +200,8 @@ static inline simd_f_t srslte_simd_f_load(const float *ptr) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_loadu(const float *ptr) { +static inline simd_f_t srslte_simd_f_loadu(const float* ptr) +{ #ifdef LV_HAVE_AVX512 return _mm512_loadu_ps(ptr); #else /* LV_HAVE_AVX512 */ @@ -209,7 +219,8 @@ static inline simd_f_t srslte_simd_f_loadu(const float *ptr) { #endif /* LV_HAVE_AVX512 */ } -static inline void srslte_simd_f_store(float *ptr, simd_f_t simdreg) { +static inline void srslte_simd_f_store(float* ptr, simd_f_t simdreg) +{ #ifdef LV_HAVE_AVX512 _mm512_store_ps(ptr, simdreg); #else /* LV_HAVE_AVX512 */ @@ -227,7 +238,8 @@ static inline void srslte_simd_f_store(float *ptr, simd_f_t simdreg) { #endif /* LV_HAVE_AVX512 */ } -static inline void srslte_simd_f_storeu(float *ptr, simd_f_t simdreg) { +static inline void srslte_simd_f_storeu(float* ptr, simd_f_t simdreg) +{ #ifdef LV_HAVE_AVX512 _mm512_storeu_ps(ptr, simdreg); #else /* LV_HAVE_AVX512 */ @@ -245,7 +257,8 @@ static inline void srslte_simd_f_storeu(float *ptr, simd_f_t simdreg) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_set1(float x) { +static inline simd_f_t srslte_simd_f_set1(float x) +{ #ifdef LV_HAVE_AVX512 return _mm512_set1_ps(x); #else /* LV_HAVE_AVX512 */ @@ -263,7 +276,8 @@ static inline simd_f_t srslte_simd_f_set1(float x) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_mul(simd_f_t a, simd_f_t b) { +static inline simd_f_t srslte_simd_f_mul(simd_f_t a, simd_f_t b) +{ #ifdef LV_HAVE_AVX512 return _mm512_mul_ps(a, b); #else /* LV_HAVE_AVX512 */ @@ -274,14 +288,15 @@ static inline simd_f_t srslte_simd_f_mul(simd_f_t a, simd_f_t b) { return _mm_mul_ps(a, b); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON - return vmulq_f32(a,b); + return vmulq_f32(a, b); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_rcp(simd_f_t a) { +static inline simd_f_t srslte_simd_f_rcp(simd_f_t a) +{ #ifdef LV_HAVE_AVX512 return _mm512_rcp14_ps(a); #else /* LV_HAVE_AVX512 */ @@ -299,7 +314,8 @@ static inline simd_f_t srslte_simd_f_rcp(simd_f_t a) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_addsub(simd_f_t a, simd_f_t b) { +static inline simd_f_t srslte_simd_f_addsub(simd_f_t a, simd_f_t b) +{ #ifdef LV_HAVE_AVX512 __m512 r = _mm512_add_ps(a, b); return _mm512_mask_sub_ps(r, 0b0101010101010101, a, b); @@ -309,31 +325,29 @@ static inline simd_f_t srslte_simd_f_addsub(simd_f_t a, simd_f_t b) { #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE return _mm_addsub_ps(a, b); -#else /* LV_HAVE_SSE */ +#else /* LV_HAVE_SSE */ #ifdef HAVE_NEON // CURRENTLY USES GENERIC IMPLEMENTATION FOR NEON - float* a_ptr = (float*) &a; - float* b_ptr = (float*) &b; - simd_f_t ret; - float* c_ptr = (float*) &ret; - for(int i = 0; i<4;i++){ - if(i%2==0){ - c_ptr[i] = a_ptr[i] - b_ptr[i]; - }else{ - c_ptr[i] = a_ptr[i] + b_ptr[i]; - } - } - - return ret; -#endif /* HAVE_NEON */ -#endif /* LV_HAVE_SSE */ -#endif /* LV_HAVE_AVX2 */ -#endif /* LV_HAVE_AVX512 */ -} - - + float* a_ptr = (float*)&a; + float* b_ptr = (float*)&b; + simd_f_t ret; + float* c_ptr = (float*)&ret; + for (int i = 0; i < 4; i++) { + if (i % 2 == 0) { + c_ptr[i] = a_ptr[i] - b_ptr[i]; + } else { + c_ptr[i] = a_ptr[i] + b_ptr[i]; + } + } + return ret; +#endif /* HAVE_NEON */ +#endif /* LV_HAVE_SSE */ +#endif /* LV_HAVE_AVX2 */ +#endif /* LV_HAVE_AVX512 */ +} -static inline simd_f_t srslte_simd_f_sub(simd_f_t a, simd_f_t b) { +static inline simd_f_t srslte_simd_f_sub(simd_f_t a, simd_f_t b) +{ #ifdef LV_HAVE_AVX512 return _mm512_sub_ps(a, b); #else /* LV_HAVE_AVX512 */ @@ -351,7 +365,8 @@ static inline simd_f_t srslte_simd_f_sub(simd_f_t a, simd_f_t b) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_add(simd_f_t a, simd_f_t b) { +static inline simd_f_t srslte_simd_f_add(simd_f_t a, simd_f_t b) +{ #ifdef LV_HAVE_AVX512 return _mm512_add_ps(a, b); #else /* LV_HAVE_AVX512 */ @@ -369,7 +384,8 @@ static inline simd_f_t srslte_simd_f_add(simd_f_t a, simd_f_t b) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_zero (void) { +static inline simd_f_t srslte_simd_f_zero(void) +{ #ifdef LV_HAVE_AVX512 return _mm512_setzero_ps(); #else /* LV_HAVE_AVX512 */ @@ -377,7 +393,7 @@ static inline simd_f_t srslte_simd_f_zero (void) { return _mm256_setzero_ps(); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - return _mm_setzero_ps(); + return _mm_setzero_ps(); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON return vdupq_n_f32(0); @@ -387,7 +403,8 @@ static inline simd_f_t srslte_simd_f_zero (void) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_swap(simd_f_t a) { +static inline simd_f_t srslte_simd_f_swap(simd_f_t a) +{ #ifdef LV_HAVE_AVX512 return _mm512_permute_ps(a, 0b10110001); #else /* LV_HAVE_AVX512 */ @@ -405,16 +422,25 @@ static inline simd_f_t srslte_simd_f_swap(simd_f_t a) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_hadd(simd_f_t a, simd_f_t b) { +static inline simd_f_t srslte_simd_f_hadd(simd_f_t a, simd_f_t b) +{ #ifdef LV_HAVE_AVX512 - const __m512i idx1 = _mm512_setr_epi32((0b00000), (0b00010), - (0b00100), (0b00110), - (0b01000), (0b01010), - (0b01100), (0b01110), - (0b10000), (0b10010), - (0b10100), (0b10110), - (0b11000), (0b11010), - (0b11100), (0b11110)); + const __m512i idx1 = _mm512_setr_epi32((0b00000), + (0b00010), + (0b00100), + (0b00110), + (0b01000), + (0b01010), + (0b01100), + (0b01110), + (0b10000), + (0b10010), + (0b10100), + (0b10110), + (0b11000), + (0b11010), + (0b11100), + (0b11110)); const __m512i idx2 = _mm512_or_epi32(idx1, _mm512_set1_epi32(1)); simd_f_t a1 = _mm512_permutex2var_ps(a, idx1, b); @@ -430,14 +456,15 @@ static inline simd_f_t srslte_simd_f_hadd(simd_f_t a, simd_f_t b) { return _mm_hadd_ps(a, b); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON - return vcombine_f32( vpadd_f32( vget_low_f32(a), vget_high_f32(a) ), vpadd_f32( vget_low_f32(b), vget_high_f32(b) ) ); + return vcombine_f32(vpadd_f32(vget_low_f32(a), vget_high_f32(a)), vpadd_f32(vget_low_f32(b), vget_high_f32(b))); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_sqrt(simd_f_t a) { +static inline simd_f_t srslte_simd_f_sqrt(simd_f_t a) +{ #ifdef LV_HAVE_AVX512 return _mm512_sqrt_ps(a); #else /* LV_HAVE_AVX512 */ @@ -449,20 +476,21 @@ static inline simd_f_t srslte_simd_f_sqrt(simd_f_t a) { #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON float32x4_t sqrt_reciprocal = vrsqrteq_f32(a); - sqrt_reciprocal = vmulq_f32(vrsqrtsq_f32(vmulq_f32(a,sqrt_reciprocal), sqrt_reciprocal),sqrt_reciprocal); - float32x4_t result = vmulq_f32(a,sqrt_reciprocal); + sqrt_reciprocal = vmulq_f32(vrsqrtsq_f32(vmulq_f32(a, sqrt_reciprocal), sqrt_reciprocal), sqrt_reciprocal); + float32x4_t result = vmulq_f32(a, sqrt_reciprocal); /* Detect zeros in NEON 1/sqrtf for preventing NaN */ - float32x4_t zeros = vmovq_n_f32(0); /* Zero vector */ - uint32x4_t mask = vceqq_f32(a, zeros); /* Zero vector mask */ - return vbslq_f32(mask, zeros, result); /* Force zero results and return */ + float32x4_t zeros = vmovq_n_f32(0); /* Zero vector */ + uint32x4_t mask = vceqq_f32(a, zeros); /* Zero vector mask */ + return vbslq_f32(mask, zeros, result); /* Force zero results and return */ #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_neg(simd_f_t a) { +static inline simd_f_t srslte_simd_f_neg(simd_f_t a) +{ #ifdef LV_HAVE_AVX512 return _mm512_xor_ps(_mm512_set1_ps(-0.0f), a); #else /* LV_HAVE_AVX512 */ @@ -480,7 +508,8 @@ static inline simd_f_t srslte_simd_f_neg(simd_f_t a) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_neg_mask(simd_f_t a, simd_f_t mask) { +static inline simd_f_t srslte_simd_f_neg_mask(simd_f_t a, simd_f_t mask) +{ #ifdef LV_HAVE_AVX512 return _mm512_xor_ps(mask, a); #else /* LV_HAVE_AVX512 */ @@ -491,14 +520,15 @@ static inline simd_f_t srslte_simd_f_neg_mask(simd_f_t a, simd_f_t mask) { return _mm_xor_ps(mask, a); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON - return (float32x4_t) veorq_s32((int32x4_t) a, (int32x4_t) mask); + return (float32x4_t)veorq_s32((int32x4_t)a, (int32x4_t)mask); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_f_abs(simd_f_t a) { +static inline simd_f_t srslte_simd_f_abs(simd_f_t a) +{ #ifdef LV_HAVE_AVX512 return _mm512_andnot_ps(_mm512_set1_ps(-0.0f), a); #else /* LV_HAVE_AVX512 */ @@ -516,10 +546,8 @@ static inline simd_f_t srslte_simd_f_abs(simd_f_t a) { #endif /* LV_HAVE_AVX512 */ } - #endif /* SRSLTE_SIMD_F_SIZE */ - #if SRSLTE_SIMD_CF_SIZE #ifdef HAVE_NEON @@ -532,34 +560,35 @@ typedef struct { #endif /* Complex Single precission Floating point functions */ -static inline simd_cf_t srslte_simd_cfi_load(const cf_t *ptr) { +static inline simd_cf_t srslte_simd_cfi_load(const cf_t* ptr) +{ simd_cf_t ret; #ifdef LV_HAVE_AVX512 __m512 in1 = _mm512_load_ps((float*)(ptr)); - __m512 in2 = _mm512_load_ps((float*)(ptr + SRSLTE_SIMD_CF_SIZE/2)); - ret.re = _mm512_permutex2var_ps(in1, _mm512_setr_epi32(0x00, 0x02, 0x04, 0x06, - 0x08, 0x0A, 0x0C, 0x0E, - 0x10, 0x12, 0x14, 0x16, - 0x18, 0x1A, 0x1C, 0x1E), in2); - ret.im = _mm512_permutex2var_ps(in1, _mm512_setr_epi32(0x01, 0x03, 0x05, 0x07, - 0x09, 0x0B, 0x0D, 0x0F, - 0x11, 0x13, 0x15, 0x17, - 0x19, 0x1B, 0x1D, 0x1F), in2); + __m512 in2 = _mm512_load_ps((float*)(ptr + SRSLTE_SIMD_CF_SIZE / 2)); + ret.re = _mm512_permutex2var_ps( + in1, + _mm512_setr_epi32(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E), + in2); + ret.im = _mm512_permutex2var_ps( + in1, + _mm512_setr_epi32(0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F), + in2); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - __m256 in1 = _mm256_permute_ps(_mm256_load_ps((float*)(ptr)), 0b11011000); - __m256 in2 = _mm256_permute_ps(_mm256_load_ps((float*)(ptr + 4)), 0b11011000); - ret.re = _mm256_unpacklo_ps(in1, in2); - ret.im = _mm256_unpackhi_ps(in1, in2); + __m256 in1 = _mm256_permute_ps(_mm256_load_ps((float*)(ptr)), 0b11011000); + __m256 in2 = _mm256_permute_ps(_mm256_load_ps((float*)(ptr + 4)), 0b11011000); + ret.re = _mm256_unpacklo_ps(in1, in2); + ret.im = _mm256_unpackhi_ps(in1, in2); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE __m128 i1 = _mm_load_ps((float*)(ptr)); __m128 i2 = _mm_load_ps((float*)(ptr + 2)); - ret.re = _mm_shuffle_ps(i1, i2, _MM_SHUFFLE(2,0,2,0)); - ret.im = _mm_shuffle_ps(i1, i2, _MM_SHUFFLE(3,1,3,1)); + ret.re = _mm_shuffle_ps(i1, i2, _MM_SHUFFLE(2, 0, 2, 0)); + ret.im = _mm_shuffle_ps(i1, i2, _MM_SHUFFLE(3, 1, 3, 1)); #else #ifdef HAVE_NEON - ret = vld2q_f32((float*)(ptr)); + ret = vld2q_f32((float*)(ptr)); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ @@ -568,34 +597,35 @@ static inline simd_cf_t srslte_simd_cfi_load(const cf_t *ptr) { } /* Complex Single precission Floating point functions */ -static inline simd_cf_t srslte_simd_cfi_loadu(const cf_t *ptr) { +static inline simd_cf_t srslte_simd_cfi_loadu(const cf_t* ptr) +{ simd_cf_t ret; #ifdef LV_HAVE_AVX512 __m512 in1 = _mm512_loadu_ps((float*)(ptr)); - __m512 in2 = _mm512_loadu_ps((float*)(ptr + SRSLTE_SIMD_CF_SIZE/2)); - ret.re = _mm512_permutex2var_ps(in1, _mm512_setr_epi32(0x00, 0x02, 0x04, 0x06, - 0x08, 0x0A, 0x0C, 0x0E, - 0x10, 0x12, 0x14, 0x16, - 0x18, 0x1A, 0x1C, 0x1E), in2); - ret.im = _mm512_permutex2var_ps(in1, _mm512_setr_epi32(0x01, 0x03, 0x05, 0x07, - 0x09, 0x0B, 0x0D, 0x0F, - 0x11, 0x13, 0x15, 0x17, - 0x19, 0x1B, 0x1D, 0x1F), in2); + __m512 in2 = _mm512_loadu_ps((float*)(ptr + SRSLTE_SIMD_CF_SIZE / 2)); + ret.re = _mm512_permutex2var_ps( + in1, + _mm512_setr_epi32(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E), + in2); + ret.im = _mm512_permutex2var_ps( + in1, + _mm512_setr_epi32(0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F), + in2); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - __m256 in1 = _mm256_permute_ps(_mm256_loadu_ps((float*)(ptr)), 0b11011000); - __m256 in2 = _mm256_permute_ps(_mm256_loadu_ps((float*)(ptr + 4)), 0b11011000); - ret.re = _mm256_unpacklo_ps(in1, in2); - ret.im = _mm256_unpackhi_ps(in1, in2); + __m256 in1 = _mm256_permute_ps(_mm256_loadu_ps((float*)(ptr)), 0b11011000); + __m256 in2 = _mm256_permute_ps(_mm256_loadu_ps((float*)(ptr + 4)), 0b11011000); + ret.re = _mm256_unpacklo_ps(in1, in2); + ret.im = _mm256_unpackhi_ps(in1, in2); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE __m128 i1 = _mm_loadu_ps((float*)(ptr)); __m128 i2 = _mm_loadu_ps((float*)(ptr + 2)); - ret.re = _mm_shuffle_ps(i1, i2, _MM_SHUFFLE(2,0,2,0)); - ret.im = _mm_shuffle_ps(i1, i2, _MM_SHUFFLE(3,1,3,1)); + ret.re = _mm_shuffle_ps(i1, i2, _MM_SHUFFLE(2, 0, 2, 0)); + ret.im = _mm_shuffle_ps(i1, i2, _MM_SHUFFLE(3, 1, 3, 1)); #else #ifdef HAVE_NEON - ret = vld2q_f32((float*)(ptr)); + ret = vld2q_f32((float*)(ptr)); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ @@ -603,19 +633,20 @@ static inline simd_cf_t srslte_simd_cfi_loadu(const cf_t *ptr) { return ret; } -static inline simd_cf_t srslte_simd_cf_load(const float *re, const float *im) { +static inline simd_cf_t srslte_simd_cf_load(const float* re, const float* im) +{ simd_cf_t ret; #ifdef LV_HAVE_AVX512 ret.re = _mm512_load_ps(re); ret.im = _mm512_load_ps(im); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - ret.re = _mm256_load_ps(re); - ret.im = _mm256_load_ps(im); + ret.re = _mm256_load_ps(re); + ret.im = _mm256_load_ps(im); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - ret.re = _mm_load_ps(re); - ret.im = _mm_load_ps(im); + ret.re = _mm_load_ps(re); + ret.im = _mm_load_ps(im); #else /*HAVE_NEON*/ #ifdef HAVE_NEON ret.val[0] = vld1q_f32(re); @@ -627,19 +658,20 @@ static inline simd_cf_t srslte_simd_cf_load(const float *re, const float *im) { return ret; } -static inline simd_cf_t srslte_simd_cf_loadu(const float *re, const float *im) { +static inline simd_cf_t srslte_simd_cf_loadu(const float* re, const float* im) +{ simd_cf_t ret; #ifdef LV_HAVE_AVX512 ret.re = _mm512_loadu_ps(re); ret.im = _mm512_loadu_ps(im); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - ret.re = _mm256_loadu_ps(re); - ret.im = _mm256_loadu_ps(im); + ret.re = _mm256_loadu_ps(re); + ret.im = _mm256_loadu_ps(im); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - ret.re = _mm_loadu_ps(re); - ret.im = _mm_loadu_ps(im); + ret.re = _mm_loadu_ps(re); + ret.im = _mm_loadu_ps(im); #else /*HAVE_NEON*/ #ifdef HAVE_NEON ret.val[0] = vld1q_f32(re); @@ -651,16 +683,17 @@ static inline simd_cf_t srslte_simd_cf_loadu(const float *re, const float *im) { return ret; } -static inline void srslte_simd_cfi_store(cf_t *ptr, simd_cf_t simdreg) { +static inline void srslte_simd_cfi_store(cf_t* ptr, simd_cf_t simdreg) +{ #ifdef LV_HAVE_AVX512 - __m512 s1 = _mm512_permutex2var_ps(simdreg.re, _mm512_setr_epi32(0x00, 0x10, 0x01, 0x11, - 0x02, 0x12, 0x03, 0x13, - 0x04, 0x14, 0x05, 0x15, - 0x06, 0x16, 0x07, 0x17), simdreg.im); - __m512 s2 = _mm512_permutex2var_ps(simdreg.re, _mm512_setr_epi32(0x08, 0x18, 0x09, 0x19, - 0x0A, 0x1A, 0x0B, 0x1B, - 0x0C, 0x1C, 0x0D, 0x1D, - 0x0E, 0x1E, 0x0F, 0x1F), simdreg.im); + __m512 s1 = _mm512_permutex2var_ps( + simdreg.re, + _mm512_setr_epi32(0x00, 0x10, 0x01, 0x11, 0x02, 0x12, 0x03, 0x13, 0x04, 0x14, 0x05, 0x15, 0x06, 0x16, 0x07, 0x17), + simdreg.im); + __m512 s2 = _mm512_permutex2var_ps( + simdreg.re, + _mm512_setr_epi32(0x08, 0x18, 0x09, 0x19, 0x0A, 0x1A, 0x0B, 0x1B, 0x0C, 0x1C, 0x0D, 0x1D, 0x0E, 0x1E, 0x0F, 0x1F), + simdreg.im); _mm512_store_ps((float*)(ptr), s1); _mm512_store_ps((float*)(ptr + 8), s2); #else /* LV_HAVE_AVX512 */ @@ -682,16 +715,17 @@ static inline void srslte_simd_cfi_store(cf_t *ptr, simd_cf_t simdreg) { #endif /* LV_HAVE_AVX512 */ } -static inline void srslte_simd_cfi_storeu(cf_t *ptr, simd_cf_t simdreg) { +static inline void srslte_simd_cfi_storeu(cf_t* ptr, simd_cf_t simdreg) +{ #ifdef LV_HAVE_AVX512 - __m512 s1 = _mm512_permutex2var_ps(simdreg.re, _mm512_setr_epi32(0x00, 0x10, 0x01, 0x11, - 0x02, 0x12, 0x03, 0x13, - 0x04, 0x14, 0x05, 0x15, - 0x06, 0x16, 0x07, 0x17), simdreg.im); - __m512 s2 = _mm512_permutex2var_ps(simdreg.re, _mm512_setr_epi32(0x08, 0x18, 0x09, 0x19, - 0x0A, 0x1A, 0x0B, 0x1B, - 0x0C, 0x1C, 0x0D, 0x1D, - 0x0E, 0x1E, 0x0F, 0x1F), simdreg.im); + __m512 s1 = _mm512_permutex2var_ps( + simdreg.re, + _mm512_setr_epi32(0x00, 0x10, 0x01, 0x11, 0x02, 0x12, 0x03, 0x13, 0x04, 0x14, 0x05, 0x15, 0x06, 0x16, 0x07, 0x17), + simdreg.im); + __m512 s2 = _mm512_permutex2var_ps( + simdreg.re, + _mm512_setr_epi32(0x08, 0x18, 0x09, 0x19, 0x0A, 0x1A, 0x0B, 0x1B, 0x0C, 0x1C, 0x0D, 0x1D, 0x0E, 0x1E, 0x0F, 0x1F), + simdreg.im); _mm512_storeu_ps((float*)(ptr), s1); _mm512_storeu_ps((float*)(ptr + 8), s2); #else /* LV_HAVE_AVX512 */ @@ -713,7 +747,8 @@ static inline void srslte_simd_cfi_storeu(cf_t *ptr, simd_cf_t simdreg) { #endif /* LV_HAVE_AVX512 */ } -static inline void srslte_simd_cf_store(float *re, float *im, simd_cf_t simdreg) { +static inline void srslte_simd_cf_store(float* re, float* im, simd_cf_t simdreg) +{ #ifdef LV_HAVE_AVX512 _mm512_store_ps(re, simdreg.re); _mm512_store_ps(im, simdreg.im); @@ -723,19 +758,20 @@ static inline void srslte_simd_cf_store(float *re, float *im, simd_cf_t simdreg) _mm256_store_ps(im, simdreg.im); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_SSE - _mm_store_ps((float *) re, simdreg.re); - _mm_store_ps((float *) im, simdreg.im); + _mm_store_ps((float*)re, simdreg.re); + _mm_store_ps((float*)im, simdreg.im); #else /*HAVE_NEON*/ #ifdef HAVE_NEON - vst1q_f32((float *) re, simdreg.val[0]); - vst1q_f32((float *) im, simdreg.val[1]); + vst1q_f32((float*)re, simdreg.val[0]); + vst1q_f32((float*)im, simdreg.val[1]); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ } -static inline void srslte_simd_cf_storeu(float *re, float *im, simd_cf_t simdreg) { +static inline void srslte_simd_cf_storeu(float* re, float* im, simd_cf_t simdreg) +{ #ifdef LV_HAVE_AVX512 _mm512_storeu_ps(re, simdreg.re); _mm512_storeu_ps(im, simdreg.im); @@ -745,29 +781,30 @@ static inline void srslte_simd_cf_storeu(float *re, float *im, simd_cf_t simdreg _mm256_storeu_ps(im, simdreg.im); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_SSE - _mm_storeu_ps((float *) re, simdreg.re); - _mm_storeu_ps((float *) im, simdreg.im); + _mm_storeu_ps((float*)re, simdreg.re); + _mm_storeu_ps((float*)im, simdreg.im); #else /*HAVE_NEON*/ #ifdef HAVE_NEON - vst1q_f32((float *) re, simdreg.val[0]); - vst1q_f32((float *) im, simdreg.val[1]); + vst1q_f32((float*)re, simdreg.val[0]); + vst1q_f32((float*)im, simdreg.val[1]); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ } -static inline simd_f_t srslte_simd_cf_re(simd_cf_t in) { +static inline simd_f_t srslte_simd_cf_re(simd_cf_t in) +{ #ifdef HAVE_NEON simd_f_t out = in.val[0]; #else - simd_f_t out = in.re; + simd_f_t out = in.re; #endif /*HAVE_NEON*/ #ifndef LV_HAVE_AVX512 #ifdef LV_HAVE_AVX2 /* Permute for AVX registers (mis SSE registers) */ const __m256i idx = _mm256_setr_epi32(0, 2, 4, 6, 1, 3, 5, 7); - out = _mm256_permutevar8x32_ps(out, idx); + out = _mm256_permutevar8x32_ps(out, idx); #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ return out; @@ -790,23 +827,24 @@ static inline simd_f_t srslte_simd_cf_im(simd_cf_t in) return out; } -static inline simd_cf_t srslte_simd_cf_set1 (cf_t x) { +static inline simd_cf_t srslte_simd_cf_set1(cf_t x) +{ simd_cf_t ret; #ifdef LV_HAVE_AVX512 ret.re = _mm512_set1_ps(__real__ x); ret.im = _mm512_set1_ps(__imag__ x); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - ret.re = _mm256_set1_ps(__real__ x); - ret.im = _mm256_set1_ps(__imag__ x); + ret.re = _mm256_set1_ps(__real__ x); + ret.im = _mm256_set1_ps(__imag__ x); #else #ifdef LV_HAVE_SSE - ret.re = _mm_set1_ps(__real__ x); - ret.im = _mm_set1_ps(__imag__ x); + ret.re = _mm_set1_ps(__real__ x); + ret.im = _mm_set1_ps(__imag__ x); #else /*HAVE_NEON*/ #ifdef HAVE_NEON - ret.val[0] = vdupq_n_f32(__real__ x); - ret.val[1] = vdupq_n_f32(__imag__ x); + ret.val[0] = vdupq_n_f32(__real__ x); + ret.val[1] = vdupq_n_f32(__imag__ x); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ @@ -814,36 +852,29 @@ static inline simd_cf_t srslte_simd_cf_set1 (cf_t x) { return ret; } -static inline simd_cf_t srslte_simd_cf_prod (simd_cf_t a, simd_cf_t b) { +static inline simd_cf_t srslte_simd_cf_prod(simd_cf_t a, simd_cf_t b) +{ simd_cf_t ret; #ifdef LV_HAVE_AVX512 - ret.re = _mm512_sub_ps(_mm512_mul_ps(a.re, b.re), - _mm512_mul_ps(a.im, b.im)); - ret.im = _mm512_add_ps(_mm512_mul_ps(a.re, b.im), - _mm512_mul_ps(a.im, b.re)); + ret.re = _mm512_sub_ps(_mm512_mul_ps(a.re, b.re), _mm512_mul_ps(a.im, b.im)); + ret.im = _mm512_add_ps(_mm512_mul_ps(a.re, b.im), _mm512_mul_ps(a.im, b.re)); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 #ifdef LV_HAVE_FMA - ret.re = _mm256_fmsub_ps(a.re, b.re, _mm256_mul_ps(a.im, b.im)); - ret.im = _mm256_fmadd_ps(a.re, b.im, _mm256_mul_ps(a.im, b.re)); -#else /* LV_HAVE_FMA */ - ret.re = _mm256_sub_ps(_mm256_mul_ps(a.re, b.re), - _mm256_mul_ps(a.im, b.im)); - ret.im = _mm256_add_ps(_mm256_mul_ps(a.re, b.im), - _mm256_mul_ps(a.im, b.re)); + ret.re = _mm256_fmsub_ps(a.re, b.re, _mm256_mul_ps(a.im, b.im)); + ret.im = _mm256_fmadd_ps(a.re, b.im, _mm256_mul_ps(a.im, b.re)); +#else /* LV_HAVE_FMA */ + ret.re = _mm256_sub_ps(_mm256_mul_ps(a.re, b.re), _mm256_mul_ps(a.im, b.im)); + ret.im = _mm256_add_ps(_mm256_mul_ps(a.re, b.im), _mm256_mul_ps(a.im, b.re)); #endif /* LV_HAVE_FMA */ #else #ifdef LV_HAVE_SSE - ret.re = _mm_sub_ps(_mm_mul_ps(a.re, b.re), - _mm_mul_ps(a.im, b.im)); - ret.im = _mm_add_ps(_mm_mul_ps(a.re, b.im), - _mm_mul_ps(a.im, b.re)); + ret.re = _mm_sub_ps(_mm_mul_ps(a.re, b.re), _mm_mul_ps(a.im, b.im)); + ret.im = _mm_add_ps(_mm_mul_ps(a.re, b.im), _mm_mul_ps(a.im, b.re)); #else #ifdef HAVE_NEON - ret.val[0] = vsubq_f32(vmulq_f32(a.val[0],b.val[0]), - vmulq_f32(a.val[1],b.val[1])); - ret.val[1] = vaddq_f32(vmulq_f32(a.val[0],b.val[1]), - vmulq_f32(a.val[1],b.val[0])); + ret.val[0] = vsubq_f32(vmulq_f32(a.val[0], b.val[0]), vmulq_f32(a.val[1], b.val[1])); + ret.val[1] = vaddq_f32(vmulq_f32(a.val[0], b.val[1]), vmulq_f32(a.val[1], b.val[0])); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ @@ -851,31 +882,24 @@ static inline simd_cf_t srslte_simd_cf_prod (simd_cf_t a, simd_cf_t b) { return ret; } -static inline simd_cf_t srslte_simd_cf_conjprod (simd_cf_t a, simd_cf_t b) { +static inline simd_cf_t srslte_simd_cf_conjprod(simd_cf_t a, simd_cf_t b) +{ simd_cf_t ret; #ifdef LV_HAVE_AVX512 - ret.re = _mm512_add_ps(_mm512_mul_ps(a.re, b.re), - _mm512_mul_ps(a.im, b.im)); - ret.im = _mm512_sub_ps(_mm512_mul_ps(a.im, b.re), - _mm512_mul_ps(a.re, b.im)); + ret.re = _mm512_add_ps(_mm512_mul_ps(a.re, b.re), _mm512_mul_ps(a.im, b.im)); + ret.im = _mm512_sub_ps(_mm512_mul_ps(a.im, b.re), _mm512_mul_ps(a.re, b.im)); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - ret.re = _mm256_add_ps(_mm256_mul_ps(a.re, b.re), - _mm256_mul_ps(a.im, b.im)); - ret.im = _mm256_sub_ps(_mm256_mul_ps(a.im, b.re), - _mm256_mul_ps(a.re, b.im)); + ret.re = _mm256_add_ps(_mm256_mul_ps(a.re, b.re), _mm256_mul_ps(a.im, b.im)); + ret.im = _mm256_sub_ps(_mm256_mul_ps(a.im, b.re), _mm256_mul_ps(a.re, b.im)); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - ret.re = _mm_add_ps(_mm_mul_ps(a.re, b.re), - _mm_mul_ps(a.im, b.im)); - ret.im = _mm_sub_ps(_mm_mul_ps(a.im, b.re), - _mm_mul_ps(a.re, b.im)); + ret.re = _mm_add_ps(_mm_mul_ps(a.re, b.re), _mm_mul_ps(a.im, b.im)); + ret.im = _mm_sub_ps(_mm_mul_ps(a.im, b.re), _mm_mul_ps(a.re, b.im)); #else #ifdef HAVE_NEON - ret.val[0] = vaddq_f32(vmulq_f32(a.val[0],b.val[0]), - vmulq_f32(a.val[1],b.val[1])); - ret.val[1] = vsubq_f32(vmulq_f32(a.val[1],b.val[0]), - vmulq_f32(a.val[0],b.val[1])); + ret.val[0] = vaddq_f32(vmulq_f32(a.val[0], b.val[0]), vmulq_f32(a.val[1], b.val[1])); + ret.val[1] = vsubq_f32(vmulq_f32(a.val[1], b.val[0]), vmulq_f32(a.val[0], b.val[1])); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ @@ -883,23 +907,24 @@ static inline simd_cf_t srslte_simd_cf_conjprod (simd_cf_t a, simd_cf_t b) { return ret; } -static inline simd_cf_t srslte_simd_cf_add (simd_cf_t a, simd_cf_t b) { +static inline simd_cf_t srslte_simd_cf_add(simd_cf_t a, simd_cf_t b) +{ simd_cf_t ret; #ifdef LV_HAVE_AVX512 ret.re = _mm512_add_ps(a.re, b.re); ret.im = _mm512_add_ps(a.im, b.im); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - ret.re = _mm256_add_ps(a.re, b.re); - ret.im = _mm256_add_ps(a.im, b.im); + ret.re = _mm256_add_ps(a.re, b.re); + ret.im = _mm256_add_ps(a.im, b.im); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - ret.re = _mm_add_ps(a.re, b.re); - ret.im = _mm_add_ps(a.im, b.im); + ret.re = _mm_add_ps(a.re, b.re); + ret.im = _mm_add_ps(a.im, b.im); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON - ret.val[0] = vaddq_f32(a.val[0],b.val[0]); - ret.val[1] = vaddq_f32(a.val[1],b.val[1]); + ret.val[0] = vaddq_f32(a.val[0], b.val[0]); + ret.val[1] = vaddq_f32(a.val[1], b.val[1]); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ @@ -907,23 +932,24 @@ static inline simd_cf_t srslte_simd_cf_add (simd_cf_t a, simd_cf_t b) { return ret; } -static inline simd_cf_t srslte_simd_cf_sub (simd_cf_t a, simd_cf_t b) { +static inline simd_cf_t srslte_simd_cf_sub(simd_cf_t a, simd_cf_t b) +{ simd_cf_t ret; #ifdef LV_HAVE_AVX512 ret.re = _mm512_sub_ps(a.re, b.re); ret.im = _mm512_sub_ps(a.im, b.im); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - ret.re = _mm256_sub_ps(a.re, b.re); - ret.im = _mm256_sub_ps(a.im, b.im); + ret.re = _mm256_sub_ps(a.re, b.re); + ret.im = _mm256_sub_ps(a.im, b.im); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - ret.re = _mm_sub_ps(a.re, b.re); - ret.im = _mm_sub_ps(a.im, b.im); + ret.re = _mm_sub_ps(a.re, b.re); + ret.im = _mm_sub_ps(a.im, b.im); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON - ret.val[0] = vsubq_f32(a.val[0],b.val[0]); - ret.val[1] = vsubq_f32(a.val[1],b.val[1]); + ret.val[0] = vsubq_f32(a.val[0], b.val[0]); + ret.val[1] = vsubq_f32(a.val[1], b.val[1]); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ @@ -931,24 +957,25 @@ static inline simd_cf_t srslte_simd_cf_sub (simd_cf_t a, simd_cf_t b) { return ret; } -static inline simd_cf_t srslte_simd_cf_mul (simd_cf_t a, simd_f_t b) { +static inline simd_cf_t srslte_simd_cf_mul(simd_cf_t a, simd_f_t b) +{ simd_cf_t ret; #ifdef LV_HAVE_AVX512 ret.re = _mm512_mul_ps(a.re, b); ret.im = _mm512_mul_ps(a.im, b); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - b = _mm256_permutevar8x32_ps(b, _mm256_setr_epi32(0,4,1,5,2,6,3,7)); - ret.re = _mm256_mul_ps(a.re, b); - ret.im = _mm256_mul_ps(a.im, b); + b = _mm256_permutevar8x32_ps(b, _mm256_setr_epi32(0, 4, 1, 5, 2, 6, 3, 7)); + ret.re = _mm256_mul_ps(a.re, b); + ret.im = _mm256_mul_ps(a.im, b); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - ret.re = _mm_mul_ps(a.re, b); - ret.im = _mm_mul_ps(a.im, b); + ret.re = _mm_mul_ps(a.re, b); + ret.im = _mm_mul_ps(a.im, b); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON - ret.val[0] = vmulq_f32(a.val[0],b); - ret.val[1] = vmulq_f32(a.val[1],b); + ret.val[0] = vmulq_f32(a.val[0], b); + ret.val[1] = vmulq_f32(a.val[1], b); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ @@ -956,43 +983,44 @@ static inline simd_cf_t srslte_simd_cf_mul (simd_cf_t a, simd_f_t b) { return ret; } -static inline simd_cf_t srslte_simd_cf_rcp (simd_cf_t a) { +static inline simd_cf_t srslte_simd_cf_rcp(simd_cf_t a) +{ simd_cf_t ret; #ifdef LV_HAVE_AVX512 - simd_f_t a2re = _mm512_mul_ps(a.re, a.re); - simd_f_t a2im = _mm512_mul_ps(a.im, a.im); - simd_f_t mod2 = _mm512_add_ps(a2re, a2im); - simd_f_t rcp = _mm512_rcp14_ps(mod2); + simd_f_t a2re = _mm512_mul_ps(a.re, a.re); + simd_f_t a2im = _mm512_mul_ps(a.im, a.im); + simd_f_t mod2 = _mm512_add_ps(a2re, a2im); + simd_f_t rcp = _mm512_rcp14_ps(mod2); simd_f_t neg_a_im = _mm512_xor_ps(_mm512_set1_ps(-0.0f), a.im); - ret.re = _mm512_mul_ps(a.re, rcp); - ret.im = _mm512_mul_ps(neg_a_im, rcp); + ret.re = _mm512_mul_ps(a.re, rcp); + ret.im = _mm512_mul_ps(neg_a_im, rcp); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - simd_f_t a2re = _mm256_mul_ps(a.re, a.re); - simd_f_t a2im = _mm256_mul_ps(a.im, a.im); - simd_f_t mod2 = _mm256_add_ps(a2re, a2im); - simd_f_t rcp = _mm256_rcp_ps(mod2); + simd_f_t a2re = _mm256_mul_ps(a.re, a.re); + simd_f_t a2im = _mm256_mul_ps(a.im, a.im); + simd_f_t mod2 = _mm256_add_ps(a2re, a2im); + simd_f_t rcp = _mm256_rcp_ps(mod2); simd_f_t neg_a_im = _mm256_xor_ps(_mm256_set1_ps(-0.0f), a.im); - ret.re = _mm256_mul_ps(a.re, rcp); - ret.im = _mm256_mul_ps(neg_a_im, rcp); + ret.re = _mm256_mul_ps(a.re, rcp); + ret.im = _mm256_mul_ps(neg_a_im, rcp); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - simd_f_t a2re = _mm_mul_ps(a.re, a.re); - simd_f_t a2im = _mm_mul_ps(a.im, a.im); - simd_f_t mod2 = _mm_add_ps(a2re, a2im); - simd_f_t rcp = _mm_rcp_ps(mod2); + simd_f_t a2re = _mm_mul_ps(a.re, a.re); + simd_f_t a2im = _mm_mul_ps(a.im, a.im); + simd_f_t mod2 = _mm_add_ps(a2re, a2im); + simd_f_t rcp = _mm_rcp_ps(mod2); simd_f_t neg_a_im = _mm_xor_ps(_mm_set1_ps(-0.0f), a.im); - ret.re = _mm_mul_ps(a.re, rcp); - ret.im = _mm_mul_ps(neg_a_im, rcp); - #else /* LV_HAVE_SSE */ -#ifdef HAVE_NEON - simd_f_t a2re = vmulq_f32(a.val[0], a.val[0]); - simd_f_t a2im = vmulq_f32(a.val[1], a.val[1]); - simd_f_t mod2 = vaddq_f32(a2re, a2im); - simd_f_t rcp = vmulq_f32(vrecpeq_f32(mod2), vrecpsq_f32(vrecpeq_f32(mod2), mod2)); + ret.re = _mm_mul_ps(a.re, rcp); + ret.im = _mm_mul_ps(neg_a_im, rcp); +#else /* LV_HAVE_SSE */ +#ifdef HAVE_NEON + simd_f_t a2re = vmulq_f32(a.val[0], a.val[0]); + simd_f_t a2im = vmulq_f32(a.val[1], a.val[1]); + simd_f_t mod2 = vaddq_f32(a2re, a2im); + simd_f_t rcp = vmulq_f32(vrecpeq_f32(mod2), vrecpsq_f32(vrecpeq_f32(mod2), mod2)); simd_f_t neg_a_im = vnegq_f32(a.val[1]); - ret.val[0] = vmulq_f32(a.val[0], rcp); - ret.val[1] = vmulq_f32(neg_a_im, rcp); + ret.val[0] = vmulq_f32(a.val[0], rcp); + ret.val[1] = vmulq_f32(neg_a_im, rcp); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ @@ -1000,76 +1028,81 @@ static inline simd_cf_t srslte_simd_cf_rcp (simd_cf_t a) { return ret; } -static inline simd_cf_t srslte_simd_cf_neg (simd_cf_t a) { +static inline simd_cf_t srslte_simd_cf_neg(simd_cf_t a) +{ simd_cf_t ret; #if HAVE_NEON ret.val[0] = srslte_simd_f_neg(a.val[0]); ret.val[1] = srslte_simd_f_neg(a.val[1]); #else /* HAVE_NEON */ - ret.re = srslte_simd_f_neg(a.re); - ret.im = srslte_simd_f_neg(a.im); + ret.re = srslte_simd_f_neg(a.re); + ret.im = srslte_simd_f_neg(a.im); #endif /* HAVE_NEON */ return ret; } -static inline simd_cf_t srslte_simd_cf_neg_mask (simd_cf_t a, simd_f_t mask) { +static inline simd_cf_t srslte_simd_cf_neg_mask(simd_cf_t a, simd_f_t mask) +{ simd_cf_t ret; #ifndef LV_HAVE_AVX512 #ifdef LV_HAVE_AVX2 - mask = _mm256_permutevar8x32_ps(mask, _mm256_setr_epi32(0,4,1,5,2,6,3,7)); + mask = _mm256_permutevar8x32_ps(mask, _mm256_setr_epi32(0, 4, 1, 5, 2, 6, 3, 7)); #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ #if HAVE_NEON ret.val[0] = srslte_simd_f_neg_mask(a.val[0], mask); ret.val[1] = srslte_simd_f_neg_mask(a.val[1], mask); -#else /* HAVE_NEON */ - ret.re = srslte_simd_f_neg_mask(a.re, mask); - ret.im = srslte_simd_f_neg_mask(a.im, mask); +#else /* HAVE_NEON */ + ret.re = srslte_simd_f_neg_mask(a.re, mask); + ret.im = srslte_simd_f_neg_mask(a.im, mask); #endif /* HAVE_NEON */ return ret; } -static inline simd_cf_t srslte_simd_cf_conj (simd_cf_t a) { +static inline simd_cf_t srslte_simd_cf_conj(simd_cf_t a) +{ simd_cf_t ret; #if HAVE_NEON ret.val[0] = a.val[0]; ret.val[1] = srslte_simd_f_neg(a.val[1]); -#else /* HAVE_NEON */ - ret.re = a.re; - ret.im = srslte_simd_f_neg(a.im); +#else /* HAVE_NEON */ + ret.re = a.re; + ret.im = srslte_simd_f_neg(a.im); #endif /* HAVE_NEON */ return ret; } -static inline simd_cf_t srslte_simd_cf_mulj (simd_cf_t a) { +static inline simd_cf_t srslte_simd_cf_mulj(simd_cf_t a) +{ simd_cf_t ret; #if HAVE_NEON ret.val[0] = srslte_simd_f_neg(a.val[1]); ret.val[1] = a.val[0]; -#else /* HAVE_NEON */ - ret.re = srslte_simd_f_neg(a.im); - ret.im = a.re; +#else /* HAVE_NEON */ + ret.re = srslte_simd_f_neg(a.im); + ret.im = a.re; #endif /* HAVE_NEON */ return ret; } -static inline simd_cf_t srslte_simd_cf_zero (void) { +static inline simd_cf_t srslte_simd_cf_zero(void) +{ simd_cf_t ret; #ifdef LV_HAVE_AVX512 ret.re = _mm512_setzero_ps(); ret.im = _mm512_setzero_ps(); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - ret.re = _mm256_setzero_ps(); - ret.im = _mm256_setzero_ps(); + ret.re = _mm256_setzero_ps(); + ret.im = _mm256_setzero_ps(); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - ret.re = _mm_setzero_ps(); - ret.im = _mm_setzero_ps(); + ret.re = _mm_setzero_ps(); + ret.im = _mm_setzero_ps(); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON - ret.val[0] = vdupq_n_f32(0); - ret.val[1] = vdupq_n_f32(0); + ret.val[0] = vdupq_n_f32(0); + ret.val[1] = vdupq_n_f32(0); #endif /* HAVE_NEON */ #endif /* HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ @@ -1082,16 +1115,16 @@ static inline simd_cf_t srslte_simd_cf_zero (void) { #if SRSLTE_SIMD_I_SIZE #ifdef LV_HAVE_AVX512 -typedef __m512i simd_i_t; +typedef __m512i simd_i_t; typedef __mmask16 simd_sel_t; #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 typedef __m256i simd_i_t; -typedef __m256 simd_sel_t; +typedef __m256 simd_sel_t; #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE typedef __m128i simd_i_t; -typedef __m128 simd_sel_t; +typedef __m128 simd_sel_t; #else /* LV_HAVE_AVX2 */ #ifdef HAVE_NEON typedef int32x4_t simd_i_t; @@ -1101,7 +1134,8 @@ typedef int32x4_t simd_sel_t; #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ -static inline simd_i_t srslte_simd_i_load(int *x) { +static inline simd_i_t srslte_simd_i_load(int* x) +{ #ifdef LV_HAVE_AVX512 return _mm512_load_epi32((__m512i*)x); #else /* LV_HAVE_AVX512 */ @@ -1119,7 +1153,8 @@ static inline simd_i_t srslte_simd_i_load(int *x) { #endif /* LV_HAVE_AVX512 */ } -static inline void srslte_simd_i_store(int *x, simd_i_t reg) { +static inline void srslte_simd_i_store(int* x, simd_i_t reg) +{ #ifdef LV_HAVE_AVX512 _mm512_store_epi32((__m512i*)x, reg); #else /* LV_HAVE_AVX512 */ @@ -1137,7 +1172,8 @@ static inline void srslte_simd_i_store(int *x, simd_i_t reg) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_i_t srslte_simd_i_set1(int x) { +static inline simd_i_t srslte_simd_i_set1(int x) +{ #ifdef LV_HAVE_AVX512 return _mm512_set1_epi32(x); #else /* LV_HAVE_AVX512 */ @@ -1155,7 +1191,8 @@ static inline simd_i_t srslte_simd_i_set1(int x) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_i_t srslte_simd_i_add(simd_i_t a, simd_i_t b) { +static inline simd_i_t srslte_simd_i_add(simd_i_t a, simd_i_t b) +{ #ifdef LV_HAVE_AVX512 return _mm512_add_epi32(a, b); #else /* LV_HAVE_AVX512 */ @@ -1173,7 +1210,8 @@ static inline simd_i_t srslte_simd_i_add(simd_i_t a, simd_i_t b) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_sel_t srslte_simd_f_max(simd_f_t a, simd_f_t b) { +static inline simd_sel_t srslte_simd_f_max(simd_f_t a, simd_f_t b) +{ #ifdef LV_HAVE_AVX512 return _mm512_cmp_ps_mask(a, b, _CMP_GT_OS); #else /* LV_HAVE_AVX512 */ @@ -1181,53 +1219,51 @@ static inline simd_sel_t srslte_simd_f_max(simd_f_t a, simd_f_t b) { return _mm256_cmp_ps(a, b, _CMP_GT_OS); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - return (simd_sel_t) _mm_cmpgt_ps(a, b); + return (simd_sel_t)_mm_cmpgt_ps(a, b); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON - return (simd_sel_t) vcgtq_f32(a, b); + return (simd_sel_t)vcgtq_f32(a, b); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ } -static inline simd_i_t srslte_simd_i_select(simd_i_t a, simd_i_t b, simd_sel_t selector) { +static inline simd_i_t srslte_simd_i_select(simd_i_t a, simd_i_t b, simd_sel_t selector) +{ #ifdef LV_HAVE_AVX512 - return (__m512i) _mm512_mask_blend_ps( selector, (__m512)a, (__m512) b); + return (__m512i)_mm512_mask_blend_ps(selector, (__m512)a, (__m512)b); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - return (__m256i) _mm256_blendv_ps((__m256) a,(__m256) b, selector); + return (__m256i)_mm256_blendv_ps((__m256)a, (__m256)b, selector); #else #ifdef LV_HAVE_SSE - return (__m128i) _mm_blendv_ps((__m128)a, (__m128)b, selector); -#else /* LV_HAVE_SSE */ + return (__m128i)_mm_blendv_ps((__m128)a, (__m128)b, selector); +#else /* LV_HAVE_SSE */ #ifdef HAVE_NEON // CURRENTLY USES GENERIC IMPLEMENTATION FOR NEON - int* a_ptr = (int*) &a; - int* b_ptr = (int*) &b; - simd_i_t ret; - int* sel = (int*) &selector; - int* c_ptr = (int*) &ret; - for(int i = 0;i<4;i++) - { - if(sel[i] == -1){ - c_ptr[i] = b_ptr[i]; - }else{ - c_ptr[i] = a_ptr[i]; - } - } + int* a_ptr = (int*)&a; + int* b_ptr = (int*)&b; + simd_i_t ret; + int* sel = (int*)&selector; + int* c_ptr = (int*)&ret; + for (int i = 0; i < 4; i++) { + if (sel[i] == -1) { + c_ptr[i] = b_ptr[i]; + } else { + c_ptr[i] = a_ptr[i]; + } + } return ret; -#endif /* HAVE_NEON */ -#endif /* LV_HAVE_SSE */ -#endif /* LV_HAVE_AVX2 */ -#endif /* LV_HAVE_AVX512 */ +#endif /* HAVE_NEON */ +#endif /* LV_HAVE_SSE */ +#endif /* LV_HAVE_AVX2 */ +#endif /* LV_HAVE_AVX512 */ } #endif /* SRSLTE_SIMD_I_SIZE*/ - #if SRSLTE_SIMD_S_SIZE - #ifdef LV_HAVE_AVX512 typedef __m512i simd_s_t; #else /* LV_HAVE_AVX512 */ @@ -1244,15 +1280,16 @@ typedef int16x8_t simd_s_t; #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ -static inline simd_s_t srslte_simd_s_load(const int16_t *ptr) { +static inline simd_s_t srslte_simd_s_load(const int16_t* ptr) +{ #ifdef LV_HAVE_AVX512 return _mm512_load_si512(ptr); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - return _mm256_load_si256((__m256i*) ptr); + return _mm256_load_si256((__m256i*)ptr); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - return _mm_load_si128((__m128i*) ptr); + return _mm_load_si128((__m128i*)ptr); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON return vld1q_s16(ptr); @@ -1262,15 +1299,16 @@ static inline simd_s_t srslte_simd_s_load(const int16_t *ptr) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_s_t srslte_simd_s_loadu(const int16_t *ptr) { +static inline simd_s_t srslte_simd_s_loadu(const int16_t* ptr) +{ #ifdef LV_HAVE_AVX512 return _mm512_loadu_si512(ptr); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - return _mm256_loadu_si256((__m256i*) ptr); + return _mm256_loadu_si256((__m256i*)ptr); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - return _mm_loadu_si128((__m128i*) ptr); + return _mm_loadu_si128((__m128i*)ptr); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON return vld1q_s16(ptr); @@ -1280,33 +1318,35 @@ static inline simd_s_t srslte_simd_s_loadu(const int16_t *ptr) { #endif /* LV_HAVE_AVX512 */ } -static inline void srslte_simd_s_store(int16_t *ptr, simd_s_t simdreg) { +static inline void srslte_simd_s_store(int16_t* ptr, simd_s_t simdreg) +{ #ifdef LV_HAVE_AVX512 _mm512_store_si512(ptr, simdreg); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - _mm256_store_si256((__m256i*) ptr, simdreg); + _mm256_store_si256((__m256i*)ptr, simdreg); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - _mm_store_si128((__m128i*) ptr, simdreg); + _mm_store_si128((__m128i*)ptr, simdreg); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON - vst1q_s16( ptr, simdreg); + vst1q_s16(ptr, simdreg); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ } -static inline void srslte_simd_s_storeu(int16_t *ptr, simd_s_t simdreg) { +static inline void srslte_simd_s_storeu(int16_t* ptr, simd_s_t simdreg) +{ #ifdef LV_HAVE_AVX512 _mm512_storeu_si512(ptr, simdreg); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - _mm256_storeu_si256((__m256i*) ptr, simdreg); + _mm256_storeu_si256((__m256i*)ptr, simdreg); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - _mm_storeu_si128((__m128i*) ptr, simdreg); + _mm_storeu_si128((__m128i*)ptr, simdreg); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON vst1q_s16(ptr, simdreg); @@ -1315,7 +1355,8 @@ static inline void srslte_simd_s_storeu(int16_t *ptr, simd_s_t simdreg) { #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ } -static inline simd_s_t srslte_simd_s_zero(void) { +static inline simd_s_t srslte_simd_s_zero(void) +{ #ifdef LV_HAVE_AVX512 return _mm512_setzero_si512(); #else /* LV_HAVE_AVX512 */ @@ -1333,7 +1374,8 @@ static inline simd_s_t srslte_simd_s_zero(void) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_s_t srslte_simd_s_mul(simd_s_t a, simd_s_t b) { +static inline simd_s_t srslte_simd_s_mul(simd_s_t a, simd_s_t b) +{ #ifdef LV_HAVE_AVX512 return _mm512_mullo_epi16(a, b); #else /* LV_HAVE_AVX512 */ @@ -1351,7 +1393,8 @@ static inline simd_s_t srslte_simd_s_mul(simd_s_t a, simd_s_t b) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_s_t srslte_simd_s_neg(simd_s_t a, simd_s_t b) { +static inline simd_s_t srslte_simd_s_neg(simd_s_t a, simd_s_t b) +{ #ifdef LV_HAVE_AVX512 __m256i a0 = _mm512_extracti64x4_epi64(a, 0); __m256i a1 = _mm512_extracti64x4_epi64(a, 1); @@ -1364,7 +1407,7 @@ static inline simd_s_t srslte_simd_s_neg(simd_s_t a, simd_s_t b) { #ifdef LV_HAVE_AVX2 return _mm256_sign_epi16(a, b); #else /* LV_HAVE_AVX2 */ - #ifdef LV_HAVE_SSE +#ifdef LV_HAVE_SSE return _mm_sign_epi16(a, b); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON @@ -1377,7 +1420,8 @@ static inline simd_s_t srslte_simd_s_neg(simd_s_t a, simd_s_t b) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_s_t srslte_simd_s_add(simd_s_t a, simd_s_t b) { +static inline simd_s_t srslte_simd_s_add(simd_s_t a, simd_s_t b) +{ #ifdef LV_HAVE_AVX512 return _mm512_add_epi16(a, b); #else /* LV_HAVE_AVX512 */ @@ -1395,7 +1439,8 @@ static inline simd_s_t srslte_simd_s_add(simd_s_t a, simd_s_t b) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_s_t srslte_simd_s_sub(simd_s_t a, simd_s_t b) { +static inline simd_s_t srslte_simd_s_sub(simd_s_t a, simd_s_t b) +{ #ifdef LV_HAVE_AVX512 return _mm512_sub_epi16(a, b); #else /* LV_HAVE_AVX512 */ @@ -1415,76 +1460,80 @@ static inline simd_s_t srslte_simd_s_sub(simd_s_t a, simd_s_t b) { #endif /* SRSLTE_SIMD_S_SIZE */ - #if SRSLTE_SIMD_C16_SIZE -typedef +typedef #ifdef LV_HAVE_AVX512 - struct { - union { - __m512i m512; - int16_t i16[32]; - } re; - union { - __m512i m512; - int16_t i16[32]; - } im; + struct { + union { + __m512i m512; + int16_t i16[32]; + } re; + union { + __m512i m512; + int16_t i16[32]; + } im; #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - struct { - union { - __m256i m256; - int16_t i16[16]; - } re; - union { - __m256i m256; - int16_t i16[16]; - } im; + struct { + union { + __m256i m256; + int16_t i16[16]; + } re; + union { + __m256i m256; + int16_t i16[16]; + } im; #else #ifdef LV_HAVE_SSE - struct { - union { - __m128i m128; - int16_t i16[8]; - } re; - union { - __m128i m128; - int16_t i16[8]; - } im; + struct { + union { + __m128i m128; + int16_t i16[8]; + } re; + union { + __m128i m128; + int16_t i16[8]; + } im; #else #ifdef HAVE_NEON - union { - int16x8x2_t m128; - int16_t i16[16]; -#endif /* HAVE_NEON */ + union { + int16x8x2_t m128; + int16_t i16[16]; +#endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ } simd_c16_t; /* Fixed point precision (16-bit) functions */ -static inline simd_c16_t srslte_simd_c16i_load(const c16_t *ptr) { +static inline simd_c16_t srslte_simd_c16i_load(const c16_t* ptr) +{ simd_c16_t ret; #ifdef LV_HAVE_AVX512 __m512i in1 = _mm512_load_si512((__m512i*)(ptr)); __m512i in2 = _mm512_load_si512((__m512i*)(ptr + 8)); - ret.re.m512 = _mm512_mask_blend_epi16(0xAAAAAAAA, in1,_mm512_shufflelo_epi16(_mm512_shufflehi_epi16(in2, 0b10100000), 0b10100000)); - ret.im.m512 = _mm512_mask_blend_epi16(0xAAAAAAAA, _mm512_shufflelo_epi16(_mm512_shufflehi_epi16(in1, 0b11110101), 0b11110101),in2); + ret.re.m512 = _mm512_mask_blend_epi16( + 0xAAAAAAAA, in1, _mm512_shufflelo_epi16(_mm512_shufflehi_epi16(in2, 0b10100000), 0b10100000)); + ret.im.m512 = _mm512_mask_blend_epi16( + 0xAAAAAAAA, _mm512_shufflelo_epi16(_mm512_shufflehi_epi16(in1, 0b11110101), 0b11110101), in2); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_AVX2 __m256i in1 = _mm256_load_si256((__m256i*)(ptr)); __m256i in2 = _mm256_load_si256((__m256i*)(ptr + 8)); - ret.re.m256 = _mm256_blend_epi16(in1,_mm256_shufflelo_epi16(_mm256_shufflehi_epi16(in2, 0b10100000), 0b10100000), 0b10101010); - ret.im.m256 = _mm256_blend_epi16(_mm256_shufflelo_epi16(_mm256_shufflehi_epi16(in1, 0b11110101), 0b11110101),in2, 0b10101010); + ret.re.m256 = + _mm256_blend_epi16(in1, _mm256_shufflelo_epi16(_mm256_shufflehi_epi16(in2, 0b10100000), 0b10100000), 0b10101010); + ret.im.m256 = + _mm256_blend_epi16(_mm256_shufflelo_epi16(_mm256_shufflehi_epi16(in1, 0b11110101), 0b11110101), in2, 0b10101010); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE __m128i in1 = _mm_load_si128((__m128i*)(ptr)); __m128i in2 = _mm_load_si128((__m128i*)(ptr + 8)); - ret.re.m128 = _mm_blend_epi16(in1,_mm_shufflelo_epi16(_mm_shufflehi_epi16(in2, 0b10100000), 0b10100000), 0b10101010); - ret.im.m128 = _mm_blend_epi16(_mm_shufflelo_epi16(_mm_shufflehi_epi16(in1, 0b11110101), 0b11110101),in2, 0b10101010); + ret.re.m128 = _mm_blend_epi16(in1, _mm_shufflelo_epi16(_mm_shufflehi_epi16(in2, 0b10100000), 0b10100000), 0b10101010); + ret.im.m128 = _mm_blend_epi16(_mm_shufflelo_epi16(_mm_shufflehi_epi16(in1, 0b11110101), 0b11110101), in2, 0b10101010); #else /* LV_HAVE_SSE*/ #ifdef HAVE_NEON - ret.m128 = vld2q_s16((int16_t*)(ptr)); + ret.m128 = vld2q_s16((int16_t*)(ptr)); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ @@ -1492,15 +1541,16 @@ static inline simd_c16_t srslte_simd_c16i_load(const c16_t *ptr) { return ret; } -static inline simd_c16_t srslte_simd_c16_load(const int16_t *re, const int16_t *im) { +static inline simd_c16_t srslte_simd_c16_load(const int16_t* re, const int16_t* im) +{ simd_c16_t ret; #ifdef LV_HAVE_AVX2 ret.re.m256 = _mm256_load_si256((__m256i*)(re)); ret.im.m256 = _mm256_load_si256((__m256i*)(im)); #else #ifdef LV_HAVE_SSE - ret.re.m128 = _mm_load_si128((__m128i*)(re)); - ret.im.m128 = _mm_load_si128((__m128i*)(im)); + ret.re.m128 = _mm_load_si128((__m128i*)(re)); + ret.im.m128 = _mm_load_si128((__m128i*)(im)); #else /* LV_HAVE_SSE*/ #ifdef HAVE_NEON ret.m128.val[0] = vld1q_s16((int16_t*)(re)); @@ -1511,15 +1561,16 @@ static inline simd_c16_t srslte_simd_c16_load(const int16_t *re, const int16_t * return ret; } -static inline simd_c16_t srslte_simd_c16_loadu(const int16_t *re, const int16_t *im) { +static inline simd_c16_t srslte_simd_c16_loadu(const int16_t* re, const int16_t* im) +{ simd_c16_t ret; #ifdef LV_HAVE_AVX2 ret.re.m256 = _mm256_loadu_si256((__m256i*)(re)); ret.im.m256 = _mm256_loadu_si256((__m256i*)(im)); #else #ifdef LV_HAVE_SSE - ret.re.m128 = _mm_loadu_si128((__m128i*)(re)); - ret.im.m128 = _mm_loadu_si128((__m128i*)(im)); + ret.re.m128 = _mm_loadu_si128((__m128i*)(re)); + ret.im.m128 = _mm_loadu_si128((__m128i*)(im)); #else /* LV_HAVE_SSE*/ #ifdef HAVE_NEON ret.m128.val[0] = vld1q_s16((int16_t*)(re)); @@ -1530,81 +1581,86 @@ static inline simd_c16_t srslte_simd_c16_loadu(const int16_t *re, const int16_t return ret; } -static inline void srslte_simd_c16i_store(c16_t *ptr, simd_c16_t simdreg) { +static inline void srslte_simd_c16i_store(c16_t* ptr, simd_c16_t simdreg) +{ #ifdef LV_HAVE_AVX2 __m256i re_sw = _mm256_shufflelo_epi16(_mm256_shufflehi_epi16(simdreg.re.m256, 0b10110001), 0b10110001); __m256i im_sw = _mm256_shufflelo_epi16(_mm256_shufflehi_epi16(simdreg.im.m256, 0b10110001), 0b10110001); - _mm256_store_si256((__m256i *) (ptr), _mm256_blend_epi16(simdreg.re.m256, im_sw, 0b10101010)); - _mm256_store_si256((__m256i *) (ptr + 8), _mm256_blend_epi16(re_sw, simdreg.im.m256, 0b10101010)); + _mm256_store_si256((__m256i*)(ptr), _mm256_blend_epi16(simdreg.re.m256, im_sw, 0b10101010)); + _mm256_store_si256((__m256i*)(ptr + 8), _mm256_blend_epi16(re_sw, simdreg.im.m256, 0b10101010)); #else #ifdef LV_HAVE_SSE __m128i re_sw = _mm_shufflelo_epi16(_mm_shufflehi_epi16(simdreg.re.m128, 0b10110001), 0b10110001); __m128i im_sw = _mm_shufflelo_epi16(_mm_shufflehi_epi16(simdreg.im.m128, 0b10110001), 0b10110001); - _mm_store_si128((__m128i *) (ptr), _mm_blend_epi16(simdreg.re.m128, im_sw, 0b10101010)); - _mm_store_si128((__m128i *) (ptr + 8), _mm_blend_epi16(re_sw, simdreg.im.m128, 0b10101010)); + _mm_store_si128((__m128i*)(ptr), _mm_blend_epi16(simdreg.re.m128, im_sw, 0b10101010)); + _mm_store_si128((__m128i*)(ptr + 8), _mm_blend_epi16(re_sw, simdreg.im.m128, 0b10101010)); #else /*HAVE_NEON*/ #ifdef HAVE_NEON - vst2q_s16((int16_t*)(ptr) ,simdreg.m128); + vst2q_s16((int16_t*)(ptr), simdreg.m128); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ } -static inline void srslte_simd_c16i_storeu(c16_t *ptr, simd_c16_t simdreg) { +static inline void srslte_simd_c16i_storeu(c16_t* ptr, simd_c16_t simdreg) +{ #ifdef LV_HAVE_AVX2 __m256i re_sw = _mm256_shufflelo_epi16(_mm256_shufflehi_epi16(simdreg.re.m256, 0b10110001), 0b10110001); __m256i im_sw = _mm256_shufflelo_epi16(_mm256_shufflehi_epi16(simdreg.im.m256, 0b10110001), 0b10110001); - _mm256_storeu_si256((__m256i *) (ptr), _mm256_blend_epi16(simdreg.re.m256, im_sw, 0b10101010)); - _mm256_storeu_si256((__m256i *) (ptr + 8), _mm256_blend_epi16(re_sw, simdreg.im.m256, 0b10101010)); + _mm256_storeu_si256((__m256i*)(ptr), _mm256_blend_epi16(simdreg.re.m256, im_sw, 0b10101010)); + _mm256_storeu_si256((__m256i*)(ptr + 8), _mm256_blend_epi16(re_sw, simdreg.im.m256, 0b10101010)); #else #ifdef LV_HAVE_SSE __m128i re_sw = _mm_shufflelo_epi16(_mm_shufflehi_epi16(simdreg.re.m128, 0b10110001), 0b10110001); __m128i im_sw = _mm_shufflelo_epi16(_mm_shufflehi_epi16(simdreg.im.m128, 0b10110001), 0b10110001); - _mm_storeu_si128((__m128i *) (ptr), _mm_blend_epi16(simdreg.re.m128, im_sw, 0b10101010)); - _mm_storeu_si128((__m128i *) (ptr + 8), _mm_blend_epi16(re_sw, simdreg.im.m128, 0b10101010)); + _mm_storeu_si128((__m128i*)(ptr), _mm_blend_epi16(simdreg.re.m128, im_sw, 0b10101010)); + _mm_storeu_si128((__m128i*)(ptr + 8), _mm_blend_epi16(re_sw, simdreg.im.m128, 0b10101010)); #else /*HAVE_NEON*/ #ifdef HAVE_NEON - vst2q_s16((int16_t*)(ptr) ,simdreg.m128); + vst2q_s16((int16_t*)(ptr), simdreg.m128); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ } -static inline void srslte_simd_c16_store(int16_t *re, int16_t *im, simd_c16_t simdreg) { +static inline void srslte_simd_c16_store(int16_t* re, int16_t* im, simd_c16_t simdreg) +{ #ifdef LV_HAVE_AVX2 - _mm256_store_si256((__m256i *) re, simdreg.re.m256); - _mm256_store_si256((__m256i *) im, simdreg.im.m256); + _mm256_store_si256((__m256i*)re, simdreg.re.m256); + _mm256_store_si256((__m256i*)im, simdreg.im.m256); #else #ifdef LV_HAVE_SSE - _mm_store_si128((__m128i *) re, simdreg.re.m128); - _mm_store_si128((__m128i *) im, simdreg.im.m128); + _mm_store_si128((__m128i*)re, simdreg.re.m128); + _mm_store_si128((__m128i*)im, simdreg.im.m128); #else #ifdef HAVE_NEON - vst1q_s16((int16_t *) re, simdreg.m128.val[0]); - vst1q_s16((int16_t *) im, simdreg.m128.val[1]); + vst1q_s16((int16_t*)re, simdreg.m128.val[0]); + vst1q_s16((int16_t*)im, simdreg.m128.val[1]); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ } -static inline void srslte_simd_c16_storeu(int16_t *re, int16_t *im, simd_c16_t simdreg) { +static inline void srslte_simd_c16_storeu(int16_t* re, int16_t* im, simd_c16_t simdreg) +{ #ifdef LV_HAVE_AVX2 - _mm256_storeu_si256((__m256i *) re, simdreg.re.m256); - _mm256_storeu_si256((__m256i *) im, simdreg.im.m256); + _mm256_storeu_si256((__m256i*)re, simdreg.re.m256); + _mm256_storeu_si256((__m256i*)im, simdreg.im.m256); #else #ifdef LV_HAVE_SSE - _mm_storeu_si128((__m128i *) re, simdreg.re.m128); - _mm_storeu_si128((__m128i *) im, simdreg.im.m128); + _mm_storeu_si128((__m128i*)re, simdreg.re.m128); + _mm_storeu_si128((__m128i*)im, simdreg.im.m128); #else #ifdef HAVE_NEON - vst1q_s16((int16_t *) re, simdreg.m128.val[0]); - vst1q_s16((int16_t *) im, simdreg.m128.val[1]); + vst1q_s16((int16_t*)re, simdreg.m128.val[0]); + vst1q_s16((int16_t*)im, simdreg.m128.val[1]); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ } -static inline simd_c16_t srslte_simd_c16_prod (simd_c16_t a, simd_c16_t b) { +static inline simd_c16_t srslte_simd_c16_prod(simd_c16_t a, simd_c16_t b) +{ simd_c16_t ret; #ifdef LV_HAVE_AVX2 ret.re.m256 = _mm256_sub_epi16(_mm256_mulhrs_epi16(a.re.m256, _mm256_slli_epi16(b.re.m256, 1)), @@ -1622,7 +1678,8 @@ static inline simd_c16_t srslte_simd_c16_prod (simd_c16_t a, simd_c16_t b) { return ret; } -static inline simd_c16_t srslte_simd_c16_add (simd_c16_t a, simd_c16_t b) { +static inline simd_c16_t srslte_simd_c16_add(simd_c16_t a, simd_c16_t b) +{ simd_c16_t ret; #ifdef LV_HAVE_AVX2 ret.re.m256 = _mm256_add_epi16(a.re.m256, b.re.m256); @@ -1633,15 +1690,16 @@ static inline simd_c16_t srslte_simd_c16_add (simd_c16_t a, simd_c16_t b) { ret.im.m128 = _mm_add_epi16(a.im.m128, b.im.m128); #else #ifdef HAVE_NEON - ret.m128.val[0] = vaddq_s16(a.m128.val[0],a.m128.val[0]); - ret.m128.val[1] = vaddq_s16(a.m128.val[1],a.m128.val[1]); + ret.m128.val[0] = vaddq_s16(a.m128.val[0], a.m128.val[0]); + ret.m128.val[1] = vaddq_s16(a.m128.val[1], a.m128.val[1]); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ return ret; } -static inline simd_c16_t srslte_simd_c16_zero (void) { +static inline simd_c16_t srslte_simd_c16_zero(void) +{ simd_c16_t ret; #ifdef LV_HAVE_AVX2 ret.re.m256 = _mm256_setzero_si256(); @@ -1664,32 +1722,33 @@ static inline simd_c16_t srslte_simd_c16_zero (void) { #if SRSLTE_SIMD_F_SIZE && SRSLTE_SIMD_S_SIZE -static inline simd_s_t srslte_simd_convert_2f_s(simd_f_t a, simd_f_t b) { +static inline simd_s_t srslte_simd_convert_2f_s(simd_f_t a, simd_f_t b) +{ #ifdef LV_HAVE_AVX512 - __m512 aa = _mm512_permutex2var_ps(a, _mm512_setr_epi32(0x00, 0x01, 0x02, 0x03, - 0x08, 0x09, 0x0A, 0x0B, - 0x10, 0x11, 0x12, 0x13, - 0x18, 0x19, 0x1A, 0x1B), b); - __m512 bb = _mm512_permutex2var_ps(a, _mm512_setr_epi32(0x04, 0x05, 0x06, 0x07, - 0x0C, 0x0D, 0x0E, 0x0F, - 0x14, 0x15, 0x16, 0x17, - 0x1C, 0x1D, 0x1E, 0x1F), b); + __m512 aa = _mm512_permutex2var_ps( + a, + _mm512_setr_epi32(0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13, 0x18, 0x19, 0x1A, 0x1B), + b); + __m512 bb = _mm512_permutex2var_ps( + a, + _mm512_setr_epi32(0x04, 0x05, 0x06, 0x07, 0x0C, 0x0D, 0x0E, 0x0F, 0x14, 0x15, 0x16, 0x17, 0x1C, 0x1D, 0x1E, 0x1F), + b); __m512i ai = _mm512_cvttps_epi32(aa); __m512i bi = _mm512_cvttps_epi32(bb); return _mm512_packs_epi32(ai, bi); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - __m256 aa = _mm256_permute2f128_ps(a, b, 0x20); - __m256 bb = _mm256_permute2f128_ps(a, b, 0x31); - __m256i ai = _mm256_cvttps_epi32(aa); - __m256i bi = _mm256_cvttps_epi32(bb); + __m256 aa = _mm256_permute2f128_ps(a, b, 0x20); + __m256 bb = _mm256_permute2f128_ps(a, b, 0x31); + __m256i ai = _mm256_cvttps_epi32(aa); + __m256i bi = _mm256_cvttps_epi32(bb); return _mm256_packs_epi32(ai, bi); #else #ifdef LV_HAVE_SSE - __m128i ai = _mm_cvttps_epi32(a); - __m128i bi = _mm_cvttps_epi32(b); + __m128i ai = _mm_cvttps_epi32(a); + __m128i bi = _mm_cvttps_epi32(b); return _mm_packs_epi32(ai, bi); - #else +#else #ifdef HAVE_NEON int32x4_t ai = vcvtq_s32_f32(a); int32x4_t bi = vcvtq_s32_f32(b); @@ -1720,17 +1779,16 @@ typedef int8x16_t simd_b_t; #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ - - -static inline simd_b_t srslte_simd_b_load(const int8_t *ptr){ +static inline simd_b_t srslte_simd_b_load(const int8_t* ptr) +{ #ifdef LV_HAVE_AVX512 return _mm512_load_si512(ptr); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - return _mm256_load_si256((__m256i*) ptr); + return _mm256_load_si256((__m256i*)ptr); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - return _mm_load_si128((__m128i*) ptr); + return _mm_load_si128((__m128i*)ptr); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON return vld1q_s8(ptr); @@ -1738,17 +1796,18 @@ static inline simd_b_t srslte_simd_b_load(const int8_t *ptr){ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ -} - -static inline simd_b_t srslte_simd_b_loadu(const int8_t *ptr){ +} + +static inline simd_b_t srslte_simd_b_loadu(const int8_t* ptr) +{ #ifdef LV_HAVE_AVX512 return _mm512_loadu_si512(ptr); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - return _mm256_loadu_si256((__m256i*) ptr); + return _mm256_loadu_si256((__m256i*)ptr); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - return _mm_loadu_si128((__m128i*) ptr); + return _mm_loadu_si128((__m128i*)ptr); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON return vld1q_s8(ptr); @@ -1758,33 +1817,35 @@ static inline simd_b_t srslte_simd_b_loadu(const int8_t *ptr){ #endif /* LV_HAVE_AVX512 */ } -static inline void srslte_simd_b_store(int8_t *ptr, simd_b_t simdreg) { +static inline void srslte_simd_b_store(int8_t* ptr, simd_b_t simdreg) +{ #ifdef LV_HAVE_AVX512 _mm512_store_si512(ptr, simdreg); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - _mm256_store_si256((__m256i*) ptr, simdreg); + _mm256_store_si256((__m256i*)ptr, simdreg); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - _mm_store_si128((__m128i*) ptr, simdreg); + _mm_store_si128((__m128i*)ptr, simdreg); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON - vst1q_s8( ptr, simdreg); + vst1q_s8(ptr, simdreg); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ } -static inline void srslte_simd_b_storeu(int8_t *ptr, simd_b_t simdreg) { +static inline void srslte_simd_b_storeu(int8_t* ptr, simd_b_t simdreg) +{ #ifdef LV_HAVE_AVX512 _mm512_storeu_si512(ptr, simdreg); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - _mm256_storeu_si256((__m256i*) ptr, simdreg); + _mm256_storeu_si256((__m256i*)ptr, simdreg); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - _mm_storeu_si128((__m128i*) ptr, simdreg); + _mm_storeu_si128((__m128i*)ptr, simdreg); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON vst1q_s8(ptr, simdreg); @@ -1794,34 +1855,35 @@ static inline void srslte_simd_b_storeu(int8_t *ptr, simd_b_t simdreg) { #endif /* LV_HAVE_AVX512 */ } +static inline simd_b_t srslte_simd_b_xor(simd_b_t a, simd_b_t b) +{ -static inline simd_b_t srslte_simd_b_xor(simd_b_t a, simd_b_t b) { - #ifdef LV_HAVE_AVX512 - return _mm512_xor_epi32(a, b); + return _mm512_xor_epi32(a, b); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 - return _mm256_xor_si256(a, b); + return _mm256_xor_si256(a, b); #else /* LV_HAVE_AVX2 */ #ifdef LV_HAVE_SSE - return _mm_xor_si128 (a, b); + return _mm_xor_si128(a, b); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON - return veorq_s8(a, b); + return veorq_s8(a, b); #endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ } -static inline simd_b_t srslte_simd_b_sub(simd_b_t a, simd_b_t b) { +static inline simd_b_t srslte_simd_b_sub(simd_b_t a, simd_b_t b) +{ #ifdef LV_HAVE_AVX512 return _mm512_subs_epi8(a, b); #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX2 return _mm256_subs_epi8(a, b); #else /* LV_HAVE_AVX2 */ - #ifdef LV_HAVE_SSE +#ifdef LV_HAVE_SSE return _mm_subs_epi8(a, b); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON @@ -1832,7 +1894,8 @@ static inline simd_b_t srslte_simd_b_sub(simd_b_t a, simd_b_t b) { #endif /* LV_HAVE_AVX512 */ } -static inline simd_s_t srslte_simd_b_neg(simd_b_t a, simd_b_t b) { +static inline simd_s_t srslte_simd_b_neg(simd_b_t a, simd_b_t b) +{ #ifdef LV_HAVE_AVX512 __m256i a0 = _mm512_extracti64x4_epi64(a, 0); __m256i a1 = _mm512_extracti64x4_epi64(a, 1); @@ -1845,7 +1908,7 @@ static inline simd_s_t srslte_simd_b_neg(simd_b_t a, simd_b_t b) { #ifdef LV_HAVE_AVX2 return _mm256_sign_epi8(a, b); #else /* LV_HAVE_AVX2 */ - #ifdef LV_HAVE_SSE +#ifdef LV_HAVE_SSE return _mm_sign_epi8(a, b); #else /* LV_HAVE_SSE */ #ifdef HAVE_NEON @@ -1858,9 +1921,6 @@ static inline simd_s_t srslte_simd_b_neg(simd_b_t a, simd_b_t b) { #endif /* LV_HAVE_AVX512 */ } - - #endif /*SRSLTE_SIMD_B_SIZE */ - #endif // SRSLTE_SIMD_H diff --git a/lib/include/srslte/phy/utils/vector.h b/lib/include/srslte/phy/utils/vector.h index 8a5e86e92..8d0d9f9a3 100644 --- a/lib/include/srslte/phy/utils/vector.h +++ b/lib/include/srslte/phy/utils/vector.h @@ -39,8 +39,8 @@ extern "C" { #include #include -#define SRSLTE_MAX(a,b) ((a)>(b)?(a):(b)) -#define SRSLTE_MIN(a,b) ((a)<(b)?(a):(b)) +#define SRSLTE_MAX(a, b) ((a) > (b) ? (a) : (b)) +#define SRSLTE_MIN(a, b) ((a) < (b) ? (a) : (b)) // Cumulative moving average #define SRSLTE_VEC_CMA(data, average, n) ((average) + ((data) - (average)) / ((n) + 1)) @@ -49,7 +49,7 @@ extern "C" { #define SRSLTE_VEC_PMA(average1, n1, average2, n2) (((average1) * (n1) + (average2) * (n2)) / ((n1) + (n2))) // Exponential moving average -#define SRSLTE_VEC_EMA(data, average, alpha) ((alpha)*(data)+(1-alpha)*(average)) +#define SRSLTE_VEC_EMA(data, average, alpha) ((alpha) * (data) + (1 - alpha) * (average)) static inline float srslte_convert_amplitude_to_dB(float v) { @@ -73,110 +73,126 @@ static inline float srslte_convert_dB_to_power(float v) } /*logical operations */ -SRSLTE_API void srslte_vec_xor_bbb(int8_t *x,int8_t *y,int8_t *z, const uint32_t len); +SRSLTE_API void srslte_vec_xor_bbb(int8_t* x, int8_t* y, int8_t* z, const uint32_t len); /** Return the sum of all the elements */ -SRSLTE_API float srslte_vec_acc_ff(const float *x, const uint32_t len); -SRSLTE_API cf_t srslte_vec_acc_cc(const cf_t *x, const uint32_t len); +SRSLTE_API float srslte_vec_acc_ff(const float* x, const uint32_t len); +SRSLTE_API cf_t srslte_vec_acc_cc(const cf_t* x, const uint32_t len); -SRSLTE_API void *srslte_vec_malloc(uint32_t size); +SRSLTE_API void* srslte_vec_malloc(uint32_t size); SRSLTE_API cf_t* srslte_vec_cf_malloc(uint32_t size); SRSLTE_API float* srslte_vec_f_malloc(uint32_t size); -SRSLTE_API void *srslte_vec_realloc(void *ptr, uint32_t old_size, uint32_t new_size); +SRSLTE_API void* srslte_vec_realloc(void* ptr, uint32_t old_size, uint32_t new_size); /* print vectors */ -SRSLTE_API void srslte_vec_fprint_c(FILE *stream, cf_t *x, const uint32_t len); -SRSLTE_API void srslte_vec_fprint_f(FILE *stream, float *x, const uint32_t len); -SRSLTE_API void srslte_vec_fprint_b(FILE *stream, uint8_t *x, const uint32_t len); -SRSLTE_API void srslte_vec_fprint_bs(FILE *stream, int8_t *x, const uint32_t len); -SRSLTE_API void srslte_vec_fprint_byte(FILE *stream, uint8_t *x, const uint32_t len); -SRSLTE_API void srslte_vec_fprint_i(FILE *stream, int *x, const uint32_t len); -SRSLTE_API void srslte_vec_fprint_s(FILE *stream, short *x, const uint32_t len); -SRSLTE_API void srslte_vec_fprint_hex(FILE *stream, uint8_t *x, const uint32_t len); -SRSLTE_API void srslte_vec_sprint_hex(char *str, const uint32_t max_str_len, uint8_t *x, const uint32_t len); +SRSLTE_API void srslte_vec_fprint_c(FILE* stream, cf_t* x, const uint32_t len); +SRSLTE_API void srslte_vec_fprint_f(FILE* stream, float* x, const uint32_t len); +SRSLTE_API void srslte_vec_fprint_b(FILE* stream, uint8_t* x, const uint32_t len); +SRSLTE_API void srslte_vec_fprint_bs(FILE* stream, int8_t* x, const uint32_t len); +SRSLTE_API void srslte_vec_fprint_byte(FILE* stream, uint8_t* x, const uint32_t len); +SRSLTE_API void srslte_vec_fprint_i(FILE* stream, int* x, const uint32_t len); +SRSLTE_API void srslte_vec_fprint_s(FILE* stream, short* x, const uint32_t len); +SRSLTE_API void srslte_vec_fprint_hex(FILE* stream, uint8_t* x, const uint32_t len); +SRSLTE_API void srslte_vec_sprint_hex(char* str, const uint32_t max_str_len, uint8_t* x, const uint32_t len); /* Saves/loads a vector to a file */ -SRSLTE_API void srslte_vec_save_file(char *filename, const void *buffer, const uint32_t len); -SRSLTE_API void srslte_vec_load_file(char *filename, void *buffer, const uint32_t len); +SRSLTE_API void srslte_vec_save_file(char* filename, const void* buffer, const uint32_t len); +SRSLTE_API void srslte_vec_load_file(char* filename, void* buffer, const uint32_t len); /* sum two vectors */ -SRSLTE_API void srslte_vec_sum_fff(const float *x, const float *y, float *z, const uint32_t len); -SRSLTE_API void srslte_vec_sum_ccc(const cf_t *x, const cf_t *y, cf_t *z, const uint32_t len); -SRSLTE_API void srslte_vec_sum_sss(const int16_t *x, const int16_t *y, int16_t *z, const uint32_t len); +SRSLTE_API void srslte_vec_sum_fff(const float* x, const float* y, float* z, const uint32_t len); +SRSLTE_API void srslte_vec_sum_ccc(const cf_t* x, const cf_t* y, cf_t* z, const uint32_t len); +SRSLTE_API void srslte_vec_sum_sss(const int16_t* x, const int16_t* y, int16_t* z, const uint32_t len); /* substract two vectors z=x-y */ -SRSLTE_API void srslte_vec_sub_fff(const float *x, const float *y, float *z, const uint32_t len); -SRSLTE_API void srslte_vec_sub_ccc(const cf_t *x, const cf_t *y, cf_t *z, const uint32_t len); -SRSLTE_API void srslte_vec_sub_sss(const int16_t *x, const int16_t *y, int16_t *z, const uint32_t len); -SRSLTE_API void srslte_vec_sub_bbb(const int8_t *x, const int8_t *y, int8_t *z, const uint32_t len); +SRSLTE_API void srslte_vec_sub_fff(const float* x, const float* y, float* z, const uint32_t len); +SRSLTE_API void srslte_vec_sub_ccc(const cf_t* x, const cf_t* y, cf_t* z, const uint32_t len); +SRSLTE_API void srslte_vec_sub_sss(const int16_t* x, const int16_t* y, int16_t* z, const uint32_t len); +SRSLTE_API void srslte_vec_sub_bbb(const int8_t* x, const int8_t* y, int8_t* z, const uint32_t len); /* scalar product */ -SRSLTE_API void srslte_vec_sc_prod_cfc(const cf_t *x, const float h, cf_t *z, const uint32_t len); -SRSLTE_API void srslte_vec_sc_prod_ccc(const cf_t *x, const cf_t h, cf_t *z, const uint32_t len); -SRSLTE_API void srslte_vec_sc_prod_fff(const float *x, const float h, float *z, const uint32_t len); +SRSLTE_API void srslte_vec_sc_prod_cfc(const cf_t* x, const float h, cf_t* z, const uint32_t len); +SRSLTE_API void srslte_vec_sc_prod_ccc(const cf_t* x, const cf_t h, cf_t* z, const uint32_t len); +SRSLTE_API void srslte_vec_sc_prod_fff(const float* x, const float h, float* z, const uint32_t len); +SRSLTE_API void srslte_vec_convert_fi(const float* x, const float scale, int16_t* z, const uint32_t len); +SRSLTE_API void srslte_vec_convert_if(const int16_t* x, const float scale, float* z, const uint32_t len); +SRSLTE_API void srslte_vec_convert_fb(const float* x, const float scale, int8_t* z, const uint32_t len); -SRSLTE_API void srslte_vec_convert_fi(const float *x, const float scale, int16_t *z, const uint32_t len); -SRSLTE_API void srslte_vec_convert_if(const int16_t *x, const float scale, float *z, const uint32_t len); -SRSLTE_API void srslte_vec_convert_fb(const float *x, const float scale, int8_t *z, const uint32_t len); - -SRSLTE_API void srslte_vec_lut_sss(const short *x, const unsigned short *lut, short *y, const uint32_t len); -SRSLTE_API void srslte_vec_lut_bbb(const int8_t *x, const unsigned short *lut, int8_t *y, const uint32_t len); -SRSLTE_API void srslte_vec_lut_sis(const short *x, const unsigned int *lut, short *y, const uint32_t len); +SRSLTE_API void srslte_vec_lut_sss(const short* x, const unsigned short* lut, short* y, const uint32_t len); +SRSLTE_API void srslte_vec_lut_bbb(const int8_t* x, const unsigned short* lut, int8_t* y, const uint32_t len); +SRSLTE_API void srslte_vec_lut_sis(const short* x, const unsigned int* lut, short* y, const uint32_t len); /* vector product (element-wise) */ -SRSLTE_API void srslte_vec_prod_ccc(const cf_t *x, const cf_t *y, cf_t *z, const uint32_t len); -SRSLTE_API void srslte_vec_prod_ccc_split(const float *x_re, const float *x_im, const float *y_re, const float *y_im, float *z_re, float *z_im, const uint32_t len); +SRSLTE_API void srslte_vec_prod_ccc(const cf_t* x, const cf_t* y, cf_t* z, const uint32_t len); +SRSLTE_API void srslte_vec_prod_ccc_split(const float* x_re, + const float* x_im, + const float* y_re, + const float* y_im, + float* z_re, + float* z_im, + const uint32_t len); /* vector product (element-wise) */ -SRSLTE_API void srslte_vec_prod_cfc(const cf_t *x, const float *y, cf_t *z, const uint32_t len); +SRSLTE_API void srslte_vec_prod_cfc(const cf_t* x, const float* y, cf_t* z, const uint32_t len); /* conjugate vector product (element-wise) */ -SRSLTE_API void srslte_vec_prod_conj_ccc(const cf_t *x, const cf_t *y, cf_t *z, const uint32_t len); +SRSLTE_API void srslte_vec_prod_conj_ccc(const cf_t* x, const cf_t* y, cf_t* z, const uint32_t len); /* real vector product (element-wise) */ -SRSLTE_API void srslte_vec_prod_fff(const float *x, const float *y, float *z, const uint32_t len); -SRSLTE_API void srslte_vec_prod_sss(const int16_t *x, const int16_t *y, int16_t *z, const uint32_t len); +SRSLTE_API void srslte_vec_prod_fff(const float* x, const float* y, float* z, const uint32_t len); +SRSLTE_API void srslte_vec_prod_sss(const int16_t* x, const int16_t* y, int16_t* z, const uint32_t len); // Negate sign (scrambling) -SRSLTE_API void srslte_vec_neg_sss(const int16_t *x, const int16_t *y, int16_t *z, const uint32_t len); -SRSLTE_API void srslte_vec_neg_bbb(const int8_t *x, const int8_t *y, int8_t *z, const uint32_t len); +SRSLTE_API void srslte_vec_neg_sss(const int16_t* x, const int16_t* y, int16_t* z, const uint32_t len); +SRSLTE_API void srslte_vec_neg_bbb(const int8_t* x, const int8_t* y, int8_t* z, const uint32_t len); /* Dot-product */ -SRSLTE_API cf_t srslte_vec_dot_prod_cfc(const cf_t *x, const float *y, const uint32_t len); -SRSLTE_API cf_t srslte_vec_dot_prod_ccc(const cf_t *x, const cf_t *y, const uint32_t len); -SRSLTE_API cf_t srslte_vec_dot_prod_conj_ccc(const cf_t *x, const cf_t *y, const uint32_t len); -SRSLTE_API float srslte_vec_dot_prod_fff(const float *x, const float *y, const uint32_t len); -SRSLTE_API int32_t srslte_vec_dot_prod_sss(const int16_t *x, const int16_t *y, const uint32_t len); +SRSLTE_API cf_t srslte_vec_dot_prod_cfc(const cf_t* x, const float* y, const uint32_t len); +SRSLTE_API cf_t srslte_vec_dot_prod_ccc(const cf_t* x, const cf_t* y, const uint32_t len); +SRSLTE_API cf_t srslte_vec_dot_prod_conj_ccc(const cf_t* x, const cf_t* y, const uint32_t len); +SRSLTE_API float srslte_vec_dot_prod_fff(const float* x, const float* y, const uint32_t len); +SRSLTE_API int32_t srslte_vec_dot_prod_sss(const int16_t* x, const int16_t* y, const uint32_t len); /* z=x/y vector division (element-wise) */ -SRSLTE_API void srslte_vec_div_ccc(const cf_t *x, const cf_t *y, cf_t *z, const uint32_t len); -SRSLTE_API void srslte_vec_div_cfc(const cf_t *x, const float *y, cf_t *z, const uint32_t len); -SRSLTE_API void srslte_vec_div_fff(const float *x, const float *y, float *z, const uint32_t len); +SRSLTE_API void srslte_vec_div_ccc(const cf_t* x, const cf_t* y, cf_t* z, const uint32_t len); +SRSLTE_API void srslte_vec_div_cfc(const cf_t* x, const float* y, cf_t* z, const uint32_t len); +SRSLTE_API void srslte_vec_div_fff(const float* x, const float* y, float* z, const uint32_t len); /* conjugate */ -SRSLTE_API void srslte_vec_conj_cc(const cf_t *x, cf_t *y, const uint32_t len); +SRSLTE_API void srslte_vec_conj_cc(const cf_t* x, cf_t* y, const uint32_t len); /* average vector power */ -SRSLTE_API float srslte_vec_avg_power_cf(const cf_t *x, const uint32_t len); +SRSLTE_API float srslte_vec_avg_power_cf(const cf_t* x, const uint32_t len); /* Correlation between complex vectors x and y */ -SRSLTE_API float srslte_vec_corr_ccc(const cf_t *x, cf_t *y, const uint32_t len); +SRSLTE_API float srslte_vec_corr_ccc(const cf_t* x, cf_t* y, const uint32_t len); /* return the index of the maximum value in the vector */ -SRSLTE_API uint32_t srslte_vec_max_fi(const float *x, const uint32_t len); -SRSLTE_API uint32_t srslte_vec_max_abs_fi(const float *x, const uint32_t len); -SRSLTE_API uint32_t srslte_vec_max_abs_ci(const cf_t *x, const uint32_t len); +SRSLTE_API uint32_t srslte_vec_max_fi(const float* x, const uint32_t len); +SRSLTE_API uint32_t srslte_vec_max_abs_fi(const float* x, const uint32_t len); +SRSLTE_API uint32_t srslte_vec_max_abs_ci(const cf_t* x, const uint32_t len); /* quantify vector of floats or int16 and convert to uint8_t */ -SRSLTE_API void srslte_vec_quant_fuc(const float *in, uint8_t *out, const float gain, const float offset, const float clip, const uint32_t len); -SRSLTE_API void srslte_vec_quant_fus(float *in, uint16_t *out, float gain, float offset, float clip, uint32_t len); -SRSLTE_API void srslte_vec_quant_suc(const int16_t *in, uint8_t *out, const float gain, const int16_t offset, const int16_t clip, const uint32_t len); -SRSLTE_API void srslte_vec_quant_sus(const int16_t *in, uint16_t *out, const float gain, const int16_t offset, const uint32_t len); +SRSLTE_API void srslte_vec_quant_fuc(const float* in, + uint8_t* out, + const float gain, + const float offset, + const float clip, + const uint32_t len); +SRSLTE_API void srslte_vec_quant_fus(float* in, uint16_t* out, float gain, float offset, float clip, uint32_t len); +SRSLTE_API void srslte_vec_quant_suc(const int16_t* in, + uint8_t* out, + const float gain, + const int16_t offset, + const int16_t clip, + const uint32_t len); +SRSLTE_API void +srslte_vec_quant_sus(const int16_t* in, uint16_t* out, const float gain, const int16_t offset, const uint32_t len); /* magnitude of each vector element */ -SRSLTE_API void srslte_vec_abs_cf(const cf_t *x, float *abs, const uint32_t len); -SRSLTE_API void srslte_vec_abs_square_cf(const cf_t *x, float *abs_square, const uint32_t len); +SRSLTE_API void srslte_vec_abs_cf(const cf_t* x, float* abs, const uint32_t len); +SRSLTE_API void srslte_vec_abs_square_cf(const cf_t* x, float* abs_square, const uint32_t len); /** * @brief Extracts module in decibels of a complex vector @@ -230,15 +246,15 @@ SRSLTE_API void srslte_vec_abs_dB_cf(const cf_t* x, float default_value, float* SRSLTE_API void srslte_vec_arg_deg_cf(const cf_t* x, float default_value, float* arg, const uint32_t len); /* Copy 256 bit aligned vector */ -SRSLTE_API void srs_vec_cf_cpy(const cf_t *src, cf_t *dst, const int len); +SRSLTE_API void srs_vec_cf_cpy(const cf_t* src, cf_t* dst, const int len); -SRSLTE_API void srslte_vec_interleave(const cf_t *x, const cf_t *y, cf_t *z, const int len); +SRSLTE_API void srslte_vec_interleave(const cf_t* x, const cf_t* y, cf_t* z, const int len); -SRSLTE_API void srslte_vec_interleave_add(const cf_t *x, const cf_t *y, cf_t *z, const int len); +SRSLTE_API void srslte_vec_interleave_add(const cf_t* x, const cf_t* y, cf_t* z, const int len); SRSLTE_API void srslte_vec_gen_sine(cf_t amplitude, float freq, cf_t* z, int len); -SRSLTE_API void srslte_vec_apply_cfo(const cf_t *x, float cfo, cf_t *z, int len); +SRSLTE_API void srslte_vec_apply_cfo(const cf_t* x, float cfo, cf_t* z, int len); SRSLTE_API float srslte_vec_estimate_frequency(const cf_t* x, int len); diff --git a/lib/include/srslte/phy/utils/vector_simd.h b/lib/include/srslte/phy/utils/vector_simd.h index 44d276591..6b2aca23c 100644 --- a/lib/include/srslte/phy/utils/vector_simd.h +++ b/lib/include/srslte/phy/utils/vector_simd.h @@ -26,21 +26,21 @@ extern "C" { #endif -#include -#include #include "srslte/config.h" +#include +#include #ifdef LV_HAVE_AVX512 #define SRSLTE_SIMD_BIT_ALIGN 512 -#define SRSLTE_IS_ALIGNED(PTR) (((size_t)(PTR) & 0x3F) == 0) +#define SRSLTE_IS_ALIGNED(PTR) (((size_t)(PTR)&0x3F) == 0) #else /* LV_HAVE_AVX512 */ #ifdef LV_HAVE_AVX #define SRSLTE_SIMD_BIT_ALIGN 256 -#define SRSLTE_IS_ALIGNED(PTR) (((size_t)(PTR) & 0x1F) == 0) +#define SRSLTE_IS_ALIGNED(PTR) (((size_t)(PTR)&0x1F) == 0) #else /* LV_HAVE_AVX */ #ifdef LV_HAVE_SSE #define SRSLTE_SIMD_BIT_ALIGN 128 -#define SRSLTE_IS_ALIGNED(PTR) (((size_t)(PTR) & 0x0F) == 0) +#define SRSLTE_IS_ALIGNED(PTR) (((size_t)(PTR)&0x0F) == 0) #else /* LV_HAVE_SSE */ #define SRSLTE_SIMD_BIT_ALIGN 64 #define SRSLTE_IS_ALIGNED(PTR) (1) @@ -48,105 +48,114 @@ extern "C" { #endif /* LV_HAVE_AVX */ #endif /* LV_HAVE_AVX512 */ - /*SIMD Logical operations*/ -SRSLTE_API void srslte_vec_xor_bbb_simd(const int8_t *x, const int8_t *y, int8_t *z, int len); +SRSLTE_API void srslte_vec_xor_bbb_simd(const int8_t* x, const int8_t* y, int8_t* z, int len); /* SIMD Basic vector math */ -SRSLTE_API void srslte_vec_sum_sss_simd(const int16_t *x, const int16_t *y, int16_t *z, int len); +SRSLTE_API void srslte_vec_sum_sss_simd(const int16_t* x, const int16_t* y, int16_t* z, int len); -SRSLTE_API void srslte_vec_sub_sss_simd(const int16_t *x, const int16_t *y, int16_t *z, int len); +SRSLTE_API void srslte_vec_sub_sss_simd(const int16_t* x, const int16_t* y, int16_t* z, int len); -SRSLTE_API void srslte_vec_sub_bbb_simd(const int8_t *x, const int8_t *y, int8_t *z, int len); +SRSLTE_API void srslte_vec_sub_bbb_simd(const int8_t* x, const int8_t* y, int8_t* z, int len); -SRSLTE_API float srslte_vec_acc_ff_simd(const float *x, int len); +SRSLTE_API float srslte_vec_acc_ff_simd(const float* x, int len); -SRSLTE_API cf_t srslte_vec_acc_cc_simd(const cf_t *x, int len); +SRSLTE_API cf_t srslte_vec_acc_cc_simd(const cf_t* x, int len); -SRSLTE_API void srslte_vec_add_fff_simd(const float *x, const float *y, float *z, int len); +SRSLTE_API void srslte_vec_add_fff_simd(const float* x, const float* y, float* z, int len); -SRSLTE_API void srslte_vec_sub_fff_simd(const float *x, const float *y, float *z, int len); +SRSLTE_API void srslte_vec_sub_fff_simd(const float* x, const float* y, float* z, int len); /* SIMD Vector Scalar Product */ -SRSLTE_API void srslte_vec_sc_prod_cfc_simd(const cf_t *x, const float h,cf_t *y, const int len); +SRSLTE_API void srslte_vec_sc_prod_cfc_simd(const cf_t* x, const float h, cf_t* y, const int len); -SRSLTE_API void srslte_vec_sc_prod_fff_simd(const float *x, const float h, float *z, const int len); +SRSLTE_API void srslte_vec_sc_prod_fff_simd(const float* x, const float h, float* z, const int len); -SRSLTE_API void srslte_vec_sc_prod_ccc_simd(const cf_t *x, const cf_t h, cf_t *z, const int len); +SRSLTE_API void srslte_vec_sc_prod_ccc_simd(const cf_t* x, const cf_t h, cf_t* z, const int len); /* SIMD Vector Product */ -SRSLTE_API void srslte_vec_prod_ccc_split_simd(const float *a_re, const float *a_im, const float *b_re, const float *b_im, - float *r_re, float *r_im, const int len); +SRSLTE_API void srslte_vec_prod_ccc_split_simd(const float* a_re, + const float* a_im, + const float* b_re, + const float* b_im, + float* r_re, + float* r_im, + const int len); -SRSLTE_API void srslte_vec_prod_ccc_c16_simd(const int16_t *a_re, const int16_t *a_im, const int16_t *b_re, const int16_t *b_im, - int16_t *r_re, int16_t *r_im, const int len); +SRSLTE_API void srslte_vec_prod_ccc_c16_simd(const int16_t* a_re, + const int16_t* a_im, + const int16_t* b_re, + const int16_t* b_im, + int16_t* r_re, + int16_t* r_im, + const int len); -SRSLTE_API void srslte_vec_prod_sss_simd(const int16_t *x, const int16_t *y, int16_t *z, const int len); +SRSLTE_API void srslte_vec_prod_sss_simd(const int16_t* x, const int16_t* y, int16_t* z, const int len); -SRSLTE_API void srslte_vec_neg_sss_simd(const int16_t *x, const int16_t *y, int16_t *z, const int len); +SRSLTE_API void srslte_vec_neg_sss_simd(const int16_t* x, const int16_t* y, int16_t* z, const int len); -SRSLTE_API void srslte_vec_neg_bbb_simd(const int8_t *x, const int8_t *y, int8_t *z, const int len); +SRSLTE_API void srslte_vec_neg_bbb_simd(const int8_t* x, const int8_t* y, int8_t* z, const int len); -SRSLTE_API void srslte_vec_prod_cfc_simd(const cf_t *x, const float *y, cf_t *z, const int len); +SRSLTE_API void srslte_vec_prod_cfc_simd(const cf_t* x, const float* y, cf_t* z, const int len); -SRSLTE_API void srslte_vec_prod_fff_simd(const float *x, const float *y, float *z, const int len); +SRSLTE_API void srslte_vec_prod_fff_simd(const float* x, const float* y, float* z, const int len); -SRSLTE_API void srslte_vec_prod_ccc_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len); +SRSLTE_API void srslte_vec_prod_ccc_simd(const cf_t* x, const cf_t* y, cf_t* z, const int len); -SRSLTE_API void srslte_vec_prod_conj_ccc_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len); +SRSLTE_API void srslte_vec_prod_conj_ccc_simd(const cf_t* x, const cf_t* y, cf_t* z, const int len); /* SIMD Division */ -SRSLTE_API void srslte_vec_div_ccc_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len); +SRSLTE_API void srslte_vec_div_ccc_simd(const cf_t* x, const cf_t* y, cf_t* z, const int len); -SRSLTE_API void srslte_vec_div_cfc_simd(const cf_t *x, const float *y, cf_t *z, const int len); +SRSLTE_API void srslte_vec_div_cfc_simd(const cf_t* x, const float* y, cf_t* z, const int len); -SRSLTE_API void srslte_vec_div_fff_simd(const float *x, const float *y, float *z, const int len); +SRSLTE_API void srslte_vec_div_fff_simd(const float* x, const float* y, float* z, const int len); /* SIMD Dot product */ -SRSLTE_API cf_t srslte_vec_dot_prod_conj_ccc_simd(const cf_t *x, const cf_t *y, const int len); +SRSLTE_API cf_t srslte_vec_dot_prod_conj_ccc_simd(const cf_t* x, const cf_t* y, const int len); -SRSLTE_API cf_t srslte_vec_dot_prod_ccc_simd(const cf_t *x, const cf_t *y, const int len); +SRSLTE_API cf_t srslte_vec_dot_prod_ccc_simd(const cf_t* x, const cf_t* y, const int len); #ifdef ENABLE_C16 -SRSLTE_API c16_t srslte_vec_dot_prod_ccc_c16i_simd(const c16_t *x, const c16_t *y, const int len); +SRSLTE_API c16_t srslte_vec_dot_prod_ccc_c16i_simd(const c16_t* x, const c16_t* y, const int len); #endif /* ENABLE_C16 */ -SRSLTE_API int srslte_vec_dot_prod_sss_simd(const int16_t *x, const int16_t *y, const int len); +SRSLTE_API int srslte_vec_dot_prod_sss_simd(const int16_t* x, const int16_t* y, const int len); /* SIMD Modulus functions */ -SRSLTE_API void srslte_vec_abs_cf_simd(const cf_t *x, float *z, const int len); +SRSLTE_API void srslte_vec_abs_cf_simd(const cf_t* x, float* z, const int len); -SRSLTE_API void srslte_vec_abs_square_cf_simd(const cf_t *x, float *z, const int len); +SRSLTE_API void srslte_vec_abs_square_cf_simd(const cf_t* x, float* z, const int len); /* Other Functions */ -SRSLTE_API void srslte_vec_lut_sss_simd(const short *x, const unsigned short *lut, short *y, const int len); +SRSLTE_API void srslte_vec_lut_sss_simd(const short* x, const unsigned short* lut, short* y, const int len); -SRSLTE_API void srslte_vec_lut_bbb_simd(const int8_t *x, const unsigned short *lut, int8_t *y, const int len); +SRSLTE_API void srslte_vec_lut_bbb_simd(const int8_t* x, const unsigned short* lut, int8_t* y, const int len); -SRSLTE_API void srslte_vec_convert_if_simd(const int16_t *x, float *z, const float scale, const int len); +SRSLTE_API void srslte_vec_convert_if_simd(const int16_t* x, float* z, const float scale, const int len); -SRSLTE_API void srslte_vec_convert_fi_simd(const float *x, int16_t *z, const float scale, const int len); +SRSLTE_API void srslte_vec_convert_fi_simd(const float* x, int16_t* z, const float scale, const int len); -SRSLTE_API void srslte_vec_convert_fb_simd(const float *x, int8_t *z, const float scale, const int len); +SRSLTE_API void srslte_vec_convert_fb_simd(const float* x, int8_t* z, const float scale, const int len); -SRSLTE_API void srslte_vec_cp_simd(const cf_t *src, cf_t *dst, int len); +SRSLTE_API void srslte_vec_cp_simd(const cf_t* src, cf_t* dst, int len); -SRSLTE_API void srslte_vec_interleave_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len); +SRSLTE_API void srslte_vec_interleave_simd(const cf_t* x, const cf_t* y, cf_t* z, const int len); -SRSLTE_API void srslte_vec_interleave_add_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len); +SRSLTE_API void srslte_vec_interleave_add_simd(const cf_t* x, const cf_t* y, cf_t* z, const int len); SRSLTE_API void srslte_vec_gen_sine_simd(cf_t amplitude, float freq, cf_t* z, int len); -SRSLTE_API void srslte_vec_apply_cfo_simd(const cf_t *x, float cfo, cf_t *z, int len); +SRSLTE_API void srslte_vec_apply_cfo_simd(const cf_t* x, float cfo, cf_t* z, int len); SRSLTE_API float srslte_vec_estimate_frequency_simd(const cf_t* x, int len); /* SIMD Find Max functions */ -SRSLTE_API uint32_t srslte_vec_max_fi_simd(const float *x, const int len); +SRSLTE_API uint32_t srslte_vec_max_fi_simd(const float* x, const int len); -SRSLTE_API uint32_t srslte_vec_max_abs_fi_simd(const float *x, const int len); +SRSLTE_API uint32_t srslte_vec_max_abs_fi_simd(const float* x, const int len); -SRSLTE_API uint32_t srslte_vec_max_ci_simd(const cf_t *x, const int len); +SRSLTE_API uint32_t srslte_vec_max_ci_simd(const cf_t* x, const int len); #ifdef __cplusplus } diff --git a/lib/include/srslte/radio/radio.h b/lib/include/srslte/radio/radio.h index 2ec2be42f..d956cc004 100644 --- a/lib/include/srslte/radio/radio.h +++ b/lib/include/srslte/radio/radio.h @@ -31,38 +31,39 @@ namespace srslte { -/* Interface to the RF frontend. - */ -class radio { - public: - radio() : tr_local_time(1024 * 10), tr_usrp_time(1024 * 10), tr_tx_time(1024 * 10), tr_is_eob(1024 * 10), zeros(NULL) - { - bzero(&rf_device, sizeof(srslte_rf_t)); - bzero(&end_of_burst_time, sizeof(srslte_timestamp_t)); - zeros = (cf_t*)srslte_vec_malloc(burst_preamble_max_samples * sizeof(cf_t)); - bzero(zeros, burst_preamble_max_samples * sizeof(cf_t)); - - log_h = NULL; - - burst_preamble_sec = 0; - is_start_of_burst = false; - burst_preamble_samples = 0; - burst_preamble_time_rounded = 0; - - cur_tx_srate = 0; - tx_adv_sec = 0; - tx_adv_nsamples = 0; - tx_adv_auto = false; - tx_adv_negative = false; - tx_freq = 0; - rx_freq = 0; - freq_offset = 0; - trace_enabled = false; - tti = 0; - agc_enabled = false; - radio_is_streaming = false; - is_initialized = false; - continuous_tx = false; +/* Interface to the RF frontend. + */ +class radio +{ +public: + radio() : tr_local_time(1024 * 10), tr_usrp_time(1024 * 10), tr_tx_time(1024 * 10), tr_is_eob(1024 * 10), zeros(NULL) + { + bzero(&rf_device, sizeof(srslte_rf_t)); + bzero(&end_of_burst_time, sizeof(srslte_timestamp_t)); + zeros = (cf_t*)srslte_vec_malloc(burst_preamble_max_samples * sizeof(cf_t)); + bzero(zeros, burst_preamble_max_samples * sizeof(cf_t)); + + log_h = NULL; + + burst_preamble_sec = 0; + is_start_of_burst = false; + burst_preamble_samples = 0; + burst_preamble_time_rounded = 0; + + cur_tx_srate = 0; + tx_adv_sec = 0; + tx_adv_nsamples = 0; + tx_adv_auto = false; + tx_adv_negative = false; + tx_freq = 0; + rx_freq = 0; + freq_offset = 0; + trace_enabled = false; + tti = 0; + agc_enabled = false; + radio_is_streaming = false; + is_initialized = false; + continuous_tx = false; }; ~radio() @@ -85,7 +86,7 @@ class radio { bool is_continuous_tx(); void set_continuous_tx(bool enable); - void get_time(srslte_timestamp_t *now); + void get_time(srslte_timestamp_t* now); int synch_wait(); void synch_issue(); bool tx_single(cf_t* buffer, uint32_t nof_samples, srslte_timestamp_t tx_time); @@ -95,9 +96,9 @@ class radio { bool rx_now(cf_t* buffer[SRSLTE_MAX_PORTS], uint32_t nof_samples, srslte_timestamp_t* rxd_time); bool rx_at(cf_t* buffer, uint32_t nof_samples, srslte_timestamp_t rx_time); - void set_tx_gain(float gain); - void set_rx_gain(float gain); - void set_tx_rx_gain_offset(float offset); + void set_tx_gain(float gain); + void set_rx_gain(float gain); + void set_tx_rx_gain_offset(float offset); float set_rx_gain_th(float gain); void set_freq_offset(double freq); @@ -111,14 +112,14 @@ class radio { void set_tx_srate(double srate); void set_rx_srate(double srate); - float get_tx_gain(); - float get_rx_gain(); - srslte_rf_info_t *get_info(); + float get_tx_gain(); + float get_rx_gain(); + srslte_rf_info_t* get_info(); float get_max_tx_power(); float set_tx_power(float power); float get_rssi(); - bool has_rssi(); + bool has_rssi(); bool is_first_of_burst(); @@ -126,50 +127,50 @@ class radio { void register_error_handler(srslte_rf_error_handler_t h); - protected: - srslte_rf_t rf_device; - log_filter* log_h; - - const static uint32_t burst_preamble_max_samples = 13824; - double burst_preamble_sec; // Start of burst preamble time (off->on RF transition time) - srslte_timestamp_t end_of_burst_time; - bool is_start_of_burst; - uint32_t burst_preamble_samples; - double burst_preamble_time_rounded; // preamble time rounded to sample time - cf_t* zeros; - double cur_tx_srate; - - double tx_adv_sec; // Transmission time advance to compensate for antenna->timestamp delay - int tx_adv_nsamples; // Transmision time advance in number of samples - - // Define default values for known radios - bool tx_adv_auto; - bool tx_adv_negative; - constexpr static double uhd_default_burst_preamble_sec = 600 * 1e-6; - constexpr static double uhd_default_tx_adv_samples = 98; - constexpr static double uhd_default_tx_adv_offset_sec = 4 * 1e-6; - - constexpr static double blade_default_burst_preamble_sec = 0.0; - constexpr static double blade_default_tx_adv_samples = 27; - constexpr static double blade_default_tx_adv_offset_sec = 1e-6; - - double tx_freq, rx_freq, freq_offset; - - trace tr_local_time; - trace tr_usrp_time; - trace tr_tx_time; - trace tr_is_eob; - bool trace_enabled; - uint32_t tti; - bool agc_enabled; - - bool continuous_tx; - bool is_initialized; - bool radio_is_streaming; - - uint32_t saved_nof_channels; - char saved_args[128]; - char saved_devname[128]; +protected: + srslte_rf_t rf_device; + log_filter* log_h; + + const static uint32_t burst_preamble_max_samples = 13824; + double burst_preamble_sec; // Start of burst preamble time (off->on RF transition time) + srslte_timestamp_t end_of_burst_time; + bool is_start_of_burst; + uint32_t burst_preamble_samples; + double burst_preamble_time_rounded; // preamble time rounded to sample time + cf_t* zeros; + double cur_tx_srate; + + double tx_adv_sec; // Transmission time advance to compensate for antenna->timestamp delay + int tx_adv_nsamples; // Transmision time advance in number of samples + + // Define default values for known radios + bool tx_adv_auto; + bool tx_adv_negative; + constexpr static double uhd_default_burst_preamble_sec = 600 * 1e-6; + constexpr static double uhd_default_tx_adv_samples = 98; + constexpr static double uhd_default_tx_adv_offset_sec = 4 * 1e-6; + + constexpr static double blade_default_burst_preamble_sec = 0.0; + constexpr static double blade_default_tx_adv_samples = 27; + constexpr static double blade_default_tx_adv_offset_sec = 1e-6; + + double tx_freq, rx_freq, freq_offset; + + trace tr_local_time; + trace tr_usrp_time; + trace tr_tx_time; + trace tr_is_eob; + bool trace_enabled; + uint32_t tti; + bool agc_enabled; + + bool continuous_tx; + bool is_initialized; + bool radio_is_streaming; + + uint32_t saved_nof_channels; + char saved_args[128]; + char saved_devname[128]; }; } // namespace srslte diff --git a/lib/include/srslte/radio/radio_base.h b/lib/include/srslte/radio/radio_base.h index 1ef9cfaab..c016f5cef 100644 --- a/lib/include/srslte/radio/radio_base.h +++ b/lib/include/srslte/radio/radio_base.h @@ -43,7 +43,7 @@ public: virtual std::string get_type() = 0; virtual int init(const rf_args_t& args_, phy_interface_radio* phy_) = 0; - virtual void stop() = 0; + virtual void stop() = 0; virtual bool get_metrics(rf_metrics_t* metrics) = 0; }; diff --git a/lib/include/srslte/radio/radio_multi.h b/lib/include/srslte/radio/radio_multi.h index 228a8444a..6e85fa91b 100644 --- a/lib/include/srslte/radio/radio_multi.h +++ b/lib/include/srslte/radio/radio_multi.h @@ -83,10 +83,10 @@ public: { return radios.at(radio_idx)->rx_now(buffer, nof_samples, rxd_time); } - void set_rx_gain(const uint32_t& radio_idx, const float& gain) override { radios.at(radio_idx)->set_rx_gain(gain); } - float set_rx_gain_th(const float& gain) override { return radios.at(0)->set_rx_gain_th(gain); } - float get_rx_gain(const uint32_t& radio_idx) override { return radios.at(radio_idx)->get_rx_gain(); } - void set_tx_freq(const uint32_t& radio_idx, const uint32_t& channel_idx, const double& freq) override + void set_rx_gain(const uint32_t& radio_idx, const float& gain) override { radios.at(radio_idx)->set_rx_gain(gain); } + float set_rx_gain_th(const float& gain) override { return radios.at(0)->set_rx_gain_th(gain); } + float get_rx_gain(const uint32_t& radio_idx) override { return radios.at(radio_idx)->get_rx_gain(); } + void set_tx_freq(const uint32_t& radio_idx, const uint32_t& channel_idx, const double& freq) override { radios.at(radio_idx)->set_tx_freq(channel_idx, freq); } diff --git a/lib/include/srslte/srslte.h b/lib/include/srslte/srslte.h index e7886118a..d50cd50a9 100644 --- a/lib/include/srslte/srslte.h +++ b/lib/include/srslte/srslte.h @@ -35,10 +35,10 @@ extern "C" { #include "srslte/version.h" #include "srslte/phy/utils/bit.h" -#include "srslte/phy/utils/ringbuffer.h" +#include "srslte/phy/utils/cexptab.h" #include "srslte/phy/utils/convolution.h" #include "srslte/phy/utils/debug.h" -#include "srslte/phy/utils/cexptab.h" +#include "srslte/phy/utils/ringbuffer.h" #include "srslte/phy/utils/vector.h" #include "srslte/phy/common/phy_common.h" @@ -46,30 +46,30 @@ extern "C" { #include "srslte/phy/common/timestamp.h" #include "srslte/phy/utils/phy_logger.h" -#include "srslte/phy/ch_estimation/chest_ul.h" #include "srslte/phy/ch_estimation/chest_dl.h" +#include "srslte/phy/ch_estimation/chest_ul.h" #include "srslte/phy/ch_estimation/refsignal_dl.h" #include "srslte/phy/ch_estimation/refsignal_ul.h" -#include "srslte/phy/resampling/interp.h" #include "srslte/phy/resampling/decim.h" +#include "srslte/phy/resampling/interp.h" #include "srslte/phy/resampling/resample_arb.h" #include "srslte/phy/channel/ch_awgn.h" -#include "srslte/phy/fec/viterbi.h" +#include "srslte/phy/fec/cbsegm.h" #include "srslte/phy/fec/convcoder.h" #include "srslte/phy/fec/crc.h" +#include "srslte/phy/fec/rm_conv.h" +#include "srslte/phy/fec/rm_turbo.h" #include "srslte/phy/fec/tc_interl.h" #include "srslte/phy/fec/turbocoder.h" #include "srslte/phy/fec/turbodecoder.h" -#include "srslte/phy/fec/cbsegm.h" -#include "srslte/phy/fec/rm_conv.h" -#include "srslte/phy/fec/rm_turbo.h" +#include "srslte/phy/fec/viterbi.h" +#include "srslte/phy/dft/dft.h" #include "srslte/phy/dft/dft_precoding.h" #include "srslte/phy/dft/ofdm.h" -#include "srslte/phy/dft/dft.h" #include "srslte/phy/io/binsource.h" #include "srslte/phy/io/filesink.h" @@ -82,8 +82,8 @@ extern "C" { #include "srslte/phy/modem/mod.h" #include "srslte/phy/modem/modem_table.h" -#include "srslte/phy/mimo/precoding.h" #include "srslte/phy/mimo/layermap.h" +#include "srslte/phy/mimo/precoding.h" #include "srslte/phy/fec/softbuffer.h" #include "srslte/phy/phch/cqi.h" @@ -103,10 +103,10 @@ extern "C" { #include "srslte/phy/phch/sch.h" #include "srslte/phy/phch/uci.h" -#include "srslte/phy/ue/ue_sync.h" -#include "srslte/phy/ue/ue_mib.h" #include "srslte/phy/ue/ue_cell_search.h" #include "srslte/phy/ue/ue_dl.h" +#include "srslte/phy/ue/ue_mib.h" +#include "srslte/phy/ue/ue_sync.h" #include "srslte/phy/ue/ue_ul.h" #include "srslte/phy/enb/enb_dl.h" diff --git a/lib/include/srslte/upper/gtpu.h b/lib/include/srslte/upper/gtpu.h index 8d1005f26..5cbe9cae9 100644 --- a/lib/include/srslte/upper/gtpu.h +++ b/lib/include/srslte/upper/gtpu.h @@ -22,9 +22,9 @@ #ifndef SRSLTE_GTPU_H #define SRSLTE_GTPU_H -#include #include "srslte/common/common.h" #include "srslte/common/log.h" +#include namespace srslte { @@ -59,60 +59,60 @@ namespace srslte { #define GTPU_FLAGS_SEQUENCE 0x02 #define GTPU_FLAGS_PACKET_NUM 0x01 -#define GTPU_MSG_ECHO_REQUEST 1 -#define GTPU_MSG_ECHO_RESPONSE 2 -#define GTPU_MSG_ERROR_INDICATION 26 -#define GTPU_MSG_SUPPORTED_EXTENSION_HEADERS_NOTIFICATION 31 -#define GTPU_MSG_END_MARKER 254 -#define GTPU_MSG_DATA_PDU 255 - -typedef struct{ - uint8_t flags; - uint8_t message_type; - uint16_t length; - uint32_t teid; - uint16_t seq_number; - uint8_t n_pdu; - uint8_t next_ext_hdr_type; -}gtpu_header_t; +#define GTPU_MSG_ECHO_REQUEST 1 +#define GTPU_MSG_ECHO_RESPONSE 2 +#define GTPU_MSG_ERROR_INDICATION 26 +#define GTPU_MSG_SUPPORTED_EXTENSION_HEADERS_NOTIFICATION 31 +#define GTPU_MSG_END_MARKER 254 +#define GTPU_MSG_DATA_PDU 255 +typedef struct { + uint8_t flags; + uint8_t message_type; + uint16_t length; + uint32_t teid; + uint16_t seq_number; + uint8_t n_pdu; + uint8_t next_ext_hdr_type; +} gtpu_header_t; -bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte::log *gtpu_log); -bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte::log *gtpu_log); +bool gtpu_read_header(srslte::byte_buffer_t* pdu, gtpu_header_t* header, srslte::log* gtpu_log); +bool gtpu_write_header(gtpu_header_t* header, srslte::byte_buffer_t* pdu, srslte::log* gtpu_log); std::string gtpu_ntoa(uint32_t addr); -inline bool gtpu_supported_flags_check(gtpu_header_t *header, srslte::log *gtpu_log) +inline bool gtpu_supported_flags_check(gtpu_header_t* header, srslte::log* gtpu_log) { - //flags - if( (header->flags & GTPU_FLAGS_VERSION_MASK) != GTPU_FLAGS_VERSION_V1 ) { + // flags + if ((header->flags & GTPU_FLAGS_VERSION_MASK) != GTPU_FLAGS_VERSION_V1) { gtpu_log->error("gtpu_header - Unhandled GTP-U Version. Flags: 0x%x\n", header->flags); return false; } - if( !(header->flags & GTPU_FLAGS_GTP_PROTOCOL) ) { + if (!(header->flags & GTPU_FLAGS_GTP_PROTOCOL)) { gtpu_log->error("gtpu_header - Unhandled Protocol Type. Flags: 0x%x\n\n", header->flags); return false; } - if( header->flags & GTPU_FLAGS_EXTENDED_HDR ) { + if (header->flags & GTPU_FLAGS_EXTENDED_HDR) { gtpu_log->error("gtpu_header - Unhandled Header Extensions. Flags: 0x%x\n\n", header->flags); return false; } - if( header->flags & GTPU_FLAGS_PACKET_NUM ) { + if (header->flags & GTPU_FLAGS_PACKET_NUM) { gtpu_log->error("gtpu_header - Unhandled Packet Number. Flags: 0x%x\n\n", header->flags); return false; } return true; } -inline bool gtpu_supported_msg_type_check(gtpu_header_t *header, srslte::log *gtpu_log) +inline bool gtpu_supported_msg_type_check(gtpu_header_t* header, srslte::log* gtpu_log) { - //msg_tpye - if( header->message_type != GTPU_MSG_DATA_PDU && header->message_type != GTPU_MSG_ECHO_REQUEST && header->message_type != GTPU_MSG_ECHO_RESPONSE) { + // msg_tpye + if (header->message_type != GTPU_MSG_DATA_PDU && header->message_type != GTPU_MSG_ECHO_REQUEST && + header->message_type != GTPU_MSG_ECHO_RESPONSE) { gtpu_log->error("gtpu_header - Unhandled message type: 0x%x\n", header->message_type); return false; } return true; } -}//namespace +} // namespace srslte #endif diff --git a/lib/include/srslte/upper/rlc.h b/lib/include/srslte/upper/rlc.h index 508f7408d..777fb1427 100644 --- a/lib/include/srslte/upper/rlc.h +++ b/lib/include/srslte/upper/rlc.h @@ -23,11 +23,11 @@ #define SRSLTE_RLC_H #include "srslte/common/buffer_pool.h" -#include "srslte/common/log.h" #include "srslte/common/common.h" +#include "srslte/common/log.h" #include "srslte/interfaces/ue_interfaces.h" -#include "srslte/upper/rlc_metrics.h" #include "srslte/upper/rlc_common.h" +#include "srslte/upper/rlc_metrics.h" namespace srslte { @@ -60,14 +60,14 @@ public: bool has_data(const uint32_t lcid); uint32_t get_buffer_state(const uint32_t lcid); uint32_t get_total_mch_buffer_state(uint32_t lcid); - int read_pdu(uint32_t lcid, uint8_t *payload, uint32_t nof_bytes); - int read_pdu_mch(uint32_t lcid, uint8_t *payload, uint32_t nof_bytes); + int read_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes); + int read_pdu_mch(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes); int get_increment_sequence_num(); - void write_pdu(uint32_t lcid, uint8_t *payload, uint32_t nof_bytes); - void write_pdu_bcch_bch(uint8_t *payload, uint32_t nof_bytes); - void write_pdu_bcch_dlsch(uint8_t *payload, uint32_t nof_bytes); - void write_pdu_pcch(uint8_t *payload, uint32_t nof_bytes); - void write_pdu_mch(uint32_t lcid, uint8_t *payload, uint32_t nof_bytes); + void write_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes); + void write_pdu_bcch_bch(uint8_t* payload, uint32_t nof_bytes); + void write_pdu_bcch_dlsch(uint8_t* payload, uint32_t nof_bytes); + void write_pdu_pcch(uint8_t* payload, uint32_t nof_bytes); + void write_pdu_mch(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes); // RRC interface void reestablish(); @@ -95,7 +95,7 @@ private: typedef std::map rlc_map_t; typedef std::pair rlc_map_pair_t; - rlc_map_t rlc_array, rlc_array_mrb; + rlc_map_t rlc_array, rlc_array_mrb; pthread_rwlock_t rwlock; uint32_t default_lcid = 0; diff --git a/lib/include/srslte/upper/rlc_am_lte.h b/lib/include/srslte/upper/rlc_am_lte.h index 99ffafb4e..ac0657072 100644 --- a/lib/include/srslte/upper/rlc_am_lte.h +++ b/lib/include/srslte/upper/rlc_am_lte.h @@ -38,27 +38,27 @@ namespace srslte { #undef RLC_AM_BUFFER_DEBUG -struct rlc_amd_rx_pdu_t{ - rlc_amd_pdu_header_t header; - unique_byte_buffer_t buf; +struct rlc_amd_rx_pdu_t { + rlc_amd_pdu_header_t header; + unique_byte_buffer_t buf; }; -struct rlc_amd_rx_pdu_segments_t{ +struct rlc_amd_rx_pdu_segments_t { std::list segments; }; -struct rlc_amd_tx_pdu_t{ - rlc_amd_pdu_header_t header; - unique_byte_buffer_t buf; - uint32_t retx_count; - bool is_acked; +struct rlc_amd_tx_pdu_t { + rlc_amd_pdu_header_t header; + unique_byte_buffer_t buf; + uint32_t retx_count; + bool is_acked; }; -struct rlc_amd_retx_t{ - uint32_t sn; - bool is_segment; - uint32_t so_start; - uint32_t so_end; +struct rlc_amd_retx_t { + uint32_t sn; + bool is_segment; + uint32_t so_start; + uint32_t so_end; }; class rlc_am_lte : public rlc_common @@ -85,14 +85,13 @@ public: // MAC interface bool has_data(); uint32_t get_buffer_state(); - int read_pdu(uint8_t *payload, uint32_t nof_bytes); - void write_pdu(uint8_t *payload, uint32_t nof_bytes); + int read_pdu(uint8_t* payload, uint32_t nof_bytes); + void write_pdu(uint8_t* payload, uint32_t nof_bytes); rlc_bearer_metrics_t get_metrics(); - void reset_metrics(); + void reset_metrics(); private: - // Transmitter sub-class class rlc_am_lte_tx : public timer_callback { @@ -113,20 +112,19 @@ private: bool has_data(); uint32_t get_buffer_state(); uint32_t get_num_tx_bytes(); - void reset_metrics(); + void reset_metrics(); // Timeout callback interface void timer_expired(uint32_t timeout_id); // Interface for Rx subclass - void handle_control_pdu(uint8_t *payload, uint32_t nof_bytes); + void handle_control_pdu(uint8_t* payload, uint32_t nof_bytes); private: - - int build_status_pdu(uint8_t *payload, uint32_t nof_bytes); - int build_retx_pdu(uint8_t *payload, uint32_t nof_bytes); - int build_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_retx_t retx); - int build_data_pdu(uint8_t *payload, uint32_t nof_bytes); + int build_status_pdu(uint8_t* payload, uint32_t nof_bytes); + int build_retx_pdu(uint8_t* payload, uint32_t nof_bytes); + int build_segment(uint8_t* payload, uint32_t nof_bytes, rlc_amd_retx_t retx); + int build_data_pdu(uint8_t* payload, uint32_t nof_bytes); void debug_state(); @@ -150,7 +148,7 @@ private: rlc_am_config_t cfg = {}; // TX SDU buffers - rlc_tx_queue tx_sdu_queue; + rlc_tx_queue tx_sdu_queue; unique_byte_buffer_t tx_sdu; bool tx_enabled = false; @@ -202,28 +200,28 @@ private: void reestablish(); void stop(); - void write_pdu(uint8_t *payload, uint32_t nof_bytes); + void write_pdu(uint8_t* payload, uint32_t nof_bytes); uint32_t get_num_rx_bytes(); - void reset_metrics(); + void reset_metrics(); // Timeout callback interface void timer_expired(uint32_t timeout_id); // Functions needed by Tx subclass to query rx state - int get_status_pdu_length(); - int get_status_pdu(rlc_status_pdu_t* status, const uint32_t nof_bytes); + int get_status_pdu_length(); + int get_status_pdu(rlc_status_pdu_t* status, const uint32_t nof_bytes); bool get_do_status(); void reset_status(); // called when status PDU has been sent private: - void handle_data_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_header_t &header); - void handle_data_pdu_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_header_t &header); + void handle_data_pdu(uint8_t* payload, uint32_t nof_bytes, rlc_amd_pdu_header_t& header); + void handle_data_pdu_segment(uint8_t* payload, uint32_t nof_bytes, rlc_amd_pdu_header_t& header); void reassemble_rx_sdus(); bool inside_rx_window(const int16_t sn); void debug_state(); void print_rx_segments(); - bool add_segment_and_check(rlc_amd_rx_pdu_segments_t *pdu, rlc_amd_rx_pdu_t *segment); + bool add_segment_and_check(rlc_amd_rx_pdu_segments_t* pdu, rlc_amd_rx_pdu_t* segment); rlc_am_lte* parent = nullptr; byte_buffer_pool* pool = nullptr; @@ -251,7 +249,7 @@ private: uint32_t vr_h = 0; // Highest rx state. SN following PDU with highest SN among rxed PDUs. // Mutexes - pthread_mutex_t mutex; + pthread_mutex_t mutex; // Rx windows std::map rx_window; diff --git a/lib/include/srslte/upper/rlc_tm.h b/lib/include/srslte/upper/rlc_tm.h index 8710e21bc..5bc058ec5 100644 --- a/lib/include/srslte/upper/rlc_tm.h +++ b/lib/include/srslte/upper/rlc_tm.h @@ -23,11 +23,11 @@ #define SRSLTE_RLC_TM_H #include "srslte/common/buffer_pool.h" -#include "srslte/common/log.h" #include "srslte/common/common.h" +#include "srslte/common/log.h" #include "srslte/interfaces/ue_interfaces.h" -#include "srslte/upper/rlc_tx_queue.h" #include "srslte/upper/rlc_common.h" +#include "srslte/upper/rlc_tx_queue.h" namespace srslte { @@ -44,13 +44,13 @@ public: bool configure(rlc_config_t cnfg); void stop(); void reestablish(); - void empty_queue(); + void empty_queue(); - rlc_mode_t get_mode(); - uint32_t get_bearer(); + rlc_mode_t get_mode(); + uint32_t get_bearer(); rlc_bearer_metrics_t get_metrics(); - void reset_metrics(); + void reset_metrics(); // PDCP interface void write_sdu(unique_byte_buffer_t sdu, bool blocking); @@ -59,8 +59,8 @@ public: // MAC interface bool has_data(); uint32_t get_buffer_state(); - int read_pdu(uint8_t *payload, uint32_t nof_bytes); - void write_pdu(uint8_t *payload, uint32_t nof_bytes); + int read_pdu(uint8_t* payload, uint32_t nof_bytes); + void write_pdu(uint8_t* payload, uint32_t nof_bytes); private: byte_buffer_pool* pool = nullptr; @@ -74,7 +74,7 @@ private: rlc_bearer_metrics_t metrics = {}; // Thread-safe queues for MAC messages - rlc_tx_queue ul_queue; + rlc_tx_queue ul_queue; }; } // namespace srslte diff --git a/lib/include/srslte/upper/rlc_tx_queue.h b/lib/include/srslte/upper/rlc_tx_queue.h index b9451e7bf..188e738bc 100644 --- a/lib/include/srslte/upper/rlc_tx_queue.h +++ b/lib/include/srslte/upper/rlc_tx_queue.h @@ -39,7 +39,8 @@ namespace srslte { class rlc_tx_queue : public block_queue::call_mutexed_itf { public: - rlc_tx_queue(int capacity = 128) : queue(capacity) { + rlc_tx_queue(int capacity = 128) : queue(capacity) + { unread_bytes = 0; queue.set_mutexed_itf(this); } @@ -61,19 +62,10 @@ public: bool try_read(unique_byte_buffer_t* msg) { return queue.try_pop(msg); } - void resize(uint32_t capacity) - { - queue.resize(capacity); - } - uint32_t size() - { - return (uint32_t) queue.size(); - } + void resize(uint32_t capacity) { queue.resize(capacity); } + uint32_t size() { return (uint32_t)queue.size(); } - uint32_t size_bytes() - { - return unread_bytes; - } + uint32_t size_bytes() { return unread_bytes; } uint32_t size_tail_bytes() { @@ -83,24 +75,19 @@ public: return m->N_bytes; } } - return 0; + return 0; } // This is a hack to reset N_bytes counter when queue is corrupted (see line 89) - void reset() { - unread_bytes = 0; - } + void reset() { unread_bytes = 0; } - bool is_empty() { - return queue.empty(); - } + bool is_empty() { return queue.empty(); } private: block_queue queue; - uint32_t unread_bytes; + uint32_t unread_bytes; }; } // namespace srslte - #endif // SRSLTE_MSG_QUEUE_H diff --git a/lib/include/srslte/upper/rlc_um_base.h b/lib/include/srslte/upper/rlc_um_base.h index 86e80a9e5..9f0531db7 100644 --- a/lib/include/srslte/upper/rlc_um_base.h +++ b/lib/include/srslte/upper/rlc_um_base.h @@ -42,7 +42,7 @@ public: uint32_t lcid_, srsue::pdcp_interface_rlc* pdcp_, srsue::rrc_interface_rlc* rrc_, - srslte::timer_handler* timers_); + srslte::timer_handler* timers_); virtual ~rlc_um_base(); void reestablish(); void stop(); @@ -64,7 +64,7 @@ public: int get_increment_sequence_num(); rlc_bearer_metrics_t get_metrics(); - void reset_metrics(); + void reset_metrics(); protected: // Transmitter sub-class base @@ -122,7 +122,7 @@ protected: protected: byte_buffer_pool* pool = nullptr; srslte::log* log = nullptr; - srslte::timer_handler* timers = nullptr; + srslte::timer_handler* timers = nullptr; srsue::pdcp_interface_rlc* pdcp = nullptr; srsue::rrc_interface_rlc* rrc = nullptr; @@ -145,7 +145,7 @@ protected: srsue::rrc_interface_rlc* rrc = nullptr; srsue::pdcp_interface_rlc* pdcp = nullptr; srslte::log* log = nullptr; - srslte::timer_handler* timers = nullptr; + srslte::timer_handler* timers = nullptr; uint32_t lcid = 0; rlc_config_t cfg = {}; std::string rb_name; @@ -156,8 +156,8 @@ protected: std::unique_ptr tx; std::unique_ptr rx; - bool tx_enabled = false; - bool rx_enabled = false; + bool tx_enabled = false; + bool rx_enabled = false; rlc_bearer_metrics_t metrics = {}; }; diff --git a/lib/include/srslte/upper/rlc_um_lte.h b/lib/include/srslte/upper/rlc_um_lte.h index 89c32c9f5..6c1cf8fa3 100644 --- a/lib/include/srslte/upper/rlc_um_lte.h +++ b/lib/include/srslte/upper/rlc_um_lte.h @@ -47,7 +47,7 @@ public: uint32_t lcid_, srsue::pdcp_interface_rlc* pdcp_, srsue::rrc_interface_rlc* rrc_, - srslte::timer_handler* timers_); + srslte::timer_handler* timers_); ~rlc_um_lte(); bool configure(rlc_config_t cnfg); diff --git a/lib/include/srslte/upper/rlc_um_nr.h b/lib/include/srslte/upper/rlc_um_nr.h index 0fb2153fa..83b66ae25 100644 --- a/lib/include/srslte/upper/rlc_um_nr.h +++ b/lib/include/srslte/upper/rlc_um_nr.h @@ -47,7 +47,7 @@ public: uint32_t lcid_, srsue::pdcp_interface_rlc* pdcp_, srsue::rrc_interface_rlc* rrc_, - srslte::timer_handler* timers_); + srslte::timer_handler* timers_); ~rlc_um_nr(); bool configure(rlc_config_t cnfg); diff --git a/lib/src/asn1/gtpc.cc b/lib/src/asn1/gtpc.cc index 6a3358394..5f1ec2307 100644 --- a/lib/src/asn1/gtpc.cc +++ b/lib/src/asn1/gtpc.cc @@ -18,9 +18,9 @@ * and at http://www.gnu.org/licenses/. * */ -#include #include "srslte/asn1/gtpc.h" #include "srslte/common/common.h" +#include namespace srslte { diff --git a/lib/src/asn1/liblte_m2ap.cc b/lib/src/asn1/liblte_m2ap.cc index 3f955ed83..62d6e2828 100644 --- a/lib/src/asn1/liblte_m2ap.cc +++ b/lib/src/asn1/liblte_m2ap.cc @@ -1946,7 +1946,8 @@ LIBLTE_ERROR_ENUM liblte_m2ap_unpack_cellinformationlist(uint8_t** ptr, LIBLTE_M * ProtocolIE MCCHRelatedBCCH-ConfigPerMBSFNArea-Item SEQUENCE *******************************************************************************/ LIBLTE_ERROR_ENUM liblte_m2ap_pack_mcchrelatedbcchconfigpermbsfnareaitem( - LIBLTE_M2AP_MCCH_RELATED_BCCH_CONFIG_PER_MBSFN_AREA_ITEM_STRUCT* ie, uint8_t** ptr) + LIBLTE_M2AP_MCCH_RELATED_BCCH_CONFIG_PER_MBSFN_AREA_ITEM_STRUCT* ie, + uint8_t** ptr) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; @@ -2018,7 +2019,8 @@ LIBLTE_ERROR_ENUM liblte_m2ap_pack_mcchrelatedbcchconfigpermbsfnareaitem( } LIBLTE_ERROR_ENUM liblte_m2ap_unpack_mcchrelatedbcchconfigpermbsfnareaitem( - uint8_t** ptr, LIBLTE_M2AP_MCCH_RELATED_BCCH_CONFIG_PER_MBSFN_AREA_ITEM_STRUCT* ie) + uint8_t** ptr, + LIBLTE_M2AP_MCCH_RELATED_BCCH_CONFIG_PER_MBSFN_AREA_ITEM_STRUCT* ie) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; diff --git a/lib/src/asn1/liblte_mme.cc b/lib/src/asn1/liblte_mme.cc index d7b06ae77..015360595 100644 --- a/lib/src/asn1/liblte_mme.cc +++ b/lib/src/asn1/liblte_mme.cc @@ -3270,7 +3270,8 @@ LIBLTE_ERROR_ENUM liblte_mme_unpack_generic_message_container_ie(uint8** ie_ptr, 24.008 v10.2.0 Section 10.5.5.28 *********************************************************************/ LIBLTE_ERROR_ENUM liblte_mme_pack_voice_domain_pref_and_ue_usage_setting_ie( - LIBLTE_MME_VOICE_DOMAIN_PREF_AND_UE_USAGE_SETTING_STRUCT* voice_domain_pref_and_ue_usage_setting, uint8** ie_ptr) + LIBLTE_MME_VOICE_DOMAIN_PREF_AND_UE_USAGE_SETTING_STRUCT* voice_domain_pref_and_ue_usage_setting, + uint8** ie_ptr) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; @@ -3287,7 +3288,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_voice_domain_pref_and_ue_usage_setting_ie( return (err); } LIBLTE_ERROR_ENUM liblte_mme_unpack_voice_domain_pref_and_ue_usage_setting_ie( - uint8** ie_ptr, LIBLTE_MME_VOICE_DOMAIN_PREF_AND_UE_USAGE_SETTING_STRUCT* voice_domain_pref_and_ue_usage_setting) + uint8** ie_ptr, + LIBLTE_MME_VOICE_DOMAIN_PREF_AND_UE_USAGE_SETTING_STRUCT* voice_domain_pref_and_ue_usage_setting) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; @@ -3674,8 +3676,10 @@ LIBLTE_ERROR_ENUM liblte_mme_unpack_esm_cause_ie(uint8** ie_ptr, uint8* cause) Document Reference: 24.301 v10.2.0 Section 9.9.4.5 *********************************************************************/ -LIBLTE_ERROR_ENUM liblte_mme_pack_esm_info_transfer_flag_ie( - LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_ENUM esm_info_transfer_flag, uint8 bit_offset, uint8** ie_ptr) +LIBLTE_ERROR_ENUM +liblte_mme_pack_esm_info_transfer_flag_ie(LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_ENUM esm_info_transfer_flag, + uint8 bit_offset, + uint8** ie_ptr) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; @@ -3687,8 +3691,10 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_esm_info_transfer_flag_ie( return (err); } -LIBLTE_ERROR_ENUM liblte_mme_unpack_esm_info_transfer_flag_ie( - uint8** ie_ptr, uint8 bit_offset, LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_ENUM* esm_info_transfer_flag) +LIBLTE_ERROR_ENUM +liblte_mme_unpack_esm_info_transfer_flag_ie(uint8** ie_ptr, + uint8 bit_offset, + LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_ENUM* esm_info_transfer_flag) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; @@ -6335,7 +6341,8 @@ liblte_mme_pack_guti_reallocation_complete_msg(LIBLTE_MME_GUTI_REALLOCATION_COMP return (err); } LIBLTE_ERROR_ENUM liblte_mme_unpack_guti_reallocation_complete_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_GUTI_REALLOCATION_COMPLETE_MSG_STRUCT* guti_realloc_complete) + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_GUTI_REALLOCATION_COMPLETE_MSG_STRUCT* guti_realloc_complete) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -7315,7 +7322,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_tracking_area_update_complete_msg( return (err); } LIBLTE_ERROR_ENUM liblte_mme_unpack_tracking_area_update_complete_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_TRACKING_AREA_UPDATE_COMPLETE_MSG_STRUCT* ta_update_complete) + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_TRACKING_AREA_UPDATE_COMPLETE_MSG_STRUCT* ta_update_complete) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -7579,7 +7587,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_downlink_generic_nas_transport_msg( return (err); } LIBLTE_ERROR_ENUM liblte_mme_unpack_downlink_generic_nas_transport_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_DOWNLINK_GENERIC_NAS_TRANSPORT_MSG_STRUCT* dl_generic_nas_transport) + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_DOWNLINK_GENERIC_NAS_TRANSPORT_MSG_STRUCT* dl_generic_nas_transport) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -7669,7 +7678,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_uplink_generic_nas_transport_msg( return (err); } LIBLTE_ERROR_ENUM liblte_mme_unpack_uplink_generic_nas_transport_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_UPLINK_GENERIC_NAS_TRANSPORT_MSG_STRUCT* ul_generic_nas_transport) + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_UPLINK_GENERIC_NAS_TRANSPORT_MSG_STRUCT* ul_generic_nas_transport) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -8460,7 +8470,8 @@ LIBLTE_ERROR_ENUM liblte_mme_unpack_activate_default_eps_bearer_context_request_ Document Reference: 24.301 v10.2.0 Section 8.3.7 *********************************************************************/ LIBLTE_ERROR_ENUM liblte_mme_pack_bearer_resource_allocation_reject_msg( - LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REJECT_MSG_STRUCT* bearer_res_alloc_rej, LIBLTE_BYTE_MSG_STRUCT* msg) + LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REJECT_MSG_STRUCT* bearer_res_alloc_rej, + LIBLTE_BYTE_MSG_STRUCT* msg) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -8504,7 +8515,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_bearer_resource_allocation_reject_msg( return (err); } LIBLTE_ERROR_ENUM liblte_mme_unpack_bearer_resource_allocation_reject_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REJECT_MSG_STRUCT* bearer_res_alloc_rej) + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REJECT_MSG_STRUCT* bearer_res_alloc_rej) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -8557,7 +8569,8 @@ LIBLTE_ERROR_ENUM liblte_mme_unpack_bearer_resource_allocation_reject_msg( Document Reference: 24.301 v10.2.0 Section 8.3.8 *********************************************************************/ LIBLTE_ERROR_ENUM liblte_mme_pack_bearer_resource_allocation_request_msg( - LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REQUEST_MSG_STRUCT* bearer_res_alloc_req, LIBLTE_BYTE_MSG_STRUCT* msg) + LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REQUEST_MSG_STRUCT* bearer_res_alloc_req, + LIBLTE_BYTE_MSG_STRUCT* msg) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -8607,7 +8620,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_bearer_resource_allocation_request_msg( return (err); } LIBLTE_ERROR_ENUM liblte_mme_unpack_bearer_resource_allocation_request_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REQUEST_MSG_STRUCT* bearer_res_alloc_req) + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_BEARER_RESOURCE_ALLOCATION_REQUEST_MSG_STRUCT* bearer_res_alloc_req) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -8666,7 +8680,8 @@ LIBLTE_ERROR_ENUM liblte_mme_unpack_bearer_resource_allocation_request_msg( Document Reference: 24.301 v10.2.0 Section 8.3.9 *********************************************************************/ LIBLTE_ERROR_ENUM liblte_mme_pack_bearer_resource_modification_reject_msg( - LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REJECT_MSG_STRUCT* bearer_res_mod_rej, LIBLTE_BYTE_MSG_STRUCT* msg) + LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REJECT_MSG_STRUCT* bearer_res_mod_rej, + LIBLTE_BYTE_MSG_STRUCT* msg) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -8710,7 +8725,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_bearer_resource_modification_reject_msg( return (err); } LIBLTE_ERROR_ENUM liblte_mme_unpack_bearer_resource_modification_reject_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REJECT_MSG_STRUCT* bearer_res_mod_rej) + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REJECT_MSG_STRUCT* bearer_res_mod_rej) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -8763,7 +8779,8 @@ LIBLTE_ERROR_ENUM liblte_mme_unpack_bearer_resource_modification_reject_msg( Document Reference: 24.301 v10.2.0 Section 8.3.10 *********************************************************************/ LIBLTE_ERROR_ENUM liblte_mme_pack_bearer_resource_modification_request_msg( - LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REQUEST_MSG_STRUCT* bearer_res_mod_req, LIBLTE_BYTE_MSG_STRUCT* msg) + LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REQUEST_MSG_STRUCT* bearer_res_mod_req, + LIBLTE_BYTE_MSG_STRUCT* msg) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -8824,7 +8841,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_bearer_resource_modification_request_msg( return (err); } LIBLTE_ERROR_ENUM liblte_mme_unpack_bearer_resource_modification_request_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REQUEST_MSG_STRUCT* bearer_res_mod_req) + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_BEARER_RESOURCE_MODIFICATION_REQUEST_MSG_STRUCT* bearer_res_mod_req) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -9488,7 +9506,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_modify_eps_bearer_context_accept_msg( return (err); } LIBLTE_ERROR_ENUM liblte_mme_unpack_modify_eps_bearer_context_accept_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_ACCEPT_MSG_STRUCT* mod_eps_bearer_context_accept) + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_ACCEPT_MSG_STRUCT* mod_eps_bearer_context_accept) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -9529,7 +9548,8 @@ LIBLTE_ERROR_ENUM liblte_mme_unpack_modify_eps_bearer_context_accept_msg( Document Reference: 24.301 v10.2.0 Section 8.3.17 *********************************************************************/ LIBLTE_ERROR_ENUM liblte_mme_pack_modify_eps_bearer_context_reject_msg( - LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REJECT_MSG_STRUCT* mod_eps_bearer_context_rej, LIBLTE_BYTE_MSG_STRUCT* msg) + LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REJECT_MSG_STRUCT* mod_eps_bearer_context_rej, + LIBLTE_BYTE_MSG_STRUCT* msg) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -9566,7 +9586,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_modify_eps_bearer_context_reject_msg( return (err); } LIBLTE_ERROR_ENUM liblte_mme_unpack_modify_eps_bearer_context_reject_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REJECT_MSG_STRUCT* mod_eps_bearer_context_rej) + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REJECT_MSG_STRUCT* mod_eps_bearer_context_rej) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -9610,7 +9631,8 @@ LIBLTE_ERROR_ENUM liblte_mme_unpack_modify_eps_bearer_context_reject_msg( Document Reference: 24.301 v10.2.0 Section 8.3.18 *********************************************************************/ LIBLTE_ERROR_ENUM liblte_mme_pack_modify_eps_bearer_context_request_msg( - LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT* mod_eps_bearer_context_req, LIBLTE_BYTE_MSG_STRUCT* msg) + LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT* mod_eps_bearer_context_req, + LIBLTE_BYTE_MSG_STRUCT* msg) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; @@ -9693,7 +9715,8 @@ LIBLTE_ERROR_ENUM liblte_mme_pack_modify_eps_bearer_context_request_msg( return (err); } LIBLTE_ERROR_ENUM liblte_mme_unpack_modify_eps_bearer_context_request_msg( - LIBLTE_BYTE_MSG_STRUCT* msg, LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT* mod_eps_bearer_context_req) + LIBLTE_BYTE_MSG_STRUCT* msg, + LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT* mod_eps_bearer_context_req) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8* msg_ptr = msg->msg; diff --git a/lib/src/common/arch_select.cc b/lib/src/common/arch_select.cc index d4c5e9e38..245913a96 100644 --- a/lib/src/common/arch_select.cc +++ b/lib/src/common/arch_select.cc @@ -26,9 +26,9 @@ #include #ifdef IS_ARM +#include #include #include -#include #define USER_HWCAP_NEON (1 << 12) #else #include @@ -39,8 +39,12 @@ #define MAX_CMD_LEN (64) #ifndef IS_ARM -static __inline int __get_cpuid_count_redef(unsigned int __leaf, unsigned int __subleaf, unsigned int* __eax, - unsigned int* __ebx, unsigned int* __ecx, unsigned int* __edx) +static __inline int __get_cpuid_count_redef(unsigned int __leaf, + unsigned int __subleaf, + unsigned int* __eax, + unsigned int* __ebx, + unsigned int* __ecx, + unsigned int* __edx) { unsigned int __max_leaf = __get_cpuid_max(__leaf & 0x80000000, 0); @@ -53,15 +57,15 @@ static __inline int __get_cpuid_count_redef(unsigned int __leaf, unsigned int __ const char* x86_get_isa() { - int ret = 0; - int has_sse42 = 0, has_avx = 0, has_avx2 = 0; + int ret = 0; + int has_sse42 = 0, has_avx = 0, has_avx2 = 0; unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0; // query basic features ret = __get_cpuid(X86_CPUID_BASIC_LEAF, &eax, &ebx, &ecx, &edx); if (ret) { has_sse42 = ecx & bit_SSE4_2; - has_avx = ecx & bit_AVX; + has_avx = ecx & bit_AVX; } // query advanced features @@ -72,11 +76,9 @@ const char* x86_get_isa() if (has_avx2) { return "avx2"; - } else - if (has_avx) { + } else if (has_avx) { return "avx"; - } else - if (has_sse42) { + } else if (has_sse42) { return "sse4.2"; } else { return "generic"; @@ -99,7 +101,7 @@ const char* arm_get_isa() } #endif -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { char cmd[MAX_CMD_LEN]; #ifdef IS_ARM diff --git a/lib/src/common/buffer_pool.cc b/lib/src/common/buffer_pool.cc index a0ce2b828..e8cde8daf 100644 --- a/lib/src/common/buffer_pool.cc +++ b/lib/src/common/buffer_pool.cc @@ -19,20 +19,20 @@ * */ -#include #include "srslte/common/buffer_pool.h" +#include #include #include -namespace srslte{ +namespace srslte { -byte_buffer_pool *byte_buffer_pool::instance = NULL; -pthread_mutex_t instance_mutex = PTHREAD_MUTEX_INITIALIZER; +byte_buffer_pool* byte_buffer_pool::instance = NULL; +pthread_mutex_t instance_mutex = PTHREAD_MUTEX_INITIALIZER; byte_buffer_pool* byte_buffer_pool::get_instance(int capacity) { pthread_mutex_lock(&instance_mutex); - if(NULL == instance) { + if (NULL == instance) { instance = new byte_buffer_pool(capacity); } pthread_mutex_unlock(&instance_mutex); @@ -42,8 +42,7 @@ byte_buffer_pool* byte_buffer_pool::get_instance(int capacity) void byte_buffer_pool::cleanup(void) { pthread_mutex_lock(&instance_mutex); - if(NULL != instance) - { + if (NULL != instance) { delete instance; instance = NULL; } diff --git a/lib/src/common/crash_handler.c b/lib/src/common/crash_handler.c index 32a256e63..6fff5373e 100644 --- a/lib/src/common/crash_handler.c +++ b/lib/src/common/crash_handler.c @@ -20,8 +20,8 @@ */ #include -#include #include +#include #include #include "srslte/common/backtrace.h" @@ -29,17 +29,18 @@ #include "srslte/version.h" const static char crash_file_name[] = "./srsLTE.backtrace.crash"; -static int bt_argc; -static char **bt_argv; +static int bt_argc; +static char** bt_argv; -static void crash_handler(int sig) { - FILE *f = fopen(crash_file_name, "a"); +static void crash_handler(int sig) +{ + FILE* f = fopen(crash_file_name, "a"); if (!f) { printf("srsLTE crashed... we could not save backtrace in '%s'...\n", crash_file_name); } else { - time_t lnTime; - struct tm *stTime; - char strdate[32]; + time_t lnTime; + struct tm* stTime; + char strdate[32]; time(&lnTime); stTime = localtime(&lnTime); @@ -62,7 +63,8 @@ static void crash_handler(int sig) { exit(1); } -void srslte_debug_handle_crash(int argc, char **argv) { +void srslte_debug_handle_crash(int argc, char** argv) +{ bt_argc = argc; bt_argv = argv; diff --git a/lib/src/common/gen_mch_tables.c b/lib/src/common/gen_mch_tables.c index ae9e2e0ee..fef992ea3 100644 --- a/lib/src/common/gen_mch_tables.c +++ b/lib/src/common/gen_mch_tables.c @@ -21,12 +21,11 @@ #include "srslte/common/gen_mch_tables.h" - /****************************************************************************** * Key Generation *****************************************************************************/ -void generate_frame_table(uint8_t *table, uint8_t alloc) +void generate_frame_table(uint8_t* table, uint8_t alloc) { table[1] = (alloc >> 5) & 0x01; table[2] = (alloc >> 4) & 0x01; @@ -36,21 +35,21 @@ void generate_frame_table(uint8_t *table, uint8_t alloc) table[8] = (alloc >> 0) & 0x01; } -void generate_mch_table(uint8_t *table, uint32_t sf_alloc, uint8_t num_frames) +void generate_mch_table(uint8_t* table, uint32_t sf_alloc, uint8_t num_frames) { - if(num_frames == 1){ - uint8_t alloc = (sf_alloc) & 0x3F; + if (num_frames == 1) { + uint8_t alloc = (sf_alloc)&0x3F; generate_frame_table(table, alloc); - } else if(num_frames == 4){ - for(uint32_t j=0; j<4; j++){ - uint8_t alloc = (sf_alloc >> 6*(3-j)) & 0x3F; - generate_frame_table(&table[j*10], alloc); + } else if (num_frames == 4) { + for (uint32_t j = 0; j < 4; j++) { + uint8_t alloc = (sf_alloc >> 6 * (3 - j)) & 0x3F; + generate_frame_table(&table[j * 10], alloc); } } } -void generate_mcch_table(uint8_t *table, uint32_t sf_alloc) +void generate_mcch_table(uint8_t* table, uint32_t sf_alloc) { - uint8_t alloc = (sf_alloc) & 0x3F; + uint8_t alloc = (sf_alloc)&0x3F; generate_frame_table(table, alloc); } diff --git a/lib/src/common/liblte_security.cc b/lib/src/common/liblte_security.cc index 3bc4ebe49..7975ad5e2 100644 --- a/lib/src/common/liblte_security.cc +++ b/lib/src/common/liblte_security.cc @@ -626,8 +626,13 @@ LIBLTE_ERROR_ENUM liblte_security_generate_k_up(uint8* 33.102 v10.0.0 Section 6.5.4 RFC4493 *********************************************************************/ -LIBLTE_ERROR_ENUM liblte_security_128_eia2( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* mac) +LIBLTE_ERROR_ENUM liblte_security_128_eia2(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* msg, + uint32 msg_len, + uint8* mac) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8 M[msg_len + 8 + 16]; @@ -712,8 +717,12 @@ LIBLTE_ERROR_ENUM liblte_security_128_eia2( return (err); } -LIBLTE_ERROR_ENUM liblte_security_128_eia2( - uint8* key, uint32 count, uint8 bearer, uint8 direction, LIBLTE_BIT_MSG_STRUCT* msg, uint8* mac) +LIBLTE_ERROR_ENUM liblte_security_128_eia2(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + LIBLTE_BIT_MSG_STRUCT* msg, + uint8* mac) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8 M[msg->N_bits * 8 + 8 + 16]; @@ -824,8 +833,13 @@ u8 GET_BIT(uint8_t* DATA, u32 i) return (DATA[i / 8] & (1 << (7 - (i % 8)))) ? 1 : 0; } -LIBLTE_ERROR_ENUM liblte_security_128_eia3( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* mac) +LIBLTE_ERROR_ENUM liblte_security_128_eia3(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* msg, + uint32 msg_len, + uint8* mac) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; @@ -900,8 +914,13 @@ LIBLTE_ERROR_ENUM liblte_security_128_eia3( Specification of the 3GPP Confidentiality and Integrity Algorithms UEA2 & UIA2 D1 v2.1 *********************************************************************/ -LIBLTE_ERROR_ENUM liblte_security_encryption_eea1( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* out) +LIBLTE_ERROR_ENUM liblte_security_encryption_eea1(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* msg, + uint32 msg_len, + uint8* out) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; S3G_STATE state, *state_ptr; @@ -972,8 +991,13 @@ LIBLTE_ERROR_ENUM liblte_security_encryption_eea1( Specification of the 3GPP Confidentiality and Integrity Algorithms UEA2 & UIA2 D1 v2.1 *********************************************************************/ -LIBLTE_ERROR_ENUM liblte_security_decryption_eea1( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* ct, uint32 ct_len, uint8* out) +LIBLTE_ERROR_ENUM liblte_security_decryption_eea1(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* ct, + uint32 ct_len, + uint8* out) { return liblte_security_encryption_eea1(key, count, bearer, direction, ct, ct_len, out); } @@ -985,8 +1009,13 @@ LIBLTE_ERROR_ENUM liblte_security_decryption_eea1( Document Reference: 33.401 v13.1.0 Annex B.1.3 *********************************************************************/ -LIBLTE_ERROR_ENUM liblte_security_encryption_eea2( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* out) +LIBLTE_ERROR_ENUM liblte_security_encryption_eea2(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* msg, + uint32 msg_len, + uint8* out) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; aes_context ctx; @@ -1028,8 +1057,13 @@ LIBLTE_ERROR_ENUM liblte_security_encryption_eea2( Document Reference: 33.401 v13.1.0 Annex B.1.3 *********************************************************************/ -LIBLTE_ERROR_ENUM liblte_security_decryption_eea2( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* ct, uint32 ct_len, uint8* out) +LIBLTE_ERROR_ENUM liblte_security_decryption_eea2(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* ct, + uint32 ct_len, + uint8* out) { return liblte_security_encryption_eea2(key, count, bearer, direction, ct, ct_len, out); } @@ -1044,8 +1078,13 @@ LIBLTE_ERROR_ENUM liblte_security_decryption_eea2( Specification of the 3GPP Confidentiality and Integrity Algorithms UEA2 & UIA2 D1 v2.1 *********************************************************************/ -LIBLTE_ERROR_ENUM liblte_security_encryption_eea3( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* out) +LIBLTE_ERROR_ENUM liblte_security_encryption_eea3(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* msg, + uint32 msg_len, + uint8* out) { LIBLTE_ERROR_ENUM err = LIBLTE_ERROR_INVALID_INPUTS; uint8_t iv[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -1111,8 +1150,13 @@ LIBLTE_ERROR_ENUM liblte_security_encryption_eea3( return (err); } -LIBLTE_ERROR_ENUM liblte_security_decryption_eea3( - uint8* key, uint32 count, uint8 bearer, uint8 direction, uint8* msg, uint32 msg_len, uint8* out) +LIBLTE_ERROR_ENUM liblte_security_decryption_eea3(uint8* key, + uint32 count, + uint8 bearer, + uint8 direction, + uint8* msg, + uint32 msg_len, + uint8* out) { return liblte_security_encryption_eea3(key, count, bearer, direction, msg, msg_len, out); } diff --git a/lib/src/common/log_filter.cc b/lib/src/common/log_filter.cc index 9b50b251f..4862f3ab4 100644 --- a/lib/src/common/log_filter.cc +++ b/lib/src/common/log_filter.cc @@ -29,7 +29,7 @@ #include "srslte/common/log_filter.h" -namespace srslte{ +namespace srslte { #define CHARS_FOR_HEX_DUMP(size) \ (3 * size + size / 16 * 20) // 3 chars per byte, plus 20 per line for position and newline) @@ -50,7 +50,7 @@ log_filter::log_filter(std::string layer) : log() init(layer, &def_logger_stdout, do_tti); } -log_filter::log_filter(std::string layer, logger *logger_, bool tti) +log_filter::log_filter(std::string layer, logger* logger_, bool tti) { do_tti = false; time_src = NULL; @@ -58,19 +58,21 @@ log_filter::log_filter(std::string layer, logger *logger_, bool tti) init(layer, logger_, tti); } -log_filter::~log_filter() -{ -} +log_filter::~log_filter() {} -void log_filter::init(std::string layer, logger *logger_, bool tti) +void log_filter::init(std::string layer, logger* logger_, bool tti) { - service_name = layer; - logger_h = logger_; - do_tti = tti; + service_name = layer; + logger_h = logger_; + do_tti = tti; } -void log_filter::all_log( - srslte::LOG_LEVEL_ENUM level, uint32_t tti, const char* msg, const uint8_t* hex, int size, bool long_msg) +void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, + uint32_t tti, + const char* msg, + const uint8_t* hex, + int size, + bool long_msg) { char buffer_tti[16] = {}; char buffer_time[64] = {}; @@ -111,12 +113,13 @@ void log_filter::all_log( } } -void log_filter::console(const char * message, ...) { - char args_msg[char_buff_size]; - va_list args; +void log_filter::console(const char* message, ...) +{ + char args_msg[char_buff_size]; + va_list args; va_start(args, message); if (vsnprintf(args_msg, char_buff_size, message, args) > 0) - printf("%s",args_msg); // Print directly to stdout + printf("%s", args_msg); // Print directly to stdout fflush(stdout); va_end(args); } @@ -145,15 +148,18 @@ void log_filter::console(const char * message, ...) { } \ } while (0) -void log_filter::error(const char * message, ...) { +void log_filter::error(const char* message, ...) +{ all_log_expand(LOG_LEVEL_ERROR); } -void log_filter::warning(const char * message, ...) { +void log_filter::warning(const char* message, ...) +{ all_log_expand(LOG_LEVEL_WARNING); } -void log_filter::info(const char * message, ...) { +void log_filter::info(const char* message, ...) +{ all_log_expand(LOG_LEVEL_INFO); } @@ -170,15 +176,16 @@ void log_filter::info_long(const char* message, ...) } } -void log_filter::debug(const char * message, ...) { +void log_filter::debug(const char* message, ...) +{ all_log_expand(LOG_LEVEL_DEBUG); } void log_filter::debug_long(const char* message, ...) { if (level >= LOG_LEVEL_DEBUG) { - char* args_msg = NULL; - va_list args; + char* args_msg = NULL; + va_list args; va_start(args, message); if (vasprintf(&args_msg, message, args) > 0) all_log(LOG_LEVEL_DEBUG, tti, args_msg, nullptr, strlen(args_msg), true); @@ -187,23 +194,28 @@ void log_filter::debug_long(const char* message, ...) } } -void log_filter::error_hex(const uint8_t *hex, int size, const char * message, ...) { +void log_filter::error_hex(const uint8_t* hex, int size, const char* message, ...) +{ all_log_hex_expand(LOG_LEVEL_ERROR); } -void log_filter::warning_hex(const uint8_t *hex, int size, const char * message, ...) { +void log_filter::warning_hex(const uint8_t* hex, int size, const char* message, ...) +{ all_log_hex_expand(LOG_LEVEL_WARNING); } -void log_filter::info_hex(const uint8_t *hex, int size, const char * message, ...) { +void log_filter::info_hex(const uint8_t* hex, int size, const char* message, ...) +{ all_log_hex_expand(LOG_LEVEL_INFO); } -void log_filter::debug_hex(const uint8_t *hex, int size, const char * message, ...) { +void log_filter::debug_hex(const uint8_t* hex, int size, const char* message, ...) +{ all_log_hex_expand(LOG_LEVEL_DEBUG); } -void log_filter::set_time_src(time_itf *source, time_format_t format) { +void log_filter::set_time_src(time_itf* source, time_format_t format) +{ this->time_src = source; this->time_format = format; } @@ -215,11 +227,11 @@ void log_filter::get_tti_str(const uint32_t tti_, char* buffer, const uint32_t b void log_filter::now_time(char* buffer, const uint32_t buffer_len) { struct timeval rawtime; - struct tm * timeinfo; - char us[16]; + struct tm* timeinfo; + char us[16]; srslte_timestamp_t now; - uint64_t usec_epoch; + uint64_t usec_epoch; if (buffer_len < 16) { fprintf(stderr, "Error buffer provided for time too small\n"); @@ -245,25 +257,25 @@ void log_filter::now_time(char* buffer, const uint32_t buffer_len) if (time_format == TIME) { snprintf(buffer, buffer_len, "%ld:%06u", now.full_secs, (uint32_t)(now.frac_secs * 1e6)); } else { - usec_epoch = now.full_secs * 1000000 + (uint32_t) (now.frac_secs * 1e6); + usec_epoch = now.full_secs * 1000000 + (uint32_t)(now.frac_secs * 1e6); snprintf(buffer, buffer_len, "%" PRIu64, usec_epoch); } } } -std::string log_filter::hex_string(const uint8_t *hex, int size) +std::string log_filter::hex_string(const uint8_t* hex, int size) { std::stringstream ss; - int c = 0; + int c = 0; ss << std::hex << std::setfill('0'); - if(hex_limit >= 0) { + if (hex_limit >= 0) { size = (size > hex_limit) ? hex_limit : size; } - while(c < size) { + while (c < size) { ss << " " << std::setw(4) << static_cast(c) << ": "; - int tmp = (size-c < 16) ? size-c : 16; - for(int i=0;i(hex[c++]) << " "; } ss << "\n"; diff --git a/lib/src/common/logger_file.cc b/lib/src/common/logger_file.cc index b38958d51..324be71c4 100644 --- a/lib/src/common/logger_file.cc +++ b/lib/src/common/logger_file.cc @@ -19,13 +19,13 @@ * */ -#define LOG_BUFFER_SIZE 1024*32 +#define LOG_BUFFER_SIZE 1024 * 32 #include "srslte/common/logger_file.h" using namespace std; -namespace srslte{ +namespace srslte { logger_file::logger_file() : logfile(NULL), is_running(false), cur_length(0), max_length(0), thread("LOGGER_FILE") { @@ -40,16 +40,17 @@ logger_file::~logger_file() pthread_cond_destroy(¬_empty); } -void logger_file::init(std::string file, int max_length_) { +void logger_file::init(std::string file, int max_length_) +{ if (is_running) { fprintf(stderr, "Error: logger thread is already running.\n"); return; } pthread_mutex_lock(&mutex); - max_length = (int64_t)max_length_*1024; - name_idx = 0; - filename = file; - logfile = fopen(filename.c_str(), "w"); + max_length = (int64_t)max_length_ * 1024; + name_idx = 0; + filename = file; + logfile = fopen(filename.c_str(), "w"); if (logfile == NULL) { printf("Error: could not create log file, no messages will be logged!\n"); } @@ -89,10 +90,11 @@ void logger_file::log(unique_log_str_t msg) pthread_mutex_unlock(&mutex); } -void logger_file::run_thread() { - while(is_running) { +void logger_file::run_thread() +{ + while (is_running) { pthread_mutex_lock(&mutex); - while(buffer.empty()) { + while (buffer.empty()) { pthread_cond_wait(¬_empty, &mutex); if (!is_running) { pthread_mutex_unlock(&mutex); @@ -108,15 +110,15 @@ void logger_file::run_thread() { buffer.pop_front(); if (n > 0) { - cur_length += (int64_t) n; + cur_length += (int64_t)n; if (cur_length >= max_length && max_length > 0) { fclose(logfile); name_idx++; char numstr[21]; // enough to hold all numbers up to 64-bits sprintf(numstr, ".%d", name_idx); - string newfilename = filename + numstr ; - logfile = fopen(newfilename.c_str(), "w"); - if(logfile==NULL) { + string newfilename = filename + numstr; + logfile = fopen(newfilename.c_str(), "w"); + if (logfile == NULL) { printf("Error: could not create log file, no messages will be logged!\n"); } cur_length = 0; diff --git a/lib/src/common/mac_nr_pdu.cc b/lib/src/common/mac_nr_pdu.cc index 2f7b22925..55aa0da62 100644 --- a/lib/src/common/mac_nr_pdu.cc +++ b/lib/src/common/mac_nr_pdu.cc @@ -116,7 +116,7 @@ void mac_nr_sch_subpdu::set_padding(const uint32_t len_) uint32_t mac_nr_sch_subpdu::write_subpdu(const uint8_t* start_) { uint8_t* ptr = const_cast(start_); - *ptr = (uint8_t)((F_bit ? 1 : 0) << 6) | ((uint8_t)lcid & 0x3f); + *ptr = (uint8_t)((F_bit ? 1 : 0) << 6) | ((uint8_t)lcid & 0x3f); ptr += 1; if (header_length == 3) { diff --git a/lib/src/common/mac_pcap.cc b/lib/src/common/mac_pcap.cc index 1c4919544..673be0daf 100644 --- a/lib/src/common/mac_pcap.cc +++ b/lib/src/common/mac_pcap.cc @@ -19,10 +19,10 @@ * */ -#include -#include "srslte/srslte.h" -#include "srslte/common/pcap.h" #include "srslte/common/mac_pcap.h" +#include "srslte/common/pcap.h" +#include "srslte/srslte.h" +#include namespace srslte { @@ -35,12 +35,12 @@ mac_pcap::~mac_pcap() void mac_pcap::enable(bool en) { - enable_write = true; + enable_write = true; } void mac_pcap::open(const char* filename, uint32_t ue_id) { - pcap_file = LTE_PCAP_Open(MAC_LTE_DLT, filename); - this->ue_id = ue_id; + pcap_file = LTE_PCAP_Open(MAC_LTE_DLT, filename); + this->ue_id = ue_id; enable_write = true; } void mac_pcap::close() @@ -53,23 +53,31 @@ void mac_pcap::close() } } -void mac_pcap::set_ue_id(uint16_t ue_id) { +void mac_pcap::set_ue_id(uint16_t ue_id) +{ this->ue_id = ue_id; } -void mac_pcap::pack_and_write(uint8_t* pdu, uint32_t pdu_len_bytes, uint32_t reTX, bool crc_ok, uint32_t tti, - uint16_t crnti, uint8_t direction, uint8_t rnti_type) +void mac_pcap::pack_and_write(uint8_t* pdu, + uint32_t pdu_len_bytes, + uint32_t reTX, + bool crc_ok, + uint32_t tti, + uint16_t crnti, + uint8_t direction, + uint8_t rnti_type) { if (enable_write) { - MAC_Context_Info_t context = - { - FDD_RADIO, direction, rnti_type, - crnti, /* RNTI */ + MAC_Context_Info_t context = { + FDD_RADIO, + direction, + rnti_type, + crnti, /* RNTI */ (uint16_t)ue_id, /* UEId */ (uint8_t)reTX, /* Retx */ - crc_ok, /* CRC Stsatus (i.e. OK) */ - (uint16_t)(tti/10), /* Sysframe number */ - (uint16_t)(tti%10) /* Subframe number */ + crc_ok, /* CRC Stsatus (i.e. OK) */ + (uint16_t)(tti / 10), /* Sysframe number */ + (uint16_t)(tti % 10) /* Subframe number */ }; if (pdu) { LTE_PCAP_MAC_WritePDU(pcap_file, &context, pdu, pdu_len_bytes); @@ -178,4 +186,4 @@ void mac_pcap::write_ul_rrc_pdu(const uint8_t* input, const int32_t input_len) write_ul_crnti(pdu, pdu_ptr - pdu, 14931, true, 0); } -} +} // namespace srslte diff --git a/lib/src/common/nas_pcap.cc b/lib/src/common/nas_pcap.cc index 3499824f9..c9e46a7bc 100644 --- a/lib/src/common/nas_pcap.cc +++ b/lib/src/common/nas_pcap.cc @@ -19,10 +19,10 @@ * */ -#include -#include "srslte/srslte.h" -#include "srslte/common/pcap.h" #include "srslte/common/nas_pcap.h" +#include "srslte/common/pcap.h" +#include "srslte/srslte.h" +#include namespace srslte { @@ -32,8 +32,8 @@ void nas_pcap::enable() } void nas_pcap::open(const char* filename, uint32_t ue_id) { - pcap_file = LTE_PCAP_Open(NAS_LTE_DLT, filename); - ue_id = ue_id; + pcap_file = LTE_PCAP_Open(NAS_LTE_DLT, filename); + ue_id = ue_id; enable_write = true; } void nas_pcap::close() @@ -42,14 +42,14 @@ void nas_pcap::close() LTE_PCAP_Close(pcap_file); } -void nas_pcap::write_nas(uint8_t *pdu, uint32_t pdu_len_bytes) +void nas_pcap::write_nas(uint8_t* pdu, uint32_t pdu_len_bytes) { - if (enable_write) { - NAS_Context_Info_t context; - if (pdu) { - LTE_PCAP_NAS_WritePDU(pcap_file, &context, pdu, pdu_len_bytes); - } + if (enable_write) { + NAS_Context_Info_t context; + if (pdu) { + LTE_PCAP_NAS_WritePDU(pcap_file, &context, pdu, pdu_len_bytes); } + } } -} +} // namespace srslte diff --git a/lib/src/common/pdu.cc b/lib/src/common/pdu.cc index d3371eb9e..9951d83ed 100644 --- a/lib/src/common/pdu.cc +++ b/lib/src/common/pdu.cc @@ -646,7 +646,7 @@ bool sch_subh::set_next_mch_sched_info(uint8_t lcid_, uint16_t mtch_stop) int sch_subh::set_sdu(uint32_t lcid_, uint32_t requested_bytes_, read_pdu_interface* sdu_itf_) { if (((sch_pdu*)parent)->has_space_sdu(requested_bytes_)) { - lcid = lcid_; + lcid = lcid_; payload = ((sch_pdu*)parent)->get_current_sdu_ptr(); // Copy data and get final number of bytes written to the MAC PDU diff --git a/lib/src/common/pdu_queue.cc b/lib/src/common/pdu_queue.cc index ed351c961..49dbb7845 100644 --- a/lib/src/common/pdu_queue.cc +++ b/lib/src/common/pdu_queue.cc @@ -19,47 +19,45 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) #include "srslte/common/pdu_queue.h" - namespace srslte { - -void pdu_queue::init(process_callback *callback_, log* log_h_) +void pdu_queue::init(process_callback* callback_, log* log_h_) { - callback = callback_; - log_h = log_h_; + callback = callback_; + log_h = log_h_; } uint8_t* pdu_queue::request(uint32_t len) -{ +{ if (len > MAX_PDU_LEN) { ERROR("Error request buffer of invalid size %d. Max bytes %d\n", len, MAX_PDU_LEN); - return NULL; + return NULL; } pdu_t* pdu = pool.allocate("pdu_queue::request", true); if (!pdu) { if (log_h) { - log_h->error("Not enough buffers for MAC PDU\n"); + log_h->error("Not enough buffers for MAC PDU\n"); } ERROR("Not enough buffers for MAC PDU\n"); } - if ((void*) pdu->ptr != (void*) pdu) { + if ((void*)pdu->ptr != (void*)pdu) { ERROR("Fatal error in memory alignment in struct pdu_queue::pdu_t\n"); exit(-1); } - - return pdu->ptr; + + return pdu->ptr; } void pdu_queue::deallocate(uint8_t* pdu) { - if (!pool.deallocate((pdu_t*) pdu)) { + if (!pool.deallocate((pdu_t*)pdu)) { log_h->warning("Error deallocating from buffer pool in deallocate(): buffer not created in this pool.\n"); } } @@ -71,8 +69,8 @@ void pdu_queue::deallocate(uint8_t* pdu) void pdu_queue::push(uint8_t* ptr, uint32_t len, channel_t channel) { if (ptr) { - pdu_t *pdu = (pdu_t*) ptr; - pdu->len = len; + pdu_t* pdu = (pdu_t*)ptr; + pdu->len = len; pdu->channel = channel; pdu_q.push(pdu); } else { @@ -82,10 +80,10 @@ void pdu_queue::push(uint8_t* ptr, uint32_t len, channel_t channel) bool pdu_queue::process_pdus() { - bool have_data = false; - uint32_t cnt = 0; - pdu_t *pdu; - while(pdu_q.try_pop(&pdu)) { + bool have_data = false; + uint32_t cnt = 0; + pdu_t* pdu; + while (pdu_q.try_pop(&pdu)) { if (callback) { callback->process_pdu(pdu->ptr, pdu->len, pdu->channel); } @@ -98,7 +96,7 @@ bool pdu_queue::process_pdus() } printf("Warning PDU queue dispatched %d packets\n", cnt); } - return have_data; + return have_data; } -} +} // namespace srslte diff --git a/lib/src/common/rlc_pcap.cc b/lib/src/common/rlc_pcap.cc index 0b71f38cd..fb02942b9 100644 --- a/lib/src/common/rlc_pcap.cc +++ b/lib/src/common/rlc_pcap.cc @@ -19,22 +19,22 @@ * */ -#include -#include "srslte/srslte.h" -#include "srslte/common/pcap.h" #include "srslte/common/rlc_pcap.h" +#include "srslte/common/pcap.h" +#include "srslte/srslte.h" +#include namespace srslte { - + void rlc_pcap::enable(bool en) { - enable_write = true; + enable_write = true; } void rlc_pcap::open(const char* filename, uint32_t ue_id) { fprintf(stdout, "Opening RLC PCAP with DLT=%d\n", UDP_DLT); pcap_file = LTE_PCAP_Open(UDP_DLT, filename); - this->ue_id = ue_id; + this->ue_id = ue_id; enable_write = true; } void rlc_pcap::close() @@ -43,22 +43,31 @@ void rlc_pcap::close() LTE_PCAP_Close(pcap_file); } -void rlc_pcap::set_ue_id(uint16_t ue_id) { +void rlc_pcap::set_ue_id(uint16_t ue_id) +{ this->ue_id = ue_id; } -void rlc_pcap::pack_and_write(uint8_t* pdu, uint32_t pdu_len_bytes, uint8_t mode, uint8_t direction, uint8_t priority, uint8_t seqnumberlength, uint16_t ueid, uint16_t channel_type, uint16_t channel_id) +void rlc_pcap::pack_and_write(uint8_t* pdu, + uint32_t pdu_len_bytes, + uint8_t mode, + uint8_t direction, + uint8_t priority, + uint8_t seqnumberlength, + uint16_t ueid, + uint16_t channel_type, + uint16_t channel_id) { if (enable_write) { RLC_Context_Info_t context; - context.rlcMode = mode; - context.direction = direction; - context.priority = priority; + context.rlcMode = mode; + context.direction = direction; + context.priority = priority; context.sequenceNumberLength = seqnumberlength; - context.ueid = ueid; - context.channelType = channel_type; - context.channelId = channel_id; - context.pduLength = pdu_len_bytes; + context.ueid = ueid; + context.channelType = channel_type; + context.channelId = channel_id; + context.pduLength = pdu_len_bytes; if (pdu) { LTE_PCAP_RLC_WritePDU(pcap_file, &context, pdu, pdu_len_bytes); } @@ -67,18 +76,34 @@ void rlc_pcap::pack_and_write(uint8_t* pdu, uint32_t pdu_len_bytes, uint8_t mode void rlc_pcap::write_dl_am_ccch(uint8_t* pdu, uint32_t pdu_len_bytes) { - uint8_t priority = 0; + uint8_t priority = 0; uint8_t seqnumberlength = 0; // normal length of 10bit - uint8_t channel_id = 0; - pack_and_write(pdu, pdu_len_bytes, RLC_AM_MODE, DIRECTION_DOWNLINK, priority, seqnumberlength, ue_id, CHANNEL_TYPE_CCCH, channel_id); + uint8_t channel_id = 0; + pack_and_write(pdu, + pdu_len_bytes, + RLC_AM_MODE, + DIRECTION_DOWNLINK, + priority, + seqnumberlength, + ue_id, + CHANNEL_TYPE_CCCH, + channel_id); } void rlc_pcap::write_ul_am_ccch(uint8_t* pdu, uint32_t pdu_len_bytes) { - uint8_t priority = 0; + uint8_t priority = 0; uint8_t seqnumberlength = 0; // normal length of 10bit - uint8_t channel_id = 0; - pack_and_write(pdu, pdu_len_bytes, RLC_AM_MODE, DIRECTION_UPLINK, priority, seqnumberlength, ue_id, CHANNEL_TYPE_CCCH, channel_id); + uint8_t channel_id = 0; + pack_and_write(pdu, + pdu_len_bytes, + RLC_AM_MODE, + DIRECTION_UPLINK, + priority, + seqnumberlength, + ue_id, + CHANNEL_TYPE_CCCH, + channel_id); } -} +} // namespace srslte diff --git a/lib/src/common/s1ap_pcap.cc b/lib/src/common/s1ap_pcap.cc index d3451b80f..69734f8a0 100644 --- a/lib/src/common/s1ap_pcap.cc +++ b/lib/src/common/s1ap_pcap.cc @@ -19,11 +19,10 @@ * */ -#include -#include "srslte/srslte.h" -#include "srslte/common/pcap.h" #include "srslte/common/s1ap_pcap.h" - +#include "srslte/common/pcap.h" +#include "srslte/srslte.h" +#include namespace srslte { @@ -33,7 +32,7 @@ void s1ap_pcap::enable() } void s1ap_pcap::open(const char* filename) { - pcap_file = LTE_PCAP_Open(S1AP_LTE_DLT, filename); + pcap_file = LTE_PCAP_Open(S1AP_LTE_DLT, filename); enable_write = true; } void s1ap_pcap::close() @@ -42,14 +41,14 @@ void s1ap_pcap::close() LTE_PCAP_Close(pcap_file); } -void s1ap_pcap::write_s1ap(uint8_t *pdu, uint32_t pdu_len_bytes) +void s1ap_pcap::write_s1ap(uint8_t* pdu, uint32_t pdu_len_bytes) { - if (enable_write) { - S1AP_Context_Info_t context; - if (pdu) { - LTE_PCAP_S1AP_WritePDU(pcap_file, &context, pdu, pdu_len_bytes); - } + if (enable_write) { + S1AP_Context_Info_t context; + if (pdu) { + LTE_PCAP_S1AP_WritePDU(pcap_file, &context, pdu, pdu_len_bytes); } + } } -} +} // namespace srslte diff --git a/lib/src/common/security.cc b/lib/src/common/security.cc index 56de0697f..e7e937283 100644 --- a/lib/src/common/security.cc +++ b/lib/src/common/security.cc @@ -36,70 +36,50 @@ namespace srslte { * Key Generation *****************************************************************************/ -uint8_t security_generate_k_asme( uint8_t *ck, - uint8_t *ik, - uint8_t *ak, - uint8_t *sqn, - uint16_t mcc, - uint16_t mnc, - uint8_t *k_asme) +uint8_t security_generate_k_asme(uint8_t* ck, + uint8_t* ik, + uint8_t* ak, + uint8_t* sqn, + uint16_t mcc, + uint16_t mnc, + uint8_t* k_asme) { - return liblte_security_generate_k_asme(ck, - ik, - ak, - sqn, - mcc, - mnc, - k_asme); + return liblte_security_generate_k_asme(ck, ik, ak, sqn, mcc, mnc, k_asme); } -uint8_t security_generate_k_enb( uint8_t *k_asme, - uint32_t nas_count, - uint8_t *k_enb) +uint8_t security_generate_k_enb(uint8_t* k_asme, uint32_t nas_count, uint8_t* k_enb) { - return liblte_security_generate_k_enb(k_asme, - nas_count, - k_enb); + return liblte_security_generate_k_enb(k_asme, nas_count, k_enb); } -uint8_t security_generate_k_enb_star( uint8_t *k_enb, - uint32_t pci, - uint32_t earfcn, - uint8_t *k_enb_star) +uint8_t security_generate_k_enb_star(uint8_t* k_enb, uint32_t pci, uint32_t earfcn, uint8_t* k_enb_star) { - return liblte_security_generate_k_enb_star(k_enb, - pci, - earfcn, - k_enb_star); + return liblte_security_generate_k_enb_star(k_enb, pci, earfcn, k_enb_star); } -uint8_t security_generate_nh( uint8_t *k_asme, - uint8_t *sync, - uint8_t *nh) +uint8_t security_generate_nh(uint8_t* k_asme, uint8_t* sync, uint8_t* nh) { - return liblte_security_generate_nh( k_asme, - sync, - nh); + return liblte_security_generate_nh(k_asme, sync, nh); } -uint8_t security_generate_k_nas( uint8_t *k_asme, - CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, - INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, - uint8_t *k_nas_enc, - uint8_t *k_nas_int) +uint8_t security_generate_k_nas(uint8_t* k_asme, + CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, + INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, + uint8_t* k_nas_enc, + uint8_t* k_nas_int) { - return liblte_security_generate_k_nas( k_asme, - (LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM)enc_alg_id, - (LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM)int_alg_id, - k_nas_enc, - k_nas_int); + return liblte_security_generate_k_nas(k_asme, + (LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM)enc_alg_id, + (LIBLTE_SECURITY_INTEGRITY_ALGORITHM_ID_ENUM)int_alg_id, + k_nas_enc, + k_nas_int); } -uint8_t security_generate_k_rrc( uint8_t *k_enb, - CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, - INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int) +uint8_t security_generate_k_rrc(uint8_t* k_enb, + CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, + INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int) { return liblte_security_generate_k_rrc(k_enb, (LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM)enc_alg_id, @@ -108,11 +88,11 @@ uint8_t security_generate_k_rrc( uint8_t *k_enb, k_rrc_int); } -uint8_t security_generate_k_up( uint8_t *k_enb, - CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, - INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, - uint8_t *k_up_enc, - uint8_t *k_up_int) +uint8_t security_generate_k_up(uint8_t* k_enb, + CIPHERING_ALGORITHM_ID_ENUM enc_alg_id, + INTEGRITY_ALGORITHM_ID_ENUM int_alg_id, + uint8_t* k_up_enc, + uint8_t* k_up_int) { return liblte_security_generate_k_up(k_enb, (LIBLTE_SECURITY_CIPHERING_ALGORITHM_ID_ENUM)enc_alg_id, @@ -125,39 +105,44 @@ uint8_t security_generate_k_up( uint8_t *k_enb, * Integrity Protection *****************************************************************************/ -uint8_t security_128_eia1( uint8_t *key, - uint32_t count, - uint32_t bearer, - uint8_t direction, - uint8_t *msg, - uint32_t msg_len, - uint8_t *mac) +uint8_t security_128_eia1(uint8_t* key, + uint32_t count, + uint32_t bearer, + uint8_t direction, + uint8_t* msg, + uint32_t msg_len, + uint8_t* mac) { uint32_t msg_len_bits; uint32_t i; - uint8_t *m_ptr; + uint8_t* m_ptr; - msg_len_bits = msg_len*8; - m_ptr = snow3g_f9(key, - count, - bearer<<27, - direction, - msg, - msg_len_bits); - for(i=0; i<4; i++) { + msg_len_bits = msg_len * 8; + m_ptr = snow3g_f9(key, count, bearer << 27, direction, msg, msg_len_bits); + for (i = 0; i < 4; i++) { mac[i] = m_ptr[i]; } return SRSLTE_SUCCESS; } -uint8_t security_128_eia2( - uint8_t* key, uint32_t count, uint32_t bearer, uint8_t direction, uint8_t* msg, uint32_t msg_len, uint8_t* mac) +uint8_t security_128_eia2(uint8_t* key, + uint32_t count, + uint32_t bearer, + uint8_t direction, + uint8_t* msg, + uint32_t msg_len, + uint8_t* mac) { return liblte_security_128_eia2(key, count, bearer, direction, msg, msg_len, mac); } -uint8_t security_128_eia3( - uint8_t* key, uint32_t count, uint32_t bearer, uint8_t direction, uint8_t* msg, uint32_t msg_len, uint8_t* mac) +uint8_t security_128_eia3(uint8_t* key, + uint32_t count, + uint32_t bearer, + uint8_t direction, + uint8_t* msg, + uint32_t msg_len, + uint8_t* mac) { return liblte_security_128_eia3(key, count, bearer, direction, msg, msg_len * 8, mac); } @@ -178,33 +163,37 @@ uint8_t security_md5(const uint8_t* input, size_t len, uint8_t* output) * Encryption / Decryption *****************************************************************************/ -uint8_t security_128_eea1(uint8_t *key, - uint32_t count, - uint8_t bearer, - uint8_t direction, - uint8_t *msg, - uint32_t msg_len, - uint8_t *msg_out){ - - return liblte_security_encryption_eea1(key, - count, - bearer, - direction, - msg, - msg_len * 8, - msg_out); +uint8_t security_128_eea1(uint8_t* key, + uint32_t count, + uint8_t bearer, + uint8_t direction, + uint8_t* msg, + uint32_t msg_len, + uint8_t* msg_out) +{ + return liblte_security_encryption_eea1(key, count, bearer, direction, msg, msg_len * 8, msg_out); } -uint8_t security_128_eea2( - uint8_t* key, uint32_t count, uint8_t bearer, uint8_t direction, uint8_t* msg, uint32_t msg_len, uint8_t* msg_out) +uint8_t security_128_eea2(uint8_t* key, + uint32_t count, + uint8_t bearer, + uint8_t direction, + uint8_t* msg, + uint32_t msg_len, + uint8_t* msg_out) { return liblte_security_encryption_eea2(key, count, bearer, direction, msg, msg_len * 8, msg_out); } -uint8_t security_128_eea3( - uint8_t* key, uint32_t count, uint8_t bearer, uint8_t direction, uint8_t* msg, uint32_t msg_len, uint8_t* msg_out) +uint8_t security_128_eea3(uint8_t* key, + uint32_t count, + uint8_t bearer, + uint8_t direction, + uint8_t* msg, + uint32_t msg_len, + uint8_t* msg_out) { return liblte_security_encryption_eea3(key, count, bearer, direction, msg, msg_len * 8, msg_out); @@ -218,62 +207,25 @@ uint8_t compute_opc(uint8_t* k, uint8_t* op, uint8_t* opc) return liblte_compute_opc(k, op, opc); } -uint8_t security_milenage_f1( uint8_t *k, - uint8_t *op, - uint8_t *rand, - uint8_t *sqn, - uint8_t *amf, - uint8_t *mac_a) +uint8_t security_milenage_f1(uint8_t* k, uint8_t* op, uint8_t* rand, uint8_t* sqn, uint8_t* amf, uint8_t* mac_a) { - return liblte_security_milenage_f1(k, - op, - rand, - sqn, - amf, - mac_a); + return liblte_security_milenage_f1(k, op, rand, sqn, amf, mac_a); } -uint8_t security_milenage_f1_star( uint8_t *k, - uint8_t *op, - uint8_t *rand, - uint8_t *sqn, - uint8_t *amf, - uint8_t *mac_s) +uint8_t security_milenage_f1_star(uint8_t* k, uint8_t* op, uint8_t* rand, uint8_t* sqn, uint8_t* amf, uint8_t* mac_s) { - return liblte_security_milenage_f1_star(k, - op, - rand, - sqn, - amf, - mac_s); + return liblte_security_milenage_f1_star(k, op, rand, sqn, amf, mac_s); } -uint8_t security_milenage_f2345( uint8_t *k, - uint8_t *op, - uint8_t *rand, - uint8_t *res, - uint8_t *ck, - uint8_t *ik, - uint8_t *ak) +uint8_t +security_milenage_f2345(uint8_t* k, uint8_t* op, uint8_t* rand, uint8_t* res, uint8_t* ck, uint8_t* ik, uint8_t* ak) { - return liblte_security_milenage_f2345(k, - op, - rand, - res, - ck, - ik, - ak); + return liblte_security_milenage_f2345(k, op, rand, res, ck, ik, ak); } -uint8_t security_milenage_f5_star( uint8_t *k, - uint8_t *op, - uint8_t *rand, - uint8_t *ak) +uint8_t security_milenage_f5_star(uint8_t* k, uint8_t* op, uint8_t* rand, uint8_t* ak) { - return liblte_security_milenage_f5_star(k, - op, - rand, - ak); + return liblte_security_milenage_f5_star(k, op, rand, ak); } } // namespace srslte diff --git a/lib/src/common/snow_3g.cc b/lib/src/common/snow_3g.cc index 3c5658623..b24e80ab6 100644 --- a/lib/src/common/snow_3g.cc +++ b/lib/src/common/snow_3g.cc @@ -1,29 +1,29 @@ /*------------------------------------------------------------------------ -* snow_3g.c -* -* Adapted from ETSI/SAGE specifications: -* "Specification of the 3GPP Confidentiality and -* Integrity Algorithms UEA2 & UIA2. -* Document 1: UEA2 and UIA2 Specification" -* "Specification of the 3GPP Confidentiality -* and Integrity Algorithms UEA2 & UIA2. -* Document 2: SNOW 3G Specification" -*------------------------------------------------------------------------*/ + * snow_3g.c + * + * Adapted from ETSI/SAGE specifications: + * "Specification of the 3GPP Confidentiality and + * Integrity Algorithms UEA2 & UIA2. + * Document 1: UEA2 and UIA2 Specification" + * "Specification of the 3GPP Confidentiality + * and Integrity Algorithms UEA2 & UIA2. + * Document 2: SNOW 3G Specification" + *------------------------------------------------------------------------*/ #include "srslte/common/snow_3g.h" /* LFSR */ -u32 LFSR_S0 = 0x00; -u32 LFSR_S1 = 0x00; -u32 LFSR_S2 = 0x00; -u32 LFSR_S3 = 0x00; -u32 LFSR_S4 = 0x00; -u32 LFSR_S5 = 0x00; -u32 LFSR_S6 = 0x00; -u32 LFSR_S7 = 0x00; -u32 LFSR_S8 = 0x00; -u32 LFSR_S9 = 0x00; +u32 LFSR_S0 = 0x00; +u32 LFSR_S1 = 0x00; +u32 LFSR_S2 = 0x00; +u32 LFSR_S3 = 0x00; +u32 LFSR_S4 = 0x00; +u32 LFSR_S5 = 0x00; +u32 LFSR_S6 = 0x00; +u32 LFSR_S7 = 0x00; +u32 LFSR_S8 = 0x00; +u32 LFSR_S9 = 0x00; u32 LFSR_S10 = 0x00; u32 LFSR_S11 = 0x00; u32 LFSR_S12 = 0x00; @@ -40,393 +40,336 @@ u32 FSM_R3 = 0x00; /* Rijndael S-box SR */ u8 SR[256] = { -0x63,0x7C,0x77,0x7B,0xF2,0x6B,0x6F,0xC5,0x30,0x01,0x67,0x2B,0xFE,0xD7,0xAB,0x76, -0xCA,0x82,0xC9,0x7D,0xFA,0x59,0x47,0xF0,0xAD,0xD4,0xA2,0xAF,0x9C,0xA4,0x72,0xC0, -0xB7,0xFD,0x93,0x26,0x36,0x3F,0xF7,0xCC,0x34,0xA5,0xE5,0xF1,0x71,0xD8,0x31,0x15, -0x04,0xC7,0x23,0xC3,0x18,0x96,0x05,0x9A,0x07,0x12,0x80,0xE2,0xEB,0x27,0xB2,0x75, -0x09,0x83,0x2C,0x1A,0x1B,0x6E,0x5A,0xA0,0x52,0x3B,0xD6,0xB3,0x29,0xE3,0x2F,0x84, -0x53,0xD1,0x00,0xED,0x20,0xFC,0xB1,0x5B,0x6A,0xCB,0xBE,0x39,0x4A,0x4C,0x58,0xCF, -0xD0,0xEF,0xAA,0xFB,0x43,0x4D,0x33,0x85,0x45,0xF9,0x02,0x7F,0x50,0x3C,0x9F,0xA8, -0x51,0xA3,0x40,0x8F,0x92,0x9D,0x38,0xF5,0xBC,0xB6,0xDA,0x21,0x10,0xFF,0xF3,0xD2, -0xCD,0x0C,0x13,0xEC,0x5F,0x97,0x44,0x17,0xC4,0xA7,0x7E,0x3D,0x64,0x5D,0x19,0x73, -0x60,0x81,0x4F,0xDC,0x22,0x2A,0x90,0x88,0x46,0xEE,0xB8,0x14,0xDE,0x5E,0x0B,0xDB, -0xE0,0x32,0x3A,0x0A,0x49,0x06,0x24,0x5C,0xC2,0xD3,0xAC,0x62,0x91,0x95,0xE4,0x79, -0xE7,0xC8,0x37,0x6D,0x8D,0xD5,0x4E,0xA9,0x6C,0x56,0xF4,0xEA,0x65,0x7A,0xAE,0x08, -0xBA,0x78,0x25,0x2E,0x1C,0xA6,0xB4,0xC6,0xE8,0xDD,0x74,0x1F,0x4B,0xBD,0x8B,0x8A, -0x70,0x3E,0xB5,0x66,0x48,0x03,0xF6,0x0E,0x61,0x35,0x57,0xB9,0x86,0xC1,0x1D,0x9E, -0xE1,0xF8,0x98,0x11,0x69,0xD9,0x8E,0x94,0x9B,0x1E,0x87,0xE9,0xCE,0x55,0x28,0xDF, -0x8C,0xA1,0x89,0x0D,0xBF,0xE6,0x42,0x68,0x41,0x99,0x2D,0x0F,0xB0,0x54,0xBB,0x16 -}; + 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, 0xCA, 0x82, 0xC9, + 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, + 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, + 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, 0x52, 0x3B, 0xD6, 0xB3, + 0x29, 0xE3, 0x2F, 0x84, 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, + 0xCF, 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, 0x51, 0xA3, + 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, 0xCD, 0x0C, 0x13, 0xEC, 0x5F, + 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, + 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, 0xC2, 0xD3, 0xAC, + 0x62, 0x91, 0x95, 0xE4, 0x79, 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, + 0xAE, 0x08, 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, 0x70, + 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, 0xE1, 0xF8, 0x98, 0x11, + 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, + 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16}; /* S-box SQ */ u8 SQ[256] = { -0x25,0x24,0x73,0x67,0xD7,0xAE,0x5C,0x30,0xA4,0xEE,0x6E,0xCB,0x7D,0xB5,0x82,0xDB, -0xE4,0x8E,0x48,0x49,0x4F,0x5D,0x6A,0x78,0x70,0x88,0xE8,0x5F,0x5E,0x84,0x65,0xE2, -0xD8,0xE9,0xCC,0xED,0x40,0x2F,0x11,0x28,0x57,0xD2,0xAC,0xE3,0x4A,0x15,0x1B,0xB9, -0xB2,0x80,0x85,0xA6,0x2E,0x02,0x47,0x29,0x07,0x4B,0x0E,0xC1,0x51,0xAA,0x89,0xD4, -0xCA,0x01,0x46,0xB3,0xEF,0xDD,0x44,0x7B,0xC2,0x7F,0xBE,0xC3,0x9F,0x20,0x4C,0x64, -0x83,0xA2,0x68,0x42,0x13,0xB4,0x41,0xCD,0xBA,0xC6,0xBB,0x6D,0x4D,0x71,0x21,0xF4, -0x8D,0xB0,0xE5,0x93,0xFE,0x8F,0xE6,0xCF,0x43,0x45,0x31,0x22,0x37,0x36,0x96,0xFA, -0xBC,0x0F,0x08,0x52,0x1D,0x55,0x1A,0xC5,0x4E,0x23,0x69,0x7A,0x92,0xFF,0x5B,0x5A, -0xEB,0x9A,0x1C,0xA9,0xD1,0x7E,0x0D,0xFC,0x50,0x8A,0xB6,0x62,0xF5,0x0A,0xF8,0xDC, -0x03,0x3C,0x0C,0x39,0xF1,0xB8,0xF3,0x3D,0xF2,0xD5,0x97,0x66,0x81,0x32,0xA0,0x00, -0x06,0xCE,0xF6,0xEA,0xB7,0x17,0xF7,0x8C,0x79,0xD6,0xA7,0xBF,0x8B,0x3F,0x1F,0x53, -0x63,0x75,0x35,0x2C,0x60,0xFD,0x27,0xD3,0x94,0xA5,0x7C,0xA1,0x05,0x58,0x2D,0xBD, -0xD9,0xC7,0xAF,0x6B,0x54,0x0B,0xE0,0x38,0x04,0xC8,0x9D,0xE7,0x14,0xB1,0x87,0x9C, -0xDF,0x6F,0xF9,0xDA,0x2A,0xC4,0x59,0x16,0x74,0x91,0xAB,0x26,0x61,0x76,0x34,0x2B, -0xAD,0x99,0xFB,0x72,0xEC,0x33,0x12,0xDE,0x98,0x3B,0xC0,0x9B,0x3E,0x18,0x10,0x3A, -0x56,0xE1,0x77,0xC9,0x1E,0x9E,0x95,0xA3,0x90,0x19,0xA8,0x6C,0x09,0xD0,0xF0,0x86 -}; + 0x25, 0x24, 0x73, 0x67, 0xD7, 0xAE, 0x5C, 0x30, 0xA4, 0xEE, 0x6E, 0xCB, 0x7D, 0xB5, 0x82, 0xDB, 0xE4, 0x8E, 0x48, + 0x49, 0x4F, 0x5D, 0x6A, 0x78, 0x70, 0x88, 0xE8, 0x5F, 0x5E, 0x84, 0x65, 0xE2, 0xD8, 0xE9, 0xCC, 0xED, 0x40, 0x2F, + 0x11, 0x28, 0x57, 0xD2, 0xAC, 0xE3, 0x4A, 0x15, 0x1B, 0xB9, 0xB2, 0x80, 0x85, 0xA6, 0x2E, 0x02, 0x47, 0x29, 0x07, + 0x4B, 0x0E, 0xC1, 0x51, 0xAA, 0x89, 0xD4, 0xCA, 0x01, 0x46, 0xB3, 0xEF, 0xDD, 0x44, 0x7B, 0xC2, 0x7F, 0xBE, 0xC3, + 0x9F, 0x20, 0x4C, 0x64, 0x83, 0xA2, 0x68, 0x42, 0x13, 0xB4, 0x41, 0xCD, 0xBA, 0xC6, 0xBB, 0x6D, 0x4D, 0x71, 0x21, + 0xF4, 0x8D, 0xB0, 0xE5, 0x93, 0xFE, 0x8F, 0xE6, 0xCF, 0x43, 0x45, 0x31, 0x22, 0x37, 0x36, 0x96, 0xFA, 0xBC, 0x0F, + 0x08, 0x52, 0x1D, 0x55, 0x1A, 0xC5, 0x4E, 0x23, 0x69, 0x7A, 0x92, 0xFF, 0x5B, 0x5A, 0xEB, 0x9A, 0x1C, 0xA9, 0xD1, + 0x7E, 0x0D, 0xFC, 0x50, 0x8A, 0xB6, 0x62, 0xF5, 0x0A, 0xF8, 0xDC, 0x03, 0x3C, 0x0C, 0x39, 0xF1, 0xB8, 0xF3, 0x3D, + 0xF2, 0xD5, 0x97, 0x66, 0x81, 0x32, 0xA0, 0x00, 0x06, 0xCE, 0xF6, 0xEA, 0xB7, 0x17, 0xF7, 0x8C, 0x79, 0xD6, 0xA7, + 0xBF, 0x8B, 0x3F, 0x1F, 0x53, 0x63, 0x75, 0x35, 0x2C, 0x60, 0xFD, 0x27, 0xD3, 0x94, 0xA5, 0x7C, 0xA1, 0x05, 0x58, + 0x2D, 0xBD, 0xD9, 0xC7, 0xAF, 0x6B, 0x54, 0x0B, 0xE0, 0x38, 0x04, 0xC8, 0x9D, 0xE7, 0x14, 0xB1, 0x87, 0x9C, 0xDF, + 0x6F, 0xF9, 0xDA, 0x2A, 0xC4, 0x59, 0x16, 0x74, 0x91, 0xAB, 0x26, 0x61, 0x76, 0x34, 0x2B, 0xAD, 0x99, 0xFB, 0x72, + 0xEC, 0x33, 0x12, 0xDE, 0x98, 0x3B, 0xC0, 0x9B, 0x3E, 0x18, 0x10, 0x3A, 0x56, 0xE1, 0x77, 0xC9, 0x1E, 0x9E, 0x95, + 0xA3, 0x90, 0x19, 0xA8, 0x6C, 0x09, 0xD0, 0xF0, 0x86}; /* MULx. -* Input V: an 8-bit input. -* Input c: an 8-bit input. -* Output : an 8-bit output. -* See section 3.1.1 for details. -*/ + * Input V: an 8-bit input. + * Input c: an 8-bit input. + * Output : an 8-bit output. + * See section 3.1.1 for details. + */ u8 MULx(u8 V, u8 c) { - if ( V & 0x80 ) - return ( (V << 1) ^ c); - else - return ( V << 1); + if (V & 0x80) + return ((V << 1) ^ c); + else + return (V << 1); } /* MULxPOW. -* Input V: an 8-bit input. -* Input i: a positive integer. -* Input c: an 8-bit input. -* Output : an 8-bit output. -* See section 3.1.2 for details. -*/ + * Input V: an 8-bit input. + * Input i: a positive integer. + * Input c: an 8-bit input. + * Output : an 8-bit output. + * See section 3.1.2 for details. + */ u8 MULxPOW(u8 V, u8 i, u8 c) { - if ( i == 0) - return V; - else - return MULx( MULxPOW( V, i-1, c ), c); + if (i == 0) + return V; + else + return MULx(MULxPOW(V, i - 1, c), c); } /* The function MUL alpha. -* Input c: 8-bit input. -* Output : 32-bit output. -* See section 3.4.2 for details. -*/ + * Input c: 8-bit input. + * Output : 32-bit output. + * See section 3.4.2 for details. + */ u32 MULalpha(u8 c) { - return ( ( ((u32)MULxPOW(c, 23, 0xa9)) << 24 ) | - ( ((u32)MULxPOW(c, 245, 0xa9)) << 16 ) | - ( ((u32)MULxPOW(c, 48, 0xa9)) << 8 ) | - ( ((u32)MULxPOW(c, 239, 0xa9)) ) ) ; + return ((((u32)MULxPOW(c, 23, 0xa9)) << 24) | (((u32)MULxPOW(c, 245, 0xa9)) << 16) | + (((u32)MULxPOW(c, 48, 0xa9)) << 8) | (((u32)MULxPOW(c, 239, 0xa9)))); } /* The function DIV alpha. -* Input c: 8-bit input. -* Output : 32-bit output. -* See section 3.4.3 for details. -*/ + * Input c: 8-bit input. + * Output : 32-bit output. + * See section 3.4.3 for details. + */ u32 DIValpha(u8 c) { - return ( ( ((u32)MULxPOW(c, 16, 0xa9)) << 24 ) | - ( ((u32)MULxPOW(c, 39, 0xa9)) << 16 ) | - ( ((u32)MULxPOW(c, 6, 0xa9)) << 8 ) | - ( ((u32)MULxPOW(c, 64, 0xa9)) ) ) ; + return ((((u32)MULxPOW(c, 16, 0xa9)) << 24) | (((u32)MULxPOW(c, 39, 0xa9)) << 16) | + (((u32)MULxPOW(c, 6, 0xa9)) << 8) | (((u32)MULxPOW(c, 64, 0xa9)))); } /* The 32x32-bit S-Box S1 -* Input: a 32-bit input. -* Output: a 32-bit output of S1 box. -* See section 3.3.1. -*/ + * Input: a 32-bit input. + * Output: a 32-bit output of S1 box. + * See section 3.3.1. + */ u32 S1(u32 w) { - u8 r0=0, r1=0, r2=0, r3=0; - u8 srw0 = SR[ (u8)((w >> 24) & 0xff) ]; - u8 srw1 = SR[ (u8)((w >> 16) & 0xff) ]; - u8 srw2 = SR[ (u8)((w >> 8) & 0xff) ]; - u8 srw3 = SR[ (u8)((w) & 0xff) ]; - r0 = ( ( MULx( srw0 , 0x1b) ) ^ - ( srw1 ) ^ - ( srw2 ) ^ - ( (MULx( srw3, 0x1b)) ^ srw3 ) - ); - r1 = ( ( ( MULx( srw0 , 0x1b) ) ^ srw0 ) ^ - ( MULx(srw1, 0x1b) ) ^ - ( srw2 ) ^ - ( srw3 ) - ); - r2 = ( ( srw0 ) ^ - ( ( MULx( srw1 , 0x1b) ) ^ srw1 ) ^ - ( MULx(srw2, 0x1b) ) ^ - ( srw3 ) - ); - r3 = ( ( srw0 ) ^ - ( srw1 ) ^ - ( ( MULx( srw2 , 0x1b) ) ^ srw2 ) ^ - ( MULx( srw3, 0x1b) ) - ); - - return ( ( ((u32)r0) << 24 ) | ( ((u32)r1) << 16 ) | ( ((u32)r2) << 8 ) | - ( ((u32)r3) ) ); + u8 r0 = 0, r1 = 0, r2 = 0, r3 = 0; + u8 srw0 = SR[(u8)((w >> 24) & 0xff)]; + u8 srw1 = SR[(u8)((w >> 16) & 0xff)]; + u8 srw2 = SR[(u8)((w >> 8) & 0xff)]; + u8 srw3 = SR[(u8)((w)&0xff)]; + r0 = ((MULx(srw0, 0x1b)) ^ (srw1) ^ (srw2) ^ ((MULx(srw3, 0x1b)) ^ srw3)); + r1 = (((MULx(srw0, 0x1b)) ^ srw0) ^ (MULx(srw1, 0x1b)) ^ (srw2) ^ (srw3)); + r2 = ((srw0) ^ ((MULx(srw1, 0x1b)) ^ srw1) ^ (MULx(srw2, 0x1b)) ^ (srw3)); + r3 = ((srw0) ^ (srw1) ^ ((MULx(srw2, 0x1b)) ^ srw2) ^ (MULx(srw3, 0x1b))); + + return ((((u32)r0) << 24) | (((u32)r1) << 16) | (((u32)r2) << 8) | (((u32)r3))); } /* The 32x32-bit S-Box S2 -* Input: a 32-bit input. -* Output: a 32-bit output of S2 box. -* See section 3.3.2. -*/ + * Input: a 32-bit input. + * Output: a 32-bit output of S2 box. + * See section 3.3.2. + */ u32 S2(u32 w) { - u8 r0=0, r1=0, r2=0, r3=0; - u8 sqw0 = SQ[ (u8)((w >> 24) & 0xff) ]; - u8 sqw1 = SQ[ (u8)((w >> 16) & 0xff) ]; - u8 sqw2 = SQ[ (u8)((w >> 8) & 0xff) ]; - u8 sqw3 = SQ[ (u8)((w) & 0xff) ]; - r0 = ( ( MULx( sqw0 , 0x69) ) ^ - ( sqw1 ) ^ - ( sqw2 ) ^ - ( (MULx( sqw3, 0x69)) ^ sqw3 ) - ); - r1 = ( ( ( MULx( sqw0 , 0x69) ) ^ sqw0 ) ^ - ( MULx(sqw1, 0x69) ) ^ - ( sqw2 ) ^ - ( sqw3 ) - ); - r2 = ( ( sqw0 ) ^ - ( ( MULx( sqw1 , 0x69) ) ^ sqw1 ) ^ - ( MULx(sqw2, 0x69) ) ^ - ( sqw3 ) - ); - r3 = ( ( sqw0 ) ^ - ( sqw1 ) ^ - ( ( MULx( sqw2 , 0x69) ) ^ sqw2 ) ^ - ( MULx( sqw3, 0x69) ) - ); - return ( ( ((u32)r0) << 24 ) | ( ((u32)r1) << 16 ) | ( ((u32)r2) << 8 ) | - ( ((u32)r3) ) ); + u8 r0 = 0, r1 = 0, r2 = 0, r3 = 0; + u8 sqw0 = SQ[(u8)((w >> 24) & 0xff)]; + u8 sqw1 = SQ[(u8)((w >> 16) & 0xff)]; + u8 sqw2 = SQ[(u8)((w >> 8) & 0xff)]; + u8 sqw3 = SQ[(u8)((w)&0xff)]; + r0 = ((MULx(sqw0, 0x69)) ^ (sqw1) ^ (sqw2) ^ ((MULx(sqw3, 0x69)) ^ sqw3)); + r1 = (((MULx(sqw0, 0x69)) ^ sqw0) ^ (MULx(sqw1, 0x69)) ^ (sqw2) ^ (sqw3)); + r2 = ((sqw0) ^ ((MULx(sqw1, 0x69)) ^ sqw1) ^ (MULx(sqw2, 0x69)) ^ (sqw3)); + r3 = ((sqw0) ^ (sqw1) ^ ((MULx(sqw2, 0x69)) ^ sqw2) ^ (MULx(sqw3, 0x69))); + return ((((u32)r0) << 24) | (((u32)r1) << 16) | (((u32)r2) << 8) | (((u32)r3))); } /* Clocking LFSR in initialization mode. -* LFSR Registers S0 to S15 are updated as the LFSR receives a single clock. -* Input F: a 32-bit word comes from output of FSM. -* See section 3.4.4. -*/ + * LFSR Registers S0 to S15 are updated as the LFSR receives a single clock. + * Input F: a 32-bit word comes from output of FSM. + * See section 3.4.4. + */ void ClockLFSRInitializationMode(u32 F) { - u32 v = ( ( (LFSR_S0 << 8) & 0xffffff00 ) ^ - ( MULalpha( (u8)((LFSR_S0>>24) & 0xff) ) ) ^ - ( LFSR_S2 ) ^ - ( (LFSR_S11 >> 8) & 0x00ffffff ) ^ - ( DIValpha( (u8)( ( LFSR_S11) & 0xff ) ) ) ^ - ( F ) - ); - LFSR_S0 = LFSR_S1; - LFSR_S1 = LFSR_S2; - LFSR_S2 = LFSR_S3; - LFSR_S3 = LFSR_S4; - LFSR_S4 = LFSR_S5; - LFSR_S5 = LFSR_S6; - LFSR_S6 = LFSR_S7; - LFSR_S7 = LFSR_S8; - LFSR_S8 = LFSR_S9; - LFSR_S9 = LFSR_S10; - LFSR_S10 = LFSR_S11; - LFSR_S11 = LFSR_S12; - LFSR_S12 = LFSR_S13; - LFSR_S13 = LFSR_S14; - LFSR_S14 = LFSR_S15; - LFSR_S15 = v; + u32 v = (((LFSR_S0 << 8) & 0xffffff00) ^ (MULalpha((u8)((LFSR_S0 >> 24) & 0xff))) ^ (LFSR_S2) ^ + ((LFSR_S11 >> 8) & 0x00ffffff) ^ (DIValpha((u8)((LFSR_S11)&0xff))) ^ (F)); + LFSR_S0 = LFSR_S1; + LFSR_S1 = LFSR_S2; + LFSR_S2 = LFSR_S3; + LFSR_S3 = LFSR_S4; + LFSR_S4 = LFSR_S5; + LFSR_S5 = LFSR_S6; + LFSR_S6 = LFSR_S7; + LFSR_S7 = LFSR_S8; + LFSR_S8 = LFSR_S9; + LFSR_S9 = LFSR_S10; + LFSR_S10 = LFSR_S11; + LFSR_S11 = LFSR_S12; + LFSR_S12 = LFSR_S13; + LFSR_S13 = LFSR_S14; + LFSR_S14 = LFSR_S15; + LFSR_S15 = v; } /* Clocking LFSR in keystream mode. -* LFSR Registers S0 to S15 are updated as the LFSR receives a single clock. -* See section 3.4.5. -*/ + * LFSR Registers S0 to S15 are updated as the LFSR receives a single clock. + * See section 3.4.5. + */ void ClockLFSRKeyStreamMode() { - u32 v = ( ( (LFSR_S0 << 8) & 0xffffff00 ) ^ - ( MULalpha( (u8)((LFSR_S0>>24) & 0xff) ) ) ^ - ( LFSR_S2 ) ^ - ( (LFSR_S11 >> 8) & 0x00ffffff ) ^ - ( DIValpha( (u8)( ( LFSR_S11) & 0xff ) ) ) - ); - LFSR_S0 = LFSR_S1; - LFSR_S1 = LFSR_S2; - LFSR_S2 = LFSR_S3; - LFSR_S3 = LFSR_S4; - LFSR_S4 = LFSR_S5; - LFSR_S5 = LFSR_S6; - LFSR_S6 = LFSR_S7; - LFSR_S7 = LFSR_S8; - LFSR_S8 = LFSR_S9; - LFSR_S9 = LFSR_S10; - LFSR_S10 = LFSR_S11; - LFSR_S11 = LFSR_S12; - LFSR_S12 = LFSR_S13; - LFSR_S13 = LFSR_S14; - LFSR_S14 = LFSR_S15; - LFSR_S15 = v; + u32 v = (((LFSR_S0 << 8) & 0xffffff00) ^ (MULalpha((u8)((LFSR_S0 >> 24) & 0xff))) ^ (LFSR_S2) ^ + ((LFSR_S11 >> 8) & 0x00ffffff) ^ (DIValpha((u8)((LFSR_S11)&0xff)))); + LFSR_S0 = LFSR_S1; + LFSR_S1 = LFSR_S2; + LFSR_S2 = LFSR_S3; + LFSR_S3 = LFSR_S4; + LFSR_S4 = LFSR_S5; + LFSR_S5 = LFSR_S6; + LFSR_S6 = LFSR_S7; + LFSR_S7 = LFSR_S8; + LFSR_S8 = LFSR_S9; + LFSR_S9 = LFSR_S10; + LFSR_S10 = LFSR_S11; + LFSR_S11 = LFSR_S12; + LFSR_S12 = LFSR_S13; + LFSR_S13 = LFSR_S14; + LFSR_S14 = LFSR_S15; + LFSR_S15 = v; } /* Clocking FSM. -* Produces a 32-bit word F. -* Updates FSM registers R1, R2, R3. -* See Section 3.4.6. -*/ + * Produces a 32-bit word F. + * Updates FSM registers R1, R2, R3. + * See Section 3.4.6. + */ u32 ClockFSM() { - u32 F = ( ( LFSR_S15 + FSM_R1 ) & 0xffffffff ) ^ FSM_R2 ; - u32 r = ( FSM_R2 + ( FSM_R3 ^ LFSR_S5 ) ) & 0xffffffff ; - FSM_R3 = S2(FSM_R2); - FSM_R2 = S1(FSM_R1); - FSM_R1 = r; - return F; + u32 F = ((LFSR_S15 + FSM_R1) & 0xffffffff) ^ FSM_R2; + u32 r = (FSM_R2 + (FSM_R3 ^ LFSR_S5)) & 0xffffffff; + FSM_R3 = S2(FSM_R2); + FSM_R2 = S1(FSM_R1); + FSM_R1 = r; + return F; } /* Initialization. -* Input k[4]: Four 32-bit words making up 128-bit key. -* Input IV[4]: Four 32-bit words making 128-bit initialization variable. -* Output: All the LFSRs and FSM are initialized for key generation. -* See Section 4.1. -*/ + * Input k[4]: Four 32-bit words making up 128-bit key. + * Input IV[4]: Four 32-bit words making 128-bit initialization variable. + * Output: All the LFSRs and FSM are initialized for key generation. + * See Section 4.1. + */ void snow3g_initialize(u32 k[4], u32 IV[4]) { - u8 i=0; - u32 F = 0x0; - LFSR_S15 = k[3] ^ IV[0]; - LFSR_S14 = k[2]; - LFSR_S13 = k[1]; - LFSR_S12 = k[0] ^ IV[1]; - LFSR_S11 = k[3] ^ 0xffffffff; - LFSR_S10 = k[2] ^ 0xffffffff ^ IV[2]; - LFSR_S9 = k[1] ^ 0xffffffff ^ IV[3]; - LFSR_S8 = k[0] ^ 0xffffffff; - LFSR_S7 = k[3]; - LFSR_S6 = k[2]; - LFSR_S5 = k[1]; - LFSR_S4 = k[0]; - LFSR_S3 = k[3] ^ 0xffffffff; - LFSR_S2 = k[2] ^ 0xffffffff; - LFSR_S1 = k[1] ^ 0xffffffff; - LFSR_S0 = k[0] ^ 0xffffffff; - FSM_R1 = 0x0; - FSM_R2 = 0x0; - FSM_R3 = 0x0; - for(i=0;i<32;i++) - { - F = ClockFSM(); - ClockLFSRInitializationMode(F); - } + u8 i = 0; + u32 F = 0x0; + LFSR_S15 = k[3] ^ IV[0]; + LFSR_S14 = k[2]; + LFSR_S13 = k[1]; + LFSR_S12 = k[0] ^ IV[1]; + LFSR_S11 = k[3] ^ 0xffffffff; + LFSR_S10 = k[2] ^ 0xffffffff ^ IV[2]; + LFSR_S9 = k[1] ^ 0xffffffff ^ IV[3]; + LFSR_S8 = k[0] ^ 0xffffffff; + LFSR_S7 = k[3]; + LFSR_S6 = k[2]; + LFSR_S5 = k[1]; + LFSR_S4 = k[0]; + LFSR_S3 = k[3] ^ 0xffffffff; + LFSR_S2 = k[2] ^ 0xffffffff; + LFSR_S1 = k[1] ^ 0xffffffff; + LFSR_S0 = k[0] ^ 0xffffffff; + FSM_R1 = 0x0; + FSM_R2 = 0x0; + FSM_R3 = 0x0; + for (i = 0; i < 32; i++) { + F = ClockFSM(); + ClockLFSRInitializationMode(F); + } } /* Generation of Keystream. -* input n: number of 32-bit words of keystream. -* input z: space for the generated keystream, assumes -* memory is allocated already. -* output: generated keystream which is filled in z -* See section 4.2. -*/ - -void snow3g_generate_keystream(u32 n, u32 *ks) + * input n: number of 32-bit words of keystream. + * input z: space for the generated keystream, assumes + * memory is allocated already. + * output: generated keystream which is filled in z + * See section 4.2. + */ + +void snow3g_generate_keystream(u32 n, u32* ks) { - u32 t = 0; - u32 F = 0x0; - ClockFSM(); /* Clock FSM once. Discard the output. */ - ClockLFSRKeyStreamMode(); /* Clock LFSR in keystream mode once. */ - for ( t=0; t> 24) & 0xff; - data[4*i+1] ^= (u8) (KS[i] >> 16) & 0xff; - data[4*i+2] ^= (u8) (KS[i] >> 8) & 0xff; - data[4*i+3] ^= (u8) (KS[i] ) & 0xff; - } - - free(KS); - - /* zero last bits of data in case its length is not byte-aligned - this is an addition to the C reference code, which did not handle it */ - if (lastbits) - data[length/8] &= 256 - (1<> 24) & 0xff; + data[4 * i + 1] ^= (u8)(KS[i] >> 16) & 0xff; + data[4 * i + 2] ^= (u8)(KS[i] >> 8) & 0xff; + data[4 * i + 3] ^= (u8)(KS[i]) & 0xff; + } + + free(KS); + + /* zero last bits of data in case its length is not byte-aligned + this is an addition to the C reference code, which did not handle it */ + if (lastbits) + data[length / 8] &= 256 - (1 << lastbits); } /* MUL64x. * Input V: a 64-bit input. * Input c: a 64-bit input. * Output : a 64-bit output. - * A 64-bit memory is allocated which is to be freed by the calling + * A 64-bit memory is allocated which is to be freed by the calling * function. * See section 4.3.2 for details. */ u64 MUL64x(u64 V, u64 c) { - if ( V & 0x8000000000000000 ) - return (V << 1) ^ c; - else - return V << 1; + if (V & 0x8000000000000000) + return (V << 1) ^ c; + else + return V << 1; } /* MUL64xPOW. @@ -439,10 +382,10 @@ u64 MUL64x(u64 V, u64 c) */ u64 MUL64xPOW(u64 V, u8 i, u64 c) { - if ( i == 0) - return V; - else - return MUL64x( MUL64xPOW(V,i-1,c) , c); + if (i == 0) + return V; + else + return MUL64x(MUL64xPOW(V, i - 1, c), c); } /* MUL64. @@ -450,21 +393,20 @@ u64 MUL64xPOW(u64 V, u8 i, u64 c) * Input P: a 64-bit input. * Input c: a 64-bit input. * Output : a 64-bit output. - * A 64-bit memory is allocated which is to be freed by the calling + * A 64-bit memory is allocated which is to be freed by the calling * function. * See section 4.3.4 for details. */ u64 MUL64(u64 V, u64 P, u64 c) { - u64 result = 0; - int i = 0; - - for ( i=0; i<64; i++) - { - if( ( P>>i ) & 0x1 ) - result ^= MUL64xPOW(V,i,c); - } - return result; + u64 result = 0; + int i = 0; + + for (i = 0; i < 64; i++) { + if ((P >> i) & 0x1) + result ^= MUL64xPOW(V, i, c); + } + return result; } /* mask8bit. @@ -474,7 +416,7 @@ u64 MUL64(u64 V, u64 P, u64 c) */ u8 mask8bit(int n) { - return 0xFF ^ ((1<<(8-n)) - 1); + return 0xFF ^ ((1 << (8 - n)) - 1); } /* f9. @@ -484,94 +426,90 @@ u8 mask8bit(int n) * Input dir:1 bit, direction of transmission (in the LSB). * Input data: length number of bits, input bit stream. * Input length: 64 bit Length, i.e., the number of bits to be MAC'd. - * Output : 32 bit block used as MAC + * Output : 32 bit block used as MAC * Generates 32-bit MAC using UIA2 algorithm as defined in Section 4. */ -u8* snow3g_f9( u8* key, u32 count, u32 fresh, u32 dir, u8 *data, u64 length) +u8* snow3g_f9(u8* key, u32 count, u32 fresh, u32 dir, u8* data, u64 length) { - u32 K[4],IV[4], z[5]; - u32 i=0, D; - static u8 MAC_I[4] = {0,0,0,0}; /* static memory for the result */ - u64 EVAL; - u64 V; - u64 P; - u64 Q; - u64 c; - - u64 M_D_2; - int rem_bits = 0; - - /* Load the Integrity Key for SNOW3G initialization as in section 4.4. */ - for (i=0; i<4; i++) - K[3-i] = (key[4*i] << 24) ^ (key[4*i+1] << 16) ^ - (key[4*i+2] << 8) ^ (key[4*i+3]); - - /* Prepare the Initialization Vector (IV) for SNOW3G initialization as - in section 4.4. */ - IV[3] = count; - IV[2] = fresh; - IV[1] = count ^ ( dir << 31 ) ; - IV[0] = fresh ^ (dir << 15); - - z[0] = z[1] = z[2] = z[3] = z[4] = 0; - - /* Run SNOW 3G to produce 5 keystream words z_1, z_2, z_3, z_4 and z_5. */ + u32 K[4], IV[4], z[5]; + u32 i = 0, D; + static u8 MAC_I[4] = {0, 0, 0, 0}; /* static memory for the result */ + u64 EVAL; + u64 V; + u64 P; + u64 Q; + u64 c; + + u64 M_D_2; + int rem_bits = 0; + + /* Load the Integrity Key for SNOW3G initialization as in section 4.4. */ + for (i = 0; i < 4; i++) + K[3 - i] = (key[4 * i] << 24) ^ (key[4 * i + 1] << 16) ^ (key[4 * i + 2] << 8) ^ (key[4 * i + 3]); + + /* Prepare the Initialization Vector (IV) for SNOW3G initialization as + in section 4.4. */ + IV[3] = count; + IV[2] = fresh; + IV[1] = count ^ (dir << 31); + IV[0] = fresh ^ (dir << 15); + + z[0] = z[1] = z[2] = z[3] = z[4] = 0; + + /* Run SNOW 3G to produce 5 keystream words z_1, z_2, z_3, z_4 and z_5. */ snow3g_initialize(K, IV); snow3g_generate_keystream(5, z); - - P = (u64)z[0] << 32 | (u64)z[1]; - Q = (u64)z[2] << 32 | (u64)z[3]; - - /* Calculation */ - if ((length % 64) == 0) - D = (length>>6) + 1; - else - D = (length>>6) + 2; - EVAL = 0; - c = 0x1b; - - /* for 0 <= i <= D-3 */ - for (i=0; i 7) - { - M_D_2 |= (u64)data[8*(D-2)+i] << (8*(7-i)); - rem_bits -= 8; - i++; - } - if (rem_bits > 0) - M_D_2 |= (u64)(data[8*(D-2)+i] & mask8bit(rem_bits)) << (8*(7-i)); - - V = EVAL ^ M_D_2; - EVAL = MUL64(V,P,c); - - /* for D-1 */ - EVAL ^= length; - - /* Multiply by Q */ - EVAL = MUL64(EVAL,Q,c); - - /* XOR with z_5: this is a modification to the reference C code, - which forgot to XOR z[5] */ - for (i=0; i<4; i++) - /* - MAC_I[i] = (mac32 >> (8*(3-i))) & 0xff; - */ - MAC_I[i] = ((EVAL >> (56-(i*8))) ^ (z[4] >> (24-(i*8)))) & 0xff; - - return MAC_I; + + P = (u64)z[0] << 32 | (u64)z[1]; + Q = (u64)z[2] << 32 | (u64)z[3]; + + /* Calculation */ + if ((length % 64) == 0) + D = (length >> 6) + 1; + else + D = (length >> 6) + 2; + EVAL = 0; + c = 0x1b; + + /* for 0 <= i <= D-3 */ + for (i = 0; i < D - 2; i++) { + V = EVAL ^ + ((u64)data[8 * i] << 56 | (u64)data[8 * i + 1] << 48 | (u64)data[8 * i + 2] << 40 | (u64)data[8 * i + 3] << 32 | + (u64)data[8 * i + 4] << 24 | (u64)data[8 * i + 5] << 16 | (u64)data[8 * i + 6] << 8 | (u64)data[8 * i + 7]); + EVAL = MUL64(V, P, c); + } + + /* for D-2 */ + rem_bits = length % 64; + if (rem_bits == 0) + rem_bits = 64; + + M_D_2 = 0; + i = 0; + while (rem_bits > 7) { + M_D_2 |= (u64)data[8 * (D - 2) + i] << (8 * (7 - i)); + rem_bits -= 8; + i++; + } + if (rem_bits > 0) + M_D_2 |= (u64)(data[8 * (D - 2) + i] & mask8bit(rem_bits)) << (8 * (7 - i)); + + V = EVAL ^ M_D_2; + EVAL = MUL64(V, P, c); + + /* for D-1 */ + EVAL ^= length; + + /* Multiply by Q */ + EVAL = MUL64(EVAL, Q, c); + + /* XOR with z_5: this is a modification to the reference C code, + which forgot to XOR z[5] */ + for (i = 0; i < 4; i++) + /* + MAC_I[i] = (mac32 >> (8*(3-i))) & 0xff; + */ + MAC_I[i] = ((EVAL >> (56 - (i * 8))) ^ (z[4] >> (24 - (i * 8)))) & 0xff; + + return MAC_I; } diff --git a/lib/src/common/thread_pool.cc b/lib/src/common/thread_pool.cc index 3d41b7f3d..9e8ec3c14 100644 --- a/lib/src/common/thread_pool.cc +++ b/lib/src/common/thread_pool.cc @@ -25,7 +25,11 @@ #include #define DEBUG 0 -#define debug_thread(fmt, ...) do { if(DEBUG) printf(fmt, __VA_ARGS__); } while(0) +#define debug_thread(fmt, ...) \ + do { \ + if (DEBUG) \ + printf(fmt, __VA_ARGS__); \ + } while (0) #define USE_QUEUE @@ -33,27 +37,23 @@ namespace srslte { thread_pool::worker::worker() : my_id(0), running(false), my_parent(NULL), thread("THREAD_POOL_WORKER") {} -void thread_pool::worker::setup(uint32_t id, thread_pool *parent, uint32_t prio, uint32_t mask) +void thread_pool::worker::setup(uint32_t id, thread_pool* parent, uint32_t prio, uint32_t mask) { - my_id = id; + my_id = id; my_parent = parent; - if(mask == 255) - { + if (mask == 255) { start(prio); + } else { + start_cpu_mask(prio, mask); } - else - { - start_cpu_mask(prio,mask); - } - } void thread_pool::worker::run_thread() { set_name(std::string("WORKER") + std::to_string(my_id)); - running = true; - while(running) { + running = true; + while (running) { wait_to_start(); if (running) { work_imp(); @@ -69,55 +69,55 @@ uint32_t thread_pool::worker::get_id() void thread_pool::worker::stop() { - running = false; + running = false; pthread_cond_signal(&my_parent->cvar[my_id]); wait_thread_finish(); } -thread_pool::thread_pool(uint32_t max_workers_) : - workers(max_workers_), - status(max_workers_), - cvar(max_workers_), - mutex(max_workers_) +thread_pool::thread_pool(uint32_t max_workers_) : + workers(max_workers_), + status(max_workers_), + cvar(max_workers_), + mutex(max_workers_) { max_workers = max_workers_; - for (uint32_t i=0;i= nof_workers) { - nof_workers = id+1; + nof_workers = id + 1; } - pthread_mutex_lock(&mutex_queue); - workers[id] = obj; - available_workers.push(obj); + pthread_mutex_lock(&mutex_queue); + workers[id] = obj; + available_workers.push(obj); obj->setup(id, this, prio, mask); pthread_cond_signal(&cvar_queue); - pthread_mutex_unlock(&mutex_queue); + pthread_mutex_unlock(&mutex_queue); } } void thread_pool::stop() { /* Stop any thread waiting for available worker */ - running = false; - + running = false; + /* Now stop all workers */ - for (uint32_t i=0;istop(); - // Need to call start to wake it up + workers[i]->stop(); + // Need to call start to wake it up start_worker(i); workers[i]->wait_thread_finish(); } @@ -128,7 +128,6 @@ void thread_pool::stop() pthread_mutex_destroy(&mutex_queue); } - void thread_pool::worker::release() { finished(); @@ -136,14 +135,14 @@ void thread_pool::worker::release() void thread_pool::worker::wait_to_start() { - + debug_thread("wait_to_start() id=%d, status=%d, enter\n", my_id, my_parent->status[my_id]); - pthread_mutex_lock(&my_parent->mutex[my_id]); - while(my_parent->status[my_id] != START_WORK && running) { + pthread_mutex_lock(&my_parent->mutex[my_id]); + while (my_parent->status[my_id] != START_WORK && running) { pthread_cond_wait(&my_parent->cvar[my_id], &my_parent->mutex[my_id]); } - my_parent->status[my_id] = WORKING; + my_parent->status[my_id] = WORKING; pthread_mutex_unlock(&my_parent->mutex[my_id]); debug_thread("wait_to_start() id=%d, status=%d, exit\n", my_id, my_parent->status[my_id]); @@ -152,104 +151,104 @@ void thread_pool::worker::wait_to_start() void thread_pool::worker::finished() { #ifdef USE_QUEUE - pthread_mutex_lock(&my_parent->mutex[my_id]); - my_parent->status[my_id] = IDLE; - pthread_mutex_unlock(&my_parent->mutex[my_id]); + pthread_mutex_lock(&my_parent->mutex[my_id]); + my_parent->status[my_id] = IDLE; + pthread_mutex_unlock(&my_parent->mutex[my_id]); - pthread_mutex_lock(&my_parent->mutex_queue); + pthread_mutex_lock(&my_parent->mutex_queue); pthread_cond_signal(&my_parent->cvar_queue); - pthread_mutex_unlock(&my_parent->mutex_queue); + pthread_mutex_unlock(&my_parent->mutex_queue); #else - pthread_mutex_lock(&my_parent->mutex[my_id]); - my_parent->status[my_id] = IDLE; + pthread_mutex_lock(&my_parent->mutex[my_id]); + my_parent->status[my_id] = IDLE; pthread_cond_signal(&my_parent->cvar[my_id]); - pthread_mutex_unlock(&my_parent->mutex[my_id]); + pthread_mutex_unlock(&my_parent->mutex[my_id]); #endif } - thread_pool::worker* thread_pool::wait_worker() { return wait_worker(0); } -bool thread_pool::find_finished_worker(uint32_t tti, uint32_t *id) { - for(uint32_t i=0;i #include -#include #include +#include #include #include #include "srslte/common/threads.h" -bool threads_new_rt(pthread_t *thread, void *(*start_routine) (void*), void *arg) { +bool threads_new_rt(pthread_t* thread, void* (*start_routine)(void*), void* arg) +{ return threads_new_rt_prio(thread, start_routine, arg, -1); } -bool threads_new_rt_prio(pthread_t *thread, void *(*start_routine) (void*), void *arg, int prio_offset) { +bool threads_new_rt_prio(pthread_t* thread, void* (*start_routine)(void*), void* arg, int prio_offset) +{ return threads_new_rt_cpu(thread, start_routine, arg, -1, prio_offset); } -bool threads_new_rt_mask(pthread_t *thread, void *(*start_routine) (void*), void *arg,int mask, int prio_offset){ -return threads_new_rt_cpu(thread, start_routine, arg, mask*100, prio_offset);// we multiply mask by 100 to distinguish it from a single cpu core id +bool threads_new_rt_mask(pthread_t* thread, void* (*start_routine)(void*), void* arg, int mask, int prio_offset) +{ + return threads_new_rt_cpu(thread, + start_routine, + arg, + mask * 100, + prio_offset); // we multiply mask by 100 to distinguish it from a single cpu core id } -bool threads_new_rt_cpu(pthread_t *thread, void *(*start_routine) (void*), void *arg, int cpu, int prio_offset) { - bool ret = false; - - pthread_attr_t attr; +bool threads_new_rt_cpu(pthread_t* thread, void* (*start_routine)(void*), void* arg, int cpu, int prio_offset) +{ + bool ret = false; + + pthread_attr_t attr; struct sched_param param; - cpu_set_t cpuset; - bool attr_enable = false; + cpu_set_t cpuset; + bool attr_enable = false; #ifdef PER_THREAD_PRIO if (prio_offset >= 0) { @@ -81,7 +89,7 @@ bool threads_new_rt_cpu(pthread_t *thread, void *(*start_routine) (void*), void #else // All threads have normal priority except prio_offset=0,1,2,3,4 if (prio_offset >= 0 && prio_offset < 5) { - param.sched_priority = 50-prio_offset; + param.sched_priority = 50 - prio_offset; pthread_attr_init(&attr); if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) { perror("pthread_attr_setinheritsched"); @@ -111,23 +119,23 @@ bool threads_new_rt_cpu(pthread_t *thread, void *(*start_routine) (void*), void } attr_enable = true; } - if(cpu > 0) { - if(cpu > 50) { + if (cpu > 0) { + if (cpu > 50) { int mask; - mask = cpu/100; - - CPU_ZERO(&cpuset); - for(int i = 0; i < 8;i++){ - if(((mask >> i) & 0x01) == 1){ - CPU_SET((size_t) i , &cpuset); - } - } + mask = cpu / 100; + + CPU_ZERO(&cpuset); + for (int i = 0; i < 8; i++) { + if (((mask >> i) & 0x01) == 1) { + CPU_SET((size_t)i, &cpuset); + } + } } else { - CPU_ZERO(&cpuset); - CPU_SET((size_t) cpu, &cpuset); + CPU_ZERO(&cpuset); + CPU_SET((size_t)cpu, &cpuset); } - - if(pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset)) { + + if (pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset)) { perror("pthread_attr_setaffinity_np"); } } @@ -140,33 +148,34 @@ bool threads_new_rt_cpu(pthread_t *thread, void *(*start_routine) (void*), void if (err) { perror("pthread_create"); } else { - ret = true; + ret = true; } } else { perror("pthread_create"); } } else { - ret = true; + ret = true; } if (attr_enable) { pthread_attr_destroy(&attr); } - return ret; + return ret; } -void threads_print_self() { - pthread_t thread; - cpu_set_t cpuset; +void threads_print_self() +{ + pthread_t thread; + cpu_set_t cpuset; struct sched_param param; - int policy; - const char *p; - int s,j; + int policy; + const char* p; + int s, j; thread = pthread_self(); s = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset); if (s != 0) { - printf("error pthread_getaffinity_np: %s\n",strerror(s)); + printf("error pthread_getaffinity_np: %s\n", strerror(s)); } printf("Set returned by pthread_getaffinity_np() contained:\n"); @@ -181,17 +190,17 @@ void threads_print_self() { printf("error pthread_getaffinity_np: %s\n", strerror(s)); } - switch(policy) { - case SCHED_FIFO: - p = "SCHED_FIFO"; - break; - case SCHED_RR: - p = "SCHED_RR"; - break; - default: - p = "Other"; - break; + switch (policy) { + case SCHED_FIFO: + p = "SCHED_FIFO"; + break; + case SCHED_RR: + p = "SCHED_RR"; + break; + default: + p = "Other"; + break; } - printf("Sched policy is %s. Priority is %d\n",p,param.sched_priority); + printf("Sched policy is %s. Priority is %d\n", p, param.sched_priority); } diff --git a/lib/src/common/tti_sync_cv.cc b/lib/src/common/tti_sync_cv.cc index a9a43278d..0a032dbc8 100644 --- a/lib/src/common/tti_sync_cv.cc +++ b/lib/src/common/tti_sync_cv.cc @@ -23,62 +23,61 @@ #include "srslte/common/tti_sync_cv.h" - namespace srslte { - tti_sync_cv::tti_sync_cv(uint32_t modulus): tti_sync(modulus) - { - pthread_mutex_init(&mutex, NULL); - pthread_cond_init(&cond, NULL); - } +tti_sync_cv::tti_sync_cv(uint32_t modulus) : tti_sync(modulus) +{ + pthread_mutex_init(&mutex, NULL); + pthread_cond_init(&cond, NULL); +} - tti_sync_cv::~tti_sync_cv() - { - // Wake up any thread waiting on cond before destroying it - pthread_mutex_lock(&mutex); - pthread_cond_signal(&cond); - pthread_cond_destroy(&cond); - pthread_mutex_unlock(&mutex); - pthread_mutex_destroy(&mutex); - } +tti_sync_cv::~tti_sync_cv() +{ + // Wake up any thread waiting on cond before destroying it + pthread_mutex_lock(&mutex); + pthread_cond_signal(&cond); + pthread_cond_destroy(&cond); + pthread_mutex_unlock(&mutex); + pthread_mutex_destroy(&mutex); +} - uint32_t tti_sync_cv::wait() - { - pthread_mutex_lock(&mutex); - while(wait_condition()) { - pthread_cond_wait(&cond, &mutex); - } - uint32_t x = consumer_cntr; - increase_consumer(); - pthread_mutex_unlock(&mutex); - return x; +uint32_t tti_sync_cv::wait() +{ + pthread_mutex_lock(&mutex); + while (wait_condition()) { + pthread_cond_wait(&cond, &mutex); } + uint32_t x = consumer_cntr; + increase_consumer(); + pthread_mutex_unlock(&mutex); + return x; +} - void tti_sync_cv::resync() - { - consumer_cntr = producer_cntr; - } +void tti_sync_cv::resync() +{ + consumer_cntr = producer_cntr; +} - void tti_sync_cv::set_producer_cntr(uint32_t producer_cntr) - { - pthread_mutex_lock(&mutex); - init_counters(producer_cntr); - pthread_cond_signal(&cond); - pthread_mutex_unlock(&mutex); - } +void tti_sync_cv::set_producer_cntr(uint32_t producer_cntr) +{ + pthread_mutex_lock(&mutex); + init_counters(producer_cntr); + pthread_cond_signal(&cond); + pthread_mutex_unlock(&mutex); +} - void tti_sync_cv::increase() - { - pthread_mutex_lock(&mutex); - increase_producer(); - pthread_cond_signal(&cond); - pthread_mutex_unlock(&mutex); - } - void tti_sync_cv::increase(uint32_t tti) - { - pthread_mutex_lock(&mutex); - increase_producer(tti); - pthread_cond_signal(&cond); - pthread_mutex_unlock(&mutex); - } +void tti_sync_cv::increase() +{ + pthread_mutex_lock(&mutex); + increase_producer(); + pthread_cond_signal(&cond); + pthread_mutex_unlock(&mutex); +} +void tti_sync_cv::increase(uint32_t tti) +{ + pthread_mutex_lock(&mutex); + increase_producer(tti); + pthread_cond_signal(&cond); + pthread_mutex_unlock(&mutex); } +} // namespace srslte diff --git a/lib/src/common/version.c b/lib/src/common/version.c index be99bc0c9..7e3d63f2c 100644 --- a/lib/src/common/version.c +++ b/lib/src/common/version.c @@ -21,20 +21,25 @@ #include "srslte/version.h" -char* srslte_get_version() { +char* srslte_get_version() +{ return SRSLTE_VERSION_STRING; } -int srslte_get_version_major() { +int srslte_get_version_major() +{ return SRSLTE_VERSION_MAJOR; } -int srslte_get_version_minor() { +int srslte_get_version_minor() +{ return SRSLTE_VERSION_MINOR; } -int srslte_get_version_patch() { +int srslte_get_version_patch() +{ return SRSLTE_VERSION_PATCH; } -int srslte_check_version(int major, int minor, int patch) { - return (SRSLTE_VERSION >= SRSLTE_VERSION_ENCODE(major,minor,patch)); +int srslte_check_version(int major, int minor, int patch) +{ + return (SRSLTE_VERSION >= SRSLTE_VERSION_ENCODE(major, minor, patch)); } diff --git a/lib/src/phy/agc/agc.c b/lib/src/phy/agc/agc.c index b6c7ca903..a0db46cc6 100644 --- a/lib/src/phy/agc/agc.c +++ b/lib/src/phy/agc/agc.c @@ -19,37 +19,39 @@ * */ +#include +#include +#include #include #include -#include -#include -#include #include "srslte/phy/utils/debug.h" #include "srslte/phy/agc/agc.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" -int srslte_agc_init (srslte_agc_t *q, srslte_agc_mode_t mode) { +int srslte_agc_init(srslte_agc_t* q, srslte_agc_mode_t mode) +{ return srslte_agc_init_acc(q, mode, 0); } -int srslte_agc_init_acc(srslte_agc_t *q, srslte_agc_mode_t mode, uint32_t nof_frames) { +int srslte_agc_init_acc(srslte_agc_t* q, srslte_agc_mode_t mode, uint32_t nof_frames) +{ bzero(q, sizeof(srslte_agc_t)); - q->mode = mode; - q->nof_frames = nof_frames; + q->mode = mode; + q->nof_frames = nof_frames; q->max_gain_db = 90.0; q->min_gain_db = 0.0; if (nof_frames > 0) { q->y_tmp = srslte_vec_malloc(sizeof(float) * nof_frames); if (!q->y_tmp) { - return SRSLTE_ERROR; + return SRSLTE_ERROR; } } else { - q->y_tmp = NULL; + q->y_tmp = NULL; } - q->target = SRSLTE_AGC_DEFAULT_TARGET; + q->target = SRSLTE_AGC_DEFAULT_TARGET; srslte_agc_reset(q); return SRSLTE_SUCCESS; } @@ -62,73 +64,84 @@ int srslte_agc_init_uhd(srslte_agc_t* q, { if (!srslte_agc_init_acc(q, mode, nof_frames)) { q->set_gain_callback = set_gain_callback; - q->uhd_handler = uhd_handler; + q->uhd_handler = uhd_handler; return SRSLTE_SUCCESS; } else { - return SRSLTE_ERROR; + return SRSLTE_ERROR; } } -void srslte_agc_free(srslte_agc_t *q) { +void srslte_agc_free(srslte_agc_t* q) +{ if (q->y_tmp) { free(q->y_tmp); } bzero(q, sizeof(srslte_agc_t)); } -void srslte_agc_reset(srslte_agc_t *q) { +void srslte_agc_reset(srslte_agc_t* q) +{ q->bandwidth = SRSLTE_AGC_DEFAULT_BW; q->lock = false; q->gain = srslte_convert_dB_to_power(50.0f); - q->y_out = 1.0; - q->isfirst = true; + q->y_out = 1.0; + q->isfirst = true; if (q->set_gain_callback && q->uhd_handler) { q->set_gain_callback(q->uhd_handler, srslte_convert_power_to_dB(q->gain)); } } -void srslte_agc_set_gain_range(srslte_agc_t *q, float min_gain_db, float max_gain_db) { +void srslte_agc_set_gain_range(srslte_agc_t* q, float min_gain_db, float max_gain_db) +{ if (q) { q->min_gain_db = min_gain_db; q->max_gain_db = max_gain_db; } } -void srslte_agc_set_bandwidth(srslte_agc_t *q, float bandwidth) { +void srslte_agc_set_bandwidth(srslte_agc_t* q, float bandwidth) +{ q->bandwidth = bandwidth; } -void srslte_agc_set_target(srslte_agc_t *q, float target) { +void srslte_agc_set_target(srslte_agc_t* q, float target) +{ q->target = target; } -float srslte_agc_get_rssi(srslte_agc_t *q) { - return q->target/q->gain; +float srslte_agc_get_rssi(srslte_agc_t* q) +{ + return q->target / q->gain; } -float srslte_agc_get_output_level(srslte_agc_t *q) { +float srslte_agc_get_output_level(srslte_agc_t* q) +{ return q->y_out; } -float srslte_agc_get_gain(srslte_agc_t *q) { +float srslte_agc_get_gain(srslte_agc_t* q) +{ return q->gain; } -void srslte_agc_set_gain(srslte_agc_t *q, float init_gain_value_db) { +void srslte_agc_set_gain(srslte_agc_t* q, float init_gain_value_db) +{ q->gain = srslte_convert_dB_to_power(init_gain_value_db); } -void srslte_agc_lock(srslte_agc_t *q, bool enable) { +void srslte_agc_lock(srslte_agc_t* q, bool enable) +{ q->lock = enable; } -void srslte_agc_process(srslte_agc_t *q, cf_t *signal, uint32_t len) { +void srslte_agc_process(srslte_agc_t* q, cf_t* signal, uint32_t len) +{ if (!q->lock) { float gain_db = srslte_convert_power_to_dB(q->gain); float gain_uhd_db = 50.0f; - float y = 0; - // Apply current gain to input signal + float y = 0; + // Apply current gain to input signal if (!q->uhd_handler) { srslte_vec_sc_prod_cfc(signal, q->gain, signal, len); } else { @@ -147,44 +160,44 @@ void srslte_agc_process(srslte_agc_t *q, cf_t *signal, uint32_t len) { gain_uhd_db = q->set_gain_callback(q->uhd_handler, gain_db); q->gain = srslte_convert_dB_to_power(gain_uhd_db); } - float *t; - switch(q->mode) { + float* t; + switch (q->mode) { case SRSLTE_AGC_MODE_ENERGY: - y = sqrtf(crealf(srslte_vec_dot_prod_conj_ccc(signal, signal, len))/len); + y = sqrtf(crealf(srslte_vec_dot_prod_conj_ccc(signal, signal, len)) / len); break; case SRSLTE_AGC_MODE_PEAK_AMPLITUDE: - t = (float*) signal; - y = t[srslte_vec_max_fi(t, 2*len)];// take only positive max to avoid abs() (should be similar) + t = (float*)signal; + y = t[srslte_vec_max_fi(t, 2 * len)]; // take only positive max to avoid abs() (should be similar) break; default: ERROR("Unsupported AGC mode\n"); - return; + return; } - + if (q->nof_frames > 0) { - q->y_tmp[q->frame_cnt++] = y; + q->y_tmp[q->frame_cnt++] = y; if (q->frame_cnt == q->nof_frames) { - q->frame_cnt = 0; - switch(q->mode) { + q->frame_cnt = 0; + switch (q->mode) { case SRSLTE_AGC_MODE_ENERGY: - y = srslte_vec_acc_ff(q->y_tmp, q->nof_frames)/q->nof_frames; + y = srslte_vec_acc_ff(q->y_tmp, q->nof_frames) / q->nof_frames; break; case SRSLTE_AGC_MODE_PEAK_AMPLITUDE: y = q->y_tmp[srslte_vec_max_fi(q->y_tmp, q->nof_frames)]; break; default: ERROR("Unsupported AGC mode\n"); - return; + return; } } } - + if (q->isfirst) { - q->y_out = y; - q->isfirst = false; + q->y_out = y; + q->isfirst = false; } else { if (q->frame_cnt == 0) { - q->y_out = (1-q->bandwidth) * q->y_out + q->bandwidth * y; + q->y_out = (1 - q->bandwidth) * q->y_out + q->bandwidth * y; if (!q->lock) { q->gain *= q->target / q->y_out; } diff --git a/lib/src/phy/ch_estimation/chest_common.c b/lib/src/phy/ch_estimation/chest_common.c index d47c33b37..88a77db3f 100644 --- a/lib/src/phy/ch_estimation/chest_common.c +++ b/lib/src/phy/ch_estimation/chest_common.c @@ -19,44 +19,44 @@ * */ +#include +#include #include #include -#include #include -#include -#include +#include #include "srslte/phy/ch_estimation/chest_common.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/convolution.h" +#include "srslte/phy/utils/vector.h" uint32_t srslte_chest_set_triangle_filter(float* fil, int filter_len) { - for (int i=0;icsr_refs, max_prb); if (ret != SRSLTE_SUCCESS) { ERROR("Error initializing CSR signal (%d)\n", ret); @@ -86,9 +86,9 @@ int srslte_chest_dl_init(srslte_chest_dl_t* q, uint32_t max_prb, uint32_t nof_rx } int pilot_vec_size; - if(SRSLTE_REFSIGNAL_MAX_NUM_SF_MBSFN(max_prb)>SRSLTE_REFSIGNAL_MAX_NUM_SF(max_prb)) { + if (SRSLTE_REFSIGNAL_MAX_NUM_SF_MBSFN(max_prb) > SRSLTE_REFSIGNAL_MAX_NUM_SF(max_prb)) { pilot_vec_size = SRSLTE_REFSIGNAL_MAX_NUM_SF_MBSFN(max_prb); - }else{ + } else { pilot_vec_size = SRSLTE_REFSIGNAL_MAX_NUM_SF(max_prb); } @@ -108,36 +108,36 @@ int srslte_chest_dl_init(srslte_chest_dl_t* q, uint32_t max_prb, uint32_t nof_rx if (!q->pilot_estimates) { perror("malloc"); goto clean_exit; - } + } q->pilot_estimates_average = srslte_vec_malloc(sizeof(cf_t) * pilot_vec_size); if (!q->pilot_estimates_average) { perror("malloc"); goto clean_exit; } - + q->pilot_recv_signal = srslte_vec_malloc(sizeof(cf_t) * pilot_vec_size); if (!q->pilot_recv_signal) { perror("malloc"); goto clean_exit; } - - if (srslte_interp_linear_vector_init(&q->srslte_interp_linvec, SRSLTE_NRE*max_prb)) { + + if (srslte_interp_linear_vector_init(&q->srslte_interp_linvec, SRSLTE_NRE * max_prb)) { ERROR("Error initializing vector interpolator\n"); goto clean_exit; } - if (srslte_interp_linear_init(&q->srslte_interp_lin, 2*max_prb, SRSLTE_NRE/2)) { + if (srslte_interp_linear_init(&q->srslte_interp_lin, 2 * max_prb, SRSLTE_NRE / 2)) { ERROR("Error initializing interpolator\n"); goto clean_exit; } - if (srslte_interp_linear_init(&q->srslte_interp_lin_3, 4*max_prb, SRSLTE_NRE/4)) { + if (srslte_interp_linear_init(&q->srslte_interp_lin_3, 4 * max_prb, SRSLTE_NRE / 4)) { ERROR("Error initializing interpolator\n"); goto clean_exit; } - if (srslte_interp_linear_init(&q->srslte_interp_lin_mbsfn, 6*max_prb, SRSLTE_NRE/6)) { + if (srslte_interp_linear_init(&q->srslte_interp_lin_mbsfn, 6 * max_prb, SRSLTE_NRE / 6)) { ERROR("Error initializing interpolator\n"); goto clean_exit; } @@ -146,21 +146,21 @@ int srslte_chest_dl_init(srslte_chest_dl_t* q, uint32_t max_prb, uint32_t nof_rx } ret = SRSLTE_SUCCESS; - + clean_exit: if (ret != SRSLTE_SUCCESS) { - srslte_chest_dl_free(q); + srslte_chest_dl_free(q); } - return ret; + return ret; } -void srslte_chest_dl_free(srslte_chest_dl_t *q) +void srslte_chest_dl_free(srslte_chest_dl_t* q) { - if(&q->csr_refs) + if (&q->csr_refs) srslte_refsignal_free(&q->csr_refs); if (q->mbsfn_refs) { - for (int i=0; imbsfn_refs[i]) { srslte_refsignal_free(q->mbsfn_refs[i]); free(q->mbsfn_refs[i]); @@ -181,10 +181,10 @@ void srslte_chest_dl_free(srslte_chest_dl_t *q) srslte_interp_linear_free(&q->srslte_interp_lin_mbsfn); if (q->pilot_estimates) { free(q->pilot_estimates); - } + } if (q->pilot_estimates_average) { free(q->pilot_estimates_average); - } + } if (q->pilot_recv_signal) { free(q->pilot_recv_signal); } @@ -258,15 +258,13 @@ int srslte_chest_dl_set_mbsfn_area_id(srslte_chest_dl_t* q, uint16_t mbsfn_area_ return SRSLTE_ERROR; } -int srslte_chest_dl_set_cell(srslte_chest_dl_t *q, srslte_cell_t cell) +int srslte_chest_dl_set_cell(srslte_chest_dl_t* q, srslte_cell_t cell) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - srslte_cell_isvalid(&cell)) - { + if (q != NULL && srslte_cell_isvalid(&cell)) { if (q->cell.id != cell.id || q->cell.nof_prb == 0) { q->cell = cell; - ret = srslte_refsignal_cs_set_cell(&q->csr_refs, cell); + ret = srslte_refsignal_cs_set_cell(&q->csr_refs, cell); if (ret != SRSLTE_SUCCESS) { ERROR("Error initializing CSR signal (%d)\n", ret); return SRSLTE_ERROR; @@ -280,7 +278,7 @@ int srslte_chest_dl_set_cell(srslte_chest_dl_t *q, srslte_cell_t cell) return SRSLTE_ERROR; } - if (srslte_interp_linear_resize(&q->srslte_interp_lin, 2*q->cell.nof_prb, SRSLTE_NRE/2)) { + if (srslte_interp_linear_resize(&q->srslte_interp_lin, 2 * q->cell.nof_prb, SRSLTE_NRE / 2)) { ERROR("Error initializing interpolator\n"); return SRSLTE_ERROR; } @@ -292,8 +290,7 @@ int srslte_chest_dl_set_cell(srslte_chest_dl_t *q, srslte_cell_t cell) if (srslte_interp_linear_resize(&q->srslte_interp_lin_mbsfn, 6 * q->cell.nof_prb, SRSLTE_NRE / 6)) { fprintf(stderr, "Error initializing interpolator\n"); return SRSLTE_ERROR; - } - + } } ret = SRSLTE_SUCCESS; } @@ -305,17 +302,18 @@ static float estimate_noise_pilots(srslte_chest_dl_t* q, srslte_dl_sf_cfg_t* sf, { srslte_sf_t ch_mode = sf->sf_type; const float weight = 1.0f; - float sum_power = 0.0f; + float sum_power = 0.0f; uint32_t count = 0; uint32_t npilots = (ch_mode == SRSLTE_SF_MBSFN) ? SRSLTE_REFSIGNAL_NUM_SF_MBSFN(q->cell.nof_prb, port_id) : srslte_refsignal_cs_nof_re(&q->csr_refs, sf, port_id); uint32_t nsymbols = (ch_mode == SRSLTE_SF_MBSFN) ? srslte_refsignal_mbsfn_nof_symbols() : srslte_refsignal_cs_nof_symbols(&q->csr_refs, sf, port_id); uint32_t nref = npilots / nsymbols; - uint32_t fidx = (ch_mode == SRSLTE_SF_MBSFN)?srslte_refsignal_mbsfn_fidx(1):srslte_refsignal_cs_fidx(q->cell, 0, port_id, 0); + uint32_t fidx = + (ch_mode == SRSLTE_SF_MBSFN) ? srslte_refsignal_mbsfn_fidx(1) : srslte_refsignal_cs_fidx(q->cell, 0, port_id, 0); - cf_t *input2d[nsymbols + 2]; - cf_t *tmp_noise = q->tmp_noise; + cf_t* input2d[nsymbols + 2]; + cf_t* tmp_noise = q->tmp_noise; // Special case for 1 symbol if (nsymbols == 1) { @@ -375,10 +373,10 @@ static float estimate_noise_pilots(srslte_chest_dl_t* q, srslte_dl_sf_cfg_t* sf, count++; } - return sum_power / (float) count * sqrtf(weight + 4.0f); + return sum_power / (float)count * sqrtf(weight + 4.0f); } -static float estimate_noise_pss(srslte_chest_dl_t *q, cf_t *input, cf_t *ce) +static float estimate_noise_pss(srslte_chest_dl_t* q, cf_t* input, cf_t* ce) { /* Get PSS from received signal */ srslte_pss_get_slot(input, q->tmp_pss, q->cell.nof_prb, q->cell.cp); @@ -394,23 +392,24 @@ static float estimate_noise_pss(srslte_chest_dl_t *q, cf_t *input, cf_t *ce) /* Compute average power */ float power = q->cell.nof_ports * srslte_vec_avg_power_cf(q->tmp_pss_noisy, SRSLTE_PSS_LEN) * M_SQRT1_2; - return power; + return power; } /* Uses the 5 empty transmitted SC before and after the SSS and PSS sequences for noise estimation */ -static float estimate_noise_empty_sc(srslte_chest_dl_t *q, cf_t *input) { +static float estimate_noise_empty_sc(srslte_chest_dl_t* q, cf_t* input) +{ int k_sss = (SRSLTE_CP_NSYMB(q->cell.cp) - 2) * q->cell.nof_prb * SRSLTE_NRE + q->cell.nof_prb * SRSLTE_NRE / 2 - 31; float noise_power = 0; - noise_power += srslte_vec_avg_power_cf(&input[k_sss-5], 5); // 5 empty SC before SSS - noise_power += srslte_vec_avg_power_cf(&input[k_sss+62], 5); // 5 empty SC after SSS + noise_power += srslte_vec_avg_power_cf(&input[k_sss - 5], 5); // 5 empty SC before SSS + noise_power += srslte_vec_avg_power_cf(&input[k_sss + 62], 5); // 5 empty SC after SSS int k_pss = (SRSLTE_CP_NSYMB(q->cell.cp) - 1) * q->cell.nof_prb * SRSLTE_NRE + q->cell.nof_prb * SRSLTE_NRE / 2 - 31; - noise_power += srslte_vec_avg_power_cf(&input[k_pss-5], 5); // 5 empty SC before PSS - noise_power += srslte_vec_avg_power_cf(&input[k_pss+62], 5); // 5 empty SC after PSS + noise_power += srslte_vec_avg_power_cf(&input[k_pss - 5], 5); // 5 empty SC before PSS + noise_power += srslte_vec_avg_power_cf(&input[k_pss + 62], 5); // 5 empty SC after PSS return noise_power; } -#define cesymb(i) ce[SRSLTE_RE_IDX(q->cell.nof_prb,i,0)] +#define cesymb(i) ce[SRSLTE_RE_IDX(q->cell.nof_prb, i, 0)] static void interpolate_pilots(srslte_chest_dl_t* q, srslte_dl_sf_cfg_t* sf, @@ -436,38 +435,42 @@ static void interpolate_pilots(srslte_chest_dl_t* q, if (sf->sf_type == SRSLTE_SF_MBSFN) { if (l == 0) { fidx_offset = srslte_refsignal_cs_fidx(q->cell, l, port_id, 0); - srslte_interp_linear_offset(&q->srslte_interp_lin, &pilot_estimates[2*q->cell.nof_prb*l], - &ce[srslte_refsignal_cs_nsymbol(l,q->cell.cp, port_id) * q->cell.nof_prb * SRSLTE_NRE], - fidx_offset, SRSLTE_NRE/2-fidx_offset); + srslte_interp_linear_offset( + &q->srslte_interp_lin, + &pilot_estimates[2 * q->cell.nof_prb * l], + &ce[srslte_refsignal_cs_nsymbol(l, q->cell.cp, port_id) * q->cell.nof_prb * SRSLTE_NRE], + fidx_offset, + SRSLTE_NRE / 2 - fidx_offset); } else { fidx_offset = srslte_refsignal_mbsfn_fidx(l - 1); - srslte_interp_linear_offset(&q->srslte_interp_lin_mbsfn, &pilot_estimates[(2*q->cell.nof_prb) + 6*q->cell.nof_prb*(l - 1)], + srslte_interp_linear_offset(&q->srslte_interp_lin_mbsfn, + &pilot_estimates[(2 * q->cell.nof_prb) + 6 * q->cell.nof_prb * (l - 1)], &ce[srslte_refsignal_mbsfn_nsymbol(l - 1) * q->cell.nof_prb * SRSLTE_NRE], - fidx_offset, (fidx_offset)?1:2); - + fidx_offset, + (fidx_offset) ? 1 : 2); } } else { if (!cfg->interpolate_subframe && nsymbols > 1) { fidx_offset = q->cell.id % 3; - srslte_interp_linear_offset(&q->srslte_interp_lin_3, - pilot_estimates, - ce, - fidx_offset, - SRSLTE_NRE / 4 - fidx_offset); + srslte_interp_linear_offset( + &q->srslte_interp_lin_3, pilot_estimates, ce, fidx_offset, SRSLTE_NRE / 4 - fidx_offset); } else { fidx_offset = srslte_refsignal_cs_fidx(q->cell, l, port_id, 0); - srslte_interp_linear_offset(&q->srslte_interp_lin, &pilot_estimates[2 * q->cell.nof_prb * l], - &ce[srslte_refsignal_cs_nsymbol(l, q->cell.cp, port_id) * q->cell.nof_prb - * SRSLTE_NRE], fidx_offset, SRSLTE_NRE / 2 - fidx_offset); + srslte_interp_linear_offset( + &q->srslte_interp_lin, + &pilot_estimates[2 * q->cell.nof_prb * l], + &ce[srslte_refsignal_cs_nsymbol(l, q->cell.cp, port_id) * q->cell.nof_prb * SRSLTE_NRE], + fidx_offset, + SRSLTE_NRE / 2 - fidx_offset); } - } + } } /* Now interpolate in the time domain between symbols */ if (sf->sf_type == SRSLTE_SF_NORM && (!cfg->interpolate_subframe || nsymbols < 3)) { // If we average per subframe, just copy the estimates in the time domain for (uint32_t l = 1; l < 2 * SRSLTE_CP_NSYMB(q->cell.cp); l++) { - memcpy(&ce[l*SRSLTE_NRE*q->cell.nof_prb], ce, sizeof(cf_t)*SRSLTE_NRE*q->cell.nof_prb); + memcpy(&ce[l * SRSLTE_NRE * q->cell.nof_prb], ce, sizeof(cf_t) * SRSLTE_NRE * q->cell.nof_prb); } } else { if (sf->sf_type == SRSLTE_SF_MBSFN) { @@ -478,8 +481,8 @@ static void interpolate_pilots(srslte_chest_dl_t* q, } else { if (SRSLTE_CP_ISNORM(q->cell.cp)) { if (port_id <= 2) { - srslte_interp_linear_vector(&q->srslte_interp_linvec, &cesymb(0), &cesymb(4), &cesymb(1), 4, 3); - srslte_interp_linear_vector(&q->srslte_interp_linvec, &cesymb(4), &cesymb(7), &cesymb(5), 3, 2); + srslte_interp_linear_vector(&q->srslte_interp_linvec, &cesymb(0), &cesymb(4), &cesymb(1), 4, 3); + srslte_interp_linear_vector(&q->srslte_interp_linvec, &cesymb(4), &cesymb(7), &cesymb(5), 3, 2); if (nsymbols == 4) { srslte_interp_linear_vector(&q->srslte_interp_linvec, &cesymb(7), &cesymb(11), &cesymb(8), 4, 3); srslte_interp_linear_vector2( @@ -546,11 +549,11 @@ static void average_pilots(srslte_chest_dl_t* q, uint32_t skip = (sf->sf_type == SRSLTE_SF_MBSFN) ? 2 * q->cell.nof_prb : 0; if (sf->sf_type == SRSLTE_SF_MBSFN) { - memcpy(&output[0],&input[0],skip*sizeof(cf_t)); + memcpy(&output[0], &input[0], skip * sizeof(cf_t)); } // Average in the frequency domain - for (int l=0;lcsr_refs, sf, port_id); - for (l=0;lcell.cp, port_id) * q->cell.nof_prb * SRSLTE_NRE]; + for (l = 0; l < nsymbols; l++) { + cf_t* tmp = &input[srslte_refsignal_cs_nsymbol(l, q->cell.cp, port_id) * q->cell.nof_prb * SRSLTE_NRE]; rssi += srslte_vec_dot_prod_conj_ccc(tmp, tmp, q->cell.nof_prb * SRSLTE_NRE); } return rssi / nsymbols; @@ -582,14 +585,14 @@ static float chest_estimate_cfo(srslte_chest_dl_t* q) uint32_t npilots = srslte_refsignal_cs_nof_re(&q->csr_refs, &sf_cfg, 0); // Compute angles between slots - for (int i=0;i<2;i++) { - srslte_vec_prod_conj_ccc(&q->pilot_estimates[i*npilots/4], - &q->pilot_estimates[(i+2)*npilots/4], - &q->tmp_cfo_estimate[i*npilots/4], - npilots/4); + for (int i = 0; i < 2; i++) { + srslte_vec_prod_conj_ccc(&q->pilot_estimates[i * npilots / 4], + &q->pilot_estimates[(i + 2) * npilots / 4], + &q->tmp_cfo_estimate[i * npilots / 4], + npilots / 4); } // Average all angles - cf_t sum = srslte_vec_acc_cc(q->tmp_cfo_estimate, npilots/2); + cf_t sum = srslte_vec_acc_cc(q->tmp_cfo_estimate, npilots / 2); // Compute CFO return -cargf(sum) * n / (ns * (n + ng)) / 2 / M_PI; @@ -736,8 +739,10 @@ static int estimate_port_mbsfn(srslte_chest_dl_t* q, srslte_vec_prod_conj_ccc( q->pilot_recv_signal, q->csr_refs.pilots[port_id / 2][sf_idx], q->pilot_estimates, (2 * q->cell.nof_prb)); - srslte_vec_prod_conj_ccc(&q->pilot_recv_signal[(2*q->cell.nof_prb)], q->mbsfn_refs[mbsfn_area_id]->pilots[port_id/2][sf_idx], - &q->pilot_estimates[(2*q->cell.nof_prb)], SRSLTE_REFSIGNAL_NUM_SF_MBSFN(q->cell.nof_prb, port_id)-(2*q->cell.nof_prb)); + srslte_vec_prod_conj_ccc(&q->pilot_recv_signal[(2 * q->cell.nof_prb)], + q->mbsfn_refs[mbsfn_area_id]->pilots[port_id / 2][sf_idx], + &q->pilot_estimates[(2 * q->cell.nof_prb)], + SRSLTE_REFSIGNAL_NUM_SF_MBSFN(q->cell.nof_prb, port_id) - (2 * q->cell.nof_prb)); chest_interpolate_noise_est(q, sf, cfg, input, ce, port_id, rxant_id); @@ -748,7 +753,7 @@ static float get_noise(srslte_chest_dl_t* q) { float n = 0; for (int i = 0; i < q->nof_rx_antennas; i++) { - n += srslte_vec_acc_ff(q->noise_estimate[i], q->cell.nof_ports)/q->cell.nof_ports; + n += srslte_vec_acc_ff(q->noise_estimate[i], q->cell.nof_ports) / q->cell.nof_ports; } if (q->nof_rx_antennas) { n /= q->nof_rx_antennas; @@ -772,7 +777,7 @@ static float get_rsrq(srslte_chest_dl_t* q) { float n = 0; for (int i = 0; i < q->nof_rx_antennas; i++) { - n += q->cell.nof_prb*q->rsrp[i][0] / q->rssi[i][0]; + n += q->cell.nof_prb * q->rsrp[i][0] / q->rssi[i][0]; } return n / q->nof_rx_antennas; } @@ -795,7 +800,7 @@ static float get_rsrp_neigbhour_port(srslte_chest_dl_t* q, uint32_t port) { float sum = 0.0f; for (int j = 0; j < q->cell.nof_ports; ++j) { - sum +=q->rsrp_corr[port][j]; + sum += q->rsrp_corr[port][j]; } if (q->cell.nof_ports) { diff --git a/lib/src/phy/ch_estimation/chest_ul.c b/lib/src/phy/ch_estimation/chest_ul.c index 4b1549ae1..f71376b9e 100644 --- a/lib/src/phy/ch_estimation/chest_ul.c +++ b/lib/src/phy/ch_estimation/chest_ul.c @@ -19,12 +19,12 @@ * */ +#include +#include #include #include -#include #include -#include -#include +#include #include "srslte/config.h" #include "srslte/phy/ch_estimation/chest_ul.h" @@ -33,26 +33,25 @@ #include "srslte/phy/utils/vector.h" #include "srslte/srslte.h" -#define NOF_REFS_SYM (q->cell.nof_prb*SRSLTE_NRE) -#define NOF_REFS_SF (NOF_REFS_SYM*2) // 2 reference symbols per subframe +#define NOF_REFS_SYM (q->cell.nof_prb * SRSLTE_NRE) +#define NOF_REFS_SF (NOF_REFS_SYM * 2) // 2 reference symbols per subframe -#define MAX_REFS_SYM (max_prb*SRSLTE_NRE) -#define MAX_REFS_SF (max_prb*SRSLTE_NRE*2) // 2 reference symbols per subframe +#define MAX_REFS_SYM (max_prb * SRSLTE_NRE) +#define MAX_REFS_SF (max_prb * SRSLTE_NRE * 2) // 2 reference symbols per subframe -/** 3GPP LTE Downlink channel estimator and equalizer. +/** 3GPP LTE Downlink channel estimator and equalizer. * Estimates the channel in the resource elements transmitting references and interpolates for the rest - * of the resource grid. - * - * The equalizer uses the channel estimates to produce an estimation of the transmitted symbol. - * - * This object depends on the srslte_refsignal_t object for creating the LTE CSR signal. -*/ - -int srslte_chest_ul_init(srslte_chest_ul_t *q, uint32_t max_prb) + * of the resource grid. + * + * The equalizer uses the channel estimates to produce an estimation of the transmitted symbol. + * + * This object depends on the srslte_refsignal_t object for creating the LTE CSR signal. + */ + +int srslte_chest_ul_init(srslte_chest_ul_t* q, uint32_t max_prb) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL) - { + if (q != NULL) { bzero(q, sizeof(srslte_chest_ul_t)); ret = srslte_refsignal_ul_init(&q->dmrs_signal, max_prb); @@ -60,7 +59,7 @@ int srslte_chest_ul_init(srslte_chest_ul_t *q, uint32_t max_prb) ERROR("Error initializing CSR signal (%d)\n", ret); goto clean_exit; } - + q->tmp_noise = srslte_vec_malloc(sizeof(cf_t) * MAX_REFS_SF); if (!q->tmp_noise) { perror("malloc"); @@ -70,29 +69,29 @@ int srslte_chest_ul_init(srslte_chest_ul_t *q, uint32_t max_prb) if (!q->pilot_estimates) { perror("malloc"); goto clean_exit; - } - for (int i=0;i<4;i++) { + } + for (int i = 0; i < 4; i++) { q->pilot_estimates_tmp[i] = srslte_vec_malloc(sizeof(cf_t) * MAX_REFS_SF); if (!q->pilot_estimates_tmp[i]) { perror("malloc"); goto clean_exit; - } + } } - q->pilot_recv_signal = srslte_vec_malloc(sizeof(cf_t) * (MAX_REFS_SF+1)); + q->pilot_recv_signal = srslte_vec_malloc(sizeof(cf_t) * (MAX_REFS_SF + 1)); if (!q->pilot_recv_signal) { perror("malloc"); goto clean_exit; } - - q->pilot_known_signal = srslte_vec_malloc(sizeof(cf_t) * (MAX_REFS_SF+1)); + + q->pilot_known_signal = srslte_vec_malloc(sizeof(cf_t) * (MAX_REFS_SF + 1)); if (!q->pilot_known_signal) { perror("malloc"); goto clean_exit; } - + if (srslte_interp_linear_vector_init(&q->srslte_interp_linvec, MAX_REFS_SYM)) { ERROR("Error initializing vector interpolator\n"); - goto clean_exit; + goto clean_exit; } q->smooth_filter_len = 3; @@ -104,19 +103,18 @@ int srslte_chest_ul_init(srslte_chest_ul_t *q, uint32_t max_prb) ERROR("Error allocating memory for pregenerated signals\n"); goto clean_exit; } - } - + ret = SRSLTE_SUCCESS; clean_exit: if (ret != SRSLTE_SUCCESS) { - srslte_chest_ul_free(q); + srslte_chest_ul_free(q); } - return ret; + return ret; } -void srslte_chest_ul_free(srslte_chest_ul_t *q) +void srslte_chest_ul_free(srslte_chest_ul_t* q) { srslte_refsignal_dmrs_pusch_pregen_free(&q->dmrs_signal, &q->dmrs_pregen); @@ -125,11 +123,11 @@ void srslte_chest_ul_free(srslte_chest_ul_t *q) free(q->tmp_noise); } srslte_interp_linear_vector_free(&q->srslte_interp_linvec); - + if (q->pilot_estimates) { free(q->pilot_estimates); - } - for (int i=0;i<4;i++) { + } + for (int i = 0; i < 4; i++) { if (q->pilot_estimates_tmp[i]) { free(q->pilot_estimates_tmp[i]); } @@ -172,9 +170,7 @@ void srslte_chest_ul_res_free(srslte_chest_ul_res_t* q) int srslte_chest_ul_set_cell(srslte_chest_ul_t* q, srslte_cell_t cell) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - srslte_cell_isvalid(&cell)) - { + if (q != NULL && srslte_cell_isvalid(&cell)) { if (cell.id != q->cell.id || q->cell.nof_prb == 0) { q->cell = cell; ret = srslte_refsignal_ul_set_cell(&q->dmrs_signal, cell); @@ -200,45 +196,53 @@ void srslte_chest_ul_pregen(srslte_chest_ul_t* q, srslte_refsignal_dmrs_pusch_cf } /* Uses the difference between the averaged and non-averaged pilot estimates */ -static float estimate_noise_pilots(srslte_chest_ul_t *q, cf_t *ce, uint32_t nrefs, uint32_t n_prb[2]) +static float estimate_noise_pilots(srslte_chest_ul_t* q, cf_t* ce, uint32_t nrefs, uint32_t n_prb[2]) { - - float power = 0; - for (int i=0;i<2;i++) { - power += srslte_chest_estimate_noise_pilots(&q->pilot_estimates[i*nrefs], - &ce[SRSLTE_REFSIGNAL_UL_L(i, q->cell.cp)*q->cell.nof_prb*SRSLTE_NRE+n_prb[i]*SRSLTE_NRE], - q->tmp_noise, - nrefs); + + float power = 0; + for (int i = 0; i < 2; i++) { + power += srslte_chest_estimate_noise_pilots( + &q->pilot_estimates[i * nrefs], + &ce[SRSLTE_REFSIGNAL_UL_L(i, q->cell.cp) * q->cell.nof_prb * SRSLTE_NRE + n_prb[i] * SRSLTE_NRE], + q->tmp_noise, + nrefs); } - power/=2; - + power /= 2; + if (q->smooth_filter_len == 3) { // Calibrated for filter length 3 - float w=q->smooth_filter[0]; - float a=7.419*w*w+0.1117*w-0.005387; - return (power/(a*0.8)); + float w = q->smooth_filter[0]; + float a = 7.419 * w * w + 0.1117 * w - 0.005387; + return (power / (a * 0.8)); } else { - return power; + return power; } } // The interpolator currently only supports same frequency allocation for each subframe -#define cesymb(i) ce[SRSLTE_RE_IDX(q->cell.nof_prb,i,n_prb[0]*SRSLTE_NRE)] -static void interpolate_pilots(srslte_chest_ul_t *q, cf_t *ce, uint32_t nrefs, uint32_t n_prb[2]) +#define cesymb(i) ce[SRSLTE_RE_IDX(q->cell.nof_prb, i, n_prb[0] * SRSLTE_NRE)] +static void interpolate_pilots(srslte_chest_ul_t* q, cf_t* ce, uint32_t nrefs, uint32_t n_prb[2]) { #ifdef DO_LINEAR_INTERPOLATION uint32_t L1 = SRSLTE_REFSIGNAL_UL_L(0, q->cell.cp); uint32_t L2 = SRSLTE_REFSIGNAL_UL_L(1, q->cell.cp); - uint32_t NL = 2*SRSLTE_CP_NSYMB(q->cell.cp); - + uint32_t NL = 2 * SRSLTE_CP_NSYMB(q->cell.cp); + /* Interpolate in the time domain between symbols */ - srslte_interp_linear_vector3(&q->srslte_interp_linvec, - &cesymb(L2), &cesymb(L1), &cesymb(L1), &cesymb(L1-1), (L2-L1), L1, false, nrefs); - srslte_interp_linear_vector3(&q->srslte_interp_linvec, - &cesymb(L1), &cesymb(L2), NULL, &cesymb(L1+1), (L2-L1), (L2-L1)-1, true, nrefs); - srslte_interp_linear_vector3(&q->srslte_interp_linvec, - &cesymb(L1), &cesymb(L2), &cesymb(L2), &cesymb(L2+1), (L2-L1), (NL-L2)-1, true, nrefs); + srslte_interp_linear_vector3( + &q->srslte_interp_linvec, &cesymb(L2), &cesymb(L1), &cesymb(L1), &cesymb(L1 - 1), (L2 - L1), L1, false, nrefs); + srslte_interp_linear_vector3( + &q->srslte_interp_linvec, &cesymb(L1), &cesymb(L2), NULL, &cesymb(L1 + 1), (L2 - L1), (L2 - L1) - 1, true, nrefs); + srslte_interp_linear_vector3(&q->srslte_interp_linvec, + &cesymb(L1), + &cesymb(L2), + &cesymb(L2), + &cesymb(L2 + 1), + (L2 - L1), + (NL - L2) - 1, + true, + nrefs); #else // Instead of a linear interpolation, we just copy the estimates to all symbols in that subframe for (int s = 0; s < 2; s++) { @@ -257,16 +261,24 @@ static void interpolate_pilots(srslte_chest_ul_t *q, cf_t *ce, uint32_t nrefs, u #endif } -static void average_pilots(srslte_chest_ul_t *q, cf_t *input, cf_t *ce, uint32_t nrefs, uint32_t n_prb[2]) { - for (int i=0;i<2;i++) { - srslte_chest_average_pilots(&input[i*nrefs], - &ce[SRSLTE_REFSIGNAL_UL_L(i, q->cell.cp)*q->cell.nof_prb*SRSLTE_NRE+n_prb[i]*SRSLTE_NRE], - q->smooth_filter, nrefs, 1, q->smooth_filter_len); +static void average_pilots(srslte_chest_ul_t* q, cf_t* input, cf_t* ce, uint32_t nrefs, uint32_t n_prb[2]) +{ + for (int i = 0; i < 2; i++) { + srslte_chest_average_pilots( + &input[i * nrefs], + &ce[SRSLTE_REFSIGNAL_UL_L(i, q->cell.cp) * q->cell.nof_prb * SRSLTE_NRE + n_prb[i] * SRSLTE_NRE], + q->smooth_filter, + nrefs, + 1, + q->smooth_filter_len); } } -int srslte_chest_ul_estimate_pusch( - srslte_chest_ul_t* q, srslte_ul_sf_cfg_t* sf, srslte_pusch_cfg_t* cfg, cf_t* input, srslte_chest_ul_res_t* res) +int srslte_chest_ul_estimate_pusch(srslte_chest_ul_t* q, + srslte_ul_sf_cfg_t* sf, + srslte_pusch_cfg_t* cfg, + cf_t* input, + srslte_chest_ul_res_t* res) { if (!q->dmrs_signal_configured) { ERROR("Error must call srslte_chest_ul_set_cfg() before using the UL estimator\n"); @@ -303,7 +315,7 @@ int srslte_chest_ul_estimate_pusch( res->noise_estimate = estimate_noise_pilots(q, res->ce, nrefs_sym, cfg->grant.n_prb); } else { // Copy estimates to CE vector without averaging - for (int i=0;i<2;i++) { + for (int i = 0; i < 2; i++) { memcpy(&res->ce[SRSLTE_REFSIGNAL_UL_L(i, q->cell.cp) * q->cell.nof_prb * SRSLTE_NRE + cfg->grant.n_prb[i] * SRSLTE_NRE], &q->pilot_estimates[i * nrefs_sym], @@ -326,8 +338,11 @@ int srslte_chest_ul_estimate_pusch( return 0; } -int srslte_chest_ul_estimate_pucch( - srslte_chest_ul_t* q, srslte_ul_sf_cfg_t* sf, srslte_pucch_cfg_t* cfg, cf_t* input, srslte_chest_ul_res_t* res) +int srslte_chest_ul_estimate_pucch(srslte_chest_ul_t* q, + srslte_ul_sf_cfg_t* sf, + srslte_pucch_cfg_t* cfg, + cf_t* input, + srslte_chest_ul_res_t* res) { if (!q->dmrs_signal_configured) { ERROR("Error must call srslte_chest_ul_set_cfg() before using the UL estimator\n"); @@ -346,17 +361,17 @@ int srslte_chest_ul_estimate_pucch( /* Generate known pilots */ if (cfg->format == SRSLTE_PUCCH_FORMAT_2A || cfg->format == SRSLTE_PUCCH_FORMAT_2B) { - float max = -1e9; + float max = -1e9; int i_max = 0; int m = 0; if (cfg->format == SRSLTE_PUCCH_FORMAT_2A) { m = 2; } else { - m = 4; + m = 4; } - - for (int i=0;ipucch2_drs_bits[0] = i % 2; cfg->pucch2_drs_bits[1] = i / 2; srslte_refsignal_dmrs_pucch_gen(&q->dmrs_signal, sf, cfg, q->pilot_known_signal); @@ -367,7 +382,7 @@ int srslte_chest_ul_estimate_pucch( i_max = i; } } - memcpy(q->pilot_estimates, q->pilot_estimates_tmp[i_max], nrefs_sf*sizeof(cf_t)); + memcpy(q->pilot_estimates, q->pilot_estimates_tmp[i_max], nrefs_sf * sizeof(cf_t)); cfg->pucch2_drs_bits[0] = i_max % 2; cfg->pucch2_drs_bits[1] = i_max / 2; @@ -380,26 +395,31 @@ int srslte_chest_ul_estimate_pucch( if (res->ce != NULL) { /* FIXME: Currently averaging entire slot, performance good enough? */ for (int ns = 0; ns < 2; ns++) { - // Average all slot - for (int i=1;ipilot_estimates[ns * n_rs * SRSLTE_NRE], &q->pilot_estimates[(i + ns * n_rs) * SRSLTE_NRE], &q->pilot_estimates[ns * n_rs * SRSLTE_NRE], SRSLTE_NRE); } - srslte_vec_sc_prod_ccc(&q->pilot_estimates[ns*n_rs*SRSLTE_NRE], (float) 1.0/n_rs, - &q->pilot_estimates[ns*n_rs*SRSLTE_NRE], + srslte_vec_sc_prod_ccc(&q->pilot_estimates[ns * n_rs * SRSLTE_NRE], + (float)1.0 / n_rs, + &q->pilot_estimates[ns * n_rs * SRSLTE_NRE], SRSLTE_NRE); - + // Average in freq domain - srslte_chest_average_pilots(&q->pilot_estimates[ns*n_rs*SRSLTE_NRE], &q->pilot_recv_signal[ns*n_rs*SRSLTE_NRE], - q->smooth_filter, SRSLTE_NRE, 1, q->smooth_filter_len); - + srslte_chest_average_pilots(&q->pilot_estimates[ns * n_rs * SRSLTE_NRE], + &q->pilot_recv_signal[ns * n_rs * SRSLTE_NRE], + q->smooth_filter, + SRSLTE_NRE, + 1, + q->smooth_filter_len); + // Determine n_prb uint32_t n_prb = srslte_pucch_n_prb(&q->cell, cfg, ns); - // copy estimates to slot - for (int i=0;icell.cp);i++) { + // copy estimates to slot + for (int i = 0; i < SRSLTE_CP_NSYMB(q->cell.cp); i++) { memcpy(&res->ce[SRSLTE_RE_IDX(q->cell.nof_prb, i + ns * SRSLTE_CP_NSYMB(q->cell.cp), n_prb * SRSLTE_NRE)], &q->pilot_recv_signal[ns * n_rs * SRSLTE_NRE], sizeof(cf_t) * SRSLTE_NRE); @@ -409,4 +429,3 @@ int srslte_chest_ul_estimate_pucch( return 0; } - diff --git a/lib/src/phy/ch_estimation/refsignal_dl.c b/lib/src/phy/ch_estimation/refsignal_dl.c index f25154c2e..552df0577 100644 --- a/lib/src/phy/ch_estimation/refsignal_dl.c +++ b/lib/src/phy/ch_estimation/refsignal_dl.c @@ -26,11 +26,11 @@ #include #include -#include "srslte/phy/common/phy_common.h" #include "srslte/phy/ch_estimation/refsignal_dl.h" -#include "srslte/phy/utils/vector.h" -#include "srslte/phy/utils/debug.h" +#include "srslte/phy/common/phy_common.h" #include "srslte/phy/common/sequence.h" +#include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" /** Allocates memory for the 20 slots in a subframe */ @@ -104,7 +104,7 @@ int srslte_refsignal_cs_set_cell(srslte_refsignal_t* q, srslte_cell_t cell) /* Compute signal */ for (uint32_t i = 0; i < 2 * q->cell.nof_prb; i++) { uint32_t idx = SRSLTE_REFSIGNAL_PILOT_IDX(i, (ns % 2) * nsymbols + l, q->cell); - mp = i + SRSLTE_MAX_PRB - cell.nof_prb; + mp = i + SRSLTE_MAX_PRB - cell.nof_prb; /* save signal */ __real__ q->pilots[p][ns / 2][idx] = (1 - 2 * (float)seq.c[2 * mp + 0]) * M_SQRT1_2; __imag__ q->pilots[p][ns / 2][idx] = (1 - 2 * (float)seq.c[2 * mp + 1]) * M_SQRT1_2; @@ -236,20 +236,21 @@ inline uint32_t srslte_refsignal_cs_nof_re(srslte_refsignal_t* q, srslte_dl_sf_c return nof_re; } -inline uint32_t srslte_refsignal_cs_fidx(srslte_cell_t cell, uint32_t l, uint32_t port_id, uint32_t m) { - return 6*m + ((srslte_refsignal_cs_v(port_id, l) + (cell.id % 6)) % 6); +inline uint32_t srslte_refsignal_cs_fidx(srslte_cell_t cell, uint32_t l, uint32_t port_id, uint32_t m) +{ + return 6 * m + ((srslte_refsignal_cs_v(port_id, l) + (cell.id % 6)) % 6); } inline uint32_t srslte_refsignal_cs_nsymbol(uint32_t l, srslte_cp_t cp, uint32_t port_id) { if (port_id < 2) { if (l % 2) { - return (l/2+1)*SRSLTE_CP_NSYMB(cp) - 3; + return (l / 2 + 1) * SRSLTE_CP_NSYMB(cp) - 3; } else { - return (l/2)*SRSLTE_CP_NSYMB(cp); - } + return (l / 2) * SRSLTE_CP_NSYMB(cp); + } } else { - return 1+l*SRSLTE_CP_NSYMB(cp); + return 1 + l * SRSLTE_CP_NSYMB(cp); } } @@ -277,8 +278,11 @@ int srslte_refsignal_cs_put_sf(srslte_refsignal_t* q, srslte_dl_sf_cfg_t* sf, ui } /** Copies the RE containing references from an array of subframe symbols to the pilots array. */ -int srslte_refsignal_cs_get_sf( - srslte_refsignal_t* q, srslte_dl_sf_cfg_t* sf, uint32_t port_id, cf_t* sf_symbols, cf_t* pilots) +int srslte_refsignal_cs_get_sf(srslte_refsignal_t* q, + srslte_dl_sf_cfg_t* sf, + uint32_t port_id, + cf_t* sf_symbols, + cf_t* pilots) { uint32_t i, l; uint32_t fidx; @@ -299,8 +303,11 @@ int srslte_refsignal_cs_get_sf( } } -SRSLTE_API int srslte_refsignal_mbsfn_put_sf( - srslte_cell_t cell, uint32_t port_id, cf_t* cs_pilots, cf_t* mbsfn_pilots, cf_t* sf_symbols) +SRSLTE_API int srslte_refsignal_mbsfn_put_sf(srslte_cell_t cell, + uint32_t port_id, + cf_t* cs_pilots, + cf_t* mbsfn_pilots, + cf_t* sf_symbols) { uint32_t i, l; uint32_t fidx; @@ -379,14 +386,14 @@ int srslte_refsignal_mbsfn_gen_seq(srslte_refsignal_t* q, srslte_cell_t cell, ui for (ns = 0; ns < SRSLTE_NOF_SF_X_FRAME; ns++) { for (p = 0; p < 2; p++) { uint32_t nsymbols = 3; // replace with function - for(l=0;lcell.nof_prb; i++) { uint32_t idx = SRSLTE_REFSIGNAL_PILOT_IDX_MBSFN(i, l, q->cell); - mp = i + 3 * (SRSLTE_MAX_PRB - cell.nof_prb); + mp = i + 3 * (SRSLTE_MAX_PRB - cell.nof_prb); __real__ q->pilots[p][ns][idx] = (1 - 2 * (float)seq_mbsfn.c[2 * mp + 0]) * M_SQRT1_2; __imag__ q->pilots[p][ns][idx] = (1 - 2 * (float)seq_mbsfn.c[2 * mp + 1]) * M_SQRT1_2; } @@ -405,19 +412,17 @@ free_and_exit: return ret; } - -int srslte_refsignal_mbsfn_init(srslte_refsignal_t * q, uint32_t max_prb) +int srslte_refsignal_mbsfn_init(srslte_refsignal_t* q, uint32_t max_prb) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; + int ret = SRSLTE_ERROR_INVALID_INPUTS; uint32_t i, p; - if (q != NULL) - { + if (q != NULL) { ret = SRSLTE_ERROR; bzero(q, sizeof(srslte_refsignal_t)); q->type = SRSLTE_SF_MBSFN; - for (p=0;p<2;p++) { + for (p = 0; p < 2; p++) { for (i = 0; i < SRSLTE_NOF_SF_X_FRAME; i++) { q->pilots[p][i] = srslte_vec_malloc(sizeof(cf_t) * max_prb * 18); if (!q->pilots[p][i]) { @@ -437,7 +442,8 @@ free_and_exit: return ret; } -int srslte_refsignal_mbsfn_set_cell(srslte_refsignal_t * q, srslte_cell_t cell, uint16_t mbsfn_area_id){ +int srslte_refsignal_mbsfn_set_cell(srslte_refsignal_t* q, srslte_cell_t cell, uint16_t mbsfn_area_id) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; q->cell = cell; @@ -456,40 +462,32 @@ free_and_exit: return ret; } - -int srslte_refsignal_mbsfn_get_sf(srslte_cell_t cell, uint32_t port_id, cf_t *sf_symbols, cf_t *pilots) +int srslte_refsignal_mbsfn_get_sf(srslte_cell_t cell, uint32_t port_id, cf_t* sf_symbols, cf_t* pilots) { uint32_t i, l; uint32_t fidx; uint32_t nsymbol; - if (srslte_cell_isvalid(&cell) && - srslte_portid_isvalid(port_id) && - pilots != NULL && - sf_symbols != NULL) - { - // getting refs from non mbsfn section of subframe + if (srslte_cell_isvalid(&cell) && srslte_portid_isvalid(port_id) && pilots != NULL && sf_symbols != NULL) { + // getting refs from non mbsfn section of subframe nsymbol = srslte_refsignal_cs_nsymbol(0, cell.cp, port_id); fidx = ((srslte_refsignal_cs_v(port_id, 0) + (cell.id % 6)) % 6); - for (i = 0; i < 2*cell.nof_prb; i++) { - pilots[SRSLTE_REFSIGNAL_PILOT_IDX(i,0,cell)] = sf_symbols[SRSLTE_RE_IDX(cell.nof_prb, nsymbol, fidx)]; - fidx += SRSLTE_NRE/2; // 2 references per PRB + for (i = 0; i < 2 * cell.nof_prb; i++) { + pilots[SRSLTE_REFSIGNAL_PILOT_IDX(i, 0, cell)] = sf_symbols[SRSLTE_RE_IDX(cell.nof_prb, nsymbol, fidx)]; + fidx += SRSLTE_NRE / 2; // 2 references per PRB } - - for (l = 0; l< srslte_refsignal_mbsfn_nof_symbols() ;l++){ + + for (l = 0; l < srslte_refsignal_mbsfn_nof_symbols(); l++) { nsymbol = srslte_refsignal_mbsfn_nsymbol(l); - fidx = srslte_refsignal_mbsfn_fidx(l); + fidx = srslte_refsignal_mbsfn_fidx(l); for (i = 0; i < 6 * cell.nof_prb; i++) { - pilots[SRSLTE_REFSIGNAL_PILOT_IDX_MBSFN(i,l,cell) + (2*cell.nof_prb)] = sf_symbols[SRSLTE_RE_IDX(cell.nof_prb, nsymbol, fidx)]; + pilots[SRSLTE_REFSIGNAL_PILOT_IDX_MBSFN(i, l, cell) + (2 * cell.nof_prb)] = + sf_symbols[SRSLTE_RE_IDX(cell.nof_prb, nsymbol, fidx)]; fidx += SRSLTE_NRE / 6; - } + } } - - return SRSLTE_SUCCESS; + + return SRSLTE_SUCCESS; } else { - return SRSLTE_ERROR_INVALID_INPUTS; - } + return SRSLTE_ERROR_INVALID_INPUTS; + } } - - - - diff --git a/lib/src/phy/ch_estimation/refsignal_dl_nbiot.c b/lib/src/phy/ch_estimation/refsignal_dl_nbiot.c index 0273f43bd..c71ef978b 100644 --- a/lib/src/phy/ch_estimation/refsignal_dl_nbiot.c +++ b/lib/src/phy/ch_estimation/refsignal_dl_nbiot.c @@ -216,8 +216,12 @@ int srslte_refsignal_nrs_put_sf(srslte_nbiot_cell_t cell, uint32_t port_id, cf_t uint32_t fidx = srslte_refsignal_dl_nbiot_fidx(cell, l, port_id, m) + cell.nbiot_prb * SRSLTE_NRE; sf_symbols[SRSLTE_RE_IDX(cell.base.nof_prb, nsymbol, fidx)] = pilots[SRSLTE_NBIOT_REFSIGNAL_PILOT_IDX(m, l, 1)]; #if EXTRA_DEBUG - DEBUG("port: %d, re_idx: %d, pilot_idx: %d, %+2.2f%+2.2fi\n", port_id, SRSLTE_RE_IDX(cell.base.nof_prb, nsymbol, fidx), SRSLTE_NBIOT_REFSIGNAL_PILOT_IDX(i,l, 1), - __real__ sf_symbols[SRSLTE_RE_IDX(cell.base.nof_prb, nsymbol, fidx)], __imag__ sf_symbols[SRSLTE_RE_IDX(cell.base.nof_prb, nsymbol, fidx)]); + DEBUG("port: %d, re_idx: %d, pilot_idx: %d, %+2.2f%+2.2fi\n", + port_id, + SRSLTE_RE_IDX(cell.base.nof_prb, nsymbol, fidx), + SRSLTE_NBIOT_REFSIGNAL_PILOT_IDX(i, l, 1), + __real__ sf_symbols[SRSLTE_RE_IDX(cell.base.nof_prb, nsymbol, fidx)], + __imag__ sf_symbols[SRSLTE_RE_IDX(cell.base.nof_prb, nsymbol, fidx)]); #endif } } @@ -246,16 +250,21 @@ int srslte_refsignal_nrs_get_sf(srslte_nbiot_cell_t cell, uint32_t port_id, cf_t uint32_t fidx = srslte_refsignal_dl_nbiot_fidx(cell, l, port_id, m) + cell.nbiot_prb * SRSLTE_NRE; pilots[SRSLTE_NBIOT_REFSIGNAL_PILOT_IDX(m, l, 1)] = sf_symbols[SRSLTE_RE_IDX(cell.base.nof_prb, nsymbol, fidx)]; #if EXTRA_DEBUG - DEBUG("port: %d, pilot_idx: %d, re_idx: %d, %+2.2f%+2.2fi\n", port_id, SRSLTE_NBIOT_REFSIGNAL_PILOT_IDX(m, l, 1), SRSLTE_RE_IDX(cell.base.nof_prb, nsymbol, fidx), - __real__ pilots[SRSLTE_NBIOT_REFSIGNAL_PILOT_IDX(m, l, 1)], __imag__ pilots[SRSLTE_NBIOT_REFSIGNAL_PILOT_IDX(m, l, 1)]); + DEBUG("port: %d, pilot_idx: %d, re_idx: %d, %+2.2f%+2.2fi\n", + port_id, + SRSLTE_NBIOT_REFSIGNAL_PILOT_IDX(m, l, 1), + SRSLTE_RE_IDX(cell.base.nof_prb, nsymbol, fidx), + __real__ pilots[SRSLTE_NBIOT_REFSIGNAL_PILOT_IDX(m, l, 1)], + __imag__ pilots[SRSLTE_NBIOT_REFSIGNAL_PILOT_IDX(m, l, 1)]); #endif } } #if EXTRA_DEBUG if (SRSLTE_VERBOSE_ISDEBUG()) { - DEBUG("SAVED FILE chest_nbiot_rx_after_demapping.bin: NRS after demapping\n",0); - srslte_vec_save_file("chest_nbiot_rx_after_demapping.bin", pilots, SRSLTE_REFSIGNAL_NUM_SF(1, port_id) * sizeof(cf_t)); + DEBUG("SAVED FILE chest_nbiot_rx_after_demapping.bin: NRS after demapping\n", 0); + srslte_vec_save_file( + "chest_nbiot_rx_after_demapping.bin", pilots, SRSLTE_REFSIGNAL_NUM_SF(1, port_id) * sizeof(cf_t)); } #endif return SRSLTE_SUCCESS; diff --git a/lib/src/phy/ch_estimation/refsignal_ul.c b/lib/src/phy/ch_estimation/refsignal_ul.c index c59e4f2e0..b23005747 100644 --- a/lib/src/phy/ch_estimation/refsignal_ul.c +++ b/lib/src/phy/ch_estimation/refsignal_ul.c @@ -19,11 +19,11 @@ * */ +#include #include +#include #include #include -#include -#include #include "srslte/phy/ch_estimation/refsignal_ul.h" #include "srslte/phy/common/phy_common.h" @@ -36,98 +36,74 @@ #include "ul_rs_tables.h" // n_dmrs_2 table 5.5.2.1.1-1 from 36.211 -uint32_t n_dmrs_2[8] = { 0, 6, 3, 4, 2, 8, 10, 9 }; +uint32_t n_dmrs_2[8] = {0, 6, 3, 4, 2, 8, 10, 9}; // n_dmrs_1 table 5.5.2.1.1-2 from 36.211 -uint32_t n_dmrs_1[8] = { 0, 2, 3, 4, 6, 8, 9, 10 }; +uint32_t n_dmrs_1[8] = {0, 2, 3, 4, 6, 8, 9, 10}; -/* Orthogonal sequences for PUCCH formats 1a, 1b and 1c. Table 5.5.2.2.1-2 +/* Orthogonal sequences for PUCCH formats 1a, 1b and 1c. Table 5.5.2.2.1-2 */ -float w_arg_pucch_format1_cpnorm[3][3] = {{0, 0, 0}, - {0, 2*M_PI/3, 4*M_PI/3}, - {0, 4*M_PI/3, 2*M_PI/3}}; +float w_arg_pucch_format1_cpnorm[3][3] = {{0, 0, 0}, {0, 2 * M_PI / 3, 4 * M_PI / 3}, {0, 4 * M_PI / 3, 2 * M_PI / 3}}; -float w_arg_pucch_format1_cpext[3][2] = {{0, 0}, - {0, M_PI}, - {0, 0}}; +float w_arg_pucch_format1_cpext[3][2] = {{0, 0}, {0, M_PI}, {0, 0}}; -float w_arg_pucch_format2_cpnorm[2] = {0, 0}; -float w_arg_pucch_format2_cpext[1] = {0}; +float w_arg_pucch_format2_cpnorm[2] = {0, 0}; +float w_arg_pucch_format2_cpext[1] = {0}; uint32_t pucch_dmrs_symbol_format1_cpnorm[3] = {2, 3, 4}; -uint32_t pucch_dmrs_symbol_format1_cpext[2] = {2, 3}; +uint32_t pucch_dmrs_symbol_format1_cpext[2] = {2, 3}; uint32_t pucch_dmrs_symbol_format2_cpnorm[2] = {1, 5}; -uint32_t pucch_dmrs_symbol_format2_cpext[1] = {3}; +uint32_t pucch_dmrs_symbol_format2_cpext[1] = {3}; /* Table 5.5.3.3-1: Frame structure type 1 sounding reference signal subframe configuration. */ -uint32_t T_sfc[15] = {1, 2, 2, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 10}; -uint32_t Delta_sfc1[7] = {0, 0, 1, 0, 1, 2, 3}; -uint32_t Delta_sfc2[4] = {0, 1, 2, 3}; - - -uint32_t m_srs_b[4][4][8] = {{ - /* m_srs for 6cell.id / 30) << 5) + (((q->cell.id % 30) + delta_ss) % 30); if (srslte_sequence_LTE_pr(&seq, 8 * SRSLTE_CP_NSYMB(q->cell.cp) * 20, c_init)) { return SRSLTE_ERROR; } - for (uint32_t ns=0;nscell.cp) * ns + i] << i); @@ -137,44 +113,45 @@ static int generate_n_prs(srslte_refsignal_ul_t * q) { } srslte_sequence_free(&seq); - return SRSLTE_SUCCESS; + return SRSLTE_SUCCESS; } -void srslte_refsignal_r_uv_arg_1prb(float *arg, uint32_t u) { +void srslte_refsignal_r_uv_arg_1prb(float* arg, uint32_t u) +{ for (int i = 0; i < SRSLTE_NRE; i++) { arg[i] = phi_M_sc_12[u][i] * M_PI / 4; } } -static int generate_srslte_sequence_hopping_v(srslte_refsignal_ul_t *q) { - srslte_sequence_t seq; +static int generate_srslte_sequence_hopping_v(srslte_refsignal_ul_t* q) +{ + srslte_sequence_t seq; bzero(&seq, sizeof(srslte_sequence_t)); - - for (uint32_t ns=0;nscell.id / 30) << 5) + ((q->cell.id%30)+delta_ss)%30)) { + + for (uint32_t ns = 0; ns < SRSLTE_NSLOTS_X_FRAME; ns++) { + for (uint32_t delta_ss = 0; delta_ss < SRSLTE_NOF_DELTA_SS; delta_ss++) { + if (srslte_sequence_LTE_pr(&seq, 20, ((q->cell.id / 30) << 5) + ((q->cell.id % 30) + delta_ss) % 30)) { return SRSLTE_ERROR; } - q->v_pusch[ns][delta_ss] = seq.c[ns]; + q->v_pusch[ns][delta_ss] = seq.c[ns]; } } srslte_sequence_free(&seq); return SRSLTE_SUCCESS; } - /** Initializes srslte_refsignal_ul_t object according to 3GPP 36.211 5.5 * */ -int srslte_refsignal_ul_init(srslte_refsignal_ul_t * q, uint32_t max_prb) +int srslte_refsignal_ul_init(srslte_refsignal_ul_t* q, uint32_t max_prb) { int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL) { - ret = SRSLTE_ERROR; - + ret = SRSLTE_ERROR; + bzero(q, sizeof(srslte_refsignal_ul_t)); // Allocate temporal buffer for computing signal argument @@ -183,7 +160,7 @@ int srslte_refsignal_ul_init(srslte_refsignal_ul_t * q, uint32_t max_prb) perror("malloc"); goto free_and_exit; } - + ret = SRSLTE_SUCCESS; } free_and_exit: @@ -193,7 +170,8 @@ free_and_exit: return ret; } -void srslte_refsignal_ul_free(srslte_refsignal_ul_t * q) { +void srslte_refsignal_ul_free(srslte_refsignal_ul_t* q) +{ if (q->tmp_arg) { free(q->tmp_arg); } @@ -203,7 +181,7 @@ void srslte_refsignal_ul_free(srslte_refsignal_ul_t * q) { /** Initializes srslte_refsignal_ul_t object according to 3GPP 36.211 5.5 * */ -int srslte_refsignal_ul_set_cell(srslte_refsignal_ul_t * q, srslte_cell_t cell) +int srslte_refsignal_ul_set_cell(srslte_refsignal_ul_t* q, srslte_cell_t cell) { int ret = SRSLTE_ERROR_INVALID_INPUTS; @@ -248,67 +226,70 @@ static uint32_t largest_prime_lower_than(uint32_t x) return 0; } -static void arg_r_uv_2prb(float *arg, uint32_t u) { - for (int i = 0; i < 2*SRSLTE_NRE; i++) { +static void arg_r_uv_2prb(float* arg, uint32_t u) +{ + for (int i = 0; i < 2 * SRSLTE_NRE; i++) { arg[i] = phi_M_sc_24[u][i] * M_PI / 4; - } + } } -static uint32_t get_q(uint32_t u, uint32_t v, uint32_t N_sz) { +static uint32_t get_q(uint32_t u, uint32_t v, uint32_t N_sz) +{ float q; float q_hat; - float n_sz = (float) N_sz; - - q_hat = n_sz *(u + 1) / 31; - if ((((uint32_t) (2 * q_hat)) % 2) == 0) { + float n_sz = (float)N_sz; + + q_hat = n_sz * (u + 1) / 31; + if ((((uint32_t)(2 * q_hat)) % 2) == 0) { q = q_hat + 0.5 + v; } else { q = q_hat + 0.5 - v; } - return (uint32_t) q; + return (uint32_t)q; } -static void arg_r_uv_mprb(float *arg, uint32_t M_sc, uint32_t u, uint32_t v) { +static void arg_r_uv_mprb(float* arg, uint32_t M_sc, uint32_t u, uint32_t v) +{ uint32_t N_sz = largest_prime_lower_than(M_sc); if (N_sz > 0) { - float q = get_q(u,v,N_sz); - float n_sz = (float) N_sz; + float q = get_q(u, v, N_sz); + float n_sz = (float)N_sz; for (uint32_t i = 0; i < M_sc; i++) { - float m = (float) (i%N_sz); - arg[i] = -M_PI * q * m * (m + 1) / n_sz; + float m = (float)(i % N_sz); + arg[i] = -M_PI * q * m * (m + 1) / n_sz; } } } /* Computes argument of r_u_v signal */ -static void compute_r_uv_arg(srslte_refsignal_ul_t *q, uint32_t nof_prb, uint32_t u, uint32_t v) { +static void compute_r_uv_arg(srslte_refsignal_ul_t* q, uint32_t nof_prb, uint32_t u, uint32_t v) +{ if (nof_prb == 1) { srslte_refsignal_r_uv_arg_1prb(q->tmp_arg, u); } else if (nof_prb == 2) { arg_r_uv_2prb(q->tmp_arg, u); } else { - arg_r_uv_mprb(q->tmp_arg, SRSLTE_NRE*nof_prb, u, v); + arg_r_uv_mprb(q->tmp_arg, SRSLTE_NRE * nof_prb, u, v); } } /* Calculates alpha according to 5.5.2.1.1 of 36.211 */ -static float pusch_alpha(srslte_refsignal_ul_t *q, srslte_refsignal_dmrs_pusch_cfg_t *cfg, - uint32_t cyclic_shift_for_dmrs, uint32_t ns) +static float pusch_alpha(srslte_refsignal_ul_t* q, + srslte_refsignal_dmrs_pusch_cfg_t* cfg, + uint32_t cyclic_shift_for_dmrs, + uint32_t ns) { - uint32_t n_dmrs_2_val = n_dmrs_2[cyclic_shift_for_dmrs]; - uint32_t n_cs = (n_dmrs_1[cfg->cyclic_shift] + n_dmrs_2_val + q->n_prs_pusch[cfg->delta_ss][ns]) % 12; - - return 2 * M_PI * (n_cs) / 12; + uint32_t n_dmrs_2_val = n_dmrs_2[cyclic_shift_for_dmrs]; + uint32_t n_cs = (n_dmrs_1[cfg->cyclic_shift] + n_dmrs_2_val + q->n_prs_pusch[cfg->delta_ss][ns]) % 12; + return 2 * M_PI * (n_cs) / 12; } static bool pusch_cfg_isvalid(srslte_refsignal_ul_t* q, srslte_refsignal_dmrs_pusch_cfg_t* cfg, uint32_t nof_prb) { - if (cfg->cyclic_shift < SRSLTE_NOF_CSHIFT && - cfg->delta_ss < SRSLTE_NOF_DELTA_SS && - nof_prb <= q->cell.nof_prb) { - return true; + if (cfg->cyclic_shift < SRSLTE_NOF_CSHIFT && cfg->delta_ss < SRSLTE_NOF_DELTA_SS && nof_prb <= q->cell.nof_prb) { + return true; } else { return false; } @@ -319,7 +300,7 @@ void srslte_refsignal_dmrs_pusch_put(srslte_refsignal_ul_t* q, cf_t* r_pusch, cf_t* sf_symbols) { - for (uint32_t ns_idx=0;ns_idx<2;ns_idx++) { + for (uint32_t ns_idx = 0; ns_idx < 2; ns_idx++) { INFO("Putting DMRS to n_prb: %d, L: %d, ns_idx: %d\n", pusch_cfg->grant.n_prb_tilde[ns_idx], pusch_cfg->grant.L_prb, @@ -349,15 +330,18 @@ void srslte_refsignal_dmrs_pusch_get(srslte_refsignal_ul_t* q, } /* Computes r sequence */ -static void compute_r( - srslte_refsignal_ul_t* q, srslte_refsignal_dmrs_pusch_cfg_t* cfg, uint32_t nof_prb, uint32_t ns, uint32_t delta_ss) +static void compute_r(srslte_refsignal_ul_t* q, + srslte_refsignal_dmrs_pusch_cfg_t* cfg, + uint32_t nof_prb, + uint32_t ns, + uint32_t delta_ss) { // Get group hopping number u uint32_t f_gh = 0; if (cfg->group_hopping_en) { f_gh = q->f_gh[ns]; } - uint32_t u = (f_gh + (q->cell.id%30)+delta_ss)%30; + uint32_t u = (f_gh + (q->cell.id % 30) + delta_ss) % 30; // Get sequence hopping number v uint32_t v = 0; @@ -365,20 +349,19 @@ static void compute_r( v = q->v_pusch[ns][cfg->delta_ss]; } - // Compute signal argument + // Compute signal argument compute_r_uv_arg(q, nof_prb, u, v); - } int srslte_refsignal_dmrs_pusch_pregen_init(srslte_refsignal_ul_dmrs_pregen_t* pregen, uint32_t max_prb) { for (uint32_t sf_idx = 0; sf_idx < SRSLTE_NOF_SF_X_FRAME; sf_idx++) { - for (uint32_t cs=0;csr[cs][sf_idx] = (cf_t**) calloc(sizeof(cf_t*), max_prb + 1); + for (uint32_t cs = 0; cs < SRSLTE_NOF_CSHIFT; cs++) { + pregen->r[cs][sf_idx] = (cf_t**)calloc(sizeof(cf_t*), max_prb + 1); if (pregen->r[cs][sf_idx]) { - for (uint32_t n=0;n<=max_prb;n++) { + for (uint32_t n = 0; n <= max_prb; n++) { if (srslte_dft_precoding_valid_prb(n)) { - pregen->r[cs][sf_idx][n] = (cf_t*) srslte_vec_malloc(sizeof(cf_t)*n*2*SRSLTE_NRE); + pregen->r[cs][sf_idx][n] = (cf_t*)srslte_vec_malloc(sizeof(cf_t) * n * 2 * SRSLTE_NRE); if (pregen->r[cs][sf_idx][n]) { } else { return SRSLTE_ERROR; @@ -398,17 +381,17 @@ int srslte_refsignal_dmrs_pusch_pregen(srslte_refsignal_ul_t* q, srslte_refsignal_dmrs_pusch_cfg_t* cfg) { for (uint32_t sf_idx = 0; sf_idx < SRSLTE_NOF_SF_X_FRAME; sf_idx++) { - for (uint32_t cs=0;csr[cs][sf_idx]) { - for (uint32_t n=0;n<=q->cell.nof_prb;n++) { + for (uint32_t n = 0; n <= q->cell.nof_prb; n++) { if (srslte_dft_precoding_valid_prb(n)) { if (pregen->r[cs][sf_idx][n]) { if (srslte_refsignal_dmrs_pusch_gen(q, cfg, n, sf_idx, cs, pregen->r[cs][sf_idx][n])) { - return SRSLTE_ERROR; + return SRSLTE_ERROR; } } else { return SRSLTE_ERROR; - } + } } } } else { @@ -419,12 +402,12 @@ int srslte_refsignal_dmrs_pusch_pregen(srslte_refsignal_ul_t* q, return SRSLTE_SUCCESS; } -void srslte_refsignal_dmrs_pusch_pregen_free(srslte_refsignal_ul_t *q, srslte_refsignal_ul_dmrs_pregen_t *pregen) +void srslte_refsignal_dmrs_pusch_pregen_free(srslte_refsignal_ul_t* q, srslte_refsignal_ul_dmrs_pregen_t* pregen) { for (uint32_t sf_idx = 0; sf_idx < SRSLTE_NOF_SF_X_FRAME; sf_idx++) { - for (uint32_t cs=0;csr[cs][sf_idx]) { - for (uint32_t n=0;n<=q->cell.nof_prb;n++) { + for (uint32_t n = 0; n <= q->cell.nof_prb; n++) { if (srslte_dft_precoding_valid_prb(n)) { if (pregen->r[cs][sf_idx][n]) { free(pregen->r[cs][sf_idx][n]); @@ -467,8 +450,8 @@ int srslte_refsignal_dmrs_pusch_gen(srslte_refsignal_ul_t* q, int ret = SRSLTE_ERROR_INVALID_INPUTS; if (pusch_cfg_isvalid(q, cfg, nof_prb)) { ret = SRSLTE_ERROR; - - for (uint32_t ns=2*sf_idx;ns<2*(sf_idx+1);ns++) { + + for (uint32_t ns = 2 * sf_idx; ns < 2 * (sf_idx + 1); ns++) { compute_r(q, cfg, nof_prb, ns, cfg->delta_ss); @@ -476,56 +459,58 @@ int srslte_refsignal_dmrs_pusch_gen(srslte_refsignal_ul_t* q, float alpha = pusch_alpha(q, cfg, cyclic_shift_for_dmrs, ns); // Do complex exponential and adjust amplitude - for (int i=0;itmp_arg[i] + alpha*i)); - } + for (int i = 0; i < SRSLTE_NRE * nof_prb; i++) { + r_pusch[(ns % 2) * SRSLTE_NRE * nof_prb + i] = cexpf(I * (q->tmp_arg[i] + alpha * i)); + } } - ret = 0; + ret = 0; } - return ret; + return ret; } /* Number of PUCCH demodulation reference symbols per slot N_rs_pucch tABLE 5.5.2.2.1-1 36.211 */ -uint32_t srslte_refsignal_dmrs_N_rs(srslte_pucch_format_t format, srslte_cp_t cp) { +uint32_t srslte_refsignal_dmrs_N_rs(srslte_pucch_format_t format, srslte_cp_t cp) +{ switch (format) { case SRSLTE_PUCCH_FORMAT_1: case SRSLTE_PUCCH_FORMAT_1A: case SRSLTE_PUCCH_FORMAT_1B: if (SRSLTE_CP_ISNORM(cp)) { - return 3; + return 3; } else { - return 2; + return 2; } case SRSLTE_PUCCH_FORMAT_2: case SRSLTE_PUCCH_FORMAT_3: if (SRSLTE_CP_ISNORM(cp)) { - return 2; + return 2; } else { - return 1; + return 1; } case SRSLTE_PUCCH_FORMAT_2A: case SRSLTE_PUCCH_FORMAT_2B: - return 2; + return 2; default: ERROR("DMRS Nof RS: Unsupported format %d\n", format); - return 0; + return 0; } - return 0; + return 0; } /* Table 5.5.2.2.2-1: Demodulation reference signal location for different PUCCH formats. 36.211 */ -uint32_t srslte_refsignal_dmrs_pucch_symbol(uint32_t m, srslte_pucch_format_t format, srslte_cp_t cp) { +uint32_t srslte_refsignal_dmrs_pucch_symbol(uint32_t m, srslte_pucch_format_t format, srslte_cp_t cp) +{ switch (format) { case SRSLTE_PUCCH_FORMAT_1: case SRSLTE_PUCCH_FORMAT_1A: case SRSLTE_PUCCH_FORMAT_1B: if (SRSLTE_CP_ISNORM(cp)) { if (m < 3) { - return pucch_dmrs_symbol_format1_cpnorm[m]; + return pucch_dmrs_symbol_format1_cpnorm[m]; } } else { if (m < 2) { - return pucch_dmrs_symbol_format1_cpext[m]; + return pucch_dmrs_symbol_format1_cpext[m]; } } break; @@ -533,7 +518,7 @@ uint32_t srslte_refsignal_dmrs_pucch_symbol(uint32_t m, srslte_pucch_format_t fo case SRSLTE_PUCCH_FORMAT_3: if (SRSLTE_CP_ISNORM(cp)) { if (m < 2) { - return pucch_dmrs_symbol_format2_cpnorm[m]; + return pucch_dmrs_symbol_format2_cpnorm[m]; } } else { if (m < 1) { @@ -549,7 +534,7 @@ uint32_t srslte_refsignal_dmrs_pucch_symbol(uint32_t m, srslte_pucch_format_t fo break; default: ERROR("DMRS Symbol indexes: Unsupported format %d\n", format); - return 0; + return 0; } return 0; } @@ -581,9 +566,9 @@ int srslte_refsignal_dmrs_pucch_gen(srslte_refsignal_ul_t* q, } uint32_t u = (f_gh + (q->cell.id % 30)) % 30; - srslte_refsignal_r_uv_arg_1prb(q->tmp_arg, u); - - for (uint32_t m=0;mtmp_arg, u); + + for (uint32_t m = 0; m < N_rs; m++) { uint32_t n_oc = 0; uint32_t l = srslte_refsignal_dmrs_pucch_symbol(m, cfg->format, q->cell.cp); @@ -596,68 +581,71 @@ int srslte_refsignal_dmrs_pucch_gen(srslte_refsignal_ul_t* q, } // Choose number of symbols and orthogonal sequence from Tables 5.5.2.2.1-1 to -3 - float *w=NULL; + float* w = NULL; switch (cfg->format) { case SRSLTE_PUCCH_FORMAT_1: case SRSLTE_PUCCH_FORMAT_1A: case SRSLTE_PUCCH_FORMAT_1B: if (SRSLTE_CP_ISNORM(q->cell.cp)) { - w=w_arg_pucch_format1_cpnorm[n_oc]; + w = w_arg_pucch_format1_cpnorm[n_oc]; } else { - w=w_arg_pucch_format1_cpext[n_oc]; + w = w_arg_pucch_format1_cpext[n_oc]; } break; case SRSLTE_PUCCH_FORMAT_2: case SRSLTE_PUCCH_FORMAT_3: if (SRSLTE_CP_ISNORM(q->cell.cp)) { - w=w_arg_pucch_format2_cpnorm; + w = w_arg_pucch_format2_cpnorm; } else { - w=w_arg_pucch_format2_cpext; + w = w_arg_pucch_format2_cpext; } break; case SRSLTE_PUCCH_FORMAT_2A: case SRSLTE_PUCCH_FORMAT_2B: - w=w_arg_pucch_format2_cpnorm; + w = w_arg_pucch_format2_cpnorm; break; default: ERROR("DMRS Generator: Unsupported format %d\n", cfg->format); - return SRSLTE_ERROR; + return SRSLTE_ERROR; } cf_t z_m = 1.0; if (m == 1) { - z_m = z_m_1; + z_m = z_m_1; } - for (uint32_t n=0;ntmp_arg[n] + alpha * n)); - } + } } } - ret = SRSLTE_SUCCESS; + ret = SRSLTE_SUCCESS; } return ret; } -int srslte_refsignal_dmrs_pucch_cp( - srslte_refsignal_ul_t* q, srslte_pucch_cfg_t* cfg, cf_t* source, cf_t* dest, bool source_is_grid) +int srslte_refsignal_dmrs_pucch_cp(srslte_refsignal_ul_t* q, + srslte_pucch_cfg_t* cfg, + cf_t* source, + cf_t* dest, + bool source_is_grid) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; + int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q && source && dest) { - uint32_t nsymbols = SRSLTE_CP_ISNORM(q->cell.cp)?SRSLTE_CP_NORM_NSYMB:SRSLTE_CP_EXT_NSYMB; + uint32_t nsymbols = SRSLTE_CP_ISNORM(q->cell.cp) ? SRSLTE_CP_NORM_NSYMB : SRSLTE_CP_EXT_NSYMB; uint32_t N_rs = srslte_refsignal_dmrs_N_rs(cfg->format, q->cell.cp); - for (uint32_t ns=0;ns<2;ns++) { - + for (uint32_t ns = 0; ns < 2; ns++) { + // Determine n_prb uint32_t n_prb = srslte_pucch_n_prb(&q->cell, cfg, ns); - for (uint32_t i=0;iformat, q->cell.cp); if (!source_is_grid) { - memcpy(&dest[SRSLTE_RE_IDX(q->cell.nof_prb, l+ns*nsymbols, n_prb*SRSLTE_NRE)], - &source[ns*N_rs*SRSLTE_NRE+i*SRSLTE_NRE], - SRSLTE_NRE*sizeof(cf_t)); + memcpy(&dest[SRSLTE_RE_IDX(q->cell.nof_prb, l + ns * nsymbols, n_prb * SRSLTE_NRE)], + &source[ns * N_rs * SRSLTE_NRE + i * SRSLTE_NRE], + SRSLTE_NRE * sizeof(cf_t)); } else { memcpy(&dest[ns * N_rs * SRSLTE_NRE + i * SRSLTE_NRE], &source[SRSLTE_RE_IDX(q->cell.nof_prb, l + ns * nsymbols, n_prb * SRSLTE_NRE)], @@ -685,50 +673,51 @@ int srslte_refsignal_dmrs_pucch_get(srslte_refsignal_ul_t* q, srslte_pucch_cfg_t static uint32_t T_srs_table(uint32_t I_srs) { - uint32_t T_srs; + uint32_t T_srs; /* This is Table 8.2-1 */ if (I_srs < 2) { - T_srs = 2; + T_srs = 2; } else if (I_srs < 7) { - T_srs = 5; + T_srs = 5; } else if (I_srs < 17) { - T_srs = 10; + T_srs = 10; } else if (I_srs < 37) { - T_srs = 20; + T_srs = 20; } else if (I_srs < 77) { - T_srs = 40; + T_srs = 40; } else if (I_srs < 157) { - T_srs = 80; + T_srs = 80; } else if (I_srs < 317) { - T_srs = 160; + T_srs = 160; } else if (I_srs < 637) { - T_srs = 320; + T_srs = 320; } else { - T_srs = 0; + T_srs = 0; } - return T_srs; + return T_srs; } -/* Returns 1 if tti is a valid subframe for SRS transmission according to I_srs (UE-specific - * configuration index), as defined in Section 8.1 of 36.213. - * Returns 0 if no SRS shall be transmitted or a negative number if error. +/* Returns 1 if tti is a valid subframe for SRS transmission according to I_srs (UE-specific + * configuration index), as defined in Section 8.1 of 36.213. + * Returns 0 if no SRS shall be transmitted or a negative number if error. */ -int srslte_refsignal_srs_send_ue(uint32_t I_srs, uint32_t tti) { +int srslte_refsignal_srs_send_ue(uint32_t I_srs, uint32_t tti) +{ if (I_srs < 1024 && tti < 10240) { uint32_t Toffset = 0; /* This is Table 8.2-1 */ if (I_srs < 2) { - Toffset = I_srs; + Toffset = I_srs; } else if (I_srs < 7) { - Toffset = I_srs-2; + Toffset = I_srs - 2; } else if (I_srs < 17) { - Toffset = I_srs-7; + Toffset = I_srs - 7; } else if (I_srs < 37) { - Toffset = I_srs-17; + Toffset = I_srs - 17; } else if (I_srs < 77) { - Toffset = I_srs-37; + Toffset = I_srs - 37; } else if (I_srs < 157) { - Toffset = I_srs-77; + Toffset = I_srs - 77; } else if (I_srs < 317) { Toffset = I_srs - 157; } else if (I_srs < 637) { @@ -813,51 +802,52 @@ void srslte_refsignal_srs_pusch_shortened(srslte_refsignal_ul_t* q, sf->shortened = shortened; } -/* Returns 1 if sf_idx is a valid subframe for SRS transmission according to subframe_config (cell-specific), +/* Returns 1 if sf_idx is a valid subframe for SRS transmission according to subframe_config (cell-specific), * as defined in Section 5.5.3.3 of 36.211. Returns 0 if no SRS shall be transmitted or a negative - * number if error. + * number if error. */ -int srslte_refsignal_srs_send_cs(uint32_t subframe_config, uint32_t sf_idx) { +int srslte_refsignal_srs_send_cs(uint32_t subframe_config, uint32_t sf_idx) +{ if (subframe_config < 15 && sf_idx < 10) { uint32_t tsfc = T_sfc[subframe_config]; if (subframe_config < 7) { - if ((sf_idx%tsfc)==Delta_sfc1[subframe_config]) { - return 1; + if ((sf_idx % tsfc) == Delta_sfc1[subframe_config]) { + return 1; } else { - return 0; + return 0; } } else if (subframe_config == 7) { - if (((sf_idx%tsfc)==0) || ((sf_idx%tsfc)==1)){ - return 1; + if (((sf_idx % tsfc) == 0) || ((sf_idx % tsfc) == 1)) { + return 1; } else { - return 0; + return 0; } } else if (subframe_config == 8) { - if (((sf_idx%tsfc)==2) || ((sf_idx%tsfc)==3)){ - return 1; + if (((sf_idx % tsfc) == 2) || ((sf_idx % tsfc) == 3)) { + return 1; } else { - return 0; + return 0; } } else if (subframe_config < 13) { - if ((sf_idx%tsfc)==Delta_sfc2[subframe_config-9]) { + if ((sf_idx % tsfc) == Delta_sfc2[subframe_config - 9]) { return 1; } else { - return 0; + return 0; } } else if (subframe_config == 13) { - if (((sf_idx%tsfc)==5) || ((sf_idx%tsfc)==7) || ((sf_idx%tsfc)==9)){ - return 0; + if (((sf_idx % tsfc) == 5) || ((sf_idx % tsfc) == 7) || ((sf_idx % tsfc) == 9)) { + return 0; } else { - return 1; + return 1; } } else if (subframe_config == 14) { - if (((sf_idx%tsfc)==7) || ((sf_idx%tsfc)==9)) { - return 0; + if (((sf_idx % tsfc) == 7) || ((sf_idx % tsfc) == 9)) { + return 0; } else { - return 1; + return 1; } } else { - return 0; + return 0; } } else { return SRSLTE_ERROR_INVALID_INPUTS; @@ -871,22 +861,24 @@ static uint32_t srsbwtable_idx(uint32_t nof_prb) } else if (nof_prb <= 60) { return 1; } else if (nof_prb <= 80) { - return 2; + return 2; } else { - return 3; + return 3; } } - + /* Returns start of common SRS BW region */ -uint32_t srslte_refsignal_srs_rb_start_cs(uint32_t bw_cfg, uint32_t nof_prb) { +uint32_t srslte_refsignal_srs_rb_start_cs(uint32_t bw_cfg, uint32_t nof_prb) +{ if (bw_cfg < 8) { - return nof_prb/2-m_srs_b[srsbwtable_idx(nof_prb)][0][bw_cfg]/2; + return nof_prb / 2 - m_srs_b[srsbwtable_idx(nof_prb)][0][bw_cfg] / 2; } - return 0; + return 0; } /* Returns number of RB defined for the cell-specific SRS */ -uint32_t srslte_refsignal_srs_rb_L_cs(uint32_t bw_cfg, uint32_t nof_prb) { +uint32_t srslte_refsignal_srs_rb_L_cs(uint32_t bw_cfg, uint32_t nof_prb) +{ if (bw_cfg < 8) { return m_srs_b[srsbwtable_idx(nof_prb)][0][bw_cfg]; } @@ -896,20 +888,20 @@ uint32_t srslte_refsignal_srs_rb_L_cs(uint32_t bw_cfg, uint32_t nof_prb) { static uint32_t srs_Fb(srslte_refsignal_srs_cfg_t* cfg, uint32_t b, uint32_t nof_prb, uint32_t tti) { uint32_t Fb = 0; - uint32_t T = T_srs_table(cfg->I_srs); + uint32_t T = T_srs_table(cfg->I_srs); if (T) { - uint32_t n_srs = tti/T; - uint32_t N_b = Nb[srsbwtable_idx(nof_prb)][b][cfg->bw_cfg]; - - uint32_t prod_1=1; - for (uint32_t bp=cfg->b_hop+1;bpbw_cfg]; + + uint32_t prod_1 = 1; + for (uint32_t bp = cfg->b_hop + 1; bp < b; bp++) { prod_1 *= Nb[srsbwtable_idx(nof_prb)][bp][cfg->bw_cfg]; } - uint32_t prod_2 = prod_1*Nb[srsbwtable_idx(nof_prb)][b][cfg->bw_cfg]; - if ((N_b%2) == 0) { - Fb = (N_b/2)*((n_srs%prod_2)/prod_1)+((n_srs%prod_2)/prod_1/2); + uint32_t prod_2 = prod_1 * Nb[srsbwtable_idx(nof_prb)][b][cfg->bw_cfg]; + if ((N_b % 2) == 0) { + Fb = (N_b / 2) * ((n_srs % prod_2) / prod_1) + ((n_srs % prod_2) / prod_1 / 2); } else { - Fb = (N_b/2)*(n_srs/prod_1); + Fb = (N_b / 2) * (n_srs / prod_1); } } return Fb; @@ -922,22 +914,21 @@ static uint32_t srs_k0_ue(srslte_refsignal_srs_cfg_t* cfg, uint32_t nof_prb, uin if (cfg->bw_cfg < 8 && cfg->B < 4 && cfg->k_tc < 2) { uint32_t k0p = srslte_refsignal_srs_rb_start_cs(cfg->bw_cfg, nof_prb) * SRSLTE_NRE + cfg->k_tc; uint32_t k0 = k0p; - uint32_t nb = 0; - for (int b=0;b<=cfg->B;b++) { + uint32_t nb = 0; + for (int b = 0; b <= cfg->B; b++) { uint32_t m_srs = m_srs_b[srsbwtable_idx(nof_prb)][b][cfg->bw_cfg]; - uint32_t m_sc = m_srs*SRSLTE_NRE/2; + uint32_t m_sc = m_srs * SRSLTE_NRE / 2; if (b <= cfg->b_hop) { - nb = (4*cfg->n_rrc/m_srs)%Nb[srsbwtable_idx(nof_prb)][b][cfg->bw_cfg]; + nb = (4 * cfg->n_rrc / m_srs) % Nb[srsbwtable_idx(nof_prb)][b][cfg->bw_cfg]; } else { - uint32_t Fb=srs_Fb(cfg, b, nof_prb, tti); - nb = ((4*cfg->n_rrc/m_srs)+Fb)%Nb[srsbwtable_idx(nof_prb)][b][cfg->bw_cfg]; + uint32_t Fb = srs_Fb(cfg, b, nof_prb, tti); + nb = ((4 * cfg->n_rrc / m_srs) + Fb) % Nb[srsbwtable_idx(nof_prb)][b][cfg->bw_cfg]; } - k0 += 2*m_sc*nb; - + k0 += 2 * m_sc * nb; } return k0; } - return 0; + return 0; } uint32_t srslte_refsignal_srs_M_sc(srslte_refsignal_ul_t* q, srslte_refsignal_srs_cfg_t* cfg) @@ -952,7 +943,7 @@ int srslte_refsignal_srs_pregen(srslte_refsignal_ul_t* q, { uint32_t M_sc = srslte_refsignal_srs_M_sc(q, cfg); for (uint32_t sf_idx = 0; sf_idx < SRSLTE_NOF_SF_X_FRAME; sf_idx++) { - pregen->r[sf_idx] = srslte_vec_malloc(2*M_sc*sizeof(cf_t)); + pregen->r[sf_idx] = srslte_vec_malloc(2 * M_sc * sizeof(cf_t)); if (pregen->r[sf_idx]) { if (srslte_refsignal_srs_gen(q, cfg, dmrs, sf_idx, pregen->r[sf_idx])) { return SRSLTE_ERROR; @@ -964,7 +955,7 @@ int srslte_refsignal_srs_pregen(srslte_refsignal_ul_t* q, return SRSLTE_SUCCESS; } -void srslte_refsignal_srs_pregen_free(srslte_refsignal_ul_t *q, srslte_refsignal_srs_pregen_t *pregen) +void srslte_refsignal_srs_pregen_free(srslte_refsignal_ul_t* q, srslte_refsignal_srs_pregen_t* pregen) { for (uint32_t sf_idx = 0; sf_idx < SRSLTE_NOF_SF_X_FRAME; sf_idx++) { if (pregen->r[sf_idx]) { @@ -982,7 +973,6 @@ int srslte_refsignal_srs_pregen_put(srslte_refsignal_ul_t* q, return srslte_refsignal_srs_put(q, cfg, tti, pregen->r[tti % SRSLTE_NOF_SF_X_FRAME], sf_symbols); } - /* Genearte SRS signal as defined in Section 5.5.3.1 */ int srslte_refsignal_srs_gen(srslte_refsignal_ul_t* q, srslte_refsignal_srs_cfg_t* cfg, @@ -995,33 +985,35 @@ int srslte_refsignal_srs_gen(srslte_refsignal_ul_t* q, ret = SRSLTE_ERROR; uint32_t M_sc = srslte_refsignal_srs_M_sc(q, cfg); - for (uint32_t ns=2*sf_idx;ns<2*(sf_idx+1);ns++) { + for (uint32_t ns = 2 * sf_idx; ns < 2 * (sf_idx + 1); ns++) { compute_r(q, pusch_cfg, M_sc / SRSLTE_NRE, ns, 0); float alpha = 2 * M_PI * cfg->n_srs / 8; // Do complex exponential and adjust amplitude - for (int i=0;itmp_arg[i] + alpha*i)); - } + for (int i = 0; i < M_sc; i++) { + r_srs[(ns % 2) * M_sc + i] = cexpf(I * (q->tmp_arg[i] + alpha * i)); + } } - ret = SRSLTE_SUCCESS; + ret = SRSLTE_SUCCESS; } - return ret; + return ret; } -int srslte_refsignal_srs_put( - srslte_refsignal_ul_t* q, srslte_refsignal_srs_cfg_t* cfg, uint32_t tti, cf_t* r_srs, cf_t* sf_symbols) +int srslte_refsignal_srs_put(srslte_refsignal_ul_t* q, + srslte_refsignal_srs_cfg_t* cfg, + uint32_t tti, + cf_t* r_srs, + cf_t* sf_symbols) { int ret = SRSLTE_ERROR_INVALID_INPUTS; if (r_srs && q) { uint32_t M_sc = srslte_refsignal_srs_M_sc(q, cfg); uint32_t k0 = srs_k0_ue(cfg, q->cell.nof_prb, tti); - for (int i=0;icell.nof_prb, 2*SRSLTE_CP_NSYMB(q->cell.cp)-1, k0 + 2*i)] = r_srs[i]; + for (int i = 0; i < M_sc; i++) { + sf_symbols[SRSLTE_RE_IDX(q->cell.nof_prb, 2 * SRSLTE_CP_NSYMB(q->cell.cp) - 1, k0 + 2 * i)] = r_srs[i]; } - ret = SRSLTE_SUCCESS; + ret = SRSLTE_SUCCESS; } - return ret; + return ret; } - diff --git a/lib/src/phy/ch_estimation/test/chest_nbiot_test_dl.c b/lib/src/phy/ch_estimation/test/chest_nbiot_test_dl.c index 84bfe8025..8797922fc 100644 --- a/lib/src/phy/ch_estimation/test/chest_nbiot_test_dl.c +++ b/lib/src/phy/ch_estimation/test/chest_nbiot_test_dl.c @@ -105,7 +105,7 @@ void parse_args(int argc, char** argv) int main(int argc, char** argv) { srslte_chest_dl_nbiot_t est = {}; - int ret = SRSLTE_ERROR; + int ret = SRSLTE_ERROR; cf_t * input = NULL, *ce = NULL, *h = NULL, *output = NULL, *sf_buffer = NULL; parse_args(argc, argv); diff --git a/lib/src/phy/ch_estimation/test/chest_test_dl.c b/lib/src/phy/ch_estimation/test/chest_test_dl.c index 8c37e9b86..95d7e67f0 100644 --- a/lib/src/phy/ch_estimation/test/chest_test_dl.c +++ b/lib/src/phy/ch_estimation/test/chest_test_dl.c @@ -19,11 +19,11 @@ * */ +#include #include #include #include #include -#include #include "srslte/srslte.h" @@ -35,9 +35,10 @@ srslte_cell_t cell = {6, // nof_prb SRSLTE_PHICH_R_1_6, SRSLTE_FDD}; -char *output_matlab = NULL; +char* output_matlab = NULL; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [recov]\n", prog); printf("\t-r nof_prb [Default %d]\n", cell.nof_prb); @@ -45,38 +46,39 @@ void usage(char *prog) { printf("\t-c cell_id (1000 tests all). [Default %d]\n", cell.id); - printf("\t-o output matlab file [Default %s]\n",output_matlab?output_matlab:"None"); + printf("\t-o output matlab file [Default %s]\n", output_matlab ? output_matlab : "None"); printf("\t-v increase verbosity\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "recov")) != -1) { - switch(opt) { - case 'r': - cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'e': - cell.cp = SRSLTE_CP_EXT; - break; - case 'c': - cell.id = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'o': - output_matlab = argv[optind]; - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + switch (opt) { + case 'r': + cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'e': + cell.cp = SRSLTE_CP_EXT; + break; + case 'c': + cell.id = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'o': + output_matlab = argv[optind]; + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } } - -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ srslte_chest_dl_t est; cf_t * input = NULL, *ce = NULL, *h = NULL, *output = NULL; int i, j, num_re; @@ -85,10 +87,10 @@ int main(int argc, char **argv) { FILE* fmatlab = NULL; uint32_t cid = 0; - parse_args(argc,argv); + parse_args(argc, argv); if (output_matlab) { - fmatlab=fopen(output_matlab, "w"); + fmatlab = fopen(output_matlab, "w"); if (!fmatlab) { perror("fopen"); goto do_exit; @@ -122,15 +124,15 @@ int main(int argc, char **argv) { cid = 0; max_cid = 504; } else { - cid = cell.id; + cid = cell.id; max_cid = cell.id; } if (srslte_chest_dl_init(&est, cell.nof_prb, 1)) { ERROR("Error initializing equalizer\n"); goto do_exit; } - while(cid <= max_cid) { - cell.id = cid; + while (cid <= max_cid) { + cell.id = cid; if (srslte_chest_dl_set_cell(&est, cell)) { ERROR("Error initializing equalizer\n"); goto do_exit; diff --git a/lib/src/phy/ch_estimation/test/chest_test_ul.c b/lib/src/phy/ch_estimation/test/chest_test_ul.c index c57294f77..cf524d569 100644 --- a/lib/src/phy/ch_estimation/test/chest_test_ul.c +++ b/lib/src/phy/ch_estimation/test/chest_test_ul.c @@ -19,11 +19,11 @@ * */ +#include #include #include #include #include -#include #include "srslte/srslte.h" @@ -38,9 +38,10 @@ srslte_cell_t cell = { }; -char *output_matlab = NULL; +char* output_matlab = NULL; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [recov]\n", prog); printf("\t-r nof_prb [Default %d]\n", cell.nof_prb); @@ -48,49 +49,50 @@ void usage(char *prog) { printf("\t-c cell_id (1000 tests all). [Default %d]\n", cell.id); - printf("\t-o output matlab file [Default %s]\n",output_matlab?output_matlab:"None"); + printf("\t-o output matlab file [Default %s]\n", output_matlab ? output_matlab : "None"); printf("\t-v increase verbosity\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "recov")) != -1) { - switch(opt) { - case 'r': - cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'e': - cell.cp = SRSLTE_CP_EXT; - break; - case 'c': - cell.id = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'o': - output_matlab = argv[optind]; - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + switch (opt) { + case 'r': + cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'e': + cell.cp = SRSLTE_CP_EXT; + break; + case 'c': + cell.id = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'o': + output_matlab = argv[optind]; + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } } - -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ srslte_chest_ul_t est; - cf_t *input = NULL, *ce = NULL, *h = NULL; - int i, j, n_port=0, sf_idx=0, cid=0, num_re; - int ret = -1; - int max_cid; - FILE *fmatlab = NULL; - - parse_args(argc,argv); + cf_t * input = NULL, *ce = NULL, *h = NULL; + int i, j, n_port = 0, sf_idx = 0, cid = 0, num_re; + int ret = -1; + int max_cid; + FILE* fmatlab = NULL; + + parse_args(argc, argv); if (output_matlab) { - fmatlab=fopen(output_matlab, "w"); + fmatlab = fopen(output_matlab, "w"); if (!fmatlab) { perror("fopen"); goto do_exit; @@ -114,13 +116,13 @@ int main(int argc, char **argv) { perror("srslte_vec_malloc"); goto do_exit; } - bzero(ce, num_re*sizeof(cf_t)); + bzero(ce, num_re * sizeof(cf_t)); if (cell.id == 1000) { - cid = 0; + cid = 0; max_cid = 504; } else { - cid = cell.id; + cid = cell.id; max_cid = cell.id; } printf("max_cid=%d, cid=%d, cell.id=%d\n", max_cid, cid, cell.id); @@ -128,68 +130,68 @@ int main(int argc, char **argv) { ERROR("Error initializing equalizer\n"); goto do_exit; } - while(cid <= max_cid) { - cell.id = cid; + while (cid <= max_cid) { + cell.id = cid; if (srslte_chest_ul_set_cell(&est, cell)) { ERROR("Error initializing equalizer\n"); goto do_exit; } - for (int n=6;n<=cell.nof_prb;n+=5) { + for (int n = 6; n <= cell.nof_prb; n += 5) { if (srslte_dft_precoding_valid_prb(n)) { - for (int delta_ss=29;delta_ss // Phi values for M_sc=12 Table 5.5.1.2-1 in 36.211 -int phi_M_sc_12[30][12] = {{-1, 1, 3,-3, 3, 3, 1, 1, 3, 1,-3, 3}, - { 1, 1, 3, 3, 3,-1, 1,-3,-3, 1,-3, 3}, - { 1, 1,-3,-3,-3,-1,-3,-3, 1,-3, 1,-1}, - {-1, 1, 1, 1, 1,-1,-3,-3, 1,-3, 3,-1}, - {-1, 3, 1,-1, 1,-1,-3,-1, 1,-1, 1, 3}, - { 1,-3, 3,-1,-1, 1, 1,-1,-1, 3,-3, 1}, - {-1, 3,-3,-3,-3, 3, 1,-1, 3, 3,-3, 1}, - {-3,-1,-1,-1, 1,-3, 3,-1, 1,-3, 3, 1}, - { 1,-3, 3, 1,-1,-1,-1, 1, 1, 3,-1, 1}, - { 1,-3,-1, 3, 3,-1,-3, 1, 1, 1, 1, 1}, - {-1, 3,-1, 1, 1,-3,-3,-1,-3,-3, 3,-1}, - { 3, 1,-1,-1, 3, 3,-3, 1, 3, 1, 3, 3}, - { 1,-3, 1, 1,-3, 1, 1, 1,-3,-3,-3, 1}, - { 3, 3,-3, 3,-3, 1, 1, 3,-1,-3, 3, 3}, - {-3, 1,-1,-3,-1, 3, 1, 3, 3, 3,-1, 1}, - { 3,-1, 1,-3,-1,-1, 1, 1, 3, 1,-1,-3}, - { 1, 3, 1,-1, 1, 3, 3, 3,-1,-1, 3,-1}, - {-3, 1, 1, 3,-3, 3,-3,-3, 3, 1, 3,-1}, - {-3, 3, 1, 1,-3, 1,-3,-3,-1,-1, 1,-3}, - {-1, 3, 1, 3, 1,-1,-1, 3,-3,-1,-3,-1}, - {-1,-3, 1, 1, 1, 1, 3, 1,-1, 1,-3,-1}, - {-1, 3,-1, 1,-3,-3,-3,-3,-3, 1,-1,-3}, - { 1, 1,-3,-3,-3,-3,-1, 3,-3, 1,-3, 3}, - { 1, 1,-1,-3,-1,-3, 1,-1, 1, 3,-1, 1}, - { 1, 1, 3, 1, 3, 3,-1, 1,-1,-3,-3, 1}, - { 1,-3, 3, 3, 1, 3, 3, 1,-3,-1,-1, 3}, - { 1, 3,-3,-3, 3,-3, 1,-1,-1, 3,-1,-3}, - {-3,-1,-3,-1,-3, 3, 1,-1, 1, 3,-3,-3}, - {-1, 3,-3, 3,-1, 3, 3,-3, 3, 3,-1,-1}, - { 3,-3,-3,-1,-1,-3,-1, 3,-3, 3, 1,-1}}; +int phi_M_sc_12[30][12] = {{-1, 1, 3, -3, 3, 3, 1, 1, 3, 1, -3, 3}, {1, 1, 3, 3, 3, -1, 1, -3, -3, 1, -3, 3}, + {1, 1, -3, -3, -3, -1, -3, -3, 1, -3, 1, -1}, {-1, 1, 1, 1, 1, -1, -3, -3, 1, -3, 3, -1}, + {-1, 3, 1, -1, 1, -1, -3, -1, 1, -1, 1, 3}, {1, -3, 3, -1, -1, 1, 1, -1, -1, 3, -3, 1}, + {-1, 3, -3, -3, -3, 3, 1, -1, 3, 3, -3, 1}, {-3, -1, -1, -1, 1, -3, 3, -1, 1, -3, 3, 1}, + {1, -3, 3, 1, -1, -1, -1, 1, 1, 3, -1, 1}, {1, -3, -1, 3, 3, -1, -3, 1, 1, 1, 1, 1}, + {-1, 3, -1, 1, 1, -3, -3, -1, -3, -3, 3, -1}, {3, 1, -1, -1, 3, 3, -3, 1, 3, 1, 3, 3}, + {1, -3, 1, 1, -3, 1, 1, 1, -3, -3, -3, 1}, {3, 3, -3, 3, -3, 1, 1, 3, -1, -3, 3, 3}, + {-3, 1, -1, -3, -1, 3, 1, 3, 3, 3, -1, 1}, {3, -1, 1, -3, -1, -1, 1, 1, 3, 1, -1, -3}, + {1, 3, 1, -1, 1, 3, 3, 3, -1, -1, 3, -1}, {-3, 1, 1, 3, -3, 3, -3, -3, 3, 1, 3, -1}, + {-3, 3, 1, 1, -3, 1, -3, -3, -1, -1, 1, -3}, {-1, 3, 1, 3, 1, -1, -1, 3, -3, -1, -3, -1}, + {-1, -3, 1, 1, 1, 1, 3, 1, -1, 1, -3, -1}, {-1, 3, -1, 1, -3, -3, -3, -3, -3, 1, -1, -3}, + {1, 1, -3, -3, -3, -3, -1, 3, -3, 1, -3, 3}, {1, 1, -1, -3, -1, -3, 1, -1, 1, 3, -1, 1}, + {1, 1, 3, 1, 3, 3, -1, 1, -1, -3, -3, 1}, {1, -3, 3, 3, 1, 3, 3, 1, -3, -1, -1, 3}, + {1, 3, -3, -3, 3, -3, 1, -1, -1, 3, -1, -3}, {-3, -1, -3, -1, -3, 3, 1, -1, 1, 3, -3, -3}, + {-1, 3, -3, 3, -1, 3, 3, -3, 3, 3, -1, -1}, {3, -3, -3, -1, -1, -3, -1, 3, -3, 3, 1, -1}}; // Phi values for M_sc=24 Table 5.5.1.2-2 in 36.211 -int phi_M_sc_24[30][24] = {{-1, 3, 1,-3, 3,-1, 1, 3,-3, 3, 1, 3,-3, 3, 1, 1,-1, 1, 3,-3, 3,-3,-1,-3}, - {-3, 3,-3,-3,-3, 1,-3,-3, 3,-1, 1, 1, 1, 3, 1,-1, 3,-3,-3, 1, 3, 1, 1,-3}, - { 3,-1, 3, 3, 1, 1,-3, 3, 3, 3, 3, 1,-1, 3,-1, 1, 1,-1,-3,-1,-1, 1, 3, 3}, - {-1,-3, 1, 1, 3,-3, 1, 1,-3,-1,-1, 1, 3, 1, 3, 1,-1, 3, 1, 1,-3,-1,-3,-1}, - {-1,-1,-1,-3,-3,-1, 1, 1, 3, 3,-1, 3,-1, 1,-1,-3, 1,-1,-3,-3, 1,-3,-1,-1}, - {-3, 1, 1, 3,-1, 1, 3, 1,-3, 1,-3, 1, 1,-1,-1, 3,-1,-3, 3,-3,-3,-3, 1, 1}, - { 1, 1,-1,-1, 3,-3,-3, 3,-3, 1,-1,-1, 1,-1, 1, 1,-1,-3,-1, 1,-1, 3,-1,-3}, - {-3, 3, 3,-1,-1,-3,-1, 3, 1, 3, 1, 3, 1, 1,-1, 3, 1,-1, 1, 3,-3,-1,-1, 1}, - {-3, 1, 3,-3, 1,-1,-3, 3,-3, 3,-1,-1,-1,-1, 1,-3,-3,-3, 1,-3,-3,-3, 1,-3}, - { 1, 1,-3, 3, 3,-1,-3,-1, 3,-3, 3, 3, 3,-1, 1, 1,-3, 1,-1, 1, 1,-3, 1, 1}, - {-1, 1,-3,-3, 3,-1, 3,-1,-1,-3,-3,-3,-1,-3,-3, 1,-1, 1, 3, 3,-1, 1,-1, 3}, - { 1, 3, 3,-3,-3, 1, 3, 1,-1,-3,-3,-3, 3, 3,-3, 3, 3,-1,-3, 3,-1, 1,-3, 1}, - { 1, 3, 3, 1, 1, 1,-1,-1, 1,-3, 3,-1, 1, 1,-3, 3, 3,-1,-3, 3,-3,-1,-3,-1}, - { 3,-1,-1,-1,-1,-3,-1, 3, 3, 1,-1, 1, 3, 3, 3,-1, 1, 1,-3, 1, 3,-1,-3, 3}, - {-3,-3, 3, 1, 3, 1,-3, 3, 1, 3, 1, 1, 3, 3,-1,-1,-3, 1,-3,-1, 3, 1, 1, 3}, - {-1,-1, 1,-3, 1, 3,-3, 1,-1,-3,-1, 3, 1, 3, 1,-1,-3,-3,-1,-1,-3,-3,-3,-1}, - {-1,-3, 3,-1,-1,-1,-1, 1, 1,-3, 3, 1, 3, 3, 1,-1, 1,-3, 1,-3, 1, 1,-3,-1}, - { 1, 3,-1, 3, 3,-1,-3, 1,-1,-3, 3, 3, 3,-1, 1, 1, 3,-1,-3,-1, 3,-1,-1,-1}, - { 1, 1, 1, 1, 1,-1, 3,-1,-3, 1, 1, 3,-3, 1,-3,-1, 1, 1,-3,-3, 3, 1, 1,-3}, - { 1, 3, 3, 1,-1,-3, 3,-1, 3, 3, 3,-3, 1,-1, 1,-1,-3,-1, 1, 3,-1, 3,-3,-3}, - {-1,-3, 3,-3,-3,-3,-1,-1,-3,-1,-3, 3, 1, 3,-3,-1, 3,-1, 1,-1, 3,-3, 1,-1}, - {-3,-3, 1, 1,-1, 1,-1, 1,-1, 3, 1,-3,-1, 1,-1, 1,-1,-1, 3, 3,-3,-1, 1,-3}, - {-3,-1,-3, 3, 1,-1,-3,-1,-3,-3, 3,-3, 3,-3,-1, 1, 3, 1,-3, 1, 3, 3,-1,-3}, - {-1,-1,-1,-1, 3, 3, 3, 1, 3, 3,-3, 1, 3,-1, 3,-1, 3, 3,-3, 3, 1,-1, 3, 3}, - { 1,-1, 3, 3,-1,-3, 3,-3,-1,-1, 3,-1, 3,-1,-1, 1, 1, 1, 1,-1,-1,-3,-1, 3}, - { 1,-1, 1,-1, 3,-1, 3, 1, 1,-1,-1,-3, 1, 1,-3, 1, 3,-3, 1, 1,-3,-3,-1,-1}, - {-3,-1, 1, 3, 1, 1,-3,-1,-1,-3, 3,-3, 3, 1,-3, 3,-3, 1,-1, 1,-3, 1, 1, 1}, - {-1,-3, 3, 3, 1, 1, 3,-1,-3,-1,-1,-1, 3, 1,-3,-3,-1, 3,-3,-1,-3,-1,-3,-1}, - {-1,-3,-1,-1, 1,-3,-1,-1, 1,-1,-3, 1, 1,-3, 1,-3,-3, 3, 1, 1,-1, 3,-1,-1}, - { 1, 1,-1,-1,-3,-1, 3,-1, 3,-1, 1, 3, 1,-1, 3, 1, 3,-3,-3, 1,-1,-1, 1, 3}}; +int phi_M_sc_24[30][24] = {{-1, 3, 1, -3, 3, -1, 1, 3, -3, 3, 1, 3, -3, 3, 1, 1, -1, 1, 3, -3, 3, -3, -1, -3}, + {-3, 3, -3, -3, -3, 1, -3, -3, 3, -1, 1, 1, 1, 3, 1, -1, 3, -3, -3, 1, 3, 1, 1, -3}, + {3, -1, 3, 3, 1, 1, -3, 3, 3, 3, 3, 1, -1, 3, -1, 1, 1, -1, -3, -1, -1, 1, 3, 3}, + {-1, -3, 1, 1, 3, -3, 1, 1, -3, -1, -1, 1, 3, 1, 3, 1, -1, 3, 1, 1, -3, -1, -3, -1}, + {-1, -1, -1, -3, -3, -1, 1, 1, 3, 3, -1, 3, -1, 1, -1, -3, 1, -1, -3, -3, 1, -3, -1, -1}, + {-3, 1, 1, 3, -1, 1, 3, 1, -3, 1, -3, 1, 1, -1, -1, 3, -1, -3, 3, -3, -3, -3, 1, 1}, + {1, 1, -1, -1, 3, -3, -3, 3, -3, 1, -1, -1, 1, -1, 1, 1, -1, -3, -1, 1, -1, 3, -1, -3}, + {-3, 3, 3, -1, -1, -3, -1, 3, 1, 3, 1, 3, 1, 1, -1, 3, 1, -1, 1, 3, -3, -1, -1, 1}, + {-3, 1, 3, -3, 1, -1, -3, 3, -3, 3, -1, -1, -1, -1, 1, -3, -3, -3, 1, -3, -3, -3, 1, -3}, + {1, 1, -3, 3, 3, -1, -3, -1, 3, -3, 3, 3, 3, -1, 1, 1, -3, 1, -1, 1, 1, -3, 1, 1}, + {-1, 1, -3, -3, 3, -1, 3, -1, -1, -3, -3, -3, -1, -3, -3, 1, -1, 1, 3, 3, -1, 1, -1, 3}, + {1, 3, 3, -3, -3, 1, 3, 1, -1, -3, -3, -3, 3, 3, -3, 3, 3, -1, -3, 3, -1, 1, -3, 1}, + {1, 3, 3, 1, 1, 1, -1, -1, 1, -3, 3, -1, 1, 1, -3, 3, 3, -1, -3, 3, -3, -1, -3, -1}, + {3, -1, -1, -1, -1, -3, -1, 3, 3, 1, -1, 1, 3, 3, 3, -1, 1, 1, -3, 1, 3, -1, -3, 3}, + {-3, -3, 3, 1, 3, 1, -3, 3, 1, 3, 1, 1, 3, 3, -1, -1, -3, 1, -3, -1, 3, 1, 1, 3}, + {-1, -1, 1, -3, 1, 3, -3, 1, -1, -3, -1, 3, 1, 3, 1, -1, -3, -3, -1, -1, -3, -3, -3, -1}, + {-1, -3, 3, -1, -1, -1, -1, 1, 1, -3, 3, 1, 3, 3, 1, -1, 1, -3, 1, -3, 1, 1, -3, -1}, + {1, 3, -1, 3, 3, -1, -3, 1, -1, -3, 3, 3, 3, -1, 1, 1, 3, -1, -3, -1, 3, -1, -1, -1}, + {1, 1, 1, 1, 1, -1, 3, -1, -3, 1, 1, 3, -3, 1, -3, -1, 1, 1, -3, -3, 3, 1, 1, -3}, + {1, 3, 3, 1, -1, -3, 3, -1, 3, 3, 3, -3, 1, -1, 1, -1, -3, -1, 1, 3, -1, 3, -3, -3}, + {-1, -3, 3, -3, -3, -3, -1, -1, -3, -1, -3, 3, 1, 3, -3, -1, 3, -1, 1, -1, 3, -3, 1, -1}, + {-3, -3, 1, 1, -1, 1, -1, 1, -1, 3, 1, -3, -1, 1, -1, 1, -1, -1, 3, 3, -3, -1, 1, -3}, + {-3, -1, -3, 3, 1, -1, -3, -1, -3, -3, 3, -3, 3, -3, -1, 1, 3, 1, -3, 1, 3, 3, -1, -3}, + {-1, -1, -1, -1, 3, 3, 3, 1, 3, 3, -3, 1, 3, -1, 3, -1, 3, 3, -3, 3, 1, -1, 3, 3}, + {1, -1, 3, 3, -1, -3, 3, -3, -1, -1, 3, -1, 3, -1, -1, 1, 1, 1, 1, -1, -1, -3, -1, 3}, + {1, -1, 1, -1, 3, -1, 3, 1, 1, -1, -1, -3, 1, 1, -3, 1, 3, -3, 1, 1, -3, -3, -1, -1}, + {-3, -1, 1, 3, 1, 1, -3, -1, -1, -3, 3, -3, 3, 1, -3, 3, -3, 1, -1, 1, -3, 1, 1, 1}, + {-1, -3, 3, 3, 1, 1, 3, -1, -3, -1, -1, -1, 3, 1, -3, -3, -1, 3, -3, -1, -3, -1, -3, -1}, + {-1, -3, -1, -1, 1, -3, -1, -1, 1, -1, -3, 1, 1, -3, 1, -3, -3, 3, 1, 1, -1, 3, -1, -1}, + {1, 1, -1, -1, -3, -1, 3, -1, 3, -1, 1, 3, 1, -1, 3, 1, 3, -3, -3, 1, -1, -1, 1, 3}}; // Prime numbers used for Section 5.5.1.1 of 36.211 #define NOF_PRIME_NUMBERS 196 -uint32_t prime_numbers[NOF_PRIME_NUMBERS] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, - 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, - 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, - 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, - 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, - 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, - 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, - 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, - 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, - 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, - 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, - 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, - 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, - 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, - 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, - 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, - 947, 953, 967, 971, 977, 983, 991, 997,1009,1013, - 1019,1021,1031,1033,1039,1049,1051,1061,1063,1069, - 1087,1091,1093,1097,1103,1109,1117,1123,1129,1151, - 1153,1163,1171,1181,1187,1193}; - +uint32_t prime_numbers[NOF_PRIME_NUMBERS] = { + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, + 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, + 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, + 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, + 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, + 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, + 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, + 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, + 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, + 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, + 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193}; diff --git a/lib/src/phy/channel/ch_awgn.c b/lib/src/phy/channel/ch_awgn.c index 4e60929bb..177edda6d 100644 --- a/lib/src/phy/channel/ch_awgn.c +++ b/lib/src/phy/channel/ch_awgn.c @@ -27,26 +27,29 @@ #include #include -float srslte_ch_awgn_get_variance(float ebno_db, float rate) { +float srslte_ch_awgn_get_variance(float ebno_db, float rate) +{ float esno_db = ebno_db + srslte_convert_power_to_dB(rate); return srslte_convert_dB_to_amplitude(-esno_db); } -void srslte_ch_awgn_c(const cf_t* x, cf_t* y, float variance, uint32_t len) { - cf_t tmp; +void srslte_ch_awgn_c(const cf_t* x, cf_t* y, float variance, uint32_t len) +{ + cf_t tmp; uint32_t i; - for (i=0;israte_hz; - double arg = 2.0 * M_PI * t / (double)q->period_s; - double delay_us = q->delay_min_us + (q->delay_max_us - q->delay_min_us) * (1.0 + sin(arg)) / 2.0; + double arg = 2.0 * M_PI * t / (double)q->period_s; + double delay_us = q->delay_min_us + (q->delay_max_us - q->delay_min_us) * (1.0 + sin(arg)) / 2.0; return delay_us; } else { @@ -100,8 +100,11 @@ void srslte_channel_delay_free(srslte_channel_delay_t* q) } } -void srslte_channel_delay_execute( - srslte_channel_delay_t* q, const cf_t* in, cf_t* out, uint32_t len, const srslte_timestamp_t* ts) +void srslte_channel_delay_execute(srslte_channel_delay_t* q, + const cf_t* in, + cf_t* out, + uint32_t len, + const srslte_timestamp_t* ts) { q->delay_us = calculate_delay_us(q, ts); q->delay_nsamples = calculate_delay_nsamples(q); diff --git a/lib/src/phy/channel/fading.c b/lib/src/phy/channel/fading.c index 41c3a8b44..4fd336ff1 100644 --- a/lib/src/phy/channel/fading.c +++ b/lib/src/phy/channel/fading.c @@ -108,7 +108,12 @@ static inline void generate_taps(srslte_channel_fading_t* q, double time) float phase = get_doppler_dispersion(time, q->coeff_a[i], q->coeff_w[i], q->coeff_p[i]); // Generate tab - generate_tap(excess_tap_delay_ns[q->model][i], relative_power_db[q->model][i], q->srate, phase, q->temp, q->N, + generate_tap(excess_tap_delay_ns[q->model][i], + relative_power_db[q->model][i], + q->srate, + phase, + q->temp, + q->N, q->path_delay); // Add to frequency response @@ -246,8 +251,11 @@ void srslte_channel_fading_free(srslte_channel_fading_t* q) } } -double srslte_channel_fading_execute( - srslte_channel_fading_t* q, const cf_t* in, cf_t* out, uint32_t nsamples, double init_time) +double srslte_channel_fading_execute(srslte_channel_fading_t* q, + const cf_t* in, + cf_t* out, + uint32_t nsamples, + double init_time) { uint32_t counter = 0; diff --git a/lib/src/phy/channel/gauss.c b/lib/src/phy/channel/gauss.c index d8b30df56..830c437c2 100644 --- a/lib/src/phy/channel/gauss.c +++ b/lib/src/phy/channel/gauss.c @@ -19,19 +19,20 @@ * */ -#include -#include #include +#include +#include -float rand_gauss (void) { - float v1,v2,s; +float rand_gauss(void) +{ + float v1, v2, s; do { - v1 = 2.0 * ((float) rand()/RAND_MAX) - 1; - v2 = 2.0 * ((float) rand()/RAND_MAX) - 1; + v1 = 2.0 * ((float)rand() / RAND_MAX) - 1; + v2 = 2.0 * ((float)rand() / RAND_MAX) - 1; - s = v1*v1 + v2*v2; - } while ( s >= 1.0 || s == 0.0); + s = v1 * v1 + v2 * v2; + } while (s >= 1.0 || s == 0.0); return (v1 * sqrtf(-2.0 * log(s) / s)); } diff --git a/lib/src/phy/channel/gauss.h b/lib/src/phy/channel/gauss.h index 7e2c1747e..2acd1ed76 100644 --- a/lib/src/phy/channel/gauss.h +++ b/lib/src/phy/channel/gauss.h @@ -19,4 +19,4 @@ * */ -float rand_gauss (void); +float rand_gauss(void); diff --git a/lib/src/phy/channel/hst.c b/lib/src/phy/channel/hst.c index c383b916b..2700c4249 100644 --- a/lib/src/phy/channel/hst.c +++ b/lib/src/phy/channel/hst.c @@ -45,8 +45,11 @@ void srslte_channel_hst_update_srate(srslte_channel_hst_t* q, uint32_t srate) } } -void srslte_channel_hst_execute( - srslte_channel_hst_t* q, cf_t* in, cf_t* out, uint32_t len, const srslte_timestamp_t* ts) +void srslte_channel_hst_execute(srslte_channel_hst_t* q, + cf_t* in, + cf_t* out, + uint32_t len, + const srslte_timestamp_t* ts) { if (q && q->srate_hz) { // Convert period from seconds to samples diff --git a/lib/src/phy/channel/rlf.c b/lib/src/phy/channel/rlf.c index bc304f48e..c30e2938f 100644 --- a/lib/src/phy/channel/rlf.c +++ b/lib/src/phy/channel/rlf.c @@ -28,8 +28,11 @@ void srslte_channel_rlf_init(srslte_channel_rlf_t* q, uint32_t t_on_ms, uint32_t q->t_off_ms = t_off_ms; } -void srslte_channel_rlf_execute( - srslte_channel_rlf_t* q, const cf_t* in, cf_t* out, uint32_t nsamples, const srslte_timestamp_t* ts) +void srslte_channel_rlf_execute(srslte_channel_rlf_t* q, + const cf_t* in, + cf_t* out, + uint32_t nsamples, + const srslte_timestamp_t* ts) { uint32_t period_ms = q->t_on_ms + q->t_off_ms; double full_secs_ms = (ts->full_secs * 1000) % period_ms; diff --git a/lib/src/phy/channel/test/delay_channel_test.c b/lib/src/phy/channel/test/delay_channel_test.c index 14e2192ec..baf7d78f7 100644 --- a/lib/src/phy/channel/test/delay_channel_test.c +++ b/lib/src/phy/channel/test/delay_channel_test.c @@ -27,12 +27,12 @@ static srslte_channel_delay_t delay = {}; -static uint32_t delay_min_us = 10; -static uint32_t delay_max_us = 3333; +static uint32_t delay_min_us = 10; +static uint32_t delay_max_us = 3333; static float delay_period_s = 1; static float delay_init_time_s = 0; -static uint32_t srate_hz = 1920000; -static uint32_t sim_time_periods = 1; +static uint32_t srate_hz = 1920000; +static uint32_t sim_time_periods = 1; #define INPUT_TYPE 0 /* 0: Dirac Delta; Otherwise: Random*/ diff --git a/lib/src/phy/channel/test/fading_channel_test.c b/lib/src/phy/channel/test/fading_channel_test.c index dcda2c6d0..038a84863 100644 --- a/lib/src/phy/channel/test/fading_channel_test.c +++ b/lib/src/phy/channel/test/fading_channel_test.c @@ -181,7 +181,9 @@ int main(int argc, char** argv) goto clean_exit; } - printf("-- Starting Fading channel simulator. srate=%.2fMHz; model=%s; duration=%dms\n", (double)srate / 1e6, model, + printf("-- Starting Fading channel simulator. srate=%.2fMHz; model=%s; duration=%dms\n", + (double)srate / 1e6, + model, duration_ms); for (int i = 0; i < duration_ms; i++) { diff --git a/lib/src/phy/common/phy_common.c b/lib/src/phy/common/phy_common.c index 49f7175b6..085fff6e4 100644 --- a/lib/src/phy/common/phy_common.c +++ b/lib/src/phy/common/phy_common.c @@ -30,14 +30,15 @@ #ifdef FORCE_STANDARD_RATE static bool use_standard_rates = true; -#else -static bool use_standard_rates = false; +#else +static bool use_standard_rates = false; #endif /* Returns true if the structure pointed by cell has valid parameters */ -bool srslte_cellid_isvalid(uint32_t cell_id) { +bool srslte_cellid_isvalid(uint32_t cell_id) +{ if (cell_id < 504) { return true; } else { @@ -45,7 +46,8 @@ bool srslte_cellid_isvalid(uint32_t cell_id) { } } -bool srslte_nofprb_isvalid(uint32_t nof_prb) { +bool srslte_nofprb_isvalid(uint32_t nof_prb) +{ if (nof_prb == 1 || (nof_prb >= 6 && nof_prb <= SRSLTE_MAX_PRB)) { return true; } else { @@ -53,38 +55,37 @@ bool srslte_nofprb_isvalid(uint32_t nof_prb) { } } -bool srslte_cell_isvalid(srslte_cell_t *cell) { - return srslte_cellid_isvalid(cell->id) && - srslte_portid_isvalid(cell->nof_ports) && +bool srslte_cell_isvalid(srslte_cell_t* cell) +{ + return srslte_cellid_isvalid(cell->id) && srslte_portid_isvalid(cell->nof_ports) && srslte_nofprb_isvalid(cell->nof_prb); } -void srslte_cell_fprint(FILE *stream, srslte_cell_t *cell, uint32_t sfn) { +void srslte_cell_fprint(FILE* stream, srslte_cell_t* cell, uint32_t sfn) +{ fprintf(stream, " - Type: %s\n", cell->frame_type == SRSLTE_FDD ? "FDD" : "TDD"); fprintf(stream, " - PCI: %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 Length: %s\n", cell->phich_length == SRSLTE_PHICH_EXT ? "Extended" : "Normal"); fprintf(stream, " - PHICH Resources: "); switch (cell->phich_resources) { - case SRSLTE_PHICH_R_1_6: - fprintf(stream, "1/6"); - break; - case 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; + case SRSLTE_PHICH_R_1_6: + fprintf(stream, "1/6"); + break; + case 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); - } // Internal type for srslte_tdd_sf_t @@ -98,8 +99,16 @@ static srslte_tdd_sf_t tdd_sf[7][10] = {{D, S, U, U, U, D, S, U, U, U}, {D, S, U, D, D, D, D, D, D, D}, {D, S, U, U, U, D, S, U, U, D}}; -static uint32_t tdd_nof_sf_symbols[10][3] = { - {3, 10, 1}, {9, 4, 1}, {10, 3, 1}, {11, 2, 1}, {12, 1, 1}, {3, 9, 2}, {9, 3, 2}, {10, 2, 2}, {11, 1, 1}, {6, 6, 2}}; +static uint32_t tdd_nof_sf_symbols[10][3] = {{3, 10, 1}, + {9, 4, 1}, + {10, 3, 1}, + {11, 2, 1}, + {12, 1, 1}, + {3, 9, 2}, + {9, 3, 2}, + {10, 2, 2}, + {11, 1, 1}, + {6, 6, 2}}; srslte_tdd_sf_t srslte_sfidx_tdd_type(srslte_tdd_config_t tdd_config, uint32_t sf_idx) { @@ -180,7 +189,8 @@ bool srslte_portid_isvalid(uint32_t port_id) } } -bool srslte_N_id_2_isvalid(uint32_t N_id_2) { +bool srslte_N_id_2_isvalid(uint32_t N_id_2) +{ if (N_id_2 < 3) { return true; } else { @@ -188,7 +198,8 @@ bool srslte_N_id_2_isvalid(uint32_t N_id_2) { } } -bool srslte_N_id_1_isvalid(uint32_t N_id_1) { +bool srslte_N_id_1_isvalid(uint32_t N_id_1) +{ if (N_id_1 < 168) { return true; } else { @@ -196,11 +207,13 @@ bool srslte_N_id_1_isvalid(uint32_t N_id_1) { } } -srslte_mod_t srslte_str2mod (char * mod_str) { +srslte_mod_t srslte_str2mod(char* mod_str) +{ int i = 0; /* Upper case */ - while (mod_str[i] &= (~' '), mod_str[++i]); + while (mod_str[i] &= (~' '), mod_str[++i]) + ; if (!strcmp(mod_str, "QPSK")) { return SRSLTE_MOD_QPSK; @@ -211,46 +224,48 @@ srslte_mod_t srslte_str2mod (char * mod_str) { } else if (!strcmp(mod_str, "256QAM")) { return SRSLTE_MOD_256QAM; } else { - return (srslte_mod_t) SRSLTE_ERROR_INVALID_INPUTS; + return (srslte_mod_t)SRSLTE_ERROR_INVALID_INPUTS; } }; - -char *srslte_mod_string(srslte_mod_t mod) { +char* srslte_mod_string(srslte_mod_t mod) +{ switch (mod) { - case SRSLTE_MOD_BPSK: - return "BPSK"; - case SRSLTE_MOD_QPSK: - return "QPSK"; - case SRSLTE_MOD_16QAM: - return "16QAM"; - case SRSLTE_MOD_64QAM: - return "64QAM"; - case SRSLTE_MOD_256QAM: - return "256QAM"; - default: - return "N/A"; - } -} - -uint32_t srslte_mod_bits_x_symbol(srslte_mod_t mod) { + case SRSLTE_MOD_BPSK: + return "BPSK"; + case SRSLTE_MOD_QPSK: + return "QPSK"; + case SRSLTE_MOD_16QAM: + return "16QAM"; + case SRSLTE_MOD_64QAM: + return "64QAM"; + case SRSLTE_MOD_256QAM: + return "256QAM"; + default: + return "N/A"; + } +} + +uint32_t srslte_mod_bits_x_symbol(srslte_mod_t mod) +{ switch (mod) { - case SRSLTE_MOD_BPSK: - return 1; - case SRSLTE_MOD_QPSK: - return 2; - case SRSLTE_MOD_16QAM: - return 4; - case SRSLTE_MOD_64QAM: - return 6; - case SRSLTE_MOD_256QAM: - return 8; - default: - return 0; - } + case SRSLTE_MOD_BPSK: + return 1; + case SRSLTE_MOD_QPSK: + return 2; + case SRSLTE_MOD_16QAM: + return 4; + case SRSLTE_MOD_64QAM: + return 6; + case SRSLTE_MOD_256QAM: + return 8; + default: + return 0; + } } -char *srslte_cp_string(srslte_cp_t cp) { +char* srslte_cp_string(srslte_cp_t cp) +{ if (cp == SRSLTE_CP_NORM) { return "Normal "; } else { @@ -259,82 +274,88 @@ char *srslte_cp_string(srslte_cp_t cp) { } /* Returns the new time advance N_ta_new as specified in Section 4.2.3 of 36.213 */ -uint32_t srslte_N_ta_new(uint32_t N_ta_old, uint32_t ta) { - - ta &= 63; - int n_ta_new = N_ta_old + ((float) ta - 31) * 16; +uint32_t srslte_N_ta_new(uint32_t N_ta_old, uint32_t ta) +{ + + ta &= 63; + int n_ta_new = N_ta_old + ((float)ta - 31) * 16; if (n_ta_new < 0) { - return 0; + return 0; } else { if (n_ta_new < 20512) { - return (uint32_t) n_ta_new; + return (uint32_t)n_ta_new; } else { - return 20512; + return 20512; } } } float srslte_coderate(uint32_t tbs, uint32_t nof_re) { - return (float) (tbs + 24)/(nof_re); + return (float)(tbs + 24) / (nof_re); } -/* Returns the new time advance as indicated by the random access response +/* Returns the new time advance as indicated by the random access response * as specified in Section 4.2.3 of 36.213 */ -uint32_t srslte_N_ta_new_rar(uint32_t ta) { +uint32_t srslte_N_ta_new_rar(uint32_t ta) +{ if (ta > 1282) { - ta = 1282; + ta = 1282; } - return ta*16; + return ta * 16; } -void srslte_use_standard_symbol_size(bool enabled) { +void srslte_use_standard_symbol_size(bool enabled) +{ use_standard_rates = enabled; } -int srslte_sampling_freq_hz(uint32_t nof_prb) { - int n = srslte_symbol_sz(nof_prb); - if (n == -1) { - return SRSLTE_ERROR; - } else { - return 15000 * n; - } +int srslte_sampling_freq_hz(uint32_t nof_prb) +{ + int n = srslte_symbol_sz(nof_prb); + if (n == -1) { + return SRSLTE_ERROR; + } else { + return 15000 * n; + } } -int srslte_symbol_sz_power2(uint32_t nof_prb) { - if (nof_prb<=6) { +int srslte_symbol_sz_power2(uint32_t nof_prb) +{ + if (nof_prb <= 6) { return 128; - } else if (nof_prb<=15) { + } else if (nof_prb <= 15) { return 256; - } else if (nof_prb<=25) { + } else if (nof_prb <= 25) { return 512; - } else if (nof_prb<=50) { + } else if (nof_prb <= 50) { return 1024; - } else if (nof_prb<=75) { + } else if (nof_prb <= 75) { return 1536; - } else if (nof_prb<=110) { + } else if (nof_prb <= 110) { return 2048; } else { return -1; } } -int srslte_symbol_sz(uint32_t nof_prb) { - if (nof_prb<=0) { +int srslte_symbol_sz(uint32_t nof_prb) +{ + if (nof_prb <= 0) { return SRSLTE_ERROR; } if (!use_standard_rates) { - if (nof_prb<=6) { + if (nof_prb <= 6) { return 128; - } else if (nof_prb<=15) { + } else if (nof_prb <= 15) { return 256; - } else if (nof_prb<=25) { + } else if (nof_prb <= 25) { return 384; - } else if (nof_prb<=50) { + } else if (nof_prb <= 50) { return 768; - } else if (nof_prb<=75) { + } else if (nof_prb <= 75) { return 1024; - } else if (nof_prb<=110) { + } else if (nof_prb <= 110) { return 1536; } else { return SRSLTE_ERROR; @@ -347,7 +368,7 @@ int srslte_symbol_sz(uint32_t nof_prb) { int srslte_nof_prb(uint32_t symbol_sz) { if (!use_standard_rates) { - switch(symbol_sz) { + switch (symbol_sz) { case 128: return 6; case 256: @@ -362,7 +383,7 @@ int srslte_nof_prb(uint32_t symbol_sz) return 100; } } else { - switch(symbol_sz) { + switch (symbol_sz) { case 128: return 6; case 256: @@ -380,54 +401,48 @@ int srslte_nof_prb(uint32_t symbol_sz) return SRSLTE_ERROR; } -bool srslte_symbol_sz_isvalid(uint32_t symbol_sz) { +bool srslte_symbol_sz_isvalid(uint32_t symbol_sz) +{ if (!use_standard_rates) { - if (symbol_sz == 128 || - symbol_sz == 256 || - symbol_sz == 384 || - symbol_sz == 768 || - symbol_sz == 1024 || + if (symbol_sz == 128 || symbol_sz == 256 || symbol_sz == 384 || symbol_sz == 768 || symbol_sz == 1024 || symbol_sz == 1536) { return true; } else { - return false; + return false; } } else { - if (symbol_sz == 128 || - symbol_sz == 256 || - symbol_sz == 512 || - symbol_sz == 1024 || - symbol_sz == 1536 || + if (symbol_sz == 128 || symbol_sz == 256 || symbol_sz == 512 || symbol_sz == 1024 || symbol_sz == 1536 || symbol_sz == 2048) { return true; } else { - return false; + return false; } - } + } } -uint32_t srslte_voffset(uint32_t symbol_id, uint32_t cell_id, uint32_t nof_ports) { - if (nof_ports == 1 && symbol_id==0) { - return (cell_id+3) % 6; +uint32_t srslte_voffset(uint32_t symbol_id, uint32_t cell_id, uint32_t nof_ports) +{ + if (nof_ports == 1 && symbol_id == 0) { + return (cell_id + 3) % 6; } else { return cell_id % 6; } } - /** Computes sequence-group pattern f_gh according to 5.5.1.3 of 36.211 */ -int srslte_group_hopping_f_gh(uint32_t f_gh[SRSLTE_NSLOTS_X_FRAME], uint32_t cell_id) { - srslte_sequence_t seq; +int srslte_group_hopping_f_gh(uint32_t f_gh[SRSLTE_NSLOTS_X_FRAME], uint32_t cell_id) +{ + srslte_sequence_t seq; bzero(&seq, sizeof(srslte_sequence_t)); - + if (srslte_sequence_LTE_pr(&seq, 160, cell_id / 30)) { return SRSLTE_ERROR; } - - for (uint32_t ns=0;ns= band->ul_earfcn_offset) { - return band->fd_low_mhz - band->duplex_mhz + 0.1*(ul_earfcn - band->ul_earfcn_offset); + return band->fd_low_mhz - band->duplex_mhz + 0.1 * (ul_earfcn - band->ul_earfcn_offset); } else { return 0.0; } @@ -617,53 +634,58 @@ uint8_t srslte_band_get_band(uint32_t dl_earfcn) float srslte_band_fd(uint32_t dl_earfcn) { - uint32_t i = SRSLTE_NOF_LTE_BANDS-1; + uint32_t i = SRSLTE_NOF_LTE_BANDS - 1; if (dl_earfcn > lte_bands[i].dl_earfcn_offset) { ERROR("Invalid DL_EARFCN=%d\n", dl_earfcn); } i--; - while(i > 0 && lte_bands[i].dl_earfcn_offset>dl_earfcn) { + while (i > 0 && lte_bands[i].dl_earfcn_offset > dl_earfcn) { i--; } - return get_fd(<e_bands[i], dl_earfcn); + return get_fd(<e_bands[i], dl_earfcn); } - -float srslte_band_fu(uint32_t ul_earfcn) { - uint32_t i = SRSLTE_NOF_LTE_BANDS-1; +float srslte_band_fu(uint32_t ul_earfcn) +{ + uint32_t i = SRSLTE_NOF_LTE_BANDS - 1; if (ul_earfcn > lte_bands[i].ul_earfcn_offset) { ERROR("Invalid UL_EARFCN=%d\n", ul_earfcn); } i--; - while(i > 0 && (lte_bands[i].ul_earfcn_offset>ul_earfcn || lte_bands[i].ul_earfcn_offset == 0)) { + while (i > 0 && (lte_bands[i].ul_earfcn_offset > ul_earfcn || lte_bands[i].ul_earfcn_offset == 0)) { i--; } return get_fu(<e_bands[i], ul_earfcn); } -uint32_t srslte_band_ul_earfcn(uint32_t dl_earfcn) { - uint32_t i = SRSLTE_NOF_LTE_BANDS-1; +uint32_t srslte_band_ul_earfcn(uint32_t dl_earfcn) +{ + uint32_t i = SRSLTE_NOF_LTE_BANDS - 1; if (dl_earfcn > lte_bands[i].dl_earfcn_offset) { ERROR("Invalid DL_EARFCN=%d\n", dl_earfcn); } i--; - while(i > 0 && lte_bands[i].dl_earfcn_offset>dl_earfcn) { + while (i > 0 && lte_bands[i].dl_earfcn_offset > dl_earfcn) { i--; } - return lte_bands[i].ul_earfcn_offset + (dl_earfcn-lte_bands[i].dl_earfcn_offset); + return lte_bands[i].ul_earfcn_offset + (dl_earfcn - lte_bands[i].dl_earfcn_offset); } -int srslte_band_get_fd_band_all(uint32_t band, srslte_earfcn_t *earfcn, uint32_t max_elems) { +int srslte_band_get_fd_band_all(uint32_t band, srslte_earfcn_t* earfcn, uint32_t max_elems) +{ return srslte_band_get_fd_band(band, earfcn, -1, -1, max_elems); } -int srslte_band_get_fd_band( - uint32_t band, srslte_earfcn_t* earfcn, int start_earfcn, int end_earfcn, uint32_t max_elems) +int srslte_band_get_fd_band(uint32_t band, + srslte_earfcn_t* earfcn, + int start_earfcn, + int end_earfcn, + uint32_t max_elems) { uint32_t i, j; uint32_t nof_earfcn; - i=0; - while(i < SRSLTE_NOF_LTE_BANDS && lte_bands[i].band != band) { + i = 0; + while (i < SRSLTE_NOF_LTE_BANDS && lte_bands[i].band != band) { i++; } if (i >= SRSLTE_NOF_LTE_BANDS - 1) { @@ -671,9 +693,9 @@ int srslte_band_get_fd_band( return SRSLTE_ERROR; } if (end_earfcn == -1) { - end_earfcn = lte_bands[i+1].dl_earfcn_offset-1; + end_earfcn = lte_bands[i + 1].dl_earfcn_offset - 1; } else { - if (end_earfcn > lte_bands[i+1].dl_earfcn_offset-1) { + if (end_earfcn > lte_bands[i + 1].dl_earfcn_offset - 1) { ERROR("Error: Invalid end earfcn %d. Max is %d\n", end_earfcn, lte_bands[i + 1].dl_earfcn_offset - 1); return SRSLTE_ERROR; } @@ -691,18 +713,19 @@ int srslte_band_get_fd_band( if (nof_earfcn > max_elems) { nof_earfcn = max_elems; } - for (j=0;j 0;i++) { + int n; + int nof_fd = 0; + for (i = 0; i < SRSLTE_NOF_LTE_BANDS && max_elems > 0; i++) { if (lte_bands[i].area == region) { n = srslte_band_get_fd_band(i, &earfcn[nof_fd], -1, -1, max_elems); if (n != -1) { @@ -716,13 +739,13 @@ int srslte_band_get_fd_region(enum band_geographical_area region, srslte_earfcn_ return nof_fd; } - /* Returns the interval tti1-tti2 mod 10240 */ -uint32_t srslte_tti_interval(uint32_t tti1, uint32_t tti2) { +uint32_t srslte_tti_interval(uint32_t tti1, uint32_t tti2) +{ if (tti1 >= tti2) { - return tti1-tti2; + return tti1 - tti2; } else { - return 10240-tti2+tti1; + return 10240 - tti2 + tti1; } } diff --git a/lib/src/phy/common/sequence.c b/lib/src/phy/common/sequence.c index ee4884123..db55bde82 100644 --- a/lib/src/phy/common/sequence.c +++ b/lib/src/phy/common/sequence.c @@ -19,10 +19,10 @@ * */ -#include +#include #include +#include #include -#include #include "srslte/phy/common/sequence.h" #include "srslte/phy/utils/bit.h" @@ -41,11 +41,12 @@ * Section 7.2 */ #ifdef static_memory -static uint8_t x1[Nc+MAX_SEQ_LEN+31]; -static uint8_t x2[Nc+MAX_SEQ_LEN+31]; +static uint8_t x1[Nc + MAX_SEQ_LEN + 31]; +static uint8_t x2[Nc + MAX_SEQ_LEN + 31]; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -int srslte_sequence_set_LTE_pr(srslte_sequence_t *q, uint32_t len, uint32_t seed) { +int srslte_sequence_set_LTE_pr(srslte_sequence_t* q, uint32_t len, uint32_t seed) +{ int n; if (len > q->max_len) { @@ -66,7 +67,7 @@ int srslte_sequence_set_LTE_pr(srslte_sequence_t *q, uint32_t len, uint32_t seed for (n = 0; n < Nc + len; n++) { x1[n + 31] = (x1[n + 3] + x1[n]) & 0x1; - x2[n + 31] = (x2[n + 3] + x2[n + 2] + x2[n+1] + x2[n]) & 0x1; + x2[n + 31] = (x2[n + 3] + x2[n + 2] + x2[n + 1] + x2[n]) & 0x1; } for (n = 0; n < len; n++) { @@ -78,8 +79,9 @@ int srslte_sequence_set_LTE_pr(srslte_sequence_t *q, uint32_t len, uint32_t seed } #else -int srslte_sequence_set_LTE_pr(srslte_sequence_t *q, uint32_t len, uint32_t seed) { - int n; +int srslte_sequence_set_LTE_pr(srslte_sequence_t* q, uint32_t len, uint32_t seed) +{ + int n; uint32_t *x1, *x2; if (len > q->max_len) { @@ -106,7 +108,7 @@ int srslte_sequence_set_LTE_pr(srslte_sequence_t *q, uint32_t len, uint32_t seed for (n = 0; n < Nc + len; n++) { x1[n + 31] = (x1[n + 3] + x1[n]) & 0x1; - x2[n + 31] = (x2[n + 3] + x2[n + 2] + +x2[n+1] + x2[n]) & 0x1; + x2[n + 31] = (x2[n + 3] + x2[n + 2] + +x2[n + 1] + x2[n]) & 0x1; } for (n = 0; n < len; n++) { @@ -121,22 +123,25 @@ int srslte_sequence_set_LTE_pr(srslte_sequence_t *q, uint32_t len, uint32_t seed #endif -int srslte_sequence_LTE_pr(srslte_sequence_t *q, uint32_t len, uint32_t seed) { +int srslte_sequence_LTE_pr(srslte_sequence_t* q, uint32_t len, uint32_t seed) +{ if (srslte_sequence_init(q, len)) { return SRSLTE_ERROR; } q->cur_len = len; srslte_sequence_set_LTE_pr(q, len, seed); srslte_bit_pack_vector(q->c, q->c_bytes, len); - for (int i=0;ic_float[i] = (1-2*q->c[i]); - q->c_short[i] = (int16_t) q->c_float[i]; - q->c_char[i] = (int8_t) q->c_float[i];; + for (int i = 0; i < len; i++) { + q->c_float[i] = (1 - 2 * q->c[i]); + q->c_short[i] = (int16_t)q->c_float[i]; + q->c_char[i] = (int8_t)q->c_float[i]; + ; } return SRSLTE_SUCCESS; } -int srslte_sequence_init(srslte_sequence_t *q, uint32_t len) { +int srslte_sequence_init(srslte_sequence_t* q, uint32_t len) +{ if (q->c && len > q->max_len) { srslte_sequence_free(q); } @@ -145,7 +150,7 @@ int srslte_sequence_init(srslte_sequence_t *q, uint32_t len) { if (!q->c) { return SRSLTE_ERROR; } - q->c_bytes = srslte_vec_malloc(len * sizeof(uint8_t)/8+8); + q->c_bytes = srslte_vec_malloc(len * sizeof(uint8_t) / 8 + 8); if (!q->c_bytes) { return SRSLTE_ERROR; } @@ -166,7 +171,8 @@ int srslte_sequence_init(srslte_sequence_t *q, uint32_t len) { return SRSLTE_SUCCESS; } -void srslte_sequence_free(srslte_sequence_t *q) { +void srslte_sequence_free(srslte_sequence_t* q) +{ if (q->c) { free(q->c); } @@ -184,5 +190,3 @@ void srslte_sequence_free(srslte_sequence_t *q) { } bzero(q, sizeof(srslte_sequence_t)); } - - diff --git a/lib/src/phy/common/timestamp.c b/lib/src/phy/common/timestamp.c index ea3e6cf4a..1d3328797 100644 --- a/lib/src/phy/common/timestamp.c +++ b/lib/src/phy/common/timestamp.c @@ -22,12 +22,13 @@ #include "srslte/phy/common/timestamp.h" #include "math.h" -int srslte_timestamp_init(srslte_timestamp_t *t, time_t full_secs, double frac_secs){ +int srslte_timestamp_init(srslte_timestamp_t* t, time_t full_secs, double frac_secs) +{ int ret = SRSLTE_ERROR; - if(t != NULL && frac_secs >= 0.0){ + if (t != NULL && frac_secs >= 0.0) { t->full_secs = full_secs; t->frac_secs = frac_secs; - ret = SRSLTE_SUCCESS; + ret = SRSLTE_SUCCESS; } return ret; } @@ -43,12 +44,13 @@ void srslte_timestamp_init_uint64(srslte_timestamp_t* ts_time, uint64_t ts_count } } -int srslte_timestamp_copy(srslte_timestamp_t *dest, srslte_timestamp_t *src){ +int srslte_timestamp_copy(srslte_timestamp_t* dest, srslte_timestamp_t* src) +{ int ret = SRSLTE_ERROR; - if(dest != NULL && src != NULL){ + if (dest != NULL && src != NULL) { dest->full_secs = src->full_secs; dest->frac_secs = src->frac_secs; - ret = SRSLTE_SUCCESS; + ret = SRSLTE_SUCCESS; } return ret; } @@ -70,9 +72,10 @@ int srslte_timestamp_compare(const srslte_timestamp_t* a, const srslte_timestamp return ret; } -int srslte_timestamp_add(srslte_timestamp_t *t, time_t full_secs, double frac_secs){ +int srslte_timestamp_add(srslte_timestamp_t* t, time_t full_secs, double frac_secs) +{ int ret = SRSLTE_ERROR; - if(t != NULL && frac_secs >= 0.0){ + if (t != NULL && frac_secs >= 0.0) { t->frac_secs += frac_secs; t->full_secs += full_secs; double r = floor(t->frac_secs); @@ -83,24 +86,26 @@ int srslte_timestamp_add(srslte_timestamp_t *t, time_t full_secs, double frac_se return ret; } -int srslte_timestamp_sub(srslte_timestamp_t *t, time_t full_secs, double frac_secs){ +int srslte_timestamp_sub(srslte_timestamp_t* t, time_t full_secs, double frac_secs) +{ int ret = SRSLTE_ERROR; - if(t != NULL && frac_secs >= 0.0){ + if (t != NULL && frac_secs >= 0.0) { t->frac_secs -= frac_secs; t->full_secs -= full_secs; - if(t->frac_secs < 0){ + if (t->frac_secs < 0) { t->frac_secs = t->frac_secs + 1; t->full_secs--; } - if(t->full_secs < 0) + if (t->full_secs < 0) return SRSLTE_ERROR; ret = SRSLTE_SUCCESS; } return ret; } -double srslte_timestamp_real(srslte_timestamp_t *t){ - return t->frac_secs + t->full_secs; +double srslte_timestamp_real(srslte_timestamp_t* t) +{ + return t->frac_secs + t->full_secs; } bool srslte_timestamp_iszero(const srslte_timestamp_t* t) @@ -108,9 +113,10 @@ bool srslte_timestamp_iszero(const srslte_timestamp_t* t) return ((t->full_secs == 0) && (t->frac_secs == 0)); } -uint32_t srslte_timestamp_uint32(srslte_timestamp_t *t){ - uint32_t x = t->full_secs*1e6 + (uint32_t) (t->frac_secs*1e6); - return x; +uint32_t srslte_timestamp_uint32(srslte_timestamp_t* t) +{ + uint32_t x = t->full_secs * 1e6 + (uint32_t)(t->frac_secs * 1e6); + return x; } uint64_t srslte_timestamp_uint64(const srslte_timestamp_t* t, double srate) diff --git a/lib/src/phy/dft/dft_fftw.c b/lib/src/phy/dft/dft_fftw.c index 7228de3b7..30df37a2d 100644 --- a/lib/src/phy/dft/dft_fftw.c +++ b/lib/src/phy/dft/dft_fftw.c @@ -30,8 +30,8 @@ #include "srslte/phy/dft/dft.h" #include "srslte/phy/utils/vector.h" -#define dft_ceil(a,b) ((a-1)/b+1) -#define dft_floor(a,b) (a/b) +#define dft_ceil(a, b) ((a - 1) / b + 1) +#define dft_floor(a, b) (a / b) #define FFTW_WISDOM_FILE "%s/.srslte_fftwisdom" @@ -53,7 +53,8 @@ static int get_fftw_wisdom_file(char* full_path, uint32_t n) static pthread_mutex_t fft_mutex = PTHREAD_MUTEX_INITIALIZER; -void srslte_dft_load() { +void srslte_dft_load() +{ #ifdef FFTW_WISDOM_FILE char full_path[256]; get_fftw_wisdom_file(full_path, sizeof(full_path)); @@ -63,7 +64,8 @@ void srslte_dft_load() { #endif } -void srslte_dft_exit() { +void srslte_dft_exit() +{ #ifdef FFTW_WISDOM_FILE char full_path[256]; get_fftw_wisdom_file(full_path, sizeof(full_path)); @@ -72,23 +74,24 @@ void srslte_dft_exit() { fftwf_cleanup(); } -int srslte_dft_plan(srslte_dft_plan_t *plan, const int dft_points, srslte_dft_dir_t dir, - srslte_dft_mode_t mode) { +int srslte_dft_plan(srslte_dft_plan_t* plan, const int dft_points, srslte_dft_dir_t dir, srslte_dft_mode_t mode) +{ bzero(plan, sizeof(srslte_dft_plan_t)); - if(mode == SRSLTE_DFT_COMPLEX){ - return srslte_dft_plan_c(plan,dft_points,dir); + if (mode == SRSLTE_DFT_COMPLEX) { + return srslte_dft_plan_c(plan, dft_points, dir); } else { - return srslte_dft_plan_r(plan,dft_points,dir); + return srslte_dft_plan_r(plan, dft_points, dir); } return 0; } -int srslte_dft_replan(srslte_dft_plan_t *plan, const int new_dft_points) { +int srslte_dft_replan(srslte_dft_plan_t* plan, const int new_dft_points) +{ if (new_dft_points <= plan->init_size) { - if(plan->mode == SRSLTE_DFT_COMPLEX){ - return srslte_dft_replan_c(plan,new_dft_points); + if (plan->mode == SRSLTE_DFT_COMPLEX) { + return srslte_dft_replan_c(plan, new_dft_points); } else { - return srslte_dft_replan_r(plan,new_dft_points); + return srslte_dft_replan_r(plan, new_dft_points); } } else { ERROR("DFT: Error calling replan: new_dft_points (%d) must be lower or equal " @@ -99,19 +102,25 @@ int srslte_dft_replan(srslte_dft_plan_t *plan, const int new_dft_points) { } } - - -static void allocate(srslte_dft_plan_t *plan, int size_in, int size_out, int len) { - plan->in = fftwf_malloc(size_in*len); - plan->out = fftwf_malloc(size_out*len); +static void allocate(srslte_dft_plan_t* plan, int size_in, int size_out, int len) +{ + plan->in = fftwf_malloc(size_in * len); + plan->out = fftwf_malloc(size_out * len); } -int srslte_dft_replan_guru_c(srslte_dft_plan_t *plan, const int new_dft_points, cf_t *in_buffer, - cf_t *out_buffer, int istride, int ostride, int how_many, - int idist, int odist) { +int srslte_dft_replan_guru_c(srslte_dft_plan_t* plan, + const int new_dft_points, + cf_t* in_buffer, + cf_t* out_buffer, + int istride, + int ostride, + int how_many, + int idist, + int odist) +{ int sign = (plan->forward) ? FFTW_FORWARD : FFTW_BACKWARD; - const fftwf_iodim iodim = {new_dft_points, istride, ostride}; + const fftwf_iodim iodim = {new_dft_points, istride, ostride}; const fftwf_iodim howmany_dims = {how_many, idist, odist}; pthread_mutex_lock(&fft_mutex); @@ -126,13 +135,14 @@ int srslte_dft_replan_guru_c(srslte_dft_plan_t *plan, const int new_dft_points, if (!plan->p) { return -1; } - plan->size = new_dft_points; + plan->size = new_dft_points; plan->init_size = plan->size; return 0; } -int srslte_dft_replan_c(srslte_dft_plan_t *plan, const int new_dft_points) { +int srslte_dft_replan_c(srslte_dft_plan_t* plan, const int new_dft_points) +{ int sign = (plan->dir == SRSLTE_DFT_FORWARD) ? FFTW_FORWARD : FFTW_BACKWARD; pthread_mutex_lock(&fft_mutex); @@ -150,12 +160,20 @@ int srslte_dft_replan_c(srslte_dft_plan_t *plan, const int new_dft_points) { return 0; } -int srslte_dft_plan_guru_c(srslte_dft_plan_t *plan, const int dft_points, srslte_dft_dir_t dir, cf_t *in_buffer, - cf_t *out_buffer, int istride, int ostride, int how_many, - int idist, int odist) { +int srslte_dft_plan_guru_c(srslte_dft_plan_t* plan, + const int dft_points, + srslte_dft_dir_t dir, + cf_t* in_buffer, + cf_t* out_buffer, + int istride, + int ostride, + int how_many, + int idist, + int odist) +{ int sign = (dir == SRSLTE_DFT_FORWARD) ? FFTW_FORWARD : FFTW_BACKWARD; - const fftwf_iodim iodim = {dft_points, istride, ostride}; + const fftwf_iodim iodim = {dft_points, istride, ostride}; const fftwf_iodim howmany_dims = {how_many, idist, odist}; pthread_mutex_lock(&fft_mutex); @@ -166,48 +184,50 @@ int srslte_dft_plan_guru_c(srslte_dft_plan_t *plan, const int dft_points, srslte } pthread_mutex_unlock(&fft_mutex); - plan->size = dft_points; + plan->size = dft_points; plan->init_size = plan->size; - plan->mode = SRSLTE_DFT_COMPLEX; - plan->dir = dir; - plan->forward = (dir==SRSLTE_DFT_FORWARD)?true:false; - plan->mirror = false; - plan->db = false; - plan->norm = false; - plan->dc = false; - plan->is_guru = true; + plan->mode = SRSLTE_DFT_COMPLEX; + plan->dir = dir; + plan->forward = (dir == SRSLTE_DFT_FORWARD) ? true : false; + plan->mirror = false; + plan->db = false; + plan->norm = false; + plan->dc = false; + plan->is_guru = true; return 0; } -int srslte_dft_plan_c(srslte_dft_plan_t *plan, const int dft_points, srslte_dft_dir_t dir) { - allocate(plan,sizeof(fftwf_complex),sizeof(fftwf_complex), dft_points); +int srslte_dft_plan_c(srslte_dft_plan_t* plan, const int dft_points, srslte_dft_dir_t dir) +{ + allocate(plan, sizeof(fftwf_complex), sizeof(fftwf_complex), dft_points); pthread_mutex_lock(&fft_mutex); int sign = (dir == SRSLTE_DFT_FORWARD) ? FFTW_FORWARD : FFTW_BACKWARD; - plan->p = fftwf_plan_dft_1d(dft_points, plan->in, plan->out, sign, FFTW_TYPE); + plan->p = fftwf_plan_dft_1d(dft_points, plan->in, plan->out, sign, FFTW_TYPE); pthread_mutex_unlock(&fft_mutex); if (!plan->p) { return -1; } - plan->size = dft_points; + plan->size = dft_points; plan->init_size = plan->size; - plan->mode = SRSLTE_DFT_COMPLEX; - plan->dir = dir; - plan->forward = (dir==SRSLTE_DFT_FORWARD)?true:false; - plan->mirror = false; - plan->db = false; - plan->norm = false; - plan->dc = false; - plan->is_guru = false; + plan->mode = SRSLTE_DFT_COMPLEX; + plan->dir = dir; + plan->forward = (dir == SRSLTE_DFT_FORWARD) ? true : false; + plan->mirror = false; + plan->db = false; + plan->norm = false; + plan->dc = false; + plan->is_guru = false; return 0; } -int srslte_dft_replan_r(srslte_dft_plan_t *plan, const int new_dft_points) { +int srslte_dft_replan_r(srslte_dft_plan_t* plan, const int new_dft_points) +{ int sign = (plan->dir == SRSLTE_DFT_FORWARD) ? FFTW_R2HC : FFTW_HC2R; pthread_mutex_lock(&fft_mutex); @@ -225,8 +245,9 @@ int srslte_dft_replan_r(srslte_dft_plan_t *plan, const int new_dft_points) { return 0; } -int srslte_dft_plan_r(srslte_dft_plan_t *plan, const int dft_points, srslte_dft_dir_t dir) { - allocate(plan,sizeof(float),sizeof(float), dft_points); +int srslte_dft_plan_r(srslte_dft_plan_t* plan, const int dft_points, srslte_dft_dir_t dir) +{ + allocate(plan, sizeof(float), sizeof(float), dft_points); int sign = (dir == SRSLTE_DFT_FORWARD) ? FFTW_R2HC : FFTW_HC2R; pthread_mutex_lock(&fft_mutex); @@ -236,91 +257,97 @@ int srslte_dft_plan_r(srslte_dft_plan_t *plan, const int dft_points, srslte_dft_ if (!plan->p) { return -1; } - plan->size = dft_points; + plan->size = dft_points; plan->init_size = plan->size; - plan->mode = SRSLTE_REAL; - plan->dir = dir; - plan->forward = (dir==SRSLTE_DFT_FORWARD)?true:false; - plan->mirror = false; - plan->db = false; - plan->norm = false; - plan->dc = false; + plan->mode = SRSLTE_REAL; + plan->dir = dir; + plan->forward = (dir == SRSLTE_DFT_FORWARD) ? true : false; + plan->mirror = false; + plan->db = false; + plan->norm = false; + plan->dc = false; return 0; } -void srslte_dft_plan_set_mirror(srslte_dft_plan_t *plan, bool val){ +void srslte_dft_plan_set_mirror(srslte_dft_plan_t* plan, bool val) +{ plan->mirror = val; } -void srslte_dft_plan_set_db(srslte_dft_plan_t *plan, bool val){ +void srslte_dft_plan_set_db(srslte_dft_plan_t* plan, bool val) +{ plan->db = val; } -void srslte_dft_plan_set_norm(srslte_dft_plan_t *plan, bool val){ +void srslte_dft_plan_set_norm(srslte_dft_plan_t* plan, bool val) +{ plan->norm = val; } -void srslte_dft_plan_set_dc(srslte_dft_plan_t *plan, bool val){ +void srslte_dft_plan_set_dc(srslte_dft_plan_t* plan, bool val) +{ plan->dc = val; } -static void copy_pre(uint8_t *dst, uint8_t *src, int size_d, int len, - bool forward, bool mirror, bool dc) { - int offset = dc?1:0; - if(mirror && !forward){ - int hlen = dft_floor(len,2); - memset(dst,0,size_d*offset); - memcpy(&dst[size_d*offset], &src[size_d*hlen], size_d*(len-hlen-offset)); - memcpy(&dst[(len-hlen)*size_d], src, size_d*hlen); +static void copy_pre(uint8_t* dst, uint8_t* src, int size_d, int len, bool forward, bool mirror, bool dc) +{ + int offset = dc ? 1 : 0; + if (mirror && !forward) { + int hlen = dft_floor(len, 2); + memset(dst, 0, size_d * offset); + memcpy(&dst[size_d * offset], &src[size_d * hlen], size_d * (len - hlen - offset)); + memcpy(&dst[(len - hlen) * size_d], src, size_d * hlen); } else { - memcpy(dst,src,size_d*len); + memcpy(dst, src, size_d * len); } } -static void copy_post(uint8_t *dst, uint8_t *src, int size_d, int len, - bool forward, bool mirror, bool dc) { - int offset = dc?1:0; - if(mirror && forward){ - int hlen = dft_ceil(len,2); - memcpy(dst, &src[size_d*hlen], size_d*(len-hlen)); - memcpy(&dst[(len-hlen)*size_d], &src[size_d*offset], size_d*(hlen-offset)); +static void copy_post(uint8_t* dst, uint8_t* src, int size_d, int len, bool forward, bool mirror, bool dc) +{ + int offset = dc ? 1 : 0; + if (mirror && forward) { + int hlen = dft_ceil(len, 2); + memcpy(dst, &src[size_d * hlen], size_d * (len - hlen)); + memcpy(&dst[(len - hlen) * size_d], &src[size_d * offset], size_d * (hlen - offset)); } else { - memcpy(dst,src,size_d*len); + memcpy(dst, src, size_d * len); } } -void srslte_dft_run(srslte_dft_plan_t *plan, const void *in, void *out) { - if(plan->mode == SRSLTE_DFT_COMPLEX) { - srslte_dft_run_c(plan,in,out); +void srslte_dft_run(srslte_dft_plan_t* plan, const void* in, void* out) +{ + if (plan->mode == SRSLTE_DFT_COMPLEX) { + srslte_dft_run_c(plan, in, out); } else { - srslte_dft_run_r(plan,in,out); + srslte_dft_run_r(plan, in, out); } } -void srslte_dft_run_c_zerocopy(srslte_dft_plan_t *plan, const cf_t *in, cf_t *out) { - fftwf_execute_dft(plan->p, (cf_t*) in, out); +void srslte_dft_run_c_zerocopy(srslte_dft_plan_t* plan, const cf_t* in, cf_t* out) +{ + fftwf_execute_dft(plan->p, (cf_t*)in, out); } -void srslte_dft_run_c(srslte_dft_plan_t *plan, const cf_t *in, cf_t *out) { - float norm; - int i; - fftwf_complex *f_out = plan->out; +void srslte_dft_run_c(srslte_dft_plan_t* plan, const cf_t* in, cf_t* out) +{ + float norm; + int i; + fftwf_complex* f_out = plan->out; - copy_pre((uint8_t*)plan->in, (uint8_t*)in, sizeof(cf_t), plan->size, - plan->forward, plan->mirror, plan->dc); + copy_pre((uint8_t*)plan->in, (uint8_t*)in, sizeof(cf_t), plan->size, plan->forward, plan->mirror, plan->dc); fftwf_execute(plan->p); if (plan->norm) { - norm = 1.0/sqrtf(plan->size); - srslte_vec_sc_prod_cfc(f_out, norm, f_out, plan->size); + norm = 1.0 / sqrtf(plan->size); + srslte_vec_sc_prod_cfc(f_out, norm, f_out, plan->size); } if (plan->db) { - for (i=0;isize;i++) { + for (i = 0; i < plan->size; i++) { f_out[i] = srslte_convert_power_to_dB(f_out[i]); } } - copy_post((uint8_t*)out, (uint8_t*)plan->out, sizeof(cf_t), plan->size, - plan->forward, plan->mirror, plan->dc); + copy_post((uint8_t*)out, (uint8_t*)plan->out, sizeof(cf_t), plan->size, plan->forward, plan->mirror, plan->dc); } -void srslte_dft_run_guru_c(srslte_dft_plan_t *plan) { +void srslte_dft_run_guru_c(srslte_dft_plan_t* plan) +{ if (plan->is_guru == true) { fftwf_execute(plan->p); } else { @@ -328,39 +355,43 @@ void srslte_dft_run_guru_c(srslte_dft_plan_t *plan) { } } -void srslte_dft_run_r(srslte_dft_plan_t *plan, const float *in, float *out) { - float norm; - int i; - int len = plan->size; - float *f_out = plan->out; +void srslte_dft_run_r(srslte_dft_plan_t* plan, const float* in, float* out) +{ + float norm; + int i; + int len = plan->size; + float* f_out = plan->out; - memcpy(plan->in,in,sizeof(float)*plan->size); + memcpy(plan->in, in, sizeof(float) * plan->size); fftwf_execute(plan->p); if (plan->norm) { - norm = 1.0/plan->size; - srslte_vec_sc_prod_fff(f_out, norm, f_out, plan->size); + norm = 1.0 / plan->size; + srslte_vec_sc_prod_fff(f_out, norm, f_out, plan->size); } if (plan->db) { - for (i=0;iout,sizeof(float)*plan->size); + memcpy(out, plan->out, sizeof(float) * plan->size); } -void srslte_dft_plan_free(srslte_dft_plan_t *plan) { - if (!plan) return; - if (!plan->size) return; +void srslte_dft_plan_free(srslte_dft_plan_t* plan) +{ + if (!plan) + return; + if (!plan->size) + return; pthread_mutex_lock(&fft_mutex); if (!plan->is_guru) { - if (plan->in) fftwf_free(plan->in); - if (plan->out) fftwf_free(plan->out); + if (plan->in) + fftwf_free(plan->in); + if (plan->out) + fftwf_free(plan->out); } - if (plan->p) fftwf_destroy_plan(plan->p); + if (plan->p) + fftwf_destroy_plan(plan->p); pthread_mutex_unlock(&fft_mutex); bzero(plan, sizeof(srslte_dft_plan_t)); } - - - diff --git a/lib/src/phy/dft/dft_precoding.c b/lib/src/phy/dft/dft_precoding.c index fa8286a56..c301d2b78 100644 --- a/lib/src/phy/dft/dft_precoding.c +++ b/lib/src/phy/dft/dft_precoding.c @@ -19,34 +19,34 @@ * */ +#include +#include +#include #include #include +#include #include #include -#include -#include -#include -#include #include "srslte/phy/common/phy_common.h" -#include "srslte/phy/utils/debug.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/dft/dft.h" #include "srslte/phy/dft/dft_precoding.h" +#include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" /* Create DFT plans for transform precoding */ -int srslte_dft_precoding_init(srslte_dft_precoding_t *q, uint32_t max_prb, bool is_tx) +int srslte_dft_precoding_init(srslte_dft_precoding_t* q, uint32_t max_prb, bool is_tx) { int ret = SRSLTE_ERROR_INVALID_INPUTS; bzero(q, sizeof(srslte_dft_precoding_t)); if (max_prb <= SRSLTE_MAX_PRB) { ret = SRSLTE_ERROR; - for (uint32_t i=1;i<=max_prb;i++) { - if(srslte_dft_precoding_valid_prb(i)) { + for (uint32_t i = 1; i <= max_prb; i++) { + if (srslte_dft_precoding_valid_prb(i)) { DEBUG("Initiating DFT precoding plan for %d PRBs\n", i); - if (srslte_dft_plan_c(&q->dft_plan[i], i*SRSLTE_NRE, is_tx?SRSLTE_DFT_FORWARD:SRSLTE_DFT_BACKWARD)) { + if (srslte_dft_plan_c(&q->dft_plan[i], i * SRSLTE_NRE, is_tx ? SRSLTE_DFT_FORWARD : SRSLTE_DFT_BACKWARD)) { ERROR("Error: Creating DFT plan %d\n", i); goto clean_exit; } @@ -54,60 +54,65 @@ int srslte_dft_precoding_init(srslte_dft_precoding_t *q, uint32_t max_prb, bool } } q->max_prb = max_prb; - ret = SRSLTE_SUCCESS; + ret = SRSLTE_SUCCESS; } - clean_exit: +clean_exit: if (ret == SRSLTE_ERROR) { srslte_dft_precoding_free(q); } return ret; } -int srslte_dft_precoding_init_rx(srslte_dft_precoding_t *q, uint32_t max_prb) +int srslte_dft_precoding_init_rx(srslte_dft_precoding_t* q, uint32_t max_prb) { return srslte_dft_precoding_init(q, max_prb, false); } -int srslte_dft_precoding_init_tx(srslte_dft_precoding_t *q, uint32_t max_prb) { +int srslte_dft_precoding_init_tx(srslte_dft_precoding_t* q, uint32_t max_prb) +{ return srslte_dft_precoding_init(q, max_prb, true); } /* Free DFT plans for transform precoding */ -void srslte_dft_precoding_free(srslte_dft_precoding_t *q) +void srslte_dft_precoding_free(srslte_dft_precoding_t* q) { - for (uint32_t i=1;i<=q->max_prb;i++) { - if(srslte_dft_precoding_valid_prb(i)) { + for (uint32_t i = 1; i <= q->max_prb; i++) { + if (srslte_dft_precoding_valid_prb(i)) { srslte_dft_plan_free(&q->dft_plan[i]); } - } + } bzero(q, sizeof(srslte_dft_precoding_t)); } -static bool valid_prb[101]={true,true,true,true,true,true,true,false,true,true,true,false,true,false,false,true,true,false,true,false,true,false,false,false, - true,true,false,true,false,false,true,false,true,false,false,false,true,false,false,false,true,false,false,false,false,true,false,false,true,false, - true,false,false,false,true,false,false,false,false,false,true,false,false,false,true,false,false,false,false,false,false,false,true,false,false,true, - false,false,false,false,true,true,false,false,false,false,false,false,false,false,true,false,false,false,false,false,true,false,false,false,true}; +static bool valid_prb[101] = {true, true, true, true, true, true, true, false, true, true, true, false, true, + false, false, true, true, false, true, false, true, false, false, false, true, true, + false, true, false, false, true, false, true, false, false, false, true, false, false, + false, true, false, false, false, false, true, false, false, true, false, true, false, + false, false, true, false, false, false, false, false, true, false, false, false, true, + false, false, false, false, false, false, false, true, false, false, true, false, false, + false, false, true, true, false, false, false, false, false, false, false, false, true, + false, false, false, false, false, true, false, false, false, true}; -bool srslte_dft_precoding_valid_prb(uint32_t nof_prb) { +bool srslte_dft_precoding_valid_prb(uint32_t nof_prb) +{ if (nof_prb <= 100) { return valid_prb[nof_prb]; } - return false; + return false; } -int srslte_dft_precoding(srslte_dft_precoding_t *q, cf_t *input, cf_t *output, - uint32_t nof_prb, uint32_t nof_symbols) +int srslte_dft_precoding(srslte_dft_precoding_t* q, cf_t* input, cf_t* output, uint32_t nof_prb, uint32_t nof_symbols) { - + if (!srslte_dft_precoding_valid_prb(nof_prb) && nof_prb <= q->max_prb) { ERROR("Error invalid number of PRB (%d)\n", nof_prb); - return SRSLTE_ERROR; + return SRSLTE_ERROR; } - for (uint32_t i=0;idft_plan[nof_prb], &input[i*SRSLTE_NRE*nof_prb], &output[i*SRSLTE_NRE*nof_prb]); + for (uint32_t i = 0; i < nof_symbols; i++) { + srslte_dft_run_c(&q->dft_plan[nof_prb], &input[i * SRSLTE_NRE * nof_prb], &output[i * SRSLTE_NRE * nof_prb]); } - + return SRSLTE_SUCCESS; } diff --git a/lib/src/phy/dft/ofdm.c b/lib/src/phy/dft/ofdm.c index be55f8edb..a17c684d2 100644 --- a/lib/src/phy/dft/ofdm.c +++ b/lib/src/phy/dft/ofdm.c @@ -35,24 +35,39 @@ /* Uncomment next line for avoiding Guru DFT call */ //#define AVOID_GURU -int srslte_ofdm_init_(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, cf_t *out_buffer, int symbol_sz, int nof_prb, srslte_dft_dir_t dir) { +int srslte_ofdm_init_(srslte_ofdm_t* q, + srslte_cp_t cp, + cf_t* in_buffer, + cf_t* out_buffer, + int symbol_sz, + int nof_prb, + srslte_dft_dir_t dir) +{ return srslte_ofdm_init_mbsfn_(q, cp, in_buffer, out_buffer, symbol_sz, nof_prb, dir, SRSLTE_SF_NORM); } -int srslte_ofdm_init_mbsfn_(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, cf_t *out_buffer, int symbol_sz, int nof_prb, srslte_dft_dir_t dir, srslte_sf_t sf_type) { +int srslte_ofdm_init_mbsfn_(srslte_ofdm_t* q, + srslte_cp_t cp, + cf_t* in_buffer, + cf_t* out_buffer, + int symbol_sz, + int nof_prb, + srslte_dft_dir_t dir, + srslte_sf_t sf_type) +{ /* Set OFDM object attributes */ - q->symbol_sz = (uint32_t) symbol_sz; - q->nof_symbols = SRSLTE_CP_NSYMB(cp); + q->symbol_sz = (uint32_t)symbol_sz; + q->nof_symbols = SRSLTE_CP_NSYMB(cp); q->nof_symbols_mbsfn = SRSLTE_CP_NSYMB(SRSLTE_CP_EXT); - q->cp = cp; - q->freq_shift = false; - q->nof_re = (uint32_t) nof_prb * SRSLTE_NRE; - q->nof_guards = ((symbol_sz - q->nof_re) / 2); - q->slot_sz = (uint32_t) SRSLTE_SLOT_LEN(symbol_sz); - q->sf_sz = (uint32_t) SRSLTE_SF_LEN(symbol_sz); - q->in_buffer = in_buffer; - q->out_buffer= out_buffer; + q->cp = cp; + q->freq_shift = false; + q->nof_re = (uint32_t)nof_prb * SRSLTE_NRE; + q->nof_guards = ((symbol_sz - q->nof_re) / 2); + q->slot_sz = (uint32_t)SRSLTE_SLOT_LEN(symbol_sz); + q->sf_sz = (uint32_t)SRSLTE_SF_LEN(symbol_sz); + q->in_buffer = in_buffer; + q->out_buffer = out_buffer; if (srslte_dft_plan_c(&q->fft_plan, symbol_sz, dir)) { ERROR("Error: Creating DFT plan\n"); @@ -60,15 +75,15 @@ int srslte_ofdm_init_mbsfn_(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, c } #ifdef AVOID_GURU - q->tmp = srslte_vec_malloc((uint32_t) symbol_sz * sizeof(cf_t)); + q->tmp = srslte_vec_malloc((uint32_t)symbol_sz * sizeof(cf_t)); if (!q->tmp) { perror("malloc"); return -1; } bzero(q->tmp, sizeof(cf_t) * symbol_sz); #else - int cp1 = SRSLTE_CP_ISNORM(cp)?SRSLTE_CP_LEN_NORM(0, symbol_sz):SRSLTE_CP_LEN_EXT(symbol_sz); - int cp2 = SRSLTE_CP_ISNORM(cp)?SRSLTE_CP_LEN_NORM(1, symbol_sz):SRSLTE_CP_LEN_EXT(symbol_sz); + int cp1 = SRSLTE_CP_ISNORM(cp) ? SRSLTE_CP_LEN_NORM(0, symbol_sz) : SRSLTE_CP_LEN_EXT(symbol_sz); + int cp2 = SRSLTE_CP_ISNORM(cp) ? SRSLTE_CP_LEN_NORM(1, symbol_sz) : SRSLTE_CP_LEN_EXT(symbol_sz); q->tmp = srslte_vec_malloc(sizeof(cf_t) * q->sf_sz); if (!q->tmp) { @@ -79,26 +94,39 @@ int srslte_ofdm_init_mbsfn_(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, c if (dir == SRSLTE_DFT_BACKWARD) { bzero(in_buffer, sizeof(cf_t) * SRSLTE_SF_LEN_RE(nof_prb, cp)); - }else { + } else { bzero(in_buffer, sizeof(cf_t) * q->sf_sz); } for (int slot = 0; slot < 2; slot++) { - //bzero(&q->fft_plan_sf[slot], sizeof(srslte_dft_plan_t)); - //bzero(q->tmp + SRSLTE_CP_NSYMB(cp)*symbol_sz*slot, sizeof(cf_t) * (cp1 + (SRSLTE_CP_NSYMB(cp) - 1)*cp2 + SRSLTE_CP_NSYMB(cp)*symbol_sz)); + // bzero(&q->fft_plan_sf[slot], sizeof(srslte_dft_plan_t)); + // bzero(q->tmp + SRSLTE_CP_NSYMB(cp)*symbol_sz*slot, sizeof(cf_t) * (cp1 + (SRSLTE_CP_NSYMB(cp) - 1)*cp2 + + // SRSLTE_CP_NSYMB(cp)*symbol_sz)); if (dir == SRSLTE_DFT_FORWARD) { - if (srslte_dft_plan_guru_c(&q->fft_plan_sf[slot], symbol_sz, dir, + if (srslte_dft_plan_guru_c(&q->fft_plan_sf[slot], + symbol_sz, + dir, in_buffer + cp1 + q->slot_sz * slot, q->tmp + q->nof_symbols * q->symbol_sz * slot, - 1, 1, SRSLTE_CP_NSYMB(cp), symbol_sz + cp2, symbol_sz)) { + 1, + 1, + SRSLTE_CP_NSYMB(cp), + symbol_sz + cp2, + symbol_sz)) { ERROR("Error: Creating DFT plan (1)\n"); return -1; } } else { - if (srslte_dft_plan_guru_c(&q->fft_plan_sf[slot], symbol_sz, dir, + if (srslte_dft_plan_guru_c(&q->fft_plan_sf[slot], + symbol_sz, + dir, q->tmp + q->nof_symbols * q->symbol_sz * slot, out_buffer + cp1 + q->slot_sz * slot, - 1, 1, SRSLTE_CP_NSYMB(cp), symbol_sz, symbol_sz + cp2)) { + 1, + 1, + SRSLTE_CP_NSYMB(cp), + symbol_sz, + symbol_sz + cp2)) { ERROR("Error: Creating DFT plan (1)\n"); return -1; } @@ -116,47 +144,52 @@ int srslte_ofdm_init_mbsfn_(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, c srslte_dft_plan_set_dc(&q->fft_plan, true); DEBUG("Init %s symbol_sz=%d, nof_symbols=%d, cp=%s, nof_re=%d, nof_guards=%d\n", - dir==SRSLTE_DFT_FORWARD?"FFT":"iFFT", q->symbol_sz, q->nof_symbols, - q->cp==SRSLTE_CP_NORM?"Normal":"Extended", q->nof_re, q->nof_guards); - + dir == SRSLTE_DFT_FORWARD ? "FFT" : "iFFT", + q->symbol_sz, + q->nof_symbols, + q->cp == SRSLTE_CP_NORM ? "Normal" : "Extended", + q->nof_re, + q->nof_guards); + // MBSFN logic if (sf_type == SRSLTE_SF_MBSFN) { - q->mbsfn_subframe = true; + q->mbsfn_subframe = true; q->non_mbsfn_region = 2; // default set to 2 } else { q->mbsfn_subframe = false; } - + return SRSLTE_SUCCESS; } -void srslte_ofdm_set_non_mbsfn_region(srslte_ofdm_t *q, uint8_t non_mbsfn_region) +void srslte_ofdm_set_non_mbsfn_region(srslte_ofdm_t* q, uint8_t non_mbsfn_region) { q->non_mbsfn_region = non_mbsfn_region; } -int srslte_ofdm_replan_(srslte_ofdm_t *q, srslte_cp_t cp, int symbol_sz, int nof_prb) { +int srslte_ofdm_replan_(srslte_ofdm_t* q, srslte_cp_t cp, int symbol_sz, int nof_prb) +{ if (srslte_dft_replan_c(&q->fft_plan, symbol_sz)) { ERROR("Error: Creating DFT plan\n"); return -1; } - q->symbol_sz = (uint32_t) symbol_sz; - q->nof_symbols = SRSLTE_CP_NSYMB(cp); + q->symbol_sz = (uint32_t)symbol_sz; + q->nof_symbols = SRSLTE_CP_NSYMB(cp); q->nof_symbols_mbsfn = SRSLTE_CP_NSYMB(SRSLTE_CP_EXT); - q->cp = cp; - q->nof_re = (uint32_t) nof_prb * SRSLTE_NRE; - q->nof_guards = ((symbol_sz - q->nof_re) / 2); - q->slot_sz = (uint32_t) SRSLTE_SLOT_LEN(symbol_sz); - q->sf_sz = (uint32_t) SRSLTE_SF_LEN(symbol_sz); + q->cp = cp; + q->nof_re = (uint32_t)nof_prb * SRSLTE_NRE; + q->nof_guards = ((symbol_sz - q->nof_re) / 2); + q->slot_sz = (uint32_t)SRSLTE_SLOT_LEN(symbol_sz); + q->sf_sz = (uint32_t)SRSLTE_SF_LEN(symbol_sz); #ifndef AVOID_GURU - cf_t *in_buffer = q->in_buffer; - cf_t *out_buffer = q->out_buffer; + cf_t* in_buffer = q->in_buffer; + cf_t* out_buffer = q->out_buffer; - int cp1 = SRSLTE_CP_ISNORM(cp)?SRSLTE_CP_LEN_NORM(0, symbol_sz):SRSLTE_CP_LEN_EXT(symbol_sz); - int cp2 = SRSLTE_CP_ISNORM(cp)?SRSLTE_CP_LEN_NORM(1, symbol_sz):SRSLTE_CP_LEN_EXT(symbol_sz); + int cp1 = SRSLTE_CP_ISNORM(cp) ? SRSLTE_CP_LEN_NORM(0, symbol_sz) : SRSLTE_CP_LEN_EXT(symbol_sz); + int cp2 = SRSLTE_CP_ISNORM(cp) ? SRSLTE_CP_LEN_NORM(1, symbol_sz) : SRSLTE_CP_LEN_EXT(symbol_sz); srslte_dft_dir_t dir = q->fft_plan_sf[0].dir; @@ -173,7 +206,7 @@ int srslte_ofdm_replan_(srslte_ofdm_t *q, srslte_cp_t cp, int symbol_sz, int nof if (dir == SRSLTE_DFT_BACKWARD) { bzero(in_buffer, sizeof(cf_t) * SRSLTE_SF_LEN_RE(nof_prb, cp)); - }else { + } else { bzero(in_buffer, sizeof(cf_t) * q->sf_sz); } @@ -181,18 +214,30 @@ int srslte_ofdm_replan_(srslte_ofdm_t *q, srslte_cp_t cp, int symbol_sz, int nof srslte_dft_plan_free(&q->fft_plan_sf[slot]); if (dir == SRSLTE_DFT_FORWARD) { - if (srslte_dft_plan_guru_c(&q->fft_plan_sf[slot], symbol_sz, dir, + if (srslte_dft_plan_guru_c(&q->fft_plan_sf[slot], + symbol_sz, + dir, in_buffer + cp1 + q->slot_sz * slot, q->tmp + q->nof_symbols * q->symbol_sz * slot, - 1, 1, SRSLTE_CP_NSYMB(cp), symbol_sz + cp2, symbol_sz)) { + 1, + 1, + SRSLTE_CP_NSYMB(cp), + symbol_sz + cp2, + symbol_sz)) { ERROR("Error: Creating DFT plan (1)\n"); return -1; } } else { - if (srslte_dft_plan_guru_c(&q->fft_plan_sf[slot], symbol_sz, dir, + if (srslte_dft_plan_guru_c(&q->fft_plan_sf[slot], + symbol_sz, + dir, q->tmp + q->nof_symbols * q->symbol_sz * slot, out_buffer + cp1 + q->slot_sz * slot, - 1, 1, SRSLTE_CP_NSYMB(cp), symbol_sz, symbol_sz + cp2)) { + 1, + 1, + SRSLTE_CP_NSYMB(cp), + symbol_sz, + symbol_sz + cp2)) { ERROR("Error: Creating DFT plan (1)\n"); return -1; } @@ -200,19 +245,22 @@ int srslte_ofdm_replan_(srslte_ofdm_t *q, srslte_cp_t cp, int symbol_sz, int nof } #endif /* AVOID_GURU */ - if (q->freq_shift) { srslte_ofdm_set_freq_shift(q, q->freq_shift_f); } DEBUG("Replan symbol_sz=%d, nof_symbols=%d, cp=%s, nof_re=%d, nof_guards=%d\n", - q->symbol_sz, q->nof_symbols, - q->cp==SRSLTE_CP_NORM?"Normal":"Extended", q->nof_re, q->nof_guards); + q->symbol_sz, + q->nof_symbols, + q->cp == SRSLTE_CP_NORM ? "Normal" : "Extended", + q->nof_re, + q->nof_guards); return SRSLTE_SUCCESS; } -void srslte_ofdm_free_(srslte_ofdm_t *q) { +void srslte_ofdm_free_(srslte_ofdm_t* q) +{ srslte_dft_plan_free(&q->fft_plan); #ifndef AVOID_GURU @@ -232,7 +280,8 @@ void srslte_ofdm_free_(srslte_ofdm_t *q) { bzero(q, sizeof(srslte_ofdm_t)); } -int srslte_ofdm_rx_init(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, cf_t *out_buffer, uint32_t max_prb) { +int srslte_ofdm_rx_init(srslte_ofdm_t* q, srslte_cp_t cp, cf_t* in_buffer, cf_t* out_buffer, uint32_t max_prb) +{ int symbol_sz = srslte_symbol_sz(max_prb); if (symbol_sz < 0) { ERROR("Error: Invalid nof_prb=%d\n", max_prb); @@ -242,7 +291,7 @@ int srslte_ofdm_rx_init(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, cf_t return srslte_ofdm_init_(q, cp, in_buffer, out_buffer, symbol_sz, max_prb, SRSLTE_DFT_FORWARD); } -int srslte_ofdm_rx_init_mbsfn(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, cf_t *out_buffer, uint32_t max_prb) +int srslte_ofdm_rx_init_mbsfn(srslte_ofdm_t* q, srslte_cp_t cp, cf_t* in_buffer, cf_t* out_buffer, uint32_t max_prb) { int symbol_sz = srslte_symbol_sz(max_prb); if (symbol_sz < 0) { @@ -253,25 +302,24 @@ int srslte_ofdm_rx_init_mbsfn(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, return srslte_ofdm_init_mbsfn_(q, cp, in_buffer, out_buffer, symbol_sz, max_prb, SRSLTE_DFT_FORWARD, SRSLTE_SF_MBSFN); } - -int srslte_ofdm_tx_init(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, cf_t *out_buffer, uint32_t max_prb) { +int srslte_ofdm_tx_init(srslte_ofdm_t* q, srslte_cp_t cp, cf_t* in_buffer, cf_t* out_buffer, uint32_t max_prb) +{ uint32_t i; - int ret; - + int ret; + int symbol_sz = srslte_symbol_sz(max_prb); if (symbol_sz < 0) { ERROR("Error: Invalid nof_prb=%d\n", max_prb); return -1; } q->max_prb = max_prb; - ret = srslte_ofdm_init_(q, cp, in_buffer, out_buffer, symbol_sz, max_prb, SRSLTE_DFT_BACKWARD); + ret = srslte_ofdm_init_(q, cp, in_buffer, out_buffer, symbol_sz, max_prb, SRSLTE_DFT_BACKWARD); - if (ret == SRSLTE_SUCCESS) { srslte_dft_plan_set_norm(&q->fft_plan, false); - + /* set now zeros at CP */ - for (i=0;inof_symbols;i++) { + for (i = 0; i < q->nof_symbols; i++) { bzero(q->tmp, q->nof_guards * sizeof(cf_t)); bzero(&q->tmp[q->nof_re + q->nof_guards], q->nof_guards * sizeof(cf_t)); } @@ -279,11 +327,11 @@ int srslte_ofdm_tx_init(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, cf_t return ret; } -int srslte_ofdm_tx_init_mbsfn(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, cf_t *out_buffer, uint32_t nof_prb) +int srslte_ofdm_tx_init_mbsfn(srslte_ofdm_t* q, srslte_cp_t cp, cf_t* in_buffer, cf_t* out_buffer, uint32_t nof_prb) { uint32_t i; - int ret; - + int ret; + int symbol_sz = srslte_symbol_sz(nof_prb); if (symbol_sz < 0) { ERROR("Error: Invalid nof_prb=%d\n", nof_prb); @@ -291,12 +339,12 @@ int srslte_ofdm_tx_init_mbsfn(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, } q->max_prb = nof_prb; ret = srslte_ofdm_init_mbsfn_(q, cp, in_buffer, out_buffer, symbol_sz, nof_prb, SRSLTE_DFT_BACKWARD, SRSLTE_SF_MBSFN); - + if (ret == SRSLTE_SUCCESS) { srslte_dft_plan_set_norm(&q->fft_plan, false); - + /* set now zeros at CP */ - for (i=0;inof_symbols;i++) { + for (i = 0; i < q->nof_symbols; i++) { bzero(q->tmp, q->nof_guards * sizeof(cf_t)); bzero(&q->tmp[q->nof_re + q->nof_guards], q->nof_guards * sizeof(cf_t)); } @@ -304,7 +352,8 @@ int srslte_ofdm_tx_init_mbsfn(srslte_ofdm_t *q, srslte_cp_t cp, cf_t *in_buffer, return ret; } -int srslte_ofdm_rx_set_prb(srslte_ofdm_t *q, srslte_cp_t cp, uint32_t nof_prb) { +int srslte_ofdm_rx_set_prb(srslte_ofdm_t* q, srslte_cp_t cp, uint32_t nof_prb) +{ if (nof_prb <= q->max_prb) { int symbol_sz = srslte_symbol_sz(nof_prb); if (symbol_sz < 0) { @@ -320,9 +369,10 @@ int srslte_ofdm_rx_set_prb(srslte_ofdm_t *q, srslte_cp_t cp, uint32_t nof_prb) { } } -int srslte_ofdm_tx_set_prb(srslte_ofdm_t *q, srslte_cp_t cp, uint32_t nof_prb) { +int srslte_ofdm_tx_set_prb(srslte_ofdm_t* q, srslte_cp_t cp, uint32_t nof_prb) +{ uint32_t i; - int ret; + int ret; if (nof_prb <= q->max_prb) { int symbol_sz = srslte_symbol_sz(nof_prb); @@ -335,7 +385,7 @@ int srslte_ofdm_tx_set_prb(srslte_ofdm_t *q, srslte_cp_t cp, uint32_t nof_prb) { if (ret == SRSLTE_SUCCESS) { /* set now zeros at CP */ - for (i=0;inof_symbols;i++) { + for (i = 0; i < q->nof_symbols; i++) { bzero(q->tmp, q->nof_guards * sizeof(cf_t)); bzero(&q->tmp[q->nof_re + q->nof_guards], q->nof_guards * sizeof(cf_t)); } @@ -349,42 +399,45 @@ int srslte_ofdm_tx_set_prb(srslte_ofdm_t *q, srslte_cp_t cp, uint32_t nof_prb) { } } - -void srslte_ofdm_rx_free(srslte_ofdm_t *q) { +void srslte_ofdm_rx_free(srslte_ofdm_t* q) +{ srslte_ofdm_free_(q); } -/* Shifts the signal after the iFFT or before the FFT. +/* Shifts the signal after the iFFT or before the FFT. * Freq_shift is relative to inter-carrier spacing. - * Caution: This function shall not be called during run-time + * Caution: This function shall not be called during run-time */ -int srslte_ofdm_set_freq_shift(srslte_ofdm_t *q, float freq_shift) { - cf_t *ptr = q->shift_buffer; - for (uint32_t n=0;n<2;n++) { - for (uint32_t i=0;inof_symbols;i++) { - uint32_t cplen = SRSLTE_CP_ISNORM(q->cp)?SRSLTE_CP_LEN_NORM(i, q->symbol_sz):SRSLTE_CP_LEN_EXT(q->symbol_sz); - for (uint32_t t=0;tsymbol_sz+cplen;t++) { - ptr[t] = cexpf(I*2*M_PI*((float) t-(float)cplen)*freq_shift/q->symbol_sz); +int srslte_ofdm_set_freq_shift(srslte_ofdm_t* q, float freq_shift) +{ + cf_t* ptr = q->shift_buffer; + for (uint32_t n = 0; n < 2; n++) { + for (uint32_t i = 0; i < q->nof_symbols; i++) { + uint32_t cplen = SRSLTE_CP_ISNORM(q->cp) ? SRSLTE_CP_LEN_NORM(i, q->symbol_sz) : SRSLTE_CP_LEN_EXT(q->symbol_sz); + for (uint32_t t = 0; t < q->symbol_sz + cplen; t++) { + ptr[t] = cexpf(I * 2 * M_PI * ((float)t - (float)cplen) * freq_shift / q->symbol_sz); } - ptr += q->symbol_sz+cplen; - } + ptr += q->symbol_sz + cplen; + } } - + /* Disable DC carrier addition */ - srslte_dft_plan_set_dc(&q->fft_plan, false); - - q->freq_shift = true; + srslte_dft_plan_set_dc(&q->fft_plan, false); + + q->freq_shift = true; q->freq_shift_f = freq_shift; return SRSLTE_SUCCESS; } -void srslte_ofdm_tx_free(srslte_ofdm_t *q) { +void srslte_ofdm_tx_free(srslte_ofdm_t* q) +{ srslte_ofdm_free_(q); } -void srslte_ofdm_rx_slot_ng(srslte_ofdm_t *q, cf_t *input, cf_t *output) { +void srslte_ofdm_rx_slot_ng(srslte_ofdm_t* q, cf_t* input, cf_t* output) +{ uint32_t i; - for (i=0;inof_symbols;i++) { - input += SRSLTE_CP_ISNORM(q->cp)?SRSLTE_CP_LEN_NORM(i, q->symbol_sz):SRSLTE_CP_LEN_EXT(q->symbol_sz); + for (i = 0; i < q->nof_symbols; i++) { + input += SRSLTE_CP_ISNORM(q->cp) ? SRSLTE_CP_LEN_NORM(i, q->symbol_sz) : SRSLTE_CP_LEN_EXT(q->symbol_sz); srslte_dft_run_c(&q->fft_plan, input, q->tmp); memcpy(output, &q->tmp[q->nof_guards], q->nof_re * sizeof(cf_t)); input += q->symbol_sz; @@ -395,15 +448,17 @@ void srslte_ofdm_rx_slot_ng(srslte_ofdm_t *q, cf_t *input, cf_t *output) { /* Transforms input samples into output OFDM symbols. * Performs FFT on a each symbol and removes CP. */ -void srslte_ofdm_rx_slot(srslte_ofdm_t *q, int slot_in_sf) { - cf_t *output = q->out_buffer + slot_in_sf * q->nof_re * q->nof_symbols; +void srslte_ofdm_rx_slot(srslte_ofdm_t* q, int slot_in_sf) +{ + cf_t* output = q->out_buffer + slot_in_sf * q->nof_re * q->nof_symbols; #ifdef AVOID_GURU - srslte_ofdm_rx_slot_ng(q, q->in_buffer + slot_in_sf * q->slot_sz, q->out_buffer + slot_in_sf * q->nof_re * q->nof_symbols); + srslte_ofdm_rx_slot_ng( + q, q->in_buffer + slot_in_sf * q->slot_sz, q->out_buffer + slot_in_sf * q->nof_re * q->nof_symbols); #else - float norm = 1.0f/sqrtf(q->fft_plan.size); - cf_t *tmp = q->tmp + slot_in_sf * q->symbol_sz * q->nof_symbols; - uint32_t dc = (q->fft_plan.dc) ? 1:0; + float norm = 1.0f / sqrtf(q->fft_plan.size); + cf_t* tmp = q->tmp + slot_in_sf * q->symbol_sz * q->nof_symbols; + uint32_t dc = (q->fft_plan.dc) ? 1 : 0; srslte_dft_run_guru_c(&q->fft_plan_sf[slot_in_sf]); @@ -421,14 +476,14 @@ void srslte_ofdm_rx_slot(srslte_ofdm_t *q, int slot_in_sf) { #endif } -void srslte_ofdm_rx_slot_mbsfn(srslte_ofdm_t *q, cf_t *input, cf_t *output) +void srslte_ofdm_rx_slot_mbsfn(srslte_ofdm_t* q, cf_t* input, cf_t* output) { uint32_t i; - for(i = 0; i < q->nof_symbols_mbsfn; i++){ - if(i == q->non_mbsfn_region) { - input += SRSLTE_NON_MBSFN_REGION_GUARD_LENGTH(q->non_mbsfn_region,q->symbol_sz); + for (i = 0; i < q->nof_symbols_mbsfn; i++) { + if (i == q->non_mbsfn_region) { + input += SRSLTE_NON_MBSFN_REGION_GUARD_LENGTH(q->non_mbsfn_region, q->symbol_sz); } - input += (i>=q->non_mbsfn_region)?SRSLTE_CP_LEN_EXT(q->symbol_sz):SRSLTE_CP_LEN_NORM(i, q->symbol_sz); + input += (i >= q->non_mbsfn_region) ? SRSLTE_CP_LEN_EXT(q->symbol_sz) : SRSLTE_CP_LEN_NORM(i, q->symbol_sz); srslte_dft_run_c(&q->fft_plan, input, q->tmp); memcpy(output, &q->tmp[q->nof_guards], q->nof_re * sizeof(cf_t)); input += q->symbol_sz; @@ -436,46 +491,47 @@ void srslte_ofdm_rx_slot_mbsfn(srslte_ofdm_t *q, cf_t *input, cf_t *output) } } - - -void srslte_ofdm_rx_slot_zerocopy(srslte_ofdm_t *q, cf_t *input, cf_t *output) { +void srslte_ofdm_rx_slot_zerocopy(srslte_ofdm_t* q, cf_t* input, cf_t* output) +{ uint32_t i; - for (i=0;inof_symbols;i++) { - input += SRSLTE_CP_ISNORM(q->cp)?SRSLTE_CP_LEN_NORM(i, q->symbol_sz):SRSLTE_CP_LEN_EXT(q->symbol_sz); + for (i = 0; i < q->nof_symbols; i++) { + input += SRSLTE_CP_ISNORM(q->cp) ? SRSLTE_CP_LEN_NORM(i, q->symbol_sz) : SRSLTE_CP_LEN_EXT(q->symbol_sz); srslte_dft_run_c_zerocopy(&q->fft_plan, input, q->tmp); - memcpy(output, &q->tmp[q->symbol_sz/2+q->nof_guards], sizeof(cf_t)*q->nof_re/2); - memcpy(&output[q->nof_re/2], &q->tmp[1], sizeof(cf_t)*q->nof_re/2); + memcpy(output, &q->tmp[q->symbol_sz / 2 + q->nof_guards], sizeof(cf_t) * q->nof_re / 2); + memcpy(&output[q->nof_re / 2], &q->tmp[1], sizeof(cf_t) * q->nof_re / 2); input += q->symbol_sz; output += q->nof_re; - } + } } -void srslte_ofdm_rx_sf(srslte_ofdm_t *q) { +void srslte_ofdm_rx_sf(srslte_ofdm_t* q) +{ uint32_t n; if (q->freq_shift) { - srslte_vec_prod_ccc(q->in_buffer, q->shift_buffer, q->in_buffer, 2*q->slot_sz); + srslte_vec_prod_ccc(q->in_buffer, q->shift_buffer, q->in_buffer, 2 * q->slot_sz); } if (!q->mbsfn_subframe) { - for (n=0;n<2;n++) { + for (n = 0; n < 2; n++) { srslte_ofdm_rx_slot(q, n); } } else { - srslte_ofdm_rx_slot_mbsfn(q, &q->in_buffer[0*q->slot_sz], &q->out_buffer[0*q->nof_re*q->nof_symbols]); + srslte_ofdm_rx_slot_mbsfn(q, &q->in_buffer[0 * q->slot_sz], &q->out_buffer[0 * q->nof_re * q->nof_symbols]); srslte_ofdm_rx_slot(q, 1); } } -void srslte_ofdm_rx_sf_ng(srslte_ofdm_t *q, cf_t *input, cf_t *output) { +void srslte_ofdm_rx_sf_ng(srslte_ofdm_t* q, cf_t* input, cf_t* output) +{ uint32_t n; if (q->freq_shift) { - srslte_vec_prod_ccc(input, q->shift_buffer, input, 2*q->slot_sz); + srslte_vec_prod_ccc(input, q->shift_buffer, input, 2 * q->slot_sz); } if (!q->mbsfn_subframe) { - for (n=0;n<2;n++) { - srslte_ofdm_rx_slot_ng(q, &input[n*q->slot_sz], &output[n*q->nof_re*q->nof_symbols]); + for (n = 0; n < 2; n++) { + srslte_ofdm_rx_slot_ng(q, &input[n * q->slot_sz], &output[n * q->nof_re * q->nof_symbols]); } } else { - srslte_ofdm_rx_slot_mbsfn(q, &q->in_buffer[0*q->slot_sz], &q->out_buffer[0*q->nof_re*q->nof_symbols]); + srslte_ofdm_rx_slot_mbsfn(q, &q->in_buffer[0 * q->slot_sz], &q->out_buffer[0 * q->nof_re * q->nof_symbols]); srslte_ofdm_rx_slot(q, 1); } } @@ -483,13 +539,14 @@ void srslte_ofdm_rx_sf_ng(srslte_ofdm_t *q, cf_t *input, cf_t *output) { /* Transforms input OFDM symbols into output samples. * Performs FFT on a each symbol and adds CP. */ -void srslte_ofdm_tx_slot(srslte_ofdm_t *q, int slot_in_sf) { - cf_t *input = q->in_buffer + slot_in_sf * q->nof_re * q->nof_symbols; - cf_t *output = q->out_buffer + slot_in_sf * q->slot_sz; +void srslte_ofdm_tx_slot(srslte_ofdm_t* q, int slot_in_sf) +{ + cf_t* input = q->in_buffer + slot_in_sf * q->nof_re * q->nof_symbols; + cf_t* output = q->out_buffer + slot_in_sf * q->slot_sz; #ifdef AVOID_GURU - for (int i=0;inof_symbols;i++) { - int cp_len = SRSLTE_CP_ISNORM(q->cp)?SRSLTE_CP_LEN_NORM(i, q->symbol_sz):SRSLTE_CP_LEN_EXT(q->symbol_sz); + for (int i = 0; i < q->nof_symbols; i++) { + int cp_len = SRSLTE_CP_ISNORM(q->cp) ? SRSLTE_CP_LEN_NORM(i, q->symbol_sz) : SRSLTE_CP_LEN_EXT(q->symbol_sz); memcpy(&q->tmp[q->nof_guards], input, q->nof_re * sizeof(cf_t)); srslte_dft_run_c(&q->fft_plan, q->tmp, &output[cp_len]); input += q->nof_re; @@ -498,11 +555,11 @@ void srslte_ofdm_tx_slot(srslte_ofdm_t *q, int slot_in_sf) { output += q->symbol_sz + cp_len; } #else - float norm = 1.0f/sqrtf(q->symbol_sz); - cf_t *tmp = q->tmp + slot_in_sf * q->symbol_sz * q->nof_symbols; + float norm = 1.0f / sqrtf(q->symbol_sz); + cf_t* tmp = q->tmp + slot_in_sf * q->symbol_sz * q->nof_symbols; bzero(tmp, q->slot_sz); - uint32_t dc = (q->fft_plan.dc) ? 1:0; + uint32_t dc = (q->fft_plan.dc) ? 1 : 0; for (int i = 0; i < q->nof_symbols; i++) { memcpy(&tmp[dc], &input[q->nof_re / 2], q->nof_re / 2 * sizeof(cf_t)); @@ -514,7 +571,7 @@ void srslte_ofdm_tx_slot(srslte_ofdm_t *q, int slot_in_sf) { srslte_dft_run_guru_c(&q->fft_plan_sf[slot_in_sf]); - for (int i=0;inof_symbols;i++) { + for (int i = 0; i < q->nof_symbols; i++) { int cp_len = SRSLTE_CP_ISNORM(q->cp) ? SRSLTE_CP_LEN_NORM(i, q->symbol_sz) : SRSLTE_CP_LEN_EXT(q->symbol_sz); if (q->fft_plan.norm) { @@ -553,33 +610,34 @@ void srslte_ofdm_tx_slot(srslte_ofdm_t *q, int slot_in_sf) { free(output2);/**/ } -void srslte_ofdm_tx_slot_mbsfn(srslte_ofdm_t *q, cf_t *input, cf_t *output) +void srslte_ofdm_tx_slot_mbsfn(srslte_ofdm_t* q, cf_t* input, cf_t* output) { uint32_t i, cp_len; - for(i=0;inof_symbols_mbsfn;i++) { - cp_len = ( i>(q->non_mbsfn_region-1) )?SRSLTE_CP_LEN_EXT(q->symbol_sz):SRSLTE_CP_LEN_NORM(i, q->symbol_sz); + for (i = 0; i < q->nof_symbols_mbsfn; i++) { + cp_len = (i > (q->non_mbsfn_region - 1)) ? SRSLTE_CP_LEN_EXT(q->symbol_sz) : SRSLTE_CP_LEN_NORM(i, q->symbol_sz); memcpy(&q->tmp[q->nof_guards], input, q->nof_re * sizeof(cf_t)); srslte_dft_run_c(&q->fft_plan, q->tmp, &output[cp_len]); input += q->nof_re; /* add CP */ memcpy(output, &output[q->symbol_sz], cp_len * sizeof(cf_t)); output += q->symbol_sz + cp_len; - + /*skip the small section between the non mbms region and the mbms region*/ - if(i == (q->non_mbsfn_region - 1)) - output += SRSLTE_NON_MBSFN_REGION_GUARD_LENGTH(q->non_mbsfn_region,q->symbol_sz); - } + if (i == (q->non_mbsfn_region - 1)) + output += SRSLTE_NON_MBSFN_REGION_GUARD_LENGTH(q->non_mbsfn_region, q->symbol_sz); + } } -void srslte_ofdm_set_normalize(srslte_ofdm_t *q, bool normalize_enable) { +void srslte_ofdm_set_normalize(srslte_ofdm_t* q, bool normalize_enable) +{ srslte_dft_plan_set_norm(&q->fft_plan, normalize_enable); } -void srslte_ofdm_tx_sf(srslte_ofdm_t *q) +void srslte_ofdm_tx_sf(srslte_ofdm_t* q) { uint32_t n; if (!q->mbsfn_subframe) { - for (n=0;n<2;n++) { + for (n = 0; n < 2; n++) { srslte_ofdm_tx_slot(q, n); } } else { @@ -587,7 +645,6 @@ void srslte_ofdm_tx_sf(srslte_ofdm_t *q) srslte_ofdm_tx_slot(q, 1); } if (q->freq_shift) { - srslte_vec_prod_ccc(q->out_buffer, q->shift_buffer, q->out_buffer, 2*q->slot_sz); + srslte_vec_prod_ccc(q->out_buffer, q->shift_buffer, q->out_buffer, 2 * q->slot_sz); } } - diff --git a/lib/src/phy/dft/test/ofdm_test.c b/lib/src/phy/dft/test/ofdm_test.c index 70523c360..a82163226 100644 --- a/lib/src/phy/dft/test/ofdm_test.c +++ b/lib/src/phy/dft/test/ofdm_test.c @@ -19,78 +19,82 @@ * */ +#include #include #include #include #include #include -#include #include "srslte/srslte.h" -int nof_prb = -1; -srslte_cp_t cp = SRSLTE_CP_NORM; -int nof_repetitions = 128; +int nof_prb = -1; +srslte_cp_t cp = SRSLTE_CP_NORM; +int nof_repetitions = 128; -static double elapsed_us(struct timeval *ts_start, struct timeval *ts_end) { +static double elapsed_us(struct timeval* ts_start, struct timeval* ts_end) +{ if (ts_end->tv_usec > ts_start->tv_usec) { - return ((double) ts_end->tv_sec - (double) ts_start->tv_sec) * 1000000 + - (double) ts_end->tv_usec - (double) ts_start->tv_usec; + return ((double)ts_end->tv_sec - (double)ts_start->tv_sec) * 1000000 + (double)ts_end->tv_usec - + (double)ts_start->tv_usec; } else { - return ((double) ts_end->tv_sec - (double) ts_start->tv_sec - 1) * 1000000 + - ((double) ts_end->tv_usec + 1000000) - (double) ts_start->tv_usec; + return ((double)ts_end->tv_sec - (double)ts_start->tv_sec - 1) * 1000000 + ((double)ts_end->tv_usec + 1000000) - + (double)ts_start->tv_usec; } } -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s\n", prog); printf("\t-n nof_prb [Default All]\n"); printf("\t-e extended cyclic prefix [Default Normal]\n"); printf("\t-r nof_repetitions [Default %d]\n", nof_repetitions); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "ner")) != -1) { switch (opt) { - case 'n': - nof_prb = (int)strtol(argv[optind], NULL, 10); - break; - case 'e': - cp = SRSLTE_CP_EXT; - break; - case 'r': - nof_repetitions = (int)strtol(argv[optind], NULL, 10); - break; - default: - usage(argv[0]); - exit(-1); + case 'n': + nof_prb = (int)strtol(argv[optind], NULL, 10); + break; + case 'e': + cp = SRSLTE_CP_EXT; + break; + case 'r': + nof_repetitions = (int)strtol(argv[optind], NULL, 10); + break; + default: + usage(argv[0]); + exit(-1); } } } - -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ struct timeval start, end; - srslte_ofdm_t fft, ifft; - cf_t *input, *outfft, *outifft; - float mse; - int n_prb, max_prb, n_re; - int i; + srslte_ofdm_t fft, ifft; + cf_t * input, *outfft, *outifft; + float mse; + int n_prb, max_prb, n_re; + int i; parse_args(argc, argv); if (nof_prb == -1) { - n_prb = 6; + n_prb = 6; max_prb = 100; } else { - n_prb = nof_prb; + n_prb = nof_prb; max_prb = nof_prb; } - while(n_prb <= max_prb) { + while (n_prb <= max_prb) { n_re = SRSLTE_CP_NSYMB(cp) * n_prb * SRSLTE_NRE; - printf("Running test for %d PRB, %d RE... ", n_prb, n_re);fflush(stdout); + printf("Running test for %d PRB, %d RE... ", n_prb, n_re); + fflush(stdout); input = srslte_vec_malloc(sizeof(cf_t) * n_re * 2); if (!input) { @@ -121,31 +125,42 @@ int main(int argc, char **argv) { } srslte_ofdm_set_normalize(&ifft, true); - for (i=0;i 1.0f) printf("%04d. %+.1f%+.1fi Vs. %+.1f%+.1f %+.1f%+.1f (mse=%f)\n", i, __real__ input[i], __imag__ input[i], __real__ outifft[i], __imag__ outifft[i], __real__ outfft[i], __imag__ outfft[i], mse); + mse += (__real__ error * __real__ error + __imag__ error * __imag__ error) / cabsf(input[i]); + if (mse > 1.0f) + printf("%04d. %+.1f%+.1fi Vs. %+.1f%+.1f %+.1f%+.1f (mse=%f)\n", + i, + __real__ input[i], + __imag__ input[i], + __real__ outifft[i], + __imag__ outifft[i], + __real__ outfft[i], + __imag__ outfft[i], + mse); } /*for (i=0;i #include -#define CURRENT_FFTSIZE srslte_symbol_sz(q->cell.nof_prb) -#define CURRENT_SFLEN SRSLTE_SF_LEN(CURRENT_FFTSIZE) +#define CURRENT_FFTSIZE srslte_symbol_sz(q->cell.nof_prb) +#define CURRENT_SFLEN SRSLTE_SF_LEN(CURRENT_FFTSIZE) #define CURRENT_SLOTLEN_RE SRSLTE_SLOT_LEN_RE(q->cell.nof_prb, q->cell.cp) #define CURRENT_SFLEN_RE SRSLTE_NOF_RE(q->cell) #define SRSLTE_ENB_RF_AMP 0.1 -int srslte_enb_dl_init(srslte_enb_dl_t *q, cf_t *out_buffer[SRSLTE_MAX_PORTS], uint32_t max_prb) +int srslte_enb_dl_init(srslte_enb_dl_t* q, cf_t* out_buffer[SRSLTE_MAX_PORTS], uint32_t max_prb) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; - - if (q != NULL) - { + int ret = SRSLTE_ERROR_INVALID_INPUTS; + + if (q != NULL) { ret = SRSLTE_ERROR; - + bzero(q, sizeof(srslte_enb_dl_t)); - for (int i=0;isf_symbols[i] = srslte_vec_malloc(SRSLTE_SF_LEN_RE(max_prb, SRSLTE_CP_NORM) * sizeof(cf_t)); if (!q->sf_symbols[i]) { perror("malloc"); @@ -103,19 +102,19 @@ int srslte_enb_dl_init(srslte_enb_dl_t *q, cf_t *out_buffer[SRSLTE_MAX_PORTS], u goto clean_exit; } ret = SRSLTE_SUCCESS; - + } else { ERROR("Invalid parameters\n"); } -clean_exit: +clean_exit: if (ret == SRSLTE_ERROR) { srslte_enb_dl_free(q); } return ret; } -void srslte_enb_dl_free(srslte_enb_dl_t *q) +void srslte_enb_dl_free(srslte_enb_dl_t* q) { if (q) { for (int i = 0; i < SRSLTE_MAX_PORTS; i++) { @@ -131,22 +130,20 @@ void srslte_enb_dl_free(srslte_enb_dl_t *q) srslte_pmch_free(&q->pmch); srslte_refsignal_free(&q->csr_signal); srslte_refsignal_free(&q->mbsfnr_signal); - for (int i=0;isf_symbols[i]) { free(q->sf_symbols[i]); } } bzero(q, sizeof(srslte_enb_dl_t)); - } + } } -int srslte_enb_dl_set_cell(srslte_enb_dl_t *q, srslte_cell_t cell) +int srslte_enb_dl_set_cell(srslte_enb_dl_t* q, srslte_cell_t cell) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - srslte_cell_isvalid(&cell)) - { + if (q != NULL && srslte_cell_isvalid(&cell)) { if (q->cell.id != cell.id || q->cell.nof_prb == 0) { if (q->cell.nof_prb != 0) { srslte_regs_free(&q->regs); @@ -162,7 +159,7 @@ int srslte_enb_dl_set_cell(srslte_enb_dl_t *q, srslte_cell_t cell) return SRSLTE_ERROR; } } - + if (srslte_ofdm_tx_set_prb(&q->ifft_mbsfn, SRSLTE_CP_EXT, q->cell.nof_prb)) { ERROR("Error re-planning ifft_mbsfn\n"); return SRSLTE_ERROR; @@ -208,7 +205,7 @@ int srslte_enb_dl_set_cell(srslte_enb_dl_t *q, srslte_cell_t cell) return SRSLTE_ERROR; } /* Generate PSS/SSS signals */ - srslte_pss_generate(q->pss_signal, cell.id%3); + srslte_pss_generate(q->pss_signal, cell.id % 3); srslte_sss_generate(q->sss_signal0, q->sss_signal5, cell.id); } ret = SRSLTE_SUCCESS; @@ -230,16 +227,16 @@ void srslte_enb_dl_rem_rnti(srslte_enb_dl_t* q, uint16_t rnti) } #ifdef resolve -void srslte_enb_dl_apply_power_allocation(srslte_enb_dl_t *q) +void srslte_enb_dl_apply_power_allocation(srslte_enb_dl_t* q) { uint32_t nof_symbols_slot = SRSLTE_CP_NSYMB(q->cell.cp); - uint32_t nof_re_symbol = SRSLTE_NRE * q->cell.nof_prb; + uint32_t nof_re_symbol = SRSLTE_NRE * q->cell.nof_prb; if (q->rho_b != 0.0f && q->rho_b != 1.0f) { float scaling = q->rho_b; for (uint32_t i = 0; i < q->cell.nof_ports; i++) { for (uint32_t j = 0; j < 2; j++) { - cf_t *ptr; + cf_t* ptr; ptr = q->sf_symbols[i] + nof_re_symbol * (j * nof_symbols_slot + 0); srslte_vec_sc_prod_cfc(ptr, scaling, ptr, nof_re_symbol); if (q->cell.cp == SRSLTE_CP_NORM) { @@ -258,16 +255,16 @@ void srslte_enb_dl_apply_power_allocation(srslte_enb_dl_t *q) } } -void srslte_enb_dl_prepare_power_allocation(srslte_enb_dl_t *q) +void srslte_enb_dl_prepare_power_allocation(srslte_enb_dl_t* q) { uint32_t nof_symbols_slot = SRSLTE_CP_NSYMB(q->cell.cp); - uint32_t nof_re_symbol = SRSLTE_NRE * q->cell.nof_prb; + uint32_t nof_re_symbol = SRSLTE_NRE * q->cell.nof_prb; if (q->rho_b != 0.0f && q->rho_b != 1.0f) { float scaling = 1.0f / q->rho_b; for (uint32_t i = 0; i < q->cell.nof_ports; i++) { for (uint32_t j = 0; j < 2; j++) { - cf_t *ptr; + cf_t* ptr; ptr = q->sf_symbols[i] + nof_re_symbol * (j * nof_symbols_slot + 0); srslte_vec_sc_prod_cfc(ptr, scaling, ptr, nof_re_symbol); if (q->cell.cp == SRSLTE_CP_NORM) { @@ -302,10 +299,9 @@ static void put_sync(srslte_enb_dl_t* q) if (sf_idx == 0 || sf_idx == 5) { for (int p = 0; p < q->cell.nof_ports; p++) { srslte_pss_put_slot(q->pss_signal, q->sf_symbols[p], q->cell.nof_prb, q->cell.cp); - srslte_sss_put_slot(sf_idx ? q->sss_signal5 : q->sss_signal0, q->sf_symbols[p], - q->cell.nof_prb, q->cell.cp); + srslte_sss_put_slot(sf_idx ? q->sss_signal5 : q->sss_signal0, q->sf_symbols[p], q->cell.nof_prb, q->cell.cp); } - } + } } static void put_refs(srslte_enb_dl_t* q) @@ -417,8 +413,11 @@ void srslte_enb_dl_gen_signal(srslte_enb_dl_t* q) } } -bool srslte_enb_dl_gen_cqi_periodic( - srslte_cell_t* cell, srslte_dl_cfg_t* dl_cfg, uint32_t tti, uint32_t ri, srslte_cqi_cfg_t* cqi_cfg) +bool srslte_enb_dl_gen_cqi_periodic(srslte_cell_t* cell, + srslte_dl_cfg_t* dl_cfg, + uint32_t tti, + uint32_t ri, + srslte_cqi_cfg_t* cqi_cfg) { bool cqi_enabled = false; if (srslte_cqi_periodic_ri_send(&dl_cfg->cqi_report, tti, cell->frame_type)) { diff --git a/lib/src/phy/enb/enb_ul.c b/lib/src/phy/enb/enb_ul.c index 8ec178ce5..e5830bee5 100644 --- a/lib/src/phy/enb/enb_ul.c +++ b/lib/src/phy/enb/enb_ul.c @@ -26,15 +26,13 @@ #include #include -#define CURRENT_FFTSIZE srslte_symbol_sz(q->cell.nof_prb) -#define CURRENT_SFLEN SRSLTE_SF_LEN(CURRENT_FFTSIZE) +#define CURRENT_FFTSIZE srslte_symbol_sz(q->cell.nof_prb) +#define CURRENT_SFLEN SRSLTE_SF_LEN(CURRENT_FFTSIZE) #define CURRENT_SLOTLEN_RE SRSLTE_SLOT_LEN_RE(q->cell.nof_prb, q->cell.cp) #define CURRENT_SFLEN_RE SRSLTE_NOF_RE(q->cell) -int srslte_enb_ul_init(srslte_enb_ul_t *q, - cf_t *in_buffer, - uint32_t max_prb) +int srslte_enb_ul_init(srslte_enb_ul_t* q, cf_t* in_buffer, uint32_t max_prb) { int ret = SRSLTE_ERROR_INVALID_INPUTS; @@ -90,7 +88,7 @@ clean_exit: return ret; } -void srslte_enb_ul_free(srslte_enb_ul_t *q) +void srslte_enb_ul_free(srslte_enb_ul_t* q) { if (q) { @@ -148,7 +146,7 @@ int srslte_enb_ul_set_cell(srslte_enb_ul_t* q, srslte_cell_t cell, srslte_refsig return ret; } -int srslte_enb_ul_add_rnti(srslte_enb_ul_t *q, uint16_t rnti) +int srslte_enb_ul_add_rnti(srslte_enb_ul_t* q, uint16_t rnti) { if (srslte_pucch_set_rnti(&q->pucch, rnti)) { ERROR("Error setting PUCCH rnti\n"); @@ -167,7 +165,7 @@ void srslte_enb_ul_rem_rnti(srslte_enb_ul_t* q, uint16_t rnti) srslte_pusch_free_rnti(&q->pusch, rnti); } -void srslte_enb_ul_fft(srslte_enb_ul_t *q) +void srslte_enb_ul_fft(srslte_enb_ul_t* q) { srslte_ofdm_rx_sf(&q->fft); } diff --git a/lib/src/phy/fec/cbsegm.c b/lib/src/phy/fec/cbsegm.c index 3a723cfcc..98e338369 100644 --- a/lib/src/phy/fec/cbsegm.c +++ b/lib/src/phy/fec/cbsegm.c @@ -19,29 +19,24 @@ * */ -#include #include +#include -#include "srslte/phy/fec/turbodecoder_gen.h" #include "srslte/phy/fec/cbsegm.h" +#include "srslte/phy/fec/turbodecoder_gen.h" #include "srslte/phy/utils/debug.h" - -const uint32_t tc_cb_sizes[SRSLTE_NOF_TC_CB_SIZES] = { 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, - 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, - 240, 248, 256, 264, 272, 280, 288, 296, 304, 312, 320, 328, 336, 344, - 352, 360, 368, 376, 384, 392, 400, 408, 416, 424, 432, 440, 448, 456, - 464, 472, 480, 488, 496, 504, 512, 528, 544, 560, 576, 592, 608, 624, - 640, 656, 672, 688, 704, 720, 736, 752, 768, 784, 800, 816, 832, 848, - 864, 880, 896, 912, 928, 944, 960, 976, 992, 1008, 1024, 1056, 1088, - 1120, 1152, 1184, 1216, 1248, 1280, 1312, 1344, 1376, 1408, 1440, 1472, - 1504, 1536, 1568, 1600, 1632, 1664, 1696, 1728, 1760, 1792, 1824, 1856, - 1888, 1920, 1952, 1984, 2016, 2048, 2112, 2176, 2240, 2304, 2368, 2432, - 2496, 2560, 2624, 2688, 2752, 2816, 2880, 2944, 3008, 3072, 3136, 3200, - 3264, 3328, 3392, 3456, 3520, 3584, 3648, 3712, 3776, 3840, 3904, 3968, - 4032, 4096, 4160, 4224, 4288, 4352, 4416, 4480, 4544, 4608, 4672, 4736, - 4800, 4864, 4928, 4992, 5056, 5120, 5184, 5248, 5312, 5376, 5440, 5504, - 5568, 5632, 5696, 5760, 5824, 5888, 5952, 6016, 6080, 6144 }; +const uint32_t tc_cb_sizes[SRSLTE_NOF_TC_CB_SIZES] = { + 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, + 192, 200, 208, 216, 224, 232, 240, 248, 256, 264, 272, 280, 288, 296, 304, 312, 320, 328, 336, + 344, 352, 360, 368, 376, 384, 392, 400, 408, 416, 424, 432, 440, 448, 456, 464, 472, 480, 488, + 496, 504, 512, 528, 544, 560, 576, 592, 608, 624, 640, 656, 672, 688, 704, 720, 736, 752, 768, + 784, 800, 816, 832, 848, 864, 880, 896, 912, 928, 944, 960, 976, 992, 1008, 1024, 1056, 1088, 1120, + 1152, 1184, 1216, 1248, 1280, 1312, 1344, 1376, 1408, 1440, 1472, 1504, 1536, 1568, 1600, 1632, 1664, 1696, 1728, + 1760, 1792, 1824, 1856, 1888, 1920, 1952, 1984, 2016, 2048, 2112, 2176, 2240, 2304, 2368, 2432, 2496, 2560, 2624, + 2688, 2752, 2816, 2880, 2944, 3008, 3072, 3136, 3200, 3264, 3328, 3392, 3456, 3520, 3584, 3648, 3712, 3776, 3840, + 3904, 3968, 4032, 4096, 4160, 4224, 4288, 4352, 4416, 4480, 4544, 4608, 4672, 4736, 4800, 4864, 4928, 4992, 5056, + 5120, 5184, 5248, 5312, 5376, 5440, 5504, 5568, 5632, 5696, 5760, 5824, 5888, 5952, 6016, 6080, 6144}; /** * Calculate Codeblock Segmentation parameters as in Section 5.1.2 of 36.212 @@ -50,55 +45,62 @@ const uint32_t tc_cb_sizes[SRSLTE_NOF_TC_CB_SIZES] = { 40, 48, 56, 64, 72, 80, 8 * @param[in] tbs Input Transport Block Size in bits. CRC's will be added to this * @return Error code */ -int srslte_cbsegm(srslte_cbsegm_t *s, uint32_t tbs) { +int srslte_cbsegm(srslte_cbsegm_t* s, uint32_t tbs) +{ uint32_t Bp, B, idx1; - int ret; + int ret; if (tbs == 0) { bzero(s, sizeof(srslte_cbsegm_t)); ret = SRSLTE_SUCCESS; } else { - B = tbs + 24; - s->tbs = tbs; - + B = tbs + 24; + s->tbs = tbs; + /* Calculate CB sizes */ if (B <= SRSLTE_TCOD_MAX_LEN_CB) { s->C = 1; - Bp = B; + Bp = B; } else { - s->C = (uint32_t) ceilf((float) B / (SRSLTE_TCOD_MAX_LEN_CB - 24)); - Bp = B + 24 * s->C; + s->C = (uint32_t)ceilf((float)B / (SRSLTE_TCOD_MAX_LEN_CB - 24)); + Bp = B + 24 * s->C; } - ret = srslte_cbsegm_cbindex((Bp-1) / s->C + 1); + ret = srslte_cbsegm_cbindex((Bp - 1) / s->C + 1); if (ret != SRSLTE_ERROR) { - idx1 = (uint32_t) ret; - ret = srslte_cbsegm_cbsize(idx1); + idx1 = (uint32_t)ret; + ret = srslte_cbsegm_cbsize(idx1); if (ret != SRSLTE_ERROR) { - s->K1 = (uint32_t) ret; + s->K1 = (uint32_t)ret; s->K1_idx = idx1; if (idx1 > 0) { - ret = srslte_cbsegm_cbsize(idx1 - 1); + ret = srslte_cbsegm_cbsize(idx1 - 1); } if (ret != SRSLTE_ERROR) { if (s->C == 1) { - s->K2 = 0; + s->K2 = 0; s->K2_idx = 0; - s->C2 = 0; - s->C1 = 1; + s->C2 = 0; + s->C1 = 1; } else { - s->K2 = (uint32_t) ret; - s->K2_idx = idx1-1; - s->C2 = (s->C * s->K1 - Bp) / (s->K1 - s->K2); - s->C1 = s->C - s->C2; + s->K2 = (uint32_t)ret; + s->K2_idx = idx1 - 1; + s->C2 = (s->C * s->K1 - Bp) / (s->K1 - s->K2); + s->C1 = s->C - s->C2; } s->F = s->C1 * s->K1 + s->C2 * s->K2 - Bp; INFO("CB Segmentation: TBS: %d, C=%d, C+=%d K+=%d, C-=%d, K-=%d, F=%d, Bp=%d\n", - tbs, s->C, s->C1, s->K1, s->C2, s->K2, s->F, Bp); - ret = SRSLTE_SUCCESS; + tbs, + s->C, + s->C1, + s->K1, + s->C2, + s->K2, + s->F, + Bp); + ret = SRSLTE_SUCCESS; } } - } - + } } return ret; } @@ -108,7 +110,8 @@ int srslte_cbsegm(srslte_cbsegm_t *s, uint32_t tbs) { * * @return I_TBS or error code */ -int srslte_cbsegm_cbindex(uint32_t long_cb) { +int srslte_cbsegm_cbindex(uint32_t long_cb) +{ int j = 0; while (j < SRSLTE_NOF_TC_CB_SIZES && tc_cb_sizes[j] < long_cb) { j++; @@ -126,9 +129,10 @@ int srslte_cbsegm_cbindex(uint32_t long_cb) { * * @return Code block size in bits or error code */ -int srslte_cbsegm_cbsize(uint32_t index) { +int srslte_cbsegm_cbsize(uint32_t index) +{ if (index < SRSLTE_NOF_TC_CB_SIZES) { - return (int) tc_cb_sizes[index]; + return (int)tc_cb_sizes[index]; } else { return SRSLTE_ERROR; } @@ -140,11 +144,12 @@ int srslte_cbsegm_cbsize(uint32_t index) { * @param[in] size Size of code block in bits * @return true if Code Block size is allowed */ -bool srslte_cbsegm_cbsize_isvalid(uint32_t size) { - for (int i=0;i -#include -#include #include +#include +#include +#include -#include "srslte/phy/fec/convcoder.h" #include "parity.h" +#include "srslte/phy/fec/convcoder.h" /** * Convolution encodes according to given parameters. @@ -40,19 +40,16 @@ * @param[in] frame_length Number of bits in input_array * @return Number of bits in output */ -int srslte_convcoder_encode(srslte_convcoder_t *q, uint8_t *input, uint8_t *output, uint32_t frame_length) { +int srslte_convcoder_encode(srslte_convcoder_t* q, uint8_t* input, uint8_t* output, uint32_t frame_length) +{ uint32_t sr; - uint32_t i,j; + uint32_t i, j; - if (q != NULL && - input != NULL && - output != NULL && - frame_length > q->K + 1) - { + if (q != NULL && input != NULL && output != NULL && frame_length > q->K + 1) { uint32_t len = q->tail_biting ? frame_length : (frame_length + q->K - 1); if (q->tail_biting) { sr = 0; - for (i=frame_length - q->K + 1; iK + 1; i < frame_length; i++) { sr = (sr << 1) | (input[i] & 1); } } else { @@ -60,14 +57,13 @@ int srslte_convcoder_encode(srslte_convcoder_t *q, uint8_t *input, uint8_t *outp } for (i = 0; i < len; i++) { uint8_t bit = (i < frame_length) ? (input[i] & 1) : 0; - sr = (sr << 1) | bit; - for (j=0;jR;j++) { + sr = (sr << 1) | bit; + for (j = 0; j < q->R; j++) { output[q->R * i + j] = parity(sr & q->poly[j]); } } - return q->R*len; + return q->R * len; } else { return SRSLTE_ERROR_INVALID_INPUTS; } } - diff --git a/lib/src/phy/fec/crc.c b/lib/src/phy/fec/crc.c index f0a90ba3c..e07159d27 100644 --- a/lib/src/phy/fec/crc.c +++ b/lib/src/phy/fec/crc.c @@ -27,13 +27,14 @@ #include "srslte/phy/utils/bit.h" #include "srslte/phy/utils/debug.h" -void gen_crc_table(srslte_crc_t *h) { +void gen_crc_table(srslte_crc_t* h) +{ - int i, j, ord = (h->order - 8); + int i, j, ord = (h->order - 8); uint64_t bit, crc; for (i = 0; i < 256; i++) { - crc = ((uint64_t) i) << ord; + crc = ((uint64_t)i) << ord; for (j = 0; j < 8; j++) { bit = crc & h->crchighbit; crc <<= 1; @@ -44,7 +45,8 @@ void gen_crc_table(srslte_crc_t *h) { } } -uint64_t reversecrcbit(uint32_t crc, int nbits, srslte_crc_t *h) { +uint64_t reversecrcbit(uint32_t crc, int nbits, srslte_crc_t* h) +{ uint64_t m, rmask = 0x1; @@ -57,7 +59,8 @@ uint64_t reversecrcbit(uint32_t crc, int nbits, srslte_crc_t *h) { return (crc & h->crcmask); } -int srslte_crc_set_init(srslte_crc_t *crc_par, uint64_t crc_init_value) { +int srslte_crc_set_init(srslte_crc_t* crc_par, uint64_t crc_init_value) +{ crc_par->crcinit = crc_init_value; if (crc_par->crcinit != (crc_par->crcinit & crc_par->crcmask)) { @@ -67,16 +70,17 @@ int srslte_crc_set_init(srslte_crc_t *crc_par, uint64_t crc_init_value) { return 0; } -int srslte_crc_init(srslte_crc_t *h, uint32_t crc_poly, int crc_order) { +int srslte_crc_init(srslte_crc_t* h, uint32_t crc_poly, int crc_order) +{ - // Set crc working default parameters + // Set crc working default parameters h->polynom = crc_poly; - h->order = crc_order; + h->order = crc_order; h->crcinit = 0x00000000; // Compute bit masks for whole CRC and CRC high bit - h->crcmask = ((((uint64_t) 1 << (h->order - 1)) - 1) << 1) | 1; - h->crchighbit = (uint64_t) 1 << (h->order - 1); + h->crcmask = ((((uint64_t)1 << (h->order - 1)) - 1) << 1) | 1; + h->crchighbit = (uint64_t)1 << (h->order - 1); // check parameters if (h->order % 8 != 0) { @@ -95,10 +99,11 @@ int srslte_crc_init(srslte_crc_t *h, uint32_t crc_poly, int crc_order) { return 0; } -uint32_t srslte_crc_checksum(srslte_crc_t *h, uint8_t *data, int len) { - int i, k, len8, res8, a = 0; +uint32_t srslte_crc_checksum(srslte_crc_t* h, uint8_t* data, int len) +{ + int i, k, len8, res8, a = 0; uint32_t crc = 0; - uint8_t *pter; + uint8_t* pter; srslte_crc_set_init(h, 0); @@ -111,53 +116,53 @@ uint32_t srslte_crc_checksum(srslte_crc_t *h, uint8_t *data, int len) { // Calculate CRC for (i = 0; i < len8 + a; i++) { - pter = (uint8_t *) (data + 8 * i); + pter = (uint8_t*)(data + 8 * i); uint8_t byte; if (i == len8) { byte = 0x00; for (k = 0; k < res8; k++) { - byte |= ((uint8_t) *(pter + k)) << (7 - k); + byte |= ((uint8_t) * (pter + k)) << (7 - k); } } else { - byte = (uint8_t) (srslte_bit_pack(&pter, 8) & 0xFF); + byte = (uint8_t)(srslte_bit_pack(&pter, 8) & 0xFF); } srslte_crc_checksum_put_byte(h, byte); } - crc = (uint32_t) srslte_crc_checksum_get(h); + crc = (uint32_t)srslte_crc_checksum_get(h); // Reverse CRC res8 positions if (a == 1) { crc = reversecrcbit(crc, 8 - res8, h); } - //Return CRC value + // Return CRC value return crc; - } // len is multiple of 8 -uint32_t srslte_crc_checksum_byte(srslte_crc_t *h, uint8_t *data, int len) { - int i; +uint32_t srslte_crc_checksum_byte(srslte_crc_t* h, uint8_t* data, int len) +{ + int i; uint32_t crc = 0; srslte_crc_set_init(h, 0); // Calculate CRC - for (i = 0; i < len/8; i++) { + for (i = 0; i < len / 8; i++) { srslte_crc_checksum_put_byte(h, data[i]); } - crc = (uint32_t) srslte_crc_checksum_get(h); + crc = (uint32_t)srslte_crc_checksum_get(h); return crc; - } -uint32_t srslte_crc_attach_byte(srslte_crc_t *h, uint8_t *data, int len) { +uint32_t srslte_crc_attach_byte(srslte_crc_t* h, uint8_t* data, int len) +{ uint32_t checksum = srslte_crc_checksum_byte(h, data, len); // Add CRC - for (int i=0;iorder/8;i++) { - data[len/8+(h->order/8-i-1)] = (checksum&(0xff<<(8*i)))>>(8*i); + for (int i = 0; i < h->order / 8; i++) { + data[len / 8 + (h->order / 8 - i - 1)] = (checksum & (0xff << (8 * i))) >> (8 * i); } return checksum; } @@ -165,12 +170,12 @@ uint32_t srslte_crc_attach_byte(srslte_crc_t *h, uint8_t *data, int len) { /** Appends crc_order checksum bits to the buffer data. * The buffer data must be len + crc_order bytes */ -uint32_t srslte_crc_attach(srslte_crc_t *h, uint8_t *data, int len) { +uint32_t srslte_crc_attach(srslte_crc_t* h, uint8_t* data, int len) +{ uint32_t checksum = srslte_crc_checksum(h, data, len); // Add CRC - uint8_t *ptr = &data[len]; + uint8_t* ptr = &data[len]; srslte_bit_unpack(checksum, &ptr, h->order); return checksum; } - diff --git a/lib/src/phy/fec/parity.c b/lib/src/phy/fec/parity.c index f775ec7ab..aa3f649f4 100644 --- a/lib/src/phy/fec/parity.c +++ b/lib/src/phy/fec/parity.c @@ -19,22 +19,23 @@ * */ -#include #include +#include -uint8_t Partab[256]; +uint8_t Partab[256]; uint32_t P_init; /* Create 256-entry odd-parity lookup table * Needed only on non-ia32 machines */ -void partab_init(void) { +void partab_init(void) +{ uint32_t i, cnt, ti; /* Initialize parity lookup table */ for (i = 0; i < 256; i++) { cnt = 0; - ti = i; + ti = i; while (ti) { if (ti & 1) cnt++; diff --git a/lib/src/phy/fec/parity.h b/lib/src/phy/fec/parity.h index 32f4c3623..493465988 100644 --- a/lib/src/phy/fec/parity.h +++ b/lib/src/phy/fec/parity.h @@ -19,31 +19,35 @@ * */ +#include + #ifdef __x86_64__ #define __i386__ #endif /* Determine parity of argument: 1 = odd, 0 = even */ #ifdef __i386__ -static inline uint32_t parityb(uint8_t x){ - __asm__ __volatile__ ("test %1,%1;setpo %0" : "=q" (x) : "q" (x)); +static inline uint32_t parityb(uint8_t x) +{ + __asm__ __volatile__("test %1,%1;setpo %0" : "=q"(x) : "q"(x)); return x; } #else void partab_init(); -static inline uint32_t parityb(uint8_t x){ - extern uint8_t Partab[256]; +static inline uint32_t parityb(uint8_t x) +{ + extern uint8_t Partab[256]; extern uint32_t P_init; - if(!P_init){ + if (!P_init) { partab_init(); } return Partab[x]; } #endif - -static inline uint32_t parity(int x){ +static inline uint32_t parity(int x) +{ /* Fold down to one byte */ x ^= (x >> 16); x ^= (x >> 8); diff --git a/lib/src/phy/fec/rm_conv.c b/lib/src/phy/fec/rm_conv.c index 1e8fa4e36..447ab3094 100644 --- a/lib/src/phy/fec/rm_conv.c +++ b/lib/src/phy/fec/rm_conv.c @@ -19,9 +19,9 @@ * */ -#include -#include #include +#include +#include #include "srslte/phy/fec/rm_conv.h" #include "srslte/phy/utils/debug.h" @@ -29,11 +29,10 @@ #define NCOLS 32 #define NROWS_MAX NCOLS -uint8_t RM_PERM_CC[NCOLS] = { 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, - 7, 23, 15, 31, 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30 }; -uint8_t RM_PERM_CC_INV[NCOLS] = - { 16, 0, 24, 8, 20, 4, 28, 12, 18, 2, 26, 10, 22, 6, 30, 14, 17, 1, 25, 9, - 21, 5, 29, 13, 19, 3, 27, 11, 23, 7, 31, 15 }; +uint8_t RM_PERM_CC[NCOLS] = {1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31, + 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30}; +uint8_t RM_PERM_CC_INV[NCOLS] = {16, 0, 24, 8, 20, 4, 28, 12, 18, 2, 26, 10, 22, 6, 30, 14, + 17, 1, 25, 9, 21, 5, 29, 13, 19, 3, 27, 11, 23, 7, 31, 15}; /** * Rate matching for convolution encoder @@ -41,19 +40,20 @@ uint8_t RM_PERM_CC_INV[NCOLS] = * @param[in] input Unpacked bit array. Size in_len * @param[output] output Unpacked bit array. Size out_len <= in_len */ -int srslte_rm_conv_tx(uint8_t *input, uint32_t in_len, uint8_t *output, uint32_t out_len) { +int srslte_rm_conv_tx(uint8_t* input, uint32_t in_len, uint8_t* output, uint32_t out_len) +{ uint8_t tmp[3 * NCOLS * NROWS_MAX]; - int nrows, ndummy, K_p; + int nrows, ndummy, K_p; int i, j, k, s; - nrows = (uint32_t) (in_len / 3 - 1) / NCOLS + 1; + nrows = (uint32_t)(in_len / 3 - 1) / NCOLS + 1; if (nrows > NROWS_MAX) { ERROR("Input too large. Max input length is %d\n", 3 * NCOLS * NROWS_MAX); return -1; } - K_p = nrows * NCOLS; + K_p = nrows * NCOLS; ndummy = K_p - in_len / 3; if (ndummy < 0) { ndummy = 0; @@ -91,15 +91,16 @@ int srslte_rm_conv_tx(uint8_t *input, uint32_t in_len, uint8_t *output, uint32_t /* Undoes Convolutional Code Rate Matching. * 3GPP TS 36.212 v10.1.0 section 5.1.4.2 */ -int srslte_rm_conv_rx(float *input, uint32_t in_len, float *output, uint32_t out_len) { +int srslte_rm_conv_rx(float* input, uint32_t in_len, float* output, uint32_t out_len) +{ int nrows, ndummy, K_p; int i, j, k; int d_i, d_j; float tmp[3 * NCOLS * NROWS_MAX]; - - nrows = (uint32_t) (out_len / 3 - 1) / NCOLS + 1; + + nrows = (uint32_t)(out_len / 3 - 1) / NCOLS + 1; if (nrows > NROWS_MAX) { ERROR("Output too large. Max output length is %d\n", 3 * NCOLS * NROWS_MAX); return -1; @@ -152,20 +153,21 @@ int srslte_rm_conv_rx(float *input, uint32_t in_len, float *output, uint32_t out return 0; } -/************* FIX THIS. MOVE ALL PROCESSING TO INT16 AND HAVE ONLY 1 IMPLEMENTATION ******/ +/************* FIX THIS. MOVE ALL PROCESSING TO INT16 AND HAVE ONLY 1 IMPLEMENTATION ******/ /* Undoes Convolutional Code Rate Matching. * 3GPP TS 36.212 v10.1.0 section 5.1.4.2 */ -int srslte_rm_conv_rx_s(int16_t *input, uint32_t in_len, int16_t *output, uint32_t out_len) { +int srslte_rm_conv_rx_s(int16_t* input, uint32_t in_len, int16_t* output, uint32_t out_len) +{ int nrows, ndummy, K_p; int i, j, k; int d_i, d_j; int16_t tmp[3 * NCOLS * NROWS_MAX]; - - nrows = (uint32_t) (out_len / 3 - 1) / NCOLS + 1; + + nrows = (uint32_t)(out_len / 3 - 1) / NCOLS + 1; if (nrows > NROWS_MAX) { ERROR("Output too large. Max output length is %d\n", 3 * NCOLS * NROWS_MAX); return -1; @@ -217,4 +219,3 @@ int srslte_rm_conv_rx_s(int16_t *input, uint32_t in_len, int16_t *output, uint32 } return 0; } - diff --git a/lib/src/phy/fec/rm_turbo.c b/lib/src/phy/fec/rm_turbo.c index 9d99d6974..5204e564d 100644 --- a/lib/src/phy/fec/rm_turbo.c +++ b/lib/src/phy/fec/rm_turbo.c @@ -19,12 +19,12 @@ * */ -#include -#include #include #include -#include #include +#include +#include +#include #include "srslte/phy/fec/cbsegm.h" #include "srslte/phy/fec/rm_turbo.h" @@ -34,40 +34,60 @@ #ifdef LV_HAVE_SSE #include -int srslte_rm_turbo_rx_lut_sse(int16_t *input, int16_t *output, uint16_t *deinter, uint32_t in_len, uint32_t cb_idx, uint32_t rv_idx); -int srslte_rm_turbo_rx_lut_sse_8bit(int8_t *input, int8_t *output, uint16_t *deinter, uint32_t in_len, uint32_t cb_idx, uint32_t rv_idx); +int srslte_rm_turbo_rx_lut_sse(int16_t* input, + int16_t* output, + uint16_t* deinter, + uint32_t in_len, + uint32_t cb_idx, + uint32_t rv_idx); +int srslte_rm_turbo_rx_lut_sse_8bit(int8_t* input, + int8_t* output, + uint16_t* deinter, + uint32_t in_len, + uint32_t cb_idx, + uint32_t rv_idx); #endif #ifdef LV_HAVE_AVX #include -int srslte_rm_turbo_rx_lut_avx(int16_t *input, int16_t *output, uint16_t *deinter, uint32_t in_len, uint32_t cb_idx, uint32_t rv_idx); -int srslte_rm_turbo_rx_lut_avx_8bit(int8_t *input, int8_t *output, uint16_t *deinter, uint32_t in_len, uint32_t cb_idx, uint32_t rv_idx); +int srslte_rm_turbo_rx_lut_avx(int16_t* input, + int16_t* output, + uint16_t* deinter, + uint32_t in_len, + uint32_t cb_idx, + uint32_t rv_idx); +int srslte_rm_turbo_rx_lut_avx_8bit(int8_t* input, + int8_t* output, + uint16_t* deinter, + uint32_t in_len, + uint32_t cb_idx, + uint32_t rv_idx); #endif #define NCOLS 32 #define NROWS_MAX NCOLS -static uint8_t RM_PERM_TC[NCOLS] = { 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, - 6, 22, 14, 30, 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31 }; +static uint8_t RM_PERM_TC[NCOLS] = {0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30, + 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31}; /* Align tables to 16-byte boundary */ -static uint16_t interleaver_systematic_bits[192][6160]; // 4 tail bits +static uint16_t interleaver_systematic_bits[192][6160]; // 4 tail bits static srslte_bit_interleaver_t bit_interleavers_systematic_bits[192]; -static uint16_t interleaver_parity_bits[192][2*6160]; +static uint16_t interleaver_parity_bits[192][2 * 6160]; static srslte_bit_interleaver_t bit_interleavers_parity_bits[192]; -static uint16_t deinterleaver[192][4][18448]; -static int k0_vec[SRSLTE_NOF_TC_CB_SIZES][4][2]; -static bool rm_turbo_tables_generated = false; - +static uint16_t deinterleaver[192][4][18448]; +static int k0_vec[SRSLTE_NOF_TC_CB_SIZES][4][2]; +static bool rm_turbo_tables_generated = false; // Store deinterleaver version for sub-block turbo decoder #if SRSLTE_TDEC_EXPECT_INPUT_SB == 1 // Prepare bit for sub-block decoder processing. These are the nof subblock sizes #define NOF_DEINTER_TABLE_SB_IDX 3 const static int deinter_table_sb_idx[NOF_DEINTER_TABLE_SB_IDX] = {8, 16, 32}; -int deinter_table_idx_from_sb_len(uint32_t nof_subblocks) { - for (int i=0;i= ndummy) { table_bits[k_b] = i * NCOLS + RM_PERM_TC[j] - ndummy; - k_b++; - last_is_null=false; + k_b++; + last_is_null = false; } else { - last_is_null=true; + last_is_null = true; } for (int k = 0; k < 4; k++) { if (k0_vec_[k][1] == -1) { @@ -112,18 +132,18 @@ static void srslte_rm_turbo_gentable_parity(uint16_t* table_parity, int k0_vec_[4][2], int offset, uint16_t nrows, int ndummy) { - bool last_is_null=true; - int k_b=0, buff_idx0=0; - int K_p = nrows*NCOLS; - int buff_idx1=0; + bool last_is_null = true; + int k_b = 0, buff_idx0 = 0; + int K_p = nrows * NCOLS; + int buff_idx1 = 0; for (int j = 0; j < NCOLS; j++) { - for (int i = 0; i < nrows; i++) { + for (int i = 0; i < nrows; i++) { if (i * NCOLS + RM_PERM_TC[j] >= ndummy) { table_parity[k_b] = i * NCOLS + RM_PERM_TC[j] - ndummy; k_b++; - last_is_null=false; + last_is_null = false; } else { - last_is_null=true; + last_is_null = true; } for (int k = 0; k < 4; k++) { if (k0_vec_[k][1] == -1) { @@ -133,14 +153,14 @@ srslte_rm_turbo_gentable_parity(uint16_t* table_parity, int k0_vec_[4][2], int o } } buff_idx0++; - + int kidx = (RM_PERM_TC[buff_idx1 / nrows] + NCOLS * (buff_idx1 % nrows) + 1) % K_p; if ((kidx - ndummy) >= 0) { - table_parity[k_b] = kidx-ndummy+offset; + table_parity[k_b] = kidx - ndummy + offset; k_b++; - last_is_null=false; + last_is_null = false; } else { - last_is_null=true; + last_is_null = true; } for (int k = 0; k < 4; k++) { if (k0_vec_[k][1] == -1) { @@ -150,28 +170,28 @@ srslte_rm_turbo_gentable_parity(uint16_t* table_parity, int k0_vec_[4][2], int o } } buff_idx1++; - } + } } } -static void srslte_rm_turbo_gentable_receive(uint16_t *table, uint32_t cb_len, uint32_t rv_idx) +static void srslte_rm_turbo_gentable_receive(uint16_t* table, uint32_t cb_len, uint32_t rv_idx) { - - int nrows = (uint32_t) (cb_len / 3 - 1) / NCOLS + 1; - int ndummy = nrows*NCOLS - cb_len / 3; + + int nrows = (uint32_t)(cb_len / 3 - 1) / NCOLS + 1; + int ndummy = nrows * NCOLS - cb_len / 3; if (ndummy < 0) { ndummy = 0; } /* Undo bit collection. Account for dummy bits */ - int N_cb = 3*nrows*NCOLS; - int k0 = nrows*(2*(uint16_t) ceilf((float) N_cb/(float) (8*nrows))*rv_idx+2); - - int kidx; - int K_p = nrows * NCOLS; - int k = 0, jp=0, j=0; - bool isdummy = false; - int d_i, d_j; + int N_cb = 3 * nrows * NCOLS; + int k0 = nrows * (2 * (uint16_t)ceilf((float)N_cb / (float)(8 * nrows)) * rv_idx + 2); + + int kidx; + int K_p = nrows * NCOLS; + int k = 0, jp = 0, j = 0; + bool isdummy = false; + int d_i, d_j; while (k < cb_len) { jp = (k0 + j) % N_cb; @@ -181,29 +201,29 @@ static void srslte_rm_turbo_gentable_receive(uint16_t *table, uint32_t cb_len, u d_j = ((jp - K_p) / 2) % nrows; } else { d_i = jp / nrows; - d_j = jp % nrows; - } + d_j = jp % nrows; + } if (d_j * NCOLS + RM_PERM_TC[d_i] >= ndummy) { isdummy = false; if (d_j * NCOLS + RM_PERM_TC[d_i] - ndummy < 0) { isdummy = true; - } + } } else { isdummy = true; } } else { uint32_t jpp = (jp - K_p - 1) / 2; - kidx = (RM_PERM_TC[jpp / nrows] + NCOLS * (jpp % nrows) + 1) % K_p; + kidx = (RM_PERM_TC[jpp / nrows] + NCOLS * (jpp % nrows) + 1) % K_p; if ((kidx - ndummy) < 0) { isdummy = true; } else { isdummy = false; - } + } } - + if (!isdummy) { - temp_table1[k] = jp%(3*nrows*NCOLS); + temp_table1[k] = jp % (3 * nrows * NCOLS); k++; } j++; @@ -222,15 +242,15 @@ static void srslte_rm_turbo_gentable_receive(uint16_t *table, uint32_t cb_len, u kidx = (k / NCOLS + nrows * RM_PERM_TC[k % NCOLS]) % K_p; kidx = 2 * kidx + K_p + 1; } - temp_table2[kidx] = 3*i+j; + temp_table2[kidx] = 3 * i + j; } } - for (int i=0;i= in_len) { cp_len = in_len - r_ptr; } - srslte_bit_copy(output, w_len+w_offset, w_buff, r_ptr, cp_len); - r_ptr += cp_len; + srslte_bit_copy(output, w_len + w_offset, w_buff, r_ptr, cp_len); + r_ptr += cp_len; if (r_ptr >= in_len) { - r_ptr -= in_len; + r_ptr -= in_len; } - w_len += cp_len; + w_len += cp_len; } return 0; } else { - return SRSLTE_ERROR_INVALID_INPUTS; + return SRSLTE_ERROR_INVALID_INPUTS; } } -int srslte_rm_turbo_rx_lut(int16_t *input, int16_t *output, uint32_t in_len, uint32_t cb_idx, uint32_t rv_idx) +int srslte_rm_turbo_rx_lut(int16_t* input, int16_t* output, uint32_t in_len, uint32_t cb_idx, uint32_t rv_idx) { return srslte_rm_turbo_rx_lut_(input, output, in_len, cb_idx, rv_idx, true); } @@ -381,40 +407,45 @@ int srslte_rm_turbo_rx_lut(int16_t *input, int16_t *output, uint32_t in_len, uin * @param[in] rv_idx Redundancy Version from DCI control message * @return Error code */ -int srslte_rm_turbo_rx_lut_(int16_t *input, int16_t *output, uint32_t in_len, uint32_t cb_idx, uint32_t rv_idx, bool enable_input_tdec) +int srslte_rm_turbo_rx_lut_(int16_t* input, + int16_t* output, + uint32_t in_len, + uint32_t cb_idx, + uint32_t rv_idx, + bool enable_input_tdec) { if (rv_idx < 4 && cb_idx < SRSLTE_NOF_TC_CB_SIZES) { #if SRSLTE_TDEC_EXPECT_INPUT_SB == 1 - int cb_len=srslte_cbsegm_cbsize(cb_idx); - int idx = deinter_table_idx_from_sb_len(srslte_tdec_autoimp_get_subblocks(cb_len)); - uint16_t *deinter = NULL; - if (idx < 0 || !enable_input_tdec) { - deinter = deinterleaver[cb_idx][rv_idx]; - } else if (idx < NOF_DEINTER_TABLE_SB_IDX) { - deinter = deinterleaver_sb[idx][cb_idx][rv_idx]; - } else { - ERROR("Sub-block size index %d not supported in srslte_rm_turbo_rx_lut()\n", idx); - return -1; - } + int cb_len = srslte_cbsegm_cbsize(cb_idx); + int idx = deinter_table_idx_from_sb_len(srslte_tdec_autoimp_get_subblocks(cb_len)); + uint16_t* deinter = NULL; + if (idx < 0 || !enable_input_tdec) { + deinter = deinterleaver[cb_idx][rv_idx]; + } else if (idx < NOF_DEINTER_TABLE_SB_IDX) { + deinter = deinterleaver_sb[idx][cb_idx][rv_idx]; + } else { + ERROR("Sub-block size index %d not supported in srslte_rm_turbo_rx_lut()\n", idx); + return -1; + } #else - uint16_t *deinter = deinterleaver[cb_idx][rv_idx]; + uint16_t* deinter = deinterleaver[cb_idx][rv_idx]; #endif - #ifdef LV_HAVE_AVX +#ifdef LV_HAVE_AVX return srslte_rm_turbo_rx_lut_avx(input, output, deinter, in_len, cb_idx, rv_idx); - #else - #ifdef LV_HAVE_SSE +#else +#ifdef LV_HAVE_SSE return srslte_rm_turbo_rx_lut_sse(input, output, deinter, in_len, cb_idx, rv_idx); - #else - uint32_t out_len = 3*srslte_cbsegm_cbsize(cb_idx)+12; +#else + uint32_t out_len = 3 * srslte_cbsegm_cbsize(cb_idx) + 12; - for (int i=0;i= out_len && inputCnt < in_len - 8) { /* Copy last elements */ - for (int j=(nwrapps+1)*out_len-4;j<(nwrapps+1)*out_len;j++) { - output[deinter[j%out_len]] += input[j]; + for (int j = (nwrapps + 1) * out_len - 4; j < (nwrapps + 1) * out_len; j++) { + output[deinter[j % out_len]] += input[j]; inputCnt++; } /* And wrap pointers */ nwrapps++; - intCnt = 8; - xPtr = (const __m128i*) &input[nwrapps*out_len]; - lutPtr = (const __m128i*) deinter; + intCnt = 8; + xPtr = (const __m128i*)&input[nwrapps * out_len]; + lutPtr = (const __m128i*)deinter; } - } - for (int i=inputCnt;i= out_len && inputCnt < in_len - 16) { /* Copy last elements */ - if ((out_len%16) == 12) { - for (int j=(nwrapps+1)*out_len-12;j<(nwrapps+1)*out_len;j++) { - output[deinter[j%out_len]] += input[j]; + if ((out_len % 16) == 12) { + for (int j = (nwrapps + 1) * out_len - 12; j < (nwrapps + 1) * out_len; j++) { + output[deinter[j % out_len]] += input[j]; inputCnt++; } } else { - for (int j=(nwrapps+1)*out_len-4;j<(nwrapps+1)*out_len;j++) { - output[deinter[j%out_len]] += input[j]; + for (int j = (nwrapps + 1) * out_len - 4; j < (nwrapps + 1) * out_len; j++) { + output[deinter[j % out_len]] += input[j]; inputCnt++; } } /* And wrap pointers */ nwrapps++; intCnt = 16; - xPtr = (const __m128i*) &input[nwrapps*out_len]; - lutPtr = (const __m128i*) deinter; + xPtr = (const __m128i*)&input[nwrapps * out_len]; + lutPtr = (const __m128i*)deinter; } } - for (int i=inputCnt;i= out_len && inputCnt < in_len - 16) { /* Copy last elements */ - if ((out_len%16) == 12) { - for (int j=(nwrapps+1)*out_len-12;j<(nwrapps+1)*out_len;j++) { - output[deinter[j%out_len]] += input[j]; + if ((out_len % 16) == 12) { + for (int j = (nwrapps + 1) * out_len - 12; j < (nwrapps + 1) * out_len; j++) { + output[deinter[j % out_len]] += input[j]; inputCnt++; } } else { - for (int j=(nwrapps+1)*out_len-4;j<(nwrapps+1)*out_len;j++) { - output[deinter[j%out_len]] += input[j]; + for (int j = (nwrapps + 1) * out_len - 4; j < (nwrapps + 1) * out_len; j++) { + output[deinter[j % out_len]] += input[j]; inputCnt++; } } /* And wrap pointers */ nwrapps++; intCnt = 16; - xPtr = (const __m256i*) &input[nwrapps*out_len]; - lutPtr = (const __m256i*) deinter; + xPtr = (const __m256i*)&input[nwrapps * out_len]; + lutPtr = (const __m256i*)deinter; } } - for (int i=inputCnt;i= out_len && inputCnt < in_len - 32) { - printf("warning rate matching wrapping remainder %d\n", out_len%32); + printf("warning rate matching wrapping remainder %d\n", out_len % 32); /* Copy last elements */ - for (int j=(nwrapps+1)*out_len-(out_len%32) ;j<(nwrapps+1)*out_len;j++) { - output[deinter[j%out_len]] += input[j]; + for (int j = (nwrapps + 1) * out_len - (out_len % 32); j < (nwrapps + 1) * out_len; j++) { + output[deinter[j % out_len]] += input[j]; inputCnt++; } /* And wrap pointers */ nwrapps++; intCnt = 32; - xPtr = (const __m256i*) &input[nwrapps*out_len]; - lutPtr = (const __m256i*) deinter; + xPtr = (const __m256i*)&input[nwrapps * out_len]; + lutPtr = (const __m256i*)deinter; } } - for (int i=inputCnt;i w_buff_len) { fprintf(stderr, - "Input too large. Max input length including dummy bits is %d (3x%dx32, in_len %d, Kp=%d)\n", - w_buff_len, nrows, in_len, K_p); + "Input too large. Max input length including dummy bits is %d (3x%dx32, in_len %d, Kp=%d)\n", + w_buff_len, + nrows, + in_len, + K_p); return -1; } @@ -1020,19 +1055,18 @@ int srslte_rm_turbo_tx(uint8_t *w_buff, uint32_t w_buff_len, uint8_t *input, uin } } } - + /* Bit selection and transmission 5.1.4.1.2 */ - N_cb = 3 * K_p; // TODO: Soft buffer size limitation + N_cb = 3 * K_p; // TODO: Soft buffer size limitation + + k0 = nrows * (2 * (uint16_t)ceilf((float)N_cb / (float)(8 * nrows)) * rv_idx + 2); + k = 0; + j = 0; - k0 = nrows - * (2 * (uint16_t) ceilf((float) N_cb / (float) (8 * nrows)) * rv_idx + 2); - k = 0; - j = 0; - while (k < out_len) { if (w_buff[(k0 + j) % N_cb] != SRSLTE_TX_NULL) { output[k] = w_buff[(k0 + j) % N_cb]; - k++; + k++; } j++; } @@ -1041,21 +1075,26 @@ int srslte_rm_turbo_tx(uint8_t *w_buff, uint32_t w_buff_len, uint8_t *input, uin /* Undoes Turbo Code Rate Matching. * 3GPP TS 36.212 v10.1.0 section 5.1.4.1 - * - * Soft-combines the data available in w_buff + * + * Soft-combines the data available in w_buff */ -int srslte_rm_turbo_rx(float *w_buff, uint32_t w_buff_len, float *input, uint32_t in_len, float *output, - uint32_t out_len, uint32_t rv_idx, uint32_t nof_filler_bits) { +int srslte_rm_turbo_rx(float* w_buff, + uint32_t w_buff_len, + float* input, + uint32_t in_len, + float* output, + uint32_t out_len, + uint32_t rv_idx, + uint32_t nof_filler_bits) +{ - int nrows, ndummy, K_p, k0, N_cb, jp, kidx; - int i, j, k; - int d_i, d_j; + int nrows, ndummy, K_p, k0, N_cb, jp, kidx; + int i, j, k; + int d_i, d_j; bool isdummy; - - - nrows = (uint16_t) (out_len / 3 - 1) / NCOLS + 1; - K_p = nrows * NCOLS; + nrows = (uint16_t)(out_len / 3 - 1) / NCOLS + 1; + K_p = nrows * NCOLS; if (3 * K_p > w_buff_len) { ERROR("Output too large. Max output length including dummy bits is %d (3x%dx32, in_len %d)\n", w_buff_len, @@ -1069,17 +1108,15 @@ int srslte_rm_turbo_rx(float *w_buff, uint32_t w_buff_len, float *input, uint32_ return -1; } - ndummy = K_p - out_len / 3; if (ndummy < 0) { ndummy = 0; } /* Undo bit collection. Account for dummy bits */ - N_cb = 3 * K_p; // TODO: Soft buffer size limitation - k0 = nrows - * (2 * (uint16_t) ceilf((float) N_cb / (float) (8 * nrows)) * rv_idx + 2); - + N_cb = 3 * K_p; // TODO: Soft buffer size limitation + k0 = nrows * (2 * (uint16_t)ceilf((float)N_cb / (float)(8 * nrows)) * rv_idx + 2); + k = 0; j = 0; while (k < in_len) { @@ -1091,25 +1128,25 @@ int srslte_rm_turbo_rx(float *w_buff, uint32_t w_buff_len, float *input, uint32_ d_j = ((jp - K_p) / 2) % nrows; } else { d_i = jp / nrows; - d_j = jp % nrows; - } + d_j = jp % nrows; + } if (d_j * NCOLS + RM_PERM_TC[d_i] >= ndummy) { isdummy = false; if (d_j * NCOLS + RM_PERM_TC[d_i] - ndummy < nof_filler_bits) { isdummy = true; - } + } } else { isdummy = true; } } else { uint16_t jpp = (jp - K_p - 1) / 2; - kidx = (RM_PERM_TC[jpp / nrows] + NCOLS * (jpp % nrows) + 1) % K_p; + kidx = (RM_PERM_TC[jpp / nrows] + NCOLS * (jpp % nrows) + 1) % K_p; if ((kidx - ndummy) < 0) { isdummy = true; } else { isdummy = false; - } + } } if (!isdummy) { @@ -1119,12 +1156,12 @@ int srslte_rm_turbo_rx(float *w_buff, uint32_t w_buff_len, float *input, uint32_ w_buff[jp] += input[k]; /* soft combine LLRs */ } k++; - } + } j++; } - - //printf("wbuff:\n"); - //srslte_vec_fprint_f(stdout, w_buff, out_len); + + // printf("wbuff:\n"); + // srslte_vec_fprint_f(stdout, w_buff, out_len); /* interleaving and bit selection */ for (i = 0; i < out_len / 3; i++) { diff --git a/lib/src/phy/fec/softbuffer.c b/lib/src/phy/fec/softbuffer.c index 9523eb7a2..785428986 100644 --- a/lib/src/phy/fec/softbuffer.c +++ b/lib/src/phy/fec/softbuffer.c @@ -19,42 +19,43 @@ * */ +#include +#include +#include #include #include +#include #include #include -#include -#include -#include -#include #include "srslte/phy/common/phy_common.h" -#include "srslte/phy/phch/ra.h" -#include "srslte/phy/fec/turbodecoder_gen.h" #include "srslte/phy/fec/rm_turbo.h" #include "srslte/phy/fec/softbuffer.h" -#include "srslte/phy/utils/vector.h" +#include "srslte/phy/fec/turbodecoder_gen.h" +#include "srslte/phy/phch/ra.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" #define MAX_PDSCH_RE(cp) (2 * SRSLTE_CP_NSYMB(cp) * 12) -int srslte_softbuffer_rx_init(srslte_softbuffer_rx_t *q, uint32_t nof_prb) { +int srslte_softbuffer_rx_init(srslte_softbuffer_rx_t* q, uint32_t nof_prb) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; - - if (q != NULL) { + + if (q != NULL) { bzero(q, sizeof(srslte_softbuffer_rx_t)); ret = srslte_ra_tbs_from_idx(33, nof_prb); if (ret != SRSLTE_ERROR) { - q->max_cb = (uint32_t) ret / (SRSLTE_TCOD_MAX_LEN_CB - 24) + 1; - ret = SRSLTE_ERROR; - + q->max_cb = (uint32_t)ret / (SRSLTE_TCOD_MAX_LEN_CB - 24) + 1; + ret = SRSLTE_ERROR; + q->buffer_f = srslte_vec_malloc(sizeof(int16_t*) * q->max_cb); if (!q->buffer_f) { perror("malloc"); goto clean_exit; } - + q->data = srslte_vec_malloc(sizeof(uint8_t*) * q->max_cb); if (!q->data) { perror("malloc"); @@ -69,25 +70,25 @@ int srslte_softbuffer_rx_init(srslte_softbuffer_rx_t *q, uint32_t nof_prb) { bzero(q->cb_crc, sizeof(bool) * q->max_cb); // FIXME: Use HARQ buffer limitation based on UE category - for (uint32_t i=0;imax_cb;i++) { + for (uint32_t i = 0; i < q->max_cb; i++) { q->buffer_f[i] = srslte_vec_malloc(sizeof(int16_t) * SOFTBUFFER_SIZE); if (!q->buffer_f[i]) { perror("malloc"); goto clean_exit; } - q->data[i] = srslte_vec_malloc(sizeof(uint8_t) * 6144/8); + q->data[i] = srslte_vec_malloc(sizeof(uint8_t) * 6144 / 8); if (!q->data[i]) { perror("malloc"); goto clean_exit; } - } - //srslte_softbuffer_rx_reset(q); + } + // srslte_softbuffer_rx_reset(q); ret = SRSLTE_SUCCESS; } } - clean_exit: +clean_exit: if (ret != SRSLTE_SUCCESS) { srslte_softbuffer_rx_free(q); } @@ -95,10 +96,11 @@ int srslte_softbuffer_rx_init(srslte_softbuffer_rx_t *q, uint32_t nof_prb) { return ret; } -void srslte_softbuffer_rx_free(srslte_softbuffer_rx_t *q) { +void srslte_softbuffer_rx_free(srslte_softbuffer_rx_t* q) +{ if (q) { if (q->buffer_f) { - for (uint32_t i=0;imax_cb;i++) { + for (uint32_t i = 0; i < q->max_cb; i++) { if (q->buffer_f[i]) { free(q->buffer_f[i]); } @@ -106,7 +108,7 @@ void srslte_softbuffer_rx_free(srslte_softbuffer_rx_t *q) { free(q->buffer_f); } if (q->data) { - for (uint32_t i=0;imax_cb;i++) { + for (uint32_t i = 0; i < q->max_cb; i++) { if (q->data[i]) { free(q->data[i]); } @@ -120,23 +122,26 @@ void srslte_softbuffer_rx_free(srslte_softbuffer_rx_t *q) { } } -void srslte_softbuffer_rx_reset_tbs(srslte_softbuffer_rx_t *q, uint32_t tbs) { - uint32_t nof_cb = (tbs + 24)/(SRSLTE_TCOD_MAX_LEN_CB - 24) + 1; +void srslte_softbuffer_rx_reset_tbs(srslte_softbuffer_rx_t* q, uint32_t tbs) +{ + uint32_t nof_cb = (tbs + 24) / (SRSLTE_TCOD_MAX_LEN_CB - 24) + 1; srslte_softbuffer_rx_reset_cb(q, nof_cb); } -void srslte_softbuffer_rx_reset(srslte_softbuffer_rx_t *q) { +void srslte_softbuffer_rx_reset(srslte_softbuffer_rx_t* q) +{ srslte_softbuffer_rx_reset_cb(q, q->max_cb); } -void srslte_softbuffer_rx_reset_cb(srslte_softbuffer_rx_t *q, uint32_t nof_cb) { +void srslte_softbuffer_rx_reset_cb(srslte_softbuffer_rx_t* q, uint32_t nof_cb) +{ if (q->buffer_f) { if (nof_cb > q->max_cb) { - nof_cb = q->max_cb; + nof_cb = q->max_cb; } - for (uint32_t i=0;ibuffer_f[i]) { - bzero(q->buffer_f[i], SOFTBUFFER_SIZE*sizeof(int16_t)); + bzero(q->buffer_f[i], SOFTBUFFER_SIZE * sizeof(int16_t)); } if (q->data[i]) { bzero(q->data[i], sizeof(uint8_t) * 6144 / 8); @@ -149,34 +154,33 @@ void srslte_softbuffer_rx_reset_cb(srslte_softbuffer_rx_t *q, uint32_t nof_cb) { q->tb_crc = false; } +int srslte_softbuffer_tx_init(srslte_softbuffer_tx_t* q, uint32_t nof_prb) +{ + int ret = SRSLTE_ERROR_INVALID_INPUTS; + if (q != NULL) { + ret = SRSLTE_ERROR; -int srslte_softbuffer_tx_init(srslte_softbuffer_tx_t *q, uint32_t nof_prb) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; - - if (q != NULL) { - ret = SRSLTE_ERROR; - bzero(q, sizeof(srslte_softbuffer_tx_t)); ret = srslte_ra_tbs_from_idx(33, nof_prb); if (ret != SRSLTE_ERROR) { - q->max_cb = (uint32_t) ret / (SRSLTE_TCOD_MAX_LEN_CB - 24) + 1; - + q->max_cb = (uint32_t)ret / (SRSLTE_TCOD_MAX_LEN_CB - 24) + 1; + q->buffer_b = srslte_vec_malloc(sizeof(uint8_t*) * q->max_cb); if (!q->buffer_b) { perror("malloc"); return SRSLTE_ERROR; } - + // FIXME: Use HARQ buffer limitation based on UE category - for (uint32_t i=0;imax_cb;i++) { + for (uint32_t i = 0; i < q->max_cb; i++) { q->buffer_b[i] = srslte_vec_malloc(sizeof(float) * SOFTBUFFER_SIZE); if (!q->buffer_b[i]) { perror("malloc"); return SRSLTE_ERROR; } - } + } srslte_softbuffer_tx_reset(q); ret = SRSLTE_SUCCESS; } @@ -184,10 +188,11 @@ int srslte_softbuffer_tx_init(srslte_softbuffer_tx_t *q, uint32_t nof_prb) { return ret; } -void srslte_softbuffer_tx_free(srslte_softbuffer_tx_t *q) { +void srslte_softbuffer_tx_free(srslte_softbuffer_tx_t* q) +{ if (q) { if (q->buffer_b) { - for (uint32_t i=0;imax_cb;i++) { + for (uint32_t i = 0; i < q->max_cb; i++) { if (q->buffer_b[i]) { free(q->buffer_b[i]); } @@ -198,23 +203,25 @@ void srslte_softbuffer_tx_free(srslte_softbuffer_tx_t *q) { } } - -void srslte_softbuffer_tx_reset_tbs(srslte_softbuffer_tx_t *q, uint32_t tbs) { - uint32_t nof_cb = (tbs + 24)/(SRSLTE_TCOD_MAX_LEN_CB - 24) + 1; +void srslte_softbuffer_tx_reset_tbs(srslte_softbuffer_tx_t* q, uint32_t tbs) +{ + uint32_t nof_cb = (tbs + 24) / (SRSLTE_TCOD_MAX_LEN_CB - 24) + 1; srslte_softbuffer_tx_reset_cb(q, nof_cb); } -void srslte_softbuffer_tx_reset(srslte_softbuffer_tx_t *q) { +void srslte_softbuffer_tx_reset(srslte_softbuffer_tx_t* q) +{ srslte_softbuffer_tx_reset_cb(q, q->max_cb); } -void srslte_softbuffer_tx_reset_cb(srslte_softbuffer_tx_t *q, uint32_t nof_cb) { - int i; +void srslte_softbuffer_tx_reset_cb(srslte_softbuffer_tx_t* q, uint32_t nof_cb) +{ + int i; if (q->buffer_b) { if (nof_cb > q->max_cb) { - nof_cb = q->max_cb; + nof_cb = q->max_cb; } - for (i=0;ibuffer_b[i]) { bzero(q->buffer_b[i], sizeof(uint8_t) * SOFTBUFFER_SIZE); } diff --git a/lib/src/phy/fec/tc_interl_lte.c b/lib/src/phy/fec/tc_interl_lte.c index 546bd7401..d1aec0e65 100644 --- a/lib/src/phy/fec/tc_interl_lte.c +++ b/lib/src/phy/fec/tc_interl_lte.c @@ -19,14 +19,14 @@ * */ +#include #include #include -#include #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/fec/cbsegm.h" #include "srslte/phy/fec/tc_interl.h" #include "srslte/phy/fec/turbocoder.h" -#include "srslte/phy/fec/cbsegm.h" #include "srslte/phy/utils/debug.h" /************************************************ @@ -35,42 +35,38 @@ * ************************************************/ -const uint32_t f1_list[SRSLTE_NOF_TC_CB_SIZES] = { 3, 7, 19, 7, 7, 11, 5, 11, 7, 41, 103, - 15, 9, 17, 9, 21, 101, 21, 57, 23, 13, 27, 11, 27, 85, 29, 33, 15, 17, 33, - 103, 19, 19, 37, 19, 21, 21, 115, 193, 21, 133, 81, 45, 23, 243, 151, 155, - 25, 51, 47, 91, 29, 29, 247, 29, 89, 91, 157, 55, 31, 17, 35, 227, 65, 19, - 37, 41, 39, 185, 43, 21, 155, 79, 139, 23, 217, 25, 17, 127, 25, 239, 17, - 137, 215, 29, 15, 147, 29, 59, 65, 55, 31, 17, 171, 67, 35, 19, 39, 19, 199, - 21, 211, 21, 43, 149, 45, 49, 71, 13, 17, 25, 183, 55, 127, 27, 29, 29, 57, - 45, 31, 59, 185, 113, 31, 17, 171, 209, 253, 367, 265, 181, 39, 27, 127, - 143, 43, 29, 45, 157, 47, 13, 111, 443, 51, 51, 451, 257, 57, 313, 271, 179, - 331, 363, 375, 127, 31, 33, 43, 33, 477, 35, 233, 357, 337, 37, 71, 71, 37, - 39, 127, 39, 39, 31, 113, 41, 251, 43, 21, 43, 45, 45, 161, 89, 323, 47, 23, - 47, 263 }; - -const uint32_t f2_list[SRSLTE_NOF_TC_CB_SIZES] = { 10, 12, 42, 16, 18, 20, 22, 24, 26, 84, - 90, 32, 34, 108, 38, 120, 84, 44, 46, 48, 50, 52, 36, 56, 58, 60, 62, 32, - 198, 68, 210, 36, 74, 76, 78, 120, 82, 84, 86, 44, 90, 46, 94, 48, 98, 40, - 102, 52, 106, 72, 110, 168, 114, 58, 118, 180, 122, 62, 84, 64, 66, 68, 420, - 96, 74, 76, 234, 80, 82, 252, 86, 44, 120, 92, 94, 48, 98, 80, 102, 52, 106, - 48, 110, 112, 114, 58, 118, 60, 122, 124, 84, 64, 66, 204, 140, 72, 74, 76, - 78, 240, 82, 252, 86, 88, 60, 92, 846, 48, 28, 80, 102, 104, 954, 96, 110, - 112, 114, 116, 354, 120, 610, 124, 420, 64, 66, 136, 420, 216, 444, 456, - 468, 80, 164, 504, 172, 88, 300, 92, 188, 96, 28, 240, 204, 104, 212, 192, - 220, 336, 228, 232, 236, 120, 244, 248, 168, 64, 130, 264, 134, 408, 138, - 280, 142, 480, 146, 444, 120, 152, 462, 234, 158, 80, 96, 902, 166, 336, - 170, 86, 174, 176, 178, 120, 182, 184, 186, 94, 190, 480 }; - -int srslte_tc_interl_LTE_gen(srslte_tc_interl_t *h, uint32_t long_cb) +const uint32_t f1_list[SRSLTE_NOF_TC_CB_SIZES] = { + 3, 7, 19, 7, 7, 11, 5, 11, 7, 41, 103, 15, 9, 17, 9, 21, 101, 21, 57, 23, 13, + 27, 11, 27, 85, 29, 33, 15, 17, 33, 103, 19, 19, 37, 19, 21, 21, 115, 193, 21, 133, 81, + 45, 23, 243, 151, 155, 25, 51, 47, 91, 29, 29, 247, 29, 89, 91, 157, 55, 31, 17, 35, 227, + 65, 19, 37, 41, 39, 185, 43, 21, 155, 79, 139, 23, 217, 25, 17, 127, 25, 239, 17, 137, 215, + 29, 15, 147, 29, 59, 65, 55, 31, 17, 171, 67, 35, 19, 39, 19, 199, 21, 211, 21, 43, 149, + 45, 49, 71, 13, 17, 25, 183, 55, 127, 27, 29, 29, 57, 45, 31, 59, 185, 113, 31, 17, 171, + 209, 253, 367, 265, 181, 39, 27, 127, 143, 43, 29, 45, 157, 47, 13, 111, 443, 51, 51, 451, 257, + 57, 313, 271, 179, 331, 363, 375, 127, 31, 33, 43, 33, 477, 35, 233, 357, 337, 37, 71, 71, 37, + 39, 127, 39, 39, 31, 113, 41, 251, 43, 21, 43, 45, 45, 161, 89, 323, 47, 23, 47, 263}; + +const uint32_t f2_list[SRSLTE_NOF_TC_CB_SIZES] = { + 10, 12, 42, 16, 18, 20, 22, 24, 26, 84, 90, 32, 34, 108, 38, 120, 84, 44, 46, 48, 50, + 52, 36, 56, 58, 60, 62, 32, 198, 68, 210, 36, 74, 76, 78, 120, 82, 84, 86, 44, 90, 46, + 94, 48, 98, 40, 102, 52, 106, 72, 110, 168, 114, 58, 118, 180, 122, 62, 84, 64, 66, 68, 420, + 96, 74, 76, 234, 80, 82, 252, 86, 44, 120, 92, 94, 48, 98, 80, 102, 52, 106, 48, 110, 112, + 114, 58, 118, 60, 122, 124, 84, 64, 66, 204, 140, 72, 74, 76, 78, 240, 82, 252, 86, 88, 60, + 92, 846, 48, 28, 80, 102, 104, 954, 96, 110, 112, 114, 116, 354, 120, 610, 124, 420, 64, 66, 136, + 420, 216, 444, 456, 468, 80, 164, 504, 172, 88, 300, 92, 188, 96, 28, 240, 204, 104, 212, 192, 220, + 336, 228, 232, 236, 120, 244, 248, 168, 64, 130, 264, 134, 408, 138, 280, 142, 480, 146, 444, 120, 152, + 462, 234, 158, 80, 96, 902, 166, 336, 170, 86, 174, 176, 178, 120, 182, 184, 186, 94, 190, 480}; + +int srslte_tc_interl_LTE_gen(srslte_tc_interl_t* h, uint32_t long_cb) { return srslte_tc_interl_LTE_gen_interl(h, long_cb, 1); } -#define deinter(x,win) ((x%(long_cb/win))*(win)+x/(long_cb/win)) -#define inter(x,win) ((x%win)*(long_cb/win)+x/win) - +#define deinter(x, win) ((x % (long_cb / win)) * (win) + x / (long_cb / win)) +#define inter(x, win) ((x % win) * (long_cb / win) + x / win) -int srslte_tc_interl_LTE_gen_interl(srslte_tc_interl_t *h, uint32_t long_cb, uint32_t interl_win) { +int srslte_tc_interl_LTE_gen_interl(srslte_tc_interl_t* h, uint32_t long_cb, uint32_t interl_win) +{ uint32_t cb_table_idx, f1, f2; uint64_t i, j; @@ -91,24 +87,22 @@ int srslte_tc_interl_LTE_gen_interl(srslte_tc_interl_t *h, uint32_t long_cb, uin h->forward[0] = 0; h->reverse[0] = 0; for (i = 1; i < long_cb; i++) { - j = (f1 * i + f2 * i * i) % (long_cb); - h->forward[i] = (uint32_t) j; - h->reverse[j] = (uint32_t) i; + j = (f1 * i + f2 * i * i) % (long_cb); + h->forward[i] = (uint32_t)j; + h->reverse[j] = (uint32_t)i; } if (interl_win != 1) { - uint16_t *f = malloc(long_cb*sizeof(uint16_t)); - uint16_t *r = malloc(long_cb*sizeof(uint16_t)); - memcpy(f, h->forward, long_cb*sizeof(uint16_t)); - memcpy(r, h->reverse, long_cb*sizeof(uint16_t)); + uint16_t* f = malloc(long_cb * sizeof(uint16_t)); + uint16_t* r = malloc(long_cb * sizeof(uint16_t)); + memcpy(f, h->forward, long_cb * sizeof(uint16_t)); + memcpy(r, h->reverse, long_cb * sizeof(uint16_t)); for (i = 0; i < long_cb; i++) { - h->forward[i] = deinter(f[inter(i,interl_win)],interl_win); - h->reverse[i] = deinter(r[inter(i,interl_win)],interl_win); + h->forward[i] = deinter(f[inter(i, interl_win)], interl_win); + h->reverse[i] = deinter(r[inter(i, interl_win)], interl_win); } free(f); free(r); } return 0; - } - diff --git a/lib/src/phy/fec/tc_interl_umts.c b/lib/src/phy/fec/tc_interl_umts.c index 1ce302047..1758cac80 100644 --- a/lib/src/phy/fec/tc_interl_umts.c +++ b/lib/src/phy/fec/tc_interl_umts.c @@ -19,15 +19,15 @@ * */ +#include #include #include #include -#include #include "srslte/phy/fec/tc_interl.h" #include "srslte/phy/utils/debug.h" -#define TURBO_SRSLTE_TCOD_RATE 3 +#define TURBO_SRSLTE_TCOD_RATE 3 uint32_t mcd(uint32_t x, uint32_t y); @@ -37,19 +37,19 @@ uint32_t mcd(uint32_t x, uint32_t y); * ************************************************/ -#define MAX_ROWS 20 -#define MAX_COLS 256 +#define MAX_ROWS 20 +#define MAX_COLS 256 -const unsigned short table_p[52] = { 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, - 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, - 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, - 211, 223, 227, 229, 233, 239, 241, 251, 257 }; -const uint8_t table_v[52] = { 3, 2, 2, 3, 2, 5, 2, 3, 2, 6, 3, 5, 2, 2, 2, - 2, 7, 5, 3, 2, 3, 5, 2, 5, 2, 6, 3, 3, 2, 3, 2, 2, 6, 5, 2, 5, 2, 2, 2, 19, - 5, 2, 3, 2, 3, 2, 6, 3, 7, 7, 6, 3 }; +const unsigned short table_p[52] = {7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, + 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, + 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, + 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257}; +const uint8_t table_v[52] = {3, 2, 2, 3, 2, 5, 2, 3, 2, 6, 3, 5, 2, 2, 2, 2, 7, 5, 3, 2, 3, 5, 2, 5, 2, 6, + 3, 3, 2, 3, 2, 2, 6, 5, 2, 5, 2, 2, 2, 19, 5, 2, 3, 2, 3, 2, 6, 3, 7, 7, 6, 3}; -int srslte_tc_interl_init(srslte_tc_interl_t *h, uint32_t max_long_cb) { - int ret = -1; +int srslte_tc_interl_init(srslte_tc_interl_t* h, uint32_t max_long_cb) +{ + int ret = -1; h->forward = malloc(sizeof(uint32_t) * max_long_cb); if (!h->forward) { perror("malloc"); @@ -61,14 +61,16 @@ int srslte_tc_interl_init(srslte_tc_interl_t *h, uint32_t max_long_cb) { goto clean_exit; } h->max_long_cb = max_long_cb; - ret = 0; - clean_exit: if (ret == -1) { + ret = 0; +clean_exit: + if (ret == -1) { srslte_tc_interl_free(h); } return ret; } -void srslte_tc_interl_free(srslte_tc_interl_t *h) { +void srslte_tc_interl_free(srslte_tc_interl_t* h) +{ if (h->forward) { free(h->forward); } @@ -78,17 +80,18 @@ void srslte_tc_interl_free(srslte_tc_interl_t *h) { bzero(h, sizeof(srslte_tc_interl_t)); } -int srslte_tc_interl_UMTS_gen(srslte_tc_interl_t *h, uint32_t long_cb) { +int srslte_tc_interl_UMTS_gen(srslte_tc_interl_t* h, uint32_t long_cb) +{ - uint32_t i, j; - uint32_t res, prim, aux; - uint32_t kp, k; + uint32_t i, j; + uint32_t res, prim, aux; + uint32_t kp, k; uint16_t *per, *desper; - uint8_t v; - uint16_t p; - uint16_t s[MAX_COLS], q[MAX_ROWS], r[MAX_ROWS], T[MAX_ROWS]; - uint16_t U[MAX_COLS * MAX_ROWS]; - uint32_t M_Rows, M_Cols, M_long; + uint8_t v; + uint16_t p; + uint16_t s[MAX_COLS], q[MAX_ROWS], r[MAX_ROWS], T[MAX_ROWS]; + uint16_t U[MAX_COLS * MAX_ROWS]; + uint32_t M_Rows, M_Cols, M_long; M_long = long_cb; @@ -100,16 +103,15 @@ int srslte_tc_interl_UMTS_gen(srslte_tc_interl_t *h, uint32_t long_cb) { /* Find R*/ if ((40 <= M_long) && (M_long <= 159)) M_Rows = 5; - else if (((160 <= M_long) && (M_long <= 200)) - || ((481 <= M_long) && (M_long <= 530))) + else if (((160 <= M_long) && (M_long <= 200)) || ((481 <= M_long) && (M_long <= 530))) M_Rows = 10; else M_Rows = 20; /* Find p i v*/ if ((481 <= M_long) && (M_long <= 530)) { - p = 53; - v = 2; + p = 53; + v = 2; M_Cols = p; } else { i = 0; @@ -118,12 +120,11 @@ int srslte_tc_interl_UMTS_gen(srslte_tc_interl_t *h, uint32_t long_cb) { v = table_v[i]; i++; } while (M_long > (M_Rows * (p + 1))); - } /* Find C*/ - if ((M_long) <= (M_Rows) * ((p) - 1)) - M_Cols = (p) - 1; + if ((M_long) <= (M_Rows) * ((p)-1)) + M_Cols = (p)-1; else if (((M_Rows) * (p - 1) < M_long) && (M_long <= (M_Rows) * (p))) M_Cols = p; else if ((M_Rows) * (p) < M_long) @@ -151,8 +152,7 @@ int srslte_tc_interl_UMTS_gen(srslte_tc_interl_t *h, uint32_t long_cb) { T[2] = 2; T[3] = 1; T[4] = 0; - } else if ((M_long <= 200 && M_long >= 160) - || (M_long <= 530 && M_long >= 481)) { + } else if ((M_long <= 200 && M_long >= 160) || (M_long <= 530 && M_long >= 481)) { T[0] = 9; T[1] = 8; T[2] = 7; @@ -163,18 +163,17 @@ int srslte_tc_interl_UMTS_gen(srslte_tc_interl_t *h, uint32_t long_cb) { T[7] = 2; T[8] = 1; T[9] = 0; - } else if ((M_long <= 2480 && M_long >= 2281) - || (M_long <= 3210 && M_long >= 3161)) { - T[0] = 19; - T[1] = 9; - T[2] = 14; - T[3] = 4; - T[4] = 0; - T[5] = 2; - T[6] = 5; - T[7] = 7; - T[8] = 12; - T[9] = 18; + } else if ((M_long <= 2480 && M_long >= 2281) || (M_long <= 3210 && M_long >= 3161)) { + T[0] = 19; + T[1] = 9; + T[2] = 14; + T[3] = 4; + T[4] = 0; + T[5] = 2; + T[6] = 5; + T[7] = 7; + T[8] = 12; + T[9] = 18; T[10] = 16; T[11] = 13; T[12] = 17; @@ -186,16 +185,16 @@ int srslte_tc_interl_UMTS_gen(srslte_tc_interl_t *h, uint32_t long_cb) { T[18] = 8; T[19] = 10; } else { - T[0] = 19; - T[1] = 9; - T[2] = 14; - T[3] = 4; - T[4] = 0; - T[5] = 2; - T[6] = 5; - T[7] = 7; - T[8] = 12; - T[9] = 18; + T[0] = 19; + T[1] = 9; + T[2] = 14; + T[3] = 4; + T[4] = 0; + T[5] = 2; + T[6] = 5; + T[7] = 7; + T[8] = 12; + T[9] = 18; T[10] = 10; T[11] = 8; T[12] = 13; @@ -226,16 +225,16 @@ int srslte_tc_interl_UMTS_gen(srslte_tc_interl_t *h, uint32_t long_cb) { } else if (M_Cols == p + 1) { for (i = 0; i < M_Rows; i++) { U[i * M_Cols + p - 1] = 0; - U[i * M_Cols + p] = p; + U[i * M_Cols + p] = p; } if (M_long == M_Cols * M_Rows) { - aux = U[(M_Rows - 1) * M_Cols + p]; + aux = U[(M_Rows - 1) * M_Cols + p]; U[(M_Rows - 1) * M_Cols + p] = U[(M_Rows - 1) * M_Cols + 0]; U[(M_Rows - 1) * M_Cols + 0] = aux; } } - per = h->forward; + per = h->forward; desper = h->reverse; k = 0; @@ -244,17 +243,17 @@ int srslte_tc_interl_UMTS_gen(srslte_tc_interl_t *h, uint32_t long_cb) { kp = T[i] * M_Cols + U[i * M_Cols + j]; if (kp < M_long) { desper[kp] = k; - per[k] = kp; + per[k] = kp; k++; } } } return 0; - } -uint32_t mcd(uint32_t x, uint32_t y) { +uint32_t mcd(uint32_t x, uint32_t y) +{ uint32_t r = 1; while (r) { diff --git a/lib/src/phy/fec/test/crc_test.c b/lib/src/phy/fec/test/crc_test.c index 1e1523e64..dd0dc9ea3 100644 --- a/lib/src/phy/fec/test/crc_test.c +++ b/lib/src/phy/fec/test/crc_test.c @@ -19,22 +19,23 @@ * */ +#include #include #include #include #include -#include -#include #include +#include -#include "srslte/srslte.h" #include "crc_test.h" +#include "srslte/srslte.h" -int num_bits = 5001, crc_length = 24; +int num_bits = 5001, crc_length = 24; uint32_t crc_poly = 0x1864CFB; -uint32_t seed = 1; +uint32_t seed = 1; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [nlps]\n", prog); printf("\t-n num_bits [Default %d]\n", num_bits); printf("\t-l crc_length [Default %d]\n", crc_length); @@ -42,33 +43,35 @@ void usage(char *prog) { printf("\t-s seed [Default 0=time]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "nlps")) != -1) { switch (opt) { - case 'n': - num_bits = (int)strtol(argv[optind], NULL, 10); - break; - case 'l': - crc_length = (int)strtol(argv[optind], NULL, 10); - break; - case 'p': - crc_poly = (uint32_t) strtoul(argv[optind], NULL, 16); - break; - case 's': - seed = (uint32_t) strtoul(argv[optind], NULL, 0); - break; - default: - usage(argv[0]); - exit(-1); + case 'n': + num_bits = (int)strtol(argv[optind], NULL, 10); + break; + case 'l': + crc_length = (int)strtol(argv[optind], NULL, 10); + break; + case 'p': + crc_poly = (uint32_t)strtoul(argv[optind], NULL, 16); + break; + case 's': + seed = (uint32_t)strtoul(argv[optind], NULL, 0); + break; + default: + usage(argv[0]); + exit(-1); } } } -int main(int argc, char **argv) { - int i; - uint8_t *data; - uint32_t crc_word, expected_word; +int main(int argc, char** argv) +{ + int i; + uint8_t* data; + uint32_t crc_word, expected_word; srslte_crc_t crc_p; parse_args(argc, argv); @@ -89,7 +92,7 @@ int main(int argc, char **argv) { data[i] = rand() % 2; } - //Initialize CRC params and tables + // Initialize CRC params and tables if (srslte_crc_init(&crc_p, crc_poly, crc_length)) { exit(-1); } @@ -100,8 +103,7 @@ int main(int argc, char **argv) { free(data); // check if generated word is as expected - if (get_expected_word(num_bits, crc_length, crc_poly, seed, - &expected_word)) { + if (get_expected_word(num_bits, crc_length, crc_poly, seed, &expected_word)) { ERROR("Test parameters not defined in test_results.h\n"); exit(-1); } diff --git a/lib/src/phy/fec/test/crc_test.h b/lib/src/phy/fec/test/crc_test.h index 3fc7a8cce..98b43f36f 100644 --- a/lib/src/phy/fec/test/crc_test.h +++ b/lib/src/phy/fec/test/crc_test.h @@ -21,34 +21,32 @@ #include +#include "srslte/phy/common/phy_common.h" #include "srslte/phy/fec/crc.h" typedef struct { - int n; - int l; + int n; + int l; uint32_t p; uint32_t s; uint32_t word; -}expected_word_t; - +} expected_word_t; static expected_word_t expected_words[] = { - {5001, 24, SRSLTE_LTE_CRC24A, 1, 0x1C5C97}, // LTE CRC24A (36.212 Sec 5.1.1) - {5001, 24, SRSLTE_LTE_CRC24B, 1, 0x36D1F0}, // LTE CRC24B - {5001, 16, SRSLTE_LTE_CRC16, 1, 0x7FF4}, // LTE CRC16: 0x7FF4 - {5001, 8, SRSLTE_LTE_CRC8, 1, 0xF0}, // LTE CRC8 0xF8 + {5001, 24, SRSLTE_LTE_CRC24A, 1, 0x1C5C97}, // LTE CRC24A (36.212 Sec 5.1.1) + {5001, 24, SRSLTE_LTE_CRC24B, 1, 0x36D1F0}, // LTE CRC24B + {5001, 16, SRSLTE_LTE_CRC16, 1, 0x7FF4}, // LTE CRC16: 0x7FF4 + {5001, 8, SRSLTE_LTE_CRC8, 1, 0xF0}, // LTE CRC8 0xF8 - {-1, -1, 0, 0, 0} -}; + {-1, -1, 0, 0, 0}}; -int get_expected_word(int n, int l, uint32_t p, unsigned int s, unsigned int *word) { +int get_expected_word(int n, int l, uint32_t p, unsigned int s, unsigned int* word) +{ int i; - i=0; - while(expected_words[i].n != -1) { - if (expected_words[i].l == l - && expected_words[i].p == p - && expected_words[i].s == s) { + i = 0; + while (expected_words[i].n != -1) { + if (expected_words[i].l == l && expected_words[i].p == p && expected_words[i].s == s) { break; } else { i++; diff --git a/lib/src/phy/fec/test/rm_conv_test.c b/lib/src/phy/fec/test/rm_conv_test.c index e513ffce8..33cf51a72 100644 --- a/lib/src/phy/fec/test/rm_conv_test.c +++ b/lib/src/phy/fec/test/rm_conv_test.c @@ -19,36 +19,38 @@ * */ +#include +#include #include #include #include #include -#include -#include #include -#include +#include #include "srslte/srslte.h" -int nof_tx_bits=-1, nof_rx_bits=-1; +int nof_tx_bits = -1, nof_rx_bits = -1; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s -t nof_tx_bits -r nof_rx_bits\n", prog); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "tr")) != -1) { switch (opt) { - case 't': - nof_tx_bits = (int)strtol(argv[optind], NULL, 10); - break; - case 'r': - nof_rx_bits = (int)strtol(argv[optind], NULL, 10); - break; - default: - usage(argv[0]); - exit(-1); + case 't': + nof_tx_bits = (int)strtol(argv[optind], NULL, 10); + break; + case 'r': + nof_rx_bits = (int)strtol(argv[optind], NULL, 10); + break; + default: + usage(argv[0]); + exit(-1); } } if (nof_tx_bits == -1) { @@ -61,11 +63,12 @@ void parse_args(int argc, char **argv) { } } -int main(int argc, char **argv) { - int i; +int main(int argc, char** argv) +{ + int i; uint8_t *bits, *rm_bits; - float *rm_symbols, *unrm_symbols; - int nof_errors; + float * rm_symbols, *unrm_symbols; + int nof_errors; parse_args(argc, argv); @@ -90,16 +93,16 @@ int main(int argc, char **argv) { exit(-1); } - for (i=0;i 0) != bits[i]) { nof_errors++; } diff --git a/lib/src/phy/fec/test/rm_turbo_test.c b/lib/src/phy/fec/test/rm_turbo_test.c index fa398c6e8..5e739649e 100644 --- a/lib/src/phy/fec/test/rm_turbo_test.c +++ b/lib/src/phy/fec/test/rm_turbo_test.c @@ -19,53 +19,54 @@ * */ +#include +#include #include #include #include #include -#include -#include #include -#include +#include #include "srslte/srslte.h" - int nof_e_bits = -1; -int rv_idx = -1; -int cb_idx = -1; +int rv_idx = -1; +int cb_idx = -1; -uint8_t systematic[6148], parity[2*6148]; -uint8_t systematic_bytes[6148/8+1], parity_bytes[2*6148/8+1]; +uint8_t systematic[6148], parity[2 * 6148]; +uint8_t systematic_bytes[6148 / 8 + 1], parity_bytes[2 * 6148 / 8 + 1]; -#define BUFFSZ 6176*3 +#define BUFFSZ 6176 * 3 -uint8_t bits[3*6144+12]; +uint8_t bits[3 * 6144 + 12]; uint8_t buff_b[BUFFSZ]; -float buff_f[BUFFSZ]; -float bits_f[3*6144+12]; -short bits2_s[3*6144+12]; +float buff_f[BUFFSZ]; +float bits_f[3 * 6144 + 12]; +short bits2_s[3 * 6144 + 12]; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s -c cb_idx -e nof_e_bits [-i rv_idx]\n", prog); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "cei")) != -1) { switch (opt) { - case 'c': - cb_idx = (int)strtol(argv[optind], NULL, 10); - break; - case 'e': - nof_e_bits = (int)strtol(argv[optind], NULL, 10); - break; - case 'i': - rv_idx = (int)strtol(argv[optind], NULL, 10); - break; - default: - usage(argv[0]); - exit(-1); + case 'c': + cb_idx = (int)strtol(argv[optind], NULL, 10); + break; + case 'e': + nof_e_bits = (int)strtol(argv[optind], NULL, 10); + break; + case 'i': + rv_idx = (int)strtol(argv[optind], NULL, 10); + break; + default: + usage(argv[0]); + exit(-1); } } if (nof_e_bits == -1) { @@ -74,15 +75,15 @@ void parse_args(int argc, char **argv) { } } - -int main(int argc, char **argv) { - int i; +int main(int argc, char** argv) +{ + int i; uint8_t *rm_bits, *rm_bits2, *rm_bits2_bytes; - short *rm_bits_s; - float *rm_bits_f; - + short* rm_bits_s; + float* rm_bits_f; + parse_args(argc, argv); - + srslte_rm_turbo_gentables(); rm_bits_s = srslte_vec_malloc(sizeof(short) * nof_e_bits); @@ -105,90 +106,89 @@ int main(int argc, char **argv) { perror("malloc"); exit(-1); } - rm_bits2_bytes = malloc(sizeof(uint8_t) * nof_e_bits/8 + 1); + rm_bits2_bytes = malloc(sizeof(uint8_t) * nof_e_bits / 8 + 1); if (!rm_bits2_bytes) { perror("malloc"); exit(-1); } - uint32_t st=0, end=188; + uint32_t st = 0, end = 188; if (cb_idx != -1) { - st=cb_idx; - end=cb_idx+1; + st = cb_idx; + end = cb_idx + 1; } - uint32_t rv_st=0, rv_end=4; + uint32_t rv_st = 0, rv_end = 4; if (rv_idx != -1) { - rv_st=rv_idx; - rv_end=rv_idx+1; + rv_st = rv_idx; + rv_end = rv_idx + 1; } - - for (cb_idx=st;cb_idx 0) { srslte_rm_turbo_tx(buff_b, BUFFSZ, bits, long_cb_enc, rm_bits, nof_e_bits, rv_idx); } - for (int i=0;i 0) { - bzero(rm_bits2_bytes, nof_e_bits/8); + bzero(rm_bits2_bytes, nof_e_bits / 8); srslte_rm_turbo_tx_lut(buff_b, systematic_bytes, parity_bytes, rm_bits2_bytes, cb_idx, nof_e_bits, 0, rv_idx); } srslte_bit_unpack_vector(rm_bits2_bytes, rm_bits2, nof_e_bits); - for (int i=0;i #include #include #include #include -#include -#include #include +#include +#include "srslte/srslte.h" #include #include -#include "srslte/srslte.h" uint32_t long_cb = 0; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s\n", prog); printf("\t-l long_cb [Default %u]\n", long_cb); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "lv")) != -1) { switch (opt) { - case 'l': - long_cb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + case 'l': + long_cb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } } -uint8_t input_bytes[6144/8]; +uint8_t input_bytes[6144 / 8]; uint8_t input_bits[6144]; -uint8_t parity[3*6144+12]; -uint8_t parity_bits[3*6144+12]; -uint8_t output_bits[3*6144+12]; -uint8_t output_bits2[3*6144+12]; +uint8_t parity[3 * 6144 + 12]; +uint8_t parity_bits[3 * 6144 + 12]; +uint8_t output_bits[3 * 6144 + 12]; +uint8_t output_bits2[3 * 6144 + 12]; -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ parse_args(argc, argv); - + srslte_tcod_t tcod; srslte_tcod_init(&tcod, 6144); - uint32_t st=0, end=187; + uint32_t st = 0, end = 187; if (long_cb) { - st=srslte_cbsegm_cbindex(long_cb); - end=st; + st = srslte_cbsegm_cbindex(long_cb); + end = st; } - - for (uint32_t len=st;len<=end;len++) { - long_cb = srslte_cbsegm_cbsize(len); + + for (uint32_t len = st; len <= end; len++) { + long_cb = srslte_cbsegm_cbsize(len); printf("Checking long_cb=%d\n", long_cb); - for (int i=0;i #include #include #include #include -#include -#include #include +#include #include "srslte/srslte.h" #include @@ -34,30 +34,28 @@ #include "turbodecoder_test.h" - - uint32_t frame_length = 1000, nof_frames = 100; -float ebno_db = 100.0; -uint32_t seed = 0; -int K = -1; +float ebno_db = 100.0; +uint32_t seed = 0; +int K = -1; -#define MAX_ITERATIONS 10 -int nof_cb = 1; -int nof_iterations = MAX_ITERATIONS; +#define MAX_ITERATIONS 10 +int nof_cb = 1; +int nof_iterations = MAX_ITERATIONS; int test_known_data = 0; -int test_errors = 0; +int test_errors = 0; int nof_repetitions = 1; srslte_tdec_impl_type_t tdec_type; -#define SNR_POINTS 4 -#define SNR_MIN 1.0 -#define SNR_MAX 8.0 +#define SNR_POINTS 4 +#define SNR_MIN 1.0 +#define SNR_MAX 8.0 -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [kcinNledts]\n", prog); - printf( - "\t-k Test with known data (ignores frame_length) [Default disabled]\n"); + printf("\t-k Test with known data (ignores frame_length) [Default disabled]\n"); printf("\t-c nof_cb in parallel [Default %d]\n", nof_cb); printf("\t-i nof_iterations [Default %d]\n", nof_iterations); printf("\t-n nof_frames [Default %d]\n", nof_frames); @@ -69,68 +67,69 @@ void usage(char *prog) { printf("\t-s seed [Default 0=time]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "kcinNledts")) != -1) { switch (opt) { - case 'c': - nof_cb = (int)strtol(argv[optind], NULL, 10); - break; - case 'n': - nof_frames = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'N': - nof_repetitions = (int)strtol(argv[optind], NULL, 10); - break; - case 'k': - test_known_data = 1; - break; - case 't': - test_errors = 1; - break; - case 'i': - nof_iterations = (int)strtol(argv[optind], NULL, 10); - break; - case 'l': - frame_length = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'd': - tdec_type = (srslte_tdec_impl_type_t)strtol(argv[optind], NULL, 10); - break; - case 'e': - ebno_db = strtof(argv[optind], NULL); - break; - case 's': - seed = (uint32_t) strtoul(argv[optind], NULL, 0); - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + case 'c': + nof_cb = (int)strtol(argv[optind], NULL, 10); + break; + case 'n': + nof_frames = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'N': + nof_repetitions = (int)strtol(argv[optind], NULL, 10); + break; + case 'k': + test_known_data = 1; + break; + case 't': + test_errors = 1; + break; + case 'i': + nof_iterations = (int)strtol(argv[optind], NULL, 10); + break; + case 'l': + frame_length = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'd': + tdec_type = (srslte_tdec_impl_type_t)strtol(argv[optind], NULL, 10); + break; + case 'e': + ebno_db = strtof(argv[optind], NULL); + break; + case 's': + seed = (uint32_t)strtoul(argv[optind], NULL, 0); + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } } - -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ srslte_random_t random_gen = srslte_random_init(0); - uint32_t frame_cnt; - float *llr; - short *llr_s; - uint8_t *llr_c; - uint8_t *data_tx, *data_rx, *data_rx_bytes, *symbols; - uint32_t i, j; - float var[SNR_POINTS]; - uint32_t snr_points; + uint32_t frame_cnt; + float* llr; + short* llr_s; + uint8_t* llr_c; + uint8_t * data_tx, *data_rx, *data_rx_bytes, *symbols; + uint32_t i, j; + float var[SNR_POINTS]; + uint32_t snr_points; uint32_t errors = 0; - uint32_t coded_length; - struct timeval tdata[3]; - float mean_usec; - srslte_tdec_t tdec; - srslte_tcod_t tcod; - + uint32_t coded_length; + struct timeval tdata[3]; + float mean_usec; + srslte_tdec_t tdec; + srslte_tcod_t tcod; + parse_args(argc, argv); if (!seed) { @@ -197,13 +196,13 @@ int main(int argc, char **argv) { #ifdef HAVE_NEON tdec_type = SRSLTE_TDEC_NEON_WINDOW; #else - // tdec_type = SRSLTE_TDEC_SSE_WINDOW; + // tdec_type = SRSLTE_TDEC_SSE_WINDOW; #endif if (srslte_tdec_init_manual(&tdec, frame_length, tdec_type)) { ERROR("Error initiating Turbo decoder\n"); exit(-1); } - + srslte_tdec_force_not_sb(&tdec); float ebno_inc, esno_db; @@ -223,7 +222,7 @@ int main(int argc, char **argv) { for (i = 0; i < snr_points; i++) { mean_usec = 0; - errors = 0; + errors = 0; frame_cnt = 0; while (frame_cnt < nof_frames) { /* generate data_tx */ @@ -249,8 +248,8 @@ int main(int argc, char **argv) { } srslte_ch_awgn_f(llr, llr, var[i], coded_length); - for (j=0;j typedef struct { - int n; + int n; uint32_t s; - int iterations; - int len; - float ebno; - int errors; + int iterations; + int len; + float ebno; + int errors; } expected_errors_t; -static expected_errors_t expected_errors[] = { - { 100, 1, 1, 504, 1.0, 3989 }, - { 100, 1, 2, 504, 1.0, 1922 }, - { 100, 1, 3, 504, 1.0, 1096 }, - { 100, 1, 4, 504, 1.0, 957 }, +static expected_errors_t expected_errors[] = {{100, 1, 1, 504, 1.0, 3989}, + {100, 1, 2, 504, 1.0, 1922}, + {100, 1, 3, 504, 1.0, 1096}, + {100, 1, 4, 504, 1.0, 957}, - { 100, 1, 1, 504, 2.0, 803 }, - { 100, 1, 2, 504, 2.0, 47 }, - { 100, 1, 3, 504, 2.0, 7 }, - { 100, 1, 4, 504, 2.0, 0 }, + {100, 1, 1, 504, 2.0, 803}, + {100, 1, 2, 504, 2.0, 47}, + {100, 1, 3, 504, 2.0, 7}, + {100, 1, 4, 504, 2.0, 0}, - { 100, 1, 1, 6144, 1.5, 24719 }, - { 100, 1, 2, 6144, 1.5, 897 }, - { 100, 1, 3, 6144, 1.5, 2 }, - { 100, 1, 4, 6144, 1.5, 0 }, - { -1, 0, -1, -1, -1.0, -1} -}; + {100, 1, 1, 6144, 1.5, 24719}, + {100, 1, 2, 6144, 1.5, 897}, + {100, 1, 3, 6144, 1.5, 2}, + {100, 1, 4, 6144, 1.5, 0}, + {-1, 0, -1, -1, -1.0, -1}}; - -int get_expected_errors(int n, uint32_t s, int iterations, int len, float ebno) { +int get_expected_errors(int n, uint32_t s, int iterations, int len, float ebno) +{ int i; i = 0; while (expected_errors[i].n != -1) { - if (expected_errors[i].n == n - && expected_errors[i].s == s - && expected_errors[i].len == len - && expected_errors[i].iterations == iterations - && expected_errors[i].ebno == ebno) { + if (expected_errors[i].n == n && expected_errors[i].s == s && expected_errors[i].len == len && + expected_errors[i].iterations == iterations && expected_errors[i].ebno == ebno) { break; } else { i++; @@ -67,96 +62,64 @@ int get_expected_errors(int n, uint32_t s, int iterations, int len, float ebno) } #define KNOWN_DATA_NFRAMES 1 -#define KNOWN_DATA_SEED 1 -#define KNOWN_DATA_EBNO 0.5 +#define KNOWN_DATA_SEED 1 +#define KNOWN_DATA_EBNO 0.5 const int known_data_errors[4] = {47, 18, 0, 0}; -#define KNOWN_DATA_LEN 504 -const uint8_t known_data[KNOWN_DATA_LEN] = { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, - 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, - 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, - 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, - 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, - 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, - 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, - 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, - 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, - 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, - 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, - 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, - 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, - 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, - 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, - 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, - 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, - 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, - 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1 }; +#define KNOWN_DATA_LEN 504 +const uint8_t known_data[KNOWN_DATA_LEN] = { + 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, + 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, + 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, + 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, + 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, + 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, + 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, + 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, + 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, + 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, + 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, + 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1}; -const uint8_t known_data_encoded[3 * KNOWN_DATA_LEN + 12] = { 0, 0, 0, 0, 0, 1, 1, - 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, - 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, - 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, - 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, - 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, - 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, - 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, - 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, - 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, - 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, - 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, - 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, - 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, - 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, - 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, - 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, - 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, - 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, - 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, - 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, - 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, - 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, - 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, - 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, - 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, - 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, - 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, - 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, - 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, - 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, - 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, - 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, - 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, - 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, - 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, - 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, - 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, - 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, - 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, - 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, - 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, - 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, - 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, - 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, - 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, - 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, - 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, - 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, - 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, - 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, - 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, - 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, - 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, - 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, - 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, - 1, 0, 1, 1, 1 }; +const uint8_t known_data_encoded[3 * KNOWN_DATA_LEN + 12] = { + 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, + 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, + 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, + 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, + 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, + 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, + 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, + 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, + 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, + 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, + 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, + 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, + 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, + 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, + 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, + 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, + 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, + 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, + 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, + 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, + 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, + 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, + 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, + 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, + 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, + 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, + 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, + 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, + 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, + 1, 1, 1}; diff --git a/lib/src/phy/fec/test/viterbi_test.c b/lib/src/phy/fec/test/viterbi_test.c index 7dd37ec51..995828080 100644 --- a/lib/src/phy/fec/test/viterbi_test.c +++ b/lib/src/phy/fec/test/viterbi_test.c @@ -38,16 +38,17 @@ #undef VITERBI_16 #endif -int frame_length = 1000, nof_frames = 256; -float ebno_db = 100.0; -uint32_t seed = 0; -bool tail_biting = false; +int frame_length = 1000, nof_frames = 256; +float ebno_db = 100.0; +uint32_t seed = 0; +bool tail_biting = false; -#define SNR_POINTS 10 -#define SNR_MIN 0.0 -#define SNR_MAX 5.0 +#define SNR_POINTS 10 +#define SNR_MIN 0.0 +#define SNR_MAX 5.0 -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [nlest]\n", prog); printf("\t-n nof_frames [Default %d]\n", nof_frames); printf("\t-l frame_length [Default %d]\n", frame_length); @@ -56,50 +57,51 @@ void usage(char *prog) { printf("\t-t tail_bitting [Default %s]\n", tail_biting ? "yes" : "no"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "nlste")) != -1) { switch (opt) { - case 'n': - nof_frames = (int)strtol(argv[optind], NULL, 10); - break; - case 'l': - frame_length = (int)strtol(argv[optind], NULL, 10); - break; - case 'e': - ebno_db = strtof(argv[optind], NULL); - break; - case 's': - seed = (uint32_t) strtoul(argv[optind], NULL, 0); - break; - case 't': - tail_biting = true; - break; - default: - usage(argv[0]); - exit(-1); + case 'n': + nof_frames = (int)strtol(argv[optind], NULL, 10); + break; + case 'l': + frame_length = (int)strtol(argv[optind], NULL, 10); + break; + case 'e': + ebno_db = strtof(argv[optind], NULL); + break; + case 's': + seed = (uint32_t)strtoul(argv[optind], NULL, 0); + break; + case 't': + tail_biting = true; + break; + default: + usage(argv[0]); + exit(-1); } } } -int main(int argc, char **argv) { - int frame_cnt; - float *llr; - uint16_t *llr_s; - uint8_t *llr_c; - uint8_t *data_tx, *data_rx, *data_rx2, *symbols; +int main(int argc, char** argv) +{ + int frame_cnt; + float* llr; + uint16_t* llr_s; + uint8_t* llr_c; + uint8_t * data_tx, *data_rx, *data_rx2, *symbols; int j; - float var[SNR_POINTS], varunc[SNR_POINTS]; - int snr_points; - uint32_t errors; + float var[SNR_POINTS], varunc[SNR_POINTS]; + int snr_points; + uint32_t errors; #ifdef TEST_SSE - uint32_t errors2; + uint32_t errors2; srslte_viterbi_t dec_sse; #endif - srslte_viterbi_t dec; + srslte_viterbi_t dec; srslte_convcoder_t cod; - int coded_length; - + int coded_length; parse_args(argc, argv); @@ -108,21 +110,21 @@ int main(int argc, char **argv) { } srand(seed); - cod.poly[0] = 0x6D; - cod.poly[1] = 0x4F; - cod.poly[2] = 0x57; - cod.K = 7; + cod.poly[0] = 0x6D; + cod.poly[1] = 0x4F; + cod.poly[2] = 0x57; + cod.K = 7; cod.tail_biting = tail_biting; - cod.R = 3; + cod.R = 3; coded_length = cod.R * (frame_length + ((cod.tail_biting) ? 0 : cod.K - 1)); srslte_viterbi_init(&dec, SRSLTE_VITERBI_37, cod.poly, frame_length, cod.tail_biting); - printf("Convolutional Code 1/3 K=%d Tail bitting: %s\n", cod.K, cod.tail_biting ? "yes" : "no"); + printf("Convolutional Code 1/3 K=%d Tail bitting: %s\n", cod.K, cod.tail_biting ? "yes" : "no"); #ifdef TEST_SSE srslte_viterbi_init_sse(&dec_sse, SRSLTE_VITERBI_37, cod.poly, frame_length, cod.tail_biting); -#endif - +#endif + printf(" Frame length: %d\n", frame_length); if (ebno_db < 100.0) { printf(" EbNo: %.2f\n", ebno_db); @@ -172,7 +174,7 @@ int main(int argc, char **argv) { if (ebno_db == 100.0) { snr_points = SNR_POINTS; for (uint32_t i = 0; i < snr_points; i++) { - ebno_db = SNR_MIN + i * ebno_inc; + ebno_db = SNR_MIN + i * ebno_inc; esno_db = ebno_db + srslte_convert_power_to_dB(1.0f / 3.0f); var[i] = srslte_convert_dB_to_amplitude(esno_db); varunc[i] = srslte_convert_dB_to_amplitude(ebno_db); @@ -186,7 +188,7 @@ int main(int argc, char **argv) { for (uint32_t i = 0; i < snr_points; i++) { frame_cnt = 0; - errors = 0; + errors = 0; #ifdef TEST_SSE errors2 = 0; #endif @@ -211,13 +213,13 @@ int main(int argc, char **argv) { for (j = 0; j < coded_length; j++) { llr[j] = symbols[j] ? M_SQRT2 : -M_SQRT2; } - + srslte_ch_awgn_f(llr, llr, var[i], coded_length); - //srslte_vec_fprint_f(stdout, llr, 100); - - srslte_vec_quant_fuc(llr, llr_c, 32, 127.5, 255, coded_length); + // srslte_vec_fprint_f(stdout, llr, 100); + + srslte_vec_quant_fuc(llr, llr_c, 32, 127.5, 255, coded_length); srslte_vec_quant_fus(llr, llr_s, 8192, 32767.5, 65535, coded_length); - + struct timeval t[3]; gettimeofday(&t[1], NULL); int M = 1; @@ -229,48 +231,47 @@ int main(int argc, char **argv) { srslte_viterbi_decode_uc(&dec, llr_c, data_rx, frame_length); #endif } - + #ifdef TEST_SSE gettimeofday(&t[2], NULL); get_time_interval(t); - //printf("Execution time:\t\t%.1f us\n", (float) t[0].tv_usec/M); + // printf("Execution time:\t\t%.1f us\n", (float) t[0].tv_usec/M); gettimeofday(&t[1], NULL); - for (int i=0;i typedef struct { - int n; + int n; uint32_t s; - int len; - bool tail; - float ebno; - int errors; -}expected_errors_t; + int len; + bool tail; + float ebno; + int errors; +} expected_errors_t; /* The SSE implementation uses 5-bit metrics and has 0.75 dB loss approximation */ #ifdef LV_HAVE_SSE -static expected_errors_t expected_errors[] = { - {1000, 1, 40, true, 0.0, 7282}, - {1000, 1, 40, true, 2.0, 725}, - {1000, 1, 40, true, 3.0, 176}, - {1000, 1, 40, true, 4.5, 24}, +static expected_errors_t expected_errors[] = {{1000, 1, 40, true, 0.0, 7282}, + {1000, 1, 40, true, 2.0, 725}, + {1000, 1, 40, true, 3.0, 176}, + {1000, 1, 40, true, 4.5, 24}, - {100, 1, 1000, true, 0.0, 13208}, - {100, 1, 1000, true, 2.0, 939}, - {100, 1, 1000, true, 3.0, 110}, - {100, 1, 1000, true, 4.5, 5}, + {100, 1, 1000, true, 0.0, 13208}, + {100, 1, 1000, true, 2.0, 939}, + {100, 1, 1000, true, 3.0, 110}, + {100, 1, 1000, true, 4.5, 5}, - {-1, -1, -1, true, -1.0, -1} -}; + {-1, -1, -1, true, -1.0, -1}}; #elif HAVE_NEON -static expected_errors_t expected_errors[] = { - {1000, 1, 40, true, 0.0, 7282}, - {1000, 1, 40, true, 2.0, 725}, - {1000, 1, 40, true, 3.0, 176}, - {1000, 1, 40, true, 4.5, 24}, +static expected_errors_t expected_errors[] = {{1000, 1, 40, true, 0.0, 7282}, + {1000, 1, 40, true, 2.0, 725}, + {1000, 1, 40, true, 3.0, 176}, + {1000, 1, 40, true, 4.5, 24}, - {100, 1, 1000, true, 0.0, 13208}, - {100, 1, 1000, true, 2.0, 939}, - {100, 1, 1000, true, 3.0, 110}, - {100, 1, 1000, true, 4.5, 5}, + {100, 1, 1000, true, 0.0, 13208}, + {100, 1, 1000, true, 2.0, 939}, + {100, 1, 1000, true, 3.0, 110}, + {100, 1, 1000, true, 4.5, 5}, - {-1, -1, -1, true, -1.0, -1} -}; + {-1, -1, -1, true, -1.0, -1}}; +#else -#else +static expected_errors_t expected_errors[] = {{1000, 1, 40, true, 0.0, 5363}, + {1000, 1, 40, true, 2.0, 356}, + {1000, 1, 40, true, 3.0, 48}, + {1000, 1, 40, true, 4.5, 0}, -static expected_errors_t expected_errors[] = { - {1000, 1, 40, true, 0.0, 5363}, - {1000, 1, 40, true, 2.0, 356}, - {1000, 1, 40, true, 3.0, 48}, - {1000, 1, 40, true, 4.5, 0}, + {100, 1, 1000, true, 0.0, 8753}, + {100, 1, 1000, true, 2.0, 350}, + {100, 1, 1000, true, 3.0, 33}, + {100, 1, 1000, true, 4.5, 0}, - {100, 1, 1000, true, 0.0, 8753}, - {100, 1, 1000, true, 2.0, 350}, - {100, 1, 1000, true, 3.0, 33}, - {100, 1, 1000, true, 4.5, 0}, - - {-1, -1, -1, true, -1.0, -1} -}; + {-1, -1, -1, true, -1.0, -1}}; #endif -int get_expected_errors(int n, uint32_t s, int len, bool tail, float ebno) { +int get_expected_errors(int n, uint32_t s, int len, bool tail, float ebno) +{ int i; - i=0; - while(expected_errors[i].n != -1) { - if (expected_errors[i].n == n - && expected_errors[i].s == s - && expected_errors[i].len == len - && expected_errors[i].tail == tail - && expected_errors[i].ebno == ebno) { + i = 0; + while (expected_errors[i].n != -1) { + if (expected_errors[i].n == n && expected_errors[i].s == s && expected_errors[i].len == len && + expected_errors[i].tail == tail && expected_errors[i].ebno == ebno) { break; } else { i++; diff --git a/lib/src/phy/fec/turbocoder.c b/lib/src/phy/fec/turbocoder.c index 894a4b032..07bf94130 100644 --- a/lib/src/phy/fec/turbocoder.c +++ b/lib/src/phy/fec/turbocoder.c @@ -19,10 +19,10 @@ * */ -#include #include -#include +#include #include +#include #include "srslte/phy/fec/cbsegm.h" #include "srslte/phy/fec/turbocoder.h" @@ -40,25 +40,27 @@ typedef struct { uint8_t output; } tcod_lut_t; -static tcod_lut_t tcod_lut[8][256]; -static uint16_t tcod_per_fw[188][6144]; +static tcod_lut_t tcod_lut[8][256]; +static uint16_t tcod_per_fw[188][6144]; static srslte_bit_interleaver_t tcod_interleavers[188]; -static bool table_initiated = false; +static bool table_initiated = false; -int srslte_tcod_init(srslte_tcod_t *h, uint32_t max_long_cb) { +int srslte_tcod_init(srslte_tcod_t* h, uint32_t max_long_cb) +{ h->max_long_cb = max_long_cb; - h->temp = srslte_vec_malloc(max_long_cb/8); - + h->temp = srslte_vec_malloc(max_long_cb / 8); + if (!table_initiated) { - table_initiated = true; + table_initiated = true; srslte_tcod_gentable(); } return 0; } -void srslte_tcod_free(srslte_tcod_t *h) { +void srslte_tcod_free(srslte_tcod_t* h) +{ h->max_long_cb = 0; if (h->temp) { free(h->temp); @@ -73,14 +75,14 @@ void srslte_tcod_free(srslte_tcod_t *h) { } /* Expects bits (1 byte = 1 bit) and produces bits. The systematic and parity bits are interlaced in the output */ -int srslte_tcod_encode(srslte_tcod_t *h, uint8_t *input, uint8_t *output, uint32_t long_cb) +int srslte_tcod_encode(srslte_tcod_t* h, uint8_t* input, uint8_t* output, uint32_t long_cb) { - uint8_t reg1_0, reg1_1, reg1_2, reg2_0, reg2_1, reg2_2; - uint32_t i, k = 0, j; - uint8_t bit; - uint8_t in, out; - uint16_t *per; + uint8_t reg1_0, reg1_1, reg1_2, reg2_0, reg2_1, reg2_2; + uint32_t i, k = 0, j; + uint8_t bit; + uint8_t in, out; + uint16_t* per; if (long_cb > h->max_long_cb) { ERROR("Turbo coder initiated for max_long_cb=%d\n", h->max_long_cb); @@ -92,7 +94,7 @@ int srslte_tcod_encode(srslte_tcod_t *h, uint8_t *input, uint8_t *output, uint32 ERROR("Invalid CB size %d\n", long_cb); return -1; } - + per = tcod_per_fw[longcb_idx]; reg1_0 = 0; @@ -111,16 +113,16 @@ int srslte_tcod_encode(srslte_tcod_t *h, uint8_t *input, uint8_t *output, uint32 bit = input[i]; } output[k] = input[i]; - + k++; - in = bit ^ (reg1_2 ^ reg1_1); + in = bit ^ (reg1_2 ^ reg1_1); out = reg1_2 ^ (reg1_0 ^ in); reg1_2 = reg1_1; reg1_1 = reg1_0; reg1_0 = in; - + if (input[i] == SRSLTE_TX_NULL) { output[k] = SRSLTE_TX_NULL; } else { @@ -130,10 +132,10 @@ int srslte_tcod_encode(srslte_tcod_t *h, uint8_t *input, uint8_t *output, uint32 bit = input[per[i]]; if (bit == SRSLTE_TX_NULL) { - bit = 0; + bit = 0; } - in = bit ^ (reg2_2 ^ reg2_1); + in = bit ^ (reg2_2 ^ reg2_1); out = reg2_2 ^ (reg2_0 ^ in); reg2_2 = reg2_1; @@ -142,7 +144,6 @@ int srslte_tcod_encode(srslte_tcod_t *h, uint8_t *input, uint8_t *output, uint32 output[k] = out; k++; - } k = 3 * long_cb; @@ -154,7 +155,7 @@ int srslte_tcod_encode(srslte_tcod_t *h, uint8_t *input, uint8_t *output, uint32 output[k] = bit; k++; - in = bit ^ (reg1_2 ^ reg1_1); + in = bit ^ (reg1_2 ^ reg1_1); out = reg1_2 ^ (reg1_0 ^ in); reg1_2 = reg1_1; @@ -172,7 +173,7 @@ int srslte_tcod_encode(srslte_tcod_t *h, uint8_t *input, uint8_t *output, uint32 output[k] = bit; k++; - in = bit ^ (reg2_2 ^ reg2_1); + in = bit ^ (reg2_2 ^ reg2_1); out = reg2_2 ^ (reg2_0 ^ in); reg2_2 = reg2_1; @@ -186,17 +187,17 @@ int srslte_tcod_encode(srslte_tcod_t *h, uint8_t *input, uint8_t *output, uint32 } /* Expects bytes and produces bytes. The systematic and parity bits are interlaced in the output */ -int srslte_tcod_encode_lut(srslte_tcod_t *h, - srslte_crc_t *crc_tb, - srslte_crc_t *crc_cb, - uint8_t *input, - uint8_t *parity, - uint32_t cblen_idx, - bool last_cb) +int srslte_tcod_encode_lut(srslte_tcod_t* h, + srslte_crc_t* crc_tb, + srslte_crc_t* crc_cb, + uint8_t* input, + uint8_t* parity, + uint32_t cblen_idx, + bool last_cb) { if (cblen_idx < 188) { - uint32_t long_cb = (uint32_t) srslte_cbsegm_cbsize(cblen_idx); - + uint32_t long_cb = (uint32_t)srslte_cbsegm_cbsize(cblen_idx); + if (long_cb % 8) { ERROR("Turbo coder LUT implementation long_cb must be multiple of 8\n"); return -1; @@ -224,37 +225,37 @@ int srslte_tcod_encode_lut(srslte_tcod_t *h, /* Run actual encoder */ tcod_lut_t l = tcod_lut[state0][in]; - parity[i] = l.output; - state0 = l.next_state; + parity[i] = l.output; + state0 = l.next_state; } if (last_cb) { - uint32_t checksum = (uint32_t) srslte_crc_checksum_get(crc_tb); + uint32_t checksum = (uint32_t)srslte_crc_checksum_get(crc_tb); for (int i = 0; i < crc_tb->order / 8; i++) { - int mask_shift = 8 * (crc_tb->order / 8 - i - 1); - int idx = block_size_nocrc + i; - uint8_t in = (uint8_t) ((checksum >> mask_shift) & 0xff); + int mask_shift = 8 * (crc_tb->order / 8 - i - 1); + int idx = block_size_nocrc + i; + uint8_t in = (uint8_t)((checksum >> mask_shift) & 0xff); /* Put byte in CB CRC and save latest checksum */ srslte_crc_checksum_put_byte(crc_cb, in); - input[idx] = in; + input[idx] = in; tcod_lut_t l = tcod_lut[state0][in]; - parity[idx] = l.output; - state0 = l.next_state; + parity[idx] = l.output; + state0 = l.next_state; } } - uint32_t checksum = (uint32_t) srslte_crc_checksum_get(crc_cb); + uint32_t checksum = (uint32_t)srslte_crc_checksum_get(crc_cb); for (int i = 0; i < crc_cb->order / 8; i++) { - int mask_shift = 8 * (crc_cb->order / 8 - i - 1); - int idx = (long_cb - crc_cb->order) / 8 + i; - uint8_t in = (uint8_t) ((checksum >> mask_shift) & 0xff); + int mask_shift = 8 * (crc_cb->order / 8 - i - 1); + int idx = (long_cb - crc_cb->order) / 8 + i; + uint8_t in = (uint8_t)((checksum >> mask_shift) & 0xff); - input[idx] = in; + input[idx] = in; tcod_lut_t l = tcod_lut[state0][in]; - parity[idx] = l.output; - state0 = l.next_state; + parity[idx] = l.output; + state0 = l.next_state; } } else { @@ -267,54 +268,54 @@ int srslte_tcod_encode_lut(srslte_tcod_t *h, srslte_crc_checksum_put_byte(crc_tb, in); tcod_lut_t l = tcod_lut[state0][in]; - parity[i] = l.output; - state0 = l.next_state; + parity[i] = l.output; + state0 = l.next_state; } if (last_cb) { - uint32_t checksum = (uint32_t) srslte_crc_checksum_get(crc_tb); + uint32_t checksum = (uint32_t)srslte_crc_checksum_get(crc_tb); for (int i = 0; i < crc_tb->order / 8; i++) { - int mask_shift = 8 * (crc_tb->order / 8 - i - 1); - int idx = block_size_nocrc + i; - uint8_t in = (uint8_t) ((checksum >> mask_shift) & 0xff); + int mask_shift = 8 * (crc_tb->order / 8 - i - 1); + int idx = block_size_nocrc + i; + uint8_t in = (uint8_t)((checksum >> mask_shift) & 0xff); - input[idx] = in; + input[idx] = in; tcod_lut_t l = tcod_lut[state0][in]; - parity[idx] = l.output; - state0 = l.next_state; + parity[idx] = l.output; + state0 = l.next_state; } } } - parity[long_cb / 8] = 0; // will put tail here later - + parity[long_cb / 8] = 0; // will put tail here later + /* Interleave input */ srslte_bit_interleaver_run(&tcod_interleavers[cblen_idx], input, h->temp, 0); - //srslte_bit_interleave(input, h->temp, tcod_per_fw[cblen_idx], long_cb); + // srslte_bit_interleave(input, h->temp, tcod_per_fw[cblen_idx], long_cb); /* Parity bits for the 2nd constituent encoders */ uint8_t state1 = 0; - for (uint32_t i=0;itemp[i]]; - uint8_t out = l.output; - parity[long_cb/8+i] |= (out&0xf0)>>4; - parity[long_cb/8+i+1] = (out&0xf)<<4; - state1 = l.next_state; + for (uint32_t i = 0; i < long_cb / 8; i++) { + tcod_lut_t l = tcod_lut[state1][h->temp[i]]; + uint8_t out = l.output; + parity[long_cb / 8 + i] |= (out & 0xf0) >> 4; + parity[long_cb / 8 + i + 1] = (out & 0xf) << 4; + state1 = l.next_state; } /* Tail bits */ uint8_t reg1_0, reg1_1, reg1_2, reg2_0, reg2_1, reg2_2; - uint8_t bit, in, out; - uint8_t k=0; - uint8_t tail[12]; - - reg2_0 = (state1&4)>>2; - reg2_1 = (state1&2)>>1; - reg2_2 = state1&1; - - reg1_0 = (state0&4)>>2; - reg1_1 = (state0&2)>>1; - reg1_2 = state0&1; - + uint8_t bit, in, out; + uint8_t k = 0; + uint8_t tail[12]; + + reg2_0 = (state1 & 4) >> 2; + reg2_1 = (state1 & 2) >> 1; + reg2_2 = state1 & 1; + + reg1_0 = (state0 & 4) >> 2; + reg1_1 = (state0 & 2) >> 1; + reg1_2 = state0 & 1; + /* TAILING CODER #1 */ for (uint32_t j = 0; j < NOF_REGS; j++) { bit = reg1_2 ^ reg1_1; @@ -322,7 +323,7 @@ int srslte_tcod_encode_lut(srslte_tcod_t *h, tail[k] = bit; k++; - in = bit ^ (reg1_2 ^ reg1_1); + in = bit ^ (reg1_2 ^ reg1_1); out = reg1_2 ^ (reg1_0 ^ in); reg1_2 = reg1_1; @@ -340,7 +341,7 @@ int srslte_tcod_encode_lut(srslte_tcod_t *h, tail[k] = bit; k++; - in = bit ^ (reg2_2 ^ reg2_1); + in = bit ^ (reg2_2 ^ reg2_1); out = reg2_2 ^ (reg2_0 ^ in); reg2_2 = reg2_1; @@ -350,35 +351,36 @@ int srslte_tcod_encode_lut(srslte_tcod_t *h, tail[k] = out; k++; } - + uint8_t tailv[3][4]; - for (int i=0;i<4;i++) { - for (int j=0;j<3;j++) { - tailv[j][i] = tail[3*i+j]; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 3; j++) { + tailv[j][i] = tail[3 * i + j]; } } - uint8_t *x = tailv[0]; - input[long_cb/8] = (srslte_bit_pack(&x, 4)<<4); - x = tailv[1]; - parity[long_cb/8] |= (srslte_bit_pack(&x, 4)<<4); + uint8_t* x = tailv[0]; + input[long_cb / 8] = (srslte_bit_pack(&x, 4) << 4); + x = tailv[1]; + parity[long_cb / 8] |= (srslte_bit_pack(&x, 4) << 4); x = tailv[2]; - parity[2*long_cb/8] |= (srslte_bit_pack(&x, 4)&0xf); - - return 3*long_cb+TOTALTAIL; + parity[2 * long_cb / 8] |= (srslte_bit_pack(&x, 4) & 0xf); + + return 3 * long_cb + TOTALTAIL; } else { - return -1; + return -1; } } -void srslte_tcod_gentable() { - srslte_tc_interl_t interl; +void srslte_tcod_gentable() +{ + srslte_tc_interl_t interl; if (srslte_tc_interl_init(&interl, 6144)) { ERROR("Error initiating interleave\n"); return; } - - for (uint32_t len=0;len<188;len++) { + + for (uint32_t len = 0; len < 188; len++) { uint32_t long_cb = srslte_cbsegm_cbsize(len); if (srslte_tc_interl_LTE_gen(&interl, long_cb)) { ERROR("Error initiating TC interleaver for long_cb=%d\n", long_cb); @@ -394,30 +396,29 @@ void srslte_tcod_gentable() { } } // Compute state transitions - for (uint32_t state=0;state<8;state++) { - for (uint32_t data=0;data<256;data++) { + for (uint32_t state = 0; state < 8; state++) { + for (uint32_t data = 0; data < 256; data++) { uint8_t reg_0, reg_1, reg_2; - reg_0 = (state&4)>>2; - reg_1 = (state&2)>>1; - reg_2 = state&1; + reg_0 = (state & 4) >> 2; + reg_1 = (state & 2) >> 1; + reg_2 = state & 1; tcod_lut[state][data].output = 0; uint8_t bit, in, out; for (uint32_t i = 0; i < 8; i++) { - bit = (data&(1<<(7-i)))?1:0; + bit = (data & (1 << (7 - i))) ? 1 : 0; - in = bit ^ (reg_2 ^ reg_1); + in = bit ^ (reg_2 ^ reg_1); out = reg_2 ^ (reg_0 ^ in); reg_2 = reg_1; reg_1 = reg_0; reg_0 = in; - tcod_lut[state][data].output |= out<<(7-i); - + tcod_lut[state][data].output |= out << (7 - i); } - tcod_lut[state][data].next_state = (uint8_t) ((reg_0 << 2 | reg_1 << 1 | reg_2) % 8); + tcod_lut[state][data].next_state = (uint8_t)((reg_0 << 2 | reg_1 << 1 | reg_2) % 8); } } diff --git a/lib/src/phy/fec/turbodecoder.c b/lib/src/phy/fec/turbodecoder.c index a113bc4e7..2dbb2cffb 100644 --- a/lib/src/phy/fec/turbodecoder.c +++ b/lib/src/phy/fec/turbodecoder.c @@ -20,8 +20,8 @@ */ #include -#include #include +#include #include #include "srslte/phy/fec/turbodecoder.h" @@ -32,24 +32,20 @@ /* Generic (no SSE) implementation */ #include "srslte/phy/fec/turbodecoder_gen.h" -srslte_tdec_16bit_impl_t gen_impl = { - tdec_gen_init, - tdec_gen_free, - tdec_gen_dec, - tdec_gen_extract_input, - tdec_gen_decision_byte -}; +srslte_tdec_16bit_impl_t gen_impl = {tdec_gen_init, + tdec_gen_free, + tdec_gen_dec, + tdec_gen_extract_input, + tdec_gen_decision_byte}; /* SSE no-window implementation */ #ifdef LV_HAVE_SSE #include "srslte/phy/fec/turbodecoder_sse.h" -srslte_tdec_16bit_impl_t sse_impl = { - tdec_sse_init, - tdec_sse_free, - tdec_sse_dec, - tdec_sse_extract_input, - tdec_sse_decision_byte -}; +srslte_tdec_16bit_impl_t sse_impl = {tdec_sse_init, + tdec_sse_free, + tdec_sse_dec, + tdec_sse_extract_input, + tdec_sse_decision_byte}; /* SSE window implementation */ @@ -57,13 +53,11 @@ srslte_tdec_16bit_impl_t sse_impl = { #include "srslte/phy/fec/turbodecoder_win.h" #undef WINIMP_IS_SSE16 -srslte_tdec_16bit_impl_t sse16_win_impl = { - tdec_winsse16_init, - tdec_winsse16_free, - tdec_winsse16_dec, - tdec_winsse16_extract_input, - tdec_winsse16_decision_byte -}; +srslte_tdec_16bit_impl_t sse16_win_impl = {tdec_winsse16_init, + tdec_winsse16_free, + tdec_winsse16_dec, + tdec_winsse16_extract_input, + tdec_winsse16_decision_byte}; #endif /* AVX window implementation */ @@ -71,13 +65,11 @@ srslte_tdec_16bit_impl_t sse16_win_impl = { #define WINIMP_IS_AVX16 #include "srslte/phy/fec/turbodecoder_win.h" #undef WINIMP_IS_AVX16 -srslte_tdec_16bit_impl_t avx16_win_impl = { - tdec_winavx16_init, - tdec_winavx16_free, - tdec_winavx16_dec, - tdec_winavx16_extract_input, - tdec_winavx16_decision_byte -}; +srslte_tdec_16bit_impl_t avx16_win_impl = {tdec_winavx16_init, + tdec_winavx16_free, + tdec_winavx16_dec, + tdec_winavx16_extract_input, + tdec_winavx16_decision_byte}; #endif /* SSE window implementation */ @@ -86,13 +78,11 @@ srslte_tdec_16bit_impl_t avx16_win_impl = { #include "srslte/phy/fec/turbodecoder_win.h" #undef WINIMP_IS_SSE8 -srslte_tdec_8bit_impl_t sse8_win_impl = { - tdec_winsse8_init, - tdec_winsse8_free, - tdec_winsse8_dec, - tdec_winsse8_extract_input, - tdec_winsse8_decision_byte -}; +srslte_tdec_8bit_impl_t sse8_win_impl = {tdec_winsse8_init, + tdec_winsse8_free, + tdec_winsse8_dec, + tdec_winsse8_extract_input, + tdec_winsse8_decision_byte}; #endif /* AVX window implementation */ @@ -100,39 +90,33 @@ srslte_tdec_8bit_impl_t sse8_win_impl = { #define WINIMP_IS_AVX8 #include "srslte/phy/fec/turbodecoder_win.h" #undef WINIMP_IS_AVX8 -srslte_tdec_8bit_impl_t avx8_win_impl = { - tdec_winavx8_init, - tdec_winavx8_free, - tdec_winavx8_dec, - tdec_winavx8_extract_input, - tdec_winavx8_decision_byte -}; +srslte_tdec_8bit_impl_t avx8_win_impl = {tdec_winavx8_init, + tdec_winavx8_free, + tdec_winavx8_dec, + tdec_winavx8_extract_input, + tdec_winavx8_decision_byte}; #endif - #ifdef HAVE_NEON #define WINIMP_IS_NEON16 #include "srslte/phy/fec/turbodecoder_win.h" #undef WINIMP_IS_NEON16 -srslte_tdec_16bit_impl_t arm16_win_impl = { - tdec_winarm16_init, - tdec_winarm16_free, - tdec_winarm16_dec, - tdec_winarm16_extract_input, - tdec_winarm16_decision_byte -}; +srslte_tdec_16bit_impl_t arm16_win_impl = {tdec_winarm16_init, + tdec_winarm16_free, + tdec_winarm16_dec, + tdec_winarm16_extract_input, + tdec_winarm16_decision_byte}; #endif -#define AUTO_16_SSE 0 +#define AUTO_16_SSE 0 #define AUTO_16_SSEWIN 1 #define AUTO_16_AVXWIN 2 -#define AUTO_8_SSEWIN 0 -#define AUTO_8_AVXWIN 1 -#define AUTO_16_GEN 0 +#define AUTO_8_SSEWIN 0 +#define AUTO_8_AVXWIN 1 +#define AUTO_16_GEN 0 #define AUTO_16_NEONWIN 1 - // Include interfaces for 8 and 16 bit decoder implementations #define LLR_IS_8BIT #include "srslte/phy/fec/turbodecoder_iter.h" @@ -142,12 +126,13 @@ srslte_tdec_16bit_impl_t arm16_win_impl = { #include "srslte/phy/fec/turbodecoder_iter.h" #undef LLR_IS_16BIT - -int srslte_tdec_init(srslte_tdec_t * h, uint32_t max_long_cb) { +int srslte_tdec_init(srslte_tdec_t* h, uint32_t max_long_cb) +{ return srslte_tdec_init_manual(h, max_long_cb, SRSLTE_TDEC_AUTO); } -uint32_t interleaver_idx(uint32_t nof_subblocks) { +uint32_t interleaver_idx(uint32_t nof_subblocks) +{ switch (nof_subblocks) { case 32: return 3; @@ -163,7 +148,7 @@ uint32_t interleaver_idx(uint32_t nof_subblocks) { } /* Initializes the turbo decoder object */ -int srslte_tdec_init_manual(srslte_tdec_t * h, uint32_t max_long_cb, srslte_tdec_impl_type_t dec_type) +int srslte_tdec_init_manual(srslte_tdec_t* h, uint32_t max_long_cb, srslte_tdec_impl_type_t dec_type) { int ret = -1; bzero(h, sizeof(srslte_tdec_t)); @@ -172,41 +157,41 @@ int srslte_tdec_init_manual(srslte_tdec_t * h, uint32_t max_long_cb, srslte_tdec h->dec_type = dec_type; // Set manual - switch(dec_type) { + switch (dec_type) { case SRSLTE_TDEC_AUTO: break; #ifdef LV_HAVE_SSE case SRSLTE_TDEC_SSE: - h->dec16[0] = &sse_impl; + h->dec16[0] = &sse_impl; h->current_llr_type = SRSLTE_TDEC_16; break; case SRSLTE_TDEC_SSE_WINDOW: - h->dec16[0] = &sse16_win_impl; + h->dec16[0] = &sse16_win_impl; h->current_llr_type = SRSLTE_TDEC_16; break; case SRSLTE_TDEC_SSE8_WINDOW: - h->dec8[0] = &sse8_win_impl; + h->dec8[0] = &sse8_win_impl; h->current_llr_type = SRSLTE_TDEC_8; break; #endif /* LV_HAVE_SSE */ #ifdef HAVE_NEON case SRSLTE_TDEC_NEON_WINDOW: - h->dec16[0] = &arm16_win_impl; + h->dec16[0] = &arm16_win_impl; h->current_llr_type = SRSLTE_TDEC_16; break; #else /* HAVE_NEON */ case SRSLTE_TDEC_GENERIC: - h->dec16[0] = &gen_impl; + h->dec16[0] = &gen_impl; h->current_llr_type = SRSLTE_TDEC_16; break; #endif /* HAVE_NEON */ #ifdef LV_HAVE_AVX2 case SRSLTE_TDEC_AVX_WINDOW: - h->dec16[0] = &avx16_win_impl; + h->dec16[0] = &avx16_win_impl; h->current_llr_type = SRSLTE_TDEC_16; break; case SRSLTE_TDEC_AVX8_WINDOW: - h->dec8[0] = &avx8_win_impl; + h->dec8[0] = &avx8_win_impl; h->current_llr_type = SRSLTE_TDEC_8; break; #endif /* LV_HAVE_AVX2 */ @@ -214,7 +199,7 @@ int srslte_tdec_init_manual(srslte_tdec_t * h, uint32_t max_long_cb, srslte_tdec ERROR("Error decoder %d not supported\n", dec_type); goto clean_and_exit; } - + h->max_long_cb = max_long_cb; h->app1 = srslte_vec_malloc(sizeof(int16_t) * len); @@ -252,7 +237,7 @@ int srslte_tdec_init_manual(srslte_tdec_t * h, uint32_t max_long_cb, srslte_tdec perror("srslte_vec_malloc"); goto clean_and_exit; } - h->input_conv = srslte_vec_malloc(sizeof(int16_t) * (len * 3+32*3)); + h->input_conv = srslte_vec_malloc(sizeof(int16_t) * (len * 3 + 32 * 3)); if (!h->input_conv) { perror("srslte_vec_malloc"); goto clean_and_exit; @@ -260,68 +245,69 @@ int srslte_tdec_init_manual(srslte_tdec_t * h, uint32_t max_long_cb, srslte_tdec if (dec_type == SRSLTE_TDEC_AUTO) { #ifdef HAVE_NEON - h->dec16[AUTO_16_GEN] = &gen_impl; + h->dec16[AUTO_16_GEN] = &gen_impl; h->dec16[AUTO_16_NEONWIN] = &arm16_win_impl; #elif LV_HAVE_SSE - h->dec16[AUTO_16_SSE] = &gen_impl; + h->dec16[AUTO_16_SSE] = &gen_impl; h->dec16[AUTO_16_SSEWIN] = &sse16_win_impl; - h->dec8[AUTO_8_SSEWIN] = &sse8_win_impl; + h->dec8[AUTO_8_SSEWIN] = &sse8_win_impl; #ifdef LV_HAVE_AVX2 h->dec16[AUTO_16_AVXWIN] = &avx16_win_impl; - h->dec8[AUTO_8_AVXWIN] = &avx8_win_impl; + h->dec8[AUTO_8_AVXWIN] = &avx8_win_impl; #endif /* LV_HAVE_AVX2 */ #else /* HAVE_NEON | LV_HAVE_SSE */ - h->dec16[AUTO_16_SSE] = &gen_impl; + h->dec16[AUTO_16_SSE] = &gen_impl; h->dec16[AUTO_16_SSEWIN] = &gen_impl; #endif /* HAVE_NEON | LV_HAVE_SSE */ - for (int td=0;tddec16[td]) { - if ((h->nof_blocks16[td] = h->dec16[td]->tdec_init(&h->dec16_hdlr[td], h->max_long_cb))<0) { + if ((h->nof_blocks16[td] = h->dec16[td]->tdec_init(&h->dec16_hdlr[td], h->max_long_cb)) < 0) { goto clean_and_exit; } } } - for (int td=0;tddec8[td]) { - if ((h->nof_blocks8[td] = h->dec8[td]->tdec_init(&h->dec8_hdlr[td], h->max_long_cb))<0) { + if ((h->nof_blocks8[td] = h->dec8[td]->tdec_init(&h->dec8_hdlr[td], h->max_long_cb)) < 0) { goto clean_and_exit; } } } // Compute 1 interleaver for each possible nof_subblocks (1, 8, 16 or 32) - for (int s=0;s<4;s++) { - for (int i=0;iinterleaver[s][i], srslte_cbsegm_cbsize(i)) < 0) { goto clean_and_exit; } - srslte_tc_interl_LTE_gen_interl(&h->interleaver[s][i], srslte_cbsegm_cbsize(i), s?(8<<(s-1)):1); + srslte_tc_interl_LTE_gen_interl(&h->interleaver[s][i], srslte_cbsegm_cbsize(i), s ? (8 << (s - 1)) : 1); } } } else { uint32_t nof_subblocks; if (dec_type < SRSLTE_TDEC_SSE8_WINDOW) { - if ((h->nof_blocks16[0] = h->dec16[0]->tdec_init(&h->dec16_hdlr[0], h->max_long_cb))<0) { + if ((h->nof_blocks16[0] = h->dec16[0]->tdec_init(&h->dec16_hdlr[0], h->max_long_cb)) < 0) { goto clean_and_exit; } nof_subblocks = h->nof_blocks16[0]; } else { - if ((h->nof_blocks8[0] = h->dec8[0]->tdec_init(&h->dec8_hdlr[0], h->max_long_cb))<0) { + if ((h->nof_blocks8[0] = h->dec8[0]->tdec_init(&h->dec8_hdlr[0], h->max_long_cb)) < 0) { goto clean_and_exit; } nof_subblocks = h->nof_blocks8[0]; } - for (int i=0;iinterleaver[interleaver_idx(nof_subblocks)][i], srslte_cbsegm_cbsize(i)) < 0) { goto clean_and_exit; } - srslte_tc_interl_LTE_gen_interl(&h->interleaver[interleaver_idx(nof_subblocks)][i], srslte_cbsegm_cbsize(i), nof_subblocks); + srslte_tc_interl_LTE_gen_interl( + &h->interleaver[interleaver_idx(nof_subblocks)][i], srslte_cbsegm_cbsize(i), nof_subblocks); } } h->current_cbidx = -1; - ret = 0; + ret = 0; clean_and_exit: if (ret == -1) { @@ -330,7 +316,7 @@ clean_and_exit: return ret; } -void srslte_tdec_free(srslte_tdec_t * h) +void srslte_tdec_free(srslte_tdec_t* h) { if (h->app1) { free(h->app1); @@ -357,18 +343,18 @@ void srslte_tdec_free(srslte_tdec_t * h) free(h->input_conv); } - for (int td=0;tddec8[td] && h->dec8_hdlr[td]) { h->dec8[td]->tdec_free(h->dec8_hdlr[td]); } } - for (int td=0;tddec16[td] && h->dec16_hdlr[td]) { h->dec16[td]->tdec_free(h->dec16_hdlr[td]); } } - for (int s=0;s<4;s++) { - for (int i=0;iinterleaver[s][i]); } } @@ -376,38 +362,40 @@ void srslte_tdec_free(srslte_tdec_t * h) bzero(h, sizeof(srslte_tdec_t)); } -void srslte_tdec_force_not_sb(srslte_tdec_t *h) { +void srslte_tdec_force_not_sb(srslte_tdec_t* h) +{ h->force_not_sb = true; } -static void tdec_decision_byte(srslte_tdec_t * h, uint8_t *output) +static void tdec_decision_byte(srslte_tdec_t* h, uint8_t* output) { if (h->current_llr_type == SRSLTE_TDEC_16) { - h->dec16[h->current_dec]->tdec_decision_byte(!(h->n_iter%2)?h->app1:h->ext1, output, h->current_long_cb); + h->dec16[h->current_dec]->tdec_decision_byte(!(h->n_iter % 2) ? h->app1 : h->ext1, output, h->current_long_cb); } else { - h->dec8[h->current_dec]->tdec_decision_byte(!(h->n_iter%2)?(int8_t*)h->app1:(int8_t*)h->ext1, output, h->current_long_cb); + h->dec8[h->current_dec]->tdec_decision_byte( + !(h->n_iter % 2) ? (int8_t*)h->app1 : (int8_t*)h->ext1, output, h->current_long_cb); } } - /* Returns number of subblocks in automatic mode for this long_cb */ uint32_t srslte_tdec_autoimp_get_subblocks(uint32_t long_cb) { #ifdef LV_HAVE_AVX2 - if (!(long_cb%16) && long_cb > 800) { + if (!(long_cb % 16) && long_cb > 800) { return 16; } else #endif - if (!(long_cb%8) && long_cb > 400) { + if (!(long_cb % 8) && long_cb > 400) { return 8; } else { return 0; } } -static int tdec_sb_idx(uint32_t long_cb) { +static int tdec_sb_idx(uint32_t long_cb) +{ uint32_t nof_sb = srslte_tdec_autoimp_get_subblocks(long_cb); - switch(nof_sb) { + switch (nof_sb) { case 16: return AUTO_16_AVXWIN; case 8: @@ -422,56 +410,57 @@ static int tdec_sb_idx(uint32_t long_cb) { uint32_t srslte_tdec_autoimp_get_subblocks_8bit(uint32_t long_cb) { #ifdef LV_HAVE_AVX2 - if (!(long_cb%32) && long_cb > 2048) { + if (!(long_cb % 32) && long_cb > 2048) { return 32; } else #endif - if (!(long_cb%16) && long_cb > 800) { + if (!(long_cb % 16) && long_cb > 800) { return 16; - } else if (!(long_cb%8) && long_cb > 400) { + } else if (!(long_cb % 8) && long_cb > 400) { return 8; } else { return 0; } } -static int tdec_sb_idx_8(uint32_t long_cb) { +static int tdec_sb_idx_8(uint32_t long_cb) +{ uint32_t nof_sb = srslte_tdec_autoimp_get_subblocks_8bit(long_cb); - switch(nof_sb) { + switch (nof_sb) { case 32: return AUTO_8_AVXWIN; case 16: return AUTO_8_SSEWIN; case 8: - return 10+AUTO_16_SSEWIN; + return 10 + AUTO_16_SSEWIN; case 0: - return 10+AUTO_16_SSE; + return 10 + AUTO_16_SSE; } ERROR("Error in tdec_sb_idx_8() invalid nof_sb=%d\n", nof_sb); return 0; } // TODO: Implement SSE version. Don't really a problem since this only called at very low rates -static void convert_8_to_16(int8_t *in, int16_t *out, uint32_t len) +static void convert_8_to_16(int8_t* in, int16_t* out, uint32_t len) { - for (int i=0;idec_type == SRSLTE_TDEC_AUTO) { - h->current_llr_type = SRSLTE_TDEC_8; - h->current_dec = tdec_sb_idx_8(h->current_long_cb); + h->current_llr_type = SRSLTE_TDEC_8; + h->current_dec = tdec_sb_idx_8(h->current_long_cb); h->current_inter_idx = interleaver_idx(h->nof_blocks8[h->current_dec]); // If long_cb is not multiple of any 8-bit decoder, use a 16-bit decoder and do type conversion @@ -486,7 +475,7 @@ static void tdec_iteration_8(srslte_tdec_t * h, int8_t * input) if (h->current_llr_type == SRSLTE_TDEC_16) { if (!h->n_iter) { - convert_8_to_16(input, h->input_conv, 3*h->current_long_cb+12); + convert_8_to_16(input, h->input_conv, 3 * h->current_long_cb + 12); } run_tdec_iteration_16bit(h, h->input_conv); } else { @@ -494,12 +483,12 @@ static void tdec_iteration_8(srslte_tdec_t * h, int8_t * input) } } -static void tdec_iteration_16(srslte_tdec_t * h, int16_t * input) +static void tdec_iteration_16(srslte_tdec_t* h, int16_t* input) { // Select decoder if in auto mode if (h->dec_type == SRSLTE_TDEC_AUTO) { h->current_llr_type = SRSLTE_TDEC_16; - h->current_dec = tdec_sb_idx(h->current_long_cb); + h->current_dec = tdec_sb_idx(h->current_long_cb); } else { h->current_dec = 0; } @@ -510,7 +499,7 @@ static void tdec_iteration_16(srslte_tdec_t * h, int16_t * input) h->current_inter_idx = interleaver_idx(h->nof_blocks8[h->current_dec]); if (!h->n_iter) { - convert_16_to_8(input, h->input_conv, 3*h->current_long_cb+12); + convert_16_to_8(input, h->input_conv, 3 * h->current_long_cb + 12); } run_tdec_iteration_8bit(h, h->input_conv); } else { @@ -519,14 +508,14 @@ static void tdec_iteration_16(srslte_tdec_t * h, int16_t * input) } /* Resets the decoder and sets the codeblock length */ -int srslte_tdec_new_cb(srslte_tdec_t * h, uint32_t long_cb) +int srslte_tdec_new_cb(srslte_tdec_t* h, uint32_t long_cb) { if (long_cb > h->max_long_cb) { ERROR("TDEC was initialized for max_long_cb=%d\n", h->max_long_cb); return -1; } - h->n_iter = 0; + h->n_iter = 0; h->current_long_cb = long_cb; h->current_cbidx = srslte_cbsegm_cbindex(long_cb); if (h->current_cbidx < 0) { @@ -536,7 +525,7 @@ int srslte_tdec_new_cb(srslte_tdec_t * h, uint32_t long_cb) return 0; } -void srslte_tdec_iteration(srslte_tdec_t * h, int16_t * input, uint8_t *output) +void srslte_tdec_iteration(srslte_tdec_t* h, int16_t* input, uint8_t* output) { if (h->current_cbidx >= 0) { tdec_iteration_16(h, input); @@ -545,8 +534,7 @@ void srslte_tdec_iteration(srslte_tdec_t * h, int16_t * input, uint8_t *output) } /* Runs nof_iterations iterations and decides the output bits */ -int srslte_tdec_run_all(srslte_tdec_t * h, int16_t * input, uint8_t *output, - uint32_t nof_iterations, uint32_t long_cb) +int srslte_tdec_run_all(srslte_tdec_t* h, int16_t* input, uint8_t* output, uint32_t nof_iterations, uint32_t long_cb) { if (srslte_tdec_new_cb(h, long_cb)) { return SRSLTE_ERROR; @@ -561,8 +549,7 @@ int srslte_tdec_run_all(srslte_tdec_t * h, int16_t * input, uint8_t *output, return SRSLTE_SUCCESS; } - -void srslte_tdec_iteration_8bit(srslte_tdec_t * h, int8_t * input, uint8_t *output) +void srslte_tdec_iteration_8bit(srslte_tdec_t* h, int8_t* input, uint8_t* output) { if (h->current_cbidx >= 0) { tdec_iteration_8(h, input); @@ -571,8 +558,11 @@ void srslte_tdec_iteration_8bit(srslte_tdec_t * h, int8_t * input, uint8_t *outp } /* Runs nof_iterations iterations and decides the output bits */ -int srslte_tdec_run_all_8bit(srslte_tdec_t * h, int8_t * input, uint8_t *output, - uint32_t nof_iterations, uint32_t long_cb) +int srslte_tdec_run_all_8bit(srslte_tdec_t* h, + int8_t* input, + uint8_t* output, + uint32_t nof_iterations, + uint32_t long_cb) { if (srslte_tdec_new_cb(h, long_cb)) { return SRSLTE_ERROR; @@ -587,9 +577,7 @@ int srslte_tdec_run_all_8bit(srslte_tdec_t * h, int8_t * input, uint8_t *output, return SRSLTE_SUCCESS; } -int srslte_tdec_get_nof_iterations(srslte_tdec_t * h) +int srslte_tdec_get_nof_iterations(srslte_tdec_t* h) { return h->n_iter; } - - diff --git a/lib/src/phy/fec/turbodecoder_gen.c b/lib/src/phy/fec/turbodecoder_gen.c index 3fadafc54..c0d89986a 100644 --- a/lib/src/phy/fec/turbodecoder_gen.c +++ b/lib/src/phy/fec/turbodecoder_gen.c @@ -19,28 +19,32 @@ * */ +#include +#include #include #include -#include #include #include -#include #include "srslte/phy/fec/turbodecoder_gen.h" #include "srslte/phy/utils/vector.h" -#define NUMSTATES 8 -#define NINPUTS 2 -#define TAIL 3 -#define TOTALTAIL 12 +#define NUMSTATES 8 +#define NINPUTS 2 +#define TAIL 3 +#define TOTALTAIL 12 #define INF 10000 #define debug_enabled 0 #if debug_enabled -#define debug_state printf("k=%5d, in=%5d, pa=%3d, out=%5d, alpha=", k, x, parity[k-1], out); srslte_vec_fprint_s(stdout, alpha, 8); \ - printf(", beta="); srslte_vec_fprint_s(stdout, &beta[8*(k)], 8); printf("\n"); +#define debug_state \ + printf("k=%5d, in=%5d, pa=%3d, out=%5d, alpha=", k, x, parity[k - 1], out); \ + srslte_vec_fprint_s(stdout, alpha, 8); \ + printf(", beta="); \ + srslte_vec_fprint_s(stdout, &beta[8 * (k)], 8); \ + printf("\n"); #else #define debug_state #endif @@ -51,13 +55,13 @@ * Decoder * ************************************************/ -static void map_gen_beta(tdec_gen_t *s, int16_t *input, int16_t *app, int16_t *parity, uint32_t long_cb) +static void map_gen_beta(tdec_gen_t* s, int16_t* input, int16_t* app, int16_t* parity, uint32_t long_cb) { - int16_t m_b[8], new[8], old[8]; - int16_t x, y, xy; - int k; - uint32_t end = long_cb + SRSLTE_TCOD_RATE; - int16_t *beta = s->beta; + int16_t m_b[8], new[8], old[8]; + int16_t x, y, xy; + int k; + uint32_t end = long_cb + SRSLTE_TCOD_RATE; + int16_t* beta = s->beta; uint32_t i; for (i = 0; i < 8; i++) { @@ -66,7 +70,7 @@ static void map_gen_beta(tdec_gen_t *s, int16_t *input, int16_t *app, int16_t *p for (k = end - 1; k >= 0; k--) { x = input[k]; - if (app && k new[i]) new[i] = m_b[i]; - old[i] = new[i]; + old[i] = new[i]; beta[8 * k + i] = old[i]; } - if ((k%4)==0 && k < long_cb) { + if ((k % 4) == 0 && k < long_cb) { for (i = 1; i < 8; i++) { old[i] -= old[0]; } @@ -107,15 +111,16 @@ static void map_gen_beta(tdec_gen_t *s, int16_t *input, int16_t *app, int16_t *p } } -static void map_gen_alpha(tdec_gen_t *s, int16_t *input, int16_t *app, int16_t *parity, int16_t *output, uint32_t long_cb) +static void +map_gen_alpha(tdec_gen_t* s, int16_t* input, int16_t* app, int16_t* parity, int16_t* output, uint32_t long_cb) { - int16_t m_b[8], new[8], old[8], max1[8], max0[8]; - int16_t m1, m0; - int16_t x, y, xy; - int16_t out; + int16_t m_b[8], new[8], old[8], max1[8], max0[8]; + int16_t m1, m0; + int16_t x, y, xy; + int16_t out; uint32_t k; - uint32_t end = long_cb; - int16_t *beta = s->beta; + uint32_t end = long_cb; + int16_t* beta = s->beta; uint32_t i; old[0] = 0; @@ -137,7 +142,7 @@ static void map_gen_alpha(tdec_gen_t *s, int16_t *input, int16_t *app, int16_t * xy = x + y; #if debug_enabled - memcpy(alpha, old, sizeof(int16_t)*8); + memcpy(alpha, old, sizeof(int16_t) * 8); #endif m_b[0] = old[0]; @@ -175,28 +180,28 @@ static void map_gen_alpha(tdec_gen_t *s, int16_t *input, int16_t *app, int16_t * for (i = 0; i < 8; i++) { if (m_b[i] > new[i]) new[i] = m_b[i]; - old[i] = new[i]; } + old[i] = new[i]; + } - if ((k%4)==0) { + if ((k % 4) == 0) { for (i = 1; i < 8; i++) { old[i] -= old[0]; } old[0] = 0; } - out = m1 - m0; + out = m1 - m0; output[k - 1] = out; debug_state; - } } -int tdec_gen_init(void **hh, uint32_t max_long_cb) +int tdec_gen_init(void** hh, uint32_t max_long_cb) { *hh = calloc(1, sizeof(tdec_gen_t)); - tdec_gen_t *h = (tdec_gen_t*) *hh; + tdec_gen_t* h = (tdec_gen_t*)*hh; h->beta = srslte_vec_malloc(sizeof(int16_t) * (max_long_cb + SRSLTE_TCOD_TOTALTAIL + 1) * NUMSTATES); if (!h->beta) { @@ -207,9 +212,9 @@ int tdec_gen_init(void **hh, uint32_t max_long_cb) return 1; } -void tdec_gen_free(void *hh) +void tdec_gen_free(void* hh) { - tdec_gen_t *h = (tdec_gen_t*) hh; + tdec_gen_t* h = (tdec_gen_t*)hh; if (h) { if (h->beta) { free(h->beta); @@ -218,9 +223,9 @@ void tdec_gen_free(void *hh) } } -void tdec_gen_dec(void *hh, int16_t *input, int16_t *app, int16_t *parity, int16_t *output, uint32_t long_cb) +void tdec_gen_dec(void* hh, int16_t* input, int16_t* app, int16_t* parity, int16_t* output, uint32_t long_cb) { - tdec_gen_t *h = (tdec_gen_t*) hh; + tdec_gen_t* h = (tdec_gen_t*)hh; h->beta[(long_cb + TAIL) * NUMSTATES] = 0; for (uint32_t k = 1; k < NUMSTATES; k++) @@ -230,7 +235,12 @@ void tdec_gen_dec(void *hh, int16_t *input, int16_t *app, int16_t *parity, int16 map_gen_alpha(h, input, app, parity, output, long_cb); } -void tdec_gen_extract_input(int16_t *input, int16_t *syst, int16_t *app2, int16_t *parity0, int16_t *parity1, uint32_t long_cb) +void tdec_gen_extract_input(int16_t* input, + int16_t* syst, + int16_t* app2, + int16_t* parity0, + int16_t* parity1, + uint32_t long_cb) { // Prepare systematic and parity bits for MAP DEC #1 for (uint32_t i = 0; i < long_cb; i++) { @@ -243,28 +253,25 @@ void tdec_gen_extract_input(int16_t *input, int16_t *syst, int16_t *app2, int16_ parity0[i] = input[SRSLTE_TCOD_RATE * long_cb + NINPUTS * (i - long_cb) + 1]; app2[i] = input[SRSLTE_TCOD_RATE * long_cb + NINPUTS * SRSLTE_TCOD_RATE + NINPUTS * (i - long_cb)]; - parity1[i] = input[SRSLTE_TCOD_RATE * long_cb + NINPUTS * SRSLTE_TCOD_RATE - + NINPUTS * (i - long_cb) + 1]; + parity1[i] = input[SRSLTE_TCOD_RATE * long_cb + NINPUTS * SRSLTE_TCOD_RATE + NINPUTS * (i - long_cb) + 1]; } - } -void tdec_gen_decision_byte(int16_t *app1, uint8_t *output, uint32_t long_cb) +void tdec_gen_decision_byte(int16_t* app1, uint8_t* output, uint32_t long_cb) { uint8_t mask[8] = {0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1}; // long_cb is always byte aligned - for (uint32_t i = 0; i < long_cb/8; i++) { - uint8_t out0 = app1[8*i+0]>0?mask[0]:0; - uint8_t out1 = app1[8*i+1]>0?mask[1]:0; - uint8_t out2 = app1[8*i+2]>0?mask[2]:0; - uint8_t out3 = app1[8*i+3]>0?mask[3]:0; - uint8_t out4 = app1[8*i+4]>0?mask[4]:0; - uint8_t out5 = app1[8*i+5]>0?mask[5]:0; - uint8_t out6 = app1[8*i+6]>0?mask[6]:0; - uint8_t out7 = app1[8*i+7]>0?mask[7]:0; + for (uint32_t i = 0; i < long_cb / 8; i++) { + uint8_t out0 = app1[8 * i + 0] > 0 ? mask[0] : 0; + uint8_t out1 = app1[8 * i + 1] > 0 ? mask[1] : 0; + uint8_t out2 = app1[8 * i + 2] > 0 ? mask[2] : 0; + uint8_t out3 = app1[8 * i + 3] > 0 ? mask[3] : 0; + uint8_t out4 = app1[8 * i + 4] > 0 ? mask[4] : 0; + uint8_t out5 = app1[8 * i + 5] > 0 ? mask[5] : 0; + uint8_t out6 = app1[8 * i + 6] > 0 ? mask[6] : 0; + uint8_t out7 = app1[8 * i + 7] > 0 ? mask[7] : 0; output[i] = out0 | out1 | out2 | out3 | out4 | out5 | out6 | out7; } } - diff --git a/lib/src/phy/fec/turbodecoder_sse.c b/lib/src/phy/fec/turbodecoder_sse.c index c6286645f..cc3acd72f 100644 --- a/lib/src/phy/fec/turbodecoder_sse.c +++ b/lib/src/phy/fec/turbodecoder_sse.c @@ -19,12 +19,12 @@ * */ +#include +#include #include #include -#include #include #include -#include #include "srslte/phy/fec/turbodecoder_sse.h" #include "srslte/phy/utils/vector.h" @@ -36,53 +36,57 @@ #endif - -#define NUMSTATES 8 -#define NINPUTS 2 -#define TAIL 3 -#define TOTALTAIL 12 +#define NUMSTATES 8 +#define NINPUTS 2 +#define TAIL 3 +#define TOTALTAIL 12 #define INF 10000 - #ifdef LV_HAVE_SSE - #define debug_enabled 0 #if debug_enabled -#define debug_state(c,d) printf("k=%5d, in=%5d, pa=%5d, out=%5d, alpha=", k-d,\ - s->branch[2*(k-d)] + s->branch[2*(k-d)+1], \ - -s->branch[2*(k-d)] + s->branch[2*(k-d)+1], output[k-d]);print_128i(alpha_k);\ - printf(", beta=");print_128i(beta_k);printf("\n"); - -static void print_128i(__m128i x) { - int16_t *s = (int16_t*) &x; +#define debug_state(c, d) \ + printf("k=%5d, in=%5d, pa=%5d, out=%5d, alpha=", \ + k - d, \ + s->branch[2 * (k - d)] + s->branch[2 * (k - d) + 1], \ + -s->branch[2 * (k - d)] + s->branch[2 * (k - d) + 1], \ + output[k - d]); \ + print_128i(alpha_k); \ + printf(", beta="); \ + print_128i(beta_k); \ + printf("\n"); + +static void print_128i(__m128i x) +{ + int16_t* s = (int16_t*)&x; printf("[%5d", s[0]); - for (int i=1;i<8;i++) { + for (int i = 1; i < 8; i++) { printf(",%5d", s[i]); } printf("]"); } -static uint32_t max_128i(__m128i x) { - int16_t *s = (int16_t*) &x; - int16_t m = -INF; +static uint32_t max_128i(__m128i x) +{ + int16_t* s = (int16_t*)&x; + int16_t m = -INF; uint32_t max = 0; - for (int i=1;i<8;i++) { + for (int i = 1; i < 8; i++) { if (s[i] > m) { max = i; - m = s[i]; + m = s[i]; } } return max; } #else -#define debug_state(c,d) +#define debug_state(c, d) #endif - //#define use_beta_transposed_max #ifndef use_beta_transposed_max @@ -96,264 +100,293 @@ static inline int16_t hMax(__m128i buffer) } /* Computes beta values */ -void tdec_sse_beta(tdec_sse_t * s, int16_t * output, uint32_t long_cb) +void tdec_sse_beta(tdec_sse_t* s, int16_t* output, uint32_t long_cb) { - int k; - uint32_t end = long_cb + 3; - const __m128i *alphaPtr = (const __m128i*) s->alpha; - + int k; + uint32_t end = long_cb + 3; + const __m128i* alphaPtr = (const __m128i*)s->alpha; + __m128i beta_k = _mm_set_epi16(-INF, -INF, -INF, -INF, -INF, -INF, -INF, 0); - __m128i g, bp, bn, alpha_k; - + __m128i g, bp, bn, alpha_k; + /* Define the shuffle constant for the positive beta */ - __m128i shuf_bp = _mm_set_epi8( - 15, 14, // 7 - 7, 6, // 3 - 5, 4, // 2 - 13, 12, // 6 - 11, 10, // 5 - 3, 2, // 1 - 1, 0, // 0 - 9, 8 // 4 + __m128i shuf_bp = _mm_set_epi8(15, + 14, // 7 + 7, + 6, // 3 + 5, + 4, // 2 + 13, + 12, // 6 + 11, + 10, // 5 + 3, + 2, // 1 + 1, + 0, // 0 + 9, + 8 // 4 ); /* Define the shuffle constant for the negative beta */ - __m128i shuf_bn = _mm_set_epi8( - 7, 6, // 3 - 15, 14, // 7 - 13, 12, // 6 - 5, 4, // 2 - 3, 2, // 1 - 11, 10, // 5 - 9, 8, // 4 - 1, 0 // 0 + __m128i shuf_bn = _mm_set_epi8(7, + 6, // 3 + 15, + 14, // 7 + 13, + 12, // 6 + 5, + 4, // 2 + 3, + 2, // 1 + 11, + 10, // 5 + 9, + 8, // 4 + 1, + 0 // 0 ); - - alphaPtr += long_cb-1; + + alphaPtr += long_cb - 1; /* Define shuffle for branch costs */ - __m128i shuf_g[4]; - shuf_g[3] = _mm_set_epi8(3,2,1,0,1,0,3,2,3,2,1,0,1,0,3,2); - shuf_g[2] = _mm_set_epi8(7,6,5,4,5,4,7,6,7,6,5,4,5,4,7,6); - shuf_g[1] = _mm_set_epi8(11,10,9,8,9,8,11,10,11,10,9,8,9,8,11,10); - shuf_g[0] = _mm_set_epi8(15,14,13,12,13,12,15,14,15,14,13,12,13,12,15,14); - __m128i gv; - int16_t *b = &s->branch[2*long_cb-8]; - __m128i *gPtr = (__m128i*) b; + __m128i shuf_g[4]; + shuf_g[3] = _mm_set_epi8(3, 2, 1, 0, 1, 0, 3, 2, 3, 2, 1, 0, 1, 0, 3, 2); + shuf_g[2] = _mm_set_epi8(7, 6, 5, 4, 5, 4, 7, 6, 7, 6, 5, 4, 5, 4, 7, 6); + shuf_g[1] = _mm_set_epi8(11, 10, 9, 8, 9, 8, 11, 10, 11, 10, 9, 8, 9, 8, 11, 10); + shuf_g[0] = _mm_set_epi8(15, 14, 13, 12, 13, 12, 15, 14, 15, 14, 13, 12, 13, 12, 15, 14); + __m128i gv; + int16_t* b = &s->branch[2 * long_cb - 8]; + __m128i* gPtr = (__m128i*)b; /* Define shuffle for beta normalization */ - __m128i shuf_norm = _mm_set_epi8(1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0); - - /* This defines a beta computation step: - * Adds and substracts the branch metrics to the previous beta step, - * shuffles the states according to the trellis path and selects maximum state + __m128i shuf_norm = _mm_set_epi8(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0); + + /* This defines a beta computation step: + * Adds and substracts the branch metrics to the previous beta step, + * shuffles the states according to the trellis path and selects maximum state */ -#define BETA_STEP(g) bp = _mm_add_epi16(beta_k, g);\ - bn = _mm_sub_epi16(beta_k, g);\ - bp = _mm_shuffle_epi8(bp, shuf_bp);\ - bn = _mm_shuffle_epi8(bn, shuf_bn);\ - beta_k = _mm_max_epi16(bp, bn); - - /* Loads the alpha metrics from memory and adds them to the temporal bn and bp - * metrics. Then computes horizontal maximum of both metrics and computes difference - */ -#define BETA_STEP_CNT(c,d) g = _mm_shuffle_epi8(gv, shuf_g[c]);\ - BETA_STEP(g)\ - alpha_k = _mm_load_si128(alphaPtr);\ - alphaPtr--;\ - bp = _mm_add_epi16(bp, alpha_k);\ - bn = _mm_add_epi16(bn, alpha_k);\ - output[k-d] = hMax(bn)-hMax(bp);\ - debug_state(c,d); - - - /* The tail does not require to load alpha or produce outputs. Only update +#define BETA_STEP(g) \ + bp = _mm_add_epi16(beta_k, g); \ + bn = _mm_sub_epi16(beta_k, g); \ + bp = _mm_shuffle_epi8(bp, shuf_bp); \ + bn = _mm_shuffle_epi8(bn, shuf_bn); \ + beta_k = _mm_max_epi16(bp, bn); + + /* Loads the alpha metrics from memory and adds them to the temporal bn and bp + * metrics. Then computes horizontal maximum of both metrics and computes difference + */ +#define BETA_STEP_CNT(c, d) \ + g = _mm_shuffle_epi8(gv, shuf_g[c]); \ + BETA_STEP(g) \ + alpha_k = _mm_load_si128(alphaPtr); \ + alphaPtr--; \ + bp = _mm_add_epi16(bp, alpha_k); \ + bn = _mm_add_epi16(bn, alpha_k); \ + output[k - d] = hMax(bn) - hMax(bp); \ + debug_state(c, d); + + /* The tail does not require to load alpha or produce outputs. Only update * beta metrics accordingly */ - for (k=end-1; k>=long_cb; k--) { - int16_t g0 = s->branch[2*k]; - int16_t g1 = s->branch[2*k+1]; - g = _mm_set_epi16(g1, g0, g0, g1, g1, g0, g0, g1); + for (k = end - 1; k >= long_cb; k--) { + int16_t g0 = s->branch[2 * k]; + int16_t g1 = s->branch[2 * k + 1]; + g = _mm_set_epi16(g1, g0, g0, g1, g1, g0, g0, g1); BETA_STEP(g); } - + /* We inline 2 trelis steps for each normalization */ __m128i norm; - for (; k >= 0; k-=8) { + for (; k >= 0; k -= 8) { gv = _mm_load_si128(gPtr); gPtr--; - BETA_STEP_CNT(0,0); - BETA_STEP_CNT(1,1); - BETA_STEP_CNT(2,2); - BETA_STEP_CNT(3,3); - norm = _mm_shuffle_epi8(beta_k, shuf_norm); + BETA_STEP_CNT(0, 0); + BETA_STEP_CNT(1, 1); + BETA_STEP_CNT(2, 2); + BETA_STEP_CNT(3, 3); + norm = _mm_shuffle_epi8(beta_k, shuf_norm); beta_k = _mm_sub_epi16(beta_k, norm); - gv = _mm_load_si128(gPtr); + gv = _mm_load_si128(gPtr); gPtr--; - BETA_STEP_CNT(0,4); - BETA_STEP_CNT(1,5); - BETA_STEP_CNT(2,6); - BETA_STEP_CNT(3,7); - - norm = _mm_shuffle_epi8(beta_k, shuf_norm); + BETA_STEP_CNT(0, 4); + BETA_STEP_CNT(1, 5); + BETA_STEP_CNT(2, 6); + BETA_STEP_CNT(3, 7); + + norm = _mm_shuffle_epi8(beta_k, shuf_norm); beta_k = _mm_sub_epi16(beta_k, norm); - } + } } #endif /* Computes alpha metrics */ -void tdec_sse_alpha(tdec_sse_t * s, uint32_t long_cb) +void tdec_sse_alpha(tdec_sse_t* s, uint32_t long_cb) { uint32_t k; - int16_t *alpha = s->alpha; + int16_t* alpha = s->alpha; uint32_t i; - alpha[0] = 0; + alpha[0] = 0; for (i = 1; i < 8; i++) { alpha[i] = -INF; } - + /* Define the shuffle constant for the positive alpha */ - __m128i shuf_ap = _mm_set_epi8( - 15, 14, // 7 - 9, 8, // 4 - 7, 6, // 3 - 1, 0, // 0 - 13, 12, // 6 - 11, 10, // 5 - 5, 4, // 2 - 3, 2 // 1 + __m128i shuf_ap = _mm_set_epi8(15, + 14, // 7 + 9, + 8, // 4 + 7, + 6, // 3 + 1, + 0, // 0 + 13, + 12, // 6 + 11, + 10, // 5 + 5, + 4, // 2 + 3, + 2 // 1 ); /* Define the shuffle constant for the negative alpha */ - __m128i shuf_an = _mm_set_epi8( - 13, 12, // 6 - 11, 10, // 5 - 5, 4, // 2 - 3, 2, // 1 - 15, 14, // 7 - 9, 8, // 4 - 7, 6, // 3 - 1, 0 // 0 + __m128i shuf_an = _mm_set_epi8(13, + 12, // 6 + 11, + 10, // 5 + 5, + 4, // 2 + 3, + 2, // 1 + 15, + 14, // 7 + 9, + 8, // 4 + 7, + 6, // 3 + 1, + 0 // 0 ); - + /* Define shuffle for branch costs */ __m128i shuf_g[4]; - shuf_g[0] = _mm_set_epi8(3,2,3,2,1,0,1,0,1,0,1,0,3,2,3,2); - shuf_g[1] = _mm_set_epi8(7,6,7,6,5,4,5,4,5,4,5,4,7,6,7,6); - shuf_g[2] = _mm_set_epi8(11,10,11,10,9,8,9,8,9,8,9,8,11,10,11,10); - shuf_g[3] = _mm_set_epi8(15,14,15,14,13,12,13,12,13,12,13,12,15,14,15,14); - - __m128i shuf_norm = _mm_set_epi8(1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0); - - __m128i* alphaPtr = (__m128i*) alpha; + shuf_g[0] = _mm_set_epi8(3, 2, 3, 2, 1, 0, 1, 0, 1, 0, 1, 0, 3, 2, 3, 2); + shuf_g[1] = _mm_set_epi8(7, 6, 7, 6, 5, 4, 5, 4, 5, 4, 5, 4, 7, 6, 7, 6); + shuf_g[2] = _mm_set_epi8(11, 10, 11, 10, 9, 8, 9, 8, 9, 8, 9, 8, 11, 10, 11, 10); + shuf_g[3] = _mm_set_epi8(15, 14, 15, 14, 13, 12, 13, 12, 13, 12, 13, 12, 15, 14, 15, 14); + + __m128i shuf_norm = _mm_set_epi8(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0); + + __m128i* alphaPtr = (__m128i*)alpha; alphaPtr++; - __m128i gv; - __m128i *gPtr = (__m128i*) s->branch; - __m128i g, ap, an; - + __m128i gv; + __m128i* gPtr = (__m128i*)s->branch; + __m128i g, ap, an; + __m128i alpha_k = _mm_set_epi16(-INF, -INF, -INF, -INF, -INF, -INF, -INF, 0); - - /* This defines a alpha computation step: - * Adds and substracts the branch metrics to the previous alpha step, - * shuffles the states according to the trellis path and selects maximum state + + /* This defines a alpha computation step: + * Adds and substracts the branch metrics to the previous alpha step, + * shuffles the states according to the trellis path and selects maximum state */ -#define ALPHA_STEP(c) g = _mm_shuffle_epi8(gv, shuf_g[c]); \ - ap = _mm_add_epi16(alpha_k, g);\ - an = _mm_sub_epi16(alpha_k, g);\ - ap = _mm_shuffle_epi8(ap, shuf_ap);\ - an = _mm_shuffle_epi8(an, shuf_an);\ - alpha_k = _mm_max_epi16(ap, an);\ - _mm_store_si128(alphaPtr, alpha_k);\ - alphaPtr++; \ +#define ALPHA_STEP(c) \ + g = _mm_shuffle_epi8(gv, shuf_g[c]); \ + ap = _mm_add_epi16(alpha_k, g); \ + an = _mm_sub_epi16(alpha_k, g); \ + ap = _mm_shuffle_epi8(ap, shuf_ap); \ + an = _mm_shuffle_epi8(an, shuf_an); \ + alpha_k = _mm_max_epi16(ap, an); \ + _mm_store_si128(alphaPtr, alpha_k); \ + alphaPtr++; /* In this loop, we compute 8 steps and normalize twice for each branch metrics memory load */ __m128i norm; - for (k = 0; k < long_cb/8; k++) { + for (k = 0; k < long_cb / 8; k++) { gv = _mm_load_si128(gPtr); gPtr++; ALPHA_STEP(0); ALPHA_STEP(1); ALPHA_STEP(2); ALPHA_STEP(3); - norm = _mm_shuffle_epi8(alpha_k, shuf_norm); + norm = _mm_shuffle_epi8(alpha_k, shuf_norm); alpha_k = _mm_sub_epi16(alpha_k, norm); - gv = _mm_load_si128(gPtr); + gv = _mm_load_si128(gPtr); gPtr++; ALPHA_STEP(0); ALPHA_STEP(1); ALPHA_STEP(2); ALPHA_STEP(3); - norm = _mm_shuffle_epi8(alpha_k, shuf_norm); + norm = _mm_shuffle_epi8(alpha_k, shuf_norm); alpha_k = _mm_sub_epi16(alpha_k, norm); - } + } } /* Compute branch metrics (gamma) */ -void tdec_sse_gamma(tdec_sse_t * h, int16_t *input, int16_t *app, int16_t *parity, uint32_t long_cb) +void tdec_sse_gamma(tdec_sse_t* h, int16_t* input, int16_t* app, int16_t* parity, uint32_t long_cb) { - __m128i res00, res10, res01, res11, res0, res1; + __m128i res00, res10, res01, res11, res0, res1; __m128i in, ap, pa, g1, g0; - __m128i *inPtr = (__m128i*) input; - __m128i *appPtr = (__m128i*) app; - __m128i *paPtr = (__m128i*) parity; - __m128i *resPtr = (__m128i*) h->branch; - - __m128i res00_mask = _mm_set_epi8(0xff,0xff,7,6,0xff,0xff,5,4,0xff,0xff,3,2,0xff,0xff,1,0); - __m128i res10_mask = _mm_set_epi8(0xff,0xff,15,14,0xff,0xff,13,12,0xff,0xff,11,10,0xff,0xff,9,8); - __m128i res01_mask = _mm_set_epi8(7,6,0xff,0xff,5,4,0xff,0xff,3,2,0xff,0xff,1,0,0xff,0xff); - __m128i res11_mask = _mm_set_epi8(15,14,0xff,0xff,13,12,0xff,0xff,11,10,0xff,0xff,9,8,0xff,0xff); - - for (int i=0;ibranch; + + __m128i res00_mask = _mm_set_epi8(0xff, 0xff, 7, 6, 0xff, 0xff, 5, 4, 0xff, 0xff, 3, 2, 0xff, 0xff, 1, 0); + __m128i res10_mask = _mm_set_epi8(0xff, 0xff, 15, 14, 0xff, 0xff, 13, 12, 0xff, 0xff, 11, 10, 0xff, 0xff, 9, 8); + __m128i res01_mask = _mm_set_epi8(7, 6, 0xff, 0xff, 5, 4, 0xff, 0xff, 3, 2, 0xff, 0xff, 1, 0, 0xff, 0xff); + __m128i res11_mask = _mm_set_epi8(15, 14, 0xff, 0xff, 13, 12, 0xff, 0xff, 11, 10, 0xff, 0xff, 9, 8, 0xff, 0xff); + + for (int i = 0; i < long_cb / 8; i++) { in = _mm_load_si128(inPtr); inPtr++; pa = _mm_load_si128(paPtr); paPtr++; - + if (appPtr) { ap = _mm_load_si128(appPtr); appPtr++; in = _mm_add_epi16(ap, in); } - + g1 = _mm_add_epi16(in, pa); g0 = _mm_sub_epi16(in, pa); g1 = _mm_srai_epi16(g1, 1); g0 = _mm_srai_epi16(g0, 1); - + res00 = _mm_shuffle_epi8(g0, res00_mask); res10 = _mm_shuffle_epi8(g0, res10_mask); res01 = _mm_shuffle_epi8(g1, res01_mask); res11 = _mm_shuffle_epi8(g1, res11_mask); - res0 = _mm_or_si128(res00, res01); - res1 = _mm_or_si128(res10, res11); + res0 = _mm_or_si128(res00, res01); + res1 = _mm_or_si128(res10, res11); _mm_store_si128(resPtr, res0); resPtr++; - _mm_store_si128(resPtr, res1); + _mm_store_si128(resPtr, res1); resPtr++; - //printf("k=%d, in=%d, pa=%d, g0=%d, g1=%d\n", i, input[i], parity[i], h->branch[2*i], h->branch[2*i+1]); + // printf("k=%d, in=%d, pa=%d, g0=%d, g1=%d\n", i, input[i], parity[i], h->branch[2*i], h->branch[2*i+1]); } - for (int i=long_cb;ibranch[2*i] = (input[i] - parity[i])/2; - h->branch[2*i+1] = (input[i] + parity[i])/2; + for (int i = long_cb; i < long_cb + 3; i++) { + h->branch[2 * i] = (input[i] - parity[i]) / 2; + h->branch[2 * i + 1] = (input[i] + parity[i]) / 2; } } - /* Inititalizes constituent decoder object */ -int tdec_sse_init(void **hh, uint32_t max_long_cb) +int tdec_sse_init(void** hh, uint32_t max_long_cb) { *hh = calloc(1, sizeof(tdec_sse_t)); - - tdec_sse_t *h = (tdec_sse_t*) *hh; - + + tdec_sse_t* h = (tdec_sse_t*)*hh; + h->max_long_cb = max_long_cb; h->alpha = srslte_vec_malloc(sizeof(int16_t) * (max_long_cb + TOTALTAIL + 1) * NUMSTATES); @@ -369,9 +402,9 @@ int tdec_sse_init(void **hh, uint32_t max_long_cb) return 1; } -void tdec_sse_free(void *hh) +void tdec_sse_free(void* hh) { - tdec_sse_t *h = (tdec_sse_t*) hh; + tdec_sse_t* h = (tdec_sse_t*)hh; if (h) { if (h->alpha) { @@ -385,10 +418,9 @@ void tdec_sse_free(void *hh) } /* Runs one instance of a decoder */ -void tdec_sse_dec(void *hh, int16_t * input, int16_t *app, int16_t * parity, - int16_t *output, uint32_t long_cb) +void tdec_sse_dec(void* hh, int16_t* input, int16_t* app, int16_t* parity, int16_t* output, uint32_t long_cb) { - tdec_sse_t *h = (tdec_sse_t*) hh; + tdec_sse_t* h = (tdec_sse_t*)hh; // Compute branch metrics tdec_sse_gamma(h, input, app, parity, long_cb); @@ -403,53 +435,62 @@ void tdec_sse_dec(void *hh, int16_t * input, int16_t *app, int16_t * parity, /* Deinterleaves the 3 streams from the input (systematic and 2 parity bits) into * 3 buffers ready to be used by compute_gamma() */ -void tdec_sse_extract_input(int16_t *input, int16_t *syst0, int16_t *app2, int16_t *parity0, int16_t *parity1, uint32_t long_cb) { +void tdec_sse_extract_input(int16_t* input, + int16_t* syst0, + int16_t* app2, + int16_t* parity0, + int16_t* parity1, + uint32_t long_cb) +{ uint32_t i; - __m128i *inputPtr = (__m128i*) input; - __m128i in0, in1, in2; - __m128i s0, s1, s2, s; - __m128i p00, p01, p02, p0; - __m128i p10, p11, p12, p1; + __m128i* inputPtr = (__m128i*)input; + __m128i in0, in1, in2; + __m128i s0, s1, s2, s; + __m128i p00, p01, p02, p0; + __m128i p10, p11, p12, p1; - __m128i *sysPtr = (__m128i*) syst0; - __m128i *pa0Ptr = (__m128i*) parity0; - __m128i *pa1Ptr = (__m128i*) parity1; + __m128i* sysPtr = (__m128i*)syst0; + __m128i* pa0Ptr = (__m128i*)parity0; + __m128i* pa1Ptr = (__m128i*)parity1; // pick bits 0, 3, 6 from 1st word - __m128i s0_mask = _mm_set_epi8(0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,13,12,7,6,1,0); + __m128i s0_mask = _mm_set_epi8(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 13, 12, 7, 6, 1, 0); // pick bits 1, 4, 7 from 2st word - __m128i s1_mask = _mm_set_epi8(0xff,0xff,0xff,0xff,15,14,9,8,3,2,0xff,0xff,0xff,0xff,0xff,0xff); + __m128i s1_mask = _mm_set_epi8(0xff, 0xff, 0xff, 0xff, 15, 14, 9, 8, 3, 2, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff); // pick bits 2, 5 from 3rd word - __m128i s2_mask = _mm_set_epi8(11,10,5,4,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff); + __m128i s2_mask = _mm_set_epi8(11, 10, 5, 4, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff); // pick bits 1, 4, 7 from 1st word - __m128i p00_mask = _mm_set_epi8(0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,15,14,9,8,3,2); + __m128i p00_mask = _mm_set_epi8(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 15, 14, 9, 8, 3, 2); // pick bits 2, 5, from 2st word - __m128i p01_mask = _mm_set_epi8(0xff,0xff,0xff,0xff,0xff,0xff,11,10,5,4,0xff,0xff,0xff,0xff,0xff,0xff); + __m128i p01_mask = _mm_set_epi8(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 11, 10, 5, 4, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff); // pick bits 0, 3, 6 from 3rd word - __m128i p02_mask = _mm_set_epi8(13,12,7,6,1,0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff); + __m128i p02_mask = _mm_set_epi8(13, 12, 7, 6, 1, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff); // pick bits 2, 5 from 1st word - __m128i p10_mask = _mm_set_epi8(0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,11,10,5,4); + __m128i p10_mask = _mm_set_epi8(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 11, 10, 5, 4); // pick bits 0, 3, 6, from 2st word - __m128i p11_mask = _mm_set_epi8(0xff,0xff,0xff,0xff,0xff,0xff,13,12,7,6,1,0,0xff,0xff,0xff,0xff); + __m128i p11_mask = _mm_set_epi8(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 13, 12, 7, 6, 1, 0, 0xff, 0xff, 0xff, 0xff); // pick bits 1, 4, 7 from 3rd word - __m128i p12_mask = _mm_set_epi8(15,14,9,8,3,2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff); + __m128i p12_mask = _mm_set_epi8(15, 14, 9, 8, 3, 2, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff); // Split systematic and parity bits - for (i = 0; i < long_cb/8; i++) { + for (i = 0; i < long_cb / 8; i++) { - in0 = _mm_load_si128(inputPtr); inputPtr++; - in1 = _mm_load_si128(inputPtr); inputPtr++; - in2 = _mm_load_si128(inputPtr); inputPtr++; + in0 = _mm_load_si128(inputPtr); + inputPtr++; + in1 = _mm_load_si128(inputPtr); + inputPtr++; + in2 = _mm_load_si128(inputPtr); + inputPtr++; /* Deinterleave Systematic bits */ s0 = _mm_shuffle_epi8(in0, s0_mask); s1 = _mm_shuffle_epi8(in1, s1_mask); s2 = _mm_shuffle_epi8(in2, s2_mask); - s = _mm_or_si128(s0, s1); - s = _mm_or_si128(s, s2); + s = _mm_or_si128(s0, s1); + s = _mm_or_si128(s, s2); _mm_store_si128(sysPtr, s); sysPtr++; @@ -458,8 +499,8 @@ void tdec_sse_extract_input(int16_t *input, int16_t *syst0, int16_t *app2, int16 p00 = _mm_shuffle_epi8(in0, p00_mask); p01 = _mm_shuffle_epi8(in1, p01_mask); p02 = _mm_shuffle_epi8(in2, p02_mask); - p0 = _mm_or_si128(p00, p01); - p0 = _mm_or_si128(p0, p02); + p0 = _mm_or_si128(p00, p01); + p0 = _mm_or_si128(p0, p02); _mm_store_si128(pa0Ptr, p0); pa0Ptr++; @@ -468,61 +509,56 @@ void tdec_sse_extract_input(int16_t *input, int16_t *syst0, int16_t *app2, int16 p10 = _mm_shuffle_epi8(in0, p10_mask); p11 = _mm_shuffle_epi8(in1, p11_mask); p12 = _mm_shuffle_epi8(in2, p12_mask); - p1 = _mm_or_si128(p10, p11); - p1 = _mm_or_si128(p1, p12); + p1 = _mm_or_si128(p10, p11); + p1 = _mm_or_si128(p1, p12); _mm_store_si128(pa1Ptr, p1); pa1Ptr++; - } for (i = 0; i < 3; i++) { - syst0[i+long_cb] = input[3*long_cb + 2*i]; - parity0[i+long_cb] = input[3*long_cb + 2*i + 1]; + syst0[i + long_cb] = input[3 * long_cb + 2 * i]; + parity0[i + long_cb] = input[3 * long_cb + 2 * i + 1]; } for (i = 0; i < 3; i++) { - app2[i+long_cb] = input[3*long_cb + 6 + 2*i]; - parity1[i+long_cb] = input[3*long_cb + 6 + 2*i + 1]; + app2[i + long_cb] = input[3 * long_cb + 6 + 2 * i]; + parity1[i + long_cb] = input[3 * long_cb + 6 + 2 * i + 1]; } } -void tdec_sse_decision_byte(int16_t *app1, uint8_t *output, uint32_t long_cb) +void tdec_sse_decision_byte(int16_t* app1, uint8_t* output, uint32_t long_cb) { uint8_t mask[8] = {0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1}; // long_cb is always byte aligned - for (uint32_t i = 0; i < long_cb/8; i++) { - uint8_t out0 = app1[8*i+0]>0?mask[0]:0; - uint8_t out1 = app1[8*i+1]>0?mask[1]:0; - uint8_t out2 = app1[8*i+2]>0?mask[2]:0; - uint8_t out3 = app1[8*i+3]>0?mask[3]:0; - uint8_t out4 = app1[8*i+4]>0?mask[4]:0; - uint8_t out5 = app1[8*i+5]>0?mask[5]:0; - uint8_t out6 = app1[8*i+6]>0?mask[6]:0; - uint8_t out7 = app1[8*i+7]>0?mask[7]:0; + for (uint32_t i = 0; i < long_cb / 8; i++) { + uint8_t out0 = app1[8 * i + 0] > 0 ? mask[0] : 0; + uint8_t out1 = app1[8 * i + 1] > 0 ? mask[1] : 0; + uint8_t out2 = app1[8 * i + 2] > 0 ? mask[2] : 0; + uint8_t out3 = app1[8 * i + 3] > 0 ? mask[3] : 0; + uint8_t out4 = app1[8 * i + 4] > 0 ? mask[4] : 0; + uint8_t out5 = app1[8 * i + 5] > 0 ? mask[5] : 0; + uint8_t out6 = app1[8 * i + 6] > 0 ? mask[6] : 0; + uint8_t out7 = app1[8 * i + 7] > 0 ? mask[7] : 0; output[i] = out0 | out1 | out2 | out3 | out4 | out5 | out6 | out7; } } - - - /*********************** - * - * This is an attempt to parallelize the horizontal max - * by doing a 8x8 tranpose of the vectors and computing max - * in cascade. However since we need to store 16 registers + * + * This is an attempt to parallelize the horizontal max + * by doing a 8x8 tranpose of the vectors and computing max + * in cascade. However since we need to store 16 registers * for the positive and negative values the performance is not very good */ - #ifdef use_beta_transposed_max -static inline __m128i transposed_max(__m128i a, __m128i b, __m128i c, __m128i d, - __m128i e, __m128i f, __m128i g, __m128i h) +static inline __m128i +transposed_max(__m128i a, __m128i b, __m128i c, __m128i d, __m128i e, __m128i f, __m128i g, __m128i h) { - // Transpose 8 vectors + // Transpose 8 vectors __m128i t0 = _mm_unpacklo_epi16(a, b); __m128i t1 = _mm_unpacklo_epi16(c, d); __m128i t2 = _mm_unpacklo_epi16(e, f); @@ -550,131 +586,138 @@ static inline __m128i transposed_max(__m128i a, __m128i b, __m128i c, __m128i d, __m128i x6 = _mm_unpacklo_epi64(s5, s7); __m128i x7 = _mm_unpackhi_epi64(s5, s7); - // Cascade max on the transposed vector - __m128i res = _mm_max_epi16(x0, - _mm_max_epi16(x1, - _mm_max_epi16(x2, - _mm_max_epi16(x3, - _mm_max_epi16(x4, - _mm_max_epi16(x5, - _mm_max_epi16(x6, - x7))))))); - - return res; + // Cascade max on the transposed vector + __m128i res = _mm_max_epi16( + x0, + _mm_max_epi16(x1, + _mm_max_epi16(x2, _mm_max_epi16(x3, _mm_max_epi16(x4, _mm_max_epi16(x5, _mm_max_epi16(x6, x7))))))); + + return res; } -void tdec_sse_beta(tdec_sse_t * s, int16_t * output, uint32_t long_cb) +void tdec_sse_beta(tdec_sse_t* s, int16_t* output, uint32_t long_cb) { - int k; - uint32_t end = long_cb + 3; - const __m128i *alphaPtr = (const __m128i*) s->alpha; - + int k; + uint32_t end = long_cb + 3; + const __m128i* alphaPtr = (const __m128i*)s->alpha; + __m128i beta_k = _mm_set_epi16(-INF, -INF, -INF, -INF, -INF, -INF, -INF, 0); - __m128i g, alpha_k; + __m128i g, alpha_k; __m128i bn, bn_0, bn_1, bn_2, bn_3, bn_4, bn_5, bn_6, bn_7; __m128i bp, bp_0, bp_1, bp_2, bp_3, bp_4, bp_5, bp_6, bp_7; - + /* Define the shuffle constant for the positive beta */ - __m128i shuf_bp = _mm_set_epi8( - 15, 14, // 7 - 7, 6, // 3 - 5, 4, // 2 - 13, 12, // 6 - 11, 10, // 5 - 3, 2, // 1 - 1, 0, // 0 - 9, 8 // 4 + __m128i shuf_bp = _mm_set_epi8(15, + 14, // 7 + 7, + 6, // 3 + 5, + 4, // 2 + 13, + 12, // 6 + 11, + 10, // 5 + 3, + 2, // 1 + 1, + 0, // 0 + 9, + 8 // 4 ); /* Define the shuffle constant for the negative beta */ - __m128i shuf_bn = _mm_set_epi8( - 7, 6, // 3 - 15, 14, // 7 - 13, 12, // 6 - 5, 4, // 2 - 3, 2, // 1 - 11, 10, // 5 - 9, 8, // 4 - 1, 0 // 0 + __m128i shuf_bn = _mm_set_epi8(7, + 6, // 3 + 15, + 14, // 7 + 13, + 12, // 6 + 5, + 4, // 2 + 3, + 2, // 1 + 11, + 10, // 5 + 9, + 8, // 4 + 1, + 0 // 0 ); - - alphaPtr += long_cb-1; + + alphaPtr += long_cb - 1; /* Define shuffle for branch costs */ - __m128i shuf_g[4]; - shuf_g[3] = _mm_set_epi8(3,2,1,0,1,0,3,2,3,2,1,0,1,0,3,2); - shuf_g[2] = _mm_set_epi8(7,6,5,4,5,4,7,6,7,6,5,4,5,4,7,6); - shuf_g[1] = _mm_set_epi8(11,10,9,8,9,8,11,10,11,10,9,8,9,8,11,10); - shuf_g[0] = _mm_set_epi8(15,14,13,12,13,12,15,14,15,14,13,12,13,12,15,14); - __m128i gv; - int16_t *b = &s->branch[2*long_cb-8]; - __m128i *gPtr = (__m128i*) b; + __m128i shuf_g[4]; + shuf_g[3] = _mm_set_epi8(3, 2, 1, 0, 1, 0, 3, 2, 3, 2, 1, 0, 1, 0, 3, 2); + shuf_g[2] = _mm_set_epi8(7, 6, 5, 4, 5, 4, 7, 6, 7, 6, 5, 4, 5, 4, 7, 6); + shuf_g[1] = _mm_set_epi8(11, 10, 9, 8, 9, 8, 11, 10, 11, 10, 9, 8, 9, 8, 11, 10); + shuf_g[0] = _mm_set_epi8(15, 14, 13, 12, 13, 12, 15, 14, 15, 14, 13, 12, 13, 12, 15, 14); + __m128i gv; + int16_t* b = &s->branch[2 * long_cb - 8]; + __m128i* gPtr = (__m128i*)b; /* Define shuffle for beta normalization */ - __m128i shuf_norm = _mm_set_epi8(1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0); - - /* This defines a beta computation step: - * Adds and substracts the branch metrics to the previous beta step, - * shuffles the states according to the trellis path and selects maximum state + __m128i shuf_norm = _mm_set_epi8(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0); + + /* This defines a beta computation step: + * Adds and substracts the branch metrics to the previous beta step, + * shuffles the states according to the trellis path and selects maximum state + */ +#define BETA_STEP(g) \ + bp = _mm_add_epi16(beta_k, g); \ + bn = _mm_sub_epi16(beta_k, g); \ + bp = _mm_shuffle_epi8(bp, shuf_bp); \ + bn = _mm_shuffle_epi8(bn, shuf_bn); \ + beta_k = _mm_max_epi16(bp, bn); + + /* Loads the alpha metrics from memory and adds them to the temporal bn and bp + * metrics. */ -#define BETA_STEP(g) bp = _mm_add_epi16(beta_k, g);\ - bn = _mm_sub_epi16(beta_k, g);\ - bp = _mm_shuffle_epi8(bp, shuf_bp);\ - bn = _mm_shuffle_epi8(bn, shuf_bn);\ - beta_k = _mm_max_epi16(bp, bn); - - /* Loads the alpha metrics from memory and adds them to the temporal bn and bp - * metrics. - */ -#define BETA_STEP_CNT(c,d) g = _mm_shuffle_epi8(gv, shuf_g[c]);\ - BETA_STEP(g)\ - alpha_k = _mm_load_si128(alphaPtr);\ - alphaPtr--;\ - bp_##d = _mm_add_epi16(bp, alpha_k);\ - bn_##d = _mm_add_epi16(bn, alpha_k);\ - - /* The tail does not require to load alpha or produce outputs. Only update +#define BETA_STEP_CNT(c, d) \ + g = _mm_shuffle_epi8(gv, shuf_g[c]); \ + BETA_STEP(g) \ + alpha_k = _mm_load_si128(alphaPtr); \ + alphaPtr--; \ + bp_##d = _mm_add_epi16(bp, alpha_k); \ + bn_##d = _mm_add_epi16(bn, alpha_k); + + /* The tail does not require to load alpha or produce outputs. Only update * beta metrics accordingly */ - for (k=end-1; k>=long_cb; k--) { - int16_t g0 = s->branch[2*k]; - int16_t g1 = s->branch[2*k+1]; - g = _mm_set_epi16(g1, g0, g0, g1, g1, g0, g0, g1); + for (k = end - 1; k >= long_cb; k--) { + int16_t g0 = s->branch[2 * k]; + int16_t g1 = s->branch[2 * k + 1]; + g = _mm_set_epi16(g1, g0, g0, g1, g1, g0, g0, g1); BETA_STEP(g); - } - + } + /* We inline 2 trelis steps for each normalization */ - __m128i norm; - __m128i *outPtr = (__m128i*) &output[long_cb-8]; - for (; k >= 0; k-=8) { + __m128i norm; + __m128i* outPtr = (__m128i*)&output[long_cb - 8]; + for (; k >= 0; k -= 8) { gv = _mm_load_si128(gPtr); gPtr--; - - BETA_STEP_CNT(0,0); - BETA_STEP_CNT(1,1); - BETA_STEP_CNT(2,2); - BETA_STEP_CNT(3,3); - norm = _mm_shuffle_epi8(beta_k, shuf_norm); + + BETA_STEP_CNT(0, 0); + BETA_STEP_CNT(1, 1); + BETA_STEP_CNT(2, 2); + BETA_STEP_CNT(3, 3); + norm = _mm_shuffle_epi8(beta_k, shuf_norm); beta_k = _mm_sub_epi16(beta_k, norm); - gv = _mm_load_si128(gPtr); + gv = _mm_load_si128(gPtr); gPtr--; - BETA_STEP_CNT(0,4); - BETA_STEP_CNT(1,5); - BETA_STEP_CNT(2,6); - BETA_STEP_CNT(3,7); - norm = _mm_shuffle_epi8(beta_k, shuf_norm); + BETA_STEP_CNT(0, 4); + BETA_STEP_CNT(1, 5); + BETA_STEP_CNT(2, 6); + BETA_STEP_CNT(3, 7); + norm = _mm_shuffle_epi8(beta_k, shuf_norm); beta_k = _mm_sub_epi16(beta_k, norm); - + __m128i bn_transp = transposed_max(bn_7, bn_6, bn_5, bn_4, bn_3, bn_2, bn_1, bn_0); __m128i bp_transp = transposed_max(bp_7, bp_6, bp_5, bp_4, bp_3, bp_2, bp_1, bp_0); - __m128i outval = _mm_sub_epi16(bp_transp,bn_transp); + __m128i outval = _mm_sub_epi16(bp_transp, bn_transp); _mm_store_si128(outPtr, outval); - outPtr--; - } + outPtr--; + } } #endif - - - #endif - - diff --git a/lib/src/phy/fec/viterbi.c b/lib/src/phy/fec/viterbi.c index 7e61e91ee..2e4a32919 100644 --- a/lib/src/phy/fec/viterbi.c +++ b/lib/src/phy/fec/viterbi.c @@ -19,9 +19,9 @@ * */ -#include -#include #include +#include +#include #include #include @@ -39,23 +39,22 @@ #define DEFAULT_GAIN 100 #define DEFAULT_GAIN_16 1000 -#define VITERBI_16 +#define VITERBI_16 #ifndef LV_HAVE_AVX2 #undef VITERBI_16 #endif - //#undef LV_HAVE_SSE -int decode37(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_length) { - srslte_viterbi_t *q = o; +int decode37(void* o, uint8_t* symbols, uint8_t* data, uint32_t frame_length) +{ + srslte_viterbi_t* q = o; uint32_t best_state; if (frame_length > q->framebits) { - fprintf(stderr, "Initialized decoder for max frame length %d bits\n", - q->framebits); + fprintf(stderr, "Initialized decoder for max frame length %d bits\n", q->framebits); return -1; } @@ -64,12 +63,12 @@ int decode37(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_length) { /* Decode block */ if (q->tail_biting) { - for (int i=0;itmp[i*3*frame_length], symbols, 3*frame_length*sizeof(uint8_t)); + for (int i = 0; i < TB_ITER; i++) { + memcpy(&q->tmp[i * 3 * frame_length], symbols, 3 * frame_length * sizeof(uint8_t)); } - update_viterbi37_blk_port(q->ptr, q->tmp, TB_ITER*frame_length, &best_state); - chainback_viterbi37_port(q->ptr, q->tmp, TB_ITER*frame_length, best_state); - memcpy(data, &q->tmp[((int) (TB_ITER/2))*frame_length], frame_length*sizeof(uint8_t)); + update_viterbi37_blk_port(q->ptr, q->tmp, TB_ITER * frame_length, &best_state); + chainback_viterbi37_port(q->ptr, q->tmp, TB_ITER * frame_length, best_state); + memcpy(data, &q->tmp[((int)(TB_ITER / 2)) * frame_length], frame_length * sizeof(uint8_t)); } else { update_viterbi37_blk_port(q->ptr, symbols, frame_length + q->K - 1, NULL); chainback_viterbi37_port(q->ptr, data, frame_length, 0); @@ -78,40 +77,40 @@ int decode37(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_length) { return q->framebits; } - #ifdef LV_HAVE_SSE -int decode37_sse(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_length) { - srslte_viterbi_t *q = o; +int decode37_sse(void* o, uint8_t* symbols, uint8_t* data, uint32_t frame_length) +{ + srslte_viterbi_t* q = o; uint32_t best_state; if (frame_length > q->framebits) { - fprintf(stderr, "Initialized decoder for max frame length %d bits\n", - q->framebits); + fprintf(stderr, "Initialized decoder for max frame length %d bits\n", q->framebits); return -1; } /* Initialize Viterbi decoder */ - init_viterbi37_sse(q->ptr, q->tail_biting?-1:0); + init_viterbi37_sse(q->ptr, q->tail_biting ? -1 : 0); /* Decode block */ if (q->tail_biting) { - for (int i=0;itmp[i*3*frame_length], symbols, 3*frame_length*sizeof(uint8_t)); + for (int i = 0; i < TB_ITER; i++) { + memcpy(&q->tmp[i * 3 * frame_length], symbols, 3 * frame_length * sizeof(uint8_t)); } - update_viterbi37_blk_sse(q->ptr, q->tmp, TB_ITER*frame_length, &best_state); - chainback_viterbi37_sse(q->ptr, q->tmp, TB_ITER*frame_length, best_state); - memcpy(data, &q->tmp[((int) (TB_ITER/2))*frame_length], frame_length*sizeof(uint8_t)); + update_viterbi37_blk_sse(q->ptr, q->tmp, TB_ITER * frame_length, &best_state); + chainback_viterbi37_sse(q->ptr, q->tmp, TB_ITER * frame_length, best_state); + memcpy(data, &q->tmp[((int)(TB_ITER / 2)) * frame_length], frame_length * sizeof(uint8_t)); } else { - update_viterbi37_blk_sse(q->ptr, symbols, frame_length+q->K-1, NULL); + update_viterbi37_blk_sse(q->ptr, symbols, frame_length + q->K - 1, NULL); chainback_viterbi37_sse(q->ptr, data, frame_length, 0); } - + return q->framebits; } -void free37_sse(void *o) { - srslte_viterbi_t *q = o; +void free37_sse(void* o) +{ + srslte_viterbi_t* q = o; if (q->symbols_uc) { free(q->symbols_uc); } @@ -123,42 +122,41 @@ void free37_sse(void *o) { #endif - - #ifdef LV_HAVE_AVX2 -int decode37_avx2_16bit(void *o, uint16_t *symbols, uint8_t *data, uint32_t frame_length) { - srslte_viterbi_t *q = o; +int decode37_avx2_16bit(void* o, uint16_t* symbols, uint8_t* data, uint32_t frame_length) +{ + srslte_viterbi_t* q = o; uint32_t best_state; if (frame_length > q->framebits) { - fprintf(stderr, "Initialized decoder for max frame length %d bits\n", - q->framebits); + fprintf(stderr, "Initialized decoder for max frame length %d bits\n", q->framebits); return -1; } - + /* Initialize Viterbi decoder */ - init_viterbi37_avx2_16bit(q->ptr, q->tail_biting?-1:0); + init_viterbi37_avx2_16bit(q->ptr, q->tail_biting ? -1 : 0); /* Decode block */ if (q->tail_biting) { - for (int i=0;itmp_s[i*3*frame_length], symbols, 3*frame_length*sizeof(uint16_t)); + for (int i = 0; i < TB_ITER; i++) { + memcpy(&q->tmp_s[i * 3 * frame_length], symbols, 3 * frame_length * sizeof(uint16_t)); } - update_viterbi37_blk_avx2_16bit(q->ptr, q->tmp_s, TB_ITER*frame_length, &best_state); - chainback_viterbi37_avx2_16bit(q->ptr, q->tmp, TB_ITER*frame_length, best_state); - memcpy(data, &q->tmp[((int) (TB_ITER/2))*frame_length], frame_length*sizeof(uint8_t)); + update_viterbi37_blk_avx2_16bit(q->ptr, q->tmp_s, TB_ITER * frame_length, &best_state); + chainback_viterbi37_avx2_16bit(q->ptr, q->tmp, TB_ITER * frame_length, best_state); + memcpy(data, &q->tmp[((int)(TB_ITER / 2)) * frame_length], frame_length * sizeof(uint8_t)); } else { - update_viterbi37_blk_avx2_16bit(q->ptr, symbols, frame_length+q->K-1, NULL); + update_viterbi37_blk_avx2_16bit(q->ptr, symbols, frame_length + q->K - 1, NULL); chainback_viterbi37_avx2_16bit(q->ptr, data, frame_length, 0); } - + return q->framebits; } -void free37_avx2_16bit(void *o) { - srslte_viterbi_t *q = o; - +void free37_avx2_16bit(void* o) +{ + srslte_viterbi_t* q = o; + if (q->symbols_uc) { free(q->symbols_uc); } @@ -174,37 +172,37 @@ void free37_avx2_16bit(void *o) { delete_viterbi37_avx2_16bit(q->ptr); } - -int decode37_avx2(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_length) { - srslte_viterbi_t *q = o; +int decode37_avx2(void* o, uint8_t* symbols, uint8_t* data, uint32_t frame_length) +{ + srslte_viterbi_t* q = o; uint32_t best_state; if (frame_length > q->framebits) { - fprintf(stderr, "Initialized decoder for max frame length %d bits\n", - q->framebits); + fprintf(stderr, "Initialized decoder for max frame length %d bits\n", q->framebits); return -1; } /* Initialize Viterbi decoder */ - init_viterbi37_avx2(q->ptr, q->tail_biting?-1:0); + init_viterbi37_avx2(q->ptr, q->tail_biting ? -1 : 0); /* Decode block */ if (q->tail_biting) { - for (int i=0;itmp[i*3*frame_length], symbols, 3*frame_length*sizeof(uint8_t)); + for (int i = 0; i < TB_ITER; i++) { + memcpy(&q->tmp[i * 3 * frame_length], symbols, 3 * frame_length * sizeof(uint8_t)); } - update_viterbi37_blk_avx2(q->ptr, q->tmp, TB_ITER*frame_length, &best_state); - chainback_viterbi37_avx2(q->ptr, q->tmp, TB_ITER*frame_length, best_state); - memcpy(data, &q->tmp[((int) (TB_ITER/2))*frame_length], frame_length*sizeof(uint8_t)); + update_viterbi37_blk_avx2(q->ptr, q->tmp, TB_ITER * frame_length, &best_state); + chainback_viterbi37_avx2(q->ptr, q->tmp, TB_ITER * frame_length, best_state); + memcpy(data, &q->tmp[((int)(TB_ITER / 2)) * frame_length], frame_length * sizeof(uint8_t)); } else { - update_viterbi37_blk_avx2(q->ptr, symbols, frame_length+q->K-1, NULL); + update_viterbi37_blk_avx2(q->ptr, symbols, frame_length + q->K - 1, NULL); chainback_viterbi37_avx2(q->ptr, data, frame_length, 0); } - + return q->framebits; } -void free37_avx2(void *o) { - srslte_viterbi_t *q = o; +void free37_avx2(void* o) +{ + srslte_viterbi_t* q = o; if (q->symbols_uc) { free(q->symbols_uc); } @@ -214,12 +212,12 @@ void free37_avx2(void *o) { delete_viterbi37_avx2(q->ptr); } - #endif #ifdef HAVE_NEON -int decode37_neon(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_length) { - srslte_viterbi_t *q = o; +int decode37_neon(void* o, uint8_t* symbols, uint8_t* data, uint32_t frame_length) +{ + srslte_viterbi_t* q = o; uint32_t best_state; @@ -229,26 +227,27 @@ int decode37_neon(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_lengt } /* Initialize Viterbi decoder */ - init_viterbi37_neon(q->ptr, q->tail_biting?-1:0); + init_viterbi37_neon(q->ptr, q->tail_biting ? -1 : 0); /* Decode block */ if (q->tail_biting) { - for (int i=0;itmp[i*3*frame_length], symbols, 3*frame_length*sizeof(uint8_t)); + for (int i = 0; i < TB_ITER; i++) { + memcpy(&q->tmp[i * 3 * frame_length], symbols, 3 * frame_length * sizeof(uint8_t)); } - update_viterbi37_blk_neon(q->ptr, q->tmp, TB_ITER*frame_length, &best_state); - chainback_viterbi37_neon(q->ptr, q->tmp, TB_ITER*frame_length, best_state); - memcpy(data, &q->tmp[((int) (TB_ITER/2))*frame_length], frame_length*sizeof(uint8_t)); + update_viterbi37_blk_neon(q->ptr, q->tmp, TB_ITER * frame_length, &best_state); + chainback_viterbi37_neon(q->ptr, q->tmp, TB_ITER * frame_length, best_state); + memcpy(data, &q->tmp[((int)(TB_ITER / 2)) * frame_length], frame_length * sizeof(uint8_t)); } else { - update_viterbi37_blk_neon(q->ptr, symbols, frame_length+q->K-1, NULL); + update_viterbi37_blk_neon(q->ptr, symbols, frame_length + q->K - 1, NULL); chainback_viterbi37_neon(q->ptr, data, frame_length, 0); } - + return q->framebits; } -void free37_neon(void *o) { - srslte_viterbi_t *q = o; +void free37_neon(void* o) +{ + srslte_viterbi_t* q = o; if (q->symbols_uc) { free(q->symbols_uc); } @@ -260,8 +259,9 @@ void free37_neon(void *o) { #endif -void free37(void *o) { - srslte_viterbi_t *q = o; +void free37(void* o) +{ + srslte_viterbi_t* q = o; if (q->symbols_uc) { free(q->symbols_uc); } @@ -271,17 +271,18 @@ void free37(void *o) { delete_viterbi37_port(q->ptr); } -int init37(srslte_viterbi_t *q, int poly[3], uint32_t framebits, bool tail_biting) { - q->K = 7; - q->R = 3; - q->framebits = framebits; - q->gain_quant_s = 4; - q->gain_quant = DEFAULT_GAIN; - q->tail_biting = tail_biting; - q->decode = decode37; - q->free = free37; - q->decode_f = NULL; - q->symbols_uc = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); +int init37(srslte_viterbi_t* q, int poly[3], uint32_t framebits, bool tail_biting) +{ + q->K = 7; + q->R = 3; + q->framebits = framebits; + q->gain_quant_s = 4; + q->gain_quant = DEFAULT_GAIN; + q->tail_biting = tail_biting; + q->decode = decode37; + q->free = free37; + q->decode_f = NULL; + q->symbols_uc = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); if (!q->symbols_uc) { perror("malloc"); return -1; @@ -297,34 +298,35 @@ int init37(srslte_viterbi_t *q, int poly[3], uint32_t framebits, bool tail_bitin } else { q->tmp = NULL; } - - if ((q->ptr = create_viterbi37_port(poly, TB_ITER*framebits)) == NULL) { + + if ((q->ptr = create_viterbi37_port(poly, TB_ITER * framebits)) == NULL) { ERROR("create_viterbi37 failed\n"); free37(q); return -1; } else { return 0; - } + } } #ifdef LV_HAVE_SSE -int init37_sse(srslte_viterbi_t *q, int poly[3], uint32_t framebits, bool tail_biting) { - q->K = 7; - q->R = 3; - q->framebits = framebits; - q->gain_quant_s = 4; - q->gain_quant = DEFAULT_GAIN; - q->tail_biting = tail_biting; - q->decode = decode37_sse; - q->free = free37_sse; - q->decode_f = NULL; - q->symbols_uc = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); +int init37_sse(srslte_viterbi_t* q, int poly[3], uint32_t framebits, bool tail_biting) +{ + q->K = 7; + q->R = 3; + q->framebits = framebits; + q->gain_quant_s = 4; + q->gain_quant = DEFAULT_GAIN; + q->tail_biting = tail_biting; + q->decode = decode37_sse; + q->free = free37_sse; + q->decode_f = NULL; + q->symbols_uc = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); if (!q->symbols_uc) { perror("malloc"); return -1; } if (q->tail_biting) { - q->tmp = srslte_vec_malloc(TB_ITER*3*(q->framebits + q->K - 1) * sizeof(uint8_t)); + q->tmp = srslte_vec_malloc(TB_ITER * 3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); if (!q->tmp) { perror("malloc"); free37(q); @@ -333,35 +335,36 @@ int init37_sse(srslte_viterbi_t *q, int poly[3], uint32_t framebits, bool tail_b } else { q->tmp = NULL; } - - if ((q->ptr = create_viterbi37_sse(poly, TB_ITER*framebits)) == NULL) { + + if ((q->ptr = create_viterbi37_sse(poly, TB_ITER * framebits)) == NULL) { ERROR("create_viterbi37 failed\n"); free37(q); return -1; } else { return 0; - } + } } #endif #ifdef HAVE_NEON -int init37_neon(srslte_viterbi_t *q, int poly[3], uint32_t framebits, bool tail_biting) { - q->K = 7; - q->R = 3; - q->framebits = framebits; - q->gain_quant_s = 4; - q->gain_quant = DEFAULT_GAIN; - q->tail_biting = tail_biting; - q->decode = decode37_neon; - q->free = free37_neon; - q->decode_f = NULL; - q->symbols_uc = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); +int init37_neon(srslte_viterbi_t* q, int poly[3], uint32_t framebits, bool tail_biting) +{ + q->K = 7; + q->R = 3; + q->framebits = framebits; + q->gain_quant_s = 4; + q->gain_quant = DEFAULT_GAIN; + q->tail_biting = tail_biting; + q->decode = decode37_neon; + q->free = free37_neon; + q->decode_f = NULL; + q->symbols_uc = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); if (!q->symbols_uc) { perror("malloc"); return -1; } if (q->tail_biting) { - q->tmp = srslte_vec_malloc(TB_ITER*3*(q->framebits + q->K - 1) * sizeof(uint8_t)); + q->tmp = srslte_vec_malloc(TB_ITER * 3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); if (!q->tmp) { perror("malloc"); free37(q); @@ -370,36 +373,36 @@ int init37_neon(srslte_viterbi_t *q, int poly[3], uint32_t framebits, bool tail_ } else { q->tmp = NULL; } - - if ((q->ptr = create_viterbi37_neon(poly, TB_ITER*framebits)) == NULL) { + + if ((q->ptr = create_viterbi37_neon(poly, TB_ITER * framebits)) == NULL) { ERROR("create_viterbi37 failed\n"); free37(q); return -1; } else { return 0; - } + } } #endif - #ifdef LV_HAVE_AVX2 -int init37_avx2(srslte_viterbi_t *q, int poly[3], uint32_t framebits, bool tail_biting) { - q->K = 7; - q->R = 3; - q->framebits = framebits; - q->gain_quant_s = 4; - q->gain_quant = DEFAULT_GAIN; - q->tail_biting = tail_biting; - q->decode = decode37_avx2; - q->free = free37_avx2; - q->decode_f = NULL; - q->symbols_uc = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); +int init37_avx2(srslte_viterbi_t* q, int poly[3], uint32_t framebits, bool tail_biting) +{ + q->K = 7; + q->R = 3; + q->framebits = framebits; + q->gain_quant_s = 4; + q->gain_quant = DEFAULT_GAIN; + q->tail_biting = tail_biting; + q->decode = decode37_avx2; + q->free = free37_avx2; + q->decode_f = NULL; + q->symbols_uc = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); if (!q->symbols_uc) { perror("malloc"); return -1; } if (q->tail_biting) { - q->tmp = srslte_vec_malloc(TB_ITER*3*(q->framebits + q->K - 1) * sizeof(uint8_t)); + q->tmp = srslte_vec_malloc(TB_ITER * 3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); if (!q->tmp) { perror("malloc"); free37(q); @@ -408,35 +411,36 @@ int init37_avx2(srslte_viterbi_t *q, int poly[3], uint32_t framebits, bool tail_ } else { q->tmp = NULL; } - - if ((q->ptr = create_viterbi37_avx2(poly, TB_ITER*framebits)) == NULL) { + + if ((q->ptr = create_viterbi37_avx2(poly, TB_ITER * framebits)) == NULL) { ERROR("create_viterbi37 failed\n"); free37(q); return -1; } else { return 0; - } + } } -int init37_avx2_16bit(srslte_viterbi_t *q, int poly[3], uint32_t framebits, bool tail_biting) { - q->K = 7; - q->R = 3; - q->framebits = framebits; - q->gain_quant_s = 4; - q->gain_quant = DEFAULT_GAIN_16; - q->tail_biting = tail_biting; - q->decode_s = decode37_avx2_16bit; - q->free = free37_avx2_16bit; - q->decode_f = NULL; - q->symbols_uc = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); - q->symbols_us = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint16_t)); +int init37_avx2_16bit(srslte_viterbi_t* q, int poly[3], uint32_t framebits, bool tail_biting) +{ + q->K = 7; + q->R = 3; + q->framebits = framebits; + q->gain_quant_s = 4; + q->gain_quant = DEFAULT_GAIN_16; + q->tail_biting = tail_biting; + q->decode_s = decode37_avx2_16bit; + q->free = free37_avx2_16bit; + q->decode_f = NULL; + q->symbols_uc = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); + q->symbols_us = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint16_t)); if (!q->symbols_uc || !q->symbols_us) { perror("malloc"); return -1; } if (q->tail_biting) { - q->tmp = srslte_vec_malloc(TB_ITER*3*(q->framebits + q->K - 1) * sizeof(uint8_t)); - q->tmp_s = srslte_vec_malloc(TB_ITER*3*(q->framebits + q->K - 1) * sizeof(uint16_t)); + q->tmp = srslte_vec_malloc(TB_ITER * 3 * (q->framebits + q->K - 1) * sizeof(uint8_t)); + q->tmp_s = srslte_vec_malloc(TB_ITER * 3 * (q->framebits + q->K - 1) * sizeof(uint16_t)); if (!q->tmp) { perror("malloc"); free37(q); @@ -445,77 +449,92 @@ int init37_avx2_16bit(srslte_viterbi_t *q, int poly[3], uint32_t framebits, bool } else { q->tmp = NULL; } - //printf("pt0\n"); - if ((q->ptr = create_viterbi37_avx2_16bit(poly, TB_ITER*framebits)) == NULL) { + // printf("pt0\n"); + if ((q->ptr = create_viterbi37_avx2_16bit(poly, TB_ITER * framebits)) == NULL) { ERROR("create_viterbi37 failed\n"); free37(q); return -1; } else { return 0; - } + } } #endif -void srslte_viterbi_set_gain_quant(srslte_viterbi_t *q, float gain_quant) { +void srslte_viterbi_set_gain_quant(srslte_viterbi_t* q, float gain_quant) +{ q->gain_quant = gain_quant; } -void srslte_viterbi_set_gain_quant_s(srslte_viterbi_t *q, int16_t gain_quant) { +void srslte_viterbi_set_gain_quant_s(srslte_viterbi_t* q, int16_t gain_quant) +{ q->gain_quant_s = gain_quant; } -int srslte_viterbi_init(srslte_viterbi_t *q, srslte_viterbi_type_t type, int poly[3], uint32_t max_frame_length, bool tail_bitting) +int srslte_viterbi_init(srslte_viterbi_t* q, + srslte_viterbi_type_t type, + int poly[3], + uint32_t max_frame_length, + bool tail_bitting) { switch (type) { - case SRSLTE_VITERBI_37: + case SRSLTE_VITERBI_37: #ifdef LV_HAVE_SSE - - #ifdef LV_HAVE_AVX2 - #ifdef VITERBI_16 - return init37_avx2_16bit(q, poly, max_frame_length, tail_bitting); - #else - return init37_avx2(q, poly, max_frame_length, tail_bitting); - #endif - #else - return init37_sse(q, poly, max_frame_length, tail_bitting); - #endif + +#ifdef LV_HAVE_AVX2 +#ifdef VITERBI_16 + return init37_avx2_16bit(q, poly, max_frame_length, tail_bitting); #else - #ifdef HAVE_NEON - return init37_neon(q, poly, max_frame_length, tail_bitting); - #else - return init37(q, poly, max_frame_length, tail_bitting); - #endif + return init37_avx2(q, poly, max_frame_length, tail_bitting); #endif - default: - ERROR("Decoder not implemented\n"); - return -1; +#else + return init37_sse(q, poly, max_frame_length, tail_bitting); +#endif +#else +#ifdef HAVE_NEON + return init37_neon(q, poly, max_frame_length, tail_bitting); +#else + return init37(q, poly, max_frame_length, tail_bitting); +#endif +#endif + default: + ERROR("Decoder not implemented\n"); + return -1; } } #ifdef LV_HAVE_SSE -int srslte_viterbi_init_sse(srslte_viterbi_t *q, srslte_viterbi_type_t type, int poly[3], uint32_t max_frame_length, bool tail_bitting) +int srslte_viterbi_init_sse(srslte_viterbi_t* q, + srslte_viterbi_type_t type, + int poly[3], + uint32_t max_frame_length, + bool tail_bitting) { - return init37_sse(q, poly, max_frame_length, tail_bitting); + return init37_sse(q, poly, max_frame_length, tail_bitting); } #endif #ifdef LV_HAVE_AVX2 -int srslte_viterbi_init_avx2(srslte_viterbi_t *q, srslte_viterbi_type_t type, int poly[3], uint32_t max_frame_length, bool tail_bitting) +int srslte_viterbi_init_avx2(srslte_viterbi_t* q, + srslte_viterbi_type_t type, + int poly[3], + uint32_t max_frame_length, + bool tail_bitting) { - return init37_avx2(q, poly, max_frame_length, tail_bitting); + return init37_avx2(q, poly, max_frame_length, tail_bitting); } #endif -void srslte_viterbi_free(srslte_viterbi_t *q) { +void srslte_viterbi_free(srslte_viterbi_t* q) +{ if (q->free) { - q->free(q); + q->free(q); } bzero(q, sizeof(srslte_viterbi_t)); } /* symbols are real-valued */ -int srslte_viterbi_decode_f(srslte_viterbi_t *q, float *symbols, uint8_t *data, uint32_t frame_length) +int srslte_viterbi_decode_f(srslte_viterbi_t* q, float* symbols, uint8_t* data, uint32_t frame_length) { uint32_t len; if (frame_length > q->framebits) { @@ -529,16 +548,16 @@ int srslte_viterbi_decode_f(srslte_viterbi_t *q, float *symbols, uint8_t *data, } if (!q->decode_f) { float max = 1e-9; - for (int i=0;i max) { max = fabs(symbols[i]); } } #ifdef VITERBI_16 - srslte_vec_quant_fus(symbols, q->symbols_us, q->gain_quant/max, 32767.5, 65535, len); + srslte_vec_quant_fus(symbols, q->symbols_us, q->gain_quant / max, 32767.5, 65535, len); return srslte_viterbi_decode_us(q, q->symbols_us, data, frame_length); #else - srslte_vec_quant_fuc(symbols, q->symbols_uc, q->gain_quant/max, 127.5, 255, len); + srslte_vec_quant_fuc(symbols, q->symbols_uc, q->gain_quant / max, 127.5, 255, len); return srslte_viterbi_decode_uc(q, q->symbols_uc, data, frame_length); #endif } else { @@ -547,7 +566,7 @@ int srslte_viterbi_decode_f(srslte_viterbi_t *q, float *symbols, uint8_t *data, } /* symbols are int16 */ -int srslte_viterbi_decode_s(srslte_viterbi_t *q, int16_t *symbols, uint8_t *data, uint32_t frame_length) +int srslte_viterbi_decode_s(srslte_viterbi_t* q, int16_t* symbols, uint8_t* data, uint32_t frame_length) { uint32_t len; if (frame_length > q->framebits) { @@ -559,31 +578,28 @@ int srslte_viterbi_decode_s(srslte_viterbi_t *q, int16_t *symbols, uint8_t *data } else { len = 3 * (frame_length + q->K - 1); } - - int16_t max = -INT16_MAX; - for (int i=0;i max) { max = abs(symbols[i]); } } #ifdef VITERBI_16 - srslte_vec_quant_sus(symbols, q->symbols_us, 1, 32767, len); - return srslte_viterbi_decode_us(q, q->symbols_us, data, frame_length); + srslte_vec_quant_sus(symbols, q->symbols_us, 1, 32767, len); + return srslte_viterbi_decode_us(q, q->symbols_us, data, frame_length); #else - srslte_vec_quant_suc(symbols, q->symbols_uc, (float) q->gain_quant/max, 127, 255, len); - return srslte_viterbi_decode_uc(q, q->symbols_uc, data, frame_length); + srslte_vec_quant_suc(symbols, q->symbols_uc, (float)q->gain_quant / max, 127, 255, len); + return srslte_viterbi_decode_uc(q, q->symbols_uc, data, frame_length); #endif - - } -int srslte_viterbi_decode_us(srslte_viterbi_t *q, uint16_t *symbols, uint8_t *data, uint32_t frame_length) +int srslte_viterbi_decode_us(srslte_viterbi_t* q, uint16_t* symbols, uint8_t* data, uint32_t frame_length) { return q->decode_s(q, symbols, data, frame_length); } - -int srslte_viterbi_decode_uc(srslte_viterbi_t *q, uint8_t *symbols, uint8_t *data, uint32_t frame_length) +int srslte_viterbi_decode_uc(srslte_viterbi_t* q, uint8_t* symbols, uint8_t* data, uint32_t frame_length) { return q->decode(q, symbols, data, frame_length); } diff --git a/lib/src/phy/fec/viterbi37.h b/lib/src/phy/fec/viterbi37.h index 878efe1b1..1bbf46100 100644 --- a/lib/src/phy/fec/viterbi37.h +++ b/lib/src/phy/fec/viterbi37.h @@ -21,107 +21,60 @@ #include -void *create_viterbi37_port(int polys[3], - uint32_t len); +void* create_viterbi37_port(int polys[3], uint32_t len); -int init_viterbi37_port(void *p, - int starting_state); +int init_viterbi37_port(void* p, int starting_state); -int chainback_viterbi37_port(void *p, - uint8_t *data, - uint32_t nbits, - uint32_t endstate); +int chainback_viterbi37_port(void* p, uint8_t* data, uint32_t nbits, uint32_t endstate); -void delete_viterbi37_port(void *p); +void delete_viterbi37_port(void* p); -int update_viterbi37_blk_port(void *p, - uint8_t *syms, - uint32_t nbits, - uint32_t *best_state); +int update_viterbi37_blk_port(void* p, uint8_t* syms, uint32_t nbits, uint32_t* best_state); +void* create_viterbi37_sse(int polys[3], uint32_t len); -void *create_viterbi37_sse(int polys[3], - uint32_t len); +int init_viterbi37_sse(void* p, int starting_state); -int init_viterbi37_sse(void *p, - int starting_state); +void reset_blk_sse(void* p, int nbits); +int chainback_viterbi37_sse(void* p, uint8_t* data, uint32_t nbits, uint32_t endstate); -void reset_blk_sse(void *p, int nbits); +void delete_viterbi37_sse(void* p); -int chainback_viterbi37_sse(void *p, - uint8_t *data, - uint32_t nbits, - uint32_t endstate); +int update_viterbi37_blk_sse(void* p, uint8_t* syms, uint32_t nbits, uint32_t* best_state); -void delete_viterbi37_sse(void *p); +void* create_viterbi37_neon(int polys[3], uint32_t len); -int update_viterbi37_blk_sse(void *p, - uint8_t *syms, - uint32_t nbits, - uint32_t *best_state); +int init_viterbi37_neon(void* p, int starting_state); -void *create_viterbi37_neon(int polys[3], - uint32_t len); +void reset_blk_neon(void* p, int nbits); -int init_viterbi37_neon(void *p, - int starting_state); +int chainback_viterbi37_neon(void* p, uint8_t* data, uint32_t nbits, uint32_t endstate); +void delete_viterbi37_neon(void* p); -void reset_blk_neon(void *p, int nbits); +int update_viterbi37_blk_neon(void* p, uint8_t* syms, uint32_t nbits, uint32_t* best_state); -int chainback_viterbi37_neon(void *p, - uint8_t *data, - uint32_t nbits, - uint32_t endstate); +void* create_viterbi37_avx2(int polys[3], uint32_t len); -void delete_viterbi37_neon(void *p); +int init_viterbi37_avx2(void* p, int starting_state); -int update_viterbi37_blk_neon(void *p, - uint8_t *syms, - uint32_t nbits, - uint32_t *best_state); +void reset_blk_avx2(void* p, int nbits); +int chainback_viterbi37_avx2(void* p, uint8_t* data, uint32_t nbits, uint32_t endstate); -void *create_viterbi37_avx2(int polys[3], - uint32_t len); +void delete_viterbi37_avx2(void* p); -int init_viterbi37_avx2(void *p, - int starting_state); +int update_viterbi37_blk_avx2(void* p, uint8_t* syms, uint32_t nbits, uint32_t* best_state); +void* create_viterbi37_avx2_16bit(int polys[3], uint32_t len); -void reset_blk_avx2(void *p, int nbits); +int init_viterbi37_avx2_16bit(void* p, int starting_state); -int chainback_viterbi37_avx2(void *p, - uint8_t *data, - uint32_t nbits, - uint32_t endstate); +void reset_blk_avx2_16bit(void* p, int nbits); -void delete_viterbi37_avx2(void *p); +int chainback_viterbi37_avx2_16bit(void* p, uint8_t* data, uint32_t nbits, uint32_t endstate); -int update_viterbi37_blk_avx2(void *p, - uint8_t *syms, - uint32_t nbits, - uint32_t *best_state); +void delete_viterbi37_avx2_16bit(void* p); - -void *create_viterbi37_avx2_16bit(int polys[3], - uint32_t len); - -int init_viterbi37_avx2_16bit(void *p, - int starting_state); - - -void reset_blk_avx2_16bit(void *p, int nbits); - -int chainback_viterbi37_avx2_16bit(void *p, - uint8_t *data, - uint32_t nbits, - uint32_t endstate); - -void delete_viterbi37_avx2_16bit(void *p); - -int update_viterbi37_blk_avx2_16bit(void *p, - uint16_t *syms, - uint32_t nbits, - uint32_t *best_state); \ No newline at end of file +int update_viterbi37_blk_avx2_16bit(void* p, uint16_t* syms, uint32_t nbits, uint32_t* best_state); \ No newline at end of file diff --git a/lib/src/phy/fec/viterbi37_avx2.c b/lib/src/phy/fec/viterbi37_avx2.c index 8735bf7ea..36f176d15 100644 --- a/lib/src/phy/fec/viterbi37_avx2.c +++ b/lib/src/phy/fec/viterbi37_avx2.c @@ -1,90 +1,91 @@ /* Adapted Phil Karn's r=1/3 k=9 viterbi decoder to r=1/3 k=7 - * + * * K=15 r=1/6 Viterbi decoder for x86 SSE2 * Copyright Mar 2004, Phil Karn, KA9Q * May be used under the terms of the GNU Lesser General Public License (LGPL) */ -#include +#include "parity.h" +#include +#include #include +#include #include -#include -#include -#include "parity.h" //#define DEBUG #ifdef LV_HAVE_AVX2 #include -#include #include -#include -#define _mm256_set_m128i(v0, v1) _mm256_insertf128_si256(_mm256_castsi128_si256(v1), (v0), 1) +#include +#define _mm256_set_m128i(v0, v1) _mm256_insertf128_si256(_mm256_castsi128_si256(v1), (v0), 1) #define _mm256_setr_m128i(v0, v1) _mm256_set_m128i((v1), (v0)) -typedef union { - unsigned char c[64]; - __m128i v[4]; +typedef union { + unsigned char c[64]; + __m128i v[4]; } metric_t; -typedef union { - unsigned int w[2]; - unsigned char c[8]; - unsigned short s[4]; - __m64 v; +typedef union { + unsigned int w[2]; + unsigned char c[8]; + unsigned short s[4]; + __m64 v; } decision_t; -union branchtab27 { - unsigned char c[32]; - __m256i v; +union branchtab27 { + unsigned char c[32]; + __m256i v; } Branchtab37_sse2[3]; int firstGo; /* State info for instance of Viterbi decoder */ struct v37 { - metric_t metrics1; /* path metric buffer 1 */ - metric_t metrics2; /* path metric buffer 2 */ - decision_t *dp; /* Pointer to current decision */ - metric_t *old_metrics,*new_metrics; /* Pointers to path metrics, swapped on every bit */ - decision_t *decisions; /* Beginning of decisions for block */ - uint32_t len; + metric_t metrics1; /* path metric buffer 1 */ + metric_t metrics2; /* path metric buffer 2 */ + decision_t* dp; /* Pointer to current decision */ + metric_t * old_metrics, *new_metrics; /* Pointers to path metrics, swapped on every bit */ + decision_t* decisions; /* Beginning of decisions for block */ + uint32_t len; }; -void set_viterbi37_polynomial_avx2(int polys[3]) { +void set_viterbi37_polynomial_avx2(int polys[3]) +{ int state; - for(state=0;state < 32;state++){ - Branchtab37_sse2[0].c[state] = (polys[0] < 0) ^ parity((2*state) & polys[0]) ? 255:0; - Branchtab37_sse2[1].c[state] = (polys[1] < 0) ^ parity((2*state) & polys[1]) ? 255:0; - Branchtab37_sse2[2].c[state] = (polys[2] < 0) ^ parity((2*state) & polys[2]) ? 255:0; + for (state = 0; state < 32; state++) { + Branchtab37_sse2[0].c[state] = (polys[0] < 0) ^ parity((2 * state) & polys[0]) ? 255 : 0; + Branchtab37_sse2[1].c[state] = (polys[1] < 0) ^ parity((2 * state) & polys[1]) ? 255 : 0; + Branchtab37_sse2[2].c[state] = (polys[2] < 0) ^ parity((2 * state) & polys[2]) ? 255 : 0; } } -void clear_v37_avx2(struct v37 *vp) { - bzero(vp->decisions, sizeof(decision_t)*vp->len); - vp->dp = NULL; +void clear_v37_avx2(struct v37* vp) +{ + bzero(vp->decisions, sizeof(decision_t) * vp->len); + vp->dp = NULL; bzero(&vp->metrics1, sizeof(metric_t)); bzero(&vp->metrics2, sizeof(metric_t)); - vp->old_metrics = NULL; - vp->new_metrics = NULL; + vp->old_metrics = NULL; + vp->new_metrics = NULL; } - /* Initialize Viterbi decoder for start of new frame */ -int init_viterbi37_avx2(void *p, int starting_state) { - struct v37 *vp = p; - uint32_t i; +int init_viterbi37_avx2(void* p, int starting_state) +{ + struct v37* vp = p; + uint32_t i; firstGo = 1; - - for(i=0;i<64;i++) + + for (i = 0; i < 64; i++) vp->metrics1.c[i] = 63; - + clear_v37_avx2(vp); vp->old_metrics = &vp->metrics1; vp->new_metrics = &vp->metrics2; - vp->dp = vp->decisions; + vp->dp = vp->decisions; if (starting_state != -1) { vp->old_metrics->c[starting_state & 63] = 0; /* Bias known start state */ @@ -93,188 +94,192 @@ int init_viterbi37_avx2(void *p, int starting_state) { } /* Create a new instance of a Viterbi decoder */ -void *create_viterbi37_avx2(int polys[3], uint32_t len) { - void *p; - struct v37 *vp; +void* create_viterbi37_avx2(int polys[3], uint32_t len) +{ + void* p; + struct v37* vp; set_viterbi37_polynomial_avx2(polys); - + /* Ordinary malloc() only returns 8-byte alignment, we need 16 */ - if(posix_memalign(&p, sizeof(__m128i),sizeof(struct v37))) + if (posix_memalign(&p, sizeof(__m128i), sizeof(struct v37))) return NULL; - vp = (struct v37 *)p; - if(posix_memalign(&p, sizeof(__m128i),(len+6)*sizeof(decision_t))) { + vp = (struct v37*)p; + if (posix_memalign(&p, sizeof(__m128i), (len + 6) * sizeof(decision_t))) { free(vp); return NULL; } - vp->decisions = (decision_t *)p; - vp->len = len+6; + vp->decisions = (decision_t*)p; + vp->len = len + 6; return vp; } - /* Viterbi chainback */ -int chainback_viterbi37_avx2( - void *p, - uint8_t *data, /* Decoded output data */ - uint32_t nbits, /* Number of data bits */ - uint32_t endstate) { /* Terminal encoder state */ - struct v37 *vp = p; - +int chainback_viterbi37_avx2(void* p, + uint8_t* data, /* Decoded output data */ + uint32_t nbits, /* Number of data bits */ + uint32_t endstate) +{ /* Terminal encoder state */ + struct v37* vp = p; + if (p == NULL) return -1; - decision_t *d = (decision_t *)vp->decisions; + decision_t* d = (decision_t*)vp->decisions; /* Make room beyond the end of the encoder register so we can * accumulate a full byte of decoded data */ endstate %= 64; endstate <<= 2; - + /* The store into data[] only needs to be done every 8 bits. * But this avoids a conditional branch, and the writes will * combine in the cache anyway */ d += 6; /* Look past tail */ - while(nbits--) { + while (nbits--) { int k; - k = (d[nbits].c[(endstate>>2)/8] >> ((endstate>>2)%8)) & 1; - endstate = (endstate >> 1) | (k << 7); + k = (d[nbits].c[(endstate >> 2) / 8] >> ((endstate >> 2) % 8)) & 1; + endstate = (endstate >> 1) | (k << 7); data[nbits] = k; - //printf("nbits=%d, endstate=%3d, k=%d, w[0]=%d, w[1]=%d, c=%d\n", nbits, endstate, k, d[nbits].s[1]&1, d[nbits].s[2]&1, d[nbits].c[(endstate>>2)/8]&1); + // printf("nbits=%d, endstate=%3d, k=%d, w[0]=%d, w[1]=%d, c=%d\n", nbits, endstate, k, d[nbits].s[1]&1, + // d[nbits].s[2]&1, d[nbits].c[(endstate>>2)/8]&1); } return 0; } /* Delete instance of a Viterbi decoder */ -void delete_viterbi37_avx2(void *p){ - struct v37 *vp = p; +void delete_viterbi37_avx2(void* p) +{ + struct v37* vp = p; - if(vp != NULL){ + if (vp != NULL) { free(vp->decisions); free(vp); } } -void printer_256i(char *s, __m256i val) { - +void printer_256i(char* s, __m256i val) +{ + printf("%s: ", s); - - uint8_t *x = (uint8_t*) &val; - for (int i=0;i<32;i++) { + + uint8_t* x = (uint8_t*)&val; + for (int i = 0; i < 32; i++) { printf("%3d, ", x[i]); } printf("\n"); } -void printer_128i(char *s, __m128i val) { - +void printer_128i(char* s, __m128i val) +{ + printf("%s: ", s); - - uint8_t *x = (uint8_t*) &val; - for (int i=0;i<16;i++) { + + uint8_t* x = (uint8_t*)&val; + for (int i = 0; i < 16; i++) { printf("%3d, ", x[i]); } printf("\n"); } -void printer_m64(char *s, __m64 val) { - +void printer_m64(char* s, __m64 val) +{ + printf("%s: ", s); - - uint8_t *x = (uint8_t*) &val; - for (int i=0;i<8;i++) { + + uint8_t* x = (uint8_t*)&val; + for (int i = 0; i < 8; i++) { printf("%3d, ", x[i]); } printf("\n"); } +void update_viterbi37_blk_avx2(void* p, unsigned char* syms, int nbits, uint32_t* best_state) +{ + struct v37* vp = p; + decision_t* d; -void update_viterbi37_blk_avx2(void *p,unsigned char *syms,int nbits, uint32_t *best_state) { - struct v37 *vp = p; - decision_t *d; - - if(p == NULL) + if (p == NULL) return; - + #ifdef DEBUG printf("["); #endif - - d = (decision_t *) vp->dp; - - for (int s=0;sdp; + + for (int s = 0; s < nbits; s++) { + memset(d + s, 0, sizeof(decision_t)); } - - while(nbits--) { - __m256i sym0v,sym1v,sym2v; - - void *tmp; + + while (nbits--) { + __m256i sym0v, sym1v, sym2v; + + void* tmp; sym0v = _mm256_set1_epi8(syms[0]); sym1v = _mm256_set1_epi8(syms[1]); sym2v = _mm256_set1_epi8(syms[2]); syms += 3; - - - __m256i decision0,decision1,survivor0,survivor1,metric,m_metric,m0,m1,m2,m3; + + __m256i decision0, decision1, survivor0, survivor1, metric, m_metric, m0, m1, m2, m3; /* Form branch metrics */ - m0 = _mm256_avg_epu8(_mm256_xor_si256(Branchtab37_sse2[0].v,sym0v),_mm256_xor_si256(Branchtab37_sse2[1].v,sym1v)); - metric = _mm256_avg_epu8(_mm256_xor_si256(Branchtab37_sse2[2].v,sym2v),m0); - + m0 = + _mm256_avg_epu8(_mm256_xor_si256(Branchtab37_sse2[0].v, sym0v), _mm256_xor_si256(Branchtab37_sse2[1].v, sym1v)); + metric = _mm256_avg_epu8(_mm256_xor_si256(Branchtab37_sse2[2].v, sym2v), m0); + #ifdef DEBUG - print_128i("metric_initial", metric); + print_128i("metric_initial", metric); #endif - /* There's no packed bytes right shift in SSE2, so we use the word version and mask - */ - metric = _mm256_srli_epi16(metric,3); - metric = _mm256_and_si256(metric,_mm256_set1_epi8(31)); - m_metric = _mm256_sub_epi8(_mm256_set1_epi8(31),metric); - + /* There's no packed bytes right shift in SSE2, so we use the word version and mask + */ + metric = _mm256_srli_epi16(metric, 3); + metric = _mm256_and_si256(metric, _mm256_set1_epi8(31)); + m_metric = _mm256_sub_epi8(_mm256_set1_epi8(31), metric); + #ifdef DEBUG - print_128i("metric ", metric); - print_128i("m_metric ", m_metric); + print_128i("metric ", metric); + print_128i("m_metric ", m_metric); #endif - __m256i temp = _mm256_set_m128i( vp->old_metrics->v[1], vp->old_metrics->v[0]); - m0 = _mm256_add_epi8(temp,metric); - m2 = _mm256_add_epi8(temp,m_metric); - - temp = _mm256_set_m128i( vp->old_metrics->v[3], vp->old_metrics->v[2]); - m3 = _mm256_add_epi8(temp,metric); - m1 = _mm256_add_epi8(temp,m_metric); - - /* Compare and select, using modulo arithmetic */ - decision0 = _mm256_cmpgt_epi8(_mm256_sub_epi8(m0,m1),_mm256_setzero_si256()); - decision1 =_mm256_cmpgt_epi8(_mm256_sub_epi8(m2,m3),_mm256_setzero_si256()); - survivor0 = _mm256_or_si256(_mm256_and_si256(decision0,m1),_mm256_andnot_si256(decision0,m0)); - survivor1 = _mm256_or_si256(_mm256_and_si256(decision1,m3),_mm256_andnot_si256(decision1,m2)); - - unsigned int x = _mm256_movemask_epi8(_mm256_unpackhi_epi8(decision0,decision1)); - unsigned int y = _mm256_movemask_epi8(_mm256_unpacklo_epi8(decision0,decision1)); - - d->s[0] = (short) y; - d->s[1] = (short) x; - d->s[2] = (short) (y >>16); - d->s[3] = (short) (x >>16); - - + __m256i temp = _mm256_set_m128i(vp->old_metrics->v[1], vp->old_metrics->v[0]); + m0 = _mm256_add_epi8(temp, metric); + m2 = _mm256_add_epi8(temp, m_metric); + + temp = _mm256_set_m128i(vp->old_metrics->v[3], vp->old_metrics->v[2]); + m3 = _mm256_add_epi8(temp, metric); + m1 = _mm256_add_epi8(temp, m_metric); + + /* Compare and select, using modulo arithmetic */ + decision0 = _mm256_cmpgt_epi8(_mm256_sub_epi8(m0, m1), _mm256_setzero_si256()); + decision1 = _mm256_cmpgt_epi8(_mm256_sub_epi8(m2, m3), _mm256_setzero_si256()); + survivor0 = _mm256_or_si256(_mm256_and_si256(decision0, m1), _mm256_andnot_si256(decision0, m0)); + survivor1 = _mm256_or_si256(_mm256_and_si256(decision1, m3), _mm256_andnot_si256(decision1, m2)); + + unsigned int x = _mm256_movemask_epi8(_mm256_unpackhi_epi8(decision0, decision1)); + unsigned int y = _mm256_movemask_epi8(_mm256_unpacklo_epi8(decision0, decision1)); + + d->s[0] = (short)y; + d->s[1] = (short)x; + d->s[2] = (short)(y >> 16); + d->s[3] = (short)(x >> 16); + __m256i unpack; - unpack = _mm256_unpacklo_epi8(survivor0,survivor1); - vp->new_metrics->v[0] =_mm256_castsi256_si128(unpack); + unpack = _mm256_unpacklo_epi8(survivor0, survivor1); + vp->new_metrics->v[0] = _mm256_castsi256_si128(unpack); + + vp->new_metrics->v[1] = _mm256_extractf128_si256(unpack, 1); - vp->new_metrics->v[1] = _mm256_extractf128_si256(unpack,1); + unpack = _mm256_unpackhi_epi8(survivor0, survivor1); - unpack = _mm256_unpackhi_epi8(survivor0,survivor1); + vp->new_metrics->v[2] = _mm256_castsi256_si128(unpack); + vp->new_metrics->v[3] = _mm256_extractf128_si256(unpack, 1); - vp->new_metrics->v[2] =_mm256_castsi256_si128(unpack); - vp->new_metrics->v[3] = _mm256_extractf128_si256(unpack,1); - __m128i temp1 = vp->new_metrics->v[1]; vp->new_metrics->v[1] = vp->new_metrics->v[2]; @@ -282,53 +287,55 @@ void update_viterbi37_blk_avx2(void *p,unsigned char *syms,int nbits, uint32_t * // See if we need to normalize if (vp->new_metrics->c[0] > 100) { - int i; - uint8_t adjust; + int i; + uint8_t adjust; __m128i adjustv; - union { __m128i v; signed short w[8]; } t; - + union { + __m128i v; + signed short w[8]; + } t; + adjustv = vp->new_metrics->v[0]; - for(i=1;i<4;i++) { - adjustv = _mm_min_epu8(adjustv,vp->new_metrics->v[i]); + for (i = 1; i < 4; i++) { + adjustv = _mm_min_epu8(adjustv, vp->new_metrics->v[i]); } - - adjustv = _mm_min_epu8(adjustv,_mm_srli_si128(adjustv,8)); - adjustv = _mm_min_epu8(adjustv,_mm_srli_si128(adjustv,4)); - adjustv = _mm_min_epu8(adjustv,_mm_srli_si128(adjustv,2)); - - t.v = adjustv; - adjust = t.w[0]; + + adjustv = _mm_min_epu8(adjustv, _mm_srli_si128(adjustv, 8)); + adjustv = _mm_min_epu8(adjustv, _mm_srli_si128(adjustv, 4)); + adjustv = _mm_min_epu8(adjustv, _mm_srli_si128(adjustv, 2)); + + t.v = adjustv; + adjust = t.w[0]; adjustv = _mm_set1_epi8(adjust); - + /* We cannot use a saturated subtract, because we often have to adjust by more than SHRT_MAX * This is okay since it can't overflow anyway */ - for(i=0;i<4;i++) - vp->new_metrics->v[i] = _mm_sub_epi8(vp->new_metrics->v[i],adjustv); - + for (i = 0; i < 4; i++) + vp->new_metrics->v[i] = _mm_sub_epi8(vp->new_metrics->v[i], adjustv); } firstGo = 0; d++; /* Swap pointers to old and new metrics */ - tmp = vp->old_metrics; + tmp = vp->old_metrics; vp->old_metrics = vp->new_metrics; vp->new_metrics = tmp; } - + if (best_state) { - uint32_t i, bst=0; - uint8_t minmetric=UINT8_MAX; - for (i=0;i<64;i++) { + uint32_t i, bst = 0; + uint8_t minmetric = UINT8_MAX; + for (i = 0; i < 64; i++) { if (vp->old_metrics->c[i] <= minmetric) { - bst = i; + bst = i; minmetric = vp->old_metrics->c[i]; } } *best_state = bst; } - #ifdef DEBUG +#ifdef DEBUG printf("];\n===========================================\n"); #endif @@ -336,6 +343,3 @@ void update_viterbi37_blk_avx2(void *p,unsigned char *syms,int nbits, uint32_t * } #endif - - - diff --git a/lib/src/phy/fec/viterbi37_avx2_16bit.c b/lib/src/phy/fec/viterbi37_avx2_16bit.c index 913b6a82e..643284f6b 100644 --- a/lib/src/phy/fec/viterbi37_avx2_16bit.c +++ b/lib/src/phy/fec/viterbi37_avx2_16bit.c @@ -1,94 +1,94 @@ /* Adapted Phil Karn's r=1/3 k=9 viterbi decoder to r=1/3 k=7 - * + * * K=15 r=1/6 Viterbi decoder for x86 SSE2 * Copyright Mar 2004, Phil Karn, KA9Q * May be used under the terms of the GNU Lesser General Public License (LGPL) */ -#include +#include "parity.h" +#include +#include #include +#include #include -#include -#include -#include "parity.h" //#define DEBUG #ifdef LV_HAVE_AVX2 - #include -#include #include -#include +#include -typedef union { - //unsigned char c[64]; - //__m128i v[4]; +typedef union { + // unsigned char c[64]; + //__m128i v[4]; unsigned short c[64]; - __m256i v[4]; + __m256i v[4]; } metric_t; -typedef union { - unsigned int w[2]; - unsigned char c[8]; - unsigned short s[4]; - __m64 v[1]; +typedef union { + unsigned int w[2]; + unsigned char c[8]; + unsigned short s[4]; + __m64 v[1]; } decision_t; -union branchtab27 { +union branchtab27 { - //unsigned char c[32]; - //__m128i v[2]; + // unsigned char c[32]; + //__m128i v[2]; unsigned short c[32]; - __m256i v[2]; + __m256i v[2]; } Branchtab37_sse2[3]; int firstGo; /* State info for instance of Viterbi decoder */ struct v37 { - metric_t metrics1; /* path metric buffer 1 */ - metric_t metrics2; /* path metric buffer 2 */ - decision_t *dp; /* Pointer to current decision */ - metric_t *old_metrics,*new_metrics; /* Pointers to path metrics, swapped on every bit */ - decision_t *decisions; /* Beginning of decisions for block */ - uint32_t len; + metric_t metrics1; /* path metric buffer 1 */ + metric_t metrics2; /* path metric buffer 2 */ + decision_t* dp; /* Pointer to current decision */ + metric_t * old_metrics, *new_metrics; /* Pointers to path metrics, swapped on every bit */ + decision_t* decisions; /* Beginning of decisions for block */ + uint32_t len; }; -void set_viterbi37_polynomial_avx2_16bit(int polys[3]) { +void set_viterbi37_polynomial_avx2_16bit(int polys[3]) +{ int state; - for(state=0;state < 32;state++){ - Branchtab37_sse2[0].c[state] = (polys[0] < 0) ^ parity((2*state) & polys[0]) ? 65535:0; - Branchtab37_sse2[1].c[state] = (polys[1] < 0) ^ parity((2*state) & polys[1]) ? 65535:0; - Branchtab37_sse2[2].c[state] = (polys[2] < 0) ^ parity((2*state) & polys[2]) ? 65535:0; + for (state = 0; state < 32; state++) { + Branchtab37_sse2[0].c[state] = (polys[0] < 0) ^ parity((2 * state) & polys[0]) ? 65535 : 0; + Branchtab37_sse2[1].c[state] = (polys[1] < 0) ^ parity((2 * state) & polys[1]) ? 65535 : 0; + Branchtab37_sse2[2].c[state] = (polys[2] < 0) ^ parity((2 * state) & polys[2]) ? 65535 : 0; } } -void clear_v37_avx2_16bit(struct v37 *vp) { - bzero(vp->decisions, sizeof(decision_t)*vp->len); - vp->dp = NULL; +void clear_v37_avx2_16bit(struct v37* vp) +{ + bzero(vp->decisions, sizeof(decision_t) * vp->len); + vp->dp = NULL; bzero(&vp->metrics1, sizeof(metric_t)); bzero(&vp->metrics2, sizeof(metric_t)); - vp->old_metrics = NULL; - vp->new_metrics = NULL; + vp->old_metrics = NULL; + vp->new_metrics = NULL; } - /* Initialize Viterbi decoder for start of new frame */ -int init_viterbi37_avx2_16bit(void *p, int starting_state) { +int init_viterbi37_avx2_16bit(void* p, int starting_state) +{ - struct v37 *vp = p; - uint32_t i; + struct v37* vp = p; + uint32_t i; - for(i=0;i<64;i++) + for (i = 0; i < 64; i++) vp->metrics1.c[i] = 63; clear_v37_avx2_16bit(vp); -firstGo = 1; + firstGo = 1; vp->old_metrics = &vp->metrics1; vp->new_metrics = &vp->metrics2; - vp->dp = vp->decisions; + vp->dp = vp->decisions; if (starting_state != -1) { vp->old_metrics->c[starting_state & 63] = 0; /* Bias known start state */ } @@ -96,261 +96,254 @@ firstGo = 1; } /* Create a new instance of a Viterbi decoder */ -void *create_viterbi37_avx2_16bit(int polys[3], uint32_t len) { - void *p; - struct v37 *vp; +void* create_viterbi37_avx2_16bit(int polys[3], uint32_t len) +{ + void* p; + struct v37* vp; set_viterbi37_polynomial_avx2_16bit(polys); - + /* Ordinary malloc() only returns 8-byte alignment, we need 16 */ - if(posix_memalign(&p, sizeof(__m256i),sizeof(struct v37))) + if (posix_memalign(&p, sizeof(__m256i), sizeof(struct v37))) return NULL; - vp = (struct v37 *)p; - if(posix_memalign(&p, sizeof(__m256i),(len+6)*sizeof(decision_t))) { + vp = (struct v37*)p; + if (posix_memalign(&p, sizeof(__m256i), (len + 6) * sizeof(decision_t))) { free(vp); return NULL; } - vp->decisions = (decision_t *)p; - vp->len = len+6; + vp->decisions = (decision_t*)p; + vp->len = len + 6; return vp; } - /* Viterbi chainback */ -int chainback_viterbi37_avx2_16bit( - void *p, - uint8_t *data, /* Decoded output data */ - uint32_t nbits, /* Number of data bits */ - uint32_t endstate) { /* Terminal encoder state */ - struct v37 *vp = p; - +int chainback_viterbi37_avx2_16bit(void* p, + uint8_t* data, /* Decoded output data */ + uint32_t nbits, /* Number of data bits */ + uint32_t endstate) +{ /* Terminal encoder state */ + struct v37* vp = p; + if (p == NULL) return -1; - - decision_t *d = (decision_t *)vp->decisions; + + decision_t* d = (decision_t*)vp->decisions; /* Make room beyond the end of the encoder register so we can * accumulate a full byte of decoded data */ endstate %= 64; endstate <<= 2; - + /* The store into data[] only needs to be done every 8 bits. * But this avoids a conditional branch, and the writes will * combine in the cache anyway */ d += 6; /* Look past tail */ - while(nbits--) { + while (nbits--) { int k; - k = (d[nbits].c[(endstate>>2)/8] >> ((endstate>>2)%8)) & 1; - endstate = (endstate >> 1) | (k << 7); + k = (d[nbits].c[(endstate >> 2) / 8] >> ((endstate >> 2) % 8)) & 1; + endstate = (endstate >> 1) | (k << 7); data[nbits] = k; - //printf("nbits=%d, endstate=%3d, k=%d, w[0]=%d, w[1]=%d, c=%d\n", nbits, endstate, k, d[nbits].s[1]&1, d[nbits].s[2]&1, d[nbits].c[(endstate>>2)/8]&1); + // printf("nbits=%d, endstate=%3d, k=%d, w[0]=%d, w[1]=%d, c=%d\n", nbits, endstate, k, d[nbits].s[1]&1, + // d[nbits].s[2]&1, d[nbits].c[(endstate>>2)/8]&1); } return 0; } /* Delete instance of a Viterbi decoder */ -void delete_viterbi37_avx2_16bit(void *p){ - struct v37 *vp = p; +void delete_viterbi37_avx2_16bit(void* p) +{ + struct v37* vp = p; - if(vp != NULL){ + if (vp != NULL) { free(vp->decisions); free(vp); } } -void print_256i(char *s, __m256i val) { - +void print_256i(char* s, __m256i val) +{ + printf("%s: ", s); - uint16_t *x = (uint16_t*) &val; - for (int i=0;i<16;i++) { - printf("%.5f, ", (float)x[i]/65535); + uint16_t* x = (uint16_t*)&val; + for (int i = 0; i < 16; i++) { + printf("%.5f, ", (float)x[i] / 65535); } printf("\n"); } -void print_256i_char(char *s, __m256i val) { - +void print_256i_char(char* s, __m256i val) +{ + printf("%s: ", s); - uint8_t *x = (uint8_t*) &val; - for (int i=0;i<32;i++) { - printf("%d, ",x[31-i]); + uint8_t* x = (uint8_t*)&val; + for (int i = 0; i < 32; i++) { + printf("%d, ", x[31 - i]); } printf("\n"); } - -inline unsigned short my_mm256_movemask_epi16(__m256i x) { - uint32_t x1 = _mm256_movemask_epi8(x); +inline unsigned short my_mm256_movemask_epi16(__m256i x) +{ + uint32_t x1 = _mm256_movemask_epi8(x); uint16_t tmp = 0; - for(int i = 0; i<16;i++){ - tmp |= ((x1 >> ((i*2)+1)) & 0x01) << i; - } - - return (tmp); - } + for (int i = 0; i < 16; i++) { + tmp |= ((x1 >> ((i * 2) + 1)) & 0x01) << i; + } + return (tmp); +} -void update_viterbi37_blk_avx2_16bit(void *p, unsigned short *syms, int nbits, uint32_t *best_state) { - struct v37 *vp = p; - decision_t *d; +void update_viterbi37_blk_avx2_16bit(void* p, unsigned short* syms, int nbits, uint32_t* best_state) +{ + struct v37* vp = p; + decision_t* d; - if(p == NULL) + if (p == NULL) return; - + #ifdef DEBUG printf("["); #endif - - d = (decision_t *) vp->dp; - - for (int s=0;sdp; + + for (int s = 0; s < nbits; s++) { + memset(d + s, 0, sizeof(decision_t)); } - - while(nbits--) { - __m256i sym0v,sym1v,sym2v; - void *tmp; - int i; - - // printf("nbits=%d, syms=%d,%d,%d\n", nbits, syms[0], syms[1], syms[2]);fflush(stdout); - + + while (nbits--) { + __m256i sym0v, sym1v, sym2v; + void* tmp; + int i; + + // printf("nbits=%d, syms=%d,%d,%d\n", nbits, syms[0], syms[1], syms[2]);fflush(stdout); + /* Splat the 0th symbol across sym0v, the 1st symbol across sym1v, etc */ - - sym0v = _mm256_set1_epi16(syms[0]); + + sym0v = _mm256_set1_epi16(syms[0]); sym1v = _mm256_set1_epi16(syms[1]); - sym2v = _mm256_set1_epi16(syms[2]); - + sym2v = _mm256_set1_epi16(syms[2]); - syms += 3; - - for(i=0;i<2;i++){ - - - __m256i decision0,decision1,metric,m_metric,m0,m1,m2,m3,survivor0,survivor1; - - - /* Form branch metrics */ - m0 = _mm256_avg_epu16(_mm256_xor_si256(Branchtab37_sse2[0].v[i],sym0v),_mm256_xor_si256(Branchtab37_sse2[1].v[i],sym1v)); - metric = _mm256_avg_epu16(_mm256_xor_si256(Branchtab37_sse2[2].v[i],sym2v),m0); - + for (i = 0; i < 2; i++) { + + __m256i decision0, decision1, metric, m_metric, m0, m1, m2, m3, survivor0, survivor1; + + /* Form branch metrics */ + m0 = _mm256_avg_epu16(_mm256_xor_si256(Branchtab37_sse2[0].v[i], sym0v), + _mm256_xor_si256(Branchtab37_sse2[1].v[i], sym1v)); + metric = _mm256_avg_epu16(_mm256_xor_si256(Branchtab37_sse2[2].v[i], sym2v), m0); #ifdef DEBUG print_128i("metric_initial", metric); #endif /* There's no packed bytes right shift in SSE2, so we use the word version and mask */ - - metric = _mm256_srli_epi16(metric,3); - m_metric = _mm256_sub_epi16(_mm256_set1_epi16(8191),metric); - - + metric = _mm256_srli_epi16(metric, 3); + m_metric = _mm256_sub_epi16(_mm256_set1_epi16(8191), metric); - #ifdef DEBUG print_128i("metric ", metric); print_128i("m_metric ", m_metric); #endif - + /* Add branch metrics to path metrics */ - - m0 = _mm256_add_epi16(vp->old_metrics->v[i],metric); - m3 = _mm256_add_epi16(vp->old_metrics->v[2+i],metric); - m1 = _mm256_add_epi16(vp->old_metrics->v[2+i],m_metric); - m2 = _mm256_add_epi16(vp->old_metrics->v[i],m_metric); - + + m0 = _mm256_add_epi16(vp->old_metrics->v[i], metric); + m3 = _mm256_add_epi16(vp->old_metrics->v[2 + i], metric); + m1 = _mm256_add_epi16(vp->old_metrics->v[2 + i], m_metric); + m2 = _mm256_add_epi16(vp->old_metrics->v[i], m_metric); /* Compare and select, using modulo arithmetic */ - - decision0 = _mm256_cmpgt_epi16(_mm256_sub_epi16(m0,m1),_mm256_setzero_si256()); - decision1 = _mm256_cmpgt_epi16(_mm256_sub_epi16(m2,m3),_mm256_setzero_si256()); - survivor0 = _mm256_or_si256(_mm256_and_si256(decision0,m1),_mm256_andnot_si256(decision0,m0)); - survivor1 = _mm256_or_si256(_mm256_and_si256(decision1,m3),_mm256_andnot_si256(decision1,m2)); - - + + decision0 = _mm256_cmpgt_epi16(_mm256_sub_epi16(m0, m1), _mm256_setzero_si256()); + decision1 = _mm256_cmpgt_epi16(_mm256_sub_epi16(m2, m3), _mm256_setzero_si256()); + survivor0 = _mm256_or_si256(_mm256_and_si256(decision0, m1), _mm256_andnot_si256(decision0, m0)); + survivor1 = _mm256_or_si256(_mm256_and_si256(decision1, m3), _mm256_andnot_si256(decision1, m2)); /* Pack each set of decisions into 16 bits */ - - decision0 = _mm256_permute4x64_epi64(decision0,216); - decision1 = _mm256_permute4x64_epi64(decision1,216); - - __m256i packed = _mm256_packus_epi16( _mm256_srli_epi16(_mm256_unpacklo_epi16(decision0,decision1),8),_mm256_srli_epi16(_mm256_unpackhi_epi16(decision0,decision1),8)); + + decision0 = _mm256_permute4x64_epi64(decision0, 216); + decision1 = _mm256_permute4x64_epi64(decision1, 216); + + __m256i packed = _mm256_packus_epi16(_mm256_srli_epi16(_mm256_unpacklo_epi16(decision0, decision1), 8), + _mm256_srli_epi16(_mm256_unpackhi_epi16(decision0, decision1), 8)); d->w[i] = _mm256_movemask_epi8(packed); - - unsigned char temp_char1 = d->c[4*i + 1]; - unsigned char temp_char2 = d->c[4*i + 2]; - - d->c[4*i+1] = temp_char2; - d->c[4*i+2] = temp_char1; - + + unsigned char temp_char1 = d->c[4 * i + 1]; + unsigned char temp_char2 = d->c[4 * i + 2]; + + d->c[4 * i + 1] = temp_char2; + d->c[4 * i + 2] = temp_char1; + /* Store surviving metrics */ - survivor0 = _mm256_permute4x64_epi64(survivor0,216); - survivor1 = _mm256_permute4x64_epi64(survivor1,216); - - vp->new_metrics->v[2*i] = _mm256_unpacklo_epi16(survivor0,survivor1); - vp->new_metrics->v[2*i+1] = _mm256_unpackhi_epi16(survivor0,survivor1); - + survivor0 = _mm256_permute4x64_epi64(survivor0, 216); + survivor1 = _mm256_permute4x64_epi64(survivor1, 216); + + vp->new_metrics->v[2 * i] = _mm256_unpacklo_epi16(survivor0, survivor1); + vp->new_metrics->v[2 * i + 1] = _mm256_unpackhi_epi16(survivor0, survivor1); } // See if we need to normalize if (vp->new_metrics->c[0] > 12288) { int i; - - uint16_t adjust; - __m256i adjustv; - union { __m256i v; signed short w[8]; } t; - + + uint16_t adjust; + __m256i adjustv; + union { + __m256i v; + signed short w[8]; + } t; + adjustv = vp->new_metrics->v[0]; - for(i=1;i<4;i++) { - adjustv = _mm256_min_epu16(adjustv,vp->new_metrics->v[i]); + for (i = 1; i < 4; i++) { + adjustv = _mm256_min_epu16(adjustv, vp->new_metrics->v[i]); } - adjustv = _mm256_min_epu16(adjustv,_mm256_srli_si256(adjustv,16)); - adjustv = _mm256_min_epu16(adjustv,_mm256_srli_si256(adjustv,8)); - adjustv = _mm256_min_epu16(adjustv,_mm256_srli_si256(adjustv,4)); - - - t.v = adjustv; - adjust = t.w[0]; + adjustv = _mm256_min_epu16(adjustv, _mm256_srli_si256(adjustv, 16)); + adjustv = _mm256_min_epu16(adjustv, _mm256_srli_si256(adjustv, 8)); + adjustv = _mm256_min_epu16(adjustv, _mm256_srli_si256(adjustv, 4)); + + t.v = adjustv; + adjust = t.w[0]; adjustv = _mm256_set1_epi16(adjust); - + /* We cannot use a saturated subtract, because we often have to adjust by more than SHRT_MAX * This is okay since it can't overflow anyway */ - for(i=0;i<4;i++) - vp->new_metrics->v[i] = _mm256_sub_epi16(vp->new_metrics->v[i],adjustv); + for (i = 0; i < 4; i++) + vp->new_metrics->v[i] = _mm256_sub_epi16(vp->new_metrics->v[i], adjustv); } - d++; /* Swap pointers to old and new metrics */ - tmp = vp->old_metrics; + tmp = vp->old_metrics; vp->old_metrics = vp->new_metrics; vp->new_metrics = tmp; } - + if (best_state) { - uint32_t i, bst=0; - - uint16_t minmetric= UINT16_MAX; - for (i=0;i<64;i++) { + uint32_t i, bst = 0; + + uint16_t minmetric = UINT16_MAX; + for (i = 0; i < 64; i++) { if (vp->old_metrics->c[i] <= minmetric) { - bst = i; + bst = i; minmetric = vp->old_metrics->c[i]; } } *best_state = bst; } - #ifdef DEBUG +#ifdef DEBUG printf("];\n===========================================\n"); #endif @@ -358,6 +351,3 @@ void update_viterbi37_blk_avx2_16bit(void *p, unsigned short *syms, int nbits, u } #endif - - - diff --git a/lib/src/phy/fec/viterbi37_neon.c b/lib/src/phy/fec/viterbi37_neon.c index 94ddf67cc..9de1540ae 100644 --- a/lib/src/phy/fec/viterbi37_neon.c +++ b/lib/src/phy/fec/viterbi37_neon.c @@ -1,90 +1,91 @@ /* Adapted Phil Karn's r=1/3 k=9 viterbi decoder to r=1/3 k=7 - * + * * K=15 r=1/6 Viterbi decoder for ARM NEON * Copyright Mar 2004, Phil Karn, KA9Q * May be used under the terms of the GNU Lesser General Public License (LGPL) */ -#include +#include "parity.h" +#include +#include #include +#include #include -#include -#include -#include "parity.h" //#define DEBUG #ifdef HAVE_NEON #include -typedef union { - unsigned char c[64]; - uint8x16_t v[4]; +typedef union { + unsigned char c[64]; + uint8x16_t v[4]; } metric_t; -typedef union { - unsigned long w[2]; - unsigned char c[8]; - unsigned short s[4]; - uint8x8_t v[1]; +typedef union { + unsigned long w[2]; + unsigned char c[8]; + unsigned short s[4]; + uint8x8_t v[1]; } decision_t; -union branchtab27{ +union branchtab27 { unsigned char c[32]; - uint8x16_t v[2]; + uint8x16_t v[2]; } Branchtab37_neon[3]; int8_t __attribute__((aligned(16))) xr[8]; uint8x8_t mask_and; -int8x8_t mask_shift; - +int8x8_t mask_shift; /* State info for instance of Viterbi decoder */ struct v37 { - metric_t metrics1; /* path metric buffer 1 */ - metric_t metrics2; /* path metric buffer 2 */ - decision_t *dp; /* Pointer to current decision */ - metric_t *old_metrics,*new_metrics; /* Pointers to path metrics, swapped on every bit */ - decision_t *decisions; /* Beginning of decisions for block */ - uint32_t len; + metric_t metrics1; /* path metric buffer 1 */ + metric_t metrics2; /* path metric buffer 2 */ + decision_t* dp; /* Pointer to current decision */ + metric_t * old_metrics, *new_metrics; /* Pointers to path metrics, swapped on every bit */ + decision_t* decisions; /* Beginning of decisions for block */ + uint32_t len; }; -void set_viterbi37_polynomial_neon(int polys[3]) { +void set_viterbi37_polynomial_neon(int polys[3]) +{ int state; - for(state=0;state < 32;state++){ - Branchtab37_neon[0].c[state] = (polys[0] < 0) ^ parity((2*state) & polys[0]) ? 255:0; - Branchtab37_neon[1].c[state] = (polys[1] < 0) ^ parity((2*state) & polys[1]) ? 255:0; - Branchtab37_neon[2].c[state] = (polys[2] < 0) ^ parity((2*state) & polys[2]) ? 255:0; + for (state = 0; state < 32; state++) { + Branchtab37_neon[0].c[state] = (polys[0] < 0) ^ parity((2 * state) & polys[0]) ? 255 : 0; + Branchtab37_neon[1].c[state] = (polys[1] < 0) ^ parity((2 * state) & polys[1]) ? 255 : 0; + Branchtab37_neon[2].c[state] = (polys[2] < 0) ^ parity((2 * state) & polys[2]) ? 255 : 0; } } -void clear_v37_neon(struct v37 *vp) { - bzero(vp->decisions, sizeof(decision_t)*vp->len); - vp->dp = NULL; +void clear_v37_neon(struct v37* vp) +{ + bzero(vp->decisions, sizeof(decision_t) * vp->len); + vp->dp = NULL; bzero(&vp->metrics1, sizeof(metric_t)); bzero(&vp->metrics2, sizeof(metric_t)); - vp->old_metrics = NULL; - vp->new_metrics = NULL; + vp->old_metrics = NULL; + vp->new_metrics = NULL; } - /* Initialize Viterbi decoder for start of new frame */ -int init_viterbi37_neon(void *p, int starting_state) { - struct v37 *vp = p; - uint32_t i; - for(i=0;i<64;i++) +int init_viterbi37_neon(void* p, int starting_state) +{ + struct v37* vp = p; + uint32_t i; + for (i = 0; i < 64; i++) vp->metrics1.c[i] = 63; - + clear_v37_neon(vp); - for(int i = 0; i <8;i++) - xr[i] = i-7; - - mask_and = vdup_n_u8(0x80); + for (int i = 0; i < 8; i++) + xr[i] = i - 7; + + mask_and = vdup_n_u8(0x80); mask_shift = vld1_s8(xr); vp->old_metrics = &vp->metrics1; vp->new_metrics = &vp->metrics2; - vp->dp = vp->decisions; + vp->dp = vp->decisions; if (starting_state != -1) { vp->old_metrics->c[starting_state & 63] = 0; /* Bias known start state */ } @@ -92,90 +93,94 @@ int init_viterbi37_neon(void *p, int starting_state) { } /* Create a new instance of a Viterbi decoder */ -void *create_viterbi37_neon(int polys[3], uint32_t len) { - void *p; - struct v37 *vp; +void* create_viterbi37_neon(int polys[3], uint32_t len) +{ + void* p; + struct v37* vp; set_viterbi37_polynomial_neon(polys); - + /* Ordinary malloc() only returns 8-byte alignment, we need 16 */ - if(posix_memalign(&p, sizeof(uint8x16_t),sizeof(struct v37))) + if (posix_memalign(&p, sizeof(uint8x16_t), sizeof(struct v37))) return NULL; - vp = (struct v37 *)p; - if(posix_memalign(&p, sizeof(uint8x16_t),(len+6)*sizeof(decision_t))) { + vp = (struct v37*)p; + if (posix_memalign(&p, sizeof(uint8x16_t), (len + 6) * sizeof(decision_t))) { free(vp); return NULL; } - vp->decisions = (decision_t *)p; - vp->len = len+6; + vp->decisions = (decision_t*)p; + vp->len = len + 6; return vp; } - /* Viterbi chainback */ -int chainback_viterbi37_neon( - void *p, - uint8_t *data, /* Decoded output data */ - uint32_t nbits, /* Number of data bits */ - uint32_t endstate) { /* Terminal encoder state */ - struct v37 *vp = p; - +int chainback_viterbi37_neon(void* p, + uint8_t* data, /* Decoded output data */ + uint32_t nbits, /* Number of data bits */ + uint32_t endstate) +{ /* Terminal encoder state */ + struct v37* vp = p; + if (p == NULL) return -1; - decision_t *d = (decision_t *)vp->decisions; + decision_t* d = (decision_t*)vp->decisions; /* Make room beyond the end of the encoder register so we can * accumulate a full byte of decoded data */ endstate %= 64; endstate <<= 2; - + /* The store into data[] only needs to be done every 8 bits. * But this avoids a conditional branch, and the writes will * combine in the cache anyway */ d += 6; /* Look past tail */ - while(nbits--) { + while (nbits--) { int k; - k = (d[nbits].c[(endstate>>2)/8] >> ((endstate>>2)%8)) & 1; - endstate = (endstate >> 1) | (k << 7); + k = (d[nbits].c[(endstate >> 2) / 8] >> ((endstate >> 2) % 8)) & 1; + endstate = (endstate >> 1) | (k << 7); data[nbits] = k; - //printf("nbits=%d, endstate=%3d, k=%d, w[0]=%d, w[1]=%d, c=%d\n", nbits, endstate, k, d[nbits].s[1]&1, d[nbits].s[2]&1, d[nbits].c[(endstate>>2)/8]&1); + // printf("nbits=%d, endstate=%3d, k=%d, w[0]=%d, w[1]=%d, c=%d\n", nbits, endstate, k, d[nbits].s[1]&1, + // d[nbits].s[2]&1, d[nbits].c[(endstate>>2)/8]&1); } return 0; } /* Delete instance of a Viterbi decoder */ -void delete_viterbi37_neon(void *p){ - struct v37 *vp = p; +void delete_viterbi37_neon(void* p) +{ + struct v37* vp = p; - if(vp != NULL){ + if (vp != NULL) { free(vp->decisions); free(vp); } } -void print_uint8x16_t(char *s, uint8x16_t val) { - +void print_uint8x16_t(char* s, uint8x16_t val) +{ + printf("%s: ", s); - - uint8_t *x = (uint8_t*) &val; - for (int i=0;i<16;i++) { + + uint8_t* x = (uint8_t*)&val; + for (int i = 0; i < 16; i++) { printf("%3d, ", x[i]); } printf("\n"); } -static inline int movemask_neon(uint8x16_t movemask_low_in) { +static inline int movemask_neon(uint8x16_t movemask_low_in) +{ uint8x8_t lo = vget_low_u8(movemask_low_in); uint8x8_t hi = vget_high_u8(movemask_low_in); - lo = vand_u8(lo, mask_and); - lo = vshl_u8(lo, mask_shift); - hi = vand_u8(hi, mask_and); - hi = vshl_u8(hi, mask_shift); + lo = vand_u8(lo, mask_and); + lo = vshl_u8(lo, mask_shift); + hi = vand_u8(hi, mask_and); + hi = vshl_u8(hi, mask_shift); lo = vpadd_u8(lo, lo); lo = vpadd_u8(lo, lo); @@ -188,136 +193,137 @@ static inline int movemask_neon(uint8x16_t movemask_low_in) { return ((hi[0] << 8) | (lo[0] & 0xFF)); } -void update_viterbi37_blk_neon(void *p,unsigned char *syms,int nbits, uint32_t *best_state) { - struct v37 *vp = p; - decision_t *d; +void update_viterbi37_blk_neon(void* p, unsigned char* syms, int nbits, uint32_t* best_state) +{ + struct v37* vp = p; + decision_t* d; uint8_t thirtyone; thirtyone = 31; - if(p == NULL) + if (p == NULL) return; - + #ifdef DEBUG printf("["); #endif - - d = (decision_t *) vp->dp; - - for (int s=0;sdp; + + for (int s = 0; s < nbits; s++) { + memset(d + s, 0, sizeof(decision_t)); } - - while(nbits--) { - uint8x16_t sym0v,sym1v,sym2v; - void *tmp; - int i; - - // printf("nbits=%d, syms=%d,%d,%d\n", nbits, syms[0], syms[1], syms[2]);fflush(stdout); - + + while (nbits--) { + uint8x16_t sym0v, sym1v, sym2v; + void* tmp; + int i; + + // printf("nbits=%d, syms=%d,%d,%d\n", nbits, syms[0], syms[1], syms[2]);fflush(stdout); + /* Splat the 0th symbol across sym0v, the 1st symbol across sym1v, etc */ - sym0v = vld1q_dup_u8(syms); - sym1v = vld1q_dup_u8(syms+1); - sym2v = vld1q_dup_u8(syms+2); + sym0v = vld1q_dup_u8(syms); + sym1v = vld1q_dup_u8(syms + 1); + sym2v = vld1q_dup_u8(syms + 2); syms += 3; - - for(i=0;i<2;i++) { + + for (i = 0; i < 2; i++) { uint8x16_t decision0, decision1, metric, m_metric, m0, m1, m2, m3, survivor0, survivor1; /* Form branch metrics */ - m0 = vrhaddq_u8(veorq_u8(Branchtab37_neon[0].v[i],sym0v),veorq_u8(Branchtab37_neon[1].v[i],sym1v)); - metric = vrhaddq_u8(veorq_u8(Branchtab37_neon[2].v[i],sym2v),m0); - - metric = vshrq_n_u8(metric,3); - m_metric = vsubq_u8(vld1q_dup_u8(&thirtyone),metric); + m0 = vrhaddq_u8(veorq_u8(Branchtab37_neon[0].v[i], sym0v), veorq_u8(Branchtab37_neon[1].v[i], sym1v)); + metric = vrhaddq_u8(veorq_u8(Branchtab37_neon[2].v[i], sym2v), m0); + + metric = vshrq_n_u8(metric, 3); + m_metric = vsubq_u8(vld1q_dup_u8(&thirtyone), metric); /* Add branch metrics to path metrics */ - m0 = vaddq_u8(vp->old_metrics->v[i],metric); - m3 = vaddq_u8(vp->old_metrics->v[2+i],metric); - m1 = vaddq_u8(vp->old_metrics->v[2+i],m_metric); - m2 = vaddq_u8(vp->old_metrics->v[i],m_metric); - + m0 = vaddq_u8(vp->old_metrics->v[i], metric); + m3 = vaddq_u8(vp->old_metrics->v[2 + i], metric); + m1 = vaddq_u8(vp->old_metrics->v[2 + i], m_metric); + m2 = vaddq_u8(vp->old_metrics->v[i], m_metric); + /* Compare and select, using modulo arithmetic */ - decision0 = (uint8x16_t)vcgtq_s8(vsubq_s8((int8x16_t)m0,(int8x16_t)m1),vdupq_n_s8(0)); - decision1 = (uint8x16_t)vcgtq_s8(vsubq_s8((int8x16_t)m2,(int8x16_t)m3),vdupq_n_s8(0)); - survivor0 = vorrq_u8(vandq_u8(decision0,m1),vandq_u8(vmvnq_u8(decision0),m0)); - survivor1 = vorrq_u8 (vandq_u8(decision1,m3),vandq_u8(vmvnq_u8(decision1),m2) ); + decision0 = (uint8x16_t)vcgtq_s8(vsubq_s8((int8x16_t)m0, (int8x16_t)m1), vdupq_n_s8(0)); + decision1 = (uint8x16_t)vcgtq_s8(vsubq_s8((int8x16_t)m2, (int8x16_t)m3), vdupq_n_s8(0)); + survivor0 = vorrq_u8(vandq_u8(decision0, m1), vandq_u8(vmvnq_u8(decision0), m0)); + survivor1 = vorrq_u8(vandq_u8(decision1, m3), vandq_u8(vmvnq_u8(decision1), m2)); /* Pack each set of decisions into 16 bits */ - uint8x8_t a1 = vget_low_u8(decision0); - uint8x8_t b1 = vget_low_u8(decision1); - uint8x8x2_t result = vzip_u8(a1, b1); - uint8x16_t movemask_low_in = vcombine_u8(result.val[0], result.val[1]); - - d->s[2*i] = movemask_neon(movemask_low_in); - - a1 = vget_high_u8(decision0); - b1 = vget_high_u8(decision1); - result = vzip_u8(a1, b1); + uint8x8_t a1 = vget_low_u8(decision0); + uint8x8_t b1 = vget_low_u8(decision1); + uint8x8x2_t result = vzip_u8(a1, b1); + uint8x16_t movemask_low_in = vcombine_u8(result.val[0], result.val[1]); + + d->s[2 * i] = movemask_neon(movemask_low_in); + + a1 = vget_high_u8(decision0); + b1 = vget_high_u8(decision1); + result = vzip_u8(a1, b1); uint8x16_t movemask_hi_in = vcombine_u8(result.val[0], result.val[1]); - d->s[2*i+1] = movemask_neon(movemask_hi_in); + d->s[2 * i + 1] = movemask_neon(movemask_hi_in); - a1 = vget_low_u8(survivor0); - b1 = vget_low_u8(survivor1); - result = vzip_u8(a1, b1); - vp->new_metrics->v[2*i] = vcombine_u8(result.val[0], result.val[1]); + a1 = vget_low_u8(survivor0); + b1 = vget_low_u8(survivor1); + result = vzip_u8(a1, b1); + vp->new_metrics->v[2 * i] = vcombine_u8(result.val[0], result.val[1]); - a1 = vget_high_u8(survivor0); - b1 = vget_high_u8(survivor1); - result = vzip_u8(a1, b1); - vp->new_metrics->v[2*i+1] = vcombine_u8(result.val[0], result.val[1]); - - } + a1 = vget_high_u8(survivor0); + b1 = vget_high_u8(survivor1); + result = vzip_u8(a1, b1); + vp->new_metrics->v[2 * i + 1] = vcombine_u8(result.val[0], result.val[1]); + } // See if we need to normalize if (vp->new_metrics->c[0] > 100) { - int i; - uint8_t adjust; - uint8x16_t adjustv; - - union { uint8x16_t v; signed short w[8]; } t; - + int i; + uint8_t adjust; + uint8x16_t adjustv; + + union { + uint8x16_t v; + signed short w[8]; + } t; + adjustv = vp->new_metrics->v[0]; - for(i=1;i<4;i++) - { - adjustv = vminq_u8(vp->new_metrics->v[i],adjustv); + for (i = 1; i < 4; i++) { + adjustv = vminq_u8(vp->new_metrics->v[i], adjustv); } - - adjustv = vminq_u8(adjustv,vextq_u8(adjustv, vdupq_n_u8(0), (8))); - adjustv = vminq_u8(adjustv,vextq_u8(adjustv, vdupq_n_u8(0), (4))); - adjustv = vminq_u8(adjustv,vextq_u8(adjustv, vdupq_n_u8(0), (2))); - t.v = adjustv; - adjust = t.w[0]; + + adjustv = vminq_u8(adjustv, vextq_u8(adjustv, vdupq_n_u8(0), (8))); + adjustv = vminq_u8(adjustv, vextq_u8(adjustv, vdupq_n_u8(0), (4))); + adjustv = vminq_u8(adjustv, vextq_u8(adjustv, vdupq_n_u8(0), (2))); + t.v = adjustv; + adjust = t.w[0]; adjustv = vld1q_dup_u8(&adjust); - + /* We cannot use a saturated subtract, because we often have to adjust by more than SHRT_MAX * This is okay since it can't overflow anyway */ - for(i=0;i<4;i++) { - vp->new_metrics->v[i] = vsubq_u8(vp->new_metrics->v[i],adjustv); + for (i = 0; i < 4; i++) { + vp->new_metrics->v[i] = vsubq_u8(vp->new_metrics->v[i], adjustv); } - } d++; /* Swap pointers to old and new metrics */ - tmp = vp->old_metrics; + tmp = vp->old_metrics; vp->old_metrics = vp->new_metrics; vp->new_metrics = tmp; } - + if (best_state) { - uint32_t i, bst=0; - uint8_t minmetric=UINT8_MAX; - for (i=0;i<64;i++) { + uint32_t i, bst = 0; + uint8_t minmetric = UINT8_MAX; + for (i = 0; i < 64; i++) { if (vp->old_metrics->c[i] <= minmetric) { - bst = i; + bst = i; minmetric = vp->old_metrics->c[i]; } } *best_state = bst; } - #ifdef DEBUG +#ifdef DEBUG printf("];\n===========================================\n"); #endif @@ -325,6 +331,3 @@ void update_viterbi37_blk_neon(void *p,unsigned char *syms,int nbits, uint32_t * } #endif - - - diff --git a/lib/src/phy/fec/viterbi37_port.c b/lib/src/phy/fec/viterbi37_port.c index db2acc7e7..122dfd188 100644 --- a/lib/src/phy/fec/viterbi37_port.c +++ b/lib/src/phy/fec/viterbi37_port.c @@ -1,17 +1,17 @@ /* Adapted Phil Karn's r=1/3 k=9 viterbi decoder to r=1/3 k=7 - * + * * K=9 r=1/3 Viterbi decoder in portable C * Copyright Aug 2006, Phil Karn, KA9Q * May be used under the terms of the GNU Lesser General Public License (LGPL) */ +#include #include #include -#include -#include -#include "viterbi37.h" #include "parity.h" +#include "viterbi37.h" #include +#include //#define DEBUG @@ -28,84 +28,86 @@ static union { /* State info for instance of Viterbi decoder */ struct v37 { - metric_t metrics1; /* path metric buffer 1 */ - metric_t metrics2; /* path metric buffer 2 */ - decision_t *dp; /* Pointer to current decision */ - metric_t *old_metrics, *new_metrics; /* Pointers to path metrics, swapped on every bit */ - decision_t *decisions; /* Beginning of decisions for block */ - uint32_t len; + metric_t metrics1; /* path metric buffer 1 */ + metric_t metrics2; /* path metric buffer 2 */ + decision_t* dp; /* Pointer to current decision */ + metric_t * old_metrics, *new_metrics; /* Pointers to path metrics, swapped on every bit */ + decision_t* decisions; /* Beginning of decisions for block */ + uint32_t len; }; -void clear_v37(struct v37 *vp) { - bzero(vp->decisions, sizeof(decision_t)*vp->len); - vp->dp = NULL; +void clear_v37(struct v37* vp) +{ + bzero(vp->decisions, sizeof(decision_t) * vp->len); + vp->dp = NULL; bzero(&vp->metrics1, sizeof(metric_t)); bzero(&vp->metrics2, sizeof(metric_t)); - vp->old_metrics = NULL; - vp->new_metrics = NULL; + vp->old_metrics = NULL; + vp->new_metrics = NULL; } /* Initialize Viterbi decoder for start of new frame */ -int init_viterbi37_port(void *p, int starting_state) { - struct v37 *vp = p; - uint32_t i; - +int init_viterbi37_port(void* p, int starting_state) +{ + struct v37* vp = p; + uint32_t i; + if (p == NULL) return -1; - + clear_v37(vp); - + for (i = 0; i < 64; i++) vp->metrics1.w[i] = 63; vp->old_metrics = &vp->metrics1; vp->new_metrics = &vp->metrics2; - vp->dp = vp->decisions; + vp->dp = vp->decisions; if (starting_state != -1) { vp->old_metrics->w[starting_state & 255] = 0; /* Bias known start state */ } return 0; } -void set_viterbi37_polynomial_port(int polys[3]) { +void set_viterbi37_polynomial_port(int polys[3]) +{ int state; for (state = 0; state < 32; state++) { - Branchtab37[0].c[state] = - (polys[0] < 0) ^ parity((2 * state) & abs(polys[0])) ? 255 : 0; - Branchtab37[1].c[state] = - (polys[1] < 0) ^ parity((2 * state) & abs(polys[1])) ? 255 : 0; - Branchtab37[2].c[state] = - (polys[2] < 0) ^ parity((2 * state) & abs(polys[2])) ? 255 : 0; + Branchtab37[0].c[state] = (polys[0] < 0) ^ parity((2 * state) & abs(polys[0])) ? 255 : 0; + Branchtab37[1].c[state] = (polys[1] < 0) ^ parity((2 * state) & abs(polys[1])) ? 255 : 0; + Branchtab37[2].c[state] = (polys[2] < 0) ^ parity((2 * state) & abs(polys[2])) ? 255 : 0; } } /* Create a new instance of a Viterbi decoder */ -void *create_viterbi37_port(int polys[3], uint32_t len) { - struct v37 *vp; +void* create_viterbi37_port(int polys[3], uint32_t len) +{ + struct v37* vp; set_viterbi37_polynomial_port(polys); - if ((vp = (struct v37 *) malloc(sizeof(struct v37))) == NULL) - return NULL ; + if ((vp = (struct v37*)malloc(sizeof(struct v37))) == NULL) + return NULL; - if ((vp->decisions = (decision_t *) malloc((len + 6) * sizeof(decision_t))) - == NULL) { + if ((vp->decisions = (decision_t*)malloc((len + 6) * sizeof(decision_t))) == NULL) { free(vp); - return NULL ; + return NULL; } - - vp->len = len+6; + + vp->len = len + 6; return vp; } /* Viterbi chainback */ -int chainback_viterbi37_port(void *p, uint8_t *data, /* Decoded output data */ - uint32_t nbits, /* Number of data bits */ - uint32_t endstate) { /* Terminal encoder state */ - struct v37 *vp = p; - decision_t *d; +int chainback_viterbi37_port(void* p, + uint8_t* data, /* Decoded output data */ + uint32_t nbits, /* Number of data bits */ + uint32_t endstate) +{ /* Terminal encoder state */ + struct v37* vp = p; + decision_t* d; if (p == NULL) return -1; @@ -126,19 +128,20 @@ int chainback_viterbi37_port(void *p, uint8_t *data, /* Decoded output data */ while (nbits-- != 0) { int k; - k = (d[nbits].w[(endstate >> 2) / 32] >> ((endstate >> 2) % 32)) & 1; - endstate = (endstate >> 1) | (k << 7); + k = (d[nbits].w[(endstate >> 2) / 32] >> ((endstate >> 2) % 32)) & 1; + endstate = (endstate >> 1) | (k << 7); data[nbits] = k; #ifdef DEBUG - // printf("endstate=%3d, k=%d, w[0]=%d, w[1]=%d\n", endstate, k, d[nbits].w[0]&1, d[nbits].w[1]&1); + // printf("endstate=%3d, k=%d, w[0]=%d, w[1]=%d\n", endstate, k, d[nbits].w[0]&1, d[nbits].w[1]&1); #endif } return 0; } /* Delete instance of a Viterbi decoder */ -void delete_viterbi37_port(void *p) { - struct v37 *vp = p; +void delete_viterbi37_port(void* p) +{ + struct v37* vp = p; if (vp != NULL) { free(vp->decisions); @@ -147,43 +150,44 @@ void delete_viterbi37_port(void *p) { } /* C-language butterfly */ -#define BFLY(i) {\ -uint32_t metric,m0,m1,decision;\ - metric = (Branchtab37[0].c[i] ^ sym0) + (Branchtab37[1].c[i] ^ sym1) + \ - (Branchtab37[2].c[i] ^ sym2);\ - m0 = vp->old_metrics->w[i] + metric;\ - m1 = vp->old_metrics->w[i+32] + (765 - metric);\ - decision = (signed int)(m0-m1) > 0;\ - vp->new_metrics->w[2*i] = decision ? m1 : m0;\ - d->w[i/16] |= decision << ((2*i)&31);\ - m0 -= (metric+metric-765);\ - m1 += (metric+metric-765);\ - decision = (signed int)(m0-m1) > 0;\ - vp->new_metrics->w[2*i+1] = decision ? m1 : m0;\ - d->w[i/16] |= decision << ((2*i+1)&31);\ -} +#define BFLY(i) \ + { \ + uint32_t metric, m0, m1, decision; \ + metric = (Branchtab37[0].c[i] ^ sym0) + (Branchtab37[1].c[i] ^ sym1) + (Branchtab37[2].c[i] ^ sym2); \ + m0 = vp->old_metrics->w[i] + metric; \ + m1 = vp->old_metrics->w[i + 32] + (765 - metric); \ + decision = (signed int)(m0 - m1) > 0; \ + vp->new_metrics->w[2 * i] = decision ? m1 : m0; \ + d->w[i / 16] |= decision << ((2 * i) & 31); \ + m0 -= (metric + metric - 765); \ + m1 += (metric + metric - 765); \ + decision = (signed int)(m0 - m1) > 0; \ + vp->new_metrics->w[2 * i + 1] = decision ? m1 : m0; \ + d->w[i / 16] |= decision << ((2 * i + 1) & 31); \ + } /* Update decoder with a block of demodulated symbols * Note that nbits is the number of decoded data bits, not the number * of symbols! */ -int update_viterbi37_blk_port(void *p, uint8_t *syms, uint32_t nbits, uint32_t *best_state) { - struct v37 *vp = p; - decision_t *d; +int update_viterbi37_blk_port(void* p, uint8_t* syms, uint32_t nbits, uint32_t* best_state) +{ + struct v37* vp = p; + decision_t* d; if (p == NULL) return -1; - uint32_t k=0; - d = (decision_t *) vp->dp; - + uint32_t k = 0; + d = (decision_t*)vp->dp; + #ifdef DEBUG printf("["); #endif - + while (nbits--) { - void *tmp; - uint8_t sym0, sym1, sym2; + void* tmp; + uint8_t sym0, sym1, sym2; uint32_t i; d->w[0] = d->w[1] = 0; @@ -195,31 +199,31 @@ int update_viterbi37_blk_port(void *p, uint8_t *syms, uint32_t nbits, uint32_t * k++; for (i = 0; i < 32; i++) BFLY(i); - + #ifdef DEBUG - uint32_t wmin=UINT_MAX; - int minstate = 0; - for (int j=0;j<64;j++) { + uint32_t wmin = UINT_MAX; + int minstate = 0; + for (int j = 0; j < 64; j++) { if (vp->new_metrics->w[j] <= wmin) { - wmin = vp->new_metrics->w[j]; - minstate = j; + wmin = vp->new_metrics->w[j]; + minstate = j; } } printf("%3d, ", minstate); #endif - + d++; - tmp = vp->old_metrics; + tmp = vp->old_metrics; vp->old_metrics = vp->new_metrics; vp->new_metrics = tmp; } if (best_state) { - uint32_t i, bst=0; - uint32_t minmetric=UINT_MAX; - for (i=0;i<64;i++) { + uint32_t i, bst = 0; + uint32_t minmetric = UINT_MAX; + for (i = 0; i < 64; i++) { if (vp->old_metrics->w[i] <= minmetric) { - bst = i; + bst = i; minmetric = vp->old_metrics->w[i]; } } diff --git a/lib/src/phy/fec/viterbi37_sse.c b/lib/src/phy/fec/viterbi37_sse.c index d6dc6a9e2..edf10c55e 100644 --- a/lib/src/phy/fec/viterbi37_sse.c +++ b/lib/src/phy/fec/viterbi37_sse.c @@ -1,16 +1,16 @@ /* Adapted Phil Karn's r=1/3 k=9 viterbi decoder to r=1/3 k=7 - * + * * K=15 r=1/6 Viterbi decoder for x86 SSE2 * Copyright Mar 2004, Phil Karn, KA9Q * May be used under the terms of the GNU Lesser General Public License (LGPL) */ -#include +#include "parity.h" +#include +#include #include +#include #include -#include -#include -#include "parity.h" //#define DEBUG @@ -18,66 +18,67 @@ #include -typedef union { - unsigned char c[64]; - __m128i v[4]; +typedef union { + unsigned char c[64]; + __m128i v[4]; } metric_t; -typedef union { - unsigned long w[2]; - unsigned char c[8]; - unsigned short s[4]; - __m64 v[1]; +typedef union { + unsigned long w[2]; + unsigned char c[8]; + unsigned short s[4]; + __m64 v[1]; } decision_t; -union branchtab27 { - unsigned char c[32]; - __m128i v[2]; +union branchtab27 { + unsigned char c[32]; + __m128i v[2]; } Branchtab37_sse2[3]; - /* State info for instance of Viterbi decoder */ struct v37 { - metric_t metrics1; /* path metric buffer 1 */ - metric_t metrics2; /* path metric buffer 2 */ - decision_t *dp; /* Pointer to current decision */ - metric_t *old_metrics,*new_metrics; /* Pointers to path metrics, swapped on every bit */ - decision_t *decisions; /* Beginning of decisions for block */ - uint32_t len; + metric_t metrics1; /* path metric buffer 1 */ + metric_t metrics2; /* path metric buffer 2 */ + decision_t* dp; /* Pointer to current decision */ + metric_t * old_metrics, *new_metrics; /* Pointers to path metrics, swapped on every bit */ + decision_t* decisions; /* Beginning of decisions for block */ + uint32_t len; }; -void set_viterbi37_polynomial_sse(int polys[3]) { +void set_viterbi37_polynomial_sse(int polys[3]) +{ int state; - for(state=0;state < 32;state++){ - Branchtab37_sse2[0].c[state] = (polys[0] < 0) ^ parity((2*state) & polys[0]) ? 255:0; - Branchtab37_sse2[1].c[state] = (polys[1] < 0) ^ parity((2*state) & polys[1]) ? 255:0; - Branchtab37_sse2[2].c[state] = (polys[2] < 0) ^ parity((2*state) & polys[2]) ? 255:0; + for (state = 0; state < 32; state++) { + Branchtab37_sse2[0].c[state] = (polys[0] < 0) ^ parity((2 * state) & polys[0]) ? 255 : 0; + Branchtab37_sse2[1].c[state] = (polys[1] < 0) ^ parity((2 * state) & polys[1]) ? 255 : 0; + Branchtab37_sse2[2].c[state] = (polys[2] < 0) ^ parity((2 * state) & polys[2]) ? 255 : 0; } } -void clear_v37_sse(struct v37 *vp) { - bzero(vp->decisions, sizeof(decision_t)*vp->len); - vp->dp = NULL; +void clear_v37_sse(struct v37* vp) +{ + bzero(vp->decisions, sizeof(decision_t) * vp->len); + vp->dp = NULL; bzero(&vp->metrics1, sizeof(metric_t)); bzero(&vp->metrics2, sizeof(metric_t)); - vp->old_metrics = NULL; - vp->new_metrics = NULL; + vp->old_metrics = NULL; + vp->new_metrics = NULL; } - /* Initialize Viterbi decoder for start of new frame */ -int init_viterbi37_sse(void *p, int starting_state) { - struct v37 *vp = p; - uint32_t i; - - for(i=0;i<64;i++) +int init_viterbi37_sse(void* p, int starting_state) +{ + struct v37* vp = p; + uint32_t i; + + for (i = 0; i < 64; i++) vp->metrics1.c[i] = 63; clear_v37_sse(vp); vp->old_metrics = &vp->metrics1; vp->new_metrics = &vp->metrics2; - vp->dp = vp->decisions; + vp->dp = vp->decisions; if (starting_state != -1) { vp->old_metrics->c[starting_state & 63] = 0; /* Bias known start state */ } @@ -85,204 +86,209 @@ int init_viterbi37_sse(void *p, int starting_state) { } /* Create a new instance of a Viterbi decoder */ -void *create_viterbi37_sse(int polys[3], uint32_t len) { - void *p; - struct v37 *vp; +void* create_viterbi37_sse(int polys[3], uint32_t len) +{ + void* p; + struct v37* vp; set_viterbi37_polynomial_sse(polys); - + /* Ordinary malloc() only returns 8-byte alignment, we need 16 */ - if(posix_memalign(&p, sizeof(__m128i),sizeof(struct v37))) + if (posix_memalign(&p, sizeof(__m128i), sizeof(struct v37))) return NULL; - vp = (struct v37 *)p; - if(posix_memalign(&p, sizeof(__m128i),(len+6)*sizeof(decision_t))) { + vp = (struct v37*)p; + if (posix_memalign(&p, sizeof(__m128i), (len + 6) * sizeof(decision_t))) { free(vp); return NULL; } - vp->decisions = (decision_t *)p; - vp->len = len+6; + vp->decisions = (decision_t*)p; + vp->len = len + 6; return vp; } - /* Viterbi chainback */ -int chainback_viterbi37_sse( - void *p, - uint8_t *data, /* Decoded output data */ - uint32_t nbits, /* Number of data bits */ - uint32_t endstate) { /* Terminal encoder state */ - struct v37 *vp = p; - +int chainback_viterbi37_sse(void* p, + uint8_t* data, /* Decoded output data */ + uint32_t nbits, /* Number of data bits */ + uint32_t endstate) +{ /* Terminal encoder state */ + struct v37* vp = p; + if (p == NULL) return -1; - decision_t *d = (decision_t *)vp->decisions; + decision_t* d = (decision_t*)vp->decisions; /* Make room beyond the end of the encoder register so we can * accumulate a full byte of decoded data */ endstate %= 64; endstate <<= 2; - + /* The store into data[] only needs to be done every 8 bits. * But this avoids a conditional branch, and the writes will * combine in the cache anyway */ d += 6; /* Look past tail */ - while(nbits--) { + while (nbits--) { int k; - k = (d[nbits].c[(endstate>>2)/8] >> ((endstate>>2)%8)) & 1; - endstate = (endstate >> 1) | (k << 7); + k = (d[nbits].c[(endstate >> 2) / 8] >> ((endstate >> 2) % 8)) & 1; + endstate = (endstate >> 1) | (k << 7); data[nbits] = k; - //printf("nbits=%d, endstate=%3d, k=%d, w[0]=%d, w[1]=%d, c=%d\n", nbits, endstate, k, d[nbits].s[1]&1, d[nbits].s[2]&1, d[nbits].c[(endstate>>2)/8]&1); + // printf("nbits=%d, endstate=%3d, k=%d, w[0]=%d, w[1]=%d, c=%d\n", nbits, endstate, k, d[nbits].s[1]&1, + // d[nbits].s[2]&1, d[nbits].c[(endstate>>2)/8]&1); } return 0; } /* Delete instance of a Viterbi decoder */ -void delete_viterbi37_sse(void *p){ - struct v37 *vp = p; +void delete_viterbi37_sse(void* p) +{ + struct v37* vp = p; - if(vp != NULL){ + if (vp != NULL) { free(vp->decisions); free(vp); } } -void print_128i(char *s, __m128i val) { - +void print_128i(char* s, __m128i val) +{ + printf("%s: ", s); - - uint8_t *x = (uint8_t*) &val; - for (int i=0;i<16;i++) { + + uint8_t* x = (uint8_t*)&val; + for (int i = 0; i < 16; i++) { printf("%3d, ", x[i]); } printf("\n"); } -void update_viterbi37_blk_sse(void *p,unsigned char *syms,int nbits, uint32_t *best_state) { - struct v37 *vp = p; - decision_t *d; +void update_viterbi37_blk_sse(void* p, unsigned char* syms, int nbits, uint32_t* best_state) +{ + struct v37* vp = p; + decision_t* d; - if(p == NULL) + if (p == NULL) return; - + #ifdef DEBUG printf("["); #endif - - d = (decision_t *) vp->dp; - - for (int s=0;sdp; + + for (int s = 0; s < nbits; s++) { + memset(d + s, 0, sizeof(decision_t)); } - - while(nbits--) { - __m128i sym0v,sym1v,sym2v; - void *tmp; - int i; - - // printf("nbits=%d, syms=%d,%d,%d\n", nbits, syms[0], syms[1], syms[2]);fflush(stdout); - + + while (nbits--) { + __m128i sym0v, sym1v, sym2v; + void* tmp; + int i; + + // printf("nbits=%d, syms=%d,%d,%d\n", nbits, syms[0], syms[1], syms[2]);fflush(stdout); + /* Splat the 0th symbol across sym0v, the 1st symbol across sym1v, etc */ sym0v = _mm_set1_epi8(syms[0]); sym1v = _mm_set1_epi8(syms[1]); sym2v = _mm_set1_epi8(syms[2]); syms += 3; - - for(i=0;i<2;i++){ - __m128i decision0,decision1,metric,m_metric,m0,m1,m2,m3,survivor0,survivor1; + + for (i = 0; i < 2; i++) { + __m128i decision0, decision1, metric, m_metric, m0, m1, m2, m3, survivor0, survivor1; /* Form branch metrics */ - m0 = _mm_avg_epu8(_mm_xor_si128(Branchtab37_sse2[0].v[i],sym0v),_mm_xor_si128(Branchtab37_sse2[1].v[i],sym1v)); - metric = _mm_avg_epu8(_mm_xor_si128(Branchtab37_sse2[2].v[i],sym2v),m0); + m0 = _mm_avg_epu8(_mm_xor_si128(Branchtab37_sse2[0].v[i], sym0v), _mm_xor_si128(Branchtab37_sse2[1].v[i], sym1v)); + metric = _mm_avg_epu8(_mm_xor_si128(Branchtab37_sse2[2].v[i], sym2v), m0); #ifdef DEBUG print_128i("metric_initial", metric); #endif /* There's no packed bytes right shift in SSE2, so we use the word version and mask */ - metric = _mm_srli_epi16(metric,3); - metric = _mm_and_si128(metric,_mm_set1_epi8(31)); - m_metric = _mm_sub_epi8(_mm_set1_epi8(31),metric); - + metric = _mm_srli_epi16(metric, 3); + metric = _mm_and_si128(metric, _mm_set1_epi8(31)); + m_metric = _mm_sub_epi8(_mm_set1_epi8(31), metric); + #ifdef DEBUG print_128i("metric ", metric); print_128i("m_metric ", m_metric); #endif - + /* Add branch metrics to path metrics */ - m0 = _mm_add_epi8(vp->old_metrics->v[i],metric); - m3 = _mm_add_epi8(vp->old_metrics->v[2+i],metric); - m1 = _mm_add_epi8(vp->old_metrics->v[2+i],m_metric); - m2 = _mm_add_epi8(vp->old_metrics->v[i],m_metric); - + m0 = _mm_add_epi8(vp->old_metrics->v[i], metric); + m3 = _mm_add_epi8(vp->old_metrics->v[2 + i], metric); + m1 = _mm_add_epi8(vp->old_metrics->v[2 + i], m_metric); + m2 = _mm_add_epi8(vp->old_metrics->v[i], m_metric); + /* Compare and select, using modulo arithmetic */ - decision0 = _mm_cmpgt_epi8(_mm_sub_epi8(m0,m1),_mm_setzero_si128()); - decision1 = _mm_cmpgt_epi8(_mm_sub_epi8(m2,m3),_mm_setzero_si128()); - survivor0 = _mm_or_si128(_mm_and_si128(decision0,m1),_mm_andnot_si128(decision0,m0)); - survivor1 = _mm_or_si128(_mm_and_si128(decision1,m3),_mm_andnot_si128(decision1,m2)); - + decision0 = _mm_cmpgt_epi8(_mm_sub_epi8(m0, m1), _mm_setzero_si128()); + decision1 = _mm_cmpgt_epi8(_mm_sub_epi8(m2, m3), _mm_setzero_si128()); + survivor0 = _mm_or_si128(_mm_and_si128(decision0, m1), _mm_andnot_si128(decision0, m0)); + survivor1 = _mm_or_si128(_mm_and_si128(decision1, m3), _mm_andnot_si128(decision1, m2)); + /* Pack each set of decisions into 16 bits */ - d->s[2*i] = _mm_movemask_epi8(_mm_unpacklo_epi8(decision0,decision1)); - d->s[2*i+1] = _mm_movemask_epi8(_mm_unpackhi_epi8(decision0,decision1)); + d->s[2 * i] = _mm_movemask_epi8(_mm_unpacklo_epi8(decision0, decision1)); + d->s[2 * i + 1] = _mm_movemask_epi8(_mm_unpackhi_epi8(decision0, decision1)); /* Store surviving metrics */ - vp->new_metrics->v[2*i] = _mm_unpacklo_epi8(survivor0,survivor1); - vp->new_metrics->v[2*i+1] = _mm_unpackhi_epi8(survivor0,survivor1); - + vp->new_metrics->v[2 * i] = _mm_unpacklo_epi8(survivor0, survivor1); + vp->new_metrics->v[2 * i + 1] = _mm_unpackhi_epi8(survivor0, survivor1); } // See if we need to normalize if (vp->new_metrics->c[0] > 100) { - int i; - uint8_t adjust; + int i; + uint8_t adjust; __m128i adjustv; - union { __m128i v; signed short w[8]; } t; - + union { + __m128i v; + signed short w[8]; + } t; + adjustv = vp->new_metrics->v[0]; - for(i=1;i<4;i++) { - adjustv = _mm_min_epu8(adjustv,vp->new_metrics->v[i]); + for (i = 1; i < 4; i++) { + adjustv = _mm_min_epu8(adjustv, vp->new_metrics->v[i]); } - - adjustv = _mm_min_epu8(adjustv,_mm_srli_si128(adjustv,8)); - adjustv = _mm_min_epu8(adjustv,_mm_srli_si128(adjustv,4)); - adjustv = _mm_min_epu8(adjustv,_mm_srli_si128(adjustv,2)); - - t.v = adjustv; - adjust = t.w[0]; + + adjustv = _mm_min_epu8(adjustv, _mm_srli_si128(adjustv, 8)); + adjustv = _mm_min_epu8(adjustv, _mm_srli_si128(adjustv, 4)); + adjustv = _mm_min_epu8(adjustv, _mm_srli_si128(adjustv, 2)); + + t.v = adjustv; + adjust = t.w[0]; adjustv = _mm_set1_epi8(adjust); - + /* We cannot use a saturated subtract, because we often have to adjust by more than SHRT_MAX * This is okay since it can't overflow anyway */ - for(i=0;i<4;i++) - vp->new_metrics->v[i] = _mm_sub_epi8(vp->new_metrics->v[i],adjustv); + for (i = 0; i < 4; i++) + vp->new_metrics->v[i] = _mm_sub_epi8(vp->new_metrics->v[i], adjustv); } - d++; /* Swap pointers to old and new metrics */ - tmp = vp->old_metrics; + tmp = vp->old_metrics; vp->old_metrics = vp->new_metrics; vp->new_metrics = tmp; } - + if (best_state) { - uint32_t i, bst=0; - uint8_t minmetric=UINT8_MAX; - for (i=0;i<64;i++) { + uint32_t i, bst = 0; + uint8_t minmetric = UINT8_MAX; + for (i = 0; i < 64; i++) { if (vp->old_metrics->c[i] <= minmetric) { - bst = i; + bst = i; minmetric = vp->old_metrics->c[i]; } } *best_state = bst; } - #ifdef DEBUG +#ifdef DEBUG printf("];\n===========================================\n"); #endif @@ -290,6 +296,3 @@ void update_viterbi37_blk_sse(void *p,unsigned char *syms,int nbits, uint32_t *b } #endif - - - diff --git a/lib/src/phy/io/binsource.c b/lib/src/phy/io/binsource.c index f3a129fb9..b2812566d 100644 --- a/lib/src/phy/io/binsource.c +++ b/lib/src/phy/io/binsource.c @@ -19,30 +19,30 @@ * */ -#include #include #include +#include #include "srslte/phy/io/binsource.h" #include "srslte/phy/utils/bit.h" -#define DIV(a,b) ((a-1)/b+1) - +#define DIV(a, b) ((a - 1) / b + 1) /* Internal functions */ -static int gen_seq_buff(srslte_binsource_t* q, int nwords) { +static int gen_seq_buff(srslte_binsource_t* q, int nwords) +{ if (q->seq_buff_nwords != nwords) { free(q->seq_buff); q->seq_buff_nwords = 0; } if (!q->seq_buff_nwords) { - q->seq_buff = malloc(nwords*sizeof(uint32_t)); + q->seq_buff = malloc(nwords * sizeof(uint32_t)); if (!q->seq_buff) { return -1; } q->seq_buff_nwords = nwords; } - for (int i=0;iseq_buff_nwords;i++) { + for (int i = 0; i < q->seq_buff_nwords; i++) { q->seq_buff[i] = rand_r(&q->seed); } return 0; @@ -53,14 +53,16 @@ static int gen_seq_buff(srslte_binsource_t* q, int nwords) { /** * Initializes the binsource object. */ -void srslte_binsource_init(srslte_binsource_t* q) { - bzero((void*) q,sizeof(srslte_binsource_t)); +void srslte_binsource_init(srslte_binsource_t* q) +{ + bzero((void*)q, sizeof(srslte_binsource_t)); } /** * Destroys binsource object */ -void srslte_binsource_free(srslte_binsource_t* q) { +void srslte_binsource_free(srslte_binsource_t* q) +{ if (q->seq_buff) { free(q->seq_buff); } @@ -70,14 +72,16 @@ void srslte_binsource_free(srslte_binsource_t* q) { /** * Sets a new seed */ -void srslte_binsource_seed_set(srslte_binsource_t* q, uint32_t seed) { +void srslte_binsource_seed_set(srslte_binsource_t* q, uint32_t seed) +{ q->seed = seed; } /** * Sets local time as seed. */ -void srslte_binsource_seed_time(srslte_binsource_t *q) { +void srslte_binsource_seed_time(srslte_binsource_t* q) +{ struct timeval t1; gettimeofday(&t1, NULL); q->seed = t1.tv_usec * t1.tv_sec; @@ -86,44 +90,45 @@ void srslte_binsource_seed_time(srslte_binsource_t *q) { /** * Generates a sequence of nbits random bits */ -int srslte_binsource_cache_gen(srslte_binsource_t* q, int nbits) { - if (gen_seq_buff(q,DIV(nbits,32))) { +int srslte_binsource_cache_gen(srslte_binsource_t* q, int nbits) +{ + if (gen_seq_buff(q, DIV(nbits, 32))) { return -1; } q->seq_cache_nbits = nbits; - q->seq_cache_rp = 0; + q->seq_cache_rp = 0; return 0; } -static int int_2_bits(uint32_t* src, uint8_t* dst, int nbits) { +static int int_2_bits(uint32_t* src, uint8_t* dst, int nbits) +{ int n; - n=nbits/32; - for (int i=0;iseq_cache_rp += int_2_bits(&q->seq_buff[q->seq_cache_rp],bits,nbits); +void srslte_binsource_cache_cpy(srslte_binsource_t* q, uint8_t* bits, int nbits) +{ + q->seq_cache_rp += int_2_bits(&q->seq_buff[q->seq_cache_rp], bits, nbits); } /** * Stores in the bits buffer a sequence of nbits pseudo-random bits. * Overwrites the bits generated using srslte_binsource_cache_gen. */ -int srslte_binsource_generate(srslte_binsource_t* q, uint8_t *bits, int nbits) { +int srslte_binsource_generate(srslte_binsource_t* q, uint8_t* bits, int nbits) +{ - if (gen_seq_buff(q,DIV(nbits,32))) { + if (gen_seq_buff(q, DIV(nbits, 32))) { return -1; } - int_2_bits(q->seq_buff,bits,nbits); + int_2_bits(q->seq_buff, bits, nbits); return 0; } - - - diff --git a/lib/src/phy/io/filesink.c b/lib/src/phy/io/filesink.c index 27458941d..bf5495123 100644 --- a/lib/src/phy/io/filesink.c +++ b/lib/src/phy/io/filesink.c @@ -19,15 +19,15 @@ * */ +#include #include #include -#include #include - #include "srslte/phy/io/filesink.h" -int srslte_filesink_init(srslte_filesink_t *q, char *filename, srslte_datatype_t type) { +int srslte_filesink_init(srslte_filesink_t* q, char* filename, srslte_datatype_t type) +{ bzero(q, sizeof(srslte_filesink_t)); q->f = fopen(filename, "w"); if (!q->f) { @@ -38,90 +38,93 @@ int srslte_filesink_init(srslte_filesink_t *q, char *filename, srslte_datatype_t return 0; } -void srslte_filesink_free(srslte_filesink_t *q) { +void srslte_filesink_free(srslte_filesink_t* q) +{ if (q->f) { fclose(q->f); } bzero(q, sizeof(srslte_filesink_t)); } -int srslte_filesink_write(srslte_filesink_t *q, void *buffer, int nsamples) { - int i = 0; - float *fbuf = (float*) buffer; - _Complex float *cbuf = (_Complex float*) buffer; - _Complex short *sbuf = (_Complex short*) buffer; - int size; +int srslte_filesink_write(srslte_filesink_t* q, void* buffer, int nsamples) +{ + int i = 0; + float* fbuf = (float*)buffer; + _Complex float* cbuf = (_Complex float*)buffer; + _Complex short* sbuf = (_Complex short*)buffer; + int size; - switch(q->type) { - case SRSLTE_TEXT: - fprintf(q->f, "%s",(char *)buffer); - break; - case SRSLTE_FLOAT: - for (i=0;if,"%g\n",fbuf[i]); - } - break; - case SRSLTE_COMPLEX_FLOAT: - for (i=0;i= 0) - fprintf(q->f,"%g+%gi\n",__real__ cbuf[i],__imag__ cbuf[i]); - else - fprintf(q->f,"%g-%gi\n",__real__ cbuf[i],fabsf(__imag__ cbuf[i])); - } - break; - case SRSLTE_COMPLEX_SHORT: - for (i=0;i= 0) - fprintf(q->f,"%hd+%hdi\n",__real__ sbuf[i],__imag__ sbuf[i]); - else - fprintf(q->f,"%hd-%hdi\n",__real__ sbuf[i],(short) abs(__imag__ sbuf[i])); - } - break; - case SRSLTE_FLOAT_BIN: - case SRSLTE_COMPLEX_FLOAT_BIN: - case SRSLTE_COMPLEX_SHORT_BIN: - if (q->type == SRSLTE_FLOAT_BIN) { - size = sizeof(float); - } else if (q->type == SRSLTE_COMPLEX_FLOAT_BIN) { - size = sizeof(_Complex float); - } else if (q->type == SRSLTE_COMPLEX_SHORT_BIN) { - size = sizeof(_Complex short); - } - return fwrite(buffer, size, nsamples, q->f); - break; - default: - i = -1; - break; + switch (q->type) { + case SRSLTE_TEXT: + fprintf(q->f, "%s", (char*)buffer); + break; + case SRSLTE_FLOAT: + for (i = 0; i < nsamples; i++) { + fprintf(q->f, "%g\n", fbuf[i]); + } + break; + case SRSLTE_COMPLEX_FLOAT: + for (i = 0; i < nsamples; i++) { + if (__imag__ cbuf[i] >= 0) + fprintf(q->f, "%g+%gi\n", __real__ cbuf[i], __imag__ cbuf[i]); + else + fprintf(q->f, "%g-%gi\n", __real__ cbuf[i], fabsf(__imag__ cbuf[i])); + } + break; + case SRSLTE_COMPLEX_SHORT: + for (i = 0; i < nsamples; i++) { + if (__imag__ sbuf[i] >= 0) + fprintf(q->f, "%hd+%hdi\n", __real__ sbuf[i], __imag__ sbuf[i]); + else + fprintf(q->f, "%hd-%hdi\n", __real__ sbuf[i], (short)abs(__imag__ sbuf[i])); + } + break; + case SRSLTE_FLOAT_BIN: + case SRSLTE_COMPLEX_FLOAT_BIN: + case SRSLTE_COMPLEX_SHORT_BIN: + if (q->type == SRSLTE_FLOAT_BIN) { + size = sizeof(float); + } else if (q->type == SRSLTE_COMPLEX_FLOAT_BIN) { + size = sizeof(_Complex float); + } else if (q->type == SRSLTE_COMPLEX_SHORT_BIN) { + size = sizeof(_Complex short); + } + return fwrite(buffer, size, nsamples, q->f); + break; + default: + i = -1; + break; } return i; } -int srslte_filesink_write_multi(srslte_filesink_t *q, void **buffer, int nsamples, int nchannels) { - int i, j; - float **fbuf = (float**) buffer; - _Complex float **cbuf = (_Complex float**) buffer; - _Complex short **sbuf = (_Complex short**) buffer; - int size; +int srslte_filesink_write_multi(srslte_filesink_t* q, void** buffer, int nsamples, int nchannels) +{ + int i, j; + float** fbuf = (float**)buffer; + _Complex float** cbuf = (_Complex float**)buffer; + _Complex short** sbuf = (_Complex short**)buffer; + int size; - switch(q->type) { + switch (q->type) { case SRSLTE_FLOAT: - for (i=0;if, "%g%c", fbuf[j][i], (j!=(nchannels-1))?'\t':'\n'); + for (i = 0; i < nsamples; i++) { + for (j = 0; j < nchannels; j++) { + fprintf(q->f, "%g%c", fbuf[j][i], (j != (nchannels - 1)) ? '\t' : '\n'); } } break; case SRSLTE_COMPLEX_FLOAT: - for (i=0;if, "%g%+gi%c", __real__ cbuf[j][i], __imag__ cbuf[j][i], (j!=(nchannels-1))?'\t':'\n'); + for (i = 0; i < nsamples; i++) { + for (j = 0; j < nchannels; j++) { + fprintf(q->f, "%g%+gi%c", __real__ cbuf[j][i], __imag__ cbuf[j][i], (j != (nchannels - 1)) ? '\t' : '\n'); } } break; case SRSLTE_COMPLEX_SHORT: - for (i=0;if, "%hd%+hdi%c", __real__ sbuf[j][i], __imag__ sbuf[j][i], (j!=(nchannels-1))?'\t':'\n'); + for (i = 0; i < nsamples; i++) { + for (j = 0; j < nchannels; j++) { + fprintf(q->f, "%hd%+hdi%c", __real__ sbuf[j][i], __imag__ sbuf[j][i], (j != (nchannels - 1)) ? '\t' : '\n'); } } break; diff --git a/lib/src/phy/io/filesource.c b/lib/src/phy/io/filesource.c index 3f4f4ee8d..33501147b 100644 --- a/lib/src/phy/io/filesource.c +++ b/lib/src/phy/io/filesource.c @@ -26,7 +26,8 @@ #include "srslte/phy/io/filesource.h" #include "srslte/phy/utils/debug.h" -int srslte_filesource_init(srslte_filesource_t *q, char *filename, srslte_datatype_t type) { +int srslte_filesource_init(srslte_filesource_t* q, char* filename, srslte_datatype_t type) +{ bzero(q, sizeof(srslte_filesource_t)); q->f = fopen(filename, "r"); if (!q->f) { @@ -37,85 +38,90 @@ int srslte_filesource_init(srslte_filesource_t *q, char *filename, srslte_dataty return 0; } -void srslte_filesource_free(srslte_filesource_t *q) { +void srslte_filesource_free(srslte_filesource_t* q) +{ if (q->f) { fclose(q->f); } bzero(q, sizeof(srslte_filesource_t)); } -void srslte_filesource_seek(srslte_filesource_t *q, int pos) { - if (fseek(q->f, pos, SEEK_SET) != 0){ +void srslte_filesource_seek(srslte_filesource_t* q, int pos) +{ + if (fseek(q->f, pos, SEEK_SET) != 0) { perror("srslte_filesource_seek"); } } -int read_complex_f(FILE *f, _Complex float *y) { - char in_str[64]; +int read_complex_f(FILE* f, _Complex float* y) +{ + char in_str[64]; _Complex float x = 0; if (NULL == fgets(in_str, 64, f)) { return -1; } else { if (index(in_str, 'i') || index(in_str, 'j')) { - sscanf(in_str,"%f%fi",&(__real__ x),&(__imag__ x)); + sscanf(in_str, "%f%fi", &(__real__ x), &(__imag__ x)); } else { __imag__ x = 0; - sscanf(in_str,"%f",&(__real__ x)); + sscanf(in_str, "%f", &(__real__ x)); } *y = x; return 0; } } -int srslte_filesource_read(srslte_filesource_t *q, void *buffer, int nsamples) { - int i; - float *fbuf = (float*) buffer; - _Complex float *cbuf = (_Complex float*) buffer; - _Complex short *sbuf = (_Complex short*) buffer; - int size; +int srslte_filesource_read(srslte_filesource_t* q, void* buffer, int nsamples) +{ + int i; + float* fbuf = (float*)buffer; + _Complex float* cbuf = (_Complex float*)buffer; + _Complex short* sbuf = (_Complex short*)buffer; + int size; - switch(q->type) { - case SRSLTE_FLOAT: - for (i=0;if,"%g\n",&fbuf[i])) - break; - } - break; - case SRSLTE_COMPLEX_FLOAT: - for (i=0;if, &cbuf[i])) { - break; + switch (q->type) { + case SRSLTE_FLOAT: + for (i = 0; i < nsamples; i++) { + if (EOF == fscanf(q->f, "%g\n", &fbuf[i])) + break; } - } - break; - case SRSLTE_COMPLEX_SHORT: - for (i=0;if,"%hd%hdi\n",&(__real__ sbuf[i]),&(__imag__ sbuf[i]))) - break; - } - break; - case SRSLTE_FLOAT_BIN: - case SRSLTE_COMPLEX_FLOAT_BIN: - case SRSLTE_COMPLEX_SHORT_BIN: - if (q->type == SRSLTE_FLOAT_BIN) { - size = sizeof(float); - } else if (q->type == SRSLTE_COMPLEX_FLOAT_BIN) { - size = sizeof(_Complex float); - } else if (q->type == SRSLTE_COMPLEX_SHORT_BIN) { - size = sizeof(_Complex short); - } - return fread(buffer, size, nsamples, q->f); - break; - default: - i = -1; - break; + break; + case SRSLTE_COMPLEX_FLOAT: + for (i = 0; i < nsamples; i++) { + if (read_complex_f(q->f, &cbuf[i])) { + break; + } + } + break; + case SRSLTE_COMPLEX_SHORT: + for (i = 0; i < nsamples; i++) { + if (EOF == fscanf(q->f, "%hd%hdi\n", &(__real__ sbuf[i]), &(__imag__ sbuf[i]))) + break; + } + break; + case SRSLTE_FLOAT_BIN: + case SRSLTE_COMPLEX_FLOAT_BIN: + case SRSLTE_COMPLEX_SHORT_BIN: + if (q->type == SRSLTE_FLOAT_BIN) { + size = sizeof(float); + } else if (q->type == SRSLTE_COMPLEX_FLOAT_BIN) { + size = sizeof(_Complex float); + } else if (q->type == SRSLTE_COMPLEX_SHORT_BIN) { + size = sizeof(_Complex short); + } + return fread(buffer, size, nsamples, q->f); + break; + default: + i = -1; + break; } return i; } -int srslte_filesource_read_multi(srslte_filesource_t *q, void **buffer, int nsamples, int nof_channels) { - int i, j, count = 0; - _Complex float **cbuf = (_Complex float **) buffer; +int srslte_filesource_read_multi(srslte_filesource_t* q, void** buffer, int nsamples, int nof_channels) +{ + int i, j, count = 0; + _Complex float** cbuf = (_Complex float**)buffer; switch (q->type) { case SRSLTE_FLOAT: @@ -129,7 +135,7 @@ int srslte_filesource_read_multi(srslte_filesource_t *q, void **buffer, int nsam case SRSLTE_COMPLEX_FLOAT_BIN: for (i = 0; i < nsamples; i++) { for (j = 0; j < nof_channels; j++) { - count += fread(&cbuf[j][i], sizeof(cf_t), (size_t) 1, q->f); + count += fread(&cbuf[j][i], sizeof(cf_t), (size_t)1, q->f); } } break; diff --git a/lib/src/phy/io/netsink.c b/lib/src/phy/io/netsink.c index b8b15e441..092f730d0 100644 --- a/lib/src/phy/io/netsink.c +++ b/lib/src/phy/io/netsink.c @@ -19,93 +19,95 @@ * */ -#include -#include #include -#include +#include +#include +#include +#include #include #include -#include #include -#include -#include - +#include +#include #include "srslte/phy/io/netsink.h" -int srslte_netsink_init(srslte_netsink_t *q, const char *address, uint16_t port, srslte_netsink_type_t type) { +int srslte_netsink_init(srslte_netsink_t* q, const char* address, uint16_t port, srslte_netsink_type_t type) +{ bzero(q, sizeof(srslte_netsink_t)); - q->sockfd=socket(AF_INET, type==SRSLTE_NETSINK_TCP?SOCK_STREAM:SOCK_DGRAM,0); + q->sockfd = socket(AF_INET, type == SRSLTE_NETSINK_TCP ? SOCK_STREAM : SOCK_DGRAM, 0); if (q->sockfd < 0) { perror("socket"); - return -1; + return -1; } int enable = 1; -#if defined (SO_REUSEADDR) +#if defined(SO_REUSEADDR) if (setsockopt(q->sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) - perror("setsockopt(SO_REUSEADDR) failed"); + perror("setsockopt(SO_REUSEADDR) failed"); #endif -#if defined (SO_REUSEPORT) +#if defined(SO_REUSEPORT) if (setsockopt(q->sockfd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(int)) < 0) - perror("setsockopt(SO_REUSEPORT) failed"); + perror("setsockopt(SO_REUSEPORT) failed"); #endif - q->servaddr.sin_family = AF_INET; - q->servaddr.sin_addr.s_addr=inet_addr(address); - q->servaddr.sin_port=htons(port); - q->connected = false; - q->type = type; - + q->servaddr.sin_family = AF_INET; + q->servaddr.sin_addr.s_addr = inet_addr(address); + q->servaddr.sin_port = htons(port); + q->connected = false; + q->type = type; + return 0; } -void srslte_netsink_free(srslte_netsink_t *q) { +void srslte_netsink_free(srslte_netsink_t* q) +{ if (q->sockfd) { close(q->sockfd); } bzero(q, sizeof(srslte_netsink_t)); } -int srslte_netsink_set_nonblocking(srslte_netsink_t *q) { +int srslte_netsink_set_nonblocking(srslte_netsink_t* q) +{ if (fcntl(q->sockfd, F_SETFL, O_NONBLOCK)) { perror("fcntl"); - return -1; + return -1; } - return 0; + return 0; } -int srslte_netsink_write(srslte_netsink_t *q, void *buffer, int nof_bytes) { +int srslte_netsink_write(srslte_netsink_t* q, void* buffer, int nof_bytes) +{ if (!q->connected) { - if (connect(q->sockfd,&q->servaddr,sizeof(q->servaddr)) < 0) { + if (connect(q->sockfd, &q->servaddr, sizeof(q->servaddr)) < 0) { if (errno == ECONNREFUSED || errno == EINPROGRESS) { - return 0; + return 0; } else { perror("connect"); exit(-1); - return -1; + return -1; } } else { - q->connected = true; + q->connected = true; } - } - int n = 0; + } + int n = 0; if (q->connected) { - n = write(q->sockfd, buffer, nof_bytes); + n = write(q->sockfd, buffer, nof_bytes); if (n < 0) { if (errno == ECONNRESET) { close(q->sockfd); - q->sockfd=socket(AF_INET, q->type==SRSLTE_NETSINK_TCP?SOCK_STREAM:SOCK_DGRAM,0); + q->sockfd = socket(AF_INET, q->type == SRSLTE_NETSINK_TCP ? SOCK_STREAM : SOCK_DGRAM, 0); if (q->sockfd < 0) { perror("socket"); - return -1; + return -1; } - q->connected = false; - return 0; + q->connected = false; + return 0; } - } - } + } + } return n; } - diff --git a/lib/src/phy/io/netsource.c b/lib/src/phy/io/netsource.c index 139860129..229fdc8f8 100644 --- a/lib/src/phy/io/netsource.c +++ b/lib/src/phy/io/netsource.c @@ -19,95 +19,98 @@ * */ -#include -#include #include -#include +#include #include +#include #include #include #include -#include +#include +#include #include "srslte/phy/io/netsource.h" -int srslte_netsource_init(srslte_netsource_t *q, const char *address, uint16_t port, srslte_netsource_type_t type) { +int srslte_netsource_init(srslte_netsource_t* q, const char* address, uint16_t port, srslte_netsource_type_t type) +{ bzero(q, sizeof(srslte_netsource_t)); - q->sockfd=socket(AF_INET,type==SRSLTE_NETSOURCE_TCP?SOCK_STREAM:SOCK_DGRAM,0); + q->sockfd = socket(AF_INET, type == SRSLTE_NETSOURCE_TCP ? SOCK_STREAM : SOCK_DGRAM, 0); if (q->sockfd < 0) { perror("socket"); - return -1; + return -1; } - // Make sockets reusable + // Make sockets reusable int enable = 1; -#if defined (SO_REUSEADDR) +#if defined(SO_REUSEADDR) if (setsockopt(q->sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) - perror("setsockopt(SO_REUSEADDR) failed"); + perror("setsockopt(SO_REUSEADDR) failed"); #endif -#if defined (SO_REUSEPORT) +#if defined(SO_REUSEPORT) if (setsockopt(q->sockfd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(int)) < 0) - perror("setsockopt(SO_REUSEPORT) failed"); + perror("setsockopt(SO_REUSEPORT) failed"); #endif - q->type = type; - - q->servaddr.sin_family = AF_INET; - q->servaddr.sin_addr.s_addr=inet_addr(address); - q->servaddr.sin_port=htons(port); - - if (bind(q->sockfd,(struct sockaddr *)&q->servaddr,sizeof(struct sockaddr_in))) { + q->type = type; + + q->servaddr.sin_family = AF_INET; + q->servaddr.sin_addr.s_addr = inet_addr(address); + q->servaddr.sin_port = htons(port); + + if (bind(q->sockfd, (struct sockaddr*)&q->servaddr, sizeof(struct sockaddr_in))) { perror("bind"); - return -1; + return -1; } - q->connfd = 0; + q->connfd = 0; return 0; } -void srslte_netsource_free(srslte_netsource_t *q) { +void srslte_netsource_free(srslte_netsource_t* q) +{ if (q->sockfd) { close(q->sockfd); } bzero(q, sizeof(srslte_netsource_t)); } -int srslte_netsource_read(srslte_netsource_t *q, void *buffer, int nbytes) { +int srslte_netsource_read(srslte_netsource_t* q, void* buffer, int nbytes) +{ if (q->type == SRSLTE_NETSOURCE_UDP) { int n = recv(q->sockfd, buffer, nbytes, 0); - + if (n == -1) { if (errno == EAGAIN) { - return 0; + return 0; } else { - return -1; + return -1; } } else { - return n; - } + return n; + } } else { if (q->connfd == 0) { printf("Waiting for TCP connection\n"); listen(q->sockfd, 1); socklen_t clilen = sizeof(q->cliaddr); - q->connfd = accept(q->sockfd, (struct sockaddr *)&q->cliaddr, &clilen); + q->connfd = accept(q->sockfd, (struct sockaddr*)&q->cliaddr, &clilen); if (q->connfd < 0) { - perror("accept"); - return -1; + perror("accept"); + return -1; } } int n = read(q->connfd, buffer, nbytes); if (n == 0) { printf("Connection closed\n"); close(q->connfd); - q->connfd = 0; + q->connfd = 0; return 0; } if (n == -1) { - perror("read"); + perror("read"); } - return n; + return n; } } @@ -127,21 +130,23 @@ int srslte_netsource_write(srslte_netsource_t* q, void* buffer, int nbytes) return SRSLTE_SUCCESS; } -int srslte_netsource_set_nonblocking(srslte_netsource_t *q) { +int srslte_netsource_set_nonblocking(srslte_netsource_t* q) +{ if (fcntl(q->sockfd, F_SETFL, O_NONBLOCK)) { perror("fcntl"); - return -1; + return -1; } - return 0; + return 0; } -int srslte_netsource_set_timeout(srslte_netsource_t *q, uint32_t microseconds) { - struct timeval t; - t.tv_sec = 0; - t.tv_usec = microseconds; +int srslte_netsource_set_timeout(srslte_netsource_t* q, uint32_t microseconds) +{ + struct timeval t; + t.tv_sec = 0; + t.tv_usec = microseconds; if (setsockopt(q->sockfd, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(struct timeval))) { perror("setsockopt"); - return -1; + return -1; } - return 0; + return 0; } diff --git a/lib/src/phy/mimo/layermap.c b/lib/src/phy/mimo/layermap.c index 0017df516..f1b335696 100644 --- a/lib/src/phy/mimo/layermap.c +++ b/lib/src/phy/mimo/layermap.c @@ -19,8 +19,8 @@ * */ -#include #include +#include #include #include "srslte/phy/common/phy_common.h" @@ -28,26 +28,32 @@ #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" -int srslte_layermap_single(cf_t *d, cf_t *x, int nof_symbols) { +int srslte_layermap_single(cf_t* d, cf_t* x, int nof_symbols) +{ memcpy(x, d, sizeof(cf_t) * nof_symbols); return nof_symbols; } -int srslte_layermap_diversity(cf_t *d, cf_t *x[SRSLTE_MAX_LAYERS], int nof_layers, int nof_symbols) { +int srslte_layermap_diversity(cf_t* d, cf_t* x[SRSLTE_MAX_LAYERS], int nof_layers, int nof_symbols) +{ int i, j; - for (i=0;i #include -#include #include +#include +#include #include "srslte/phy/common/phy_common.h" #include "srslte/phy/mimo/precoding.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/mat.h" #include "srslte/phy/utils/simd.h" +#include "srslte/phy/utils/vector.h" #ifdef LV_HAVE_SSE #include -int srslte_predecoding_single_sse(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_MAX_PORTS], cf_t *x, int nof_rxant, int nof_symbols, float scaling, float noise_estimate); -int srslte_predecoding_diversity2_sse(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], cf_t *x[SRSLTE_MAX_LAYERS], int nof_rxant, int nof_symbols, float scaling); +int srslte_predecoding_single_sse(cf_t* y[SRSLTE_MAX_PORTS], + cf_t* h[SRSLTE_MAX_PORTS], + cf_t* x, + int nof_rxant, + int nof_symbols, + float scaling, + float noise_estimate); +int srslte_predecoding_diversity2_sse(cf_t* y[SRSLTE_MAX_PORTS], + cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + cf_t* x[SRSLTE_MAX_LAYERS], + int nof_rxant, + int nof_symbols, + float scaling); #endif #ifdef LV_HAVE_AVX #include -int srslte_predecoding_single_avx(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_MAX_PORTS], cf_t *x, int nof_rxant, int nof_symbols, float scaling, float noise_estimate); +int srslte_predecoding_single_avx(cf_t* y[SRSLTE_MAX_PORTS], + cf_t* h[SRSLTE_MAX_PORTS], + cf_t* x, + int nof_rxant, + int nof_symbols, + float scaling, + float noise_estimate); #endif #include "srslte/phy/utils/mat.h" static srslte_mimo_decoder_t mimo_decoder = SRSLTE_MIMO_DECODER_MMSE; /************************************************ - * + * * RECEIVER SIDE FUNCTIONS - * + * **************************************************/ #ifdef LV_HAVE_SSE -#define PROD(a,b) _mm_addsub_ps(_mm_mul_ps(a,_mm_moveldup_ps(b)),_mm_mul_ps(_mm_shuffle_ps(a,a,0xB1),_mm_movehdup_ps(b))) +#define PROD(a, b) \ + _mm_addsub_ps(_mm_mul_ps(a, _mm_moveldup_ps(b)), _mm_mul_ps(_mm_shuffle_ps(a, a, 0xB1), _mm_movehdup_ps(b))) + +int srslte_predecoding_single_sse(cf_t* y[SRSLTE_MAX_PORTS], + cf_t* h[SRSLTE_MAX_PORTS], + cf_t* x, + int nof_rxant, + int nof_symbols, + float scaling, + float noise_estimate) +{ -int srslte_predecoding_single_sse(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_MAX_PORTS], cf_t *x, int nof_rxant, int nof_symbols, float scaling, float noise_estimate) { - - float *xPtr = (float*) x; - const float *hPtr1 = (const float*) h[0]; - const float *yPtr1 = (const float*) y[0]; - const float *hPtr2 = (const float*) h[1]; - const float *yPtr2 = (const float*) y[1]; + float* xPtr = (float*)x; + const float* hPtr1 = (const float*)h[0]; + const float* yPtr1 = (const float*)y[0]; + const float* hPtr2 = (const float*)h[1]; + const float* yPtr2 = (const float*)y[1]; __m128 conjugator = _mm_setr_ps(0, -0.f, 0, -0.f); - + __m128 noise = _mm_set1_ps(noise_estimate); __m128 h1Val1, h2Val1, y1Val1, y2Val1; __m128 h1Val2, h2Val2, y1Val2, y2Val2; __m128 hsquare, h1square, h2square, h1conj1, h2conj1, x1Val1, x2Val1; __m128 hsquare2, h1conj2, h2conj2, x1Val2, x2Val2; - for (int i=0;i 0) { - hsquare = _mm_add_ps(hsquare, noise); + hsquare = _mm_add_ps(hsquare, noise); } - - h1square = _mm_shuffle_ps(hsquare, hsquare, _MM_SHUFFLE(1, 1, 0, 0)); - h2square = _mm_shuffle_ps(hsquare, hsquare, _MM_SHUFFLE(3, 3, 2, 2)); - + + h1square = _mm_shuffle_ps(hsquare, hsquare, _MM_SHUFFLE(1, 1, 0, 0)); + h2square = _mm_shuffle_ps(hsquare, hsquare, _MM_SHUFFLE(3, 3, 2, 2)); + /* Conjugate channel */ - h1conj1 = _mm_xor_ps(h1Val1, conjugator); - h2conj1 = _mm_xor_ps(h2Val1, conjugator); + h1conj1 = _mm_xor_ps(h1Val1, conjugator); + h2conj1 = _mm_xor_ps(h2Val1, conjugator); if (nof_rxant == 2) { - h1conj2 = _mm_xor_ps(h1Val2, conjugator); - h2conj2 = _mm_xor_ps(h2Val2, conjugator); + h1conj2 = _mm_xor_ps(h1Val2, conjugator); + h2conj2 = _mm_xor_ps(h2Val2, conjugator); } - - /* Complex product */ + + /* Complex product */ x1Val1 = PROD(y1Val1, h1conj1); x2Val1 = PROD(y2Val1, h2conj1); @@ -115,25 +148,26 @@ int srslte_predecoding_single_sse(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_MAX_ x1Val1 = _mm_add_ps(x1Val1, x1Val2); x2Val1 = _mm_add_ps(x2Val1, x2Val2); } - + x1Val1 = _mm_div_ps(x1Val1, h1square); x2Val1 = _mm_div_ps(x2Val1, h2square); - x1Val1 = _mm_mul_ps(x1Val1, _mm_set1_ps(1/scaling)); - x2Val1 = _mm_mul_ps(x2Val1, _mm_set1_ps(1/scaling)); + x1Val1 = _mm_mul_ps(x1Val1, _mm_set1_ps(1 / scaling)); + x2Val1 = _mm_mul_ps(x2Val1, _mm_set1_ps(1 / scaling)); - _mm_store_ps(xPtr, x1Val1); xPtr+=4; - _mm_store_ps(xPtr, x2Val1); xPtr+=4; - + _mm_store_ps(xPtr, x1Val1); + xPtr += 4; + _mm_store_ps(xPtr, x2Val1); + xPtr += 4; } - for (int i=8*(nof_symbols/8);i 0) { - h12square = _mm256_add_ps(h12square, noise); + h12square = _mm256_add_ps(h12square, noise); } - + h1_p = _mm256_permute_ps(h12square, _MM_SHUFFLE(1, 1, 0, 0)); h2_p = _mm256_permute_ps(h12square, _MM_SHUFFLE(3, 3, 2, 2)); - h1square = _mm256_permute2f128_ps(h1_p, h2_p, 2<<4); - h2square = _mm256_permute2f128_ps(h1_p, h2_p, 3<<4 | 1); - + h1square = _mm256_permute2f128_ps(h1_p, h2_p, 2 << 4); + h2square = _mm256_permute2f128_ps(h1_p, h2_p, 3 << 4 | 1); + /* Conjugate channel */ - h1conj1 = _mm256_xor_ps(h1Val1, conjugator); - h2conj1 = _mm256_xor_ps(h2Val1, conjugator); + h1conj1 = _mm256_xor_ps(h1Val1, conjugator); + h2conj1 = _mm256_xor_ps(h2Val1, conjugator); if (nof_rxant == 2) { - h1conj2 = _mm256_xor_ps(h1Val2, conjugator); - h2conj2 = _mm256_xor_ps(h2Val2, conjugator); + h1conj2 = _mm256_xor_ps(h1Val2, conjugator); + h2conj2 = _mm256_xor_ps(h2Val2, conjugator); } - - /* Complex product */ + + /* Complex product */ x1Val = PROD_AVX(y1Val1, h1conj1); x2Val = PROD_AVX(y2Val1, h2conj1); if (nof_rxant == 2) { x1Val = _mm256_add_ps(x1Val, PROD_AVX(y1Val2, h1conj2)); - x2Val = _mm256_add_ps(x2Val, PROD_AVX(y2Val2, h2conj2)); + x2Val = _mm256_add_ps(x2Val, PROD_AVX(y2Val2, h2conj2)); } - + x1Val = _mm256_div_ps(x1Val, h1square); x2Val = _mm256_div_ps(x2Val, h2square); x1Val = _mm256_mul_ps(x1Val, avx_scaling); x2Val = _mm256_mul_ps(x2Val, avx_scaling); - _mm256_store_ps(xPtr, x1Val); xPtr+=8; - _mm256_store_ps(xPtr, x2Val); xPtr+=8; + _mm256_store_ps(xPtr, x1Val); + xPtr += 8; + _mm256_store_ps(xPtr, x2Val); + xPtr += 8; } - for (int i=16*(nof_symbols/16);i 32 && nof_rxant <= 2) { - return srslte_predecoding_single_sse(y, h, x, nof_rxant, nof_symbols, scaling, noise_estimate); - } else { - return srslte_predecoding_single_gen(y, h, x, nof_rxant, nof_symbols, scaling, noise_estimate); - } - #else +#ifdef LV_HAVE_SSE + if (nof_symbols > 32 && nof_rxant <= 2) { + return srslte_predecoding_single_sse(y, h, x, nof_rxant, nof_symbols, scaling, noise_estimate); + } else { return srslte_predecoding_single_gen(y, h, x, nof_rxant, nof_symbols, scaling, noise_estimate); - #endif + } +#else + return srslte_predecoding_single_gen(y, h, x, nof_rxant, nof_symbols, scaling, noise_estimate); +#endif #endif } /* ZF/MMSE SISO equalizer x=y(h'h+no)^(-1)h' (ZF if n0=0.0)*/ -int srslte_predecoding_single_multi(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_MAX_PORTS], cf_t *x, float *csi[SRSLTE_MAX_CODEWORDS], - int nof_rxant, int nof_symbols, float scaling, float noise_estimate) { +int srslte_predecoding_single_multi(cf_t* y[SRSLTE_MAX_PORTS], + cf_t* h[SRSLTE_MAX_PORTS], + cf_t* x, + float* csi[SRSLTE_MAX_CODEWORDS], + int nof_rxant, + int nof_symbols, + float scaling, + float noise_estimate) +{ if (csi && csi[0]) { return srslte_predecoding_single_csi(y, h, x, csi[0], nof_rxant, nof_symbols, scaling, noise_estimate); } @@ -335,38 +415,43 @@ int srslte_predecoding_single_multi(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_MA return srslte_predecoding_single_gen(y, h, x, nof_rxant, nof_symbols, scaling, noise_estimate); } #else - #ifdef LV_HAVE_SSE - if (nof_symbols > 32) { - return srslte_predecoding_single_sse(y, h, x, nof_rxant, nof_symbols, scaling, noise_estimate); - } else { - return srslte_predecoding_single_gen(y, h, x, nof_rxant, nof_symbols, scaling, noise_estimate); - } - #else +#ifdef LV_HAVE_SSE + if (nof_symbols > 32) { + return srslte_predecoding_single_sse(y, h, x, nof_rxant, nof_symbols, scaling, noise_estimate); + } else { return srslte_predecoding_single_gen(y, h, x, nof_rxant, nof_symbols, scaling, noise_estimate); - #endif + } +#else + return srslte_predecoding_single_gen(y, h, x, nof_rxant, nof_symbols, scaling, noise_estimate); +#endif #endif } /* C implementatino of the SFBC equalizer */ -int srslte_predecoding_diversity_gen_(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], - cf_t *x[SRSLTE_MAX_LAYERS], - int nof_rxant, int nof_ports, int nof_symbols, int symbol_start, float scaling) +int srslte_predecoding_diversity_gen_(cf_t* y[SRSLTE_MAX_PORTS], + cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + cf_t* x[SRSLTE_MAX_LAYERS], + int nof_rxant, + int nof_ports, + int nof_symbols, + int symbol_start, + float scaling) { int i; if (nof_ports == 2) { cf_t h00, h01, h10, h11, r0, r1; - for (i = symbol_start/2; i < nof_symbols / 2; i++) { + for (i = symbol_start / 2; i < nof_symbols / 2; i++) { float hh = 0; - cf_t x0 = 0; - cf_t x1 = 0; - for (int p=0;p 32 && nof_ports == 2) { return srslte_predecoding_diversity2_sse(y, h, x, nof_rxant, nof_symbols, scaling); @@ -558,27 +671,33 @@ int srslte_predecoding_diversity(cf_t *y_, cf_t *h_[SRSLTE_MAX_PORTS], cf_t *x[S } #else return srslte_predecoding_diversity_gen(y, h, x, nof_rxant, nof_ports, nof_symbols, scaling); -#endif +#endif } -int srslte_predecoding_diversity_csi(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], - cf_t *x[SRSLTE_MAX_LAYERS], float *csi[SRSLTE_MAX_CODEWORDS], - int nof_rxant, int nof_ports, int nof_symbols, float scaling) { +int srslte_predecoding_diversity_csi(cf_t* y[SRSLTE_MAX_PORTS], + cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + cf_t* x[SRSLTE_MAX_LAYERS], + float* csi[SRSLTE_MAX_CODEWORDS], + int nof_rxant, + int nof_ports, + int nof_symbols, + float scaling) +{ int i; if (nof_ports == 2) { cf_t h00, h01, h10, h11, r0, r1; for (i = 0; i < nof_symbols / 2; i++) { float hh = 0; - cf_t x0 = 0; - cf_t x1 = 0; - for (int p=0;p max_sinr) { max_sinr = sinr_list[i]; - *pmi = i; + *pmi = i; } } @@ -2238,16 +2360,19 @@ int srslte_precoding_pmi_select_1l_gen(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT #ifdef LV_HAVE_SSE /* PMI Select for 1 layer */ -int srslte_precoding_pmi_select_1l_sse(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t nof_symbols, - float noise_estimate, uint32_t *pmi, - float sinr_list[SRSLTE_MAX_CODEBOOKS]) { - float max_sinr = 0.0; +int srslte_precoding_pmi_select_1l_sse(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + uint32_t nof_symbols, + float noise_estimate, + uint32_t* pmi, + float sinr_list[SRSLTE_MAX_CODEBOOKS]) +{ + float max_sinr = 0.0; uint32_t i, count; - __m128 sse_norm = _mm_set1_ps(0.5f); + __m128 sse_norm = _mm_set1_ps(0.5f); for (i = 0; i < 4; i++) { sinr_list[i] = 0; - count = 0; + count = 0; for (uint32_t j = 0; j < nof_symbols - PMI_SEL_PRECISION * 2 + 1; j += PMI_SEL_PRECISION * 2) { /* 0. Load channel matrix */ @@ -2326,7 +2451,7 @@ int srslte_precoding_pmi_select_1l_sse(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT if (sinr_list[i] > max_sinr) { max_sinr = sinr_list[i]; - *pmi = i; + *pmi = i; } } @@ -2338,51 +2463,54 @@ int srslte_precoding_pmi_select_1l_sse(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT #ifdef LV_HAVE_AVX /* PMI Select for 1 layer */ -int srslte_precoding_pmi_select_1l_avx(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t nof_symbols, - float noise_estimate, uint32_t *pmi, - float sinr_list[SRSLTE_MAX_CODEBOOKS]) { - float max_sinr = 0.0; +int srslte_precoding_pmi_select_1l_avx(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + uint32_t nof_symbols, + float noise_estimate, + uint32_t* pmi, + float sinr_list[SRSLTE_MAX_CODEBOOKS]) +{ + float max_sinr = 0.0; uint32_t i, count; - __m256 avx_norm = _mm256_set1_ps(0.5f); + __m256 avx_norm = _mm256_set1_ps(0.5f); for (i = 0; i < 4; i++) { sinr_list[i] = 0; - count = 0; + count = 0; for (uint32_t j = 0; j < nof_symbols - PMI_SEL_PRECISION * 4 + 1; j += PMI_SEL_PRECISION * 4) { /* 0. Load channel matrix */ __m256 h00 = _mm256_setr_ps(crealf(h[0][0][j]), - cimagf(h[0][0][j]), - crealf(h[0][0][j + PMI_SEL_PRECISION]), - cimagf(h[0][0][j + PMI_SEL_PRECISION]), - crealf(h[0][0][j + PMI_SEL_PRECISION * 2]), - cimagf(h[0][0][j + PMI_SEL_PRECISION * 2]), - crealf(h[0][0][j + PMI_SEL_PRECISION * 3]), - cimagf(h[0][0][j + PMI_SEL_PRECISION * 3])); + cimagf(h[0][0][j]), + crealf(h[0][0][j + PMI_SEL_PRECISION]), + cimagf(h[0][0][j + PMI_SEL_PRECISION]), + crealf(h[0][0][j + PMI_SEL_PRECISION * 2]), + cimagf(h[0][0][j + PMI_SEL_PRECISION * 2]), + crealf(h[0][0][j + PMI_SEL_PRECISION * 3]), + cimagf(h[0][0][j + PMI_SEL_PRECISION * 3])); __m256 h01 = _mm256_setr_ps(crealf(h[1][0][j]), - cimagf(h[1][0][j]), - crealf(h[1][0][j + PMI_SEL_PRECISION]), - cimagf(h[1][0][j + PMI_SEL_PRECISION]), - crealf(h[1][0][j + PMI_SEL_PRECISION * 2]), - cimagf(h[1][0][j + PMI_SEL_PRECISION * 2]), - crealf(h[1][0][j + PMI_SEL_PRECISION * 3]), - cimagf(h[1][0][j + PMI_SEL_PRECISION * 3])); + cimagf(h[1][0][j]), + crealf(h[1][0][j + PMI_SEL_PRECISION]), + cimagf(h[1][0][j + PMI_SEL_PRECISION]), + crealf(h[1][0][j + PMI_SEL_PRECISION * 2]), + cimagf(h[1][0][j + PMI_SEL_PRECISION * 2]), + crealf(h[1][0][j + PMI_SEL_PRECISION * 3]), + cimagf(h[1][0][j + PMI_SEL_PRECISION * 3])); __m256 h10 = _mm256_setr_ps(crealf(h[0][1][j]), - cimagf(h[0][1][j]), - crealf(h[0][1][j + PMI_SEL_PRECISION]), - cimagf(h[0][1][j + PMI_SEL_PRECISION]), - crealf(h[0][1][j + PMI_SEL_PRECISION * 2]), - cimagf(h[0][1][j + PMI_SEL_PRECISION * 2]), - crealf(h[0][1][j + PMI_SEL_PRECISION * 3]), - cimagf(h[0][1][j + PMI_SEL_PRECISION * 3])); + cimagf(h[0][1][j]), + crealf(h[0][1][j + PMI_SEL_PRECISION]), + cimagf(h[0][1][j + PMI_SEL_PRECISION]), + crealf(h[0][1][j + PMI_SEL_PRECISION * 2]), + cimagf(h[0][1][j + PMI_SEL_PRECISION * 2]), + crealf(h[0][1][j + PMI_SEL_PRECISION * 3]), + cimagf(h[0][1][j + PMI_SEL_PRECISION * 3])); __m256 h11 = _mm256_setr_ps(crealf(h[1][1][j]), - cimagf(h[1][1][j]), - crealf(h[1][1][j + PMI_SEL_PRECISION]), - cimagf(h[1][1][j + PMI_SEL_PRECISION]), - crealf(h[1][1][j + PMI_SEL_PRECISION * 2]), - cimagf(h[1][1][j + PMI_SEL_PRECISION * 2]), - crealf(h[1][1][j + PMI_SEL_PRECISION * 3]), - cimagf(h[1][1][j + PMI_SEL_PRECISION * 3])); + cimagf(h[1][1][j]), + crealf(h[1][1][j + PMI_SEL_PRECISION]), + cimagf(h[1][1][j + PMI_SEL_PRECISION]), + crealf(h[1][1][j + PMI_SEL_PRECISION * 2]), + cimagf(h[1][1][j + PMI_SEL_PRECISION * 2]), + crealf(h[1][1][j + PMI_SEL_PRECISION * 3]), + cimagf(h[1][1][j + PMI_SEL_PRECISION * 3])); /* 1. B = W'* H' */ __m256 a0, a1; @@ -2405,13 +2533,13 @@ int srslte_precoding_pmi_select_1l_avx(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT break; } - /* 2. B = W' * H' * H = A * H */ -#ifdef LV_HAVE_FMA + /* 2. B = W' * H' * H = A * H */ +#ifdef LV_HAVE_FMA __m256 b0 = _MM256_PROD_ADD_PS(a0, h00, _MM256_PROD_PS(a1, h10)); __m256 b1 = _MM256_PROD_ADD_PS(a0, h01, _MM256_PROD_PS(a1, h11)); #else - __m256 b0 = _mm256_add_ps(_MM256_PROD_PS(a0, h00), _MM256_PROD_PS(a1, h10)); - __m256 b1 = _mm256_add_ps(_MM256_PROD_PS(a0, h01), _MM256_PROD_PS(a1, h11)); + __m256 b0 = _mm256_add_ps(_MM256_PROD_PS(a0, h00), _MM256_PROD_PS(a1, h10)); + __m256 b1 = _mm256_add_ps(_MM256_PROD_PS(a0, h01), _MM256_PROD_PS(a1, h11)); #endif /* LV_HAVE_FMA */ /* 3. C = W' * H' * H * W' = B * W */ @@ -2447,7 +2575,7 @@ int srslte_precoding_pmi_select_1l_avx(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT if (sinr_list[i] > max_sinr) { max_sinr = sinr_list[i]; - *pmi = i; + *pmi = i; } } @@ -2456,14 +2584,17 @@ int srslte_precoding_pmi_select_1l_avx(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT #endif /* LV_HAVE_AVX */ -int srslte_precoding_pmi_select_1l(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t nof_symbols, - float noise_estimate, uint32_t *pmi, - float sinr_list[SRSLTE_MAX_CODEBOOKS]) { +int srslte_precoding_pmi_select_1l(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + uint32_t nof_symbols, + float noise_estimate, + uint32_t* pmi, + float sinr_list[SRSLTE_MAX_CODEBOOKS]) +{ int ret; #ifdef LV_HAVE_AVX ret = srslte_precoding_pmi_select_1l_avx(h, nof_symbols, noise_estimate, pmi, sinr_list); #else - #ifdef LV_HAVE_SSE +#ifdef LV_HAVE_SSE ret = srslte_precoding_pmi_select_1l_sse(h, nof_symbols, noise_estimate, pmi, sinr_list); #else ret = srslte_precoding_pmi_select_1l_gen(h, nof_symbols, noise_estimate, pmi, sinr_list); @@ -2479,16 +2610,19 @@ int srslte_precoding_pmi_select_1l(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], return ret; } -int srslte_precoding_pmi_select_2l_gen(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t nof_symbols, - float noise_estimate, uint32_t *pmi, - float sinr_list[SRSLTE_MAX_CODEBOOKS]) { +int srslte_precoding_pmi_select_2l_gen(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + uint32_t nof_symbols, + float noise_estimate, + uint32_t* pmi, + float sinr_list[SRSLTE_MAX_CODEBOOKS]) +{ - float max_sinr = 0.0; + float max_sinr = 0.0; uint32_t i, count; for (i = 0; i < 2; i++) { sinr_list[i] = 0; - count = 0; + count = 0; for (uint32_t j = 0; j < nof_symbols; j += PMI_SEL_PRECISION) { /* 0. Load channel matrix */ @@ -2550,7 +2684,7 @@ int srslte_precoding_pmi_select_2l_gen(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT c11 += noise_estimate; /* 5. detC */ - cf_t detC = c00 * c11 - c01 * c10; + cf_t detC = c00 * c11 - c01 * c10; cf_t inv_detC = conjf(detC) / (crealf(detC) * crealf(detC) + cimagf(detC) * cimagf(detC)); cf_t den0 = noise_estimate * c00 * inv_detC; @@ -2572,7 +2706,7 @@ int srslte_precoding_pmi_select_2l_gen(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT if (sinr_list[i] > max_sinr) { max_sinr = sinr_list[i]; - *pmi = i; + *pmi = i; } } @@ -2581,20 +2715,23 @@ int srslte_precoding_pmi_select_2l_gen(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT #ifdef LV_HAVE_SSE -int srslte_precoding_pmi_select_2l_sse(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t nof_symbols, - float noise_estimate, uint32_t *pmi, - float sinr_list[SRSLTE_MAX_CODEBOOKS]) { +int srslte_precoding_pmi_select_2l_sse(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + uint32_t nof_symbols, + float noise_estimate, + uint32_t* pmi, + float sinr_list[SRSLTE_MAX_CODEBOOKS]) +{ - float max_sinr = 0.0; + float max_sinr = 0.0; uint32_t i, count; __m128 sse_noise_estimate = _mm_setr_ps(noise_estimate, 0.0f, noise_estimate, 0.0f); - __m128 sse_norm = _mm_set1_ps(0.25f); - __m128 sse_ones = _mm_set1_ps(1.0f); + __m128 sse_norm = _mm_set1_ps(0.25f); + __m128 sse_ones = _mm_set1_ps(1.0f); for (i = 0; i < 2; i++) { sinr_list[i] = 0; - count = 0; + count = 0; for (uint32_t j = 0; j < nof_symbols - PMI_SEL_PRECISION * 2 + 1; j += PMI_SEL_PRECISION * 2) { /* 0. Load channel matrix */ @@ -2668,9 +2805,9 @@ int srslte_precoding_pmi_select_2l_sse(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT c11 = _mm_add_ps(c11, sse_noise_estimate); /* 5. detC */ - __m128 detC = srslte_mat_2x2_det_sse(c00, c01, c10, c11); + __m128 detC = srslte_mat_2x2_det_sse(c00, c01, c10, c11); __m128 inv_detC = srslte_mat_cf_recip_sse(detC); - inv_detC = _mm_mul_ps(sse_noise_estimate, inv_detC); + inv_detC = _mm_mul_ps(sse_noise_estimate, inv_detC); __m128 den0 = _MM_PROD_PS(c00, inv_detC); __m128 den1 = _MM_PROD_PS(c11, inv_detC); @@ -2679,7 +2816,7 @@ int srslte_precoding_pmi_select_2l_sse(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT __m128 gamma1 = _mm_sub_ps(_mm_rcp_ps(den1), sse_ones); /* Add for averaging */ - __m128 sinr_sse = _mm_add_ps(gamma0, gamma1); + __m128 sinr_sse = _mm_add_ps(gamma0, gamma1); __attribute__((aligned(128))) float sinr[4]; _mm_store_ps(sinr, sinr_sse); @@ -2695,7 +2832,7 @@ int srslte_precoding_pmi_select_2l_sse(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT if (sinr_list[i] > max_sinr) { max_sinr = sinr_list[i]; - *pmi = i; + *pmi = i; } } @@ -2706,56 +2843,59 @@ int srslte_precoding_pmi_select_2l_sse(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT #ifdef LV_HAVE_AVX -int srslte_precoding_pmi_select_2l_avx(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t nof_symbols, - float noise_estimate, uint32_t *pmi, - float sinr_list[SRSLTE_MAX_CODEBOOKS]) { +int srslte_precoding_pmi_select_2l_avx(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + uint32_t nof_symbols, + float noise_estimate, + uint32_t* pmi, + float sinr_list[SRSLTE_MAX_CODEBOOKS]) +{ - float max_sinr = 0.0; + float max_sinr = 0.0; uint32_t i, count; - __m256 avx_noise_estimate = _mm256_setr_ps(noise_estimate, 0.0f, noise_estimate, 0.0f, - noise_estimate, 0.0f, noise_estimate, 0.0f); + __m256 avx_noise_estimate = + _mm256_setr_ps(noise_estimate, 0.0f, noise_estimate, 0.0f, noise_estimate, 0.0f, noise_estimate, 0.0f); __m256 avx_norm = _mm256_set1_ps(0.25f); __m256 avx_ones = _mm256_set1_ps(1.0f); for (i = 0; i < 2; i++) { sinr_list[i] = 0; - count = 0; + count = 0; for (uint32_t j = 0; j < nof_symbols - PMI_SEL_PRECISION * 4 + 1; j += PMI_SEL_PRECISION * 4) { /* 0. Load channel matrix */ __m256 h00 = _mm256_setr_ps(crealf(h[0][0][j]), - cimagf(h[0][0][j]), - crealf(h[0][0][j + PMI_SEL_PRECISION]), - cimagf(h[0][0][j + PMI_SEL_PRECISION]), - crealf(h[0][0][j + PMI_SEL_PRECISION * 2]), - cimagf(h[0][0][j + PMI_SEL_PRECISION * 2]), - crealf(h[0][0][j + PMI_SEL_PRECISION * 3]), - cimagf(h[0][0][j + PMI_SEL_PRECISION * 3])); + cimagf(h[0][0][j]), + crealf(h[0][0][j + PMI_SEL_PRECISION]), + cimagf(h[0][0][j + PMI_SEL_PRECISION]), + crealf(h[0][0][j + PMI_SEL_PRECISION * 2]), + cimagf(h[0][0][j + PMI_SEL_PRECISION * 2]), + crealf(h[0][0][j + PMI_SEL_PRECISION * 3]), + cimagf(h[0][0][j + PMI_SEL_PRECISION * 3])); __m256 h01 = _mm256_setr_ps(crealf(h[1][0][j]), - cimagf(h[1][0][j]), - crealf(h[1][0][j + PMI_SEL_PRECISION]), - cimagf(h[1][0][j + PMI_SEL_PRECISION]), - crealf(h[1][0][j + PMI_SEL_PRECISION * 2]), - cimagf(h[1][0][j + PMI_SEL_PRECISION * 2]), - crealf(h[1][0][j + PMI_SEL_PRECISION * 3]), - cimagf(h[1][0][j + PMI_SEL_PRECISION * 3])); + cimagf(h[1][0][j]), + crealf(h[1][0][j + PMI_SEL_PRECISION]), + cimagf(h[1][0][j + PMI_SEL_PRECISION]), + crealf(h[1][0][j + PMI_SEL_PRECISION * 2]), + cimagf(h[1][0][j + PMI_SEL_PRECISION * 2]), + crealf(h[1][0][j + PMI_SEL_PRECISION * 3]), + cimagf(h[1][0][j + PMI_SEL_PRECISION * 3])); __m256 h10 = _mm256_setr_ps(crealf(h[0][1][j]), - cimagf(h[0][1][j]), - crealf(h[0][1][j + PMI_SEL_PRECISION]), - cimagf(h[0][1][j + PMI_SEL_PRECISION]), - crealf(h[0][1][j + PMI_SEL_PRECISION * 2]), - cimagf(h[0][1][j + PMI_SEL_PRECISION * 2]), - crealf(h[0][1][j + PMI_SEL_PRECISION * 3]), - cimagf(h[0][1][j + PMI_SEL_PRECISION * 3])); + cimagf(h[0][1][j]), + crealf(h[0][1][j + PMI_SEL_PRECISION]), + cimagf(h[0][1][j + PMI_SEL_PRECISION]), + crealf(h[0][1][j + PMI_SEL_PRECISION * 2]), + cimagf(h[0][1][j + PMI_SEL_PRECISION * 2]), + crealf(h[0][1][j + PMI_SEL_PRECISION * 3]), + cimagf(h[0][1][j + PMI_SEL_PRECISION * 3])); __m256 h11 = _mm256_setr_ps(crealf(h[1][1][j]), - cimagf(h[1][1][j]), - crealf(h[1][1][j + PMI_SEL_PRECISION]), - cimagf(h[1][1][j + PMI_SEL_PRECISION]), - crealf(h[1][1][j + PMI_SEL_PRECISION * 2]), - cimagf(h[1][1][j + PMI_SEL_PRECISION * 2]), - crealf(h[1][1][j + PMI_SEL_PRECISION * 3]), - cimagf(h[1][1][j + PMI_SEL_PRECISION * 3])); + cimagf(h[1][1][j]), + crealf(h[1][1][j + PMI_SEL_PRECISION]), + cimagf(h[1][1][j + PMI_SEL_PRECISION]), + crealf(h[1][1][j + PMI_SEL_PRECISION * 2]), + cimagf(h[1][1][j + PMI_SEL_PRECISION * 2]), + crealf(h[1][1][j + PMI_SEL_PRECISION * 3]), + cimagf(h[1][1][j + PMI_SEL_PRECISION * 3])); /* 1. B = W'* H' */ __m256 a00, a01, a10, a11; @@ -2776,7 +2916,7 @@ int srslte_precoding_pmi_select_2l_avx(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT return SRSLTE_ERROR; } - /* 2. B = W' * H' * H = A * H */ + /* 2. B = W' * H' * H = A * H */ #ifdef LV_HAVE_FMA __m256 b00 = _MM256_PROD_ADD_PS(a00, h00, _MM256_PROD_PS(a01, h10)); __m256 b01 = _MM256_PROD_ADD_PS(a00, h01, _MM256_PROD_PS(a01, h11)); @@ -2817,9 +2957,9 @@ int srslte_precoding_pmi_select_2l_avx(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT c11 = _mm256_add_ps(c11, avx_noise_estimate); /* 5. detC */ - __m256 detC = srslte_mat_2x2_det_avx(c00, c01, c10, c11); + __m256 detC = srslte_mat_2x2_det_avx(c00, c01, c10, c11); __m256 inv_detC = srslte_mat_cf_recip_avx(detC); - inv_detC = _mm256_mul_ps(avx_noise_estimate, inv_detC); + inv_detC = _mm256_mul_ps(avx_noise_estimate, inv_detC); __m256 den0 = _MM256_PROD_PS(c00, inv_detC); __m256 den1 = _MM256_PROD_PS(c11, inv_detC); @@ -2828,7 +2968,7 @@ int srslte_precoding_pmi_select_2l_avx(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT __m256 gamma1 = _mm256_sub_ps(_mm256_rcp_ps(den1), avx_ones); /* Add for averaging */ - __m256 sinr_avx = _mm256_permute_ps(_mm256_add_ps(gamma0, gamma1), 0b00101000); + __m256 sinr_avx = _mm256_permute_ps(_mm256_add_ps(gamma0, gamma1), 0b00101000); __attribute__((aligned(256))) float sinr[8]; _mm256_store_ps(sinr, sinr_avx); @@ -2844,7 +2984,7 @@ int srslte_precoding_pmi_select_2l_avx(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT if (sinr_list[i] > max_sinr) { max_sinr = sinr_list[i]; - *pmi = i; + *pmi = i; } } @@ -2854,15 +2994,18 @@ int srslte_precoding_pmi_select_2l_avx(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT #endif /* LV_HAVE_AVX */ /* PMI Select for 2 layers */ -int srslte_precoding_pmi_select_2l(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t nof_symbols, - float noise_estimate, uint32_t *pmi, - float sinr_list[SRSLTE_MAX_CODEBOOKS]) { +int srslte_precoding_pmi_select_2l(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + uint32_t nof_symbols, + float noise_estimate, + uint32_t* pmi, + float sinr_list[SRSLTE_MAX_CODEBOOKS]) +{ int ret; #ifdef LV_HAVE_AVX ret = srslte_precoding_pmi_select_2l_avx(h, nof_symbols, noise_estimate, pmi, sinr_list); #else - #ifdef LV_HAVE_SSE +#ifdef LV_HAVE_SSE ret = srslte_precoding_pmi_select_2l_sse(h, nof_symbols, noise_estimate, pmi, sinr_list); #else ret = srslte_precoding_pmi_select_2l_gen(h, nof_symbols, noise_estimate, pmi, sinr_list); @@ -2877,9 +3020,13 @@ int srslte_precoding_pmi_select_2l(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], return ret; } -int srslte_precoding_pmi_select(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t nof_symbols, - float noise_estimate, int nof_layers, uint32_t *pmi, - float sinr[SRSLTE_MAX_CODEBOOKS]) { +int srslte_precoding_pmi_select(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + uint32_t nof_symbols, + float noise_estimate, + int nof_layers, + uint32_t* pmi, + float sinr[SRSLTE_MAX_CODEBOOKS]) +{ int ret; if (sinr == NULL || pmi == NULL) { @@ -2898,9 +3045,10 @@ int srslte_precoding_pmi_select(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uin } /* PMI Select for 1 layer */ -float srslte_precoding_2x2_cn_gen(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t nof_symbols) { - uint32_t count = 0; - float cn_avg = 0.0f; +float srslte_precoding_2x2_cn_gen(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t nof_symbols) +{ + uint32_t count = 0; + float cn_avg = 0.0f; for (uint32_t i = 0; i < nof_symbols; i += PMI_SEL_PRECISION) { /* 0. Load channel matrix */ @@ -2923,8 +3071,12 @@ float srslte_precoding_2x2_cn_gen(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], u /* Computes the condition number for a given number of antennas, * stores in the parameter *cn the Condition Number in dB */ -int srslte_precoding_cn(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t nof_tx_antennas, - uint32_t nof_rx_antennas, uint32_t nof_symbols, float *cn) { +int srslte_precoding_cn(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], + uint32_t nof_tx_antennas, + uint32_t nof_rx_antennas, + uint32_t nof_symbols, + float* cn) +{ if (nof_tx_antennas == 2 && nof_rx_antennas == 2) { *cn = srslte_precoding_2x2_cn_gen(h, nof_symbols); return SRSLTE_SUCCESS; @@ -2933,4 +3085,3 @@ int srslte_precoding_cn(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t no return SRSLTE_ERROR; } } - diff --git a/lib/src/phy/mimo/test/layermap_test.c b/lib/src/phy/mimo/test/layermap_test.c index 99189d61e..437e75059 100644 --- a/lib/src/phy/mimo/test/layermap_test.c +++ b/lib/src/phy/mimo/test/layermap_test.c @@ -31,11 +31,12 @@ #include "srslte/srslte.h" -int nof_symbols = 1000; -int nof_cw = 1, nof_layers = 1; -char *mimo_type_name = NULL; +int nof_symbols = 1000; +int nof_cw = 1, nof_layers = 1; +char* mimo_type_name = NULL; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s -m [%s|%s|%s|%s] -c [nof_cw] -l [nof_layers]\n", prog, srslte_mimotype2str(0), @@ -45,25 +46,26 @@ void usage(char *prog) { printf("\t-n num_symbols [Default %d]\n", nof_symbols); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "mcln")) != -1) { switch (opt) { - case 'n': - nof_symbols = (int)strtol(argv[optind], NULL, 10); - break; - case 'c': - nof_cw = (int)strtol(argv[optind], NULL, 10); - break; - case 'l': - nof_layers = (int)strtol(argv[optind], NULL, 10); - break; - case 'm': - mimo_type_name = argv[optind]; - break; - default: - usage(argv[0]); - exit(-1); + case 'n': + nof_symbols = (int)strtol(argv[optind], NULL, 10); + break; + case 'c': + nof_cw = (int)strtol(argv[optind], NULL, 10); + break; + case 'l': + nof_layers = (int)strtol(argv[optind], NULL, 10); + break; + case 'm': + mimo_type_name = argv[optind]; + break; + default: + usage(argv[0]); + exit(-1); } } if (!mimo_type_name) { @@ -72,13 +74,14 @@ void parse_args(int argc, char **argv) { } } -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ srslte_random_t random = srslte_random_init(0); - int i, j, num_errors, symbols_layer; - cf_t *d[SRSLTE_MAX_CODEWORDS], *x[SRSLTE_MAX_LAYERS], *dp[SRSLTE_MAX_CODEWORDS]; + int i, j, num_errors, symbols_layer; + cf_t * d[SRSLTE_MAX_CODEWORDS], *x[SRSLTE_MAX_LAYERS], *dp[SRSLTE_MAX_CODEWORDS]; srslte_tx_scheme_t type; - int nof_symb_cw[SRSLTE_MAX_CODEWORDS]; - int n[2]; + int nof_symb_cw[SRSLTE_MAX_CODEWORDS]; + int n[2]; parse_args(argc, argv); @@ -88,8 +91,8 @@ int main(int argc, char **argv) { } if (nof_cw > 1) { - n[0] = nof_layers / nof_cw; - n[1] = nof_layers - n[0]; + n[0] = nof_layers / nof_cw; + n[1] = nof_layers - n[0]; nof_symb_cw[0] = nof_symbols * n[0]; nof_symb_cw[1] = nof_symbols * n[1]; } else { @@ -97,7 +100,7 @@ int main(int argc, char **argv) { nof_symb_cw[1] = 0; } - for (i=0;i +#include +#include #include #include #include #include -#include -#include #include -#include -#include - +#include -#include "srslte/phy/utils/vector.h" -#include "srslte/phy/mimo/precoding.h" #include "pmi_select_test.h" +#include "srslte/phy/mimo/precoding.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" -int main(int argc, char **argv) { - cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; - float noise_estimate; - float sinr_1l[SRSLTE_MAX_CODEBOOKS]; - float sinr_2l[SRSLTE_MAX_CODEBOOKS]; - float cn; +int main(int argc, char** argv) +{ + cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; + float noise_estimate; + float sinr_1l[SRSLTE_MAX_CODEBOOKS]; + float sinr_2l[SRSLTE_MAX_CODEBOOKS]; + float cn; uint32_t pmi[2]; - uint32_t nof_symbols = (uint32_t) SRSLTE_SF_LEN_RE(6, SRSLTE_CP_NORM); - int ret = SRSLTE_ERROR; + uint32_t nof_symbols = (uint32_t)SRSLTE_SF_LEN_RE(6, SRSLTE_CP_NORM); + int ret = SRSLTE_ERROR; /* Allocate channels */ for (int i = 0; i < SRSLTE_MAX_PORTS; i++) { @@ -57,7 +57,7 @@ int main(int argc, char **argv) { } for (int c = 0; c < PMI_SELECT_TEST_NOF_CASES; c++) { - pmi_select_test_case_gold_t *gold = &pmi_select_test_case_gold[c]; + pmi_select_test_case_gold_t* gold = &pmi_select_test_case_gold[c]; /* Set channel */ for (int i = 0; i < 2; i++) { @@ -84,7 +84,10 @@ int main(int argc, char **argv) { for (int i = 0; i < ret; i++) { if (fabsf(gold->snri_1l[i] - sinr_1l[i]) > 0.1) { ERROR("Test case %d failed computing 1 layer SINR for codebook %d (test=%.2f; gold=%.2f)\n", - c + 1, i, sinr_1l[i], gold->snri_1l[i]); + c + 1, + i, + sinr_1l[i], + gold->snri_1l[i]); goto clean; } } @@ -106,7 +109,10 @@ int main(int argc, char **argv) { for (int i = 0; i < ret; i++) { if (fabsf(gold->snri_2l[i] - sinr_2l[i]) > 0.1) { ERROR("Test case %d failed computing 2 layer SINR for codebook %d (test=%.2f; gold=%.2f)\n", - c + 1, i, sinr_2l[i], gold->snri_2l[i]); + c + 1, + i, + sinr_2l[i], + gold->snri_2l[i]); goto clean; } } @@ -125,8 +131,7 @@ int main(int argc, char **argv) { /* Check condition number */ if (fabsf(gold->k - cn) > 0.1) { - ERROR("Test case %d failed computing condition number (test=%.2f; gold=%.2f)\n", - c + 1, cn, gold->k); + ERROR("Test case %d failed computing condition number (test=%.2f; gold=%.2f)\n", c + 1, cn, gold->k); goto clean; } } @@ -134,7 +139,7 @@ int main(int argc, char **argv) { /* Test passed */ ret = SRSLTE_SUCCESS; - clean: +clean: for (int i = 0; i < SRSLTE_MAX_PORTS; i++) { for (int j = 0; j < SRSLTE_MAX_PORTS; j++) { if (h[i][j]) { diff --git a/lib/src/phy/mimo/test/pmi_select_test.h b/lib/src/phy/mimo/test/pmi_select_test.h index 5a16185f5..24e3eb2d1 100644 --- a/lib/src/phy/mimo/test/pmi_select_test.h +++ b/lib/src/phy/mimo/test/pmi_select_test.h @@ -24,209 +24,197 @@ #define PMI_SELECT_TEST_NOF_CASES 16 +#include + +typedef _Complex float cf_t; + typedef struct { - cf_t h[2][2]; /* Channel estimate */ - float n; /* Noise estimation */ - float snri_1l[4]; /* SINR Approximation for 1 layer (linear) */ - float snri_2l[2]; /* SINR Approximation for 2 layers (linear) */ - uint32_t pmi[2]; /* Precoding Matrix Indicator for 1 and 2 layers */ - uint32_t ri; /* Rank indicator */ - float k; /* Condition number (κ) in dB */ + cf_t h[2][2]; /* Channel estimate */ + float n; /* Noise estimation */ + float snri_1l[4]; /* SINR Approximation for 1 layer (linear) */ + float snri_2l[2]; /* SINR Approximation for 2 layers (linear) */ + uint32_t pmi[2]; /* Precoding Matrix Indicator for 1 and 2 layers */ + uint32_t ri; /* Rank indicator */ + float k; /* Condition number (κ) in dB */ } pmi_select_test_case_gold_t; -static pmi_select_test_case_gold_t pmi_select_test_case_gold [PMI_SELECT_TEST_NOF_CASES] = { - { /* Test case 1 */ - .h = { - {+0.626226f+0.060103f*_Complex_I, -0.233387f-0.449860f*_Complex_I}, - {+0.234558f-0.502742f*_Complex_I, +0.150990f-0.096722f*_Complex_I} - }, - .n = 0.227713, - .snri_1l = {2.728043f, 1.630673f, 3.226421f, 1.132295f}, - .snri_2l = {1.797660f, 1.982149f}, - .pmi = {2, 1}, - .ri = 1, - .k = 6.4007, - }, - { /* Test case 2 */ - .h = { - {+0.608899f-0.825846f*_Complex_I, +0.972208f+0.604183f*_Complex_I}, - {-0.940016f+0.978290f*_Complex_I, +0.071328f-0.866107f*_Complex_I} - }, - .n = 0.939398, - .snri_1l = {0.686850f, 4.591972f, 3.773925f, 1.504897f}, - .snri_2l = {2.298235f, 1.761859f}, - .pmi = {1, 0}, - .ri = 1, - .k = 11.1305, - }, - { /* Test case 3 */ - .h = { - {-0.963645f+0.770719f*_Complex_I, +0.367677f+0.798010f*_Complex_I}, - {+0.567473f+0.251875f*_Complex_I, +0.068275f-0.724262f*_Complex_I} - }, - .n = 0.217802, - .snri_1l = {3.209674f, 11.525338f, 11.962786f, 2.772226f}, - .snri_2l = {3.226053f, 3.526363f}, - .pmi = {2, 1}, - .ri = 1, - .k = 15.4589, - }, - { /* Test case 4 */ - .h = { - {-0.635718f+0.879322f*_Complex_I, -0.916360f-0.291089f*_Complex_I}, - {-0.786117f-0.178742f*_Complex_I, +0.232887f+0.968699f*_Complex_I} - }, - .n = 0.945579, - .snri_1l = {1.818313f, 2.141519f, 1.995787f, 1.964045f}, - .snri_2l = {1.965011f, 1.958537f}, - .pmi = {1, 0}, - .ri = 2, - .k = 1.2910, - }, - { /* Test case 5 */ - .h = { - {+0.353289f+0.324764f*_Complex_I, +0.976605f-0.511669f*_Complex_I}, - {+0.533663f-0.408985f*_Complex_I, -0.326601f+0.360357f*_Complex_I} - }, - .n = 0.527847, - .snri_1l = {1.173803f, 2.869865f, 2.273783f, 1.769885f}, - .snri_2l = {1.871430f, 1.713879f}, - .pmi = {1, 0}, - .ri = 2, - .k = 5.5388, - }, - { /* Test case 6 */ - .h = { - {-0.176813f+0.103585f*_Complex_I, +0.205276f+0.167141f*_Complex_I}, - {+0.501040f+0.023640f*_Complex_I, +0.167066f-0.834815f*_Complex_I} - }, - .n = 0.719570, - .snri_1l = {0.490387f, 1.022313f, 1.111245f, 0.401456f}, - .snri_2l = {0.578124f, 0.597176f}, - .pmi = {2, 1}, - .ri = 1, - .k = 21.8808, - }, - { /* Test case 7 */ - .h = { - {+0.992312f+0.773088f*_Complex_I, -0.290931f-0.090610f*_Complex_I}, - {+0.942518f-0.173145f*_Complex_I, -0.307102f-0.564536f*_Complex_I} - }, - .n = 0.125655, - .snri_1l = {19.459529f, 4.467420f, 18.044021f, 5.882928f}, - .snri_2l = {8.055238f, 6.832247f}, - .pmi = {0, 0}, - .ri = 1, - .k = 9.9136, - }, - { /* Test case 8 */ - .h = { - {-0.382171f-0.980395f*_Complex_I, +0.452209f+0.686427f*_Complex_I}, - {+0.565744f+0.844664f*_Complex_I, +0.387575f+0.541908f*_Complex_I} - }, - .n = 0.042660, - .snri_1l = {26.560881f, 49.864772f, 33.269985f, 43.155668f}, - .snri_2l = {37.201526f, 34.461078f}, - .pmi = {1, 0}, - .ri = 2, - .k = 3.1172, - }, - { /* Test case 9 */ - .h = { - {-0.243628f-0.461891f*_Complex_I, +0.408679f+0.346062f*_Complex_I}, - {+0.459026f-0.045016f*_Complex_I, -0.551446f+0.247433f*_Complex_I} - }, - .n = 0.236445, - .snri_1l = {1.429443f, 3.381496f, 0.227617f, 4.583322f}, - .snri_2l = {1.272903f, 2.118832f}, - .pmi = {3, 1}, - .ri = 1, - .k = 24.1136, - }, - { /* Test case 10 */ - .h = { - {-0.645752f-0.784222f*_Complex_I, +0.659287f-0.635545f*_Complex_I}, - {+0.533843f-0.801809f*_Complex_I, +0.868957f-0.020472f*_Complex_I} - }, - .n = 0.193245, - .snri_1l = {13.697372f, 4.693597f, 1.561737f, 16.829232f}, - .snri_2l = {2.961344f, 5.773049f}, - .pmi = {3, 1}, - .ri = 1, - .k = 17.5194, - }, - { /* Test case 11 */ - .h = { - {+0.791783f+0.544990f*_Complex_I, -0.801821f-0.376120f*_Complex_I}, - {-0.911669f-0.642035f*_Complex_I, +0.114590f-0.322089f*_Complex_I} - }, - .n = 0.210146, - .snri_1l = {2.340213f, 12.261749f, 5.921675f, 8.680286f}, - .snri_2l = {6.912040f, 4.520201f}, - .pmi = {1, 0}, - .ri = 2, - .k = 7.7819, - }, - { /* Test case 12 */ - .h = { - {+0.020305f-0.218290f*_Complex_I, +0.812729f-0.890767f*_Complex_I}, - {+0.257848f+0.002566f*_Complex_I, -0.796932f-0.136558f*_Complex_I} - }, - .n = 0.997560, - .snri_1l = {0.591218f, 1.636514f, 1.880263f, 0.347469f}, - .snri_2l = {0.869026f, 0.967991f}, - .pmi = {2, 1}, - .ri = 1, - .k = 12.9774, - }, - { /* Test case 13 */ - .h = { - {+0.623205f-0.219990f*_Complex_I, -0.028697f+0.854712f*_Complex_I}, - {+0.788896f+0.834988f*_Complex_I, -0.724907f+0.427148f*_Complex_I} - }, - .n = 0.618337, - .snri_1l = {3.706176f, 1.461946f, 0.479632f, 4.688490f}, - .snri_2l = {1.444336f, 2.102567f}, - .pmi = {3, 1}, - .ri = 1, - .k = 17.0493, - }, - { /* Test case 14 */ - .h = { - {-0.313424f+0.292955f*_Complex_I, +0.872055f+0.666304f*_Complex_I}, - {-0.750452f-0.203436f*_Complex_I, +0.461171f+0.499644f*_Complex_I} - }, - .n = 0.835221, - .snri_1l = {2.560265f, 0.379539f, 0.976562f, 1.963242f}, - .snri_2l = {1.380223f, 1.109300f}, - .pmi = {0, 0}, - .ri = 1, - .k = 10.1729, - }, - { /* Test case 15 */ - .h = { - {-0.355079f-0.339153f*_Complex_I, +0.104523f+0.238943f*_Complex_I}, - {+0.958258f-0.278727f*_Complex_I, +0.098617f+0.513019f*_Complex_I} - }, - .n = 0.413901, - .snri_1l = {1.633620f, 2.178855f, 0.809297f, 3.003178f}, - .snri_2l = {1.250898f, 1.512017f}, - .pmi = {3, 1}, - .ri = 1, - .k = 10.8925, - }, - { /* Test case 16 */ - .h = { - {-0.015310f+0.675606f*_Complex_I, +0.389486f+0.478144f*_Complex_I}, - {+0.945468f+0.908349f*_Complex_I, -0.344490f-0.936155f*_Complex_I} - }, - .n = 0.356869, - .snri_1l = {5.024121f, 4.926495f, 7.364348f, 2.586268f}, - .snri_2l = {3.165416f, 3.851590f}, - .pmi = {2, 1}, - .ri = 2, - .k = 7.7799, - }, +static pmi_select_test_case_gold_t pmi_select_test_case_gold[PMI_SELECT_TEST_NOF_CASES] = { + { + /* Test case 1 */ + .h = {{+0.626226f + 0.060103f * _Complex_I, -0.233387f - 0.449860f * _Complex_I}, + {+0.234558f - 0.502742f * _Complex_I, +0.150990f - 0.096722f * _Complex_I}}, + .n = 0.227713, + .snri_1l = {2.728043f, 1.630673f, 3.226421f, 1.132295f}, + .snri_2l = {1.797660f, 1.982149f}, + .pmi = {2, 1}, + .ri = 1, + .k = 6.4007, + }, + { + /* Test case 2 */ + .h = {{+0.608899f - 0.825846f * _Complex_I, +0.972208f + 0.604183f * _Complex_I}, + {-0.940016f + 0.978290f * _Complex_I, +0.071328f - 0.866107f * _Complex_I}}, + .n = 0.939398, + .snri_1l = {0.686850f, 4.591972f, 3.773925f, 1.504897f}, + .snri_2l = {2.298235f, 1.761859f}, + .pmi = {1, 0}, + .ri = 1, + .k = 11.1305, + }, + { + /* Test case 3 */ + .h = {{-0.963645f + 0.770719f * _Complex_I, +0.367677f + 0.798010f * _Complex_I}, + {+0.567473f + 0.251875f * _Complex_I, +0.068275f - 0.724262f * _Complex_I}}, + .n = 0.217802, + .snri_1l = {3.209674f, 11.525338f, 11.962786f, 2.772226f}, + .snri_2l = {3.226053f, 3.526363f}, + .pmi = {2, 1}, + .ri = 1, + .k = 15.4589, + }, + { + /* Test case 4 */ + .h = {{-0.635718f + 0.879322f * _Complex_I, -0.916360f - 0.291089f * _Complex_I}, + {-0.786117f - 0.178742f * _Complex_I, +0.232887f + 0.968699f * _Complex_I}}, + .n = 0.945579, + .snri_1l = {1.818313f, 2.141519f, 1.995787f, 1.964045f}, + .snri_2l = {1.965011f, 1.958537f}, + .pmi = {1, 0}, + .ri = 2, + .k = 1.2910, + }, + { + /* Test case 5 */ + .h = {{+0.353289f + 0.324764f * _Complex_I, +0.976605f - 0.511669f * _Complex_I}, + {+0.533663f - 0.408985f * _Complex_I, -0.326601f + 0.360357f * _Complex_I}}, + .n = 0.527847, + .snri_1l = {1.173803f, 2.869865f, 2.273783f, 1.769885f}, + .snri_2l = {1.871430f, 1.713879f}, + .pmi = {1, 0}, + .ri = 2, + .k = 5.5388, + }, + { + /* Test case 6 */ + .h = {{-0.176813f + 0.103585f * _Complex_I, +0.205276f + 0.167141f * _Complex_I}, + {+0.501040f + 0.023640f * _Complex_I, +0.167066f - 0.834815f * _Complex_I}}, + .n = 0.719570, + .snri_1l = {0.490387f, 1.022313f, 1.111245f, 0.401456f}, + .snri_2l = {0.578124f, 0.597176f}, + .pmi = {2, 1}, + .ri = 1, + .k = 21.8808, + }, + { + /* Test case 7 */ + .h = {{+0.992312f + 0.773088f * _Complex_I, -0.290931f - 0.090610f * _Complex_I}, + {+0.942518f - 0.173145f * _Complex_I, -0.307102f - 0.564536f * _Complex_I}}, + .n = 0.125655, + .snri_1l = {19.459529f, 4.467420f, 18.044021f, 5.882928f}, + .snri_2l = {8.055238f, 6.832247f}, + .pmi = {0, 0}, + .ri = 1, + .k = 9.9136, + }, + { + /* Test case 8 */ + .h = {{-0.382171f - 0.980395f * _Complex_I, +0.452209f + 0.686427f * _Complex_I}, + {+0.565744f + 0.844664f * _Complex_I, +0.387575f + 0.541908f * _Complex_I}}, + .n = 0.042660, + .snri_1l = {26.560881f, 49.864772f, 33.269985f, 43.155668f}, + .snri_2l = {37.201526f, 34.461078f}, + .pmi = {1, 0}, + .ri = 2, + .k = 3.1172, + }, + { + /* Test case 9 */ + .h = {{-0.243628f - 0.461891f * _Complex_I, +0.408679f + 0.346062f * _Complex_I}, + {+0.459026f - 0.045016f * _Complex_I, -0.551446f + 0.247433f * _Complex_I}}, + .n = 0.236445, + .snri_1l = {1.429443f, 3.381496f, 0.227617f, 4.583322f}, + .snri_2l = {1.272903f, 2.118832f}, + .pmi = {3, 1}, + .ri = 1, + .k = 24.1136, + }, + { + /* Test case 10 */ + .h = {{-0.645752f - 0.784222f * _Complex_I, +0.659287f - 0.635545f * _Complex_I}, + {+0.533843f - 0.801809f * _Complex_I, +0.868957f - 0.020472f * _Complex_I}}, + .n = 0.193245, + .snri_1l = {13.697372f, 4.693597f, 1.561737f, 16.829232f}, + .snri_2l = {2.961344f, 5.773049f}, + .pmi = {3, 1}, + .ri = 1, + .k = 17.5194, + }, + { + /* Test case 11 */ + .h = {{+0.791783f + 0.544990f * _Complex_I, -0.801821f - 0.376120f * _Complex_I}, + {-0.911669f - 0.642035f * _Complex_I, +0.114590f - 0.322089f * _Complex_I}}, + .n = 0.210146, + .snri_1l = {2.340213f, 12.261749f, 5.921675f, 8.680286f}, + .snri_2l = {6.912040f, 4.520201f}, + .pmi = {1, 0}, + .ri = 2, + .k = 7.7819, + }, + { + /* Test case 12 */ + .h = {{+0.020305f - 0.218290f * _Complex_I, +0.812729f - 0.890767f * _Complex_I}, + {+0.257848f + 0.002566f * _Complex_I, -0.796932f - 0.136558f * _Complex_I}}, + .n = 0.997560, + .snri_1l = {0.591218f, 1.636514f, 1.880263f, 0.347469f}, + .snri_2l = {0.869026f, 0.967991f}, + .pmi = {2, 1}, + .ri = 1, + .k = 12.9774, + }, + { + /* Test case 13 */ + .h = {{+0.623205f - 0.219990f * _Complex_I, -0.028697f + 0.854712f * _Complex_I}, + {+0.788896f + 0.834988f * _Complex_I, -0.724907f + 0.427148f * _Complex_I}}, + .n = 0.618337, + .snri_1l = {3.706176f, 1.461946f, 0.479632f, 4.688490f}, + .snri_2l = {1.444336f, 2.102567f}, + .pmi = {3, 1}, + .ri = 1, + .k = 17.0493, + }, + { + /* Test case 14 */ + .h = {{-0.313424f + 0.292955f * _Complex_I, +0.872055f + 0.666304f * _Complex_I}, + {-0.750452f - 0.203436f * _Complex_I, +0.461171f + 0.499644f * _Complex_I}}, + .n = 0.835221, + .snri_1l = {2.560265f, 0.379539f, 0.976562f, 1.963242f}, + .snri_2l = {1.380223f, 1.109300f}, + .pmi = {0, 0}, + .ri = 1, + .k = 10.1729, + }, + { + /* Test case 15 */ + .h = {{-0.355079f - 0.339153f * _Complex_I, +0.104523f + 0.238943f * _Complex_I}, + {+0.958258f - 0.278727f * _Complex_I, +0.098617f + 0.513019f * _Complex_I}}, + .n = 0.413901, + .snri_1l = {1.633620f, 2.178855f, 0.809297f, 3.003178f}, + .snri_2l = {1.250898f, 1.512017f}, + .pmi = {3, 1}, + .ri = 1, + .k = 10.8925, + }, + { + /* Test case 16 */ + .h = {{-0.015310f + 0.675606f * _Complex_I, +0.389486f + 0.478144f * _Complex_I}, + {+0.945468f + 0.908349f * _Complex_I, -0.344490f - 0.936155f * _Complex_I}}, + .n = 0.356869, + .snri_1l = {5.024121f, 4.926495f, 7.364348f, 2.586268f}, + .snri_2l = {3.165416f, 3.851590f}, + .pmi = {2, 1}, + .ri = 2, + .k = 7.7799, + }, }; #endif /* PMI_SELECT_TEST_H */ diff --git a/lib/src/phy/mimo/test/precoder_test.c b/lib/src/phy/mimo/test/precoder_test.c index cf670b3df..8e69a0d63 100644 --- a/lib/src/phy/mimo/test/precoder_test.c +++ b/lib/src/phy/mimo/test/precoder_test.c @@ -29,21 +29,22 @@ #include #include -#include "srslte/srslte.h" #include "srslte/phy/channel/ch_awgn.h" +#include "srslte/srslte.h" -#define MSE_THRESHOLD 0.0005 +#define MSE_THRESHOLD 0.0005 -int nof_symbols = 1000; -uint32_t codebook_idx = 0; -int nof_layers = 1, nof_tx_ports = 1, nof_rx_ports = 1, nof_re = 1; -char *mimo_type_name = NULL; -char decoder_type_name [17] = "zf"; -float snr_db = 100.0f; -float scaling = 0.1f; -static srslte_random_t random_gen = NULL; +int nof_symbols = 1000; +uint32_t codebook_idx = 0; +int nof_layers = 1, nof_tx_ports = 1, nof_rx_ports = 1, nof_re = 1; +char* mimo_type_name = NULL; +char decoder_type_name[17] = "zf"; +float snr_db = 100.0f; +float scaling = 0.1f; +static srslte_random_t random_gen = NULL; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s -m [%s|%s|%s|%s] -l [nof_layers] -p [nof_tx_ports]\n" " -r [nof_rx_ports] -g [scaling]\n", prog, @@ -60,41 +61,42 @@ void usage(char *prog) { printf("* Performance test example:\n\t for snr in {0..20..1}; do ./precoding_test -m single -s $snr; done; \n\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "mplnrcdsg")) != -1) { switch (opt) { - case 'n': - nof_symbols = (int)strtol(argv[optind], NULL, 10); - break; - case 'p': - nof_tx_ports = (int)strtol(argv[optind], NULL, 10); - break; - case 'r': - nof_rx_ports = (int)strtol(argv[optind], NULL, 10); - break; - case 'l': - nof_layers = (int)strtol(argv[optind], NULL, 10); - break; - case 'm': - mimo_type_name = argv[optind]; - break; - case 'c': - codebook_idx = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'd': - strncpy(decoder_type_name, argv[optind], 15); - decoder_type_name[15] = 0; - break; - case 's': - snr_db = strtof(argv[optind], NULL); - break; - case 'g': - scaling = strtof(argv[optind], NULL); - break; - default: - usage(argv[0]); - exit(-1); + case 'n': + nof_symbols = (int)strtol(argv[optind], NULL, 10); + break; + case 'p': + nof_tx_ports = (int)strtol(argv[optind], NULL, 10); + break; + case 'r': + nof_rx_ports = (int)strtol(argv[optind], NULL, 10); + break; + case 'l': + nof_layers = (int)strtol(argv[optind], NULL, 10); + break; + case 'm': + mimo_type_name = argv[optind]; + break; + case 'c': + codebook_idx = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'd': + strncpy(decoder_type_name, argv[optind], 15); + decoder_type_name[15] = 0; + break; + case 's': + snr_db = strtof(argv[optind], NULL); + break; + case 'g': + scaling = strtof(argv[optind], NULL); + break; + default: + usage(argv[0]); + exit(-1); } } if (!mimo_type_name) { @@ -103,7 +105,8 @@ void parse_args(int argc, char **argv) { } } -void populate_channel_cdd(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t n) { +void populate_channel_cdd(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t n) +{ int i, j, k; for (i = 0; i < nof_tx_ports; i++) { @@ -115,7 +118,8 @@ void populate_channel_cdd(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t } } -void populate_channel_diversity(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t n) { +void populate_channel_diversity(cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t n) +{ int i, j, k, l; for (i = 0; i < nof_tx_ports; i++) { @@ -131,7 +135,8 @@ void populate_channel_diversity(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uin } } -void populate_channel_single(cf_t *h) { +void populate_channel_single(cf_t* h) +{ int i; for (i = 0; i < nof_re; i++) { @@ -147,7 +152,7 @@ void populate_channel(srslte_tx_scheme_t type, cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_ populate_channel_cdd(h, (uint32_t)nof_re); break; case SRSLTE_TXSCHEME_DIVERSITY: - populate_channel_diversity(h, (uint32_t) nof_re); + populate_channel_diversity(h, (uint32_t)nof_re); break; case SRSLTE_TXSCHEME_PORT0: default: @@ -155,8 +160,9 @@ void populate_channel(srslte_tx_scheme_t type, cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_ } } -static void awgn(cf_t *y[SRSLTE_MAX_PORTS], uint32_t n, float snr) { - int i; +static void awgn(cf_t* y[SRSLTE_MAX_PORTS], uint32_t n, float snr) +{ + int i; float std_dev = srslte_convert_dB_to_amplitude(-(snr + 3.0f)) * scaling; for (i = 0; i < nof_rx_ports; i++) { @@ -166,7 +172,7 @@ static void awgn(cf_t *y[SRSLTE_MAX_PORTS], uint32_t n, float snr) { int main(int argc, char** argv) { - int i, j, k, nof_errors = 0, ret = SRSLTE_SUCCESS; + int i, j, k, nof_errors = 0, ret = SRSLTE_SUCCESS; float mse; cf_t *x[SRSLTE_MAX_LAYERS], *r[SRSLTE_MAX_PORTS], *y[SRSLTE_MAX_PORTS], *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], *xr[SRSLTE_MAX_LAYERS]; @@ -195,14 +201,14 @@ int main(int argc, char** argv) nof_re = nof_symbols; break; case SRSLTE_TXSCHEME_CDD: - nof_re = nof_symbols*nof_tx_ports/nof_layers; + nof_re = nof_symbols * nof_tx_ports / nof_layers; if (nof_rx_ports != 2 || nof_tx_ports != 2) { ERROR("CDD nof_tx_ports=%d nof_rx_ports=%d is not currently supported\n", nof_tx_ports, nof_rx_ports); exit(-1); } break; default: - nof_re = nof_symbols*nof_layers; + nof_re = nof_symbols * nof_layers; } /* Allocate x and xr (received symbols) in memory for each layer */ @@ -273,14 +279,14 @@ int main(int argc, char** argv) (we are in the frequency domain so it's a multiplication) */ for (i = 0; i < nof_rx_ports; i++) { for (k = 0; k < nof_re; k++) { - r[i][k] = (cf_t) (0.0 + 0.0 * _Complex_I); + r[i][k] = (cf_t)(0.0 + 0.0 * _Complex_I); for (j = 0; j < nof_tx_ports; j++) { r[i][k] += y[j][k] * h[j][i][k]; } } } - awgn(r, (uint32_t) nof_re, snr_db); + awgn(r, (uint32_t)nof_re, snr_db); /* If CDD or Spatial muliplex choose decoder */ if (strncmp(decoder_type_name, "zf", 16) == 0) { @@ -292,7 +298,6 @@ int main(int argc, char** argv) goto quit; } - /* predecoding / equalization */ struct timeval t[3]; gettimeofday(&t[1], NULL); @@ -318,26 +323,29 @@ int main(int argc, char** argv) mse += cabsf(xr[i][j] - x[i][j]); if ((crealf(xr[i][j]) > 0) != (crealf(x[i][j]) > 0)) { - nof_errors ++; + nof_errors++; } if ((cimagf(xr[i][j]) > 0) != (cimagf(x[i][j]) > 0)) { - nof_errors ++; + nof_errors++; } } } - printf("SNR: %5.1fdB;\tExecution time: %5ldus;\tMSE: %.6f;\tBER: %.6f\n", snr_db, t[0].tv_usec, - mse / nof_layers / nof_symbols, (float) nof_errors / (4.0f * nof_re)); + printf("SNR: %5.1fdB;\tExecution time: %5ldus;\tMSE: %.6f;\tBER: %.6f\n", + snr_db, + t[0].tv_usec, + mse / nof_layers / nof_symbols, + (float)nof_errors / (4.0f * nof_re)); if (mse / nof_layers / nof_symbols > MSE_THRESHOLD) { ret = SRSLTE_ERROR; - } + } - quit: - srslte_random_free(random_gen); +quit: + srslte_random_free(random_gen); - /* Free all data */ - for (i = 0; i < nof_layers; i++) { - free(x[i]); - free(xr[i]); + /* Free all data */ + for (i = 0; i < nof_layers; i++) { + free(x[i]); + free(xr[i]); } for (i = 0; i < nof_rx_ports; i++) { diff --git a/lib/src/phy/modem/demod_hard.c b/lib/src/phy/modem/demod_hard.c index 6968d2944..997c35c0b 100644 --- a/lib/src/phy/modem/demod_hard.c +++ b/lib/src/phy/modem/demod_hard.c @@ -22,44 +22,44 @@ #include #include -#include "srslte/phy/modem/demod_hard.h" #include "hard_demod_lte.h" +#include "srslte/phy/modem/demod_hard.h" - -void srslte_demod_hard_init(srslte_demod_hard_t* q) { - bzero((void*) q, sizeof(srslte_demod_hard_t)); +void srslte_demod_hard_init(srslte_demod_hard_t* q) +{ + bzero((void*)q, sizeof(srslte_demod_hard_t)); } -void srslte_demod_hard_table_set(srslte_demod_hard_t* q, srslte_mod_t mod) { +void srslte_demod_hard_table_set(srslte_demod_hard_t* q, srslte_mod_t mod) +{ q->mod = mod; } -int srslte_demod_hard_demodulate(srslte_demod_hard_t* q, cf_t* symbols, uint8_t *bits, uint32_t nsymbols) { +int srslte_demod_hard_demodulate(srslte_demod_hard_t* q, cf_t* symbols, uint8_t* bits, uint32_t nsymbols) +{ - int nbits=-1; - switch(q->mod) { - case SRSLTE_MOD_BPSK: - hard_bpsk_demod(symbols,bits,nsymbols); - nbits=nsymbols; - break; - case SRSLTE_MOD_QPSK: - hard_qpsk_demod(symbols,bits,nsymbols); - nbits=nsymbols*2; - break; - case SRSLTE_MOD_16QAM: - hard_qam16_demod(symbols,bits,nsymbols); - nbits=nsymbols*4; - break; - case SRSLTE_MOD_64QAM: - hard_qam64_demod(symbols,bits,nsymbols); - nbits=nsymbols*6; - break; - case SRSLTE_MOD_256QAM: - hard_qam256_demod(symbols, bits, nsymbols); - nbits = nsymbols * 8; - break; + int nbits = -1; + switch (q->mod) { + case SRSLTE_MOD_BPSK: + hard_bpsk_demod(symbols, bits, nsymbols); + nbits = nsymbols; + break; + case SRSLTE_MOD_QPSK: + hard_qpsk_demod(symbols, bits, nsymbols); + nbits = nsymbols * 2; + break; + case SRSLTE_MOD_16QAM: + hard_qam16_demod(symbols, bits, nsymbols); + nbits = nsymbols * 4; + break; + case SRSLTE_MOD_64QAM: + hard_qam64_demod(symbols, bits, nsymbols); + nbits = nsymbols * 6; + break; + case SRSLTE_MOD_256QAM: + hard_qam256_demod(symbols, bits, nsymbols); + nbits = nsymbols * 8; + break; } return nbits; } - - diff --git a/lib/src/phy/modem/demod_soft.c b/lib/src/phy/modem/demod_soft.c index 8f0443fd6..0ef5ac914 100644 --- a/lib/src/phy/modem/demod_soft.c +++ b/lib/src/phy/modem/demod_soft.c @@ -19,9 +19,9 @@ * */ +#include #include #include -#include #include "srslte/phy/modem/demod_soft.h" #include "srslte/phy/utils/bit.h" @@ -30,46 +30,61 @@ #ifdef HAVE_NEONv8 #include -inline static uint8x16_t v_load_s8(int i15, int i14, int i13, int i12, int i11, - int i10, int i9, int i8, int i7, int i6, - int i5, int i4, int i3, int i2, int i1, - int i0) { - uint8_t __attribute__((aligned(16))) data[16] = { - i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15}; +inline static uint8x16_t v_load_s8(int i15, + int i14, + int i13, + int i12, + int i11, + int i10, + int i9, + int i8, + int i7, + int i6, + int i5, + int i4, + int i3, + int i2, + int i1, + int i0) +{ + uint8_t __attribute__((aligned(16))) + data[16] = {i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15}; return vld1q_u8(data); } #define int8x16_to_8x8x2(v) ((int8x8x2_t){{vget_low_s8(v), vget_high_s8(v)}}) -inline static void vshuff_s32_even(int32x4_t a, int imm, int32x4_t *res) { +inline static void vshuff_s32_even(int32x4_t a, int imm, int32x4_t* res) +{ *res = vsetq_lane_s32(vgetq_lane_s32((a), ((imm) >> 2) & 0x3), *res, 1); *res = vsetq_lane_s32(vgetq_lane_s32((a), ((imm) >> 6) & 0x3), *res, 3); } -inline static void vshuff_s32_odd(int32x4_t a, int imm, int32x4_t *res) { +inline static void vshuff_s32_odd(int32x4_t a, int imm, int32x4_t* res) +{ *res = vsetq_lane_s32(vgetq_lane_s32((a), (imm)&0x3), *res, 0); *res = vsetq_lane_s32(vgetq_lane_s32((a), ((imm) >> 4) & 0x3), *res, 2); } -inline static void vshuff_s32_idx(int32x4_t a, int imm, int32x4_t *res, - int idx) { - *res = - vsetq_lane_s32(vgetq_lane_s32((a), ((imm) >> idx * 2) & 0x3), *res, idx); +inline static void vshuff_s32_idx(int32x4_t a, int imm, int32x4_t* res, int idx) +{ + *res = vsetq_lane_s32(vgetq_lane_s32((a), ((imm) >> idx * 2) & 0x3), *res, idx); } -inline static void vshuff_s16_idx(int16x8_t a, int imm, int16x8_t *res, - int idx) { - *res = vsetq_lane_s16(vgetq_lane_s16((a), ((imm) >> (idx * 4)) & 0xF), *res, - idx); +inline static void vshuff_s16_idx(int16x8_t a, int imm, int16x8_t* res, int idx) +{ + *res = vsetq_lane_s16(vgetq_lane_s16((a), ((imm) >> (idx * 4)) & 0xF), *res, idx); } -inline static void vshuff_s16_even(int16x8_t a, int imm, int16x8_t *res) { +inline static void vshuff_s16_even(int16x8_t a, int imm, int16x8_t* res) +{ *res = vsetq_lane_s16(vgetq_lane_s16((a), ((imm) >> 4) & 0xF), *res, 1); *res = vsetq_lane_s16(vgetq_lane_s16((a), ((imm) >> 12) & 0xF), *res, 3); *res = vsetq_lane_s16(vgetq_lane_s16((a), ((imm) >> 20) & 0xF), *res, 5); *res = vsetq_lane_s16(vgetq_lane_s16((a), ((imm) >> 28) & 0xF), *res, 7); } -inline static void vshuff_s16_odd(int16x8_t a, int imm, int16x8_t *res) { +inline static void vshuff_s16_odd(int16x8_t a, int imm, int16x8_t* res) +{ *res = vsetq_lane_s16(vgetq_lane_s16((a), ((imm)) & 0xF), *res, 0); *res = vsetq_lane_s16(vgetq_lane_s16((a), ((imm) >> 8) & 0xF), *res, 2); *res = vsetq_lane_s16(vgetq_lane_s16((a), ((imm) >> 16) & 0xF), *res, 4); @@ -80,56 +95,63 @@ inline static void vshuff_s16_odd(int16x8_t a, int imm, int16x8_t *res) { #ifdef LV_HAVE_SSE #include -void demod_16qam_lte_s_sse(const cf_t *symbols, short *llr, int nsymbols); +void demod_16qam_lte_s_sse(const cf_t* symbols, short* llr, int nsymbols); #endif -#define SCALE_SHORT_CONV_QPSK 100 +#define SCALE_SHORT_CONV_QPSK 100 #define SCALE_SHORT_CONV_QAM16 400 #define SCALE_SHORT_CONV_QAM64 700 #define SCALE_SHORT_CONV_QAM256 1000 -#define SCALE_BYTE_CONV_QPSK 20 +#define SCALE_BYTE_CONV_QPSK 20 #define SCALE_BYTE_CONV_QAM16 30 #define SCALE_BYTE_CONV_QAM64 40 #define SCALE_BYTE_CONV_QAM256 50 -void demod_bpsk_lte_b(const cf_t *symbols, int8_t *llr, int nsymbols) { - for (int i=0;i #include #include +#include -#include "srslte/phy/modem/demod_hard.h" #include "hard_demod_lte.h" - +#include "srslte/phy/modem/demod_hard.h" /** * @ingroup Hard BPSK demodulator @@ -44,7 +43,7 @@ inline void hard_bpsk_demod(const cf_t* in, uint8_t* out, uint32_t N) { uint32_t s; - for (s=0; s 0) { if ((__imag__ in[s] > 0) || (__real__ in[s] > -__imag__ in[s])) { out[s] = 0x0; @@ -79,16 +78,16 @@ inline void hard_qpsk_demod(const cf_t* in, uint8_t* out, uint32_t N) { uint32_t s; - for (s=0; s 0) { - out[2*s] = 0x0; + out[2 * s] = 0x0; } else { - out[2*s] = 0x1; + out[2 * s] = 0x1; } if (__imag__ in[s] > 0) { - out[2*s+1] = 0x0; + out[2 * s + 1] = 0x0; } else { - out[2*s+1] = 0x1; + out[2 * s + 1] = 0x1; } } } @@ -113,29 +112,29 @@ inline void hard_qam16_demod(const cf_t* in, uint8_t* out, uint32_t N) { uint32_t s; - for (s=0; s 0) { - out[4*s] = 0x0; + out[4 * s] = 0x0; } else { - out[4*s] = 0x1; + out[4 * s] = 0x1; } if ((__real__ in[s] > QAM16_THRESHOLD) || (__real__ in[s] < -QAM16_THRESHOLD)) { - out[4*s+2] = 0x1; + out[4 * s + 2] = 0x1; } else { - out[4*s+2] = 0x0; + out[4 * s + 2] = 0x0; } if (__imag__ in[s] > 0) { - out[4*s+1] = 0x0; + out[4 * s + 1] = 0x0; } else { - out[4*s+1] = 0x1; + out[4 * s + 1] = 0x1; } if ((__imag__ in[s] > QAM16_THRESHOLD) || (__imag__ in[s] < -QAM16_THRESHOLD)) { - out[4*s+3] = 0x1; + out[4 * s + 3] = 0x1; } else { - out[4*s+3] = 0x0; + out[4 * s + 3] = 0x0; } } } @@ -155,45 +154,45 @@ inline void hard_qam64_demod(const cf_t* in, uint8_t* out, uint32_t N) { uint32_t s; - for (s=0; s 0){ - out[6*s] = 0x0; + if (__real__ in[s] > 0) { + out[6 * s] = 0x0; } else { - out[6*s] = 0x1; + out[6 * s] = 0x1; } if ((__real__ in[s] > QAM64_THRESHOLD_3) || (__real__ in[s] < -QAM64_THRESHOLD_3)) { - out[6*s+2] = 0x1; - out[6*s+4] = 0x1; + out[6 * s + 2] = 0x1; + out[6 * s + 4] = 0x1; } else if ((__real__ in[s] > QAM64_THRESHOLD_2) || (__real__ in[s] < -QAM64_THRESHOLD_2)) { - out[6*s+2] = 0x1; - out[6*s+4] = 0x0; + out[6 * s + 2] = 0x1; + out[6 * s + 4] = 0x0; } else if ((__real__ in[s] > QAM64_THRESHOLD_1) || (__real__ in[s] < -QAM64_THRESHOLD_1)) { - out[6*s+2] = 0x0; - out[6*s+4] = 0x0; + out[6 * s + 2] = 0x0; + out[6 * s + 4] = 0x0; } else { - out[6*s+2] = 0x0; - out[6*s+4] = 0x1; + out[6 * s + 2] = 0x0; + out[6 * s + 4] = 0x1; } /* bits associated with/obtained from quadrature component: b1, b3, b5 */ - if (__imag__ in[s] > 0){ - out[6*s+1] = 0x0; + if (__imag__ in[s] > 0) { + out[6 * s + 1] = 0x0; } else { - out[6*s+1] = 0x1; + out[6 * s + 1] = 0x1; } if ((__imag__ in[s] > QAM64_THRESHOLD_3) || (__imag__ in[s] < -QAM64_THRESHOLD_3)) { - out[6*s+3] = 0x1; - out[6*s+5] = 0x1; + out[6 * s + 3] = 0x1; + out[6 * s + 5] = 0x1; } else if ((__imag__ in[s] > QAM64_THRESHOLD_2) || (__imag__ in[s] < -QAM64_THRESHOLD_2)) { - out[6*s+3] = 0x1; - out[6*s+5] = 0x0; + out[6 * s + 3] = 0x1; + out[6 * s + 5] = 0x0; } else if ((__imag__ in[s] > QAM64_THRESHOLD_1) || (__imag__ in[s] < -QAM64_THRESHOLD_1)) { - out[6*s+3] = 0x0; - out[6*s+5] = 0x0; + out[6 * s + 3] = 0x0; + out[6 * s + 5] = 0x0; } else { - out[6*s+3] = 0x0; - out[6*s+5] = 0x1; + out[6 * s + 3] = 0x0; + out[6 * s + 5] = 0x1; } } } diff --git a/lib/src/phy/modem/hard_demod_lte.h b/lib/src/phy/modem/hard_demod_lte.h index e49f1ec30..0fc94656c 100644 --- a/lib/src/phy/modem/hard_demod_lte.h +++ b/lib/src/phy/modem/hard_demod_lte.h @@ -19,6 +19,10 @@ * */ +#include + +typedef _Complex float cf_t; + /* Thresholds for Demodulation */ /* Assume perfect amplitude and phase alignment. * Check threshold values for real case @@ -35,20 +39,12 @@ #define QAM256_THRESHOLD_6 (12 / sqrtf(170)) #define QAM256_THRESHOLD_7 (14 / sqrtf(170)) -void hard_bpsk_demod(const cf_t* in, - uint8_t* out, - uint32_t N); +void hard_bpsk_demod(const cf_t* in, uint8_t* out, uint32_t N); -void hard_qpsk_demod(const cf_t* in, - uint8_t* out, - uint32_t N); +void hard_qpsk_demod(const cf_t* in, uint8_t* out, uint32_t N); -void hard_qam16_demod(const cf_t* in, - uint8_t* out, - uint32_t N); +void hard_qam16_demod(const cf_t* in, uint8_t* out, uint32_t N); -void hard_qam64_demod(const cf_t* in, - uint8_t* out, - uint32_t N); +void hard_qam64_demod(const cf_t* in, uint8_t* out, uint32_t N); void hard_qam256_demod(const cf_t* in, uint8_t* out, uint32_t N); diff --git a/lib/src/phy/modem/lte_tables.c b/lib/src/phy/modem/lte_tables.c index 355e551aa..93ede52fb 100644 --- a/lib/src/phy/modem/lte_tables.c +++ b/lib/src/phy/modem/lte_tables.c @@ -19,13 +19,13 @@ * */ -#include #include -#include #include +#include +#include -#include "srslte/phy/modem/modem_table.h" #include "lte_tables.h" +#include "srslte/phy/modem/modem_table.h" /** * Set the BPSK modulation table */ @@ -36,9 +36,8 @@ void set_BPSKtable(cf_t* table) // | 0 //---------> I // 1 | - table[0] = BPSK_LEVEL + BPSK_LEVEL*_Complex_I; - table[1] = -BPSK_LEVEL -BPSK_LEVEL*_Complex_I; - + table[0] = BPSK_LEVEL + BPSK_LEVEL * _Complex_I; + table[1] = -BPSK_LEVEL - BPSK_LEVEL * _Complex_I; } /** @@ -51,10 +50,10 @@ void set_QPSKtable(cf_t* table) // 10 | 00 //-----------> I // 11 | 01 - table[0] = QPSK_LEVEL + QPSK_LEVEL*_Complex_I; - table[1] = QPSK_LEVEL - QPSK_LEVEL*_Complex_I; - table[2] = -QPSK_LEVEL + QPSK_LEVEL*_Complex_I; - table[3] = -QPSK_LEVEL - QPSK_LEVEL*_Complex_I; + table[0] = QPSK_LEVEL + QPSK_LEVEL * _Complex_I; + table[1] = QPSK_LEVEL - QPSK_LEVEL * _Complex_I; + table[2] = -QPSK_LEVEL + QPSK_LEVEL * _Complex_I; + table[3] = -QPSK_LEVEL - QPSK_LEVEL * _Complex_I; } /** @@ -68,22 +67,22 @@ void set_16QAMtable(cf_t* table) //---------------------------------> I // 1110 1100 | 0100 0110 // 1111 1101 | 0101 0111 - table[0] = QAM16_LEVEL_1 + QAM16_LEVEL_1*_Complex_I; - table[1] = QAM16_LEVEL_1 + QAM16_LEVEL_2*_Complex_I; - table[2] = QAM16_LEVEL_2 + QAM16_LEVEL_1*_Complex_I; - table[3] = QAM16_LEVEL_2 + QAM16_LEVEL_2*_Complex_I; - table[4] = QAM16_LEVEL_1 - QAM16_LEVEL_1*_Complex_I; - table[5] = QAM16_LEVEL_1 - QAM16_LEVEL_2*_Complex_I; - table[6] = QAM16_LEVEL_2 - QAM16_LEVEL_1*_Complex_I; - table[7] = QAM16_LEVEL_2 - QAM16_LEVEL_2*_Complex_I; - table[8] = -QAM16_LEVEL_1 + QAM16_LEVEL_1*_Complex_I; - table[9] = -QAM16_LEVEL_1 + QAM16_LEVEL_2*_Complex_I; - table[10] = -QAM16_LEVEL_2 + QAM16_LEVEL_1*_Complex_I; - table[11] = -QAM16_LEVEL_2 + QAM16_LEVEL_2*_Complex_I; - table[12] = -QAM16_LEVEL_1 - QAM16_LEVEL_1*_Complex_I; - table[13] = -QAM16_LEVEL_1 - QAM16_LEVEL_2*_Complex_I; - table[14] = -QAM16_LEVEL_2 - QAM16_LEVEL_1*_Complex_I; - table[15] = -QAM16_LEVEL_2 - QAM16_LEVEL_2*_Complex_I; + table[0] = QAM16_LEVEL_1 + QAM16_LEVEL_1 * _Complex_I; + table[1] = QAM16_LEVEL_1 + QAM16_LEVEL_2 * _Complex_I; + table[2] = QAM16_LEVEL_2 + QAM16_LEVEL_1 * _Complex_I; + table[3] = QAM16_LEVEL_2 + QAM16_LEVEL_2 * _Complex_I; + table[4] = QAM16_LEVEL_1 - QAM16_LEVEL_1 * _Complex_I; + table[5] = QAM16_LEVEL_1 - QAM16_LEVEL_2 * _Complex_I; + table[6] = QAM16_LEVEL_2 - QAM16_LEVEL_1 * _Complex_I; + table[7] = QAM16_LEVEL_2 - QAM16_LEVEL_2 * _Complex_I; + table[8] = -QAM16_LEVEL_1 + QAM16_LEVEL_1 * _Complex_I; + table[9] = -QAM16_LEVEL_1 + QAM16_LEVEL_2 * _Complex_I; + table[10] = -QAM16_LEVEL_2 + QAM16_LEVEL_1 * _Complex_I; + table[11] = -QAM16_LEVEL_2 + QAM16_LEVEL_2 * _Complex_I; + table[12] = -QAM16_LEVEL_1 - QAM16_LEVEL_1 * _Complex_I; + table[13] = -QAM16_LEVEL_1 - QAM16_LEVEL_2 * _Complex_I; + table[14] = -QAM16_LEVEL_2 - QAM16_LEVEL_1 * _Complex_I; + table[15] = -QAM16_LEVEL_2 - QAM16_LEVEL_2 * _Complex_I; } /** @@ -92,70 +91,70 @@ void set_64QAMtable(cf_t* table) { // LTE-64QAM constellation: // see [3GPP TS 36.211 version 10.5.0 Release 10, Section 7.1.4] - table[0] = QAM64_LEVEL_2 + QAM64_LEVEL_2*_Complex_I; - table[1] = QAM64_LEVEL_2 + QAM64_LEVEL_1*_Complex_I; - table[2] = QAM64_LEVEL_1 + QAM64_LEVEL_2*_Complex_I; - table[3] = QAM64_LEVEL_1 + QAM64_LEVEL_1*_Complex_I; - table[4] = QAM64_LEVEL_2 + QAM64_LEVEL_3*_Complex_I; - table[5] = QAM64_LEVEL_2 + QAM64_LEVEL_4*_Complex_I; - table[6] = QAM64_LEVEL_1 + QAM64_LEVEL_3*_Complex_I; - table[7] = QAM64_LEVEL_1 + QAM64_LEVEL_4*_Complex_I; - table[8] = QAM64_LEVEL_3 + QAM64_LEVEL_2*_Complex_I; - table[9] = QAM64_LEVEL_3 + QAM64_LEVEL_1*_Complex_I; - table[10] = QAM64_LEVEL_4 + QAM64_LEVEL_2*_Complex_I; - table[11] = QAM64_LEVEL_4 + QAM64_LEVEL_1*_Complex_I; - table[12] = QAM64_LEVEL_3 + QAM64_LEVEL_3*_Complex_I; - table[13] = QAM64_LEVEL_3 + QAM64_LEVEL_4*_Complex_I; - table[14] = QAM64_LEVEL_4 + QAM64_LEVEL_3*_Complex_I; - table[15] = QAM64_LEVEL_4 + QAM64_LEVEL_4*_Complex_I; - table[16] = QAM64_LEVEL_2 - QAM64_LEVEL_2*_Complex_I; - table[17] = QAM64_LEVEL_2 - QAM64_LEVEL_1*_Complex_I; - table[18] = QAM64_LEVEL_1 - QAM64_LEVEL_2*_Complex_I; - table[19] = QAM64_LEVEL_1 - QAM64_LEVEL_1*_Complex_I; - table[20] = QAM64_LEVEL_2 - QAM64_LEVEL_3*_Complex_I; - table[21] = QAM64_LEVEL_2 - QAM64_LEVEL_4*_Complex_I; - table[22] = QAM64_LEVEL_1 - QAM64_LEVEL_3*_Complex_I; - table[23] = QAM64_LEVEL_1 - QAM64_LEVEL_4*_Complex_I; - table[24] = QAM64_LEVEL_3 - QAM64_LEVEL_2*_Complex_I; - table[25] = QAM64_LEVEL_3 - QAM64_LEVEL_1*_Complex_I; - table[26] = QAM64_LEVEL_4 - QAM64_LEVEL_2*_Complex_I; - table[27] = QAM64_LEVEL_4 - QAM64_LEVEL_1*_Complex_I; - table[28] = QAM64_LEVEL_3 - QAM64_LEVEL_3*_Complex_I; - table[29] = QAM64_LEVEL_3 - QAM64_LEVEL_4*_Complex_I; - table[30] = QAM64_LEVEL_4 - QAM64_LEVEL_3*_Complex_I; - table[31] = QAM64_LEVEL_4 - QAM64_LEVEL_4*_Complex_I; - table[32] = -QAM64_LEVEL_2 + QAM64_LEVEL_2*_Complex_I; - table[33] = -QAM64_LEVEL_2 + QAM64_LEVEL_1*_Complex_I; - table[34] = -QAM64_LEVEL_1 + QAM64_LEVEL_2*_Complex_I; - table[35] = -QAM64_LEVEL_1 + QAM64_LEVEL_1*_Complex_I; - table[36] = -QAM64_LEVEL_2 + QAM64_LEVEL_3*_Complex_I; - table[37] = -QAM64_LEVEL_2 + QAM64_LEVEL_4*_Complex_I; - table[38] = -QAM64_LEVEL_1 + QAM64_LEVEL_3*_Complex_I; - table[39] = -QAM64_LEVEL_1 + QAM64_LEVEL_4*_Complex_I; - table[40] = -QAM64_LEVEL_3 + QAM64_LEVEL_2*_Complex_I; - table[41] = -QAM64_LEVEL_3 + QAM64_LEVEL_1*_Complex_I; - table[42] = -QAM64_LEVEL_4 + QAM64_LEVEL_2*_Complex_I; - table[43] = -QAM64_LEVEL_4 + QAM64_LEVEL_1*_Complex_I; - table[44] = -QAM64_LEVEL_3 + QAM64_LEVEL_3*_Complex_I; - table[45] = -QAM64_LEVEL_3 + QAM64_LEVEL_4*_Complex_I; - table[46] = -QAM64_LEVEL_4 + QAM64_LEVEL_3*_Complex_I; - table[47] = -QAM64_LEVEL_4 + QAM64_LEVEL_4*_Complex_I; - table[48] = -QAM64_LEVEL_2 - QAM64_LEVEL_2*_Complex_I; - table[49] = -QAM64_LEVEL_2 - QAM64_LEVEL_1*_Complex_I; - table[50] = -QAM64_LEVEL_1 - QAM64_LEVEL_2*_Complex_I; - table[51] = -QAM64_LEVEL_1 - QAM64_LEVEL_1*_Complex_I; - table[52] = -QAM64_LEVEL_2 - QAM64_LEVEL_3*_Complex_I; - table[53] = -QAM64_LEVEL_2 - QAM64_LEVEL_4*_Complex_I; - table[54] = -QAM64_LEVEL_1 - QAM64_LEVEL_3*_Complex_I; - table[55] = -QAM64_LEVEL_1 - QAM64_LEVEL_4*_Complex_I; - table[56] = -QAM64_LEVEL_3 - QAM64_LEVEL_2*_Complex_I; - table[57] = -QAM64_LEVEL_3 - QAM64_LEVEL_1*_Complex_I; - table[58] = -QAM64_LEVEL_4 - QAM64_LEVEL_2*_Complex_I; - table[59] = -QAM64_LEVEL_4 - QAM64_LEVEL_1*_Complex_I; - table[60] = -QAM64_LEVEL_3 - QAM64_LEVEL_3*_Complex_I; - table[61] = -QAM64_LEVEL_3 - QAM64_LEVEL_4*_Complex_I; - table[62] = -QAM64_LEVEL_4 - QAM64_LEVEL_3*_Complex_I; - table[63] = -QAM64_LEVEL_4 - QAM64_LEVEL_4*_Complex_I; + table[0] = QAM64_LEVEL_2 + QAM64_LEVEL_2 * _Complex_I; + table[1] = QAM64_LEVEL_2 + QAM64_LEVEL_1 * _Complex_I; + table[2] = QAM64_LEVEL_1 + QAM64_LEVEL_2 * _Complex_I; + table[3] = QAM64_LEVEL_1 + QAM64_LEVEL_1 * _Complex_I; + table[4] = QAM64_LEVEL_2 + QAM64_LEVEL_3 * _Complex_I; + table[5] = QAM64_LEVEL_2 + QAM64_LEVEL_4 * _Complex_I; + table[6] = QAM64_LEVEL_1 + QAM64_LEVEL_3 * _Complex_I; + table[7] = QAM64_LEVEL_1 + QAM64_LEVEL_4 * _Complex_I; + table[8] = QAM64_LEVEL_3 + QAM64_LEVEL_2 * _Complex_I; + table[9] = QAM64_LEVEL_3 + QAM64_LEVEL_1 * _Complex_I; + table[10] = QAM64_LEVEL_4 + QAM64_LEVEL_2 * _Complex_I; + table[11] = QAM64_LEVEL_4 + QAM64_LEVEL_1 * _Complex_I; + table[12] = QAM64_LEVEL_3 + QAM64_LEVEL_3 * _Complex_I; + table[13] = QAM64_LEVEL_3 + QAM64_LEVEL_4 * _Complex_I; + table[14] = QAM64_LEVEL_4 + QAM64_LEVEL_3 * _Complex_I; + table[15] = QAM64_LEVEL_4 + QAM64_LEVEL_4 * _Complex_I; + table[16] = QAM64_LEVEL_2 - QAM64_LEVEL_2 * _Complex_I; + table[17] = QAM64_LEVEL_2 - QAM64_LEVEL_1 * _Complex_I; + table[18] = QAM64_LEVEL_1 - QAM64_LEVEL_2 * _Complex_I; + table[19] = QAM64_LEVEL_1 - QAM64_LEVEL_1 * _Complex_I; + table[20] = QAM64_LEVEL_2 - QAM64_LEVEL_3 * _Complex_I; + table[21] = QAM64_LEVEL_2 - QAM64_LEVEL_4 * _Complex_I; + table[22] = QAM64_LEVEL_1 - QAM64_LEVEL_3 * _Complex_I; + table[23] = QAM64_LEVEL_1 - QAM64_LEVEL_4 * _Complex_I; + table[24] = QAM64_LEVEL_3 - QAM64_LEVEL_2 * _Complex_I; + table[25] = QAM64_LEVEL_3 - QAM64_LEVEL_1 * _Complex_I; + table[26] = QAM64_LEVEL_4 - QAM64_LEVEL_2 * _Complex_I; + table[27] = QAM64_LEVEL_4 - QAM64_LEVEL_1 * _Complex_I; + table[28] = QAM64_LEVEL_3 - QAM64_LEVEL_3 * _Complex_I; + table[29] = QAM64_LEVEL_3 - QAM64_LEVEL_4 * _Complex_I; + table[30] = QAM64_LEVEL_4 - QAM64_LEVEL_3 * _Complex_I; + table[31] = QAM64_LEVEL_4 - QAM64_LEVEL_4 * _Complex_I; + table[32] = -QAM64_LEVEL_2 + QAM64_LEVEL_2 * _Complex_I; + table[33] = -QAM64_LEVEL_2 + QAM64_LEVEL_1 * _Complex_I; + table[34] = -QAM64_LEVEL_1 + QAM64_LEVEL_2 * _Complex_I; + table[35] = -QAM64_LEVEL_1 + QAM64_LEVEL_1 * _Complex_I; + table[36] = -QAM64_LEVEL_2 + QAM64_LEVEL_3 * _Complex_I; + table[37] = -QAM64_LEVEL_2 + QAM64_LEVEL_4 * _Complex_I; + table[38] = -QAM64_LEVEL_1 + QAM64_LEVEL_3 * _Complex_I; + table[39] = -QAM64_LEVEL_1 + QAM64_LEVEL_4 * _Complex_I; + table[40] = -QAM64_LEVEL_3 + QAM64_LEVEL_2 * _Complex_I; + table[41] = -QAM64_LEVEL_3 + QAM64_LEVEL_1 * _Complex_I; + table[42] = -QAM64_LEVEL_4 + QAM64_LEVEL_2 * _Complex_I; + table[43] = -QAM64_LEVEL_4 + QAM64_LEVEL_1 * _Complex_I; + table[44] = -QAM64_LEVEL_3 + QAM64_LEVEL_3 * _Complex_I; + table[45] = -QAM64_LEVEL_3 + QAM64_LEVEL_4 * _Complex_I; + table[46] = -QAM64_LEVEL_4 + QAM64_LEVEL_3 * _Complex_I; + table[47] = -QAM64_LEVEL_4 + QAM64_LEVEL_4 * _Complex_I; + table[48] = -QAM64_LEVEL_2 - QAM64_LEVEL_2 * _Complex_I; + table[49] = -QAM64_LEVEL_2 - QAM64_LEVEL_1 * _Complex_I; + table[50] = -QAM64_LEVEL_1 - QAM64_LEVEL_2 * _Complex_I; + table[51] = -QAM64_LEVEL_1 - QAM64_LEVEL_1 * _Complex_I; + table[52] = -QAM64_LEVEL_2 - QAM64_LEVEL_3 * _Complex_I; + table[53] = -QAM64_LEVEL_2 - QAM64_LEVEL_4 * _Complex_I; + table[54] = -QAM64_LEVEL_1 - QAM64_LEVEL_3 * _Complex_I; + table[55] = -QAM64_LEVEL_1 - QAM64_LEVEL_4 * _Complex_I; + table[56] = -QAM64_LEVEL_3 - QAM64_LEVEL_2 * _Complex_I; + table[57] = -QAM64_LEVEL_3 - QAM64_LEVEL_1 * _Complex_I; + table[58] = -QAM64_LEVEL_4 - QAM64_LEVEL_2 * _Complex_I; + table[59] = -QAM64_LEVEL_4 - QAM64_LEVEL_1 * _Complex_I; + table[60] = -QAM64_LEVEL_3 - QAM64_LEVEL_3 * _Complex_I; + table[61] = -QAM64_LEVEL_3 - QAM64_LEVEL_4 * _Complex_I; + table[62] = -QAM64_LEVEL_4 - QAM64_LEVEL_3 * _Complex_I; + table[63] = -QAM64_LEVEL_4 - QAM64_LEVEL_4 * _Complex_I; } /** diff --git a/lib/src/phy/modem/lte_tables.h b/lib/src/phy/modem/lte_tables.h index 95d99469c..04a10e925 100644 --- a/lib/src/phy/modem/lte_tables.h +++ b/lib/src/phy/modem/lte_tables.h @@ -19,6 +19,8 @@ * */ +typedef _Complex float cf_t; + #define BPSK_LEVEL M_SQRT1_2 #define QPSK_LEVEL M_SQRT1_2 @@ -31,7 +33,8 @@ #define QAM64_LEVEL_3 (5.0f / sqrtf(42.0f)) #define QAM64_LEVEL_4 (7.0f / sqrtf(42.0f)) -/* HARD DEMODULATION Thresholds, necessary for obtaining the zone of received symbol for optimized LLR approx implementation */ +/* HARD DEMODULATION Thresholds, necessary for obtaining the zone of received symbol for optimized LLR approx + * implementation */ #define QAM16_THRESHOLD (2.0f / sqrtf(10.0f)) #define QAM64_THRESHOLD_1 (2.0f / sqrtf(42.0f)) #define QAM64_THRESHOLD_2 (4.0f / sqrtf(42.0f)) @@ -42,9 +45,6 @@ /* this is not an QAM64 level, but, rather, an auxiliary value that can be used for computing the * symbol from the bit sequence */ - - - void set_BPSKtable(cf_t* table); void set_QPSKtable(cf_t* table); diff --git a/lib/src/phy/modem/mod.c b/lib/src/phy/modem/mod.c index ffd4df12a..c7667198e 100644 --- a/lib/src/phy/modem/mod.c +++ b/lib/src/phy/modem/mod.c @@ -19,10 +19,10 @@ * */ +#include #include #include #include -#include #include "srslte/phy/modem/mod.h" #include "srslte/phy/utils/bit.h" @@ -30,14 +30,15 @@ /** Low-level API */ -int srslte_mod_modulate(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, uint32_t nbits) { - uint32_t i,j,idx; - uint8_t *b_ptr=(uint8_t*) bits; - j=0; - for (i=0;inbits_x_symbol) { - idx = srslte_bit_pack(&b_ptr,q->nbits_x_symbol); +int srslte_mod_modulate(srslte_modem_table_t* q, uint8_t* bits, cf_t* symbols, uint32_t nbits) +{ + uint32_t i, j, idx; + uint8_t* b_ptr = (uint8_t*)bits; + j = 0; + for (i = 0; i < nbits; i += q->nbits_x_symbol) { + idx = srslte_bit_pack(&b_ptr, q->nbits_x_symbol); if (idx < q->nsymbols) { - symbols[j] = q->symbol_table[idx]; + symbols[j] = q->symbol_table[idx]; } else { return SRSLTE_ERROR; } @@ -45,77 +46,81 @@ int srslte_mod_modulate(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, u } return j; } - -void mod_bpsk_bytes(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, uint32_t nbits) { + +void mod_bpsk_bytes(srslte_modem_table_t* q, uint8_t* bits, cf_t* symbols, uint32_t nbits) +{ uint8_t mask_bpsk[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; uint8_t shift_bpsk[8] = {7, 6, 5, 4, 3, 2, 1, 0}; - for (int i=0;isymbol_table_bpsk[bits[i]], sizeof(bpsk_packed_t)); + for (int i = 0; i < nbits / 8; i++) { + memcpy(&symbols[8 * i], &q->symbol_table_bpsk[bits[i]], sizeof(bpsk_packed_t)); + } + for (int i = 0; i < nbits % 8; i++) { + symbols[8 * (nbits / 8) + i] = q->symbol_table[(bits[8 * (nbits / 8) + i] & mask_bpsk[i]) >> shift_bpsk[i]]; } - for (int i=0;isymbol_table[(bits[8*(nbits/8)+i]&mask_bpsk[i])>>shift_bpsk[i]]; - } } -void mod_qpsk_bytes(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, uint32_t nbits) { +void mod_qpsk_bytes(srslte_modem_table_t* q, uint8_t* bits, cf_t* symbols, uint32_t nbits) +{ uint8_t mask_qpsk[4] = {0xc0, 0x30, 0x0c, 0x03}; - uint8_t shift_qpsk[4] = {6, 4, 2, 0}; - for (int i=0;isymbol_table_qpsk[bits[i]], sizeof(qpsk_packed_t)); + uint8_t shift_qpsk[4] = {6, 4, 2, 0}; + for (int i = 0; i < nbits / 8; i++) { + memcpy(&symbols[4 * i], &q->symbol_table_qpsk[bits[i]], sizeof(qpsk_packed_t)); } // Encode last 1, 2 or 3 bit pairs if not multiple of 8 - for (int i=0;i<(nbits%8)/2;i++) { - symbols[4*(nbits/8)+i] = q->symbol_table[(bits[nbits/8]&mask_qpsk[i])>>shift_qpsk[i]]; + for (int i = 0; i < (nbits % 8) / 2; i++) { + symbols[4 * (nbits / 8) + i] = q->symbol_table[(bits[nbits / 8] & mask_qpsk[i]) >> shift_qpsk[i]]; } } -void mod_16qam_bytes(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, uint32_t nbits) { - for (int i=0;isymbol_table_16qam[bits[i]], sizeof(qam16_packed_t)); +void mod_16qam_bytes(srslte_modem_table_t* q, uint8_t* bits, cf_t* symbols, uint32_t nbits) +{ + for (int i = 0; i < nbits / 8; i++) { + memcpy(&symbols[2 * i], &q->symbol_table_16qam[bits[i]], sizeof(qam16_packed_t)); } // Encode last 4 bits if not multiple of 8 - if (nbits%8) { - symbols[2*(nbits/8)] = q->symbol_table[(bits[nbits/8]&0xf0)>>4]; + if (nbits % 8) { + symbols[2 * (nbits / 8)] = q->symbol_table[(bits[nbits / 8] & 0xf0) >> 4]; } } -void mod_64qam_bytes(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, uint32_t nbits) { - uint8_t in0, in1, in2, in3; +void mod_64qam_bytes(srslte_modem_table_t* q, uint8_t* bits, cf_t* symbols, uint32_t nbits) +{ + uint8_t in0, in1, in2, in3; uint32_t in80, in81, in82; - - for (int i=0;i>2; - in1 = (in80&0x03)<<4 | ((in81&0xf0)>>4); - in2 = (in81&0x0f)<<2 | ((in82&0xc0)>>6); - in3 = in82&0x3f; - - symbols[i*4+0] = q->symbol_table[in0]; - symbols[i*4+1] = q->symbol_table[in1]; - symbols[i*4+2] = q->symbol_table[in2]; - symbols[i*4+3] = q->symbol_table[in3]; + + for (int i = 0; i < nbits / 24; i++) { + in80 = bits[3 * i + 0]; + in81 = bits[3 * i + 1]; + in82 = bits[3 * i + 2]; + + in0 = (in80 & 0xfc) >> 2; + in1 = (in80 & 0x03) << 4 | ((in81 & 0xf0) >> 4); + in2 = (in81 & 0x0f) << 2 | ((in82 & 0xc0) >> 6); + in3 = in82 & 0x3f; + + symbols[i * 4 + 0] = q->symbol_table[in0]; + symbols[i * 4 + 1] = q->symbol_table[in1]; + symbols[i * 4 + 2] = q->symbol_table[in2]; + symbols[i * 4 + 3] = q->symbol_table[in3]; } - if (nbits%24 >= 6) { - in80 = bits[3*(nbits/24)+0]; - in0 = (in80&0xfc)>>2; - - symbols[4*(nbits/24)+0] = q->symbol_table[in0]; + if (nbits % 24 >= 6) { + in80 = bits[3 * (nbits / 24) + 0]; + in0 = (in80 & 0xfc) >> 2; + + symbols[4 * (nbits / 24) + 0] = q->symbol_table[in0]; } - if (nbits%24 >= 12) { - in81 = bits[3*(nbits/24)+1]; - in1 = (in80&0x03)<<4 | ((in81&0xf0)>>4); - - symbols[4*(nbits/24)+1] = q->symbol_table[in1]; + if (nbits % 24 >= 12) { + in81 = bits[3 * (nbits / 24) + 1]; + in1 = (in80 & 0x03) << 4 | ((in81 & 0xf0) >> 4); + + symbols[4 * (nbits / 24) + 1] = q->symbol_table[in1]; } - if (nbits%24 >= 18) { - in82 = bits[3*(nbits/24)+2]; - in2 = (in81&0x0f)<<2 | ((in82&0xc0)>>6); + if (nbits % 24 >= 18) { + in82 = bits[3 * (nbits / 24) + 2]; + in2 = (in81 & 0x0f) << 2 | ((in82 & 0xc0) >> 6); - symbols[4*(nbits/24)+2] = q->symbol_table[in2]; + symbols[4 * (nbits / 24) + 2] = q->symbol_table[in2]; } } @@ -127,18 +132,18 @@ void mod_256qam_bytes(srslte_modem_table_t* q, uint8_t* bits, cf_t* symbols, uin } /* Assumes packet bits as input */ -int srslte_mod_modulate_bytes(srslte_modem_table_t* q, uint8_t *bits, cf_t* symbols, uint32_t nbits) +int srslte_mod_modulate_bytes(srslte_modem_table_t* q, uint8_t* bits, cf_t* symbols, uint32_t nbits) { if (!q->byte_tables_init) { ERROR("Error need to initiated modem tables for packeted bits before calling srslte_mod_modulate_bytes()\n"); - return -1; + return -1; } if (nbits % q->nbits_x_symbol) { ERROR("Error modulator expects number of bits (%d) to be multiple of %d\n", nbits, q->nbits_x_symbol); - return -1; + return -1; } - switch(q->nbits_x_symbol) { + switch (q->nbits_x_symbol) { case 1: mod_bpsk_bytes(q, bits, symbols, nbits); break; @@ -156,7 +161,7 @@ int srslte_mod_modulate_bytes(srslte_modem_table_t* q, uint8_t *bits, cf_t* symb break; default: ERROR("srslte_mod_modulate_bytes() accepts QPSK/16QAM/64QAM modulations only\n"); - return -1; + return -1; } - return nbits/q->nbits_x_symbol; + return nbits / q->nbits_x_symbol; } diff --git a/lib/src/phy/modem/modem_table.c b/lib/src/phy/modem/modem_table.c index fce79937e..d4c689313 100644 --- a/lib/src/phy/modem/modem_table.c +++ b/lib/src/phy/modem/modem_table.c @@ -19,28 +19,31 @@ * */ -#include #include +#include #include #include #include #include +#include "lte_tables.h" #include "srslte/phy/common/phy_common.h" #include "srslte/phy/modem/modem_table.h" #include "srslte/phy/utils/vector.h" -#include "lte_tables.h" /** Internal functions */ -static int table_create(srslte_modem_table_t* q) { - q->symbol_table = srslte_vec_malloc(q->nsymbols*sizeof(cf_t)); - return q->symbol_table==NULL; +static int table_create(srslte_modem_table_t* q) +{ + q->symbol_table = srslte_vec_malloc(q->nsymbols * sizeof(cf_t)); + return q->symbol_table == NULL; } -void srslte_modem_table_init(srslte_modem_table_t* q) { - bzero((void*)q,sizeof(srslte_modem_table_t)); +void srslte_modem_table_init(srslte_modem_table_t* q) +{ + bzero((void*)q, sizeof(srslte_modem_table_t)); } -void srslte_modem_table_free(srslte_modem_table_t* q) { +void srslte_modem_table_free(srslte_modem_table_t* q) +{ if (q->symbol_table) { free(q->symbol_table); } @@ -58,12 +61,14 @@ void srslte_modem_table_free(srslte_modem_table_t* q) { } bzero(q, sizeof(srslte_modem_table_t)); } -void srslte_modem_table_reset(srslte_modem_table_t* q) { +void srslte_modem_table_reset(srslte_modem_table_t* q) +{ srslte_modem_table_free(q); srslte_modem_table_init(q); } -int srslte_modem_table_set(srslte_modem_table_t* q, cf_t* table, uint32_t nsymbols, uint32_t nbits_x_symbol) { +int srslte_modem_table_set(srslte_modem_table_t* q, cf_t* table, uint32_t nsymbols, uint32_t nbits_x_symbol) +{ if (q->nsymbols) { return SRSLTE_ERROR; } @@ -71,98 +76,97 @@ int srslte_modem_table_set(srslte_modem_table_t* q, cf_t* table, uint32_t nsymbo if (table_create(q)) { return SRSLTE_ERROR; } - memcpy(q->symbol_table,table,q->nsymbols*sizeof(cf_t)); + memcpy(q->symbol_table, table, q->nsymbols * sizeof(cf_t)); q->nbits_x_symbol = nbits_x_symbol; return SRSLTE_SUCCESS; } -int srslte_modem_table_lte(srslte_modem_table_t* q, srslte_mod_t modulation) { +int srslte_modem_table_lte(srslte_modem_table_t* q, srslte_mod_t modulation) +{ srslte_modem_table_init(q); - switch(modulation) { - case SRSLTE_MOD_BPSK: - q->nbits_x_symbol = 1; - q->nsymbols = 2; - if (table_create(q)) { - return SRSLTE_ERROR; - } - set_BPSKtable(q->symbol_table); - break; - case SRSLTE_MOD_QPSK: - q->nbits_x_symbol = 2; - q->nsymbols = 4; - if (table_create(q)) { - return SRSLTE_ERROR; - } - set_QPSKtable(q->symbol_table); - break; - case SRSLTE_MOD_16QAM: - q->nbits_x_symbol = 4; - q->nsymbols = 16; - if (table_create(q)) { - return SRSLTE_ERROR; - } - set_16QAMtable(q->symbol_table); - break; - case SRSLTE_MOD_64QAM: - q->nbits_x_symbol = 6; - q->nsymbols = 64; - if (table_create(q)) { - return SRSLTE_ERROR; - } - set_64QAMtable(q->symbol_table); - break; - case SRSLTE_MOD_256QAM: - q->nbits_x_symbol = 8; - q->nsymbols = 256; - if (table_create(q)) { - return SRSLTE_ERROR; - } - set_256QAMtable(q->symbol_table); - break; + switch (modulation) { + case SRSLTE_MOD_BPSK: + q->nbits_x_symbol = 1; + q->nsymbols = 2; + if (table_create(q)) { + return SRSLTE_ERROR; + } + set_BPSKtable(q->symbol_table); + break; + case SRSLTE_MOD_QPSK: + q->nbits_x_symbol = 2; + q->nsymbols = 4; + if (table_create(q)) { + return SRSLTE_ERROR; + } + set_QPSKtable(q->symbol_table); + break; + case SRSLTE_MOD_16QAM: + q->nbits_x_symbol = 4; + q->nsymbols = 16; + if (table_create(q)) { + return SRSLTE_ERROR; + } + set_16QAMtable(q->symbol_table); + break; + case SRSLTE_MOD_64QAM: + q->nbits_x_symbol = 6; + q->nsymbols = 64; + if (table_create(q)) { + return SRSLTE_ERROR; + } + set_64QAMtable(q->symbol_table); + break; + case SRSLTE_MOD_256QAM: + q->nbits_x_symbol = 8; + q->nsymbols = 256; + if (table_create(q)) { + return SRSLTE_ERROR; + } + set_256QAMtable(q->symbol_table); + break; } return SRSLTE_SUCCESS; } -void srslte_modem_table_bytes(srslte_modem_table_t* q) { - uint8_t mask_qpsk[4] = {0xc0, 0x30, 0xc, 0x3}; - uint8_t mask_16qam[2] = {0xf0, 0xf}; - - switch(q->nbits_x_symbol) { +void srslte_modem_table_bytes(srslte_modem_table_t* q) +{ + uint8_t mask_qpsk[4] = {0xc0, 0x30, 0xc, 0x3}; + uint8_t mask_16qam[2] = {0xf0, 0xf}; + + switch (q->nbits_x_symbol) { case 1: - q->symbol_table_bpsk = srslte_vec_malloc(sizeof(bpsk_packed_t)*256); - for (uint32_t i=0;i<256;i++) { - for (int j=0;j<8;j++) { - q->symbol_table_bpsk[i].symbol[j] = q->symbol_table[(i&(1<<(7-j)))>>(7-j)]; + q->symbol_table_bpsk = srslte_vec_malloc(sizeof(bpsk_packed_t) * 256); + for (uint32_t i = 0; i < 256; i++) { + for (int j = 0; j < 8; j++) { + q->symbol_table_bpsk[i].symbol[j] = q->symbol_table[(i & (1 << (7 - j))) >> (7 - j)]; } } - q->byte_tables_init = true; + q->byte_tables_init = true; break; case 2: - q->symbol_table_qpsk = srslte_vec_malloc(sizeof(qpsk_packed_t)*256); - for (uint32_t i=0;i<256;i++) { - for (int j=0;j<4;j++) { - q->symbol_table_qpsk[i].symbol[j] = q->symbol_table[(i&mask_qpsk[j])>>(6-j*2)]; + q->symbol_table_qpsk = srslte_vec_malloc(sizeof(qpsk_packed_t) * 256); + for (uint32_t i = 0; i < 256; i++) { + for (int j = 0; j < 4; j++) { + q->symbol_table_qpsk[i].symbol[j] = q->symbol_table[(i & mask_qpsk[j]) >> (6 - j * 2)]; } } - q->byte_tables_init = true; + q->byte_tables_init = true; break; case 4: - q->symbol_table_16qam = srslte_vec_malloc(sizeof(qam16_packed_t)*256); - for (uint32_t i=0;i<256;i++) { - for (int j=0;j<2;j++) { - q->symbol_table_16qam[i].symbol[j] = q->symbol_table[(i&mask_16qam[j])>>(4-j*4)]; + q->symbol_table_16qam = srslte_vec_malloc(sizeof(qam16_packed_t) * 256); + for (uint32_t i = 0; i < 256; i++) { + for (int j = 0; j < 2; j++) { + q->symbol_table_16qam[i].symbol[j] = q->symbol_table[(i & mask_16qam[j]) >> (4 - j * 4)]; } } - q->byte_tables_init = true; + q->byte_tables_init = true; break; case 6: - q->byte_tables_init = true; + q->byte_tables_init = true; break; case 8: q->byte_tables_init = true; break; } } - - - diff --git a/lib/src/phy/modem/test/modem_test.c b/lib/src/phy/modem/test/modem_test.c index a10962a1f..da81d0a68 100644 --- a/lib/src/phy/modem/test/modem_test.c +++ b/lib/src/phy/modem/test/modem_test.c @@ -19,74 +19,76 @@ * */ +#include +#include #include #include #include #include -#include -#include #include -#include +#include #include "srslte/srslte.h" -time_t start, finish; +time_t start, finish; struct timeval x, y; -int num_bits = 1000; +int num_bits = 1000; srslte_mod_t modulation = SRSLTE_MOD_BPSK; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [nmse]\n", prog); printf("\t-n num_bits [Default %d]\n", num_bits); printf("\t-m modulation (1: BPSK, 2: QPSK, 4: QAM16, 6: QAM64, 8: QAM256) [Default BPSK]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "nm")) != -1) { switch (opt) { - case 'n': - num_bits = (int)strtol(argv[optind], NULL, 10); - break; - case 'm': - switch (strtol(argv[optind], NULL, 10)) { - case 1: - modulation = SRSLTE_MOD_BPSK; - break; - case 2: - modulation = SRSLTE_MOD_QPSK; - break; - case 4: - modulation = SRSLTE_MOD_16QAM; - break; - case 6: - modulation = SRSLTE_MOD_64QAM; - break; - case 8: - modulation = SRSLTE_MOD_256QAM; - break; - default: - ERROR("Invalid modulation %ld. Possible values: " - "(1: BPSK, 2: QPSK, 4: QAM16, 6: QAM64, 8: QAM256)\n", - strtol(argv[optind], NULL, 10)); - break; - } - break; - default: - usage(argv[0]); - exit(-1); + case 'n': + num_bits = (int)strtol(argv[optind], NULL, 10); + break; + case 'm': + switch (strtol(argv[optind], NULL, 10)) { + case 1: + modulation = SRSLTE_MOD_BPSK; + break; + case 2: + modulation = SRSLTE_MOD_QPSK; + break; + case 4: + modulation = SRSLTE_MOD_16QAM; + break; + case 6: + modulation = SRSLTE_MOD_64QAM; + break; + case 8: + modulation = SRSLTE_MOD_256QAM; + break; + default: + ERROR("Invalid modulation %ld. Possible values: " + "(1: BPSK, 2: QPSK, 4: QAM16, 6: QAM64, 8: QAM256)\n", + strtol(argv[optind], NULL, 10)); + break; + } + break; + default: + usage(argv[0]); + exit(-1); } } } - -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ int ret = SRSLTE_SUCCESS; - int i; + int i; srslte_modem_table_t mod; - uint8_t *input, *input_bytes, *output; - cf_t *symbols, *symbols_bytes; + uint8_t * input, *input_bytes, *output; + cf_t * symbols, *symbols_bytes; float* llr; parse_args(argc, argv); @@ -96,7 +98,7 @@ int main(int argc, char **argv) { ERROR("Error initializing modem table\n"); exit(-1); } - + srslte_modem_table_bytes(&mod); /* check that num_bits is multiple of num_bits x symbol */ @@ -111,7 +113,7 @@ int main(int argc, char **argv) { perror("malloc"); exit(-1); } - input_bytes = srslte_vec_malloc(sizeof(uint8_t) * num_bits/8); + input_bytes = srslte_vec_malloc(sizeof(uint8_t) * num_bits / 8); if (!input_bytes) { perror("malloc"); exit(-1); @@ -139,34 +141,33 @@ int main(int argc, char **argv) { } /* generate random data */ - for (i=0;i=0 ? 1 : 0; + for (i = 0; i < num_bits; i++) { + output[i] = llr[i] >= 0 ? 1 : 0; } /* check errors */ diff --git a/lib/src/phy/modem/test/soft_demod_test.c b/lib/src/phy/modem/test/soft_demod_test.c index 2be4154d1..0d072f507 100644 --- a/lib/src/phy/modem/test/soft_demod_test.c +++ b/lib/src/phy/modem/test/soft_demod_test.c @@ -19,68 +19,70 @@ * */ +#include +#include #include #include #include #include -#include -#include #include -#include +#include #include "srslte/srslte.h" -int nof_frames = 10; -int num_bits = 1000; +int nof_frames = 10; +int num_bits = 1000; srslte_mod_t modulation = 10; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [nfv] -m modulation (1: BPSK, 2: QPSK, 4: QAM16, 6: QAM64)\n", prog); printf("\t-n num_bits [Default %d]\n", num_bits); printf("\t-f nof_frames [Default %d]\n", nof_frames); printf("\t-v srslte_verbose [Default None]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "nmvf")) != -1) { switch (opt) { - case 'n': - num_bits = (int)strtol(argv[optind], NULL, 10); - break; - case 'f': - nof_frames = (int)strtol(argv[optind], NULL, 10); - break; - case 'v': - srslte_verbose++; - break; - case 'm': - switch (strtol(argv[optind], NULL, 10)) { - case 1: - modulation = SRSLTE_MOD_BPSK; - break; - case 2: - modulation = SRSLTE_MOD_QPSK; - break; - case 4: - modulation = SRSLTE_MOD_16QAM; - break; - case 6: - modulation = SRSLTE_MOD_64QAM; - break; - case 8: - modulation = SRSLTE_MOD_256QAM; - break; - default: - ERROR("Invalid modulation %d. Possible values: " - "(1: BPSK, 2: QPSK, 4: QAM16, 6: QAM64)\n", - (int)strtol(argv[optind], NULL, 10)); - break; - } - break; - default: - usage(argv[0]); - exit(-1); + case 'n': + num_bits = (int)strtol(argv[optind], NULL, 10); + break; + case 'f': + nof_frames = (int)strtol(argv[optind], NULL, 10); + break; + case 'v': + srslte_verbose++; + break; + case 'm': + switch (strtol(argv[optind], NULL, 10)) { + case 1: + modulation = SRSLTE_MOD_BPSK; + break; + case 2: + modulation = SRSLTE_MOD_QPSK; + break; + case 4: + modulation = SRSLTE_MOD_16QAM; + break; + case 6: + modulation = SRSLTE_MOD_64QAM; + break; + case 8: + modulation = SRSLTE_MOD_256QAM; + break; + default: + ERROR("Invalid modulation %d. Possible values: " + "(1: BPSK, 2: QPSK, 4: QAM16, 6: QAM64)\n", + (int)strtol(argv[optind], NULL, 10)); + break; + } + break; + default: + usage(argv[0]); + exit(-1); } } if (modulation == 10) { @@ -89,14 +91,15 @@ void parse_args(int argc, char **argv) { } } -float mse_threshold() { - switch(modulation) { - case SRSLTE_MOD_BPSK: +float mse_threshold() +{ + switch (modulation) { + case SRSLTE_MOD_BPSK: return 1.0e-6; case SRSLTE_MOD_QPSK: - return 1.0e-6; - case SRSLTE_MOD_16QAM: - return 0.11; + return 1.0e-6; + case SRSLTE_MOD_16QAM: + return 0.11; case SRSLTE_MOD_64QAM: return 0.19; case SRSLTE_MOD_256QAM: @@ -106,14 +109,15 @@ float mse_threshold() { } } -int main(int argc, char **argv) { - int i; +int main(int argc, char** argv) +{ + int i; srslte_modem_table_t mod; - uint8_t *input, *output; - cf_t *symbols; - float *llr; - short *llr_s; - int8_t *llr_b; + uint8_t * input, *output; + cf_t* symbols; + float* llr; + short* llr_s; + int8_t* llr_b; parse_args(argc, argv); @@ -163,15 +167,15 @@ int main(int argc, char **argv) { /* generate random data */ srand(0); - - int ret = -1; - struct timeval t[3]; - float mean_texec = 0.0; - float mean_texec_s = 0.0; - float mean_texec_b = 0.0; - for (int n=0;n 0) { - mean_texec = SRSLTE_VEC_CMA((float) t[0].tv_usec, mean_texec, n-1); + mean_texec = SRSLTE_VEC_CMA((float)t[0].tv_usec, mean_texec, n - 1); } gettimeofday(&t[1], NULL); @@ -193,7 +197,7 @@ int main(int argc, char **argv) { get_time_interval(t); if (n > 0) { - mean_texec_s = SRSLTE_VEC_CMA((float) t[0].tv_usec, mean_texec_s, n-1); + mean_texec_s = SRSLTE_VEC_CMA((float)t[0].tv_usec, mean_texec_s, n - 1); } gettimeofday(&t[1], NULL); @@ -202,7 +206,7 @@ int main(int argc, char **argv) { get_time_interval(t); if (n > 0) { - mean_texec_b = SRSLTE_VEC_CMA((float) t[0].tv_usec, mean_texec_b, n-1); + mean_texec_b = SRSLTE_VEC_CMA((float)t[0].tv_usec, mean_texec_b, n - 1); } if (SRSLTE_VERBOSE_ISDEBUG()) { @@ -210,7 +214,7 @@ int main(int argc, char **argv) { srslte_vec_fprint_b(stdout, input, num_bits); printf("symbols="); - srslte_vec_fprint_c(stdout, symbols, num_bits/mod.nbits_x_symbol); + srslte_vec_fprint_c(stdout, symbols, num_bits / mod.nbits_x_symbol); printf("llr="); srslte_vec_fprint_f(stdout, llr, num_bits); @@ -220,18 +224,17 @@ int main(int argc, char **argv) { printf("llr_b="); srslte_vec_fprint_bs(stdout, llr_b, num_bits); - } // Check demodulation errors - for (int i=0;i0?1:0)) { - printf("Error in bit %d\n", i); - goto clean_exit; + for (int i = 0; i < num_bits; i++) { + if (input[i] != (llr[i] > 0 ? 1 : 0)) { + printf("Error in bit %d\n", i); + goto clean_exit; } } } - ret = 0; + ret = 0; clean_exit: free(llr_b); @@ -244,6 +247,11 @@ clean_exit: srslte_modem_table_free(&mod); printf("Mean Throughput: %.2f/%.2f/%.2f. Mbps ExTime: %.2f/%.2f/%.2f us\n", - num_bits/mean_texec, num_bits/mean_texec_s, num_bits/mean_texec_b, mean_texec, mean_texec_s, mean_texec_b); + num_bits / mean_texec, + num_bits / mean_texec_s, + num_bits / mean_texec_b, + mean_texec, + mean_texec_s, + mean_texec_b); exit(ret); } diff --git a/lib/src/phy/phch/cqi.c b/lib/src/phy/phch/cqi.c index 52115d135..4a981a84e 100644 --- a/lib/src/phy/phch/cqi.c +++ b/lib/src/phy/phch/cqi.c @@ -29,18 +29,18 @@ #include #include -#include "srslte/phy/phch/cqi.h" #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/phch/cqi.h" #include "srslte/phy/utils/bit.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" /******************************************************* * PACKING FUNCTIONS * *******************************************************/ static int cqi_hl_subband_pack(srslte_cqi_cfg_t* cfg, srslte_cqi_hl_subband_t* msg, uint8_t* buff) { - uint8_t *body_ptr = buff; + uint8_t* body_ptr = buff; uint32_t bit_count = 0; /* Unpack codeword 0, common for 3GPP 36.212 Tables 5.2.2.6.2-1 and 5.2.2.6.2-2 */ @@ -87,7 +87,7 @@ static int cqi_ue_subband_pack(srslte_cqi_cfg_t* cfg, srslte_cqi_ue_subband_t* m /* Pack CQI following 3GPP TS 36.212 Tables 5.2.3.3.1-1 and 5.2.3.3.1-2 */ static int cqi_format2_wideband_pack(srslte_cqi_cfg_t* cfg, srslte_cqi_format2_wideband_t* msg, uint8_t* buff) { - uint8_t *body_ptr = buff; + uint8_t* body_ptr = buff; srslte_bit_unpack(msg->wideband_cqi, &body_ptr, 4); @@ -133,23 +133,22 @@ int srslte_cqi_value_pack(srslte_cqi_cfg_t* cfg, srslte_cqi_value_t* value, uint return -1; } - /******************************************************* * UNPACKING FUNCTIONS * *******************************************************/ int cqi_hl_subband_unpack(srslte_cqi_cfg_t* cfg, uint8_t* buff, srslte_cqi_hl_subband_t* msg) { - uint8_t *body_ptr = buff; + uint8_t* body_ptr = buff; uint32_t bit_count = 0; - msg->wideband_cqi_cw0 = (uint8_t) srslte_bit_pack(&body_ptr, 4); + msg->wideband_cqi_cw0 = (uint8_t)srslte_bit_pack(&body_ptr, 4); msg->subband_diff_cqi_cw0 = srslte_bit_pack(&body_ptr, 2 * cfg->N); bit_count += 4 + 2 * cfg->N; /* Unpack codeword 1, 3GPP 36.212 Table 5.2.2.6.2-2 */ if (cfg->rank_is_not_one) { - msg->wideband_cqi_cw1 = (uint8_t) srslte_bit_pack(&body_ptr, 4); + msg->wideband_cqi_cw1 = (uint8_t)srslte_bit_pack(&body_ptr, 4); msg->subband_diff_cqi_cw1 = srslte_bit_pack(&body_ptr, 2 * cfg->N); bit_count += 4 + 2 * cfg->N; } @@ -157,14 +156,14 @@ int cqi_hl_subband_unpack(srslte_cqi_cfg_t* cfg, uint8_t* buff, srslte_cqi_hl_su /* If PMI is present, unpack it */ if (cfg->pmi_present) { if (cfg->four_antenna_ports) { - msg->pmi = (uint8_t) srslte_bit_pack(&body_ptr, 4); + msg->pmi = (uint8_t)srslte_bit_pack(&body_ptr, 4); bit_count += 4; } else { if (cfg->rank_is_not_one) { - msg->pmi = (uint8_t) srslte_bit_pack(&body_ptr, 1); + msg->pmi = (uint8_t)srslte_bit_pack(&body_ptr, 1); bit_count += 1; } else { - msg->pmi = (uint8_t) srslte_bit_pack(&body_ptr, 2); + msg->pmi = (uint8_t)srslte_bit_pack(&body_ptr, 2); bit_count += 2; } } @@ -187,20 +186,20 @@ int cqi_ue_subband_unpack(srslte_cqi_cfg_t* cfg, uint8_t* buff, srslte_cqi_ue_su static int cqi_format2_wideband_unpack(srslte_cqi_cfg_t* cfg, uint8_t* buff, srslte_cqi_format2_wideband_t* msg) { uint8_t* body_ptr = buff; - msg->wideband_cqi = (uint8_t) srslte_bit_pack(&body_ptr, 4); + msg->wideband_cqi = (uint8_t)srslte_bit_pack(&body_ptr, 4); if (cfg->pmi_present) { if (cfg->four_antenna_ports) { if (cfg->rank_is_not_one) { - msg->spatial_diff_cqi = (uint8_t) srslte_bit_pack(&body_ptr, 3); + msg->spatial_diff_cqi = (uint8_t)srslte_bit_pack(&body_ptr, 3); } - msg->pmi = (uint8_t) srslte_bit_pack(&body_ptr, 4); + msg->pmi = (uint8_t)srslte_bit_pack(&body_ptr, 4); } else { if (cfg->rank_is_not_one) { - msg->spatial_diff_cqi = (uint8_t) srslte_bit_pack(&body_ptr, 3); - msg->pmi = (uint8_t) srslte_bit_pack(&body_ptr, 1); + msg->spatial_diff_cqi = (uint8_t)srslte_bit_pack(&body_ptr, 3); + msg->pmi = (uint8_t)srslte_bit_pack(&body_ptr, 1); } else { - msg->pmi = (uint8_t) srslte_bit_pack(&body_ptr, 2); + msg->pmi = (uint8_t)srslte_bit_pack(&body_ptr, 2); } } } @@ -387,36 +386,36 @@ static bool cqi_get_N_fdd(uint32_t I_cqi_pmi, uint32_t* N_p, uint32_t* N_offset) { // Acccording to 3GPP 36.213 R10 Table 7.2.2-1A: Mapping of I CQI / PMI to N pd and N OFFSET , CQI for FDD if (I_cqi_pmi <= 1) { - *N_p = 2; + *N_p = 2; *N_offset = I_cqi_pmi; } else if (I_cqi_pmi <= 6) { - *N_p = 5; + *N_p = 5; *N_offset = I_cqi_pmi - 2; } else if (I_cqi_pmi <= 16) { - *N_p = 10; + *N_p = 10; *N_offset = I_cqi_pmi - 7; } else if (I_cqi_pmi <= 36) { - *N_p = 20; + *N_p = 20; *N_offset = I_cqi_pmi - 17; } else if (I_cqi_pmi <= 76) { - *N_p = 40; + *N_p = 40; *N_offset = I_cqi_pmi - 37; } else if (I_cqi_pmi <= 156) { - *N_p = 80; + *N_p = 80; *N_offset = I_cqi_pmi - 77; } else if (I_cqi_pmi <= 316) { - *N_p = 160; + *N_p = 160; *N_offset = I_cqi_pmi - 157; } else if (I_cqi_pmi == 317) { return false; } else if (I_cqi_pmi <= 349) { - *N_p = 32; + *N_p = 32; *N_offset = I_cqi_pmi - 318; } else if (I_cqi_pmi <= 413) { - *N_p = 64; + *N_p = 64; *N_offset = I_cqi_pmi - 350; } else if (I_cqi_pmi <= 541) { - *N_p = 128; + *N_p = 128; *N_offset = I_cqi_pmi - 414; } else if (I_cqi_pmi <= 1023) { return false; @@ -471,11 +470,11 @@ static bool cqi_send(uint32_t I_cqi_pmi, uint32_t tti, bool is_fdd) } if (N_p) { - if ((tti-N_offset)%N_p == 0) { + if ((tti - N_offset) % N_p == 0) { return true; } } - return false; + return false; } static bool ri_send(uint32_t I_cqi_pmi, uint32_t I_ri, uint32_t tti, bool is_fdd) @@ -513,7 +512,7 @@ static bool ri_send(uint32_t I_cqi_pmi, uint32_t I_ri, uint32_t tti, bool is_fdd M_ri = 16; N_offset_ri = -(I_ri - 644); } else if (I_ri <= 965) { - M_ri = 32; + M_ri = 32; N_offset_ri = -(I_ri - 805); } else { return false; @@ -539,33 +538,49 @@ bool srslte_cqi_periodic_send(srslte_cqi_report_cfg_t* cfg, uint32_t tti, srslte } // CQI-to-Spectral Efficiency: 36.213 Table 7.2.3-1 */ -static float cqi_to_coderate[16] = {0, 0.1523, 0.2344, 0.3770, 0.6016, 0.8770, 1.1758, 1.4766, 1.9141, 2.4063, 2.7305, 3.3223, 3.9023, 4.5234, 5.1152, 5.5547}; - -float srslte_cqi_to_coderate(uint32_t cqi) { +static float cqi_to_coderate[16] = {0, + 0.1523, + 0.2344, + 0.3770, + 0.6016, + 0.8770, + 1.1758, + 1.4766, + 1.9141, + 2.4063, + 2.7305, + 3.3223, + 3.9023, + 4.5234, + 5.1152, + 5.5547}; + +float srslte_cqi_to_coderate(uint32_t cqi) +{ if (cqi < 16) { return cqi_to_coderate[cqi]; } else { - return 0; + return 0; } } /* SNR-to-CQI conversion, got from "Downlink SNR to CQI Mapping for Different Multiple Antenna Techniques in LTE" - * Table III. -*/ + * Table III. + */ // From paper -static float cqi_to_snr_table[15] = { 1.95, 4, 6, 8, 10, 11.95, 14.05, 16, 17.9, 20.9, 22.5, 24.75, 25.5, 27.30, 29}; +static float cqi_to_snr_table[15] = {1.95, 4, 6, 8, 10, 11.95, 14.05, 16, 17.9, 20.9, 22.5, 24.75, 25.5, 27.30, 29}; -// From experimental measurements @ 5 MHz -//static float cqi_to_snr_table[15] = { 1, 1.75, 3, 4, 5, 6, 7.5, 9, 11.5, 13.0, 15.0, 18, 20, 22.5, 26.5}; +// From experimental measurements @ 5 MHz +// static float cqi_to_snr_table[15] = { 1, 1.75, 3, 4, 5, 6, 7.5, 9, 11.5, 13.0, 15.0, 18, 20, 22.5, 26.5}; uint8_t srslte_cqi_from_snr(float snr) { - for (int cqi=14;cqi>=0;cqi--) { - if (snr >= cqi_to_snr_table[cqi]) { - return (uint8_t) cqi+1; - } - } - return 0; + for (int cqi = 14; cqi >= 0; cqi--) { + if (snr >= cqi_to_snr_table[cqi]) { + return (uint8_t)cqi + 1; + } + } + return 0; } /* Returns the subband size for higher layer-configured subband feedback, @@ -594,24 +609,25 @@ int srslte_cqi_hl_get_no_subbands(int nof_prb) { int hl_size = cqi_hl_get_subband_size(nof_prb); if (hl_size > 0) { - return (int)ceil((float)nof_prb/hl_size); + return (int)ceil((float)nof_prb / hl_size); } else { return 0; } } -void srslte_cqi_to_str(const uint8_t *cqi_value, int cqi_len, char *str, int str_len) { +void srslte_cqi_to_str(const uint8_t* cqi_value, int cqi_len, char* str, int str_len) +{ int i = 0; for (i = 0; i < cqi_len && i < (str_len - 5); i++) { - str[i] = (cqi_value[i] == 0)?(char)'0':(char)'1'; + str[i] = (cqi_value[i] == 0) ? (char)'0' : (char)'1'; } if (i == (str_len - 5)) { str[i++] = '.'; str[i++] = '.'; str[i++] = '.'; - str[i++] = (cqi_value[cqi_len - 1] == 0)?(char)'0':(char)'1'; + str[i++] = (cqi_value[cqi_len - 1] == 0) ? (char)'0' : (char)'1'; } str[i] = '\0'; } diff --git a/lib/src/phy/phch/dci.c b/lib/src/phy/phch/dci.c index aaeb6814a..f24d9324c 100644 --- a/lib/src/phy/phch/dci.c +++ b/lib/src/phy/phch/dci.c @@ -19,14 +19,14 @@ * */ +#include +#include +#include #include #include +#include #include #include -#include -#include -#include -#include #include "srslte/phy/common/phy_common.h" #include "srslte/phy/phch/dci.h" @@ -92,10 +92,10 @@ int srslte_dci_rar_to_ul_dci(srslte_cell_t* cell, srslte_dci_rar_grant_t* rar, s static uint32_t riv_nbits(uint32_t nof_prb) { - return (uint32_t) ceilf(log2f((float) nof_prb * ((float) nof_prb + 1) / 2)); + return (uint32_t)ceilf(log2f((float)nof_prb * ((float)nof_prb + 1) / 2)); } -const uint32_t ambiguous_sizes[10] = { 12, 14, 16, 20, 24, 26, 32, 40, 44, 56 }; +const uint32_t ambiguous_sizes[10] = {12, 14, 16, 20, 24, 26, 32, 40, 44, 56}; static bool is_ambiguous_size(uint32_t size) { @@ -227,7 +227,7 @@ static uint32_t dci_format1C_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, { uint32_t n_vrb_dl_gap1 = srslte_ra_type2_n_vrb_dl(cell->nof_prb, true); uint32_t n_step = srslte_ra_type2_n_rb_step(cell->nof_prb); - uint32_t n = riv_nbits((uint32_t) n_vrb_dl_gap1 / n_step) + 5; + uint32_t n = riv_nbits((uint32_t)n_vrb_dl_gap1 / n_step) + 5; if (cell->nof_prb >= 50) { n++; } @@ -323,7 +323,7 @@ static uint32_t dci_format2_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, static uint32_t precoding_bits_f2a(uint32_t nof_ports) { if (nof_ports <= 2) { - return 0; + return 0; } else { return 2; } @@ -340,7 +340,6 @@ static uint32_t dci_format2A_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, n++; } return n; - } static uint32_t dci_format2B_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg) @@ -410,8 +409,11 @@ srslte_dci_format_sizeof(srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci * * TODO: TPC and cyclic shift for DM RS not implemented */ -static int dci_format0_pack( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_ul_t* dci, srslte_dci_msg_t* msg) +static int dci_format0_pack(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_ul_t* dci, + srslte_dci_msg_t* msg) { /* pack bits */ @@ -422,9 +424,9 @@ static int dci_format0_pack( srslte_bit_unpack(dci->cif, &y, 3); } - *y++ = 0; // format differentiation + *y++ = 0; // format differentiation if (dci->freq_hop_fl == SRSLTE_RA_PUSCH_HOP_DISABLED) { // frequency hopping - *y++ = 0; + *y++ = 0; n_ul_hop = 0; } else { *y++ = 1; @@ -471,8 +473,11 @@ static int dci_format0_pack( * * TODO: TPC and cyclic shift for DM RS not implemented */ -static int dci_format0_unpack( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_msg_t* msg, srslte_dci_ul_t* dci) +static int dci_format0_unpack(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_msg_t* msg, + srslte_dci_ul_t* dci) { /* pack bits */ @@ -507,7 +512,7 @@ static int dci_format0_unpack( n_ul_hop = 1; // Table 8.4-1 of 36.213 dci->freq_hop_fl = *y++; } else { - n_ul_hop = 2; // Table 8.4-1 of 36.213 + n_ul_hop = 2; // Table 8.4-1 of 36.213 dci->freq_hop_fl = y[0] << 1 | y[1]; y += 2; } @@ -538,7 +543,7 @@ static int dci_format0_unpack( // CQI request if (cfg->multiple_csi_request_enabled) { dci->multiple_csi_request_present = true; - dci->multiple_csi_request = srslte_bit_pack(&y, 2); + dci->multiple_csi_request = srslte_bit_pack(&y, 2); } else { dci->cqi_request = *y++ ? true : false; } @@ -546,12 +551,12 @@ static int dci_format0_unpack( // SRS request if (cfg->srs_request_enabled) { dci->srs_request_present = true; - dci->srs_request = *y++ ? true : false; + dci->srs_request = *y++ ? true : false; } if (cfg->ra_format_enabled) { dci->ra_type_present = true; - dci->ra_type = *y++ ? true : false; + dci->ra_type = *y++ ? true : false; } return SRSLTE_SUCCESS; @@ -563,8 +568,11 @@ static int dci_format0_unpack( * TODO: TPC commands */ -static int dci_format1_pack( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_dl_t* dci, srslte_dci_msg_t* msg) +static int dci_format1_pack(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_dl_t* dci, + srslte_dci_msg_t* msg) { uint32_t nof_prb = cell->nof_prb; @@ -580,7 +588,7 @@ static int dci_format1_pack( } /* Resource allocation: type0 or type 1 */ - uint32_t P = srslte_ra_type0_P(nof_prb); + uint32_t P = srslte_ra_type0_P(nof_prb); uint32_t alloc_size = (uint32_t)ceilf((float)nof_prb / P); switch (dci->alloc_type) { case SRSLTE_RA_ALLOC_TYPE0: @@ -622,8 +630,11 @@ static int dci_format1_pack( return SRSLTE_SUCCESS; } -static int dci_format1_unpack( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_msg_t* msg, srslte_dci_dl_t* dci) +static int dci_format1_unpack(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_msg_t* msg, + srslte_dci_dl_t* dci) { /* pack bits */ @@ -689,8 +700,11 @@ static int dci_format1_unpack( * * TODO: RA procedure initiated by PDCCH, TPC commands */ -static int dci_format1As_pack( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_dl_t* dci, srslte_dci_msg_t* msg) +static int dci_format1As_pack(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_dl_t* dci, + srslte_dci_msg_t* msg) { uint32_t nof_prb = cell->nof_prb; @@ -741,7 +755,7 @@ static int dci_format1As_pack( *y++ = 0; *y++ = 0; } else { - y++; // MSB of TPC is reserved + y++; // MSB of TPC is reserved *y++ = dci->type2_alloc.n_prb1a; // LSB indicates N_prb_1a for TBS } @@ -758,8 +772,11 @@ static int dci_format1As_pack( /* Unpacks DCI format 1A for compact scheduling of PDSCH words according to 36.212 5.3.3.1.3 * */ -static int dci_format1As_unpack( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_msg_t* msg, srslte_dci_dl_t* dci) +static int dci_format1As_unpack(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_msg_t* msg, + srslte_dci_dl_t* dci) { /* pack bits */ @@ -787,20 +804,20 @@ static int dci_format1As_unpack( // Check if RA procedure by PDCCH order if (*y == 0) { int nof_bits = riv_nbits(cell->nof_prb); - int i=0; + int i = 0; // Check all bits in RBA are set to 1 - while(inof_bits-1 && y[i] == 0) { + while (i < msg->nof_bits - 1 && y[i] == 0) { i++; } - if (i == msg->nof_bits-1) { + if (i == msg->nof_bits - 1) { // This is a Random access order - y+=1+nof_bits; + y += 1 + nof_bits; dci->is_ra_order = true; dci->ra_preamble = srslte_bit_pack(&y, 6); @@ -864,8 +881,11 @@ static int dci_format1As_unpack( return SRSLTE_SUCCESS; } -static int dci_format1B_unpack( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_msg_t* msg, srslte_dci_dl_t* dci) +static int dci_format1B_unpack(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_msg_t* msg, + srslte_dci_dl_t* dci) { /* pack bits */ @@ -915,8 +935,11 @@ static int dci_format1B_unpack( /* Format 1C for compact scheduling of PDSCH words * */ -static int dci_format1Cs_pack( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_dl_t* dci, srslte_dci_msg_t* msg) +static int dci_format1Cs_pack(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_dl_t* dci, + srslte_dci_msg_t* msg) { uint32_t nof_prb = cell->nof_prb; @@ -951,8 +974,11 @@ static int dci_format1Cs_pack( return SRSLTE_SUCCESS; } -static int dci_format1Cs_unpack( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_msg_t* msg, srslte_dci_dl_t* dci) +static int dci_format1Cs_unpack(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_msg_t* msg, + srslte_dci_dl_t* dci) { /* pack bits */ uint8_t* y = msg->payload; @@ -983,8 +1009,11 @@ static int dci_format1Cs_unpack( return SRSLTE_SUCCESS; } -static int dci_format1D_unpack( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_msg_t* msg, srslte_dci_dl_t* dci) +static int dci_format1D_unpack(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_msg_t* msg, + srslte_dci_dl_t* dci) { /* pack bits */ @@ -1032,8 +1061,11 @@ static int dci_format1D_unpack( return SRSLTE_SUCCESS; } -static int dci_format2AB_pack( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_dl_t* dci, srslte_dci_msg_t* msg) +static int dci_format2AB_pack(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_dl_t* dci, + srslte_dci_msg_t* msg) { uint32_t nof_prb = cell->nof_prb; @@ -1052,7 +1084,7 @@ static int dci_format2AB_pack( /* Resource allocation: type0 or type 1 */ uint32_t P = srslte_ra_type0_P(nof_prb); - uint32_t alloc_size = (uint32_t) ceilf((float) nof_prb / P); + uint32_t alloc_size = (uint32_t)ceilf((float)nof_prb / P); switch (dci->alloc_type) { case SRSLTE_RA_ALLOC_TYPE0: srslte_bit_unpack((uint32_t)dci->type0_alloc.rbg_bitmask, &y, alloc_size); @@ -1107,8 +1139,11 @@ static int dci_format2AB_pack( return SRSLTE_SUCCESS; } -static int dci_format2AB_unpack( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_msg_t* msg, srslte_dci_dl_t* dci) +static int dci_format2AB_unpack(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_msg_t* msg, + srslte_dci_dl_t* dci) { /* pack bits */ @@ -1154,7 +1189,7 @@ static int dci_format2AB_unpack( /* harq process number */ dci->pid = srslte_bit_pack(&y, HARQ_PID_LEN); - // Transpor block to codeword swap flag + // Transpor block to codeword swap flag if (msg->format == SRSLTE_DCI_FORMAT2B) { dci->sram_id = *y++ ? true : false; } else { @@ -1172,7 +1207,7 @@ static int dci_format2AB_unpack( } } - // Precoding information + // Precoding information if (msg->format == SRSLTE_DCI_FORMAT2) { dci->pinfo = srslte_bit_pack(&y, precoding_bits_f2(cell->nof_ports)); } else if (msg->format == SRSLTE_DCI_FORMAT2A) { @@ -1199,8 +1234,11 @@ static int dci_format2AB_unpack( return SRSLTE_SUCCESS; } -int srslte_dci_msg_pack_pdsch( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_dl_t* dci, srslte_dci_msg_t* msg) +int srslte_dci_msg_pack_pdsch(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_dl_t* dci, + srslte_dci_msg_t* msg) { msg->rnti = dci->rnti; msg->location = dci->location; @@ -1229,8 +1267,11 @@ int srslte_dci_msg_pack_pdsch( } } -int srslte_dci_msg_unpack_pdsch( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_msg_t* msg, srslte_dci_dl_t* dci) +int srslte_dci_msg_unpack_pdsch(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_msg_t* msg, + srslte_dci_dl_t* dci) { // Initialize DCI bzero(dci, sizeof(srslte_dci_dl_t)); @@ -1280,8 +1321,11 @@ int srslte_dci_msg_unpack_pdsch( } } -int srslte_dci_msg_pack_pusch( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_ul_t* dci, srslte_dci_msg_t* msg) +int srslte_dci_msg_pack_pusch(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_ul_t* dci, + srslte_dci_msg_t* msg) { msg->rnti = dci->rnti; msg->location = dci->location; @@ -1296,8 +1340,11 @@ int srslte_dci_msg_pack_pusch( return dci_format0_pack(cell, sf, cfg, dci, msg); } -int srslte_dci_msg_unpack_pusch( - srslte_cell_t* cell, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* cfg, srslte_dci_msg_t* msg, srslte_dci_ul_t* dci) +int srslte_dci_msg_unpack_pusch(srslte_cell_t* cell, + srslte_dl_sf_cfg_t* sf, + srslte_dci_cfg_t* cfg, + srslte_dci_msg_t* msg, + srslte_dci_ul_t* dci) { // Initialize DCI bzero(dci, sizeof(srslte_dci_ul_t)); @@ -1398,8 +1445,8 @@ char* srslte_dci_format_string(srslte_dci_format_t format) } } - -char* srslte_dci_format_string_short(srslte_dci_format_t format) { +char* srslte_dci_format_string_short(srslte_dci_format_t format) +{ switch (format) { case SRSLTE_DCI_FORMAT0: return "0"; @@ -1607,10 +1654,10 @@ uint32_t srslte_dci_ul_info(srslte_dci_ul_t* dci_ul, char* info_str, uint32_t le n = srslte_print_check(info_str, len, n, ", csi=%d", dci_ul->multiple_csi_request); } if (dci_ul->srs_request_present) { - n = srslte_print_check(info_str, len, n, ", srs_request=%s", dci_ul->srs_request?"yes":"no"); + n = srslte_print_check(info_str, len, n, ", srs_request=%s", dci_ul->srs_request ? "yes" : "no"); } if (dci_ul->ra_type_present) { - n = srslte_print_check(info_str, len, n, ", ra_type=%s", dci_ul->ra_type?"yes":"no"); + n = srslte_print_check(info_str, len, n, ", ra_type=%s", dci_ul->ra_type ? "yes" : "no"); } if (dci_ul->is_tdd) { diff --git a/lib/src/phy/phch/pbch.c b/lib/src/phy/phch/pbch.c index fe1f115d4..45fb04387 100644 --- a/lib/src/phy/phch/pbch.c +++ b/lib/src/phy/phch/pbch.c @@ -30,33 +30,34 @@ #include #include "prb_dl.h" -#include "srslte/phy/phch/pbch.h" #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/phch/pbch.h" #include "srslte/phy/utils/bit.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" -#define PBCH_RE_CP_NORM 240 -#define PBCH_RE_CP_EXT 216 +#define PBCH_RE_CP_NORM 240 +#define PBCH_RE_CP_EXT 216 -const uint8_t srslte_crc_mask[4][16] = { - { 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 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 } }; +const uint8_t srslte_crc_mask[4][16] = {{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}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}}; -bool srslte_pbch_exists(int nframe, int nslot) { +bool srslte_pbch_exists(int nframe, int nslot) +{ return (!(nframe % 5) && nslot == 1); } -cf_t *offset_original; +cf_t* offset_original; + +int srslte_pbch_cp(cf_t* input, cf_t* output, srslte_cell_t cell, bool put) +{ + int i; + cf_t* ptr; + + offset_original = input; -int srslte_pbch_cp(cf_t *input, cf_t *output, srslte_cell_t cell, bool put) { - int i; - cf_t *ptr; - - offset_original = input; - if (put) { ptr = input; output += cell.nof_prb * SRSLTE_NRE / 2 - 36; @@ -64,14 +65,14 @@ int srslte_pbch_cp(cf_t *input, cf_t *output, srslte_cell_t cell, bool put) { ptr = output; input += cell.nof_prb * SRSLTE_NRE / 2 - 36; } - + /* symbol 0 & 1 */ for (i = 0; i < 2; i++) { - prb_cp_ref(&input, &output, cell.id % 3, 4, 4*6, put); + prb_cp_ref(&input, &output, cell.id % 3, 4, 4 * 6, put); if (put) { - output += cell.nof_prb * SRSLTE_NRE - 2*36 + (cell.id%3==2?1:0); + output += cell.nof_prb * SRSLTE_NRE - 2 * 36 + (cell.id % 3 == 2 ? 1 : 0); } else { - input += cell.nof_prb * SRSLTE_NRE - 2*36 + (cell.id%3==2?1:0); + input += cell.nof_prb * SRSLTE_NRE - 2 * 36 + (cell.id % 3 == 2 ? 1 : 0); } } /* symbols 2 & 3 */ @@ -79,19 +80,19 @@ int srslte_pbch_cp(cf_t *input, cf_t *output, srslte_cell_t cell, bool put) { for (i = 0; i < 2; i++) { prb_cp(&input, &output, 6); if (put) { - output += cell.nof_prb * SRSLTE_NRE - 2*36; + output += cell.nof_prb * SRSLTE_NRE - 2 * 36; } else { - input += cell.nof_prb * SRSLTE_NRE - 2*36; + input += cell.nof_prb * SRSLTE_NRE - 2 * 36; } } } else { prb_cp(&input, &output, 6); if (put) { - output += cell.nof_prb * SRSLTE_NRE - 2*36; + output += cell.nof_prb * SRSLTE_NRE - 2 * 36; } else { - input += cell.nof_prb * SRSLTE_NRE - 2*36; + input += cell.nof_prb * SRSLTE_NRE - 2 * 36; } - prb_cp_ref(&input, &output, cell.id % 3, 4, 4*6, put); + prb_cp_ref(&input, &output, cell.id % 3, 4, 4 * 6, put); } if (put) { return input - ptr; @@ -111,7 +112,8 @@ int srslte_pbch_cp(cf_t *input, cf_t *output, srslte_cell_t cell, bool put) { * @param[out] slot1_data Complex symbol buffer for slot1 * @param[in] cell Cell configuration */ -int srslte_pbch_put(cf_t *pbch, cf_t *slot1_data, srslte_cell_t cell) { +int srslte_pbch_put(cf_t* pbch, cf_t* slot1_data, srslte_cell_t cell) +{ return srslte_pbch_cp(pbch, slot1_data, cell, true); } @@ -126,19 +128,20 @@ int srslte_pbch_put(cf_t *pbch, cf_t *slot1_data, srslte_cell_t cell) { * @param[out] pbch Extracted complex PBCH symbols * @param[in] cell Cell configuration */ -int srslte_pbch_get(cf_t *slot1_data, cf_t *pbch, srslte_cell_t cell) { +int srslte_pbch_get(cf_t* slot1_data, cf_t* pbch, srslte_cell_t cell) +{ return srslte_pbch_cp(slot1_data, pbch, cell, false); } -/** Initializes the PBCH transmitter and receiver. - * At the receiver, the field nof_ports in the cell structure indicates the - * maximum number of BS transmitter ports to look for. +/** Initializes the PBCH transmitter and receiver. + * At the receiver, the field nof_ports in the cell structure indicates the + * maximum number of BS transmitter ports to look for. */ -int srslte_pbch_init(srslte_pbch_t *q) { +int srslte_pbch_init(srslte_pbch_t* q) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL) - { + if (q != NULL) { ret = SRSLTE_ERROR; bzero(q, sizeof(srslte_pbch_t)); @@ -146,15 +149,15 @@ int srslte_pbch_init(srslte_pbch_t *q) { if (srslte_modem_table_lte(&q->mod, SRSLTE_MOD_QPSK)) { goto clean; } - int poly[3] = { 0x6D, 0x4F, 0x57 }; + int poly[3] = {0x6D, 0x4F, 0x57}; if (srslte_viterbi_init(&q->decoder, SRSLTE_VITERBI_37, poly, 40, true)) { goto clean; } if (srslte_crc_init(&q->crc, SRSLTE_LTE_CRC16, 16)) { goto clean; } - q->encoder.K = 7; - q->encoder.R = 3; + q->encoder.K = 7; + q->encoder.R = 3; q->encoder.tail_biting = true; memcpy(q->encoder.poly, poly, 3 * sizeof(int)); @@ -194,14 +197,15 @@ int srslte_pbch_init(srslte_pbch_t *q) { ret = SRSLTE_SUCCESS; } -clean: +clean: if (ret == SRSLTE_ERROR) { srslte_pbch_free(q); } return ret; } -void srslte_pbch_free(srslte_pbch_t *q) { +void srslte_pbch_free(srslte_pbch_t* q) +{ srslte_sequence_free(&q->seq); srslte_modem_table_free(&q->mod); srslte_viterbi_free(&q->decoder); @@ -232,15 +236,14 @@ void srslte_pbch_free(srslte_pbch_t *q) { bzero(q, sizeof(srslte_pbch_t)); } -int srslte_pbch_set_cell(srslte_pbch_t *q, srslte_cell_t cell) { +int srslte_pbch_set_cell(srslte_pbch_t* q, srslte_cell_t cell) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - srslte_cell_isvalid(&cell)) - { + if (q != NULL && srslte_cell_isvalid(&cell)) { if (cell.nof_ports == 0) { q->search_all_ports = true; - cell.nof_ports = SRSLTE_MAX_PORTS; + cell.nof_ports = SRSLTE_MAX_PORTS; } else { q->search_all_ports = false; } @@ -258,7 +261,6 @@ int srslte_pbch_set_cell(srslte_pbch_t *q, srslte_cell_t cell) { return ret; } - /** * Unpacks MIB from PBCH message. * @@ -266,20 +268,21 @@ int srslte_pbch_set_cell(srslte_pbch_t *q, srslte_cell_t cell) { * @param[out] sfn System frame number * @param[out] cell MIB information about PHICH and system bandwidth will be saved here */ -void srslte_pbch_mib_unpack(uint8_t *msg, srslte_cell_t *cell, uint32_t *sfn) { +void srslte_pbch_mib_unpack(uint8_t* msg, srslte_cell_t* cell, uint32_t* sfn) +{ int phich_res; uint32_t bw_idx = srslte_bit_pack(&msg, 3); switch (bw_idx) { - case 0: - cell->nof_prb = 6; - break; - case 1: - cell->nof_prb = 15; - break; - default: - cell->nof_prb = (bw_idx - 1) * 25; - break; + case 0: + cell->nof_prb = 6; + break; + case 1: + cell->nof_prb = 15; + break; + default: + cell->nof_prb = (bw_idx - 1) * 25; + break; } if (*msg) { cell->phich_length = SRSLTE_PHICH_EXT; @@ -290,21 +293,21 @@ void srslte_pbch_mib_unpack(uint8_t *msg, srslte_cell_t *cell, uint32_t *sfn) { phich_res = srslte_bit_pack(&msg, 2); switch (phich_res) { - case 0: + case 0: cell->phich_resources = SRSLTE_PHICH_R_1_6; - break; - case 1: + break; + case 1: cell->phich_resources = SRSLTE_PHICH_R_1_2; - break; - case 2: + break; + case 2: cell->phich_resources = SRSLTE_PHICH_R_1; - break; - case 3: + break; + case 3: cell->phich_resources = SRSLTE_PHICH_R_2; - break; + break; } if (sfn) { - *sfn = srslte_bit_pack(&msg, 8) << 2; + *sfn = srslte_bit_pack(&msg, 8) << 2; } } @@ -315,10 +318,11 @@ void srslte_pbch_mib_unpack(uint8_t *msg, srslte_cell_t *cell, uint32_t *sfn) { * @param[in] sfn System frame number * @param[in] cell Cell configuration to be encoded in MIB */ -void srslte_pbch_mib_pack(srslte_cell_t *cell, uint32_t sfn, uint8_t *payload) { +void srslte_pbch_mib_pack(srslte_cell_t* cell, uint32_t sfn, uint8_t* payload) +{ int bw, phich_res = 0; - - uint8_t *msg = payload; + + uint8_t* msg = payload; bzero(msg, 24); @@ -335,29 +339,30 @@ void srslte_pbch_mib_pack(srslte_cell_t *cell, uint32_t sfn, uint8_t *payload) { msg++; switch (cell->phich_resources) { - case SRSLTE_PHICH_R_1_6: - phich_res = 0; - break; - case SRSLTE_PHICH_R_1_2: - phich_res = 1; - break; - case SRSLTE_PHICH_R_1: - phich_res = 2; - break; - case SRSLTE_PHICH_R_2: - phich_res = 3; - break; + case SRSLTE_PHICH_R_1_6: + phich_res = 0; + break; + case SRSLTE_PHICH_R_1_2: + phich_res = 1; + break; + case SRSLTE_PHICH_R_1: + phich_res = 2; + break; + case SRSLTE_PHICH_R_2: + phich_res = 3; + break; } srslte_bit_unpack(phich_res, &msg, 2); srslte_bit_unpack(sfn >> 2, &msg, 8); - } -void srslte_pbch_decode_reset(srslte_pbch_t *q) { +void srslte_pbch_decode_reset(srslte_pbch_t* q) +{ q->frame_idx = 0; } -void srslte_crc_set_mask(uint8_t *data, int nof_ports) { +void srslte_crc_set_mask(uint8_t* data, int nof_ports) +{ int i; for (i = 0; i < 16; i++) { data[SRSLTE_BCH_PAYLOAD_LEN + i] = (data[SRSLTE_BCH_PAYLOAD_LEN + i] + srslte_crc_mask[nof_ports - 1][i]) % 2; @@ -370,14 +375,15 @@ void srslte_crc_set_mask(uint8_t *data, int nof_ports) { * * 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[SRSLTE_BCH_PAYLOADCRC_LEN]; memcpy(data, bits, SRSLTE_BCH_PAYLOADCRC_LEN * sizeof(uint8_t)); srslte_crc_set_mask(data, nof_ports); int ret = srslte_crc_checksum(&q->crc, data, SRSLTE_BCH_PAYLOADCRC_LEN); if (ret == 0) { - uint32_t chkzeros=0; - for (int i=0;itemp[dst * nof_bits], &q->llr[src * nof_bits], - n * nof_bits * sizeof(float)); + memcpy(&q->temp[dst * nof_bits], &q->llr[src * nof_bits], n * nof_bits * sizeof(float)); /* descramble */ - srslte_scrambling_f_offset(&q->seq, &q->temp[dst * nof_bits], dst * nof_bits, - n * nof_bits); + srslte_scrambling_f_offset(&q->seq, &q->temp[dst * nof_bits], dst * nof_bits, n * nof_bits); for (j = 0; j < dst * nof_bits; j++) { q->temp[j] = SRSLTE_RX_NULL; @@ -413,7 +417,7 @@ int decode_frame(srslte_pbch_t *q, uint32_t src, uint32_t dst, uint32_t n, srslte_rm_conv_rx(q->temp, 4 * nof_bits, q->rm_f, SRSLTE_BCH_ENCODED_LEN); /* Normalize LLR */ - srslte_vec_sc_prod_fff(q->rm_f, 1.0/((float) 2*n), q->rm_f, SRSLTE_BCH_ENCODED_LEN); + srslte_vec_sc_prod_fff(q->rm_f, 1.0 / ((float)2 * n), q->rm_f, SRSLTE_BCH_ENCODED_LEN); /* decode */ srslte_viterbi_decode_f(&q->decoder, q->rm_f, q->data, SRSLTE_BCH_PAYLOADCRC_LEN); @@ -427,7 +431,6 @@ int decode_frame(srslte_pbch_t *q, uint32_t src, uint32_t dst, uint32_t n, ERROR("Error in PBCH decoder: Invalid frame pointers dst=%d, src=%d, n=%d\n", src, dst, n); return -1; } - } /* Decodes the PBCH channel @@ -447,8 +450,8 @@ int srslte_pbch_decode(srslte_pbch_t* q, { uint32_t src, dst, nb; uint32_t nant; - int i; - int nof_bits; + int i; + int nof_bits; cf_t* x[SRSLTE_MAX_LAYERS]; int ret = SRSLTE_ERROR_INVALID_INPUTS; @@ -490,9 +493,9 @@ int srslte_pbch_decode(srslte_pbch_t* q, /* Try decoding for 1 to cell.nof_ports antennas */ if (q->search_all_ports) { - nant = 1; + nant = 1; } else { - nant = q->cell.nof_ports; + nant = q->cell.nof_ports; } do { @@ -510,26 +513,30 @@ int srslte_pbch_decode(srslte_pbch_t* q, /* demodulate symbols */ srslte_demod_soft_demodulate(SRSLTE_MOD_QPSK, q->d, &q->llr[nof_bits * (frame_idx - 1)], q->nof_symbols); - + /* We don't know where the 40 ms begin, so we try all combinations. E.g. if we received - * 4 frames, try 1,2,3,4 individually, 12, 23, 34 in pairs, 123, 234 and finally 1234. - * We know they are ordered. - */ + * 4 frames, try 1,2,3,4 individually, 12, 23, 34 in pairs, 123, 234 and finally 1234. + * We know they are ordered. + */ for (nb = 0; nb < frame_idx; nb++) { for (dst = 0; (dst < 4 - nb); dst++) { for (src = 0; src < frame_idx - nb; src++) { ret = decode_frame(q, src, dst, nb + 1, nof_bits, nant); if (ret == 1) { if (sfn_offset) { - *sfn_offset = (int) dst - src + frame_idx - 1; + *sfn_offset = (int)dst - src + frame_idx - 1; } if (nof_tx_ports) { - *nof_tx_ports = nant; + *nof_tx_ports = nant; } if (bch_payload) { - memcpy(bch_payload, q->data, sizeof(uint8_t) * SRSLTE_BCH_PAYLOAD_LEN); + memcpy(bch_payload, q->data, sizeof(uint8_t) * SRSLTE_BCH_PAYLOAD_LEN); } - INFO("Decoded PBCH: src=%d, dst=%d, nb=%d, sfn_offset=%d\n", src, dst, nb+1, (int) dst - src + frame_idx - 1); + INFO("Decoded PBCH: src=%d, dst=%d, nb=%d, sfn_offset=%d\n", + src, + dst, + nb + 1, + (int)dst - src + frame_idx - 1); srslte_pbch_decode_reset(q); return 1; } @@ -538,7 +545,7 @@ int srslte_pbch_decode(srslte_pbch_t* q, } } nant++; - } while(nant <= q->cell.nof_ports); + } while (nant <= q->cell.nof_ports); /* If not found, make room for the next packet of radio frame symbols */ if (q->frame_idx == 4) { @@ -556,9 +563,9 @@ int srslte_pbch_encode(srslte_pbch_t* q, cf_t* sf_symbols[SRSLTE_MAX_PORTS], uint32_t frame_idx) { - int i; - int nof_bits; - cf_t *x[SRSLTE_MAX_LAYERS]; + int i; + int nof_bits; + cf_t* x[SRSLTE_MAX_LAYERS]; if (q != NULL && bch_payload != NULL) { /* Set pointers for layermapping & precoding */ @@ -569,9 +576,9 @@ int srslte_pbch_encode(srslte_pbch_t* q, x[i] = q->x[i]; } memset(&x[q->cell.nof_ports], 0, sizeof(cf_t*) * (SRSLTE_MAX_LAYERS - q->cell.nof_ports)); - - frame_idx=frame_idx%4; - + + frame_idx = frame_idx % 4; + memcpy(q->data, bch_payload, sizeof(uint8_t) * SRSLTE_BCH_PAYLOAD_LEN); /* encode & modulate */ @@ -582,16 +589,13 @@ int srslte_pbch_encode(srslte_pbch_t* q, 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[frame_idx * nof_bits], - frame_idx * nof_bits, nof_bits); - srslte_mod_modulate(&q->mod, &q->rm_b[frame_idx * nof_bits], q->d, - nof_bits); + srslte_scrambling_b_offset(&q->seq, &q->rm_b[frame_idx * nof_bits], frame_idx * nof_bits, nof_bits); + srslte_mod_modulate(&q->mod, &q->rm_b[frame_idx * nof_bits], q->d, nof_bits); /* layer mapping & precoding */ if (q->cell.nof_ports > 1) { srslte_layermap_diversity(q->d, x, q->cell.nof_ports, q->nof_symbols); - srslte_precoding_diversity(x, q->symbols, q->cell.nof_ports, - q->nof_symbols / q->cell.nof_ports, 1.0f); + srslte_precoding_diversity(x, q->symbols, q->cell.nof_ports, q->nof_symbols / q->cell.nof_ports, 1.0f); } else { memcpy(q->symbols[0], q->d, q->nof_symbols * sizeof(cf_t)); } @@ -605,4 +609,3 @@ int srslte_pbch_encode(srslte_pbch_t* q, return SRSLTE_ERROR_INVALID_INPUTS; } } - diff --git a/lib/src/phy/phch/pcfich.c b/lib/src/phy/phch/pcfich.c index 4db7bf463..c90354528 100644 --- a/lib/src/phy/phch/pcfich.c +++ b/lib/src/phy/phch/pcfich.c @@ -19,75 +19,72 @@ * */ +#include +#include +#include #include #include +#include #include #include -#include -#include -#include -#include -#include "srslte/phy/phch/regs.h" -#include "srslte/phy/phch/pcfich.h" #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/phch/pcfich.h" +#include "srslte/phy/phch/regs.h" #include "srslte/phy/utils/bit.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" // Table 5.3.4-1 -static uint8_t cfi_table[4][PCFICH_CFI_LEN] = { - { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, - 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 }, - { 1, 0, 1, - 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, - 0, 1, 1, 0 }, - { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, - 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 }, - { 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 } // reserved +static uint8_t cfi_table[4][PCFICH_CFI_LEN] = { + {0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1}, + {1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0}, + {1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1}, + {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} // reserved }; -bool srslte_pcfich_exists(int nframe, int nslot) { +bool srslte_pcfich_exists(int nframe, int nslot) +{ return true; } /** Initializes the pcfich channel receiver. * On ERROR returns -1 and frees the structrure */ -int srslte_pcfich_init(srslte_pcfich_t *q, uint32_t nof_rx_antennas) { +int srslte_pcfich_init(srslte_pcfich_t* q, uint32_t nof_rx_antennas) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; - - if (q != NULL) - { + + if (q != NULL) { ret = SRSLTE_ERROR; - + bzero(q, sizeof(srslte_pcfich_t)); q->nof_rx_antennas = nof_rx_antennas; - q->nof_symbols = PCFICH_RE; + q->nof_symbols = PCFICH_RE; if (srslte_modem_table_lte(&q->mod, SRSLTE_MOD_QPSK)) { goto clean; } /* convert cfi bit tables to floats for demodulation */ - for (int i=0;i<3;i++) { - for (int j=0;jcfi_table_float[i][j] = (float) 2.0*cfi_table[i][j]-1.0; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < PCFICH_CFI_LEN; j++) { + q->cfi_table_float[i][j] = (float)2.0 * cfi_table[i][j] - 1.0; } } ret = SRSLTE_SUCCESS; } - - clean: + +clean: if (ret == SRSLTE_ERROR) { srslte_pcfich_free(q); } return ret; } -void srslte_pcfich_free(srslte_pcfich_t *q) { +void srslte_pcfich_free(srslte_pcfich_t* q) +{ for (int ns = 0; ns < SRSLTE_NOF_SF_X_FRAME; ns++) { srslte_sequence_free(&q->seq[ns]); } @@ -96,13 +93,11 @@ void srslte_pcfich_free(srslte_pcfich_t *q) { bzero(q, sizeof(srslte_pcfich_t)); } -int srslte_pcfich_set_cell(srslte_pcfich_t *q, srslte_regs_t *regs, srslte_cell_t cell) { +int srslte_pcfich_set_cell(srslte_pcfich_t* q, srslte_regs_t* regs, srslte_cell_t cell) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - regs != NULL && - srslte_cell_isvalid(&cell)) - { + if (q != NULL && regs != NULL && srslte_cell_isvalid(&cell)) { q->regs = regs; if (cell.id != q->cell.id || q->cell.nof_prb == 0) { q->cell = cell; @@ -117,24 +112,24 @@ int srslte_pcfich_set_cell(srslte_pcfich_t *q, srslte_regs_t *regs, srslte_cell_ return ret; } - /** Finds the CFI with minimum distance with the vector of received 32 bits. * Saves the CFI value in the cfi pointer and returns the distance. */ -float srslte_pcfich_cfi_decode(srslte_pcfich_t *q, uint32_t *cfi) { - int i; - int index = 0; +float srslte_pcfich_cfi_decode(srslte_pcfich_t* q, uint32_t* cfi) +{ + int i; + int index = 0; float max_corr = 0; float corr[3]; - + for (i = 0; i < 3; i++) { corr[i] = srslte_vec_dot_prod_fff(q->cfi_table_float[i], q->data_f, PCFICH_CFI_LEN); if (corr[i] > max_corr) { - max_corr = corr[i]; - index = i; + max_corr = corr[i]; + index = i; } } - + if (cfi) { *cfi = index + 1; } @@ -144,12 +139,13 @@ float srslte_pcfich_cfi_decode(srslte_pcfich_t *q, uint32_t *cfi) { /** Encodes the CFI producing a vector of 32 bits. * 36.211 10.3 section 5.3.4 */ -int srslte_pcfich_cfi_encode(uint32_t cfi, uint8_t bits[PCFICH_CFI_LEN]) { +int srslte_pcfich_cfi_encode(uint32_t cfi, uint8_t bits[PCFICH_CFI_LEN]) +{ if (cfi < 1 || cfi > 3) { return SRSLTE_ERROR_INVALID_INPUTS; - } else{ + } else { memcpy(bits, cfi_table[cfi - 1], PCFICH_CFI_LEN * sizeof(uint8_t)); - return SRSLTE_SUCCESS; + return SRSLTE_SUCCESS; } } @@ -175,12 +171,12 @@ int srslte_pcfich_decode(srslte_pcfich_t* q, for (i = 0; i < SRSLTE_MAX_PORTS; i++) { x[i] = q->x[i]; } - - cf_t *q_symbols[SRSLTE_MAX_PORTS]; - cf_t *q_ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; - + + cf_t* q_symbols[SRSLTE_MAX_PORTS]; + cf_t* q_ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; + /* extract symbols */ - for (int j=0;jnof_rx_antennas;j++) { + for (int j = 0; j < q->nof_rx_antennas; j++) { if (q->nof_symbols != srslte_regs_pcfich_get(q->regs, sf_symbols[j], q->symbols[j])) { ERROR("There was an error getting the PCFICH symbols\n"); return SRSLTE_ERROR; @@ -197,14 +193,15 @@ int srslte_pcfich_decode(srslte_pcfich_t* q, q_ce[i][j] = q->ce[i][j]; } } - + /* in control channels, only diversity is supported */ if (q->cell.nof_ports == 1) { /* no need for layer demapping */ srslte_predecoding_single_multi( q_symbols, q_ce[0], q->d, NULL, q->nof_rx_antennas, q->nof_symbols, 1.0f, channel->noise_estimate); } else { - srslte_predecoding_diversity_multi(q_symbols, q_ce, x, NULL, q->nof_rx_antennas, q->cell.nof_ports, q->nof_symbols, 1.0f); + srslte_predecoding_diversity_multi( + q_symbols, q_ce, x, NULL, q->nof_rx_antennas, q->cell.nof_ports, q->nof_symbols, 1.0f); srslte_layerdemap_diversity(x, q->d, q->cell.nof_ports, q->nof_symbols / q->cell.nof_ports); } @@ -223,7 +220,6 @@ int srslte_pcfich_decode(srslte_pcfich_t* q, } else { return SRSLTE_ERROR_INVALID_INPUTS; } - } /** Encodes CFI and maps symbols to the slot @@ -237,8 +233,8 @@ int srslte_pcfich_encode(srslte_pcfich_t* q, srslte_dl_sf_cfg_t* sf, cf_t* slot_ uint32_t sf_idx = sf->tti % 10; /* Set pointers for layermapping & precoding */ - cf_t *x[SRSLTE_MAX_LAYERS]; - cf_t *q_symbols[SRSLTE_MAX_PORTS]; + cf_t* x[SRSLTE_MAX_LAYERS]; + cf_t* q_symbols[SRSLTE_MAX_PORTS]; /* number of layers equals number of ports */ for (i = 0; i < q->cell.nof_ports; i++) { @@ -276,5 +272,3 @@ int srslte_pcfich_encode(srslte_pcfich_t* q, srslte_dl_sf_cfg_t* sf, cf_t* slot_ return SRSLTE_ERROR_INVALID_INPUTS; } } - - diff --git a/lib/src/phy/phch/pdcch.c b/lib/src/phy/phch/pdcch.c index 9f7fb1792..8a92bb804 100644 --- a/lib/src/phy/phch/pdcch.c +++ b/lib/src/phy/phch/pdcch.c @@ -19,47 +19,47 @@ * */ +#include +#include #include #include +#include #include #include -#include -#include -#include +#include "srslte/phy/common/phy_common.h" #include "srslte/phy/phch/dci.h" -#include "srslte/phy/phch/regs.h" #include "srslte/phy/phch/pdcch.h" -#include "srslte/phy/common/phy_common.h" +#include "srslte/phy/phch/regs.h" #include "srslte/phy/utils/bit.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" -#define PDCCH_NOF_FORMATS 4 -#define PDCCH_FORMAT_NOF_CCE(i) (1<0&&cfi<4)?q->nof_cce[cfi-1]:0) -#define NOF_REGS(cfi) ((cfi>0&&cfi<4)?q->nof_regs[cfi-1]:0) +#define NOF_CCE(cfi) ((cfi > 0 && cfi < 4) ? q->nof_cce[cfi - 1] : 0) +#define NOF_REGS(cfi) ((cfi > 0 && cfi < 4) ? q->nof_regs[cfi - 1] : 0) -float srslte_pdcch_coderate(uint32_t nof_bits, uint32_t l) { - return (float) (nof_bits+16)/(4*PDCCH_FORMAT_NOF_REGS(l)); +float srslte_pdcch_coderate(uint32_t nof_bits, uint32_t l) +{ + return (float)(nof_bits + 16) / (4 * PDCCH_FORMAT_NOF_REGS(l)); } /** Initializes the PDCCH transmitter and receiver */ -static int pdcch_init(srslte_pdcch_t *q, uint32_t max_prb, uint32_t nof_rx_antennas, bool is_ue) +static int pdcch_init(srslte_pdcch_t* q, uint32_t max_prb, uint32_t nof_rx_antennas, bool is_ue) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL) - { + if (q != NULL) { ret = SRSLTE_ERROR; bzero(q, sizeof(srslte_pdcch_t)); q->nof_rx_antennas = nof_rx_antennas; q->is_ue = is_ue; /* Allocate memory for the maximum number of PDCCH bits (CFI=3) */ - q->max_bits = max_prb*3*12*2; + q->max_bits = max_prb * 3 * 12 * 2; INFO("Init PDCCH: Max bits: %d\n", q->max_bits); @@ -70,7 +70,7 @@ static int pdcch_init(srslte_pdcch_t *q, uint32_t max_prb, uint32_t nof_rx_anten goto clean; } - int poly[3] = { 0x6D, 0x4F, 0x57 }; + int poly[3] = {0x6D, 0x4F, 0x57}; if (srslte_viterbi_init(&q->decoder, SRSLTE_VITERBI_37, poly, SRSLTE_DCI_MAX_BITS + 16, true)) { goto clean; } @@ -84,7 +84,7 @@ static int pdcch_init(srslte_pdcch_t *q, uint32_t max_prb, uint32_t nof_rx_anten if (!q->llr) { goto clean; } - + bzero(q->llr, sizeof(float) * q->max_bits); q->d = srslte_vec_malloc(sizeof(cf_t) * q->max_bits / 2); @@ -113,22 +113,25 @@ static int pdcch_init(srslte_pdcch_t *q, uint32_t max_prb, uint32_t nof_rx_anten ret = SRSLTE_SUCCESS; } - clean: +clean: if (ret == SRSLTE_ERROR) { srslte_pdcch_free(q); } return ret; } -int srslte_pdcch_init_enb(srslte_pdcch_t *q, uint32_t max_prb) { +int srslte_pdcch_init_enb(srslte_pdcch_t* q, uint32_t max_prb) +{ return pdcch_init(q, max_prb, 0, false); } -int srslte_pdcch_init_ue(srslte_pdcch_t *q, uint32_t max_prb, uint32_t nof_rx_antennas) { +int srslte_pdcch_init_ue(srslte_pdcch_t* q, uint32_t max_prb, uint32_t nof_rx_antennas) +{ return pdcch_init(q, max_prb, nof_rx_antennas, true); } -void srslte_pdcch_free(srslte_pdcch_t *q) { +void srslte_pdcch_free(srslte_pdcch_t* q) +{ if (q->e) { free(q->e); @@ -147,7 +150,7 @@ void srslte_pdcch_free(srslte_pdcch_t *q) { free(q->symbols[i]); } if (q->is_ue) { - for (int j=0;jnof_rx_antennas;j++) { + for (int j = 0; j < q->nof_rx_antennas; j++) { if (q->ce[i][j]) { free(q->ce[i][j]); } @@ -162,7 +165,6 @@ void srslte_pdcch_free(srslte_pdcch_t *q) { srslte_viterbi_free(&q->decoder); bzero(q, sizeof(srslte_pdcch_t)); - } void srslte_pdcch_set_regs(srslte_pdcch_t* q, srslte_regs_t* regs) @@ -182,15 +184,11 @@ int srslte_pdcch_set_cell(srslte_pdcch_t* q, srslte_regs_t* regs, srslte_cell_t { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - regs != NULL && - srslte_cell_isvalid(&cell)) - { + if (q != NULL && regs != NULL && srslte_cell_isvalid(&cell)) { srslte_pdcch_set_regs(q, regs); - INFO("PDCCH: Cell config PCI=%d, %d ports.\n", - q->cell.id, q->cell.nof_ports); + INFO("PDCCH: Cell config PCI=%d, %d ports.\n", q->cell.id, q->cell.nof_ports); if (q->cell.id != cell.id || q->cell.nof_prb == 0) { q->cell = cell; @@ -198,7 +196,7 @@ int srslte_pdcch_set_cell(srslte_pdcch_t* q, srslte_regs_t* regs, srslte_cell_t for (int i = 0; i < SRSLTE_NOF_SF_X_FRAME; i++) { // we need to pregenerate the sequence for the maximum number of bits, which is 8 times // the maximum number of REGs (for CFI=3) - if (srslte_sequence_pdcch(&q->seq[i], 2 * i, q->cell.id, 8*srslte_regs_pdcch_nregs(q->regs, 3))) { + if (srslte_sequence_pdcch(&q->seq[i], 2 * i, q->cell.id, 8 * srslte_regs_pdcch_nregs(q->regs, 3))) { return SRSLTE_ERROR; } } @@ -208,31 +206,41 @@ int srslte_pdcch_set_cell(srslte_pdcch_t* q, srslte_regs_t* regs, srslte_cell_t return ret; } -uint32_t srslte_pdcch_ue_locations( - srslte_pdcch_t* q, srslte_dl_sf_cfg_t* sf, srslte_dci_location_t* c, uint32_t max_candidates, uint16_t rnti) +uint32_t srslte_pdcch_ue_locations(srslte_pdcch_t* q, + srslte_dl_sf_cfg_t* sf, + srslte_dci_location_t* c, + uint32_t max_candidates, + uint16_t rnti) { return srslte_pdcch_ue_locations_ncce(NOF_CCE(sf->cfi), c, max_candidates, sf->tti % 10, rnti); } -uint32_t srslte_pdcch_ue_locations_ncce( - uint32_t nof_cce, srslte_dci_location_t* c, uint32_t max_candidates, uint32_t sf_idx, uint16_t rnti) +uint32_t srslte_pdcch_ue_locations_ncce(uint32_t nof_cce, + srslte_dci_location_t* c, + uint32_t max_candidates, + uint32_t sf_idx, + uint16_t rnti) { return srslte_pdcch_ue_locations_ncce_L(nof_cce, c, max_candidates, sf_idx, rnti, -1); } -/** 36.213 v9.1.1 - * Computes up to max_candidates UE-specific candidates for DCI messages and saves them +/** 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. + * Returns the number of candidates saved in the array c. */ -uint32_t srslte_pdcch_ue_locations_ncce_L( - uint32_t nof_cce, srslte_dci_location_t* c, uint32_t max_candidates, uint32_t sf_idx, uint16_t rnti, int Ls) +uint32_t srslte_pdcch_ue_locations_ncce_L(uint32_t nof_cce, + srslte_dci_location_t* c, + uint32_t max_candidates, + uint32_t sf_idx, + uint16_t rnti, + int Ls) { - int l; // this must be int because of the for(;;--) loop - uint32_t i, k, L, m; - uint32_t Yk, ncce; - const int nof_candidates[4] = { 6, 6, 2, 2}; + int l; // this must be int because of the for(;;--) loop + uint32_t i, k, L, m; + uint32_t Yk, ncce; + const int nof_candidates[4] = {6, 6, 2, 2}; // Compute Yk for this subframe Yk = rnti; @@ -244,19 +252,17 @@ uint32_t srslte_pdcch_ue_locations_ncce_L( // All aggregation levels from 8 to 1 for (l = 3; l >= 0; l--) { L = (1 << l); - if (Ls<0 || Ls==L) { + if (Ls < 0 || Ls == L) { // For all candidates as given in table 9.1.1-1 for (i = 0; i < nof_candidates[l]; i++) { if (nof_cce >= L) { ncce = L * ((Yk + i) % (nof_cce / L)); // Check if candidate fits in c vector and in CCE region - if (k < max_candidates && ncce + L <= nof_cce) - { - c[k].L = l; + if (k < max_candidates && ncce + L <= nof_cce) { + c[k].L = l; c[k].ncce = ncce; - DEBUG("UE-specific SS Candidate %d: nCCE: %d, L: %d\n", - k, c[k].ncce, c[k].L); + DEBUG("UE-specific SS Candidate %d: nCCE: %d, L: %d\n", k, c[k].ncce, c[k].L); k++; } @@ -271,24 +277,22 @@ uint32_t srslte_pdcch_ue_locations_ncce_L( sf_idx, nof_cce); - return k; + return k; } - - /** * 36.213 9.1.1 - * Computes up to max_candidates candidates in the common search space - * for DCI messages and saves them in the structure pointed by c. - * Returns the number of candidates saved in the array c. + * Computes up to max_candidates candidates in the common search space + * 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_pdcch_common_locations(srslte_pdcch_t *q, srslte_dci_location_t *c, uint32_t max_candidates, - uint32_t cfi) +uint32_t +srslte_pdcch_common_locations(srslte_pdcch_t* q, srslte_dci_location_t* c, uint32_t max_candidates, uint32_t cfi) { - return srslte_pdcch_common_locations_ncce(NOF_CCE(cfi), c, max_candidates); + return srslte_pdcch_common_locations_ncce(NOF_CCE(cfi), c, max_candidates); } -uint32_t srslte_pdcch_common_locations_ncce(uint32_t nof_cce, srslte_dci_location_t *c, uint32_t max_candidates) +uint32_t srslte_pdcch_common_locations_ncce(uint32_t nof_cce, srslte_dci_location_t* c, uint32_t max_candidates) { uint32_t i, l, L, k; @@ -307,58 +311,51 @@ uint32_t srslte_pdcch_common_locations_ncce(uint32_t nof_cce, srslte_dci_locatio } } } - + INFO("Initiated %d candidate(s) in the Common search space\n", k); - + return k; } - - - - - /** 36.212 5.3.3.2 to 5.3.3.4 * * Returns XOR between parity and remainder bits * * TODO: UE transmit antenna selection CRC mask */ -int srslte_pdcch_dci_decode(srslte_pdcch_t *q, float *e, uint8_t *data, uint32_t E, uint32_t nof_bits, uint16_t *crc) { +int srslte_pdcch_dci_decode(srslte_pdcch_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); - + 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); - + 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; + *crc = p_bits ^ crc_res; } - + return SRSLTE_SUCCESS; } else { ERROR("Invalid parameters: E: %d, max_bits: %d, nof_bits: %d\n", E, q->max_bits, nof_bits); - return SRSLTE_ERROR_INVALID_INPUTS; + return SRSLTE_ERROR_INVALID_INPUTS; } } else { - return SRSLTE_ERROR_INVALID_INPUTS; + return SRSLTE_ERROR_INVALID_INPUTS; } } @@ -368,8 +365,7 @@ int srslte_pdcch_dci_decode(srslte_pdcch_t *q, float *e, uint8_t *data, uint32_t * The decoded message is stored in msg and the CRC remainder in msg->rnti * */ -int srslte_pdcch_decode_msg( - srslte_pdcch_t* q, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* dci_cfg, srslte_dci_msg_t* msg) +int srslte_pdcch_decode_msg(srslte_pdcch_t* q, srslte_dl_sf_cfg_t* sf, srslte_dci_cfg_t* dci_cfg, srslte_dci_msg_t* msg) { int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL && msg != NULL && srslte_dci_location_isvalid(&msg->location)) { @@ -382,7 +378,7 @@ int srslte_pdcch_decode_msg( uint32_t e_bits = PDCCH_FORMAT_NOF_BITS(msg->location.L); double mean = 0; - for (int i=0;illr[msg->location.ncce * 72 + i]); } mean /= e_bits; @@ -398,12 +394,12 @@ int srslte_pdcch_decode_msg( ERROR("Error calling pdcch_dci_decode\n"); } DEBUG("Decoded DCI: nCCE=%d, L=%d, format=%s, msg_len=%d, mean=%f, crc_rem=0x%x\n", - msg->location.ncce, - msg->location.L, - srslte_dci_format_string(msg->format), - nof_bits, - mean, - msg->rnti); + msg->location.ncce, + msg->location.L, + srslte_dci_format_string(msg->format), + nof_bits, + mean, + msg->rnti); } else { DEBUG( "Skipping DCI: nCCE=%d, L=%d, msg_len=%d, mean=%f\n", msg->location.ncce, msg->location.L, nof_bits, mean); @@ -415,11 +411,10 @@ int srslte_pdcch_decode_msg( return ret; } -int cnt=0; +int cnt = 0; - -/** Performs PDCCH receiver processing to extract LLR for all control region. LLR bits are stored in srslte_pdcch_t object. - * DCI can be decoded from given locations in successive calls to srslte_pdcch_decode_msg() +/** Performs PDCCH receiver processing to extract LLR for all control region. LLR bits are stored in srslte_pdcch_t + * object. DCI can be decoded from given locations in successive calls to srslte_pdcch_decode_msg() */ int srslte_pdcch_extract_llr(srslte_pdcch_t* q, srslte_dl_sf_cfg_t* sf, @@ -431,12 +426,12 @@ int srslte_pdcch_extract_llr(srslte_pdcch_t* q, /* Set pointers for layermapping & precoding */ uint32_t i, nof_symbols; - cf_t *x[SRSLTE_MAX_LAYERS]; + cf_t* x[SRSLTE_MAX_LAYERS]; if (q != NULL && sf->cfi > 0 && sf->cfi < 4) { uint32_t e_bits = 72 * NOF_CCE(sf->cfi); - nof_symbols = e_bits/2; + nof_symbols = e_bits / 2; ret = SRSLTE_ERROR; bzero(q->llr, sizeof(float) * q->max_bits); @@ -449,7 +444,7 @@ int srslte_pdcch_extract_llr(srslte_pdcch_t* q, memset(&x[q->cell.nof_ports], 0, sizeof(cf_t*) * (SRSLTE_MAX_LAYERS - q->cell.nof_ports)); /* extract symbols */ - for (int j=0;jnof_rx_antennas;j++) { + for (int j = 0; j < q->nof_rx_antennas; j++) { int n = srslte_regs_pdcch_get(q->regs, sf->cfi, sf_symbols[j], q->symbols[j]); if (nof_symbols != n) { ERROR("Expected %d PDCCH symbols but got %d symbols\n", nof_symbols, n); @@ -463,7 +458,7 @@ int srslte_pdcch_extract_llr(srslte_pdcch_t* q, ERROR("Expected %d PDCCH symbols but got %d symbols\n", nof_symbols, n); return ret; } - } + } } /* in control channels, only diversity is supported */ @@ -472,7 +467,8 @@ int srslte_pdcch_extract_llr(srslte_pdcch_t* q, srslte_predecoding_single_multi( q->symbols, q->ce[0], q->d, NULL, q->nof_rx_antennas, nof_symbols, 1.0f, channel->noise_estimate / 2); } else { - srslte_predecoding_diversity_multi(q->symbols, q->ce, x, NULL, q->nof_rx_antennas, q->cell.nof_ports, nof_symbols, 1.0f); + srslte_predecoding_diversity_multi( + q->symbols, q->ce, x, NULL, q->nof_rx_antennas, q->cell.nof_ports, nof_symbols, 1.0f); srslte_layerdemap_diversity(x, q->d, q->cell.nof_ports, nof_symbols / q->cell.nof_ports); } @@ -483,14 +479,15 @@ int srslte_pdcch_extract_llr(srslte_pdcch_t* q, srslte_scrambling_f_offset(&q->seq[sf->tti % 10], q->llr, 0, e_bits); ret = SRSLTE_SUCCESS; - } - return ret; + } + return ret; } -static void crc_set_mask_rnti(uint8_t *crc, uint16_t rnti) { +static void crc_set_mask_rnti(uint8_t* crc, uint16_t rnti) +{ uint32_t i; - uint8_t mask[16]; - uint8_t *r = mask; + uint8_t mask[16]; + uint8_t* r = mask; DEBUG("Mask CRC with RNTI 0x%x\n", rnti); @@ -500,12 +497,17 @@ static void crc_set_mask_rnti(uint8_t *crc, uint16_t rnti) { } } -void srslte_pdcch_dci_encode_conv(srslte_pdcch_t *q, uint8_t *data, uint32_t nof_bits, uint8_t *coded_data, uint16_t rnti) { +void srslte_pdcch_dci_encode_conv(srslte_pdcch_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; + 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); @@ -517,19 +519,13 @@ void srslte_pdcch_dci_encode_conv(srslte_pdcch_t *q, uint8_t *data, uint32_t nof /** 36.212 5.3.3.2 to 5.3.3.4 * TODO: UE transmit antenna selection CRC mask */ -int srslte_pdcch_dci_encode(srslte_pdcch_t *q, uint8_t *data, uint8_t *e, uint32_t nof_bits, uint32_t E, - uint16_t rnti) +int srslte_pdcch_dci_encode(srslte_pdcch_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_pdcch_dci_encode_conv(q, data, nof_bits, tmp, rnti); + if (q != NULL && data != NULL && e != NULL && nof_bits < SRSLTE_DCI_MAX_BITS && E < q->max_bits) { + + srslte_pdcch_dci_encode_conv(q, data, nof_bits, tmp, rnti); DEBUG("CConv output: "); if (SRSLTE_VERBOSE_ISDEBUG()) { @@ -537,20 +533,20 @@ int srslte_pdcch_dci_encode(srslte_pdcch_t *q, uint8_t *data, uint8_t *e, uint32 } srslte_rm_conv_tx(tmp, 3 * (nof_bits + 16), e, E); - + return SRSLTE_SUCCESS; } else { return SRSLTE_ERROR_INVALID_INPUTS; } } -/** Encodes ONE DCI message and allocates the encoded bits to the srslte_dci_location_t indicated by - * the parameter location. The CRC is scrambled with the RNTI parameter. - * This function can be called multiple times and encoded DCI messages will be allocated to the - * sf_symbols buffer ready for transmission. - * If the same location is provided in multiple messages, the encoded bits will be overwritten. - * - * @TODO: Use a bitmask and CFI to ensure message locations are valid and old messages are not overwritten. +/** Encodes ONE DCI message and allocates the encoded bits to the srslte_dci_location_t indicated by + * the parameter location. The CRC is scrambled with the RNTI parameter. + * This function can be called multiple times and encoded DCI messages will be allocated to the + * sf_symbols buffer ready for transmission. + * If the same location is provided in multiple messages, the encoded bits will be overwritten. + * + * @TODO: Use a bitmask and CFI to ensure message locations are valid and old messages are not overwritten. */ int srslte_pdcch_encode(srslte_pdcch_t* q, srslte_dl_sf_cfg_t* sf, @@ -558,7 +554,7 @@ int srslte_pdcch_encode(srslte_pdcch_t* q, cf_t* sf_symbols[SRSLTE_MAX_PORTS]) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; + int ret = SRSLTE_ERROR_INVALID_INPUTS; uint32_t i; cf_t* x[SRSLTE_MAX_LAYERS]; uint32_t nof_symbols; @@ -566,8 +562,8 @@ int srslte_pdcch_encode(srslte_pdcch_t* q, if (q != NULL && sf_symbols != NULL && sf->cfi > 0 && sf->cfi < 4 && srslte_dci_location_isvalid(&msg->location)) { uint32_t e_bits = PDCCH_FORMAT_NOF_BITS(msg->location.L); - nof_symbols = e_bits/2; - ret = SRSLTE_ERROR; + nof_symbols = e_bits / 2; + ret = SRSLTE_ERROR; if (msg->location.ncce + PDCCH_FORMAT_NOF_CCE(msg->location.L) <= NOF_CCE(sf->cfi) && msg->nof_bits < SRSLTE_DCI_MAX_BITS - 16) { @@ -589,10 +585,10 @@ int srslte_pdcch_encode(srslte_pdcch_t* q, srslte_scrambling_b_offset(&q->seq[sf->tti % 10], q->e, 72 * msg->location.ncce, e_bits); DEBUG("Scrambling output: "); - if (SRSLTE_VERBOSE_ISDEBUG()) { + if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_b(stdout, q->e, e_bits); } - + srslte_mod_modulate(&q->mod, q->e, q->d, e_bits); /* layer mapping & precoding */ @@ -602,7 +598,7 @@ int srslte_pdcch_encode(srslte_pdcch_t* q, } else { memcpy(q->symbols[0], q->d, nof_symbols * sizeof(cf_t)); } - + /* mapping to resource elements */ for (i = 0; i < q->cell.nof_ports; i++) { srslte_regs_pdcch_put_offset(q->regs, @@ -612,7 +608,7 @@ int srslte_pdcch_encode(srslte_pdcch_t* q, msg->location.ncce * 9, PDCCH_FORMAT_NOF_REGS(msg->location.L)); } - + ret = SRSLTE_SUCCESS; } else { diff --git a/lib/src/phy/phch/pdsch.c b/lib/src/phy/phch/pdsch.c index ea38645b8..853166461 100644 --- a/lib/src/phy/phch/pdsch.c +++ b/lib/src/phy/phch/pdsch.c @@ -34,7 +34,6 @@ #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" - #ifdef LV_HAVE_SSE #include #endif /* LV_HAVE_SSE */ @@ -46,15 +45,18 @@ const static float pdsch_cfg_cell_specific_ratio_table[2][4] = { /* One antenna port */ {1.0f / 1.0f, 4.0f / 5.0f, 3.0f / 5.0f, 2.0f / 5.0f}, /* Two or more antenna port */ {5.0f / 4.0f, 1.0f / 1.0f, 3.0f / 4.0f, 1.0f / 2.0f}}; -const static srslte_mod_t modulations[5] = { - SRSLTE_MOD_BPSK, SRSLTE_MOD_QPSK, SRSLTE_MOD_16QAM, SRSLTE_MOD_64QAM, SRSLTE_MOD_256QAM}; +const static srslte_mod_t modulations[5] = {SRSLTE_MOD_BPSK, + SRSLTE_MOD_QPSK, + SRSLTE_MOD_16QAM, + SRSLTE_MOD_64QAM, + SRSLTE_MOD_256QAM}; typedef struct { /* Thread identifier: they must set before thread creation */ pthread_t pthread; - uint32_t tb_idx; - void *pdsch_ptr; - bool *ack; + uint32_t tb_idx; + void* pdsch_ptr; + bool* ack; /* Configuration Encoder/Decoder: they must be set before posting start semaphore */ srslte_dl_sf_cfg_t* sf; @@ -62,7 +64,7 @@ typedef struct { srslte_sch_t dl_sch; /* Encoder/Decoder data pointers: they must be set before posting start semaphore */ - uint8_t *data; + uint8_t* data; /* Execution status */ int ret_status; @@ -76,7 +78,7 @@ typedef struct { bool quit; } srslte_pdsch_coworker_t; -static void *srslte_pdsch_decode_thread (void *arg); +static void* srslte_pdsch_decode_thread(void* arg); int srslte_pdsch_cp(srslte_pdsch_t* q, cf_t* input, @@ -88,18 +90,18 @@ int srslte_pdsch_cp(srslte_pdsch_t* q, { uint32_t s, n, l, lp, lstart, nof_refs; bool skip_symbol; - cf_t *in_ptr = input, *out_ptr = output; + cf_t * in_ptr = input, *out_ptr = output; uint32_t offset = 0; #ifdef DEBUG_IDX indices_ptr = 0; if (put) { - offset_original = output; + offset_original = output; } else { - offset_original = input; + offset_original = input; } #endif - + if (q->cell.nof_ports == 1) { nof_refs = 2; } else { @@ -144,11 +146,9 @@ int srslte_pdsch_cp(srslte_pdsch_t* q, } lp = l + s * grant->nof_symb_slot[0]; if (put) { - out_ptr = &output[(lp * q->cell.nof_prb + n) - * SRSLTE_NRE]; + out_ptr = &output[(lp * q->cell.nof_prb + n) * SRSLTE_NRE]; } else { - in_ptr = &input[(lp * q->cell.nof_prb + n) - * SRSLTE_NRE]; + in_ptr = &input[(lp * q->cell.nof_prb + n) * SRSLTE_NRE]; } // This is a symbol in a normal PRB with or without references if (!skip_symbol) { @@ -172,7 +172,7 @@ int srslte_pdsch_cp(srslte_pdsch_t* q, if ((q->cell.nof_prb % 2) && skip_symbol) { if (n == q->cell.nof_prb / 2 - 3) { if (SRSLTE_SYMBOL_HAS_REF(l, q->cell.cp, q->cell.nof_ports)) { - prb_cp_ref(&in_ptr, &out_ptr, offset, nof_refs, nof_refs/2, put); + prb_cp_ref(&in_ptr, &out_ptr, offset, nof_refs, nof_refs / 2, put); } else { prb_cp_half(&in_ptr, &out_ptr, 1); } @@ -183,7 +183,7 @@ int srslte_pdsch_cp(srslte_pdsch_t* q, in_ptr += 6; } if (SRSLTE_SYMBOL_HAS_REF(l, q->cell.cp, q->cell.nof_ports)) { - prb_cp_ref(&in_ptr, &out_ptr, offset, nof_refs, nof_refs/2, put); + prb_cp_ref(&in_ptr, &out_ptr, offset, nof_refs, nof_refs / 2, put); } else { prb_cp_half(&in_ptr, &out_ptr, 1); } @@ -196,9 +196,9 @@ int srslte_pdsch_cp(srslte_pdsch_t* q, int r; if (put) { - r = abs((int) (input - in_ptr)); + r = abs((int)(input - in_ptr)); } else { - r = abs((int) (output - out_ptr)); + r = abs((int)(output - out_ptr)); } return r; @@ -211,8 +211,12 @@ int srslte_pdsch_cp(srslte_pdsch_t* q, * * 36.211 10.3 section 6.3.5 */ -int srslte_pdsch_put( - srslte_pdsch_t* q, cf_t* symbols, cf_t* sf_symbols, srslte_pdsch_grant_t* grant, uint32_t lstart, uint32_t subframe) +int srslte_pdsch_put(srslte_pdsch_t* q, + cf_t* symbols, + cf_t* sf_symbols, + srslte_pdsch_grant_t* grant, + uint32_t lstart, + uint32_t subframe) { return srslte_pdsch_cp(q, symbols, sf_symbols, grant, lstart, subframe, true); } @@ -224,23 +228,26 @@ int srslte_pdsch_put( * * 36.211 10.3 section 6.3.5 */ -int srslte_pdsch_get( - srslte_pdsch_t* q, cf_t* sf_symbols, cf_t* symbols, srslte_pdsch_grant_t* grant, uint32_t lstart, uint32_t subframe) +int srslte_pdsch_get(srslte_pdsch_t* q, + cf_t* sf_symbols, + cf_t* symbols, + srslte_pdsch_grant_t* grant, + uint32_t lstart, + uint32_t subframe) { return srslte_pdsch_cp(q, sf_symbols, symbols, grant, lstart, subframe, false); } /** Initializes the PDSCH transmitter and receiver */ -static int pdsch_init(srslte_pdsch_t *q, uint32_t max_prb, bool is_ue, uint32_t nof_antennas) +static int pdsch_init(srslte_pdsch_t* q, uint32_t max_prb, bool is_ue, uint32_t nof_antennas) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL) - { - + if (q != NULL) { + bzero(q, sizeof(srslte_pdsch_t)); ret = SRSLTE_ERROR; - + q->max_re = max_prb * MAX_PDSCH_RE(q->cell.cp); q->is_ue = is_ue; q->nof_rx_antennas = nof_antennas; @@ -291,7 +298,7 @@ static int pdsch_init(srslte_pdsch_t *q, uint32_t max_prb, bool is_ue, uint32_t } } - q->users = calloc(sizeof(srslte_pdsch_user_t*), q->is_ue?1:(1+SRSLTE_SIRNTI)); + q->users = calloc(sizeof(srslte_pdsch_user_t*), q->is_ue ? 1 : (1 + SRSLTE_SIRNTI)); if (!q->users) { ERROR("malloc"); goto clean; @@ -320,18 +327,19 @@ clean: return ret; } -int srslte_pdsch_init_ue(srslte_pdsch_t *q, uint32_t max_prb, uint32_t nof_antennas) +int srslte_pdsch_init_ue(srslte_pdsch_t* q, uint32_t max_prb, uint32_t nof_antennas) { return pdsch_init(q, max_prb, true, nof_antennas); } -int srslte_pdsch_init_enb(srslte_pdsch_t *q, uint32_t max_prb) +int srslte_pdsch_init_enb(srslte_pdsch_t* q, uint32_t max_prb) { return pdsch_init(q, max_prb, false, 0); } -static void srslte_pdsch_disable_coworker(srslte_pdsch_t *q) { - srslte_pdsch_coworker_t *h = (srslte_pdsch_coworker_t *) q->coworker_ptr; +static void srslte_pdsch_disable_coworker(srslte_pdsch_t* q) +{ + srslte_pdsch_coworker_t* h = (srslte_pdsch_coworker_t*)q->coworker_ptr; if (h) { /* Stop threads */ h->quit = true; @@ -388,7 +396,8 @@ clean: return ret; } -void srslte_pdsch_free(srslte_pdsch_t *q) { +void srslte_pdsch_free(srslte_pdsch_t* q) +{ srslte_pdsch_disable_coworker(q); for (int i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { @@ -428,7 +437,7 @@ void srslte_pdsch_free(srslte_pdsch_t *q) { if (q->is_ue) { srslte_pdsch_free_rnti(q, 0); } else { - for (int u=0;u<=SRSLTE_SIRNTI;u++) { + for (int u = 0; u <= SRSLTE_SIRNTI; u++) { if (q->users[u]) { srslte_pdsch_free_rnti(q, u); } @@ -446,7 +455,7 @@ void srslte_pdsch_free(srslte_pdsch_t *q) { bzero(q, sizeof(srslte_pdsch_t)); } -int srslte_pdsch_set_cell(srslte_pdsch_t *q, srslte_cell_t cell) +int srslte_pdsch_set_cell(srslte_pdsch_t* q, srslte_cell_t cell) { int ret = SRSLTE_ERROR_INVALID_INPUTS; @@ -455,7 +464,10 @@ int srslte_pdsch_set_cell(srslte_pdsch_t *q, srslte_cell_t cell) q->max_re = q->cell.nof_prb * MAX_PDSCH_RE(q->cell.cp); INFO("PDSCH: Cell config PCI=%d, %d ports, %d PRBs, max_symbols: %d\n", - q->cell.id, q->cell.nof_ports, q->cell.nof_prb, q->max_re); + q->cell.id, + q->cell.nof_ports, + q->cell.nof_prb, + q->max_re); ret = SRSLTE_SUCCESS; } @@ -465,8 +477,9 @@ int srslte_pdsch_set_cell(srslte_pdsch_t *q, srslte_cell_t cell) /* Precalculate the PDSCH scramble sequences for a given RNTI. This function takes a while * to execute, so shall be called once the final C-RNTI has been allocated for the session. */ -int srslte_pdsch_set_rnti(srslte_pdsch_t *q, uint16_t rnti) { - uint32_t rnti_idx = q->is_ue?0:rnti; +int srslte_pdsch_set_rnti(srslte_pdsch_t* q, uint16_t rnti) +{ + uint32_t rnti_idx = q->is_ue ? 0 : rnti; if (!q->users[rnti_idx] || q->is_ue) { if (!q->users[rnti_idx]) { @@ -493,7 +506,7 @@ int srslte_pdsch_set_rnti(srslte_pdsch_t *q, uint16_t rnti) { } } q->ue_rnti = rnti; - q->users[rnti_idx]->cell_id = q->cell.id; + q->users[rnti_idx]->cell_id = q->cell.id; q->users[rnti_idx]->sequence_generated = true; } else { ERROR("Error generating PDSCH sequence: rnti=0x%x already generated\n", rnti); @@ -503,7 +516,7 @@ int srslte_pdsch_set_rnti(srslte_pdsch_t *q, uint16_t rnti) { void srslte_pdsch_free_rnti(srslte_pdsch_t* q, uint16_t rnti) { - uint32_t rnti_idx = q->is_ue?0:rnti; + uint32_t rnti_idx = q->is_ue ? 0 : rnti; if (q->users[rnti_idx]) { for (int i = 0; i < SRSLTE_NOF_SF_X_FRAME; i++) { for (int j = 0; j < SRSLTE_MAX_CODEWORDS; j++) { @@ -512,7 +525,7 @@ void srslte_pdsch_free_rnti(srslte_pdsch_t* q, uint16_t rnti) } free(q->users[rnti_idx]); q->users[rnti_idx] = NULL; - q->ue_rnti = 0; + q->ue_rnti = 0; } } static float apply_power_allocation(srslte_pdsch_t* q, srslte_pdsch_cfg_t* cfg, cf_t* sf_symbols_m[SRSLTE_MAX_PORTS]) @@ -553,17 +566,14 @@ static float apply_power_allocation(srslte_pdsch_t* q, srslte_pdsch_cfg_t* cfg, return rho_a; } -static srslte_sequence_t *get_user_sequence(srslte_pdsch_t *q, uint16_t rnti, - uint32_t codeword_idx, uint32_t sf_idx, uint32_t len) +static srslte_sequence_t* +get_user_sequence(srslte_pdsch_t* q, uint16_t rnti, uint32_t codeword_idx, uint32_t sf_idx, uint32_t len) { - uint32_t rnti_idx = q->is_ue?0:rnti; + uint32_t rnti_idx = q->is_ue ? 0 : rnti; // The scrambling sequence is pregenerated for all RNTIs in the eNodeB but only for C-RNTI in the UE - if (q->users[rnti_idx] && - q->users[rnti_idx]->sequence_generated && - q->users[rnti_idx]->cell_id == q->cell.id && - (!q->is_ue || q->ue_rnti == rnti)) - { + if (q->users[rnti_idx] && q->users[rnti_idx]->sequence_generated && q->users[rnti_idx]->cell_id == q->cell.id && + (!q->is_ue || q->ue_rnti == rnti)) { return &q->users[rnti_idx]->seq[codeword_idx][sf_idx]; } else { srslte_sequence_pdsch(&q->tmp_seq, rnti, codeword_idx, 2 * sf_idx, q->cell.id, len); @@ -571,7 +581,7 @@ static srslte_sequence_t *get_user_sequence(srslte_pdsch_t *q, uint16_t rnti, } } -static void csi_correction(srslte_pdsch_t *q, srslte_pdsch_cfg_t *cfg, uint32_t codeword_idx, uint32_t tb_idx, void *e) +static void csi_correction(srslte_pdsch_t* q, srslte_pdsch_cfg_t* cfg, uint32_t codeword_idx, uint32_t tb_idx, void* e) { uint32_t qm = 0; @@ -597,18 +607,18 @@ static void csi_correction(srslte_pdsch_t *q, srslte_pdsch_cfg_t *cfg, uint32_t } const uint32_t csi_max_idx = srslte_vec_max_fi(q->csi[codeword_idx], cfg->grant.tb[tb_idx].nof_bits / qm); - float csi_max = 1.0f; + float csi_max = 1.0f; if (csi_max_idx < cfg->grant.tb[tb_idx].nof_bits / qm) { csi_max = q->csi[codeword_idx][csi_max_idx]; } - int8_t *e_b = e; - int16_t *e_s = e; - float* csi_v = q->csi[codeword_idx]; + int8_t* e_b = e; + int16_t* e_s = e; + float* csi_v = q->csi[codeword_idx]; if (q->llr_is_8bit) { for (int i = 0; i < cfg->grant.tb[tb_idx].nof_bits / qm; i++) { const float csi = *(csi_v++) / csi_max; for (int k = 0; k < qm; k++) { - *e_b = (int8_t) ((float) *e_b * csi); + *e_b = (int8_t)((float)*e_b * csi); e_b++; } } @@ -624,7 +634,7 @@ static void csi_correction(srslte_pdsch_t *q, srslte_pdsch_cfg_t *cfg, uint32_t for (; i < cfg->grant.tb[tb_idx].nof_bits - 3; i += 4) { __m128 _csi1 = _mm_set1_ps(*(csi_v++)); __m128 _csi2 = _mm_set1_ps(*(csi_v++)); - _csi1 = _mm_blend_ps(_csi1, _csi2, 3); + _csi1 = _mm_blend_ps(_csi1, _csi2, 3); _csi1 = _mm_mul_ps(_csi1, _csi_scale); @@ -647,8 +657,8 @@ static void csi_correction(srslte_pdsch_t *q, srslte_pdsch_cfg_t *cfg, uint32_t __m128 _csi1 = _mm_set1_ps(*(csi_v++)); __m128 _csi3 = _mm_set1_ps(*(csi_v++)); - _csi1 = _mm_mul_ps(_csi1, _csi_scale); - _csi3 = _mm_mul_ps(_csi3, _csi_scale); + _csi1 = _mm_mul_ps(_csi1, _csi_scale); + _csi3 = _mm_mul_ps(_csi3, _csi_scale); __m128 _csi2 = _mm_blend_ps(_csi1, _csi3, 3); _e[0] = _mm_mulhi_pi16(_e[0], _mm_cvtps_pi16(_csi1)); @@ -678,7 +688,7 @@ static void csi_correction(srslte_pdsch_t *q, srslte_pdsch_cfg_t *cfg, uint32_t for (; i < cfg->grant.tb[tb_idx].nof_bits / qm; i++) { const float csi = q->csi[codeword_idx][i] / csi_max; for (int k = 0; k < qm; k++) { - e_s[qm * i + k] = (int16_t) ((float) e_s[qm * i + k] * csi); + e_s[qm * i + k] = (int16_t)((float)e_s[qm * i + k] * csi); } } } @@ -789,10 +799,10 @@ static int srslte_pdsch_codeword_decode(srslte_pdsch_t* q, *ack = true; } else if (ret == SRSLTE_ERROR) { *ack = false; - ret = SRSLTE_SUCCESS; + ret = SRSLTE_SUCCESS; } else if (ret == SRSLTE_ERROR_INVALID_INPUTS) { *ack = false; - ret = SRSLTE_ERROR; + ret = SRSLTE_ERROR; } } else { ERROR("Invalid parameters in TB%d &softbuffer=%p &data=%p &ack=%p, nbits=%d, nof_re=%d\n", @@ -807,8 +817,9 @@ static int srslte_pdsch_codeword_decode(srslte_pdsch_t* q, return ret; } -static void *srslte_pdsch_decode_thread(void *arg) { - srslte_pdsch_coworker_t *q = (srslte_pdsch_coworker_t *) arg; +static void* srslte_pdsch_decode_thread(void* arg) +{ + srslte_pdsch_coworker_t* q = (srslte_pdsch_coworker_t*)arg; INFO("[PDSCH Coworker] waiting for data\n"); @@ -876,7 +887,7 @@ int srslte_pdsch_decode(srslte_pdsch_t* q, // Extract Symbols and Channel Estimates uint32_t lstart = SRSLTE_NOF_CTRL_SYMBOLS(q->cell, sf->cfi); - for (int j=0;jnof_rx_antennas;j++) { + for (int j = 0; j < q->nof_rx_antennas; j++) { int n = srslte_pdsch_get(q, sf_symbols[j], q->symbols[j], &cfg->grant, lstart, sf->tti % 10); if (n != cfg->grant.nof_re) { ERROR("Error expecting %d symbols but got %d\n", cfg->grant.nof_re, n); @@ -893,7 +904,7 @@ int srslte_pdsch_decode(srslte_pdsch_t* q, } // Prepare layers - int nof_symbols [SRSLTE_MAX_CODEWORDS]; + int nof_symbols[SRSLTE_MAX_CODEWORDS]; nof_symbols[0] = cfg->grant.nof_re * nof_tb / cfg->grant.nof_layers; nof_symbols[1] = cfg->grant.nof_re * nof_tb / cfg->grant.nof_layers; @@ -941,16 +952,16 @@ int srslte_pdsch_decode(srslte_pdsch_t* q, if (!data[tb_idx].crc) { int ret = SRSLTE_SUCCESS; if (cfg->grant.nof_tb > 1 && tb_idx == 0 && q->coworker_ptr) { - srslte_pdsch_coworker_t *h = (srslte_pdsch_coworker_t *) q->coworker_ptr; + srslte_pdsch_coworker_t* h = (srslte_pdsch_coworker_t*)q->coworker_ptr; - h->pdsch_ptr = q; - h->cfg = cfg; + h->pdsch_ptr = q; + h->cfg = cfg; h->sf = sf; h->data = data[tb_idx].payload; - h->tb_idx = tb_idx; + h->tb_idx = tb_idx; h->ack = &data[tb_idx].crc; h->dl_sch.max_iterations = q->dl_sch.max_iterations; - h->started = true; + h->started = true; sem_post(&h->start); } else { @@ -1066,7 +1077,7 @@ int srslte_pdsch_encode(srslte_pdsch_t* q, int i; /* Set pointers for layermapping & precoding */ cf_t* x[SRSLTE_MAX_LAYERS]; - int ret = SRSLTE_ERROR_INVALID_INPUTS; + int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL && cfg != NULL) { struct timeval t[3]; diff --git a/lib/src/phy/phch/phich.c b/lib/src/phy/phch/phich.c index 822db881c..ec838e707 100644 --- a/lib/src/phy/phch/phich.c +++ b/lib/src/phy/phch/phich.c @@ -19,44 +19,50 @@ * */ +#include +#include +#include +#include #include #include +#include #include #include -#include -#include -#include -#include -#include -#include "srslte/phy/phch/regs.h" -#include "srslte/phy/phch/phich.h" #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/phch/phich.h" +#include "srslte/phy/phch/regs.h" #include "srslte/phy/utils/bit.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" /** Table 6.9.1-2 */ -const cf_t w_normal[SRSLTE_PHICH_NORM_NSEQUENCES][4] = { { 1, 1, 1, 1 }, - { 1, -1, 1, -1 }, { 1, 1, -1, -1 }, { 1, -1, -1, 1 }, { I, I, I, I }, { - I, -I, I, -I }, { I, I, -I, -I }, { I, -I, -I, I } }; -const cf_t w_ext[SRSLTE_PHICH_EXT_NSEQUENCES][2] = { { 1, 1 }, { 1, -1 }, { I, I }, { -I, -I } }; - - -uint32_t srslte_phich_ngroups(srslte_phich_t *q) { +const cf_t w_normal[SRSLTE_PHICH_NORM_NSEQUENCES][4] = {{1, 1, 1, 1}, + {1, -1, 1, -1}, + {1, 1, -1, -1}, + {1, -1, -1, 1}, + {I, I, I, I}, + {I, -I, I, -I}, + {I, I, -I, -I}, + {I, -I, -I, I}}; +const cf_t w_ext[SRSLTE_PHICH_EXT_NSEQUENCES][2] = {{1, 1}, {1, -1}, {I, I}, {I, -I}}; + +uint32_t srslte_phich_ngroups(srslte_phich_t* q) +{ return srslte_regs_phich_ngroups(q->regs); } -uint32_t srslte_phich_nsf(srslte_phich_t *q) { +uint32_t srslte_phich_nsf(srslte_phich_t* q) +{ if (SRSLTE_CP_ISNORM(q->cell.cp)) { return SRSLTE_PHICH_NORM_NSF; } else { - return SRSLTE_PHICH_EXT_NSF; + return SRSLTE_PHICH_EXT_NSF; } } -void srslte_phich_reset(srslte_phich_t *q, cf_t *slot_symbols[SRSLTE_MAX_PORTS]) { +void srslte_phich_reset(srslte_phich_t* q, cf_t* slot_symbols[SRSLTE_MAX_PORTS]) +{ int i; for (i = 0; i < SRSLTE_MAX_PORTS; i++) { srslte_regs_phich_reset(q->regs, slot_symbols[i]); @@ -64,31 +70,31 @@ void srslte_phich_reset(srslte_phich_t *q, cf_t *slot_symbols[SRSLTE_MAX_PORTS]) } /** Initializes the phich channel receiver */ -int srslte_phich_init(srslte_phich_t *q, uint32_t nof_rx_antennas) +int srslte_phich_init(srslte_phich_t* q, uint32_t nof_rx_antennas) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - - if (q != NULL) - { + + if (q != NULL) { bzero(q, sizeof(srslte_phich_t)); ret = SRSLTE_ERROR; - + q->nof_rx_antennas = nof_rx_antennas; - + if (srslte_modem_table_lte(&q->mod, SRSLTE_MOD_BPSK)) { goto clean; } ret = SRSLTE_SUCCESS; } - clean: +clean: if (ret == SRSLTE_ERROR) { srslte_phich_free(q); } return ret; } -void srslte_phich_free(srslte_phich_t *q) { +void srslte_phich_free(srslte_phich_t* q) +{ for (int ns = 0; ns < SRSLTE_NOF_SF_X_FRAME; ns++) { srslte_sequence_free(&q->seq[ns]); } @@ -102,14 +108,11 @@ void srslte_phich_set_regs(srslte_phich_t* q, srslte_regs_t* regs) q->regs = regs; } -int srslte_phich_set_cell(srslte_phich_t *q, srslte_regs_t *regs, srslte_cell_t cell) +int srslte_phich_set_cell(srslte_phich_t* q, srslte_regs_t* regs, srslte_cell_t cell) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - regs != NULL && - srslte_cell_isvalid(&cell)) - { + if (q != NULL && regs != NULL && srslte_cell_isvalid(&cell)) { q->regs = regs; @@ -126,8 +129,6 @@ int srslte_phich_set_cell(srslte_phich_t *q, srslte_regs_t *regs, srslte_cell_t return ret; } - - /* Computes n_group and n_seq according to Section 9.1.2 in 36.213 */ void srslte_phich_calc(srslte_phich_t* q, srslte_phich_grant_t* grant, srslte_phich_resource_t* n_phich) { @@ -142,39 +143,40 @@ void srslte_phich_calc(srslte_phich_t* q, srslte_phich_grant_t* grant, srslte_ph } } - /* Decodes ACK * */ -uint8_t srslte_phich_ack_decode(float bits[SRSLTE_PHICH_NBITS], float *distance) { - int i; - float ack_table[2][3] = {{-1.0, -1.0, -1.0}, {1.0, 1.0, 1.0}}; - float max_corr = -9999; - uint8_t index=0; - +uint8_t srslte_phich_ack_decode(float bits[SRSLTE_PHICH_NBITS], float* distance) +{ + int i; + float ack_table[2][3] = {{-1.0, -1.0, -1.0}, {1.0, 1.0, 1.0}}; + float max_corr = -9999; + uint8_t index = 0; + if (SRSLTE_VERBOSE_ISINFO()) { INFO("Received bits: "); srslte_vec_fprint_f(stdout, bits, SRSLTE_PHICH_NBITS); } - + for (i = 0; i < 2; i++) { float corr = srslte_vec_dot_prod_fff(ack_table[i], bits, SRSLTE_PHICH_NBITS) / SRSLTE_PHICH_NBITS; INFO("Corr%d=%f\n", i, corr); if (corr > max_corr) { - max_corr = corr; + max_corr = corr; if (distance) { *distance = max_corr; } - index = i; + index = i; } - } + } return index; } /** Encodes the ACK * 36.212 */ -void srslte_phich_ack_encode(uint8_t ack, uint8_t bits[SRSLTE_PHICH_NBITS]) { +void srslte_phich_ack_encode(uint8_t ack, uint8_t bits[SRSLTE_PHICH_NBITS]) +{ memset(bits, ack, 3 * sizeof(uint8_t)); } @@ -187,9 +189,9 @@ int srslte_phich_decode(srslte_phich_t* q, { /* Set pointers for layermapping & precoding */ - int i, j; - cf_t *x[SRSLTE_MAX_LAYERS]; - + int i, j; + cf_t* x[SRSLTE_MAX_LAYERS]; + if (q == NULL || sf_symbols == NULL) { return SRSLTE_ERROR_INVALID_INPUTS; } @@ -224,17 +226,17 @@ int srslte_phich_decode(srslte_phich_t* q, x[i] = q->x[i]; } - cf_t *q_ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; - cf_t *q_sf_symbols[SRSLTE_MAX_PORTS]; - + cf_t* q_ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; + cf_t* q_sf_symbols[SRSLTE_MAX_PORTS]; + /* extract symbols */ - for (int j=0;jnof_rx_antennas;j++) { + for (int j = 0; j < q->nof_rx_antennas; j++) { if (SRSLTE_PHICH_MAX_NSYMB != srslte_regs_phich_get(q->regs, sf_symbols[j], q->sf_symbols[j], n_phich.ngroup)) { ERROR("There was an error getting the phich symbols\n"); return SRSLTE_ERROR; - } - q_sf_symbols[j] = q->sf_symbols[j]; - + } + q_sf_symbols[j] = q->sf_symbols[j]; + /* extract channel estimates */ for (i = 0; i < q->cell.nof_ports; i++) { if (SRSLTE_PHICH_MAX_NSYMB != srslte_regs_phich_get(q->regs, channel->ce[i][j], q->ce[i][j], n_phich.ngroup)) { @@ -243,7 +245,6 @@ int srslte_phich_decode(srslte_phich_t* q, } q_ce[i][j] = q->ce[i][j]; } - } /* in control channels, only diversity is supported */ @@ -252,7 +253,8 @@ int srslte_phich_decode(srslte_phich_t* q, srslte_predecoding_single_multi( q_sf_symbols, q_ce[0], q->d0, NULL, q->nof_rx_antennas, SRSLTE_PHICH_MAX_NSYMB, 1.0f, channel->noise_estimate); } else { - srslte_predecoding_diversity_multi(q_sf_symbols, q_ce, x, NULL, q->nof_rx_antennas, q->cell.nof_ports, SRSLTE_PHICH_MAX_NSYMB, 1.0f); + srslte_predecoding_diversity_multi( + q_sf_symbols, q_ce, x, NULL, q->nof_rx_antennas, q->cell.nof_ports, SRSLTE_PHICH_MAX_NSYMB, 1.0f); srslte_layerdemap_diversity(x, q->d0, q->cell.nof_ports, SRSLTE_PHICH_MAX_NSYMB / q->cell.nof_ports); } DEBUG("Recv!!: \n"); @@ -351,8 +353,8 @@ int srslte_phich_encode(srslte_phich_t* q, } /* Set pointers for layermapping & precoding */ - cf_t *x[SRSLTE_MAX_LAYERS]; - cf_t *symbols_precoding[SRSLTE_MAX_PORTS]; + cf_t* x[SRSLTE_MAX_LAYERS]; + cf_t* symbols_precoding[SRSLTE_MAX_PORTS]; /* number of layers equals number of ports */ for (i = 0; i < q->cell.nof_ports; i++) { @@ -416,8 +418,8 @@ int srslte_phich_encode(srslte_phich_t* q, /* layer mapping & precoding */ if (q->cell.nof_ports > 1) { srslte_layermap_diversity(q->d0, x, q->cell.nof_ports, SRSLTE_PHICH_MAX_NSYMB); - srslte_precoding_diversity(x, symbols_precoding, q->cell.nof_ports, - SRSLTE_PHICH_MAX_NSYMB / q->cell.nof_ports, 1.0f); + srslte_precoding_diversity( + x, symbols_precoding, q->cell.nof_ports, SRSLTE_PHICH_MAX_NSYMB / q->cell.nof_ports, 1.0f); /**FIXME: According to 6.9.2, Precoding for 4 tx ports is different! */ } else { memcpy(q->sf_symbols[0], q->d0, SRSLTE_PHICH_MAX_NSYMB * sizeof(cf_t)); @@ -433,4 +435,3 @@ int srslte_phich_encode(srslte_phich_t* q, return SRSLTE_SUCCESS; } - diff --git a/lib/src/phy/phch/pmch.c b/lib/src/phy/phch/pmch.c index a5109ed1f..416459e43 100644 --- a/lib/src/phy/phch/pmch.c +++ b/lib/src/phy/phch/pmch.c @@ -19,14 +19,14 @@ * */ +#include +#include +#include #include #include +#include #include #include -#include -#include -#include -#include #include "prb_dl.h" #include "srslte/phy/common/phy_common.h" @@ -37,23 +37,22 @@ #define MAX_PMCH_RE (2 * SRSLTE_CP_EXT_NSYMB * 12) -const static srslte_mod_t modulations[4] = - { SRSLTE_MOD_BPSK, SRSLTE_MOD_QPSK, SRSLTE_MOD_16QAM, SRSLTE_MOD_64QAM }; +const static srslte_mod_t modulations[4] = {SRSLTE_MOD_BPSK, SRSLTE_MOD_QPSK, SRSLTE_MOD_16QAM, SRSLTE_MOD_64QAM}; static int pmch_cp(srslte_pmch_t* q, cf_t* input, cf_t* output, uint32_t lstart_grant, bool put) { uint32_t s, n, l, lp, lstart, lend, nof_refs; - cf_t *in_ptr = input, *out_ptr = output; + cf_t * in_ptr = input, *out_ptr = output; uint32_t offset = 0; - #ifdef DEBUG_IDX +#ifdef DEBUG_IDX indices_ptr = 0; if (put) { offset_original = output; } else { offset_original = input; } - #endif +#endif nof_refs = 6; for (s = 0; s < 2; s++) { for (l = 0; l < SRSLTE_CP_EXT_NSYMB; l++) { @@ -66,7 +65,7 @@ static int pmch_cp(srslte_pmch_t* q, cf_t* input, cf_t* output, uint32_t lstart_ lstart = 0; } lend = SRSLTE_CP_EXT_NSYMB; - lp = l + s * SRSLTE_CP_EXT_NSYMB; + lp = l + s * SRSLTE_CP_EXT_NSYMB; if (put) { out_ptr = &output[(lp * q->cell.nof_prb + n) * SRSLTE_NRE]; } else { @@ -74,7 +73,7 @@ static int pmch_cp(srslte_pmch_t* q, cf_t* input, cf_t* output, uint32_t lstart_ } // This is a symbol in a normal PRB with or without references if (l >= lstart && l < lend) { - if (SRSLTE_SYMBOL_HAS_REF_MBSFN(l,s)) { + if (SRSLTE_SYMBOL_HAS_REF_MBSFN(l, s)) { if (l == 0 && s == 1) { offset = 1; } else { @@ -92,9 +91,9 @@ static int pmch_cp(srslte_pmch_t* q, cf_t* input, cf_t* output, uint32_t lstart_ int r; if (put) { - r = abs((int) (input - in_ptr)); + r = abs((int)(input - in_ptr)); } else { - r = abs((int) (output - out_ptr)); + r = abs((int)(output - out_ptr)); } return r; @@ -128,20 +127,17 @@ int srslte_pmch_init(srslte_pmch_t* q, uint32_t max_prb, uint32_t nof_rx_antenna { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - nof_rx_antennas <= SRSLTE_MAX_PORTS) - { - + if (q != NULL && nof_rx_antennas <= SRSLTE_MAX_PORTS) { + bzero(q, sizeof(srslte_pmch_t)); ret = SRSLTE_ERROR; - - q->cell.nof_prb = max_prb; - q->cell.nof_ports = 1; - q->max_re = max_prb * MAX_PMCH_RE; - q->nof_rx_antennas = nof_rx_antennas; - - INFO("Init PMCH: %d PRBs, max_symbols: %d\n", - max_prb, q->max_re); + + q->cell.nof_prb = max_prb; + q->cell.nof_ports = 1; + q->max_re = max_prb * MAX_PMCH_RE; + q->nof_rx_antennas = nof_rx_antennas; + + INFO("Init PMCH: %d PRBs, max_symbols: %d\n", max_prb, q->max_re); for (int i = 0; i < 4; i++) { if (srslte_modem_table_lte(&q->mod[i], modulations[i])) { @@ -149,15 +145,15 @@ int srslte_pmch_init(srslte_pmch_t* q, uint32_t max_prb, uint32_t nof_rx_antenna } srslte_modem_table_bytes(&q->mod[i]); } - + srslte_sch_init(&q->dl_sch); - + // Allocate int16_t for reception (LLRs) q->e = srslte_vec_malloc(sizeof(int16_t) * q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM)); if (!q->e) { goto clean; } - + q->d = srslte_vec_malloc(sizeof(cf_t) * q->max_re); if (!q->d) { goto clean; @@ -168,36 +164,37 @@ int srslte_pmch_init(srslte_pmch_t* q, uint32_t max_prb, uint32_t nof_rx_antenna if (!q->x[i]) { goto clean; } - for (int j=0;jnof_rx_antennas;j++) { + for (int j = 0; j < q->nof_rx_antennas; j++) { q->ce[i][j] = srslte_vec_malloc(sizeof(cf_t) * q->max_re); if (!q->ce[i][j]) { goto clean; } } } - for (int j=0;jnof_rx_antennas;j++) { + for (int j = 0; j < q->nof_rx_antennas; j++) { q->symbols[j] = srslte_vec_malloc(sizeof(cf_t) * q->max_re); if (!q->symbols[j]) { goto clean; - } + } } - + q->seqs = calloc(SRSLTE_MAX_MBSFN_AREA_IDS, sizeof(srslte_pmch_seq_t*)); if (!q->seqs) { perror("calloc"); goto clean; } - + ret = SRSLTE_SUCCESS; } - clean: +clean: if (ret == SRSLTE_ERROR) { srslte_pmch_free(q); } return ret; } -void srslte_pmch_free(srslte_pmch_t *q) { +void srslte_pmch_free(srslte_pmch_t* q) +{ if (q->e) { free(q->e); } @@ -217,14 +214,14 @@ void srslte_pmch_free(srslte_pmch_t *q) { for (uint32_t i = 0; i < q->nof_rx_antennas; i++) { if (q->symbols[i]) { free(q->symbols[i]); - } + } } if (q->seqs) { for (uint32_t i = 0; i < SRSLTE_MAX_MBSFN_AREA_IDS; i++) { if (q->seqs[i]) { srslte_pmch_free_area_id(q, i); } - } + } free(q->seqs); } for (uint32_t i = 0; i < 4; i++) { @@ -234,21 +231,21 @@ void srslte_pmch_free(srslte_pmch_t *q) { srslte_sch_free(&q->dl_sch); bzero(q, sizeof(srslte_pmch_t)); - } -int srslte_pmch_set_cell(srslte_pmch_t *q, srslte_cell_t cell) +int srslte_pmch_set_cell(srslte_pmch_t* q, srslte_cell_t cell) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - srslte_cell_isvalid(&cell)) - { + if (q != NULL && srslte_cell_isvalid(&cell)) { q->cell = cell; q->max_re = q->cell.nof_prb * MAX_PMCH_RE; - INFO("PMCH: Cell config PCI=%d, %d ports, %d PRBs, max_symbols: %d\n", q->cell.nof_ports, - q->cell.id, q->cell.nof_prb, q->max_re); + INFO("PMCH: Cell config PCI=%d, %d ports, %d PRBs, max_symbols: %d\n", + q->cell.nof_ports, + q->cell.id, + q->cell.nof_prb, + q->max_re); ret = SRSLTE_SUCCESS; } @@ -258,13 +255,15 @@ int srslte_pmch_set_cell(srslte_pmch_t *q, srslte_cell_t cell) /* Precalculate the scramble sequences for a given MBSFN area ID. This function takes a while * to execute. */ -int srslte_pmch_set_area_id(srslte_pmch_t *q, uint16_t area_id) { - uint32_t i; +int srslte_pmch_set_area_id(srslte_pmch_t* q, uint16_t area_id) +{ + uint32_t i; if (!q->seqs[area_id]) { q->seqs[area_id] = calloc(1, sizeof(srslte_pmch_seq_t)); if (q->seqs[area_id]) { for (i = 0; i < SRSLTE_NOF_SF_X_FRAME; i++) { - if (srslte_sequence_pmch(&q->seqs[area_id]->seq[i], 2 * i , area_id, q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM))) { + if (srslte_sequence_pmch( + &q->seqs[area_id]->seq[i], 2 * i, area_id, q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM))) { return SRSLTE_ERROR; } } @@ -296,7 +295,7 @@ int srslte_pmch_decode(srslte_pmch_t* q, /* Set pointers for layermapping & precoding */ uint32_t i, n; - cf_t *x[SRSLTE_MAX_LAYERS]; + cf_t* x[SRSLTE_MAX_LAYERS]; if (q != NULL && sf_symbols != NULL && out != NULL && cfg != NULL) { INFO("Decoding PMCH SF: %d, MBSFN area ID: 0x%x, Mod %s, TBS: %d, NofSymbols: %d, NofBitsE: %d, rv_idx: %d, " @@ -373,7 +372,6 @@ int srslte_pmch_decode(srslte_pmch_t* q, /* descramble */ srslte_scrambling_s_offset(&q->seqs[cfg->area_id]->seq[sf->tti % 10], q->e, 0, cfg->pdsch_cfg.grant.tb[0].nof_bits); - if (SRSLTE_VERBOSE_ISDEBUG()) { DEBUG("SAVED FILE llr.dat: LLR estimates after demodulation and descrambling\n"); srslte_vec_save_file("llr.dat", q->e, cfg->pdsch_cfg.grant.tb[0].nof_bits * sizeof(int16_t)); @@ -388,19 +386,19 @@ int srslte_pmch_decode(srslte_pmch_t* q, } void srslte_configure_pmch(srslte_pmch_cfg_t* pmch_cfg, srslte_cell_t* cell, srslte_mbsfn_cfg_t* mbsfn_cfg) { - pmch_cfg->area_id = 1; + pmch_cfg->area_id = 1; pmch_cfg->pdsch_cfg.grant.nof_layers = 1; pmch_cfg->pdsch_cfg.grant.nof_prb = cell->nof_prb; pmch_cfg->pdsch_cfg.grant.tb[0].mcs_idx = mbsfn_cfg->mbsfn_mcs; pmch_cfg->pdsch_cfg.grant.tb[0].enabled = mbsfn_cfg->enable; pmch_cfg->pdsch_cfg.grant.tb[0].rv = SRSLTE_PMCH_RV; - pmch_cfg->pdsch_cfg.grant.last_tbs[0] = 0; + pmch_cfg->pdsch_cfg.grant.last_tbs[0] = 0; srslte_dl_fill_ra_mcs(&pmch_cfg->pdsch_cfg.grant.tb[0], pmch_cfg->pdsch_cfg.grant.last_tbs[0], pmch_cfg->pdsch_cfg.grant.nof_prb, false); - pmch_cfg->pdsch_cfg.grant.nof_tb = 1; - pmch_cfg->pdsch_cfg.grant.nof_layers = 1; + pmch_cfg->pdsch_cfg.grant.nof_tb = 1; + pmch_cfg->pdsch_cfg.grant.nof_layers = 1; for (int i = 0; i < 2; i++) { for (uint32_t j = 0; j < pmch_cfg->pdsch_cfg.grant.nof_prb; j++) { pmch_cfg->pdsch_cfg.grant.prb_idx[i][j] = true; @@ -408,13 +406,16 @@ void srslte_configure_pmch(srslte_pmch_cfg_t* pmch_cfg, srslte_cell_t* cell, srs } } -int srslte_pmch_encode( - srslte_pmch_t* q, srslte_dl_sf_cfg_t* sf, srslte_pmch_cfg_t* cfg, uint8_t* data, cf_t* sf_symbols[SRSLTE_MAX_PORTS]) +int srslte_pmch_encode(srslte_pmch_t* q, + srslte_dl_sf_cfg_t* sf, + srslte_pmch_cfg_t* cfg, + uint8_t* data, + cf_t* sf_symbols[SRSLTE_MAX_PORTS]) { int i; /* Set pointers for layermapping & precoding */ - cf_t *x[SRSLTE_MAX_LAYERS]; + cf_t* x[SRSLTE_MAX_LAYERS]; int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL && cfg != NULL) { for (i = 0; i < q->cell.nof_ports; i++) { @@ -424,7 +425,7 @@ int srslte_pmch_encode( } if (cfg->pdsch_cfg.grant.tb[0].tbs == 0) { - return SRSLTE_ERROR_INVALID_INPUTS; + return SRSLTE_ERROR_INVALID_INPUTS; } if (cfg->pdsch_cfg.grant.nof_re > q->max_re) { @@ -470,12 +471,8 @@ int srslte_pmch_encode( for (i = 0; i < q->cell.nof_ports; i++) { pmch_put(q, q->symbols[i], sf_symbols[i], lstart); } - + ret = SRSLTE_SUCCESS; - } - return ret; + } + return ret; } - - - - diff --git a/lib/src/phy/phch/prach.c b/lib/src/phy/phch/prach.c index 97fb04441..7961f91fb 100644 --- a/lib/src/phy/phch/prach.c +++ b/lib/src/phy/phch/prach.c @@ -32,19 +32,19 @@ float save_corr[4096]; -//PRACH detection threshold is PRACH_DETECT_FACTOR*average +// PRACH detection threshold is PRACH_DETECT_FACTOR*average #define PRACH_DETECT_FACTOR 18 -#define N_SEQS 64 // Number of prach sequences available -#define N_RB_SC 12 // Number of subcarriers per resource block -#define DELTA_F 15000 // Normal subcarrier spacing -#define DELTA_F_RA 1250 // PRACH subcarrier spacing -#define DELTA_F_RA_4 7500 // PRACH subcarrier spacing for format 4 -#define PHI 7 // PRACH phi parameter -#define PHI_4 2 // PRACH phi parameter for format 4 -#define MAX_ROOTS 838 // Max number of root sequences +#define N_SEQS 64 // Number of prach sequences available +#define N_RB_SC 12 // Number of subcarriers per resource block +#define DELTA_F 15000 // Normal subcarrier spacing +#define DELTA_F_RA 1250 // PRACH subcarrier spacing +#define DELTA_F_RA_4 7500 // PRACH subcarrier spacing for format 4 +#define PHI 7 // PRACH phi parameter +#define PHI_4 2 // PRACH phi parameter for format 4 +#define MAX_ROOTS 838 // Max number of root sequences -#define PRACH_AMP 1.0 +#define PRACH_AMP 1.0 int srslte_prach_set_cell_(srslte_prach_t* p, uint32_t N_ifft_ul, @@ -54,11 +54,13 @@ int srslte_prach_set_cell_(srslte_prach_t* p, uint32_t zero_corr_zone_config, srslte_tdd_config_t* tdd_config); -uint32_t srslte_prach_get_preamble_format(uint32_t config_idx) { +uint32_t srslte_prach_get_preamble_format(uint32_t config_idx) +{ return config_idx / 16; } -srslte_prach_sfn_t srslte_prach_get_sfn(uint32_t config_idx) { +srslte_prach_sfn_t srslte_prach_get_sfn(uint32_t config_idx) +{ if ((config_idx % 16) < 3 || (config_idx % 16) == 15) { return SRSLTE_PRACH_SFN_EVEN; } else { @@ -66,10 +68,11 @@ srslte_prach_sfn_t srslte_prach_get_sfn(uint32_t config_idx) { } } -/* Returns true if current_tti is a valid opportunity for PRACH transmission and the is an allowed subframe, +/* Returns true if current_tti is a valid opportunity for PRACH transmission and the is an allowed subframe, * or allowed_subframe == -1 */ -bool srslte_prach_tti_opportunity(srslte_prach_t *p, uint32_t current_tti, int allowed_subframe) { +bool srslte_prach_tti_opportunity(srslte_prach_t* p, uint32_t current_tti, int allowed_subframe) +{ uint32_t config_idx = p->config_idx; if (!p->tdd_config.configured) { return srslte_prach_tti_opportunity_config_fdd(config_idx, current_tti, allowed_subframe); @@ -89,8 +92,7 @@ bool srslte_prach_tti_opportunity_config_fdd(uint32_t config_idx, uint32_t curre return true; } - if ((prach_sfn == SRSLTE_PRACH_SFN_EVEN && ((current_tti / 10) % 2) == 0) || - prach_sfn == SRSLTE_PRACH_SFN_ANY) { + if ((prach_sfn == SRSLTE_PRACH_SFN_EVEN && ((current_tti / 10) % 2) == 0) || prach_sfn == SRSLTE_PRACH_SFN_ANY) { srslte_prach_sf_config_t sf_config; srslte_prach_sf_config(config_idx, &sf_config); for (int i = 0; i < sf_config.nof_sf; i++) { @@ -209,30 +211,33 @@ bool srslte_prach_tti_opportunity_config_tdd(uint32_t config_idx, return false; } -void srslte_prach_sf_config(uint32_t config_idx, srslte_prach_sf_config_t *sf_config) { +void srslte_prach_sf_config(uint32_t config_idx, srslte_prach_sf_config_t* sf_config) +{ memcpy(sf_config, &prach_sf_config[config_idx % 16], sizeof(srslte_prach_sf_config_t)); } // For debug use only -void print(void *d, uint32_t size, uint32_t len, char *file_str) { - FILE *f; +void print(void* d, uint32_t size, uint32_t len, char* file_str) +{ + FILE* f; f = fopen(file_str, "wb"); fwrite(d, size, len, f); fclose(f); } -int srslte_prach_gen_seqs(srslte_prach_t *p) { - uint32_t u = 0; - uint32_t v = 1; - int v_max = 0; - uint32_t p_ = 0; - uint32_t d_u = 0; - uint32_t d_start = 0; - uint32_t N_shift = 0; - int N_neg_shift = 0; - uint32_t N_group = 0; - uint32_t C_v = 0; - cf_t root[839]; +int srslte_prach_gen_seqs(srslte_prach_t* p) +{ + uint32_t u = 0; + uint32_t v = 1; + int v_max = 0; + uint32_t p_ = 0; + uint32_t d_u = 0; + uint32_t d_start = 0; + uint32_t N_shift = 0; + int N_neg_shift = 0; + uint32_t N_group = 0; + uint32_t C_v = 0; + cf_t root[839]; // Generate our 64 preamble sequences for (int i = 0; i < N_SEQS; i++) { @@ -247,7 +252,7 @@ int srslte_prach_gen_seqs(srslte_prach_t *p) { for (int j = 0; j < p->N_zc; j++) { double phase = -M_PI * u * j * (j + 1) / p->N_zc; - root[j] = cexp(phase * I); + root[j] = cexp(phase * I); } p->root_seqs_idx[p->N_roots++] = i; @@ -332,18 +337,18 @@ int srslte_prach_set_cfg(srslte_prach_t* p, srslte_prach_cfg_t* cfg, uint32_t no &cfg->tdd_config); } -int srslte_prach_init(srslte_prach_t *p, uint32_t max_N_ifft_ul) { +int srslte_prach_init(srslte_prach_t* p, uint32_t max_N_ifft_ul) +{ int ret = SRSLTE_ERROR; - if (p != NULL && - max_N_ifft_ul < 2049) { + if (p != NULL && max_N_ifft_ul < 2049) { bzero(p, sizeof(srslte_prach_t)); p->max_N_ifft_ul = max_N_ifft_ul; // Set up containers p->prach_bins = srslte_vec_malloc(sizeof(cf_t) * MAX_N_zc); - p->corr_spec = srslte_vec_malloc(sizeof(cf_t) * MAX_N_zc); - p->corr = srslte_vec_malloc(sizeof(float) * MAX_N_zc); + p->corr_spec = srslte_vec_malloc(sizeof(cf_t) * MAX_N_zc); + p->corr = srslte_vec_malloc(sizeof(float) * MAX_N_zc); // Set up ZC FFTS if (srslte_dft_plan(&p->zc_fft, MAX_N_zc, SRSLTE_DFT_FORWARD, SRSLTE_DFT_COMPLEX)) { @@ -361,7 +366,7 @@ int srslte_prach_init(srslte_prach_t *p, uint32_t max_N_ifft_ul) { uint32_t fft_size_alloc = max_N_ifft_ul * DELTA_F / DELTA_F_RA; p->ifft_in = (cf_t*)srslte_vec_malloc(fft_size_alloc * sizeof(cf_t)); - p->ifft_out = (cf_t *) srslte_vec_malloc(fft_size_alloc * sizeof(cf_t)); + p->ifft_out = (cf_t*)srslte_vec_malloc(fft_size_alloc * sizeof(cf_t)); if (srslte_dft_plan(&p->ifft, fft_size_alloc, SRSLTE_DFT_BACKWARD, SRSLTE_DFT_COMPLEX)) { ERROR("Error creating DFT plan\n"); return -1; @@ -400,22 +405,19 @@ int srslte_prach_set_cell_(srslte_prach_t* p, srslte_tdd_config_t* tdd_config) { int ret = SRSLTE_ERROR; - if (p != NULL && - N_ifft_ul < 2049 && - config_idx < 64 && - root_seq_index < MAX_ROOTS) { + if (p != NULL && N_ifft_ul < 2049 && config_idx < 64 && root_seq_index < MAX_ROOTS) { if (N_ifft_ul > p->max_N_ifft_ul) { ERROR("PRACH: Error in set_cell(): N_ifft_ul must be lower or equal max_N_ifft_ul in init()\n"); return -1; } uint32_t preamble_format = srslte_prach_get_preamble_format(config_idx); - p->config_idx = config_idx; - p->f = preamble_format; - p->rsi = root_seq_index; - p->hs = high_speed_flag; - p->zczc = zero_corr_zone_config; - p->detect_factor = PRACH_DETECT_FACTOR; + p->config_idx = config_idx; + p->f = preamble_format; + p->rsi = root_seq_index; + p->hs = high_speed_flag; + p->zczc = zero_corr_zone_config; + p->detect_factor = PRACH_DETECT_FACTOR; if (tdd_config) { p->tdd_config = *tdd_config; } @@ -495,7 +497,7 @@ int srslte_prach_set_cell_(srslte_prach_t* p, } p->N_seq = prach_Tseq[p->f] * p->N_ifft_ul / 2048; - p->N_cp = prach_Tcp[p->f] * p->N_ifft_ul / 2048; + p->N_cp = prach_Tcp[p->f] * p->N_ifft_ul / 2048; p->T_seq = prach_Tseq[p->f] * SRSLTE_LTE_TS; p->T_tot = (prach_Tseq[p->f] + prach_Tcp[p->f]) * SRSLTE_LTE_TS; @@ -507,17 +509,15 @@ int srslte_prach_set_cell_(srslte_prach_t* p, return ret; } -int srslte_prach_gen(srslte_prach_t *p, - uint32_t seq_index, - uint32_t freq_offset, - cf_t *signal) { +int srslte_prach_gen(srslte_prach_t* p, uint32_t seq_index, uint32_t freq_offset, cf_t* signal) +{ int ret = SRSLTE_ERROR; if (p != NULL && seq_index < N_SEQS && signal != NULL) { // Calculate parameters uint32_t N_rb_ul = srslte_nof_prb(p->N_ifft_ul); - uint32_t k_0 = freq_offset * N_RB_SC - N_rb_ul * N_RB_SC / 2 + p->N_ifft_ul / 2; - uint32_t K = DELTA_F / DELTA_F_RA; - uint32_t begin = PHI + (K * k_0) + (K / 2); + uint32_t k_0 = freq_offset * N_RB_SC - N_rb_ul * N_RB_SC / 2 + p->N_ifft_ul / 2; + uint32_t K = DELTA_F / DELTA_F_RA; + uint32_t begin = PHI + (K * k_0) + (K / 2); if (6 + freq_offset > N_rb_ul) { ERROR("Error no space for PRACH: frequency offset=%d, N_rb_ul=%d\n", freq_offset, N_rb_ul); @@ -525,7 +525,11 @@ int srslte_prach_gen(srslte_prach_t *p, } DEBUG("N_zc: %d, N_cp: %d, N_seq: %d, N_ifft_prach=%d begin: %d\n", - p->N_zc, p->N_cp, p->N_seq, p->N_ifft_prach, begin); + p->N_zc, + p->N_cp, + p->N_seq, + p->N_ifft_prach, + begin); // Map dft-precoded sequence to ifft bins memset(p->ifft_in, 0, begin * sizeof(cf_t)); @@ -548,16 +552,18 @@ int srslte_prach_gen(srslte_prach_t *p, return ret; } -void srslte_prach_set_detect_factor(srslte_prach_t *p, float ratio) { +void srslte_prach_set_detect_factor(srslte_prach_t* p, float ratio) +{ p->detect_factor = ratio; } -int srslte_prach_detect(srslte_prach_t *p, - uint32_t freq_offset, - cf_t *signal, - uint32_t sig_len, - uint32_t *indices, - uint32_t *n_indices) { +int srslte_prach_detect(srslte_prach_t* p, + uint32_t freq_offset, + cf_t* signal, + uint32_t sig_len, + uint32_t* indices, + uint32_t* n_indices) +{ return srslte_prach_detect_offset(p, freq_offset, signal, sig_len, indices, NULL, NULL, n_indices); } @@ -571,10 +577,7 @@ int srslte_prach_detect_offset(srslte_prach_t* p, uint32_t* n_indices) { int ret = SRSLTE_ERROR; - if (p != NULL && - signal != NULL && - sig_len > 0 && - indices != NULL) { + if (p != NULL && signal != NULL && sig_len > 0 && indices != NULL) { if (sig_len < p->N_ifft_prach) { ERROR("srslte_prach_detect: Signal length is %d and should be %d\n", sig_len, p->N_ifft_prach); @@ -588,14 +591,14 @@ int srslte_prach_detect_offset(srslte_prach_t* p, // Extract bins of interest uint32_t N_rb_ul = srslte_nof_prb(p->N_ifft_ul); - uint32_t k_0 = freq_offset * N_RB_SC - N_rb_ul * N_RB_SC / 2 + p->N_ifft_ul / 2; - uint32_t K = DELTA_F / DELTA_F_RA; - uint32_t begin = PHI + (K * k_0) + (K / 2); + uint32_t k_0 = freq_offset * N_RB_SC - N_rb_ul * N_RB_SC / 2 + p->N_ifft_ul / 2; + uint32_t K = DELTA_F / DELTA_F_RA; + uint32_t begin = PHI + (K * k_0) + (K / 2); memcpy(p->prach_bins, &p->signal_fft[begin], p->N_zc * sizeof(cf_t)); for (int i = 0; i < p->N_roots; i++) { - cf_t *root_spec = p->dft_seqs[p->root_seqs_idx[i]]; + cf_t* root_spec = p->dft_seqs[p->root_seqs_idx[i]]; srslte_vec_prod_conj_ccc(p->prach_bins, root_spec, p->corr_spec, p->N_zc); @@ -616,7 +619,7 @@ int srslte_prach_detect_offset(srslte_prach_t* p, float max_peak = 0; for (int j = 0; j < n_wins; j++) { uint32_t start = (p->N_zc - (j * p->N_cs)) % p->N_zc; - uint32_t end = start + winsize; + uint32_t end = start + winsize; if (end > p->deadzone) { end -= p->deadzone; } @@ -624,7 +627,7 @@ int srslte_prach_detect_offset(srslte_prach_t* p, p->peak_values[j] = 0; for (int k = start; k < end; k++) { if (p->corr[k] > p->peak_values[j]) { - p->peak_values[j] = p->corr[k]; + p->peak_values[j] = p->corr[k]; p->peak_offsets[j] = k - start; if (p->peak_values[j] > max_peak) { max_peak = p->peak_values[j]; @@ -635,8 +638,8 @@ int srslte_prach_detect_offset(srslte_prach_t* p, if (max_peak > p->detect_factor * corr_ave) { for (int j = 0; j < n_wins; j++) { if (p->peak_values[j] > p->detect_factor * corr_ave) { - //printf("saving prach correlation\n"); - //memcpy(save_corr, p->corr, p->N_zc*sizeof(float)); + // printf("saving prach correlation\n"); + // memcpy(save_corr, p->corr, p->N_zc*sizeof(float)); if (indices) { indices[*n_indices] = (i * n_wins) + j; } @@ -652,7 +655,7 @@ int srslte_prach_detect_offset(srslte_prach_t* p, corr = 1.91; } - t_offsets[*n_indices] = corr*p->peak_offsets[j]/(DELTA_F_RA * p->N_zc); + t_offsets[*n_indices] = corr * p->peak_offsets[j] / (DELTA_F_RA * p->N_zc); } (*n_indices)++; } @@ -665,7 +668,8 @@ int srslte_prach_detect_offset(srslte_prach_t* p, return ret; } -int srslte_prach_free(srslte_prach_t *p) { +int srslte_prach_free(srslte_prach_t* p) +{ free(p->prach_bins); free(p->corr_spec); free(p->corr); @@ -685,26 +689,27 @@ int srslte_prach_free(srslte_prach_t *p) { return 0; } -int srslte_prach_print_seqs(srslte_prach_t *p) { +int srslte_prach_print_seqs(srslte_prach_t* p) +{ for (int i = 0; i < N_SEQS; i++) { - FILE *f; - char str[32]; + FILE* f; + char str[32]; sprintf(str, "prach_seq_%d.bin", i); f = fopen(str, "wb"); fwrite(p->seqs[i], sizeof(cf_t), p->N_zc, f); fclose(f); } for (int i = 0; i < N_SEQS; i++) { - FILE *f; - char str[32]; + FILE* f; + char str[32]; sprintf(str, "prach_dft_seq_%d.bin", i); f = fopen(str, "wb"); fwrite(p->dft_seqs[i], sizeof(cf_t), p->N_zc, f); fclose(f); } for (int i = 0; i < p->N_roots; i++) { - FILE *f; - char str[32]; + FILE* f; + char str[32]; sprintf(str, "prach_root_seq_%d.bin", i); f = fopen(str, "wb"); fwrite(p->seqs[p->root_seqs_idx[i]], sizeof(cf_t), p->N_zc, f); diff --git a/lib/src/phy/phch/prach_tables.h b/lib/src/phy/phch/prach_tables.h index 17f1f34ee..863c9b23e 100644 --- a/lib/src/phy/phch/prach_tables.h +++ b/lib/src/phy/phch/prach_tables.h @@ -44,157 +44,404 @@ uint32_t prach_Ncs_format4[7] = {2, 4, 6, 8, 10, 12, 15}; // Table 5.7.2-4 - Root ZC sequence order uint32_t prach_zc_roots[838] = { - 129, 710, 140, 699, 120, 719, 210, 629, 168, 671, 84, 755, - 105, 734, 93, 746, 70, 769, 60, 779, 2, 837, 1, 838, - 56, 783, 112, 727, 148, 691, 80, 759, 42, 797, 40, 799, - 35, 804, 73, 766, 146, 693, 31, 808, 28, 811, 30, 809, - 27, 812, 29, 810, 24, 815, 48, 791, 68, 771, 74, 765, - 178, 661, 136, 703, 86, 753, 78, 761, 43, 796, 39, 800, - 20, 819, 21, 818, 95, 744, 202, 637, 190, 649, 181, 658, - 137, 702, 125, 714, 151, 688, 217, 622, 128, 711, 142, 697, - 122, 717, 203, 636, 118, 721, 110, 729, 89, 750, 103, 736, - 61, 778, 55, 784, 15, 824, 14, 825, 12, 827, 23, 816, - 34, 805, 37, 802, 46, 793, 207, 632, 179, 660, 145, 694, - 130, 709, 223, 616, 228, 611, 227, 612, 132, 707, 133, 706, - 143, 696, 135, 704, 161, 678, 201, 638, 173, 666, 106, 733, - 83, 756, 91, 748, 66, 773, 53, 786, 10, 829, 9, 830, - 7, 832, 8, 831, 16, 823, 47, 792, 64, 775, 57, 782, - 104, 735, 101, 738, 108, 731, 208, 631, 184, 655, 197, 642, - 191, 648, 121, 718, 141, 698, 149, 690, 216, 623, 218, 621, - 152, 687, 144, 695, 134, 705, 138, 701, 199, 640, 162, 677, - 176, 663, 119, 720, 158, 681, 164, 675, 174, 665, 171, 668, - 170, 669, 87, 752, 169, 670, 88, 751, 107, 732, 81, 758, - 82, 757, 100, 739, 98, 741, 71, 768, 59, 780, 65, 774, - 50, 789, 49, 790, 26, 813, 17, 822, 13, 826, 6, 833, - 5, 834, 33, 806, 51, 788, 75, 764, 99, 740, 96, 743, - 97, 742, 166, 673, 172, 667, 175, 664, 187, 652, 163, 676, - 185, 654, 200, 639, 114, 725, 189, 650, 115, 724, 194, 645, - 195, 644, 192, 647, 182, 657, 157, 682, 156, 683, 211, 628, - 154, 685, 123, 716, 139, 700, 212, 627, 153, 686, 213, 626, - 215, 624, 150, 689, 225, 614, 224, 615, 221, 618, 220, 619, - 127, 712, 147, 692, 124, 715, 193, 646, 205, 634, 206, 633, - 116, 723, 160, 679, 186, 653, 167, 672, 79, 760, 85, 754, - 77, 762, 92, 747, 58, 781, 62, 777, 69, 770, 54, 785, - 36, 803, 32, 807, 25, 814, 18, 821, 11, 828, 4, 835, - 3, 836, 19, 820, 22, 817, 41, 798, 38, 801, 44, 795, - 52, 787, 45, 794, 63, 776, 67, 772, 72, 767, 76, 763, - 94, 745, 102, 737, 90, 749, 109, 730, 165, 674, 111, 728, - 209, 630, 204, 635, 117, 722, 188, 651, 159, 680, 198, 641, - 113, 726, 183, 656, 180, 659, 177, 662, 196, 643, 155, 684, - 214, 625, 126, 713, 131, 708, 219, 620, 222, 617, 226, 613, - 230, 609, 232, 607, 262, 577, 252, 587, 418, 421, 416, 423, - 413, 426, 411, 428, 376, 463, 395, 444, 283, 556, 285, 554, - 379, 460, 390, 449, 363, 476, 384, 455, 388, 451, 386, 453, - 361, 478, 387, 452, 360, 479, 310, 529, 354, 485, 328, 511, - 315, 524, 337, 502, 349, 490, 335, 504, 324, 515, 323, 516, - 320, 519, 334, 505, 359, 480, 295, 544, 385, 454, 292, 547, - 291, 548, 381, 458, 399, 440, 380, 459, 397, 442, 369, 470, - 377, 462, 410, 429, 407, 432, 281, 558, 414, 425, 247, 592, - 277, 562, 271, 568, 272, 567, 264, 575, 259, 580, 237, 602, - 239, 600, 244, 595, 243, 596, 275, 564, 278, 561, 250, 589, - 246, 593, 417, 422, 248, 591, 394, 445, 393, 446, 370, 469, - 365, 474, 300, 539, 299, 540, 364, 475, 362, 477, 298, 541, - 312, 527, 313, 526, 314, 525, 353, 486, 352, 487, 343, 496, - 327, 512, 350, 489, 326, 513, 319, 520, 332, 507, 333, 506, - 348, 491, 347, 492, 322, 517, 330, 509, 338, 501, 341, 498, - 340, 499, 342, 497, 301, 538, 366, 473, 401, 438, 371, 468, - 408, 431, 375, 464, 249, 590, 269, 570, 238, 601, 234, 605, - 257, 582, 273, 566, 255, 584, 254, 585, 245, 594, 251, 588, - 412, 427, 372, 467, 282, 557, 403, 436, 396, 443, 392, 447, - 391, 448, 382, 457, 389, 450, 294, 545, 297, 542, 311, 528, - 344, 495, 345, 494, 318, 521, 331, 508, 325, 514, 321, 518, - 346, 493, 339, 500, 351, 488, 306, 533, 289, 550, 400, 439, - 378, 461, 374, 465, 415, 424, 270, 569, 241, 598, 231, 608, - 260, 579, 268, 571, 276, 563, 409, 430, 398, 441, 290, 549, - 304, 535, 308, 531, 358, 481, 316, 523, 293, 546, 288, 551, - 284, 555, 368, 471, 253, 586, 256, 583, 263, 576, 242, 597, - 274, 565, 402, 437, 383, 456, 357, 482, 329, 510, 317, 522, - 307, 532, 286, 553, 287, 552, 266, 573, 261, 578, 236, 603, - 303, 536, 356, 483, 355, 484, 405, 434, 404, 435, 406, 433, - 235, 604, 267, 572, 302, 537, 309, 530, 265, 574, 233, 606, - 367, 472, 296, 543, 336, 503, 305, 534, 373, 466, 280, 559, + 129, 710, 140, 699, 120, 719, 210, 629, 168, 671, 84, 755, 105, 734, 93, 746, 70, 769, 60, 779, 2, 837, 1, + 838, 56, 783, 112, 727, 148, 691, 80, 759, 42, 797, 40, 799, 35, 804, 73, 766, 146, 693, 31, 808, 28, 811, + 30, 809, 27, 812, 29, 810, 24, 815, 48, 791, 68, 771, 74, 765, 178, 661, 136, 703, 86, 753, 78, 761, 43, + 796, 39, 800, 20, 819, 21, 818, 95, 744, 202, 637, 190, 649, 181, 658, 137, 702, 125, 714, 151, 688, 217, 622, + 128, 711, 142, 697, 122, 717, 203, 636, 118, 721, 110, 729, 89, 750, 103, 736, 61, 778, 55, 784, 15, 824, 14, + 825, 12, 827, 23, 816, 34, 805, 37, 802, 46, 793, 207, 632, 179, 660, 145, 694, 130, 709, 223, 616, 228, 611, + 227, 612, 132, 707, 133, 706, 143, 696, 135, 704, 161, 678, 201, 638, 173, 666, 106, 733, 83, 756, 91, 748, 66, + 773, 53, 786, 10, 829, 9, 830, 7, 832, 8, 831, 16, 823, 47, 792, 64, 775, 57, 782, 104, 735, 101, 738, + 108, 731, 208, 631, 184, 655, 197, 642, 191, 648, 121, 718, 141, 698, 149, 690, 216, 623, 218, 621, 152, 687, 144, + 695, 134, 705, 138, 701, 199, 640, 162, 677, 176, 663, 119, 720, 158, 681, 164, 675, 174, 665, 171, 668, 170, 669, + 87, 752, 169, 670, 88, 751, 107, 732, 81, 758, 82, 757, 100, 739, 98, 741, 71, 768, 59, 780, 65, 774, 50, + 789, 49, 790, 26, 813, 17, 822, 13, 826, 6, 833, 5, 834, 33, 806, 51, 788, 75, 764, 99, 740, 96, 743, + 97, 742, 166, 673, 172, 667, 175, 664, 187, 652, 163, 676, 185, 654, 200, 639, 114, 725, 189, 650, 115, 724, 194, + 645, 195, 644, 192, 647, 182, 657, 157, 682, 156, 683, 211, 628, 154, 685, 123, 716, 139, 700, 212, 627, 153, 686, + 213, 626, 215, 624, 150, 689, 225, 614, 224, 615, 221, 618, 220, 619, 127, 712, 147, 692, 124, 715, 193, 646, 205, + 634, 206, 633, 116, 723, 160, 679, 186, 653, 167, 672, 79, 760, 85, 754, 77, 762, 92, 747, 58, 781, 62, 777, + 69, 770, 54, 785, 36, 803, 32, 807, 25, 814, 18, 821, 11, 828, 4, 835, 3, 836, 19, 820, 22, 817, 41, + 798, 38, 801, 44, 795, 52, 787, 45, 794, 63, 776, 67, 772, 72, 767, 76, 763, 94, 745, 102, 737, 90, 749, + 109, 730, 165, 674, 111, 728, 209, 630, 204, 635, 117, 722, 188, 651, 159, 680, 198, 641, 113, 726, 183, 656, 180, + 659, 177, 662, 196, 643, 155, 684, 214, 625, 126, 713, 131, 708, 219, 620, 222, 617, 226, 613, 230, 609, 232, 607, + 262, 577, 252, 587, 418, 421, 416, 423, 413, 426, 411, 428, 376, 463, 395, 444, 283, 556, 285, 554, 379, 460, 390, + 449, 363, 476, 384, 455, 388, 451, 386, 453, 361, 478, 387, 452, 360, 479, 310, 529, 354, 485, 328, 511, 315, 524, + 337, 502, 349, 490, 335, 504, 324, 515, 323, 516, 320, 519, 334, 505, 359, 480, 295, 544, 385, 454, 292, 547, 291, + 548, 381, 458, 399, 440, 380, 459, 397, 442, 369, 470, 377, 462, 410, 429, 407, 432, 281, 558, 414, 425, 247, 592, + 277, 562, 271, 568, 272, 567, 264, 575, 259, 580, 237, 602, 239, 600, 244, 595, 243, 596, 275, 564, 278, 561, 250, + 589, 246, 593, 417, 422, 248, 591, 394, 445, 393, 446, 370, 469, 365, 474, 300, 539, 299, 540, 364, 475, 362, 477, + 298, 541, 312, 527, 313, 526, 314, 525, 353, 486, 352, 487, 343, 496, 327, 512, 350, 489, 326, 513, 319, 520, 332, + 507, 333, 506, 348, 491, 347, 492, 322, 517, 330, 509, 338, 501, 341, 498, 340, 499, 342, 497, 301, 538, 366, 473, + 401, 438, 371, 468, 408, 431, 375, 464, 249, 590, 269, 570, 238, 601, 234, 605, 257, 582, 273, 566, 255, 584, 254, + 585, 245, 594, 251, 588, 412, 427, 372, 467, 282, 557, 403, 436, 396, 443, 392, 447, 391, 448, 382, 457, 389, 450, + 294, 545, 297, 542, 311, 528, 344, 495, 345, 494, 318, 521, 331, 508, 325, 514, 321, 518, 346, 493, 339, 500, 351, + 488, 306, 533, 289, 550, 400, 439, 378, 461, 374, 465, 415, 424, 270, 569, 241, 598, 231, 608, 260, 579, 268, 571, + 276, 563, 409, 430, 398, 441, 290, 549, 304, 535, 308, 531, 358, 481, 316, 523, 293, 546, 288, 551, 284, 555, 368, + 471, 253, 586, 256, 583, 263, 576, 242, 597, 274, 565, 402, 437, 383, 456, 357, 482, 329, 510, 317, 522, 307, 532, + 286, 553, 287, 552, 266, 573, 261, 578, 236, 603, 303, 536, 356, 483, 355, 484, 405, 434, 404, 435, 406, 433, 235, + 604, 267, 572, 302, 537, 309, 530, 265, 574, 233, 606, 367, 472, 296, 543, 336, 503, 305, 534, 373, 466, 280, 559, 279, 560, 419, 420, 240, 599, 258, 581, 229, 610}; // Table 5.7.2-5 - Root ZC sequence order for preamble format 4 uint32_t prach_zc_roots_format4[138] = { - 1, 138, 2, 137, 3, 136, 4, 135, 5, 134, 6, 133, - 7, 132, 8, 131, 9, 130, 10, 129, 11, 128, 12, 127, - 13, 126, 14, 125, 15, 124, 16, 123, 17, 122, 18, 121, - 19, 120, 20, 119, 21, 118, 22, 117, 23, 116, 24, 115, - 25, 114, 26, 113, 27, 112, 28, 111, 29, 110, 30, 109, - 31, 108, 32, 107, 33, 106, 34, 105, 35, 104, 36, 103, - 37, 102, 38, 101, 39, 100, 40, 99, 41, 98, 42, 97, - 43, 96, 44, 95, 45, 94, 46, 93, 47, 92, 48, 91, - 49, 90, 50, 89, 51, 88, 52, 87, 53, 86, 54, 85, - 55, 84, 56, 83, 57, 82, 58, 81, 59, 80, 60, 79, - 61, 78, 62, 77, 63, 76, 64, 75, 65, 74, 66, 73, - 67, 72, 68, 71, 69, 70}; + 1, 138, 2, 137, 3, 136, 4, 135, 5, 134, 6, 133, 7, 132, 8, 131, 9, 130, 10, 129, 11, 128, 12, + 127, 13, 126, 14, 125, 15, 124, 16, 123, 17, 122, 18, 121, 19, 120, 20, 119, 21, 118, 22, 117, 23, 116, + 24, 115, 25, 114, 26, 113, 27, 112, 28, 111, 29, 110, 30, 109, 31, 108, 32, 107, 33, 106, 34, 105, 35, + 104, 36, 103, 37, 102, 38, 101, 39, 100, 40, 99, 41, 98, 42, 97, 43, 96, 44, 95, 45, 94, 46, 93, + 47, 92, 48, 91, 49, 90, 50, 89, 51, 88, 52, 87, 53, 86, 54, 85, 55, 84, 56, 83, 57, 82, 58, + 81, 59, 80, 60, 79, 61, 78, 62, 77, 63, 76, 64, 75, 65, 74, 66, 73, 67, 72, 68, 71, 69, 70}; -srslte_prach_sf_config_t prach_sf_config[16] = { - {1, {1, 0, 0, 0, 0}}, - {1, {4, 0, 0, 0, 0}}, - {1, {7, 0, 0, 0, 0}}, - {1, {1, 0, 0, 0, 0}}, - {1, {4, 0, 0, 0, 0}}, - {1, {7, 0, 0, 0, 0}}, - {2, {1, 6, 0, 0, 0}}, - {2, {2, 7, 0, 0, 0}}, - {2, {3, 8, 0, 0, 0}}, - {3, {1, 4, 7, 0, 0}}, - {3, {2, 5, 8, 0, 0}}, - {3, {3, 6, 9, 0, 0}}, - {5, {0, 2, 4, 6, 8}}, - {5, {1, 3, 5, 7, 9}}, - {-1, {0, 0, 0, 0, 0}}, // this means all subframes - {1, {9, 0, 0, 0, 0}}}; +srslte_prach_sf_config_t prach_sf_config[16] = {{1, {1, 0, 0, 0, 0}}, + {1, {4, 0, 0, 0, 0}}, + {1, {7, 0, 0, 0, 0}}, + {1, {1, 0, 0, 0, 0}}, + {1, {4, 0, 0, 0, 0}}, + {1, {7, 0, 0, 0, 0}}, + {2, {1, 6, 0, 0, 0}}, + {2, {2, 7, 0, 0, 0}}, + {2, {3, 8, 0, 0, 0}}, + {3, {1, 4, 7, 0, 0}}, + {3, {2, 5, 8, 0, 0}}, + {3, {3, 6, 9, 0, 0}}, + {5, {0, 2, 4, 6, 8}}, + {5, {1, 3, 5, 7, 9}}, + {-1, {0, 0, 0, 0, 0}}, // this means all subframes + {1, {9, 0, 0, 0, 0}}}; srslte_prach_tdd_loc_table_t prach_tdd_loc_table[64][7] = { - { {1,{{0,1,0,2}}},{1,{{0,1,0,1}}}, {1,{{0,1,0,0}}}, {1,{{0,1,0,2}}}, {1,{{0,1,0,1}}}, {1,{{0,1,0,0}}}, {1,{{0,1,0,2}}}}, - { {1,{{0,2,0,2}}},{1,{{0,2,0,1}}}, {1,{{0,2,0,0}}}, {1,{{0,2,0,2}}}, {1,{{0,2,0,1}}}, {1,{{0,2,0,0}}}, {1,{{0,2,0,2}}}}, - { {1,{{0,1,1,2}}},{1,{{0,1,1,1}}}, {1,{{0,1,1,0}}}, {1,{{0,1,0,1}}}, {1,{{0,1,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,1,1,1}}}}, - { {1,{{0,0,0,2}}},{1,{{0,0,0,1}}}, {1,{{0,0,0,0}}}, {1,{{0,0,0,2}}}, {1,{{0,0,0,1}}}, {1,{{0,0,0,0}}}, {1,{{0,0,0,2}}}}, - { {1,{{0,0,1,2}}},{1,{{0,0,1,1}}}, {1,{{0,0,1,0}}}, {1,{{0,0,0,1}}}, {1,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,0,1,1}}}}, - { {1,{{0,0,0,1}}},{1,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,0,0,1}}}}, - { {2,{{0,0,0,2},{0,0,1,2}}}, {2,{{0,0,0,1},{0,0,1,1}}}, {2,{{0,0,0,0},{0,0,1,0}}}, {2,{{0,0,0,1},{0,0,0,2}}}, {2,{{0,0,0,0},{0,0,0,1}}}, {2,{{0,0,0,0},{1,0,0,0}}}, {2,{{0,0,0,2},{0,0,1,1}}}}, - { {2,{{0,0,0,1},{0,0,1,1}}}, {2,{{0,0,0,0},{0,0,1,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {2,{{0,0,0,0},{0,0,0,2}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {2,{{0,0,0,1},{0,0,1,0}}}}, - { {2,{{0,0,0,0},{0,0,1,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {2,{{0,0,0,0},{0,0,0,1}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {2,{{0,0,0,0},{0,0,1,1}}}}, - { {3,{{0,0,0,1},{0,0,0,2},{0,0,1,2}}}, {3,{{0,0,0,0},{0,0,0,1},{0,0,1,1}}}, {3,{{0,0,0,0},{0,0,1,0},{1,0,0,0}}}, {3,{{0,0,0,0},{0,0,0,1},{0,0,0,2}}}, {3,{{0,0,0,0},{0,0,0,1},{1,0,0,1}}}, {3,{{0,0,0,0},{1,0,0,0},{2,0,0,0}}}, {3,{{0,0,0,1},{0,0,0,2},{0,0,1,1}}}}, - { {3,{{0,0,0,0},{0,0,1,0},{0,0,1,1}}}, {3,{{0,0,0,1},{0,0,1,0},{0,0,1,1}}}, {3,{{0,0,0,0},{0,0,1,0},{1,0,1,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {3,{{0,0,0,0},{0,0,0,1},{1,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {3,{{0,0,0,0},{0,0,0,2},{0,0,1,0}}}}, - { {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {3,{{0,0,0,0},{0,0,0,1},{0,0,1,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},{0,0,0,0},{0,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {3,{{0,0,0,1},{0,0,1,0},{0,0,1,1}}}}, - { {4,{{0,0,0,1},{0,0,0,2},{0,0,1,1},{0,0,1,2}}}, {4,{{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1}}}, {4,{{0,0,0,0},{0,0,1,0},{1,0,0,0},{1,0,1,0}}}, {4,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{1,0,0,2}}}, {4,{{0,0,0,0},{0,0,0,1},{1,0,0,0},{1,0,0,1}}}, {4,{{0,0,0,0},{1,0,0,0},{2,0,0,0},{3,0,0,0}}}, {4,{{0,0,0,1},{0,0,0,2},{0,0,1,0},{0,0,1,1}}}}, - { {4,{{0,0,0,0},{0,0,0,2},{0,0,1,0},{0,0,1,2}}}, {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,0,0}}}, {4,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{1,0,0,1}}}, {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,0,0}}}, {4,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{0,0,1,1}}}}, - { {4,{{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1}}}, {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,0,0}}}, {4,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{1,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,0},{0,0,0,0}}}, {4,{{0,0,0,0},{0,0,0,2},{0,0,1,0},{0,0,1,1}}}}, - { {5,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{0,0,1,1},{0,0,1,2}}}, {5,{{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},{1,0,0,1}}}, {5,{{0,0,0,0},{0,0,1,0},{1,0,0,0},{1,0,1,0},{2,0,0,0}}}, {5,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{1,0,0,1},{1,0,0,2}}}, {5,{{0,0,0,0},{0,0,0,1},{1,0,0,0},{1,0,0,1},{2,0,0,1}}}, {5,{{0,0,0,0},{1,0,0,0},{2,0,0,0},{3,0,0,0},{4,0,0,0}}}, {5,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{0,0,1,0},{0,0,1,1}}}}, - { {5,{{0,0,0,1},{0,0,0,2},{0,0,1,0},{0,0,1,1},{0,0,1,2}}}, {5,{{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},{1,0,1,1}}}, {5,{{0,0,0,0},{0,0,1,0},{1,0,0,0},{1,0,1,0},{2,0,1,0}}}, {5,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{1,0,0,0},{1,0,0,2}}}, {5,{{0,0,0,0},{0,0,0,1},{1,0,0,0},{1,0,0,1},{2,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,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}}}, - { {5,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{0,0,1,0},{0,0,1,2}}}, {5,{{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},{1,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {5,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{1,0,0,0},{1,0,0,1}}}, {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,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}}}}, - { {6,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{0,0,1,0},{0,0,1,1},{0,0,1,2}}}, {6,{{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},{1,0,0,1},{1,0,1,1}}}, {6,{{0,0,0,0},{0,0,1,0},{1,0,0,0},{1,0,1,0},{2,0,0,0},{2,0,1,0}}}, {6,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{1,0,0,0},{1,0,0,1},{1,0,0,2}}}, {6,{{0,0,0,0},{0,0,0,1},{1,0,0,0},{1,0,0,1},{2,0,0,0},{2,0,0,1}}}, {6,{{0,0,0,0},{1,0,0,0},{2,0,0,0},{3,0,0,0},{4,0,0,0},{5,0,0,0}}}, {6,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{0,0,1,0},{0,0,1,1},{1,0,0,2}}}}, - { {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}}}, {6,{{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},{1,0,0,0},{1,0,1,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,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},{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,0},{0,0,0,0}}}, {6,{{0,0,0,0},{0,0,0,1},{0,0,0,2},{0,0,1,0},{0,0,1,1},{1,0,1,1}}}}, - { {1,{{0,1,0,1}}},{1,{{0,1,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,1,0,1}}}, {1,{{0,1,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,1,0,1}}}}, - { {1,{{0,2,0,1}}},{1,{{0,2,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,2,0,1}}}, {1,{{0,2,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,2,0,1}}}}, - { {1,{{0,1,1,1}}},{1,{{0,1,1,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,1,1,0}}}}, - { {1,{{0,0,0,1}}},{1,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,0,0,1}}}, {1,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,0,0,1}}}}, - { {1,{{0,0,1,1}}},{1,{{0,0,1,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,0,1,0}}}}, - { {2,{{0,0,0,1},{0,0,1,1}}}, {2,{{0,0,0,0},{0,0,1,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {2,{{0,0,0,1},{1,0,0,1}}}, {2,{{0,0,0,0},{1,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {2,{{0,0,0,1},{0,0,1,0}}}}, - { {3,{{0,0,0,1},{0,0,1,1},{1,0,0,1}}}, {3,{{0,0,0,0},{0,0,1,0},{1,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {3,{{0,0,0,1},{1,0,0,1},{2,0,0,1}}}, {3,{{0,0,0,0},{1,0,0,0},{2,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {3,{{0,0,0,1},{0,0,1,0},{1,0,0,1}}}}, - { {4,{{0,0,0,1},{0,0,1,1},{1,0,0,1},{1,0,1,1}}}, {4,{{0,0,0,0},{0,0,1,0},{1,0,0,0},{1,0,1,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {4,{{0,0,0,1},{1,0,0,1},{2,0,0,1},{3,0,0,1}}}, {4,{{0,0,0,0},{1,0,0,0},{2,0,0,0},{3,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {4,{{0,0,0,1},{0,0,1,0},{1,0,0,1},{1,0,1,0}}}}, - { {5,{{0,0,0,1},{0,0,1,1},{1,0,0,1},{1,0,1,1},{2,0,0,1}}}, {5,{{0,0,0,0},{0,0,1,0},{1,0,0,0},{1,0,1,0},{2,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {5,{{0,0,0,1},{1,0,0,1},{2,0,0,1},{3,0,0,1},{4,0,0,1}}}, {5,{{0,0,0,0},{1,0,0,0},{2,0,0,0},{3,0,0,0},{4,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {5,{{0,0,0,1},{0,0,1,0},{1,0,0,1},{1,0,1,0},{2,0,0,1}}}}, - { {6,{{0,0,0,1},{0,0,1,1},{1,0,0,1},{1,0,1,1},{2,0,0,1},{2,0,1,1}}}, {6,{{0,0,0,0},{0,0,1,0},{1,0,0,0},{1,0,1,0},{2,0,0,0},{2,0,1,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}}}, {6,{{0,0,0,1},{1,0,0,1},{2,0,0,1},{3,0,0,1},{4,0,0,1},{5,0,0,1}}}, {6,{{0,0,0,0},{1,0,0,0},{2,0,0,0},{3,0,0,0},{4,0,0,0},{5,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}}}, {6,{{0,0,0,1},{0,0,1,0},{1,0,0,1},{1,0,1,0},{2,0,0,1},{2,0,1,0}}}}, - { {1,{{0,1,0,1}}},{1,{{0,1,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,1,0,1}}}, {1,{{0,1,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,1,0,1}}}}, - { {1,{{0,2,0,1}}},{1,{{0,2,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,2,0,1}}}, {1,{{0,2,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,2,0,1}}}}, - { {1,{{0,1,1,1}}},{1,{{0,1,1,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,1,1,0}}}}, - { {1,{{0,0,0,1}}},{1,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,0,0,1}}}, {1,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,0,0,1}}}}, - { {1,{{0,0,1,1}}},{1,{{0,0,1,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,0,1,0}}}}, - { {2,{{0,0,0,1},{0,0,1,1}}}, {2,{{0,0,0,0},{0,0,1,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {2,{{0,0,0,1},{1,0,0,1}}}, {2,{{0,0,0,0},{1,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {2,{{0,0,0,1},{0,0,1,0}}}}, - { {3,{{0,0,0,1},{0,0,1,1},{1,0,0,1}}}, {3,{{0,0,0,0},{0,0,1,0},{1,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {3,{{0,0,0,1},{1,0,0,1},{2,0,0,1}}}, {3,{{0,0,0,0},{1,0,0,0},{2,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {3,{{0,0,0,1},{0,0,1,0},{1,0,0,1}}}}, - { {4,{{0,0,0,1},{0,0,1,1},{1,0,0,1},{1,0,1,1}}}, {4,{{0,0,0,0},{0,0,1,0},{1,0,0,0},{1,0,1,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {4,{{0,0,0,1},{1,0,0,1},{2,0,0,1},{3,0,0,1}}}, {4,{{0,0,0,0},{1,0,0,0},{2,0,0,0},{3,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {4,{{0,0,0,1},{0,0,1,0},{1,0,0,1},{1,0,1,0}}}}, - { {5,{{0,0,0,1},{0,0,1,1},{1,0,0,1},{1,0,1,1},{2,0,0,1}}}, {5,{{0,0,0,0},{0,0,1,0},{1,0,0,0},{1,0,1,0},{2,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {5,{{0,0,0,1},{1,0,0,1},{2,0,0,1},{3,0,0,1},{4,0,0,1}}}, {5,{{0,0,0,0},{1,0,0,0},{2,0,0,0},{3,0,0,0},{4,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}}, {5,{{0,0,0,1},{0,0,1,0},{1,0,0,1},{1,0,1,0},{2,0,0,1}}}}, - { {6,{{0,0,0,1},{0,0,1,1},{1,0,0,1},{1,0,1,1},{2,0,0,1},{2,0,1,1}}}, {6,{{0,0,0,0},{0,0,1,0},{1,0,0,0},{1,0,1,0},{2,0,0,0},{2,0,1,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}}}, {6,{{0,0,0,1},{1,0,0,1},{2,0,0,1},{3,0,0,1},{4,0,0,1},{5,0,0,1}}}, {6,{{0,0,0,0},{1,0,0,0},{2,0,0,0},{3,0,0,0},{4,0,0,0},{5,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}}}, {6,{{0,0,0,1},{0,0,1,0},{1,0,0,1},{1,0,1,0},{2,0,0,1},{2,0,1,0}}}}, - { {1,{{0,1,0,0}}},{0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,1,0,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,1,0,0}}}}, - { {1,{{0,2,0,0}}},{0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,2,0,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,2,0,0}}}}, - { {1,{{0,1,1,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,{{0,0,0,0}}},{0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {0,{{0,0,0,0}}}, {1,{{0,0,0,0}}}}, - { {1,{{0,0,1,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}}}}, - { {2,{{0,0,0,0},{0,0,1,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {2,{{0,0,0,0},{1,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {0,{{0,0,0,0},{0,0,0,0}}}, {2,{{0,0,0,0},{1,0,0,0}}}}, - { {3,{{0,0,0,0},{0,0,1,0},{1,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}}}, {3,{{0,0,0,0},{1,0,0,0},{2,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}}}, {3,{{0,0,0,0},{1,0,0,0},{2,0,0,0}}}}, - { {4,{{0,0,0,0},{0,0,1,0},{1,0,0,0},{1,0,1,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,0,0,0}}}, {4,{{0,0,0,0},{1,0,0,0},{2,0,0,0},{3,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,0},{0,0,0,0}}}, {4,{{0,0,0,0},{1,0,0,0},{2,0,0,0},{3,0,0,0}}}} -}; \ No newline at end of file + {{1, {{0, 1, 0, 2}}}, + {1, {{0, 1, 0, 1}}}, + {1, {{0, 1, 0, 0}}}, + {1, {{0, 1, 0, 2}}}, + {1, {{0, 1, 0, 1}}}, + {1, {{0, 1, 0, 0}}}, + {1, {{0, 1, 0, 2}}}}, + {{1, {{0, 2, 0, 2}}}, + {1, {{0, 2, 0, 1}}}, + {1, {{0, 2, 0, 0}}}, + {1, {{0, 2, 0, 2}}}, + {1, {{0, 2, 0, 1}}}, + {1, {{0, 2, 0, 0}}}, + {1, {{0, 2, 0, 2}}}}, + {{1, {{0, 1, 1, 2}}}, + {1, {{0, 1, 1, 1}}}, + {1, {{0, 1, 1, 0}}}, + {1, {{0, 1, 0, 1}}}, + {1, {{0, 1, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 1, 1, 1}}}}, + {{1, {{0, 0, 0, 2}}}, + {1, {{0, 0, 0, 1}}}, + {1, {{0, 0, 0, 0}}}, + {1, {{0, 0, 0, 2}}}, + {1, {{0, 0, 0, 1}}}, + {1, {{0, 0, 0, 0}}}, + {1, {{0, 0, 0, 2}}}}, + {{1, {{0, 0, 1, 2}}}, + {1, {{0, 0, 1, 1}}}, + {1, {{0, 0, 1, 0}}}, + {1, {{0, 0, 0, 1}}}, + {1, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 0, 1, 1}}}}, + {{1, {{0, 0, 0, 1}}}, + {1, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 0, 0, 1}}}}, + {{2, {{0, 0, 0, 2}, {0, 0, 1, 2}}}, + {2, {{0, 0, 0, 1}, {0, 0, 1, 1}}}, + {2, {{0, 0, 0, 0}, {0, 0, 1, 0}}}, + {2, {{0, 0, 0, 1}, {0, 0, 0, 2}}}, + {2, {{0, 0, 0, 0}, {0, 0, 0, 1}}}, + {2, {{0, 0, 0, 0}, {1, 0, 0, 0}}}, + {2, {{0, 0, 0, 2}, {0, 0, 1, 1}}}}, + {{2, {{0, 0, 0, 1}, {0, 0, 1, 1}}}, + {2, {{0, 0, 0, 0}, {0, 0, 1, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {2, {{0, 0, 0, 0}, {0, 0, 0, 2}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {2, {{0, 0, 0, 1}, {0, 0, 1, 0}}}}, + {{2, {{0, 0, 0, 0}, {0, 0, 1, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {2, {{0, 0, 0, 0}, {0, 0, 0, 1}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {2, {{0, 0, 0, 0}, {0, 0, 1, 1}}}}, + {{3, {{0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 1, 2}}}, + {3, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 1}}}, + {3, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}}}, + {3, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}}}, + {3, {{0, 0, 0, 0}, {0, 0, 0, 1}, {1, 0, 0, 1}}}, + {3, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}}}, + {3, {{0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 1, 1}}}}, + {{3, {{0, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 1, 1}}}, + {3, {{0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}}}, + {3, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 1, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {3, {{0, 0, 0, 0}, {0, 0, 0, 1}, {1, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {3, {{0, 0, 0, 0}, {0, 0, 0, 2}, {0, 0, 1, 0}}}}, + {{0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {3, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 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}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {3, {{0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}}}}, + {{4, {{0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 1, 1}, {0, 0, 1, 2}}}, + {4, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}}}, + {4, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}}}, + {4, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {1, 0, 0, 2}}}, + {4, {{0, 0, 0, 0}, {0, 0, 0, 1}, {1, 0, 0, 0}, {1, 0, 0, 1}}}, + {4, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}, {3, 0, 0, 0}}}, + {4, {{0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 1, 0}, {0, 0, 1, 1}}}}, + {{4, {{0, 0, 0, 0}, {0, 0, 0, 2}, {0, 0, 1, 0}, {0, 0, 1, 2}}}, + {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, 0, 0}}}, + {4, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {1, 0, 0, 1}}}, + {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, 0, 0}}}, + {4, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 1, 1}}}}, + {{4, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}}}, + {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, 0, 0}}}, + {4, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {1, 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, 0}, {0, 0, 0, 0}}}, + {4, {{0, 0, 0, 0}, {0, 0, 0, 2}, {0, 0, 1, 0}, {0, 0, 1, 1}}}}, + {{5, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 1, 1}, {0, 0, 1, 2}}}, + {5, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}, {1, 0, 0, 1}}}, + {5, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}, {2, 0, 0, 0}}}, + {5, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {1, 0, 0, 1}, {1, 0, 0, 2}}}, + {5, {{0, 0, 0, 0}, {0, 0, 0, 1}, {1, 0, 0, 0}, {1, 0, 0, 1}, {2, 0, 0, 1}}}, + {5, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}, {3, 0, 0, 0}, {4, 0, 0, 0}}}, + {5, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 1, 0}, {0, 0, 1, 1}}}}, + {{5, {{0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 0, 1, 2}}}, + {5, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}, {1, 0, 1, 1}}}, + {5, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}, {2, 0, 1, 0}}}, + {5, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {1, 0, 0, 0}, {1, 0, 0, 2}}}, + {5, {{0, 0, 0, 0}, {0, 0, 0, 1}, {1, 0, 0, 0}, {1, 0, 0, 1}, {2, 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, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}}, + {{5, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 1, 0}, {0, 0, 1, 2}}}, + {5, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}, {1, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {5, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {1, 0, 0, 0}, {1, 0, 0, 1}}}, + {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, 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}}}}, + {{6, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 0, 1, 2}}}, + {6, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}, {1, 0, 0, 1}, {1, 0, 1, 1}}}, + {6, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}, {2, 0, 0, 0}, {2, 0, 1, 0}}}, + {6, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {1, 0, 0, 0}, {1, 0, 0, 1}, {1, 0, 0, 2}}}, + {6, {{0, 0, 0, 0}, {0, 0, 0, 1}, {1, 0, 0, 0}, {1, 0, 0, 1}, {2, 0, 0, 0}, {2, 0, 0, 1}}}, + {6, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}, {3, 0, 0, 0}, {4, 0, 0, 0}, {5, 0, 0, 0}}}, + {6, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 1, 0}, {0, 0, 1, 1}, {1, 0, 0, 2}}}}, + {{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}}}, + {6, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}, {1, 0, 0, 0}, {1, 0, 1, 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, 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}, {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, 0}, {0, 0, 0, 0}}}, + {6, {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 1, 0}, {0, 0, 1, 1}, {1, 0, 1, 1}}}}, + {{1, {{0, 1, 0, 1}}}, + {1, {{0, 1, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 1, 0, 1}}}, + {1, {{0, 1, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 1, 0, 1}}}}, + {{1, {{0, 2, 0, 1}}}, + {1, {{0, 2, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 2, 0, 1}}}, + {1, {{0, 2, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 2, 0, 1}}}}, + {{1, {{0, 1, 1, 1}}}, + {1, {{0, 1, 1, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 1, 1, 0}}}}, + {{1, {{0, 0, 0, 1}}}, + {1, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 0, 0, 1}}}, + {1, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 0, 0, 1}}}}, + {{1, {{0, 0, 1, 1}}}, + {1, {{0, 0, 1, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 0, 1, 0}}}}, + {{2, {{0, 0, 0, 1}, {0, 0, 1, 1}}}, + {2, {{0, 0, 0, 0}, {0, 0, 1, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {2, {{0, 0, 0, 1}, {1, 0, 0, 1}}}, + {2, {{0, 0, 0, 0}, {1, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {2, {{0, 0, 0, 1}, {0, 0, 1, 0}}}}, + {{3, {{0, 0, 0, 1}, {0, 0, 1, 1}, {1, 0, 0, 1}}}, + {3, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {3, {{0, 0, 0, 1}, {1, 0, 0, 1}, {2, 0, 0, 1}}}, + {3, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {3, {{0, 0, 0, 1}, {0, 0, 1, 0}, {1, 0, 0, 1}}}}, + {{4, {{0, 0, 0, 1}, {0, 0, 1, 1}, {1, 0, 0, 1}, {1, 0, 1, 1}}}, + {4, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {4, {{0, 0, 0, 1}, {1, 0, 0, 1}, {2, 0, 0, 1}, {3, 0, 0, 1}}}, + {4, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}, {3, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {4, {{0, 0, 0, 1}, {0, 0, 1, 0}, {1, 0, 0, 1}, {1, 0, 1, 0}}}}, + {{5, {{0, 0, 0, 1}, {0, 0, 1, 1}, {1, 0, 0, 1}, {1, 0, 1, 1}, {2, 0, 0, 1}}}, + {5, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}, {2, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {5, {{0, 0, 0, 1}, {1, 0, 0, 1}, {2, 0, 0, 1}, {3, 0, 0, 1}, {4, 0, 0, 1}}}, + {5, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}, {3, 0, 0, 0}, {4, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {5, {{0, 0, 0, 1}, {0, 0, 1, 0}, {1, 0, 0, 1}, {1, 0, 1, 0}, {2, 0, 0, 1}}}}, + {{6, {{0, 0, 0, 1}, {0, 0, 1, 1}, {1, 0, 0, 1}, {1, 0, 1, 1}, {2, 0, 0, 1}, {2, 0, 1, 1}}}, + {6, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}, {2, 0, 0, 0}, {2, 0, 1, 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}}}, + {6, {{0, 0, 0, 1}, {1, 0, 0, 1}, {2, 0, 0, 1}, {3, 0, 0, 1}, {4, 0, 0, 1}, {5, 0, 0, 1}}}, + {6, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}, {3, 0, 0, 0}, {4, 0, 0, 0}, {5, 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}}}, + {6, {{0, 0, 0, 1}, {0, 0, 1, 0}, {1, 0, 0, 1}, {1, 0, 1, 0}, {2, 0, 0, 1}, {2, 0, 1, 0}}}}, + {{1, {{0, 1, 0, 1}}}, + {1, {{0, 1, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 1, 0, 1}}}, + {1, {{0, 1, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 1, 0, 1}}}}, + {{1, {{0, 2, 0, 1}}}, + {1, {{0, 2, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 2, 0, 1}}}, + {1, {{0, 2, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 2, 0, 1}}}}, + {{1, {{0, 1, 1, 1}}}, + {1, {{0, 1, 1, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 1, 1, 0}}}}, + {{1, {{0, 0, 0, 1}}}, + {1, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 0, 0, 1}}}, + {1, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 0, 0, 1}}}}, + {{1, {{0, 0, 1, 1}}}, + {1, {{0, 0, 1, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 0, 1, 0}}}}, + {{2, {{0, 0, 0, 1}, {0, 0, 1, 1}}}, + {2, {{0, 0, 0, 0}, {0, 0, 1, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {2, {{0, 0, 0, 1}, {1, 0, 0, 1}}}, + {2, {{0, 0, 0, 0}, {1, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {2, {{0, 0, 0, 1}, {0, 0, 1, 0}}}}, + {{3, {{0, 0, 0, 1}, {0, 0, 1, 1}, {1, 0, 0, 1}}}, + {3, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {3, {{0, 0, 0, 1}, {1, 0, 0, 1}, {2, 0, 0, 1}}}, + {3, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {3, {{0, 0, 0, 1}, {0, 0, 1, 0}, {1, 0, 0, 1}}}}, + {{4, {{0, 0, 0, 1}, {0, 0, 1, 1}, {1, 0, 0, 1}, {1, 0, 1, 1}}}, + {4, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {4, {{0, 0, 0, 1}, {1, 0, 0, 1}, {2, 0, 0, 1}, {3, 0, 0, 1}}}, + {4, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}, {3, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {4, {{0, 0, 0, 1}, {0, 0, 1, 0}, {1, 0, 0, 1}, {1, 0, 1, 0}}}}, + {{5, {{0, 0, 0, 1}, {0, 0, 1, 1}, {1, 0, 0, 1}, {1, 0, 1, 1}, {2, 0, 0, 1}}}, + {5, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}, {2, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {5, {{0, 0, 0, 1}, {1, 0, 0, 1}, {2, 0, 0, 1}, {3, 0, 0, 1}, {4, 0, 0, 1}}}, + {5, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}, {3, 0, 0, 0}, {4, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}, + {5, {{0, 0, 0, 1}, {0, 0, 1, 0}, {1, 0, 0, 1}, {1, 0, 1, 0}, {2, 0, 0, 1}}}}, + {{6, {{0, 0, 0, 1}, {0, 0, 1, 1}, {1, 0, 0, 1}, {1, 0, 1, 1}, {2, 0, 0, 1}, {2, 0, 1, 1}}}, + {6, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}, {2, 0, 0, 0}, {2, 0, 1, 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}}}, + {6, {{0, 0, 0, 1}, {1, 0, 0, 1}, {2, 0, 0, 1}, {3, 0, 0, 1}, {4, 0, 0, 1}, {5, 0, 0, 1}}}, + {6, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}, {3, 0, 0, 0}, {4, 0, 0, 0}, {5, 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}}}, + {6, {{0, 0, 0, 1}, {0, 0, 1, 0}, {1, 0, 0, 1}, {1, 0, 1, 0}, {2, 0, 0, 1}, {2, 0, 1, 0}}}}, + {{1, {{0, 1, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 1, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 1, 0, 0}}}}, + {{1, {{0, 2, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 2, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 2, 0, 0}}}}, + {{1, {{0, 1, 1, 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, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}}}, + {1, {{0, 0, 0, 0}}}}, + {{1, {{0, 0, 1, 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}}}}, + {{2, {{0, 0, 0, 0}, {0, 0, 1, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {2, {{0, 0, 0, 0}, {1, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {0, {{0, 0, 0, 0}, {0, 0, 0, 0}}}, + {2, {{0, 0, 0, 0}, {1, 0, 0, 0}}}}, + {{3, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 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}}}, + {3, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 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}}}, + {3, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}}}}, + {{4, {{0, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 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, 0, 0, 0}}}, + {4, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}, {3, 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, 0}, {0, 0, 0, 0}}}, + {4, {{0, 0, 0, 0}, {1, 0, 0, 0}, {2, 0, 0, 0}, {3, 0, 0, 0}}}}}; \ No newline at end of file diff --git a/lib/src/phy/phch/prb_dl.c b/lib/src/phy/phch/prb_dl.c index 069806ba6..832f4365a 100644 --- a/lib/src/phy/phch/prb_dl.c +++ b/lib/src/phy/phch/prb_dl.c @@ -28,22 +28,23 @@ //#define DEBUG_IDX #ifdef DEBUG_IDX -extern cf_t *offset_original; +extern cf_t* offset_original; SRSLTE_API int indices[100000]; -SRSLTE_API int indices_ptr=0; +SRSLTE_API int indices_ptr = 0; #endif -void print_indexes(cf_t *offset, int len) { +void print_indexes(cf_t* offset, int len) +{ #ifdef DEBUG_IDX - for (int i=0;i #include "srslte/phy/ch_estimation/refsignal_ul.h" -#include "srslte/phy/phch/pucch.h" -#include "srslte/phy/common/sequence.h" #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/common/sequence.h" #include "srslte/phy/mimo/precoding.h" +#include "srslte/phy/modem/demod_soft.h" +#include "srslte/phy/phch/pucch.h" #include "srslte/phy/scrambling/scrambling.h" #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" -#include "srslte/phy/modem/demod_soft.h" #define MAX_PUSCH_RE(cp) (2 * SRSLTE_CP_NSYMB(cp) * 12) @@ -49,14 +49,14 @@ int srslte_pucch_init_(srslte_pucch_t* q, bool is_ue) if (q != NULL) { ret = SRSLTE_ERROR; bzero(q, sizeof(srslte_pucch_t)); - + if (srslte_modem_table_lte(&q->mod, SRSLTE_MOD_QPSK)) { return SRSLTE_ERROR; } q->is_ue = is_ue; - q->users = calloc(sizeof(srslte_pucch_user_t*), q->is_ue?1:(1+SRSLTE_SIRNTI)); + q->users = calloc(sizeof(srslte_pucch_user_t*), q->is_ue ? 1 : (1 + SRSLTE_SIRNTI)); if (!q->users) { perror("malloc"); goto clean_exit; @@ -68,11 +68,11 @@ int srslte_pucch_init_(srslte_pucch_t* q, bool is_ue) srslte_uci_cqi_pucch_init(&q->cqi); - q->z = srslte_vec_malloc(sizeof(cf_t)*SRSLTE_PUCCH_MAX_SYMBOLS); - q->z_tmp = srslte_vec_malloc(sizeof(cf_t)*SRSLTE_PUCCH_MAX_SYMBOLS); + q->z = srslte_vec_malloc(sizeof(cf_t) * SRSLTE_PUCCH_MAX_SYMBOLS); + q->z_tmp = srslte_vec_malloc(sizeof(cf_t) * SRSLTE_PUCCH_MAX_SYMBOLS); if (!q->is_ue) { - q->ce = srslte_vec_malloc(sizeof(cf_t)*SRSLTE_PUCCH_MAX_SYMBOLS); + q->ce = srslte_vec_malloc(sizeof(cf_t) * SRSLTE_PUCCH_MAX_SYMBOLS); } ret = SRSLTE_SUCCESS; @@ -84,15 +84,18 @@ clean_exit: return ret; } -int srslte_pucch_init_ue(srslte_pucch_t *q) { +int srslte_pucch_init_ue(srslte_pucch_t* q) +{ return srslte_pucch_init_(q, true); } -int srslte_pucch_init_enb(srslte_pucch_t *q) { +int srslte_pucch_init_enb(srslte_pucch_t* q) +{ return srslte_pucch_init_(q, false); } -void srslte_pucch_free(srslte_pucch_t *q) { +void srslte_pucch_free(srslte_pucch_t* q) +{ if (q->users) { if (q->is_ue) { srslte_pucch_free_rnti(q, 0); @@ -121,7 +124,8 @@ void srslte_pucch_free(srslte_pucch_t *q) { bzero(q, sizeof(srslte_pucch_t)); } -int srslte_pucch_set_cell(srslte_pucch_t *q, srslte_cell_t cell) { +int srslte_pucch_set_cell(srslte_pucch_t* q, srslte_cell_t cell) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL && srslte_cell_isvalid(&cell)) { @@ -145,22 +149,22 @@ int srslte_pucch_set_cell(srslte_pucch_t *q, srslte_cell_t cell) { void srslte_pucch_free_rnti(srslte_pucch_t* q, uint16_t rnti) { - uint32_t rnti_idx = q->is_ue?0:rnti; + uint32_t rnti_idx = q->is_ue ? 0 : rnti; if (q->users[rnti_idx]) { for (int i = 0; i < SRSLTE_NOF_SF_X_FRAME; i++) { srslte_sequence_free(&q->users[rnti_idx]->seq_f2[i]); - } + } free(q->users[rnti_idx]); q->users[rnti_idx] = NULL; - q->ue_rnti = 0; + q->ue_rnti = 0; } } int srslte_pucch_set_rnti(srslte_pucch_t* q, uint16_t rnti) { - uint32_t rnti_idx = q->is_ue?0:rnti; + uint32_t rnti_idx = q->is_ue ? 0 : rnti; if (!q->users[rnti_idx] || q->is_ue) { if (!q->users[rnti_idx]) { q->users[rnti_idx] = calloc(1, sizeof(srslte_pucch_user_t)); @@ -178,8 +182,8 @@ int srslte_pucch_set_rnti(srslte_pucch_t* q, uint16_t rnti) return SRSLTE_ERROR; } } - q->ue_rnti = rnti; - q->users[rnti_idx]->cell_id = q->cell.id; + q->ue_rnti = rnti; + q->users[rnti_idx]->cell_id = q->cell.id; q->users[rnti_idx]->sequence_generated = true; } else { ERROR("Error generating PUSCH sequence: rnti=0x%x already generated\n", rnti); @@ -187,41 +191,41 @@ int srslte_pucch_set_rnti(srslte_pucch_t* q, uint16_t rnti) return SRSLTE_SUCCESS; } -static cf_t uci_encode_format1() { +static cf_t uci_encode_format1() +{ return 1.0; } -static cf_t uci_encode_format1a(uint8_t bit) { - return bit?-1.0:1.0; +static cf_t uci_encode_format1a(uint8_t bit) +{ + return bit ? -1.0 : 1.0; } -static cf_t uci_encode_format1b(uint8_t bits[2]) { +static cf_t uci_encode_format1b(uint8_t bits[2]) +{ if (bits[0] == 0) { if (bits[1] == 0) { - return 1; + return 1; } else { - return -I; + return -I; } } else { if (bits[1] == 0) { - return I; + return I; } else { - return -1.0; - } + return -1.0; + } } } -static srslte_sequence_t *get_user_sequence(srslte_pucch_t *q, uint16_t rnti, uint32_t sf_idx) +static srslte_sequence_t* get_user_sequence(srslte_pucch_t* q, uint16_t rnti, uint32_t sf_idx) { - uint32_t rnti_idx = q->is_ue?0:rnti; + uint32_t rnti_idx = q->is_ue ? 0 : rnti; // The scrambling sequence is pregenerated for all RNTIs in the eNodeB but only for C-RNTI in the UE if (rnti >= SRSLTE_CRNTI_START && rnti < SRSLTE_CRNTI_END) { - if (q->users[rnti_idx] && - q->users[rnti_idx]->sequence_generated && - q->users[rnti_idx]->cell_id == q->cell.id && - (!q->is_ue || q->ue_rnti == rnti)) - { + if (q->users[rnti_idx] && q->users[rnti_idx]->sequence_generated && q->users[rnti_idx]->cell_id == q->cell.id && + (!q->is_ue || q->ue_rnti == rnti)) { return &q->users[rnti_idx]->seq_f2[sf_idx]; } else { if (srslte_sequence_pucch(&q->tmp_seq, rnti, 2 * sf_idx, q->cell.id)) { @@ -241,7 +245,7 @@ static int uci_mod_bits(srslte_pucch_t* q, srslte_ul_sf_cfg_t* sf, srslte_pucch_cfg_t* cfg, uint8_t bits[SRSLTE_PUCCH_MAX_BITS]) { uint8_t tmp[2]; - srslte_sequence_t *seq; + srslte_sequence_t* seq; switch (cfg->format) { case SRSLTE_PUCCH_FORMAT_1: q->d[0] = uci_encode_format1(); @@ -250,8 +254,8 @@ uci_mod_bits(srslte_pucch_t* q, srslte_ul_sf_cfg_t* sf, srslte_pucch_cfg_t* cfg, q->d[0] = uci_encode_format1a(bits[0]); break; case SRSLTE_PUCCH_FORMAT_1B: - tmp[0] = bits[0]; - tmp[1] = bits[1]; + tmp[0] = bits[0]; + tmp[1] = bits[1]; q->d[0] = uci_encode_format1b(tmp); break; case SRSLTE_PUCCH_FORMAT_2: @@ -259,7 +263,7 @@ uci_mod_bits(srslte_pucch_t* q, srslte_ul_sf_cfg_t* sf, srslte_pucch_cfg_t* cfg, case SRSLTE_PUCCH_FORMAT_2B: seq = get_user_sequence(q, cfg->rnti, sf->tti % 10); if (seq) { - memcpy(q->bits_scram, bits, SRSLTE_PUCCH2_NOF_BITS*sizeof(uint8_t)); + memcpy(q->bits_scram, bits, SRSLTE_PUCCH2_NOF_BITS * sizeof(uint8_t)); srslte_scrambling_b_offset(seq, q->bits_scram, 0, SRSLTE_PUCCH2_NOF_BITS); srslte_mod_modulate(&q->mod, q->bits_scram, q->d, SRSLTE_PUCCH2_NOF_BITS); } else { @@ -286,7 +290,7 @@ uci_mod_bits(srslte_pucch_t* q, srslte_ul_sf_cfg_t* sf, srslte_pucch_cfg_t* cfg, } // Declare this here, since we can not include refsignal_ul.h -void srslte_refsignal_r_uv_arg_1prb(float *arg, uint32_t u); +void srslte_refsignal_r_uv_arg_1prb(float* arg, uint32_t u); /* 3GPP 36211 Table 5.5.2.2.2-1: Demodulation reference signal location for different PUCCH formats. */ static const uint32_t pucch_symbol_format1_cpnorm[4] = {0, 1, 5, 6}; @@ -404,8 +408,12 @@ static uint32_t get_pucch_symbol(uint32_t m, srslte_pucch_format_t format, srslt } /* Map PUCCH symbols to physical resources according to 5.4.3 in 36.211 */ -static int pucch_cp( - srslte_pucch_t* q, srslte_ul_sf_cfg_t* sf, srslte_pucch_cfg_t* cfg, cf_t* source, cf_t* dest, bool source_is_grid) +static int pucch_cp(srslte_pucch_t* q, + srslte_ul_sf_cfg_t* sf, + srslte_pucch_cfg_t* cfg, + cf_t* source, + cf_t* dest, + bool source_is_grid) { int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q && source && dest) { @@ -765,8 +773,11 @@ static void decode_bits(srslte_uci_cfg_t* uci_cfg, } /* Encode, modulate and resource mapping of UCI data over PUCCH */ -int srslte_pucch_encode( - srslte_pucch_t* q, srslte_ul_sf_cfg_t* sf, srslte_pucch_cfg_t* cfg, srslte_uci_value_t* uci_data, cf_t* sf_symbols) +int srslte_pucch_encode(srslte_pucch_t* q, + srslte_ul_sf_cfg_t* sf, + srslte_pucch_cfg_t* cfg, + srslte_uci_value_t* uci_data, + cf_t* sf_symbols) { uint8_t pucch_bits[SRSLTE_PUCCH_MAX_BITS]; bzero(pucch_bits, SRSLTE_PUCCH_MAX_BITS * sizeof(uint8_t)); @@ -845,7 +856,7 @@ int srslte_pucch_decode(srslte_pucch_t* q, case SRSLTE_PUCCH_FORMAT_1: case SRSLTE_PUCCH_FORMAT_3: default: - /* Not considered, do nothing */; + /* Not considered, do nothing */; } ret = SRSLTE_SUCCESS; diff --git a/lib/src/phy/phch/pusch.c b/lib/src/phy/phch/pusch.c index 6cf003c91..c9bee27c2 100644 --- a/lib/src/phy/phch/pusch.c +++ b/lib/src/phy/phch/pusch.c @@ -30,63 +30,69 @@ #include #include "srslte/phy/ch_estimation/refsignal_ul.h" +#include "srslte/phy/common/phy_common.h" +#include "srslte/phy/dft/dft_precoding.h" #include "srslte/phy/phch/pusch.h" #include "srslte/phy/phch/pusch_cfg.h" #include "srslte/phy/phch/uci.h" -#include "srslte/phy/common/phy_common.h" #include "srslte/phy/utils/bit.h" #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" -#include "srslte/phy/dft/dft_precoding.h" #define MAX_PUSCH_RE(cp) (2 * SRSLTE_CP_NSYMB(cp) * 12) #define ACK_SNR_TH -1.0 -const static srslte_mod_t modulations[4] = - { SRSLTE_MOD_BPSK, SRSLTE_MOD_QPSK, SRSLTE_MOD_16QAM, SRSLTE_MOD_64QAM }; - +const static srslte_mod_t modulations[4] = {SRSLTE_MOD_BPSK, SRSLTE_MOD_QPSK, SRSLTE_MOD_16QAM, SRSLTE_MOD_64QAM}; /* Allocate/deallocate PUSCH RBs to the resource grid */ -static int pusch_cp( - srslte_pusch_t* q, srslte_pusch_grant_t* grant, cf_t* input, cf_t* output, bool is_shortened, bool advance_input) +static int pusch_cp(srslte_pusch_t* q, + srslte_pusch_grant_t* grant, + cf_t* input, + cf_t* output, + bool is_shortened, + bool advance_input) { cf_t* in_ptr = input; cf_t* out_ptr = output; uint32_t L_ref = 3; if (SRSLTE_CP_ISEXT(q->cell.cp)) { - L_ref = 2; + L_ref = 2; } for (uint32_t slot = 0; slot < 2; slot++) { uint32_t N_srs = 0; if (is_shortened && slot == 1) { - N_srs = 1; + N_srs = 1; } - INFO("%s PUSCH %d PRB to index %d at slot %d\n",advance_input?"Allocating":"Getting",grant->L_prb, grant->n_prb_tilde[slot], slot); - for (uint32_t l=0;lcell.cp)-N_srs;l++) { + INFO("%s PUSCH %d PRB to index %d at slot %d\n", + advance_input ? "Allocating" : "Getting", + grant->L_prb, + grant->n_prb_tilde[slot], + slot); + for (uint32_t l = 0; l < SRSLTE_CP_NSYMB(q->cell.cp) - N_srs; l++) { if (l != L_ref) { - uint32_t idx = SRSLTE_RE_IDX(q->cell.nof_prb, l+slot*SRSLTE_CP_NSYMB(q->cell.cp), - grant->n_prb_tilde[slot]*SRSLTE_NRE); + uint32_t idx = SRSLTE_RE_IDX( + q->cell.nof_prb, l + slot * SRSLTE_CP_NSYMB(q->cell.cp), grant->n_prb_tilde[slot] * SRSLTE_NRE); if (advance_input) { - out_ptr = &output[idx]; + out_ptr = &output[idx]; } else { in_ptr = &input[idx]; - } - memcpy(out_ptr, in_ptr, grant->L_prb * SRSLTE_NRE * sizeof(cf_t)); + } + memcpy(out_ptr, in_ptr, grant->L_prb * SRSLTE_NRE * sizeof(cf_t)); if (advance_input) { - in_ptr += grant->L_prb*SRSLTE_NRE; + in_ptr += grant->L_prb * SRSLTE_NRE; } else { - out_ptr += grant->L_prb*SRSLTE_NRE; + out_ptr += grant->L_prb * SRSLTE_NRE; } } - } + } } if (advance_input) { return in_ptr - input; } else { - return out_ptr - output; + return out_ptr - output; } } @@ -106,11 +112,10 @@ static int pusch_init(srslte_pusch_t* q, uint32_t max_prb, bool is_ue) int ret = SRSLTE_ERROR_INVALID_INPUTS; int i; - if (q != NULL) - { - + if (q != NULL) { + bzero(q, sizeof(srslte_pusch_t)); - ret = SRSLTE_ERROR; + ret = SRSLTE_ERROR; q->max_re = max_prb * MAX_PUSCH_RE(SRSLTE_CP_NORM); INFO("Init PUSCH: %d PRBs\n", max_prb); @@ -124,7 +129,7 @@ static int pusch_init(srslte_pusch_t* q, uint32_t max_prb, bool is_ue) q->is_ue = is_ue; - q->users = calloc(sizeof(srslte_pusch_user_t*), q->is_ue?1:(1+SRSLTE_SIRNTI)); + q->users = calloc(sizeof(srslte_pusch_user_t*), q->is_ue ? 1 : (1 + SRSLTE_SIRNTI)); if (!q->users) { perror("malloc"); goto clean; @@ -138,7 +143,7 @@ static int pusch_init(srslte_pusch_t* q, uint32_t max_prb, bool is_ue) if (srslte_dft_precoding_init(&q->dft_precoding, max_prb, is_ue)) { ERROR("Error initiating DFT transform precoding\n"); - goto clean; + goto clean; } // Allocate int16 for reception (LLRs). Buffer casted to uint8_t for transmission @@ -154,7 +159,7 @@ static int pusch_init(srslte_pusch_t* q, uint32_t max_prb, bool is_ue) } q->d = srslte_vec_malloc(sizeof(cf_t) * q->max_re); if (!q->d) { - goto clean; + goto clean; } if (!q->is_ue) { @@ -170,22 +175,25 @@ static int pusch_init(srslte_pusch_t* q, uint32_t max_prb, bool is_ue) ret = SRSLTE_SUCCESS; } - clean: +clean: if (ret == SRSLTE_ERROR) { srslte_pusch_free(q); } return ret; } -int srslte_pusch_init_ue(srslte_pusch_t *q, uint32_t max_prb) { +int srslte_pusch_init_ue(srslte_pusch_t* q, uint32_t max_prb) +{ return pusch_init(q, max_prb, true); } -int srslte_pusch_init_enb(srslte_pusch_t *q, uint32_t max_prb) { +int srslte_pusch_init_enb(srslte_pusch_t* q, uint32_t max_prb) +{ return pusch_init(q, max_prb, false); } -void srslte_pusch_free(srslte_pusch_t *q) { +void srslte_pusch_free(srslte_pusch_t* q) +{ int i; if (q->q) { @@ -203,14 +211,14 @@ void srslte_pusch_free(srslte_pusch_t *q) { if (q->z) { free(q->z); } - + srslte_dft_precoding_free(&q->dft_precoding); if (q->users) { if (q->is_ue) { srslte_pusch_free_rnti(q, 0); } else { - for (int rnti=0;rnti<=SRSLTE_SIRNTI;rnti++) { + for (int rnti = 0; rnti <= SRSLTE_SIRNTI; rnti++) { srslte_pusch_free_rnti(q, rnti); } } @@ -218,35 +226,36 @@ void srslte_pusch_free(srslte_pusch_t *q) { } srslte_sequence_free(&q->tmp_seq); - + for (i = 0; i < 4; i++) { srslte_modem_table_free(&q->mod[i]); } srslte_sch_free(&q->ul_sch); bzero(q, sizeof(srslte_pusch_t)); - } -int srslte_pusch_set_cell(srslte_pusch_t *q, srslte_cell_t cell) { +int srslte_pusch_set_cell(srslte_pusch_t* q, srslte_cell_t cell) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL && srslte_cell_isvalid(&cell)) { q->cell = cell; q->max_re = cell.nof_prb * MAX_PUSCH_RE(cell.cp); - ret = SRSLTE_SUCCESS; + ret = SRSLTE_SUCCESS; } return ret; } -/* Precalculate the PUSCH scramble sequences for a given RNTI. This function takes a while +/* Precalculate the PUSCH scramble sequences for a given RNTI. This function takes a while * to execute, so shall be called once the final C-RNTI has been allocated for the session. * For the connection procedure, use srslte_pusch_encode() functions */ -int srslte_pusch_set_rnti(srslte_pusch_t *q, uint16_t rnti) { +int srslte_pusch_set_rnti(srslte_pusch_t* q, uint16_t rnti) +{ uint32_t i; - uint32_t rnti_idx = q->is_ue?0:rnti; + uint32_t rnti_idx = q->is_ue ? 0 : rnti; if (!q->users[rnti_idx] || q->is_ue) { if (!q->users[rnti_idx]) { @@ -258,16 +267,18 @@ int srslte_pusch_set_rnti(srslte_pusch_t *q, uint16_t rnti) { } q->users[rnti_idx]->sequence_generated = false; for (i = 0; i < SRSLTE_NOF_SF_X_FRAME; i++) { - if (srslte_sequence_pusch(&q->users[rnti_idx]->seq[i], rnti, 2 * i, q->cell.id, - q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM))) - { + if (srslte_sequence_pusch(&q->users[rnti_idx]->seq[i], + rnti, + 2 * i, + q->cell.id, + q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM))) { ERROR("Error initializing PUSCH scrambling sequence\n"); srslte_pusch_free_rnti(q, rnti); return SRSLTE_ERROR; } } q->ue_rnti = rnti; - q->users[rnti_idx]->cell_id = q->cell.id; + q->users[rnti_idx]->cell_id = q->cell.id; q->users[rnti_idx]->sequence_generated = true; } else { ERROR("Error generating PUSCH sequence: rnti=0x%x already generated\n", rnti); @@ -275,23 +286,24 @@ int srslte_pusch_set_rnti(srslte_pusch_t *q, uint16_t rnti) { return SRSLTE_SUCCESS; } -void srslte_pusch_free_rnti(srslte_pusch_t *q, uint16_t rnti) { +void srslte_pusch_free_rnti(srslte_pusch_t* q, uint16_t rnti) +{ - uint32_t rnti_idx = q->is_ue?0:rnti; + uint32_t rnti_idx = q->is_ue ? 0 : rnti; if (q->users[rnti_idx]) { for (int i = 0; i < SRSLTE_NOF_SF_X_FRAME; i++) { srslte_sequence_free(&q->users[rnti_idx]->seq[i]); - } + } free(q->users[rnti_idx]); q->users[rnti_idx] = NULL; - q->ue_rnti = 0; + q->ue_rnti = 0; } } static srslte_sequence_t* get_user_sequence(srslte_pusch_t* q, uint16_t rnti, uint32_t sf_idx, uint32_t len) { - uint32_t rnti_idx = q->is_ue?0:rnti; + uint32_t rnti_idx = q->is_ue ? 0 : rnti; if (SRSLTE_RNTI_ISUSER(rnti)) { // The scrambling sequence is pregenerated for all RNTIs in the eNodeB but only for C-RNTI in the UE @@ -313,14 +325,15 @@ static srslte_sequence_t* get_user_sequence(srslte_pusch_t* q, uint16_t rnti, ui /** Converts the PUSCH data bits to symbols mapped to the slot ready for transmission */ -int srslte_pusch_encode( - srslte_pusch_t* q, srslte_ul_sf_cfg_t* sf, srslte_pusch_cfg_t* cfg, srslte_pusch_data_t* data, cf_t* sf_symbols) +int srslte_pusch_encode(srslte_pusch_t* q, + srslte_ul_sf_cfg_t* sf, + srslte_pusch_cfg_t* cfg, + srslte_pusch_data_t* data, + cf_t* sf_symbols) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; - - if (q != NULL && - cfg != NULL) - { + int ret = SRSLTE_ERROR_INVALID_INPUTS; + + if (q != NULL && cfg != NULL) { /* Limit UL modulation if not supported by the UE or disabled by higher layers */ if (!cfg->enable_64qam) { @@ -385,17 +398,17 @@ int srslte_pusch_encode( uint8_t* d = q->q; for (int i = 0; i < nof_ri_ack_bits; i++) { if (q->ul_sch.ack_ri_bits[i].type == UCI_BIT_PLACEHOLDER) { - d[q->ul_sch.ack_ri_bits[i].position/8] |= (1<<(7-q->ul_sch.ack_ri_bits[i].position%8)); + d[q->ul_sch.ack_ri_bits[i].position / 8] |= (1 << (7 - q->ul_sch.ack_ri_bits[i].position % 8)); } else if (q->ul_sch.ack_ri_bits[i].type == UCI_BIT_REPETITION) { if (q->ul_sch.ack_ri_bits[i].position > 1) { - uint32_t p=q->ul_sch.ack_ri_bits[i].position; + uint32_t p = q->ul_sch.ack_ri_bits[i].position; uint8_t bit = d[(p - 1) / 8] & (1 << (7 - (p - 1) % 8)); if (bit) { d[p / 8] |= 1 << (7 - p % 8); } else { - d[p/8] &= ~(1<<(7-p%8)); + d[p / 8] &= ~(1 << (7 - p % 8)); } - } + } } } @@ -418,8 +431,8 @@ int srslte_pusch_encode( } ret = SRSLTE_SUCCESS; - } - return ret; + } + return ret; } /** Decodes the PUSCH from the received symbols @@ -521,8 +534,11 @@ int srslte_pusch_decode(srslte_pusch_t* q, return ret; } -uint32_t srslte_pusch_grant_tx_info( - srslte_pusch_grant_t* grant, srslte_uci_cfg_t* uci_cfg, srslte_uci_value_t* uci_data, char* str, uint32_t str_len) +uint32_t srslte_pusch_grant_tx_info(srslte_pusch_grant_t* grant, + srslte_uci_cfg_t* uci_cfg, + srslte_uci_value_t* uci_data, + char* str, + uint32_t str_len) { uint32_t len = srslte_ra_ul_info(grant, str, str_len); diff --git a/lib/src/phy/phch/ra.c b/lib/src/phy/phch/ra.c index ecd038b28..274bf46c1 100644 --- a/lib/src/phy/phch/ra.c +++ b/lib/src/phy/phch/ra.c @@ -33,7 +33,7 @@ #include "tbs_tables.h" -#define min(a,b) (a 0 && n_prb <= SRSLTE_MAX_PRB) { - if (tbs <= tbs_table[0][n_prb-1]) { + if (tbs <= tbs_table[0][n_prb - 1]) { return 0; } - if (tbs >= tbs_table[26][n_prb-1]) { + if (tbs >= tbs_table[26][n_prb - 1]) { return 27; } for (idx = 0; idx < 26; idx++) { - if (tbs_table[idx][n_prb-1] <= tbs && tbs_table[idx+1][n_prb-1] >= tbs) { - return idx+1; + if (tbs_table[idx][n_prb - 1] <= tbs && tbs_table[idx + 1][n_prb - 1] >= tbs) { + return idx + 1; } } } diff --git a/lib/src/phy/phch/ra_ul.c b/lib/src/phy/phch/ra_ul.c index 3b5bed2db..c04f21657 100644 --- a/lib/src/phy/phch/ra_ul.c +++ b/lib/src/phy/phch/ra_ul.c @@ -313,9 +313,16 @@ int srslte_ra_ul_dci_to_grant(srslte_cell_t* cell, } } -uint32_t srslte_ra_ul_info(srslte_pusch_grant_t *grant, char *info_str, uint32_t len) +uint32_t srslte_ra_ul_info(srslte_pusch_grant_t* grant, char* info_str, uint32_t len) { - return srslte_print_check(info_str, len, 0, ", rb=(%d,%d), nof_re=%d, tbs=%d, mod=%d, rv=%d", grant->n_prb_tilde[0], - grant->n_prb_tilde[0] + grant->L_prb - 1, grant->nof_re, grant->tb.tbs / 8, - srslte_mod_bits_x_symbol(grant->tb.mod), grant->tb.rv); + return srslte_print_check(info_str, + len, + 0, + ", rb=(%d,%d), nof_re=%d, tbs=%d, mod=%d, rv=%d", + grant->n_prb_tilde[0], + grant->n_prb_tilde[0] + grant->L_prb - 1, + grant->nof_re, + grant->tb.tbs / 8, + srslte_mod_bits_x_symbol(grant->tb.mod), + grant->tb.rv); } \ No newline at end of file diff --git a/lib/src/phy/phch/regs.c b/lib/src/phy/phch/regs.c index 2e091dcd7..9f7afddb3 100644 --- a/lib/src/phy/phch/regs.c +++ b/lib/src/phy/phch/regs.c @@ -19,36 +19,25 @@ * */ +#include #include -#include #include -#include +#include #include "srslte/phy/common/phy_common.h" #include "srslte/phy/phch/regs.h" #include "srslte/phy/utils/debug.h" -#define REG_IDX(r, i, n) r->k[i]+r->l*n*SRSLTE_NRE - - -srslte_regs_reg_t *regs_find_reg(srslte_regs_t *h, uint32_t k, uint32_t l); -int regs_put_reg(srslte_regs_reg_t *reg, - cf_t *reg_data, - cf_t *slot_symbols, - uint32_t nof_prb); +#define REG_IDX(r, i, n) r->k[i] + r->l* n* SRSLTE_NRE -int regs_add_reg(srslte_regs_reg_t *reg, - cf_t *reg_data, - cf_t *slot_symbols, - uint32_t nof_prb); +srslte_regs_reg_t* regs_find_reg(srslte_regs_t* h, uint32_t k, uint32_t l); +int regs_put_reg(srslte_regs_reg_t* reg, cf_t* reg_data, cf_t* slot_symbols, uint32_t nof_prb); -int regs_get_reg(srslte_regs_reg_t *reg, - cf_t *slot_symbols, - cf_t *reg_data, - uint32_t nof_prb); +int regs_add_reg(srslte_regs_reg_t* reg, cf_t* reg_data, cf_t* slot_symbols, uint32_t nof_prb); -int regs_reset_reg(srslte_regs_reg_t *reg, cf_t *slot_symbols, uint32_t nof_prb); +int regs_get_reg(srslte_regs_reg_t* reg, cf_t* slot_symbols, cf_t* reg_data, uint32_t nof_prb); +int regs_reset_reg(srslte_regs_reg_t* reg, cf_t* slot_symbols, uint32_t nof_prb); /*************************************************************** * @@ -56,38 +45,39 @@ int regs_reset_reg(srslte_regs_reg_t *reg, cf_t *slot_symbols, uint32_t nof_prb) * ***************************************************************/ -void regs_pdcch_free(srslte_regs_t *h) { +void regs_pdcch_free(srslte_regs_t* h) +{ int i; - for (i=0;i<3;i++) { + for (i = 0; i < 3; i++) { if (h->pdcch[i].regs) { free(h->pdcch[i].regs); - h->pdcch[i].regs = NULL; + h->pdcch[i].regs = NULL; } } } -#define PDCCH_NCOLS 32 -const uint8_t PDCCH_PERM[PDCCH_NCOLS] = - { 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31, 0, 16, 8, - 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30 }; +#define PDCCH_NCOLS 32 +const uint8_t PDCCH_PERM[PDCCH_NCOLS] = {1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31, + 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30}; /** Initialize REGs for PDCCH * 36.211 10.3 section 6.8.5 */ -int regs_pdcch_init(srslte_regs_t *h) { - int i, m, cfi, nof_ctrl_symbols; - int ret = SRSLTE_ERROR; - int nrows, ndummy, j; - uint32_t k, kp; - srslte_regs_reg_t **tmp = NULL; +int regs_pdcch_init(srslte_regs_t* h) +{ + int i, m, cfi, nof_ctrl_symbols; + int ret = SRSLTE_ERROR; + int nrows, ndummy, j; + uint32_t k, kp; + srslte_regs_reg_t** tmp = NULL; bzero(&h->pdcch, sizeof(srslte_regs_ch_t)); - for (cfi=0;cfi<3;cfi++) { + for (cfi = 0; cfi < 3; cfi++) { if (h->cell.nof_prb <= 10) { - nof_ctrl_symbols = cfi+2; + nof_ctrl_symbols = cfi + 2; } else { - nof_ctrl_symbols = cfi+1; + nof_ctrl_symbols = cfi + 1; } tmp = malloc(sizeof(srslte_regs_reg_t*) * h->nof_regs); @@ -97,8 +87,8 @@ int regs_pdcch_init(srslte_regs_t *h) { } /* Number and count REGs for this CFI */ - m=0; - for (i=0;inof_regs;i++) { + m = 0; + for (i = 0; i < h->nof_regs; i++) { if (h->regs[i].l < nof_ctrl_symbols && !h->regs[i].assigned) { tmp[m] = &h->regs[i]; m++; @@ -114,30 +104,32 @@ int regs_pdcch_init(srslte_regs_t *h) { } /* Interleave REGs */ - nrows = (h->pdcch[cfi].nof_regs-1)/PDCCH_NCOLS+1; - ndummy = PDCCH_NCOLS*nrows - h->pdcch[cfi].nof_regs; + nrows = (h->pdcch[cfi].nof_regs - 1) / PDCCH_NCOLS + 1; + ndummy = PDCCH_NCOLS * nrows - h->pdcch[cfi].nof_regs; if (ndummy < 0) { ndummy = 0; } - k=0; + k = 0; for (j = 0; j < PDCCH_NCOLS; j++) { for (i = 0; i < nrows; i++) { - if (i*PDCCH_NCOLS + PDCCH_PERM[j] >= ndummy) { - m = i*PDCCH_NCOLS + PDCCH_PERM[j]-ndummy; + if (i * PDCCH_NCOLS + PDCCH_PERM[j] >= ndummy) { + m = i * PDCCH_NCOLS + PDCCH_PERM[j] - ndummy; if (k < h->cell.id) { - kp = (h->pdcch[cfi].nof_regs + k-(h->cell.id%h->pdcch[cfi].nof_regs))%h->pdcch[cfi].nof_regs; + kp = (h->pdcch[cfi].nof_regs + k - (h->cell.id % h->pdcch[cfi].nof_regs)) % h->pdcch[cfi].nof_regs; } else { - kp = (k-h->cell.id)%h->pdcch[cfi].nof_regs; + kp = (k - h->cell.id) % h->pdcch[cfi].nof_regs; } h->pdcch[cfi].regs[m] = tmp[kp]; k++; } } } - h->pdcch[cfi].nof_regs = (h->pdcch[cfi].nof_regs/9)*9; - INFO("Init PDCCH REG space CFI %d. %d useful REGs (%d CCEs)\n",cfi+1, - h->pdcch[cfi].nof_regs, h->pdcch[cfi].nof_regs/9); + h->pdcch[cfi].nof_regs = (h->pdcch[cfi].nof_regs / 9) * 9; + INFO("Init PDCCH REG space CFI %d. %d useful REGs (%d CCEs)\n", + cfi + 1, + h->pdcch[cfi].nof_regs, + h->pdcch[cfi].nof_regs / 9); free(tmp); tmp = NULL; } @@ -153,19 +145,21 @@ clean_and_exit: return ret; } -int srslte_regs_pdcch_nregs(srslte_regs_t *h, uint32_t cfi) { +int srslte_regs_pdcch_nregs(srslte_regs_t* h, uint32_t cfi) +{ if (cfi < 1 || cfi > 3) { ERROR("Invalid CFI=%d\n", cfi); return SRSLTE_ERROR; } else { - return (int) h->pdcch[cfi-1].nof_regs; + return (int)h->pdcch[cfi - 1].nof_regs; } } -int srslte_regs_pdcch_ncce(srslte_regs_t *h, uint32_t cfi) { +int srslte_regs_pdcch_ncce(srslte_regs_t* h, uint32_t cfi) +{ int nregs = srslte_regs_pdcch_nregs(h, cfi); if (nregs > 0) { - return (uint32_t) (nregs / 9); + return (uint32_t)(nregs / 9); } else { return SRSLTE_ERROR; } @@ -175,16 +169,22 @@ int srslte_regs_pdcch_ncce(srslte_regs_t *h, uint32_t cfi) { * second part of 6.8.5 in 36.211 */ -int srslte_regs_pdcch_put_offset(srslte_regs_t *h, uint32_t cfi, cf_t *d, cf_t *slot_symbols, uint32_t start_reg, uint32_t nof_regs) { +int srslte_regs_pdcch_put_offset(srslte_regs_t* h, + uint32_t cfi, + cf_t* d, + cf_t* slot_symbols, + uint32_t start_reg, + uint32_t nof_regs) +{ if (cfi < 1 || cfi > 3) { ERROR("Invalid CFI=%d\n", cfi); return SRSLTE_ERROR; } - if (start_reg + nof_regs <= h->pdcch[cfi-1].nof_regs) { + if (start_reg + nof_regs <= h->pdcch[cfi - 1].nof_regs) { uint32_t i, k; k = 0; - for (i=start_reg;ipdcch[cfi-1].regs[i], &d[k], slot_symbols, h->cell.nof_prb); + for (i = start_reg; i < start_reg + nof_regs; i++) { + regs_put_reg(h->pdcch[cfi - 1].regs[i], &d[k], slot_symbols, h->cell.nof_prb); k += 4; } return k; @@ -194,24 +194,31 @@ int srslte_regs_pdcch_put_offset(srslte_regs_t *h, uint32_t cfi, cf_t *d, cf_t * } } -int srslte_regs_pdcch_put(srslte_regs_t *h, uint32_t cfi, cf_t *d, cf_t *slot_symbols) { +int srslte_regs_pdcch_put(srslte_regs_t* h, uint32_t cfi, cf_t* d, cf_t* slot_symbols) +{ if (cfi < 1 || cfi > 3) { ERROR("Invalid CFI=%d\n", cfi); return SRSLTE_ERROR; } - return srslte_regs_pdcch_put_offset(h, cfi, d, slot_symbols, 0, h->pdcch[cfi-1].nof_regs); + return srslte_regs_pdcch_put_offset(h, cfi, d, slot_symbols, 0, h->pdcch[cfi - 1].nof_regs); } -int srslte_regs_pdcch_get_offset(srslte_regs_t *h, uint32_t cfi, cf_t *slot_symbols, cf_t *d, uint32_t start_reg, uint32_t nof_regs) { +int srslte_regs_pdcch_get_offset(srslte_regs_t* h, + uint32_t cfi, + cf_t* slot_symbols, + cf_t* d, + uint32_t start_reg, + uint32_t nof_regs) +{ if (cfi < 1 || cfi > 3) { ERROR("Invalid CFI=%d\n", cfi); return SRSLTE_ERROR; } - if (start_reg + nof_regs <= h->pdcch[cfi-1].nof_regs) { + if (start_reg + nof_regs <= h->pdcch[cfi - 1].nof_regs) { uint32_t i, k; k = 0; - for (i=start_reg;ipdcch[cfi-1].regs[i], slot_symbols, &d[k], h->cell.nof_prb); + for (i = start_reg; i < start_reg + nof_regs; i++) { + regs_get_reg(h->pdcch[cfi - 1].regs[i], slot_symbols, &d[k], h->cell.nof_prb); k += 4; } return k; @@ -221,18 +228,15 @@ int srslte_regs_pdcch_get_offset(srslte_regs_t *h, uint32_t cfi, cf_t *slot_symb } } - -int srslte_regs_pdcch_get(srslte_regs_t *h, uint32_t cfi, cf_t *slot_symbols, cf_t *d) { +int srslte_regs_pdcch_get(srslte_regs_t* h, uint32_t cfi, cf_t* slot_symbols, cf_t* d) +{ if (cfi < 1 || cfi > 3) { ERROR("Invalid CFI=%d\n", cfi); return SRSLTE_ERROR; } - return srslte_regs_pdcch_get_offset(h, cfi, slot_symbols, d, 0, h->pdcch[cfi-1].nof_regs); + return srslte_regs_pdcch_get_offset(h, cfi, slot_symbols, d, 0, h->pdcch[cfi - 1].nof_regs); } - - - /*************************************************************** * * PHICH REG ALLOCATION @@ -244,44 +248,46 @@ int srslte_regs_pdcch_get(srslte_regs_t *h, uint32_t cfi, cf_t *slot_symbols, cf */ int regs_phich_init(srslte_regs_t* h, uint32_t phich_mi, bool mbsfn_or_sf1_6_tdd) { - float ng; - uint32_t i, ni, li, n[3], nreg, mi; - srslte_regs_reg_t **regs_phich[3]; - int ret = SRSLTE_ERROR; - - for (int i=0;i<3;i++) { - regs_phich[i] = NULL; - } - - switch(h->phich_res) { - case SRSLTE_PHICH_R_1_6: - ng = (float) 1/6; - break; - case SRSLTE_PHICH_R_1_2: - ng = (float) 1/2; - break; - case SRSLTE_PHICH_R_1: - ng = 1; - break; - case SRSLTE_PHICH_R_2: - ng = 2; - break; - default: - ng = 0; - break; + float ng; + uint32_t i, ni, li, n[3], nreg, mi; + srslte_regs_reg_t** regs_phich[3]; + int ret = SRSLTE_ERROR; + + for (int i = 0; i < 3; i++) { + regs_phich[i] = NULL; + } + + switch (h->phich_res) { + case SRSLTE_PHICH_R_1_6: + ng = (float)1 / 6; + break; + case SRSLTE_PHICH_R_1_2: + ng = (float)1 / 2; + break; + case SRSLTE_PHICH_R_1: + ng = 1; + break; + case SRSLTE_PHICH_R_2: + ng = 2; + break; + default: + ng = 0; + break; } h->ngroups_phich_m1 = (int)ceilf(ng * ((float)h->cell.nof_prb / 8)); h->ngroups_phich = (int)phich_mi * h->ngroups_phich_m1; - h->phich = malloc(sizeof(srslte_regs_ch_t) * h->ngroups_phich); + h->phich = malloc(sizeof(srslte_regs_ch_t) * h->ngroups_phich); if (!h->phich) { perror("malloc"); return -1; } - INFO("Creating %d PHICH mapping units. %s length, Ng=%.2f\n",h->ngroups_phich, - h->phich_len==SRSLTE_PHICH_EXT?"Extended":"Normal",ng); - for (i=0;ingroups_phich;i++) { + INFO("Creating %d PHICH mapping units. %s length, Ng=%.2f\n", + h->ngroups_phich, + h->phich_len == SRSLTE_PHICH_EXT ? "Extended" : "Normal", + ng); + for (i = 0; i < h->ngroups_phich; i++) { h->phich[i].nof_regs = REGS_PHICH_REGS_X_GROUP; - h->phich[i].regs = malloc(sizeof(srslte_regs_reg_t*) * REGS_PHICH_REGS_X_GROUP); + h->phich[i].regs = malloc(sizeof(srslte_regs_reg_t*) * REGS_PHICH_REGS_X_GROUP); if (!h->phich[i].regs) { perror("malloc"); goto clean_and_exit; @@ -291,15 +297,15 @@ int regs_phich_init(srslte_regs_t* h, uint32_t phich_mi, bool mbsfn_or_sf1_6_tdd /** Here begins the mapping algorithm */ /* Step 2. Count REGs not assigned to PCFICH */ - bzero(n, 3*sizeof(int)); - for (i=0;inof_regs;i++) { + bzero(n, 3 * sizeof(int)); + for (i = 0; i < h->nof_regs; i++) { if (h->regs[i].l < 3 && !h->regs[i].assigned) { n[h->regs[i].l]++; } } bzero(regs_phich, sizeof(srslte_regs_reg_t*) * 3); - for (i=0;i<3;i++) { + for (i = 0; i < 3; i++) { regs_phich[i] = malloc(n[i] * sizeof(srslte_regs_reg_t*)); if (!regs_phich[i]) { perror("malloc"); @@ -309,15 +315,15 @@ int regs_phich_init(srslte_regs_t* h, uint32_t phich_mi, bool mbsfn_or_sf1_6_tdd bzero(n, 3 * sizeof(int)); /* Step 3. Number REGs not assigned to PCFICH */ - for (i=0;inof_regs;i++) { + for (i = 0; i < h->nof_regs; i++) { // they are already sorted starting from the REG with the lowest frequency-domain index if (h->regs[i].l < 3 && !h->regs[i].assigned) { regs_phich[h->regs[i].l][n[h->regs[i].l]++] = &h->regs[i]; } } - nreg=0; - for (mi=0;mingroups_phich;mi++) { // here ngroups is the number of mapping units + nreg = 0; + for (mi = 0; mi < h->ngroups_phich; mi++) { // here ngroups is the number of mapping units for (i = 0; i < 3; i++) { // Step 7 if (h->phich_len == SRSLTE_PHICH_NORM) { @@ -333,9 +339,9 @@ int regs_phich_init(srslte_regs_t* h, uint32_t phich_mi, bool mbsfn_or_sf1_6_tdd } else { ni = ((h->cell.id * n[li] / n[0]) + mi + i * n[li] / 3) % n[li]; } - h->phich[mi].regs[i] = regs_phich[li][ni]; + h->phich[mi].regs[i] = regs_phich[li][ni]; h->phich[mi].regs[i]->assigned = true; - DEBUG("Assigned PHICH REG#%d (%d,%d)\n",nreg,h->phich[mi].regs[i]->k0,li); + DEBUG("Assigned PHICH REG#%d (%d,%d)\n", nreg, h->phich[mi].regs[i]->k0, li); nreg++; } } @@ -350,7 +356,7 @@ int regs_phich_init(srslte_regs_t* h, uint32_t phich_mi, bool mbsfn_or_sf1_6_tdd clean_and_exit: if (ret == SRSLTE_ERROR) { if (h->phich) { - for (i=0;ingroups_phich;i++) { + for (i = 0; i < h->ngroups_phich; i++) { if (h->phich[i].regs) { free(h->phich[i].regs); } @@ -358,7 +364,7 @@ clean_and_exit: free(h->phich); } } - for (i=0;i<3;i++) { + for (i = 0; i < 3; i++) { if (regs_phich[i]) { free(regs_phich[i]); } @@ -366,35 +372,37 @@ clean_and_exit: return ret; } -void regs_phich_free(srslte_regs_t *h) { +void regs_phich_free(srslte_regs_t* h) +{ uint32_t i; if (h->phich) { if (SRSLTE_CP_ISEXT(h->cell.cp)) { h->ngroups_phich /= 2; } - for (i=0;ingroups_phich;i++) { + for (i = 0; i < h->ngroups_phich; i++) { if (h->phich[i].regs) { free(h->phich[i].regs); h->phich[i].regs = NULL; } } free(h->phich); - h->phich = NULL; + h->phich = NULL; } } -uint32_t srslte_regs_phich_nregs(srslte_regs_t *h) { +uint32_t srslte_regs_phich_nregs(srslte_regs_t* h) +{ uint32_t i; uint32_t n; - n=0; - for (i=0;ingroups_phich;i++) { + n = 0; + for (i = 0; i < h->ngroups_phich; i++) { n += h->phich[i].nof_regs; } return n; } - -uint32_t srslte_regs_phich_ngroups(srslte_regs_t *h) { +uint32_t srslte_regs_phich_ngroups(srslte_regs_t* h) +{ return h->ngroups_phich; } @@ -410,7 +418,8 @@ uint32_t srslte_regs_phich_ngroups_m1(srslte_regs_t* h) * * Returns the number of written symbols, or -1 on error */ -int srslte_regs_phich_add(srslte_regs_t *h, cf_t symbols[REGS_PHICH_NSYM], uint32_t ngroup, cf_t *slot_symbols) { +int srslte_regs_phich_add(srslte_regs_t* h, cf_t symbols[REGS_PHICH_NSYM], uint32_t ngroup, cf_t* slot_symbols) +{ uint32_t i; if (ngroup >= h->ngroups_phich) { ERROR("Error invalid ngroup %d\n", ngroup); @@ -419,11 +428,11 @@ int srslte_regs_phich_add(srslte_regs_t *h, cf_t symbols[REGS_PHICH_NSYM], uint3 if (SRSLTE_CP_ISEXT(h->cell.cp)) { ngroup /= 2; } - srslte_regs_ch_t *rch = &h->phich[ngroup]; - for (i = 0; i < rch->nof_regs && i*REGS_RE_X_REG < REGS_PHICH_NSYM; i++) { - regs_add_reg(rch->regs[i], &symbols[i*REGS_RE_X_REG], slot_symbols, h->cell.nof_prb); + srslte_regs_ch_t* rch = &h->phich[ngroup]; + for (i = 0; i < rch->nof_regs && i * REGS_RE_X_REG < REGS_PHICH_NSYM; i++) { + regs_add_reg(rch->regs[i], &symbols[i * REGS_RE_X_REG], slot_symbols, h->cell.nof_prb); } - return i*REGS_RE_X_REG; + return i * REGS_RE_X_REG; } /** @@ -431,17 +440,18 @@ int srslte_regs_phich_add(srslte_regs_t *h, cf_t symbols[REGS_PHICH_NSYM], uint3 * * Returns the number of written symbols, or -1 on error */ -int srslte_regs_phich_reset(srslte_regs_t *h, cf_t *slot_symbols) { +int srslte_regs_phich_reset(srslte_regs_t* h, cf_t* slot_symbols) +{ uint32_t i; uint32_t ngroup, ng; - for (ngroup = 0;ngroup < h->ngroups_phich;SRSLTE_CP_ISEXT(h->cell.cp)?ngroup+=2:ngroup++) { + for (ngroup = 0; ngroup < h->ngroups_phich; SRSLTE_CP_ISEXT(h->cell.cp) ? ngroup += 2 : ngroup++) { if (SRSLTE_CP_ISEXT(h->cell.cp)) { - ng = ngroup/2; + ng = ngroup / 2; } else { ng = ngroup; } - srslte_regs_ch_t *rch = &h->phich[ng]; - for (i = 0; i < rch->nof_regs && i*REGS_RE_X_REG < REGS_PHICH_NSYM; i++) { + srslte_regs_ch_t* rch = &h->phich[ng]; + for (i = 0; i < rch->nof_regs && i * REGS_RE_X_REG < REGS_PHICH_NSYM; i++) { regs_reset_reg(rch->regs[i], slot_symbols, h->cell.nof_prb); } } @@ -453,7 +463,8 @@ int srslte_regs_phich_reset(srslte_regs_t *h, cf_t *slot_symbols) { * * Returns the number of written symbols, or -1 on error */ -int srslte_regs_phich_get(srslte_regs_t *h, cf_t *slot_symbols, cf_t symbols[REGS_PHICH_NSYM], uint32_t ngroup) { +int srslte_regs_phich_get(srslte_regs_t* h, cf_t* slot_symbols, cf_t symbols[REGS_PHICH_NSYM], uint32_t ngroup) +{ uint32_t i; if (ngroup >= h->ngroups_phich) { ERROR("Error invalid ngroup %d\n", ngroup); @@ -462,36 +473,27 @@ int srslte_regs_phich_get(srslte_regs_t *h, cf_t *slot_symbols, cf_t symbols[REG if (SRSLTE_CP_ISEXT(h->cell.cp)) { ngroup /= 2; } - srslte_regs_ch_t *rch = &h->phich[ngroup]; - for (i = 0; i < rch->nof_regs && i*REGS_RE_X_REG < REGS_PHICH_NSYM; i++) { - regs_get_reg(rch->regs[i], slot_symbols, &symbols[i*REGS_RE_X_REG], h->cell.nof_prb); + srslte_regs_ch_t* rch = &h->phich[ngroup]; + for (i = 0; i < rch->nof_regs && i * REGS_RE_X_REG < REGS_PHICH_NSYM; i++) { + regs_get_reg(rch->regs[i], slot_symbols, &symbols[i * REGS_RE_X_REG], h->cell.nof_prb); } - return i*REGS_RE_X_REG; + return i * REGS_RE_X_REG; } - - - - - - - - - /*************************************************************** * * PCFICH REG ALLOCATION * ***************************************************************/ - /** Initialize REGs for PCFICH * 36.211 10.3 section 6.7.4 */ -int regs_pcfich_init(srslte_regs_t *h) { - uint32_t i; - uint32_t k_hat, k; - srslte_regs_ch_t *ch = &h->pcfich; +int regs_pcfich_init(srslte_regs_t* h) +{ + uint32_t i; + uint32_t k_hat, k; + srslte_regs_ch_t* ch = &h->pcfich; ch->regs = malloc(sizeof(srslte_regs_reg_t*) * REGS_PCFICH_NREGS); if (!ch->regs) { @@ -505,8 +507,7 @@ int regs_pcfich_init(srslte_regs_t *h) { k_hat = (SRSLTE_NRE / 2) * (h->cell.id % (2 * h->cell.nof_prb)); for (i = 0; i < REGS_PCFICH_NREGS; i++) { - k = (k_hat + (i * h->cell.nof_prb / 2) * (SRSLTE_NRE / 2)) - % (h->cell.nof_prb * SRSLTE_NRE); + k = (k_hat + (i * h->cell.nof_prb / 2) * (SRSLTE_NRE / 2)) % (h->cell.nof_prb * SRSLTE_NRE); ch->regs[i] = regs_find_reg(h, k, 0); if (!ch->regs[i]) { ERROR("Error allocating PCFICH: REG (%d,0) not found\n", k); @@ -515,21 +516,23 @@ int regs_pcfich_init(srslte_regs_t *h) { ERROR("Error allocating PCFICH: REG (%d,0) already allocated\n", k); return SRSLTE_ERROR; } else { - ch->regs[i]->assigned = true; + ch->regs[i]->assigned = true; DEBUG("Assigned PCFICH REG#%d (%d,0)\n", i, k); } } return SRSLTE_SUCCESS; } -void regs_pcfich_free(srslte_regs_t *h) { +void regs_pcfich_free(srslte_regs_t* h) +{ if (h->pcfich.regs) { free(h->pcfich.regs); - h->pcfich.regs = NULL; + h->pcfich.regs = NULL; } } -uint32_t srslte_regs_pcfich_nregs(srslte_regs_t *h) { +uint32_t srslte_regs_pcfich_nregs(srslte_regs_t* h) +{ return h->pcfich.nof_regs; } @@ -538,14 +541,15 @@ uint32_t srslte_regs_pcfich_nregs(srslte_regs_t *h) { * * Returns the number of written symbols, or -1 on error */ -int srslte_regs_pcfich_put(srslte_regs_t *h, cf_t symbols[REGS_PCFICH_NSYM], cf_t *slot_symbols) { - srslte_regs_ch_t *rch = &h->pcfich; +int srslte_regs_pcfich_put(srslte_regs_t* h, cf_t symbols[REGS_PCFICH_NSYM], cf_t* slot_symbols) +{ + srslte_regs_ch_t* rch = &h->pcfich; uint32_t i; - for (i = 0; i < rch->nof_regs && i*REGS_RE_X_REG < REGS_PCFICH_NSYM; i++) { - regs_put_reg(rch->regs[i], &symbols[i*REGS_RE_X_REG], slot_symbols, h->cell.nof_prb); + for (i = 0; i < rch->nof_regs && i * REGS_RE_X_REG < REGS_PCFICH_NSYM; i++) { + regs_put_reg(rch->regs[i], &symbols[i * REGS_RE_X_REG], slot_symbols, h->cell.nof_prb); } - return i*REGS_RE_X_REG; + return i * REGS_RE_X_REG; } /** @@ -553,37 +557,26 @@ int srslte_regs_pcfich_put(srslte_regs_t *h, cf_t symbols[REGS_PCFICH_NSYM], cf_ * * Returns the number of written symbols, or -1 on error */ -int srslte_regs_pcfich_get(srslte_regs_t *h, cf_t *slot_symbols, cf_t ch_data[REGS_PCFICH_NSYM]) { - srslte_regs_ch_t *rch = &h->pcfich; - uint32_t i; - for (i = 0; i < rch->nof_regs && i*REGS_RE_X_REG < REGS_PCFICH_NSYM; i++) { - regs_get_reg(rch->regs[i], slot_symbols, &ch_data[i*REGS_RE_X_REG], h->cell.nof_prb); +int srslte_regs_pcfich_get(srslte_regs_t* h, cf_t* slot_symbols, cf_t ch_data[REGS_PCFICH_NSYM]) +{ + srslte_regs_ch_t* rch = &h->pcfich; + uint32_t i; + for (i = 0; i < rch->nof_regs && i * REGS_RE_X_REG < REGS_PCFICH_NSYM; i++) { + regs_get_reg(rch->regs[i], slot_symbols, &ch_data[i * REGS_RE_X_REG], h->cell.nof_prb); } - return i*REGS_RE_X_REG; + return i * REGS_RE_X_REG; } - - - - - - - - - - - - - /*************************************************************** * * COMMON FUNCTIONS * ***************************************************************/ -srslte_regs_reg_t *regs_find_reg(srslte_regs_t *h, uint32_t k, uint32_t l) { +srslte_regs_reg_t* regs_find_reg(srslte_regs_t* h, uint32_t k, uint32_t l) +{ uint32_t i; - for (i=0;inof_regs;i++) { + for (i = 0; i < h->nof_regs; i++) { if (h->regs[i].l == l && h->regs[i].k0 == k) { return &h->regs[i]; } @@ -595,34 +588,35 @@ srslte_regs_reg_t *regs_find_reg(srslte_regs_t *h, uint32_t k, uint32_t l) { * Returns the number of REGs in a PRB * 36.211 Section 6.2.4 */ -int regs_num_x_symbol(uint32_t symbol, uint32_t nof_port, srslte_cp_t cp) { +int regs_num_x_symbol(uint32_t symbol, uint32_t nof_port, srslte_cp_t cp) +{ switch (symbol) { - case 0: - return 2; - case 1: - switch (nof_port) { + case 0: + return 2; case 1: + switch (nof_port) { + case 1: + case 2: + return 3; + case 4: + return 2; + default: + ERROR("Invalid number of ports %d\n", nof_port); + return SRSLTE_ERROR; + } + break; case 2: return 3; - case 4: - return 2; + case 3: + if (SRSLTE_CP_ISNORM(cp)) { + return 3; + } else { + return 2; + } default: - ERROR("Invalid number of ports %d\n", nof_port); + ERROR("Invalid symbol %d\n", symbol); return SRSLTE_ERROR; - } - break; - case 2: - return 3; - case 3: - if (SRSLTE_CP_ISNORM(cp)) { - return 3; - } else { - return 2; - } - default: - ERROR("Invalid symbol %d\n", symbol); - return SRSLTE_ERROR; } } @@ -630,51 +624,53 @@ int regs_num_x_symbol(uint32_t symbol, uint32_t nof_port, srslte_cp_t cp) { * Initializes the indices of a REG * 36.211 Section 6.2.4 */ -int regs_reg_init(srslte_regs_reg_t *reg, uint32_t symbol, uint32_t nreg, uint32_t k0, uint32_t maxreg, uint32_t vo) { +int regs_reg_init(srslte_regs_reg_t* reg, uint32_t symbol, uint32_t nreg, uint32_t k0, uint32_t maxreg, uint32_t vo) +{ uint32_t i, j, z; - reg->l = symbol; + reg->l = symbol; reg->assigned = false; switch (maxreg) { - case 2: - reg->k0 = k0 + nreg * 6; - /* there are two references in the middle */ - j = z = 0; - for (i = 0; i < vo; i++) { - reg->k[j] = k0 + nreg * 6 + i; - j++; - } - for (i = 0; i < 2; i++) { - reg->k[j] = k0 + nreg * 6 + i + vo + 1; - j++; - } - z = j; - for (i = 0; i < 4 - z; i++) { - reg->k[j] = k0 + nreg * 6 + vo + 3 + i + 1; - j++; - } - if (j != 4) { - ERROR("Something went wrong: expected 2 references\n"); - return SRSLTE_ERROR; - } - break; + case 2: + reg->k0 = k0 + nreg * 6; + /* there are two references in the middle */ + j = z = 0; + for (i = 0; i < vo; i++) { + reg->k[j] = k0 + nreg * 6 + i; + j++; + } + for (i = 0; i < 2; i++) { + reg->k[j] = k0 + nreg * 6 + i + vo + 1; + j++; + } + z = j; + for (i = 0; i < 4 - z; i++) { + reg->k[j] = k0 + nreg * 6 + vo + 3 + i + 1; + j++; + } + if (j != 4) { + ERROR("Something went wrong: expected 2 references\n"); + return SRSLTE_ERROR; + } + break; - case 3: - reg->k0 = k0 + nreg * 4; - /* there is no reference */ - for (i = 0; i < 4; i++) { - reg->k[i] = k0 + nreg * 4 + i; - } - break; - default: - ERROR("Invalid number of REGs per PRB: %d\n", maxreg); - return SRSLTE_ERROR; + case 3: + reg->k0 = k0 + nreg * 4; + /* there is no reference */ + for (i = 0; i < 4; i++) { + reg->k[i] = k0 + nreg * 4 + i; + } + break; + default: + ERROR("Invalid number of REGs per PRB: %d\n", maxreg); + return SRSLTE_ERROR; } return SRSLTE_SUCCESS; } -void srslte_regs_free(srslte_regs_t *h) { +void srslte_regs_free(srslte_regs_t* h) +{ if (h->regs) { free(h->regs); } @@ -703,18 +699,16 @@ int srslte_regs_init_opts(srslte_regs_t* h, srslte_cell_t cell, uint32_t phich_m uint32_t n[4], vo; uint32_t max_ctrl_symbols; - if (h != NULL && - srslte_cell_isvalid(&cell)) - { + if (h != NULL && srslte_cell_isvalid(&cell)) { bzero(h, sizeof(srslte_regs_t)); ret = SRSLTE_ERROR; - - max_ctrl_symbols = cell.nof_prb<=10?4:3; - vo = cell.id % 3; - h->cell = cell; + + max_ctrl_symbols = cell.nof_prb <= 10 ? 4 : 3; + vo = cell.id % 3; + h->cell = cell; h->max_ctrl_symbols = max_ctrl_symbols; - h->phich_res = cell.phich_resources; - h->phich_len = cell.phich_length; + h->phich_res = cell.phich_resources; + h->phich_len = cell.phich_length; h->nof_regs = 0; for (i = 0; i < max_ctrl_symbols; i++) { @@ -724,8 +718,11 @@ int srslte_regs_init_opts(srslte_regs_t* h, srslte_cell_t cell, uint32_t phich_m } h->nof_regs += h->cell.nof_prb * n[i]; } - INFO("Indexing %d REGs. CellId: %d, %d PRB, CP: %s\n", h->nof_regs, h->cell.id, h->cell.nof_prb, - SRSLTE_CP_ISNORM(h->cell.cp)?"Normal":"Extended"); + INFO("Indexing %d REGs. CellId: %d, %d PRB, CP: %s\n", + h->nof_regs, + h->cell.id, + h->cell.nof_prb, + SRSLTE_CP_ISNORM(h->cell.cp) ? "Normal" : "Extended"); h->regs = malloc(sizeof(srslte_regs_reg_t) * h->nof_regs); if (!h->regs) { perror("malloc"); @@ -788,7 +785,8 @@ clean_and_exit: /** * Puts one REG data (4 symbols) in the slot symbols array */ -int regs_put_reg(srslte_regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, uint32_t nof_prb) { +int regs_put_reg(srslte_regs_reg_t* reg, cf_t* reg_data, cf_t* slot_symbols, uint32_t nof_prb) +{ uint32_t i; for (i = 0; i < REGS_RE_X_REG; i++) { slot_symbols[REG_IDX(reg, i, nof_prb)] = reg_data[i]; @@ -800,7 +798,8 @@ int regs_put_reg(srslte_regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, uin * Adds one REG data (4 symbols) in the slot symbols array * Used by PHICH */ -int regs_add_reg(srslte_regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, uint32_t nof_prb) { +int regs_add_reg(srslte_regs_reg_t* reg, cf_t* reg_data, cf_t* slot_symbols, uint32_t nof_prb) +{ uint32_t i; for (i = 0; i < REGS_RE_X_REG; i++) { slot_symbols[REG_IDX(reg, i, nof_prb)] += reg_data[i]; @@ -808,11 +807,11 @@ int regs_add_reg(srslte_regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, uin return REGS_RE_X_REG; } - /** * Reset REG data (4 symbols) in the slot symbols array */ -int regs_reset_reg(srslte_regs_reg_t *reg, cf_t *slot_symbols, uint32_t nof_prb) { +int regs_reset_reg(srslte_regs_reg_t* reg, cf_t* slot_symbols, uint32_t nof_prb) +{ uint32_t i; for (i = 0; i < REGS_RE_X_REG; i++) { slot_symbols[REG_IDX(reg, i, nof_prb)] = 0; @@ -823,12 +822,11 @@ int regs_reset_reg(srslte_regs_reg_t *reg, cf_t *slot_symbols, uint32_t nof_prb) /** * Gets one REG data (4 symbols) from the slot symbols array */ -int regs_get_reg(srslte_regs_reg_t *reg, cf_t *slot_symbols, cf_t *reg_data, uint32_t nof_prb) { +int regs_get_reg(srslte_regs_reg_t* reg, cf_t* slot_symbols, cf_t* reg_data, uint32_t nof_prb) +{ uint32_t i; for (i = 0; i < REGS_RE_X_REG; i++) { reg_data[i] = slot_symbols[REG_IDX(reg, i, nof_prb)]; } return REGS_RE_X_REG; } - - diff --git a/lib/src/phy/phch/sch.c b/lib/src/phy/phch/sch.c index 569c16da7..2f91f2bba 100644 --- a/lib/src/phy/phch/sch.c +++ b/lib/src/phy/phch/sch.c @@ -32,67 +32,70 @@ #include #include -#define SRSLTE_PDSCH_MAX_TDEC_ITERS 10 +#define SRSLTE_PDSCH_MAX_TDEC_ITERS 10 #ifdef LV_HAVE_SSE #include #endif /* LV_HAVE_SSE */ - /* 36.213 Table 8.6.3-1: Mapping of HARQ-ACK offset values and the index signalled by higher layers */ -float beta_harq_offset[16] = {2.0, 2.5, 3.125, 4.0, 5.0, 6.250, 8.0, 10.0, - 12.625, 15.875, 20.0, 31.0, 50.0, 80.0, 126.0, -1.0}; - +float beta_harq_offset[16] = + {2.0, 2.5, 3.125, 4.0, 5.0, 6.250, 8.0, 10.0, 12.625, 15.875, 20.0, 31.0, 50.0, 80.0, 126.0, -1.0}; + /* 36.213 Table 8.6.3-2: Mapping of RI offset values and the index signalled by higher layers */ -float beta_ri_offset[16] = {1.25, 1.625, 2.0, 2.5, 3.125, 4.0, 5.0, 6.25, 8.0, 10.0, - 12.625, 15.875, 20.0, -1.0, -1.0, -1.0}; +float beta_ri_offset[16] = + {1.25, 1.625, 2.0, 2.5, 3.125, 4.0, 5.0, 6.25, 8.0, 10.0, 12.625, 15.875, 20.0, -1.0, -1.0, -1.0}; /* 36.213 Table 8.6.3-3: Mapping of CQI offset values and the index signalled by higher layers */ -float beta_cqi_offset[16] = {-1.0, -1.0, 1.125, 1.25, 1.375, 1.625, 1.750, 2.0, 2.25, 2.5, 2.875, - 3.125, 3.5, 4.0, 5.0, 6.25}; - +float beta_cqi_offset[16] = + {-1.0, -1.0, 1.125, 1.25, 1.375, 1.625, 1.750, 2.0, 2.25, 2.5, 2.875, 3.125, 3.5, 4.0, 5.0, 6.25}; -float srslte_sch_beta_cqi(uint32_t I_cqi) { +float srslte_sch_beta_cqi(uint32_t I_cqi) +{ if (I_cqi < 16) { return beta_cqi_offset[I_cqi]; } else { return 0; } } - -uint32_t srslte_sch_find_Ioffset_ack(float beta) { - for (int i=0;i<16;i++) { + +uint32_t srslte_sch_find_Ioffset_ack(float beta) +{ + for (int i = 0; i < 16; i++) { if (beta_harq_offset[i] >= beta) { - return i; + return i; } } return 0; } - -uint32_t srslte_sch_find_Ioffset_ri(float beta) { - for (int i=0;i<16;i++) { + +uint32_t srslte_sch_find_Ioffset_ri(float beta) +{ + for (int i = 0; i < 16; i++) { if (beta_ri_offset[i] >= beta) { - return i; + return i; } } return 0; } - -uint32_t srslte_sch_find_Ioffset_cqi(float beta) { - for (int i=0;i<16;i++) { + +uint32_t srslte_sch_find_Ioffset_cqi(float beta) +{ + for (int i = 0; i < 16; i++) { if (beta_cqi_offset[i] >= beta) { - return i; + return i; } } return 0; } - -int srslte_sch_init(srslte_sch_t *q) { + +int srslte_sch_init(srslte_sch_t* q) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q) { ret = SRSLTE_ERROR; bzero(q, sizeof(srslte_sch_t)); - + if (srslte_crc_init(&q->crc_tb, SRSLTE_LTE_CRC24A, 24)) { ERROR("Error initiating CRC\n"); goto clean; @@ -112,42 +115,43 @@ int srslte_sch_init(srslte_sch_t *q) { } q->max_iterations = SRSLTE_PDSCH_MAX_TDEC_ITERS; - + srslte_rm_turbo_gentables(); - + // Allocate int16 for reception (LLRs) - q->cb_in = srslte_vec_malloc(sizeof(uint8_t) * (SRSLTE_TCOD_MAX_LEN_CB+8)/8); + q->cb_in = srslte_vec_malloc(sizeof(uint8_t) * (SRSLTE_TCOD_MAX_LEN_CB + 8) / 8); if (!q->cb_in) { goto clean; } - + q->parity_bits = srslte_vec_malloc(sizeof(uint8_t) * (3 * SRSLTE_TCOD_MAX_LEN_CB + 16) / 8); if (!q->parity_bits) { goto clean; - } - q->temp_g_bits = srslte_vec_malloc(sizeof(uint8_t)*SRSLTE_MAX_PRB*12*12*12); + } + q->temp_g_bits = srslte_vec_malloc(sizeof(uint8_t) * SRSLTE_MAX_PRB * 12 * 12 * 12); if (!q->temp_g_bits) { - goto clean; + goto clean; } - bzero(q->temp_g_bits, SRSLTE_MAX_PRB*12*12*12); - q->ul_interleaver = srslte_vec_malloc(sizeof(uint32_t)*SRSLTE_MAX_PRB*12*12*12); + bzero(q->temp_g_bits, SRSLTE_MAX_PRB * 12 * 12 * 12); + q->ul_interleaver = srslte_vec_malloc(sizeof(uint32_t) * SRSLTE_MAX_PRB * 12 * 12 * 12); if (!q->ul_interleaver) { - goto clean; + goto clean; } if (srslte_uci_cqi_init(&q->uci_cqi)) { goto clean; } - + ret = SRSLTE_SUCCESS; } -clean: +clean: if (ret == SRSLTE_ERROR) { srslte_sch_free(q); } - return ret; + return ret; } -void srslte_sch_free(srslte_sch_t *q) { +void srslte_sch_free(srslte_sch_t* q) +{ srslte_rm_turbo_free_tables(); if (q->cb_in) { @@ -168,7 +172,8 @@ void srslte_sch_free(srslte_sch_t *q) { bzero(q, sizeof(srslte_sch_t)); } -void srslte_sch_set_max_noi(srslte_sch_t *q, uint32_t max_iterations) { +void srslte_sch_set_max_noi(srslte_sch_t* q, uint32_t max_iterations) +{ q->max_iterations = max_iterations; } @@ -180,13 +185,18 @@ float srslte_sch_last_noi(srslte_sch_t* q) /* Encode a transport block according to 36.212 5.3.2 * */ -static int encode_tb_off(srslte_sch_t *q, - srslte_softbuffer_tx_t *softbuffer, srslte_cbsegm_t *cb_segm, - uint32_t Qm, uint32_t rv, uint32_t nof_e_bits, - uint8_t *data, uint8_t *e_bits, uint32_t w_offset) +static int encode_tb_off(srslte_sch_t* q, + srslte_softbuffer_tx_t* softbuffer, + srslte_cbsegm_t* cb_segm, + uint32_t Qm, + uint32_t rv, + uint32_t nof_e_bits, + uint8_t* data, + uint8_t* e_bits, + uint32_t w_offset) { uint32_t i; - uint32_t cb_len=0, rp=0, wp=0, rlen=0, n_e=0; + uint32_t cb_len = 0, rp = 0, wp = 0, rlen = 0, n_e = 0; int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL && e_bits != NULL && cb_segm != NULL && softbuffer != NULL) { @@ -198,14 +208,14 @@ static int encode_tb_off(srslte_sch_t *q, if (cb_segm->C > softbuffer->max_cb) { ERROR("Error number of CB to encode (%d) exceeds soft buffer size (%d CBs)\n", cb_segm->C, softbuffer->max_cb); - return -1; + return -1; } uint32_t Gp = nof_e_bits / Qm; - + uint32_t gamma = Gp; if (cb_segm->C > 0) { - gamma = Gp%cb_segm->C; + gamma = Gp % cb_segm->C; } /* Reset TB CRC */ @@ -215,13 +225,13 @@ static int encode_tb_off(srslte_sch_t *q, rp = 0; for (i = 0; i < cb_segm->C; i++) { - uint32_t cblen_idx; + uint32_t cblen_idx; /* Get read lengths */ if (i < cb_segm->C2) { - cb_len = cb_segm->K2; + cb_len = cb_segm->K2; cblen_idx = cb_segm->K2_idx; } else { - cb_len = cb_segm->K1; + cb_len = cb_segm->K1; cblen_idx = cb_segm->K1_idx; } if (cb_segm->C > 1) { @@ -230,27 +240,25 @@ static int encode_tb_off(srslte_sch_t *q, rlen = cb_len; } if (i <= cb_segm->C - gamma - 1) { - n_e = Qm * (Gp/cb_segm->C); + n_e = Qm * (Gp / cb_segm->C); } else { - n_e = Qm * ((uint32_t) ceilf((float) Gp/cb_segm->C)); + n_e = Qm * ((uint32_t)ceilf((float)Gp / cb_segm->C)); } - INFO("CB#%d: cb_len: %d, rlen: %d, wp: %d, rp: %d, E: %d\n", i, - cb_len, rlen, wp, rp, n_e); + INFO("CB#%d: cb_len: %d, rlen: %d, wp: %d, rp: %d, E: %d\n", i, cb_len, rlen, wp, rp, n_e); if (data) { bool last_cb = false; /* Copy data to another buffer, making space for the Codeblock CRC */ if (i < cb_segm->C - 1) { - // Copy data - memcpy(q->cb_in, &data[rp/8], rlen * sizeof(uint8_t)/8); + // Copy data + memcpy(q->cb_in, &data[rp / 8], rlen * sizeof(uint8_t) / 8); } else { - INFO("Last CB, appending parity: %d from %d and 24 to %d\n", - rlen - 24, rp, rlen - 24); - + INFO("Last CB, appending parity: %d from %d and 24 to %d\n", rlen - 24, rp, rlen - 24); + /* Append Transport Block parity bits to the last CB */ - memcpy(q->cb_in, &data[rp/8], (rlen - 24) * sizeof(uint8_t)/8); + memcpy(q->cb_in, &data[rp / 8], (rlen - 24) * sizeof(uint8_t) / 8); last_cb = true; } @@ -265,12 +273,17 @@ static int encode_tb_off(srslte_sch_t *q, cblen_idx, last_cb); } - DEBUG("RM cblen_idx=%d, n_e=%d, wp=%d, nof_e_bits=%d\n",cblen_idx, n_e, wp, nof_e_bits); - + DEBUG("RM cblen_idx=%d, n_e=%d, wp=%d, nof_e_bits=%d\n", cblen_idx, n_e, wp, nof_e_bits); + /* Rate matching */ - if (srslte_rm_turbo_tx_lut(softbuffer->buffer_b[i], q->cb_in, q->parity_bits, - &e_bits[(wp+w_offset)/8], cblen_idx, n_e, (wp+w_offset)%8, rv)) - { + if (srslte_rm_turbo_tx_lut(softbuffer->buffer_b[i], + q->cb_in, + q->parity_bits, + &e_bits[(wp + w_offset) / 8], + cblen_idx, + n_e, + (wp + w_offset) % 8, + rv)) { ERROR("Error in rate matching\n"); return SRSLTE_ERROR; } @@ -279,7 +292,7 @@ static int encode_tb_off(srslte_sch_t *q, rp += rlen; wp += n_e; } - + INFO("END CB#%d: wp: %d, rp: %d\n", i, wp, rp); ret = SRSLTE_SUCCESS; } else { @@ -288,22 +301,30 @@ static int encode_tb_off(srslte_sch_t *q, return ret; } -static int encode_tb(srslte_sch_t *q, - srslte_softbuffer_tx_t *soft_buffer, srslte_cbsegm_t *cb_segm, - uint32_t Qm, uint32_t rv, uint32_t nof_e_bits, - uint8_t *data, uint8_t *e_bits) +static int encode_tb(srslte_sch_t* q, + srslte_softbuffer_tx_t* soft_buffer, + srslte_cbsegm_t* cb_segm, + uint32_t Qm, + uint32_t rv, + uint32_t nof_e_bits, + uint8_t* data, + uint8_t* e_bits) { return encode_tb_off(q, soft_buffer, cb_segm, Qm, rv, nof_e_bits, data, e_bits, 0); } -bool decode_tb_cb(srslte_sch_t *q, - srslte_softbuffer_rx_t *softbuffer, srslte_cbsegm_t *cb_segm, - uint32_t Qm, uint32_t rv, uint32_t nof_e_bits, - void *e_bits, uint8_t *data) +bool decode_tb_cb(srslte_sch_t* q, + srslte_softbuffer_rx_t* softbuffer, + srslte_cbsegm_t* cb_segm, + uint32_t Qm, + uint32_t rv, + uint32_t nof_e_bits, + void* e_bits, + uint8_t* data) { - int8_t *e_bits_b = e_bits; - int16_t *e_bits_s = e_bits; + int8_t* e_bits_b = e_bits; + int16_t* e_bits_s = e_bits; if (cb_segm->C > SRSLTE_MAX_CODEBLOCKS) { ERROR("Error SRSLTE_MAX_CODEBLOCKS=%d\n", SRSLTE_MAX_CODEBLOCKS); @@ -312,29 +333,28 @@ bool decode_tb_cb(srslte_sch_t *q, q->avg_iterations = 0; - for (int cb_idx=0;cb_idxC;cb_idx++) - { + for (int cb_idx = 0; cb_idx < cb_segm->C; cb_idx++) { /* Do not process blocks with CRC Ok */ if (softbuffer->cb_crc[cb_idx] == false) { - uint32_t cb_len = cb_idxC1?cb_segm->K1:cb_segm->K2; - uint32_t cb_len_idx = cb_idxC1?cb_segm->K1_idx:cb_segm->K2_idx; + uint32_t cb_len = cb_idx < cb_segm->C1 ? cb_segm->K1 : cb_segm->K2; + uint32_t cb_len_idx = cb_idx < cb_segm->C1 ? cb_segm->K1_idx : cb_segm->K2_idx; - uint32_t rlen = cb_segm->C==1?cb_len:(cb_len-24); - uint32_t Gp = nof_e_bits / Qm; - uint32_t gamma = cb_segm->C>0?Gp%cb_segm->C:Gp; - uint32_t n_e = Qm * (Gp/cb_segm->C); + uint32_t rlen = cb_segm->C == 1 ? cb_len : (cb_len - 24); + uint32_t Gp = nof_e_bits / Qm; + uint32_t gamma = cb_segm->C > 0 ? Gp % cb_segm->C : Gp; + uint32_t n_e = Qm * (Gp / cb_segm->C); - uint32_t rp = cb_idx*n_e; + uint32_t rp = cb_idx * n_e; uint32_t n_e2 = n_e; if (cb_idx > cb_segm->C - gamma) { - n_e2 = n_e+Qm; - rp = (cb_segm->C - gamma)*n_e + (cb_idx-(cb_segm->C - gamma))*n_e2; + n_e2 = n_e + Qm; + rp = (cb_segm->C - gamma) * n_e + (cb_idx - (cb_segm->C - gamma)) * n_e2; } if (q->llr_is_8bit) { - if (srslte_rm_turbo_rx_lut_8bit(&e_bits_b[rp], (int8_t*) softbuffer->buffer_f[cb_idx], n_e2, cb_len_idx, rv)) { + if (srslte_rm_turbo_rx_lut_8bit(&e_bits_b[rp], (int8_t*)softbuffer->buffer_f[cb_idx], n_e2, cb_len_idx, rv)) { ERROR("Error in rate matching\n"); return SRSLTE_ERROR; } @@ -348,33 +368,33 @@ bool decode_tb_cb(srslte_sch_t *q, srslte_tdec_new_cb(&q->decoder, cb_len); // Run iterations and use CRC for early stopping - bool early_stop = false; - uint32_t cb_noi = 0; + bool early_stop = false; + uint32_t cb_noi = 0; do { if (q->llr_is_8bit) { - srslte_tdec_iteration_8bit(&q->decoder, (int8_t*) softbuffer->buffer_f[cb_idx], &data[cb_idx*rlen/8]); + srslte_tdec_iteration_8bit(&q->decoder, (int8_t*)softbuffer->buffer_f[cb_idx], &data[cb_idx * rlen / 8]); } else { - srslte_tdec_iteration(&q->decoder, softbuffer->buffer_f[cb_idx], &data[cb_idx*rlen/8]); + srslte_tdec_iteration(&q->decoder, softbuffer->buffer_f[cb_idx], &data[cb_idx * rlen / 8]); } q->avg_iterations++; cb_noi++; - uint32_t len_crc; + uint32_t len_crc; srslte_crc_t* crc_ptr; if (cb_segm->C > 1) { len_crc = cb_len; crc_ptr = &q->crc_cb; } else { - len_crc = cb_segm->tbs+24; + len_crc = cb_segm->tbs + 24; crc_ptr = &q->crc_tb; } // CRC is OK - if (!srslte_crc_checksum_byte(crc_ptr, &data[cb_idx*rlen/8], len_crc)) { + if (!srslte_crc_checksum_byte(crc_ptr, &data[cb_idx * rlen / 8], len_crc)) { softbuffer->cb_crc[cb_idx] = true; - early_stop = true; + early_stop = true; // CRC is error and exceeded maximum iterations for this CB. // Early stop the whole transport block. @@ -383,13 +403,20 @@ bool decode_tb_cb(srslte_sch_t *q, } while (cb_noi < q->max_iterations && !early_stop); INFO("CB %d: rp=%d, n_e=%d, cb_len=%d, CRC=%s, rlen=%d, iterations=%d/%d\n", - cb_idx, rp, n_e2, cb_len, early_stop?"OK":"KO", rlen, cb_noi, q->max_iterations); + cb_idx, + rp, + n_e2, + cb_len, + early_stop ? "OK" : "KO", + rlen, + cb_noi, + q->max_iterations); } else { // Copy decoded data from previous transmissions - uint32_t cb_len = cb_idxC1?cb_segm->K1:cb_segm->K2; - uint32_t rlen = cb_segm->C==1?cb_len:(cb_len-24); - memcpy(&data[cb_idx*rlen/8], softbuffer->data[cb_idx], rlen/8 * sizeof(uint8_t)); + uint32_t cb_len = cb_idx < cb_segm->C1 ? cb_segm->K1 : cb_segm->K2; + uint32_t rlen = cb_segm->C == 1 ? cb_len : (cb_len - 24); + memcpy(&data[cb_idx * rlen / 8], softbuffer->data[cb_idx], rlen / 8 * sizeof(uint8_t)); } } @@ -402,9 +429,9 @@ bool decode_tb_cb(srslte_sch_t *q, if (!softbuffer->tb_crc) { for (int i = 0; i < cb_segm->C; i++) { if (softbuffer->cb_crc[i]) { - uint32_t cb_len = iC1?cb_segm->K1:cb_segm->K2; - uint32_t rlen = cb_segm->C==1?cb_len:(cb_len-24); - memcpy(softbuffer->data[i], &data[i * rlen / 8], rlen/8 * sizeof(uint8_t)); + uint32_t cb_len = i < cb_segm->C1 ? cb_segm->K1 : cb_segm->K2; + uint32_t rlen = cb_segm->C == 1 ? cb_len : (cb_len - 24); + memcpy(softbuffer->data[i], &data[i * rlen / 8], rlen / 8 * sizeof(uint8_t)); } } } @@ -435,49 +462,45 @@ static int decode_tb(srslte_sch_t* q, int16_t* e_bits, uint8_t* data) { - - if (q != NULL && - data != NULL && - softbuffer != NULL && - e_bits != NULL && - cb_segm != NULL) - { - + + if (q != NULL && data != NULL && softbuffer != NULL && e_bits != NULL && cb_segm != NULL) { + if (cb_segm->tbs == 0 || cb_segm->C == 0) { return SRSLTE_SUCCESS; } - + if (cb_segm->F) { fprintf(stderr, "Error filler bits are not supported. Use standard TBS\n"); return SRSLTE_ERROR_INVALID_INPUTS; } if (cb_segm->C > softbuffer->max_cb) { - fprintf(stderr, "Error number of CB to decode (%d) exceeds soft buffer size (%d CBs)\n", cb_segm->C, + fprintf(stderr, + "Error number of CB to decode (%d) exceeds soft buffer size (%d CBs)\n", + cb_segm->C, softbuffer->max_cb); return SRSLTE_ERROR_INVALID_INPUTS; } - - bool crc_ok = true; - data[cb_segm->tbs/8+0] = 0; - data[cb_segm->tbs/8+1] = 0; - data[cb_segm->tbs/8+2] = 0; - + bool crc_ok = true; + + data[cb_segm->tbs / 8 + 0] = 0; + data[cb_segm->tbs / 8 + 1] = 0; + data[cb_segm->tbs / 8 + 2] = 0; + // Process Codeblocks crc_ok = decode_tb_cb(q, softbuffer, cb_segm, Qm, rv, nof_e_bits, e_bits, data); if (crc_ok) { uint32_t par_rx = 0, par_tx = 0; - + // Compute transport block CRC par_rx = srslte_crc_checksum_byte(&q->crc_tb, data, cb_segm->tbs); // check parity bits - par_tx = ((uint32_t) data[cb_segm->tbs/8+0])<<16 | - ((uint32_t) data[cb_segm->tbs/8+1])<<8 | - ((uint32_t) data[cb_segm->tbs/8+2]); + par_tx = ((uint32_t)data[cb_segm->tbs / 8 + 0]) << 16 | ((uint32_t)data[cb_segm->tbs / 8 + 1]) << 8 | + ((uint32_t)data[cb_segm->tbs / 8 + 2]); if (par_rx == par_tx && par_rx) { INFO("TB decoded OK\n"); @@ -487,8 +510,8 @@ static int decode_tb(srslte_sch_t* q, return SRSLTE_ERROR; } } else { - return SRSLTE_ERROR; - } + return SRSLTE_ERROR; + } } else { ERROR("Missing inputs: data=%d, softbuffer=%d, e_bits=%d, cb_segm=%d\n", data != 0, @@ -504,8 +527,12 @@ int srslte_dlsch_decode(srslte_sch_t* q, srslte_pdsch_cfg_t* cfg, int16_t* e_bit return srslte_dlsch_decode2(q, cfg, e_bits, data, 0, 1); } -int srslte_dlsch_decode2( - srslte_sch_t* q, srslte_pdsch_cfg_t* cfg, int16_t* e_bits, uint8_t* data, int tb_idx, uint32_t nof_layers) +int srslte_dlsch_decode2(srslte_sch_t* q, + srslte_pdsch_cfg_t* cfg, + int16_t* e_bits, + uint8_t* data, + int tb_idx, + uint32_t nof_layers) { uint32_t Nl = 1; @@ -546,8 +573,12 @@ int srslte_dlsch_encode(srslte_sch_t* q, srslte_pdsch_cfg_t* cfg, uint8_t* data, return srslte_dlsch_encode2(q, cfg, data, e_bits, 0, 1); } -int srslte_dlsch_encode2( - srslte_sch_t* q, srslte_pdsch_cfg_t* cfg, uint8_t* data, uint8_t* e_bits, int tb_idx, uint32_t nof_layers) +int srslte_dlsch_encode2(srslte_sch_t* q, + srslte_pdsch_cfg_t* cfg, + uint8_t* data, + uint8_t* e_bits, + int tb_idx, + uint32_t nof_layers) { uint32_t Nl = 1; @@ -577,38 +608,47 @@ int srslte_dlsch_encode2( /* Compute the interleaving function on-the-fly, because it depends on number of RI bits * Profiling show that the computation of this matrix is neglegible. */ -static void ulsch_interleave_gen(uint32_t H_prime_total, uint32_t N_pusch_symbs, uint32_t Qm, - uint8_t *ri_present, uint32_t *interleaver_lut) +static void ulsch_interleave_gen(uint32_t H_prime_total, + uint32_t N_pusch_symbs, + uint32_t Qm, + uint8_t* ri_present, + uint32_t* interleaver_lut) { - uint32_t rows = H_prime_total/N_pusch_symbs; + uint32_t rows = H_prime_total / N_pusch_symbs; uint32_t cols = N_pusch_symbs; - uint32_t idx = 0; - for(uint32_t j=0; j> (6 - read_bit_idx)) & (uint8_t) 0x03; + uint32_t write_bit_idx = k % 8; + uint8_t w = (g_bits[read_byte_idx] >> (6 - read_bit_idx)) & (uint8_t)0x03; q_bits[write_byte_idx] |= w << (6 - write_bit_idx); bit_read_idx += 2; @@ -622,10 +662,10 @@ static void ulsch_interleave_qm2(const uint8_t *g_bits, uint32_t rows, uint32_t if (ri_present[k]) { /* do nothing */ } else { - uint32_t read_byte_idx = bit_read_idx / 8; - uint32_t read_bit_idx = bit_read_idx % 8; + uint32_t read_byte_idx = bit_read_idx / 8; + uint32_t read_bit_idx = bit_read_idx % 8; uint32_t write_byte_idx = k / 8; - uint32_t write_bit_idx = k % 8; + uint32_t write_bit_idx = k % 8; uint8_t w = (g_bits[read_byte_idx] >> (6 - read_bit_idx)) & (uint8_t)0x03; q_bits[write_byte_idx] |= w << (6 - write_bit_idx); @@ -635,16 +675,22 @@ static void ulsch_interleave_qm2(const uint8_t *g_bits, uint32_t rows, uint32_t } } -static void ulsch_interleave_qm4(uint8_t *g_bits, uint32_t rows, uint32_t cols, uint8_t *q_bits, uint32_t ri_min_row, const uint8_t *ri_present) { +static void ulsch_interleave_qm4(uint8_t* g_bits, + uint32_t rows, + uint32_t cols, + uint8_t* q_bits, + uint32_t ri_min_row, + const uint8_t* ri_present) +{ uint32_t bit_read_idx = 0; - + for (uint32_t j = 0; j < ri_min_row; j++) { int32_t i = 0; #ifdef DOES_NOT_WORK #ifndef HAVE_NEON - __m128i _counter = _mm_slli_epi32(_mm_add_epi32(_mm_mullo_epi32(_counter0,_rows),_mm_set1_epi32(j)), 2); - uint8_t *_g_bits = &g_bits[bit_read_idx/8]; + __m128i _counter = _mm_slli_epi32(_mm_add_epi32(_mm_mullo_epi32(_counter0, _rows), _mm_set1_epi32(j)), 2); + uint8_t* _g_bits = &g_bits[bit_read_idx / 8]; /* First bits are aligned to byte */ if (0 == (bit_read_idx & 0x3)) { @@ -654,8 +700,8 @@ static void ulsch_interleave_qm4(uint8_t *g_bits, uint32_t rows, uint32_t cols, uint8_t w2 = *(_g_bits++); __m128i _write_byte_idx = _mm_srli_epi32(_counter, 3); - __m128i _write_bit_idx = _mm_and_si128(_counter, _7); - __m128i _write_shift = _mm_sub_epi32(_4, _write_bit_idx); + __m128i _write_bit_idx = _mm_and_si128(_counter, _7); + __m128i _write_shift = _mm_sub_epi32(_4, _write_bit_idx); q_bits[_mm_extract_epi32(_write_byte_idx, 0)] |= (w1 >> 0x4) << _mm_extract_epi32(_write_shift, 0); q_bits[_mm_extract_epi32(_write_byte_idx, 1)] |= (w1 & 0xf) << _mm_extract_epi32(_write_shift, 1); @@ -666,8 +712,8 @@ static void ulsch_interleave_qm4(uint8_t *g_bits, uint32_t rows, uint32_t cols, } else { for (; i < (cols - 3); i += 4) { __m128i _write_byte_idx = _mm_srli_epi32(_counter, 3); - __m128i _write_bit_idx = _mm_and_si128(_counter, _7); - __m128i _write_shift = _mm_sub_epi32(_4, _write_bit_idx); + __m128i _write_bit_idx = _mm_and_si128(_counter, _7); + __m128i _write_shift = _mm_sub_epi32(_4, _write_bit_idx); uint8_t w1 = *(_g_bits); uint8_t w2 = *(_g_bits++); @@ -681,18 +727,18 @@ static void ulsch_interleave_qm4(uint8_t *g_bits, uint32_t rows, uint32_t cols, } } bit_read_idx += i * 4; - #endif /* HAVE_NEON */ +#endif /* HAVE_NEON */ #endif /* LV_HAVE_SSE */ /* Spare bits */ for (; i < cols; i++) { uint32_t k = (i * rows + j) * 4; - uint32_t read_byte_idx = bit_read_idx / 8; - uint32_t read_bit_idx = bit_read_idx % 8; + uint32_t read_byte_idx = bit_read_idx / 8; + uint32_t read_bit_idx = bit_read_idx % 8; uint32_t write_byte_idx = k / 8; - uint32_t write_bit_idx = k % 8; - uint8_t w = (g_bits[read_byte_idx] >> (4 - read_bit_idx)) & (uint8_t) 0x0f; + uint32_t write_bit_idx = k % 8; + uint8_t w = (g_bits[read_byte_idx] >> (4 - read_bit_idx)) & (uint8_t)0x0f; q_bits[write_byte_idx] |= w << (4 - write_bit_idx); bit_read_idx += 4; @@ -707,50 +753,50 @@ static void ulsch_interleave_qm4(uint8_t *g_bits, uint32_t rows, uint32_t cols, if (ri_present[k]) { /* do nothing */ } else { - uint32_t read_byte_idx = bit_read_idx / 8; - uint32_t read_bit_idx = bit_read_idx % 8; + uint32_t read_byte_idx = bit_read_idx / 8; + uint32_t read_bit_idx = bit_read_idx % 8; uint32_t write_byte_idx = k / 8; - uint32_t write_bit_idx = k % 8; - uint8_t w = (g_bits[read_byte_idx] >> (4 - read_bit_idx)) & (uint8_t) 0x0f; + uint32_t write_bit_idx = k % 8; + uint8_t w = (g_bits[read_byte_idx] >> (4 - read_bit_idx)) & (uint8_t)0x0f; q_bits[write_byte_idx] |= w << (4 - write_bit_idx); bit_read_idx += 4; } } - } } -static void ulsch_interleave_qm6(const uint8_t *g_bits, - uint32_t rows, - uint32_t cols, - uint8_t *q_bits, - uint32_t ri_min_row, - const uint8_t *ri_present) { +static void ulsch_interleave_qm6(const uint8_t* g_bits, + uint32_t rows, + uint32_t cols, + uint8_t* q_bits, + uint32_t ri_min_row, + const uint8_t* ri_present) +{ uint32_t bit_read_idx = 0; for (uint32_t j = 0; j < ri_min_row; j++) { for (uint32_t i = 0; i < cols; i++) { uint32_t k = (i * rows + j) * 6; - uint32_t read_byte_idx = bit_read_idx / 8; - uint32_t read_bit_idx = bit_read_idx % 8; + uint32_t read_byte_idx = bit_read_idx / 8; + uint32_t read_bit_idx = bit_read_idx % 8; uint32_t write_byte_idx = k / 8; - uint32_t write_bit_idx = k % 8; - uint8_t w; + uint32_t write_bit_idx = k % 8; + uint8_t w; switch (read_bit_idx) { case 0: w = g_bits[read_byte_idx] >> 2; break; case 2: - w = g_bits[read_byte_idx] & (uint8_t) 0x3f; + w = g_bits[read_byte_idx] & (uint8_t)0x3f; break; case 4: - w = ((g_bits[read_byte_idx] << 2) | (g_bits[read_byte_idx + 1] >> 6)) & (uint8_t) 0x3f; + w = ((g_bits[read_byte_idx] << 2) | (g_bits[read_byte_idx + 1] >> 6)) & (uint8_t)0x3f; break; case 6: - w = ((g_bits[read_byte_idx] << 4) | (g_bits[read_byte_idx + 1] >> 4)) & (uint8_t) 0x3f; + w = ((g_bits[read_byte_idx] << 4) | (g_bits[read_byte_idx + 1] >> 4)) & (uint8_t)0x3f; break; default: w = 0; @@ -786,24 +832,24 @@ static void ulsch_interleave_qm6(const uint8_t *g_bits, if (ri_present[k]) { /* do nothing */ } else { - uint32_t read_byte_idx = bit_read_idx / 8; - uint32_t read_bit_idx = bit_read_idx % 8; + uint32_t read_byte_idx = bit_read_idx / 8; + uint32_t read_bit_idx = bit_read_idx % 8; uint32_t write_byte_idx = k / 8; - uint32_t write_bit_idx = k % 8; - uint8_t w; + uint32_t write_bit_idx = k % 8; + uint8_t w; switch (read_bit_idx) { case 0: w = g_bits[read_byte_idx] >> 2; break; case 2: - w = g_bits[read_byte_idx] & (uint8_t) 0x3f; + w = g_bits[read_byte_idx] & (uint8_t)0x3f; break; case 4: - w = ((g_bits[read_byte_idx] << 2) | (g_bits[read_byte_idx + 1] >> 6)) & (uint8_t) 0x3f; + w = ((g_bits[read_byte_idx] << 2) | (g_bits[read_byte_idx + 1] >> 6)) & (uint8_t)0x3f; break; case 6: - w = ((g_bits[read_byte_idx] << 4) | (g_bits[read_byte_idx + 1] >> 4)) & (uint8_t) 0x3f; + w = ((g_bits[read_byte_idx] << 4) | (g_bits[read_byte_idx + 1] >> 4)) & (uint8_t)0x3f; break; default: w = 0; @@ -845,14 +891,14 @@ static void ulsch_interleave(uint8_t* g_bits, uint8_t* ri_present) { - const uint32_t nof_bits = H_prime_total * Qm; - uint32_t rows = H_prime_total / N_pusch_symbs; - uint32_t cols = N_pusch_symbs; - uint32_t ri_min_row = rows; + const uint32_t nof_bits = H_prime_total * Qm; + uint32_t rows = H_prime_total / N_pusch_symbs; + uint32_t cols = N_pusch_symbs; + uint32_t ri_min_row = rows; // Prepare ri_bits for fast search using temp_buffer if (nof_ri_bits > 0) { - for (uint32_t i=0;i 0) { - for (uint32_t i=0;igrant.tb.nof_bits; uint32_t Qm = srslte_mod_bits_x_symbol(cfg->grant.tb.mod); @@ -1127,7 +1176,7 @@ int srslte_ulsch_encode(srslte_sch_t* q, } Q_prime_ri = (uint32_t)ret; } - + // Encode CQI if (uci_cqi_len > 0) { ret = srslte_uci_encode_cqi_pusch(&q->uci_cqi, @@ -1138,7 +1187,7 @@ int srslte_ulsch_encode(srslte_sch_t* q, Q_prime_ri, q->temp_g_bits); if (ret < 0) { - return ret; + return ret; } Q_prime_cqi = (uint32_t)ret; @@ -1148,12 +1197,12 @@ int srslte_ulsch_encode(srslte_sch_t* q, srslte_vec_fprint_b(stdout, q->temp_g_bits, Q_prime_cqi*Qm); }*/ - srslte_bit_pack_vector(q->temp_g_bits, g_bits, Q_prime_cqi*Qm); + srslte_bit_pack_vector(q->temp_g_bits, g_bits, Q_prime_cqi * Qm); // Reset the buffer because will be reused in ulsch_interleave bzero(q->temp_g_bits, Q_prime_cqi * Qm); } - - e_offset += Q_prime_cqi*Qm; + + e_offset += Q_prime_cqi * Qm; // Encode UL-SCH if (cb_segm.tbs > 0) { @@ -1161,10 +1210,10 @@ int srslte_ulsch_encode(srslte_sch_t* q, ret = encode_tb_off( q, cfg->softbuffers.tx, &cb_segm, Qm, cfg->grant.tb.rv, G * Qm, data, &g_bits[e_offset / 8], e_offset % 8); if (ret) { - return ret; - } - } - + return ret; + } + } + // Interleave UL-SCH (and RI and CQI) ulsch_interleave(g_bits, Qm, nb_q / Qm, cfg->grant.nof_symb, q_bits, q->ack_ri_bits, Q_prime_ri * Qm, q->temp_g_bits); @@ -1184,9 +1233,9 @@ int srslte_ulsch_encode(srslte_sch_t* q, cfg->uci_cfg.ack[0].N_bundle, &q->ack_ri_bits[Q_prime_ri * Qm]); if (ret < 0) { - return ret; + return ret; } - Q_prime_ack = (uint32_t) ret; + Q_prime_ack = (uint32_t)ret; } uint32_t nof_ri_ack_bits = (Q_prime_ack + Q_prime_ri) * Qm; @@ -1195,9 +1244,9 @@ int srslte_ulsch_encode(srslte_sch_t* q, uint32_t p = q->ack_ri_bits[i].position; if (p < nb_q) { if (q->ack_ri_bits[i].type == UCI_BIT_1) { - q_bits[p/8] |= (1<<(7-p%8)); + q_bits[p / 8] |= (1 << (7 - p % 8)); } else { - q_bits[p/8] &= ~(1<<(7-p%8)); + q_bits[p / 8] &= ~(1 << (7 - p % 8)); } } else { ERROR("Invalid RI/ACK bit %d/%d, position %d. Max bits=%d, Qm=%d\n", i, nof_ri_ack_bits, p, nb_q, Qm); @@ -1208,4 +1257,3 @@ int srslte_ulsch_encode(srslte_sch_t* q, return nof_ri_ack_bits; } - diff --git a/lib/src/phy/phch/sequences.c b/lib/src/phy/phch/sequences.c index 1ea7f51df..564197871 100644 --- a/lib/src/phy/phch/sequences.c +++ b/lib/src/phy/phch/sequences.c @@ -19,57 +19,63 @@ * */ -#include #include "srslte/phy/common/phy_common.h" #include "srslte/phy/common/sequence.h" +#include /** * 36.211 6.6.1 */ -int srslte_sequence_pbch(srslte_sequence_t *seq, srslte_cp_t cp, uint32_t cell_id) { - return srslte_sequence_LTE_pr(seq, SRSLTE_CP_ISNORM(cp)?1920:1728, cell_id); +int srslte_sequence_pbch(srslte_sequence_t* seq, srslte_cp_t cp, uint32_t cell_id) +{ + return srslte_sequence_LTE_pr(seq, SRSLTE_CP_ISNORM(cp) ? 1920 : 1728, cell_id); } /** * 36.211 6.7.1 */ -int srslte_sequence_pcfich(srslte_sequence_t *seq, uint32_t nslot, uint32_t cell_id) { - return srslte_sequence_LTE_pr(seq, 32, (nslot/2+1) * (2*cell_id + 1) * 512 + cell_id); +int srslte_sequence_pcfich(srslte_sequence_t* seq, uint32_t nslot, uint32_t cell_id) +{ + return srslte_sequence_LTE_pr(seq, 32, (nslot / 2 + 1) * (2 * cell_id + 1) * 512 + cell_id); } - /** * 36.211 6.9.1 */ -int srslte_sequence_phich(srslte_sequence_t *seq, uint32_t nslot, uint32_t cell_id) { - return srslte_sequence_LTE_pr(seq, 12, (nslot/2+1) * (2*cell_id + 1) * 512 + cell_id); +int srslte_sequence_phich(srslte_sequence_t* seq, uint32_t nslot, uint32_t cell_id) +{ + return srslte_sequence_LTE_pr(seq, 12, (nslot / 2 + 1) * (2 * cell_id + 1) * 512 + cell_id); } /** * 36.211 6.8.2 */ -int srslte_sequence_pdcch(srslte_sequence_t *seq, uint32_t nslot, uint32_t cell_id, uint32_t len) { - return srslte_sequence_LTE_pr(seq, len, (nslot/2) * 512 + cell_id); +int srslte_sequence_pdcch(srslte_sequence_t* seq, uint32_t nslot, uint32_t cell_id, uint32_t len) +{ + return srslte_sequence_LTE_pr(seq, len, (nslot / 2) * 512 + cell_id); } /** * 36.211 6.3.1 */ -int srslte_sequence_pdsch(srslte_sequence_t *seq, uint16_t rnti, int q, uint32_t nslot, uint32_t cell_id, uint32_t len) { - return srslte_sequence_LTE_pr(seq, len, (rnti<<14) + (q<<13) + ((nslot/2)<<9) + cell_id); +int srslte_sequence_pdsch(srslte_sequence_t* seq, uint16_t rnti, int q, uint32_t nslot, uint32_t cell_id, uint32_t len) +{ + return srslte_sequence_LTE_pr(seq, len, (rnti << 14) + (q << 13) + ((nslot / 2) << 9) + cell_id); } /** * 36.211 5.3.1 */ -int srslte_sequence_pusch(srslte_sequence_t *seq, uint16_t rnti, uint32_t nslot, uint32_t cell_id, uint32_t len) { - return srslte_sequence_LTE_pr(seq, len, (rnti<<14) + ((nslot/2)<<9) + cell_id); +int srslte_sequence_pusch(srslte_sequence_t* seq, uint16_t rnti, uint32_t nslot, uint32_t cell_id, uint32_t len) +{ + return srslte_sequence_LTE_pr(seq, len, (rnti << 14) + ((nslot / 2) << 9) + cell_id); } /** * 36.211 5.4.2 */ -int srslte_sequence_pucch(srslte_sequence_t *seq, uint16_t rnti, uint32_t nslot, uint32_t cell_id) { +int srslte_sequence_pucch(srslte_sequence_t* seq, uint16_t rnti, uint32_t nslot, uint32_t cell_id) +{ return srslte_sequence_LTE_pr(seq, 12 * 4, ((((nslot / 2) + 1) * (2 * cell_id + 1)) << 16) + rnti); } @@ -82,15 +88,16 @@ int srslte_sequence_pmch(srslte_sequence_t* seq, uint32_t nslot, uint32_t mbsfn_ /** * 36.211 6.6.1 and 10.2.4.1 (13.2.0) */ -int srslte_sequence_npbch(srslte_sequence_t *seq, srslte_cp_t cp, uint32_t cell_id) { - bzero(seq, sizeof(srslte_sequence_t)); - return srslte_sequence_LTE_pr(seq, SRSLTE_NBIOT_NPBCH_NOF_TOTAL_BITS, cell_id); +int srslte_sequence_npbch(srslte_sequence_t* seq, srslte_cp_t cp, uint32_t cell_id) +{ + bzero(seq, sizeof(srslte_sequence_t)); + return srslte_sequence_LTE_pr(seq, SRSLTE_NBIOT_NPBCH_NOF_TOTAL_BITS, cell_id); } /** * 36.211 6.6.1 and 10.2.4.4 (14.2.0) */ -int srslte_sequence_npbch_r14(srslte_sequence_t *seq, uint32_t n_id_ncell, uint32_t nf) +int srslte_sequence_npbch_r14(srslte_sequence_t* seq, uint32_t n_id_ncell, uint32_t nf) { bzero(seq, sizeof(srslte_sequence_t)); return srslte_sequence_LTE_pr(seq, @@ -102,39 +109,55 @@ int srslte_sequence_npbch_r14(srslte_sequence_t *seq, uint32_t n_id_ncell, uint3 /** * 36.211 6.3.1 and 10.2.3.1 (13.2.0) */ -int srslte_sequence_npdsch(srslte_sequence_t *seq, uint16_t rnti, int q, uint32_t nf, uint32_t nslot, uint32_t cell_id, uint32_t len) { +int srslte_sequence_npdsch(srslte_sequence_t* seq, + uint16_t rnti, + int q, + uint32_t nf, + uint32_t nslot, + uint32_t cell_id, + uint32_t len) +{ bzero(seq, sizeof(srslte_sequence_t)); - return srslte_sequence_LTE_pr(seq, len, (rnti<<14) + ((nf % 2)<<13) + ((nslot/2)<<9) + cell_id); + return srslte_sequence_LTE_pr(seq, len, (rnti << 14) + ((nf % 2) << 13) + ((nslot / 2) << 9) + cell_id); } /** * 36.211 6.3.1 and 10.2.3.1 (14.2.0) */ -int srslte_sequence_npdsch_bcch_r14(srslte_sequence_t *seq, uint32_t nf, uint32_t n_id_ncell, uint32_t len) { +int srslte_sequence_npdsch_bcch_r14(srslte_sequence_t* seq, uint32_t nf, uint32_t n_id_ncell, uint32_t len) +{ bzero(seq, sizeof(srslte_sequence_t)); - return srslte_sequence_LTE_pr(seq, len, (0xffff<<15) + (n_id_ncell + 1) * ((nf % 61)+1)); + return srslte_sequence_LTE_pr(seq, len, (0xffff << 15) + (n_id_ncell + 1) * ((nf % 61) + 1)); } /** * 36.211 6.6.1 and 10.2.5.2 (13.2.0) */ -int srslte_sequence_npdcch(srslte_sequence_t *seq, uint32_t nslot, uint32_t cell_id, uint32_t len) { +int srslte_sequence_npdcch(srslte_sequence_t* seq, uint32_t nslot, uint32_t cell_id, uint32_t len) +{ bzero(seq, sizeof(srslte_sequence_t)); - return srslte_sequence_LTE_pr(seq, len, (nslot/2) * 512 + cell_id); + return srslte_sequence_LTE_pr(seq, len, (nslot / 2) * 512 + cell_id); } /** * 36.211 5.3.1 and 10.1.3.1 (13.2.0) */ -int srslte_sequence_npusch(srslte_sequence_t *seq, uint16_t rnti, uint32_t nf, uint32_t nslot, uint32_t cell_id, uint32_t len) { +int srslte_sequence_npusch(srslte_sequence_t* seq, + uint16_t rnti, + uint32_t nf, + uint32_t nslot, + uint32_t cell_id, + uint32_t len) +{ bzero(seq, sizeof(srslte_sequence_t)); - return srslte_sequence_LTE_pr(seq, len, (rnti<<14) + ((nf % 2)<<13) + ((nslot/2)<<9) + cell_id); + return srslte_sequence_LTE_pr(seq, len, (rnti << 14) + ((nf % 2) << 13) + ((nslot / 2) << 9) + cell_id); } /** * 36.211 7.2.0 and 10.1.6.1 (13.2.0) */ -int srslte_sequence_nprach(srslte_sequence_t *seq, uint32_t cell_id) { - bzero(seq, sizeof(srslte_sequence_t)); - return srslte_sequence_LTE_pr(seq, 1600, cell_id); +int srslte_sequence_nprach(srslte_sequence_t* seq, uint32_t cell_id) +{ + bzero(seq, sizeof(srslte_sequence_t)); + return srslte_sequence_LTE_pr(seq, 1600, cell_id); } \ No newline at end of file diff --git a/lib/src/phy/phch/tbs_tables.h b/lib/src/phy/phch/tbs_tables.h index 31d675fb4..a8a104157 100644 --- a/lib/src/phy/phch/tbs_tables.h +++ b/lib/src/phy/phch/tbs_tables.h @@ -217,14 +217,13 @@ static const int tbs_table[34][110] = { 48936, 48936, 48936, 51024, 51024, 52752, 52752, 52752, 55056, 55056, 55056, 55056, 57336, 57336, 57336, 59256, 59256, 59256, 61664, 61664, 61664, 63776, 63776, 63776, 66592, 66592, 66592, 68808, 68808, 68808, 71112, 71112, 71112, 73712, 73712, 75376, 75376, 75376, 75376, 75376, 75376, 75376, 75376, 75376, 75376, 75376}, - {648, 1320, 1992, 2664, 3368, 4008, 4584, 5352, 5992, 6712, 7224, 7992, 8504, 9144, 9912, - 10680, 11448, 11832, 12576, 12960, 14112, 14688, 15264, 15840, 16416, 16992, 17568, 18336, 19080, 19848, - 20616, 21384, 22152, 22920, 22920, 23688, 24496, 25456, 25456, 26416, 27376, 27376, 28336, 29296, 29296, - 30576, 31704, 31704, 32856, 32856, 34008, 34008, 35160, 35160, 36696, 36696, 37888, 37888, 39232, 39232, - 40576, 40576, 42368, 42368, 43816, 43816, 43816, 45352, 45352, 46888, 46888, 46888, 48936, 48936, 48936, - 51024, 51024, 51024, 52752, 52752, 52752, 55056, 55056, 55056, 57336, 57336, 57336, 59256, 59256, 59256, - 59256, 61664, 61664, 61664, 63776, 63776, 63776, 63776, 66592, 66592, 66592, 66592, 68808, 68808, 68808, - 71112, 71112, 71112, 71112, 73712}, + {648, 1320, 1992, 2664, 3368, 4008, 4584, 5352, 5992, 6712, 7224, 7992, 8504, 9144, 9912, 10680, + 11448, 11832, 12576, 12960, 14112, 14688, 15264, 15840, 16416, 16992, 17568, 18336, 19080, 19848, 20616, 21384, + 22152, 22920, 22920, 23688, 24496, 25456, 25456, 26416, 27376, 27376, 28336, 29296, 29296, 30576, 31704, 31704, + 32856, 32856, 34008, 34008, 35160, 35160, 36696, 36696, 37888, 37888, 39232, 39232, 40576, 40576, 42368, 42368, + 43816, 43816, 43816, 45352, 45352, 46888, 46888, 46888, 48936, 48936, 48936, 51024, 51024, 51024, 52752, 52752, + 52752, 55056, 55056, 55056, 57336, 57336, 57336, 59256, 59256, 59256, 59256, 61664, 61664, 61664, 63776, 63776, + 63776, 63776, 66592, 66592, 66592, 66592, 68808, 68808, 68808, 71112, 71112, 71112, 71112, 73712}, {680, 1384, 2088, 2792, 3496, 4264, 4968, 5544, 6200, 6968, 7736, 8504, 9144, 9912, 10680, 11064, 11832, 12576, 13536, 14112, 14688, 15264, 16416, 16992, 17568, 18336, 19080, 19848, 20616, 21384, 22152, 22152, 22920, 23688, 24496, 25456, 26416, 26416, 27376, 28336, 29296, 29296, 30576, 30576, 31704, 32856, 32856, 34008, diff --git a/lib/src/phy/phch/test/npbch_file_test.c b/lib/src/phy/phch/test/npbch_file_test.c index 3675ae564..418fa8fb9 100644 --- a/lib/src/phy/phch/test/npbch_file_test.c +++ b/lib/src/phy/phch/test/npbch_file_test.c @@ -200,7 +200,7 @@ int main(int argc, char** argv) uint8_t bch_payload[SRSLTE_MIB_NB_LEN] = {}; int ret = SRSLTE_ERROR; uint32_t nof_tx_ports = 0; - int sfn_offset = 0; + int sfn_offset = 0; if (argc < 3) { usage(argv[0]); diff --git a/lib/src/phy/phch/test/pbch_file_test.c b/lib/src/phy/phch/test/pbch_file_test.c index 5544bd183..29ea0279e 100644 --- a/lib/src/phy/phch/test/pbch_file_test.c +++ b/lib/src/phy/phch/test/pbch_file_test.c @@ -27,7 +27,7 @@ #include "srslte/srslte.h" -char *input_file_name = NULL; +char* input_file_name = NULL; srslte_cell_t cell = { 6, // nof_prb @@ -40,20 +40,22 @@ srslte_cell_t cell = { }; -int nof_frames = 1; +int nof_frames = 1; -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}; +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))) -srslte_filesource_t fsrc; +srslte_filesource_t fsrc; cf_t * input_buffer, *fft_buffer[SRSLTE_MAX_CODEWORDS]; -srslte_pbch_t pbch; -srslte_ofdm_t fft; -srslte_chest_dl_t chest; +srslte_pbch_t pbch; +srslte_ofdm_t fft; +srslte_chest_dl_t chest; srslte_chest_dl_res_t chest_res; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [vcoe] -i input_file\n", prog); printf("\t-c cell_id [Default %d]\n", cell.id); printf("\t-p nof_prb [Default %d]\n", cell.nof_prb); @@ -62,32 +64,33 @@ void usage(char *prog) { printf("\t-v [set srslte_verbose to debug, default none]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "ivcpne")) != -1) { - switch(opt) { - case 'i': - input_file_name = argv[optind]; - break; - case 'c': - cell.id = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'p': - cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'n': - nof_frames = (int)strtol(argv[optind], NULL, 10); - break; - case 'v': - srslte_verbose++; - break; - case 'e': - cell.cp = SRSLTE_CP_EXT; - break; - default: - usage(argv[0]); - exit(-1); + switch (opt) { + case 'i': + input_file_name = argv[optind]; + break; + case 'c': + cell.id = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'p': + cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'n': + nof_frames = (int)strtol(argv[optind], NULL, 10); + break; + case 'v': + srslte_verbose++; + break; + case 'e': + cell.cp = SRSLTE_CP_EXT; + break; + default: + usage(argv[0]); + exit(-1); } } if (!input_file_name) { @@ -96,7 +99,8 @@ void parse_args(int argc, char **argv) { } } -int base_init() { +int base_init() +{ if (srslte_filesource_init(&fsrc, input_file_name, SRSLTE_COMPLEX_FLOAT_BIN)) { ERROR("Error opening file %s\n", input_file_name); @@ -157,7 +161,8 @@ int base_init() { return 0; } -void base_free() { +void base_free() +{ srslte_filesource_free(&fsrc); free(input_buffer); @@ -171,9 +176,10 @@ void base_free() { srslte_pbch_free(&pbch); } -int main(int argc, char **argv) { - uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; - int n; +int main(int argc, char** argv) +{ + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; + int n; uint32_t nof_tx_ports; int sfn_offset; @@ -182,16 +188,16 @@ int main(int argc, char **argv) { exit(-1); } - parse_args(argc,argv); + parse_args(argc, argv); if (base_init()) { ERROR("Error initializing receiver\n"); exit(-1); } - int frame_cnt = 0; - int nof_decoded_mibs = 0; - int nread = 0; + int frame_cnt = 0; + int nof_decoded_mibs = 0; + int nread = 0; do { nread = srslte_filesource_read(&fsrc, input_buffer, FLEN); @@ -221,7 +227,7 @@ int main(int argc, char **argv) { ERROR("Error reading from file\n"); exit(-1); } - } while(nread > 0 && frame_cnt < nof_frames); + } while (nread > 0 && frame_cnt < nof_frames); base_free(); srslte_dft_exit(); @@ -231,7 +237,7 @@ int main(int argc, char **argv) { printf("Could not decode PBCH\n"); exit(-1); } 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, SRSLTE_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"); diff --git a/lib/src/phy/phch/test/pbch_test.c b/lib/src/phy/phch/test/pbch_test.c index 725df21ab..a077c643e 100644 --- a/lib/src/phy/phch/test/pbch_test.c +++ b/lib/src/phy/phch/test/pbch_test.c @@ -23,8 +23,8 @@ #include #include #include -#include #include +#include #include "srslte/srslte.h" @@ -39,7 +39,8 @@ srslte_cell_t cell = { }; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [cpv]\n", prog); printf("\t-c cell id [Default %d]\n", cell.id); printf("\t-p cell.nof_ports [Default %d]\n", cell.nof_ports); @@ -47,25 +48,26 @@ void usage(char *prog) { printf("\t-v [set srslte_verbose to debug, default none]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "cpnv")) != -1) { - switch(opt) { - case 'p': - cell.nof_ports = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'n': - cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'c': - cell.id = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + switch (opt) { + case 'p': + cell.nof_ports = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'n': + cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'c': + cell.id = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } } @@ -74,13 +76,13 @@ int main(int argc, char** argv) { srslte_chest_dl_res_t chest_dl_res; srslte_pbch_t pbch; - uint8_t bch_payload_tx[SRSLTE_BCH_PAYLOAD_LEN], bch_payload_rx[SRSLTE_BCH_PAYLOAD_LEN]; + uint8_t bch_payload_tx[SRSLTE_BCH_PAYLOAD_LEN], bch_payload_rx[SRSLTE_BCH_PAYLOAD_LEN]; int i, j, k; int nof_re; cf_t* sf_symbols[SRSLTE_MAX_PORTS]; uint32_t nof_rx_ports; - parse_args(argc,argv); + parse_args(argc, argv); nof_re = SRSLTE_SF_LEN_RE(cell.nof_prb, SRSLTE_CP_NORM); @@ -97,7 +99,6 @@ int main(int argc, char** argv) perror("malloc"); exit(-1); } - } if (srslte_pbch_init(&pbch)) { ERROR("Error creating PBCH object\n"); @@ -109,19 +110,19 @@ int main(int argc, char** argv) } srand(time(NULL)); - for (i=0;i 0) { - printf("PDSCH Decoded OK!\n"); + if (ret > 0) { + printf("PDSCH Decoded OK!\n"); } else if (ret == 0) { printf("No DCI dci found\n"); } else if (ret < 0) { printf("Error decoding PDSCH\n"); } - sf_idx = (sf_idx+1)%10; + sf_idx = (sf_idx + 1) % 10; nof_frames++; } while (nof_frames <= max_frames && ret == 0); @@ -218,6 +223,6 @@ int main(int argc, char **argv) { if (ret > 0) { exit(0); } else { - exit(-1); + exit(-1); } } diff --git a/lib/src/phy/phch/test/pdsch_test.c b/lib/src/phy/phch/test/pdsch_test.c index fc9d8524f..1e04ee314 100644 --- a/lib/src/phy/phch/test/pdsch_test.c +++ b/lib/src/phy/phch/test/pdsch_test.c @@ -22,8 +22,8 @@ #include #include #include -#include #include +#include #include "srslte/srslte.h" @@ -54,9 +54,10 @@ static uint32_t pmi = 0; static char* input_file = NULL; static int M = 1; static bool enable_256qam = false; -static bool use_8_bit = false; +static bool use_8_bit = false; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [fmMbcsrtRFpnwav] \n", prog); printf("\t-f read signal from file [Default generate it with pdsch_encode()]\n"); printf("\t-m MCS [Default %d]\n", mcs[0]); @@ -79,76 +80,80 @@ void usage(char *prog) { printf("\t-q Enable/Disable 256QAM modulation (default %s)\n", enable_256qam ? "enabled" : "disabled"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "fmMcsbrtRFpnqawvXxj")) != -1) { - switch(opt) { - case 'f': - input_file = argv[optind]; - break; - case 'm': - mcs[0] = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'b': - use_8_bit = true; - break; - case 'M': - mcs[1] = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 's': - subframe = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'X': - M = (int)strtol(argv[optind], NULL, 10); - break; - case 'r': - rv_idx[0] = (int)strtol(argv[optind], NULL, 10); - break; - case 't': - rv_idx[1] = (int)strtol(argv[optind], NULL, 10); - break; - case 'R': - rnti = (uint16_t)strtol(argv[optind], NULL, 10); - break; - case 'F': - cfi = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'x': - tm = (srslte_tm_t)(strtol(argv[optind], NULL, 10) - 1); - break; - case 'p': - pmi = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'n': - cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'c': - cell.id = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'a': - nof_rx_antennas = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'w': - tb_cw_swap = true; - break; - case 'j': - enable_coworker = true; - break; - case 'v': - srslte_verbose++; - break; - case 'q': - enable_256qam ^= true; - break; - default: - usage(argv[0]); - exit(-1); + switch (opt) { + case 'f': + input_file = argv[optind]; + break; + case 'm': + mcs[0] = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'b': + use_8_bit = true; + break; + case 'M': + mcs[1] = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 's': + subframe = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'X': + M = (int)strtol(argv[optind], NULL, 10); + break; + case 'r': + rv_idx[0] = (int)strtol(argv[optind], NULL, 10); + break; + case 't': + rv_idx[1] = (int)strtol(argv[optind], NULL, 10); + break; + case 'R': + rnti = (uint16_t)strtol(argv[optind], NULL, 10); + break; + case 'F': + cfi = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'x': + tm = (srslte_tm_t)(strtol(argv[optind], NULL, 10) - 1); + break; + case 'p': + pmi = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'n': + cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'c': + cell.id = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'a': + nof_rx_antennas = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'w': + tb_cw_swap = true; + break; + case 'j': + enable_coworker = true; + break; + case 'v': + srslte_verbose++; + break; + case 'q': + enable_256qam ^= true; + break; + default: + usage(argv[0]); + exit(-1); } } } -static int check_softbits( - srslte_pdsch_t* pdsch_enb, srslte_pdsch_t* pdsch_ue, srslte_pdsch_cfg_t* pdsch_cfg, uint32_t sf_idx, int tb) +static int check_softbits(srslte_pdsch_t* pdsch_enb, + srslte_pdsch_t* pdsch_ue, + srslte_pdsch_cfg_t* pdsch_cfg, + uint32_t sf_idx, + int tb) { int ret = SRSLTE_SUCCESS; @@ -181,11 +186,12 @@ static int check_softbits( return ret; } -int main(int argc, char **argv) { - int ret = -1; +int main(int argc, char** argv) +{ + int ret = -1; struct timeval t[3] = {}; - srslte_softbuffer_tx_t *softbuffers_tx[SRSLTE_MAX_CODEWORDS]; - bool acks[SRSLTE_MAX_CODEWORDS] = {false}; + srslte_softbuffer_tx_t* softbuffers_tx[SRSLTE_MAX_CODEWORDS]; + bool acks[SRSLTE_MAX_CODEWORDS] = {false}; uint8_t* data_tx[SRSLTE_MAX_CODEWORDS] = {NULL}; uint8_t* data_rx[SRSLTE_MAX_CODEWORDS] = {NULL}; @@ -329,7 +335,7 @@ int main(int argc, char **argv) { goto quit; } - pdsch_rx.llr_is_8bit = use_8_bit; + pdsch_rx.llr_is_8bit = use_8_bit; pdsch_rx.dl_sch.llr_is_8bit = use_8_bit; srslte_pdsch_set_rnti(&pdsch_rx, rnti); @@ -397,7 +403,7 @@ int main(int argc, char **argv) { for (int tb = 0; tb < SRSLTE_MAX_CODEWORDS; tb++) { if (pdsch_cfg.grant.tb[tb].enabled) { for (int byte = 0; byte < pdsch_cfg.grant.tb[tb].tbs / 8; byte++) { - data_tx[tb][byte] = (uint8_t) (rand() % 256); + data_tx[tb][byte] = (uint8_t)(rand() % 256); } } } diff --git a/lib/src/phy/phch/test/phich_file_test.c b/lib/src/phy/phch/test/phich_file_test.c index 9f8d1e777..f00e039c8 100644 --- a/lib/src/phy/phch/test/phich_file_test.c +++ b/lib/src/phy/phch/test/phich_file_test.c @@ -27,8 +27,8 @@ #include "srslte/srslte.h" -char *input_file_name = NULL; -char *matlab_file_name = NULL; +char* input_file_name = NULL; +char* matlab_file_name = NULL; srslte_cell_t cell = { 50, // cell.nof_prb @@ -43,19 +43,20 @@ srslte_cell_t cell = { int flen; int nof_ctrl_symbols = 1; -int numsubframe = 0; +int numsubframe = 0; -FILE *fmatlab = NULL; +FILE* fmatlab = NULL; -srslte_filesource_t fsrc; +srslte_filesource_t fsrc; cf_t * input_buffer, *fft_buffer[SRSLTE_MAX_CODEWORDS]; -srslte_phich_t phich; -srslte_regs_t regs; -srslte_ofdm_t fft; -srslte_chest_dl_t chest; +srslte_phich_t phich; +srslte_regs_t regs; +srslte_ofdm_t fft; +srslte_chest_dl_t chest; srslte_chest_dl_res_t chest_res; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [vcoe] -i input_file\n", prog); printf("\t-o output matlab file name [Default Disabled]\n"); printf("\t-c cell.id [Default %d]\n", cell.id); @@ -68,53 +69,54 @@ void usage(char *prog) { printf("\t-v [set srslte_verbose to debug, default none]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "iovcenpfgl")) != -1) { - switch(opt) { - case 'i': - input_file_name = argv[optind]; - break; - case 'o': - matlab_file_name = argv[optind]; - break; - case 'c': - cell.id = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'f': - nof_ctrl_symbols = (int)strtol(argv[optind], NULL, 10); - break; - case 'g': - if (!strcmp(argv[optind], "1/6")) { - cell.phich_resources = SRSLTE_PHICH_R_1_6; - } else if (!strcmp(argv[optind], "1/2")) { - cell.phich_resources = SRSLTE_PHICH_R_1_2; - } else if (!strcmp(argv[optind], "1")) { - cell.phich_resources = SRSLTE_PHICH_R_1; - } else if (!strcmp(argv[optind], "2")) { - cell.phich_resources = SRSLTE_PHICH_R_2; - } else { - ERROR("Invalid phich ng factor %s. Setting to default.\n", argv[optind]); - } - break; - case 'e': - cell.phich_length = SRSLTE_PHICH_EXT; - break; - case 'n': - cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'p': - cell.nof_ports = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'v': - srslte_verbose++; - break; - case 'l': - cell.cp = SRSLTE_CP_EXT; - break; - default: - usage(argv[0]); - exit(-1); + switch (opt) { + case 'i': + input_file_name = argv[optind]; + break; + case 'o': + matlab_file_name = argv[optind]; + break; + case 'c': + cell.id = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'f': + nof_ctrl_symbols = (int)strtol(argv[optind], NULL, 10); + break; + case 'g': + if (!strcmp(argv[optind], "1/6")) { + cell.phich_resources = SRSLTE_PHICH_R_1_6; + } else if (!strcmp(argv[optind], "1/2")) { + cell.phich_resources = SRSLTE_PHICH_R_1_2; + } else if (!strcmp(argv[optind], "1")) { + cell.phich_resources = SRSLTE_PHICH_R_1; + } else if (!strcmp(argv[optind], "2")) { + cell.phich_resources = SRSLTE_PHICH_R_2; + } else { + ERROR("Invalid phich ng factor %s. Setting to default.\n", argv[optind]); + } + break; + case 'e': + cell.phich_length = SRSLTE_PHICH_EXT; + break; + case 'n': + cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'p': + cell.nof_ports = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'v': + srslte_verbose++; + break; + case 'l': + cell.cp = SRSLTE_CP_EXT; + break; + default: + usage(argv[0]); + exit(-1); } } if (!input_file_name) { @@ -123,7 +125,8 @@ void parse_args(int argc, char **argv) { } } -int base_init() { +int base_init() +{ if (srslte_filesource_init(&fsrc, input_file_name, SRSLTE_COMPLEX_FLOAT_BIN)) { ERROR("Error opening file %s\n", input_file_name); @@ -196,7 +199,8 @@ int base_init() { return 0; } -void base_free() { +void base_free() +{ srslte_filesource_free(&fsrc); if (fmatlab) { @@ -216,8 +220,9 @@ void base_free() { srslte_regs_free(®s); } -int main(int argc, char **argv) { - int n; +int main(int argc, char** argv) +{ + int n; uint32_t ngroup, nseq, max_nseq; if (argc < 3) { @@ -225,9 +230,9 @@ int main(int argc, char **argv) { exit(-1); } - parse_args(argc,argv); + parse_args(argc, argv); - max_nseq = SRSLTE_CP_ISNORM(cell.cp)?SRSLTE_PHICH_NORM_NSEQUENCES:SRSLTE_PHICH_EXT_NSEQUENCES; + max_nseq = SRSLTE_CP_ISNORM(cell.cp) ? SRSLTE_PHICH_NORM_NSEQUENCES : SRSLTE_PHICH_EXT_NSEQUENCES; if (base_init()) { ERROR("Error initializing memory\n"); diff --git a/lib/src/phy/phch/test/phich_test.c b/lib/src/phy/phch/test/phich_test.c index 42db813ea..b808cbf28 100644 --- a/lib/src/phy/phch/test/phich_test.c +++ b/lib/src/phy/phch/test/phich_test.c @@ -41,7 +41,8 @@ srslte_cell_t cell = { srslte_phich_r_t phich_res = SRSLTE_PHICH_R_1; srslte_phich_length_t phich_length = SRSLTE_PHICH_NORM; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [cpvgel]\n", prog); printf("\t-c cell id [Default %d]\n", cell.id); printf("\t-p cell.nof_ports [Default %d]\n", cell.nof_ports); @@ -52,63 +53,64 @@ void usage(char *prog) { printf("\t-v [set srslte_verbose to debug, default none]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "cpnvgel")) != -1) { - switch(opt) { - case 'p': - cell.nof_ports = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'n': - cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'c': - cell.id = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'g': - if (!strcmp(argv[optind], "1/6")) { - phich_res = SRSLTE_PHICH_R_1_6; - } else if (!strcmp(argv[optind], "1/2")) { - phich_res = SRSLTE_PHICH_R_1_2; - } else if (!strcmp(argv[optind], "1")) { - phich_res = SRSLTE_PHICH_R_1; - } else if (!strcmp(argv[optind], "2")) { - phich_res = SRSLTE_PHICH_R_2; - } else { - ERROR("Invalid phich ng factor %s. Setting to default.\n", argv[optind]); - } - break; - case 'e': - phich_length = SRSLTE_PHICH_EXT; - break; - case 'l': - cell.cp = SRSLTE_CP_EXT; - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + switch (opt) { + case 'p': + cell.nof_ports = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'n': + cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'c': + cell.id = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'g': + if (!strcmp(argv[optind], "1/6")) { + phich_res = SRSLTE_PHICH_R_1_6; + } else if (!strcmp(argv[optind], "1/2")) { + phich_res = SRSLTE_PHICH_R_1_2; + } else if (!strcmp(argv[optind], "1")) { + phich_res = SRSLTE_PHICH_R_1; + } else if (!strcmp(argv[optind], "2")) { + phich_res = SRSLTE_PHICH_R_2; + } else { + ERROR("Invalid phich ng factor %s. Setting to default.\n", argv[optind]); + } + break; + case 'e': + phich_length = SRSLTE_PHICH_EXT; + break; + case 'l': + cell.cp = SRSLTE_CP_EXT; + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } } - -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ srslte_phich_t phich; - srslte_regs_t regs; - int i, j; - int nof_re; - cf_t *slot_symbols[SRSLTE_MAX_PORTS]; + srslte_regs_t regs; + int i, j; + int nof_re; + cf_t* slot_symbols[SRSLTE_MAX_PORTS]; uint8_t ack[50][SRSLTE_PHICH_NORM_NSEQUENCES]; uint32_t nsf; - int cid, max_cid; - uint32_t ngroup, nseq, max_nseq; + int cid, max_cid; + uint32_t ngroup, nseq, max_nseq; - parse_args(argc,argv); + parse_args(argc, argv); - max_nseq = SRSLTE_CP_ISNORM(cell.cp)?SRSLTE_PHICH_NORM_NSEQUENCES:SRSLTE_PHICH_EXT_NSEQUENCES; + max_nseq = SRSLTE_CP_ISNORM(cell.cp) ? SRSLTE_PHICH_NORM_NSEQUENCES : SRSLTE_PHICH_EXT_NSEQUENCES; nof_re = SRSLTE_CP_NORM_NSYMB * cell.nof_prb * SRSLTE_NRE; @@ -127,19 +129,19 @@ int main(int argc, char **argv) { } if (cell.id == 1000) { - cid = 0; + cid = 0; max_cid = 503; } else { - cid = cell.id; + cid = cell.id; max_cid = cell.id; } if (srslte_phich_init(&phich, 1)) { ERROR("Error creating PBCH object\n"); exit(-1); } - while(cid <= max_cid) { + while (cid <= max_cid) { cell.id = cid; - + printf("Testing CellID=%d...\n", cid); if (srslte_regs_init(®s, cell)) { @@ -164,8 +166,8 @@ int main(int argc, char **argv) { srslte_phich_resource_t resource; /* Transmit all PHICH groups and sequence numbers */ - for (ngroup=0;ngroup= 0) { exit(0); } else { - exit(-1); + exit(-1); } } diff --git a/lib/src/phy/phch/test/pmch_test.c b/lib/src/phy/phch/test/pmch_test.c index d81e32d7b..07907ce73 100644 --- a/lib/src/phy/phch/test/pmch_test.c +++ b/lib/src/phy/phch/test/pmch_test.c @@ -48,18 +48,19 @@ srslte_cell_t cell = { }; -uint32_t cfi = 2; -uint32_t mcs_idx = 2; -uint32_t subframe = 1; -int rv_idx[SRSLTE_MAX_CODEWORDS] = {0, 1}; -uint16_t rnti = 1234; -uint32_t nof_rx_antennas = 1; -uint32_t pmi = 0; -char *input_file = NULL; -uint32_t mbsfn_area_id = 1; -uint32_t non_mbsfn_region = 2; - -void usage(char *prog) { +uint32_t cfi = 2; +uint32_t mcs_idx = 2; +uint32_t subframe = 1; +int rv_idx[SRSLTE_MAX_CODEWORDS] = {0, 1}; +uint16_t rnti = 1234; +uint32_t nof_rx_antennas = 1; +uint32_t pmi = 0; +char* input_file = NULL; +uint32_t mbsfn_area_id = 1; +uint32_t non_mbsfn_region = 2; + +void usage(char* prog) +{ printf("Usage: %s [fmMcsrtRFpnwav] \n", prog); printf("\t-f read signal from file [Default generate it with pdsch_encode()]\n"); printf("\t-m MCS [Default %d]\n", mcs_idx); @@ -75,55 +76,57 @@ void usage(char *prog) { printf("\t-v [set srslte_verbose to debug, default none]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "fmMcsrtRFpnav")) != -1) { - switch(opt) { - case 'f': - input_file = argv[optind]; - break; - case 'm': - mcs_idx = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 's': - subframe = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'r': - rv_idx[0] = (int)strtol(argv[optind], NULL, 10); - break; - case 'R': - rnti = (uint16_t)strtol(argv[optind], NULL, 10); - break; - case 'F': - cfi = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'p': - pmi = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'n': - cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'c': - cell.id = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'a': - nof_rx_antennas = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + switch (opt) { + case 'f': + input_file = argv[optind]; + break; + case 'm': + mcs_idx = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 's': + subframe = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'r': + rv_idx[0] = (int)strtol(argv[optind], NULL, 10); + break; + case 'R': + rnti = (uint16_t)strtol(argv[optind], NULL, 10); + break; + case 'F': + cfi = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'p': + pmi = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'n': + cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'c': + cell.id = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'a': + nof_rx_antennas = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } } -int main(int argc, char **argv) { - uint32_t i, j, k; - int ret = -1; +int main(int argc, char** argv) +{ + uint32_t i, j, k; + int ret = -1; struct timeval t[3]; - int M=1; + int M = 1; static uint8_t* data_tx[SRSLTE_MAX_CODEWORDS] = {NULL}; static uint8_t* data_rx[SRSLTE_MAX_CODEWORDS] = {NULL}; @@ -142,20 +145,20 @@ int main(int argc, char **argv) { srslte_pmch_cfg_t pmch_cfg; srslte_ofdm_t ifft_mbsfn[SRSLTE_MAX_PORTS], fft_mbsfn[SRSLTE_MAX_PORTS]; - parse_args(argc,argv); + parse_args(argc, argv); /* Initialise to zeros */ bzero(&pmch, sizeof(srslte_pmch_t)); - bzero(tx_slot_symbols, sizeof(cf_t*)*SRSLTE_MAX_PORTS); - bzero(rx_slot_symbols, sizeof(cf_t*)*SRSLTE_MAX_PORTS); + bzero(tx_slot_symbols, sizeof(cf_t*) * SRSLTE_MAX_PORTS); + bzero(rx_slot_symbols, sizeof(cf_t*) * SRSLTE_MAX_PORTS); bzero(t, 3 * sizeof(struct timeval)); cell.nof_ports = 1; - + /* init memory */ srslte_chest_dl_res_init(&chest_dl_res, cell.nof_prb); srslte_chest_dl_res_set_identity(&chest_dl_res); - for (i=0;i +#include #include #include #include -#include -#include -#include #include -#include +#include +#include #include "srslte/srslte.h" -#define MAX_LEN 70176 +#define MAX_LEN 70176 -uint32_t nof_prb = 50; -uint32_t config_idx = 3; -uint32_t root_seq_idx = 0; -uint32_t zero_corr_zone = 15; +uint32_t nof_prb = 50; +uint32_t config_idx = 3; +uint32_t root_seq_idx = 0; +uint32_t zero_corr_zone = 15; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s\n", prog); printf("\t-n Uplink number of PRB [Default %d]\n", nof_prb); printf("\t-f Preamble format [Default 0]\n"); @@ -45,7 +46,8 @@ void usage(char *prog) { printf("\t-z Zero correlation zone config [Default 1]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "nfrz")) != -1) { switch (opt) { @@ -73,10 +75,10 @@ int main(int argc, char** argv) parse_args(argc, argv); srslte_prach_t prach; - bool high_speed_flag = false; + bool high_speed_flag = false; cf_t preamble[MAX_LEN]; - memset(preamble, 0, sizeof(cf_t)*MAX_LEN); + memset(preamble, 0, sizeof(cf_t) * MAX_LEN); srslte_prach_cfg_t prach_cfg; ZERO_OBJECT(prach_cfg); @@ -97,11 +99,10 @@ int main(int argc, char** argv) uint32_t seq_index = 0; uint32_t indices[64]; uint32_t n_indices = 0; - for(int i=0;i<64;i++) + for (int i = 0; i < 64; i++) indices[i] = 0; - for(seq_index=0;seq_index<64;seq_index++) - { + for (seq_index = 0; seq_index < 64; seq_index++) { srslte_prach_gen(&prach, seq_index, 0, preamble); uint32_t prach_len = prach.N_seq; @@ -112,7 +113,7 @@ int main(int argc, char** argv) gettimeofday(&t[2], NULL); get_time_interval(t); printf("texec=%ld us\n", t[0].tv_usec); - if(n_indices != 1 || indices[0] != seq_index) + if (n_indices != 1 || indices[0] != seq_index) return -1; } diff --git a/lib/src/phy/phch/test/prach_test_multi.c b/lib/src/phy/phch/test/prach_test_multi.c index 874e9403a..bf3ed69ba 100644 --- a/lib/src/phy/phch/test/prach_test_multi.c +++ b/lib/src/phy/phch/test/prach_test_multi.c @@ -19,26 +19,27 @@ * */ +#include +#include #include #include #include -#include -#include #include -#include +#include #include "srslte/phy/phch/prach.h" #include "srslte/phy/utils/debug.h" -#define MAX_LEN 70176 +#define MAX_LEN 70176 -uint32_t nof_prb = 6; -uint32_t preamble_format = 0; -uint32_t root_seq_idx = 0; -uint32_t zero_corr_zone = 1; -uint32_t n_seqs = 64; +uint32_t nof_prb = 6; +uint32_t preamble_format = 0; +uint32_t root_seq_idx = 0; +uint32_t zero_corr_zone = 1; +uint32_t n_seqs = 64; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s\n", prog); printf("\t-N Uplink number of PRB [Default %d]\n", nof_prb); printf("\t-f Preamble format [Default 0]\n"); @@ -47,28 +48,29 @@ void usage(char *prog) { printf("\t-n Number of sequences used for each test [Default 64]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "Nfrzn")) != -1) { switch (opt) { - case 'N': - nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'f': - preamble_format = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'r': - root_seq_idx = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'z': - zero_corr_zone = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'n': - n_seqs = (uint32_t)strtol(argv[optind], NULL, 10); - break; - default: - usage(argv[0]); - exit(-1); + case 'N': + nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'f': + preamble_format = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'r': + root_seq_idx = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'z': + zero_corr_zone = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'n': + n_seqs = (uint32_t)strtol(argv[optind], NULL, 10); + break; + default: + usage(argv[0]); + exit(-1); } } } @@ -78,12 +80,12 @@ int main(int argc, char** argv) parse_args(argc, argv); srslte_prach_t prach; - bool high_speed_flag = false; + bool high_speed_flag = false; cf_t preamble[MAX_LEN]; - memset(preamble, 0, sizeof(cf_t)*MAX_LEN); + memset(preamble, 0, sizeof(cf_t) * MAX_LEN); cf_t preamble_sum[MAX_LEN]; - memset(preamble_sum, 0, sizeof(cf_t)*MAX_LEN); + memset(preamble_sum, 0, sizeof(cf_t) * MAX_LEN); srslte_prach_cfg_t prach_cfg; ZERO_OBJECT(prach_cfg); @@ -102,18 +104,17 @@ int main(int argc, char** argv) return -1; } - uint32_t seq_index = 0; + uint32_t seq_index = 0; uint32_t frequency_offset = 0; uint32_t indices[64]; uint32_t n_indices = 0; - for(int i=0;i<64;i++) + for (int i = 0; i < 64; i++) indices[i] = 0; srslte_prach_set_detect_factor(&prach, 10); - for(seq_index=0;seq_index +#include #include #include #include -#include -#include #include -#include +#include #include "srslte/phy/rf/rf.h" #include "srslte/srslte.h" -#define MAX_LEN 70176 - +#define MAX_LEN 70176 uint32_t nof_prb = 25; uint32_t preamble_format = 0; @@ -39,17 +38,18 @@ uint32_t root_seq_idx = 0; uint32_t seq_idx = 0; uint32_t frequency_offset = 0; uint32_t zero_corr_zone = 11; -float timeadv = 0; -uint32_t nof_frames = 20; +float timeadv = 0; +uint32_t nof_frames = 20; -float uhd_rx_gain=40, uhd_tx_gain=60, uhd_freq=2.4e9; -char *uhd_args=""; -char *output_filename = "prach_rx"; +float uhd_rx_gain = 40, uhd_tx_gain = 60, uhd_freq = 2.4e9; +char* uhd_args = ""; +char* output_filename = "prach_rx"; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s \n", prog); printf("\t-a UHD args [Default %s]\n", uhd_args); - printf("\t-f UHD TX/RX frequency [Default %.2f MHz]\n", uhd_freq/1e6); + printf("\t-f UHD TX/RX frequency [Default %.2f MHz]\n", uhd_freq / 1e6); printf("\t-g UHD RX gain [Default %.1f dB]\n", uhd_rx_gain); printf("\t-G UHD TX gain [Default %.1f dB]\n", uhd_tx_gain); printf("\t-p Number of UL RB [Default %d]\n", nof_prb); @@ -62,69 +62,71 @@ void usage(char *prog) { printf("\t-o Save transmitted PRACH in file [Default no]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "apfFgGrstoPOz")) != -1) { switch (opt) { - case 'a': - uhd_args = argv[optind]; - break; - case 'o': - output_filename = argv[optind]; - break; - case 'f': - uhd_freq = strtof(argv[optind], NULL); - break; - case 'g': - uhd_rx_gain = strtof(argv[optind], NULL); - break; - case 'G': - uhd_tx_gain = strtof(argv[optind], NULL); - break; - case 'P': - preamble_format = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'O': - frequency_offset = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 't': - timeadv = strtof(argv[optind], NULL); - break; - case 'p': - nof_prb = (int)strtol(argv[optind], NULL, 10); - if (!srslte_nofprb_isvalid(nof_prb)) { - ERROR("Invalid number of UL RB %d\n", nof_prb); + case 'a': + uhd_args = argv[optind]; + break; + case 'o': + output_filename = argv[optind]; + break; + case 'f': + uhd_freq = strtof(argv[optind], NULL); + break; + case 'g': + uhd_rx_gain = strtof(argv[optind], NULL); + break; + case 'G': + uhd_tx_gain = strtof(argv[optind], NULL); + break; + case 'P': + preamble_format = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'O': + frequency_offset = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 't': + timeadv = strtof(argv[optind], NULL); + break; + case 'p': + nof_prb = (int)strtol(argv[optind], NULL, 10); + if (!srslte_nofprb_isvalid(nof_prb)) { + ERROR("Invalid number of UL RB %d\n", nof_prb); + exit(-1); + } + break; + case 'F': + preamble_format = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'r': + root_seq_idx = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 's': + seq_idx = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'z': + zero_corr_zone = (uint32_t)strtol(argv[optind], NULL, 10); + break; + default: + usage(argv[0]); exit(-1); - } - break; - case 'F': - preamble_format = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'r': - root_seq_idx = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 's': - seq_idx = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'z': - zero_corr_zone = (uint32_t)strtol(argv[optind], NULL, 10); - break; - default: - usage(argv[0]); - exit(-1); } } } -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ parse_args(argc, argv); srslte_prach_t prach; - bool high_speed_flag = false; + bool high_speed_flag = false; cf_t preamble[MAX_LEN]; - memset(preamble, 0, sizeof(cf_t)*MAX_LEN); + memset(preamble, 0, sizeof(cf_t) * MAX_LEN); srslte_prach_cfg_t prach_cfg; ZERO_OBJECT(prach_cfg); @@ -143,21 +145,21 @@ int main(int argc, char **argv) { return -1; } - int srate = srslte_sampling_freq_hz(nof_prb); - uint32_t flen = srate/1000; + int srate = srslte_sampling_freq_hz(nof_prb); + uint32_t flen = srate / 1000; printf("Generating PRACH\n"); - bzero(preamble, flen*sizeof(cf_t)); + bzero(preamble, flen * sizeof(cf_t)); srslte_prach_gen(&prach, seq_idx, frequency_offset, preamble); uint32_t prach_len = prach.N_seq + prach.N_cp; srslte_vec_save_file("generated", preamble, prach_len * sizeof(cf_t)); - cf_t *buffer = malloc(sizeof(cf_t)*flen*nof_frames); - - // Send through UHD - srslte_rf_t rf; + cf_t* buffer = malloc(sizeof(cf_t) * flen * nof_frames); + + // Send through UHD + srslte_rf_t rf; printf("Opening RF device...\n"); if (srslte_rf_open(&rf, uhd_args)) { ERROR("Error opening &uhd\n"); @@ -166,59 +168,63 @@ int main(int argc, char **argv) { printf("Subframe len: %d samples\n", flen); printf("Set RX gain: %.1f dB\n", uhd_rx_gain); printf("Set TX gain: %.1f dB\n", uhd_tx_gain); - printf("Set TX/RX freq: %.2f MHz\n", uhd_freq/ 1000000); - + printf("Set TX/RX freq: %.2f MHz\n", uhd_freq / 1000000); + srslte_rf_set_rx_gain(&rf, uhd_rx_gain); srslte_rf_set_tx_gain(&rf, uhd_tx_gain); srslte_rf_set_rx_freq(&rf, 0, uhd_freq); srslte_rf_set_tx_freq(&rf, 0, uhd_freq); - printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000); - float srate_rf = srslte_rf_set_rx_srate(&rf, (double) srate); + printf("Setting sampling rate %.2f MHz\n", (float)srate / 1000000); + float srate_rf = srslte_rf_set_rx_srate(&rf, (double)srate); if (srate_rf != srate) { ERROR("Could not set sampling rate\n"); exit(-1); } - srslte_rf_set_tx_srate(&rf, (double) srate); + srslte_rf_set_tx_srate(&rf, (double)srate); sleep(1); - - cf_t *zeros = calloc(sizeof(cf_t),flen); - - srslte_timestamp_t tstamp; - + + cf_t* zeros = calloc(sizeof(cf_t), flen); + + srslte_timestamp_t tstamp; + srslte_rf_start_rx_stream(&rf, false); - uint32_t nframe=0; - - while(nframe #include #include -#include #include +#include #include "srslte/srslte.h" @@ -39,46 +39,49 @@ srslte_cell_t cell = { }; -uint32_t subframe = 0; -bool test_cqi_only = false; +uint32_t subframe = 0; +bool test_cqi_only = false; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [csNnv]\n", prog); printf("\t-c cell id [Default %d]\n", cell.id); printf("\t-s subframe [Default %d]\n", subframe); printf("\t-n nof_prb [Default %d]\n", cell.nof_prb); - printf("\t-q Test CQI encoding/decoding only [Default %s].\n", test_cqi_only?"yes":"no"); + printf("\t-q Test CQI encoding/decoding only [Default %s].\n", test_cqi_only ? "yes" : "no"); printf("\t-v [set verbose to debug, default none]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "csNnqv")) != -1) { - switch(opt) { - case 's': - subframe = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'n': - cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'c': - cell.id = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'q': - test_cqi_only = true; - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + switch (opt) { + case 's': + subframe = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'n': + cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'c': + cell.id = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'q': + test_cqi_only = true; + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } } -int test_uci_cqi_pucch(void) { - int ret = SRSLTE_SUCCESS; +int test_uci_cqi_pucch(void) +{ + int ret = SRSLTE_SUCCESS; __attribute__((aligned(256))) uint8_t o_bits[SRSLTE_UCI_MAX_CQI_LEN_PUCCH] = {0}; __attribute__((aligned(256))) uint8_t e_bits[SRSLTE_UCI_CQI_CODED_PUCCH_B] = {0}; __attribute__((aligned(256))) int16_t e_symb[SRSLTE_UCI_CQI_CODED_PUCCH_B] = {0}; @@ -88,22 +91,22 @@ int test_uci_cqi_pucch(void) { srslte_uci_cqi_pucch_init(&uci_cqi_pucch); - for (uint32_t nof_bits = 1; nof_bits <= SRSLTE_UCI_MAX_CQI_LEN_PUCCH-1; nof_bits++) { - for (uint32_t cqi = 0; cqi < (1 < 15) { ext_code = SRSLTE_ERROR; } } else if (!strcmp(param, "I_offset_ri")) { - uci_cfg.I_offset_ri = (uint32_t) strtol(arg, NULL, 10); + uci_cfg.I_offset_ri = (uint32_t)strtol(arg, NULL, 10); if (uci_cfg.I_offset_ri > 15) { ext_code = SRSLTE_ERROR; } } else if (!strcmp(param, "I_offset_ack")) { - uci_cfg.I_offset_ack = (uint32_t) strtol(arg, NULL, 10); + uci_cfg.I_offset_ack = (uint32_t)strtol(arg, NULL, 10); if (uci_cfg.I_offset_ack > 15) { ext_code = SRSLTE_ERROR; } @@ -134,33 +136,34 @@ void parse_extensive_param(char *param, char *arg) { } } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "msLFrncpvf")) != -1) { switch (opt) { case 'm': - mcs_idx = (uint32_t) strtol(argv[optind], NULL, 10); + mcs_idx = (uint32_t)strtol(argv[optind], NULL, 10); break; case 's': - subframe = (uint32_t) strtol(argv[optind], NULL, 10); + subframe = (uint32_t)strtol(argv[optind], NULL, 10); break; case 'R': - riv = (int) strtol(argv[optind], NULL, 10); + riv = (int)strtol(argv[optind], NULL, 10); break; case 'L': L_rb = (uint32_t)strtol(argv[optind], NULL, 10); break; case 'F': - freq_hop = (int) strtol(argv[optind], NULL, 10); + freq_hop = (int)strtol(argv[optind], NULL, 10); break; case 'r': - rv_idx = (uint32_t) strtol(argv[optind], NULL, 10); + rv_idx = (uint32_t)strtol(argv[optind], NULL, 10); break; case 'n': - cell.nof_prb = (uint32_t) strtol(argv[optind], NULL, 10); + cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); break; case 'c': - cell.id = (uint32_t) strtol(argv[optind], NULL, 10); + cell.id = (uint32_t)strtol(argv[optind], NULL, 10); break; case 'p': parse_extensive_param(argv[optind], argv[optind + 1]); @@ -180,14 +183,14 @@ int main(int argc, char** argv) { srslte_random_t random_h = srslte_random_init(0); srslte_chest_ul_res_t chest_res; - srslte_pusch_t pusch_tx; - srslte_pusch_t pusch_rx; - uint8_t *data = NULL; - uint8_t *data_rx = NULL; - cf_t *sf_symbols = NULL; - int ret = -1; - struct timeval t[3]; - srslte_pusch_cfg_t cfg; + srslte_pusch_t pusch_tx; + srslte_pusch_t pusch_rx; + uint8_t* data = NULL; + uint8_t* data_rx = NULL; + cf_t* sf_symbols = NULL; + int ret = -1; + struct timeval t[3]; + srslte_pusch_cfg_t cfg; srslte_softbuffer_tx_t softbuffer_tx; srslte_softbuffer_rx_t softbuffer_rx; @@ -204,7 +207,7 @@ int main(int argc, char** argv) dci.freq_hop_fl = freq_hop; if (riv >= 0) { - dci.type2_alloc.riv = (uint32_t) riv; + dci.type2_alloc.riv = (uint32_t)riv; } else { dci.type2_alloc.riv = srslte_ra_type2_to_riv(L_rb, 0, cell.nof_prb); } @@ -248,7 +251,7 @@ int main(int argc, char** argv) srslte_pusch_set_rnti(&pusch_rx, rnti); uint32_t nof_re = SRSLTE_NRE * cell.nof_prb * 2 * SRSLTE_CP_NSYMB(cell.cp); - sf_symbols = srslte_vec_malloc(sizeof(cf_t) * nof_re); + sf_symbols = srslte_vec_malloc(sizeof(cf_t) * nof_re); if (!sf_symbols) { perror("malloc"); exit(-1); @@ -386,15 +389,15 @@ int main(int argc, char** argv) (float)cfg.grant.tb.tbs / t[0].tv_usec); } - quit: - srslte_chest_ul_res_free(&chest_res); - srslte_pusch_free(&pusch_tx); - srslte_pusch_free(&pusch_rx); - srslte_softbuffer_tx_free(&softbuffer_tx); - srslte_softbuffer_rx_free(&softbuffer_rx); - srslte_random_free(random_h); - if (sf_symbols) { - free(sf_symbols); +quit: + srslte_chest_ul_res_free(&chest_res); + srslte_pusch_free(&pusch_tx); + srslte_pusch_free(&pusch_rx); + srslte_softbuffer_tx_free(&softbuffer_tx); + srslte_softbuffer_rx_free(&softbuffer_rx); + srslte_random_free(random_h); + if (sf_symbols) { + free(sf_symbols); } if (data) { free(data); diff --git a/lib/src/phy/phch/uci.c b/lib/src/phy/phch/uci.c index 8b5ede7d1..54d9f2d09 100644 --- a/lib/src/phy/phch/uci.c +++ b/lib/src/phy/phch/uci.c @@ -19,97 +19,65 @@ * */ +#include +#include +#include #include #include +#include #include #include -#include -#include -#include -#include -#include "srslte/phy/phch/uci.h" +#include "srslte/phy/common/phy_common.h" #include "srslte/phy/fec/cbsegm.h" #include "srslte/phy/fec/convcoder.h" #include "srslte/phy/fec/crc.h" #include "srslte/phy/fec/rm_conv.h" -#include "srslte/phy/common/phy_common.h" -#include "srslte/phy/utils/vector.h" +#include "srslte/phy/phch/uci.h" #include "srslte/phy/utils/bit.h" #include "srslte/phy/utils/debug.h" - +#include "srslte/phy/utils/vector.h" /* Table 5.2.2.6.4-1: Basis sequence for (32, O) code */ -static uint8_t M_basis_seq[32][11]={ - {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, - {1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1 }, - {1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1 }, - {1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1 }, - {1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 }, - {1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 }, - {1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1 }, - {1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1 }, - {1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1 }, - {1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1 }, - {1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1 }, - {1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1 }, - {1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1 }, - {1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1 }, - {1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1 }, - {1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1 }, - {1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0 }, - {1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0 }, - {1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0 }, - {1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 }, - {1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 }, - {1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1 }, - {1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1 }, - {1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1 }, - {1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0 }, - {1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1 }, - {1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0 }, - {1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0 }, - {1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 }, - {1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 }, - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - }; - - -static uint8_t M_basis_seq_pucch[20][13]={ - {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0}, - {1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0}, - {1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1}, - {1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1}, - {1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1}, - {1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1}, - {1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1}, - {1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1}, - {1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1}, - {1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1}, - {1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1}, - {1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}, - {1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1}, - {1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1}, - {1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1}, - {1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1}, - {1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1}, - {1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1}, - {1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}, - {1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0}, - }; - -void srslte_uci_cqi_pucch_init(srslte_uci_cqi_pucch_t *q) { +static uint8_t M_basis_seq[32][11] = { + {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1}, {1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1}, + {1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1}, {1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1}, {1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1}, + {1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1}, {1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1}, {1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1}, + {1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1}, {1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1}, {1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1}, + {1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1}, {1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1}, {1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1}, + {1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1}, {1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0}, {1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0}, + {1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0}, {1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0}, {1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1}, + {1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1}, {1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1}, {1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1}, + {1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}, {1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1}, {1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0}, + {1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0}, {1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0}, {1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, +}; + +static uint8_t M_basis_seq_pucch[20][13] = { + {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0}, {1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0}, + {1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1}, {1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1}, + {1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1}, {1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1}, + {1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1}, {1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1}, + {1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1}, {1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1}, + {1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1}, {1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}, + {1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1}, {1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1}, + {1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1}, {1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1}, + {1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1}, {1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1}, + {1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0}, +}; + +void srslte_uci_cqi_pucch_init(srslte_uci_cqi_pucch_t* q) +{ uint8_t word[16]; uint32_t nwords = 1 << SRSLTE_UCI_MAX_CQI_LEN_PUCCH; - q->cqi_table = srslte_vec_malloc(nwords * sizeof(int8_t *)); - q->cqi_table_s = srslte_vec_malloc(nwords * sizeof(int16_t *)); + q->cqi_table = srslte_vec_malloc(nwords * sizeof(int8_t*)); + q->cqi_table_s = srslte_vec_malloc(nwords * sizeof(int16_t*)); for (uint32_t w = 0; w < nwords; w++) { - q->cqi_table[w] = srslte_vec_malloc(SRSLTE_UCI_CQI_CODED_PUCCH_B * sizeof(int8_t)); + q->cqi_table[w] = srslte_vec_malloc(SRSLTE_UCI_CQI_CODED_PUCCH_B * sizeof(int8_t)); q->cqi_table_s[w] = srslte_vec_malloc(SRSLTE_UCI_CQI_CODED_PUCCH_B * sizeof(int16_t)); - uint8_t *ptr = word; + uint8_t* ptr = word; srslte_bit_unpack(w, &ptr, SRSLTE_UCI_MAX_CQI_LEN_PUCCH); srslte_uci_encode_cqi_pucch(word, SRSLTE_UCI_MAX_CQI_LEN_PUCCH, q->cqi_table[w]); for (int j = 0; j < SRSLTE_UCI_CQI_CODED_PUCCH_B; j++) { @@ -118,9 +86,10 @@ void srslte_uci_cqi_pucch_init(srslte_uci_cqi_pucch_t *q) { } } -void srslte_uci_cqi_pucch_free(srslte_uci_cqi_pucch_t *q) { - uint32_t nwords = 1 << SRSLTE_UCI_MAX_CQI_LEN_PUCCH; - for (uint32_t w=0;wcqi_table[w]) { free(q->cqi_table[w]); } @@ -132,17 +101,17 @@ void srslte_uci_cqi_pucch_free(srslte_uci_cqi_pucch_t *q) { free(q->cqi_table_s); } -/* Encode UCI CQI/PMI as described in 5.2.3.3 of 36.212 +/* Encode UCI CQI/PMI as described in 5.2.3.3 of 36.212 */ -int srslte_uci_encode_cqi_pucch(uint8_t *cqi_data, uint32_t cqi_len, uint8_t b_bits[SRSLTE_UCI_CQI_CODED_PUCCH_B]) +int srslte_uci_encode_cqi_pucch(uint8_t* cqi_data, uint32_t cqi_len, uint8_t b_bits[SRSLTE_UCI_CQI_CODED_PUCCH_B]) { if (cqi_len <= SRSLTE_UCI_MAX_CQI_LEN_PUCCH) { - for (uint32_t i=0;icqi_table[packed], SRSLTE_UCI_CQI_CODED_PUCCH_B); @@ -164,22 +136,19 @@ int srslte_uci_encode_cqi_pucch_from_table(srslte_uci_cqi_pucch_t *q, uint8_t *c } } -/* Decode UCI CQI/PMI over PUCCH +/* Decode UCI CQI/PMI over PUCCH */ int16_t srslte_uci_decode_cqi_pucch(srslte_uci_cqi_pucch_t* q, int16_t b_bits[SRSLTE_CQI_MAX_BITS], uint8_t* cqi_data, uint32_t cqi_len) { - if (cqi_len < SRSLTE_UCI_MAX_CQI_LEN_PUCCH && - b_bits != NULL && - cqi_data != NULL) - { - uint32_t max_w = 0; - int32_t max_corr = INT32_MIN; - uint32_t nwords = 1 << SRSLTE_UCI_MAX_CQI_LEN_PUCCH; - for (uint32_t w=0;wcqi_table_s[w], b_bits, SRSLTE_UCI_CQI_CODED_PUCCH_B); if (corr > max_corr) { @@ -188,9 +157,9 @@ int16_t srslte_uci_decode_cqi_pucch(srslte_uci_cqi_pucch_t* q, } } // Convert word to bits again - uint8_t *ptr = cqi_data; + uint8_t* ptr = cqi_data; srslte_bit_unpack(max_w, &ptr, SRSLTE_UCI_MAX_CQI_LEN_PUCCH); - + INFO("Decoded CQI: w=%d, corr=%d\n", max_w, max_corr); return max_corr; } else { @@ -200,9 +169,9 @@ int16_t srslte_uci_decode_cqi_pucch(srslte_uci_cqi_pucch_t* q, void encode_cqi_pusch_block(uint8_t* data, uint32_t nof_bits, uint8_t output[32]) { - for (int i=0;i<32;i++) { + for (int i = 0; i < 32; i++) { output[i] = 0; - for (int n=0;ncqi_table[i] = srslte_vec_malloc(sizeof(uint8_t)*nwords*32); +void cqi_pusch_pregen(srslte_uci_cqi_pusch_t* q) +{ + uint8_t word[11]; + + for (int i = 0; i < 11; i++) { + uint32_t nwords = (1 << (i + 1)); + q->cqi_table[i] = srslte_vec_malloc(sizeof(uint8_t) * nwords * 32); q->cqi_table_s[i] = srslte_vec_malloc(sizeof(int16_t) * nwords * 32); - for (uint32_t w=0;wcqi_table[i][32 * w]); - for (int j=0;j<32;j++) { - q->cqi_table_s[i][32*w+j] = 2*q->cqi_table[i][32*w+j]-1; + for (int j = 0; j < 32; j++) { + q->cqi_table_s[i][32 * w + j] = 2 * q->cqi_table[i][32 * w + j] - 1; } } } } -void cqi_pusch_pregen_free(srslte_uci_cqi_pusch_t *q) { - for (int i=0;i<11;i++) { +void cqi_pusch_pregen_free(srslte_uci_cqi_pusch_t* q) +{ + for (int i = 0; i < 11; i++) { if (q->cqi_table[i]) { free(q->cqi_table[i]); } @@ -242,24 +213,25 @@ void cqi_pusch_pregen_free(srslte_uci_cqi_pusch_t *q) { } } -int srslte_uci_cqi_init(srslte_uci_cqi_pusch_t *q) { +int srslte_uci_cqi_init(srslte_uci_cqi_pusch_t* q) +{ if (srslte_crc_init(&q->crc, SRSLTE_LTE_CRC8, 8)) { return SRSLTE_ERROR; } - int poly[3] = { 0x6D, 0x4F, 0x57 }; + int poly[3] = {0x6D, 0x4F, 0x57}; if (srslte_viterbi_init(&q->viterbi, SRSLTE_VITERBI_37, poly, SRSLTE_UCI_MAX_CQI_LEN_PUSCH, true)) { return SRSLTE_ERROR; } - + cqi_pusch_pregen(q); - + return SRSLTE_SUCCESS; } -void srslte_uci_cqi_free(srslte_uci_cqi_pusch_t *q) +void srslte_uci_cqi_free(srslte_uci_cqi_pusch_t* q) { srslte_viterbi_free(&q->viterbi); - + cqi_pusch_pregen_free(q); } @@ -270,7 +242,7 @@ static uint32_t Q_prime_cqi(srslte_pusch_cfg_t* cfg, uint32_t O, float beta, uin uint32_t Q_prime = 0; uint32_t L = (O < 11) ? 0 : 8; - uint32_t x = 999999; + uint32_t x = 999999; if (K > 0) { x = (uint32_t)ceilf((float)(O + L) * cfg->grant.L_prb * SRSLTE_NRE * cfg->grant.nof_symb * beta / K); @@ -278,85 +250,71 @@ static uint32_t Q_prime_cqi(srslte_pusch_cfg_t* cfg, uint32_t O, float beta, uin Q_prime = SRSLTE_MIN(x, cfg->grant.L_prb * SRSLTE_NRE * cfg->grant.nof_symb - Q_prime_ri); - return Q_prime; + return Q_prime; } /* Encode UCI CQI/PMI for payloads equal or lower to 11 bits (Sec 5.2.2.6.4) */ -int encode_cqi_short(srslte_uci_cqi_pusch_t *q, uint8_t *data, uint32_t nof_bits, uint8_t *q_bits, uint32_t Q) +int encode_cqi_short(srslte_uci_cqi_pusch_t* q, uint8_t* data, uint32_t nof_bits, uint8_t* q_bits, uint32_t Q) { - if (nof_bits <= 11 && - nof_bits > 0 && - q != NULL && - data != NULL && - q_bits != NULL) - { - uint8_t *ptr = data; - uint32_t w = srslte_bit_pack(&ptr, nof_bits); - - for (int i=0;icqi_table[nof_bits-1][w*32+(i%32)]; + if (nof_bits <= 11 && nof_bits > 0 && q != NULL && data != NULL && q_bits != NULL) { + uint8_t* ptr = data; + uint32_t w = srslte_bit_pack(&ptr, nof_bits); + + for (int i = 0; i < Q; i++) { + q_bits[i] = q->cqi_table[nof_bits - 1][w * 32 + (i % 32)]; } return SRSLTE_SUCCESS; } else { - return SRSLTE_ERROR_INVALID_INPUTS; + return SRSLTE_ERROR_INVALID_INPUTS; } } // For decoding the block-encoded CQI we use ML decoding -int decode_cqi_short(srslte_uci_cqi_pusch_t *q, int16_t *q_bits, uint32_t Q, uint8_t *data, uint32_t nof_bits) +int decode_cqi_short(srslte_uci_cqi_pusch_t* q, int16_t* q_bits, uint32_t Q, uint8_t* data, uint32_t nof_bits) { - if (nof_bits <= 11 && - nof_bits > 0 && - q != NULL && - data != NULL && - q_bits != NULL) - { - // Accumulate all copies of the 32-length sequence - if (Q>32) { - int i=1; - for (;i 0 && q != NULL && data != NULL && q_bits != NULL) { + // Accumulate all copies of the 32-length sequence + if (Q > 32) { + int i = 1; + for (; i < Q / 32; i++) { + srslte_vec_sum_sss(&q_bits[i * 32], q_bits, q_bits, 32); } - srslte_vec_sum_sss(&q_bits[i*32], q_bits, q_bits, Q%32); + srslte_vec_sum_sss(&q_bits[i * 32], q_bits, q_bits, Q % 32); } - - uint32_t max_w = 0; - int32_t max_corr = INT32_MIN; - for (uint32_t w=0;w<(1<cqi_table_s[nof_bits-1][w*32], q_bits, SRSLTE_MIN(32, Q)); + int32_t corr = srslte_vec_dot_prod_sss(&q->cqi_table_s[nof_bits - 1][w * 32], q_bits, SRSLTE_MIN(32, Q)); if (corr > max_corr) { - max_corr = corr; - max_w = w; + max_corr = corr; + max_w = w; } } // Convert word to bits again - uint8_t *ptr = data; + uint8_t* ptr = data; srslte_bit_unpack(max_w, &ptr, nof_bits); - + INFO("Decoded CQI: w=%d, corr=%d\n", max_w, max_corr); return SRSLTE_SUCCESS; } else { return SRSLTE_ERROR_INVALID_INPUTS; - } + } } /* Encode UCI CQI/PMI for payloads greater than 11 bits (go through CRC, conv coder and rate match) */ -int encode_cqi_long(srslte_uci_cqi_pusch_t *q, uint8_t *data, uint32_t nof_bits, uint8_t *q_bits, uint32_t Q) +int encode_cqi_long(srslte_uci_cqi_pusch_t* q, uint8_t* data, uint32_t nof_bits, uint8_t* q_bits, uint32_t Q) { srslte_convcoder_t encoder; - if (nof_bits + 8 < SRSLTE_UCI_MAX_CQI_LEN_PUSCH && - q != NULL && - data != NULL && - q_bits != NULL) - { - int poly[3] = { 0x6D, 0x4F, 0x57 }; - encoder.K = 7; - encoder.R = 3; + if (nof_bits + 8 < SRSLTE_UCI_MAX_CQI_LEN_PUSCH && q != NULL && data != NULL && q_bits != NULL) { + int poly[3] = {0x6D, 0x4F, 0x57}; + encoder.K = 7; + encoder.R = 3; encoder.tail_biting = true; memcpy(encoder.poly, poly, 3 * sizeof(int)); @@ -365,9 +323,9 @@ int encode_cqi_long(srslte_uci_cqi_pusch_t *q, uint8_t *data, uint32_t nof_bits, DEBUG("cqi_crc_tx="); if (SRSLTE_VERBOSE_ISDEBUG()) { - srslte_vec_fprint_b(stdout, q->tmp_cqi, nof_bits+8); + srslte_vec_fprint_b(stdout, q->tmp_cqi, nof_bits + 8); } - + srslte_convcoder_encode(&encoder, q->tmp_cqi, q->encoded_cqi, nof_bits + 8); DEBUG("cconv_tx="); @@ -376,23 +334,18 @@ int encode_cqi_long(srslte_uci_cqi_pusch_t *q, uint8_t *data, uint32_t nof_bits, } srslte_rm_conv_tx(q->encoded_cqi, 3 * (nof_bits + 8), q_bits, Q); - + return SRSLTE_SUCCESS; } else { - return SRSLTE_ERROR_INVALID_INPUTS; + return SRSLTE_ERROR_INVALID_INPUTS; } } -int decode_cqi_long(srslte_uci_cqi_pusch_t *q, int16_t *q_bits, uint32_t Q, - uint8_t *data, uint32_t nof_bits) +int decode_cqi_long(srslte_uci_cqi_pusch_t* q, int16_t* q_bits, uint32_t Q, uint8_t* data, uint32_t nof_bits) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (nof_bits + 8 < SRSLTE_UCI_MAX_CQI_LEN_PUSCH && - q != NULL && - data != NULL && - q_bits != NULL) - { - + int ret = SRSLTE_ERROR_INVALID_INPUTS; + if (nof_bits + 8 < SRSLTE_UCI_MAX_CQI_LEN_PUSCH && q != NULL && data != NULL && q_bits != NULL) { + srslte_rm_conv_rx_s(q_bits, Q, q->encoded_cqi_s, 3 * (nof_bits + 8)); DEBUG("cconv_rx="); @@ -401,24 +354,24 @@ int decode_cqi_long(srslte_uci_cqi_pusch_t *q, int16_t *q_bits, uint32_t Q, } srslte_viterbi_decode_s(&q->viterbi, q->encoded_cqi_s, q->tmp_cqi, nof_bits + 8); - + DEBUG("cqi_crc_rx="); if (SRSLTE_VERBOSE_ISDEBUG()) { - srslte_vec_fprint_b(stdout, q->tmp_cqi, nof_bits+8); + srslte_vec_fprint_b(stdout, q->tmp_cqi, nof_bits + 8); } - + ret = srslte_crc_checksum(&q->crc, q->tmp_cqi, nof_bits + 8); - if (ret == 0) { - memcpy(data, q->tmp_cqi, nof_bits*sizeof(uint8_t)); + if (ret == 0) { + memcpy(data, q->tmp_cqi, nof_bits * sizeof(uint8_t)); ret = 1; } else { - ret = 0; + ret = 0; } } - return ret; + return ret; } -/* Encode UCI CQI/PMI +/* Encode UCI CQI/PMI */ int srslte_uci_decode_cqi_pusch(srslte_uci_cqi_pusch_t* q, srslte_pusch_cfg_t* cfg, @@ -431,7 +384,7 @@ int srslte_uci_decode_cqi_pusch(srslte_uci_cqi_pusch_t* q, { if (beta < 0) { ERROR("Error beta is reserved\n"); - return -1; + return -1; } uint32_t Q_prime = Q_prime_cqi(cfg, cqi_len, beta, Q_prime_ri); uint32_t Qm = srslte_mod_bits_x_symbol(cfg->grant.tb.mod); @@ -446,23 +399,23 @@ int srslte_uci_decode_cqi_pusch(srslte_uci_cqi_pusch_t* q, ret = decode_cqi_long(q, q_bits, Q_prime * Qm, cqi_data, cqi_len); if (ret == 1) { if (cqi_ack) { - *cqi_ack = true; + *cqi_ack = true; } - ret = 0; + ret = 0; } else if (ret == 0) { if (cqi_ack) { - *cqi_ack = false; + *cqi_ack = false; } } } if (ret) { return ret; } else { - return (int) Q_prime; + return (int)Q_prime; } } -/* Encode UCI CQI/PMI as described in 5.2.2.6 of 36.212 +/* Encode UCI CQI/PMI as described in 5.2.2.6 of 36.212 */ int srslte_uci_encode_cqi_pusch(srslte_uci_cqi_pusch_t* q, srslte_pusch_cfg_t* cfg, @@ -494,19 +447,22 @@ int srslte_uci_encode_cqi_pusch(srslte_uci_cqi_pusch_t* q, } /* Generates UCI-ACK bits and computes position in q bits */ -static int uci_ulsch_interleave_ack_gen( - uint32_t ack_q_bit_idx, uint32_t Qm, uint32_t H_prime_total, uint32_t N_pusch_symbs, srslte_uci_bit_t* ack_bits) +static int uci_ulsch_interleave_ack_gen(uint32_t ack_q_bit_idx, + uint32_t Qm, + uint32_t H_prime_total, + uint32_t N_pusch_symbs, + srslte_uci_bit_t* ack_bits) { const uint32_t ack_column_set_norm[4] = {2, 3, 8, 9}; - const uint32_t ack_column_set_ext[4] = {1, 2, 6, 7}; + const uint32_t ack_column_set_ext[4] = {1, 2, 6, 7}; if (H_prime_total / N_pusch_symbs >= 1 + ack_q_bit_idx / 4) { - uint32_t row = H_prime_total/N_pusch_symbs-1-ack_q_bit_idx/4; - uint32_t colidx = (3*ack_q_bit_idx)%4; + uint32_t row = H_prime_total / N_pusch_symbs - 1 - ack_q_bit_idx / 4; + uint32_t colidx = (3 * ack_q_bit_idx) % 4; uint32_t col = N_pusch_symbs > 10 ? ack_column_set_norm[colidx] : ack_column_set_ext[colidx]; - for(uint32_t k=0; k= 1+ri_q_bit_idx/4) { - uint32_t row = H_prime_total/N_pusch_symbs-1-ri_q_bit_idx/4; - uint32_t colidx = (3*ri_q_bit_idx)%4; + if (H_prime_total / N_pusch_symbs >= 1 + ri_q_bit_idx / 4) { + uint32_t row = H_prime_total / N_pusch_symbs - 1 - ri_q_bit_idx / 4; + uint32_t colidx = (3 * ri_q_bit_idx) % 4; uint32_t col = N_pusch_symbs > 10 ? ri_column_set_norm[colidx] : ri_column_set_ext[colidx]; - for(uint32_t k=0; kK_segm; @@ -577,7 +536,7 @@ static uint32_t encode_ri_ack(uint8_t data[2], uint32_t O_ack, uint8_t Qm, srslt if (O_ack == 1) { q_encoded_bits[i++].type = data[0] ? UCI_BIT_1 : UCI_BIT_0; q_encoded_bits[i++].type = UCI_BIT_REPETITION; - while(i < Qm) { + while (i < Qm) { q_encoded_bits[i++].type = UCI_BIT_PLACEHOLDER; } } else if (O_ack == 2) { @@ -593,7 +552,7 @@ static uint32_t encode_ri_ack(uint8_t data[2], uint32_t O_ack, uint8_t Qm, srslt } q_encoded_bits[i++].type = data[1] ? UCI_BIT_1 : UCI_BIT_0; q_encoded_bits[i++].type = (data[0] ^ data[1]) ? UCI_BIT_1 : UCI_BIT_0; - while(i 0); + data[0] = (uint8_t)(sum[0] > 0); if (nof_bits == 2) { - data[1] = (uint8_t) (sum[1] > 0); + data[1] = (uint8_t)(sum[1] > 0); } - return (int) Qprime; + return (int)Qprime; } uint32_t srslte_uci_cfg_total_ack(srslte_uci_cfg_t* uci_cfg) diff --git a/lib/src/phy/resampling/decim.c b/lib/src/phy/resampling/decim.c index 1e4de45c3..cd230fa59 100644 --- a/lib/src/phy/resampling/decim.c +++ b/lib/src/phy/resampling/decim.c @@ -19,25 +19,25 @@ * */ -#include -#include #include "srslte/phy/resampling/decim.h" #include "srslte/phy/utils/debug.h" - +#include +#include /* Performs integer linear decimation by a factor of M */ -void srslte_decim_c(cf_t *input, cf_t *output, int M, int len) { +void srslte_decim_c(cf_t* input, cf_t* output, int M, int len) +{ int i; - for (i=0;i #include "srslte/phy/resampling/interp.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" /*************** STATIC FUNCTIONS ***********************/ -cf_t srslte_interp_linear_onesample(cf_t input0, cf_t input1) { - return 2*input1-input0; +cf_t srslte_interp_linear_onesample(cf_t input0, cf_t input1) +{ + return 2 * input1 - input0; } -cf_t srslte_interp_linear_onesample_cabs(cf_t input0, cf_t input1) { - float re0=0, im0=0, re1=0, im1=0, re=0, im=0; +cf_t srslte_interp_linear_onesample_cabs(cf_t input0, cf_t input1) +{ + float re0 = 0, im0 = 0, re1 = 0, im1 = 0, re = 0, im = 0; re0 = crealf(input0); im0 = cimagf(input1); re1 = crealf(input0); im1 = cimagf(input1); - re = 2*re1-re0; - im = 2*im1-im0; - return (re+im*_Complex_I); + re = 2 * re1 - re0; + im = 2 * im1 - im0; + return (re + im * _Complex_I); } - /* Performs 1st order integer linear interpolation */ -void srslte_interp_linear_f(float *input, float *output, uint32_t M, uint32_t len) { +void srslte_interp_linear_f(float* input, float* output, uint32_t M, uint32_t len) +{ uint32_t i, j; - for (i=0;i 1) { - for (j=0;jdiff_vec = srslte_vec_malloc(vector_len * sizeof(cf_t)); if (!q->diff_vec) { perror("malloc"); - return SRSLTE_ERROR; - } + return SRSLTE_ERROR; + } q->vector_len = vector_len; q->max_vector_len = vector_len; } - return ret; + return ret; } -int srslte_interp_linear_vector_resize(srslte_interp_linsrslte_vec_t *q, uint32_t vector_len) +int srslte_interp_linear_vector_resize(srslte_interp_linsrslte_vec_t* q, uint32_t vector_len) { if (vector_len <= q->max_vector_len) { q->vector_len = vector_len; @@ -121,45 +125,61 @@ int srslte_interp_linear_vector_resize(srslte_interp_linsrslte_vec_t *q, uint32_ } } -void srslte_interp_linear_vector_free(srslte_interp_linsrslte_vec_t *q) { +void srslte_interp_linear_vector_free(srslte_interp_linsrslte_vec_t* q) +{ if (q->diff_vec) { free(q->diff_vec); } bzero(q, sizeof(srslte_interp_linsrslte_vec_t)); - } -void srslte_interp_linear_vector(srslte_interp_linsrslte_vec_t *q, cf_t *in0, cf_t *in1, cf_t *between, - uint32_t in1_in0_d, uint32_t M) +void srslte_interp_linear_vector(srslte_interp_linsrslte_vec_t* q, + cf_t* in0, + cf_t* in1, + cf_t* between, + uint32_t in1_in0_d, + uint32_t M) { - srslte_interp_linear_vector2(q, in0, in1, NULL, between, in1_in0_d, M); + srslte_interp_linear_vector2(q, in0, in1, NULL, between, in1_in0_d, M); } -void srslte_interp_linear_vector2(srslte_interp_linsrslte_vec_t *q, cf_t *in0, cf_t *in1, cf_t *start, cf_t *between, - uint32_t in1_in0_d, uint32_t M) +void srslte_interp_linear_vector2(srslte_interp_linsrslte_vec_t* q, + cf_t* in0, + cf_t* in1, + cf_t* start, + cf_t* between, + uint32_t in1_in0_d, + uint32_t M) { - srslte_interp_linear_vector3(q, in0, in1, start, between, in1_in0_d, M, true, q->vector_len); + srslte_interp_linear_vector3(q, in0, in1, start, between, in1_in0_d, M, true, q->vector_len); } -void srslte_interp_linear_vector3(srslte_interp_linsrslte_vec_t *q, cf_t *in0, cf_t *in1, cf_t *start, cf_t *between, - uint32_t in1_in0_d, uint32_t M, bool to_right, uint32_t len) +void srslte_interp_linear_vector3(srslte_interp_linsrslte_vec_t* q, + cf_t* in0, + cf_t* in1, + cf_t* start, + cf_t* between, + uint32_t in1_in0_d, + uint32_t M, + bool to_right, + uint32_t len) { uint32_t i; - + srslte_vec_sub_ccc(in1, in0, q->diff_vec, len); - srslte_vec_sc_prod_cfc(q->diff_vec, (float) 1/in1_in0_d, q->diff_vec, len); + srslte_vec_sc_prod_cfc(q->diff_vec, (float)1 / in1_in0_d, q->diff_vec, len); if (start) { - srslte_vec_sum_ccc(start, q->diff_vec, between, len); + srslte_vec_sum_ccc(start, q->diff_vec, between, len); } else { srslte_vec_sum_ccc(in0, q->diff_vec, between, len); } - for (i=0;idiff_vec, &between[q->vector_len], len); - between += q->vector_len; + between += q->vector_len; } else { between -= q->vector_len; srslte_vec_sum_ccc(&between[q->vector_len], q->diff_vec, between, len); @@ -167,44 +187,45 @@ void srslte_interp_linear_vector3(srslte_interp_linsrslte_vec_t *q, cf_t *in0, c } } -int srslte_interp_linear_init(srslte_interp_lin_t *q, uint32_t vector_len, uint32_t M) +int srslte_interp_linear_init(srslte_interp_lin_t* q, uint32_t vector_len, uint32_t M) { int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q) { bzero(q, sizeof(srslte_interp_lin_t)); - ret = SRSLTE_SUCCESS; + ret = SRSLTE_SUCCESS; q->diff_vec = srslte_vec_malloc(vector_len * sizeof(cf_t)); if (!q->diff_vec) { perror("malloc"); - return SRSLTE_ERROR; - } + return SRSLTE_ERROR; + } q->diff_vec2 = srslte_vec_malloc(M * vector_len * sizeof(cf_t)); if (!q->diff_vec2) { perror("malloc"); free(q->diff_vec); - return SRSLTE_ERROR; - } + return SRSLTE_ERROR; + } q->ramp = srslte_vec_malloc(M * sizeof(float)); if (!q->ramp) { perror("malloc"); free(q->ramp); free(q->diff_vec); - return SRSLTE_ERROR; - } - - for (int i=0;iramp[i] = (float) i; + return SRSLTE_ERROR; + } + + for (int i = 0; i < M; i++) { + q->ramp[i] = (float)i; } - q->vector_len = vector_len; - q->M = M; + q->vector_len = vector_len; + q->M = M; q->max_vector_len = vector_len; - q->max_M = M; + q->max_M = M; } - return ret; + return ret; } -void srslte_interp_linear_free(srslte_interp_lin_t *q) { +void srslte_interp_linear_free(srslte_interp_lin_t* q) +{ if (q->diff_vec) { free(q->diff_vec); } @@ -216,20 +237,18 @@ void srslte_interp_linear_free(srslte_interp_lin_t *q) { } bzero(q, sizeof(srslte_interp_lin_t)); - } - -int srslte_interp_linear_resize(srslte_interp_lin_t *q, uint32_t vector_len, uint32_t M) +int srslte_interp_linear_resize(srslte_interp_lin_t* q, uint32_t vector_len, uint32_t M) { if (vector_len <= q->max_vector_len && M <= q->max_M) { - for (int i=0;iramp[i] = (float) i; + for (int i = 0; i < M; i++) { + q->ramp[i] = (float)i; } q->vector_len = vector_len; - q->M = M; + q->M = M; return SRSLTE_SUCCESS; } else { ERROR("Error resizing interp_linear: vector_len and M must be lower or equal than initialized\n"); @@ -237,32 +256,30 @@ int srslte_interp_linear_resize(srslte_interp_lin_t *q, uint32_t vector_len, uin } } -void srslte_interp_linear_offset(srslte_interp_lin_t *q, cf_t *input, cf_t *output, - uint32_t off_st, uint32_t off_end) +void srslte_interp_linear_offset(srslte_interp_lin_t* q, cf_t* input, cf_t* output, uint32_t off_st, uint32_t off_end) { uint32_t i, j; - cf_t diff; - - i=0; - for (j=0;jM; + cf_t diff; + + i = 0; + for (j = 0; j < off_st; j++) { + output[off_st - j - 1] = input[i] - (j + 1) * (input[i + 1] - input[i]) / q->M; } - srslte_vec_sub_ccc(&input[1], input, q->diff_vec, (q->vector_len-1)); - srslte_vec_sc_prod_cfc(q->diff_vec, (float) 1/q->M, q->diff_vec, q->vector_len-1); - for (i=0;ivector_len-1;i++) { - for (j=0;jM;j++) { - output[i*q->M+j+off_st] = input[i]; - q->diff_vec2[i*q->M+j] = q->diff_vec[i]; + srslte_vec_sub_ccc(&input[1], input, q->diff_vec, (q->vector_len - 1)); + srslte_vec_sc_prod_cfc(q->diff_vec, (float)1 / q->M, q->diff_vec, q->vector_len - 1); + for (i = 0; i < q->vector_len - 1; i++) { + for (j = 0; j < q->M; j++) { + output[i * q->M + j + off_st] = input[i]; + q->diff_vec2[i * q->M + j] = q->diff_vec[i]; } - srslte_vec_prod_cfc(&q->diff_vec2[i*q->M],q->ramp,&q->diff_vec2[i*q->M],q->M); + srslte_vec_prod_cfc(&q->diff_vec2[i * q->M], q->ramp, &q->diff_vec2[i * q->M], q->M); } - srslte_vec_sum_ccc(&output[off_st], q->diff_vec2, &output[off_st], q->M*(q->vector_len-1)); - + srslte_vec_sum_ccc(&output[off_st], q->diff_vec2, &output[off_st], q->M * (q->vector_len - 1)); + if (q->vector_len > 1) { - diff = input[q->vector_len-1]-input[q->vector_len-2]; - for (j=0;jM+j+off_st] = input[i] + j * diff / q->M; + diff = input[q->vector_len - 1] - input[q->vector_len - 2]; + for (j = 0; j < off_end; j++) { + output[i * q->M + j + off_st] = input[i] + j * diff / q->M; } } } - diff --git a/lib/src/phy/resampling/resample_arb.c b/lib/src/phy/resampling/resample_arb.c index 1acd9eb45..646819ae6 100644 --- a/lib/src/phy/resampling/resample_arb.c +++ b/lib/src/phy/resampling/resample_arb.c @@ -19,14 +19,13 @@ * */ -#include -#include #include "srslte/phy/resampling/resample_arb.h" #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" +#include +#include - - +// clang-format off float srslte_resample_arb_polyfilt[SRSLTE_RESAMPLE_ARB_N][SRSLTE_RESAMPLE_ARB_M] __attribute__((aligned(256))) = {{0.000499262532685, 0.000859897001646, -0.008521087467670, 0.994530856609344, 0.017910413444042, -0.006922415923327, 0.002400347497314, 0.000000000000000 }, {-0.001216900418513, 0.008048813790083, -0.032752435654402, 0.991047739982605, 0.046474494040012, -0.015253192745149, 0.004479591734707, -0.001903604716063 }, @@ -101,76 +100,81 @@ float srslte_resample_arb_polyfilt[SRSLTE_RESAMPLE_ARB_N][SRSLTE_RESAMPLE_ARB_M] {0.000764085430796, -0.030612377229395, 0.154765509342932, 0.702921418438421, 0.206204344739138, -0.034615802155152, 0.000568080243211, 0.000003596427925}, {0.000722236729272, -0.032053439082436, 0.171322660416961, 0.704261032406613, 0.188481383863832, -0.033395686652146, 0.000657994314549 , 0.000002955485215}}; -static inline cf_t srslte_resample_arb_dot_prod(cf_t* x, float *y, int len){ - - cf_t res1 = srslte_vec_dot_prod_cfc(x,y,len); +// clang-format on +static inline cf_t srslte_resample_arb_dot_prod(cf_t* x, float* y, int len) +{ + cf_t res1 = srslte_vec_dot_prod_cfc(x, y, len); return res1; } // Right-shift our window of samples -void srslte_resample_arb_push(srslte_resample_arb_t *q, cf_t x){ - - memmove(&q->reg[1], &q->reg[0], (SRSLTE_RESAMPLE_ARB_M-1)*sizeof(cf_t)); +void srslte_resample_arb_push(srslte_resample_arb_t* q, cf_t x) +{ + + memmove(&q->reg[1], &q->reg[0], (SRSLTE_RESAMPLE_ARB_M - 1) * sizeof(cf_t)); q->reg[0] = x; } // Initialize our struct -void srslte_resample_arb_init(srslte_resample_arb_t *q, float rate, bool interpolate){ - - memset(q->reg, 0, SRSLTE_RESAMPLE_ARB_M*sizeof(cf_t)); - q->acc = 0.0; - q->rate = rate; +void srslte_resample_arb_init(srslte_resample_arb_t* q, float rate, bool interpolate) +{ + + memset(q->reg, 0, SRSLTE_RESAMPLE_ARB_M * sizeof(cf_t)); + q->acc = 0.0; + q->rate = rate; q->interpolate = interpolate; - q->step = (1/rate)*SRSLTE_RESAMPLE_ARB_N; + q->step = (1 / rate) * SRSLTE_RESAMPLE_ARB_N; } // Resample a block of input data -int srslte_resample_arb_compute(srslte_resample_arb_t *q, cf_t *input, cf_t *output, int n_in){ - int cnt = 0; - int n_out = 0; - int idx = 0; - cf_t res1,res2; - cf_t *filter_input; +int srslte_resample_arb_compute(srslte_resample_arb_t* q, cf_t* input, cf_t* output, int n_in) +{ + int cnt = 0; + int n_out = 0; + int idx = 0; + cf_t res1, res2; + cf_t* filter_input; float frac = 0; - memset(q->reg, 0, SRSLTE_RESAMPLE_ARB_M*sizeof(cf_t)); - + memset(q->reg, 0, SRSLTE_RESAMPLE_ARB_M * sizeof(cf_t)); + while (cnt < n_in) { - - if(cntreg[SRSLTE_RESAMPLE_ARB_M - cnt], input, (cnt)*sizeof(cf_t)); + + if (cnt < SRSLTE_RESAMPLE_ARB_M) { + memcpy(&q->reg[SRSLTE_RESAMPLE_ARB_M - cnt], input, (cnt) * sizeof(cf_t)); filter_input = q->reg; - } else{ - filter_input = &input[cnt-SRSLTE_RESAMPLE_ARB_M]; + } else { + filter_input = &input[cnt - SRSLTE_RESAMPLE_ARB_M]; } - + res1 = srslte_resample_arb_dot_prod(filter_input, srslte_resample_arb_polyfilt[idx], SRSLTE_RESAMPLE_ARB_M); - if(q->interpolate){ - res2 = srslte_resample_arb_dot_prod(filter_input, srslte_resample_arb_polyfilt[(idx+1)%SRSLTE_RESAMPLE_ARB_N], SRSLTE_RESAMPLE_ARB_M); + if (q->interpolate) { + res2 = srslte_resample_arb_dot_prod( + filter_input, srslte_resample_arb_polyfilt[(idx + 1) % SRSLTE_RESAMPLE_ARB_N], SRSLTE_RESAMPLE_ARB_M); } - if(idx == SRSLTE_RESAMPLE_ARB_N){ + if (idx == SRSLTE_RESAMPLE_ARB_N) { *output = res1; - }else { - *output = (q->interpolate)?(res1 + (res2-res1)*frac):res1; + } else { + *output = (q->interpolate) ? (res1 + (res2 - res1) * frac) : res1; } - + output++; n_out++; q->acc += q->step; idx = (int)(q->acc); - - while(idx >= SRSLTE_RESAMPLE_ARB_N){ + + while (idx >= SRSLTE_RESAMPLE_ARB_N) { q->acc -= SRSLTE_RESAMPLE_ARB_N; idx -= SRSLTE_RESAMPLE_ARB_N; - if(cnt < n_in){ + if (cnt < n_in) { cnt++; } } - - if(q->interpolate){ + + if (q->interpolate) { frac = q->acc - idx; - if(frac < 0) - frac = frac*(-1); + if (frac < 0) + frac = frac * (-1); } } return n_out; diff --git a/lib/src/phy/resampling/test/resample_arb_bench.c b/lib/src/phy/resampling/test/resample_arb_bench.c index 27eb8709f..6ec63b754 100644 --- a/lib/src/phy/resampling/test/resample_arb_bench.c +++ b/lib/src/phy/resampling/test/resample_arb_bench.c @@ -19,40 +19,40 @@ * */ +#include #include #include #include -#include -#include #include +#include -#include "srslte/srslte.h" #include "srslte/phy/resampling/resample_arb.h" - +#include "srslte/srslte.h" #define ITERATIONS 10000 -int main(int argc, char **argv) { - int N=9000; - float rate = 24.0/25.0; - cf_t *in = malloc(N*sizeof(cf_t)); - cf_t *out = malloc(N*sizeof(cf_t)); +int main(int argc, char** argv) +{ + int N = 9000; + float rate = 24.0 / 25.0; + cf_t* in = malloc(N * sizeof(cf_t)); + cf_t* out = malloc(N * sizeof(cf_t)); - for(int i=0;i #include #include #include -#include -#include #include +#include -#include "srslte/srslte.h" #include "srslte/phy/resampling/resample_arb.h" +#include "srslte/srslte.h" +int main(int argc, char** argv) +{ + int N = 100; // Number of sinwave samples + int delay = 5; // Delay of our resampling filter + float down = 25.0; // Downsampling rate -int main(int argc, char **argv) { - int N = 100; // Number of sinwave samples - int delay = 5; // Delay of our resampling filter - float down = 25.0; // Downsampling rate - - - - - for(int up=1;up diff && pre != post){ - printf("Interpolation failed at index %f\n", idx); - exit(-1); + for (int i = delay + 1; i < n_out; i++) { + float idx = i / rate; + int pre = floor(idx) - delay; + int post = ceil(idx) - delay; + int round = roundf(idx) - delay; + float diff = fabs(creal(in[pre]) - creal(in[post])); + float diff2 = fabs(creal(out[i]) - creal(in[round])); + if (diff2 > diff && pre != post) { + printf("Interpolation failed at index %f\n", idx); + exit(-1); } } diff --git a/lib/src/phy/rf/rf_blade_imp.c b/lib/src/phy/rf/rf_blade_imp.c index 99ce92021..7c7d48293 100644 --- a/lib/src/phy/rf/rf_blade_imp.c +++ b/lib/src/phy/rf/rf_blade_imp.c @@ -23,21 +23,21 @@ #include #include -#include "srslte/srslte.h" #include "rf_blade_imp.h" +#include "srslte/srslte.h" #define UNUSED __attribute__((unused)) -#define CONVERT_BUFFER_SIZE (240*1024) +#define CONVERT_BUFFER_SIZE (240 * 1024) typedef struct { - struct bladerf *dev; + struct bladerf* dev; bladerf_sample_rate rx_rate; bladerf_sample_rate tx_rate; - int16_t rx_buffer[CONVERT_BUFFER_SIZE]; - int16_t tx_buffer[CONVERT_BUFFER_SIZE]; - bool rx_stream_enabled; - bool tx_stream_enabled; - srslte_rf_info_t info; + int16_t rx_buffer[CONVERT_BUFFER_SIZE]; + int16_t tx_buffer[CONVERT_BUFFER_SIZE]; + bool rx_stream_enabled; + bool tx_stream_enabled; + srslte_rf_info_t info; } rf_blade_handler_t; static srslte_rf_error_handler_t blade_error_handler = NULL; @@ -52,72 +52,72 @@ void rf_blade_register_error_handler(UNUSED void* ptr, srslte_rf_error_handler_t blade_error_handler = new_handler; } -const unsigned int num_buffers = 256; -const unsigned int ms_buffer_size_rx = 1024; -const unsigned int buffer_size_tx = 1024; -const unsigned int num_transfers = 32; -const unsigned int timeout_ms = 4000; +const unsigned int num_buffers = 256; +const unsigned int ms_buffer_size_rx = 1024; +const unsigned int buffer_size_tx = 1024; +const unsigned int num_transfers = 32; +const unsigned int timeout_ms = 4000; const char* rf_blade_devname(UNUSED void* h) { return DEVNAME; } -int rf_blade_start_tx_stream(void *h) +int rf_blade_start_tx_stream(void* h) { - int status; - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; - + int status; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; + status = bladerf_sync_config(handler->dev, - BLADERF_TX_X1, - BLADERF_FORMAT_SC16_Q11_META, - num_buffers, - buffer_size_tx, - num_transfers, - timeout_ms); + BLADERF_TX_X1, + BLADERF_FORMAT_SC16_Q11_META, + num_buffers, + buffer_size_tx, + num_transfers, + timeout_ms); if (status != 0) { ERROR("Failed to configure TX sync interface: %s\n", bladerf_strerror(status)); - return status; + return status; } status = bladerf_enable_module(handler->dev, BLADERF_TX_X1, true); if (status != 0) { ERROR("Failed to enable TX module: %s\n", bladerf_strerror(status)); return status; } - handler->tx_stream_enabled = true; + handler->tx_stream_enabled = true; return 0; } int rf_blade_start_rx_stream(void* h, UNUSED bool now) { - int status; - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; - + int status; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; + /* Configure the device's RX module for use with the sync interface. - * SC16 Q11 samples *with* metadata are used. */ - uint32_t buffer_size_rx = ms_buffer_size_rx*(handler->rx_rate/1000/1024); - + * SC16 Q11 samples *with* metadata are used. */ + uint32_t buffer_size_rx = ms_buffer_size_rx * (handler->rx_rate / 1000 / 1024); + status = bladerf_sync_config(handler->dev, - BLADERF_RX_X1, - BLADERF_FORMAT_SC16_Q11_META, - num_buffers, - buffer_size_rx, - num_transfers, - timeout_ms); + BLADERF_RX_X1, + BLADERF_FORMAT_SC16_Q11_META, + num_buffers, + buffer_size_rx, + num_transfers, + timeout_ms); if (status != 0) { ERROR("Failed to configure RX sync interface: %s\n", bladerf_strerror(status)); return status; } status = bladerf_sync_config(handler->dev, - BLADERF_TX_X1, - BLADERF_FORMAT_SC16_Q11_META, - num_buffers, - buffer_size_tx, - num_transfers, - timeout_ms); + BLADERF_TX_X1, + BLADERF_FORMAT_SC16_Q11_META, + num_buffers, + buffer_size_tx, + num_transfers, + timeout_ms); if (status != 0) { ERROR("Failed to configure TX sync interface: %s\n", bladerf_strerror(status)); - return status; + return status; } status = bladerf_enable_module(handler->dev, BLADERF_RX_X1, true); if (status != 0) { @@ -129,13 +129,13 @@ int rf_blade_start_rx_stream(void* h, UNUSED bool now) ERROR("Failed to enable TX module: %s\n", bladerf_strerror(status)); return status; } - handler->rx_stream_enabled = true; + handler->rx_stream_enabled = true; return 0; } -int rf_blade_stop_rx_stream(void *h) +int rf_blade_stop_rx_stream(void* h) { - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; int status = bladerf_enable_module(handler->dev, BLADERF_RX_X1, false); if (status != 0) { ERROR("Failed to enable RX module: %s\n", bladerf_strerror(status)); @@ -147,7 +147,7 @@ int rf_blade_stop_rx_stream(void *h) return status; } handler->rx_stream_enabled = false; - handler->tx_stream_enabled = false; + handler->tx_stream_enabled = false; return 0; } @@ -155,7 +155,7 @@ void rf_blade_flush_buffer(UNUSED void* h) {} bool rf_blade_has_rssi(UNUSED void* h) { - return false; + return false; } float rf_blade_get_rssi(UNUSED void* h) @@ -165,21 +165,21 @@ float rf_blade_get_rssi(UNUSED void* h) int rf_blade_open_multi(char* args, void** h, UNUSED uint32_t nof_channels) { - return rf_blade_open(args, h); + return rf_blade_open(args, h); } -int rf_blade_open(char *args, void **h) +int rf_blade_open(char* args, void** h) { - const struct bladerf_range *range_tx = NULL; - const struct bladerf_range *range_rx = NULL; - *h = NULL; - - rf_blade_handler_t *handler = (rf_blade_handler_t*) malloc(sizeof(rf_blade_handler_t)); + const struct bladerf_range* range_tx = NULL; + const struct bladerf_range* range_rx = NULL; + *h = NULL; + + rf_blade_handler_t* handler = (rf_blade_handler_t*)malloc(sizeof(rf_blade_handler_t)); if (!handler) { perror("malloc"); - return -1; + return -1; } - *h = handler; + *h = handler; printf("Opening bladeRF...\n"); int status = bladerf_open(&handler->dev, args); @@ -193,9 +193,9 @@ int rf_blade_open(char *args, void **h) ERROR("Unable to open device: %s\n", bladerf_strerror(status)); return status; } - - //bladerf_log_set_verbosity(BLADERF_LOG_LEVEL_VERBOSE); - + + // bladerf_log_set_verbosity(BLADERF_LOG_LEVEL_VERBOSE); + /* Get Gain ranges and set Rx to maximum */ status = bladerf_get_gain_range(handler->dev, BLADERF_RX_X1, &range_rx); if ((status != 0) || (range_rx == NULL)) { @@ -230,18 +230,17 @@ int rf_blade_open(char *args, void **h) return 0; } - -int rf_blade_close(void *h) +int rf_blade_close(void* h) { - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; bladerf_close(handler->dev); return 0; } -double rf_blade_set_rx_srate(void *h, double freq) +double rf_blade_set_rx_srate(void* h, double freq) { - uint32_t bw; - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + uint32_t bw; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; int status = bladerf_set_sample_rate(handler->dev, BLADERF_RX_X1, (uint32_t)freq, &handler->rx_rate); if (status != 0) { ERROR("Failed to set samplerate = %u: %s\n", (uint32_t)freq, bladerf_strerror(status)); @@ -260,14 +259,14 @@ double rf_blade_set_rx_srate(void *h, double freq) return -1; } } - printf("Set RX sampling rate %.2f Mhz, filter BW: %.2f Mhz\n", (float) handler->rx_rate/1e6, (float) bw/1e6); - return (double) handler->rx_rate; + printf("Set RX sampling rate %.2f Mhz, filter BW: %.2f Mhz\n", (float)handler->rx_rate / 1e6, (float)bw / 1e6); + return (double)handler->rx_rate; } -double rf_blade_set_tx_srate(void *h, double freq) +double rf_blade_set_tx_srate(void* h, double freq) { - uint32_t bw; - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + uint32_t bw; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; int status = bladerf_set_sample_rate(handler->dev, BLADERF_TX_X1, (uint32_t)freq, &handler->tx_rate); if (status != 0) { ERROR("Failed to set samplerate = %u: %s\n", (uint32_t)freq, bladerf_strerror(status)); @@ -278,13 +277,13 @@ double rf_blade_set_tx_srate(void *h, double freq) ERROR("Failed to set bandwidth = %u: %s\n", handler->tx_rate, bladerf_strerror(status)); return -1; } - return (double) handler->tx_rate; + return (double)handler->tx_rate; } -double rf_blade_set_rx_gain(void *h, double gain) +double rf_blade_set_rx_gain(void* h, double gain) { - int status; - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + int status; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; status = bladerf_set_gain(handler->dev, BLADERF_RX_X1, (bladerf_gain)gain); if (status != 0) { ERROR("Failed to set RX gain: %s\n", bladerf_strerror(status)); @@ -293,10 +292,10 @@ double rf_blade_set_rx_gain(void *h, double gain) return rf_blade_get_rx_gain(h); } -double rf_blade_set_tx_gain(void *h, double gain) +double rf_blade_set_tx_gain(void* h, double gain) { - int status; - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + int status; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; status = bladerf_set_gain(handler->dev, BLADERF_TX_X1, (bladerf_gain)gain); if (status != 0) { ERROR("Failed to set TX gain: %s\n", bladerf_strerror(status)); @@ -305,11 +304,11 @@ double rf_blade_set_tx_gain(void *h, double gain) return rf_blade_get_tx_gain(h); } -double rf_blade_get_rx_gain(void *h) +double rf_blade_get_rx_gain(void* h) { - int status; - bladerf_gain gain = 0; - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + int status; + bladerf_gain gain = 0; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; status = bladerf_get_gain(handler->dev, BLADERF_RX_X1, &gain); if (status != 0) { ERROR("Failed to get RX gain: %s\n", bladerf_strerror(status)); @@ -318,11 +317,11 @@ double rf_blade_get_rx_gain(void *h) return gain; } -double rf_blade_get_tx_gain(void *h) +double rf_blade_get_tx_gain(void* h) { - int status; - bladerf_gain gain = 0; - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + int status; + bladerf_gain gain = 0; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; status = bladerf_get_gain(handler->dev, BLADERF_TX_X1, &gain); if (status != 0) { ERROR("Failed to get TX gain: %s\n", bladerf_strerror(status)); @@ -331,13 +330,13 @@ double rf_blade_get_tx_gain(void *h) return gain; } -srslte_rf_info_t *rf_blade_get_info(void *h) +srslte_rf_info_t* rf_blade_get_info(void* h) { - srslte_rf_info_t *info = NULL; + srslte_rf_info_t* info = NULL; if (h) { - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; info = &handler->info; } @@ -347,22 +346,22 @@ srslte_rf_info_t *rf_blade_get_info(void *h) double rf_blade_set_rx_freq(void* h, UNUSED uint32_t ch, double freq) { rf_blade_handler_t* handler = (rf_blade_handler_t*)h; - bladerf_frequency f_int = (uint32_t) round(freq); + bladerf_frequency f_int = (uint32_t)round(freq); int status = bladerf_set_frequency(handler->dev, BLADERF_RX_X1, f_int); if (status != 0) { ERROR("Failed to set samplerate = %u: %s\n", (uint32_t)freq, bladerf_strerror(status)); return -1; } - f_int=0; + f_int = 0; bladerf_get_frequency(handler->dev, BLADERF_RX_X1, &f_int); printf("set RX frequency to %lu\n", f_int); - + return freq; } double rf_blade_set_tx_freq(void* h, UNUSED uint32_t ch, double freq) { - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; bladerf_frequency f_int = (uint32_t)round(freq); int status = bladerf_set_frequency(handler->dev, BLADERF_TX_X1, f_int); if (status != 0) { @@ -370,28 +369,29 @@ double rf_blade_set_tx_freq(void* h, UNUSED uint32_t ch, double freq) return -1; } - f_int=0; + f_int = 0; bladerf_get_frequency(handler->dev, BLADERF_TX_X1, &f_int); printf("set TX frequency to %lu\n", f_int); return freq; } -static void timestamp_to_secs(uint32_t rate, uint64_t timestamp, time_t *secs, double *frac_secs) { - double totalsecs = (double) timestamp/rate; - time_t secs_i = (time_t) totalsecs; +static void timestamp_to_secs(uint32_t rate, uint64_t timestamp, time_t* secs, double* frac_secs) +{ + double totalsecs = (double)timestamp / rate; + time_t secs_i = (time_t)totalsecs; if (secs) { *secs = secs_i; } if (frac_secs) { - *frac_secs = totalsecs-secs_i; + *frac_secs = totalsecs - secs_i; } } -void rf_blade_get_time(void *h, time_t *secs, double *frac_secs) +void rf_blade_get_time(void* h, time_t* secs, double* frac_secs) { - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; struct bladerf_metadata meta; - + int status = bladerf_get_timestamp(handler->dev, BLADERF_RX, &meta.timestamp); if (status != 0) { ERROR("Failed to get current RX timestamp: %s\n", bladerf_strerror(status)); @@ -399,27 +399,31 @@ void rf_blade_get_time(void *h, time_t *secs, double *frac_secs) timestamp_to_secs(handler->rx_rate, meta.timestamp, secs, frac_secs); } -int rf_blade_recv_with_time_multi(void *h, - void **data, +int rf_blade_recv_with_time_multi(void* h, + void** data, uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs) + bool blocking, + time_t* secs, + double* frac_secs) { - return rf_blade_recv_with_time(h, *data, nsamples, blocking, secs, frac_secs); + return rf_blade_recv_with_time(h, *data, nsamples, blocking, secs, frac_secs); } -int rf_blade_recv_with_time( - void* h, void* data, uint32_t nsamples, UNUSED bool blocking, time_t* secs, double* frac_secs) +int rf_blade_recv_with_time(void* h, + void* data, + uint32_t nsamples, + UNUSED bool blocking, + time_t* secs, + double* frac_secs) { - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; struct bladerf_metadata meta; - int status; - + int status; + memset(&meta, 0, sizeof(meta)); meta.flags = BLADERF_META_FLAG_RX_NOW; - - if (2*nsamples > CONVERT_BUFFER_SIZE) { + + if (2 * nsamples > CONVERT_BUFFER_SIZE) { ERROR("RX failed: nsamples exceeds buffer size (%d>%d)\n", nsamples, CONVERT_BUFFER_SIZE); return -1; } @@ -440,23 +444,23 @@ int rf_blade_recv_with_time( } timestamp_to_secs(handler->rx_rate, meta.timestamp, secs, frac_secs); - srslte_vec_convert_if(handler->rx_buffer, 2048, data, 2*nsamples); - + srslte_vec_convert_if(handler->rx_buffer, 2048, data, 2 * nsamples); + return nsamples; } - -int rf_blade_send_timed_multi(void *h, - void *data[4], - int nsamples, - time_t secs, - double frac_secs, - bool has_time_spec, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst) + +int rf_blade_send_timed_multi(void* h, + void* data[4], + int nsamples, + time_t secs, + double frac_secs, + bool has_time_spec, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst) { - return rf_blade_send_timed(h, data[0], nsamples, secs, frac_secs, has_time_spec, blocking, is_start_of_burst, - is_end_of_burst); + return rf_blade_send_timed( + h, data[0], nsamples, secs, frac_secs, has_time_spec, blocking, is_start_of_burst, is_end_of_burst); } int rf_blade_send_timed(void* h, @@ -469,20 +473,20 @@ int rf_blade_send_timed(void* h, bool is_start_of_burst, bool is_end_of_burst) { - rf_blade_handler_t *handler = (rf_blade_handler_t*) h; + rf_blade_handler_t* handler = (rf_blade_handler_t*)h; struct bladerf_metadata meta; - int status; - + int status; + if (!handler->tx_stream_enabled) { rf_blade_start_tx_stream(h); } - - if (2*nsamples > CONVERT_BUFFER_SIZE) { + + if (2 * nsamples > CONVERT_BUFFER_SIZE) { ERROR("TX failed: nsamples exceeds buffer size (%d>%d)\n", nsamples, CONVERT_BUFFER_SIZE); return -1; } - srslte_vec_convert_fi(data, 2048, handler->tx_buffer, 2*nsamples); + srslte_vec_convert_fi(data, 2048, handler->tx_buffer, 2 * nsamples); memset(&meta, 0, sizeof(meta)); if (is_start_of_burst) { @@ -520,6 +524,6 @@ int rf_blade_send_timed(void* h, ERROR("TX warning: underflow detected.\n"); } } - + return nsamples; } diff --git a/lib/src/phy/rf/rf_blade_imp.h b/lib/src/phy/rf/rf_blade_imp.h index 53cf24158..0a4564e81 100644 --- a/lib/src/phy/rf/rf_blade_imp.h +++ b/lib/src/phy/rf/rf_blade_imp.h @@ -24,93 +24,74 @@ #define DEVNAME "bladerf" -SRSLTE_API int rf_blade_open(char *args, - void **handler); +SRSLTE_API int rf_blade_open(char* args, void** handler); -SRSLTE_API int rf_blade_open_multi(char *args, - void **handler, uint32_t nof_channels); +SRSLTE_API int rf_blade_open_multi(char* args, void** handler, uint32_t nof_channels); SRSLTE_API const char* rf_blade_devname(void* h); -SRSLTE_API int rf_blade_close(void *h); +SRSLTE_API int rf_blade_close(void* h); -SRSLTE_API int rf_blade_start_rx_stream(void *h, bool now); +SRSLTE_API int rf_blade_start_rx_stream(void* h, bool now); -SRSLTE_API int rf_blade_start_rx_stream_nsamples(void *h, - uint32_t nsamples); +SRSLTE_API int rf_blade_start_rx_stream_nsamples(void* h, uint32_t nsamples); -SRSLTE_API int rf_blade_stop_rx_stream(void *h); +SRSLTE_API int rf_blade_stop_rx_stream(void* h); -SRSLTE_API void rf_blade_flush_buffer(void *h); +SRSLTE_API void rf_blade_flush_buffer(void* h); -SRSLTE_API bool rf_blade_has_rssi(void *h); +SRSLTE_API bool rf_blade_has_rssi(void* h); -SRSLTE_API float rf_blade_get_rssi(void *h); +SRSLTE_API float rf_blade_get_rssi(void* h); SRSLTE_API double rf_blade_set_rx_srate(void* h, double freq); -SRSLTE_API double rf_blade_set_rx_gain(void *h, - double gain); +SRSLTE_API double rf_blade_set_rx_gain(void* h, double gain); -SRSLTE_API float rf_blade_get_rx_gain_offset(void *h); +SRSLTE_API float rf_blade_get_rx_gain_offset(void* h); -SRSLTE_API double rf_blade_get_rx_gain(void *h); +SRSLTE_API double rf_blade_get_rx_gain(void* h); -SRSLTE_API double rf_blade_get_tx_gain(void *h); +SRSLTE_API double rf_blade_get_tx_gain(void* h); -SRSLTE_API srslte_rf_info_t *rf_blade_get_info(void *h); +SRSLTE_API srslte_rf_info_t* rf_blade_get_info(void* h); -SRSLTE_API void rf_blade_suppress_stdout(void *h); +SRSLTE_API void rf_blade_suppress_stdout(void* h); -SRSLTE_API void rf_blade_register_error_handler(void *h, - srslte_rf_error_handler_t error_handler); +SRSLTE_API void rf_blade_register_error_handler(void* h, srslte_rf_error_handler_t error_handler); SRSLTE_API double rf_blade_set_rx_freq(void* h, uint32_t ch, double freq); -SRSLTE_API int rf_blade_recv_with_time_multi(void *h, - void **data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs); +SRSLTE_API int +rf_blade_recv_with_time_multi(void* h, void** data, uint32_t nsamples, bool blocking, time_t* secs, double* frac_secs); -SRSLTE_API int rf_blade_recv_with_time(void *h, - void *data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs); +SRSLTE_API int +rf_blade_recv_with_time(void* h, void* data, uint32_t nsamples, bool blocking, time_t* secs, double* frac_secs); -SRSLTE_API double rf_blade_set_tx_srate(void *h, - double freq); +SRSLTE_API double rf_blade_set_tx_srate(void* h, double freq); -SRSLTE_API double rf_blade_set_tx_gain(void *h, - double gain); +SRSLTE_API double rf_blade_set_tx_gain(void* h, double gain); SRSLTE_API double rf_blade_set_tx_freq(void* h, uint32_t ch, double freq); -SRSLTE_API void rf_blade_get_time(void *h, - time_t *secs, - double *frac_secs); - -SRSLTE_API int rf_blade_send_timed_multi(void *h, - void *data[4], - int nsamples, - time_t secs, - double frac_secs, - bool has_time_spec, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst); - -SRSLTE_API int rf_blade_send_timed(void *h, - void *data, - int nsamples, - time_t secs, - double frac_secs, - bool has_time_spec, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst); - - +SRSLTE_API void rf_blade_get_time(void* h, time_t* secs, double* frac_secs); + +SRSLTE_API int rf_blade_send_timed_multi(void* h, + void* data[4], + int nsamples, + time_t secs, + double frac_secs, + bool has_time_spec, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst); + +SRSLTE_API int rf_blade_send_timed(void* h, + void* data, + int nsamples, + time_t secs, + double frac_secs, + bool has_time_spec, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst); diff --git a/lib/src/phy/rf/rf_dev.h b/lib/src/phy/rf/rf_dev.h index efa8923ae..8fa76caf2 100644 --- a/lib/src/phy/rf/rf_dev.h +++ b/lib/src/phy/rf/rf_dev.h @@ -19,42 +19,65 @@ * */ +#include "srslte/phy/rf/rf.h" +#include + /* RF frontend API */ typedef struct { - const char *name; + const char* name; const char* (*srslte_rf_devname)(void* h); - int (*srslte_rf_start_rx_stream)(void *h, bool now); - int (*srslte_rf_stop_rx_stream)(void *h); - void (*srslte_rf_flush_buffer)(void *h); - bool (*srslte_rf_has_rssi)(void *h); - float (*srslte_rf_get_rssi)(void *h); - void (*srslte_rf_suppress_stdout)(void *h); - void (*srslte_rf_register_error_handler)(void *h, srslte_rf_error_handler_t error_handler); - int (*srslte_rf_open)(char *args, void **h); - int (*srslte_rf_open_multi)(char *args, void **h, uint32_t nof_channels); - int (*srslte_rf_close)(void *h); - double (*srslte_rf_set_rx_srate)(void *h, double freq); - double (*srslte_rf_set_rx_gain)(void *h, double gain); - double (*srslte_rf_set_tx_gain)(void *h, double gain); - double (*srslte_rf_get_rx_gain)(void *h); - double (*srslte_rf_get_tx_gain)(void *h); - srslte_rf_info_t *(*srslte_rf_get_info)(void *h); + int (*srslte_rf_start_rx_stream)(void* h, bool now); + int (*srslte_rf_stop_rx_stream)(void* h); + void (*srslte_rf_flush_buffer)(void* h); + bool (*srslte_rf_has_rssi)(void* h); + float (*srslte_rf_get_rssi)(void* h); + void (*srslte_rf_suppress_stdout)(void* h); + void (*srslte_rf_register_error_handler)(void* h, srslte_rf_error_handler_t error_handler); + int (*srslte_rf_open)(char* args, void** h); + int (*srslte_rf_open_multi)(char* args, void** h, uint32_t nof_channels); + int (*srslte_rf_close)(void* h); + double (*srslte_rf_set_rx_srate)(void* h, double freq); + double (*srslte_rf_set_rx_gain)(void* h, double gain); + double (*srslte_rf_set_tx_gain)(void* h, double gain); + double (*srslte_rf_get_rx_gain)(void* h); + double (*srslte_rf_get_tx_gain)(void* h); + srslte_rf_info_t* (*srslte_rf_get_info)(void* h); double (*srslte_rf_set_rx_freq)(void* h, uint32_t ch, double freq); - double (*srslte_rf_set_tx_srate)(void *h, double freq); + double (*srslte_rf_set_tx_srate)(void* h, double freq); double (*srslte_rf_set_tx_freq)(void* h, uint32_t ch, double freq); void (*srslte_rf_get_time)(void* h, time_t* secs, double* frac_secs); void (*srslte_rf_sync_pps)(void* h); - int (*srslte_rf_recv_with_time)(void *h, void *data, uint32_t nsamples, - bool blocking, time_t *secs,double *frac_secs); - int (*srslte_rf_recv_with_time_multi)(void *h, void **data, uint32_t nsamples, - bool blocking, time_t *secs,double *frac_secs); - int (*srslte_rf_send_timed)(void *h, void *data, int nsamples, - time_t secs, double frac_secs, bool has_time_spec, - bool blocking, bool is_start_of_burst, bool is_end_of_burst); - int (*srslte_rf_send_timed_multi)(void *h, void *data[4], int nsamples, - time_t secs, double frac_secs, bool has_time_spec, - bool blocking, bool is_start_of_burst, bool is_end_of_burst); -} rf_dev_t; + int (*srslte_rf_recv_with_time)(void* h, + void* data, + uint32_t nsamples, + bool blocking, + time_t* secs, + double* frac_secs); + int (*srslte_rf_recv_with_time_multi)(void* h, + void** data, + uint32_t nsamples, + bool blocking, + time_t* secs, + double* frac_secs); + int (*srslte_rf_send_timed)(void* h, + void* data, + int nsamples, + time_t secs, + double frac_secs, + bool has_time_spec, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst); + int (*srslte_rf_send_timed_multi)(void* h, + void* data[4], + int nsamples, + time_t secs, + double frac_secs, + bool has_time_spec, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst); +} rf_dev_t; /* Define implementation for UHD */ #ifdef ENABLE_UHD @@ -195,43 +218,17 @@ static rf_dev_t dev_zmq = {"zmq", //#define ENABLE_DUMMY_DEV #ifdef ENABLE_DUMMY_DEV -int dummy_rcv() { +int dummy_rcv() +{ usleep(100000); - return 1; -} -void dummy_fnc() { - + return 1; } +void dummy_fnc() {} -static rf_dev_t dev_dummy = { - "dummy", - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_fnc, - dummy_rcv, - dummy_fnc, - dummy_fnc, - dummy_fnc -}; +static rf_dev_t dev_dummy = {"dummy", dummy_fnc, dummy_fnc, dummy_fnc, dummy_fnc, dummy_fnc, dummy_fnc, + dummy_fnc, dummy_fnc, dummy_fnc, dummy_fnc, dummy_fnc, dummy_fnc, dummy_fnc, + dummy_fnc, dummy_fnc, dummy_fnc, dummy_fnc, dummy_fnc, dummy_fnc, dummy_fnc, + dummy_fnc, dummy_fnc, dummy_rcv, dummy_fnc, dummy_fnc, dummy_fnc}; #endif static rf_dev_t* available_devices[] = { diff --git a/lib/src/phy/rf/rf_helper.h b/lib/src/phy/rf/rf_helper.h index ddfbf1adc..c38a2b00a 100644 --- a/lib/src/phy/rf/rf_helper.h +++ b/lib/src/phy/rf/rf_helper.h @@ -23,23 +23,23 @@ #include -#define REMOVE_SUBSTRING_WITHCOMAS(S, TOREMOVE) \ - remove_substring(S, TOREMOVE ",");\ - remove_substring(S, TOREMOVE ", ");\ - remove_substring(S, "," TOREMOVE);\ - remove_substring(S, ", " TOREMOVE);\ +#define REMOVE_SUBSTRING_WITHCOMAS(S, TOREMOVE) \ + remove_substring(S, TOREMOVE ","); \ + remove_substring(S, TOREMOVE ", "); \ + remove_substring(S, "," TOREMOVE); \ + remove_substring(S, ", " TOREMOVE); \ remove_substring(S, TOREMOVE) static inline void remove_substring(char* s, const char* toremove) { - while((s=strstr(s,toremove))) { - memmove(s,s+strlen(toremove),1+strlen(s+strlen(toremove))); + while ((s = strstr(s, toremove))) { + memmove(s, s + strlen(toremove), 1 + strlen(s + strlen(toremove))); } } static inline void copy_subdev_string(char* dst, char* src) { - int n = 0; + int n = 0; int len = (int)strlen(src); /* Copy until end of string or comma */ while (n < len && src[n] != '\0' && src[n] != ',') { diff --git a/lib/src/phy/rf/rf_imp.c b/lib/src/phy/rf/rf_imp.c index eb1d214be..ed4113220 100644 --- a/lib/src/phy/rf/rf_imp.c +++ b/lib/src/phy/rf/rf_imp.c @@ -21,42 +21,44 @@ #include +#include "rf_dev.h" #include "srslte/phy/rf/rf.h" #include "srslte/srslte.h" -#include "rf_dev.h" -int rf_get_available_devices(char **devnames, int max_strlen) { - int i=0; - while(available_devices[i]->name) { +int rf_get_available_devices(char** devnames, int max_strlen) +{ + int i = 0; + while (available_devices[i]->name) { strncpy(devnames[i], available_devices[i]->name, max_strlen); i++; } return i; } -double srslte_rf_set_rx_gain_th(srslte_rf_t *rf, double gain) +double srslte_rf_set_rx_gain_th(srslte_rf_t* rf, double gain) { - if (gain > rf->cur_rx_gain + 2 || gain < rf->cur_rx_gain - 2){ + if (gain > rf->cur_rx_gain + 2 || gain < rf->cur_rx_gain - 2) { pthread_mutex_lock(&rf->mutex); - rf->new_rx_gain = gain; + rf->new_rx_gain = gain; pthread_cond_signal(&rf->cond); pthread_mutex_unlock(&rf->mutex); } return rf->cur_rx_gain; } -void srslte_rf_set_tx_rx_gain_offset(srslte_rf_t *rf, double offset) { - rf->tx_rx_gain_offset = offset; +void srslte_rf_set_tx_rx_gain_offset(srslte_rf_t* rf, double offset) +{ + rf->tx_rx_gain_offset = offset; } /* This thread listens for set_rx_gain commands to the USRP */ -static void* thread_gain_fcn(void *h) { - srslte_rf_t* rf = (srslte_rf_t*) h; - - while(rf->thread_gain_run) { +static void* thread_gain_fcn(void* h) +{ + srslte_rf_t* rf = (srslte_rf_t*)h; + + while (rf->thread_gain_run) { pthread_mutex_lock(&rf->mutex); - while(rf->cur_rx_gain == rf->new_rx_gain) - { + while (rf->cur_rx_gain == rf->new_rx_gain) { pthread_cond_wait(&rf->cond, &rf->mutex); } if (rf->new_rx_gain != rf->cur_rx_gain) { @@ -66,17 +68,17 @@ static void* thread_gain_fcn(void *h) { } if (rf->tx_gain_same_rx) { printf("setting also tx\n"); - srslte_rf_set_tx_gain(h, rf->cur_rx_gain+rf->tx_rx_gain_offset); + srslte_rf_set_tx_gain(h, rf->cur_rx_gain + rf->tx_rx_gain_offset); } pthread_mutex_unlock(&rf->mutex); } - return NULL; + return NULL; } - /* Create auxiliary thread and mutexes for AGC */ -int srslte_rf_start_gain_thread(srslte_rf_t *rf, bool tx_gain_same_rx) { - rf->tx_gain_same_rx = tx_gain_same_rx; +int srslte_rf_start_gain_thread(srslte_rf_t* rf, bool tx_gain_same_rx) +{ + rf->tx_gain_same_rx = tx_gain_same_rx; rf->tx_rx_gain_offset = 0.0; if (pthread_mutex_init(&rf->mutex, NULL)) { return -1; @@ -93,90 +95,93 @@ int srslte_rf_start_gain_thread(srslte_rf_t *rf, bool tx_gain_same_rx) { return 0; } -const char* srslte_rf_get_devname(srslte_rf_t *rf) { - return ((rf_dev_t*) rf->dev)->name; +const char* srslte_rf_get_devname(srslte_rf_t* rf) +{ + return ((rf_dev_t*)rf->dev)->name; } -int srslte_rf_open_devname(srslte_rf_t *rf, char *devname, char *args, uint32_t nof_channels) { +int srslte_rf_open_devname(srslte_rf_t* rf, char* devname, char* args, uint32_t nof_channels) +{ rf->thread_gain_run = false; /* Try to open the device if name is provided */ if (devname) { if (devname[0] != '\0') { - int i=0; - while(available_devices[i] != NULL) { + int i = 0; + while (available_devices[i] != NULL) { if (!strcmp(available_devices[i]->name, devname)) { rf->dev = available_devices[i]; return available_devices[i]->srslte_rf_open_multi(args, &rf->handler, nof_channels); } i++; - } + } printf("Device %s not found. Switching to auto mode\n", devname); } } - + /* If in auto mode or provided device not found, try to open in order of apperance in available_devices[] array */ - int i=0; - while(available_devices[i] != NULL) { + int i = 0; + while (available_devices[i] != NULL) { if (!available_devices[i]->srslte_rf_open_multi(args, &rf->handler, nof_channels)) { rf->dev = available_devices[i]; - return 0; + return 0; } i++; } ERROR("No compatible RF frontend found\n"); - return -1; + return -1; } -const char* srslte_rf_name(srslte_rf_t *rf) { - return ((rf_dev_t*) rf->dev)->srslte_rf_devname(rf->handler); +const char* srslte_rf_name(srslte_rf_t* rf) +{ + return ((rf_dev_t*)rf->dev)->srslte_rf_devname(rf->handler); } -int srslte_rf_start_rx_stream(srslte_rf_t *rf, bool now) +int srslte_rf_start_rx_stream(srslte_rf_t* rf, bool now) { - return ((rf_dev_t*) rf->dev)->srslte_rf_start_rx_stream(rf->handler, now); + return ((rf_dev_t*)rf->dev)->srslte_rf_start_rx_stream(rf->handler, now); } -int srslte_rf_stop_rx_stream(srslte_rf_t *rf) +int srslte_rf_stop_rx_stream(srslte_rf_t* rf) { - return ((rf_dev_t*) rf->dev)->srslte_rf_stop_rx_stream(rf->handler); + return ((rf_dev_t*)rf->dev)->srslte_rf_stop_rx_stream(rf->handler); } -void srslte_rf_flush_buffer(srslte_rf_t *rf) +void srslte_rf_flush_buffer(srslte_rf_t* rf) { - ((rf_dev_t*) rf->dev)->srslte_rf_flush_buffer(rf->handler); + ((rf_dev_t*)rf->dev)->srslte_rf_flush_buffer(rf->handler); } -bool srslte_rf_has_rssi(srslte_rf_t *rf) +bool srslte_rf_has_rssi(srslte_rf_t* rf) { - return ((rf_dev_t*) rf->dev)->srslte_rf_has_rssi(rf->handler); + return ((rf_dev_t*)rf->dev)->srslte_rf_has_rssi(rf->handler); } -float srslte_rf_get_rssi(srslte_rf_t *rf) +float srslte_rf_get_rssi(srslte_rf_t* rf) { - return ((rf_dev_t*) rf->dev)->srslte_rf_get_rssi(rf->handler); + return ((rf_dev_t*)rf->dev)->srslte_rf_get_rssi(rf->handler); } -void srslte_rf_suppress_stdout(srslte_rf_t *rf) +void srslte_rf_suppress_stdout(srslte_rf_t* rf) { - ((rf_dev_t*) rf->dev)->srslte_rf_suppress_stdout(rf->handler); + ((rf_dev_t*)rf->dev)->srslte_rf_suppress_stdout(rf->handler); } -void srslte_rf_register_error_handler(srslte_rf_t *rf, srslte_rf_error_handler_t error_handler) +void srslte_rf_register_error_handler(srslte_rf_t* rf, srslte_rf_error_handler_t error_handler) { - ((rf_dev_t*) rf->dev)->srslte_rf_register_error_handler(rf->handler, error_handler); + ((rf_dev_t*)rf->dev)->srslte_rf_register_error_handler(rf->handler, error_handler); } -int srslte_rf_open(srslte_rf_t *h, char *args) +int srslte_rf_open(srslte_rf_t* h, char* args) { return srslte_rf_open_devname(h, NULL, args, 1); } -int srslte_rf_open_multi(srslte_rf_t *h, char *args, uint32_t nof_channels) +int srslte_rf_open_multi(srslte_rf_t* h, char* args, uint32_t nof_channels) { return srslte_rf_open_devname(h, NULL, args, nof_channels); } -int srslte_rf_close(srslte_rf_t *rf) +int srslte_rf_close(srslte_rf_t* rf) { // Stop gain thread if (rf->thread_gain_run) { @@ -184,33 +189,34 @@ int srslte_rf_close(srslte_rf_t *rf) pthread_join(rf->thread_gain, NULL); } - return ((rf_dev_t*) rf->dev)->srslte_rf_close(rf->handler); + return ((rf_dev_t*)rf->dev)->srslte_rf_close(rf->handler); } -double srslte_rf_set_rx_srate(srslte_rf_t *rf, double freq) +double srslte_rf_set_rx_srate(srslte_rf_t* rf, double freq) { - return ((rf_dev_t*) rf->dev)->srslte_rf_set_rx_srate(rf->handler, freq); + return ((rf_dev_t*)rf->dev)->srslte_rf_set_rx_srate(rf->handler, freq); } -double srslte_rf_set_rx_gain(srslte_rf_t *rf, double gain) +double srslte_rf_set_rx_gain(srslte_rf_t* rf, double gain) { - return ((rf_dev_t*) rf->dev)->srslte_rf_set_rx_gain(rf->handler, gain); + return ((rf_dev_t*)rf->dev)->srslte_rf_set_rx_gain(rf->handler, gain); } -double srslte_rf_get_rx_gain(srslte_rf_t *rf) +double srslte_rf_get_rx_gain(srslte_rf_t* rf) { - return ((rf_dev_t*) rf->dev)->srslte_rf_get_rx_gain(rf->handler); + return ((rf_dev_t*)rf->dev)->srslte_rf_get_rx_gain(rf->handler); } -double srslte_rf_get_tx_gain(srslte_rf_t *rf) +double srslte_rf_get_tx_gain(srslte_rf_t* rf) { - return ((rf_dev_t*) rf->dev)->srslte_rf_get_tx_gain(rf->handler); + return ((rf_dev_t*)rf->dev)->srslte_rf_get_tx_gain(rf->handler); } -srslte_rf_info_t *srslte_rf_get_info(srslte_rf_t *rf) { - srslte_rf_info_t *ret = NULL; - if (((rf_dev_t*) rf->dev)->srslte_rf_get_info) { - ret = ((rf_dev_t*) rf->dev)->srslte_rf_get_info(rf->handler); +srslte_rf_info_t* srslte_rf_get_info(srslte_rf_t* rf) +{ + srslte_rf_info_t* ret = NULL; + if (((rf_dev_t*)rf->dev)->srslte_rf_get_info) { + ret = ((rf_dev_t*)rf->dev)->srslte_rf_get_info(rf->handler); } return ret; } @@ -220,45 +226,44 @@ double srslte_rf_set_rx_freq(srslte_rf_t* rf, uint32_t ch, double freq) return ((rf_dev_t*)rf->dev)->srslte_rf_set_rx_freq(rf->handler, ch, freq); } - -int srslte_rf_recv(srslte_rf_t *rf, void *data, uint32_t nsamples, bool blocking) +int srslte_rf_recv(srslte_rf_t* rf, void* data, uint32_t nsamples, bool blocking) { return srslte_rf_recv_with_time(rf, data, nsamples, blocking, NULL, NULL); } -int srslte_rf_recv_multi(srslte_rf_t *rf, void **data, uint32_t nsamples, bool blocking) +int srslte_rf_recv_multi(srslte_rf_t* rf, void** data, uint32_t nsamples, bool blocking) { return srslte_rf_recv_with_time_multi(rf, data, nsamples, blocking, NULL, NULL); } -int srslte_rf_recv_with_time(srslte_rf_t *rf, - void *data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs) +int srslte_rf_recv_with_time(srslte_rf_t* rf, + void* data, + uint32_t nsamples, + bool blocking, + time_t* secs, + double* frac_secs) { - return ((rf_dev_t*) rf->dev)->srslte_rf_recv_with_time(rf->handler, data, nsamples, blocking, secs, frac_secs); + return ((rf_dev_t*)rf->dev)->srslte_rf_recv_with_time(rf->handler, data, nsamples, blocking, secs, frac_secs); } -int srslte_rf_recv_with_time_multi(srslte_rf_t *rf, - void **data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs) +int srslte_rf_recv_with_time_multi(srslte_rf_t* rf, + void** data, + uint32_t nsamples, + bool blocking, + time_t* secs, + double* frac_secs) { - return ((rf_dev_t*) rf->dev)->srslte_rf_recv_with_time_multi(rf->handler, data, nsamples, blocking, secs, frac_secs); + return ((rf_dev_t*)rf->dev)->srslte_rf_recv_with_time_multi(rf->handler, data, nsamples, blocking, secs, frac_secs); } -double srslte_rf_set_tx_gain(srslte_rf_t *rf, double gain) +double srslte_rf_set_tx_gain(srslte_rf_t* rf, double gain) { - return ((rf_dev_t*) rf->dev)->srslte_rf_set_tx_gain(rf->handler, gain); + return ((rf_dev_t*)rf->dev)->srslte_rf_set_tx_gain(rf->handler, gain); } -double srslte_rf_set_tx_srate(srslte_rf_t *rf, double freq) +double srslte_rf_set_tx_srate(srslte_rf_t* rf, double freq) { - return ((rf_dev_t*) rf->dev)->srslte_rf_set_tx_srate(rf->handler, freq); + return ((rf_dev_t*)rf->dev)->srslte_rf_set_tx_srate(rf->handler, freq); } double srslte_rf_set_tx_freq(srslte_rf_t* rf, uint32_t ch, double freq) @@ -266,9 +271,9 @@ double srslte_rf_set_tx_freq(srslte_rf_t* rf, uint32_t ch, double freq) return ((rf_dev_t*)rf->dev)->srslte_rf_set_tx_freq(rf->handler, ch, freq); } -void srslte_rf_get_time(srslte_rf_t *rf, time_t *secs, double *frac_secs) +void srslte_rf_get_time(srslte_rf_t* rf, time_t* secs, double* frac_secs) { - return ((rf_dev_t*) rf->dev)->srslte_rf_get_time(rf->handler, secs, frac_secs); + return ((rf_dev_t*)rf->dev)->srslte_rf_get_time(rf->handler, secs, frac_secs); } int srslte_rf_sync(srslte_rf_t* rf) @@ -284,74 +289,77 @@ int srslte_rf_sync(srslte_rf_t* rf) return ret; } -int srslte_rf_send_timed3(srslte_rf_t *rf, - void *data, - int nsamples, - time_t secs, - double frac_secs, - bool has_time_spec, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst) +int srslte_rf_send_timed3(srslte_rf_t* rf, + void* data, + int nsamples, + time_t secs, + double frac_secs, + bool has_time_spec, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst) { - return ((rf_dev_t*) rf->dev)->srslte_rf_send_timed(rf->handler, data, nsamples, secs, frac_secs, - has_time_spec, blocking, is_start_of_burst, is_end_of_burst); + return ((rf_dev_t*)rf->dev) + ->srslte_rf_send_timed( + rf->handler, data, nsamples, secs, frac_secs, has_time_spec, blocking, is_start_of_burst, is_end_of_burst); } -int srslte_rf_send_timed_multi(srslte_rf_t *rf, - void *data[4], - int nsamples, - time_t secs, - double frac_secs, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst) +int srslte_rf_send_timed_multi(srslte_rf_t* rf, + void* data[4], + int nsamples, + time_t secs, + double frac_secs, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst) { - return ((rf_dev_t*) rf->dev)->srslte_rf_send_timed_multi(rf->handler, data, nsamples, secs, frac_secs, - true, blocking, is_start_of_burst, is_end_of_burst); + return ((rf_dev_t*)rf->dev) + ->srslte_rf_send_timed_multi( + rf->handler, data, nsamples, secs, frac_secs, true, blocking, is_start_of_burst, is_end_of_burst); } -int srslte_rf_send_multi(srslte_rf_t *rf, - void *data[4], - int nsamples, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst) +int srslte_rf_send_multi(srslte_rf_t* rf, + void* data[4], + int nsamples, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst) { - return ((rf_dev_t*) rf->dev)->srslte_rf_send_timed_multi(rf->handler, data, nsamples, 0, 0, - false, blocking, is_start_of_burst, is_end_of_burst); + return ((rf_dev_t*)rf->dev) + ->srslte_rf_send_timed_multi( + rf->handler, data, nsamples, 0, 0, false, blocking, is_start_of_burst, is_end_of_burst); } -int srslte_rf_send(srslte_rf_t *rf, void *data, uint32_t nsamples, bool blocking) +int srslte_rf_send(srslte_rf_t* rf, void* data, uint32_t nsamples, bool blocking) { - return srslte_rf_send2(rf, data, nsamples, blocking, true, true); + return srslte_rf_send2(rf, data, nsamples, blocking, true, true); } -int srslte_rf_send2(srslte_rf_t *rf, void *data, uint32_t nsamples, bool blocking, bool start_of_burst, bool end_of_burst) +int srslte_rf_send2(srslte_rf_t* rf, + void* data, + uint32_t nsamples, + bool blocking, + bool start_of_burst, + bool end_of_burst) { return srslte_rf_send_timed3(rf, data, nsamples, 0, 0, false, blocking, start_of_burst, end_of_burst); } - -int srslte_rf_send_timed(srslte_rf_t *rf, - void *data, - int nsamples, - time_t secs, - double frac_secs) +int srslte_rf_send_timed(srslte_rf_t* rf, void* data, int nsamples, time_t secs, double frac_secs) { return srslte_rf_send_timed2(rf, data, nsamples, secs, frac_secs, true, true); } -int srslte_rf_send_timed2(srslte_rf_t *rf, - void *data, - int nsamples, - time_t secs, - double frac_secs, - bool is_start_of_burst, - bool is_end_of_burst) +int srslte_rf_send_timed2(srslte_rf_t* rf, + void* data, + int nsamples, + time_t secs, + double frac_secs, + bool is_start_of_burst, + bool is_end_of_burst) { return srslte_rf_send_timed3(rf, data, nsamples, secs, frac_secs, true, true, is_start_of_burst, is_end_of_burst); } diff --git a/lib/src/phy/rf/rf_soapy_imp.c b/lib/src/phy/rf/rf_soapy_imp.c index ddbee1550..8aebf8be9 100644 --- a/lib/src/phy/rf/rf_soapy_imp.c +++ b/lib/src/phy/rf/rf_soapy_imp.c @@ -19,19 +19,19 @@ * */ -#include +#include #include +#include #include -#include -#include "srslte/srslte.h" -#include "rf_soapy_imp.h" #include "rf_helper.h" +#include "rf_soapy_imp.h" +#include "srslte/srslte.h" #include #include -#include #include +#include #include #define HAVE_ASYNC_THREAD 1 @@ -43,24 +43,24 @@ #define PRINT_TX_STATS 0 typedef struct { - char *devname; - SoapySDRKwargs args; - SoapySDRDevice *device; - SoapySDRRange *ranges; - SoapySDRStream *rxStream; - SoapySDRStream *txStream; - bool tx_stream_active; - bool rx_stream_active; + char* devname; + SoapySDRKwargs args; + SoapySDRDevice* device; + SoapySDRRange* ranges; + SoapySDRStream* rxStream; + SoapySDRStream* txStream; + bool tx_stream_active; + bool rx_stream_active; srslte_rf_info_t info; - double tx_rate; + double tx_rate; double master_clock_rate; - size_t rx_mtu, tx_mtu; + size_t rx_mtu, tx_mtu; size_t num_rx_channels; size_t num_tx_channels; srslte_rf_error_handler_t soapy_error_handler; - bool async_thread_running; + bool async_thread_running; pthread_t async_thread; uint32_t num_time_errors; @@ -71,11 +71,10 @@ typedef struct { uint32_t num_stream_curruption; } rf_soapy_handler_t; +cf_t zero_mem[64 * 1024]; -cf_t zero_mem[64*1024]; - - -static void log_overflow(rf_soapy_handler_t *h) { +static void log_overflow(rf_soapy_handler_t* h) +{ if (h->soapy_error_handler) { srslte_rf_error_t error; bzero(&error, sizeof(srslte_rf_error_t)); @@ -86,11 +85,12 @@ static void log_overflow(rf_soapy_handler_t *h) { } } -static void log_late(rf_soapy_handler_t *h, bool is_rx) { +static void log_late(rf_soapy_handler_t* h, bool is_rx) +{ if (h->soapy_error_handler) { srslte_rf_error_t error; bzero(&error, sizeof(srslte_rf_error_t)); - error.opt = is_rx?1:0; + error.opt = is_rx ? 1 : 0; error.type = SRSLTE_RF_ERROR_LATE; h->soapy_error_handler(error); } else { @@ -98,7 +98,8 @@ static void log_late(rf_soapy_handler_t *h, bool is_rx) { } } -static void log_underflow(rf_soapy_handler_t *h) { +static void log_underflow(rf_soapy_handler_t* h) +{ if (h->soapy_error_handler) { srslte_rf_error_t error; bzero(&error, sizeof(srslte_rf_error_t)); @@ -109,17 +110,17 @@ static void log_underflow(rf_soapy_handler_t *h) { } } - #if HAVE_ASYNC_THREAD -static void* async_thread(void *h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; +static void* async_thread(void* h) +{ + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; - while(handler->async_thread_running) { - int ret = 0; - size_t chanMask = 0; - int flags = 0; + while (handler->async_thread_running) { + int ret = 0; + size_t chanMask = 0; + int flags = 0; const long timeoutUs = 400000; // arbitrarily chosen - long long timeNs; + long long timeNs; ret = SoapySDRDevice_readStreamStatus(handler->device, handler->txStream, &chanMask, &flags, &timeNs, timeoutUs); if (ret == SOAPY_SDR_TIME_ERROR) { @@ -149,72 +150,66 @@ static void* async_thread(void *h) { } #endif - -int soapy_error(void *h) +int soapy_error(void* h) { return 0; } - -void rf_soapy_get_freq_range(void *h) +void rf_soapy_get_freq_range(void* h) { // not supported } - -void rf_soapy_suppress_handler(const char *x) +void rf_soapy_suppress_handler(const char* x) { // not supported } - -void rf_soapy_msg_handler(const char *msg) +void rf_soapy_msg_handler(const char* msg) { // not supported } - -void rf_soapy_suppress_stdout(void *h) +void rf_soapy_suppress_stdout(void* h) { // not supported } - -void rf_soapy_register_error_handler(void *h, srslte_rf_error_handler_t new_handler) +void rf_soapy_register_error_handler(void* h, srslte_rf_error_handler_t new_handler) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; handler->soapy_error_handler = new_handler; } const char* rf_soapy_devname(void* h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; return handler->devname; } static bool rf_soapy_rx_wait_lo_locked(rf_soapy_handler_t* handler) { - char *ret = SoapySDRDevice_readChannelSensor(handler->device, SOAPY_SDR_RX, 0, "lo_locked"); + char* ret = SoapySDRDevice_readChannelSensor(handler->device, SOAPY_SDR_RX, 0, "lo_locked"); if (ret != NULL) { return (strcmp(ret, "true") == 0 ? true : false); } return true; } -void rf_soapy_calibrate_tx(void *h) +void rf_soapy_calibrate_tx(void* h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - double actual_bw = SoapySDRDevice_getBandwidth(handler->device, SOAPY_SDR_TX, 0); - char str_buf[25]; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; + double actual_bw = SoapySDRDevice_getBandwidth(handler->device, SOAPY_SDR_TX, 0); + char str_buf[25]; snprintf(str_buf, sizeof(str_buf), "%f", actual_bw); str_buf[24] = 0; SoapySDRDevice_writeSetting(handler->device, "CALIBRATE_TX", str_buf); } -int rf_soapy_start_rx_stream(void *h, bool now) +int rf_soapy_start_rx_stream(void* h, bool now) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if(handler->rx_stream_active == false){ + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; + if (handler->rx_stream_active == false) { if (SoapySDRDevice_activateStream(handler->device, handler->rxStream, 0, 0, 0) != 0) { printf("Error starting Rx streaming.\n"); return SRSLTE_ERROR; @@ -225,22 +220,20 @@ int rf_soapy_start_rx_stream(void *h, bool now) return SRSLTE_SUCCESS; } - -int rf_soapy_start_tx_stream(void *h) +int rf_soapy_start_tx_stream(void* h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if(handler->tx_stream_active == false){ - if(SoapySDRDevice_activateStream(handler->device, handler->txStream, 0, 0, 0) != 0) + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; + if (handler->tx_stream_active == false) { + if (SoapySDRDevice_activateStream(handler->device, handler->txStream, 0, 0, 0) != 0) return SRSLTE_ERROR; handler->tx_stream_active = true; } return SRSLTE_SUCCESS; } - -int rf_soapy_stop_rx_stream(void *h) +int rf_soapy_stop_rx_stream(void* h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; if (SoapySDRDevice_deactivateStream(handler->device, handler->rxStream, 0, 0) != 0) return SRSLTE_ERROR; @@ -248,38 +241,34 @@ int rf_soapy_stop_rx_stream(void *h) return SRSLTE_SUCCESS; } - -int rf_soapy_stop_tx_stream(void *h) +int rf_soapy_stop_tx_stream(void* h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if(SoapySDRDevice_deactivateStream(handler->device, handler->txStream, 0, 0) != 0) + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; + if (SoapySDRDevice_deactivateStream(handler->device, handler->txStream, 0, 0) != 0) return SRSLTE_ERROR; handler->tx_stream_active = false; return SRSLTE_SUCCESS; } - -void rf_soapy_flush_buffer(void *h) +void rf_soapy_flush_buffer(void* h) { - int n; - cf_t tmp1[1024]; - cf_t tmp2[1024]; - void *data[2] = {tmp1, tmp2}; + int n; + cf_t tmp1[1024]; + cf_t tmp2[1024]; + void* data[2] = {tmp1, tmp2}; do { n = rf_soapy_recv_with_time_multi(h, data, 1024, 0, NULL, NULL); } while (n > 0); } - -bool rf_soapy_has_rssi(void *h) +bool rf_soapy_has_rssi(void* h) { // TODO: implement rf_soapy_has_rssi() return false; } - -float rf_soapy_get_rssi(void *h) +float rf_soapy_get_rssi(void* h) { printf("TODO: implement rf_soapy_get_rssi()\n"); return 0.0; @@ -287,7 +276,7 @@ float rf_soapy_get_rssi(void *h) int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) { - size_t length; + size_t length; SoapySDRKwargs* soapy_args = SoapySDRDevice_enumerate(NULL, &length); if (length == 0) { @@ -300,16 +289,16 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) printf("Soapy has found device #%d: ", (int)i); for (size_t j = 0; j < soapy_args[i].size; j++) { printf("%s=%s, ", soapy_args[i].keys[j], soapy_args[i].vals[j]); - if(!strcmp(soapy_args[i].keys[j],"name") && !strcmp(soapy_args[i].vals[j], "LimeSDR-USB")){ + if (!strcmp(soapy_args[i].keys[j], "name") && !strcmp(soapy_args[i].vals[j], "LimeSDR-USB")) { devname = DEVNAME_LIME; - } else if (!strcmp(soapy_args[i].keys[j],"name") && !strcmp(soapy_args[i].vals[j], "LimeSDR Mini")){ + } else if (!strcmp(soapy_args[i].keys[j], "name") && !strcmp(soapy_args[i].vals[j], "LimeSDR Mini")) { devname = DEVNAME_LIME_MINI; } } printf("\n"); } - SoapySDRDevice *sdr = SoapySDRDevice_make(&(soapy_args[0])); + SoapySDRDevice* sdr = SoapySDRDevice_make(&(soapy_args[0])); if (sdr == NULL) { printf("Failed to create Soapy object\n"); return SRSLTE_ERROR; @@ -317,13 +306,13 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) SoapySDRKwargsList_clear(soapy_args, length); // create handler - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) malloc(sizeof(rf_soapy_handler_t)); + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)malloc(sizeof(rf_soapy_handler_t)); bzero(handler, sizeof(rf_soapy_handler_t)); - *h = handler; - handler->device = sdr; + *h = handler; + handler->device = sdr; handler->tx_stream_active = false; handler->rx_stream_active = false; - handler->devname = devname; + handler->devname = devname; // Setup Rx streamer size_t num_available_channels = SoapySDRDevice_getNumChannels(handler->device, SOAPY_SDR_RX); @@ -334,8 +323,13 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) rx_channels[i] = i; } printf("Setting up Rx stream with %zd channel(s)\n", handler->num_rx_channels); - if (SoapySDRDevice_setupStream(handler->device, &handler->rxStream, SOAPY_SDR_RX, SOAPY_SDR_CF32, rx_channels, - handler->num_rx_channels, NULL) != 0) { + if (SoapySDRDevice_setupStream(handler->device, + &handler->rxStream, + SOAPY_SDR_RX, + SOAPY_SDR_CF32, + rx_channels, + handler->num_rx_channels, + NULL) != 0) { printf("Rx setupStream fail: %s\n", SoapySDRDevice_lastError()); return SRSLTE_ERROR; } @@ -351,8 +345,13 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) tx_channels[i] = i; } printf("Setting up Tx stream with %zd channel(s)\n", handler->num_tx_channels); - if (SoapySDRDevice_setupStream(handler->device, &handler->txStream, SOAPY_SDR_TX, SOAPY_SDR_CF32, tx_channels, - handler->num_tx_channels, NULL) != 0) { + if (SoapySDRDevice_setupStream(handler->device, + &handler->txStream, + SOAPY_SDR_TX, + SOAPY_SDR_CF32, + tx_channels, + handler->num_tx_channels, + NULL) != 0) { printf("Tx setupStream fail: %s\n", SoapySDRDevice_lastError()); return SRSLTE_ERROR; } @@ -368,7 +367,7 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) char** list; list = SoapySDRDevice_listSensors(handler->device, &list_length); printf("Available device sensors: \n"); - for(int i = 0; i < list_length; i++) { + for (int i = 0; i < list_length; i++) { printf(" - %s\n", list[i]); } @@ -382,8 +381,8 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) } // Set static radio info - SoapySDRRange tx_range = SoapySDRDevice_getGainRange(handler->device, SOAPY_SDR_TX, 0); - SoapySDRRange rx_range = SoapySDRDevice_getGainRange(handler->device, SOAPY_SDR_RX, 0); + SoapySDRRange tx_range = SoapySDRDevice_getGainRange(handler->device, SOAPY_SDR_TX, 0); + SoapySDRRange rx_range = SoapySDRDevice_getGainRange(handler->device, SOAPY_SDR_RX, 0); handler->info.min_tx_gain = tx_range.minimum; handler->info.max_tx_gain = tx_range.maximum; handler->info.min_rx_gain = rx_range.minimum; @@ -392,9 +391,9 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) // Check device arguments if (args) { // config file - const char config_arg[] = "config="; - char config_str[64] = {0}; - char *config_ptr = strstr(args, config_arg); + const char config_arg[] = "config="; + char config_str[64] = {0}; + char* config_ptr = strstr(args, config_arg); if (config_ptr) { copy_subdev_string(config_str, config_ptr + strlen(config_arg)); printf("Loading config file %s\n", config_str); @@ -404,8 +403,8 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) } // rx antenna - const char rx_ant_arg[] = "rxant="; - char rx_ant_str[64] = {0}; + const char rx_ant_arg[] = "rxant="; + char rx_ant_str[64] = {0}; char* rx_ant_ptr = strstr(args, rx_ant_arg); if (rx_ant_ptr) { copy_subdev_string(rx_ant_str, rx_ant_ptr + strlen(rx_ant_arg)); @@ -418,8 +417,8 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) } // tx antenna - const char tx_ant_arg[] = "txant="; - char tx_ant_str[64] = {0}; + const char tx_ant_arg[] = "txant="; + char tx_ant_str[64] = {0}; char* tx_ant_ptr = strstr(args, tx_ant_arg); if (tx_ant_ptr) { copy_subdev_string(tx_ant_str, tx_ant_ptr + strlen(tx_ant_arg)); @@ -432,9 +431,9 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) } // log level - const char loglevel_arg[] = "loglevel="; - char loglevel_str[64] = {0}; - char *loglevel_ptr = strstr(args, loglevel_arg); + const char loglevel_arg[] = "loglevel="; + char loglevel_str[64] = {0}; + char* loglevel_ptr = strstr(args, loglevel_arg); if (loglevel_ptr) { copy_subdev_string(loglevel_str, loglevel_ptr + strlen(loglevel_arg)); if (strcmp(loglevel_str, "error") == 0) { @@ -461,8 +460,8 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) rf_soapy_set_tx_gain(handler, 45); rf_soapy_set_rx_gain(handler, 35); - cf_t dummy_buffer[1920]; - cf_t *dummy_buffer_array[SRSLTE_MAX_PORTS]; + cf_t dummy_buffer[1920]; + cf_t* dummy_buffer_array[SRSLTE_MAX_PORTS]; for (int i = 0; i < SRSLTE_MAX_PORTS; i++) { dummy_buffer_array[i] = dummy_buffer; } @@ -475,21 +474,21 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) // list gains and AGC mode bool has_agc = SoapySDRDevice_hasGainMode(handler->device, SOAPY_SDR_RX, 0); - list = SoapySDRDevice_listGains(handler->device, SOAPY_SDR_RX, 0, &list_length); - printf("State of gain elements for Rx channel 0 (AGC %s):\n", has_agc ? "supported":"not supported"); - for(int i = 0; i < list_length; i++) { + list = SoapySDRDevice_listGains(handler->device, SOAPY_SDR_RX, 0, &list_length); + printf("State of gain elements for Rx channel 0 (AGC %s):\n", has_agc ? "supported" : "not supported"); + for (int i = 0; i < list_length; i++) { printf(" - %s: %.2f dB\n", list[i], SoapySDRDevice_getGainElement(handler->device, SOAPY_SDR_RX, 0, list[i])); } has_agc = SoapySDRDevice_hasGainMode(handler->device, SOAPY_SDR_TX, 0); list = SoapySDRDevice_listGains(handler->device, SOAPY_SDR_TX, 0, &list_length); - printf("State of gain elements for Tx channel 0 (AGC %s):\n", has_agc ? "supported":"not supported"); - for(int i = 0; i < list_length; i++) { + printf("State of gain elements for Tx channel 0 (AGC %s):\n", has_agc ? "supported" : "not supported"); + for (int i = 0; i < list_length; i++) { printf(" - %s: %.2f dB\n", list[i], SoapySDRDevice_getGainElement(handler->device, SOAPY_SDR_TX, 0, list[i])); } // print actual antenna configuration - char *ant = SoapySDRDevice_getAntenna(handler->device, SOAPY_SDR_RX, 0); + char* ant = SoapySDRDevice_getAntenna(handler->device, SOAPY_SDR_RX, 0); printf("Rx antenna set to %s\n", ant); ant = SoapySDRDevice_getAntenna(handler->device, SOAPY_SDR_TX, 0); @@ -509,16 +508,14 @@ int rf_soapy_open_multi(char* args, void** h, uint32_t num_requested_channels) return SRSLTE_SUCCESS; } - -int rf_soapy_open(char *args, void **h) +int rf_soapy_open(char* args, void** h) { return rf_soapy_open_multi(args, h, 1); } - -int rf_soapy_close(void *h) +int rf_soapy_close(void* h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; #if HAVE_ASYNC_THREAD if (handler->async_thread_running) { @@ -540,20 +537,25 @@ int rf_soapy_close(void *h) SoapySDRDevice_unmake(handler->device); // print statistics - if (handler->num_lates) printf("#lates=%d\n", handler->num_lates); - if (handler->num_overflows) printf("#overflows=%d\n", handler->num_overflows); - if (handler->num_underflows) printf("#underflows=%d\n", handler->num_underflows); - if (handler->num_time_errors) printf("#time_errors=%d\n", handler->num_time_errors); - if (handler->num_other_errors) printf("#other_errors=%d\n", handler->num_other_errors); + if (handler->num_lates) + printf("#lates=%d\n", handler->num_lates); + if (handler->num_overflows) + printf("#overflows=%d\n", handler->num_overflows); + if (handler->num_underflows) + printf("#underflows=%d\n", handler->num_underflows); + if (handler->num_time_errors) + printf("#time_errors=%d\n", handler->num_time_errors); + if (handler->num_other_errors) + printf("#other_errors=%d\n", handler->num_other_errors); free(handler); return SRSLTE_SUCCESS; } -double rf_soapy_set_rx_srate(void *h, double rate) +double rf_soapy_set_rx_srate(void* h, double rate) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; // Restart streaming, as the Lime seems to have problems reconfiguring the sample rate during streaming bool rx_stream_active = handler->rx_stream_active; @@ -593,9 +595,9 @@ double rf_soapy_set_rx_srate(void *h, double rate) return SoapySDRDevice_getSampleRate(handler->device, SOAPY_SDR_RX, 0); } -double rf_soapy_set_tx_srate(void *h, double rate) +double rf_soapy_set_tx_srate(void* h, double rate) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; // stop/start streaming during rate reconfiguration bool rx_stream_active = handler->rx_stream_active; @@ -635,10 +637,9 @@ double rf_soapy_set_tx_srate(void *h, double rate) return handler->tx_rate; } - -double rf_soapy_set_rx_gain(void *h, double gain) +double rf_soapy_set_rx_gain(void* h, double gain) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; for (uint32_t i = 0; i < handler->num_rx_channels; i++) { if (SoapySDRDevice_setGain(handler->device, SOAPY_SDR_RX, i, gain) != 0) { @@ -649,10 +650,9 @@ double rf_soapy_set_rx_gain(void *h, double gain) return rf_soapy_get_rx_gain(h); } - -double rf_soapy_set_tx_gain(void *h, double gain) +double rf_soapy_set_tx_gain(void* h, double gain) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; for (uint32_t i = 0; i < handler->num_tx_channels; i++) { if (SoapySDRDevice_setGain(handler->device, SOAPY_SDR_TX, i, gain) != 0) { printf("setGain fail: %s\n", SoapySDRDevice_lastError()); @@ -663,25 +663,24 @@ double rf_soapy_set_tx_gain(void *h, double gain) } // Return gain of first channel -double rf_soapy_get_rx_gain(void *h) +double rf_soapy_get_rx_gain(void* h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; return SoapySDRDevice_getGain(handler->device, SOAPY_SDR_RX, 0); } // Return gain of first channel -double rf_soapy_get_tx_gain(void *h) +double rf_soapy_get_tx_gain(void* h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; return SoapySDRDevice_getGain(handler->device, SOAPY_SDR_TX, 0); } - -srslte_rf_info_t * rf_soapy_get_info(void *h) +srslte_rf_info_t* rf_soapy_get_info(void* h) { - srslte_rf_info_t *info = NULL; + srslte_rf_info_t* info = NULL; if (h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; info = &handler->info; } return info; @@ -689,7 +688,7 @@ srslte_rf_info_t * rf_soapy_get_info(void *h) double rf_soapy_set_rx_freq(void* h, uint32_t ch, double freq) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; for (uint32_t i = 0; i < handler->num_rx_channels; i++) { if (SoapySDRDevice_setFrequency(handler->device, SOAPY_SDR_RX, i, freq, NULL) != 0) { @@ -707,7 +706,7 @@ double rf_soapy_set_rx_freq(void* h, uint32_t ch, double freq) double rf_soapy_set_tx_freq(void* h, uint32_t ch, double freq) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; for (uint32_t i = 0; i < handler->num_tx_channels; i++) { if (SoapySDRDevice_setFrequency(handler->device, SOAPY_SDR_TX, i, freq, NULL) != 0) { printf("setFrequency fail: %s\n", SoapySDRDevice_lastError()); @@ -717,29 +716,27 @@ double rf_soapy_set_tx_freq(void* h, uint32_t ch, double freq) return SoapySDRDevice_getFrequency(handler->device, SOAPY_SDR_TX, 0); } - -void rf_soapy_get_time(void *h, time_t *secs, double *frac_secs) +void rf_soapy_get_time(void* h, time_t* secs, double* frac_secs) { printf("Todo: implement rf_soapy_get_time()\n"); } - -//TODO: add multi-channel support -int rf_soapy_recv_with_time_multi(void *h, - void *data[SRSLTE_MAX_PORTS], - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs) +// TODO: add multi-channel support +int rf_soapy_recv_with_time_multi(void* h, + void* data[SRSLTE_MAX_PORTS], + uint32_t nsamples, + bool blocking, + time_t* secs, + double* frac_secs) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; int flags = 0; // flags set by receive operation - const long timeoutUs = 400000; // arbitrarily chosen + const long timeoutUs = 400000; // arbitrarily chosen - int trials = 0; - int ret = 0; - long long timeNs; //timestamp for receive buffer - int n = 0; + int trials = 0; + int ret = 0; + long long timeNs; // timestamp for receive buffer + int n = 0; #if PRINT_RX_STATS printf("rx: nsamples=%d rx_mtu=%zd\n", nsamples, handler->rx_mtu); @@ -753,11 +750,12 @@ int rf_soapy_recv_with_time_multi(void *h, void* buffs_ptr[SRSLTE_MAX_PORTS] = {}; for (int i = 0; i < handler->num_rx_channels; i++) { - cf_t *data_c = (cf_t*) data[i]; + cf_t* data_c = (cf_t*)data[i]; buffs_ptr[i] = &data_c[n]; } - ret = SoapySDRDevice_readStream(handler->device, handler->rxStream, buffs_ptr, rx_samples, &flags, &timeNs, timeoutUs); + ret = SoapySDRDevice_readStream( + handler->device, handler->rxStream, buffs_ptr, rx_samples, &flags, &timeNs, timeoutUs); if (ret == SOAPY_SDR_OVERFLOW || (ret > 0 && (flags & SOAPY_SDR_END_ABRUPT) != 0)) { log_overflow(handler); continue; @@ -774,7 +772,7 @@ int rf_soapy_recv_with_time_multi(void *h, if (secs != NULL && frac_secs != NULL && n == 0) { *secs = floor(timeNs / 1e9); *frac_secs = (timeNs % 1000000000) / 1e9; - //printf("rx_time: secs=%lld, frac_secs=%lf timeNs=%llu\n", *secs, *frac_secs, timeNs); + // printf("rx_time: secs=%lld, frac_secs=%lf timeNs=%llu\n", *secs, *frac_secs, timeNs); } #if PRINT_RX_STATS @@ -788,13 +786,7 @@ int rf_soapy_recv_with_time_multi(void *h, return n; } - -int rf_soapy_recv_with_time(void *h, - void *data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs) +int rf_soapy_recv_with_time(void* h, void* data, uint32_t nsamples, bool blocking, time_t* secs, double* frac_secs) { return rf_soapy_recv_with_time_multi(h, &data, nsamples, blocking, secs, frac_secs); } @@ -809,11 +801,11 @@ int rf_soapy_send_timed(void* h, bool is_start_of_burst, bool is_end_of_burst) { - void *_data[SRSLTE_MAX_PORTS]= {data, zero_mem, zero_mem, zero_mem}; - return rf_soapy_send_timed_multi(h, _data, nsamples, secs, frac_secs, has_time_spec, blocking, is_start_of_burst, is_end_of_burst); + void* _data[SRSLTE_MAX_PORTS] = {data, zero_mem, zero_mem, zero_mem}; + return rf_soapy_send_timed_multi( + h, _data, nsamples, secs, frac_secs, has_time_spec, blocking, is_start_of_burst, is_end_of_burst); } - // Todo: Check correct handling of flags, use RF metrics API, fix timed transmissions int rf_soapy_send_timed_multi(void* h, void* data[SRSLTE_MAX_PORTS], @@ -825,13 +817,13 @@ int rf_soapy_send_timed_multi(void* h, bool is_start_of_burst, bool is_end_of_burst) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t *) h; - int flags = 0; - const long timeoutUs = 100000; // arbitrarily chosen - long long timeNs = 0; - int trials = 0; - int ret = 0; - int n = 0; + rf_soapy_handler_t* handler = (rf_soapy_handler_t*)h; + int flags = 0; + const long timeoutUs = 100000; // arbitrarily chosen + long long timeNs = 0; + int trials = 0; + int ret = 0; + int n = 0; #if PRINT_TX_STATS printf("tx: namples=%d, mtu=%zd\n", nsamples, handler->tx_mtu); @@ -868,7 +860,7 @@ int rf_soapy_send_timed_multi(void* h, } // only set time flag for first tx - if(has_time_spec && n == 0) { + if (has_time_spec && n == 0) { flags |= SOAPY_SDR_HAS_TIME; } @@ -882,8 +874,8 @@ int rf_soapy_send_timed_multi(void* h, buffs_ptr[i] = &data_c[n]; } - ret = SoapySDRDevice_writeStream(handler->device, handler->txStream, buffs_ptr, tx_samples, &flags, timeNs, - timeoutUs); + ret = SoapySDRDevice_writeStream( + handler->device, handler->txStream, buffs_ptr, tx_samples, &flags, timeNs, timeoutUs); if (ret >= 0) { // Tx was ok #if PRINT_TX_STATS @@ -893,7 +885,11 @@ int rf_soapy_send_timed_multi(void* h, if (has_time_spec && ret < nsamples) { long long adv = SoapySDR_ticksToTimeNs(ret, handler->tx_rate); #if PRINT_TX_STATS - printf(" - tx: timeNs_old=%llu, adv=%llu, timeNs_new=%llu, tx_rate=%f\n", timeNs, adv, timeNs+adv, handler->tx_rate); + printf(" - tx: timeNs_old=%llu, adv=%llu, timeNs_new=%llu, tx_rate=%f\n", + timeNs, + adv, + timeNs + adv, + handler->tx_rate); #endif timeNs += adv; } diff --git a/lib/src/phy/rf/rf_soapy_imp.h b/lib/src/phy/rf/rf_soapy_imp.h index d90ed6a56..453b10e5f 100644 --- a/lib/src/phy/rf/rf_soapy_imp.h +++ b/lib/src/phy/rf/rf_soapy_imp.h @@ -19,32 +19,31 @@ * */ -#include -#include #include "srslte/config.h" #include "srslte/phy/rf/rf.h" +#include +#include #define DEVNAME_NONE "none" #define DEVNAME_LIME "lime" #define DEVNAME_LIME_MINI "lime_mini" -SRSLTE_API int rf_soapy_open(char *args, - void **handler); +SRSLTE_API int rf_soapy_open(char* args, void** handler); SRSLTE_API int rf_soapy_open_multi(char* args, void** handler, uint32_t num_requested_channels); SRSLTE_API const char* rf_soapy_devname(void* h); -SRSLTE_API int rf_soapy_close(void *h); +SRSLTE_API int rf_soapy_close(void* h); -SRSLTE_API int rf_soapy_start_rx_stream(void *h, bool now); +SRSLTE_API int rf_soapy_start_rx_stream(void* h, bool now); -SRSLTE_API int rf_soapy_stop_rx_stream(void *h); +SRSLTE_API int rf_soapy_stop_rx_stream(void* h); -SRSLTE_API void rf_soapy_calibrate_tx(void *h); +SRSLTE_API void rf_soapy_calibrate_tx(void* h); -SRSLTE_API void rf_soapy_flush_buffer(void *h); +SRSLTE_API void rf_soapy_flush_buffer(void* h); -SRSLTE_API bool rf_soapy_has_rssi(void *h); +SRSLTE_API bool rf_soapy_has_rssi(void* h); SRSLTE_API float rf_soapy_get_rssi(void* h); @@ -52,63 +51,50 @@ SRSLTE_API void rf_soapy_set_master_clock_rate(void* h, double rate); SRSLTE_API double rf_soapy_set_rx_srate(void* h, double freq); -SRSLTE_API double rf_soapy_set_rx_gain(void *h, - double gain); +SRSLTE_API double rf_soapy_set_rx_gain(void* h, double gain); -SRSLTE_API double rf_soapy_get_rx_gain(void *h); +SRSLTE_API double rf_soapy_get_rx_gain(void* h); -SRSLTE_API double rf_soapy_set_tx_gain(void *h, - double gain); +SRSLTE_API double rf_soapy_set_tx_gain(void* h, double gain); -SRSLTE_API double rf_soapy_get_tx_gain(void *h); +SRSLTE_API double rf_soapy_get_tx_gain(void* h); -SRSLTE_API srslte_rf_info_t *rf_soapy_get_info(void *h); +SRSLTE_API srslte_rf_info_t* rf_soapy_get_info(void* h); -SRSLTE_API void rf_soapy_suppress_stdout(void *h); +SRSLTE_API void rf_soapy_suppress_stdout(void* h); -SRSLTE_API void rf_soapy_register_error_handler(void *h, srslte_rf_error_handler_t error_handler); +SRSLTE_API void rf_soapy_register_error_handler(void* h, srslte_rf_error_handler_t error_handler); SRSLTE_API double rf_soapy_set_rx_freq(void* h, uint32_t ch, double freq); -SRSLTE_API int rf_soapy_recv_with_time(void *h, - void *data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs); +SRSLTE_API int +rf_soapy_recv_with_time(void* h, void* data, uint32_t nsamples, bool blocking, time_t* secs, double* frac_secs); -SRSLTE_API int rf_soapy_recv_with_time_multi(void *h, - void **data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs); +SRSLTE_API int +rf_soapy_recv_with_time_multi(void* h, void** data, uint32_t nsamples, bool blocking, time_t* secs, double* frac_secs); -SRSLTE_API double rf_soapy_set_tx_srate(void *h, - double freq); +SRSLTE_API double rf_soapy_set_tx_srate(void* h, double freq); SRSLTE_API double rf_soapy_set_tx_freq(void* h, uint32_t ch, double freq); -SRSLTE_API void rf_soapy_get_time(void *h, - time_t *secs, - double *frac_secs); - -SRSLTE_API int rf_soapy_send_timed(void *h, - void *data, - int nsamples, - time_t secs, - double frac_secs, - bool has_time_spec, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst); - -int rf_soapy_send_timed_multi(void *h, - void *data[4], - int nsamples, +SRSLTE_API void rf_soapy_get_time(void* h, time_t* secs, double* frac_secs); + +SRSLTE_API int rf_soapy_send_timed(void* h, + void* data, + int nsamples, + time_t secs, + double frac_secs, + bool has_time_spec, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst); + +int rf_soapy_send_timed_multi(void* h, + void* data[4], + int nsamples, time_t secs, double frac_secs, - bool has_time_spec, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst); + bool has_time_spec, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst); diff --git a/lib/src/phy/rf/rf_uhd_imp.c b/lib/src/phy/rf/rf_uhd_imp.c index e5633e6bd..1ddf9a5a3 100644 --- a/lib/src/phy/rf/rf_uhd_imp.c +++ b/lib/src/phy/rf/rf_uhd_imp.c @@ -845,8 +845,12 @@ int rf_uhd_recv_with_time(void* h, void* data, uint32_t nsamples, bool blocking, return rf_uhd_recv_with_time_multi(h, &data, nsamples, blocking, secs, frac_secs); } -int rf_uhd_recv_with_time_multi( - void* h, void* data[SRSLTE_MAX_PORTS], uint32_t nsamples, bool blocking, time_t* secs, double* frac_secs) +int rf_uhd_recv_with_time_multi(void* h, + void* data[SRSLTE_MAX_PORTS], + uint32_t nsamples, + bool blocking, + time_t* secs, + double* frac_secs) { rf_uhd_handler_t* handler = (rf_uhd_handler_t*)h; uhd_rx_metadata_handle* md = &handler->rx_md_first; diff --git a/lib/src/phy/rf/rf_uhd_imp.h b/lib/src/phy/rf/rf_uhd_imp.h index 49c85ea13..d71dd6ee7 100644 --- a/lib/src/phy/rf/rf_uhd_imp.h +++ b/lib/src/phy/rf/rf_uhd_imp.h @@ -21,8 +21,9 @@ #include #include - + #include "srslte/config.h" +#include "srslte/phy/common/phy_common.h" #include "srslte/phy/rf/rf.h" #define DEVNAME_B200 "uhd_b200" @@ -30,68 +31,51 @@ #define DEVNAME_N300 "uhd_n300" #define DEVNAME_E3X0 "uhd_e3x0" +SRSLTE_API int rf_uhd_open(char* args, void** handler); -SRSLTE_API int rf_uhd_open(char *args, - void **handler); - -SRSLTE_API int rf_uhd_open_multi(char *args, - void **handler, - uint32_t nof_channels); +SRSLTE_API int rf_uhd_open_multi(char* args, void** handler, uint32_t nof_channels); SRSLTE_API const char* rf_uhd_devname(void* h); -SRSLTE_API int rf_uhd_close(void *h); +SRSLTE_API int rf_uhd_close(void* h); -SRSLTE_API int rf_uhd_start_rx_stream(void *h, - bool now); +SRSLTE_API int rf_uhd_start_rx_stream(void* h, bool now); -SRSLTE_API int rf_uhd_start_rx_stream_nsamples(void *h, - uint32_t nsamples); +SRSLTE_API int rf_uhd_start_rx_stream_nsamples(void* h, uint32_t nsamples); -SRSLTE_API int rf_uhd_stop_rx_stream(void *h); +SRSLTE_API int rf_uhd_stop_rx_stream(void* h); -SRSLTE_API void rf_uhd_flush_buffer(void *h); +SRSLTE_API void rf_uhd_flush_buffer(void* h); -SRSLTE_API bool rf_uhd_has_rssi(void *h); +SRSLTE_API bool rf_uhd_has_rssi(void* h); SRSLTE_API float rf_uhd_get_rssi(void* h); SRSLTE_API double rf_uhd_set_rx_srate(void* h, double freq); -SRSLTE_API double rf_uhd_set_rx_gain(void *h, - double gain); +SRSLTE_API double rf_uhd_set_rx_gain(void* h, double gain); -SRSLTE_API double rf_uhd_get_rx_gain(void *h); +SRSLTE_API double rf_uhd_get_rx_gain(void* h); -SRSLTE_API double rf_uhd_get_tx_gain(void *h); +SRSLTE_API double rf_uhd_get_tx_gain(void* h); -SRSLTE_API srslte_rf_info_t *rf_uhd_get_info(void *h); +SRSLTE_API srslte_rf_info_t* rf_uhd_get_info(void* h); -SRSLTE_API void rf_uhd_suppress_stdout(void *h); +SRSLTE_API void rf_uhd_suppress_stdout(void* h); -SRSLTE_API void rf_uhd_register_error_handler(void *h, srslte_rf_error_handler_t error_handler); +SRSLTE_API void rf_uhd_register_error_handler(void* h, srslte_rf_error_handler_t error_handler); SRSLTE_API double rf_uhd_set_rx_freq(void* h, uint32_t ch, double freq); -SRSLTE_API int rf_uhd_recv_with_time(void *h, - void *data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs); +SRSLTE_API int +rf_uhd_recv_with_time(void* h, void* data, uint32_t nsamples, bool blocking, time_t* secs, double* frac_secs); -SRSLTE_API int rf_uhd_recv_with_time_multi(void *h, - void **data, - uint32_t nsamples, - bool blocking, - time_t *secs, - double *frac_secs); +SRSLTE_API int +rf_uhd_recv_with_time_multi(void* h, void** data, uint32_t nsamples, bool blocking, time_t* secs, double* frac_secs); -SRSLTE_API double rf_uhd_set_tx_srate(void *h, - double freq); +SRSLTE_API double rf_uhd_set_tx_srate(void* h, double freq); -SRSLTE_API double rf_uhd_set_tx_gain(void *h, - double gain); +SRSLTE_API double rf_uhd_set_tx_gain(void* h, double gain); SRSLTE_API double rf_uhd_set_tx_freq(void* h, uint32_t ch, double freq); @@ -99,23 +83,22 @@ SRSLTE_API void rf_uhd_get_time(void* h, time_t* secs, double* frac_secs); SRSLTE_API void rf_uhd_sync_pps(void* h); -SRSLTE_API int rf_uhd_send_timed(void *h, - void *data, - int nsamples, - time_t secs, - double frac_secs, - bool has_time_spec, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst); - -SRSLTE_API int rf_uhd_send_timed_multi(void *h, - void *data[SRSLTE_MAX_PORTS], - int nsamples, +SRSLTE_API int rf_uhd_send_timed(void* h, + void* data, + int nsamples, + time_t secs, + double frac_secs, + bool has_time_spec, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst); + +SRSLTE_API int rf_uhd_send_timed_multi(void* h, + void* data[SRSLTE_MAX_PORTS], + int nsamples, time_t secs, double frac_secs, - bool has_time_spec, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst); - + bool has_time_spec, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst); diff --git a/lib/src/phy/rf/rf_utils.c b/lib/src/phy/rf/rf_utils.c index f3b6f33ba..6f8178635 100644 --- a/lib/src/phy/rf/rf_utils.c +++ b/lib/src/phy/rf/rf_utils.c @@ -19,13 +19,13 @@ * */ +#include #include #include #include #include -#include -#include #include +#include #include @@ -34,10 +34,11 @@ #include "srslte/phy/rf/rf.h" #include "srslte/phy/rf/rf_utils.h" -int rf_rssi_scan(srslte_rf_t *rf, float *freqs, float *rssi, int nof_bands, double fs, int nsamp) { - int i, j; - int ret = -1; - cf_t *buffer; +int rf_rssi_scan(srslte_rf_t* rf, float* freqs, float* rssi, int nof_bands, double fs, int nsamp) +{ + int i, j; + int ret = -1; + cf_t* buffer; double f; buffer = calloc(nsamp, sizeof(cf_t)); @@ -48,16 +49,16 @@ int rf_rssi_scan(srslte_rf_t *rf, float *freqs, float *rssi, int nof_bands, doub srslte_rf_set_rx_gain(rf, 20.0); srslte_rf_set_rx_srate(rf, fs); - for (i=0;imax_frames_pbch, bch_payload, &cell->nof_ports, NULL); + ret = srslte_ue_mib_sync_decode(&ue_mib, config->max_frames_pbch, bch_payload, &cell->nof_ports, NULL); if (ret < 0) { ERROR("Error decoding MIB\n"); - goto clean_exit; + goto clean_exit; } if (ret == 1) { srslte_pbch_mib_unpack(bch_payload, cell, NULL); } - - // Save CFO + + // Save CFO if (cfo) { *cfo = srslte_ue_sync_get_cfo(&ue_mib.ue_sync); } - -clean_exit: + +clean_exit: srslte_rf_stop_rx_stream(rf); srslte_ue_mib_sync_free(&ue_mib); - return ret; + return ret; } -/** This function is simply a wrapper to the ue_cell_search module for rf devices +/** This function is simply a wrapper to the ue_cell_search module for rf devices */ -int rf_cell_search(srslte_rf_t *rf, uint32_t nof_rx_antennas, - cell_search_cfg_t *config, - int force_N_id_2, srslte_cell_t *cell, float *cfo) +int rf_cell_search(srslte_rf_t* rf, + uint32_t nof_rx_antennas, + cell_search_cfg_t* config, + int force_N_id_2, + srslte_cell_t* cell, + float* cfo) { - int ret = SRSLTE_ERROR; - srslte_ue_cellsearch_t cs; + int ret = SRSLTE_ERROR; + srslte_ue_cellsearch_t cs; srslte_ue_cellsearch_result_t found_cells[3]; - bzero(found_cells, 3*sizeof(srslte_ue_cellsearch_result_t)); + bzero(found_cells, 3 * sizeof(srslte_ue_cellsearch_result_t)); if (srslte_ue_cellsearch_init_multi( &cs, config->max_frames_pss, srslte_rf_recv_wrapper_cs, nof_rx_antennas, (void*)rf)) { fprintf(stderr, "Error initiating UE cell detect\n"); - return SRSLTE_ERROR; + return SRSLTE_ERROR; } if (config->nof_valid_pss_frames) { srslte_ue_cellsearch_set_nof_valid_frames(&cs, config->nof_valid_pss_frames); } - INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ/1000000); + INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ / 1000000); srslte_rf_set_rx_srate(rf, SRSLTE_CS_SAMP_FREQ); - + INFO("Starting receiver...\n"); srslte_rf_start_rx_stream(rf, false); @@ -179,10 +190,10 @@ int rf_cell_search(srslte_rf_t *rf, uint32_t nof_rx_antennas, /* Find a cell in the given N_id_2 or go through the 3 of them to find the strongest */ uint32_t max_peak_cell = 0; if (force_N_id_2 >= 0) { - ret = srslte_ue_cellsearch_scan_N_id_2(&cs, force_N_id_2, &found_cells[force_N_id_2]); + ret = srslte_ue_cellsearch_scan_N_id_2(&cs, force_N_id_2, &found_cells[force_N_id_2]); max_peak_cell = force_N_id_2; } else { - ret = srslte_ue_cellsearch_scan(&cs, found_cells, &max_peak_cell); + ret = srslte_ue_cellsearch_scan(&cs, found_cells, &max_peak_cell); } srslte_rf_stop_rx_stream(rf); @@ -194,8 +205,8 @@ int rf_cell_search(srslte_rf_t *rf, uint32_t nof_rx_antennas, ERROR("Could not find any cell in this frequency\n"); return SRSLTE_SUCCESS; } - - for (int i=0;i<3;i++) { + + for (int i = 0; i < 3; i++) { if (i == max_peak_cell) { printf("*"); } else { @@ -212,7 +223,7 @@ int rf_cell_search(srslte_rf_t *rf, uint32_t nof_rx_antennas, // Save result if (cell) { - cell->id = found_cells[max_peak_cell].cell_id; + cell->id = found_cells[max_peak_cell].cell_id; cell->cp = found_cells[max_peak_cell].cp; cell->frame_type = found_cells[max_peak_cell].frame_type; } @@ -221,10 +232,10 @@ int rf_cell_search(srslte_rf_t *rf, uint32_t nof_rx_antennas, if (cfo) { *cfo = found_cells[max_peak_cell].cfo; } - + srslte_ue_cellsearch_free(&cs); - return ret; + return ret; } /* Finds a cell and decodes MIB from the PBCH. @@ -244,13 +255,12 @@ int rf_search_and_decode_mib(srslte_rf_t* rf, printf("Searching for cell...\n"); ret = rf_cell_search(rf, nof_rx_antennas, config, force_N_id_2, cell, cfo); if (ret > 0) { - printf("Decoding PBCH for cell %d (N_id_2=%d)\n", cell->id, cell->id%3); + printf("Decoding PBCH for cell %d (N_id_2=%d)\n", cell->id, cell->id % 3); ret = rf_mib_decoder(rf, nof_rx_antennas, config, cell, cfo); if (ret < 0) { ERROR("Could not decode PBCH from CELL ID %d\n", cell->id); return SRSLTE_ERROR; - } + } } return ret; } - diff --git a/lib/src/phy/rf/rf_zmq_imp.c b/lib/src/phy/rf/rf_zmq_imp.c index 2721f2974..18a795a89 100644 --- a/lib/src/phy/rf/rf_zmq_imp.c +++ b/lib/src/phy/rf/rf_zmq_imp.c @@ -47,7 +47,7 @@ typedef struct { bool tx_used; // Server - void* context; + void* context; rf_zmq_tx_t transmitter[SRSLTE_MAX_PORTS]; rf_zmq_rx_t receiver[SRSLTE_MAX_PORTS]; @@ -62,7 +62,7 @@ typedef struct { // Rx timestamp uint64_t next_rx_ts; - pthread_t thread; + pthread_t thread; } rf_zmq_handler_t; void update_rates(rf_zmq_handler_t* handler, double srate); @@ -216,10 +216,10 @@ int rf_zmq_open_multi(char* args, void** h, uint32_t nof_channels) rf_zmq_opts_t rx_opts = {}; rf_zmq_opts_t tx_opts = {}; - rx_opts.socket_type = ZMQ_REQ; - tx_opts.socket_type = ZMQ_REP; - tx_opts.id = handler->id; - rx_opts.id = handler->id; + rx_opts.socket_type = ZMQ_REQ; + tx_opts.socket_type = ZMQ_REP; + tx_opts.id = handler->id; + rx_opts.id = handler->id; // parse args if (args && strlen(args)) { @@ -381,8 +381,7 @@ int rf_zmq_open_multi(char* args, void** h, uint32_t nof_channels) // initialize transmitter if (strlen(handler->tx_port) != 0) { - if (rf_zmq_tx_open(&handler->transmitter[i], tx_opts, handler->context, handler->tx_port) != - SRSLTE_SUCCESS) { + if (rf_zmq_tx_open(&handler->transmitter[i], tx_opts, handler->context, handler->tx_port) != SRSLTE_SUCCESS) { fprintf(stderr, "[zmq] Error: opening transmitter\n"); goto clean_exit; } @@ -477,11 +476,15 @@ void update_rates(rf_zmq_handler_t* handler, double srate) handler->srate = (uint32_t)srate; handler->decim_factor = handler->base_srate / handler->srate; } else { - fprintf(stderr, "Error: couldn't update sample rate. %.2f is not divisible by %.2f\n", srate / 1e6, + fprintf(stderr, + "Error: couldn't update sample rate. %.2f is not divisible by %.2f\n", + srate / 1e6, handler->base_srate / 1e6); } - printf("Current sample rate is %.2f MHz with a base rate of %.2f MHz (x%d decimation)\n", handler->srate / 1e6, - handler->base_srate / 1e6, handler->decim_factor); + printf("Current sample rate is %.2f MHz with a base rate of %.2f MHz (x%d decimation)\n", + handler->srate / 1e6, + handler->base_srate / 1e6, + handler->decim_factor); } } @@ -588,8 +591,12 @@ int rf_zmq_recv_with_time(void* h, void* data, uint32_t nsamples, bool blocking, return rf_zmq_recv_with_time_multi(h, &data, nsamples, blocking, secs, frac_secs); } -int rf_zmq_recv_with_time_multi( - void* h, void* data[4], uint32_t nsamples, bool blocking, time_t* secs, double* frac_secs) +int rf_zmq_recv_with_time_multi(void* h, + void* data[4], + uint32_t nsamples, + bool blocking, + time_t* secs, + double* frac_secs) { int ret = SRSLTE_ERROR; @@ -731,8 +738,8 @@ int rf_zmq_send_timed(void* h, { void* _data[4] = {data, NULL, NULL, NULL}; - return rf_zmq_send_timed_multi(h, _data, nsamples, secs, frac_secs, has_time_spec, blocking, is_start_of_burst, - is_end_of_burst); + return rf_zmq_send_timed_multi( + h, _data, nsamples, secs, frac_secs, has_time_spec, blocking, is_start_of_burst, is_end_of_burst); } // TODO: Implement Tx upsampling diff --git a/lib/src/phy/rf/rf_zmq_imp.h b/lib/src/phy/rf/rf_zmq_imp.h index d8758fba4..73c6e3312 100644 --- a/lib/src/phy/rf/rf_zmq_imp.h +++ b/lib/src/phy/rf/rf_zmq_imp.h @@ -65,19 +65,11 @@ SRSLTE_API void rf_zmq_register_error_handler(void* h, srslte_rf_error_handler_t SRSLTE_API double rf_zmq_set_rx_freq(void* h, uint32_t ch, double freq); -SRSLTE_API int rf_zmq_recv_with_time(void* h, - void* data, - uint32_t nsamples, - bool blocking, - time_t* secs, - double* frac_secs); - -SRSLTE_API int rf_zmq_recv_with_time_multi(void* h, - void** data, - uint32_t nsamples, - bool blocking, - time_t* secs, - double* frac_secs); +SRSLTE_API int +rf_zmq_recv_with_time(void* h, void* data, uint32_t nsamples, bool blocking, time_t* secs, double* frac_secs); + +SRSLTE_API int +rf_zmq_recv_with_time_multi(void* h, void** data, uint32_t nsamples, bool blocking, time_t* secs, double* frac_secs); SRSLTE_API double rf_zmq_set_tx_srate(void* h, double freq); diff --git a/lib/src/phy/rf/rf_zmq_imp_rx.c b/lib/src/phy/rf/rf_zmq_imp_rx.c index e927febc8..b88ac658a 100644 --- a/lib/src/phy/rf/rf_zmq_imp_rx.c +++ b/lib/src/phy/rf/rf_zmq_imp_rx.c @@ -25,11 +25,11 @@ */ #include "rf_zmq_imp_trx.h" +#include #include #include #include #include -#include static void* rf_zmq_async_rx_thread(void* h) { @@ -180,7 +180,7 @@ int rf_zmq_rx_open(rf_zmq_rx_t* q, rf_zmq_opts_t opts, void* zmq_ctx, char* sock goto clean_exit; } - ret = SRSLTE_SUCCESS; + ret = SRSLTE_SUCCESS; } clean_exit: @@ -189,20 +189,20 @@ clean_exit: int rf_zmq_rx_baseband(rf_zmq_rx_t* q, cf_t* buffer, uint32_t nsamples) { - void *dst_buffer = buffer; - uint32_t sample_sz = sizeof(cf_t); + void* dst_buffer = buffer; + uint32_t sample_sz = sizeof(cf_t); if (q->sample_format != ZMQ_TYPE_FC32) { dst_buffer = q->temp_buffer_convert; - sample_sz = 2*sizeof(short); + sample_sz = 2 * sizeof(short); } - int n = srslte_ringbuffer_read_timed(&q->ringbuffer, dst_buffer, sample_sz*nsamples, ZMQ_TIMEOUT_MS); + int n = srslte_ringbuffer_read_timed(&q->ringbuffer, dst_buffer, sample_sz * nsamples, ZMQ_TIMEOUT_MS); if (n < 0) { return n; } if (q->sample_format == ZMQ_TYPE_SC16) { - srslte_vec_convert_if(dst_buffer, INT16_MAX, (float*) buffer, 2*nsamples); + srslte_vec_convert_if(dst_buffer, INT16_MAX, (float*)buffer, 2 * nsamples); } return n; diff --git a/lib/src/phy/rf/rf_zmq_imp_trx.h b/lib/src/phy/rf/rf_zmq_imp_trx.h index 178ab8824..10e636948 100644 --- a/lib/src/phy/rf/rf_zmq_imp_trx.h +++ b/lib/src/phy/rf/rf_zmq_imp_trx.h @@ -40,10 +40,7 @@ #define ZMQ_BASERATE_DEFAULT_HZ (23040000) #define ZMQ_ID_STRLEN 16 -typedef enum { - ZMQ_TYPE_FC32 = 0, - ZMQ_TYPE_SC16 -} rf_zmq_format_t; +typedef enum { ZMQ_TYPE_FC32 = 0, ZMQ_TYPE_SC16 } rf_zmq_format_t; typedef struct { char id[ZMQ_ID_STRLEN]; @@ -60,7 +57,7 @@ typedef struct { typedef struct { char id[ZMQ_ID_STRLEN]; uint32_t socket_type; - rf_zmq_format_t sample_format; + rf_zmq_format_t sample_format; void* sock; uint64_t nsamples; bool running; @@ -72,7 +69,7 @@ typedef struct { } rf_zmq_rx_t; typedef struct { - const char *id; + const char* id; uint32_t socket_type; rf_zmq_format_t sample_format; } rf_zmq_opts_t; diff --git a/lib/src/phy/rf/rf_zmq_imp_tx.c b/lib/src/phy/rf/rf_zmq_imp_tx.c index 8465cd799..9f1feb4cc 100644 --- a/lib/src/phy/rf/rf_zmq_imp_tx.c +++ b/lib/src/phy/rf/rf_zmq_imp_tx.c @@ -25,12 +25,12 @@ */ #include "rf_zmq_imp_trx.h" +#include #include #include #include #include #include -#include int rf_zmq_tx_open(rf_zmq_tx_t* q, rf_zmq_opts_t opts, void* zmq_ctx, char* sock_args) { @@ -136,13 +136,13 @@ static int _rf_zmq_tx_baseband(rf_zmq_tx_t* q, cf_t* buffer, uint32_t nsamples) if (q->sample_format == ZMQ_TYPE_SC16) { buf = q->temp_buffer_convert; - sample_sz = 2*sizeof(short); - srslte_vec_convert_fi((float*) buffer, INT16_MAX, (short*) q->temp_buffer_convert, 2*nsamples); + sample_sz = 2 * sizeof(short); + srslte_vec_convert_fi((float*)buffer, INT16_MAX, (short*)q->temp_buffer_convert, 2 * nsamples); } // Send base-band if request was received if (n > 0) { - n = zmq_send(q->sock, buf, sample_sz*nsamples, 0); + n = zmq_send(q->sock, buf, sample_sz * nsamples, 0); if (n < 0) { if (rf_zmq_handle_error(q->id, "tx baseband send")) { n = SRSLTE_ERROR; diff --git a/lib/src/phy/rf/rf_zmq_test.c b/lib/src/phy/rf/rf_zmq_test.c index e350978f2..66206dbb8 100644 --- a/lib/src/phy/rf/rf_zmq_test.c +++ b/lib/src/phy/rf/rf_zmq_test.c @@ -113,8 +113,8 @@ void enb_tx_function(const char* tx_args, bool timed_tx) // subframes) srslte_timestamp_copy(&tx_time, &rx_time); srslte_timestamp_add(&tx_time, 0, TX_OFFSET_MS * 1e-3); - ret = srslte_rf_send_timed_multi(&enb_radio, (void**)data_ptr, SF_LEN, tx_time.full_secs, tx_time.frac_secs, true, - true, false); + ret = srslte_rf_send_timed_multi( + &enb_radio, (void**)data_ptr, SF_LEN, tx_time.full_secs, tx_time.frac_secs, true, true, false); } else { // normal tx ret = srslte_rf_send_multi(&enb_radio, (void**)data_ptr, SF_LEN, true, true, false); @@ -193,14 +193,16 @@ int main() // two trx radios with continous tx (no timed tx) using TCP transport for both directions if (run_test("tx_port=tcp://*:5554,rx_port=tcp://localhost:5555,id=ue,base_srate=1.92e6", - "rx_port=tcp://localhost:5554,tx_port=tcp://*:5555,id=enb,base_srate=1.92e6", false) != SRSLTE_SUCCESS) { + "rx_port=tcp://localhost:5554,tx_port=tcp://*:5555,id=enb,base_srate=1.92e6", + false) != SRSLTE_SUCCESS) { fprintf(stderr, "Two TRx radio test failed!\n"); return -1; } // two trx radios with continous tx (no timed tx) using TCP for UL (UE tx) and IPC for eNB DL (eNB tx) if (run_test("tx_port=tcp://*:5554,rx_port=ipc://dl,id=ue,base_srate=1.92e6", - "rx_port=tcp://localhost:5554,tx_port=ipc://dl,id=enb,base_srate=1.92e6", true) != SRSLTE_SUCCESS) { + "rx_port=tcp://localhost:5554,tx_port=ipc://dl,id=enb,base_srate=1.92e6", + true) != SRSLTE_SUCCESS) { fprintf(stderr, "Two TRx radio test with timed tx failed!\n"); return -1; } diff --git a/lib/src/phy/rf/uhd_c_api.h b/lib/src/phy/rf/uhd_c_api.h index 270206642..0a27a39db 100644 --- a/lib/src/phy/rf/uhd_c_api.h +++ b/lib/src/phy/rf/uhd_c_api.h @@ -19,14 +19,14 @@ * */ -#include #include "srslte/config.h" #include "srslte/phy/rf/rf.h" +#include /* Declare functions not currently provided by the C-API */ SRSLTE_API void rf_uhd_register_msg_handler_c(void (*new_handler)(const char*)); -SRSLTE_API void uhd_tx_metadata_set_time_spec(uhd_tx_metadata_handle *md, time_t secs, double frac_secs); -SRSLTE_API void uhd_tx_metadata_set_start(uhd_tx_metadata_handle *md, bool is_start_of_burst); -SRSLTE_API void uhd_tx_metadata_set_has_time_spec(uhd_tx_metadata_handle *md, bool has_time_spec); -SRSLTE_API void uhd_tx_metadata_set_end(uhd_tx_metadata_handle *md, bool is_end_of_burst); -SRSLTE_API void uhd_tx_metadata_add_time_spec(uhd_tx_metadata_handle *md, double frac_secs); +SRSLTE_API void uhd_tx_metadata_set_time_spec(uhd_tx_metadata_handle* md, time_t secs, double frac_secs); +SRSLTE_API void uhd_tx_metadata_set_start(uhd_tx_metadata_handle* md, bool is_start_of_burst); +SRSLTE_API void uhd_tx_metadata_set_has_time_spec(uhd_tx_metadata_handle* md, bool has_time_spec); +SRSLTE_API void uhd_tx_metadata_set_end(uhd_tx_metadata_handle* md, bool is_end_of_burst); +SRSLTE_API void uhd_tx_metadata_add_time_spec(uhd_tx_metadata_handle* md, double frac_secs); diff --git a/lib/src/phy/scrambling/scrambling.c b/lib/src/phy/scrambling/scrambling.c index f1394d3c7..31c5a44b7 100644 --- a/lib/src/phy/scrambling/scrambling.c +++ b/lib/src/phy/scrambling/scrambling.c @@ -19,85 +19,96 @@ * */ +#include "srslte/phy/scrambling/scrambling.h" +#include "srslte/phy/utils/bit.h" +#include "srslte/phy/utils/vector.h" +#include #include #include #include -#include -#include "srslte/phy/utils/bit.h" -#include "srslte/phy/utils/vector.h" -#include "srslte/phy/scrambling/scrambling.h" -void srslte_scrambling_f(srslte_sequence_t *s, float *data) { +void srslte_scrambling_f(srslte_sequence_t* s, float* data) +{ srslte_scrambling_f_offset(s, data, 0, s->cur_len); } -void srslte_scrambling_f_offset(srslte_sequence_t *s, float *data, int offset, int len) { - assert (len + offset <= s->cur_len); +void srslte_scrambling_f_offset(srslte_sequence_t* s, float* data, int offset, int len) +{ + assert(len + offset <= s->cur_len); srslte_vec_prod_fff(data, &s->c_float[offset], data, len); } -void srslte_scrambling_s(srslte_sequence_t *s, short *data) { +void srslte_scrambling_s(srslte_sequence_t* s, short* data) +{ srslte_scrambling_s_offset(s, data, 0, s->cur_len); } -void srslte_scrambling_s_offset(srslte_sequence_t *s, short *data, int offset, int len) { - assert (len + offset <= s->cur_len); +void srslte_scrambling_s_offset(srslte_sequence_t* s, short* data, int offset, int len) +{ + assert(len + offset <= s->cur_len); srslte_vec_neg_sss(data, &s->c_short[offset], data, len); } -void srslte_scrambling_sb_offset(srslte_sequence_t *s, int8_t *data, int offset, int len) { - assert (len + offset <= s->cur_len); +void srslte_scrambling_sb_offset(srslte_sequence_t* s, int8_t* data, int offset, int len) +{ + assert(len + offset <= s->cur_len); srslte_vec_neg_bbb(data, &s->c_char[offset], data, len); } -void srslte_scrambling_c(srslte_sequence_t *s, cf_t *data) { +void srslte_scrambling_c(srslte_sequence_t* s, cf_t* data) +{ srslte_scrambling_c_offset(s, data, 0, s->cur_len); } -void srslte_scrambling_c_offset(srslte_sequence_t *s, cf_t *data, int offset, int len) { - assert (len + offset <= s->cur_len); +void srslte_scrambling_c_offset(srslte_sequence_t* s, cf_t* data, int offset, int len) +{ + assert(len + offset <= s->cur_len); srslte_vec_prod_cfc(data, &s->c_float[offset], data, len); } -void scrambling_b(uint8_t *c, uint8_t *data, int len) { +void scrambling_b(uint8_t* c, uint8_t* data, int len) +{ - srslte_vec_xor_bbb((int8_t*)c,(int8_t*)data,(int8_t*)data,len); + srslte_vec_xor_bbb((int8_t*)c, (int8_t*)data, (int8_t*)data, len); } -void scrambling_b_word(uint8_t *c, uint8_t *data, int len) { - // Do XOR every 64 bits +void scrambling_b_word(uint8_t* c, uint8_t* data, int len) +{ + // Do XOR every 64 bits // FIXME: Use 32-bit in 32-bit machines - uint64_t *x = (uint64_t*) data; - uint64_t *y = (uint64_t*) c; - for (int i=0;ic, data, s->cur_len); +void srslte_scrambling_b(srslte_sequence_t* s, uint8_t* data) +{ + scrambling_b_word(s->c, data, s->cur_len); } -void srslte_scrambling_b_offset(srslte_sequence_t *s, uint8_t *data, int offset, int len) { - if (offset%8) { +void srslte_scrambling_b_offset(srslte_sequence_t* s, uint8_t* data, int offset, int len) +{ + if (offset % 8) { // Do not load words if offset is not word-aligned scrambling_b(&s->c[offset], data, len); } else { - scrambling_b_word(&s->c[offset], data, len); + scrambling_b_word(&s->c[offset], data, len); } } -void srslte_scrambling_bytes(srslte_sequence_t *s, uint8_t *data, int len) { - scrambling_b_word(s->c_bytes, data, len/8); +void srslte_scrambling_bytes(srslte_sequence_t* s, uint8_t* data, int len) +{ + scrambling_b_word(s->c_bytes, data, len / 8); // Scramble last bits - if (len%8) { + if (len % 8) { uint8_t tmp_bits[8]; - srslte_bit_unpack_vector(&data[len/8], tmp_bits, len%8); - scrambling_b(&s->c[8*(len/8)], tmp_bits, len%8); - srslte_bit_pack_vector(tmp_bits, &data[len/8], len%8); - } + srslte_bit_unpack_vector(&data[len / 8], tmp_bits, len % 8); + scrambling_b(&s->c[8 * (len / 8)], tmp_bits, len % 8); + srslte_bit_pack_vector(tmp_bits, &data[len / 8], len % 8); + } } diff --git a/lib/src/phy/scrambling/test/scrambling_test.c b/lib/src/phy/scrambling/test/scrambling_test.c index 7934abe1c..cdb7c7fc1 100644 --- a/lib/src/phy/scrambling/test/scrambling_test.c +++ b/lib/src/phy/scrambling/test/scrambling_test.c @@ -19,52 +19,54 @@ * */ +#include +#include #include #include #include #include -#include -#include #include -#include +#include #include "srslte/srslte.h" -char *srslte_sequence_name = NULL; -bool do_floats = false; -srslte_cp_t cp = SRSLTE_CP_NORM; -int cell_id = -1; -int nof_bits = 100; +char* srslte_sequence_name = NULL; +bool do_floats = false; +srslte_cp_t cp = SRSLTE_CP_NORM; +int cell_id = -1; +int nof_bits = 100; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [ef] -c cell_id -s [PBCH, PDSCH, PDCCH, PMCH, PUCCH]\n", prog); printf("\t -l nof_bits [Default %d]\n", nof_bits); printf("\t -e CP extended [Default CP Normal]\n"); printf("\t -f scramble floats [Default bits]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "csefl")) != -1) { switch (opt) { - case 'c': - cell_id = (int)strtol(argv[optind], NULL, 10); - break; - case 'l': - nof_bits = (int)strtol(argv[optind], NULL, 10); - break; - case 'e': - cp = SRSLTE_CP_EXT; - break; - case 'f': - do_floats = true; - break; - case 's': - srslte_sequence_name = argv[optind]; - break; - default: - usage(argv[0]); - exit(-1); + case 'c': + cell_id = (int)strtol(argv[optind], NULL, 10); + break; + case 'l': + nof_bits = (int)strtol(argv[optind], NULL, 10); + break; + case 'e': + cp = SRSLTE_CP_EXT; + break; + case 'f': + do_floats = true; + break; + case 's': + srslte_sequence_name = argv[optind]; + break; + default: + usage(argv[0]); + exit(-1); } } if (cell_id == -1) { @@ -77,7 +79,8 @@ void parse_args(int argc, char **argv) { } } -int init_sequence(srslte_sequence_t *seq, char *name) { +int init_sequence(srslte_sequence_t* seq, char* name) +{ if (!strcmp(name, "PBCH")) { bzero(seq, sizeof(srslte_sequence_t)); return srslte_sequence_pbch(seq, cp, cell_id); @@ -90,14 +93,14 @@ int init_sequence(srslte_sequence_t *seq, char *name) { } } - -int main(int argc, char **argv) { - int i; +int main(int argc, char** argv) +{ + int i; srslte_sequence_t seq; - uint8_t *input_b, *scrambled_b; - float *input_f, *scrambled_f; - struct timeval t[3]; - + uint8_t * input_b, *scrambled_b; + float * input_f, *scrambled_f; + struct timeval t[3]; + parse_args(argc, argv); if (init_sequence(&seq, srslte_sequence_name) == -1) { @@ -117,8 +120,8 @@ int main(int argc, char **argv) { exit(-1); } - for (i=0;i #include -#include "srslte/phy/utils/cexptab.h" #include "srslte/phy/sync/cfo.h" -#include "srslte/phy/utils/vector.h" +#include "srslte/phy/utils/cexptab.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" /* Set next macro to 1 for using table generated CFO compensation */ #define SRSLTE_CFO_USE_EXP_TABLE 0 -int srslte_cfo_init(srslte_cfo_t *h, uint32_t nsamples) { +int srslte_cfo_init(srslte_cfo_t* h, uint32_t nsamples) +{ #if SRSLTE_CFO_USE_EXP_TABLE int ret = SRSLTE_ERROR; bzero(h, sizeof(srslte_cfo_t)); @@ -44,9 +45,9 @@ int srslte_cfo_init(srslte_cfo_t *h, uint32_t nsamples) { if (!h->cur_cexp) { goto clean; } - h->tol = 0; - h->last_freq = 0; - h->nsamples = nsamples; + h->tol = 0; + h->last_freq = 0; + h->nsamples = nsamples; h->max_samples = nsamples; srslte_cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, h->nsamples); @@ -56,13 +57,14 @@ clean: srslte_cfo_free(h); } return ret; -#else /* SRSLTE_CFO_USE_EXP_TABLE */ +#else /* SRSLTE_CFO_USE_EXP_TABLE */ h->nsamples = nsamples; return SRSLTE_SUCCESS; #endif /* SRSLTE_CFO_USE_EXP_TABLE */ } -void srslte_cfo_free(srslte_cfo_t *h) { +void srslte_cfo_free(srslte_cfo_t* h) +{ #if SRSLTE_CFO_USE_EXP_TABLE srslte_cexptab_free(&h->tab); if (h->cur_cexp) { @@ -72,11 +74,13 @@ void srslte_cfo_free(srslte_cfo_t *h) { bzero(h, sizeof(srslte_cfo_t)); } -void srslte_cfo_set_tol(srslte_cfo_t *h, float tol) { +void srslte_cfo_set_tol(srslte_cfo_t* h, float tol) +{ h->tol = tol; } -int srslte_cfo_resize(srslte_cfo_t *h, uint32_t samples) { +int srslte_cfo_resize(srslte_cfo_t* h, uint32_t samples) +{ #if SRSLTE_CFO_USE_EXP_TABLE if (samples <= h->max_samples) { srslte_cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, samples); @@ -89,15 +93,16 @@ int srslte_cfo_resize(srslte_cfo_t *h, uint32_t samples) { return SRSLTE_SUCCESS; } -void srslte_cfo_correct(srslte_cfo_t *h, const cf_t *input, cf_t *output, float freq) { +void srslte_cfo_correct(srslte_cfo_t* h, const cf_t* input, cf_t* output, float freq) +{ #if SRSLTE_CFO_USE_EXP_TABLE if (fabs(h->last_freq - freq) > h->tol) { h->last_freq = freq; srslte_cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, h->nsamples); - DEBUG("CFO generating new table for frequency %.4fe-6\n", freq*1e6); + DEBUG("CFO generating new table for frequency %.4fe-6\n", freq * 1e6); } srslte_vec_prod_ccc(h->cur_cexp, input, output, h->nsamples); -#else /* SRSLTE_CFO_USE_EXP_TABLE */ +#else /* SRSLTE_CFO_USE_EXP_TABLE */ srslte_vec_apply_cfo(input, freq, output, h->nsamples); #endif /* SRSLTE_CFO_USE_EXP_TABLE */ } @@ -107,8 +112,12 @@ void srslte_cfo_correct(srslte_cfo_t *h, const cf_t *input, cf_t *output, float * Note that when correction table needs to be regenerated, the regeneration * takes place for the maximum number of samples */ -void srslte_cfo_correct_offset( - srslte_cfo_t* h, const cf_t* input, cf_t* output, float freq, int cexp_offset, int nsamples) +void srslte_cfo_correct_offset(srslte_cfo_t* h, + const cf_t* input, + cf_t* output, + float freq, + int cexp_offset, + int nsamples) { if (fabs(h->last_freq - freq) > h->tol) { h->last_freq = freq; diff --git a/lib/src/phy/sync/cp.c b/lib/src/phy/sync/cp.c index 087cfdcba..9da193ab1 100644 --- a/lib/src/phy/sync/cp.c +++ b/lib/src/phy/sync/cp.c @@ -23,12 +23,12 @@ #include #include "srslte/phy/sync/cp.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" -int srslte_cp_synch_init(srslte_cp_synch_t *q, uint32_t symbol_sz) +int srslte_cp_synch_init(srslte_cp_synch_t* q, uint32_t symbol_sz) { - q->symbol_sz = symbol_sz; + q->symbol_sz = symbol_sz; q->max_symbol_sz = symbol_sz; q->corr = srslte_vec_malloc(sizeof(cf_t) * q->symbol_sz); @@ -39,14 +39,14 @@ int srslte_cp_synch_init(srslte_cp_synch_t *q, uint32_t symbol_sz) return SRSLTE_SUCCESS; } -void srslte_cp_synch_free(srslte_cp_synch_t *q) +void srslte_cp_synch_free(srslte_cp_synch_t* q) { if (q->corr) { free(q->corr); } } -int srslte_cp_synch_resize(srslte_cp_synch_t *q, uint32_t symbol_sz) +int srslte_cp_synch_resize(srslte_cp_synch_t* q, uint32_t symbol_sz) { if (symbol_sz > q->max_symbol_sz) { ERROR("Error in cp_synch_resize(): symbol_sz must be lower than initialized\n"); @@ -57,26 +57,26 @@ int srslte_cp_synch_resize(srslte_cp_synch_t *q, uint32_t symbol_sz) return SRSLTE_SUCCESS; } - -uint32_t srslte_cp_synch(srslte_cp_synch_t *q, const cf_t *input, uint32_t max_offset, uint32_t nof_symbols, uint32_t cp_len) -{ - if (max_offset > q->symbol_sz) { - max_offset = q->symbol_sz; +uint32_t +srslte_cp_synch(srslte_cp_synch_t* q, const cf_t* input, uint32_t max_offset, uint32_t nof_symbols, uint32_t cp_len) +{ + if (max_offset > q->symbol_sz) { + max_offset = q->symbol_sz; } - for (int i=0;icorr[i] = 0; - const cf_t *inputPtr = input; - for (int n=0;ncorr[i] += srslte_vec_dot_prod_conj_ccc(&inputPtr[i], &inputPtr[i+q->symbol_sz], cplen)/nof_symbols; - inputPtr += q->symbol_sz+cplen; - } + for (int i = 0; i < max_offset; i++) { + q->corr[i] = 0; + const cf_t* inputPtr = input; + for (int n = 0; n < nof_symbols; n++) { + uint32_t cplen = (n % 7) ? cp_len : cp_len + 1; + q->corr[i] += srslte_vec_dot_prod_conj_ccc(&inputPtr[i], &inputPtr[i + q->symbol_sz], cplen) / nof_symbols; + inputPtr += q->symbol_sz + cplen; + } } uint32_t max_idx = srslte_vec_max_abs_ci(q->corr, max_offset); - return max_idx; + return max_idx; } -cf_t srslte_cp_synch_corr_output(srslte_cp_synch_t *q, uint32_t offset) +cf_t srslte_cp_synch_corr_output(srslte_cp_synch_t* q, uint32_t offset) { if (offset < q->symbol_sz) { return q->corr[offset]; @@ -84,4 +84,3 @@ cf_t srslte_cp_synch_corr_output(srslte_cp_synch_t *q, uint32_t offset) return 0; } } - diff --git a/lib/src/phy/sync/find_sss.c b/lib/src/phy/sync/find_sss.c index c7468b269..0b28a1ff1 100644 --- a/lib/src/phy/sync/find_sss.c +++ b/lib/src/phy/sync/find_sss.c @@ -19,50 +19,53 @@ * */ -#include #include #include +#include -#include "srslte/phy/utils/vector.h" #include "srslte/phy/sync/sss.h" +#include "srslte/phy/utils/vector.h" #define MAX_M 3 - -static void corr_all_zs(cf_t z[SRSLTE_SSS_N], float s[SRSLTE_SSS_N][SRSLTE_SSS_N-1], float output[SRSLTE_SSS_N]) { +static void corr_all_zs(cf_t z[SRSLTE_SSS_N], float s[SRSLTE_SSS_N][SRSLTE_SSS_N - 1], float output[SRSLTE_SSS_N]) +{ uint32_t m; - cf_t tmp[SRSLTE_SSS_N]; - + cf_t tmp[SRSLTE_SSS_N]; + for (m = 0; m < SRSLTE_SSS_N; m++) { - tmp[m] = srslte_vec_dot_prod_cfc(z, s[m], SRSLTE_SSS_N - 1); + tmp[m] = srslte_vec_dot_prod_cfc(z, s[m], SRSLTE_SSS_N - 1); } srslte_vec_abs_square_cf(tmp, output, SRSLTE_SSS_N); } -static void corr_all_sz_partial(cf_t z[SRSLTE_SSS_N], float s[SRSLTE_SSS_N][SRSLTE_SSS_N], uint32_t M, float output[SRSLTE_SSS_N]) { - uint32_t Nm = SRSLTE_SSS_N/M; - cf_t tmp[SRSLTE_SSS_N]; - float tmp_abs[MAX_M-1][SRSLTE_SSS_N]; - int j, m; - float *ptr; - - for (j=0;jfft_size/2-SRSLTE_SSS_N], ce, - &input_fft[q->fft_size/2-SRSLTE_SSS_N], 2*SRSLTE_SSS_N); + srslte_vec_div_ccc( + &input_fft[q->fft_size / 2 - SRSLTE_SSS_N], ce, &input_fft[q->fft_size / 2 - SRSLTE_SSS_N], 2 * SRSLTE_SSS_N); } // Extract FFT Data for (int i = 0; i < SRSLTE_SSS_N; i++) { - y[0][i] = input_fft[q->fft_size/2-SRSLTE_SSS_N + 2 * i]; - y[1][i] = input_fft[q->fft_size/2-SRSLTE_SSS_N + 2 * i + 1]; + y[0][i] = input_fft[q->fft_size / 2 - SRSLTE_SSS_N + 2 * i]; + y[1][i] = input_fft[q->fft_size / 2 - SRSLTE_SSS_N + 2 * i + 1]; } // Normalize @@ -91,83 +94,88 @@ static void extract_pair_sss(srslte_sss_t *q, const cf_t *input, cf_t *ce, cf_t // Unmask signal with sequence generated from NID2 srslte_vec_prod_cfc(y[0], q->fc_tables[q->N_id_2].c[0], y[0], SRSLTE_SSS_N); srslte_vec_prod_cfc(y[1], q->fc_tables[q->N_id_2].c[1], y[1], SRSLTE_SSS_N); +} -} - -int srslte_sss_m0m1_diff(srslte_sss_t *q, const cf_t *input, uint32_t *m0, float *m0_value, - uint32_t *m1, float *m1_value) +int srslte_sss_m0m1_diff(srslte_sss_t* q, + const cf_t* input, + uint32_t* m0, + float* m0_value, + uint32_t* m1, + float* m1_value) { return srslte_sss_m0m1_diff_coh(q, input, NULL, m0, m0_value, m1, m1_value); } -/* Differential SSS estimation. - * Returns m0 and m1 estimates +/* Differential SSS estimation. + * Returns m0 and m1 estimates * * Source: "SSS Detection Method for Initial Cell Search in 3GPP LTE FDD/TDD Dual Mode Receiver" * Jung-In Kim, Jung-Su Han, Hee-Jin Roh and Hyung-Jin Choi * */ -int srslte_sss_m0m1_diff_coh(srslte_sss_t *q, const cf_t *input, cf_t ce[2*SRSLTE_SSS_N], uint32_t *m0, float *m0_value, - uint32_t *m1, float *m1_value) +int srslte_sss_m0m1_diff_coh(srslte_sss_t* q, + const cf_t* input, + cf_t ce[2 * SRSLTE_SSS_N], + uint32_t* m0, + float* m0_value, + uint32_t* m1, + float* m1_value) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; + int ret = SRSLTE_ERROR_INVALID_INPUTS; + + if (q != NULL && input != NULL && m0 != NULL && m1 != NULL) { - if (q != NULL && - input != NULL && - m0 != NULL && - m1 != NULL) - { - cf_t yprod[SRSLTE_SSS_N]; cf_t y[2][SRSLTE_SSS_N]; extract_pair_sss(q, input, ce, y); - - srslte_vec_prod_conj_ccc(&y[0][1], y[0], yprod, SRSLTE_SSS_N - 1); + + srslte_vec_prod_conj_ccc(&y[0][1], y[0], yprod, SRSLTE_SSS_N - 1); corr_all_zs(yprod, q->fc_tables[q->N_id_2].sd, q->corr_output_m0); *m0 = srslte_vec_max_fi(q->corr_output_m0, SRSLTE_SSS_N); if (m0_value) { *m0_value = q->corr_output_m0[*m0]; - } - + } + srslte_vec_prod_cfc(y[1], q->fc_tables[q->N_id_2].z1[*m0], y[1], SRSLTE_SSS_N); srslte_vec_prod_conj_ccc(&y[1][1], y[1], yprod, SRSLTE_SSS_N - 1); corr_all_zs(yprod, q->fc_tables[q->N_id_2].sd, q->corr_output_m1); *m1 = srslte_vec_max_fi(q->corr_output_m1, SRSLTE_SSS_N); if (m1_value) { *m1_value = q->corr_output_m1[*m1]; - } + } ret = SRSLTE_SUCCESS; - } - return ret; + } + return ret; } -/* Partial correlation SSS estimation. - * Returns m0 and m1 estimates +/* Partial correlation SSS estimation. + * Returns m0 and m1 estimates * * Source: "SSS Detection Method for Initial Cell Search in 3GPP LTE FDD/TDD Dual Mode Receiver" * Jung-In Kim, Jung-Su Han, Hee-Jin Roh and Hyung-Jin Choi */ -int srslte_sss_m0m1_partial(srslte_sss_t *q, const cf_t *input, uint32_t M, cf_t ce[2*SRSLTE_SSS_N], uint32_t *m0, float *m0_value, - uint32_t *m1, float *m1_value) +int srslte_sss_m0m1_partial(srslte_sss_t* q, + const cf_t* input, + uint32_t M, + cf_t ce[2 * SRSLTE_SSS_N], + uint32_t* m0, + float* m0_value, + uint32_t* m1, + float* m1_value) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; + int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - input != NULL && - m0 != NULL && - m1 != NULL && - M <= MAX_M) - { + if (q != NULL && input != NULL && m0 != NULL && m1 != NULL && M <= MAX_M) { cf_t y[2][SRSLTE_SSS_N]; - + extract_pair_sss(q, input, ce, y); - - corr_all_sz_partial(y[0], q->fc_tables[q->N_id_2].s, M, q->corr_output_m0); + + corr_all_sz_partial(y[0], q->fc_tables[q->N_id_2].s, M, q->corr_output_m0); *m0 = srslte_vec_max_fi(q->corr_output_m0, SRSLTE_SSS_N); if (m0_value) { *m0_value = q->corr_output_m0[*m0]; @@ -177,33 +185,34 @@ int srslte_sss_m0m1_partial(srslte_sss_t *q, const cf_t *input, uint32_t M, cf_t *m1 = srslte_vec_max_fi(q->corr_output_m1, SRSLTE_SSS_N); if (m1_value) { *m1_value = q->corr_output_m1[*m1]; - } + } ret = SRSLTE_SUCCESS; - } - return ret; + } + return ret; } -void convert_tables(srslte_sss_fc_tables_t *fc_tables, srslte_sss_tables_t *in) { +void convert_tables(srslte_sss_fc_tables_t* fc_tables, srslte_sss_tables_t* in) +{ uint32_t i, j; for (i = 0; i < SRSLTE_SSS_N; i++) { for (j = 0; j < SRSLTE_SSS_N; j++) { - fc_tables->z1[i][j] = (float) in->z1[i][j]; + fc_tables->z1[i][j] = (float)in->z1[i][j]; } } for (i = 0; i < SRSLTE_SSS_N; i++) { for (j = 0; j < SRSLTE_SSS_N; j++) { - fc_tables->s[i][j] = (float) in->s[i][j]; + fc_tables->s[i][j] = (float)in->s[i][j]; } } for (i = 0; i < SRSLTE_SSS_N; i++) { for (j = 0; j < SRSLTE_SSS_N - 1; j++) { - fc_tables->sd[i][j] = (float) in->s[i][j + 1] * in->s[i][j]; + fc_tables->sd[i][j] = (float)in->s[i][j + 1] * in->s[i][j]; } } for (i = 0; i < 2; i++) { for (j = 0; j < SRSLTE_SSS_N; j++) { - fc_tables->c[i][j] = (float) in->c[i][j]; + fc_tables->c[i][j] = (float)in->c[i][j]; } } } diff --git a/lib/src/phy/sync/gen_sss.c b/lib/src/phy/sync/gen_sss.c index d63f38e9f..11730f397 100644 --- a/lib/src/phy/sync/gen_sss.c +++ b/lib/src/phy/sync/gen_sss.c @@ -28,7 +28,8 @@ * This function generates the scrambling sequences required for generation of * SSS sequence according with 3GPP TS 36.211 version 10.5.0 Release 10. */ -void generate_zsc_tilde(int *z_tilde, int *s_tilde, int *c_tilde) { +void generate_zsc_tilde(int* z_tilde, int* s_tilde, int* c_tilde) +{ int i; int x[SRSLTE_SSS_N]; @@ -51,64 +52,70 @@ void generate_zsc_tilde(int *z_tilde, int *s_tilde, int *c_tilde) { z_tilde[i] = 1 - 2 * x[i]; } -void generate_m0m1(uint32_t N_id_1, uint32_t *m0, uint32_t *m1) { +void generate_m0m1(uint32_t N_id_1, uint32_t* m0, uint32_t* m1) +{ uint32_t q_prime = N_id_1 / (SRSLTE_SSS_N - 1); - uint32_t q = (N_id_1 + (q_prime * (q_prime + 1) / 2)) / (SRSLTE_SSS_N - 1); + uint32_t q = (N_id_1 + (q_prime * (q_prime + 1) / 2)) / (SRSLTE_SSS_N - 1); uint32_t m_prime = N_id_1 + (q * (q + 1) / 2); - *m0 = m_prime % SRSLTE_SSS_N; - *m1 = (*m0 + m_prime / SRSLTE_SSS_N + 1) % SRSLTE_SSS_N; + *m0 = m_prime % SRSLTE_SSS_N; + *m1 = (*m0 + m_prime / SRSLTE_SSS_N + 1) % SRSLTE_SSS_N; } - /* table[m0][m1-1]=N_id_1 */ -void generate_N_id_1_table(uint32_t table[30][30]) { +void generate_N_id_1_table(uint32_t table[30][30]) +{ uint32_t m0, m1; uint32_t N_id_1; - for (N_id_1=0;N_id_1<168;N_id_1++) { + for (N_id_1 = 0; N_id_1 < 168; N_id_1++) { generate_m0m1(N_id_1, &m0, &m1); - table[m0][m1-1] = N_id_1; + table[m0][m1 - 1] = N_id_1; } } - -void generate_s(int *s, int *s_tilde, uint32_t m0_m1) { +void generate_s(int* s, int* s_tilde, uint32_t m0_m1) +{ uint32_t i; for (i = 0; i < SRSLTE_SSS_N; i++) { s[i] = s_tilde[(i + m0_m1) % SRSLTE_SSS_N]; } } -void generate_s_all(int s[SRSLTE_SSS_N][SRSLTE_SSS_N], int *s_tilde) { +void generate_s_all(int s[SRSLTE_SSS_N][SRSLTE_SSS_N], int* s_tilde) +{ uint32_t i; for (i = 0; i < SRSLTE_SSS_N; i++) { generate_s(s[i], s_tilde, i); } } -void generate_c(int *c, int *c_tilde, uint32_t N_id_2, bool is_c0) { +void generate_c(int* c, int* c_tilde, uint32_t N_id_2, bool is_c0) +{ uint32_t i; for (i = 0; i < SRSLTE_SSS_N; i++) { c[i] = c_tilde[(i + N_id_2 + (is_c0 ? 3 : 0)) % SRSLTE_SSS_N]; } } -void generate_z(int *z, int *z_tilde, uint32_t m0_m1) { +void generate_z(int* z, int* z_tilde, uint32_t m0_m1) +{ uint32_t i; for (i = 0; i < SRSLTE_SSS_N; i++) { z[i] = z_tilde[(i + (m0_m1 % 8)) % SRSLTE_SSS_N]; } } -void generate_z_all(int z[SRSLTE_SSS_N][SRSLTE_SSS_N], int *z_tilde) { +void generate_z_all(int z[SRSLTE_SSS_N][SRSLTE_SSS_N], int* z_tilde) +{ uint32_t i; for (i = 0; i < SRSLTE_SSS_N; i++) { generate_z(z[i], z_tilde, i); } } -void generate_sss_all_tables(srslte_sss_tables_t *tables, uint32_t N_id_2) { +void generate_sss_all_tables(srslte_sss_tables_t* tables, uint32_t N_id_2) +{ uint32_t i; - int s_t[SRSLTE_SSS_N], c_t[SRSLTE_SSS_N], z_t[SRSLTE_SSS_N]; + int s_t[SRSLTE_SSS_N], c_t[SRSLTE_SSS_N], z_t[SRSLTE_SSS_N]; generate_zsc_tilde(z_t, s_t, c_t); generate_s_all(tables->s, s_t); @@ -118,14 +125,15 @@ void generate_sss_all_tables(srslte_sss_tables_t *tables, uint32_t N_id_2) { } } -void srslte_sss_generate(float *signal0, float *signal5, uint32_t cell_id) { +void srslte_sss_generate(float* signal0, float* signal5, uint32_t cell_id) +{ uint32_t i; uint32_t id1 = cell_id / 3; uint32_t id2 = cell_id % 3; uint32_t m0; uint32_t m1; - int s_t[SRSLTE_SSS_N], c_t[SRSLTE_SSS_N], z_t[SRSLTE_SSS_N]; + int s_t[SRSLTE_SSS_N], c_t[SRSLTE_SSS_N], z_t[SRSLTE_SSS_N]; int s0[SRSLTE_SSS_N], s1[SRSLTE_SSS_N], c0[SRSLTE_SSS_N], c1[SRSLTE_SSS_N], z1_0[SRSLTE_SSS_N], z1_1[SRSLTE_SSS_N]; generate_m0m1(id1, &m0, &m1); @@ -142,15 +150,14 @@ void srslte_sss_generate(float *signal0, float *signal5, uint32_t cell_id) { for (i = 0; i < SRSLTE_SSS_N; i++) { /** Even Resource Elements: Sub-frame 0*/ - signal0[2 * i] = (float) (s0[i] * c0[i]); + signal0[2 * i] = (float)(s0[i] * c0[i]); /** Odd Resource Elements: Sub-frame 0*/ - signal0[2 * i + 1] = (float) (s1[i] * c1[i] * z1_0[i]); + signal0[2 * i + 1] = (float)(s1[i] * c1[i] * z1_0[i]); } for (i = 0; i < SRSLTE_SSS_N; i++) { /** Even Resource Elements: Sub-frame 5*/ - signal5[2 * i] = (float) (s1[i] * c0[i]); + signal5[2 * i] = (float)(s1[i] * c0[i]); /** Odd Resource Elements: Sub-frame 5*/ - signal5[2 * i + 1] = (float) (s0[i] * c1[i] * z1_1[i]); + signal5[2 * i + 1] = (float)(s0[i] * c1[i] * z1_1[i]); } } - diff --git a/lib/src/phy/sync/npss.c b/lib/src/phy/sync/npss.c index 3bd60b2c2..44e8154d2 100644 --- a/lib/src/phy/sync/npss.c +++ b/lib/src/phy/sync/npss.c @@ -422,8 +422,11 @@ int srslte_npss_generate(cf_t* signal) /** 36.211 10.3 section 6.11.1.2 */ -void srslte_npss_put_subframe( - srslte_npss_synch_t* q, cf_t* npss_signal, cf_t* sf, const uint32_t nof_prb, const uint32_t nbiot_prb_offset) +void srslte_npss_put_subframe(srslte_npss_synch_t* q, + cf_t* npss_signal, + cf_t* sf, + const uint32_t nof_prb, + const uint32_t nbiot_prb_offset) { // skip first 3 OFDM symbols over all PRBs completely uint32_t k = 3 * nof_prb * SRSLTE_NRE + nbiot_prb_offset * SRSLTE_NRE; diff --git a/lib/src/phy/sync/nsss.c b/lib/src/phy/sync/nsss.c index 22589b7c2..fee926a4c 100644 --- a/lib/src/phy/sync/nsss.c +++ b/lib/src/phy/sync/nsss.c @@ -228,8 +228,11 @@ int srslte_nsss_corr_init(srslte_nsss_synch_t* q) return SRSLTE_SUCCESS; } -int srslte_nsss_sync_find( - srslte_nsss_synch_t* q, cf_t* input, float* corr_peak_value, uint32_t* cell_id, uint32_t* sfn_partial) +int srslte_nsss_sync_find(srslte_nsss_synch_t* q, + cf_t* input, + float* corr_peak_value, + uint32_t* cell_id, + uint32_t* sfn_partial) { int ret = SRSLTE_ERROR_INVALID_INPUTS; diff --git a/lib/src/phy/sync/pss.c b/lib/src/phy/sync/pss.c index 307b357e4..762ea7cf7 100644 --- a/lib/src/phy/sync/pss.c +++ b/lib/src/phy/sync/pss.c @@ -19,44 +19,41 @@ * */ -#include -#include -#include #include #include +#include +#include +#include #include "srslte/phy/sync/pss.h" #include "srslte/phy/utils/debug.h" - -int srslte_pss_init_N_id_2(cf_t *pss_signal_freq, cf_t *pss_signal_time, - uint32_t N_id_2, uint32_t fft_size, int cfo_i) { +int srslte_pss_init_N_id_2(cf_t* pss_signal_freq, cf_t* pss_signal_time, uint32_t N_id_2, uint32_t fft_size, int cfo_i) +{ srslte_dft_plan_t plan; - cf_t pss_signal_pad[2048]; - int ret = SRSLTE_ERROR_INVALID_INPUTS; - - if (srslte_N_id_2_isvalid(N_id_2) && - fft_size <= 2048) - { - + cf_t pss_signal_pad[2048]; + int ret = SRSLTE_ERROR_INVALID_INPUTS; + + if (srslte_N_id_2_isvalid(N_id_2) && fft_size <= 2048) { + srslte_pss_generate(pss_signal_freq, N_id_2); bzero(pss_signal_pad, fft_size * sizeof(cf_t)); bzero(pss_signal_time, fft_size * sizeof(cf_t)); - memcpy(&pss_signal_pad[(fft_size-SRSLTE_PSS_LEN)/2+cfo_i], pss_signal_freq, SRSLTE_PSS_LEN * sizeof(cf_t)); + memcpy(&pss_signal_pad[(fft_size - SRSLTE_PSS_LEN) / 2 + cfo_i], pss_signal_freq, SRSLTE_PSS_LEN * sizeof(cf_t)); - /* Convert signal into the time domain */ + /* Convert signal into the time domain */ if (srslte_dft_plan(&plan, fft_size, SRSLTE_DFT_BACKWARD, SRSLTE_DFT_COMPLEX)) { return SRSLTE_ERROR; } - + srslte_dft_plan_set_mirror(&plan, true); srslte_dft_plan_set_dc(&plan, true); srslte_dft_plan_set_norm(&plan, true); srslte_dft_run_c(&plan, pss_signal_pad, pss_signal_time); srslte_vec_conj_cc(pss_signal_time, pss_signal_time, fft_size); - srslte_vec_sc_prod_cfc(pss_signal_time, 1.0/SRSLTE_PSS_LEN, pss_signal_time, fft_size); + srslte_vec_sc_prod_cfc(pss_signal_time, 1.0 / SRSLTE_PSS_LEN, pss_signal_time, fft_size); srslte_dft_plan_free(&plan); @@ -67,48 +64,53 @@ int srslte_pss_init_N_id_2(cf_t *pss_signal_freq, cf_t *pss_signal_time, /* Initializes the PSS synchronization object with fft_size=128 */ -int srslte_pss_init(srslte_pss_t *q, uint32_t frame_size) { +int srslte_pss_init(srslte_pss_t* q, uint32_t frame_size) +{ return srslte_pss_init_fft(q, frame_size, 128); } -int srslte_pss_init_fft(srslte_pss_t *q, uint32_t frame_size, uint32_t fft_size) { +int srslte_pss_init_fft(srslte_pss_t* q, uint32_t frame_size, uint32_t fft_size) +{ return srslte_pss_init_fft_offset(q, frame_size, fft_size, 0); } -int srslte_pss_init_fft_offset(srslte_pss_t *q, uint32_t frame_size, uint32_t fft_size, int offset) { - return srslte_pss_init_fft_offset_decim(q, frame_size, fft_size, offset, 1); +int srslte_pss_init_fft_offset(srslte_pss_t* q, uint32_t frame_size, uint32_t fft_size, int offset) +{ + return srslte_pss_init_fft_offset_decim(q, frame_size, fft_size, offset, 1); } -/* Initializes the PSS synchronization object. - * - * It correlates a signal of frame_size samples with the PSS sequence in the frequency - * domain. The PSS sequence is transformed using fft_size samples. +/* Initializes the PSS synchronization object. + * + * It correlates a signal of frame_size samples with the PSS sequence in the frequency + * domain. The PSS sequence is transformed using fft_size samples. */ -int srslte_pss_init_fft_offset_decim(srslte_pss_t *q, - uint32_t max_frame_size, uint32_t max_fft_size, - int offset, int decimate) +int srslte_pss_init_fft_offset_decim(srslte_pss_t* q, + uint32_t max_frame_size, + uint32_t max_fft_size, + int offset, + int decimate) { int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL) { - - ret = SRSLTE_ERROR; - - uint32_t N_id_2; + + ret = SRSLTE_ERROR; + + uint32_t N_id_2; uint32_t buffer_size; bzero(q, sizeof(srslte_pss_t)); - - q->N_id_2 = 10; + + q->N_id_2 = 10; q->ema_alpha = 0.2; - q->max_fft_size = max_fft_size; + q->max_fft_size = max_fft_size; q->max_frame_size = max_frame_size; - q->decimate = decimate; - uint32_t fft_size = max_fft_size/q->decimate; - uint32_t frame_size = max_frame_size/q->decimate; - - q->fft_size = fft_size; + q->decimate = decimate; + uint32_t fft_size = max_fft_size / q->decimate; + uint32_t frame_size = max_frame_size / q->decimate; + + q->fft_size = fft_size; q->frame_size = frame_size; buffer_size = fft_size + frame_size + 1; @@ -116,14 +118,14 @@ int srslte_pss_init_fft_offset_decim(srslte_pss_t *q, q->filter_pss_enable = false; q->chest_on_filter = false; - if(q->decimate > 1) { - int filter_order = 3; - srslte_filt_decim_cc_init(&q->filter,q->decimate,filter_order); - q->filter.filter_output = srslte_vec_malloc((buffer_size) * sizeof(cf_t)); - q->filter.downsampled_input = srslte_vec_malloc((buffer_size + filter_order) * sizeof(cf_t)); - printf("decimation for the PSS search is %d \n",q->decimate); + if (q->decimate > 1) { + int filter_order = 3; + srslte_filt_decim_cc_init(&q->filter, q->decimate, filter_order); + q->filter.filter_output = srslte_vec_malloc((buffer_size) * sizeof(cf_t)); + q->filter.downsampled_input = srslte_vec_malloc((buffer_size + filter_order) * sizeof(cf_t)); + printf("decimation for the PSS search is %d \n", q->decimate); } - + if (srslte_dft_plan(&q->dftp_input, fft_size, SRSLTE_DFT_FORWARD, SRSLTE_DFT_COMPLEX)) { ERROR("Error creating DFT plan \n"); goto clean_and_exit; @@ -140,9 +142,9 @@ int srslte_pss_init_fft_offset_decim(srslte_pss_t *q, srslte_dft_plan_set_dc(&q->idftp_input, true); srslte_dft_plan_set_norm(&q->idftp_input, false); - bzero(q->tmp_fft2, sizeof(cf_t)*SRSLTE_SYMBOL_SZ_MAX); + bzero(q->tmp_fft2, sizeof(cf_t) * SRSLTE_SYMBOL_SZ_MAX); - q->tmp_input = srslte_vec_malloc((buffer_size + frame_size*(q->decimate - 1)) * sizeof(cf_t)); + q->tmp_input = srslte_vec_malloc((buffer_size + frame_size * (q->decimate - 1)) * sizeof(cf_t)); if (!q->tmp_input) { ERROR("Error allocating memory\n"); goto clean_and_exit; @@ -171,7 +173,7 @@ int srslte_pss_init_fft_offset_decim(srslte_pss_t *q, bzero(q->conv_output_abs, sizeof(float) * buffer_size); #endif - for (N_id_2=0;N_id_2<3;N_id_2++) { + for (N_id_2 = 0; N_id_2 < 3; N_id_2++) { q->pss_signal_time[N_id_2] = srslte_vec_malloc(buffer_size * sizeof(cf_t)); if (!q->pss_signal_time[N_id_2]) { ERROR("Error allocating memory\n"); @@ -184,19 +186,18 @@ int srslte_pss_init_fft_offset_decim(srslte_pss_t *q, } bzero(&q->pss_signal_time[N_id_2][q->fft_size], q->frame_size * sizeof(cf_t)); } - #ifdef CONVOLUTION_FFT - +#ifdef CONVOLUTION_FFT if (srslte_conv_fft_cc_init(&q->conv_fft, frame_size, fft_size)) { ERROR("Error initiating convolution FFT\n"); goto clean_and_exit; } - for(N_id_2=0; N_id_2<3; N_id_2++) { + for (N_id_2 = 0; N_id_2 < 3; N_id_2++) { q->pss_signal_freq_full[N_id_2] = srslte_vec_malloc(buffer_size * sizeof(cf_t)); srslte_dft_run_c(&q->conv_fft.filter_plan, q->pss_signal_time[N_id_2], q->pss_signal_freq_full[N_id_2]); } - #endif +#endif srslte_pss_reset(q); @@ -208,17 +209,15 @@ clean_and_exit: srslte_pss_free(q); } return ret; - } - /* Initializes the PSS synchronization object. * * It correlates a signal of frame_size samples with the PSS sequence in the frequency * domain. The PSS sequence is transformed using fft_size samples. */ -int srslte_pss_resize(srslte_pss_t *q, uint32_t frame_size, uint32_t fft_size, int offset) { - +int srslte_pss_resize(srslte_pss_t* q, uint32_t frame_size, uint32_t fft_size, int offset) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL) { @@ -233,13 +232,13 @@ int srslte_pss_resize(srslte_pss_t *q, uint32_t frame_size, uint32_t fft_size, i uint32_t N_id_2; uint32_t buffer_size; - q->N_id_2 = 10; + q->N_id_2 = 10; q->ema_alpha = 0.2; - fft_size = fft_size/q->decimate; - frame_size = frame_size/q->decimate; + fft_size = fft_size / q->decimate; + frame_size = frame_size / q->decimate; - q->fft_size = fft_size; + q->fft_size = fft_size; q->frame_size = frame_size; buffer_size = fft_size + frame_size + 1; @@ -254,7 +253,7 @@ int srslte_pss_resize(srslte_pss_t *q, uint32_t frame_size, uint32_t fft_size, i return SRSLTE_ERROR; } - bzero(q->tmp_fft2, sizeof(cf_t)*SRSLTE_SYMBOL_SZ_MAX); + bzero(q->tmp_fft2, sizeof(cf_t) * SRSLTE_SYMBOL_SZ_MAX); bzero(&q->tmp_input[q->frame_size], q->fft_size * sizeof(cf_t)); bzero(q->conv_output, sizeof(cf_t) * buffer_size); @@ -265,7 +264,7 @@ int srslte_pss_resize(srslte_pss_t *q, uint32_t frame_size, uint32_t fft_size, i #endif // Generate PSS sequences for this FFT size - for (N_id_2=0;N_id_2<3;N_id_2++) { + for (N_id_2 = 0; N_id_2 < 3; N_id_2++) { if (srslte_pss_init_N_id_2(q->pss_signal_freq[N_id_2], q->pss_signal_time[N_id_2], N_id_2, fft_size, offset)) { ERROR("Error initiating PSS detector for N_id_2=%d fft_size=%d\n", N_id_2, fft_size); return SRSLTE_ERROR; @@ -278,7 +277,7 @@ int srslte_pss_resize(srslte_pss_t *q, uint32_t frame_size, uint32_t fft_size, i ERROR("Error initiating convolution FFT\n"); return SRSLTE_ERROR; } - for(int i =0; i< 3; i++) { + for (int i = 0; i < 3; i++) { srslte_dft_run_c(&q->conv_fft.filter_plan, q->pss_signal_time[i], q->pss_signal_freq_full[i]); } @@ -289,25 +288,25 @@ int srslte_pss_resize(srslte_pss_t *q, uint32_t frame_size, uint32_t fft_size, i ret = SRSLTE_SUCCESS; } return ret; - } -void srslte_pss_free(srslte_pss_t *q) { +void srslte_pss_free(srslte_pss_t* q) +{ uint32_t i; if (q) { - for (i=0;i<3;i++) { + for (i = 0; i < 3; i++) { if (q->pss_signal_time[i]) { free(q->pss_signal_time[i]); } - if(q->pss_signal_freq_full[i]){ + if (q->pss_signal_freq_full[i]) { free(q->pss_signal_freq_full[i]); } } - #ifdef CONVOLUTION_FFT +#ifdef CONVOLUTION_FFT srslte_conv_fft_cc_free(&q->conv_fft); - #endif +#endif if (q->tmp_input) { free(q->tmp_input); } @@ -324,19 +323,18 @@ void srslte_pss_free(srslte_pss_t *q) { srslte_dft_plan_free(&q->dftp_input); srslte_dft_plan_free(&q->idftp_input); - if(q->decimate > 1) - { - srslte_filt_decim_cc_free(&q->filter); - free(q->filter.filter_output); - free(q->filter.downsampled_input); + if (q->decimate > 1) { + srslte_filt_decim_cc_free(&q->filter); + free(q->filter.filter_output); + free(q->filter.downsampled_input); } - bzero(q, sizeof(srslte_pss_t)); } } -void srslte_pss_reset(srslte_pss_t *q) { +void srslte_pss_reset(srslte_pss_t* q) +{ uint32_t buffer_size = q->fft_size + q->frame_size + 1; bzero(q->conv_output_avg, sizeof(float) * buffer_size); } @@ -345,11 +343,12 @@ void srslte_pss_reset(srslte_pss_t *q) { * This function calculates the Zadoff-Chu sequence. * @param signal Output array. */ -int srslte_pss_generate(cf_t *signal, uint32_t N_id_2) { - int i; - float arg; - const float root_value[] = { 25.0, 29.0, 34.0 }; - int root_idx; +int srslte_pss_generate(cf_t* signal, uint32_t N_id_2) +{ + int i; + float arg; + const float root_value[] = {25.0, 29.0, 34.0}; + int root_idx; int sign = -1; @@ -361,14 +360,12 @@ int srslte_pss_generate(cf_t *signal, uint32_t N_id_2) { root_idx = N_id_2; for (i = 0; i < SRSLTE_PSS_LEN / 2; i++) { - arg = (float) sign * M_PI * root_value[root_idx] - * ((float) i * ((float) i + 1.0)) / 63.0; + arg = (float)sign * M_PI * root_value[root_idx] * ((float)i * ((float)i + 1.0)) / 63.0; __real__ signal[i] = cosf(arg); __imag__ signal[i] = sinf(arg); } for (i = SRSLTE_PSS_LEN / 2; i < SRSLTE_PSS_LEN; i++) { - arg = (float) sign * M_PI * root_value[root_idx] - * (((float) i + 2.0) * ((float) i + 1.0)) / 63.0; + arg = (float)sign * M_PI * root_value[root_idx] * (((float)i + 2.0) * ((float)i + 1.0)) / 63.0; __real__ signal[i] = cosf(arg); __imag__ signal[i] = sinf(arg); } @@ -377,7 +374,8 @@ int srslte_pss_generate(cf_t *signal, uint32_t N_id_2) { /** 36.211 10.3 section 6.11.1.2 */ -void srslte_pss_put_slot(cf_t *pss_signal, cf_t *slot, uint32_t nof_prb, srslte_cp_t cp) { +void srslte_pss_put_slot(cf_t* pss_signal, cf_t* slot, uint32_t nof_prb, srslte_cp_t cp) +{ int k; k = (SRSLTE_CP_NSYMB(cp) - 1) * nof_prb * SRSLTE_NRE + nof_prb * SRSLTE_NRE / 2 - 31; memset(&slot[k - 5], 0, 5 * sizeof(cf_t)); @@ -385,7 +383,8 @@ void srslte_pss_put_slot(cf_t *pss_signal, cf_t *slot, uint32_t nof_prb, srslte_ memset(&slot[k + SRSLTE_PSS_LEN], 0, 5 * sizeof(cf_t)); } -void srslte_pss_get_slot(cf_t *slot, cf_t *pss_signal, uint32_t nof_prb, srslte_cp_t cp) { +void srslte_pss_get_slot(cf_t* slot, cf_t* pss_signal, uint32_t nof_prb, srslte_cp_t cp) +{ int k; k = (SRSLTE_CP_NSYMB(cp) - 1) * nof_prb * SRSLTE_NRE + nof_prb * SRSLTE_NRE / 2 - 31; memcpy(pss_signal, &slot[k], SRSLTE_PSS_LEN * sizeof(cf_t)); @@ -393,7 +392,8 @@ void srslte_pss_get_slot(cf_t *slot, cf_t *pss_signal, uint32_t nof_prb, srslte_ /** Sets the current N_id_2 value. Returns -1 on ERROR(0 otherwise */ -int srslte_pss_set_N_id_2(srslte_pss_t *q, uint32_t N_id_2) { +int srslte_pss_set_N_id_2(srslte_pss_t* q, uint32_t N_id_2) +{ if (!srslte_N_id_2_isvalid((N_id_2))) { ERROR("Invalid N_id_2 %d\n", N_id_2); return -1; @@ -405,39 +405,40 @@ int srslte_pss_set_N_id_2(srslte_pss_t *q, uint32_t N_id_2) { /* Sets the weight factor alpha for the exponential moving average of the PSS correlation output */ -void srslte_pss_set_ema_alpha(srslte_pss_t *q, float alpha) { +void srslte_pss_set_ema_alpha(srslte_pss_t* q, float alpha) +{ q->ema_alpha = alpha; } -float compute_peak_sidelobe(srslte_pss_t *q, uint32_t corr_peak_pos, uint32_t conv_output_len) +float compute_peak_sidelobe(srslte_pss_t* q, uint32_t corr_peak_pos, uint32_t conv_output_len) { // Find end of peak lobe to the right - int pl_ub = corr_peak_pos+1; - while(q->conv_output_avg[pl_ub+1] <= q->conv_output_avg[pl_ub] && pl_ub < conv_output_len) { - pl_ub ++; + int pl_ub = corr_peak_pos + 1; + while (q->conv_output_avg[pl_ub + 1] <= q->conv_output_avg[pl_ub] && pl_ub < conv_output_len) { + pl_ub++; } // Find end of peak lobe to the left int pl_lb; if (corr_peak_pos > 2) { - pl_lb = corr_peak_pos-1; - while(q->conv_output_avg[pl_lb-1] <= q->conv_output_avg[pl_lb] && pl_lb > 1) { - pl_lb --; + pl_lb = corr_peak_pos - 1; + while (q->conv_output_avg[pl_lb - 1] <= q->conv_output_avg[pl_lb] && pl_lb > 1) { + pl_lb--; } } else { pl_lb = 0; } - int sl_distance_right = conv_output_len-1-pl_ub; + int sl_distance_right = conv_output_len - 1 - pl_ub; if (sl_distance_right < 0) { sl_distance_right = 0; } int sl_distance_left = pl_lb; - int sl_right = pl_ub+srslte_vec_max_fi(&q->conv_output_avg[pl_ub], sl_distance_right); - int sl_left = srslte_vec_max_fi(q->conv_output_avg, sl_distance_left); + int sl_right = pl_ub + srslte_vec_max_fi(&q->conv_output_avg[pl_ub], sl_distance_right); + int sl_left = srslte_vec_max_fi(q->conv_output_avg, sl_distance_left); float side_lobe_value = SRSLTE_MAX(q->conv_output_avg[sl_right], q->conv_output_avg[sl_left]); - return q->conv_output_avg[corr_peak_pos]/side_lobe_value; + return q->conv_output_avg[corr_peak_pos] / side_lobe_value; } /** Performs time-domain PSS correlation. @@ -447,13 +448,11 @@ float compute_peak_sidelobe(srslte_pss_t *q, uint32_t corr_peak_pos, uint32_t co * * Input buffer must be subframe_size long. */ -int srslte_pss_find_pss(srslte_pss_t *q, const cf_t *input, float *corr_peak_value) +int srslte_pss_find_pss(srslte_pss_t* q, const cf_t* input, float* corr_peak_value) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - input != NULL) - { + if (q != NULL && input != NULL) { uint32_t corr_peak_pos; uint32_t conv_output_len; @@ -470,40 +469,47 @@ int srslte_pss_find_pss(srslte_pss_t *q, const cf_t *input, float *corr_peak_val * This is why we can use FFT-based convolution */ if (q->frame_size >= q->fft_size) { - #ifdef CONVOLUTION_FFT +#ifdef CONVOLUTION_FFT memcpy(q->tmp_input, input, (q->frame_size * q->decimate) * sizeof(cf_t)); - if(q->decimate > 1) { - srslte_filt_decim_cc_execute(&(q->filter), q->tmp_input, q->filter.downsampled_input, q->filter.filter_output , (q->frame_size * q->decimate)); - conv_output_len = srslte_conv_fft_cc_run_opt(&q->conv_fft, q->filter.filter_output,q->pss_signal_freq_full[q->N_id_2], q->conv_output); + if (q->decimate > 1) { + srslte_filt_decim_cc_execute(&(q->filter), + q->tmp_input, + q->filter.downsampled_input, + q->filter.filter_output, + (q->frame_size * q->decimate)); + conv_output_len = srslte_conv_fft_cc_run_opt( + &q->conv_fft, q->filter.filter_output, q->pss_signal_freq_full[q->N_id_2], q->conv_output); } else { - conv_output_len = srslte_conv_fft_cc_run_opt(&q->conv_fft, q->tmp_input, q->pss_signal_freq_full[q->N_id_2], q->conv_output); + conv_output_len = + srslte_conv_fft_cc_run_opt(&q->conv_fft, q->tmp_input, q->pss_signal_freq_full[q->N_id_2], q->conv_output); } - #else - conv_output_len = srslte_conv_cc(input, q->pss_signal_time[q->N_id_2], q->conv_output, q->frame_size, q->fft_size); - #endif +#else + conv_output_len = + srslte_conv_cc(input, q->pss_signal_time[q->N_id_2], q->conv_output, q->frame_size, q->fft_size); +#endif } else { - for (int i=0;iframe_size;i++) { + for (int i = 0; i < q->frame_size; i++) { q->conv_output[i] = srslte_vec_dot_prod_ccc(q->pss_signal_time[q->N_id_2], &input[i], q->fft_size); } conv_output_len = q->frame_size; } // Compute modulus square - srslte_vec_abs_square_cf(q->conv_output, q->conv_output_abs, conv_output_len-1); + srslte_vec_abs_square_cf(q->conv_output, q->conv_output_abs, conv_output_len - 1); // If enabled, average the absolute value from previous calls if (q->ema_alpha < 1.0 && q->ema_alpha > 0.0) { - srslte_vec_sc_prod_fff(q->conv_output_abs, q->ema_alpha, q->conv_output_abs, conv_output_len-1); - srslte_vec_sc_prod_fff(q->conv_output_avg, 1-q->ema_alpha, q->conv_output_avg, conv_output_len-1); + srslte_vec_sc_prod_fff(q->conv_output_abs, q->ema_alpha, q->conv_output_abs, conv_output_len - 1); + srslte_vec_sc_prod_fff(q->conv_output_avg, 1 - q->ema_alpha, q->conv_output_avg, conv_output_len - 1); - srslte_vec_sum_fff(q->conv_output_abs, q->conv_output_avg, q->conv_output_avg, conv_output_len-1); + srslte_vec_sum_fff(q->conv_output_abs, q->conv_output_avg, q->conv_output_avg, conv_output_len - 1); } else { - memcpy(q->conv_output_avg, q->conv_output_abs, sizeof(float)*(conv_output_len-1)); + memcpy(q->conv_output_avg, q->conv_output_abs, sizeof(float) * (conv_output_len - 1)); } /* Find maximum of the absolute value of the correlation */ - corr_peak_pos = srslte_vec_max_fi(q->conv_output_avg, conv_output_len-1); + corr_peak_pos = srslte_vec_max_fi(q->conv_output_avg, conv_output_len - 1); // save absolute value q->peak_value = q->conv_output_avg[corr_peak_pos]; @@ -518,16 +524,16 @@ int srslte_pss_find_pss(srslte_pss_t *q, const cf_t *input, float *corr_peak_val } #endif - if(q->decimate >1) { + if (q->decimate > 1) { int decimation_correction = (q->filter.num_taps - 2); - corr_peak_pos = corr_peak_pos - decimation_correction; - corr_peak_pos = corr_peak_pos*q->decimate; + corr_peak_pos = corr_peak_pos - decimation_correction; + corr_peak_pos = corr_peak_pos * q->decimate; } if (q->frame_size >= q->fft_size) { - ret = (int) corr_peak_pos; + ret = (int)corr_peak_pos; } else { - ret = (int) corr_peak_pos + q->fft_size; + ret = (int)corr_peak_pos + q->fft_size; } } return ret; @@ -537,12 +543,11 @@ int srslte_pss_find_pss(srslte_pss_t *q, const cf_t *input, float *corr_peak_val * input signal is in the time-domain. * ce is the returned frequency-domain channel estimates. */ -int srslte_pss_chest(srslte_pss_t *q, const cf_t *input, cf_t ce[SRSLTE_PSS_LEN]) { +int srslte_pss_chest(srslte_pss_t* q, const cf_t* input, cf_t ce[SRSLTE_PSS_LEN]) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - input != NULL) - { + if (q != NULL && input != NULL) { if (!srslte_N_id_2_isvalid(q->N_id_2)) { ERROR("Error finding PSS peak, Must set N_id_2 first\n"); @@ -553,7 +558,8 @@ int srslte_pss_chest(srslte_pss_t *q, const cf_t *input, cf_t ce[SRSLTE_PSS_LEN] srslte_dft_run_c(&q->dftp_input, input, q->tmp_fft); /* Compute channel estimate taking the PSS sequence as reference */ - srslte_vec_prod_conj_ccc(&q->tmp_fft[(q->fft_size-SRSLTE_PSS_LEN)/2], q->pss_signal_freq[q->N_id_2], ce, SRSLTE_PSS_LEN); + srslte_vec_prod_conj_ccc( + &q->tmp_fft[(q->fft_size - SRSLTE_PSS_LEN) / 2], q->pss_signal_freq[q->N_id_2], ce, SRSLTE_PSS_LEN); ret = SRSLTE_SUCCESS; } @@ -563,19 +569,21 @@ int srslte_pss_chest(srslte_pss_t *q, const cf_t *input, cf_t ce[SRSLTE_PSS_LEN] /* input points to beginning of last OFDM symbol of slot 0 of subframe 0 or 5 * It must be called after calling srslte_pss_cfo_compute() with filter enabled */ -void srslte_pss_sic(srslte_pss_t *q, cf_t *input) { +void srslte_pss_sic(srslte_pss_t* q, cf_t* input) +{ if (q->chest_on_filter) { - bzero(q->tmp_fft, sizeof(cf_t)*q->fft_size); + bzero(q->tmp_fft, sizeof(cf_t) * q->fft_size); // Pass transmitted PSS sequence through the channel - srslte_vec_prod_ccc(q->pss_signal_freq[q->N_id_2], q->tmp_ce, &q->tmp_fft[(q->fft_size-SRSLTE_PSS_LEN)/2], SRSLTE_PSS_LEN); + srslte_vec_prod_ccc( + q->pss_signal_freq[q->N_id_2], q->tmp_ce, &q->tmp_fft[(q->fft_size - SRSLTE_PSS_LEN) / 2], SRSLTE_PSS_LEN); // Get time-domain version of the received PSS srslte_dft_run_c(&q->idftp_input, q->tmp_fft, q->tmp_fft2); // Substract received PSS from this N_id_2 from the input signal - srslte_vec_sc_prod_cfc(q->tmp_fft2, 1.0/q->fft_size, q->tmp_fft2, q->fft_size); + srslte_vec_sc_prod_cfc(q->tmp_fft2, 1.0 / q->fft_size, q->tmp_fft2, q->fft_size); srslte_vec_sub_ccc(input, q->tmp_fft2, input, q->fft_size); } else { @@ -584,16 +592,17 @@ void srslte_pss_sic(srslte_pss_t *q, cf_t *input) { } // Frequency-domain filtering of the central 64 sub-carriers -void srslte_pss_filter(srslte_pss_t *q, const cf_t *input, cf_t *output) +void srslte_pss_filter(srslte_pss_t* q, const cf_t* input, cf_t* output) { srslte_dft_run_c(&q->dftp_input, input, q->tmp_fft); - memcpy(&q->tmp_fft2[q->fft_size/2-SRSLTE_PSS_LEN/2], - &q->tmp_fft[q->fft_size/2-SRSLTE_PSS_LEN/2], - sizeof(cf_t)*SRSLTE_PSS_LEN); + memcpy(&q->tmp_fft2[q->fft_size / 2 - SRSLTE_PSS_LEN / 2], + &q->tmp_fft[q->fft_size / 2 - SRSLTE_PSS_LEN / 2], + sizeof(cf_t) * SRSLTE_PSS_LEN); if (q->chest_on_filter) { - srslte_vec_prod_conj_ccc(&q->tmp_fft[(q->fft_size-SRSLTE_PSS_LEN)/2], q->pss_signal_freq[q->N_id_2], q->tmp_ce, SRSLTE_PSS_LEN); + srslte_vec_prod_conj_ccc( + &q->tmp_fft[(q->fft_size - SRSLTE_PSS_LEN) / 2], q->pss_signal_freq[q->N_id_2], q->tmp_ce, SRSLTE_PSS_LEN); } srslte_dft_run_c(&q->idftp_input, q->tmp_fft2, output); @@ -604,18 +613,19 @@ void srslte_pss_filter(srslte_pss_t *q, const cf_t *input, cf_t *output) * Source: An Efficient CFO Estimation Algorithm for the Downlink of 3GPP-LTE * Feng Wang and Yu Zhu */ -float srslte_pss_cfo_compute(srslte_pss_t* q, const cf_t *pss_recv) { +float srslte_pss_cfo_compute(srslte_pss_t* q, const cf_t* pss_recv) +{ cf_t y0, y1; - const cf_t *pss_ptr = pss_recv; + const cf_t* pss_ptr = pss_recv; if (q->filter_pss_enable) { srslte_pss_filter(q, pss_recv, q->tmp_fft); - pss_ptr = (const cf_t*) q->tmp_fft; + pss_ptr = (const cf_t*)q->tmp_fft; } - y0 = srslte_vec_dot_prod_ccc(q->pss_signal_time[q->N_id_2], pss_ptr, q->fft_size/2); - y1 = srslte_vec_dot_prod_ccc(&q->pss_signal_time[q->N_id_2][q->fft_size/2], &pss_ptr[q->fft_size/2], q->fft_size/2); + y0 = srslte_vec_dot_prod_ccc(q->pss_signal_time[q->N_id_2], pss_ptr, q->fft_size / 2); + y1 = srslte_vec_dot_prod_ccc( + &q->pss_signal_time[q->N_id_2][q->fft_size / 2], &pss_ptr[q->fft_size / 2], q->fft_size / 2); return cargf(conjf(y0) * y1) / M_PI; } - diff --git a/lib/src/phy/sync/refsignal_dl_sync.c b/lib/src/phy/sync/refsignal_dl_sync.c index 81751eb64..823834a9f 100644 --- a/lib/src/phy/sync/refsignal_dl_sync.c +++ b/lib/src/phy/sync/refsignal_dl_sync.c @@ -300,8 +300,12 @@ void srslte_refsignal_dl_sync_run(srslte_refsignal_dl_sync_t* q, cf_t* buffer, u } } -void srslte_refsignal_dl_sync_measure_sf( - srslte_refsignal_dl_sync_t* q, cf_t* buffer, uint32_t sf_idx, float* rsrp, float* rssi, float* cfo) +void srslte_refsignal_dl_sync_measure_sf(srslte_refsignal_dl_sync_t* q, + cf_t* buffer, + uint32_t sf_idx, + float* rsrp, + float* rssi, + float* cfo) { float rsrp_lin = 0.0f; float rssi_lin = 0.0f; diff --git a/lib/src/phy/sync/sfo.c b/lib/src/phy/sync/sfo.c index 36e01b447..c36646f8d 100644 --- a/lib/src/phy/sync/sfo.c +++ b/lib/src/phy/sync/sfo.c @@ -19,18 +19,19 @@ * */ +#include "srslte/phy/sync/sfo.h" #include #include -#include "srslte/phy/sync/sfo.h" /* Estimate SFO based on the array of time estimates t0 * of length len. The parameter period is the time between t0 samples */ -float srslte_sfo_estimate(int *t0, int len, float period) { - int i; - float sfo=0.0; - for (i=1;i -#include -#include -#include #include +#include +#include +#include +#include #include "srslte/phy/dft/dft.h" #include "srslte/phy/sync/sss.h" @@ -31,20 +31,19 @@ #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" -void generate_sss_all_tables(srslte_sss_tables_t *tables, uint32_t N_id_2); -void convert_tables(srslte_sss_fc_tables_t *fc_tables, srslte_sss_tables_t *in); +void generate_sss_all_tables(srslte_sss_tables_t* tables, uint32_t N_id_2); +void convert_tables(srslte_sss_fc_tables_t* fc_tables, srslte_sss_tables_t* in); void generate_N_id_1_table(uint32_t table[30][30]); -int srslte_sss_init(srslte_sss_t *q, uint32_t fft_size) { - - if (q != NULL && - fft_size <= 2048) - { - uint32_t N_id_2; +int srslte_sss_init(srslte_sss_t* q, uint32_t fft_size) +{ + + if (q != NULL && fft_size <= 2048) { + uint32_t N_id_2; srslte_sss_tables_t sss_tables; bzero(q, sizeof(srslte_sss_t)); - + if (srslte_dft_plan(&q->dftp_input, fft_size, SRSLTE_DFT_FORWARD, SRSLTE_DFT_COMPLEX)) { srslte_sss_free(q); return SRSLTE_ERROR; @@ -52,25 +51,24 @@ int srslte_sss_init(srslte_sss_t *q, uint32_t fft_size) { srslte_dft_plan_set_mirror(&q->dftp_input, true); srslte_dft_plan_set_dc(&q->dftp_input, true); - q->fft_size = fft_size; + q->fft_size = fft_size; q->max_fft_size = fft_size; generate_N_id_1_table(q->N_id_1_table); - - for (N_id_2=0;N_id_2<3;N_id_2++) { + + for (N_id_2 = 0; N_id_2 < 3; N_id_2++) { generate_sss_all_tables(&sss_tables, N_id_2); convert_tables(&q->fc_tables[N_id_2], &sss_tables); } q->N_id_2 = 0; return SRSLTE_SUCCESS; - } + } return SRSLTE_ERROR_INVALID_INPUTS; } -int srslte_sss_resize(srslte_sss_t *q, uint32_t fft_size) { - if (q != NULL && - fft_size <= 2048) - { +int srslte_sss_resize(srslte_sss_t* q, uint32_t fft_size) +{ + if (q != NULL && fft_size <= 2048) { if (fft_size > q->max_fft_size) { ERROR("Error in sss_synch_resize(): fft_size must be lower than initialized\n"); return SRSLTE_ERROR; @@ -85,13 +83,15 @@ int srslte_sss_resize(srslte_sss_t *q, uint32_t fft_size) { return SRSLTE_ERROR_INVALID_INPUTS; } -void srslte_sss_free(srslte_sss_t *q) { +void srslte_sss_free(srslte_sss_t* q) +{ srslte_dft_plan_free(&q->dftp_input); bzero(q, sizeof(srslte_sss_t)); } /** Sets the N_id_2 to search for */ -int srslte_sss_set_N_id_2(srslte_sss_t *q, uint32_t N_id_2) { +int srslte_sss_set_N_id_2(srslte_sss_t* q, uint32_t N_id_2) +{ if (!srslte_N_id_2_isvalid(N_id_2)) { ERROR("Invalid N_id_2 %d\n", N_id_2); return SRSLTE_ERROR; @@ -103,11 +103,12 @@ int srslte_sss_set_N_id_2(srslte_sss_t *q, uint32_t N_id_2) { /** 36.211 10.3 section 6.11.2.2 */ -void srslte_sss_put_slot(float *sss, cf_t *slot, uint32_t nof_prb, srslte_cp_t cp) { +void srslte_sss_put_slot(float* sss, cf_t* slot, uint32_t nof_prb, srslte_cp_t cp) +{ uint32_t i, k; k = (SRSLTE_CP_NSYMB(cp) - 2) * nof_prb * SRSLTE_NRE + nof_prb * SRSLTE_NRE / 2 - 31; - + if (k > 5) { memset(&slot[k - 5], 0, 5 * sizeof(cf_t)); for (i = 0; i < SRSLTE_SSS_LEN; i++) { @@ -119,12 +120,14 @@ void srslte_sss_put_slot(float *sss, cf_t *slot, uint32_t nof_prb, srslte_cp_t c } /** Sets the SSS correlation peak detection threshold */ -void srslte_sss_set_threshold(srslte_sss_t *q, float threshold) { +void srslte_sss_set_threshold(srslte_sss_t* q, float threshold) +{ q->corr_peak_threshold = threshold; } /** Returns the subframe index based on the m0 and m1 values */ -uint32_t srslte_sss_subframe(uint32_t m0, uint32_t m1) { +uint32_t srslte_sss_subframe(uint32_t m0, uint32_t m1) +{ if (m1 > m0) { return 0; } else { diff --git a/lib/src/phy/sync/sync.c b/lib/src/phy/sync/sync.c index 6c5a63cee..cc06a11e8 100644 --- a/lib/src/phy/sync/sync.c +++ b/lib/src/phy/sync/sync.c @@ -25,61 +25,60 @@ #include #include -#include "srslte/phy/utils/debug.h" #include "srslte/phy/common/phy_common.h" +#include "srslte/phy/sync/cfo.h" #include "srslte/phy/sync/sync.h" +#include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" -#include "srslte/phy/sync/cfo.h" -#define CFO_EMA_ALPHA 0.1 -#define CP_EMA_ALPHA 0.1 +#define CFO_EMA_ALPHA 0.1 +#define CP_EMA_ALPHA 0.1 #define DEFAULT_CFO_TOL 0.0 // Hz #define MAX_CFO_PSS_OFFSET 7000 -static bool fft_size_isvalid(uint32_t fft_size) { - if (fft_size >= SRSLTE_SYNC_FFT_SZ_MIN && fft_size <= SRSLTE_SYNC_FFT_SZ_MAX && (fft_size%64) == 0) { +static bool fft_size_isvalid(uint32_t fft_size) +{ + if (fft_size >= SRSLTE_SYNC_FFT_SZ_MIN && fft_size <= SRSLTE_SYNC_FFT_SZ_MAX && (fft_size % 64) == 0) { return true; } else { return false; } } -int srslte_sync_init(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size) +int srslte_sync_init(srslte_sync_t* q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size) { - return srslte_sync_init_decim(q, frame_size, max_offset, fft_size, 1); + return srslte_sync_init_decim(q, frame_size, max_offset, fft_size, 1); } -int srslte_sync_init_decim(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size, int decimate) +int srslte_sync_init_decim(srslte_sync_t* q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size, int decimate) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; - - if (q != NULL && - fft_size_isvalid(fft_size)) - { - ret = SRSLTE_ERROR; + int ret = SRSLTE_ERROR_INVALID_INPUTS; + + if (q != NULL && fft_size_isvalid(fft_size)) { + ret = SRSLTE_ERROR; bzero(q, sizeof(srslte_sync_t)); q->N_id_2 = 1000; q->N_id_1 = 1000; q->cfo_ema_alpha = CFO_EMA_ALPHA; - q->sss_alg = SSS_FULL; + q->sss_alg = SSS_FULL; - q->detect_cp = true; - q->sss_en = true; - q->cfo_pss_enable = false; - q->cfo_cp_enable = false; - q->cfo_i_initiated = false; + q->detect_cp = true; + q->sss_en = true; + q->cfo_pss_enable = false; + q->cfo_cp_enable = false; + q->cfo_i_initiated = false; q->pss_filtering_enabled = false; q->detect_frame_type = true; q->cfo_cp_nsymbols = 3; - q->fft_size = fft_size; - q->frame_size = frame_size; - q->max_offset = max_offset; - q->max_frame_size = frame_size; + q->fft_size = fft_size; + q->frame_size = frame_size; + q->max_offset = max_offset; + q->max_frame_size = frame_size; srslte_sync_cfo_reset(q); @@ -92,27 +91,27 @@ int srslte_sync_init_decim(srslte_sync_t *q, uint32_t frame_size, uint32_t max_o ERROR("Error initiating CFO\n"); goto clean_exit; } - + // Set default CFO tolerance srslte_sync_set_cfo_tol(q, DEFAULT_CFO_TOL); - for (int i=0;i<2;i++) { - q->cfo_i_corr[i] = srslte_vec_malloc(sizeof(cf_t)*q->frame_size); + for (int i = 0; i < 2; i++) { + q->cfo_i_corr[i] = srslte_vec_malloc(sizeof(cf_t) * q->frame_size); if (!q->cfo_i_corr[i]) { perror("malloc"); goto clean_exit; } } - - q->temp = srslte_vec_malloc(sizeof(cf_t)*2*q->frame_size); + + q->temp = srslte_vec_malloc(sizeof(cf_t) * 2 * q->frame_size); if (!q->temp) { perror("malloc"); goto clean_exit; } - + srslte_sync_set_cp(q, SRSLTE_CP_NORM); q->decimate = decimate; - if(!decimate) { + if (!decimate) { decimate = 1; } @@ -139,20 +138,20 @@ int srslte_sync_init_decim(srslte_sync_t *q, uint32_t frame_size, uint32_t max_o } DEBUG("SYNC init with frame_size=%d, max_offset=%d and fft_size=%d\n", frame_size, max_offset, fft_size); - + ret = SRSLTE_SUCCESS; - } else { + } else { ERROR("Invalid parameters frame_size: %d, fft_size: %d\n", frame_size, fft_size); } - -clean_exit: + +clean_exit: if (ret == SRSLTE_ERROR) { srslte_sync_free(q); } return ret; } -void srslte_sync_free(srslte_sync_t *q) +void srslte_sync_free(srslte_sync_t* q) { if (q) { srslte_pss_free(&q->pss); @@ -176,13 +175,12 @@ void srslte_sync_free(srslte_sync_t *q) } } -int srslte_sync_resize(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size) { +int srslte_sync_resize(srslte_sync_t* q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - fft_size_isvalid(fft_size)) - { + if (q != NULL && fft_size_isvalid(fft_size)) { if (frame_size > q->max_frame_size) { ERROR("Error in sync_resize(): frame_size must be lower than initialized\n"); return SRSLTE_ERROR; @@ -222,13 +220,13 @@ int srslte_sync_resize(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offse } if (q->cfo_i_initiated) { - for (int i=0;i<2;i++) { - int offset=(i==0)?-1:1; + for (int i = 0; i < 2; i++) { + int offset = (i == 0) ? -1 : 1; if (srslte_pss_resize(&q->pss_i[i], q->max_offset, q->fft_size, offset)) { ERROR("Error initializing PSS object\n"); } - for (int t=0;tframe_size;t++) { - q->cfo_i_corr[i][t] = cexpf(-2*_Complex_I*M_PI*offset*(float) t/q->fft_size); + for (int t = 0; t < q->frame_size; t++) { + q->cfo_i_corr[i][t] = cexpf(-2 * _Complex_I * M_PI * offset * (float)t / q->fft_size); } } } @@ -239,7 +237,7 @@ int srslte_sync_resize(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offse DEBUG("SYNC init with frame_size=%d, max_offset=%d and fft_size=%d\n", frame_size, max_offset, fft_size); ret = SRSLTE_SUCCESS; - } else { + } else { ERROR("Invalid parameters frame_size: %d, fft_size: %d\n", frame_size, fft_size); } @@ -252,17 +250,20 @@ void srslte_sync_set_frame_type(srslte_sync_t* q, srslte_frame_type_t frame_type q->detect_frame_type = false; } -void srslte_sync_set_cfo_tol(srslte_sync_t *q, float tol) { +void srslte_sync_set_cfo_tol(srslte_sync_t* q, float tol) +{ q->current_cfo_tol = tol; - srslte_cfo_set_tol(&q->cfo_corr_frame, tol/(15000.0*q->fft_size)); - srslte_cfo_set_tol(&q->cfo_corr_symbol, tol/(15000.0*q->fft_size)); + srslte_cfo_set_tol(&q->cfo_corr_frame, tol / (15000.0 * q->fft_size)); + srslte_cfo_set_tol(&q->cfo_corr_symbol, tol / (15000.0 * q->fft_size)); } -void srslte_sync_set_threshold(srslte_sync_t *q, float threshold) { +void srslte_sync_set_threshold(srslte_sync_t* q, float threshold) +{ q->threshold = threshold; } -void srslte_sync_sss_en(srslte_sync_t *q, bool enabled) { +void srslte_sync_sss_en(srslte_sync_t* q, bool enabled) +{ q->sss_en = enabled; } @@ -281,11 +282,12 @@ bool srslte_sync_sss_available(srslte_sync_t* q) return q->sss_available; } -int srslte_sync_get_cell_id(srslte_sync_t *q) { +int srslte_sync_get_cell_id(srslte_sync_t* q) +{ if (srslte_N_id_2_isvalid(q->N_id_2) && srslte_N_id_1_isvalid(q->N_id_1)) { - return q->N_id_1*3 + q->N_id_2; + return q->N_id_1 * 3 + q->N_id_2; } else { - return -1; + return -1; } } @@ -335,15 +337,17 @@ int srslte_sync_set_N_id_1(srslte_sync_t* q, uint32_t N_id_1) } } -uint32_t srslte_sync_get_sf_idx(srslte_sync_t *q) { +uint32_t srslte_sync_get_sf_idx(srslte_sync_t* q) +{ return q->sf_idx; } -float srslte_sync_get_cfo(srslte_sync_t *q) { +float srslte_sync_get_cfo(srslte_sync_t* q) +{ return q->cfo_cp_mean + q->cfo_pss_mean + q->cfo_i_value; } -void srslte_sync_cfo_reset(srslte_sync_t *q) +void srslte_sync_cfo_reset(srslte_sync_t* q) { q->cfo_cp_mean = 0; q->cfo_cp_is_set = false; @@ -351,7 +355,8 @@ void srslte_sync_cfo_reset(srslte_sync_t *q) q->cfo_pss_is_set = false; } -void srslte_sync_copy_cfo(srslte_sync_t *q, srslte_sync_t *src_obj) { +void srslte_sync_copy_cfo(srslte_sync_t* q, srslte_sync_t* src_obj) +{ q->cfo_cp_mean = src_obj->cfo_cp_mean; q->cfo_pss_mean = src_obj->cfo_pss_mean; q->cfo_i_value = src_obj->cfo_i_value; @@ -359,127 +364,135 @@ void srslte_sync_copy_cfo(srslte_sync_t *q, srslte_sync_t *src_obj) { q->cfo_pss_is_set = false; } -void srslte_sync_set_cfo_i_enable(srslte_sync_t *q, bool enable) { +void srslte_sync_set_cfo_i_enable(srslte_sync_t* q, bool enable) +{ q->cfo_i_enable = enable; - if (q->cfo_i_enable && !q->cfo_i_initiated) { - for (int i=0;i<2;i++) { + if (q->cfo_i_enable && !q->cfo_i_initiated) { + for (int i = 0; i < 2; i++) { int offset = (i == 0) ? -1 : 1; if (srslte_pss_init_fft_offset(&q->pss_i[i], q->max_offset, q->fft_size, offset)) { ERROR("Error initializing PSS object\n"); } - for (int t=0;tframe_size;t++) { - q->cfo_i_corr[i][t] = cexpf(-2*_Complex_I*M_PI*offset*(float) t/q->fft_size); + for (int t = 0; t < q->frame_size; t++) { + q->cfo_i_corr[i][t] = cexpf(-2 * _Complex_I * M_PI * offset * (float)t / q->fft_size); } } q->cfo_i_initiated = true; } } -void srslte_sync_set_sss_eq_enable(srslte_sync_t *q, bool enable) { - q->sss_channel_equalize = enable; +void srslte_sync_set_sss_eq_enable(srslte_sync_t* q, bool enable) +{ + q->sss_channel_equalize = enable; if (enable) { q->pss_filtering_enabled = true; q->pss.chest_on_filter = true; } } -void srslte_sync_set_pss_filt_enable(srslte_sync_t *q, bool enable) { +void srslte_sync_set_pss_filt_enable(srslte_sync_t* q, bool enable) +{ q->pss_filtering_enabled = enable; } -void srslte_sync_set_cfo_cp_enable(srslte_sync_t *q, bool enable, uint32_t nof_symbols) { +void srslte_sync_set_cfo_cp_enable(srslte_sync_t* q, bool enable, uint32_t nof_symbols) +{ q->cfo_cp_enable = enable; q->cfo_cp_nsymbols = nof_symbols; } -void srslte_sync_set_cfo_pss_enable(srslte_sync_t *q, bool enable) { +void srslte_sync_set_cfo_pss_enable(srslte_sync_t* q, bool enable) +{ q->cfo_pss_enable = enable; } -void srslte_sync_set_cfo_ema_alpha(srslte_sync_t *q, float alpha) { +void srslte_sync_set_cfo_ema_alpha(srslte_sync_t* q, float alpha) +{ q->cfo_ema_alpha = alpha; } -float srslte_sync_get_peak_value(srslte_sync_t *q) { +float srslte_sync_get_peak_value(srslte_sync_t* q) +{ return q->peak_value; } -void srslte_sync_cp_en(srslte_sync_t *q, bool enabled) { +void srslte_sync_cp_en(srslte_sync_t* q, bool enabled) +{ q->detect_cp = enabled; } -void srslte_sync_set_em_alpha(srslte_sync_t *q, float alpha) +void srslte_sync_set_em_alpha(srslte_sync_t* q, float alpha) { srslte_pss_set_ema_alpha(&q->pss, alpha); } -srslte_cp_t srslte_sync_get_cp(srslte_sync_t *q) +srslte_cp_t srslte_sync_get_cp(srslte_sync_t* q) { return q->cp; } -void srslte_sync_set_cp(srslte_sync_t *q, srslte_cp_t cp) +void srslte_sync_set_cp(srslte_sync_t* q, srslte_cp_t cp) { - q->cp = cp; - q->cp_len = SRSLTE_CP_ISNORM(q->cp)?SRSLTE_CP_LEN_NORM(1,q->fft_size):SRSLTE_CP_LEN_EXT(q->fft_size); + q->cp = cp; + q->cp_len = SRSLTE_CP_ISNORM(q->cp) ? SRSLTE_CP_LEN_NORM(1, q->fft_size) : SRSLTE_CP_LEN_EXT(q->fft_size); if (q->frame_size < q->fft_size) { - q->nof_symbols = 1; + q->nof_symbols = 1; } else { - q->nof_symbols = q->frame_size/(q->fft_size+q->cp_len)-1; + q->nof_symbols = q->frame_size / (q->fft_size + q->cp_len) - 1; } } -void srslte_sync_set_sss_algorithm(srslte_sync_t *q, sss_alg_t alg) +void srslte_sync_set_sss_algorithm(srslte_sync_t* q, sss_alg_t alg) { - q->sss_alg = alg; + q->sss_alg = alg; } -/* CP detection algorithm taken from: +/* CP detection algorithm taken from: * "SSS Detection Method for Initial Cell Search in 3GPP LTE FDD/TDD Dual Mode Receiver" - * by Jung-In Kim et al. + * by Jung-In Kim et al. */ -srslte_cp_t srslte_sync_detect_cp(srslte_sync_t *q, const cf_t *input, uint32_t peak_pos) +srslte_cp_t srslte_sync_detect_cp(srslte_sync_t* q, const cf_t* input, uint32_t peak_pos) { - float R_norm=0, R_ext=0, C_norm=0, C_ext=0; - float M_norm=0, M_ext=0; - + float R_norm = 0, R_ext = 0, C_norm = 0, C_ext = 0; + float M_norm = 0, M_ext = 0; + uint32_t cp_norm_len = SRSLTE_CP_LEN_NORM(7, q->fft_size); - uint32_t cp_ext_len = SRSLTE_CP_LEN_EXT(q->fft_size); - - uint32_t nof_symbols = peak_pos/(q->fft_size+cp_ext_len); - + uint32_t cp_ext_len = SRSLTE_CP_LEN_EXT(q->fft_size); + + uint32_t nof_symbols = peak_pos / (q->fft_size + cp_ext_len); + if (nof_symbols > 3) { - nof_symbols = 3; + nof_symbols = 3; } - + if (nof_symbols > 0) { - - const cf_t *input_cp_norm = &input[peak_pos-nof_symbols*(q->fft_size+cp_norm_len)]; - const cf_t *input_cp_ext = &input[peak_pos-nof_symbols*(q->fft_size+cp_ext_len)]; - for (int i=0;ifft_size], input_cp_norm, cp_norm_len)); - C_norm += cp_norm_len * srslte_vec_avg_power_cf(input_cp_norm, cp_norm_len); - input_cp_norm += q->fft_size+cp_norm_len; + const cf_t* input_cp_norm = &input[peak_pos - nof_symbols * (q->fft_size + cp_norm_len)]; + const cf_t* input_cp_ext = &input[peak_pos - nof_symbols * (q->fft_size + cp_ext_len)]; + + for (int i = 0; i < nof_symbols; i++) { + R_norm += crealf(srslte_vec_dot_prod_conj_ccc(&input_cp_norm[q->fft_size], input_cp_norm, cp_norm_len)); + C_norm += cp_norm_len * srslte_vec_avg_power_cf(input_cp_norm, cp_norm_len); + input_cp_norm += q->fft_size + cp_norm_len; } if (C_norm > 0) { - M_norm = R_norm/C_norm; + M_norm = R_norm / C_norm; } - - q->M_norm_avg = SRSLTE_VEC_EMA(M_norm/nof_symbols, q->M_norm_avg, CP_EMA_ALPHA); - - for (int i=0;ifft_size], input_cp_ext, cp_ext_len)); - C_ext += cp_ext_len * srslte_vec_avg_power_cf(input_cp_ext, cp_ext_len); - input_cp_ext += q->fft_size+cp_ext_len; + + q->M_norm_avg = SRSLTE_VEC_EMA(M_norm / nof_symbols, q->M_norm_avg, CP_EMA_ALPHA); + + for (int i = 0; i < nof_symbols; i++) { + R_ext += crealf(srslte_vec_dot_prod_conj_ccc(&input_cp_ext[q->fft_size], input_cp_ext, cp_ext_len)); + C_ext += cp_ext_len * srslte_vec_avg_power_cf(input_cp_ext, cp_ext_len); + input_cp_ext += q->fft_size + cp_ext_len; } if (C_ext > 0) { - M_ext = R_ext/C_ext; + M_ext = R_ext / C_ext; } - q->M_ext_avg = SRSLTE_VEC_EMA(M_ext/nof_symbols, q->M_ext_avg, CP_EMA_ALPHA); + q->M_ext_avg = SRSLTE_VEC_EMA(M_ext / nof_symbols, q->M_ext_avg, CP_EMA_ALPHA); if (q->M_norm_avg > q->M_ext_avg) { - return SRSLTE_CP_NORM; + return SRSLTE_CP_NORM; } else if (q->M_norm_avg < q->M_ext_avg) { return SRSLTE_CP_EXT; } else { @@ -490,7 +503,7 @@ srslte_cp_t srslte_sync_detect_cp(srslte_sync_t *q, const cf_t *input, uint32_t } } } else { - return SRSLTE_CP_NORM; + return SRSLTE_CP_NORM; } } @@ -524,11 +537,11 @@ static bool sync_sss_symbol(srslte_sync_t* q, const cf_t* input, uint32_t* sf_id *N_id_1 = q->N_id_1; *corr = ratio; DEBUG("SSS correlation with N_id_1=%d, sf0=%.2f, sf5=%.2f, sf_idx=%d, ratio=%.1f\n", - q->N_id_1, - res[0], - res[1], - *sf_idx, - ratio); + q->N_id_1, + res[0], + res[1], + *sf_idx, + ratio); if (ratio > 1.2) { return true; } else { @@ -563,28 +576,29 @@ static bool sync_sss_symbol(srslte_sync_t* q, const cf_t* input, uint32_t* sf_id return false; } -srslte_pss_t* srslte_sync_get_cur_pss_obj(srslte_sync_t *q) +srslte_pss_t* srslte_sync_get_cur_pss_obj(srslte_sync_t* q) { - srslte_pss_t *pss_obj[3] = {&q->pss_i[0], &q->pss, &q->pss_i[1]}; - return pss_obj[q->cfo_i_value+1]; + srslte_pss_t* pss_obj[3] = {&q->pss_i[0], &q->pss, &q->pss_i[1]}; + return pss_obj[q->cfo_i_value + 1]; } -static float cfo_cp_estimate(srslte_sync_t *q, const cf_t *input) +static float cfo_cp_estimate(srslte_sync_t* q, const cf_t* input) { - uint32_t cp_offset = 0; - cp_offset = srslte_cp_synch(&q->cp_synch, input, q->max_offset, q->cfo_cp_nsymbols, SRSLTE_CP_LEN_NORM(1,q->fft_size)); - cf_t cp_corr_max = srslte_cp_synch_corr_output(&q->cp_synch, cp_offset); + uint32_t cp_offset = 0; + cp_offset = + srslte_cp_synch(&q->cp_synch, input, q->max_offset, q->cfo_cp_nsymbols, SRSLTE_CP_LEN_NORM(1, q->fft_size)); + cf_t cp_corr_max = srslte_cp_synch_corr_output(&q->cp_synch, cp_offset); float cfo = -cargf(cp_corr_max) / M_PI / 2; - return cfo; + return cfo; } -static int cfo_i_estimate(srslte_sync_t *q, const cf_t *input, int find_offset, int *peak_pos, int *cfo_i) +static int cfo_i_estimate(srslte_sync_t* q, const cf_t* input, int find_offset, int* peak_pos, int* cfo_i) { - float peak_value; - float max_peak_value = -99; - int max_cfo_i = 0; - srslte_pss_t *pss_obj[3] = {&q->pss_i[0], &q->pss, &q->pss_i[1]}; - for (int cfo_i=0;cfo_i<3;cfo_i++) { + float peak_value; + float max_peak_value = -99; + int max_cfo_i = 0; + srslte_pss_t* pss_obj[3] = {&q->pss_i[0], &q->pss, &q->pss_i[1]}; + for (int cfo_i = 0; cfo_i < 3; cfo_i++) { srslte_pss_set_N_id_2(pss_obj[cfo_i], q->N_id_2); int p = srslte_pss_find_pss(pss_obj[cfo_i], &input[find_offset], &peak_value); if (p < 0) { @@ -593,10 +607,10 @@ static int cfo_i_estimate(srslte_sync_t *q, const cf_t *input, int find_offset, if (peak_value > max_peak_value) { max_peak_value = peak_value; if (peak_pos) { - *peak_pos = p; + *peak_pos = p; } q->peak_value = peak_value; - max_cfo_i = cfo_i-1; + max_cfo_i = cfo_i - 1; } } if (cfo_i) { @@ -608,26 +622,24 @@ static int cfo_i_estimate(srslte_sync_t *q, const cf_t *input, int find_offset, /** Finds the PSS sequence previously defined by a call to srslte_sync_set_N_id_2() * around the position find_offset in the buffer input. * - * Returns 1 if the correlation peak exceeds the threshold set by srslte_sync_set_threshold() - * or 0 otherwise. Returns a negative number on error (if N_id_2 has not been set) + * Returns 1 if the correlation peak exceeds the threshold set by srslte_sync_set_threshold() + * or 0 otherwise. Returns a negative number on error (if N_id_2 has not been set) * * The input signal is not modified. Any CFO correction is done in internal buffers * * The maximum of the correlation peak is always stored in *peak_position */ -srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, const cf_t *input, uint32_t find_offset, uint32_t *peak_position) +srslte_sync_find_ret_t +srslte_sync_find(srslte_sync_t* q, const cf_t* input, uint32_t find_offset, uint32_t* peak_position) { - srslte_sync_find_ret_t ret = SRSLTE_SYNC_ERROR; - int peak_pos = 0; + srslte_sync_find_ret_t ret = SRSLTE_SYNC_ERROR; + int peak_pos = 0; if (!q) { return SRSLTE_ERROR_INVALID_INPUTS; } - - if (input != NULL && - srslte_N_id_2_isvalid(q->N_id_2) && - fft_size_isvalid(q->fft_size)) - { + + if (input != NULL && srslte_N_id_2_isvalid(q->N_id_2) && fft_size_isvalid(q->fft_size)) { q->sss_detected = false; @@ -635,7 +647,7 @@ srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, const cf_t *input, uin *peak_position = 0; } - const cf_t *input_ptr = input; + const cf_t* input_ptr = input; /* First CFO estimation stage is integer. * Finds max PSS correlation for shifted +1/0/-1 integer versions. @@ -648,7 +660,7 @@ srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, const cf_t *input, uin } // Correct it using precomputed signal and store in buffer (don't modify input signal) if (q->cfo_i_value != 0) { - srslte_vec_prod_ccc((cf_t*) input_ptr, q->cfo_i_corr[q->cfo_i_value<0?0:1], q->temp, q->frame_size); + srslte_vec_prod_ccc((cf_t*)input_ptr, q->cfo_i_corr[q->cfo_i_value < 0 ? 0 : 1], q->temp, q->frame_size); INFO("Compensating cfo_i=%d\n", q->cfo_i_value); input_ptr = q->temp; } @@ -679,7 +691,7 @@ srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, const cf_t *input, uin */ if (!q->cfo_i_enable) { srslte_pss_set_N_id_2(&q->pss, q->N_id_2); - peak_pos = srslte_pss_find_pss(&q->pss, &input_ptr[find_offset], q->threshold>0?&q->peak_value:NULL); + peak_pos = srslte_pss_find_pss(&q->pss, &input_ptr[find_offset], q->threshold > 0 ? &q->peak_value : NULL); if (peak_pos < 0) { ERROR("Error calling finding PSS sequence at : %d \n", peak_pos); return SRSLTE_ERROR; @@ -690,12 +702,12 @@ srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, const cf_t *input, uin // Save peak position if (peak_position) { - *peak_position = (uint32_t) peak_pos; + *peak_position = (uint32_t)peak_pos; } // In case of decimation, this compensates for the constant time shift caused by the low pass filter - if(q->decimate && peak_pos < 0) { - peak_pos = 0 ;//peak_pos + q->decimate*(2);// replace 2 with q->filter_size -2; + if (q->decimate && peak_pos < 0) { + peak_pos = 0; // peak_pos + q->decimate*(2);// replace 2 with q->filter_size -2; } /* If peak is over threshold, compute CFO and SSS */ @@ -704,7 +716,7 @@ srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, const cf_t *input, uin if (q->cfo_pss_enable && peak_pos >= q->fft_size) { // Filter central bands before PSS-based CFO estimation - const cf_t *pss_ptr = &input_ptr[find_offset + peak_pos - q->fft_size]; + const cf_t* pss_ptr = &input_ptr[find_offset + peak_pos - q->fft_size]; if (q->pss_filtering_enabled) { srslte_pss_filter(&q->pss, pss_ptr, q->pss_filt); pss_ptr = q->pss_filt; @@ -715,14 +727,14 @@ srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, const cf_t *input, uin if (!q->cfo_pss_is_set) { q->cfo_pss_mean = q->cfo_pss; q->cfo_pss_is_set = true; - } else if (15000*fabsf(q->cfo_pss) < MAX_CFO_PSS_OFFSET) { + } else if (15000 * fabsf(q->cfo_pss) < MAX_CFO_PSS_OFFSET) { q->cfo_pss_mean = SRSLTE_VEC_EMA(q->cfo_pss, q->cfo_pss_mean, q->cfo_ema_alpha); } DEBUG("PSS-CFO: filter=%s, estimated=%f, mean=%f\n", - q->pss_filtering_enabled ? "yes" : "no", - q->cfo_pss, - q->cfo_pss_mean); + q->pss_filtering_enabled ? "yes" : "no", + q->cfo_pss, + q->cfo_pss_mean); } // If there is enough space for CP and SSS estimation @@ -803,7 +815,7 @@ srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, const cf_t *input, uin } else { q->sf_idx = sf_idx[0] + 1; } - q->N_id_1 = N_id_1[0]; + q->N_id_1 = N_id_1[0]; q->sss_corr = sss_corr[0]; } } @@ -834,12 +846,13 @@ srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, const cf_t *input, uin } else if (srslte_N_id_2_isvalid(q->N_id_2)) { ERROR("Must call srslte_sync_set_N_id_2() first!\n"); } - - return ret; + + return ret; } -void srslte_sync_reset(srslte_sync_t *q) { +void srslte_sync_reset(srslte_sync_t* q) +{ q->M_ext_avg = 0; - q->M_norm_avg = 0; + q->M_norm_avg = 0; srslte_pss_reset(&q->pss); } diff --git a/lib/src/phy/sync/test/cfo_test.c b/lib/src/phy/sync/test/cfo_test.c index 0fbecd525..c6bfebd3d 100644 --- a/lib/src/phy/sync/test/cfo_test.c +++ b/lib/src/phy/sync/test/cfo_test.c @@ -19,48 +19,51 @@ * */ +#include +#include #include #include #include #include -#include -#include #include -#include +#include #include "srslte/srslte.h" -#define MAX_MSE 0.1 +#define MAX_MSE 0.1 -float freq = 0; -int num_samples = 1000; +float freq = 0; +int num_samples = 1000; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s -f freq -n num_samples\n", prog); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "nf")) != -1) { switch (opt) { - case 'n': - num_samples = (int)strtol(argv[optind], NULL, 10); - break; - case 'f': - freq = strtof(argv[optind], NULL); - break; - default: - usage(argv[0]); - exit(-1); + case 'n': + num_samples = (int)strtol(argv[optind], NULL, 10); + break; + case 'f': + freq = strtof(argv[optind], NULL); + break; + default: + usage(argv[0]); + exit(-1); } } } -int main(int argc, char **argv) { - int i; - cf_t *input, *output; +int main(int argc, char** argv) +{ + int i; + cf_t * input, *output; srslte_cfo_t cfocorr; - float mse; + float mse; if (argc < 5) { usage(argv[0]); @@ -80,8 +83,8 @@ int main(int argc, char **argv) { exit(-1); } - for (i=0;i #include #include #include #include -#include -#include #include +#include #include @@ -33,22 +33,23 @@ #ifdef ENABLE_GUI void init_plots(); -void do_plots(float *corr, float energy, uint32_t size, cf_t ce[SRSLTE_PSS_LEN]); -void do_plots_sss(float *corr_m0, float *corr_m1); +void do_plots(float* corr, float energy, uint32_t size, cf_t ce[SRSLTE_PSS_LEN]); +void do_plots_sss(float* corr_m0, float* corr_m1); void destroy_plots(); #endif /* ENABLE_GUI */ -bool disable_plots = false; -char *input_file_name; -int cell_id = -1; -int nof_frames = -1; -uint32_t fft_size=64; -float threshold = 0.4; -int N_id_2_sync = -1; -srslte_cp_t cp=SRSLTE_CP_NORM; -int file_offset = 0; - -void usage(char *prog) { +bool disable_plots = false; +char* input_file_name; +int cell_id = -1; +int nof_frames = -1; +uint32_t fft_size = 64; +float threshold = 0.4; +int N_id_2_sync = -1; +srslte_cp_t cp = SRSLTE_CP_NORM; +int file_offset = 0; + +void usage(char* prog) +{ printf("Usage: %s [nlestodv] -i cell_id -f input_file_name\n", prog); printf("\t-n nof_frames [Default %d]\n", nof_frames); printf("\t-l N_id_2 to sync [Default use cell_id]\n"); @@ -64,43 +65,44 @@ void usage(char *prog) { printf("\t-v srslte_verbose\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "nlestdvoif")) != -1) { switch (opt) { - case 'f': - input_file_name = argv[optind]; - break; - case 't': - threshold = strtof(argv[optind], NULL); - break; - case 'e': - cp = SRSLTE_CP_EXT; - break; - case 'i': - cell_id = (int)strtol(argv[optind], NULL, 10); - break; - case 'o': - file_offset = (int)strtol(argv[optind], NULL, 10); - break; - case 'l': - N_id_2_sync = (int)strtol(argv[optind], NULL, 10); - break; - case 's': - fft_size = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'n': - nof_frames = (int)strtol(argv[optind], NULL, 10); - break; - case 'd': - disable_plots = true; - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + case 'f': + input_file_name = argv[optind]; + break; + case 't': + threshold = strtof(argv[optind], NULL); + break; + case 'e': + cp = SRSLTE_CP_EXT; + break; + case 'i': + cell_id = (int)strtol(argv[optind], NULL, 10); + break; + case 'o': + file_offset = (int)strtol(argv[optind], NULL, 10); + break; + case 'l': + N_id_2_sync = (int)strtol(argv[optind], NULL, 10); + break; + case 's': + fft_size = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'n': + nof_frames = (int)strtol(argv[optind], NULL, 10); + break; + case 'd': + disable_plots = true; + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } if (cell_id < 0) { @@ -108,29 +110,30 @@ void parse_args(int argc, char **argv) { exit(-1); } } - float m0_value, m1_value; +float m0_value, m1_value; -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ srslte_filesource_t fsrc; - cf_t *buffer; - int frame_cnt, n; - srslte_pss_t pss; - srslte_cfo_t cfocorr, cfocorr64; - srslte_sss_t sss; - int32_t flen; - int peak_idx, last_peak; - float peak_value; - float mean_peak; - uint32_t nof_det, nof_nodet, nof_nopeak, nof_nopeakdet; - cf_t ce[SRSLTE_PSS_LEN]; - + cf_t* buffer; + int frame_cnt, n; + srslte_pss_t pss; + srslte_cfo_t cfocorr, cfocorr64; + srslte_sss_t sss; + int32_t flen; + int peak_idx, last_peak; + float peak_value; + float mean_peak; + uint32_t nof_det, nof_nodet, nof_nopeak, nof_nopeakdet; + cf_t ce[SRSLTE_PSS_LEN]; + parse_args(argc, argv); if (N_id_2_sync == -1) { - N_id_2_sync = cell_id%3; + N_id_2_sync = cell_id % 3; } - uint32_t N_id_2 = cell_id%3; - uint32_t N_id_1 = cell_id/3; + uint32_t N_id_2 = cell_id % 3; + uint32_t N_id_1 = cell_id / 3; #ifdef ENABLE_GUI if (!disable_plots) @@ -144,7 +147,7 @@ int main(int argc, char **argv) { perror("malloc"); exit(-1); } - + if (srslte_pss_init_fft(&pss, flen, fft_size)) { ERROR("Error initiating PSS\n"); exit(-1); @@ -155,9 +158,9 @@ int main(int argc, char **argv) { exit(-1); } - srslte_cfo_init(&cfocorr, flen); - srslte_cfo_init(&cfocorr64, flen); - + srslte_cfo_init(&cfocorr, flen); + srslte_cfo_init(&cfocorr64, flen); + if (srslte_sss_init(&sss, fft_size)) { ERROR("Error initializing SSS object\n"); return SRSLTE_ERROR; @@ -170,29 +173,29 @@ int main(int argc, char **argv) { ERROR("Error opening file %s\n", input_file_name); exit(-1); } - printf("N_id_2: %d\n", N_id_2); - + printf("N_id_2: %d\n", N_id_2); + printf("Frame length %d samples\n", flen); printf("PSS detection threshold: %.2f\n", threshold); - + nof_det = nof_nodet = nof_nopeak = nof_nopeakdet = 0; - frame_cnt = 0; - last_peak = 0; - mean_peak = 0; - int peak_offset = 0; - float cfo; - float mean_cfo = 0; - uint32_t m0, m1; - uint32_t sss_error1 = 0, sss_error2 = 0, sss_error3 = 0; - uint32_t cp_is_norm = 0; - - srslte_sync_t ssync; + frame_cnt = 0; + last_peak = 0; + mean_peak = 0; + int peak_offset = 0; + float cfo; + float mean_cfo = 0; + uint32_t m0, m1; + uint32_t sss_error1 = 0, sss_error2 = 0, sss_error3 = 0; + uint32_t cp_is_norm = 0; + + srslte_sync_t ssync; bzero(&ssync, sizeof(srslte_sync_t)); ssync.fft_size = fft_size; - + n = srslte_filesource_read(&fsrc, buffer, file_offset); - - while(frame_cnt < nof_frames || nof_frames == -1) { + + while (frame_cnt < nof_frames || nof_frames == -1) { n = srslte_filesource_read(&fsrc, buffer, flen - peak_offset); if (n < 0) { ERROR("Error reading samples\n"); @@ -202,7 +205,7 @@ int main(int argc, char **argv) { fprintf(stdout, "End of file (n=%d, flen=%d, peak=%d)\n", n, flen, peak_offset); break; } - + peak_idx = srslte_pss_find_pss(&pss, buffer, &peak_value); if (peak_idx < 0) { ERROR("Error finding PSS peak\n"); @@ -210,60 +213,61 @@ int main(int argc, char **argv) { } mean_peak = SRSLTE_VEC_CMA(peak_value, mean_peak, frame_cnt); - + if (peak_value >= threshold) { nof_det++; - + if (peak_idx >= fft_size) { - // Estimate CFO - cfo = srslte_pss_cfo_compute(&pss, &buffer[peak_idx-fft_size]); - mean_cfo = SRSLTE_VEC_CMA(cfo, mean_cfo, frame_cnt); + // Estimate CFO + cfo = srslte_pss_cfo_compute(&pss, &buffer[peak_idx - fft_size]); + mean_cfo = SRSLTE_VEC_CMA(cfo, mean_cfo, frame_cnt); // Correct CFO - srslte_cfo_correct(&cfocorr, buffer, buffer, -mean_cfo / fft_size); + srslte_cfo_correct(&cfocorr, buffer, buffer, -mean_cfo / fft_size); // Estimate channel - if (srslte_pss_chest(&pss, &buffer[peak_idx-fft_size], ce)) { + if (srslte_pss_chest(&pss, &buffer[peak_idx - fft_size], ce)) { ERROR("Error computing channel estimation\n"); exit(-1); } - // Find SSS - int sss_idx = peak_idx-2*fft_size-(SRSLTE_CP_ISNORM(cp)?SRSLTE_CP_LEN(fft_size, SRSLTE_CP_NORM_LEN):SRSLTE_CP_LEN(fft_size, SRSLTE_CP_EXT_LEN)); - if (sss_idx >= 0 && sss_idx < flen-fft_size) { + // Find SSS + int sss_idx = peak_idx - 2 * fft_size - + (SRSLTE_CP_ISNORM(cp) ? SRSLTE_CP_LEN(fft_size, SRSLTE_CP_NORM_LEN) + : SRSLTE_CP_LEN(fft_size, SRSLTE_CP_EXT_LEN)); + if (sss_idx >= 0 && sss_idx < flen - fft_size) { srslte_sss_m0m1_partial(&sss, &buffer[sss_idx], 3, NULL, &m0, &m0_value, &m1, &m1_value); if (srslte_sss_N_id_1(&sss, m0, m1, m1_value + m0_value) != N_id_1) { - sss_error2++; + sss_error2++; } INFO("sf_idx = %d\n", srslte_sss_subframe(m0, m1)); INFO("Partial N_id_1: %d\n", srslte_sss_N_id_1(&sss, m0, m1, m1_value + m0_value)); srslte_sss_m0m1_diff(&sss, &buffer[sss_idx], &m0, &m0_value, &m1, &m1_value); if (srslte_sss_N_id_1(&sss, m0, m1, m1_value + m0_value) != N_id_1) { - sss_error3++; + sss_error3++; } INFO("Diff N_id_1: %d\n", srslte_sss_N_id_1(&sss, m0, m1, m1_value + m0_value)); srslte_sss_m0m1_partial(&sss, &buffer[sss_idx], 1, NULL, &m0, &m0_value, &m1, &m1_value); if (srslte_sss_N_id_1(&sss, m0, m1, m1_value + m0_value) != N_id_1) { - sss_error1++; + sss_error1++; } INFO("Full N_id_1: %d\n", srslte_sss_N_id_1(&sss, m0, m1, m1_value + m0_value)); } - - // Estimate CP - if (peak_idx > 2*(fft_size + SRSLTE_CP_LEN_EXT(fft_size))) { + + // Estimate CP + if (peak_idx > 2 * (fft_size + SRSLTE_CP_LEN_EXT(fft_size))) { srslte_cp_t cp = srslte_sync_detect_cp(&ssync, buffer, peak_idx); if (SRSLTE_CP_ISNORM(cp)) { - cp_is_norm++; - } + cp_is_norm++; + } } - + } else { INFO("No space for CFO computation. Frame starts at \n"); } - - if(srslte_sss_subframe(m0,m1) == 0) - { + + if (srslte_sss_subframe(m0, m1) == 0) { #ifdef ENABLE_GUI if (!disable_plots) do_plots_sss(sss.corr_output_m0, sss.corr_output_m1); @@ -275,26 +279,30 @@ int main(int argc, char **argv) { } if (frame_cnt > 100) { - if (abs(last_peak-peak_idx) > 4) { + if (abs(last_peak - peak_idx) > 4) { if (peak_value >= threshold) { nof_nopeakdet++; - } - nof_nopeak++; - } + } + nof_nopeak++; + } } - + frame_cnt++; - + printf("[%5d]: Pos: %5d, PSR: %4.1f (~%4.1f) Pdet: %4.2f, " - "FA: %4.2f, CFO: %+4.1f kHz SSSmiss: %4.2f/%4.2f/%4.2f CPNorm: %.0f%%\r", - frame_cnt, - peak_idx - flen/10, - peak_value, mean_peak, - (float) nof_det/frame_cnt, - (float) nof_nopeakdet/frame_cnt, mean_cfo*15, - (float) sss_error1/nof_det,(float) sss_error2/nof_det,(float) sss_error3/nof_det, - (float) cp_is_norm/nof_det * 100); - + "FA: %4.2f, CFO: %+4.1f kHz SSSmiss: %4.2f/%4.2f/%4.2f CPNorm: %.0f%%\r", + frame_cnt, + peak_idx - flen / 10, + peak_value, + mean_peak, + (float)nof_det / frame_cnt, + (float)nof_nopeakdet / frame_cnt, + mean_cfo * 15, + (float)sss_error1 / nof_det, + (float)sss_error2 / nof_det, + (float)sss_error3 / nof_det, + (float)cp_is_norm / nof_det * 100); + if (SRSLTE_VERBOSE_ISINFO()) { printf("\n"); } @@ -308,7 +316,7 @@ int main(int argc, char **argv) { last_peak = peak_idx; } - + srslte_pss_free(&pss); free(buffer); srslte_filesource_free(&fsrc); @@ -321,8 +329,7 @@ int main(int argc, char **argv) { exit(0); } -extern cf_t *tmp2; - +extern cf_t* tmp2; /********************************************************************** * Plotting Functions @@ -331,21 +338,21 @@ extern cf_t *tmp2; #include "srsgui/srsgui.h" plot_real_t pssout; -//plot_complex_t pce; +// plot_complex_t pce; -plot_real_t psss1;//, psss2; +plot_real_t psss1; //, psss2; float tmp[1000000]; -cf_t tmpce[SRSLTE_PSS_LEN]; +cf_t tmpce[SRSLTE_PSS_LEN]; - -void init_plots() { +void init_plots() +{ sdrgui_init(); plot_real_init(&pssout); plot_real_setTitle(&pssout, "PSS xCorr"); plot_real_setLabels(&pssout, "Index", "Absolute value"); plot_real_setYAxisScale(&pssout, 0, 1); - + /* plot_complex_init(&pce); plot_complex_setTitle(&pce, "Channel Estimates"); @@ -354,43 +361,44 @@ void init_plots() { plot_complex_setYAxisScale(&pce, Magnitude, 0, 2); plot_complex_setYAxisScale(&pce, Phase, -M_PI, M_PI); */ - + plot_real_init(&psss1); plot_real_setTitle(&psss1, "SSS xCorr m0"); plot_real_setLabels(&psss1, "Index", "Absolute value"); plot_real_setYAxisScale(&psss1, 0, 1); - + /* plot_real_init(&psss2); plot_real_setTitle(&psss2, "SSS xCorr m1"); plot_real_setLabels(&psss2, "Index", "Absolute value"); plot_real_setYAxisScale(&psss2, 0, 1); */ - - } -void do_plots(float *corr, float energy, uint32_t size, cf_t ce[SRSLTE_PSS_LEN]) { - srslte_vec_sc_prod_fff(corr,1./energy,tmp, size); - plot_real_setNewData(&pssout, tmp, size); - -// float norm = srslte_vec_avg_power_cf(ce, SRSLTE_PSS_LEN); - // srslte_vec_sc_prod_cfc(ce, 1.0/sqrt(norm), tmpce, SRSLTE_PSS_LEN); - - //plot_complex_setNewData(&pce, tmpce, SRSLTE_PSS_LEN); +void do_plots(float* corr, float energy, uint32_t size, cf_t ce[SRSLTE_PSS_LEN]) +{ + srslte_vec_sc_prod_fff(corr, 1. / energy, tmp, size); + plot_real_setNewData(&pssout, tmp, size); + + // float norm = srslte_vec_avg_power_cf(ce, SRSLTE_PSS_LEN); + // srslte_vec_sc_prod_cfc(ce, 1.0/sqrt(norm), tmpce, SRSLTE_PSS_LEN); + + // plot_complex_setNewData(&pce, tmpce, SRSLTE_PSS_LEN); } -void do_plots_sss(float *corr_m0, float *corr_m1) { - if (m0_value > 0) - srslte_vec_sc_prod_fff(corr_m0,1./m0_value,corr_m0, SRSLTE_SSS_N); - plot_real_setNewData(&psss1, corr_m0, SRSLTE_SSS_N); - -// if (m1_value > 0) -// srslte_vec_sc_prod_fff(corr_m1,1./m1_value,corr_m1, SRSLTE_SSS_N); -// plot_real_setNewData(&psss2, corr_m1, SRSLTE_SSS_N); +void do_plots_sss(float* corr_m0, float* corr_m1) +{ + if (m0_value > 0) + srslte_vec_sc_prod_fff(corr_m0, 1. / m0_value, corr_m0, SRSLTE_SSS_N); + plot_real_setNewData(&psss1, corr_m0, SRSLTE_SSS_N); + + // if (m1_value > 0) + // srslte_vec_sc_prod_fff(corr_m1,1./m1_value,corr_m1, SRSLTE_SSS_N); + // plot_real_setNewData(&psss2, corr_m1, SRSLTE_SSS_N); } -void destroy_plots() { +void destroy_plots() +{ sdrgui_exit(); } diff --git a/lib/src/phy/sync/test/pss_usrp.c b/lib/src/phy/sync/test/pss_usrp.c index a42a1ff52..a9a5d6477 100644 --- a/lib/src/phy/sync/test/pss_usrp.c +++ b/lib/src/phy/sync/test/pss_usrp.c @@ -19,37 +19,38 @@ * */ +#include #include #include #include #include -#include -#include #include +#include #include -#include "srslte/srslte.h" #include "srslte/phy/rf/rf.h" +#include "srslte/srslte.h" #ifdef ENABLE_GUI void init_plots(); -void do_plots_pss(float *corr, float energy, uint32_t size); -void do_plots_sss(float *corr_m0, float *corr_m1); +void do_plots_pss(float* corr, float energy, uint32_t size); +void do_plots_sss(float* corr_m0, float* corr_m1); #endif /* ENABLE_GUI */ bool tdd_mode = false; bool disable_plots = false; int cell_id = -1; char* rf_args = ""; -float rf_gain=40.0, rf_freq=-1.0; -int nof_frames = -1; -uint32_t fft_size=64; -float threshold = 0.4; -int N_id_2_sync = -1; -srslte_cp_t cp=SRSLTE_CP_NORM; - -void usage(char *prog) { +float rf_gain = 40.0, rf_freq = -1.0; +int nof_frames = -1; +uint32_t fft_size = 64; +float threshold = 0.4; +int N_id_2_sync = -1; +srslte_cp_t cp = SRSLTE_CP_NORM; + +void usage(char* prog) +{ printf("Usage: %s [aedgtvnp] -f rx_frequency_hz -i cell_id\n", prog); printf("\t-a RF args [Default %s]\n", rf_args); printf("\t-g RF Gain [Default %.2f dB]\n", rf_gain); @@ -67,7 +68,8 @@ void usage(char *prog) { printf("\t-v srslte_verbose\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "adgetTvnsfil")) != -1) { switch (opt) { @@ -117,30 +119,31 @@ void parse_args(int argc, char **argv) { exit(-1); } } - float m0_value, m1_value; +float m0_value, m1_value; -int main(int argc, char **argv) { - cf_t *buffer; - int frame_cnt, n; - srslte_rf_t rf; +int main(int argc, char** argv) +{ + cf_t* buffer; + int frame_cnt, n; + srslte_rf_t rf; srslte_pss_t pss; - srslte_cfo_t cfocorr, cfocorr64; + srslte_cfo_t cfocorr, cfocorr64; srslte_sss_t sss; - int32_t flen; - int peak_idx, last_peak; - float peak_value; - float mean_peak; - uint32_t nof_det, nof_nodet, nof_nopeak, nof_nopeakdet; - cf_t ce[SRSLTE_PSS_LEN]; - float sfo = 0; - + int32_t flen; + int peak_idx, last_peak; + float peak_value; + float mean_peak; + uint32_t nof_det, nof_nodet, nof_nopeak, nof_nopeakdet; + cf_t ce[SRSLTE_PSS_LEN]; + float sfo = 0; + parse_args(argc, argv); if (N_id_2_sync == -1) { - N_id_2_sync = cell_id%3; + N_id_2_sync = cell_id % 3; } - uint32_t N_id_2 = cell_id%3; - uint32_t N_id_1 = cell_id/3; + uint32_t N_id_2 = cell_id % 3; + uint32_t N_id_1 = cell_id / 3; #ifdef ENABLE_GUI if (!disable_plots) @@ -149,7 +152,7 @@ int main(int argc, char **argv) { float srate = 15000.0 * fft_size; - flen = srate*5/1000; + flen = srate * 5 / 1000; printf("Opening RF device...\n"); if (srslte_rf_open(&rf, rf_args)) { @@ -166,7 +169,7 @@ int main(int argc, char **argv) { perror("malloc"); exit(-1); } - + if (srslte_pss_init_fft(&pss, flen, fft_size)) { ERROR("Error initiating PSS\n"); exit(-1); @@ -177,9 +180,9 @@ int main(int argc, char **argv) { exit(-1); } - srslte_cfo_init(&cfocorr, flen); - srslte_cfo_init(&cfocorr64, flen); - + srslte_cfo_init(&cfocorr, flen); + srslte_cfo_init(&cfocorr64, flen); + if (srslte_sss_init(&sss, fft_size)) { ERROR("Error initializing SSS object\n"); exit(-1); @@ -187,36 +190,36 @@ int main(int argc, char **argv) { srslte_sss_set_N_id_2(&sss, N_id_2); - printf("N_id_2: %d\n", N_id_2); + printf("N_id_2: %d\n", N_id_2); srslte_rf_start_rx_stream(&rf, false); - + printf("Frame length %d samples\n", flen); printf("PSS detection threshold: %.2f\n", threshold); - + nof_det = nof_nodet = nof_nopeak = nof_nopeakdet = 0; - frame_cnt = 0; - last_peak = 0; - mean_peak = 0; - int peak_offset = 0; - float cfo; - float mean_cfo = 0; - uint32_t m0, m1; - uint32_t sss_error1 = 0, sss_error2 = 0, sss_error3 = 0; - uint32_t cp_is_norm = 0; - - srslte_sync_t ssync; + frame_cnt = 0; + last_peak = 0; + mean_peak = 0; + int peak_offset = 0; + float cfo; + float mean_cfo = 0; + uint32_t m0, m1; + uint32_t sss_error1 = 0, sss_error2 = 0, sss_error3 = 0; + uint32_t cp_is_norm = 0; + + srslte_sync_t ssync; bzero(&ssync, sizeof(srslte_sync_t)); ssync.fft_size = fft_size; - - uint32_t max_peak = 0; - uint32_t max_peak_ = 0; - uint32_t min_peak = fft_size; + + uint32_t max_peak = 0; + uint32_t max_peak_ = 0; + uint32_t min_peak = fft_size; uint32_t min_peak_ = fft_size; pss.filter_pss_enable = true; - - while(frame_cnt < nof_frames || nof_frames == -1) { + + while (frame_cnt < nof_frames || nof_frames == -1) { n = srslte_rf_recv(&rf, buffer, flen - peak_offset, 1); if (n < 0) { ERROR("Error receiving samples\n"); @@ -230,21 +233,21 @@ int main(int argc, char **argv) { } mean_peak = SRSLTE_VEC_CMA(peak_value, mean_peak, frame_cnt); - + if (peak_value >= threshold) { nof_det++; - + if (peak_idx >= fft_size) { // Estimate CFO - cfo = srslte_pss_cfo_compute(&pss, &buffer[peak_idx-fft_size]); - mean_cfo = SRSLTE_VEC_CMA(cfo, mean_cfo, frame_cnt); + cfo = srslte_pss_cfo_compute(&pss, &buffer[peak_idx - fft_size]); + mean_cfo = SRSLTE_VEC_CMA(cfo, mean_cfo, frame_cnt); // Correct CFO - srslte_cfo_correct(&cfocorr, buffer, buffer, -mean_cfo / fft_size); + srslte_cfo_correct(&cfocorr, buffer, buffer, -mean_cfo / fft_size); // Estimate channel - if (srslte_pss_chest(&pss, &buffer[peak_idx-fft_size], ce)) { + if (srslte_pss_chest(&pss, &buffer[peak_idx - fft_size], ce)) { ERROR("Error computing channel estimation\n"); exit(-1); } @@ -260,7 +263,7 @@ int main(int argc, char **argv) { 3 * (SRSLTE_CP_ISNORM(cp) ? SRSLTE_CP_LEN(fft_size, SRSLTE_CP_NORM_LEN) : SRSLTE_CP_LEN(fft_size, SRSLTE_CP_EXT_LEN)); } - if (sss_idx >= 0 && sss_idx < flen-fft_size) { + if (sss_idx >= 0 && sss_idx < flen - fft_size) { // Filter SSS srslte_pss_filter(&pss, &buffer[sss_idx], &buffer[sss_idx]); @@ -268,28 +271,28 @@ int main(int argc, char **argv) { INFO("Full N_id_1: %d\n", srslte_sss_N_id_1(&sss, m0, m1, m1_value + m0_value)); srslte_sss_m0m1_partial(&sss, &buffer[sss_idx], 1, ce, &m0, &m0_value, &m1, &m1_value); if (srslte_sss_N_id_1(&sss, m0, m1, m1_value + m0_value) != N_id_1) { - sss_error2++; + sss_error2++; } INFO("Partial N_id_1: %d\n", srslte_sss_N_id_1(&sss, m0, m1, m1_value + m0_value)); srslte_sss_m0m1_diff_coh(&sss, &buffer[sss_idx], ce, &m0, &m0_value, &m1, &m1_value); if (srslte_sss_N_id_1(&sss, m0, m1, m1_value + m0_value) != N_id_1) { - sss_error3++; + sss_error3++; } INFO("Diff N_id_1: %d\n", srslte_sss_N_id_1(&sss, m0, m1, m1_value + m0_value)); } srslte_sss_m0m1_partial(&sss, &buffer[sss_idx], 1, NULL, &m0, &m0_value, &m1, &m1_value); if (srslte_sss_N_id_1(&sss, m0, m1, m1_value + m0_value) != N_id_1) { - sss_error1++; + sss_error1++; } - - // Estimate CP - if (peak_idx > 2*(fft_size + SRSLTE_CP_LEN_EXT(fft_size))) { + + // Estimate CP + if (peak_idx > 2 * (fft_size + SRSLTE_CP_LEN_EXT(fft_size))) { srslte_cp_t cp = srslte_sync_detect_cp(&ssync, buffer, peak_idx); if (SRSLTE_CP_ISNORM(cp)) { - cp_is_norm++; - } + cp_is_norm++; + } } - + } else { INFO("No space for CFO computation. Frame starts at \n"); } @@ -300,49 +303,56 @@ int main(int argc, char **argv) { do_plots_sss(sss.corr_output_m0, sss.corr_output_m1); #endif /* ENABLE_GUI */ } - + } else { nof_nodet++; } printf("[%5d]: Pos: %5d (%d-%d), PSR: %4.1f (~%4.1f) Pdet: %4.2f, " "FA: %4.2f, CFO: %+7.1f Hz, SFO: %+.2f Hz SSSmiss: %4.2f/%4.2f/%4.2f CPNorm: %.0f%%\r", - frame_cnt, - peak_idx, min_peak_, max_peak_, - peak_value, mean_peak, - (float) nof_det/frame_cnt, - (float) nof_nopeakdet/frame_cnt, mean_cfo*15000, sfo, - (float) sss_error1/nof_det,(float) sss_error2/nof_det,(float) sss_error3/nof_det, - (float) cp_is_norm/nof_det * 100); - + frame_cnt, + peak_idx, + min_peak_, + max_peak_, + peak_value, + mean_peak, + (float)nof_det / frame_cnt, + (float)nof_nopeakdet / frame_cnt, + mean_cfo * 15000, + sfo, + (float)sss_error1 / nof_det, + (float)sss_error2 / nof_det, + (float)sss_error3 / nof_det, + (float)cp_is_norm / nof_det * 100); + if (frame_cnt > 100) { - if (abs(last_peak-peak_idx) > 4) { + if (abs(last_peak - peak_idx) > 4) { if (peak_value >= threshold) { nof_nopeakdet++; - } - nof_nopeak++; - } - - sfo = SRSLTE_VEC_CMA((peak_idx - last_peak)/5e-3, sfo, frame_cnt); - - int frame_idx = frame_cnt % 200; - uint32_t peak_offset_symbol = peak_idx%fft_size; + } + nof_nopeak++; + } + + sfo = SRSLTE_VEC_CMA((peak_idx - last_peak) / 5e-3, sfo, frame_cnt); + + int frame_idx = frame_cnt % 200; + uint32_t peak_offset_symbol = peak_idx % fft_size; if (peak_offset_symbol > max_peak) { - max_peak = peak_offset_symbol; + max_peak = peak_offset_symbol; } if (peak_offset_symbol < min_peak) { - min_peak = peak_offset_symbol; + min_peak = peak_offset_symbol; } if (!frame_idx) { max_peak_ = max_peak; - min_peak_ = min_peak; - max_peak = 0; - min_peak = fft_size; + min_peak_ = min_peak; + max_peak = 0; + min_peak = fft_size; } } - + frame_cnt++; - + if (SRSLTE_VERBOSE_ISINFO()) { printf("\n"); } @@ -354,7 +364,6 @@ int main(int argc, char **argv) { #endif /* ENABLE_GUI */ last_peak = peak_idx; - } srslte_sss_free(&sss); @@ -362,12 +371,11 @@ int main(int argc, char **argv) { free(buffer); srslte_rf_close(&rf); - printf("Ok\n"); exit(0); } -extern cf_t *tmp2; +extern cf_t* tmp2; /********************************************************************** * Plotting Functions @@ -376,21 +384,21 @@ extern cf_t *tmp2; #include "srsgui/srsgui.h" plot_real_t pssout; -//plot_complex_t pce; +// plot_complex_t pce; plot_real_t psss1; float tmp[1000000]; -cf_t tmpce[SRSLTE_PSS_LEN]; +cf_t tmpce[SRSLTE_PSS_LEN]; - -void init_plots() { +void init_plots() +{ sdrgui_init(); plot_real_init(&pssout); plot_real_setTitle(&pssout, "PSS xCorr"); plot_real_setLabels(&pssout, "Index", "Absolute value"); plot_real_setYAxisScale(&pssout, 0, 1); - + /* plot_complex_init(&pce); plot_complex_setTitle(&pce, "Channel Estimates"); @@ -399,22 +407,24 @@ void init_plots() { plot_complex_setYAxisScale(&pce, Magnitude, 0, 2); plot_complex_setYAxisScale(&pce, Phase, -M_PI, M_PI); */ - + plot_real_init(&psss1); plot_real_setTitle(&psss1, "SSS xCorr m0"); plot_real_setLabels(&psss1, "Index", "Absolute value"); plot_real_setYAxisScale(&psss1, 0, 1); } -void do_plots_pss(float *corr, float peak, uint32_t size) { - srslte_vec_sc_prod_fff(corr,1./peak,tmp, size); - plot_real_setNewData(&pssout, tmp, size); +void do_plots_pss(float* corr, float peak, uint32_t size) +{ + srslte_vec_sc_prod_fff(corr, 1. / peak, tmp, size); + plot_real_setNewData(&pssout, tmp, size); } -void do_plots_sss(float *corr_m0, float *corr_m1) { - if (m0_value > 0) - srslte_vec_sc_prod_fff(corr_m0,1./m0_value,corr_m0, SRSLTE_SSS_N); - plot_real_setNewData(&psss1, corr_m0, SRSLTE_SSS_N); +void do_plots_sss(float* corr_m0, float* corr_m1) +{ + if (m0_value > 0) + srslte_vec_sc_prod_fff(corr_m0, 1. / m0_value, corr_m0, SRSLTE_SSS_N); + plot_real_setNewData(&psss1, corr_m0, SRSLTE_SSS_N); } #endif /* ENABLE_GUI */ diff --git a/lib/src/phy/sync/test/sync_nbiot_test.c b/lib/src/phy/sync/test/sync_nbiot_test.c index b8877a733..7ab7044c4 100644 --- a/lib/src/phy/sync/test/sync_nbiot_test.c +++ b/lib/src/phy/sync/test/sync_nbiot_test.c @@ -84,7 +84,7 @@ void parse_args(int argc, char** argv) int main(int argc, char** argv) { int ret = SRSLTE_ERROR; - int sf_idx = 0; + int sf_idx = 0; cf_t* fft_buffer = NULL; _Complex float buffer[SFLEN]; // FLEN + fft_size diff --git a/lib/src/phy/sync/test/sync_test.c b/lib/src/phy/sync/test/sync_test.c index b0e28725e..e4cc554c6 100644 --- a/lib/src/phy/sync/test/sync_test.c +++ b/lib/src/phy/sync/test/sync_test.c @@ -19,25 +19,26 @@ * */ +#include #include #include #include #include -#include -#include #include +#include #include #include "srslte/srslte.h" -int cell_id = -1, offset = 0; -srslte_cp_t cp = SRSLTE_CP_NORM; -uint32_t nof_prb=6; +int cell_id = -1, offset = 0; +srslte_cp_t cp = SRSLTE_CP_NORM; +uint32_t nof_prb = 6; -#define FLEN SRSLTE_SF_LEN(fft_size) +#define FLEN SRSLTE_SF_LEN(fft_size) -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [cpoev]\n", prog); printf("\t-c cell_id [Default check for all]\n"); printf("\t-p nof_prb [Default %d]\n", nof_prb); @@ -46,44 +47,46 @@ void usage(char *prog) { printf("\t-v srslte_verbose\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "cpoev")) != -1) { switch (opt) { - case 'c': - cell_id = (int)strtol(argv[optind], NULL, 10); - break; - case 'p': - nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); - break; - case 'o': - offset = (int)strtol(argv[optind], NULL, 10); - break; - case 'e': - cp = SRSLTE_CP_EXT; - break; - case 'v': - srslte_verbose++; - break; - default: - usage(argv[0]); - exit(-1); + case 'c': + cell_id = (int)strtol(argv[optind], NULL, 10); + break; + case 'p': + nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); + break; + case 'o': + offset = (int)strtol(argv[optind], NULL, 10); + break; + case 'e': + cp = SRSLTE_CP_EXT; + break; + case 'v': + srslte_verbose++; + break; + default: + usage(argv[0]); + exit(-1); } } } -int main(int argc, char **argv) { - int N_id_2, sf_idx, find_sf; - cf_t *buffer, *fft_buffer; - cf_t pss_signal[SRSLTE_PSS_LEN]; - float sss_signal0[SRSLTE_SSS_LEN]; // for subframe 0 - float sss_signal5[SRSLTE_SSS_LEN]; // for subframe 5 - int cid, max_cid; - uint32_t find_idx; +int main(int argc, char** argv) +{ + int N_id_2, sf_idx, find_sf; + cf_t * buffer, *fft_buffer; + cf_t pss_signal[SRSLTE_PSS_LEN]; + float sss_signal0[SRSLTE_SSS_LEN]; // for subframe 0 + float sss_signal5[SRSLTE_SSS_LEN]; // for subframe 5 + int cid, max_cid; + uint32_t find_idx; srslte_sync_t syncobj; srslte_ofdm_t ifft; - int fft_size; - + int fft_size; + parse_args(argc, argv); fft_size = srslte_symbol_sz(nof_prb); @@ -113,39 +116,39 @@ int main(int argc, char **argv) { ERROR("Error initiating PSS/SSS\n"); return -1; } - + srslte_sync_set_cp(&syncobj, cp); /* Set a very high threshold to make sure the correlation is ok */ srslte_sync_set_threshold(&syncobj, 5.0); srslte_sync_set_sss_algorithm(&syncobj, SSS_PARTIAL_3); - + if (cell_id == -1) { - cid = 0; + cid = 0; max_cid = 49; } else { - cid = cell_id; + cid = cell_id; max_cid = cell_id; -} - while(cid <= max_cid) { - N_id_2 = cid%3; + } + while (cid <= max_cid) { + N_id_2 = cid % 3; /* Generate PSS/SSS signals */ srslte_pss_generate(pss_signal, N_id_2); srslte_sss_generate(sss_signal0, sss_signal5, cid); srslte_sync_set_N_id_2(&syncobj, N_id_2); - - // SF1 is SF5 - for (sf_idx=0;sf_idx<2;sf_idx++) { + + // SF1 is SF5 + for (sf_idx = 0; sf_idx < 2; sf_idx++) { memset(buffer, 0, sizeof(cf_t) * FLEN); srslte_pss_put_slot(pss_signal, buffer, nof_prb, cp); - srslte_sss_put_slot(sf_idx?sss_signal5:sss_signal0, buffer, nof_prb, cp); + srslte_sss_put_slot(sf_idx ? sss_signal5 : sss_signal0, buffer, nof_prb, cp); /* Transform to OFDM symbols */ memset(fft_buffer, 0, sizeof(cf_t) * FLEN); srslte_ofdm_tx_sf(&ifft); - + /* Apply sample offset */ for (int i = 0; i < FLEN; i++) { fft_buffer[FLEN - i - 1 + offset] = fft_buffer[FLEN - i - 1]; @@ -157,18 +160,17 @@ int main(int argc, char **argv) { exit(-1); } find_sf = srslte_sync_get_sf_idx(&syncobj); - printf("cell_id: %d find: %d, offset: %d, ns=%d find_ns=%d\n", cid, find_idx, offset, - sf_idx, find_sf); - if (find_idx != offset + FLEN/2) { - printf("offset != find_offset: %d != %d\n", find_idx, offset + FLEN/2); + printf("cell_id: %d find: %d, offset: %d, ns=%d find_ns=%d\n", cid, find_idx, offset, sf_idx, find_sf); + if (find_idx != offset + FLEN / 2) { + printf("offset != find_offset: %d != %d\n", find_idx, offset + FLEN / 2); exit(-1); } - if (sf_idx*5 != find_sf) { + if (sf_idx * 5 != find_sf) { printf("ns != find_ns\n"); exit(-1); } if (srslte_sync_get_cp(&syncobj) != cp) { - printf("Detected CP should be %s\n", SRSLTE_CP_ISNORM(cp)?"Normal":"Extended"); + printf("Detected CP should be %s\n", SRSLTE_CP_ISNORM(cp) ? "Normal" : "Extended"); exit(-1); } } @@ -185,4 +187,3 @@ int main(int argc, char **argv) { printf("Ok\n"); exit(0); } - diff --git a/lib/src/phy/ue/test/ue_mib_sync_test_nbiot_usrp.c b/lib/src/phy/ue/test/ue_mib_sync_test_nbiot_usrp.c index a13f78f6e..ae6b4a100 100644 --- a/lib/src/phy/ue/test/ue_mib_sync_test_nbiot_usrp.c +++ b/lib/src/phy/ue/test/ue_mib_sync_test_nbiot_usrp.c @@ -127,7 +127,7 @@ int main(int argc, char** argv) signal(SIGINT, sig_int_handler); - float srate = 15000.0 * fft_size; + float srate = 15000.0 * fft_size; int32_t flen = srate * 10 / 1000; printf("Frame length %d samples\n", flen); @@ -162,7 +162,7 @@ int main(int argc, char** argv) printf("Trying to receive MIB-NB for n_id_ncell=%d for at most %d frames\n", cell.n_id_ncell, nof_frames); int sfn_offset = 0; uint8_t bch_payload_rx[SRSLTE_MIB_NB_LEN] = {}; - int ret = srslte_ue_mib_sync_nbiot_decode(&mib_sync, max_frames, bch_payload_rx, &cell.nof_ports, &sfn_offset); + int ret = srslte_ue_mib_sync_nbiot_decode(&mib_sync, max_frames, bch_payload_rx, &cell.nof_ports, &sfn_offset); if (ret == SRSLTE_UE_MIB_NBIOT_FOUND) { srslte_mib_nb_t mib_nb; srslte_npbch_mib_unpack(bch_payload_rx, &mib_nb); diff --git a/lib/src/phy/ue/test/ue_sync_test_nbiot_usrp.c b/lib/src/phy/ue/test/ue_sync_test_nbiot_usrp.c index d6e5d88df..44529d8bf 100644 --- a/lib/src/phy/ue/test/ue_sync_test_nbiot_usrp.c +++ b/lib/src/phy/ue/test/ue_sync_test_nbiot_usrp.c @@ -138,9 +138,9 @@ int main(int argc, char** argv) parse_args(argc, argv); #ifndef DISABLE_GRAPHICS - float cfo_table[CFO_TABLE_MAX_IDX]; - uint32_t cfo_table_index = 0; - uint32_t cfo_num_plot = CFO_TABLE_MAX_IDX; + float cfo_table[CFO_TABLE_MAX_IDX]; + uint32_t cfo_table_index = 0; + uint32_t cfo_num_plot = CFO_TABLE_MAX_IDX; if (!disable_plots) { init_plots(); @@ -149,7 +149,7 @@ int main(int argc, char** argv) signal(SIGINT, sig_int_handler); - float srate = 15000.0 * fft_size; + float srate = 15000.0 * fft_size; int32_t flen = srate * 10 / 1000; printf("Frame length %d samples\n", flen); diff --git a/lib/src/phy/ue/ue_cell_search.c b/lib/src/phy/ue/ue_cell_search.c index 1ce21c70b..fb59bffeb 100644 --- a/lib/src/phy/ue/ue_cell_search.c +++ b/lib/src/phy/ue/ue_cell_search.c @@ -31,9 +31,10 @@ #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" -int srslte_ue_cellsearch_init(srslte_ue_cellsearch_t * q, uint32_t max_frames, - int (recv_callback)(void*, void*, uint32_t,srslte_timestamp_t*), - void *stream_handler) +int srslte_ue_cellsearch_init(srslte_ue_cellsearch_t* q, + uint32_t max_frames, + int(recv_callback)(void*, void*, uint32_t, srslte_timestamp_t*), + void* stream_handler) { int ret = SRSLTE_ERROR_INVALID_INPUTS; @@ -41,15 +42,15 @@ int srslte_ue_cellsearch_init(srslte_ue_cellsearch_t * q, uint32_t max_frames, ret = SRSLTE_ERROR; srslte_cell_t cell; - bzero(q, sizeof(srslte_ue_cellsearch_t)); - + bzero(q, sizeof(srslte_ue_cellsearch_t)); + bzero(&cell, sizeof(srslte_cell_t)); - cell.id = SRSLTE_CELL_ID_UNKNOWN; - cell.nof_prb = SRSLTE_CS_NOF_PRB; + cell.id = SRSLTE_CELL_ID_UNKNOWN; + cell.nof_prb = SRSLTE_CS_NOF_PRB; if (srslte_ue_sync_init(&q->ue_sync, cell.nof_prb, true, recv_callback, stream_handler)) { ERROR("Error initiating ue_sync\n"); - goto clean_exit; + goto clean_exit; } if (srslte_ue_sync_set_cell(&q->ue_sync, cell)) { @@ -61,27 +62,27 @@ int srslte_ue_cellsearch_init(srslte_ue_cellsearch_t * q, uint32_t max_frames, q->sf_buffer[p] = NULL; } q->sf_buffer[0] = srslte_vec_malloc(3 * sizeof(cf_t) * SRSLTE_SF_LEN_PRB(100)); - q->nof_rx_antennas = 1; - + q->nof_rx_antennas = 1; + q->candidates = calloc(sizeof(srslte_ue_cellsearch_result_t), max_frames); if (!q->candidates) { perror("malloc"); - goto clean_exit; + goto clean_exit; } q->mode_ntimes = calloc(sizeof(uint32_t), max_frames); if (!q->mode_ntimes) { perror("malloc"); - goto clean_exit; + goto clean_exit; } q->mode_counted = calloc(sizeof(uint8_t), max_frames); if (!q->mode_counted) { perror("malloc"); - goto clean_exit; + goto clean_exit; } - q->max_frames = max_frames; - q->nof_valid_frames = max_frames; - + q->max_frames = max_frames; + q->nof_valid_frames = max_frames; + ret = SRSLTE_SUCCESS; } @@ -104,15 +105,15 @@ int srslte_ue_cellsearch_init_multi(srslte_ue_cellsearch_t* q, ret = SRSLTE_ERROR; srslte_cell_t cell; - bzero(q, sizeof(srslte_ue_cellsearch_t)); - + bzero(q, sizeof(srslte_ue_cellsearch_t)); + bzero(&cell, sizeof(srslte_cell_t)); - cell.id = SRSLTE_CELL_ID_UNKNOWN; - cell.nof_prb = SRSLTE_CS_NOF_PRB; + cell.id = SRSLTE_CELL_ID_UNKNOWN; + cell.nof_prb = SRSLTE_CS_NOF_PRB; if (srslte_ue_sync_init_multi(&q->ue_sync, cell.nof_prb, true, recv_callback, nof_rx_antennas, stream_handler)) { fprintf(stderr, "Error initiating ue_sync\n"); - goto clean_exit; + goto clean_exit; } if (srslte_ue_sync_set_cell(&q->ue_sync, cell)) { ERROR("Error setting cell in ue_sync\n"); @@ -128,22 +129,22 @@ int srslte_ue_cellsearch_init_multi(srslte_ue_cellsearch_t* q, q->candidates = calloc(sizeof(srslte_ue_cellsearch_result_t), max_frames); if (!q->candidates) { perror("malloc"); - goto clean_exit; + goto clean_exit; } q->mode_ntimes = calloc(sizeof(uint32_t), max_frames); if (!q->mode_ntimes) { perror("malloc"); - goto clean_exit; + goto clean_exit; } q->mode_counted = calloc(sizeof(uint8_t), max_frames); if (!q->mode_counted) { perror("malloc"); - goto clean_exit; + goto clean_exit; } - q->max_frames = max_frames; - q->nof_valid_frames = max_frames; - + q->max_frames = max_frames; + q->nof_valid_frames = max_frames; + ret = SRSLTE_SUCCESS; } @@ -154,7 +155,7 @@ clean_exit: return ret; } -void srslte_ue_cellsearch_free(srslte_ue_cellsearch_t * q) +void srslte_ue_cellsearch_free(srslte_ue_cellsearch_t* q) { for (int i = 0; i < q->nof_rx_antennas; i++) { if (q->sf_buffer[i]) { @@ -171,53 +172,52 @@ void srslte_ue_cellsearch_free(srslte_ue_cellsearch_t * q) free(q->mode_ntimes); } srslte_ue_sync_free(&q->ue_sync); - - bzero(q, sizeof(srslte_ue_cellsearch_t)); + bzero(q, sizeof(srslte_ue_cellsearch_t)); } -int srslte_ue_cellsearch_set_nof_valid_frames(srslte_ue_cellsearch_t * q, uint32_t nof_frames) +int srslte_ue_cellsearch_set_nof_valid_frames(srslte_ue_cellsearch_t* q, uint32_t nof_frames) { if (nof_frames <= q->max_frames) { - q->nof_valid_frames = nof_frames; - return SRSLTE_SUCCESS; + q->nof_valid_frames = nof_frames; + return SRSLTE_SUCCESS; } else { return SRSLTE_ERROR; } } /* Decide the most likely cell based on the mode */ -static void get_cell(srslte_ue_cellsearch_t * q, uint32_t nof_detected_frames, srslte_ue_cellsearch_result_t *found_cell) +static void get_cell(srslte_ue_cellsearch_t* q, uint32_t nof_detected_frames, srslte_ue_cellsearch_result_t* found_cell) { uint32_t i, j; - + bzero(q->mode_counted, nof_detected_frames); bzero(q->mode_ntimes, sizeof(uint32_t) * nof_detected_frames); - + /* First find mode of CELL IDs */ for (i = 0; i < nof_detected_frames; i++) { uint32_t cnt = 1; - for (j=i+1;jcandidates[j].cell_id == q->candidates[i].cell_id && !q->mode_counted[j]) { - q->mode_counted[j]=1; + q->mode_counted[j] = 1; cnt++; } } - q->mode_ntimes[i] = cnt; + q->mode_ntimes[i] = cnt; } - uint32_t max_times=0, mode_pos=0; - for (i=0;imode_ntimes[i] > max_times) { max_times = q->mode_ntimes[i]; - mode_pos = i; + mode_pos = i; } } found_cell->cell_id = q->candidates[mode_pos].cell_id; /* Now in all these cell IDs, find most frequent CP and duplex mode */ uint32_t nof_normal = 0; uint32_t nof_fdd = 0; - found_cell->peak = 0; - for (i=0;ipeak = 0; + for (i = 0; i < nof_detected_frames; i++) { if (q->candidates[i].cell_id == found_cell->cell_id) { if (SRSLTE_CP_ISNORM(q->candidates[i].cp)) { nof_normal++; @@ -226,12 +226,12 @@ static void get_cell(srslte_ue_cellsearch_t * q, uint32_t nof_detected_frames, s nof_fdd++; } } - // average absolute peak value - found_cell->peak += q->candidates[i].peak; + // average absolute peak value + found_cell->peak += q->candidates[i].peak; } found_cell->peak /= nof_detected_frames; - - if (nof_normal > q->mode_ntimes[mode_pos]/2) { + + if (nof_normal > q->mode_ntimes[mode_pos] / 2) { found_cell->cp = SRSLTE_CP_NORM; } else { found_cell->cp = SRSLTE_CP_EXT; @@ -241,64 +241,63 @@ static void get_cell(srslte_ue_cellsearch_t * q, uint32_t nof_detected_frames, s } else { found_cell->frame_type = SRSLTE_TDD; } - found_cell->mode = (float) q->mode_ntimes[mode_pos]/nof_detected_frames; - - // PSR is already averaged so take the last value - found_cell->psr = q->candidates[nof_detected_frames-1].psr; - - // CFO is also already averaged - found_cell->cfo = q->candidates[nof_detected_frames-1].cfo; + found_cell->mode = (float)q->mode_ntimes[mode_pos] / nof_detected_frames; + + // PSR is already averaged so take the last value + found_cell->psr = q->candidates[nof_detected_frames - 1].psr; + + // CFO is also already averaged + found_cell->cfo = q->candidates[nof_detected_frames - 1].cfo; } /** Finds up to 3 cells, one per each N_id_2=0,1,2 and stores ID and CP in the structure pointed by found_cell. - * Each position in found_cell corresponds to a different N_id_2. + * Each position in found_cell corresponds to a different N_id_2. * Saves in the pointer max_N_id_2 the N_id_2 index of the cell with the highest PSR * Returns the number of found cells or a negative number if error */ -int srslte_ue_cellsearch_scan(srslte_ue_cellsearch_t * q, - srslte_ue_cellsearch_result_t found_cells[3], - uint32_t *max_N_id_2) +int srslte_ue_cellsearch_scan(srslte_ue_cellsearch_t* q, + srslte_ue_cellsearch_result_t found_cells[3], + uint32_t* max_N_id_2) { - int ret = 0; - float max_peak_value = -1.0; + int ret = 0; + float max_peak_value = -1.0; uint32_t nof_detected_cells = 0; - for (uint32_t N_id_2=0;N_id_2<3 && ret >= 0;N_id_2++) { + for (uint32_t N_id_2 = 0; N_id_2 < 3 && ret >= 0; N_id_2++) { INFO("CELL SEARCH: Starting scan for N_id_2=%d\n", N_id_2); ret = srslte_ue_cellsearch_scan_N_id_2(q, N_id_2, &found_cells[N_id_2]); if (ret < 0) { ERROR("Error searching cell\n"); - return ret; + return ret; } nof_detected_cells += ret; if (max_N_id_2) { if (found_cells[N_id_2].peak > max_peak_value) { max_peak_value = found_cells[N_id_2].peak; - *max_N_id_2 = N_id_2; - } + *max_N_id_2 = N_id_2; + } } } return nof_detected_cells; } -/** Finds a cell for a given N_id_2 and stores ID and CP in the structure pointed by found_cell. +/** Finds a cell for a given N_id_2 and stores ID and CP in the structure pointed by found_cell. * Returns 1 if the cell is found, 0 if not or -1 on error */ -int srslte_ue_cellsearch_scan_N_id_2(srslte_ue_cellsearch_t * q, - uint32_t N_id_2, - srslte_ue_cellsearch_result_t *found_cell) +int srslte_ue_cellsearch_scan_N_id_2(srslte_ue_cellsearch_t* q, + uint32_t N_id_2, + srslte_ue_cellsearch_result_t* found_cell) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; - uint32_t nof_detected_frames = 0; - uint32_t nof_scanned_frames = 0; + int ret = SRSLTE_ERROR_INVALID_INPUTS; + uint32_t nof_detected_frames = 0; + uint32_t nof_scanned_frames = 0; - if (q != NULL) - { + if (q != NULL) { ret = SRSLTE_SUCCESS; - bzero(q->candidates, sizeof(srslte_ue_cellsearch_result_t)*q->max_frames); - bzero(q->mode_ntimes, sizeof(uint32_t)*q->max_frames); - bzero(q->mode_counted, sizeof(uint8_t)*q->max_frames); + bzero(q->candidates, sizeof(srslte_ue_cellsearch_result_t) * q->max_frames); + bzero(q->mode_ntimes, sizeof(uint32_t) * q->max_frames); + bzero(q->mode_counted, sizeof(uint8_t) * q->max_frames); srslte_ue_sync_set_N_id_2(&q->ue_sync, N_id_2); srslte_ue_sync_reset(&q->ue_sync); @@ -322,34 +321,34 @@ int srslte_ue_cellsearch_scan_N_id_2(srslte_ue_cellsearch_t * q, q->candidates[nof_detected_frames].cfo = 15000 * srslte_sync_get_cfo(&q->ue_sync.sfind); q->candidates[nof_detected_frames].frame_type = srslte_ue_sync_get_frame_type(&q->ue_sync); INFO("CELL SEARCH: [%d/%d/%d]: Found peak PSR=%.3f, Cell_id: %d CP: %s, CFO=%.1f KHz\n", - nof_detected_frames, - nof_scanned_frames, - q->nof_valid_frames, - q->candidates[nof_detected_frames].psr, - q->candidates[nof_detected_frames].cell_id, - srslte_cp_string(q->candidates[nof_detected_frames].cp), - q->candidates[nof_detected_frames].cfo / 1000); - - nof_detected_frames++; + nof_detected_frames, + nof_scanned_frames, + q->nof_valid_frames, + q->candidates[nof_detected_frames].psr, + q->candidates[nof_detected_frames].cell_id, + srslte_cp_string(q->candidates[nof_detected_frames].cp), + q->candidates[nof_detected_frames].cfo / 1000); + + nof_detected_frames++; } } else if (ret == 0) { - /* This means a peak is not yet found and ue_sync is in find state - * Do nothing, just wait and increase nof_scanned_frames counter. + /* This means a peak is not yet found and ue_sync is in find state + * Do nothing, just wait and increase nof_scanned_frames counter. */ } - + nof_scanned_frames++; - + } while (nof_scanned_frames < q->max_frames && nof_detected_frames < q->nof_valid_frames); - + /* In either case, check if the mean PSR is above the minimum threshold */ if (nof_detected_frames > 0) { - ret = 1; // A cell has been found. + ret = 1; // A cell has been found. if (found_cell) { - get_cell(q, nof_detected_frames, found_cell); + get_cell(q, nof_detected_frames, found_cell); } } else { - ret = 0; // A cell was not found. + ret = 0; // A cell was not found. } } diff --git a/lib/src/phy/ue/ue_cell_search_nbiot.c b/lib/src/phy/ue/ue_cell_search_nbiot.c index 7b3d668d2..18c492675 100644 --- a/lib/src/phy/ue/ue_cell_search_nbiot.c +++ b/lib/src/phy/ue/ue_cell_search_nbiot.c @@ -32,7 +32,7 @@ int srslte_ue_cellsearch_nbiot_init(srslte_ue_cellsearch_nbiot_t* q, uint32_t max_frames_total, - int(recv_callback)(void*, cf_t* [SRSLTE_MAX_PORTS], uint32_t, srslte_timestamp_t*), + int(recv_callback)(void*, cf_t * [SRSLTE_MAX_PORTS], uint32_t, srslte_timestamp_t*), void* stream_handler) { int ret = SRSLTE_ERROR_INVALID_INPUTS; @@ -132,7 +132,7 @@ int srslte_ue_cellsearch_nbiot_scan(srslte_ue_cellsearch_nbiot_t* q) } } else if (ret == 0) { //< This means a peak is not yet found and we are in find state, do nothing, just wait and increase - //nof_scanned_frames counter + // nof_scanned_frames counter nof_scanned_frames++; } } while (nof_scanned_frames < q->max_frames && nof_detected_frames < q->nof_valid_frames); diff --git a/lib/src/phy/ue/ue_dl.c b/lib/src/phy/ue/ue_dl.c index 452e3602c..adf1e28e0 100644 --- a/lib/src/phy/ue/ue_dl.c +++ b/lib/src/phy/ue/ue_dl.c @@ -799,8 +799,11 @@ int srslte_ue_dl_select_ri(srslte_ue_dl_t* q, uint32_t* ri, float* cn) return ret; } -void srslte_ue_dl_gen_cqi_periodic( - srslte_ue_dl_t* q, srslte_ue_dl_cfg_t* cfg, uint32_t wideband_value, uint32_t tti, srslte_uci_data_t* uci_data) +void srslte_ue_dl_gen_cqi_periodic(srslte_ue_dl_t* q, + srslte_ue_dl_cfg_t* cfg, + uint32_t wideband_value, + uint32_t tti, + srslte_uci_data_t* uci_data) { if (srslte_cqi_periodic_ri_send(&cfg->cfg.cqi_report, tti, q->cell.frame_type)) { /* Compute RI, PMI and SINR */ @@ -956,9 +959,9 @@ static void gen_ack_fdd(srslte_pdsch_ack_t* ack_info, srslte_uci_data_t* uci_dat } } else { // By default, in FDD we just pass through all HARQ-ACK bits - uint32_t tb_count = 0; + uint32_t tb_count = 0; uint32_t tb_count_cc0 = 0; - uint32_t n = 0; + uint32_t n = 0; for (uint32_t cc_idx = 0; cc_idx < ack_info->nof_cc; cc_idx++) { for (uint32_t tb = 0; tb < nof_tb; tb++, n++) { uci_data->value.ack.ack_value[n] = ack_info->cc[cc_idx].m[0].value[tb]; @@ -1027,8 +1030,8 @@ static void gen_ack_fdd(srslte_pdsch_ack_t* ack_info, srslte_uci_data_t* uci_dat } // Table 7.3-1 -static const uint32_t multiple_acknack[10][2] = { - {0, 0}, {1, 1}, {1, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 1}}; +static const uint32_t multiple_acknack[10][2] = + {{0, 0}, {1, 1}, {1, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 1}}; /* UE downlink procedure for reporting HARQ-ACK bits in TDD, Section 7.3 36.213 */ diff --git a/lib/src/phy/ue/ue_mib.c b/lib/src/phy/ue/ue_mib.c index 7cbffbe9e..fc1852738 100644 --- a/lib/src/phy/ue/ue_mib.c +++ b/lib/src/phy/ue/ue_mib.c @@ -31,18 +31,15 @@ #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" -int srslte_ue_mib_init(srslte_ue_mib_t * q, - cf_t *in_buffer[SRSLTE_MAX_PORTS], - uint32_t max_prb) +int srslte_ue_mib_init(srslte_ue_mib_t* q, cf_t* in_buffer[SRSLTE_MAX_PORTS], uint32_t max_prb) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL) - { + if (q != NULL) { - ret = SRSLTE_ERROR; + ret = SRSLTE_ERROR; bzero(q, sizeof(srslte_ue_mib_t)); - + if (srslte_pbch_init(&q->pbch)) { ERROR("Error initiating PBCH\n"); goto clean_exit; @@ -78,7 +75,7 @@ clean_exit: return ret; } -void srslte_ue_mib_free(srslte_ue_mib_t * q) +void srslte_ue_mib_free(srslte_ue_mib_t* q) { if (q->sf_symbols[0]) { free(q->sf_symbols[0]); @@ -88,19 +85,15 @@ void srslte_ue_mib_free(srslte_ue_mib_t * q) srslte_chest_dl_free(&q->chest); srslte_pbch_free(&q->pbch); srslte_ofdm_rx_free(&q->fft); - + bzero(q, sizeof(srslte_ue_mib_t)); - } -int srslte_ue_mib_set_cell(srslte_ue_mib_t * q, - srslte_cell_t cell) +int srslte_ue_mib_set_cell(srslte_ue_mib_t* q, srslte_cell_t cell) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && - cell.nof_ports <= SRSLTE_MAX_PORTS) - { + if (q != NULL && cell.nof_ports <= SRSLTE_MAX_PORTS) { if (srslte_pbch_set_cell(&q->pbch, cell)) { ERROR("Error initiating PBCH\n"); return SRSLTE_ERROR; @@ -125,15 +118,16 @@ int srslte_ue_mib_set_cell(srslte_ue_mib_t * q, return ret; } - -void srslte_ue_mib_reset(srslte_ue_mib_t * q) +void srslte_ue_mib_reset(srslte_ue_mib_t* q) { - q->frame_cnt = 0; + q->frame_cnt = 0; srslte_pbch_decode_reset(&q->pbch); } -int srslte_ue_mib_decode(srslte_ue_mib_t * q, - uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, int *sfn_offset) +int srslte_ue_mib_decode(srslte_ue_mib_t* q, + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], + uint32_t* nof_tx_ports, + int* sfn_offset) { int ret = SRSLTE_SUCCESS; @@ -162,13 +156,13 @@ int srslte_ue_mib_decode(srslte_ue_mib_t * q, } else if (ret == 1) { INFO("MIB decoded: %u, snr=%.1f dB\n", q->frame_cnt, q->chest_res.snr_db); srslte_ue_mib_reset(q); - ret = SRSLTE_UE_MIB_FOUND; + ret = SRSLTE_UE_MIB_FOUND; } else { ret = SRSLTE_UE_MIB_NOTFOUND; INFO("MIB not decoded: %u, snr=%.1f dB\n", q->frame_cnt, q->chest_res.snr_db); q->frame_cnt++; - } - + } + return ret; } @@ -186,7 +180,8 @@ int srslte_ue_mib_sync_init_multi(srslte_ue_mib_sync_t* q, ERROR("Error initiating ue_mib\n"); return SRSLTE_ERROR; } - if (srslte_ue_sync_init_multi(&q->ue_sync, SRSLTE_UE_MIB_NOF_PRB, false, recv_callback, nof_rx_antennas, stream_handler)) { + if (srslte_ue_sync_init_multi( + &q->ue_sync, SRSLTE_UE_MIB_NOF_PRB, false, recv_callback, nof_rx_antennas, stream_handler)) { fprintf(stderr, "Error initiating ue_sync\n"); srslte_ue_mib_free(&q->ue_mib); return SRSLTE_ERROR; @@ -214,9 +209,9 @@ int srslte_ue_mib_sync_set_cell(srslte_ue_mib_sync_t* q, srslte_cell_t cell) return SRSLTE_SUCCESS; } - -void srslte_ue_mib_sync_free(srslte_ue_mib_sync_t *q) { - for (int i=0;inof_rx_antennas;i++) { +void srslte_ue_mib_sync_free(srslte_ue_mib_sync_t* q) +{ + for (int i = 0; i < q->nof_rx_antennas; i++) { if (q->sf_buffer[i]) { free(q->sf_buffer[i]); } @@ -225,24 +220,24 @@ void srslte_ue_mib_sync_free(srslte_ue_mib_sync_t *q) { srslte_ue_sync_free(&q->ue_sync); } -void srslte_ue_mib_sync_reset(srslte_ue_mib_sync_t * q) { +void srslte_ue_mib_sync_reset(srslte_ue_mib_sync_t* q) +{ srslte_ue_mib_reset(&q->ue_mib); srslte_ue_sync_reset(&q->ue_sync); } -int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t * q, - uint32_t max_frames_timeout, - uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], - uint32_t *nof_tx_ports, - int *sfn_offset) +int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t* q, + uint32_t max_frames_timeout, + uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], + uint32_t* nof_tx_ports, + int* sfn_offset) { - - int ret = SRSLTE_ERROR_INVALID_INPUTS; - uint32_t nof_frames = 0; - int mib_ret = SRSLTE_UE_MIB_NOTFOUND; - if (q != NULL) - { + int ret = SRSLTE_ERROR_INVALID_INPUTS; + uint32_t nof_frames = 0; + int mib_ret = SRSLTE_UE_MIB_NOTFOUND; + + if (q != NULL) { srslte_ue_mib_sync_reset(q); ret = SRSLTE_SUCCESS; @@ -263,10 +258,8 @@ int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t * q, } } while (mib_ret == SRSLTE_UE_MIB_NOTFOUND && ret >= 0 && nof_frames < max_frames_timeout); if (mib_ret < 0) { - ret = mib_ret; + ret = mib_ret; } } - return mib_ret; + return mib_ret; } - - diff --git a/lib/src/phy/ue/ue_mib_nbiot.c b/lib/src/phy/ue/ue_mib_nbiot.c index 39fa5b99e..1d1d6690f 100644 --- a/lib/src/phy/ue/ue_mib_nbiot.c +++ b/lib/src/phy/ue/ue_mib_nbiot.c @@ -186,7 +186,7 @@ int srslte_ue_mib_nbiot_decode(srslte_ue_mib_nbiot_t* q, int srslte_ue_mib_sync_nbiot_init_multi( srslte_ue_mib_sync_nbiot_t* q, - int(recv_callback)(void*, cf_t* [SRSLTE_MAX_PORTS], uint32_t, srslte_timestamp_t*), + int(recv_callback)(void*, cf_t * [SRSLTE_MAX_PORTS], uint32_t, srslte_timestamp_t*), uint32_t nof_rx_antennas, void* stream_handler) { @@ -247,7 +247,7 @@ int srslte_ue_mib_sync_nbiot_decode(srslte_ue_mib_sync_nbiot_t* q, int mib_ret = SRSLTE_UE_MIB_NBIOT_NOTFOUND; if (q != NULL) { - int ret = SRSLTE_SUCCESS; + int ret = SRSLTE_SUCCESS; uint32_t nof_frames = 0; do { mib_ret = SRSLTE_UE_MIB_NBIOT_NOTFOUND; diff --git a/lib/src/phy/ue/ue_sync.c b/lib/src/phy/ue/ue_sync.c index 2b56d5b3e..43cfab0f3 100644 --- a/lib/src/phy/ue/ue_sync.c +++ b/lib/src/phy/ue/ue_sync.c @@ -19,13 +19,12 @@ * */ +#include "srslte/srslte.h" +#include #include #include #include -#include #include -#include "srslte/srslte.h" - #include "srslte/phy/ue/ue_sync.h" @@ -37,7 +36,7 @@ #define TRACK_MAX_LOST 10 #define TRACK_FRAME_SIZE 32 -#define FIND_NOF_AVG_FRAMES 4 +#define FIND_NOF_AVG_FRAMES 4 #define PSS_OFFSET \ (q->sf_len / 2 + ((q->cell.frame_type == SRSLTE_FDD) \ @@ -48,48 +47,52 @@ static cf_t dummy_buffer0[15 * 2048 / 2]; static cf_t dummy_buffer1[15 * 2048 / 2]; static cf_t* dummy_offset_buffer[SRSLTE_MAX_PORTS] = {dummy_buffer0, dummy_buffer1, dummy_buffer1, dummy_buffer1}; -int srslte_ue_sync_init_file(srslte_ue_sync_t *q, uint32_t nof_prb, char *file_name, int offset_time, float offset_freq) { +int srslte_ue_sync_init_file(srslte_ue_sync_t* q, uint32_t nof_prb, char* file_name, int offset_time, float offset_freq) +{ return srslte_ue_sync_init_file_multi(q, nof_prb, file_name, offset_time, offset_freq, 1); } -void srslte_ue_sync_file_wrap(srslte_ue_sync_t *q, bool enable) { +void srslte_ue_sync_file_wrap(srslte_ue_sync_t* q, bool enable) +{ q->file_wrap_enable = enable; } -int srslte_ue_sync_init_file_multi(srslte_ue_sync_t *q, uint32_t nof_prb, char *file_name, int offset_time, - float offset_freq, uint32_t nof_rx_ant) { +int srslte_ue_sync_init_file_multi(srslte_ue_sync_t* q, + uint32_t nof_prb, + char* file_name, + int offset_time, + float offset_freq, + uint32_t nof_rx_ant) +{ int ret = SRSLTE_ERROR_INVALID_INPUTS; - - if (q != NULL && - file_name != NULL && - srslte_nofprb_isvalid(nof_prb)) - { + + if (q != NULL && file_name != NULL && srslte_nofprb_isvalid(nof_prb)) { ret = SRSLTE_ERROR; bzero(q, sizeof(srslte_ue_sync_t)); - q->file_mode = true; + q->file_mode = true; q->file_wrap_enable = true; - q->sf_len = SRSLTE_SF_LEN(srslte_symbol_sz(nof_prb)); - q->file_cfo = -offset_freq; - q->fft_size = srslte_symbol_sz(nof_prb); - q->nof_rx_antennas = nof_rx_ant; + q->sf_len = SRSLTE_SF_LEN(srslte_symbol_sz(nof_prb)); + q->file_cfo = -offset_freq; + q->fft_size = srslte_symbol_sz(nof_prb); + q->nof_rx_antennas = nof_rx_ant; q->cfo_correct_enable_find = false; q->cfo_correct_enable_track = true; if (srslte_cfo_init(&q->file_cfo_correct, 2 * q->sf_len)) { ERROR("Error initiating CFO\n"); - goto clean_exit; + goto clean_exit; } if (srslte_filesource_init(&q->file_source, file_name, SRSLTE_COMPLEX_FLOAT_BIN)) { ERROR("Error opening file %s\n", file_name); - goto clean_exit; + goto clean_exit; } - - INFO("Offseting input file by %d samples and %.1f kHz\n", offset_time, offset_freq/1000); + + INFO("Offseting input file by %d samples and %.1f kHz\n", offset_time, offset_freq / 1000); if (offset_time) { - cf_t *file_offset_buffer = srslte_vec_malloc(offset_time * nof_rx_ant * sizeof(cf_t)); + cf_t* file_offset_buffer = srslte_vec_malloc(offset_time * nof_rx_ant * sizeof(cf_t)); if (!file_offset_buffer) { perror("malloc"); goto clean_exit; @@ -100,17 +103,17 @@ int srslte_ue_sync_init_file_multi(srslte_ue_sync_t *q, uint32_t nof_prb, char * srslte_ue_sync_cfo_reset(q); srslte_ue_sync_reset(q); - + ret = SRSLTE_SUCCESS; } clean_exit: if (ret == SRSLTE_ERROR) { srslte_ue_sync_free(q); } - return ret; + return ret; } -void srslte_ue_sync_cfo_reset(srslte_ue_sync_t *q) +void srslte_ue_sync_cfo_reset(srslte_ue_sync_t* q) { q->cfo_is_copied = false; q->cfo_current_value = 0; @@ -118,7 +121,8 @@ void srslte_ue_sync_cfo_reset(srslte_ue_sync_t *q) srslte_sync_cfo_reset(&q->sfind); } -void srslte_ue_sync_reset(srslte_ue_sync_t *q) { +void srslte_ue_sync_reset(srslte_ue_sync_t* q) +{ if (!q->file_mode) { srslte_sync_reset(&q->sfind); @@ -126,47 +130,48 @@ void srslte_ue_sync_reset(srslte_ue_sync_t *q) { } else { q->sf_idx = 9; } - q->pss_stable_timeout = false; - q->state = SF_FIND; - q->frame_ok_cnt = 0; - q->frame_no_cnt = 0; - q->frame_total_cnt = 0; - q->mean_sample_offset = 0.0; + q->pss_stable_timeout = false; + q->state = SF_FIND; + q->frame_ok_cnt = 0; + q->frame_no_cnt = 0; + q->frame_total_cnt = 0; + q->mean_sample_offset = 0.0; q->next_rf_sample_offset = 0; - q->frame_find_cnt = 0; + q->frame_find_cnt = 0; } -int srslte_ue_sync_start_agc(srslte_ue_sync_t *q, - float (set_gain_callback)(void *, float), +int srslte_ue_sync_start_agc(srslte_ue_sync_t* q, + float(set_gain_callback)(void*, float), float min_gain_db, float max_gain_db, - float init_gain_value_db) { - int n = srslte_agc_init_uhd(&q->agc, SRSLTE_AGC_MODE_PEAK_AMPLITUDE, 0, set_gain_callback, q->stream); - q->do_agc = n==0?true:false; + float init_gain_value_db) +{ + int n = srslte_agc_init_uhd(&q->agc, SRSLTE_AGC_MODE_PEAK_AMPLITUDE, 0, set_gain_callback, q->stream); + q->do_agc = n == 0 ? true : false; if (q->do_agc) { srslte_agc_set_gain_range(&q->agc, min_gain_db, max_gain_db); srslte_agc_set_gain(&q->agc, init_gain_value_db); srslte_ue_sync_set_agc_period(q, 4); } - return n; + return n; } -int recv_callback_multi_to_single(void *h, cf_t *x[SRSLTE_MAX_PORTS], uint32_t nsamples, srslte_timestamp_t*t) +int recv_callback_multi_to_single(void* h, cf_t* x[SRSLTE_MAX_PORTS], uint32_t nsamples, srslte_timestamp_t* t) { - srslte_ue_sync_t *q = (srslte_ue_sync_t*) h; - return q->recv_callback_single(q->stream_single, (void*) x[0], nsamples, t); + srslte_ue_sync_t* q = (srslte_ue_sync_t*)h; + return q->recv_callback_single(q->stream_single, (void*)x[0], nsamples, t); } -int srslte_ue_sync_init(srslte_ue_sync_t *q, - uint32_t max_prb, - bool search_cell, - int (recv_callback)(void*, void*, uint32_t,srslte_timestamp_t*), - void *stream_handler) +int srslte_ue_sync_init(srslte_ue_sync_t* q, + uint32_t max_prb, + bool search_cell, + int(recv_callback)(void*, void*, uint32_t, srslte_timestamp_t*), + void* stream_handler) { - int ret = srslte_ue_sync_init_multi(q, max_prb, search_cell, recv_callback_multi_to_single, 1, (void*) q); + int ret = srslte_ue_sync_init_multi(q, max_prb, search_cell, recv_callback_multi_to_single, 1, (void*)q); q->recv_callback_single = recv_callback; - q->stream_single = stream_handler; - return ret; + q->stream_single = stream_handler; + return ret; } int srslte_ue_sync_init_multi(srslte_ue_sync_t* q, @@ -181,40 +186,36 @@ int srslte_ue_sync_init_multi(srslte_ue_sync_t* q, return srslte_ue_sync_init_multi_decim(q, max_prb, search_cell, recv_callback, nof_rx_antennas, stream_handler, 1); } -int srslte_ue_sync_init_multi_decim(srslte_ue_sync_t *q, - uint32_t max_prb, - bool search_cell, - int (recv_callback)(void*, cf_t*[SRSLTE_MAX_PORTS], uint32_t,srslte_timestamp_t*), +int srslte_ue_sync_init_multi_decim(srslte_ue_sync_t* q, + uint32_t max_prb, + bool search_cell, + int(recv_callback)(void*, cf_t * [SRSLTE_MAX_PORTS], uint32_t, srslte_timestamp_t*), uint32_t nof_rx_antennas, - void *stream_handler, - int decimate) + void* stream_handler, + int decimate) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - - if (q != NULL && - stream_handler != NULL && - nof_rx_antennas <= SRSLTE_MAX_PORTS && - recv_callback != NULL) - { + + if (q != NULL && stream_handler != NULL && nof_rx_antennas <= SRSLTE_MAX_PORTS && recv_callback != NULL) { ret = SRSLTE_ERROR; - //int decimate = q->decimate; + // int decimate = q->decimate; bzero(q, sizeof(srslte_ue_sync_t)); - q->decimate = decimate; - q->stream = stream_handler; - q->recv_callback = recv_callback; - q->nof_rx_antennas = nof_rx_antennas; - q->fft_size = srslte_symbol_sz(max_prb); - q->sf_len = SRSLTE_SF_LEN(q->fft_size); - q->file_mode = false; - q->agc_period = 0; - q->sample_offset_correct_period = DEFAULT_SAMPLE_OFFSET_CORRECT_PERIOD; - q->sfo_ema = DEFAULT_SFO_EMA_COEFF; + q->decimate = decimate; + q->stream = stream_handler; + q->recv_callback = recv_callback; + q->nof_rx_antennas = nof_rx_antennas; + q->fft_size = srslte_symbol_sz(max_prb); + q->sf_len = SRSLTE_SF_LEN(q->fft_size); + q->file_mode = false; + q->agc_period = 0; + q->sample_offset_correct_period = DEFAULT_SAMPLE_OFFSET_CORRECT_PERIOD; + q->sfo_ema = DEFAULT_SFO_EMA_COEFF; q->max_prb = max_prb; - q->cfo_ref_max = DEFAULT_CFO_REF_MAX; - q->cfo_ref_min = DEFAULT_CFO_REF_MIN; - q->cfo_pss_min = DEFAULT_CFO_PSS_MIN; + q->cfo_ref_max = DEFAULT_CFO_REF_MAX; + q->cfo_ref_min = DEFAULT_CFO_REF_MIN; + q->cfo_pss_min = DEFAULT_CFO_PSS_MIN; q->cfo_loop_bw_pss = DEFAULT_CFO_BW_PSS; q->cfo_loop_bw_ref = DEFAULT_CFO_BW_REF; @@ -225,21 +226,20 @@ int srslte_ue_sync_init_multi_decim(srslte_ue_sync_t *q, q->pss_stable_timeout = DEFAULT_PSS_STABLE_TIMEOUT; if (search_cell) { - + /* If the cell is unkown, we search PSS/SSS in 5 ms */ - q->nof_recv_sf = 5; + q->nof_recv_sf = 5; } else { - - /* If the cell is known, we work on a 1ms basis */ - q->nof_recv_sf = 1; + /* If the cell is known, we work on a 1ms basis */ + q->nof_recv_sf = 1; } - q->frame_len = q->nof_recv_sf*q->sf_len; - - if(q->fft_size < 700 && q->decimate) { - q->decimate = 1; + q->frame_len = q->nof_recv_sf * q->sf_len; + + if (q->fft_size < 700 && q->decimate) { + q->decimate = 1; } if (srslte_sync_init_decim(&q->sfind, q->frame_len, q->frame_len, q->fft_size, q->decimate)) { @@ -262,16 +262,16 @@ int srslte_ue_sync_init_multi_decim(srslte_ue_sync_t *q, } // Configure FIND and TRACK sync objects behaviour (this configuration is always the same) - srslte_sync_set_cfo_i_enable(&q->sfind, false); - srslte_sync_set_cfo_pss_enable(&q->sfind, true); - srslte_sync_set_pss_filt_enable(&q->sfind, true); - srslte_sync_set_sss_eq_enable(&q->sfind, false); + srslte_sync_set_cfo_i_enable(&q->sfind, false); + srslte_sync_set_cfo_pss_enable(&q->sfind, true); + srslte_sync_set_pss_filt_enable(&q->sfind, true); + srslte_sync_set_sss_eq_enable(&q->sfind, false); // During track, we do CFO correction outside the sync object - srslte_sync_set_cfo_i_enable(&q->strack, false); - srslte_sync_set_cfo_pss_enable(&q->strack, true); + srslte_sync_set_cfo_i_enable(&q->strack, false); + srslte_sync_set_cfo_pss_enable(&q->strack, true); srslte_sync_set_pss_filt_enable(&q->strack, true); - srslte_sync_set_sss_eq_enable(&q->strack, false); + srslte_sync_set_sss_eq_enable(&q->strack, false); // FIXME: CP detection not working very well. Not supporting Extended CP right now srslte_sync_cp_en(&q->strack, false); @@ -291,11 +291,13 @@ clean_exit: return ret; } -uint32_t srslte_ue_sync_sf_len(srslte_ue_sync_t *q) { +uint32_t srslte_ue_sync_sf_len(srslte_ue_sync_t* q) +{ return q->frame_len; } -void srslte_ue_sync_free(srslte_ue_sync_t *q) { +void srslte_ue_sync_free(srslte_ue_sync_t* q) +{ if (q->do_agc) { srslte_agc_free(&q->agc); } @@ -308,8 +310,7 @@ void srslte_ue_sync_free(srslte_ue_sync_t *q) { bzero(q, sizeof(srslte_ue_sync_t)); } - -int srslte_ue_sync_set_cell(srslte_ue_sync_t *q, srslte_cell_t cell) +int srslte_ue_sync_set_cell(srslte_ue_sync_t* q, srslte_cell_t cell) { int ret = SRSLTE_ERROR_INVALID_INPUTS; @@ -321,7 +322,7 @@ int srslte_ue_sync_set_cell(srslte_ue_sync_t *q, srslte_cell_t cell) q->cell = cell; q->fft_size = srslte_symbol_sz(q->cell.nof_prb); - q->sf_len = SRSLTE_SF_LEN(q->fft_size); + q->sf_len = SRSLTE_SF_LEN(q->fft_size); if (cell.id == 1000) { @@ -333,18 +334,18 @@ int srslte_ue_sync_set_cell(srslte_ue_sync_t *q, srslte_cell_t cell) q->nof_recv_sf = 1; } - q->frame_len = q->nof_recv_sf*q->sf_len; + q->frame_len = q->nof_recv_sf * q->sf_len; - if(q->fft_size < 700 && q->decimate) { + if (q->fft_size < 700 && q->decimate) { q->decimate = 1; } - if(srslte_sync_resize(&q->sfind, q->frame_len, q->frame_len, q->fft_size)) { + if (srslte_sync_resize(&q->sfind, q->frame_len, q->frame_len, q->fft_size)) { ERROR("Error setting cell sync find\n"); return SRSLTE_ERROR; } if (cell.id == 1000) { - if(srslte_sync_resize(&q->strack, q->frame_len, TRACK_FRAME_SIZE, q->fft_size)) { + if (srslte_sync_resize(&q->strack, q->frame_len, TRACK_FRAME_SIZE, q->fft_size)) { ERROR("Error setting cell sync track\n"); return SRSLTE_ERROR; } @@ -363,15 +364,15 @@ int srslte_ue_sync_set_cell(srslte_ue_sync_t *q, srslte_cell_t cell) if (cell.id == 1000) { q->nof_avg_find_frames = FIND_NOF_AVG_FRAMES; - srslte_sync_set_cfo_ema_alpha(&q->sfind, 0.8); + srslte_sync_set_cfo_ema_alpha(&q->sfind, 0.8); srslte_sync_set_cfo_ema_alpha(&q->strack, 0.1); - srslte_sync_set_em_alpha(&q->sfind, 1); + srslte_sync_set_em_alpha(&q->sfind, 1); - srslte_sync_set_threshold(&q->sfind, 2.0); + srslte_sync_set_threshold(&q->sfind, 2.0); srslte_sync_set_threshold(&q->strack, 1.2); - srslte_sync_set_cfo_ema_alpha(&q->sfind, 0.1); + srslte_sync_set_cfo_ema_alpha(&q->sfind, 0.1); srslte_sync_set_cfo_ema_alpha(&q->strack, 0.1); } else { @@ -382,28 +383,28 @@ int srslte_ue_sync_set_cell(srslte_ue_sync_t *q, srslte_cell_t cell) srslte_sync_set_frame_type(&q->strack, cell.frame_type); srslte_sync_set_N_id_2(&q->sfind, cell.id % 3); - srslte_sync_set_N_id_2(&q->strack, cell.id%3); + srslte_sync_set_N_id_2(&q->strack, cell.id % 3); srslte_sync_set_N_id_1(&q->sfind, cell.id / 3); // track does not correlate SSS so no need to generate sequences - srslte_sync_set_cfo_ema_alpha(&q->sfind, 0.1); + srslte_sync_set_cfo_ema_alpha(&q->sfind, 0.1); srslte_sync_set_cfo_ema_alpha(&q->strack, DEFAULT_CFO_EMA_TRACK); /* In find phase and if the cell is known, do not average pss correlation * because we only capture 1 subframe and do not know where the peak is. */ q->nof_avg_find_frames = 1; - srslte_sync_set_em_alpha(&q->sfind, 1); - srslte_sync_set_threshold(&q->sfind, 3.0); + srslte_sync_set_em_alpha(&q->sfind, 1); + srslte_sync_set_threshold(&q->sfind, 3.0); - srslte_sync_set_em_alpha(&q->strack, 0.0); + srslte_sync_set_em_alpha(&q->strack, 0.0); srslte_sync_set_threshold(&q->strack, 1.5); } // When cell is unknown, do CP CFO correction - srslte_sync_set_cfo_cp_enable(&q->sfind, true, q->frame_len<10000?14:3); - q->cfo_correct_enable_find = false; + srslte_sync_set_cfo_cp_enable(&q->sfind, true, q->frame_len < 10000 ? 14 : 3); + q->cfo_correct_enable_find = false; srslte_ue_sync_reset(q); @@ -429,91 +430,108 @@ srslte_frame_type_t srslte_ue_sync_get_frame_type(srslte_ue_sync_t* q) return q->sfind.frame_type; } -void srslte_ue_sync_get_last_timestamp(srslte_ue_sync_t *q, srslte_timestamp_t *timestamp) { +void srslte_ue_sync_get_last_timestamp(srslte_ue_sync_t* q, srslte_timestamp_t* timestamp) +{ *timestamp = q->last_timestamp; } -void srslte_ue_sync_set_cfo_loop_bw(srslte_ue_sync_t *q, float bw_pss, float bw_ref, - float pss_tol, float ref_tol, float ref_max, - uint32_t pss_stable_conv_time) { - q->cfo_loop_bw_pss = bw_pss; - q->cfo_loop_bw_ref = bw_ref; - q->cfo_pss_min = pss_tol; - q->cfo_ref_min = ref_tol; - q->cfo_ref_max = ref_max; +void srslte_ue_sync_set_cfo_loop_bw(srslte_ue_sync_t* q, + float bw_pss, + float bw_ref, + float pss_tol, + float ref_tol, + float ref_max, + uint32_t pss_stable_conv_time) +{ + q->cfo_loop_bw_pss = bw_pss; + q->cfo_loop_bw_ref = bw_ref; + q->cfo_pss_min = pss_tol; + q->cfo_ref_min = ref_tol; + q->cfo_ref_max = ref_max; q->pss_stable_timeout = pss_stable_conv_time; } -void srslte_ue_sync_set_cfo_ema(srslte_ue_sync_t *q, float ema) { +void srslte_ue_sync_set_cfo_ema(srslte_ue_sync_t* q, float ema) +{ srslte_sync_set_cfo_ema_alpha(&q->strack, ema); } -void srslte_ue_sync_set_cfo_ref(srslte_ue_sync_t *q, float ref_cfo) +void srslte_ue_sync_set_cfo_ref(srslte_ue_sync_t* q, float ref_cfo) { // Accept REF-based CFO adjustments only after PSS CFO is stable if (q->pss_is_stable) { - if (fabsf(ref_cfo)*15000 > q->cfo_ref_min) { - if (fabsf(ref_cfo)*15000 > q->cfo_ref_max) { - ref_cfo = (ref_cfo>0?q->cfo_ref_max:-q->cfo_ref_max)/15000; + if (fabsf(ref_cfo) * 15000 > q->cfo_ref_min) { + if (fabsf(ref_cfo) * 15000 > q->cfo_ref_max) { + ref_cfo = (ref_cfo > 0 ? q->cfo_ref_max : -q->cfo_ref_max) / 15000; } - q->cfo_current_value += ref_cfo*q->cfo_loop_bw_ref; + q->cfo_current_value += ref_cfo * q->cfo_loop_bw_ref; } } } -uint32_t srslte_ue_sync_get_sfidx(srslte_ue_sync_t *q) { - return q->sf_idx; +uint32_t srslte_ue_sync_get_sfidx(srslte_ue_sync_t* q) +{ + return q->sf_idx; } -void srslte_ue_sync_set_cfo_i_enable(srslte_ue_sync_t *q, bool enable) { +void srslte_ue_sync_set_cfo_i_enable(srslte_ue_sync_t* q, bool enable) +{ printf("Warning: Setting integer CFO detection/correction. This is experimental!\n"); srslte_sync_set_cfo_i_enable(&q->strack, enable); - srslte_sync_set_cfo_i_enable(&q->sfind, enable); + srslte_sync_set_cfo_i_enable(&q->sfind, enable); } -float srslte_ue_sync_get_cfo(srslte_ue_sync_t *q) { +float srslte_ue_sync_get_cfo(srslte_ue_sync_t* q) +{ return 15000 * q->cfo_current_value; } -void srslte_ue_sync_copy_cfo(srslte_ue_sync_t *q, srslte_ue_sync_t *src_obj) { +void srslte_ue_sync_copy_cfo(srslte_ue_sync_t* q, srslte_ue_sync_t* src_obj) +{ // Copy find object internal CFO averages - srslte_sync_copy_cfo(&q->sfind, &src_obj->sfind); + srslte_sync_copy_cfo(&q->sfind, &src_obj->sfind); // Current CFO is tracking-phase CFO of previous object q->cfo_current_value = src_obj->cfo_current_value; - q->cfo_is_copied = true; + q->cfo_is_copied = true; } -void srslte_ue_sync_set_cfo_tol(srslte_ue_sync_t *q, float cfo_tol) { +void srslte_ue_sync_set_cfo_tol(srslte_ue_sync_t* q, float cfo_tol) +{ srslte_sync_set_cfo_tol(&q->strack, cfo_tol); srslte_sync_set_cfo_tol(&q->sfind, cfo_tol); } -float srslte_ue_sync_get_sfo(srslte_ue_sync_t *q) { - return q->mean_sample_offset/5e-3; +float srslte_ue_sync_get_sfo(srslte_ue_sync_t* q) +{ + return q->mean_sample_offset / 5e-3; } -int srslte_ue_sync_get_last_sample_offset(srslte_ue_sync_t *q) { - return q->last_sample_offset; +int srslte_ue_sync_get_last_sample_offset(srslte_ue_sync_t* q) +{ + return q->last_sample_offset; } -void srslte_ue_sync_set_sfo_correct_period(srslte_ue_sync_t *q, uint32_t nof_subframes) { - q->sample_offset_correct_period = nof_subframes; +void srslte_ue_sync_set_sfo_correct_period(srslte_ue_sync_t* q, uint32_t nof_subframes) +{ + q->sample_offset_correct_period = nof_subframes; } -void srslte_ue_sync_set_sfo_ema(srslte_ue_sync_t *q, float ema_coefficient) { - q->sfo_ema = ema_coefficient; +void srslte_ue_sync_set_sfo_ema(srslte_ue_sync_t* q, float ema_coefficient) +{ + q->sfo_ema = ema_coefficient; } - -void srslte_ue_sync_set_N_id_2(srslte_ue_sync_t *q, uint32_t N_id_2) { +void srslte_ue_sync_set_N_id_2(srslte_ue_sync_t* q, uint32_t N_id_2) +{ if (!q->file_mode) { srslte_ue_sync_reset(q); srslte_sync_set_N_id_2(&q->strack, N_id_2); - srslte_sync_set_N_id_2(&q->sfind, N_id_2); + srslte_sync_set_N_id_2(&q->sfind, N_id_2); } } -void srslte_ue_sync_set_agc_period(srslte_ue_sync_t *q, uint32_t period) { +void srslte_ue_sync_set_agc_period(srslte_ue_sync_t* q, uint32_t period) +{ q->agc_period = period; } @@ -542,7 +560,7 @@ static int find_peak_ok(srslte_ue_sync_t* q, cf_t* input_buffer[SRSLTE_MAX_PORTS q->cell.id, srslte_cp_string(q->cell.cp)); - if (q->frame_find_cnt >= q->nof_avg_find_frames || q->peak_idx < 2*q->fft_size) { + if (q->frame_find_cnt >= q->nof_avg_find_frames || q->peak_idx < 2 * q->fft_size) { // Receive read_len samples until the start of the next subframe (different for FDD and TDD) uint32_t read_len = q->peak_idx + PSS_OFFSET; INFO("Realigning frame, reading %d samples\n", read_len); @@ -579,24 +597,25 @@ static int find_peak_ok(srslte_ue_sync_t* q, cf_t* input_buffer[SRSLTE_MAX_PORTS static int track_peak_ok(srslte_ue_sync_t* q, uint32_t track_idx) { - // Get sampling time offset - q->last_sample_offset = ((int) track_idx - (int) q->strack.max_offset/2 - (int) q->strack.fft_size); - + // Get sampling time offset + q->last_sample_offset = ((int)track_idx - (int)q->strack.max_offset / 2 - (int)q->strack.fft_size); + // Adjust sampling time every q->sample_offset_correct_period subframes - uint32_t frame_idx = 0; + uint32_t frame_idx = 0; if (q->sample_offset_correct_period) { - frame_idx = q->frame_ok_cnt%q->sample_offset_correct_period; - q->mean_sample_offset = SRSLTE_VEC_EMA((float) q->last_sample_offset, q->mean_sample_offset, q->sfo_ema); - } else { - q->mean_sample_offset = q->last_sample_offset; + frame_idx = q->frame_ok_cnt % q->sample_offset_correct_period; + q->mean_sample_offset = SRSLTE_VEC_EMA((float)q->last_sample_offset, q->mean_sample_offset, q->sfo_ema); + } else { + q->mean_sample_offset = q->last_sample_offset; } /* Adjust current CFO estimation with PSS * Since sync track has enabled only PSS-based correlation, get_cfo() returns that value only, already filtered. */ - DEBUG("TRACK: cfo_current=%f, cfo_strack=%f\n", 15000*q->cfo_current_value, 15000*srslte_sync_get_cfo(&q->strack)); - if (15000*fabsf(srslte_sync_get_cfo(&q->strack)) > q->cfo_pss_min) { - q->cfo_current_value += srslte_sync_get_cfo(&q->strack)*q->cfo_loop_bw_pss; + DEBUG( + "TRACK: cfo_current=%f, cfo_strack=%f\n", 15000 * q->cfo_current_value, 15000 * srslte_sync_get_cfo(&q->strack)); + if (15000 * fabsf(srslte_sync_get_cfo(&q->strack)) > q->cfo_pss_min) { + q->cfo_current_value += srslte_sync_get_cfo(&q->strack) * q->cfo_loop_bw_pss; q->pss_stable_cnt = 0; q->pss_is_stable = false; } else { @@ -611,52 +630,54 @@ static int track_peak_ok(srslte_ue_sync_t* q, uint32_t track_idx) // Compute cumulative moving average time offset */ if (!frame_idx) { // Adjust RF sampling time based on the mean sampling offset - q->next_rf_sample_offset = (int) round(q->mean_sample_offset); + q->next_rf_sample_offset = (int)round(q->mean_sample_offset); if (q->next_rf_sample_offset) { INFO("Time offset adjustment: %d samples (%.2f), mean SFO: %.2f Hz, ema=%f, length=%d\n", - q->next_rf_sample_offset, q->mean_sample_offset, - srslte_ue_sync_get_sfo(q), - q->sfo_ema, q->sample_offset_correct_period); + q->next_rf_sample_offset, + q->mean_sample_offset, + srslte_ue_sync_get_sfo(q), + q->sfo_ema, + q->sample_offset_correct_period); } q->mean_sample_offset = 0; } - /* If the PSS peak is beyond the frame (we sample too slowly), + /* If the PSS peak is beyond the frame (we sample too slowly), discard the offseted samples to align next frame */ if (q->next_rf_sample_offset > 0 && q->next_rf_sample_offset < MAX_TIME_OFFSET) { DEBUG("Positive time offset %d samples.\n", q->next_rf_sample_offset); - if (q->recv_callback(q->stream, dummy_offset_buffer, (uint32_t) q->next_rf_sample_offset, NULL) < 0) { + if (q->recv_callback(q->stream, dummy_offset_buffer, (uint32_t)q->next_rf_sample_offset, NULL) < 0) { ERROR("Error receiving from USRP\n"); - return SRSLTE_ERROR; + return SRSLTE_ERROR; } q->next_rf_sample_offset = 0; - } - - q->peak_idx = q->sf_len/2 + q->last_sample_offset; + } + + q->peak_idx = q->sf_len / 2 + q->last_sample_offset; q->frame_ok_cnt++; q->frame_no_cnt = 0; return 1; } -static int track_peak_no(srslte_ue_sync_t *q) { - +static int track_peak_no(srslte_ue_sync_t* q) +{ + /* if we missed too many PSS go back to FIND and consider this frame unsynchronized */ - q->frame_no_cnt++; + q->frame_no_cnt++; if (q->frame_no_cnt >= TRACK_MAX_LOST) { - INFO("\n%d frames lost. Going back to FIND\n", (int) q->frame_no_cnt); + INFO("\n%d frames lost. Going back to FIND\n", (int)q->frame_no_cnt); q->state = SF_FIND; - return 0; + return 0; } else { - INFO("Tracking peak not found. Peak %.3f, %d lost\n", - srslte_sync_get_peak_value(&q->strack), (int) q->frame_no_cnt); + INFO("Tracking peak not found. Peak %.3f, %d lost\n", srslte_sync_get_peak_value(&q->strack), (int)q->frame_no_cnt); return 1; } - } -static int receive_samples(srslte_ue_sync_t *q, cf_t *input_buffer[SRSLTE_MAX_PORTS]) { +static int receive_samples(srslte_ue_sync_t* q, cf_t* input_buffer[SRSLTE_MAX_PORTS]) +{ /* A negative time offset means there are samples in our buffer for the next subframe, because we are sampling too fast. @@ -676,21 +697,19 @@ static int receive_samples(srslte_ue_sync_t *q, cf_t *input_buffer[SRSLTE_MAX_PO /* reset time offset */ q->next_rf_sample_offset = 0; - return SRSLTE_SUCCESS; + return SRSLTE_SUCCESS; } /* Returns 1 if the subframe is synchronized in time, 0 otherwise */ int srslte_ue_sync_zerocopy(srslte_ue_sync_t* q, cf_t* input_buffer[SRSLTE_MAX_PORTS]) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; + int ret = SRSLTE_ERROR_INVALID_INPUTS; uint32_t track_idx; - if (q != NULL && - input_buffer != NULL) - { - + if (q != NULL && input_buffer != NULL) { + if (q->file_mode) { - int n = srslte_filesource_read_multi(&q->file_source, (void **) input_buffer, q->sf_len, q->nof_rx_antennas); + int n = srslte_filesource_read_multi(&q->file_source, (void**)input_buffer, q->sf_len, q->nof_rx_antennas); if (n < 0) { ERROR("Error reading input file\n"); return SRSLTE_ERROR; @@ -699,7 +718,7 @@ int srslte_ue_sync_zerocopy(srslte_ue_sync_t* q, cf_t* input_buffer[SRSLTE_MAX_P if (q->file_wrap_enable) { srslte_filesource_seek(&q->file_source, 0); q->sf_idx = 9; - n = srslte_filesource_read_multi(&q->file_source, (void **) input_buffer, q->sf_len, q->nof_rx_antennas); + n = srslte_filesource_read_multi(&q->file_source, (void**)input_buffer, q->sf_len, q->nof_rx_antennas); if (n < 0) { ERROR("Error reading input file\n"); return SRSLTE_ERROR; @@ -710,10 +729,7 @@ int srslte_ue_sync_zerocopy(srslte_ue_sync_t* q, cf_t* input_buffer[SRSLTE_MAX_P } if (q->cfo_correct_enable_track) { for (int i = 0; i < q->nof_rx_antennas; i++) { - srslte_cfo_correct(&q->file_cfo_correct, - input_buffer[i], - input_buffer[i], - q->file_cfo / 15000 / q->fft_size); + srslte_cfo_correct(&q->file_cfo_correct, input_buffer[i], input_buffer[i], q->file_cfo / 15000 / q->fft_size); } } q->sf_idx++; @@ -741,7 +757,7 @@ int srslte_ue_sync_zerocopy(srslte_ue_sync_t* q, cf_t* input_buffer[SRSLTE_MAX_P } } n = srslte_sync_find(&q->sfind, input_buffer[0], 0, &q->peak_idx); - switch(n) { + switch (n) { case SRSLTE_SYNC_ERROR: ret = SRSLTE_ERROR; ERROR("Error finding correlation peak (%d)\n", ret); @@ -752,24 +768,31 @@ int srslte_ue_sync_zerocopy(srslte_ue_sync_t* q, cf_t* input_buffer[SRSLTE_MAX_P case SRSLTE_SYNC_FOUND_NOSPACE: /* If a peak was found but there is not enough space for SSS/CP detection, discard a few samples */ INFO("No space for SSS/CP detection. Realigning frame...\n"); - q->recv_callback(q->stream, dummy_offset_buffer, q->frame_len/2, NULL); + q->recv_callback(q->stream, dummy_offset_buffer, q->frame_len / 2, NULL); srslte_sync_reset(&q->sfind); ret = SRSLTE_SUCCESS; break; default: ret = SRSLTE_SUCCESS; break; - } + } if (q->do_agc) { srslte_agc_process(&q->agc, input_buffer[0], q->sf_len); } - INFO("SYNC FIND: sf_idx=%d, ret=%d, peak_pos=%d, peak_value=%.2f, mean_cp_cfo=%.2f, mean_pss_cfo=%.2f, total_cfo_khz=%.1f\n", q->sf_idx, ret, q->peak_idx, - q->sfind.peak_value, q->sfind.cfo_cp_mean, q->sfind.cfo_pss_mean, 15 * srslte_sync_get_cfo(&q->sfind)); + INFO("SYNC FIND: sf_idx=%d, ret=%d, peak_pos=%d, peak_value=%.2f, mean_cp_cfo=%.2f, mean_pss_cfo=%.2f, " + "total_cfo_khz=%.1f\n", + q->sf_idx, + ret, + q->peak_idx, + q->sfind.peak_value, + q->sfind.cfo_cp_mean, + q->sfind.cfo_pss_mean, + 15 * srslte_sync_get_cfo(&q->sfind)); break; case SF_TRACK: - + ret = 1; // Increase subframe counter @@ -803,43 +826,47 @@ int srslte_ue_sync_zerocopy(srslte_ue_sync_t* q, cf_t* input_buffer[SRSLTE_MAX_P uint32_t pss_idx = q->frame_len - PSS_OFFSET - q->fft_size - q->strack.max_offset / 2; n = srslte_sync_find(&q->strack, input_buffer[0], pss_idx, &track_idx); - switch(n) - { + switch (n) { case SRSLTE_SYNC_ERROR: ERROR("Error tracking correlation peak\n"); return SRSLTE_ERROR; - case SRSLTE_SYNC_FOUND: + case SRSLTE_SYNC_FOUND: ret = track_peak_ok(q, track_idx); break; - case SRSLTE_SYNC_FOUND_NOSPACE: - // It's very very unlikely that we fall here because this event should happen at FIND phase only - ret = 0; - q->state = SF_FIND; + case SRSLTE_SYNC_FOUND_NOSPACE: + // It's very very unlikely that we fall here because this event should happen at FIND phase only + ret = 0; + q->state = SF_FIND; INFO("Warning: No space for SSS/CP while in tracking phase\n"); break; case SRSLTE_SYNC_NOFOUND: ret = track_peak_no(q); break; } - + if (ret == SRSLTE_ERROR) { ERROR("Error processing tracking peak\n"); - q->state = SF_FIND; + q->state = SF_FIND; return SRSLTE_SUCCESS; } q->frame_total_cnt++; - INFO("SYNC TRACK: sf_idx=%d, ret=%d, peak_pos=%d, peak_value=%.2f, mean_cp_cfo=%.2f, mean_pss_cfo=%.2f, total_cfo_khz=%.1f\n", q->sf_idx, ret, track_idx, - q->strack.peak_value, q->strack.cfo_cp_mean, q->strack.cfo_pss_mean, 15 * srslte_sync_get_cfo(&q->strack)); + INFO("SYNC TRACK: sf_idx=%d, ret=%d, peak_pos=%d, peak_value=%.2f, mean_cp_cfo=%.2f, mean_pss_cfo=%.2f, " + "total_cfo_khz=%.1f\n", + q->sf_idx, + ret, + track_idx, + q->strack.peak_value, + q->strack.cfo_cp_mean, + q->strack.cfo_pss_mean, + 15 * srslte_sync_get_cfo(&q->strack)); } else { INFO("SYNC TRACK: sf_idx=%d, ret=%d, next_state=%d\n", q->sf_idx, ret, q->state); } - break; + break; } } - } - return ret; + } + return ret; } - - diff --git a/lib/src/phy/ue/ue_sync_nbiot.c b/lib/src/phy/ue/ue_sync_nbiot.c index c0ed2c421..eb66d364b 100644 --- a/lib/src/phy/ue/ue_sync_nbiot.c +++ b/lib/src/phy/ue/ue_sync_nbiot.c @@ -164,7 +164,7 @@ int srslte_ue_sync_nbiot_init(srslte_nbiot_ue_sync_t* q, int srslte_ue_sync_nbiot_init_multi(srslte_nbiot_ue_sync_t* q, uint32_t max_prb, - int(recv_callback)(void*, cf_t* [SRSLTE_MAX_PORTS], uint32_t, srslte_timestamp_t*), + int(recv_callback)(void*, cf_t * [SRSLTE_MAX_PORTS], uint32_t, srslte_timestamp_t*), uint32_t nof_rx_antennas, void* stream_handler) { @@ -497,14 +497,14 @@ static int receive_samples(srslte_nbiot_ue_sync_t* q, cf_t* input_buffer[SRSLTE_ int srslte_ue_sync_nbiot_zerocopy(srslte_nbiot_ue_sync_t* q, cf_t* input_buffer) { cf_t* _input_buffer[SRSLTE_MAX_PORTS] = {NULL}; - _input_buffer[0] = input_buffer; + _input_buffer[0] = input_buffer; return srslte_ue_sync_nbiot_zerocopy_multi(q, _input_buffer); } /* Returns 1 if the subframe is synchronized in time, 0 otherwise */ int srslte_ue_sync_nbiot_zerocopy_multi(srslte_nbiot_ue_sync_t* q, cf_t** input_buffer) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; + int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL) { if (q->file_mode) { diff --git a/lib/src/phy/ue/ue_ul.c b/lib/src/phy/ue/ue_ul.c index b1539155d..2b36b2d3a 100644 --- a/lib/src/phy/ue/ue_ul.c +++ b/lib/src/phy/ue/ue_ul.c @@ -26,28 +26,25 @@ #include "srslte/phy/ue/ue_ul.h" -#define CURRENT_FFTSIZE srslte_symbol_sz(q->cell.nof_prb) -#define CURRENT_SFLEN SRSLTE_SF_LEN(CURRENT_FFTSIZE) +#define CURRENT_FFTSIZE srslte_symbol_sz(q->cell.nof_prb) +#define CURRENT_SFLEN SRSLTE_SF_LEN(CURRENT_FFTSIZE) #define CURRENT_SLOTLEN_RE SRSLTE_SLOT_LEN_RE(q->cell.nof_prb, q->cell.cp) #define CURRENT_SFLEN_RE SRSLTE_NOF_RE(q->cell) -#define MAX_SFLEN SRSLTE_SF_LEN(srslte_symbol_sz(max_prb)) +#define MAX_SFLEN SRSLTE_SF_LEN(srslte_symbol_sz(max_prb)) -#define DEFAULT_CFO_TOL 1.0 // Hz +#define DEFAULT_CFO_TOL 1.0 // Hz static bool srs_tx_enabled(srslte_refsignal_srs_cfg_t* srs_cfg, uint32_t tti); -int srslte_ue_ul_init(srslte_ue_ul_t *q, - cf_t *out_buffer, - uint32_t max_prb) +int srslte_ue_ul_init(srslte_ue_ul_t* q, cf_t* out_buffer, uint32_t max_prb) { - int ret = SRSLTE_ERROR_INVALID_INPUTS; - - if (q != NULL) - { + int ret = SRSLTE_ERROR_INVALID_INPUTS; + + if (q != NULL) { ret = SRSLTE_ERROR; - + bzero(q, sizeof(srslte_ue_ul_t)); q->sf_symbols = srslte_vec_malloc(SRSLTE_SF_LEN_PRB(max_prb) * sizeof(cf_t)); @@ -83,35 +80,36 @@ int srslte_ue_ul_init(srslte_ue_ul_t *q, q->refsignal = srslte_vec_malloc(2 * SRSLTE_NRE * max_prb * sizeof(cf_t)); if (!q->refsignal) { perror("malloc"); - goto clean_exit; + goto clean_exit; } - + q->srs_signal = srslte_vec_malloc(SRSLTE_NRE * max_prb * sizeof(cf_t)); if (!q->srs_signal) { perror("malloc"); - goto clean_exit; + goto clean_exit; } q->out_buffer = out_buffer; - q->signals_pregenerated = false; - ret = SRSLTE_SUCCESS; + q->signals_pregenerated = false; + ret = SRSLTE_SUCCESS; } else { ERROR("Invalid parameters\n"); } -clean_exit: +clean_exit: if (ret == SRSLTE_ERROR) { srslte_ue_ul_free(q); } return ret; } -void srslte_ue_ul_free(srslte_ue_ul_t *q) { +void srslte_ue_ul_free(srslte_ue_ul_t* q) +{ if (q) { srslte_ofdm_tx_free(&q->fft); srslte_pusch_free(&q->pusch); srslte_pucch_free(&q->pucch); - srslte_cfo_free(&q->cfo); + srslte_cfo_free(&q->cfo); srslte_refsignal_ul_free(&q->signals); if (q->sf_symbols) { @@ -133,13 +131,11 @@ void srslte_ue_ul_free(srslte_ue_ul_t *q) { } } -int srslte_ue_ul_set_cell(srslte_ue_ul_t *q, - srslte_cell_t cell) +int srslte_ue_ul_set_cell(srslte_ue_ul_t* q, srslte_cell_t cell) { int ret = SRSLTE_ERROR_INVALID_INPUTS; - if (q != NULL && srslte_cell_isvalid(&cell)) - { + if (q != NULL && srslte_cell_isvalid(&cell)) { if (q->cell.id != cell.id || q->cell.nof_prb == 0) { q->cell = cell; @@ -180,9 +176,10 @@ int srslte_ue_ul_set_cell(srslte_ue_ul_t *q, /* Precalculate the PUSCH scramble sequences for a given RNTI. This function takes a while * to execute, so shall be called once the final C-RNTI has been allocated for the session. - * For the connection procedure, use srslte_pusch_encode_rnti() or srslte_pusch_decode_rnti() functions + * For the connection procedure, use srslte_pusch_encode_rnti() or srslte_pusch_decode_rnti() functions */ -void srslte_ue_ul_set_rnti(srslte_ue_ul_t *q, uint16_t rnti) { +void srslte_ue_ul_set_rnti(srslte_ue_ul_t* q, uint16_t rnti) +{ srslte_pusch_set_rnti(&q->pusch, rnti); srslte_pucch_set_rnti(&q->pucch, rnti); q->current_rnti = rnti; @@ -200,7 +197,7 @@ int srslte_ue_ul_pregen_signals(srslte_ue_ul_t* q, srslte_ue_ul_cfg_t* cfg) if (srslte_refsignal_srs_pregen(&q->signals, &q->pregen_srs, &cfg->ul_cfg.srs, &cfg->ul_cfg.dmrs)) { return SRSLTE_ERROR; } - q->signals_pregenerated = true; + q->signals_pregenerated = true; return SRSLTE_SUCCESS; } @@ -224,16 +221,16 @@ void srslte_ue_ul_pusch_hopping(srslte_ue_ul_t* q, return srslte_ra_ul_pusch_hopping(&q->hopping, sf, &cfg->ul_cfg.hopping, grant); } -static float limit_norm_factor(srslte_ue_ul_t *q, float norm_factor, cf_t *output_signal) +static float limit_norm_factor(srslte_ue_ul_t* q, float norm_factor, cf_t* output_signal) { - uint32_t p = srslte_vec_max_abs_fi((float*) output_signal, 2*SRSLTE_SF_LEN_PRB(q->cell.nof_prb)); - float amp = fabsf(*((float*) output_signal + p)); + uint32_t p = srslte_vec_max_abs_fi((float*)output_signal, 2 * SRSLTE_SF_LEN_PRB(q->cell.nof_prb)); + float amp = fabsf(*((float*)output_signal + p)); - if (amp*norm_factor > 0.95) { - norm_factor = 0.95/amp; + if (amp * norm_factor > 0.95) { + norm_factor = 0.95 / amp; } - if (amp*norm_factor < 0.1) { - norm_factor = 0.1/amp; + if (amp * norm_factor < 0.1) { + norm_factor = 0.1 / amp; } return norm_factor; } @@ -248,7 +245,7 @@ static void apply_cfo(srslte_ue_ul_t* q, srslte_ue_ul_cfg_t* cfg) static void apply_norm(srslte_ue_ul_t* q, srslte_ue_ul_cfg_t* cfg, float norm_factor) { - uint32_t sf_len = SRSLTE_SF_LEN_PRB(q->cell.nof_prb); + uint32_t sf_len = SRSLTE_SF_LEN_PRB(q->cell.nof_prb); float* buf = NULL; float force_peak_amplitude = cfg->force_peak_amplitude > 0 ? cfg->force_peak_amplitude : 1.0f; @@ -315,7 +312,7 @@ static int pusch_encode(srslte_ue_ul_t* q, srslte_ul_sf_cfg_t* sf, srslte_ue_ul_ cfg->ul_cfg.pusch.grant.n_dmrs, q->refsignal)) { ERROR("Error generating PUSCH DMRS signals\n"); - return ret; + return ret; } srslte_refsignal_dmrs_pusch_put(&q->signals, &cfg->ul_cfg.pusch, q->refsignal, q->sf_symbols); } @@ -339,7 +336,7 @@ float srslte_ue_ul_pusch_power(srslte_ue_ul_t* q, srslte_ue_ul_cfg_t* cfg, float float p0_pusch, alpha; if (p0_preamble) { p0_pusch = p0_preamble + cfg->ul_cfg.power_ctrl.delta_preamble_msg3; - alpha = 1; + alpha = 1; } else { alpha = cfg->ul_cfg.power_ctrl.alpha; p0_pusch = cfg->ul_cfg.power_ctrl.p0_nominal_pusch + cfg->ul_cfg.power_ctrl.p0_ue_pusch; @@ -404,14 +401,13 @@ float srslte_ue_ul_pucch_power(srslte_ue_ul_t* q, srslte_ue_ul_cfg_t* cfg, srslt } } } - - //TODO: This implements closed-loop power control - float g = 0; - + + // TODO: This implements closed-loop power control + float g = 0; + float pucch_power = p0_pucch + PL + h + delta_f + g; - - DEBUG("PUCCH: P=%f -- p0=%f, PL=%f, delta_f=%f, h=%f, g=%f\n", - pucch_power, p0_pucch, PL, delta_f, h, g); + + DEBUG("PUCCH: P=%f -- p0=%f, PL=%f, delta_f=%f, h=%f, g=%f\n", pucch_power, p0_pucch, PL, delta_f, h, g); return 0; } @@ -475,7 +471,7 @@ float srs_power(srslte_ue_ul_t* q, srslte_ue_ul_cfg_t* cfg, float PL) PL, f); - return p_srs; + return p_srs; } /* Choose PUCCH format based on pending transmission as described in 10.1 of 36.213 */ @@ -992,13 +988,13 @@ int srslte_ue_ul_sr_send_tti(srslte_pucch_cfg_t* cfg, uint32_t current_tti) sr_N_offset = I_sr - 35; } else if (I_sr < 155) { sr_periodicity = 80; - sr_N_offset = I_sr-75; + sr_N_offset = I_sr - 75; } else if (I_sr < 157) { sr_periodicity = 2; - sr_N_offset = I_sr-155; + sr_N_offset = I_sr - 155; } else if (I_sr == 157) { sr_periodicity = 1; - sr_N_offset = I_sr-157; + sr_N_offset = I_sr - 157; } else { return SRSLTE_ERROR; } @@ -1063,8 +1059,11 @@ int srslte_ue_ul_encode(srslte_ue_ul_t* q, srslte_ul_sf_cfg_t* sf, srslte_ue_ul_ return ret; } -bool srslte_ue_ul_info( - srslte_ue_ul_cfg_t* cfg, srslte_ul_sf_cfg_t* sf, srslte_uci_value_t* uci_data, char* str, uint32_t str_len) +bool srslte_ue_ul_info(srslte_ue_ul_cfg_t* cfg, + srslte_ul_sf_cfg_t* sf, + srslte_uci_value_t* uci_data, + char* str, + uint32_t str_len) { uint32_t n = 0; bool ret = false; diff --git a/lib/src/phy/utils/bit.c b/lib/src/phy/utils/bit.c index 82179a88b..21837bbe2 100644 --- a/lib/src/phy/utils/bit.c +++ b/lib/src/phy/utils/bit.c @@ -19,13 +19,12 @@ * */ -#include -#include -#include #include -#include #include +#include +#include #include +#include #ifdef LV_HAVE_SSE @@ -36,27 +35,27 @@ #include "srslte/phy/utils/bit.h" #include "srslte/phy/utils/vector.h" -void srslte_bit_interleaver_init(srslte_bit_interleaver_t *q, - uint16_t *interleaver, - uint32_t nof_bits) { - static const uint8_t mask[] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 }; +void srslte_bit_interleaver_init(srslte_bit_interleaver_t* q, uint16_t* interleaver, uint32_t nof_bits) +{ + static const uint8_t mask[] = {0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1}; bzero(q, sizeof(srslte_bit_interleaver_t)); - q->interleaver = srslte_vec_malloc(sizeof(uint16_t)*nof_bits); - q->byte_idx = srslte_vec_malloc(sizeof(uint16_t)*nof_bits); - q->bit_mask = srslte_vec_malloc(sizeof(uint8_t)*nof_bits); - q->nof_bits = nof_bits; + q->interleaver = srslte_vec_malloc(sizeof(uint16_t) * nof_bits); + q->byte_idx = srslte_vec_malloc(sizeof(uint16_t) * nof_bits); + q->bit_mask = srslte_vec_malloc(sizeof(uint8_t) * nof_bits); + q->nof_bits = nof_bits; for (int i = 0; i < nof_bits; i++) { - uint16_t i_px = interleaver[i]; + uint16_t i_px = interleaver[i]; q->interleaver[i] = i_px; - q->byte_idx[i] = (uint16_t) (interleaver[i] / 8); - q->bit_mask[i] = (uint8_t) (mask[i_px%8]); + q->byte_idx[i] = (uint16_t)(interleaver[i] / 8); + q->bit_mask[i] = (uint8_t)(mask[i_px % 8]); } } -void srslte_bit_interleaver_free(srslte_bit_interleaver_t *q) { +void srslte_bit_interleaver_free(srslte_bit_interleaver_t* q) +{ if (q->interleaver) { free(q->interleaver); } @@ -72,25 +71,26 @@ void srslte_bit_interleaver_free(srslte_bit_interleaver_t *q) { bzero(q, sizeof(srslte_bit_interleaver_t)); } -void srslte_bit_interleaver_run(srslte_bit_interleaver_t *q, uint8_t *input, uint8_t *output, uint16_t w_offset) { - static const uint8_t mask[] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 }; - uint16_t *byte_idx = q->byte_idx; - uint8_t *bit_mask = q->bit_mask; - uint8_t *output_ptr = output; +void srslte_bit_interleaver_run(srslte_bit_interleaver_t* q, uint8_t* input, uint8_t* output, uint16_t w_offset) +{ + static const uint8_t mask[] = {0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1}; + uint16_t* byte_idx = q->byte_idx; + uint8_t* bit_mask = q->bit_mask; + uint8_t* output_ptr = output; - uint32_t st=0, w_offset_p=0; + uint32_t st = 0, w_offset_p = 0; if (w_offset < 8 && w_offset > 0) { - st=1; - for (uint32_t j=0;j<8-w_offset;j++) { + st = 1; + for (uint32_t j = 0; j < 8 - w_offset; j++) { uint16_t i_p = q->interleaver[j]; - if (input[i_p/8] & mask[i_p%8]) { - output[0] |= mask[j+w_offset]; + if (input[i_p / 8] & mask[i_p % 8]) { + output[0] |= mask[j + w_offset]; } else { - output[0] &= ~(mask[j+w_offset]); + output[0] &= ~(mask[j + w_offset]); } } - w_offset_p=8-w_offset; + w_offset_p = 8 - w_offset; } int i = st * 8; @@ -100,7 +100,7 @@ void srslte_bit_interleaver_run(srslte_bit_interleaver_t *q, uint8_t *input, uin output_ptr += st; #ifdef LV_HAVE_SSE - for(; i < (int) q->nof_bits - 15; i += 16) { + for (; i < (int)q->nof_bits - 15; i += 16) { __m128i in128; in128 = _mm_insert_epi8(in128, input[*(byte_idx++)], 0x7); in128 = _mm_insert_epi8(in128, input[*(byte_idx++)], 0x6); @@ -119,12 +119,12 @@ void srslte_bit_interleaver_run(srslte_bit_interleaver_t *q, uint8_t *input, uin in128 = _mm_insert_epi8(in128, input[*(byte_idx++)], 0x9); in128 = _mm_insert_epi8(in128, input[*(byte_idx++)], 0x8); - __m128i mask128 = _mm_loadu_si128((__m128i *) bit_mask); - mask128 = _mm_shuffle_epi8(mask128, _mm_set_epi8(0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, - 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7)); + __m128i mask128 = _mm_loadu_si128((__m128i*)bit_mask); + mask128 = _mm_shuffle_epi8( + mask128, _mm_set_epi8(0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7)); - __m128i cmp128 = _mm_cmpeq_epi8(_mm_and_si128(in128, mask128), mask128); - *((uint16_t *) (output_ptr)) = (uint16_t) _mm_movemask_epi8(cmp128); + __m128i cmp128 = _mm_cmpeq_epi8(_mm_and_si128(in128, mask128), mask128); + *((uint16_t*)(output_ptr)) = (uint16_t)_mm_movemask_epi8(cmp128); bit_mask += 16; output_ptr += 2; @@ -132,34 +132,34 @@ void srslte_bit_interleaver_run(srslte_bit_interleaver_t *q, uint8_t *input, uin #endif /* LV_HAVE_SSE */ - for(; i < (int) q->nof_bits - 7; i += 8) { - uint8_t out0 = (input[*(byte_idx++)] & *(bit_mask++))?mask[0]:(uint8_t)0; - uint8_t out1 = (input[*(byte_idx++)] & *(bit_mask++))?mask[1]:(uint8_t)0; - uint8_t out2 = (input[*(byte_idx++)] & *(bit_mask++))?mask[2]:(uint8_t)0; - uint8_t out3 = (input[*(byte_idx++)] & *(bit_mask++))?mask[3]:(uint8_t)0; - uint8_t out4 = (input[*(byte_idx++)] & *(bit_mask++))?mask[4]:(uint8_t)0; - uint8_t out5 = (input[*(byte_idx++)] & *(bit_mask++))?mask[5]:(uint8_t)0; - uint8_t out6 = (input[*(byte_idx++)] & *(bit_mask++))?mask[6]:(uint8_t)0; - uint8_t out7 = (input[*(byte_idx++)] & *(bit_mask++))?mask[7]:(uint8_t)0; + for (; i < (int)q->nof_bits - 7; i += 8) { + uint8_t out0 = (input[*(byte_idx++)] & *(bit_mask++)) ? mask[0] : (uint8_t)0; + uint8_t out1 = (input[*(byte_idx++)] & *(bit_mask++)) ? mask[1] : (uint8_t)0; + uint8_t out2 = (input[*(byte_idx++)] & *(bit_mask++)) ? mask[2] : (uint8_t)0; + uint8_t out3 = (input[*(byte_idx++)] & *(bit_mask++)) ? mask[3] : (uint8_t)0; + uint8_t out4 = (input[*(byte_idx++)] & *(bit_mask++)) ? mask[4] : (uint8_t)0; + uint8_t out5 = (input[*(byte_idx++)] & *(bit_mask++)) ? mask[5] : (uint8_t)0; + uint8_t out6 = (input[*(byte_idx++)] & *(bit_mask++)) ? mask[6] : (uint8_t)0; + uint8_t out7 = (input[*(byte_idx++)] & *(bit_mask++)) ? mask[7] : (uint8_t)0; *output_ptr = out0 | out1 | out2 | out3 | out4 | out5 | out6 | out7; output_ptr++; } - for (uint32_t j=0;jnof_bits%8;j++) { - uint16_t i_p = q->interleaver[(q->nof_bits/8)*8+j-w_offset]; - if (input[i_p/8] & mask[i_p%8]) { - output[q->nof_bits/8] |= mask[j]; + for (uint32_t j = 0; j < q->nof_bits % 8; j++) { + uint16_t i_p = q->interleaver[(q->nof_bits / 8) * 8 + j - w_offset]; + if (input[i_p / 8] & mask[i_p % 8]) { + output[q->nof_bits / 8] |= mask[j]; } else { - output[q->nof_bits/8] &= ~(mask[j]); + output[q->nof_bits / 8] &= ~(mask[j]); } } - for (uint32_t j=0;jinterleaver[(q->nof_bits/8)*8+j-w_offset]; - if (input[i_p/8] & (1<<(7-i_p%8))) { - output[q->nof_bits/8] |= mask[j]; + for (uint32_t j = 0; j < w_offset; j++) { + uint16_t i_p = q->interleaver[(q->nof_bits / 8) * 8 + j - w_offset]; + if (input[i_p / 8] & (1 << (7 - i_p % 8))) { + output[q->nof_bits / 8] |= mask[j]; } else { - output[q->nof_bits/8] &= ~(mask[j]); + output[q->nof_bits / 8] &= ~(mask[j]); } } @@ -199,41 +199,46 @@ void srslte_bit_interleaver_run(srslte_bit_interleaver_t *q, uint8_t *input, uin #endif } - -void srslte_bit_interleave_i(uint8_t *input, uint8_t *output, uint32_t *interleaver, uint32_t nof_bits) { +void srslte_bit_interleave_i(uint8_t* input, uint8_t* output, uint32_t* interleaver, uint32_t nof_bits) +{ srslte_bit_interleave_i_w_offset(input, output, interleaver, nof_bits, 0); } -void srslte_bit_interleave_i_w_offset(uint8_t *input, uint8_t *output, uint32_t *interleaver, uint32_t nof_bits, uint32_t w_offset) { - uint32_t st=0, w_offset_p=0; - static const uint8_t mask[] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 }; +void srslte_bit_interleave_i_w_offset(uint8_t* input, + uint8_t* output, + uint32_t* interleaver, + uint32_t nof_bits, + uint32_t w_offset) +{ + uint32_t st = 0, w_offset_p = 0; + static const uint8_t mask[] = {0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1}; if (w_offset < 8 && w_offset > 0) { - st=1; - for (uint32_t j=0;j<8-w_offset;j++) { + st = 1; + for (uint32_t j = 0; j < 8 - w_offset; j++) { uint32_t i_p = interleaver[j]; - if (input[i_p/8] & mask[i_p%8]) { - output[0] |= mask[j+w_offset]; + if (input[i_p / 8] & mask[i_p % 8]) { + output[0] |= mask[j + w_offset]; } else { - output[0] &= ~(mask[j+w_offset]); + output[0] &= ~(mask[j + w_offset]); } } - w_offset_p=8-w_offset; + w_offset_p = 8 - w_offset; } #ifdef LV_HAVE_SSE - __m64 m64mask = _mm_setr_pi8((uint8_t) 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1); + __m64 m64mask = _mm_setr_pi8((uint8_t)0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1); union { uint8_t v[8]; - __m64 m64; + __m64 m64; } a, b, c; union { - __m128i m128; + __m128i m128; uint16_t u32[4]; uint16_t u16[8]; - uint8_t u8[16]; + uint8_t u8[16]; struct { __m64 reg_a; __m64 reg_b; @@ -246,21 +251,17 @@ void srslte_bit_interleave_i_w_offset(uint8_t *input, uint8_t *output, uint32_t } v32; } ipx1, ipx2, epx1, epx2; for (uint32_t i = st; i < nof_bits / 8; i++) { - ipx1.m128 = _mm_loadu_si128((__m128i *) (interleaver + (i * 8 + 0) - w_offset_p)); - epx1.m128 = _mm_shuffle_epi8(ipx1.m128, _mm_set_epi8(0x00, 0x04, 0x08, 0x0C, - 0x00, 0x04, 0x08, 0x0C, - 0x00, 0x04, 0x08, 0x0C, - 0x00, 0x04, 0x08, 0x0C)); - ipx2.m128 = _mm_loadu_si128((__m128i *) (interleaver + (i * 8 + 4) - w_offset_p)); - epx2.m128 = _mm_shuffle_epi8(ipx2.m128, _mm_set_epi8(0x00, 0x04, 0x08, 0x0C, - 0x00, 0x04, 0x08, 0x0C, - 0x00, 0x04, 0x08, 0x0C, - 0x00, 0x04, 0x08, 0x0C)); - - epx1.m128 = _mm_blendv_epi8(epx2.m128, epx1.m128, _mm_setr_epi8(+1, +1, +1, +1, - -1, -1, -1, -1, - +1, +1, +1, +1, - -1, -1, -1, -1)); + ipx1.m128 = _mm_loadu_si128((__m128i*)(interleaver + (i * 8 + 0) - w_offset_p)); + epx1.m128 = _mm_shuffle_epi8( + ipx1.m128, + _mm_set_epi8(0x00, 0x04, 0x08, 0x0C, 0x00, 0x04, 0x08, 0x0C, 0x00, 0x04, 0x08, 0x0C, 0x00, 0x04, 0x08, 0x0C)); + ipx2.m128 = _mm_loadu_si128((__m128i*)(interleaver + (i * 8 + 4) - w_offset_p)); + epx2.m128 = _mm_shuffle_epi8( + ipx2.m128, + _mm_set_epi8(0x00, 0x04, 0x08, 0x0C, 0x00, 0x04, 0x08, 0x0C, 0x00, 0x04, 0x08, 0x0C, 0x00, 0x04, 0x08, 0x0C)); + + epx1.m128 = _mm_blendv_epi8( + epx2.m128, epx1.m128, _mm_setr_epi8(+1, +1, +1, +1, -1, -1, -1, -1, +1, +1, +1, +1, -1, -1, -1, -1)); b.m64 = _mm_and_si64(epx1.m64.reg_a, _mm_set1_pi8(0x7)); b.m64 = _mm_shuffle_pi8(m64mask, b.m64); @@ -277,11 +278,11 @@ void srslte_bit_interleave_i_w_offset(uint8_t *input, uint8_t *output, uint32_t input[ipx2.v32.i2], input[ipx2.v32.i3]); - c.m64 = _mm_cmpeq_pi8(_mm_and_si64(a.m64, b.m64), b.m64); - output[i] = (uint8_t) _mm_movemask_pi8(c.m64); + c.m64 = _mm_cmpeq_pi8(_mm_and_si64(a.m64, b.m64), b.m64); + output[i] = (uint8_t)_mm_movemask_pi8(c.m64); } -#if 0 /* Disabled */ +#if 0 /* Disabled */ /* THIS PIECE OF CODE IS FOR CHECKING SIMD BEHAVIOUR. DO NOT ENABLE. */ uint8_t *output2 = malloc(nof_bits/8); for (uint32_t i=st;i 0) { - st=1; - for (uint32_t j=0;j<8-w_offset;j++) { - uint16_t i_p = interleaver[j]; - if (input[i_p/8] & mask[i_p%8]) { - output[0] |= mask[j+w_offset]; + st = 1; + for (uint32_t j = 0; j < 8 - w_offset; j++) { + uint16_t i_p = interleaver[j]; + if (input[i_p / 8] & mask[i_p % 8]) { + output[0] |= mask[j + w_offset]; } else { - output[0] &= ~(mask[j+w_offset]); + output[0] &= ~(mask[j + w_offset]); } } - w_offset_p=8-w_offset; + w_offset_p = 8 - w_offset; } #ifdef LV_HAVE_SSE - __m64 m64mask = _mm_setr_pi8((uint8_t) 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1); + __m64 m64mask = _mm_setr_pi8((uint8_t)0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1); __m128i m128mask = _mm_set1_epi64(m64mask); union { uint8_t v[8]; - __m64 m64; + __m64 m64; } a, b, c; union { - __m128i m128; + __m128i m128; uint16_t u16[8]; - uint8_t u8[16]; + uint8_t u8[16]; struct { __m64 reg_a; __m64 reg_b; @@ -402,23 +409,38 @@ void srslte_bit_interleave_w_offset(uint8_t *input, uint8_t *output, uint16_t *i uint32_t i = st; for (; i < (nof_bits / 8 - 1); i += 2) { - ipx.m128 = _mm_loadu_si128((__m128i *) (interleaver + (i * 8) - w_offset_p)); - epx.m128 = _mm_shuffle_epi8(ipx.m128, _mm_set_epi8(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, - 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E)); - ipx2.m128 = _mm_loadu_si128((__m128i *) (interleaver + ((i + 1) * 8) - w_offset_p)); - epx2.m128 = _mm_shuffle_epi8(ipx2.m128, _mm_set_epi8(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, - 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E)); - - epx.m128 = _mm_blendv_epi8(epx.m128, epx2.m128, _mm_setr_epi8(0, 0, 0, 0, 0, 0, 0, 0, - (uint8_t) 0xFF, (uint8_t) 0xFF, - (uint8_t) 0xFF, (uint8_t) 0xFF, - (uint8_t) 0xFF, (uint8_t) 0xFF, - (uint8_t) 0xFF, (uint8_t) 0xFF)); + ipx.m128 = _mm_loadu_si128((__m128i*)(interleaver + (i * 8) - w_offset_p)); + epx.m128 = _mm_shuffle_epi8( + ipx.m128, + _mm_set_epi8(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E)); + ipx2.m128 = _mm_loadu_si128((__m128i*)(interleaver + ((i + 1) * 8) - w_offset_p)); + epx2.m128 = _mm_shuffle_epi8( + ipx2.m128, + _mm_set_epi8(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E)); + + epx.m128 = _mm_blendv_epi8(epx.m128, + epx2.m128, + _mm_setr_epi8(0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + (uint8_t)0xFF, + (uint8_t)0xFF, + (uint8_t)0xFF, + (uint8_t)0xFF, + (uint8_t)0xFF, + (uint8_t)0xFF, + (uint8_t)0xFF, + (uint8_t)0xFF)); b128.m128 = _mm_and_si128(epx.m128, _mm_set1_epi8(0x7)); b128.m128 = _mm_shuffle_epi8(m128mask, b128.m128); - ipx.m128 = _mm_srli_epi16(ipx.m128, 3); + ipx.m128 = _mm_srli_epi16(ipx.m128, 3); ipx2.m128 = _mm_srli_epi16(ipx2.m128, 3); a128.m128 = _mm_set_epi8(input[ipx2.v.i0], @@ -438,15 +460,16 @@ void srslte_bit_interleave_w_offset(uint8_t *input, uint8_t *output, uint16_t *i input[ipx.v.i6], input[ipx.v.i7]); - c128.m128 = _mm_cmpeq_epi8(_mm_and_si128(a128.m128, b128.m128), b128.m128); - uint16_t o = (uint16_t) _mm_movemask_epi8(c128.m128); - *((uint16_t *) (output + i)) = o; + c128.m128 = _mm_cmpeq_epi8(_mm_and_si128(a128.m128, b128.m128), b128.m128); + uint16_t o = (uint16_t)_mm_movemask_epi8(c128.m128); + *((uint16_t*)(output + i)) = o; } for (; i < nof_bits / 8; i++) { - ipx.m128 = _mm_loadu_si128((__m128i *) (interleaver + i * 8 - w_offset_p)); - epx.m128 = _mm_shuffle_epi8(ipx.m128, _mm_set_epi8(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, - 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E)); + ipx.m128 = _mm_loadu_si128((__m128i*)(interleaver + i * 8 - w_offset_p)); + epx.m128 = _mm_shuffle_epi8( + ipx.m128, + _mm_set_epi8(0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E)); b.m64 = _mm_and_si64(epx.m64.reg_a, _mm_set1_pi8(0x7)); b.m64 = _mm_shuffle_pi8(m64mask, b.m64); @@ -461,8 +484,8 @@ void srslte_bit_interleave_w_offset(uint8_t *input, uint8_t *output, uint16_t *i input[ipx.v.i6], input[ipx.v.i7]); - c.m64 = _mm_cmpeq_pi8(_mm_and_si64(a.m64, b.m64), b.m64); - output[i] = (uint8_t) _mm_movemask_pi8(c.m64); + c.m64 = _mm_cmpeq_pi8(_mm_and_si64(a.m64, b.m64), b.m64); + output[i] = (uint8_t)_mm_movemask_pi8(c.m64); } #if 0 @@ -500,162 +523,154 @@ void srslte_bit_interleave_w_offset(uint8_t *input, uint8_t *output, uint16_t *i free(output2); #endif -#else /* LV_HAVE_SSE */ - for (uint32_t i=st;i= (CHAR_BIT - dst_offset_modulo)) { \ - *dst &= reverse_mask[dst_offset_modulo]; \ - src_len -= CHAR_BIT - dst_offset_modulo; \ - } else { \ - *dst &= reverse_mask[dst_offset_modulo] \ - | reverse_mask_xor[dst_offset_modulo + src_len]; \ - c &= reverse_mask[dst_offset_modulo + src_len]; \ - src_len = 0; \ - } } while (0) - +#define PREPARE_FIRST_COPY() \ + do { \ + if (src_len >= (CHAR_BIT - dst_offset_modulo)) { \ + *dst &= reverse_mask[dst_offset_modulo]; \ + src_len -= CHAR_BIT - dst_offset_modulo; \ + } else { \ + *dst &= reverse_mask[dst_offset_modulo] | reverse_mask_xor[dst_offset_modulo + src_len]; \ + c &= reverse_mask[dst_offset_modulo + src_len]; \ + src_len = 0; \ + } \ + } while (0) static void -bitarray_copy(const unsigned char *src_org, int src_offset, int src_len, - unsigned char *dst_org, int dst_offset) +bitarray_copy(const unsigned char* src_org, int src_offset, int src_len, unsigned char* dst_org, int dst_offset) { - static const unsigned char reverse_mask[] = - { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff }; - static const unsigned char reverse_mask_xor[] = - { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00 }; - - if (src_len) { - const unsigned char *src; - unsigned char *dst; - int src_offset_modulo, - dst_offset_modulo; - - src = src_org + (src_offset / CHAR_BIT); - dst = dst_org + (dst_offset / CHAR_BIT); - - src_offset_modulo = src_offset % CHAR_BIT; - dst_offset_modulo = dst_offset % CHAR_BIT; - - if (src_offset_modulo == dst_offset_modulo) { - int byte_len; - int src_len_modulo; - if (src_offset_modulo) { - unsigned char c; - - c = reverse_mask_xor[dst_offset_modulo] & *src++; - - PREPARE_FIRST_COPY(); - *dst++ |= c; - } - - byte_len = src_len / CHAR_BIT; - src_len_modulo = src_len % CHAR_BIT; - - if (byte_len) { - memcpy(dst, src, byte_len); - src += byte_len; - dst += byte_len; - } - if (src_len_modulo) { - *dst &= reverse_mask_xor[src_len_modulo]; - *dst |= reverse_mask[src_len_modulo] & *src; - } - } else { - int bit_diff_ls, - bit_diff_rs; - int byte_len; - int src_len_modulo; - unsigned char c; - /* - * Begin: Line things up on destination. - */ - if (src_offset_modulo > dst_offset_modulo) { - bit_diff_ls = src_offset_modulo - dst_offset_modulo; - bit_diff_rs = CHAR_BIT - bit_diff_ls; - - c = *src++ << bit_diff_ls; - c |= *src >> bit_diff_rs; - c &= reverse_mask_xor[dst_offset_modulo]; - } else { - bit_diff_rs = dst_offset_modulo - src_offset_modulo; - bit_diff_ls = CHAR_BIT - bit_diff_rs; - - c = *src >> bit_diff_rs & - reverse_mask_xor[dst_offset_modulo]; - } - PREPARE_FIRST_COPY(); - *dst++ |= c; - - /* - * Middle: copy with only shifting the source. - */ - byte_len = src_len / CHAR_BIT; - - while (--byte_len >= 0) { - c = *src++ << bit_diff_ls; - c |= *src >> bit_diff_rs; - *dst++ = c; - } - - /* - * End: copy the remaing bits; - */ - src_len_modulo = src_len % CHAR_BIT; - if (src_len_modulo) { - c = *src++ << bit_diff_ls; - c |= *src >> bit_diff_rs; - c &= reverse_mask[src_len_modulo]; - - *dst &= reverse_mask_xor[src_len_modulo]; - *dst |= c; - } - } + static const unsigned char reverse_mask[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff}; + static const unsigned char reverse_mask_xor[] = {0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00}; + + if (src_len) { + const unsigned char* src; + unsigned char* dst; + int src_offset_modulo, dst_offset_modulo; + + src = src_org + (src_offset / CHAR_BIT); + dst = dst_org + (dst_offset / CHAR_BIT); + + src_offset_modulo = src_offset % CHAR_BIT; + dst_offset_modulo = dst_offset % CHAR_BIT; + + if (src_offset_modulo == dst_offset_modulo) { + int byte_len; + int src_len_modulo; + if (src_offset_modulo) { + unsigned char c; + + c = reverse_mask_xor[dst_offset_modulo] & *src++; + + PREPARE_FIRST_COPY(); + *dst++ |= c; + } + + byte_len = src_len / CHAR_BIT; + src_len_modulo = src_len % CHAR_BIT; + + if (byte_len) { + memcpy(dst, src, byte_len); + src += byte_len; + dst += byte_len; + } + if (src_len_modulo) { + *dst &= reverse_mask_xor[src_len_modulo]; + *dst |= reverse_mask[src_len_modulo] & *src; + } + } else { + int bit_diff_ls, bit_diff_rs; + int byte_len; + int src_len_modulo; + unsigned char c; + /* + * Begin: Line things up on destination. + */ + if (src_offset_modulo > dst_offset_modulo) { + bit_diff_ls = src_offset_modulo - dst_offset_modulo; + bit_diff_rs = CHAR_BIT - bit_diff_ls; + + c = *src++ << bit_diff_ls; + c |= *src >> bit_diff_rs; + c &= reverse_mask_xor[dst_offset_modulo]; + } else { + bit_diff_rs = dst_offset_modulo - src_offset_modulo; + bit_diff_ls = CHAR_BIT - bit_diff_rs; + + c = *src >> bit_diff_rs & reverse_mask_xor[dst_offset_modulo]; + } + PREPARE_FIRST_COPY(); + *dst++ |= c; + + /* + * Middle: copy with only shifting the source. + */ + byte_len = src_len / CHAR_BIT; + + while (--byte_len >= 0) { + c = *src++ << bit_diff_ls; + c |= *src >> bit_diff_rs; + *dst++ = c; + } + + /* + * End: copy the remaing bits; + */ + src_len_modulo = src_len % CHAR_BIT; + if (src_len_modulo) { + c = *src++ << bit_diff_ls; + c |= *src >> bit_diff_rs; + c &= reverse_mask[src_len_modulo]; + + *dst &= reverse_mask_xor[src_len_modulo]; + *dst |= c; + } } + } } /** @@ -667,40 +682,39 @@ bitarray_copy(const unsigned char *src_org, int src_offset, int src_len, * @param src_offset Input array read offset in bits * @param nof_bits Number of bits to copy */ -void srslte_bit_copy(uint8_t *dst, uint32_t dst_offset, uint8_t *src, uint32_t src_offset, uint32_t nof_bits) +void srslte_bit_copy(uint8_t* dst, uint32_t dst_offset, uint8_t* src, uint32_t src_offset, uint32_t nof_bits) { - static const uint8_t mask_dst[] = - { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff }; - if ((dst_offset%8) == 0 && (src_offset%8) == 0) { + static const uint8_t mask_dst[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff}; + if ((dst_offset % 8) == 0 && (src_offset % 8) == 0) { // copy rest of words - memcpy(&dst[dst_offset/8], &src[src_offset/8], nof_bits/8); + memcpy(&dst[dst_offset / 8], &src[src_offset / 8], nof_bits / 8); // copy last word - if (nof_bits%8) { - dst[dst_offset/8+nof_bits/8] = src[src_offset/8+nof_bits/8] & mask_dst[nof_bits%8]; + if (nof_bits % 8) { + dst[dst_offset / 8 + nof_bits / 8] = src[src_offset / 8 + nof_bits / 8] & mask_dst[nof_bits % 8]; } } else { bitarray_copy(src, src_offset, nof_bits, dst, dst_offset); } } -void srslte_bit_unpack_vector(uint8_t *packed, uint8_t *unpacked, int nof_bits) +void srslte_bit_unpack_vector(uint8_t* packed, uint8_t* unpacked, int nof_bits) { uint32_t i, nbytes; - nbytes = nof_bits/8; - for (i=0;i>(8-nof_bits%8), &unpacked, nof_bits%8); + if (nof_bits % 8) { + srslte_bit_unpack(packed[i] >> (8 - nof_bits % 8), &unpacked, nof_bits % 8); } } -void srslte_bit_unpack_l(uint64_t value, uint8_t **bits, int nof_bits) +void srslte_bit_unpack_l(uint64_t value, uint8_t** bits, int nof_bits) { int i; - for(i=0; i> (nof_bits-i-1)) & 0x1; + for (i = 0; i < nof_bits; i++) { + (*bits)[i] = (value >> (nof_bits - i - 1)) & 0x1; } *bits += nof_bits; } @@ -712,66 +726,68 @@ void srslte_bit_unpack_l(uint64_t value, uint8_t **bits, int nof_bits) * @param[in] nof_bits Number of bits to unpack * @param[out] bits Points to buffer pointer. The buffer pointer will be advanced by nof_bits */ -void srslte_bit_unpack(uint32_t value, uint8_t **bits, int nof_bits) +void srslte_bit_unpack(uint32_t value, uint8_t** bits, int nof_bits) { - int i; + int i; - for(i=0; i> (nof_bits-i-1)) & 0x1; - } - *bits += nof_bits; + for (i = 0; i < nof_bits; i++) { + (*bits)[i] = (value >> (nof_bits - i - 1)) & 0x1; + } + *bits += nof_bits; } -void srslte_bit_pack_vector(uint8_t *unpacked, uint8_t *packed, int nof_bits) +void srslte_bit_pack_vector(uint8_t* unpacked, uint8_t* packed, int nof_bits) { uint32_t i, nbytes; - nbytes = nof_bits/8; - for (i=0;i -#include -#include #include #include +#include +#include +#include #include "srslte/phy/common/phy_common.h" #include "srslte/phy/utils/cexptab.h" -int srslte_cexptab_init(srslte_cexptab_t *h, uint32_t size) { +int srslte_cexptab_init(srslte_cexptab_t* h, uint32_t size) +{ uint32_t i; h->size = size; - h->tab = malloc(sizeof(cf_t) * (1+size)); + h->tab = malloc(sizeof(cf_t) * (1 + size)); if (h->tab) { for (i = 0; i < size; i++) { - h->tab[i] = cexpf(_Complex_I * 2 * M_PI * (float) i / size); + h->tab[i] = cexpf(_Complex_I * 2 * M_PI * (float)i / size); } return SRSLTE_SUCCESS; } else { @@ -43,34 +44,36 @@ int srslte_cexptab_init(srslte_cexptab_t *h, uint32_t size) { } } -void srslte_cexptab_free(srslte_cexptab_t *h) { +void srslte_cexptab_free(srslte_cexptab_t* h) +{ if (h->tab) { free(h->tab); } bzero(h, sizeof(srslte_cexptab_t)); } -void srslte_cexptab_gen(srslte_cexptab_t *h, cf_t *x, float freq, uint32_t len) { +void srslte_cexptab_gen(srslte_cexptab_t* h, cf_t* x, float freq, uint32_t len) +{ uint32_t i; uint32_t idx; - float phase_inc = freq * h->size; - float phase=0; + float phase_inc = freq * h->size; + float phase = 0; for (i = 0; i < len; i++) { - while (phase >= (float) h->size) { - phase -= (float) h->size; + while (phase >= (float)h->size) { + phase -= (float)h->size; } while (phase < 0) { - phase += (float) h->size; + phase += (float)h->size; } - idx = (uint32_t) phase; + idx = (uint32_t)phase; x[i] = h->tab[idx]; phase += phase_inc; - } } -void srslte_cexptab_gen_direct(cf_t *x, float freq, uint32_t len) { +void srslte_cexptab_gen_direct(cf_t* x, float freq, uint32_t len) +{ uint32_t i; for (i = 0; i < len; i++) { x[i] = cexpf(_Complex_I * 2 * M_PI * freq * i); diff --git a/lib/src/phy/utils/convolution.c b/lib/src/phy/utils/convolution.c index ffe923b91..cd90812b2 100644 --- a/lib/src/phy/utils/convolution.c +++ b/lib/src/phy/utils/convolution.c @@ -24,73 +24,75 @@ #include #include "srslte/phy/dft/dft.h" -#include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/convolution.h" +#include "srslte/phy/utils/vector.h" - -int srslte_conv_fft_cc_init(srslte_conv_fft_cc_t *q, uint32_t input_len, uint32_t filter_len) { +int srslte_conv_fft_cc_init(srslte_conv_fft_cc_t* q, uint32_t input_len, uint32_t filter_len) +{ bzero(q, sizeof(srslte_conv_fft_cc_t)); - q->input_len = input_len; - q->filter_len = filter_len; - q->output_len = input_len+filter_len; + q->input_len = input_len; + q->filter_len = filter_len; + q->output_len = input_len + filter_len; q->max_filter_len = filter_len; q->max_input_len = input_len; - q->input_fft = srslte_vec_malloc(sizeof(cf_t)*q->output_len); - q->filter_fft = srslte_vec_malloc(sizeof(cf_t)*q->output_len); - q->output_fft = srslte_vec_malloc(sizeof(cf_t)*q->output_len); + q->input_fft = srslte_vec_malloc(sizeof(cf_t) * q->output_len); + q->filter_fft = srslte_vec_malloc(sizeof(cf_t) * q->output_len); + q->output_fft = srslte_vec_malloc(sizeof(cf_t) * q->output_len); if (!q->input_fft || !q->filter_fft || !q->output_fft) { return SRSLTE_ERROR; } - if (srslte_dft_plan(&q->input_plan,q->output_len,SRSLTE_DFT_FORWARD,SRSLTE_DFT_COMPLEX)) { + if (srslte_dft_plan(&q->input_plan, q->output_len, SRSLTE_DFT_FORWARD, SRSLTE_DFT_COMPLEX)) { ERROR("Error initiating input plan\n"); return SRSLTE_ERROR; } - if (srslte_dft_plan(&q->filter_plan,q->output_len,SRSLTE_DFT_FORWARD,SRSLTE_DFT_COMPLEX)) { + if (srslte_dft_plan(&q->filter_plan, q->output_len, SRSLTE_DFT_FORWARD, SRSLTE_DFT_COMPLEX)) { ERROR("Error initiating filter plan\n"); return SRSLTE_ERROR; } - if (srslte_dft_plan(&q->output_plan,q->output_len,SRSLTE_DFT_BACKWARD,SRSLTE_DFT_COMPLEX)) { + if (srslte_dft_plan(&q->output_plan, q->output_len, SRSLTE_DFT_BACKWARD, SRSLTE_DFT_COMPLEX)) { ERROR("Error initiating output plan\n"); return SRSLTE_ERROR; } srslte_dft_plan_set_norm(&q->input_plan, true); srslte_dft_plan_set_norm(&q->filter_plan, true); srslte_dft_plan_set_norm(&q->output_plan, false); - + return SRSLTE_SUCCESS; } -int srslte_conv_fft_cc_replan(srslte_conv_fft_cc_t *q, uint32_t input_len, uint32_t filter_len) { +int srslte_conv_fft_cc_replan(srslte_conv_fft_cc_t* q, uint32_t input_len, uint32_t filter_len) +{ if (input_len > q->max_input_len || filter_len > q->max_filter_len) { ERROR("Error in conv_fft_cc_replan(): input_len and filter_len must be lower than initialized\n"); return -1; } - q->input_len = input_len; + q->input_len = input_len; q->filter_len = filter_len; - q->output_len = input_len+filter_len; + q->output_len = input_len + filter_len; if (!q->input_fft || !q->filter_fft || !q->output_fft) { return SRSLTE_ERROR; } - if (srslte_dft_replan(&q->input_plan,q->output_len)) { + if (srslte_dft_replan(&q->input_plan, q->output_len)) { ERROR("Error initiating input plan\n"); return SRSLTE_ERROR; } - if (srslte_dft_replan(&q->filter_plan,q->output_len)) { + if (srslte_dft_replan(&q->filter_plan, q->output_len)) { ERROR("Error initiating filter plan\n"); return SRSLTE_ERROR; } - if (srslte_dft_replan(&q->output_plan,q->output_len)) { + if (srslte_dft_replan(&q->output_plan, q->output_len)) { ERROR("Error initiating output plan\n"); return SRSLTE_ERROR; } return SRSLTE_SUCCESS; } -void srslte_conv_fft_cc_free(srslte_conv_fft_cc_t *q) { +void srslte_conv_fft_cc_free(srslte_conv_fft_cc_t* q) +{ if (q->input_fft) { free(q->input_fft); } @@ -104,27 +106,25 @@ void srslte_conv_fft_cc_free(srslte_conv_fft_cc_t *q) { srslte_dft_plan_free(&q->input_plan); srslte_dft_plan_free(&q->filter_plan); srslte_dft_plan_free(&q->output_plan); - - bzero(q, sizeof(srslte_conv_fft_cc_t)); + bzero(q, sizeof(srslte_conv_fft_cc_t)); } -uint32_t srslte_conv_fft_cc_run_opt(srslte_conv_fft_cc_t *q, const cf_t *input, const cf_t *filter_freq, cf_t *output) +uint32_t srslte_conv_fft_cc_run_opt(srslte_conv_fft_cc_t* q, const cf_t* input, const cf_t* filter_freq, cf_t* output) { - srslte_dft_run_c(&q->input_plan, input, q->input_fft); - srslte_vec_prod_ccc(q->input_fft, filter_freq, q->output_fft, q->output_len); - srslte_dft_run_c(&q->output_plan, q->output_fft, output); - - return (q->output_len-1); // divide output length by dec factor + srslte_dft_run_c(&q->input_plan, input, q->input_fft); + srslte_vec_prod_ccc(q->input_fft, filter_freq, q->output_fft, q->output_len); + srslte_dft_run_c(&q->output_plan, q->output_fft, output); + return (q->output_len - 1); // divide output length by dec factor } -uint32_t srslte_conv_fft_cc_run(srslte_conv_fft_cc_t *q, const cf_t *input, const cf_t *filter, cf_t *output) { - +uint32_t srslte_conv_fft_cc_run(srslte_conv_fft_cc_t* q, const cf_t* input, const cf_t* filter, cf_t* output) +{ + srslte_dft_run_c(&q->filter_plan, filter, q->filter_fft); return srslte_conv_fft_cc_run_opt(q, input, q->filter_fft, output); - } uint32_t srslte_corr_fft_cc_run_opt(srslte_conv_fft_cc_t* q, cf_t* input, cf_t* filter, cf_t* output) @@ -141,97 +141,98 @@ uint32_t srslte_corr_fft_cc_run(srslte_conv_fft_cc_t* q, cf_t* input, cf_t* filt return srslte_corr_fft_cc_run_opt(q, input, q->filter_fft, output); } -uint32_t srslte_conv_cc(const cf_t *input, const cf_t *filter, cf_t *output, uint32_t input_len, uint32_t filter_len) { +uint32_t srslte_conv_cc(const cf_t* input, const cf_t* filter, cf_t* output, uint32_t input_len, uint32_t filter_len) +{ uint32_t i; - uint32_t M = filter_len; - uint32_t N = input_len; + uint32_t M = filter_len; + uint32_t N = input_len; - for (i=0;i=M-1) { - last[i] = (2+i-M/2)*input[N-1]-(1+i-M/2)*input[N-2]; + for (i = 0; i < M + M / 2; i++) { + if (i >= M - 1) { + last[i] = (2 + i - M / 2) * input[N - 1] - (1 + i - M / 2) * input[N - 2]; } else { - last[i] = input[N-M+i+1]; + last[i] = input[N - M + i + 1]; } } - for (i=0;i #include "srslte/phy/utils/debug.h" +#include -int srslte_verbose = 0; +int srslte_verbose = 0; int handler_registered = 0; -void get_time_interval(struct timeval * tdata) { +void get_time_interval(struct timeval* tdata) +{ - tdata[0].tv_sec = tdata[2].tv_sec - tdata[1].tv_sec; + tdata[0].tv_sec = tdata[2].tv_sec - tdata[1].tv_sec; tdata[0].tv_usec = tdata[2].tv_usec - tdata[1].tv_usec; if (tdata[0].tv_usec < 0) { tdata[0].tv_sec--; diff --git a/lib/src/phy/utils/filter.c b/lib/src/phy/utils/filter.c index a204f037b..8874a09ba 100644 --- a/lib/src/phy/utils/filter.c +++ b/lib/src/phy/utils/filter.c @@ -23,6 +23,7 @@ #define SRSLTE_NUM_FILTERS 8 #define SRSLTE_MAX_FILTER_SIZE 11 +// clang-format off float srslte_filt_decim2[SRSLTE_NUM_FILTERS][SRSLTE_MAX_FILTER_SIZE] = { {0.0167364016736, 0.48326359832636, 0.48326359832636, 0.01673640167364,0,0,0,0,0,0,0}, @@ -48,7 +49,6 @@ float srslte_filt_decim3[SRSLTE_NUM_FILTERS][SRSLTE_MAX_FILTER_SIZE] = }; - float srslte_filt_decim4[SRSLTE_NUM_FILTERS][SRSLTE_MAX_FILTER_SIZE] = { { 0.038579006748772, 0.461420993251228, 0.461420993251228, 0.038579006748772,0,0,0,0,0,0,0}, @@ -61,61 +61,57 @@ float srslte_filt_decim4[SRSLTE_NUM_FILTERS][SRSLTE_MAX_FILTER_SIZE] = {-0.003871323167475, 0.000000000000000, 0.032087799410030, 0.116708621643743, 0.220701186106900, 0.268747432013603, 0.220701186106900, 0.116708621643743 , 0.032087799410030, 0.000000000000000,-0.003871323167475} }; - -void srslte_filt_decim_cc_init(srslte_filt_cc_t *q, int factor, int order) +// clang-format on +void srslte_filt_decim_cc_init(srslte_filt_cc_t* q, int factor, int order) { - q->factor = factor; - q->num_taps = order + 1; - q->is_decimator = true; - q->taps = malloc(q->num_taps * sizeof(float)); - - switch(q->factor) - { - case 2: - for(int i = 0; i <(q->num_taps); i++) - q->taps[i] = srslte_filt_decim2[(q->num_taps) - 4][i]; - break; - case 3: - for(int i = 0; i <(q->num_taps); i++) - q->taps[i] = srslte_filt_decim3[(q->num_taps) - 4][i]; - break; - case 4: - for(int i = 0; i <(q->num_taps); i++) - q->taps[i] = srslte_filt_decim4[(q->num_taps) - 4][i]; - break; - default: - - break; - } - - for(int x = 0; x<(q->num_taps);x++) - { - printf("tap : %f.9\n" ,q->taps[x]); - } + q->factor = factor; + q->num_taps = order + 1; + q->is_decimator = true; + q->taps = malloc(q->num_taps * sizeof(float)); + + switch (q->factor) { + case 2: + for (int i = 0; i < (q->num_taps); i++) + q->taps[i] = srslte_filt_decim2[(q->num_taps) - 4][i]; + break; + case 3: + for (int i = 0; i < (q->num_taps); i++) + q->taps[i] = srslte_filt_decim3[(q->num_taps) - 4][i]; + break; + case 4: + for (int i = 0; i < (q->num_taps); i++) + q->taps[i] = srslte_filt_decim4[(q->num_taps) - 4][i]; + break; + default: + + break; + } + + for (int x = 0; x < (q->num_taps); x++) { + printf("tap : %f.9\n", q->taps[x]); + } } -void srslte_filt_decim_cc_free(srslte_filt_cc_t *q) +void srslte_filt_decim_cc_free(srslte_filt_cc_t* q) { - free(q->taps); + free(q->taps); } -void srslte_filt_decim_cc_execute(srslte_filt_cc_t *q, cf_t *input, cf_t *downsampled_input, cf_t *output, int size) +void srslte_filt_decim_cc_execute(srslte_filt_cc_t* q, cf_t* input, cf_t* downsampled_input, cf_t* output, int size) { - // we assume that "downsampled_input" made size (input/2 + order) so as to have prepended zeros // - srslte_downsample_cc(input, downsampled_input + (q->num_taps - 1), q->factor, size); - - for(int i = 0;i < size/q->factor;i++) - { - output[i] = srslte_vec_dot_prod_cfc(&(downsampled_input[i]), q->taps, q->num_taps); - } - - + // we assume that "downsampled_input" made size (input/2 + order) so as to have prepended zeros // + srslte_downsample_cc(input, downsampled_input + (q->num_taps - 1), q->factor, size); + + for (int i = 0; i < size / q->factor; i++) { + output[i] = srslte_vec_dot_prod_cfc(&(downsampled_input[i]), q->taps, q->num_taps); + } } /* Performs integer linear downsamling by a factor of M */ -void srslte_downsample_cc(cf_t *input, cf_t *output, int M, int size) { +void srslte_downsample_cc(cf_t* input, cf_t* output, int M, int size) +{ int i; - for (i=0;i /* SSE implementation for complex reciprocal */ -inline __m128 srslte_mat_cf_recip_sse(__m128 a) { - __m128 conj = _MM_CONJ_PS(a); +inline __m128 srslte_mat_cf_recip_sse(__m128 a) +{ + __m128 conj = _MM_CONJ_PS(a); __m128 sqabs = _mm_mul_ps(a, a); - sqabs = _mm_add_ps(_mm_movehdup_ps(sqabs), _mm_moveldup_ps(sqabs)); + sqabs = _mm_add_ps(_mm_movehdup_ps(sqabs), _mm_moveldup_ps(sqabs)); __m128 recp = _mm_rcp_ps(sqabs); @@ -135,17 +159,26 @@ inline __m128 srslte_mat_cf_recip_sse(__m128 a) { } /* SSE implementation for 2x2 determinant */ -inline __m128 srslte_mat_2x2_det_sse(__m128 a00, __m128 a01, __m128 a10, __m128 a11) { +inline __m128 srslte_mat_2x2_det_sse(__m128 a00, __m128 a01, __m128 a10, __m128 a11) +{ return _mm_sub_ps(_MM_PROD_PS(a00, a11), _MM_PROD_PS(a01, a10)); } /* SSE implementation for Zero Forcing (ZF) solver */ -inline void srslte_mat_2x2_zf_sse(__m128 y0, __m128 y1, __m128 h00, __m128 h01, __m128 h10, __m128 h11, - __m128 *x0, __m128 *x1, float norm) { +inline void srslte_mat_2x2_zf_sse(__m128 y0, + __m128 y1, + __m128 h00, + __m128 h01, + __m128 h10, + __m128 h11, + __m128* x0, + __m128* x1, + float norm) +{ __m128 detmult1 = _MM_PROD_PS(h00, h11); __m128 detmult2 = _MM_PROD_PS(h01, h10); - __m128 det = _mm_sub_ps(detmult1, detmult2); + __m128 det = _mm_sub_ps(detmult1, detmult2); __m128 detrec = _mm_mul_ps(srslte_mat_cf_recip_sse(det), _mm_set1_ps(norm)); *x0 = _MM_PROD_PS(_mm_sub_ps(_MM_PROD_PS(h11, y0), _MM_PROD_PS(h01, y1)), detrec); @@ -153,10 +186,19 @@ inline void srslte_mat_2x2_zf_sse(__m128 y0, __m128 y1, __m128 h00, __m128 h01, } /* SSE implementation for Minimum Mean Squared Error (MMSE) solver */ -inline void srslte_mat_2x2_mmse_sse(__m128 y0, __m128 y1, __m128 h00, __m128 h01, __m128 h10, __m128 h11, - __m128 *x0, __m128 *x1, float noise_estimate, float norm) { +inline void srslte_mat_2x2_mmse_sse(__m128 y0, + __m128 y1, + __m128 h00, + __m128 h01, + __m128 h10, + __m128 h11, + __m128* x0, + __m128* x1, + float noise_estimate, + float norm) +{ __m128 _noise_estimate = _mm_set_ps(0.0f, noise_estimate, 0.0f, noise_estimate); - __m128 _norm = _mm_set1_ps(norm); + __m128 _norm = _mm_set1_ps(norm); /* Create conjugated matrix */ __m128 _h00 = _MM_CONJ_PS(h00); @@ -175,8 +217,7 @@ inline void srslte_mat_2x2_mmse_sse(__m128 y0, __m128 y1, __m128 h00, __m128 h01 __m128 b01 = _mm_xor_ps(a01, _mm_set1_ps(-0.0f)); __m128 b10 = _mm_xor_ps(a10, _mm_set1_ps(-0.0f)); __m128 b11 = a00; - _norm = _mm_mul_ps(_norm, srslte_mat_cf_recip_sse(srslte_mat_2x2_det_sse(a00, a01, a10, a11))); - + _norm = _mm_mul_ps(_norm, srslte_mat_cf_recip_sse(srslte_mat_2x2_det_sse(a00, a01, a10, a11))); /* 3. W = inv(H' x H + No) x H' = B x H' */ __m128 w00 = _mm_add_ps(_MM_PROD_PS(b00, _h00), _MM_PROD_PS(b01, _h01)); @@ -195,10 +236,11 @@ inline void srslte_mat_2x2_mmse_sse(__m128 y0, __m128 y1, __m128 h00, __m128 h01 #include /* AVX implementation for complex reciprocal */ -inline __m256 srslte_mat_cf_recip_avx(__m256 a) { - __m256 conj = _MM256_CONJ_PS(a); +inline __m256 srslte_mat_cf_recip_avx(__m256 a) +{ + __m256 conj = _MM256_CONJ_PS(a); __m256 sqabs = _mm256_mul_ps(a, a); - sqabs = _mm256_add_ps(_mm256_movehdup_ps(sqabs), _mm256_moveldup_ps(sqabs)); + sqabs = _mm256_add_ps(_mm256_movehdup_ps(sqabs), _mm256_moveldup_ps(sqabs)); __m256 recp = _mm256_rcp_ps(sqabs); @@ -206,7 +248,8 @@ inline __m256 srslte_mat_cf_recip_avx(__m256 a) { } /* AVX implementation for 2x2 determinant */ -inline __m256 srslte_mat_2x2_det_avx(__m256 a00, __m256 a01, __m256 a10, __m256 a11) { +inline __m256 srslte_mat_2x2_det_avx(__m256 a00, __m256 a01, __m256 a10, __m256 a11) +{ #ifdef LV_HAVE_FMA return _MM256_PROD_SUB_PS(a00, a11, _MM256_PROD_PS(a01, a10)); #else @@ -215,26 +258,43 @@ inline __m256 srslte_mat_2x2_det_avx(__m256 a00, __m256 a01, __m256 a10, __m256 } /* AVX implementation for Zero Forcing (ZF) solver */ -inline void srslte_mat_2x2_zf_avx(__m256 y0, __m256 y1, __m256 h00, __m256 h01, __m256 h10, __m256 h11, - __m256 *x0, __m256 *x1, float norm) { - - __m256 det = srslte_mat_2x2_det_avx(h00, h01, h10, h11); +inline void srslte_mat_2x2_zf_avx(__m256 y0, + __m256 y1, + __m256 h00, + __m256 h01, + __m256 h10, + __m256 h11, + __m256* x0, + __m256* x1, + float norm) +{ + + __m256 det = srslte_mat_2x2_det_avx(h00, h01, h10, h11); __m256 detrec = _mm256_mul_ps(srslte_mat_cf_recip_avx(det), _mm256_set1_ps(norm)); #ifdef LV_HAVE_FMA *x0 = _MM256_PROD_PS(_MM256_PROD_SUB_PS(h11, y0, _MM256_PROD_PS(h01, y1)), detrec); *x1 = _MM256_PROD_PS(_MM256_PROD_SUB_PS(h00, y1, _MM256_PROD_PS(h10, y0)), detrec); #else - *x0 = _MM256_PROD_PS(_mm256_sub_ps(_MM256_PROD_PS(h11, y0), _MM256_PROD_PS(h01, y1)), detrec); - *x1 = _MM256_PROD_PS(_mm256_sub_ps(_MM256_PROD_PS(h00, y1), _MM256_PROD_PS(h10, y0)), detrec); + *x0 = _MM256_PROD_PS(_mm256_sub_ps(_MM256_PROD_PS(h11, y0), _MM256_PROD_PS(h01, y1)), detrec); + *x1 = _MM256_PROD_PS(_mm256_sub_ps(_MM256_PROD_PS(h00, y1), _MM256_PROD_PS(h10, y0)), detrec); #endif /* LV_HAVE_FMA */ } /* AVX implementation for Minimum Mean Squared Error (MMSE) solver */ -inline void srslte_mat_2x2_mmse_avx(__m256 y0, __m256 y1, __m256 h00, __m256 h01, __m256 h10, __m256 h11, - __m256 *x0, __m256 *x1, float noise_estimate, float norm) { - __m256 _noise_estimate = _mm256_set_ps(0.0f, noise_estimate, 0.0f, noise_estimate, - 0.0f, noise_estimate, 0.0f, noise_estimate); +inline void srslte_mat_2x2_mmse_avx(__m256 y0, + __m256 y1, + __m256 h00, + __m256 h01, + __m256 h10, + __m256 h11, + __m256* x0, + __m256* x1, + float noise_estimate, + float norm) +{ + __m256 _noise_estimate = + _mm256_set_ps(0.0f, noise_estimate, 0.0f, noise_estimate, 0.0f, noise_estimate, 0.0f, noise_estimate); __m256 _norm = _mm256_set1_ps(norm); /* Create conjugated matrix */ @@ -261,8 +321,7 @@ inline void srslte_mat_2x2_mmse_avx(__m256 y0, __m256 y1, __m256 h00, __m256 h01 __m256 b01 = _mm256_xor_ps(a01, _mm256_set1_ps(-0.0f)); __m256 b10 = _mm256_xor_ps(a10, _mm256_set1_ps(-0.0f)); __m256 b11 = a00; - _norm = _mm256_mul_ps(_norm, srslte_mat_cf_recip_avx(srslte_mat_2x2_det_avx(a00, a01, a10, a11))); - + _norm = _mm256_mul_ps(_norm, srslte_mat_cf_recip_avx(srslte_mat_2x2_det_avx(a00, a01, a10, a11))); /* 3. W = inv(H' x H + No) x H' = B x H' */ #ifdef LV_HAVE_FMA @@ -282,8 +341,8 @@ inline void srslte_mat_2x2_mmse_avx(__m256 y0, __m256 y1, __m256 h00, __m256 h01 *x0 = _MM256_PROD_PS(_MM256_PROD_ADD_PS(y0, w00, _MM256_PROD_PS(y1, w01)), _norm); *x1 = _MM256_PROD_PS(_MM256_PROD_ADD_PS(y0, w10, _MM256_PROD_PS(y1, w11)), _norm); #else - *x0 = _MM256_PROD_PS(_mm256_add_ps(_MM256_PROD_PS(y0, w00), _MM256_PROD_PS(y1, w01)), _norm); - *x1 = _MM256_PROD_PS(_mm256_add_ps(_MM256_PROD_PS(y0, w10), _MM256_PROD_PS(y1, w11)), _norm); + *x0 = _MM256_PROD_PS(_mm256_add_ps(_MM256_PROD_PS(y0, w00), _MM256_PROD_PS(y1, w01)), _norm); + *x1 = _MM256_PROD_PS(_mm256_add_ps(_MM256_PROD_PS(y0, w10), _MM256_PROD_PS(y1, w11)), _norm); #endif /* LV_HAVE_FMA */ } diff --git a/lib/src/phy/utils/phy_logger.c b/lib/src/phy/utils/phy_logger.c index 449030d2c..fdbc0ce54 100644 --- a/lib/src/phy/utils/phy_logger.c +++ b/lib/src/phy/utils/phy_logger.c @@ -31,21 +31,23 @@ /********************************************************************* Functions for external logging *********************************************************************/ -static phy_log_handler_t phy_log_handler; -static void *callback_ctx = NULL; +static phy_log_handler_t phy_log_handler; +static void* callback_ctx = NULL; -void srslte_phy_log_register_handler(void *ctx, phy_log_handler_t handler) { - phy_log_handler = handler; - callback_ctx = ctx; +void srslte_phy_log_register_handler(void* ctx, phy_log_handler_t handler) +{ + phy_log_handler = handler; + callback_ctx = ctx; handler_registered++; } - void srslte_phy_log_print(phy_logger_level_t log_level, const char *format, ...) { - char tmp[256]; - va_list args; +void srslte_phy_log_print(phy_logger_level_t log_level, const char* format, ...) +{ + char tmp[256]; + va_list args; va_start(args, format); if (phy_log_handler) { - if(vsnprintf(tmp, 256, format, args) > 0) { + if (vsnprintf(tmp, 256, format, args) > 0) { phy_log_handler(log_level, callback_ctx, tmp); } } diff --git a/lib/src/phy/utils/ringbuffer.c b/lib/src/phy/utils/ringbuffer.c index 22fe6d23c..8dcd2afee 100644 --- a/lib/src/phy/utils/ringbuffer.c +++ b/lib/src/phy/utils/ringbuffer.c @@ -19,21 +19,21 @@ * */ -#include #include +#include #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/ringbuffer.h" #include "srslte/phy/utils/vector.h" -int srslte_ringbuffer_init(srslte_ringbuffer_t *q, int capacity) +int srslte_ringbuffer_init(srslte_ringbuffer_t* q, int capacity) { q->buffer = srslte_vec_malloc(capacity); if (!q->buffer) { - return -1; + return -1; } - q->active = true; - q->capacity = capacity; + q->active = true; + q->capacity = capacity; pthread_mutex_init(&q->mutex, NULL); pthread_cond_init(&q->write_cvar, NULL); pthread_cond_init(&q->read_cvar, NULL); @@ -42,7 +42,7 @@ int srslte_ringbuffer_init(srslte_ringbuffer_t *q, int capacity) return 0; } -void srslte_ringbuffer_free(srslte_ringbuffer_t *q) +void srslte_ringbuffer_free(srslte_ringbuffer_t* q) { if (q) { srslte_ringbuffer_stop(q); @@ -56,32 +56,32 @@ void srslte_ringbuffer_free(srslte_ringbuffer_t *q) } } -void srslte_ringbuffer_reset(srslte_ringbuffer_t *q) +void srslte_ringbuffer_reset(srslte_ringbuffer_t* q) { // Check first if it is initiated if (q->capacity != 0) { pthread_mutex_lock(&q->mutex); q->count = 0; - q->wpm = 0; - q->rpm = 0; + q->wpm = 0; + q->rpm = 0; pthread_mutex_unlock(&q->mutex); } } -int srslte_ringbuffer_status(srslte_ringbuffer_t *q) +int srslte_ringbuffer_status(srslte_ringbuffer_t* q) { return q->count; } -int srslte_ringbuffer_space(srslte_ringbuffer_t *q) +int srslte_ringbuffer_space(srslte_ringbuffer_t* q) { return q->capacity - q->count; } -int srslte_ringbuffer_write(srslte_ringbuffer_t *q, void *p, int nof_bytes) +int srslte_ringbuffer_write(srslte_ringbuffer_t* q, void* p, int nof_bytes) { - uint8_t *ptr = (uint8_t*) p; - int w_bytes = nof_bytes; + uint8_t* ptr = (uint8_t*)p; + int w_bytes = nof_bytes; pthread_mutex_lock(&q->mutex); if (!q->active) { pthread_mutex_unlock(&q->mutex); @@ -152,11 +152,11 @@ int srslte_ringbuffer_write_timed(srslte_ringbuffer_t* q, void* p, int nof_bytes return w_bytes; } -int srslte_ringbuffer_read(srslte_ringbuffer_t *q, void *p, int nof_bytes) +int srslte_ringbuffer_read(srslte_ringbuffer_t* q, void* p, int nof_bytes) { - uint8_t *ptr = (uint8_t*) p; + uint8_t* ptr = (uint8_t*)p; pthread_mutex_lock(&q->mutex); - while(q->count < nof_bytes && q->active) { + while (q->count < nof_bytes && q->active) { pthread_cond_wait(&q->write_cvar, &q->mutex); } if (!q->active) { @@ -229,7 +229,8 @@ int srslte_ringbuffer_read_timed(srslte_ringbuffer_t* q, void* p, int nof_bytes, return ret; } -void srslte_ringbuffer_stop(srslte_ringbuffer_t *q) { +void srslte_ringbuffer_stop(srslte_ringbuffer_t* q) +{ pthread_mutex_lock(&q->mutex); q->active = false; pthread_cond_broadcast(&q->write_cvar); diff --git a/lib/src/phy/utils/test/dft_test.c b/lib/src/phy/utils/test/dft_test.c index f21ac6184..487c47b18 100644 --- a/lib/src/phy/utils/test/dft_test.c +++ b/lib/src/phy/utils/test/dft_test.c @@ -19,25 +19,24 @@ * */ +#include +#include #include #include #include -#include -#include #include -#include +#include #include "srslte/phy/dft/dft.h" - - -int N = 256; +int N = 256; bool forward = true; -bool mirror = false; -bool norm = false; -bool dc = false; +bool mirror = false; +bool norm = false; +bool dc = false; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s\n", prog); printf("\t-N Transform size [Default 256]\n"); printf("\t-b Backwards transform first [Default Forwards]\n"); @@ -46,36 +45,36 @@ void usage(char *prog) { printf("\t-d Handle insertion/removal of null DC carrier internally [Default false]\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "Nbmnd")) != -1) { switch (opt) { - case 'N': - N = (int)strtol(argv[optind], NULL, 10); - break; - case 'b': - forward = false; - break; - case 'm': - mirror = true; - break; - case 'n': - norm = true; - break; - case 'd': - dc = true; - break; - default: - usage(argv[0]); - exit(-1); + case 'N': + N = (int)strtol(argv[optind], NULL, 10); + break; + case 'b': + forward = false; + break; + case 'm': + mirror = true; + break; + case 'n': + norm = true; + break; + case 'd': + dc = true; + break; + default: + usage(argv[0]); + exit(-1); } } } void print(cf_t* in, int len) { - for(int i=0;i 0.01) + if (diff > 0.01) res = -1; } @@ -138,23 +138,23 @@ int test_dft(cf_t* in){ return res; } -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ parse_args(argc, argv); - cf_t* in = malloc(sizeof(cf_t)*N); - bzero(in, sizeof(cf_t)*N); - for(int i=1;i -#include -#include #include #include +#include +#include #include +#include #include "srslte/phy/utils/mat.h" #include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/vector_simd.h" - -bool zf_solver = false; +bool zf_solver = false; bool mmse_solver = false; -bool verbose = false; +bool verbose = false; -#define RANDOM_F() ((float)rand())/((float)RAND_MAX) +#define RANDOM_F() ((float)rand()) / ((float)RAND_MAX) #define RANDOM_S() ((int16_t)(rand() && 0x800F)) -#define RANDOM_CF() (RANDOM_F() + _Complex_I*RANDOM_F()) +#define RANDOM_CF() (RANDOM_F() + _Complex_I * RANDOM_F()) -double elapsed_us(struct timeval *ts_start, struct timeval *ts_end) { +double elapsed_us(struct timeval* ts_start, struct timeval* ts_end) +{ if (ts_end->tv_usec > ts_start->tv_usec) { - return ((double) ts_end->tv_sec - (double) ts_start->tv_sec) * 1000000 + - (double) ts_end->tv_usec - (double) ts_start->tv_usec; + return ((double)ts_end->tv_sec - (double)ts_start->tv_sec) * 1000000 + (double)ts_end->tv_usec - + (double)ts_start->tv_usec; } else { - return ((double) ts_end->tv_sec - (double) ts_start->tv_sec - 1) * 1000000 + - ((double) ts_end->tv_usec + 1000000) - (double) ts_start->tv_usec; + return ((double)ts_end->tv_sec - (double)ts_start->tv_sec - 1) * 1000000 + ((double)ts_end->tv_usec + 1000000) - + (double)ts_start->tv_usec; } } #define BLOCK_SIZE 1000 -#define RUN_TEST(FUNCTION) /*TYPE NAME (void)*/ { \ - int i;\ - struct timeval start, end;\ - gettimeofday(&start, NULL); \ - bool ret = true; \ - for (i = 0; i < BLOCK_SIZE; i++) {ret &= FUNCTION ();}\ - gettimeofday(&end, NULL);\ - if (verbose) printf("%32s: %s ... %6.2f us/call\n", #FUNCTION, (ret)?"Pass":"Fail", \ - elapsed_us(&start, &end)/BLOCK_SIZE);\ - passed &= ret;\ -} +#define RUN_TEST(FUNCTION) /*TYPE NAME (void)*/ \ + { \ + int i; \ + struct timeval start, end; \ + gettimeofday(&start, NULL); \ + bool ret = true; \ + for (i = 0; i < BLOCK_SIZE; i++) { \ + ret &= FUNCTION(); \ + } \ + gettimeofday(&end, NULL); \ + if (verbose) \ + printf( \ + "%32s: %s ... %6.2f us/call\n", #FUNCTION, (ret) ? "Pass" : "Fail", elapsed_us(&start, &end) / BLOCK_SIZE); \ + passed &= ret; \ + } -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [mzvh]\n", prog); printf("\t-m Test Minimum Mean Squared Error (MMSE) solver\n"); printf("\t-z Test Zero Forcing (ZF) solver\n"); @@ -70,7 +75,8 @@ void usage(char *prog) { printf("\t-h Show this message\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "mzvh")) != -1) { switch (opt) { @@ -91,47 +97,49 @@ void parse_args(int argc, char **argv) { } } -bool test_zf_solver_gen(void) { - cf_t x0, x1, cf_error0, cf_error1; +bool test_zf_solver_gen(void) +{ + cf_t x0, x1, cf_error0, cf_error1; float error; cf_t x0_gold = RANDOM_CF(); cf_t x1_gold = RANDOM_CF(); - cf_t h00 = RANDOM_CF(); - cf_t h01 = RANDOM_CF(); - cf_t h10 = RANDOM_CF(); - cf_t h11 = (1 - h01 * h10) / h00; - cf_t y0 = x0_gold * h00 + x1_gold * h01; - cf_t y1 = x0_gold * h10 + x1_gold * h11; + cf_t h00 = RANDOM_CF(); + cf_t h01 = RANDOM_CF(); + cf_t h10 = RANDOM_CF(); + cf_t h11 = (1 - h01 * h10) / h00; + cf_t y0 = x0_gold * h00 + x1_gold * h01; + cf_t y1 = x0_gold * h10 + x1_gold * h11; srslte_mat_2x2_zf_gen(y0, y1, h00, h01, h10, h11, &x0, &x1, 1.0f); cf_error0 = x0 - x0_gold; cf_error1 = x1 - x1_gold; - error = crealf(cf_error0) * crealf(cf_error0) + cimagf(cf_error0) * cimagf(cf_error0) + + error = crealf(cf_error0) * crealf(cf_error0) + cimagf(cf_error0) * cimagf(cf_error0) + crealf(cf_error1) * crealf(cf_error1) + cimagf(cf_error1) * cimagf(cf_error1); return (error < 1e-6); } -bool test_mmse_solver_gen(void) { - cf_t x0, x1, cf_error0, cf_error1; +bool test_mmse_solver_gen(void) +{ + cf_t x0, x1, cf_error0, cf_error1; float error; cf_t x0_gold = RANDOM_CF(); cf_t x1_gold = RANDOM_CF(); - cf_t h00 = RANDOM_CF(); - cf_t h01 = RANDOM_CF(); - cf_t h10 = RANDOM_CF(); - cf_t h11 = (1 - h01 * h10) / h00; - cf_t y0 = x0_gold * h00 + x1_gold * h01; - cf_t y1 = x0_gold * h10 + x1_gold * h11; + cf_t h00 = RANDOM_CF(); + cf_t h01 = RANDOM_CF(); + cf_t h10 = RANDOM_CF(); + cf_t h11 = (1 - h01 * h10) / h00; + cf_t y0 = x0_gold * h00 + x1_gold * h01; + cf_t y1 = x0_gold * h10 + x1_gold * h11; srslte_mat_2x2_mmse_gen(y0, y1, h00, h01, h10, h11, &x0, &x1, 0.0f, 1.0f); cf_error0 = x0 - x0_gold; cf_error1 = x1 - x1_gold; - error = crealf(cf_error0) * crealf(cf_error0) + cimagf(cf_error0) * cimagf(cf_error0) + + error = crealf(cf_error0) * crealf(cf_error0) + cimagf(cf_error0) * cimagf(cf_error0) + crealf(cf_error1) * crealf(cf_error1) + cimagf(cf_error1) * cimagf(cf_error1); return (error < 1e-6); @@ -139,27 +147,28 @@ bool test_mmse_solver_gen(void) { #ifdef LV_HAVE_SSE -bool test_zf_solver_sse(void) { - cf_t cf_error0, cf_error1; +bool test_zf_solver_sse(void) +{ + cf_t cf_error0, cf_error1; float error = 0.0f; cf_t x0_gold_1 = RANDOM_CF(); cf_t x1_gold_1 = RANDOM_CF(); - cf_t h00_1 = RANDOM_CF(); - cf_t h01_1 = RANDOM_CF(); - cf_t h10_1 = RANDOM_CF(); - cf_t h11_1 = (1 - h01_1 * h10_1) / h00_1; - cf_t y0_1 = x0_gold_1 * h00_1 + x1_gold_1 * h01_1; - cf_t y1_1 = x0_gold_1 * h10_1 + x1_gold_1 * h11_1; + cf_t h00_1 = RANDOM_CF(); + cf_t h01_1 = RANDOM_CF(); + cf_t h10_1 = RANDOM_CF(); + cf_t h11_1 = (1 - h01_1 * h10_1) / h00_1; + cf_t y0_1 = x0_gold_1 * h00_1 + x1_gold_1 * h01_1; + cf_t y1_1 = x0_gold_1 * h10_1 + x1_gold_1 * h11_1; cf_t x0_gold_2 = RANDOM_CF(); cf_t x1_gold_2 = RANDOM_CF(); - cf_t h00_2 = RANDOM_CF(); - cf_t h01_2 = RANDOM_CF(); - cf_t h10_2 = RANDOM_CF(); - cf_t h11_2 = (1 - h01_2 * h10_2) / h00_2; - cf_t y0_2 = x0_gold_2 * h00_2 + x1_gold_2 * h01_2; - cf_t y1_2 = x0_gold_2 * h10_2 + x1_gold_2 * h11_2; + cf_t h00_2 = RANDOM_CF(); + cf_t h01_2 = RANDOM_CF(); + cf_t h10_2 = RANDOM_CF(); + cf_t h11_2 = (1 - h01_2 * h10_2) / h00_2; + cf_t y0_2 = x0_gold_2 * h00_2 + x1_gold_2 * h01_2; + cf_t y1_2 = x0_gold_2 * h10_2 + x1_gold_2 * h11_2; __m128 _y0 = _mm_set_ps(cimagf(y0_1), crealf(y0_1), cimagf(y0_2), crealf(y0_2)); __m128 _y1 = _mm_set_ps(cimagf(y1_1), crealf(y1_1), cimagf(y1_2), crealf(y1_2)); @@ -173,12 +182,11 @@ bool test_zf_solver_sse(void) { srslte_mat_2x2_zf_sse(_y0, _y1, _h00, _h01, _h10, _h11, &_x0, &_x1, 1.0f); - __attribute__((aligned(128))) cf_t x0[2]; __attribute__((aligned(128))) cf_t x1[2]; - _mm_store_ps((float *) x0, _x0); - _mm_store_ps((float *) x1, _x1); + _mm_store_ps((float*)x0, _x0); + _mm_store_ps((float*)x1, _x1); cf_error0 = x0[1] - x0_gold_1; cf_error1 = x1[1] - x1_gold_1; @@ -193,27 +201,28 @@ bool test_zf_solver_sse(void) { return (error < 1e-3); } -bool test_mmse_solver_sse(void) { - cf_t cf_error0, cf_error1; +bool test_mmse_solver_sse(void) +{ + cf_t cf_error0, cf_error1; float error = 0.0f; cf_t x0_gold_1 = RANDOM_CF(); cf_t x1_gold_1 = RANDOM_CF(); - cf_t h00_1 = RANDOM_CF(); - cf_t h01_1 = RANDOM_CF(); - cf_t h10_1 = RANDOM_CF(); - cf_t h11_1 = (1 - h01_1 * h10_1) / h00_1; - cf_t y0_1 = x0_gold_1 * h00_1 + x1_gold_1 * h01_1; - cf_t y1_1 = x0_gold_1 * h10_1 + x1_gold_1 * h11_1; + cf_t h00_1 = RANDOM_CF(); + cf_t h01_1 = RANDOM_CF(); + cf_t h10_1 = RANDOM_CF(); + cf_t h11_1 = (1 - h01_1 * h10_1) / h00_1; + cf_t y0_1 = x0_gold_1 * h00_1 + x1_gold_1 * h01_1; + cf_t y1_1 = x0_gold_1 * h10_1 + x1_gold_1 * h11_1; cf_t x0_gold_2 = RANDOM_CF(); cf_t x1_gold_2 = RANDOM_CF(); - cf_t h00_2 = RANDOM_CF(); - cf_t h01_2 = RANDOM_CF(); - cf_t h10_2 = RANDOM_CF(); - cf_t h11_2 = (1 - h01_2 * h10_2) / h00_2; - cf_t y0_2 = x0_gold_2 * h00_2 + x1_gold_2 * h01_2; - cf_t y1_2 = x0_gold_2 * h10_2 + x1_gold_2 * h11_2; + cf_t h00_2 = RANDOM_CF(); + cf_t h01_2 = RANDOM_CF(); + cf_t h10_2 = RANDOM_CF(); + cf_t h11_2 = (1 - h01_2 * h10_2) / h00_2; + cf_t y0_2 = x0_gold_2 * h00_2 + x1_gold_2 * h01_2; + cf_t y1_2 = x0_gold_2 * h10_2 + x1_gold_2 * h11_2; __m128 _y0 = _mm_set_ps(cimagf(y0_1), crealf(y0_1), cimagf(y0_2), crealf(y0_2)); __m128 _y1 = _mm_set_ps(cimagf(y1_1), crealf(y1_1), cimagf(y1_2), crealf(y1_2)); @@ -227,12 +236,11 @@ bool test_mmse_solver_sse(void) { srslte_mat_2x2_mmse_sse(_y0, _y1, _h00, _h01, _h10, _h11, &_x0, &_x1, 0.0f, 1.0f); - __attribute__((aligned(128))) cf_t x0[2]; __attribute__((aligned(128))) cf_t x1[2]; - _mm_store_ps((float *) x0, _x0); - _mm_store_ps((float *) x1, _x1); + _mm_store_ps((float*)x0, _x0); + _mm_store_ps((float*)x1, _x1); cf_error0 = x0[1] - x0_gold_1; cf_error1 = x1[1] - x1_gold_1; @@ -251,52 +259,76 @@ bool test_mmse_solver_sse(void) { #ifdef LV_HAVE_AVX -bool test_zf_solver_avx(void) { - cf_t cf_error0, cf_error1; +bool test_zf_solver_avx(void) +{ + cf_t cf_error0, cf_error1; float error = 0.0f; cf_t x0_gold_1 = RANDOM_CF(); cf_t x1_gold_1 = RANDOM_CF(); - cf_t h00_1 = RANDOM_CF(); - cf_t h01_1 = RANDOM_CF(); - cf_t h10_1 = RANDOM_CF(); - cf_t h11_1 = (1 - h01_1 * h10_1) / h00_1; - cf_t y0_1 = x0_gold_1 * h00_1 + x1_gold_1 * h01_1; - cf_t y1_1 = x0_gold_1 * h10_1 + x1_gold_1 * h11_1; + cf_t h00_1 = RANDOM_CF(); + cf_t h01_1 = RANDOM_CF(); + cf_t h10_1 = RANDOM_CF(); + cf_t h11_1 = (1 - h01_1 * h10_1) / h00_1; + cf_t y0_1 = x0_gold_1 * h00_1 + x1_gold_1 * h01_1; + cf_t y1_1 = x0_gold_1 * h10_1 + x1_gold_1 * h11_1; cf_t x0_gold_2 = RANDOM_CF(); cf_t x1_gold_2 = RANDOM_CF(); - cf_t h00_2 = RANDOM_CF(); - cf_t h01_2 = RANDOM_CF(); - cf_t h10_2 = RANDOM_CF(); - cf_t h11_2 = (1 - h01_2 * h10_2) / h00_2; - cf_t y0_2 = x0_gold_2 * h00_2 + x1_gold_2 * h01_2; - cf_t y1_2 = x0_gold_2 * h10_2 + x1_gold_2 * h11_2; - - __m256 _y0 = _mm256_set_ps(cimagf(y0_1), crealf(y0_1), cimagf(y0_2), crealf(y0_2), - cimagf(y0_1), crealf(y0_1), cimagf(y0_2), crealf(y0_2)); - __m256 _y1 = _mm256_set_ps(cimagf(y1_1), crealf(y1_1), cimagf(y1_2), crealf(y1_2), - cimagf(y1_1), crealf(y1_1), cimagf(y1_2), crealf(y1_2)); - - __m256 _h00 = _mm256_set_ps(cimagf(h00_1), crealf(h00_1), cimagf(h00_2), crealf(h00_2), - cimagf(h00_1), crealf(h00_1), cimagf(h00_2), crealf(h00_2)); - __m256 _h01 = _mm256_set_ps(cimagf(h01_1), crealf(h01_1), cimagf(h01_2), crealf(h01_2), - cimagf(h01_1), crealf(h01_1), cimagf(h01_2), crealf(h01_2)); - __m256 _h10 = _mm256_set_ps(cimagf(h10_1), crealf(h10_1), cimagf(h10_2), crealf(h10_2), - cimagf(h10_1), crealf(h10_1), cimagf(h10_2), crealf(h10_2)); - __m256 _h11 = _mm256_set_ps(cimagf(h11_1), crealf(h11_1), cimagf(h11_2), crealf(h11_2), - cimagf(h11_1), crealf(h11_1), cimagf(h11_2), crealf(h11_2)); + cf_t h00_2 = RANDOM_CF(); + cf_t h01_2 = RANDOM_CF(); + cf_t h10_2 = RANDOM_CF(); + cf_t h11_2 = (1 - h01_2 * h10_2) / h00_2; + cf_t y0_2 = x0_gold_2 * h00_2 + x1_gold_2 * h01_2; + cf_t y1_2 = x0_gold_2 * h10_2 + x1_gold_2 * h11_2; + + __m256 _y0 = _mm256_set_ps( + cimagf(y0_1), crealf(y0_1), cimagf(y0_2), crealf(y0_2), cimagf(y0_1), crealf(y0_1), cimagf(y0_2), crealf(y0_2)); + __m256 _y1 = _mm256_set_ps( + cimagf(y1_1), crealf(y1_1), cimagf(y1_2), crealf(y1_2), cimagf(y1_1), crealf(y1_1), cimagf(y1_2), crealf(y1_2)); + + __m256 _h00 = _mm256_set_ps(cimagf(h00_1), + crealf(h00_1), + cimagf(h00_2), + crealf(h00_2), + cimagf(h00_1), + crealf(h00_1), + cimagf(h00_2), + crealf(h00_2)); + __m256 _h01 = _mm256_set_ps(cimagf(h01_1), + crealf(h01_1), + cimagf(h01_2), + crealf(h01_2), + cimagf(h01_1), + crealf(h01_1), + cimagf(h01_2), + crealf(h01_2)); + __m256 _h10 = _mm256_set_ps(cimagf(h10_1), + crealf(h10_1), + cimagf(h10_2), + crealf(h10_2), + cimagf(h10_1), + crealf(h10_1), + cimagf(h10_2), + crealf(h10_2)); + __m256 _h11 = _mm256_set_ps(cimagf(h11_1), + crealf(h11_1), + cimagf(h11_2), + crealf(h11_2), + cimagf(h11_1), + crealf(h11_1), + cimagf(h11_2), + crealf(h11_2)); __m256 _x0, _x1; srslte_mat_2x2_zf_avx(_y0, _y1, _h00, _h01, _h10, _h11, &_x0, &_x1, 1.0f); - __attribute__((aligned(256))) cf_t x0[4]; __attribute__((aligned(256))) cf_t x1[4]; - _mm256_store_ps((float *) x0, _x0); - _mm256_store_ps((float *) x1, _x1); + _mm256_store_ps((float*)x0, _x0); + _mm256_store_ps((float*)x1, _x1); cf_error0 = x0[1] - x0_gold_1; cf_error1 = x1[1] - x1_gold_1; @@ -311,52 +343,76 @@ bool test_zf_solver_avx(void) { return (error < 1e-3); } -bool test_mmse_solver_avx(void) { - cf_t cf_error0, cf_error1; +bool test_mmse_solver_avx(void) +{ + cf_t cf_error0, cf_error1; float error = 0.0f; cf_t x0_gold_1 = RANDOM_CF(); cf_t x1_gold_1 = RANDOM_CF(); - cf_t h00_1 = RANDOM_CF(); - cf_t h01_1 = RANDOM_CF(); - cf_t h10_1 = RANDOM_CF(); - cf_t h11_1 = (1 - h01_1 * h10_1) / h00_1; - cf_t y0_1 = x0_gold_1 * h00_1 + x1_gold_1 * h01_1; - cf_t y1_1 = x0_gold_1 * h10_1 + x1_gold_1 * h11_1; + cf_t h00_1 = RANDOM_CF(); + cf_t h01_1 = RANDOM_CF(); + cf_t h10_1 = RANDOM_CF(); + cf_t h11_1 = (1 - h01_1 * h10_1) / h00_1; + cf_t y0_1 = x0_gold_1 * h00_1 + x1_gold_1 * h01_1; + cf_t y1_1 = x0_gold_1 * h10_1 + x1_gold_1 * h11_1; cf_t x0_gold_2 = RANDOM_CF(); cf_t x1_gold_2 = RANDOM_CF(); - cf_t h00_2 = RANDOM_CF(); - cf_t h01_2 = RANDOM_CF(); - cf_t h10_2 = RANDOM_CF(); - cf_t h11_2 = (1 - h01_2 * h10_2) / h00_2; - cf_t y0_2 = x0_gold_2 * h00_2 + x1_gold_2 * h01_2; - cf_t y1_2 = x0_gold_2 * h10_2 + x1_gold_2 * h11_2; - - __m256 _y0 = _mm256_set_ps(cimagf(y0_1), crealf(y0_1), cimagf(y0_2), crealf(y0_2), - cimagf(y0_1), crealf(y0_1), cimagf(y0_2), crealf(y0_2)); - __m256 _y1 = _mm256_set_ps(cimagf(y1_1), crealf(y1_1), cimagf(y1_2), crealf(y1_2), - cimagf(y1_1), crealf(y1_1), cimagf(y1_2), crealf(y1_2)); - - __m256 _h00 = _mm256_set_ps(cimagf(h00_1), crealf(h00_1), cimagf(h00_2), crealf(h00_2), - cimagf(h00_1), crealf(h00_1), cimagf(h00_2), crealf(h00_2)); - __m256 _h01 = _mm256_set_ps(cimagf(h01_1), crealf(h01_1), cimagf(h01_2), crealf(h01_2), - cimagf(h01_1), crealf(h01_1), cimagf(h01_2), crealf(h01_2)); - __m256 _h10 = _mm256_set_ps(cimagf(h10_1), crealf(h10_1), cimagf(h10_2), crealf(h10_2), - cimagf(h10_1), crealf(h10_1), cimagf(h10_2), crealf(h10_2)); - __m256 _h11 = _mm256_set_ps(cimagf(h11_1), crealf(h11_1), cimagf(h11_2), crealf(h11_2), - cimagf(h11_1), crealf(h11_1), cimagf(h11_2), crealf(h11_2)); + cf_t h00_2 = RANDOM_CF(); + cf_t h01_2 = RANDOM_CF(); + cf_t h10_2 = RANDOM_CF(); + cf_t h11_2 = (1 - h01_2 * h10_2) / h00_2; + cf_t y0_2 = x0_gold_2 * h00_2 + x1_gold_2 * h01_2; + cf_t y1_2 = x0_gold_2 * h10_2 + x1_gold_2 * h11_2; + + __m256 _y0 = _mm256_set_ps( + cimagf(y0_1), crealf(y0_1), cimagf(y0_2), crealf(y0_2), cimagf(y0_1), crealf(y0_1), cimagf(y0_2), crealf(y0_2)); + __m256 _y1 = _mm256_set_ps( + cimagf(y1_1), crealf(y1_1), cimagf(y1_2), crealf(y1_2), cimagf(y1_1), crealf(y1_1), cimagf(y1_2), crealf(y1_2)); + + __m256 _h00 = _mm256_set_ps(cimagf(h00_1), + crealf(h00_1), + cimagf(h00_2), + crealf(h00_2), + cimagf(h00_1), + crealf(h00_1), + cimagf(h00_2), + crealf(h00_2)); + __m256 _h01 = _mm256_set_ps(cimagf(h01_1), + crealf(h01_1), + cimagf(h01_2), + crealf(h01_2), + cimagf(h01_1), + crealf(h01_1), + cimagf(h01_2), + crealf(h01_2)); + __m256 _h10 = _mm256_set_ps(cimagf(h10_1), + crealf(h10_1), + cimagf(h10_2), + crealf(h10_2), + cimagf(h10_1), + crealf(h10_1), + cimagf(h10_2), + crealf(h10_2)); + __m256 _h11 = _mm256_set_ps(cimagf(h11_1), + crealf(h11_1), + cimagf(h11_2), + crealf(h11_2), + cimagf(h11_1), + crealf(h11_1), + cimagf(h11_2), + crealf(h11_2)); __m256 _x0, _x1; srslte_mat_2x2_mmse_avx(_y0, _y1, _h00, _h01, _h10, _h11, &_x0, &_x1, 0.0f, 1.0f); - __attribute__((aligned(256))) cf_t x0[4]; __attribute__((aligned(256))) cf_t x1[4]; - _mm256_store_ps((float *) x0, _x0); - _mm256_store_ps((float *) x1, _x1); + _mm256_store_ps((float*)x0, _x0); + _mm256_store_ps((float*)x1, _x1); cf_error0 = x0[1] - x0_gold_1; cf_error1 = x1[1] - x1_gold_1; @@ -375,18 +431,19 @@ bool test_mmse_solver_avx(void) { #if SRSLTE_SIMD_CF_SIZE != 0 -bool test_zf_solver_simd(void) { - cf_t cf_error0, cf_error1; +bool test_zf_solver_simd(void) +{ + cf_t cf_error0, cf_error1; float error = 0.0f; cf_t x0_gold_1 = RANDOM_CF(); cf_t x1_gold_1 = RANDOM_CF(); - cf_t h00_1 = RANDOM_CF(); - cf_t h01_1 = RANDOM_CF(); - cf_t h10_1 = RANDOM_CF(); - cf_t h11_1 = (1 - h01_1 * h10_1) / h00_1; - cf_t y0_1 = x0_gold_1 * h00_1 + x1_gold_1 * h01_1; - cf_t y1_1 = x0_gold_1 * h10_1 + x1_gold_1 * h11_1; + cf_t h00_1 = RANDOM_CF(); + cf_t h01_1 = RANDOM_CF(); + cf_t h10_1 = RANDOM_CF(); + cf_t h11_1 = (1 - h01_1 * h10_1) / h00_1; + cf_t y0_1 = x0_gold_1 * h00_1 + x1_gold_1 * h01_1; + cf_t y1_1 = x0_gold_1 * h10_1 + x1_gold_1 * h11_1; simd_cf_t _y0 = srslte_simd_cf_set1(y0_1); simd_cf_t _y1 = srslte_simd_cf_set1(y1_1); @@ -409,13 +466,14 @@ bool test_zf_solver_simd(void) { cf_error0 = x0[1] - x0_gold_1; cf_error1 = x1[1] - x1_gold_1; error += crealf(cf_error0) * crealf(cf_error0) + cimagf(cf_error0) * cimagf(cf_error0) + - crealf(cf_error1) * crealf(cf_error1) + cimagf(cf_error1) * cimagf(cf_error1); + crealf(cf_error1) * crealf(cf_error1) + cimagf(cf_error1) * cimagf(cf_error1); return (error < 1e-3); } -bool test_mmse_solver_simd(void) { - cf_t cf_error0, cf_error1; +bool test_mmse_solver_simd(void) +{ + cf_t cf_error0, cf_error1; float error = 0.0f; cf_t x0_gold[SRSLTE_SIMD_CF_SIZE]; @@ -429,12 +487,12 @@ bool test_mmse_solver_simd(void) { for (int i = 0; i < SRSLTE_SIMD_CF_SIZE; i++) { x0_gold[i] = RANDOM_CF(); x1_gold[i] = RANDOM_CF(); - h00[i] = RANDOM_CF(); - h01[i] = RANDOM_CF(); - h10[i] = RANDOM_CF(); - h11[i] = (1 - h01[i] * h10[i]) / h00[i]; - y0[i] = x0_gold[i] * h00[i]+ x1_gold[i] * h01[i]; - y1[i] = x0_gold[i] * h10[i] + x1_gold[i] * h11[i]; + h00[i] = RANDOM_CF(); + h01[i] = RANDOM_CF(); + h10[i] = RANDOM_CF(); + h11[i] = (1 - h01[i] * h10[i]) / h00[i]; + y0[i] = x0_gold[i] * h00[i] + x1_gold[i] * h01[i]; + y1[i] = x0_gold[i] * h10[i] + x1_gold[i] * h11[i]; } simd_cf_t _y0 = srslte_simd_cfi_loadu(y0); @@ -458,17 +516,18 @@ bool test_mmse_solver_simd(void) { cf_error0 = x0[1] - x0_gold[1]; cf_error1 = x1[1] - x1_gold[1]; error += crealf(cf_error0) * crealf(cf_error0) + cimagf(cf_error0) * cimagf(cf_error0) + - crealf(cf_error1) * crealf(cf_error1) + cimagf(cf_error1) * cimagf(cf_error1); + crealf(cf_error1) * crealf(cf_error1) + cimagf(cf_error1) * cimagf(cf_error1); return (error < 1e-3); } #endif /* SRSLTE_SIMD_CF_SIZE != 0 */ -bool test_vec_dot_prod_ccc(void) { +bool test_vec_dot_prod_ccc(void) +{ __attribute__((aligned(256))) cf_t a[14]; __attribute__((aligned(256))) cf_t b[14]; - cf_t res = 0, gold = 0; + cf_t res = 0, gold = 0; for (int i = 0; i < 14; i++) { a[i] = RANDOM_CF(); @@ -477,16 +536,17 @@ bool test_vec_dot_prod_ccc(void) { res = srslte_vec_dot_prod_ccc(a, b, 14); - for (int i=0;i<14;i++) { - gold += a[i]*b[i]; + for (int i = 0; i < 14; i++) { + gold += a[i] * b[i]; } return (cabsf(res - gold) < 1e-3); } -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ bool passed = true; - int ret = 0; + int ret = 0; parse_args(argc, argv); @@ -513,7 +573,6 @@ int main(int argc, char **argv) { RUN_TEST(test_mmse_solver_sse); #endif /* LV_HAVE_SSE */ - #ifdef LV_HAVE_AVX RUN_TEST(test_mmse_solver_avx); #endif /* LV_HAVE_AVX */ diff --git a/lib/src/phy/utils/test/vector_test.c b/lib/src/phy/utils/test/vector_test.c index 7425d3068..0d94d8e30 100644 --- a/lib/src/phy/utils/test/vector_test.c +++ b/lib/src/phy/utils/test/vector_test.c @@ -22,9 +22,9 @@ #include "srslte/srslte.h" #include -bool zf_solver = false; +bool zf_solver = false; bool mmse_solver = false; -bool verbose = false; +bool verbose = false; static uint32_t nof_repetitions = 1; @@ -66,796 +66,812 @@ static srslte_random_t random_h = NULL; return passed; \ } -#define MALLOC(TYPE, NAME) TYPE *NAME = srslte_vec_malloc(sizeof(TYPE)*block_size) +#define MALLOC(TYPE, NAME) TYPE* NAME = srslte_vec_malloc(sizeof(TYPE) * block_size) - -static double elapsed_us(struct timeval *ts_start, struct timeval *ts_end) { +static double elapsed_us(struct timeval* ts_start, struct timeval* ts_end) +{ if (ts_end->tv_usec > ts_start->tv_usec) { - return ((double) ts_end->tv_sec - (double) ts_start->tv_sec) * 1000000 + - (double) ts_end->tv_usec - (double) ts_start->tv_usec; + return ((double)ts_end->tv_sec - (double)ts_start->tv_sec) * 1000000 + (double)ts_end->tv_usec - + (double)ts_start->tv_usec; } else { - return ((double) ts_end->tv_sec - (double) ts_start->tv_sec - 1) * 1000000 + - ((double) ts_end->tv_usec + 1000000) - (double) ts_start->tv_usec; + return ((double)ts_end->tv_sec - (double)ts_start->tv_sec - 1) * 1000000 + ((double)ts_end->tv_usec + 1000000) - + (double)ts_start->tv_usec; } } -float squared_error (cf_t a, cf_t b) { +float squared_error(cf_t a, cf_t b) +{ float diff_re = __real__ a - __real__ b; float diff_im = __imag__ a - __imag__ b; - return diff_re*diff_re + diff_im*diff_im; + return diff_re * diff_re + diff_im * diff_im; } - TEST(srslte_vec_xor_bbb, - MALLOC(int8_t, x); - MALLOC(int8_t, y); - MALLOC(int8_t, z); +TEST( + srslte_vec_xor_bbb, MALLOC(int8_t, x); MALLOC(int8_t, y); MALLOC(int8_t, z); - cf_t gold = 0.0f; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_B(); - y[i] = RANDOM_B(); - } + cf_t gold = 0.0f; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_B(); + y[i] = RANDOM_B(); + } - TEST_CALL(srslte_vec_xor_bbb(x, y, z, block_size)) + TEST_CALL(srslte_vec_xor_bbb(x, y, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] ^ y[i]; - mse += cabsf(gold - z[i]); - } + for (int i = 0; i < block_size; i++) { + gold = x[i] ^ y[i]; + mse += cabsf(gold - z[i]); + } - free(x); - free(y); - free(z); -) + free(x); + free(y); + free(z);) - TEST(srslte_vec_acc_ff, MALLOC(float, x); float z = 0; +TEST(srslte_vec_acc_ff, MALLOC(float, x); float z = 0; - cf_t gold = 0.0f; - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_F(); } + cf_t gold = 0.0f; + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_F(); } - TEST_CALL(z = srslte_vec_acc_ff(x, block_size)) + TEST_CALL(z = srslte_vec_acc_ff(x, block_size)) - for (int i = 0; i < block_size; i++) { gold += x[i]; } + for (int i = 0; i < block_size; i++) { gold += x[i]; } - mse += fabs(gold - z) / gold; + mse += fabs(gold - z) / gold; - free(x);) + free(x);) - TEST( - srslte_vec_dot_prod_sss, MALLOC(int16_t, x); MALLOC(int16_t, y); int16_t z = 0; +TEST( + srslte_vec_dot_prod_sss, MALLOC(int16_t, x); MALLOC(int16_t, y); int16_t z = 0; - int16_t gold = 0.0f; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_S(); - y[i] = RANDOM_S(); - } + int16_t gold = 0.0f; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_S(); + y[i] = RANDOM_S(); + } - TEST_CALL(z = srslte_vec_dot_prod_sss(x, y, block_size)) + TEST_CALL(z = srslte_vec_dot_prod_sss(x, y, block_size)) - for (int i = 0; i < block_size; i++) { gold += x[i] * y[i]; } + for (int i = 0; i < block_size; i++) { gold += x[i] * y[i]; } - mse = (gold - z) / abs(gold); + mse = (gold - z) / abs(gold); - free(x); - free(y);) + free(x); + free(y);) - TEST( - srslte_vec_sum_sss, MALLOC(int16_t, x); MALLOC(int16_t, y); MALLOC(int16_t, z); +TEST( + srslte_vec_sum_sss, MALLOC(int16_t, x); MALLOC(int16_t, y); MALLOC(int16_t, z); - int16_t gold = 0; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_S(); - y[i] = RANDOM_S(); - } + int16_t gold = 0; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_S(); + y[i] = RANDOM_S(); + } - TEST_CALL(srslte_vec_sum_sss(x, y, z, block_size)) + TEST_CALL(srslte_vec_sum_sss(x, y, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] + y[i]; - mse += abs(gold - z[i]); - } + for (int i = 0; i < block_size; i++) { + gold = x[i] + y[i]; + mse += abs(gold - z[i]); + } - free(x); - free(y); - free(z);) + free(x); + free(y); + free(z);) - TEST( - srslte_vec_sub_sss, MALLOC(int16_t, x); MALLOC(int16_t, y); MALLOC(int16_t, z); +TEST( + srslte_vec_sub_sss, MALLOC(int16_t, x); MALLOC(int16_t, y); MALLOC(int16_t, z); - int16_t gold = 0.0f; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_S(); - y[i] = RANDOM_S(); - } + int16_t gold = 0.0f; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_S(); + y[i] = RANDOM_S(); + } - TEST_CALL(srslte_vec_sub_sss(x, y, z, block_size)) + TEST_CALL(srslte_vec_sub_sss(x, y, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] - y[i]; - mse += abs(gold - z[i]); - } + for (int i = 0; i < block_size; i++) { + gold = x[i] - y[i]; + mse += abs(gold - z[i]); + } - free(x); - free(y); - free(z);) + free(x); + free(y); + free(z);) - TEST( - srslte_vec_prod_sss, MALLOC(int16_t, x); MALLOC(int16_t, y); MALLOC(int16_t, z); +TEST( + srslte_vec_prod_sss, MALLOC(int16_t, x); MALLOC(int16_t, y); MALLOC(int16_t, z); - int16_t gold = 0.0f; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_S(); - y[i] = RANDOM_S(); - } + int16_t gold = 0.0f; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_S(); + y[i] = RANDOM_S(); + } - TEST_CALL(srslte_vec_prod_sss(x, y, z, block_size)) + TEST_CALL(srslte_vec_prod_sss(x, y, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] * y[i]; - mse += abs(gold - z[i]); - } + for (int i = 0; i < block_size; i++) { + gold = x[i] * y[i]; + mse += abs(gold - z[i]); + } - free(x); - free(y); - free(z);) + free(x); + free(y); + free(z);) - TEST( - srslte_vec_neg_sss, MALLOC(int16_t, x); MALLOC(int16_t, y); MALLOC(int16_t, z); +TEST( + srslte_vec_neg_sss, MALLOC(int16_t, x); MALLOC(int16_t, y); MALLOC(int16_t, z); - int16_t gold = 0.0f; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_S(); - do { - y[i] = RANDOM_S(); - } while (!y[i]); - } + int16_t gold = 0.0f; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_S(); + do { + y[i] = RANDOM_S(); + } while (!y[i]); + } - TEST_CALL(srslte_vec_neg_sss(x, y, z, block_size)) + TEST_CALL(srslte_vec_neg_sss(x, y, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = y[i] < 0 ? -x[i] : x[i]; - mse += abs(gold - z[i]); - } + for (int i = 0; i < block_size; i++) { + gold = y[i] < 0 ? -x[i] : x[i]; + mse += abs(gold - z[i]); + } - free(x); - free(y); - free(z);) + free(x); + free(y); + free(z);) - TEST(srslte_vec_acc_cc, MALLOC(cf_t, x); cf_t z = 0.0f; +TEST(srslte_vec_acc_cc, MALLOC(cf_t, x); cf_t z = 0.0f; - cf_t gold = 0.0f; - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_F(); } + cf_t gold = 0.0f; + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_F(); } - TEST_CALL(z = srslte_vec_acc_cc(x, block_size)) + TEST_CALL(z = srslte_vec_acc_cc(x, block_size)) - for (int i = 0; i < block_size; i++) { gold += x[i]; } + for (int i = 0; i < block_size; i++) { gold += x[i]; } - mse += cabsf(gold - z) / cabsf(gold); + mse += cabsf(gold - z) / cabsf(gold); - free(x);) + free(x);) - TEST( - srslte_vec_sum_fff, MALLOC(float, x); MALLOC(float, y); MALLOC(float, z); +TEST( + srslte_vec_sum_fff, MALLOC(float, x); MALLOC(float, y); MALLOC(float, z); - cf_t gold = 0.0f; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_F(); - y[i] = RANDOM_F(); - } + cf_t gold = 0.0f; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_F(); + y[i] = RANDOM_F(); + } - TEST_CALL(srslte_vec_sum_fff(x, y, z, block_size)) + TEST_CALL(srslte_vec_sum_fff(x, y, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] + y[i]; - mse += cabsf(gold - z[i]); - } + for (int i = 0; i < block_size; i++) { + gold = x[i] + y[i]; + mse += cabsf(gold - z[i]); + } - free(x); - free(y); - free(z);) + free(x); + free(y); + free(z);) - TEST( - srslte_vec_sub_fff, MALLOC(float, x); MALLOC(float, y); MALLOC(float, z); +TEST( + srslte_vec_sub_fff, MALLOC(float, x); MALLOC(float, y); MALLOC(float, z); - cf_t gold = 0.0f; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_F(); - y[i] = RANDOM_F(); - } + cf_t gold = 0.0f; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_F(); + y[i] = RANDOM_F(); + } - TEST_CALL(srslte_vec_sub_fff(x, y, z, block_size)) + TEST_CALL(srslte_vec_sub_fff(x, y, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] - y[i]; - mse += cabsf(gold - z[i]); - } + for (int i = 0; i < block_size; i++) { + gold = x[i] - y[i]; + mse += cabsf(gold - z[i]); + } - free(x); - free(y); - free(z);) + free(x); + free(y); + free(z);) - TEST( - srslte_vec_dot_prod_ccc, MALLOC(cf_t, x); MALLOC(cf_t, y); cf_t z = 0.0f; +TEST( + srslte_vec_dot_prod_ccc, MALLOC(cf_t, x); MALLOC(cf_t, y); cf_t z = 0.0f; - cf_t gold = 0.0f; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_CF(); - y[i] = RANDOM_CF(); - } + cf_t gold = 0.0f; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_CF(); + y[i] = RANDOM_CF(); + } - TEST_CALL(z = srslte_vec_dot_prod_ccc(x, y, block_size)) + TEST_CALL(z = srslte_vec_dot_prod_ccc(x, y, block_size)) - for (int i = 0; i < block_size; i++) { gold += x[i] * y[i]; } + for (int i = 0; i < block_size; i++) { gold += x[i] * y[i]; } - mse = cabsf(gold - z) / cabsf(gold); + mse = cabsf(gold - z) / cabsf(gold); - free(x); - free(y);) + free(x); + free(y);) - TEST( - srslte_vec_dot_prod_conj_ccc, MALLOC(cf_t, x); MALLOC(cf_t, y); cf_t z = 0.0f; +TEST( + srslte_vec_dot_prod_conj_ccc, MALLOC(cf_t, x); MALLOC(cf_t, y); cf_t z = 0.0f; - cf_t gold = 0.0f; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_CF(); - y[i] = RANDOM_CF(); - } + cf_t gold = 0.0f; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_CF(); + y[i] = RANDOM_CF(); + } - TEST_CALL(z = srslte_vec_dot_prod_conj_ccc(x, y, block_size)) + TEST_CALL(z = srslte_vec_dot_prod_conj_ccc(x, y, block_size)) - for (int i = 0; i < block_size; i++) { gold += x[i] * conjf(y[i]); } + for (int i = 0; i < block_size; i++) { gold += x[i] * conjf(y[i]); } - mse = cabsf(gold - z) / cabsf(gold); + mse = cabsf(gold - z) / cabsf(gold); - free(x); - free(y);) + free(x); + free(y);) - TEST( - srslte_vec_prod_ccc, MALLOC(cf_t, x); MALLOC(cf_t, y); MALLOC(cf_t, z); +TEST( + srslte_vec_prod_ccc, MALLOC(cf_t, x); MALLOC(cf_t, y); MALLOC(cf_t, z); - cf_t gold; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_CF(); - y[i] = RANDOM_CF(); - } + cf_t gold; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_CF(); + y[i] = RANDOM_CF(); + } - TEST_CALL(srslte_vec_prod_ccc(x, y, z, block_size)) + TEST_CALL(srslte_vec_prod_ccc(x, y, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] * y[i]; - mse += cabsf(gold - z[i]); - } + for (int i = 0; i < block_size; i++) { + gold = x[i] * y[i]; + mse += cabsf(gold - z[i]); + } - free(x); - free(y); - free(z);) + free(x); + free(y); + free(z);) - TEST( - srslte_vec_prod_ccc_split, MALLOC(float, x_re); MALLOC(float, x_im); MALLOC(float, y_re); MALLOC(float, y_im); - MALLOC(float, z_re); - MALLOC(float, z_im); +TEST( + srslte_vec_prod_ccc_split, MALLOC(float, x_re); MALLOC(float, x_im); MALLOC(float, y_re); MALLOC(float, y_im); + MALLOC(float, z_re); + MALLOC(float, z_im); - cf_t gold; - for (int i = 0; i < block_size; i++) { - x_re[i] = RANDOM_F(); - x_im[i] = RANDOM_F(); - y_re[i] = RANDOM_F(); - y_im[i] = RANDOM_F(); - } + cf_t gold; + for (int i = 0; i < block_size; i++) { + x_re[i] = RANDOM_F(); + x_im[i] = RANDOM_F(); + y_re[i] = RANDOM_F(); + y_im[i] = RANDOM_F(); + } - TEST_CALL(srslte_vec_prod_ccc_split(x_re, x_im, y_re, y_im, z_re, z_im, block_size)) + TEST_CALL(srslte_vec_prod_ccc_split(x_re, x_im, y_re, y_im, z_re, z_im, block_size)) - for (int i = 0; i < block_size; i++) { - gold = (x_re[i] + I * x_im[i]) * (y_re[i] + I * y_im[i]); - mse += cabsf(gold - (z_re[i] + I*z_im[i])); - } + for (int i = 0; i < block_size; i++) { + gold = (x_re[i] + I * x_im[i]) * (y_re[i] + I * y_im[i]); + mse += cabsf(gold - (z_re[i] + I * z_im[i])); + } + + free(x_re); + free(x_im); + free(y_re); + free(y_im); + free(z_re); + free(z_im);) + +TEST( + srslte_vec_prod_conj_ccc, MALLOC(cf_t, x); MALLOC(cf_t, y); MALLOC(cf_t, z); - free(x_re); - free(x_im); - free(y_re); - free(y_im); - free(z_re); - free(z_im);) + cf_t gold; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_CF(); + y[i] = RANDOM_CF(); + } + + TEST_CALL(srslte_vec_prod_conj_ccc(x, y, z, block_size)) + + for (int i = 0; i < block_size; i++) { + gold = x[i] * conjf(y[i]); + mse += cabsf(gold - z[i]); + } + + free(x); + free(y); + free(z);) - TEST( - srslte_vec_prod_conj_ccc, MALLOC(cf_t, x); MALLOC(cf_t, y); MALLOC(cf_t, z); +TEST(srslte_vec_sc_prod_ccc, MALLOC(cf_t, x); MALLOC(cf_t, z); cf_t y = RANDOM_CF(); cf_t gold; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_CF(); - y[i] = RANDOM_CF(); - } + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } - TEST_CALL(srslte_vec_prod_conj_ccc(x, y, z, block_size)) + TEST_CALL(srslte_vec_sc_prod_ccc(x, y, z, block_size)) for (int i = 0; i < block_size; i++) { - gold = x[i] * conjf(y[i]); + gold = x[i] * y; mse += cabsf(gold - z[i]); } free(x); - free(y); free(z);) - TEST(srslte_vec_sc_prod_ccc, MALLOC(cf_t, x); MALLOC(cf_t, z); cf_t y = RANDOM_CF(); +TEST(srslte_vec_convert_fi, MALLOC(float, x); MALLOC(short, z); float scale = 1000.0f; - cf_t gold; - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } + short gold; + for (int i = 0; i < block_size; i++) { x[i] = (float)RANDOM_F(); } - TEST_CALL(srslte_vec_sc_prod_ccc(x, y, z, block_size)) + TEST_CALL(srslte_vec_convert_fi(x, scale, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] * y; - mse += cabsf(gold - z[i]); - } - - free(x); - free(z);) - - TEST(srslte_vec_convert_fi, MALLOC(float, x); MALLOC(short, z); float scale = 1000.0f; - - short gold; - for (int i = 0; i < block_size; i++) { x[i] = (float)RANDOM_F(); } - - TEST_CALL(srslte_vec_convert_fi(x, scale, z, block_size)) - - for (int i = 0; i < block_size; i++) { - gold = (short)((x[i] * scale)); - double err = cabsf((float)gold - (float)z[i]); - if (err > mse) { - mse = err; - } - } - - free(x); - free(z);) - - TEST(srslte_vec_convert_if, MALLOC(int16_t, x); MALLOC(float, z); float scale = 1000.0f; - - float gold; - float k = 1.0f / scale; - for (int i = 0; i < block_size; i++) { x[i] = (int16_t)RANDOM_S(); } - - TEST_CALL(srslte_vec_convert_if(x, scale, z, block_size)) - - for (int i = 0; i < block_size; i++) { - gold = ((float)x[i]) * k; - double err = cabsf((float)gold - (float)z[i]); - if (err > mse) { - mse = err; - } - } + for (int i = 0; i < block_size; i++) { + gold = (short)((x[i] * scale)); + double err = cabsf((float)gold - (float)z[i]); + if (err > mse) { + mse = err; + } + } - free(x); - free(z);) + free(x); + free(z);) - TEST( - srslte_vec_prod_fff, MALLOC(float, x); MALLOC(float, y); MALLOC(float, z); +TEST(srslte_vec_convert_if, MALLOC(int16_t, x); MALLOC(float, z); float scale = 1000.0f; float gold; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_F(); - y[i] = RANDOM_F(); - if (isnan(x[i])) { - printf("RANDOM_F!! x=%f; y=%f\n", x[i], y[i]); - } - } + float k = 1.0f / scale; + for (int i = 0; i < block_size; i++) { x[i] = (int16_t)RANDOM_S(); } - TEST_CALL(srslte_vec_prod_fff(x, y, z, block_size)) + TEST_CALL(srslte_vec_convert_if(x, scale, z, block_size)) for (int i = 0; i < block_size; i++) { - gold = x[i] * y[i]; - if (isnan(gold)) { - printf("x=%f; y=%f\n", x[i], y[i]); + gold = ((float)x[i]) * k; + double err = cabsf((float)gold - (float)z[i]); + if (err > mse) { + mse = err; } - mse += fabsf(gold - z[i]); } free(x); - free(y); free(z);) - TEST( - srslte_vec_prod_cfc, MALLOC(cf_t, x); MALLOC(float, y); MALLOC(cf_t, z); +TEST( + srslte_vec_prod_fff, MALLOC(float, x); MALLOC(float, y); MALLOC(float, z); - cf_t gold; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_CF(); - y[i] = RANDOM_F(); - } + float gold; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_F(); + y[i] = RANDOM_F(); + if (isnan(x[i])) { + printf("RANDOM_F!! x=%f; y=%f\n", x[i], y[i]); + } + } - TEST_CALL(srslte_vec_prod_cfc(x, y, z, block_size)) + TEST_CALL(srslte_vec_prod_fff(x, y, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] * y[i]; - mse += cabsf(gold - z[i]); - } + for (int i = 0; i < block_size; i++) { + gold = x[i] * y[i]; + if (isnan(gold)) { + printf("x=%f; y=%f\n", x[i], y[i]); + } + mse += fabsf(gold - z[i]); + } - free(x); - free(y); - free(z);) + free(x); + free(y); + free(z);) - TEST(srslte_vec_sc_prod_fff, MALLOC(float, x); MALLOC(float, z); float y = RANDOM_F(); +TEST( + srslte_vec_prod_cfc, MALLOC(cf_t, x); MALLOC(float, y); MALLOC(cf_t, z); - float gold; - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } + cf_t gold; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_CF(); + y[i] = RANDOM_F(); + } - TEST_CALL(srslte_vec_sc_prod_fff(x, y, z, block_size)) + TEST_CALL(srslte_vec_prod_cfc(x, y, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] * y; - mse += cabsf(gold - z[i]); - } + for (int i = 0; i < block_size; i++) { + gold = x[i] * y[i]; + mse += cabsf(gold - z[i]); + } - free(x); - free(z);) + free(x); + free(y); + free(z);) - TEST( - srslte_vec_abs_cf, MALLOC(cf_t, x); MALLOC(float, z); float gold; +TEST(srslte_vec_sc_prod_fff, MALLOC(float, x); MALLOC(float, z); float y = RANDOM_F(); - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } x[0] = 0.0f; + float gold; + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } - TEST_CALL(srslte_vec_abs_cf(x, z, block_size)) + TEST_CALL(srslte_vec_sc_prod_fff(x, y, z, block_size)) for (int i = 0; i < block_size; i++) { - gold = sqrtf(crealf(x[i]) * crealf(x[i]) + cimagf(x[i]) * cimagf(x[i])); - mse += cabsf(gold - z[i]) / block_size; + gold = x[i] * y; + mse += cabsf(gold - z[i]); } free(x); free(z);) - TEST(srslte_vec_abs_square_cf, MALLOC(cf_t, x); MALLOC(float, z); float gold; +TEST( + srslte_vec_abs_cf, MALLOC(cf_t, x); MALLOC(float, z); float gold; - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } x[0] = 0.0f; - TEST_CALL(srslte_vec_abs_square_cf(x, z, block_size)) + TEST_CALL(srslte_vec_abs_cf(x, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = crealf(x[i]) * crealf(x[i]) + cimagf(x[i]) * cimagf(x[i]); - mse += cabsf(gold - z[i]); - } + for (int i = 0; i < block_size; i++) { + gold = sqrtf(crealf(x[i]) * crealf(x[i]) + cimagf(x[i]) * cimagf(x[i])); + mse += cabsf(gold - z[i]) / block_size; + } - free(x); - free(z);) + free(x); + free(z);) - TEST(srslte_vec_sc_prod_cfc, MALLOC(cf_t, x); MALLOC(cf_t, z); cf_t gold; float h = RANDOM_F(); +TEST(srslte_vec_abs_square_cf, MALLOC(cf_t, x); MALLOC(float, z); float gold; - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } - TEST_CALL(srslte_vec_sc_prod_cfc(x, h, z, block_size)) + TEST_CALL(srslte_vec_abs_square_cf(x, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] * h; - mse += cabsf(gold - z[i]); - } + for (int i = 0; i < block_size; i++) { + gold = crealf(x[i]) * crealf(x[i]) + cimagf(x[i]) * cimagf(x[i]); + mse += cabsf(gold - z[i]); + } - free(x); - free(z);) + free(x); + free(z);) - TEST( - srslte_vec_div_ccc, MALLOC(cf_t, x); MALLOC(cf_t, y); MALLOC(cf_t, z); +TEST(srslte_vec_sc_prod_cfc, MALLOC(cf_t, x); MALLOC(cf_t, z); cf_t gold; float h = RANDOM_F(); - cf_t gold; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_CF(); - y[i] = RANDOM_CF(); - } + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } - TEST_CALL(srslte_vec_div_ccc(x, y, z, block_size)) + TEST_CALL(srslte_vec_sc_prod_cfc(x, h, z, block_size)) for (int i = 0; i < block_size; i++) { - gold = x[i] / y[i]; - mse += cabsf(gold - z[i]) / cabsf(gold); - } mse /= block_size; + gold = x[i] * h; + mse += cabsf(gold - z[i]); + } free(x); - free(y); free(z);) - TEST( - srslte_vec_div_cfc, MALLOC(cf_t, x); MALLOC(float, y); MALLOC(cf_t, z); +TEST( + srslte_vec_div_ccc, MALLOC(cf_t, x); MALLOC(cf_t, y); MALLOC(cf_t, z); - cf_t gold; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_CF(); - y[i] = RANDOM_F() + 0.0001f; - } + cf_t gold; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_CF(); + y[i] = RANDOM_CF(); + } - TEST_CALL(srslte_vec_div_cfc(x, y, z, block_size)) + TEST_CALL(srslte_vec_div_ccc(x, y, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] / y[i]; - mse += cabsf(gold - z[i]) / cabsf(gold); - } mse /= block_size; + for (int i = 0; i < block_size; i++) { + gold = x[i] / y[i]; + mse += cabsf(gold - z[i]) / cabsf(gold); + } mse /= block_size; - free(x); - free(y); - free(z);) + free(x); + free(y); + free(z);) - TEST( - srslte_vec_div_fff, MALLOC(float, x); MALLOC(float, y); MALLOC(float, z); +TEST( + srslte_vec_div_cfc, MALLOC(cf_t, x); MALLOC(float, y); MALLOC(cf_t, z); - cf_t gold; - for (int i = 0; i < block_size; i++) { - x[i] = RANDOM_F(); - y[i] = RANDOM_F() + 0.0001f; - } + cf_t gold; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_CF(); + y[i] = RANDOM_F() + 0.0001f; + } - TEST_CALL(srslte_vec_div_fff(x, y, z, block_size)) + TEST_CALL(srslte_vec_div_cfc(x, y, z, block_size)) - for (int i = 0; i < block_size; i++) { - gold = x[i] / y[i]; - mse += cabsf(gold - z[i]) / cabsf(gold); - } mse /= block_size; + for (int i = 0; i < block_size; i++) { + gold = x[i] / y[i]; + mse += cabsf(gold - z[i]) / cabsf(gold); + } mse /= block_size; - free(x); - free(y); - free(z);) + free(x); + free(y); + free(z);) - TEST( - srslte_vec_max_fi, MALLOC(float, x); +TEST( + srslte_vec_div_fff, MALLOC(float, x); MALLOC(float, y); MALLOC(float, z); - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_F(); } + cf_t gold; + for (int i = 0; i < block_size; i++) { + x[i] = RANDOM_F(); + y[i] = RANDOM_F() + 0.0001f; + } - uint32_t max_index = 0; - TEST_CALL(max_index = srslte_vec_max_fi(x, block_size);) + TEST_CALL(srslte_vec_div_fff(x, y, z, block_size)) - float gold_value = -INFINITY; - uint32_t gold_index = 0; - for (int i = 0; i < block_size; i++) { - if (gold_value < x[i]) { - gold_value = x[i]; - gold_index = i; - } - } mse = (gold_index != max_index) ? 1 : 0; + for (int i = 0; i < block_size; i++) { + gold = x[i] / y[i]; + mse += cabsf(gold - z[i]) / cabsf(gold); + } mse /= block_size; - free(x);) + free(x); + free(y); + free(z);) - TEST( - srslte_vec_max_abs_fi, MALLOC(float, x); +TEST( + srslte_vec_max_fi, MALLOC(float, x); - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_F(); } + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_F(); } - uint32_t max_index = 0; - TEST_CALL(max_index = srslte_vec_max_abs_fi(x, block_size);) + uint32_t max_index = 0; + TEST_CALL(max_index = srslte_vec_max_fi(x, block_size);) - float gold_value = -INFINITY; - uint32_t gold_index = 0; - for (int i = 0; i < block_size; i++) { - if (gold_value < fabsf(x[i])) { - gold_value = fabsf(x[i]); - gold_index = i; - } - } mse = (gold_index != max_index) ? 1 : 0; + float gold_value = -INFINITY; + uint32_t gold_index = 0; + for (int i = 0; i < block_size; i++) { + if (gold_value < x[i]) { + gold_value = x[i]; + gold_index = i; + } + } mse = (gold_index != max_index) ? 1 : 0; - free(x);) + free(x);) - TEST( - srslte_vec_max_abs_ci, MALLOC(cf_t, x); +TEST( + srslte_vec_max_abs_fi, MALLOC(float, x); - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_F(); } - uint32_t max_index = 0; - TEST_CALL(max_index = srslte_vec_max_abs_ci(x, block_size);) + uint32_t max_index = 0; + TEST_CALL(max_index = srslte_vec_max_abs_fi(x, block_size);) - float gold_value = -INFINITY; - uint32_t gold_index = 0; - for (int i = 0; i < block_size; i++) { - cf_t a = x[i]; - float abs2 = __real__ a * __real__ a + __imag__ a * __imag__ a; - if (abs2 > gold_value) { - gold_value = abs2; - gold_index = (uint32_t)i; - } - } mse = (gold_index != max_index) ? 1 : 0; + float gold_value = -INFINITY; + uint32_t gold_index = 0; + for (int i = 0; i < block_size; i++) { + if (gold_value < fabsf(x[i])) { + gold_value = fabsf(x[i]); + gold_index = i; + } + } mse = (gold_index != max_index) ? 1 : 0; - free(x);) + free(x);) - TEST(srslte_vec_apply_cfo, MALLOC(cf_t, x); MALLOC(cf_t, z); +TEST( + srslte_vec_max_abs_ci, MALLOC(cf_t, x); - const float cfo = 0.1f; - cf_t gold; - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } - TEST_CALL(srslte_vec_apply_cfo(x, cfo, z, block_size)) + uint32_t max_index = 0; + TEST_CALL(max_index = srslte_vec_max_abs_ci(x, block_size);) - for (int i = 0; i < block_size; i++) { - gold = x[i] * cexpf(_Complex_I * 2.0f * (float)M_PI * i * cfo); - mse += cabsf(gold - z[i]) / cabsf(gold); - } mse /= block_size; + float gold_value = -INFINITY; + uint32_t gold_index = 0; + for (int i = 0; i < block_size; i++) { + cf_t a = x[i]; + float abs2 = __real__ a * __real__ a + __imag__ a * __imag__ a; + if (abs2 > gold_value) { + gold_value = abs2; + gold_index = (uint32_t)i; + } + } mse = (gold_index != max_index) ? 1 : 0; - free(x); - free(z);) + free(x);) - TEST( - srslte_vec_gen_sine, MALLOC(cf_t, z); +TEST(srslte_vec_apply_cfo, MALLOC(cf_t, x); MALLOC(cf_t, z); - const float freq = 0.1f; + const float cfo = 0.1f; cf_t gold; - cf_t x = RANDOM_CF(); + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } - TEST_CALL(srslte_vec_gen_sine(x, freq, z, block_size)) + TEST_CALL(srslte_vec_apply_cfo(x, cfo, z, block_size)) for (int i = 0; i < block_size; i++) { - gold = x * cexpf(_Complex_I * 2.0f * (float)M_PI * i * freq); + gold = x[i] * cexpf(_Complex_I * 2.0f * (float)M_PI * i * cfo); mse += cabsf(gold - z[i]) / cabsf(gold); } mse /= block_size; + free(x); free(z);) - TEST(srslte_vec_estimate_frequency, MALLOC(cf_t, x); float freq_gold = 0.1f; float freq = 0.1f; +TEST( + srslte_vec_gen_sine, MALLOC(cf_t, z); - for (int i = 0; i < block_size; i++) { x[i] = cexpf(-I * 2.0f * M_PI * (float)i * freq_gold); } + const float freq = 0.1f; + cf_t gold; + cf_t x = RANDOM_CF(); - TEST_CALL(freq = srslte_vec_estimate_frequency(x, block_size);) if (block_size < 6) { mse = 0.0f; } else { - mse = fabsf(freq - freq_gold); - } + TEST_CALL(srslte_vec_gen_sine(x, freq, z, block_size)) - free(x);) + for (int i = 0; i < block_size; i++) { + gold = x * cexpf(_Complex_I * 2.0f * (float)M_PI * i * freq); + mse += cabsf(gold - z[i]) / cabsf(gold); + } mse /= block_size; - TEST(srslte_cfo_correct, srslte_cfo_t srslte_cfo; bzero(&srslte_cfo, sizeof(srslte_cfo)); MALLOC(cf_t, x); - MALLOC(cf_t, z); + free(z);) - const float cfo = 0.1f; - cf_t gold; - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } +TEST(srslte_vec_estimate_frequency, MALLOC(cf_t, x); float freq_gold = 0.1f; float freq = 0.1f; - srslte_cfo_init(&srslte_cfo, block_size); + for (int i = 0; i < block_size; i++) { x[i] = cexpf(-I * 2.0f * M_PI * (float)i * freq_gold); } - TEST_CALL(srslte_cfo_correct(&srslte_cfo, x, z, cfo)) + TEST_CALL(freq = srslte_vec_estimate_frequency(x, block_size);) if (block_size < 6) { mse = 0.0f; } else { + mse = fabsf(freq - freq_gold); + } - for (int i = 0; i < block_size; i++) { - gold = x[i] * cexpf(_Complex_I * 2.0f * (float)M_PI * i * cfo); - mse += cabsf(gold - z[i]) / cabsf(gold); - } mse /= block_size; + free(x);) - free(x); - free(z); - srslte_cfo_free(&srslte_cfo);) +TEST(srslte_cfo_correct, srslte_cfo_t srslte_cfo; bzero(&srslte_cfo, sizeof(srslte_cfo)); MALLOC(cf_t, x); + MALLOC(cf_t, z); - TEST(srslte_cfo_correct_change, srslte_cfo_t srslte_cfo; bzero(&srslte_cfo, sizeof(srslte_cfo)); MALLOC(cf_t, x); - MALLOC(cf_t, z); + const float cfo = 0.1f; + cf_t gold; + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } - float cfo = 0.1f; - cf_t gold; - for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } + srslte_cfo_init(&srslte_cfo, block_size); - srslte_cfo_init(&srslte_cfo, block_size); + TEST_CALL(srslte_cfo_correct(&srslte_cfo, x, z, cfo)) - TEST_CALL(cfo = (i % 2) ? 0.1 : -0.1; srslte_cfo_correct(&srslte_cfo, x, z, cfo)) + for (int i = 0; i < block_size; i++) { + gold = x[i] * cexpf(_Complex_I * 2.0f * (float)M_PI * i * cfo); + mse += cabsf(gold - z[i]) / cabsf(gold); + } mse /= block_size; - for (int i = 0; i < block_size; i++) { - gold = x[i] * cexpf(_Complex_I * 2.0f * (float)M_PI * i * cfo); - mse += cabsf(gold - z[i]) / cabsf(gold); - } mse /= block_size; + free(x); + free(z); + srslte_cfo_free(&srslte_cfo);) - free(x); - free(z); - srslte_cfo_free(&srslte_cfo);) +TEST(srslte_cfo_correct_change, srslte_cfo_t srslte_cfo; bzero(&srslte_cfo, sizeof(srslte_cfo)); MALLOC(cf_t, x); + MALLOC(cf_t, z); - int main(int argc, char** argv) - { - char func_names[MAX_FUNCTIONS][32]; - double timmings[MAX_FUNCTIONS][MAX_BLOCKS]; - uint32_t sizes[32]; - uint32_t size_count = 0; - uint32_t func_count = 0; - bool passed[MAX_FUNCTIONS][MAX_BLOCKS]; - bool all_passed = true; - random_h = srslte_random_init(0x1234); + float cfo = 0.1f; + cf_t gold; + for (int i = 0; i < block_size; i++) { x[i] = RANDOM_CF(); } + + srslte_cfo_init(&srslte_cfo, block_size); + + TEST_CALL(cfo = (i % 2) ? 0.1 : -0.1; srslte_cfo_correct(&srslte_cfo, x, z, cfo)) + + for (int i = 0; i < block_size; i++) { + gold = x[i] * cexpf(_Complex_I * 2.0f * (float)M_PI * i * cfo); + mse += cabsf(gold - z[i]) / cabsf(gold); + } mse /= block_size; - if (argc > 1) { - nof_repetitions = (uint32_t)strtol(argv[1], NULL, 10); - } + free(x); + free(z); + srslte_cfo_free(&srslte_cfo);) + +int main(int argc, char** argv) +{ + char func_names[MAX_FUNCTIONS][32]; + double timmings[MAX_FUNCTIONS][MAX_BLOCKS]; + uint32_t sizes[32]; + uint32_t size_count = 0; + uint32_t func_count = 0; + bool passed[MAX_FUNCTIONS][MAX_BLOCKS]; + bool all_passed = true; + random_h = srslte_random_init(0x1234); + + if (argc > 1) { + nof_repetitions = (uint32_t)strtol(argv[1], NULL, 10); + } - for (uint32_t block_size = 1; block_size <= 1024 * 32; block_size *= 2) { - func_count = 0; + for (uint32_t block_size = 1; block_size <= 1024 * 32; block_size *= 2) { + func_count = 0; - passed[func_count][size_count] = - test_srslte_vec_xor_bbb(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_xor_bbb(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = - test_srslte_vec_acc_ff(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_acc_ff(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = - test_srslte_vec_dot_prod_sss(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_dot_prod_sss(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = - test_srslte_vec_sum_sss(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_sum_sss(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = - test_srslte_vec_sub_sss(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_sub_sss(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = - test_srslte_vec_prod_sss(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_prod_sss(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = - test_srslte_vec_neg_sss(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_neg_sss(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = - test_srslte_vec_acc_cc(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_acc_cc(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = - test_srslte_vec_sum_fff(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_sum_fff(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = - test_srslte_vec_sub_fff(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_sub_fff(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = - test_srslte_vec_dot_prod_ccc(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_dot_prod_ccc(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = - test_srslte_vec_dot_prod_conj_ccc(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_dot_prod_conj_ccc(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = - test_srslte_vec_convert_fi(func_names[func_count], &timmings[func_count][size_count], block_size); - func_count++; + passed[func_count][size_count] = + test_srslte_vec_convert_fi(func_names[func_count], &timmings[func_count][size_count], block_size); + func_count++; - passed[func_count][size_count] = test_srslte_vec_convert_if(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_convert_if(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_prod_fff(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_prod_fff(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_prod_cfc(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_prod_cfc(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_prod_ccc(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_prod_ccc(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_prod_ccc_split(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_prod_ccc_split(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_prod_conj_ccc(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_prod_conj_ccc(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_sc_prod_ccc(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_sc_prod_ccc(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_sc_prod_fff(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_sc_prod_fff(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_abs_cf(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_abs_cf(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_abs_square_cf(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_abs_square_cf(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_sc_prod_cfc(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_sc_prod_cfc(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_div_ccc(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_div_ccc(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_div_cfc(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_div_cfc(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_div_fff(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_div_fff(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_max_fi(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_max_fi(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_max_abs_fi(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_max_abs_fi(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_max_abs_ci(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_max_abs_ci(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_vec_apply_cfo(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_vec_apply_cfo(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; passed[func_count][size_count] = @@ -866,19 +882,21 @@ float squared_error (cf_t a, cf_t b) { test_srslte_vec_estimate_frequency(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_cfo_correct(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_cfo_correct(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; - passed[func_count][size_count] = test_srslte_cfo_correct_change(func_names[func_count], &timmings[func_count][size_count], block_size); + passed[func_count][size_count] = + test_srslte_cfo_correct_change(func_names[func_count], &timmings[func_count][size_count], block_size); func_count++; sizes[size_count] = block_size; size_count++; } - char fname[69]; - FILE *f = NULL; - void * p = popen("(date +%g%m%d && hostname) | tr '\\r\\n' '__'", "r"); + char fname[69]; + FILE* f = NULL; + void* p = popen("(date +%g%m%d && hostname) | tr '\\r\\n' '__'", "r"); if (p) { fgets(fname, 64, p); strncpy(fname + strnlen(fname, 64) - 1, ".tsv", 5); @@ -889,16 +907,18 @@ float squared_error (cf_t a, cf_t b) { pclose(p); } - printf("\n"); printf("%32s |", "Subroutine/MSps"); - if (f) fprintf(f, "Subroutine/MSps Vs Vector size\t"); + if (f) + fprintf(f, "Subroutine/MSps Vs Vector size\t"); for (int i = 0; i < size_count; i++) { printf(" %7d", sizes[i]); - if (f) fprintf(f, "%d\t", sizes[i]); + if (f) + fprintf(f, "%d\t", sizes[i]); } printf(" |\n"); - if (f) fprintf(f, "\n"); + if (f) + fprintf(f, "\n"); for (int j = 0; j < 32; j++) { printf("-"); @@ -911,7 +931,8 @@ float squared_error (cf_t a, cf_t b) { for (int i = 0; i < func_count; i++) { printf("%32s | ", func_names[i]); - if (f) fprintf(f, "%s\t", func_names[i]); + if (f) + fprintf(f, "%s\t", func_names[i]); for (int j = 0; j < size_count; j++) { printf(" %s%7.1f\x1b[0m", @@ -923,11 +944,13 @@ float squared_error (cf_t a, cf_t b) { all_passed &= passed[i][j]; } printf(" |\n"); - if (f) fprintf(f, "\n"); + if (f) + fprintf(f, "\n"); } - if (f) fclose(f); + if (f) + fclose(f); srslte_random_free(random_h); - return (all_passed)?SRSLTE_SUCCESS:SRSLTE_ERROR; + return (all_passed) ? SRSLTE_SUCCESS : SRSLTE_ERROR; } diff --git a/lib/src/phy/utils/vector.c b/lib/src/phy/utils/vector.c index 95b1ad766..b0bb01d4e 100644 --- a/lib/src/phy/utils/vector.c +++ b/lib/src/phy/utils/vector.c @@ -19,8 +19,8 @@ * */ -#include #include +#include #include #include #include @@ -30,93 +30,113 @@ #include "srslte/phy/utils/vector.h" #include "srslte/phy/utils/vector_simd.h" -void srslte_vec_xor_bbb(int8_t *x,int8_t *y,int8_t *z, const uint32_t len) { +void srslte_vec_xor_bbb(int8_t* x, int8_t* y, int8_t* z, const uint32_t len) +{ srslte_vec_xor_bbb_simd(x, y, z, len); } // Used in PRACH detector, AGC and chest_dl for noise averaging -float srslte_vec_acc_ff(const float *x, const uint32_t len) { +float srslte_vec_acc_ff(const float* x, const uint32_t len) +{ return srslte_vec_acc_ff_simd(x, len); } -cf_t srslte_vec_acc_cc(const cf_t *x, const uint32_t len) { +cf_t srslte_vec_acc_cc(const cf_t* x, const uint32_t len) +{ return srslte_vec_acc_cc_simd(x, len); } -void srslte_vec_sub_fff(const float *x, const float *y, float *z, const uint32_t len) { +void srslte_vec_sub_fff(const float* x, const float* y, float* z, const uint32_t len) +{ srslte_vec_sub_fff_simd(x, y, z, len); } -void srslte_vec_sub_sss(const int16_t *x, const int16_t *y, int16_t *z, const uint32_t len) { +void srslte_vec_sub_sss(const int16_t* x, const int16_t* y, int16_t* z, const uint32_t len) +{ srslte_vec_sub_sss_simd(x, y, z, len); } -void srslte_vec_sub_bbb(const int8_t *x, const int8_t *y, int8_t *z, const uint32_t len) { +void srslte_vec_sub_bbb(const int8_t* x, const int8_t* y, int8_t* z, const uint32_t len) +{ srslte_vec_sub_bbb_simd(x, y, z, len); } // Noise estimation in chest_dl, interpolation -void srslte_vec_sub_ccc(const cf_t *x, const cf_t *y, cf_t *z, const uint32_t len) { - return srslte_vec_sub_fff((const float*) x,(const float*) y,(float*) z, 2*len); +void srslte_vec_sub_ccc(const cf_t* x, const cf_t* y, cf_t* z, const uint32_t len) +{ + return srslte_vec_sub_fff((const float*)x, (const float*)y, (float*)z, 2 * len); } // Used in PSS/SSS and sum_ccc -void srslte_vec_sum_fff(const float *x, const float *y, float *z, const uint32_t len) { +void srslte_vec_sum_fff(const float* x, const float* y, float* z, const uint32_t len) +{ srslte_vec_add_fff_simd(x, y, z, len); } -void srslte_vec_sum_sss(const int16_t *x, const int16_t *y, int16_t *z, const uint32_t len) { +void srslte_vec_sum_sss(const int16_t* x, const int16_t* y, int16_t* z, const uint32_t len) +{ srslte_vec_sum_sss_simd(x, y, z, len); } -void srslte_vec_sum_ccc(const cf_t *x, const cf_t *y, cf_t *z, const uint32_t len) { - srslte_vec_sum_fff((float*) x,(float*) y,(float*) z,2*len); +void srslte_vec_sum_ccc(const cf_t* x, const cf_t* y, cf_t* z, const uint32_t len) +{ + srslte_vec_sum_fff((float*)x, (float*)y, (float*)z, 2 * len); } // PSS, PBCH, DEMOD, FFTW, etc. -void srslte_vec_sc_prod_fff(const float *x, const float h, float *z, const uint32_t len) { +void srslte_vec_sc_prod_fff(const float* x, const float h, float* z, const uint32_t len) +{ srslte_vec_sc_prod_fff_simd(x, h, z, len); } -// Used throughout -void srslte_vec_sc_prod_cfc(const cf_t *x, const float h, cf_t *z, const uint32_t len) { - srslte_vec_sc_prod_cfc_simd(x,h,z,len); +// Used throughout +void srslte_vec_sc_prod_cfc(const cf_t* x, const float h, cf_t* z, const uint32_t len) +{ + srslte_vec_sc_prod_cfc_simd(x, h, z, len); } -// Chest UL -void srslte_vec_sc_prod_ccc(const cf_t *x, const cf_t h, cf_t *z, const uint32_t len) { - srslte_vec_sc_prod_ccc_simd(x,h,z,len); +// Chest UL +void srslte_vec_sc_prod_ccc(const cf_t* x, const cf_t h, cf_t* z, const uint32_t len) +{ + srslte_vec_sc_prod_ccc_simd(x, h, z, len); } -// Used in turbo decoder -void srslte_vec_convert_if(const int16_t *x, const float scale, float *z, const uint32_t len) { +// Used in turbo decoder +void srslte_vec_convert_if(const int16_t* x, const float scale, float* z, const uint32_t len) +{ srslte_vec_convert_if_simd(x, z, scale, len); } -void srslte_vec_convert_fi(const float *x, const float scale, int16_t *z, const uint32_t len) { +void srslte_vec_convert_fi(const float* x, const float scale, int16_t* z, const uint32_t len) +{ srslte_vec_convert_fi_simd(x, z, scale, len); } -void srslte_vec_convert_fb(const float *x, const float scale, int8_t *z, const uint32_t len) { +void srslte_vec_convert_fb(const float* x, const float scale, int8_t* z, const uint32_t len) +{ srslte_vec_convert_fb_simd(x, z, scale, len); } -void srslte_vec_lut_sss(const short *x, const unsigned short *lut, short *y, const uint32_t len) { +void srslte_vec_lut_sss(const short* x, const unsigned short* lut, short* y, const uint32_t len) +{ srslte_vec_lut_sss_simd(x, lut, y, len); } -void srslte_vec_lut_bbb(const int8_t *x, const unsigned short *lut, int8_t *y, const uint32_t len) { +void srslte_vec_lut_bbb(const int8_t* x, const unsigned short* lut, int8_t* y, const uint32_t len) +{ srslte_vec_lut_bbb_simd(x, lut, y, len); } -void srslte_vec_lut_sis(const short *x, const unsigned int *lut, short *y, const uint32_t len) { - for (int i=0; i < len; i++) { +void srslte_vec_lut_sis(const short* x, const unsigned int* lut, short* y, const uint32_t len) +{ + for (int i = 0; i < len; i++) { y[lut[i]] = x[i]; } } -void *srslte_vec_malloc(uint32_t size) { - void *ptr; +void* srslte_vec_malloc(uint32_t size) +{ + void* ptr; if (posix_memalign(&ptr, SRSLTE_SIMD_BIT_ALIGN, size)) { return NULL; } else { @@ -134,11 +154,12 @@ float* srslte_vec_f_malloc(uint32_t nsamples) return (float*)srslte_vec_malloc((uint32_t)sizeof(float) * nsamples); } -void *srslte_vec_realloc(void *ptr, uint32_t old_size, uint32_t new_size) { +void* srslte_vec_realloc(void* ptr, uint32_t old_size, uint32_t new_size) +{ #ifndef LV_HAVE_SSE return realloc(ptr, new_size); #else - void *new_ptr; + void* new_ptr; if (posix_memalign(&new_ptr, SRSLTE_SIMD_BIT_ALIGN, new_size)) { return NULL; } else { @@ -149,244 +170,278 @@ void *srslte_vec_realloc(void *ptr, uint32_t old_size, uint32_t new_size) { #endif } - -void srslte_vec_fprint_c(FILE *stream, cf_t *x, const uint32_t len) { +void srslte_vec_fprint_c(FILE* stream, cf_t* x, const uint32_t len) +{ int i; fprintf(stream, "["); - for (i=0;i= max_str_len) { + if ((3 * (len / 8 + ((len % 8) ? 1 : 0))) + 2 >= max_str_len) { ERROR("Buffer too small for printing hex string (max_str_len=%d, payload_len=%d).\n", max_str_len, len); return; } - int n=0; - n+=sprintf(&str[n], "["); - for (i=0;i clip) tmp = clip; - out[i] = (uint16_t) tmp; + out[i] = (uint16_t)tmp; } } -void srslte_vec_quant_fuc(const float *in, uint8_t *out, const float gain, const float offset, const float clip, const uint32_t len) { +void srslte_vec_quant_fuc(const float* in, + uint8_t* out, + const float gain, + const float offset, + const float clip, + const uint32_t len) +{ int i; int tmp; - - for (i=0;i clip) tmp = clip; - out[i] = (uint8_t) tmp; + out[i] = (uint8_t)tmp; } } -void srslte_vec_quant_suc(const int16_t *in, uint8_t *out, const float gain, const int16_t offset, const int16_t clip, const uint32_t len) { - int i; +void srslte_vec_quant_suc(const int16_t* in, + uint8_t* out, + const float gain, + const int16_t offset, + const int16_t clip, + const uint32_t len) +{ + int i; int16_t tmp; - - for (i=0;i clip) tmp = clip; - out[i] = (uint8_t) tmp; + out[i] = (uint8_t)tmp; } } -void srslte_vec_quant_sus(const int16_t *in, uint16_t *out, const float gain, const int16_t offset, const uint32_t len) { - int i; +void srslte_vec_quant_sus(const int16_t* in, uint16_t* out, const float gain, const int16_t offset, const uint32_t len) +{ + int i; int16_t tmp; - - for (i=0;i +#include #include +#include #include #include -#include -#include -#include "srslte/phy/utils/vector_simd.h" #include "srslte/phy/utils/simd.h" +#include "srslte/phy/utils/vector_simd.h" - -void srslte_vec_xor_bbb_simd(const int8_t *x, const int8_t *y, int8_t *z, const int len) { +void srslte_vec_xor_bbb_simd(const int8_t* x, const int8_t* y, int8_t* z, const int len) +{ int i = 0; #if SRSLTE_SIMD_B_SIZE if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(y) && SRSLTE_IS_ALIGNED(z)) { @@ -53,14 +53,15 @@ void srslte_vec_xor_bbb_simd(const int8_t *x, const int8_t *y, int8_t *z, const } } #endif /* SRSLTE_SIMD_B_SIZE */ - - for(; i < len; i++){ + + for (; i < len; i++) { z[i] = x[i] ^ y[i]; } } -int srslte_vec_dot_prod_sss_simd(const int16_t *x, const int16_t *y, const int len) { - int i = 0; +int srslte_vec_dot_prod_sss_simd(const int16_t* x, const int16_t* y, const int len) +{ + int i = 0; int result = 0; #if SRSLTE_SIMD_S_SIZE simd_s_t simd_dotProdVal = srslte_simd_s_zero(); @@ -83,21 +84,22 @@ int srslte_vec_dot_prod_sss_simd(const int16_t *x, const int16_t *y, const int l simd_dotProdVal = srslte_simd_s_add(simd_dotProdVal, z); } } - __attribute__ ((aligned (SRSLTE_SIMD_S_SIZE*2))) short dotProdVector[SRSLTE_SIMD_S_SIZE]; + __attribute__((aligned(SRSLTE_SIMD_S_SIZE * 2))) short dotProdVector[SRSLTE_SIMD_S_SIZE]; srslte_simd_s_store(dotProdVector, simd_dotProdVal); for (int k = 0; k < SRSLTE_SIMD_S_SIZE; k++) { result += dotProdVector[k]; } #endif /* SRSLTE_SIMD_S_SIZE */ - for(; i < len; i++){ + for (; i < len; i++) { result += (x[i] * y[i]); } - return result; + return result; } -void srslte_vec_sum_sss_simd(const int16_t *x, const int16_t *y, int16_t *z, const int len) { +void srslte_vec_sum_sss_simd(const int16_t* x, const int16_t* y, int16_t* z, const int len) +{ int i = 0; #if SRSLTE_SIMD_S_SIZE if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(y) && SRSLTE_IS_ALIGNED(z)) { @@ -121,12 +123,13 @@ void srslte_vec_sum_sss_simd(const int16_t *x, const int16_t *y, int16_t *z, con } #endif /* SRSLTE_SIMD_S_SIZE */ - for(; i < len; i++){ + for (; i < len; i++) { z[i] = x[i] + y[i]; } } -void srslte_vec_sub_sss_simd(const int16_t *x, const int16_t *y, int16_t *z, const int len) { +void srslte_vec_sub_sss_simd(const int16_t* x, const int16_t* y, int16_t* z, const int len) +{ int i = 0; #if SRSLTE_SIMD_S_SIZE if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(y) && SRSLTE_IS_ALIGNED(z)) { @@ -150,12 +153,13 @@ void srslte_vec_sub_sss_simd(const int16_t *x, const int16_t *y, int16_t *z, con } #endif /* SRSLTE_SIMD_S_SIZE */ - for(; i < len; i++){ + for (; i < len; i++) { z[i] = x[i] - y[i]; } } -void srslte_vec_sub_bbb_simd(const int8_t *x, const int8_t *y, int8_t *z, const int len) { +void srslte_vec_sub_bbb_simd(const int8_t* x, const int8_t* y, int8_t* z, const int len) +{ int i = 0; #if SRSLTE_SIMD_B_SIZE if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(y) && SRSLTE_IS_ALIGNED(z)) { @@ -179,12 +183,13 @@ void srslte_vec_sub_bbb_simd(const int8_t *x, const int8_t *y, int8_t *z, const } #endif /* SRSLTE_SIMD_S_SIZE */ - for(; i < len; i++){ + for (; i < len; i++) { z[i] = x[i] - y[i]; } } -void srslte_vec_prod_sss_simd(const int16_t *x, const int16_t *y, int16_t *z, const int len) { +void srslte_vec_prod_sss_simd(const int16_t* x, const int16_t* y, int16_t* z, const int len) +{ int i = 0; #if SRSLTE_SIMD_S_SIZE if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(y) && SRSLTE_IS_ALIGNED(z)) { @@ -208,14 +213,15 @@ void srslte_vec_prod_sss_simd(const int16_t *x, const int16_t *y, int16_t *z, co } #endif /* SRSLTE_SIMD_S_SIZE */ - for(; i < len; i++){ + for (; i < len; i++) { z[i] = x[i] * y[i]; } } -void srslte_vec_neg_sss_simd(const int16_t *x, const int16_t *y, int16_t *z, const int len) { +void srslte_vec_neg_sss_simd(const int16_t* x, const int16_t* y, int16_t* z, const int len) +{ int i = 0; - + #ifndef HAVE_NEON #if SRSLTE_SIMD_S_SIZE if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(y) && SRSLTE_IS_ALIGNED(z)) { @@ -240,14 +246,15 @@ void srslte_vec_neg_sss_simd(const int16_t *x, const int16_t *y, int16_t *z, con #endif /* SRSLTE_SIMD_S_SIZE */ #endif /* NOT HAVE_NEON*/ - for(; i < len; i++){ - z[i] = y[i]<0?-x[i]:x[i]; + for (; i < len; i++) { + z[i] = y[i] < 0 ? -x[i] : x[i]; } } -void srslte_vec_neg_bbb_simd(const int8_t *x, const int8_t *y, int8_t *z, const int len) { +void srslte_vec_neg_bbb_simd(const int8_t* x, const int8_t* y, int8_t* z, const int len) +{ int i = 0; - + #ifndef HAVE_NEON #if SRSLTE_SIMD_B_SIZE if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(y) && SRSLTE_IS_ALIGNED(z)) { @@ -271,8 +278,8 @@ void srslte_vec_neg_bbb_simd(const int8_t *x, const int8_t *y, int8_t *z, const } #endif /* SRSLTE_SIMD_S_SIZE */ #endif /* NOT HAVE_NEON*/ - for(; i < len; i++){ - z[i] = y[i]<0?-x[i]:x[i]; + for (; i < len; i++) { + z[i] = y[i] < 0 ? -x[i] : x[i]; } } @@ -282,13 +289,14 @@ void srslte_vec_neg_bbb_simd(const int8_t *x, const int8_t *y, int8_t *z, const y[l] = (short)x; /* No improvement with AVX */ -void srslte_vec_lut_sss_simd(const short *x, const unsigned short *lut, short *y, const int len) { +void srslte_vec_lut_sss_simd(const short* x, const unsigned short* lut, short* y, const int len) +{ int i = 0; #ifdef LV_HAVE_SSE if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(lut)) { for (; i < len - 7; i += 8) { - __m128i xVal = _mm_load_si128((__m128i *) &x[i]); - __m128i lutVal = _mm_load_si128((__m128i *) &lut[i]); + __m128i xVal = _mm_load_si128((__m128i*)&x[i]); + __m128i lutVal = _mm_load_si128((__m128i*)&lut[i]); int16_t x; uint16_t l; @@ -304,8 +312,8 @@ void srslte_vec_lut_sss_simd(const short *x, const unsigned short *lut, short *y } } else { for (; i < len - 7; i += 8) { - __m128i xVal = _mm_loadu_si128((__m128i *) &x[i]); - __m128i lutVal = _mm_loadu_si128((__m128i *) &lut[i]); + __m128i xVal = _mm_loadu_si128((__m128i*)&x[i]); + __m128i lutVal = _mm_loadu_si128((__m128i*)&lut[i]); int16_t x; uint16_t l; @@ -337,14 +345,15 @@ void srslte_vec_lut_sss_simd(const short *x, const unsigned short *lut, short *y l = (uint16_t)_mm_extract_epi16(lutVal2, j); \ y[l] = (char)x; -void srslte_vec_lut_bbb_simd(const int8_t *x, const unsigned short *lut, int8_t *y, const int len) { +void srslte_vec_lut_bbb_simd(const int8_t* x, const unsigned short* lut, int8_t* y, const int len) +{ int i = 0; #ifdef LV_HAVE_SSE if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(lut)) { for (; i < len - 15; i += 16) { - __m128i xVal = _mm_load_si128((__m128i *) &x[i]); - __m128i lutVal1 = _mm_load_si128((__m128i *) &lut[i]); - __m128i lutVal2 = _mm_load_si128((__m128i *) &lut[i+8]); + __m128i xVal = _mm_load_si128((__m128i*)&x[i]); + __m128i lutVal1 = _mm_load_si128((__m128i*)&lut[i]); + __m128i lutVal2 = _mm_load_si128((__m128i*)&lut[i + 8]); int8_t x; uint16_t l; @@ -369,9 +378,9 @@ void srslte_vec_lut_bbb_simd(const int8_t *x, const unsigned short *lut, int8_t } } else { for (; i < len - 15; i += 16) { - __m128i xVal = _mm_loadu_si128((__m128i *) &x[i]); - __m128i lutVal1 = _mm_loadu_si128((__m128i *) &lut[i]); - __m128i lutVal2 = _mm_loadu_si128((__m128i *) &lut[i+8]); + __m128i xVal = _mm_loadu_si128((__m128i*)&x[i]); + __m128i lutVal1 = _mm_loadu_si128((__m128i*)&lut[i]); + __m128i lutVal2 = _mm_loadu_si128((__m128i*)&lut[i + 8]); int8_t x; uint16_t l; @@ -402,25 +411,26 @@ void srslte_vec_lut_bbb_simd(const int8_t *x, const unsigned short *lut, int8_t } } -void srslte_vec_convert_if_simd(const int16_t *x, float *z, const float scale, const int len) { - int i = 0; +void srslte_vec_convert_if_simd(const int16_t* x, float* z, const float scale, const int len) +{ + int i = 0; const float gain = 1.0f / scale; #ifdef LV_HAVE_SSE __m128 s = _mm_set1_ps(gain); if (SRSLTE_IS_ALIGNED(z)) { for (; i < len - 3; i += 4) { - __m64 *ptr = (__m64 *) &x[i]; - __m128 fl = _mm_cvtpi16_ps(*ptr); - __m128 v = _mm_mul_ps(fl, s); + __m64* ptr = (__m64*)&x[i]; + __m128 fl = _mm_cvtpi16_ps(*ptr); + __m128 v = _mm_mul_ps(fl, s); _mm_store_ps(&z[i], v); } } else { for (; i < len - 3; i += 4) { - __m64 *ptr = (__m64 *) &x[i]; - __m128 fl = _mm_cvtpi16_ps(*ptr); - __m128 v = _mm_mul_ps(fl, s); + __m64* ptr = (__m64*)&x[i]; + __m128 fl = _mm_cvtpi16_ps(*ptr); + __m128 v = _mm_mul_ps(fl, s); _mm_storeu_ps(&z[i], v); } @@ -428,11 +438,12 @@ void srslte_vec_convert_if_simd(const int16_t *x, float *z, const float scale, c #endif /* LV_HAVE_SSE */ for (; i < len; i++) { - z[i] = ((float) x[i]) * gain; + z[i] = ((float)x[i]) * gain; } } -void srslte_vec_convert_fi_simd(const float *x, int16_t *z, const float scale, const int len) { +void srslte_vec_convert_fi_simd(const float* x, int16_t* z, const float scale, const int len) +{ int i = 0; #if SRSLTE_SIMD_F_SIZE && SRSLTE_SIMD_S_SIZE @@ -464,31 +475,33 @@ void srslte_vec_convert_fi_simd(const float *x, int16_t *z, const float scale, c } #endif /* SRSLTE_SIMD_F_SIZE && SRSLTE_SIMD_S_SIZE */ - for(; i < len; i++){ - z[i] = (int16_t) (x[i] * scale); + for (; i < len; i++) { + z[i] = (int16_t)(x[i] * scale); } } -#define SRSLTE_IS_ALIGNED_SSE(PTR) (((size_t)(PTR) & 0x0F) == 0) +#define SRSLTE_IS_ALIGNED_SSE(PTR) (((size_t)(PTR)&0x0F) == 0) -void srslte_vec_convert_fb_simd(const float *x, int8_t *z, const float scale, const int len) { +void srslte_vec_convert_fb_simd(const float* x, int8_t* z, const float scale, const int len) +{ int i = 0; - // Force the use of SSE here instead of AVX since the implementations requires too many permutes across 128-bit boundaries + // Force the use of SSE here instead of AVX since the implementations requires too many permutes across 128-bit + // boundaries #ifdef LV_HAVE_SSE __m128 s = _mm_set1_ps(scale); if (SRSLTE_IS_ALIGNED_SSE(x) && SRSLTE_IS_ALIGNED_SSE(z)) { for (; i < len - 16 + 1; i += 16) { __m128 a = _mm_load_ps(&x[i]); - __m128 b = _mm_load_ps(&x[i + 1*4]); - __m128 c = _mm_load_ps(&x[i + 2*4]); - __m128 d = _mm_load_ps(&x[i + 3*4]); + __m128 b = _mm_load_ps(&x[i + 1 * 4]); + __m128 c = _mm_load_ps(&x[i + 2 * 4]); + __m128 d = _mm_load_ps(&x[i + 3 * 4]); - __m128 sa = _mm_mul_ps(a, s); - __m128 sb = _mm_mul_ps(b, s); - __m128 sc = _mm_mul_ps(c, s); - __m128 sd = _mm_mul_ps(d, s); + __m128 sa = _mm_mul_ps(a, s); + __m128 sb = _mm_mul_ps(b, s); + __m128 sc = _mm_mul_ps(c, s); + __m128 sd = _mm_mul_ps(d, s); __m128i ai = _mm_cvttps_epi32(sa); __m128i bi = _mm_cvttps_epi32(sb); @@ -497,21 +510,21 @@ void srslte_vec_convert_fb_simd(const float *x, int8_t *z, const float scale, co __m128i ab = _mm_packs_epi32(ai, bi); __m128i cd = _mm_packs_epi32(ci, di); - __m128i i8 =_mm_packs_epi16(ab, cd); + __m128i i8 = _mm_packs_epi16(ab, cd); _mm_store_si128((__m128i*)&z[i], i8); } } else { for (; i < len - 16 + 1; i += 16) { __m128 a = _mm_load_ps(&x[i]); - __m128 b = _mm_load_ps(&x[i + 1*4]); - __m128 c = _mm_load_ps(&x[i + 2*4]); - __m128 d = _mm_load_ps(&x[i + 3*4]); + __m128 b = _mm_load_ps(&x[i + 1 * 4]); + __m128 c = _mm_load_ps(&x[i + 2 * 4]); + __m128 d = _mm_load_ps(&x[i + 3 * 4]); - __m128 sa = _mm_mul_ps(a, s); - __m128 sb = _mm_mul_ps(b, s); - __m128 sc = _mm_mul_ps(c, s); - __m128 sd = _mm_mul_ps(d, s); + __m128 sa = _mm_mul_ps(a, s); + __m128 sb = _mm_mul_ps(b, s); + __m128 sc = _mm_mul_ps(c, s); + __m128 sd = _mm_mul_ps(d, s); __m128i ai = _mm_cvttps_epi32(sa); __m128i bi = _mm_cvttps_epi32(sb); @@ -520,7 +533,7 @@ void srslte_vec_convert_fb_simd(const float *x, int8_t *z, const float scale, co __m128i ab = _mm_packs_epi32(ai, bi); __m128i cd = _mm_packs_epi32(ci, di); - __m128i i8 =_mm_packs_epi16(ab, cd); + __m128i i8 = _mm_packs_epi16(ab, cd); _mm_storeu_si128((__m128i*)&z[i], i8); } @@ -531,13 +544,14 @@ void srslte_vec_convert_fb_simd(const float *x, int8_t *z, const float scale, co #pragma message "srslte_vec_convert_fb_simd not implemented in neon" #endif /* HAVE_NEON */ - for(; i < len; i++){ - z[i] = (int8_t) (x[i] * scale); + for (; i < len; i++) { + z[i] = (int8_t)(x[i] * scale); } } -float srslte_vec_acc_ff_simd(const float *x, const int len) { - int i = 0; +float srslte_vec_acc_ff_simd(const float* x, const int len) +{ + int i = 0; float acc_sum = 0.0f; #if SRSLTE_SIMD_F_SIZE @@ -557,22 +571,23 @@ float srslte_vec_acc_ff_simd(const float *x, const int len) { } } - __attribute__((aligned(SRSLTE_SIMD_F_SIZE*4))) float sum[SRSLTE_SIMD_F_SIZE]; + __attribute__((aligned(SRSLTE_SIMD_F_SIZE * 4))) float sum[SRSLTE_SIMD_F_SIZE]; srslte_simd_f_store(sum, simd_sum); for (int k = 0; k < SRSLTE_SIMD_F_SIZE; k++) { acc_sum += sum[k]; } #endif - for (; i max_value) { max_value = values_buffer[k]; - max_index = (uint32_t) indexes_buffer[k]; + max_index = (uint32_t)indexes_buffer[k]; } } #endif /* SRSLTE_SIMD_I_SIZE */ @@ -1333,38 +1372,40 @@ uint32_t srslte_vec_max_fi_simd(const float *x, const int len) { return max_index; } -uint32_t srslte_vec_max_abs_fi_simd(const float *x, const int len) { +uint32_t srslte_vec_max_abs_fi_simd(const float* x, const int len) +{ int i = 0; - float max_value = -INFINITY; + float max_value = -INFINITY; uint32_t max_index = 0; #if SRSLTE_SIMD_I_SIZE - __attribute__ ((aligned (SRSLTE_SIMD_I_SIZE*sizeof(int)))) int indexes_buffer[SRSLTE_SIMD_I_SIZE] = {0}; - __attribute__ ((aligned (SRSLTE_SIMD_I_SIZE*sizeof(float)))) float values_buffer[SRSLTE_SIMD_I_SIZE] = {0}; + __attribute__((aligned(SRSLTE_SIMD_I_SIZE * sizeof(int)))) int indexes_buffer[SRSLTE_SIMD_I_SIZE] = {0}; + __attribute__((aligned(SRSLTE_SIMD_I_SIZE * sizeof(float)))) float values_buffer[SRSLTE_SIMD_I_SIZE] = {0}; - for (int k = 0; k < SRSLTE_SIMD_I_SIZE; k++) indexes_buffer[k] = k; - simd_i_t simd_inc = srslte_simd_i_set1(SRSLTE_SIMD_I_SIZE); - simd_i_t simd_indexes = srslte_simd_i_load(indexes_buffer); + for (int k = 0; k < SRSLTE_SIMD_I_SIZE; k++) + indexes_buffer[k] = k; + simd_i_t simd_inc = srslte_simd_i_set1(SRSLTE_SIMD_I_SIZE); + simd_i_t simd_indexes = srslte_simd_i_load(indexes_buffer); simd_i_t simd_max_indexes = srslte_simd_i_set1(0); simd_f_t simd_max_values = srslte_simd_f_set1(-INFINITY); if (SRSLTE_IS_ALIGNED(x)) { for (; i < len - SRSLTE_SIMD_I_SIZE + 1; i += SRSLTE_SIMD_I_SIZE) { - simd_f_t a = srslte_simd_f_abs(srslte_simd_f_load(&x[i])); - simd_sel_t res = srslte_simd_f_max(a, simd_max_values); + simd_f_t a = srslte_simd_f_abs(srslte_simd_f_load(&x[i])); + simd_sel_t res = srslte_simd_f_max(a, simd_max_values); simd_max_indexes = srslte_simd_i_select(simd_max_indexes, simd_indexes, res); - simd_max_values = (simd_f_t) srslte_simd_i_select((simd_i_t) simd_max_values, (simd_i_t) a, res); - simd_indexes = srslte_simd_i_add(simd_indexes, simd_inc); + simd_max_values = (simd_f_t)srslte_simd_i_select((simd_i_t)simd_max_values, (simd_i_t)a, res); + simd_indexes = srslte_simd_i_add(simd_indexes, simd_inc); } } else { for (; i < len - SRSLTE_SIMD_I_SIZE + 1; i += SRSLTE_SIMD_I_SIZE) { - simd_f_t a = srslte_simd_f_abs(srslte_simd_f_loadu(&x[i])); - simd_sel_t res = srslte_simd_f_max(a, simd_max_values); + simd_f_t a = srslte_simd_f_abs(srslte_simd_f_loadu(&x[i])); + simd_sel_t res = srslte_simd_f_max(a, simd_max_values); simd_max_indexes = srslte_simd_i_select(simd_max_indexes, simd_indexes, res); - simd_max_values = (simd_f_t) srslte_simd_i_select((simd_i_t) simd_max_values, (simd_i_t) a, res); - simd_indexes = srslte_simd_i_add(simd_indexes, simd_inc); + simd_max_values = (simd_f_t)srslte_simd_i_select((simd_i_t)simd_max_values, (simd_i_t)a, res); + simd_indexes = srslte_simd_i_add(simd_indexes, simd_inc); } } @@ -1374,7 +1415,7 @@ uint32_t srslte_vec_max_abs_fi_simd(const float *x, const int len) { for (int k = 0; k < SRSLTE_SIMD_I_SIZE; k++) { if (values_buffer[k] > max_value) { max_value = values_buffer[k]; - max_index = (uint32_t) indexes_buffer[k]; + max_index = (uint32_t)indexes_buffer[k]; } } #endif /* SRSLTE_SIMD_I_SIZE */ @@ -1390,27 +1431,29 @@ uint32_t srslte_vec_max_abs_fi_simd(const float *x, const int len) { return max_index; } -uint32_t srslte_vec_max_ci_simd(const cf_t *x, const int len) { +uint32_t srslte_vec_max_ci_simd(const cf_t* x, const int len) +{ int i = 0; - float max_value = -INFINITY; + float max_value = -INFINITY; uint32_t max_index = 0; #if SRSLTE_SIMD_I_SIZE - __attribute__ ((aligned (SRSLTE_SIMD_I_SIZE*sizeof(int)))) int indexes_buffer[SRSLTE_SIMD_I_SIZE] = {0}; - __attribute__ ((aligned (SRSLTE_SIMD_I_SIZE*sizeof(float)))) float values_buffer[SRSLTE_SIMD_I_SIZE] = {0}; + __attribute__((aligned(SRSLTE_SIMD_I_SIZE * sizeof(int)))) int indexes_buffer[SRSLTE_SIMD_I_SIZE] = {0}; + __attribute__((aligned(SRSLTE_SIMD_I_SIZE * sizeof(float)))) float values_buffer[SRSLTE_SIMD_I_SIZE] = {0}; - for (int k = 0; k < SRSLTE_SIMD_I_SIZE; k++) indexes_buffer[k] = k; - simd_i_t simd_inc = srslte_simd_i_set1(SRSLTE_SIMD_I_SIZE); - simd_i_t simd_indexes = srslte_simd_i_load(indexes_buffer); + for (int k = 0; k < SRSLTE_SIMD_I_SIZE; k++) + indexes_buffer[k] = k; + simd_i_t simd_inc = srslte_simd_i_set1(SRSLTE_SIMD_I_SIZE); + simd_i_t simd_indexes = srslte_simd_i_load(indexes_buffer); simd_i_t simd_max_indexes = srslte_simd_i_set1(0); simd_f_t simd_max_values = srslte_simd_f_set1(-INFINITY); if (SRSLTE_IS_ALIGNED(x)) { for (; i < len - SRSLTE_SIMD_I_SIZE + 1; i += SRSLTE_SIMD_I_SIZE) { - simd_f_t x1 = srslte_simd_f_load((float *) &x[i]); - simd_f_t x2 = srslte_simd_f_load((float *) &x[i + SRSLTE_SIMD_F_SIZE / 2]); + simd_f_t x1 = srslte_simd_f_load((float*)&x[i]); + simd_f_t x2 = srslte_simd_f_load((float*)&x[i + SRSLTE_SIMD_F_SIZE / 2]); simd_f_t mul1 = srslte_simd_f_mul(x1, x1); simd_f_t mul2 = srslte_simd_f_mul(x2, x2); @@ -1420,13 +1463,13 @@ uint32_t srslte_vec_max_ci_simd(const cf_t *x, const int len) { simd_sel_t res = srslte_simd_f_max(z1, simd_max_values); simd_max_indexes = srslte_simd_i_select(simd_max_indexes, simd_indexes, res); - simd_max_values = (simd_f_t) srslte_simd_i_select((simd_i_t) simd_max_values, (simd_i_t) z1, res); - simd_indexes = srslte_simd_i_add(simd_indexes, simd_inc); + simd_max_values = (simd_f_t)srslte_simd_i_select((simd_i_t)simd_max_values, (simd_i_t)z1, res); + simd_indexes = srslte_simd_i_add(simd_indexes, simd_inc); } } else { for (; i < len - SRSLTE_SIMD_I_SIZE + 1; i += SRSLTE_SIMD_I_SIZE) { - simd_f_t x1 = srslte_simd_f_loadu((float *) &x[i]); - simd_f_t x2 = srslte_simd_f_loadu((float *) &x[i + SRSLTE_SIMD_F_SIZE / 2]); + simd_f_t x1 = srslte_simd_f_loadu((float*)&x[i]); + simd_f_t x2 = srslte_simd_f_loadu((float*)&x[i + SRSLTE_SIMD_F_SIZE / 2]); simd_f_t mul1 = srslte_simd_f_mul(x1, x1); simd_f_t mul2 = srslte_simd_f_mul(x2, x2); @@ -1436,8 +1479,8 @@ uint32_t srslte_vec_max_ci_simd(const cf_t *x, const int len) { simd_sel_t res = srslte_simd_f_max(z1, simd_max_values); simd_max_indexes = srslte_simd_i_select(simd_max_indexes, simd_indexes, res); - simd_max_values = (simd_f_t) srslte_simd_i_select((simd_i_t) simd_max_values, (simd_i_t) z1, res); - simd_indexes = srslte_simd_i_add(simd_indexes, simd_inc); + simd_max_values = (simd_f_t)srslte_simd_i_select((simd_i_t)simd_max_values, (simd_i_t)z1, res); + simd_indexes = srslte_simd_i_add(simd_indexes, simd_inc); } } @@ -1447,13 +1490,13 @@ uint32_t srslte_vec_max_ci_simd(const cf_t *x, const int len) { for (int k = 0; k < SRSLTE_SIMD_I_SIZE; k++) { if (values_buffer[k] > max_value) { max_value = values_buffer[k]; - max_index = (uint32_t) indexes_buffer[k]; + max_index = (uint32_t)indexes_buffer[k]; } } #endif /* SRSLTE_SIMD_I_SIZE */ for (; i < len; i++) { - cf_t a = x[i]; + cf_t a = x[i]; float abs2 = __real__ a * __real__ a + __imag__ a * __imag__ a; if (abs2 > max_value) { max_value = abs2; @@ -1464,87 +1507,89 @@ uint32_t srslte_vec_max_ci_simd(const cf_t *x, const int len) { return max_index; } -void srslte_vec_interleave_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len) { +void srslte_vec_interleave_simd(const cf_t* x, const cf_t* y, cf_t* z, const int len) +{ uint32_t i = 0, k = 0; #ifdef LV_HAVE_SSE if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(y) && SRSLTE_IS_ALIGNED(z)) { for (; i < len - 2 + 1; i += 2) { - __m128i a = _mm_load_si128((__m128i *) &x[i]); - __m128i b = _mm_load_si128((__m128i *) &y[i]); + __m128i a = _mm_load_si128((__m128i*)&x[i]); + __m128i b = _mm_load_si128((__m128i*)&y[i]); __m128i r1 = _mm_unpacklo_epi64(a, b); - _mm_store_si128((__m128i *) &z[k], r1); + _mm_store_si128((__m128i*)&z[k], r1); k += 2; __m128i r2 = _mm_unpackhi_epi64(a, b); - _mm_store_si128((__m128i *) &z[k], r2); + _mm_store_si128((__m128i*)&z[k], r2); k += 2; } } else { for (; i < len - 2 + 1; i += 2) { - __m128i a = _mm_loadu_si128((__m128i *) &x[i]); - __m128i b = _mm_loadu_si128((__m128i *) &y[i]); + __m128i a = _mm_loadu_si128((__m128i*)&x[i]); + __m128i b = _mm_loadu_si128((__m128i*)&y[i]); __m128i r1 = _mm_unpacklo_epi64(a, b); - _mm_storeu_si128((__m128i *) &z[k], r1); + _mm_storeu_si128((__m128i*)&z[k], r1); k += 2; __m128i r2 = _mm_unpackhi_epi64(a, b); - _mm_storeu_si128((__m128i *) &z[k], r2); + _mm_storeu_si128((__m128i*)&z[k], r2); k += 2; } } #endif /* LV_HAVE_SSE */ - for (;i < len; i++) { + for (; i < len; i++) { z[k++] = x[i]; z[k++] = y[i]; } } -void srslte_vec_interleave_add_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len) { +void srslte_vec_interleave_add_simd(const cf_t* x, const cf_t* y, cf_t* z, const int len) +{ uint32_t i = 0, k = 0; #ifdef LV_HAVE_SSE if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(y) && SRSLTE_IS_ALIGNED(z)) { for (; i < len - 2 + 1; i += 2) { - __m128i a = _mm_load_si128((__m128i *) &x[i]); - __m128i b = _mm_load_si128((__m128i *) &y[i]); + __m128i a = _mm_load_si128((__m128i*)&x[i]); + __m128i b = _mm_load_si128((__m128i*)&y[i]); - __m128 r1 = (__m128) _mm_unpacklo_epi64(a, b); - __m128 z1 = _mm_load_ps((float *) &z[k]); - r1 = _mm_add_ps((__m128) r1, z1); - _mm_store_ps((float *) &z[k], r1); + __m128 r1 = (__m128)_mm_unpacklo_epi64(a, b); + __m128 z1 = _mm_load_ps((float*)&z[k]); + r1 = _mm_add_ps((__m128)r1, z1); + _mm_store_ps((float*)&z[k], r1); k += 2; - __m128 r2 = (__m128) _mm_unpackhi_epi64(a, b); - __m128 z2 = _mm_load_ps((float *) &z[k]); - r2 = _mm_add_ps((__m128) r2, z2); - _mm_store_ps((float *) &z[k], r2); + __m128 r2 = (__m128)_mm_unpackhi_epi64(a, b); + __m128 z2 = _mm_load_ps((float*)&z[k]); + r2 = _mm_add_ps((__m128)r2, z2); + _mm_store_ps((float*)&z[k], r2); k += 2; } } else { for (; i < len - 2 + 1; i += 2) { - __m128i a = _mm_loadu_si128((__m128i *) &x[i]); - __m128i b = _mm_loadu_si128((__m128i *) &y[i]); + __m128i a = _mm_loadu_si128((__m128i*)&x[i]); + __m128i b = _mm_loadu_si128((__m128i*)&y[i]); - __m128 r1 = (__m128) _mm_unpacklo_epi64(a, b); - __m128 z1 = _mm_loadu_ps((float *) &z[k]); - r1 = _mm_add_ps((__m128) r1, z1); - _mm_storeu_ps((float *) &z[k], r1); + __m128 r1 = (__m128)_mm_unpacklo_epi64(a, b); + __m128 z1 = _mm_loadu_ps((float*)&z[k]); + r1 = _mm_add_ps((__m128)r1, z1); + _mm_storeu_ps((float*)&z[k], r1); k += 2; - __m128 r2 = (__m128) _mm_unpackhi_epi64(a, b); - __m128 z2 = _mm_loadu_ps((float *) &z[k]); - r2 = _mm_add_ps((__m128) r2, z2); - _mm_storeu_ps((float *) &z[k], r2); + __m128 r2 = (__m128)_mm_unpackhi_epi64(a, b); + __m128 z2 = _mm_loadu_ps((float*)&z[k]); + r2 = _mm_add_ps((__m128)r2, z2); + _mm_storeu_ps((float*)&z[k], r2); k += 2; } } #endif /* LV_HAVE_SSE */ - for (;i < len; i++) { + for (; i < len; i++) { z[k++] += x[i]; z[k++] += y[i]; } @@ -1596,21 +1641,22 @@ void srslte_vec_gen_sine_simd(cf_t amplitude, float freq, cf_t* z, int len) } } -void srslte_vec_apply_cfo_simd(const cf_t *x, float cfo, cf_t *z, int len) { - const float TWOPI = 2.0f * (float) M_PI; - int i = 0; +void srslte_vec_apply_cfo_simd(const cf_t* x, float cfo, cf_t* z, int len) +{ + const float TWOPI = 2.0f * (float)M_PI; + int i = 0; #if SRSLTE_SIMD_CF_SIZE - __attribute__ ((aligned (SRSLTE_SIMD_BIT_ALIGN/8))) cf_t _osc[SRSLTE_SIMD_CF_SIZE]; - __attribute__ ((aligned (SRSLTE_SIMD_BIT_ALIGN/8))) cf_t _phase[SRSLTE_SIMD_CF_SIZE]; + __attribute__((aligned(SRSLTE_SIMD_BIT_ALIGN / 8))) cf_t _osc[SRSLTE_SIMD_CF_SIZE]; + __attribute__((aligned(SRSLTE_SIMD_BIT_ALIGN / 8))) cf_t _phase[SRSLTE_SIMD_CF_SIZE]; if (i < len - SRSLTE_SIMD_CF_SIZE + 1) { for (int k = 0; k < SRSLTE_SIMD_CF_SIZE; k++) { - _osc[k] = cexpf(_Complex_I * TWOPI * cfo * SRSLTE_SIMD_CF_SIZE); + _osc[k] = cexpf(_Complex_I * TWOPI * cfo * SRSLTE_SIMD_CF_SIZE); _phase[k] = cexpf(_Complex_I * TWOPI * cfo * k); } } - simd_cf_t _simd_osc = srslte_simd_cfi_load(_osc); + simd_cf_t _simd_osc = srslte_simd_cfi_load(_osc); simd_cf_t _simd_phase = srslte_simd_cfi_load(_phase); if (SRSLTE_IS_ALIGNED(x) && SRSLTE_IS_ALIGNED(z)) { @@ -1622,7 +1668,6 @@ void srslte_vec_apply_cfo_simd(const cf_t *x, float cfo, cf_t *z, int len) { srslte_simd_cfi_store(&z[i], r); _simd_phase = srslte_simd_cf_prod(_simd_phase, _simd_osc); - } } else { for (; i < len - SRSLTE_SIMD_F_SIZE + 1; i += SRSLTE_SIMD_F_SIZE) { @@ -1637,7 +1682,7 @@ void srslte_vec_apply_cfo_simd(const cf_t *x, float cfo, cf_t *z, int len) { } } #endif - cf_t osc = cexpf(_Complex_I * TWOPI * cfo); + cf_t osc = cexpf(_Complex_I * TWOPI * cfo); cf_t phase = cexpf(_Complex_I * TWOPI * cfo * i); for (; i < len; i++) { z[i] = x[i] * phase; diff --git a/lib/src/radio/radio.cc b/lib/src/radio/radio.cc index d26b79a78..1fdc9f1b7 100644 --- a/lib/src/radio/radio.cc +++ b/lib/src/radio/radio.cc @@ -38,18 +38,18 @@ bool radio::init(log_filter* _log_h, char* args, char* devname, uint32_t nof_cha } log_h = _log_h; - tx_adv_negative = false; - agc_enabled = false; - burst_preamble_samples = 0; - burst_preamble_time_rounded = 0; - cur_tx_srate = 0; - is_start_of_burst = true; - + tx_adv_negative = false; + agc_enabled = false; + burst_preamble_samples = 0; + burst_preamble_time_rounded = 0; + cur_tx_srate = 0; + is_start_of_burst = true; + // Suppress radio stdout srslte_rf_suppress_stdout(&rf_device); continuous_tx = true; - tx_adv_auto = true; + tx_adv_auto = true; // Set default preamble length each known device // We distinguish by device family, maybe we should calibrate per device if (strstr(srslte_rf_name(&rf_device), "uhd")) { @@ -73,11 +73,12 @@ bool radio::init(log_filter* _log_h, char* args, char* devname, uint32_t nof_cha return true; } -bool radio::is_init() { +bool radio::is_init() +{ return is_initialized; } -void radio::stop() +void radio::stop() { if (zeros) { free(zeros); @@ -95,35 +96,38 @@ void radio::reset() usleep(100000); } -void radio::set_tx_rx_gain_offset(float offset) { - srslte_rf_set_tx_rx_gain_offset(&rf_device, offset); +void radio::set_tx_rx_gain_offset(float offset) +{ + srslte_rf_set_tx_rx_gain_offset(&rf_device, offset); } void radio::set_burst_preamble(double preamble_us) { - burst_preamble_sec = (double) preamble_us/1e6; + burst_preamble_sec = (double)preamble_us / 1e6; } -void radio::set_continuous_tx(bool enable) { +void radio::set_continuous_tx(bool enable) +{ continuous_tx = enable; } -bool radio::is_continuous_tx() { +bool radio::is_continuous_tx() +{ return continuous_tx; } void radio::set_tx_adv(int nsamples) { - tx_adv_auto = false; + tx_adv_auto = false; tx_adv_nsamples = nsamples; if (!nsamples) { - tx_adv_sec = 0; + tx_adv_sec = 0; } - } -void radio::set_tx_adv_neg(bool tx_adv_is_neg) { - tx_adv_negative = tx_adv_is_neg; +void radio::set_tx_adv_neg(bool tx_adv_is_neg) +{ + tx_adv_negative = tx_adv_is_neg; } bool radio::start_agc(bool tx_gain_same_rx) @@ -133,14 +137,14 @@ bool radio::start_agc(bool tx_gain_same_rx) return false; } - agc_enabled = true; - - return true; + agc_enabled = true; + + return true; } bool radio::rx_at(cf_t* buffer, uint32_t nof_samples, srslte_timestamp_t rx_time) { ERROR("Not implemented\n"); - return false; + return false; } bool radio::rx_now(cf_t* buffer[SRSLTE_MAX_PORTS], uint32_t nof_samples, srslte_timestamp_t* rxd_time) @@ -176,7 +180,7 @@ float radio::get_max_tx_power() float radio::get_rssi() { - return srslte_rf_get_rssi(&rf_device); + return srslte_rf_get_rssi(&rf_device); } bool radio::has_rssi() @@ -184,7 +188,8 @@ bool radio::has_rssi() return srslte_rf_has_rssi(&rf_device); } -bool radio::is_first_of_burst() { +bool radio::is_first_of_burst() +{ return is_start_of_burst; } @@ -209,7 +214,7 @@ bool radio::tx(cf_t* buffer[SRSLTE_MAX_PORTS], uint32_t nof_samples, srslte_time } else { srslte_timestamp_add(&tx_time, 0, tx_adv_sec); } - + if (is_start_of_burst) { if (burst_preamble_samples != 0) { srslte_timestamp_t tx_time_pad; @@ -226,8 +231,8 @@ bool radio::tx(cf_t* buffer[SRSLTE_MAX_PORTS], uint32_t nof_samples, srslte_time is_start_of_burst = false; } } - - // Save possible end of burst time + + // Save possible end of burst time srslte_timestamp_copy(&end_of_burst_time, &tx_time); srslte_timestamp_add(&end_of_burst_time, 0, (double)nof_samples / cur_tx_srate); @@ -241,9 +246,9 @@ bool radio::tx(cf_t* buffer[SRSLTE_MAX_PORTS], uint32_t nof_samples, srslte_time false); is_start_of_burst = false; if (ret > 0) { - return true; + return true; } else { - return false; + return false; } } @@ -260,7 +265,8 @@ bool radio::get_is_start_of_burst() return is_start_of_burst; } -void radio::set_freq_offset(double freq) { +void radio::set_freq_offset(double freq) +{ freq_offset = freq; } @@ -306,7 +312,7 @@ double radio::get_freq_offset() double radio::get_tx_freq() { - return tx_freq; + return tx_freq; } float radio::get_tx_gain() @@ -321,22 +327,26 @@ float radio::get_rx_gain() void radio::set_tx_srate(double srate) { - cur_tx_srate = srslte_rf_set_tx_srate(&rf_device, srate); - burst_preamble_samples = (uint32_t) (cur_tx_srate * burst_preamble_sec); + cur_tx_srate = srslte_rf_set_tx_srate(&rf_device, srate); + burst_preamble_samples = (uint32_t)(cur_tx_srate * burst_preamble_sec); if (burst_preamble_samples > burst_preamble_max_samples) { - fprintf(stderr, "Error setting TX srate %.1f MHz. Maximum burst preamble samples: %d, requested: %d\n", srate*1e-6, burst_preamble_max_samples, burst_preamble_samples ); + fprintf(stderr, + "Error setting TX srate %.1f MHz. Maximum burst preamble samples: %d, requested: %d\n", + srate * 1e-6, + burst_preamble_max_samples, + burst_preamble_samples); } - burst_preamble_time_rounded = (double) burst_preamble_samples/cur_tx_srate; - - int nsamples=0; + burst_preamble_time_rounded = (double)burst_preamble_samples / cur_tx_srate; + + int nsamples = 0; /* Set time advance for each known device if in auto mode */ if (tx_adv_auto) { - + /* This values have been calibrated using the prach_test_usrp tool in srsLTE */ if (!strcmp(srslte_rf_name(&rf_device), "uhd_b200")) { - double srate_khz = round(cur_tx_srate/1e3); + double srate_khz = round(cur_tx_srate / 1e3); if (srate_khz == 1.92e3) { // 6 PRB nsamples = 57; @@ -360,21 +370,21 @@ void radio::set_tx_srate(double srate) log_h->console( "\nWarning TX/RX time offset for sampling rate %.0f KHz not calibrated. Using interpolated value\n\n", cur_tx_srate); - nsamples = cur_tx_srate*(uhd_default_tx_adv_samples * (1/cur_tx_srate) + uhd_default_tx_adv_offset_sec); + nsamples = cur_tx_srate * (uhd_default_tx_adv_samples * (1 / cur_tx_srate) + uhd_default_tx_adv_offset_sec); } - - }else if(!strcmp(srslte_rf_name(&rf_device), "uhd_usrp2")) { - double srate_khz = round(cur_tx_srate/1e3); - if (srate_khz == 1.92e3) { - nsamples = 14; // estimated - } else if (srate_khz == 3.84e3) { - nsamples = 32; + + } else if (!strcmp(srslte_rf_name(&rf_device), "uhd_usrp2")) { + double srate_khz = round(cur_tx_srate / 1e3); + if (srate_khz == 1.92e3) { + nsamples = 14; // estimated + } else if (srate_khz == 3.84e3) { + nsamples = 32; } else if (srate_khz == 5.76e3) { nsamples = 43; } else if (srate_khz == 11.52e3) { nsamples = 54; } else if (srate_khz == 15.36e3) { - nsamples = 65;// to calc + nsamples = 65; // to calc } else if (srate_khz == 23.04e3) { nsamples = 80; // to calc } else { @@ -382,11 +392,11 @@ void radio::set_tx_srate(double srate) log_h->console( "\nWarning TX/RX time offset for sampling rate %.0f KHz not calibrated. Using interpolated value\n\n", cur_tx_srate); - nsamples = cur_tx_srate*(uhd_default_tx_adv_samples * (1/cur_tx_srate) + uhd_default_tx_adv_offset_sec); + nsamples = cur_tx_srate * (uhd_default_tx_adv_samples * (1 / cur_tx_srate) + uhd_default_tx_adv_offset_sec); } - - } else if(!strcmp(srslte_rf_name(&rf_device), "lime")) { - double srate_khz = round(cur_tx_srate/1e3); + + } else if (!strcmp(srslte_rf_name(&rf_device), "lime")) { + double srate_khz = round(cur_tx_srate / 1e3); if (srate_khz == 1.92e3) { nsamples = 28; } else if (srate_khz == 3.84e3) { @@ -404,20 +414,20 @@ void radio::set_tx_srate(double srate) log_h->console( "\nWarning TX/RX time offset for sampling rate %.0f KHz not calibrated. Using interpolated value\n\n", cur_tx_srate); - nsamples = cur_tx_srate*(uhd_default_tx_adv_samples * (1/cur_tx_srate) + uhd_default_tx_adv_offset_sec); + nsamples = cur_tx_srate * (uhd_default_tx_adv_samples * (1 / cur_tx_srate) + uhd_default_tx_adv_offset_sec); } - + } else if (!strcmp(srslte_rf_name(&rf_device), "uhd_x300")) { // In X300 TX/RX offset is independent of sampling rate nsamples = 45; } else if (!strcmp(srslte_rf_name(&rf_device), "bladerf")) { - - double srate_khz = round(cur_tx_srate/1e3); + + double srate_khz = round(cur_tx_srate / 1e3); if (srate_khz == 1.92e3) { nsamples = 16; } else if (srate_khz == 3.84e3) { - nsamples = 18; + nsamples = 18; } else if (srate_khz == 5.76e3) { nsamples = 16; } else if (srate_khz == 11.52e3) { @@ -431,7 +441,7 @@ void radio::set_tx_srate(double srate) log_h->console( "\nWarning TX/RX time offset for sampling rate %.0f KHz not calibrated. Using interpolated value\n\n", cur_tx_srate); - tx_adv_sec = blade_default_tx_adv_samples * (1/cur_tx_srate) + blade_default_tx_adv_offset_sec; + tx_adv_sec = blade_default_tx_adv_samples * (1 / cur_tx_srate) + blade_default_tx_adv_offset_sec; } } else { log_h->console("\nWarning TX/RX time offset has not been calibrated for device %s. Set a value manually\n\n", @@ -441,12 +451,12 @@ void radio::set_tx_srate(double srate) nsamples = tx_adv_nsamples; log_h->console("Setting manual TX/RX offset to %d samples\n", nsamples); } - - // Calculate TX advance in seconds from samples and sampling rate - tx_adv_sec = nsamples/cur_tx_srate; - if (tx_adv_sec<0) { + + // Calculate TX advance in seconds from samples and sampling rate + tx_adv_sec = nsamples / cur_tx_srate; + if (tx_adv_sec < 0) { tx_adv_sec *= -1; - tx_adv_negative = true; + tx_adv_negative = true; } } @@ -459,6 +469,5 @@ srslte_rf_info_t* radio::get_info() { return srslte_rf_get_info(&rf_device); } - -} +} // namespace srslte diff --git a/lib/src/radio/radio_multi.cc b/lib/src/radio/radio_multi.cc index 5b39d7f36..1af4dee02 100644 --- a/lib/src/radio/radio_multi.cc +++ b/lib/src/radio/radio_multi.cc @@ -45,8 +45,8 @@ std::string radio_multi::get_type() int radio_multi::init(const rf_args_t& args_, phy_interface_radio* phy_) { - args = args_; - phy = phy_; + args = args_; + phy = phy_; // Init log log.init("RF ", logger); @@ -133,7 +133,7 @@ void radio_multi::stop() bool radio_multi::get_metrics(rf_metrics_t* metrics) { - *metrics = rf_metrics; + *metrics = rf_metrics; rf_metrics = {}; return true; } diff --git a/lib/src/radio/test/benchmark_radio.cc b/lib/src/radio/test/benchmark_radio.cc index a6b60450e..273c3ba7a 100644 --- a/lib/src/radio/test/benchmark_radio.cc +++ b/lib/src/radio/test/benchmark_radio.cc @@ -41,17 +41,17 @@ static char radios_args[SRSLTE_MAX_RADIOS][64] = {"auto", "auto", "auto"}; log_filter log_h; std::string file_pattern = "radio%d.dat"; -double freq = 2630e6; +double freq = 2630e6; uint32_t nof_radios = 1; uint32_t nof_ports = 1; -double srate = 1.92e6; /* Hz */ +double srate = 1.92e6; /* Hz */ double duration = 0.01; /* in seconds, 10 ms by default */ cf_t* buffers[SRSLTE_MAX_RADIOS][SRSLTE_MAX_PORTS]; -bool tx_enable = false; -bool measure_delay = false; -bool capture = false; -bool agc_enable = true; -float rf_gain = -1.0; +bool tx_enable = false; +bool measure_delay = false; +bool capture = false; +bool agc_enable = true; +float rf_gain = -1.0; #ifdef ENABLE_GUI #include "srsgui/srsgui.h" @@ -89,7 +89,8 @@ void usage(char* prog) printf("\t-h show this message\n"); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "foabcderpsStvhmFxwg")) != -1) { switch (opt) { @@ -259,7 +260,7 @@ int main(int argc, char** argv) /* Parse args */ parse_args(argc, argv); - uint32_t nof_samples = (uint32_t) (duration * srate); + uint32_t nof_samples = (uint32_t)(duration * srate); uint32_t frame_size = (uint32_t)(srate / 1000.0); /* 1 ms at srate */ uint32_t nof_frames = (uint32_t)ceil(nof_samples / frame_size); diff --git a/lib/src/upper/gtpu.cc b/lib/src/upper/gtpu.cc index 85519f02c..77030ed1d 100644 --- a/lib/src/upper/gtpu.cc +++ b/lib/src/upper/gtpu.cc @@ -28,64 +28,64 @@ namespace srslte { * Header pack/unpack helper functions * Ref: 3GPP TS 29.281 v10.1.0 Section 5 ***************************************************************************/ -bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte::log *gtpu_log) +bool gtpu_write_header(gtpu_header_t* header, srslte::byte_buffer_t* pdu, srslte::log* gtpu_log) { - //flags - if(!gtpu_supported_flags_check(header,gtpu_log)){ + // flags + if (!gtpu_supported_flags_check(header, gtpu_log)) { gtpu_log->error("gtpu_write_header - Unhandled GTP-U Flags. Flags: 0x%x\n", header->flags); return false; } - //msg type - if(!gtpu_supported_msg_type_check(header,gtpu_log)){ + // msg type + if (!gtpu_supported_msg_type_check(header, gtpu_log)) { gtpu_log->error("gtpu_write_header - Unhandled GTP-U Message Type. Message Type: 0x%x\n", header->message_type); return false; } - //If E, S or PN are set, the header is longer + // If E, S or PN are set, the header is longer if (header->flags & (GTPU_FLAGS_EXTENDED_HDR | GTPU_FLAGS_SEQUENCE | GTPU_FLAGS_PACKET_NUM)) { - if(pdu->get_headroom() < GTPU_EXTENDED_HEADER_LEN) { + if (pdu->get_headroom() < GTPU_EXTENDED_HEADER_LEN) { gtpu_log->error("gtpu_write_header - No room in PDU for header\n"); return false; } - pdu->msg -= GTPU_EXTENDED_HEADER_LEN; - pdu->N_bytes += GTPU_EXTENDED_HEADER_LEN; + pdu->msg -= GTPU_EXTENDED_HEADER_LEN; + pdu->N_bytes += GTPU_EXTENDED_HEADER_LEN; } else { - if(pdu->get_headroom() < GTPU_BASE_HEADER_LEN) { + if (pdu->get_headroom() < GTPU_BASE_HEADER_LEN) { gtpu_log->error("gtpu_write_header - No room in PDU for header\n"); return false; } - pdu->msg -= GTPU_BASE_HEADER_LEN; - pdu->N_bytes += GTPU_BASE_HEADER_LEN; + pdu->msg -= GTPU_BASE_HEADER_LEN; + pdu->N_bytes += GTPU_BASE_HEADER_LEN; } - //write mandatory fields - uint8_t *ptr = pdu->msg; - *ptr = header->flags; + // write mandatory fields + uint8_t* ptr = pdu->msg; + *ptr = header->flags; ptr++; *ptr = header->message_type; ptr++; uint16_to_uint8(header->length, ptr); ptr += 2; uint32_to_uint8(header->teid, ptr); - //write optional fields, if E, S or PN are set. + // write optional fields, if E, S or PN are set. if (header->flags & (GTPU_FLAGS_EXTENDED_HDR | GTPU_FLAGS_SEQUENCE | GTPU_FLAGS_PACKET_NUM)) { - //S - if (header->flags & GTPU_FLAGS_SEQUENCE ) { + // S + if (header->flags & GTPU_FLAGS_SEQUENCE) { uint16_to_uint8(header->seq_number, ptr); } else { uint16_to_uint8(0, ptr); } - ptr+=2; - //PN - if (header->flags & GTPU_FLAGS_PACKET_NUM ) { + ptr += 2; + // PN + if (header->flags & GTPU_FLAGS_PACKET_NUM) { *ptr = header->n_pdu; } else { header->n_pdu = 0; } ptr++; - //E - if (header->flags & GTPU_FLAGS_EXTENDED_HDR ) { + // E + if (header->flags & GTPU_FLAGS_EXTENDED_HDR) { *ptr = header->next_ext_hdr_type; } else { *ptr = 0; @@ -95,37 +95,37 @@ bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte return true; } -bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte::log *gtpu_log) +bool gtpu_read_header(srslte::byte_buffer_t* pdu, gtpu_header_t* header, srslte::log* gtpu_log) { - uint8_t *ptr = pdu->msg; + uint8_t* ptr = pdu->msg; - header->flags = *ptr; + header->flags = *ptr; ptr++; - header->message_type = *ptr; + header->message_type = *ptr; ptr++; uint8_to_uint16(ptr, &header->length); ptr += 2; uint8_to_uint32(ptr, &header->teid); - //flags - if(!gtpu_supported_flags_check(header,gtpu_log)){ + // flags + if (!gtpu_supported_flags_check(header, gtpu_log)) { gtpu_log->error("gtpu_read_header - Unhandled GTP-U Flags. Flags: 0x%x\n", header->flags); return false; } - //message_type - if(!gtpu_supported_msg_type_check(header,gtpu_log)){ + // message_type + if (!gtpu_supported_msg_type_check(header, gtpu_log)) { gtpu_log->error("gtpu_read_header - Unhandled GTP-U Message Type. Flags: 0x%x\n", header->message_type); return false; } - //If E, S or PN are set, header is longer + // If E, S or PN are set, header is longer if (header->flags & (GTPU_FLAGS_EXTENDED_HDR | GTPU_FLAGS_SEQUENCE | GTPU_FLAGS_PACKET_NUM)) { - pdu->msg += GTPU_EXTENDED_HEADER_LEN; - pdu->N_bytes -= GTPU_EXTENDED_HEADER_LEN; + pdu->msg += GTPU_EXTENDED_HEADER_LEN; + pdu->N_bytes -= GTPU_EXTENDED_HEADER_LEN; uint8_to_uint16(ptr, &header->seq_number); - ptr+=2; + ptr += 2; header->n_pdu = *ptr; ptr++; @@ -133,8 +133,8 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte: header->next_ext_hdr_type = *ptr; ptr++; } else { - pdu->msg += GTPU_BASE_HEADER_LEN; - pdu->N_bytes -= GTPU_BASE_HEADER_LEN; + pdu->msg += GTPU_BASE_HEADER_LEN; + pdu->N_bytes -= GTPU_BASE_HEADER_LEN; } return true; diff --git a/lib/src/upper/pdcp_entity_nr.cc b/lib/src/upper/pdcp_entity_nr.cc index 3c47508b8..6cef1c425 100644 --- a/lib/src/upper/pdcp_entity_nr.cc +++ b/lib/src/upper/pdcp_entity_nr.cc @@ -110,9 +110,7 @@ void pdcp_entity_nr::write_sdu(unique_byte_buffer_t sdu, bool blocking) discard_timer.set(static_cast(cfg.discard_timer), discard_fnc); discard_timer.run(); discard_timers_map.insert(std::make_pair(tx_next, std::move(discard_timer))); - log->debug("Discard Timer set for SN %u. Timeout: %ums\n", - tx_next, - static_cast(cfg.discard_timer)); + log->debug("Discard Timer set for SN %u. Timeout: %ums\n", tx_next, static_cast(cfg.discard_timer)); } // Perform header compression TODO diff --git a/lib/src/upper/rlc.cc b/lib/src/upper/rlc.cc index 7c02247e4..423bd6ff5 100644 --- a/lib/src/upper/rlc.cc +++ b/lib/src/upper/rlc.cc @@ -39,12 +39,12 @@ rlc::~rlc() // destroy all remaining entities pthread_rwlock_wrlock(&rwlock); for (rlc_map_t::iterator it = rlc_array.begin(); it != rlc_array.end(); ++it) { - delete(it->second); + delete (it->second); } rlc_array.clear(); for (rlc_map_t::iterator it = rlc_array_mrb.begin(); it != rlc_array_mrb.end(); ++it) { - delete(it->second); + delete (it->second); } rlc_array_mrb.clear(); @@ -69,7 +69,7 @@ void rlc::init(srsue::pdcp_interface_rlc* pdcp_, add_bearer(default_lcid, rlc_config_t()); } -void rlc::reset_metrics() +void rlc::reset_metrics() { for (rlc_map_t::iterator it = rlc_array.begin(); it != rlc_array.end(); ++it) { it->second->reset_metrics(); @@ -92,13 +92,13 @@ void rlc::stop() pthread_rwlock_unlock(&rwlock); } -void rlc::get_metrics(rlc_metrics_t &m) +void rlc::get_metrics(rlc_metrics_t& m) { pthread_rwlock_rdlock(&rwlock); gettimeofday(&metrics_time[2], NULL); get_time_interval(metrics_time); - double secs = (double)metrics_time[0].tv_sec + metrics_time[0].tv_usec*1e-6; + double secs = (double)metrics_time[0].tv_sec + metrics_time[0].tv_usec * 1e-6; for (rlc_map_t::iterator it = rlc_array.begin(); it != rlc_array.end(); ++it) { rlc_bearer_metrics_t metrics = it->second->get_metrics(); @@ -161,13 +161,13 @@ void rlc::reset() for (rlc_map_t::iterator it = rlc_array.begin(); it != rlc_array.end(); ++it) { it->second->stop(); - delete(it->second); + delete (it->second); } rlc_array.clear(); for (rlc_map_t::iterator it = rlc_array_mrb.begin(); it != rlc_array_mrb.end(); ++it) { it->second->stop(); - delete(it->second); + delete (it->second); } rlc_array_mrb.clear(); @@ -219,7 +219,6 @@ void rlc::write_sdu_mch(uint32_t lcid, unique_byte_buffer_t sdu) pthread_rwlock_unlock(&rwlock); } - bool rlc::rb_is_um(uint32_t lcid) { bool ret = false; @@ -289,7 +288,7 @@ uint32_t rlc::get_total_mch_buffer_state(uint32_t lcid) return ret; } -int rlc::read_pdu(uint32_t lcid, uint8_t *payload, uint32_t nof_bytes) +int rlc::read_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) { uint32_t ret = 0; @@ -304,7 +303,7 @@ int rlc::read_pdu(uint32_t lcid, uint8_t *payload, uint32_t nof_bytes) return ret; } -int rlc::read_pdu_mch(uint32_t lcid, uint8_t *payload, uint32_t nof_bytes) +int rlc::read_pdu_mch(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) { uint32_t ret = 0; @@ -319,7 +318,7 @@ int rlc::read_pdu_mch(uint32_t lcid, uint8_t *payload, uint32_t nof_bytes) return ret; } -void rlc::write_pdu(uint32_t lcid, uint8_t *payload, uint32_t nof_bytes) +void rlc::write_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) { pthread_rwlock_rdlock(&rwlock); if (valid_lcid(lcid)) { @@ -331,7 +330,7 @@ void rlc::write_pdu(uint32_t lcid, uint8_t *payload, uint32_t nof_bytes) } // Pass directly to PDCP, no DL througput counting done -void rlc::write_pdu_bcch_bch(uint8_t *payload, uint32_t nof_bytes) +void rlc::write_pdu_bcch_bch(uint8_t* payload, uint32_t nof_bytes) { rlc_log->info_hex(payload, nof_bytes, "BCCH BCH message received."); unique_byte_buffer_t buf = allocate_unique_buffer(*pool); @@ -346,7 +345,7 @@ void rlc::write_pdu_bcch_bch(uint8_t *payload, uint32_t nof_bytes) } // Pass directly to PDCP, no DL througput counting done -void rlc::write_pdu_bcch_dlsch(uint8_t *payload, uint32_t nof_bytes) +void rlc::write_pdu_bcch_dlsch(uint8_t* payload, uint32_t nof_bytes) { rlc_log->info_hex(payload, nof_bytes, "BCCH TXSCH message received."); unique_byte_buffer_t buf = allocate_unique_buffer(*pool); @@ -361,7 +360,7 @@ void rlc::write_pdu_bcch_dlsch(uint8_t *payload, uint32_t nof_bytes) } // Pass directly to PDCP, no DL througput counting done -void rlc::write_pdu_pcch(uint8_t *payload, uint32_t nof_bytes) +void rlc::write_pdu_pcch(uint8_t* payload, uint32_t nof_bytes) { rlc_log->info_hex(payload, nof_bytes, "PCCH message received."); unique_byte_buffer_t buf = allocate_unique_buffer(*pool); @@ -375,7 +374,7 @@ void rlc::write_pdu_pcch(uint8_t *payload, uint32_t nof_bytes) } } -void rlc::write_pdu_mch(uint32_t lcid, uint8_t *payload, uint32_t nof_bytes) +void rlc::write_pdu_mch(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) { pthread_rwlock_rdlock(&rwlock); if (valid_lcid_mrb(lcid)) { @@ -392,7 +391,7 @@ void rlc::add_bearer(uint32_t lcid, rlc_config_t cnfg) { pthread_rwlock_wrlock(&rwlock); - rlc_common *rlc_entity = NULL; + rlc_common* rlc_entity = NULL; if (not valid_lcid(lcid)) { if (cnfg.rat == srslte_rat_t::lte) { @@ -449,14 +448,13 @@ void rlc::add_bearer(uint32_t lcid, rlc_config_t cnfg) delete_and_exit: if (rlc_entity) { - delete(rlc_entity); + delete (rlc_entity); } unlock_and_exit: pthread_rwlock_unlock(&rwlock); } - void rlc::add_bearer_mrb(uint32_t lcid) { pthread_rwlock_wrlock(&rwlock); @@ -481,14 +479,13 @@ void rlc::add_bearer_mrb(uint32_t lcid) delete_and_exit: if (rlc_entity != NULL) { - delete(rlc_entity); + delete (rlc_entity); } unlock_and_exit: pthread_rwlock_unlock(&rwlock); } - void rlc::del_bearer(uint32_t lcid) { pthread_rwlock_wrlock(&rwlock); @@ -496,7 +493,7 @@ void rlc::del_bearer(uint32_t lcid) if (valid_lcid(lcid)) { rlc_map_t::iterator it = rlc_array.find(lcid); it->second->stop(); - delete(it->second); + delete (it->second); rlc_array.erase(it); rlc_log->warning("Deleted RLC bearer %s\n", rrc->get_rb_name(lcid).c_str()); } else { @@ -506,7 +503,6 @@ void rlc::del_bearer(uint32_t lcid) pthread_rwlock_unlock(&rwlock); } - void rlc::del_bearer_mrb(uint32_t lcid) { pthread_rwlock_wrlock(&rwlock); @@ -514,7 +510,7 @@ void rlc::del_bearer_mrb(uint32_t lcid) if (valid_lcid_mrb(lcid)) { rlc_map_t::iterator it = rlc_array_mrb.find(lcid); it->second->stop(); - delete(it->second); + delete (it->second); rlc_array_mrb.erase(it); rlc_log->warning("Deleted RLC MRB bearer %s\n", rrc->get_rb_name(lcid).c_str()); } else { @@ -524,7 +520,6 @@ void rlc::del_bearer_mrb(uint32_t lcid) pthread_rwlock_unlock(&rwlock); } - void rlc::change_lcid(uint32_t old_lcid, uint32_t new_lcid) { pthread_rwlock_wrlock(&rwlock); @@ -532,8 +527,8 @@ void rlc::change_lcid(uint32_t old_lcid, uint32_t new_lcid) // make sure old LCID exists and new LCID is still free if (valid_lcid(old_lcid) && not valid_lcid(new_lcid)) { // insert old rlc entity into new LCID - rlc_map_t::iterator it = rlc_array.find(old_lcid); - rlc_common *rlc_entity = it->second; + rlc_map_t::iterator it = rlc_array.find(old_lcid); + rlc_common* rlc_entity = it->second; if (not rlc_array.insert(rlc_map_pair_t(new_lcid, rlc_entity)).second) { rlc_log->error("Error inserting RLC entity into array\n."); goto exit; @@ -547,7 +542,10 @@ void rlc::change_lcid(uint32_t old_lcid, uint32_t new_lcid) rlc_log->error("Error during LCID change of RLC bearer from %d to %d\n", old_lcid, new_lcid); } } else { - rlc_log->error("Can't change LCID of bearer %s from %d to %d. Bearer doesn't exist or new LCID already occupied.\n", rrc->get_rb_name(old_lcid).c_str(), old_lcid, new_lcid); + rlc_log->error("Can't change LCID of bearer %s from %d to %d. Bearer doesn't exist or new LCID already occupied.\n", + rrc->get_rb_name(old_lcid).c_str(), + old_lcid, + new_lcid); } exit: pthread_rwlock_unlock(&rwlock); @@ -596,7 +594,6 @@ bool rlc::has_bearer(uint32_t lcid) return ret; } - /******************************************************************************* Helpers (Lock must be hold when calling those) *******************************************************************************/ diff --git a/lib/src/upper/rlc_am_lte.cc b/lib/src/upper/rlc_am_lte.cc index a3aa4ee7a..d157f902b 100644 --- a/lib/src/upper/rlc_am_lte.cc +++ b/lib/src/upper/rlc_am_lte.cc @@ -25,8 +25,8 @@ #include #define MOD 1024 -#define RX_MOD_BASE(x) (((x)-vr_r)%1024) -#define TX_MOD_BASE(x) (((x)-vt_a)%1024) +#define RX_MOD_BASE(x) (((x)-vr_r) % 1024) +#define TX_MOD_BASE(x) (((x)-vt_a) % 1024) #define LCID (parent->lcid) #define RB_NAME (parent->rb_name.c_str()) @@ -37,7 +37,13 @@ rlc_am_lte::rlc_am_lte(srslte::log* log_, srsue::pdcp_interface_rlc* pdcp_, srsue::rrc_interface_rlc* rrc_, srslte::timer_handler* timers_) : - log(log_), rrc(rrc_), pdcp(pdcp_), timers(timers_), lcid(lcid_), tx(this), rx(this) + log(log_), + rrc(rrc_), + pdcp(pdcp_), + timers(timers_), + lcid(lcid_), + tx(this), + rx(this) { } @@ -235,7 +241,7 @@ void rlc_am_lte::rlc_am_lte_tx::empty_queue() pthread_mutex_lock(&mutex); // deallocate all SDUs in transmit queue - while(tx_sdu_queue.size() > 0) { + while (tx_sdu_queue.size() > 0) { unique_byte_buffer_t buf = tx_sdu_queue.read(); } @@ -284,10 +290,15 @@ uint32_t rlc_am_lte::rlc_am_lte_tx::get_buffer_state() } // Bytes needed for retx - if(not retx_queue.empty()) { + if (not retx_queue.empty()) { rlc_amd_retx_t retx = retx_queue.front(); - log->debug("%s Buffer state - retx - SN: %d, Segment: %s, %d:%d\n", RB_NAME, retx.sn, retx.is_segment ? "true" : "false", retx.so_start, retx.so_end); - if(tx_window.end() != tx_window.find(retx.sn)) { + log->debug("%s Buffer state - retx - SN: %d, Segment: %s, %d:%d\n", + RB_NAME, + retx.sn, + retx.is_segment ? "true" : "false", + retx.so_start, + retx.so_end); + if (tx_window.end() != tx_window.find(retx.sn)) { int req_bytes = required_buffer_size(retx); if (req_bytes < 0) { log->error("In get_buffer_state(): Removing retx.sn=%d from queue\n", retx.sn); @@ -300,8 +311,8 @@ uint32_t rlc_am_lte::rlc_am_lte_tx::get_buffer_state() } // Bytes needed for tx SDUs - if(tx_window.size() < 1024) { - n_sdus = tx_sdu_queue.size(); + if (tx_window.size() < 1024) { + n_sdus = tx_sdu_queue.size(); n_bytes += tx_sdu_queue.size_bytes(); if (tx_sdu != NULL) { n_sdus++; @@ -311,7 +322,7 @@ uint32_t rlc_am_lte::rlc_am_lte_tx::get_buffer_state() // Room needed for header extensions? (integer rounding) if (n_sdus > 1) { - n_bytes += ((n_sdus-1)*1.5)+0.5; + n_bytes += ((n_sdus - 1) * 1.5) + 0.5; } // Room needed for fixed header of data PDUs @@ -433,10 +444,10 @@ void rlc_am_lte::rlc_am_lte_tx::retransmit_random_pdu() std::advance(it, rand() % tx_window.size()); log->info("Schedule SN=%d for reTx.\n", it->first); rlc_amd_retx_t retx = {}; - retx.is_segment = false; - retx.so_start = 0; - retx.so_end = it->second.buf->N_bytes; - retx.sn = it->first; + retx.is_segment = false; + retx.so_start = 0; + retx.so_end = it->second.buf->N_bytes; + retx.sn = it->first; retx_queue.push_back(retx); } } @@ -529,7 +540,7 @@ int rlc_am_lte::rlc_am_lte_tx::build_retx_pdu(uint8_t* payload, uint32_t nof_byt rlc_amd_retx_t retx = retx_queue.front(); // Sanity check - drop any retx SNs not present in tx_window - while(tx_window.end() == tx_window.find(retx.sn)) { + while (tx_window.end() == tx_window.find(retx.sn)) { retx_queue.pop_front(); if (!retx_queue.empty()) { retx = retx_queue.front(); @@ -554,7 +565,7 @@ int rlc_am_lte::rlc_am_lte_tx::build_retx_pdu(uint8_t* payload, uint32_t nof_byt // Update & write header rlc_amd_pdu_header_t new_header = tx_window[retx.sn].header; - new_header.p = 0; + new_header.p = 0; // Set poll bit pdu_without_poll++; @@ -578,16 +589,15 @@ int rlc_am_lte::rlc_am_lte_tx::build_retx_pdu(uint8_t* payload, uint32_t nof_byt retx_queue.pop_front(); tx_window[retx.sn].retx_count++; if (tx_window[retx.sn].retx_count >= cfg.max_retx_thresh) { - log->warning("%s Signaling max number of reTx=%d for for PDU %d\n", - RB_NAME, tx_window[retx.sn].retx_count, retx.sn); + log->warning( + "%s Signaling max number of reTx=%d for for PDU %d\n", RB_NAME, tx_window[retx.sn].retx_count, retx.sn); parent->rrc->max_retx_attempted(); } - log->info("%s Retx PDU scheduled for tx. SN: %d, retx count: %d\n", - RB_NAME, retx.sn, tx_window[retx.sn].retx_count); + log->info("%s Retx PDU scheduled for tx. SN: %d, retx count: %d\n", RB_NAME, retx.sn, tx_window[retx.sn].retx_count); debug_state(); - return (ptr-payload) + tx_window[retx.sn].buf->N_bytes; + return (ptr - payload) + tx_window[retx.sn].buf->N_bytes; } int rlc_am_lte::rlc_am_lte_tx::build_segment(uint8_t* payload, uint32_t nof_bytes, rlc_amd_retx_t retx) @@ -598,7 +608,7 @@ int rlc_am_lte::rlc_am_lte_tx::build_segment(uint8_t* payload, uint32_t nof_byte } if (!retx.is_segment) { retx.so_start = 0; - retx.so_end = tx_window[retx.sn].buf->N_bytes; + retx.so_end = tx_window[retx.sn].buf->N_bytes; } // Construct new header @@ -610,9 +620,9 @@ int rlc_am_lte::rlc_am_lte_tx::build_segment(uint8_t* payload, uint32_t nof_byte log->info("%s pdu_without_poll: %d\n", RB_NAME, pdu_without_poll); log->info("%s byte_without_poll: %d\n", RB_NAME, byte_without_poll); - new_header.dc = RLC_DC_FIELD_DATA_PDU; - new_header.rf = 1; - new_header.fi = RLC_FI_FIELD_NOT_START_OR_END_ALIGNED; + new_header.dc = RLC_DC_FIELD_DATA_PDU; + new_header.rf = 1; + new_header.fi = RLC_FI_FIELD_NOT_START_OR_END_ALIGNED; new_header.sn = old_header.sn; new_header.lsf = 0; new_header.so = retx.so_start; @@ -653,14 +663,14 @@ int rlc_am_lte::rlc_am_lte_tx::build_segment(uint8_t* payload, uint32_t nof_byte // Need to rebuild the li table & update fi based on so_start and so_end if (retx.so_start == 0 && rlc_am_start_aligned(old_header.fi)) { - new_header.fi &= RLC_FI_FIELD_NOT_END_ALIGNED; // segment is start aligned + new_header.fi &= RLC_FI_FIELD_NOT_END_ALIGNED; // segment is start aligned } - uint32_t lower = 0; - uint32_t upper = 0; - uint32_t li = 0; + uint32_t lower = 0; + uint32_t upper = 0; + uint32_t li = 0; - for(uint32_t i=0; i= retx.so_end) { break; } @@ -671,17 +681,17 @@ int rlc_am_lte::rlc_am_lte_tx::build_segment(uint8_t* payload, uint32_t nof_byte upper += old_header.li[i]; - head_len = rlc_am_packed_length(&new_header); + head_len = rlc_am_packed_length(&new_header); // Accomodate some extra space for for LIs if old header contained segments too head_len += old_header.N_li; - pdu_space = nof_bytes-head_len; - if(pdu_space < (retx.so_end-retx.so_start)) { + pdu_space = nof_bytes - head_len; + if (pdu_space < (retx.so_end - retx.so_start)) { retx.so_end = retx.so_start + pdu_space; } - if(upper > retx.so_start && lower < retx.so_end) { // Current SDU is needed + if (upper > retx.so_start && lower < retx.so_end) { // Current SDU is needed li = upper - lower; if (upper > retx.so_end) { li -= upper - retx.so_end; @@ -690,7 +700,7 @@ int rlc_am_lte::rlc_am_lte_tx::build_segment(uint8_t* payload, uint32_t nof_byte li -= retx.so_start - lower; } if (lower > 0 && lower == retx.so_start) { - new_header.fi &= RLC_FI_FIELD_NOT_END_ALIGNED; // segment start is aligned with this SDU + new_header.fi &= RLC_FI_FIELD_NOT_END_ALIGNED; // segment start is aligned with this SDU } if (upper == retx.so_end) { new_header.fi &= RLC_FI_FIELD_NOT_START_ALIGNED; // segment end is aligned with this SDU @@ -707,31 +717,30 @@ int rlc_am_lte::rlc_am_lte_tx::build_segment(uint8_t* payload, uint32_t nof_byte } // Update retx_queue - if(tx_window[retx.sn].buf->N_bytes == retx.so_end) { + if (tx_window[retx.sn].buf->N_bytes == retx.so_end) { retx_queue.pop_front(); new_header.lsf = 1; - if(rlc_am_end_aligned(old_header.fi)) { - new_header.fi &= RLC_FI_FIELD_NOT_START_ALIGNED; // segment is end aligned + if (rlc_am_end_aligned(old_header.fi)) { + new_header.fi &= RLC_FI_FIELD_NOT_START_ALIGNED; // segment is end aligned } - } else if(retx_queue.front().so_end == retx.so_end) { + } else if (retx_queue.front().so_end == retx.so_end) { retx_queue.pop_front(); } else { retx_queue.front().is_segment = true; - retx_queue.front().so_start = retx.so_end; + retx_queue.front().so_start = retx.so_end; } // Write header and pdu - uint8_t *ptr = payload; + uint8_t* ptr = payload; rlc_am_write_data_pdu_header(&new_header, &ptr); uint8_t* data = &tx_window[retx.sn].buf->msg[retx.so_start]; uint32_t len = retx.so_end - retx.so_start; memcpy(ptr, data, len); debug_state(); - int pdu_len = (ptr-payload) + len; + int pdu_len = (ptr - payload) + len; if (pdu_len > static_cast(nof_bytes)) { - log->error("%s Retx PDU segment length error. Available: %d, Used: %d\n", - RB_NAME, nof_bytes, pdu_len); + log->error("%s Retx PDU segment length error. Available: %d, Used: %d\n", RB_NAME, nof_bytes, pdu_len); int header_len = (ptr - payload); log->debug("%s Retx PDU segment length error. Header len: %d, Payload len: %d, N_li: %d\n", RB_NAME, @@ -740,8 +749,14 @@ int rlc_am_lte::rlc_am_lte_tx::build_segment(uint8_t* payload, uint32_t nof_byte new_header.N_li); } - log->info_hex(payload, pdu_len, "%s Retx PDU segment of SN=%d (%d B), SO: %d, N_li: %d\n", - RB_NAME, retx.sn, pdu_len, retx.so_start, new_header.N_li); + log->info_hex(payload, + pdu_len, + "%s Retx PDU segment of SN=%d (%d B), SO: %d, N_li: %d\n", + RB_NAME, + retx.sn, + pdu_len, + retx.so_start, + new_header.N_li); return pdu_len; } @@ -767,7 +782,7 @@ int rlc_am_lte::rlc_am_lte_tx::build_data_pdu(uint8_t* payload, uint32_t nof_byt log->console("vt_a = %d, vt_ms = %d, vt_s = %d, poll_sn = %d\n", vt_a, vt_ms, vt_s, poll_sn); log->console("retx_queue size: %zd PDUs\n", retx_queue.size()); std::map::iterator txit; - for(txit = tx_window.begin(); txit != tx_window.end(); txit++) { + for (txit = tx_window.begin(); txit != tx_window.end(); txit++) { log->console("tx_window - SN: %d\n", txit->first); } exit(-1); @@ -790,7 +805,7 @@ int rlc_am_lte::rlc_am_lte_tx::build_data_pdu(uint8_t* payload, uint32_t nof_byt uint32_t to_move = 0; uint32_t last_li = 0; uint32_t pdu_space = SRSLTE_MIN(nof_bytes, pdu->get_tailroom()); - uint8_t *pdu_ptr = pdu->msg; + uint8_t* pdu_ptr = pdu->msg; if (pdu_space <= head_len + 1) { log->info( @@ -798,22 +813,19 @@ int rlc_am_lte::rlc_am_lte_tx::build_data_pdu(uint8_t* payload, uint32_t nof_byt return 0; } - log->debug("%s Building PDU - pdu_space: %d, head_len: %d \n", - RB_NAME, pdu_space, head_len); + log->debug("%s Building PDU - pdu_space: %d, head_len: %d \n", RB_NAME, pdu_space, head_len); // Check for SDU segment if (tx_sdu != NULL) { - to_move = ((pdu_space-head_len) >= tx_sdu->N_bytes) ? tx_sdu->N_bytes : pdu_space-head_len; + to_move = ((pdu_space - head_len) >= tx_sdu->N_bytes) ? tx_sdu->N_bytes : pdu_space - head_len; memcpy(pdu_ptr, tx_sdu->msg, to_move); - last_li = to_move; - pdu_ptr += to_move; - pdu->N_bytes += to_move; + last_li = to_move; + pdu_ptr += to_move; + pdu->N_bytes += to_move; tx_sdu->N_bytes -= to_move; - tx_sdu->msg += to_move; - if(tx_sdu->N_bytes == 0) - { - log->debug("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", - RB_NAME, tx_sdu->get_latency_us()); + tx_sdu->msg += to_move; + if (tx_sdu->N_bytes == 0) { + log->debug("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", RB_NAME, tx_sdu->get_latency_us()); tx_sdu.reset(); } if (pdu_space > to_move) { @@ -824,7 +836,10 @@ int rlc_am_lte::rlc_am_lte_tx::build_data_pdu(uint8_t* payload, uint32_t nof_byt header.fi |= RLC_FI_FIELD_NOT_START_ALIGNED; // First byte does not correspond to first byte of SDU log->debug("%s Building PDU - added SDU segment (len:%d) - pdu_space: %d, head_len: %d \n", - RB_NAME, to_move, pdu_space, head_len); + RB_NAME, + to_move, + pdu_space, + head_len); } // Pull SDUs from queue @@ -839,26 +854,28 @@ int rlc_am_lte::rlc_am_lte_tx::build_data_pdu(uint8_t* payload, uint32_t nof_byt break; } tx_sdu = tx_sdu_queue.read(); - to_move = ((pdu_space-head_len) >= tx_sdu->N_bytes) ? tx_sdu->N_bytes : pdu_space-head_len; + to_move = ((pdu_space - head_len) >= tx_sdu->N_bytes) ? tx_sdu->N_bytes : pdu_space - head_len; memcpy(pdu_ptr, tx_sdu->msg, to_move); - last_li = to_move; - pdu_ptr += to_move; - pdu->N_bytes += to_move; + last_li = to_move; + pdu_ptr += to_move; + pdu->N_bytes += to_move; tx_sdu->N_bytes -= to_move; - tx_sdu->msg += to_move; + tx_sdu->msg += to_move; if (tx_sdu->N_bytes == 0) { - log->debug("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", - RB_NAME, tx_sdu->get_latency_us()); + log->debug("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", RB_NAME, tx_sdu->get_latency_us()); tx_sdu.reset(); } - if(pdu_space > to_move) { + if (pdu_space > to_move) { pdu_space -= to_move; } else { pdu_space = 0; } log->debug("%s Building PDU - added SDU segment (len:%d) - pdu_space: %d, head_len: %d \n", - RB_NAME, to_move, pdu_space, head_len); + RB_NAME, + to_move, + pdu_space, + head_len); } // Make sure, at least one SDU (segment) has been added until this point @@ -876,8 +893,7 @@ int rlc_am_lte::rlc_am_lte_tx::build_data_pdu(uint8_t* payload, uint32_t nof_byt byte_without_poll += (pdu->N_bytes + head_len); log->debug("%s pdu_without_poll: %d\n", RB_NAME, pdu_without_poll); log->debug("%s byte_without_poll: %d\n", RB_NAME, byte_without_poll); - if(poll_required()) - { + if (poll_required()) { log->debug("%s setting poll bit to request status\n", RB_NAME); header.p = 1; poll_sn = vt_s; @@ -890,7 +906,7 @@ int rlc_am_lte::rlc_am_lte_tx::build_data_pdu(uint8_t* payload, uint32_t nof_byt // Set SN header.sn = vt_s; - vt_s = (vt_s + 1)%MOD; + vt_s = (vt_s + 1) % MOD; // Place PDU in tx_window, write header and TX tx_window[header.sn].buf = std::move(pdu); @@ -899,7 +915,7 @@ int rlc_am_lte::rlc_am_lte_tx::build_data_pdu(uint8_t* payload, uint32_t nof_byt tx_window[header.sn].retx_count = 0; const byte_buffer_t* buffer_ptr = tx_window[header.sn].buf.get(); - uint8_t *ptr = payload; + uint8_t* ptr = payload; rlc_am_write_data_pdu_header(&header, &ptr); memcpy(ptr, buffer_ptr->msg, buffer_ptr->N_bytes); int total_len = (ptr - payload) + buffer_ptr->N_bytes; @@ -931,51 +947,52 @@ void rlc_am_lte::rlc_am_lte_tx::handle_control_pdu(uint8_t* payload, uint32_t no // Handle ACKs and NACKs std::map::iterator it; - bool update_vt_a = true; - uint32_t i = vt_a; + bool update_vt_a = true; + uint32_t i = vt_a; - while(TX_MOD_BASE(i) < TX_MOD_BASE(status.ack_sn) && - TX_MOD_BASE(i) < TX_MOD_BASE(vt_s)) - { + while (TX_MOD_BASE(i) < TX_MOD_BASE(status.ack_sn) && TX_MOD_BASE(i) < TX_MOD_BASE(vt_s)) { bool nack = false; - for(uint32_t j=0;jsecond.buf->N_bytes; + retx.sn = i; + retx.is_segment = false; + retx.so_start = 0; + retx.so_end = it->second.buf->N_bytes; - if(status.nacks[j].has_so) { + if (status.nacks[j].has_so) { // sanity check if (status.nacks[j].so_start >= it->second.buf->N_bytes) { // print error but try to send original PDU again log->info("SO_start is larger than original PDU (%d >= %d)\n", - status.nacks[j].so_start, - it->second.buf->N_bytes); + status.nacks[j].so_start, + it->second.buf->N_bytes); status.nacks[j].so_start = 0; } // check for special SO_end value - if(status.nacks[j].so_end == 0x7FFF) { + if (status.nacks[j].so_end == 0x7FFF) { status.nacks[j].so_end = it->second.buf->N_bytes; - }else{ + } else { retx.so_end = status.nacks[j].so_end + 1; } - if(status.nacks[j].so_start < it->second.buf->N_bytes && - status.nacks[j].so_end <= it->second.buf->N_bytes) { - retx.is_segment = true; - retx.so_start = status.nacks[j].so_start; + if (status.nacks[j].so_start < it->second.buf->N_bytes && + status.nacks[j].so_end <= it->second.buf->N_bytes) { + retx.is_segment = true; + retx.so_start = status.nacks[j].so_start; } else { log->warning("%s invalid segment NACK received for SN %d. so_start: %d, so_end: %d, N_bytes: %d\n", - RB_NAME, i, status.nacks[j].so_start, status.nacks[j].so_end, it->second.buf->N_bytes); + RB_NAME, + i, + status.nacks[j].so_start, + status.nacks[j].so_end, + it->second.buf->N_bytes); } } retx_queue.push_back(retx); @@ -984,20 +1001,20 @@ void rlc_am_lte::rlc_am_lte_tx::handle_control_pdu(uint8_t* payload, uint32_t no } } - if(!nack) { - //ACKed SNs get marked and removed from tx_window if possible - if(tx_window.count(i) > 0) { + if (!nack) { + // ACKed SNs get marked and removed from tx_window if possible + if (tx_window.count(i) > 0) { it = tx_window.find(i); if (it != tx_window.end()) { - if(update_vt_a) { + if (update_vt_a) { tx_window.erase(it); - vt_a = (vt_a + 1)%MOD; - vt_ms = (vt_ms + 1)%MOD; + vt_a = (vt_a + 1) % MOD; + vt_ms = (vt_ms + 1) % MOD; } } } } - i = (i+1)%MOD; + i = (i + 1) % MOD; } debug_state(); @@ -1007,8 +1024,7 @@ void rlc_am_lte::rlc_am_lte_tx::handle_control_pdu(uint8_t* payload, uint32_t no void rlc_am_lte::rlc_am_lte_tx::debug_state() { - log->debug("%s vt_a = %d, vt_ms = %d, vt_s = %d, poll_sn = %d\n", - RB_NAME, vt_a, vt_ms, vt_s, poll_sn); + log->debug("%s vt_a = %d, vt_ms = %d, vt_s = %d, poll_sn = %d\n", RB_NAME, vt_a, vt_ms, vt_s, poll_sn); } int rlc_am_lte::rlc_am_lte_tx::required_buffer_size(rlc_amd_retx_t retx) @@ -1041,22 +1057,22 @@ int rlc_am_lte::rlc_am_lte_tx::required_buffer_size(rlc_amd_retx_t retx) new_header.N_li = 0; // Need to rebuild the li table & update fi based on so_start and so_end - if(retx.so_start != 0 && rlc_am_start_aligned(old_header.fi)) { - new_header.fi &= RLC_FI_FIELD_NOT_END_ALIGNED; // segment is start aligned + if (retx.so_start != 0 && rlc_am_start_aligned(old_header.fi)) { + new_header.fi &= RLC_FI_FIELD_NOT_END_ALIGNED; // segment is start aligned } - uint32_t lower = 0; - uint32_t upper = 0; - uint32_t li = 0; + uint32_t lower = 0; + uint32_t upper = 0; + uint32_t li = 0; - for(uint32_t i=0; i= retx.so_end) { + for (uint32_t i = 0; i < old_header.N_li; i++) { + if (lower >= retx.so_end) { break; } upper += old_header.li[i]; - if (upper > retx.so_start && lower < retx.so_end) { // Current SDU is needed + if (upper > retx.so_start && lower < retx.so_end) { // Current SDU is needed li = upper - lower; if (upper > retx.so_end) { li -= upper - retx.so_end; @@ -1065,7 +1081,7 @@ int rlc_am_lte::rlc_am_lte_tx::required_buffer_size(rlc_amd_retx_t retx) li -= retx.so_start - lower; } if (lower > 0 && lower == retx.so_start) { - new_header.fi &= RLC_FI_FIELD_NOT_END_ALIGNED; // segment start is aligned with this SDU + new_header.fi &= RLC_FI_FIELD_NOT_END_ALIGNED; // segment start is aligned with this SDU } if (upper == retx.so_end) { new_header.fi &= RLC_FI_FIELD_NOT_START_ALIGNED; // segment end is aligned with this SDU @@ -1076,12 +1092,12 @@ int rlc_am_lte::rlc_am_lte_tx::required_buffer_size(rlc_amd_retx_t retx) lower += old_header.li[i]; } -// if(tx_window[retx.sn].buf->N_bytes != retx.so_end) { -// if(new_header.N_li > 0) -// new_header.N_li--; // No li for last segment -// } + // if(tx_window[retx.sn].buf->N_bytes != retx.so_end) { + // if(new_header.N_li > 0) + // new_header.N_li--; // No li for last segment + // } - return rlc_am_packed_length(&new_header) + (retx.so_end-retx.so_start); + return rlc_am_packed_length(&new_header) + (retx.so_end - retx.so_start); } bool rlc_am_lte::rlc_am_lte_tx::retx_queue_has_sn(uint32_t sn) @@ -1095,8 +1111,6 @@ bool rlc_am_lte::rlc_am_lte_tx::retx_queue_has_sn(uint32_t sn) return false; } - - /**************************************************************************** * Rx subclass implementation ***************************************************************************/ @@ -1149,11 +1163,11 @@ void rlc_am_lte::rlc_am_lte_rx::stop() rx_sdu.reset(); - vr_r = 0; - vr_mr = RLC_AM_WINDOW_SIZE; - vr_x = 0; - vr_ms = 0; - vr_h = 0; + vr_r = 0; + vr_mr = RLC_AM_WINDOW_SIZE; + vr_x = 0; + vr_ms = 0; + vr_h = 0; poll_received = false; do_status = false; @@ -1171,10 +1185,7 @@ void rlc_am_lte::rlc_am_lte_rx::handle_data_pdu(uint8_t* payload, uint32_t nof_b { std::map::iterator it; - log->info_hex(payload, nof_bytes, "%s Rx data PDU SN=%d (%d B)", - RB_NAME, - header.sn, - nof_bytes); + log->info_hex(payload, nof_bytes, "%s Rx data PDU SN=%d (%d B)", RB_NAME, header.sn, nof_bytes); log->debug("%s\n", rlc_amd_pdu_header_to_string(header).c_str()); // sanity check for segments not exceeding PDU length @@ -1189,24 +1200,22 @@ void rlc_am_lte::rlc_am_lte_rx::handle_data_pdu(uint8_t* payload, uint32_t nof_b } } - if(!inside_rx_window(header.sn)) { - if(header.p) { + if (!inside_rx_window(header.sn)) { + if (header.p) { log->info("%s Status packet requested through polling bit\n", RB_NAME); do_status = true; } - log->info("%s SN: %d outside rx window [%d:%d] - discarding\n", - RB_NAME, header.sn, vr_r, vr_mr); + log->info("%s SN: %d outside rx window [%d:%d] - discarding\n", RB_NAME, header.sn, vr_r, vr_mr); return; } it = rx_window.find(header.sn); - if(rx_window.end() != it) { - if(header.p) { + if (rx_window.end() != it) { + if (header.p) { log->info("%s Status packet requested through polling bit\n", RB_NAME); do_status = true; } - log->info("%s Discarding duplicate SN: %d\n", - RB_NAME, header.sn); + log->info("%s Discarding duplicate SN: %d\n", RB_NAME, header.sn); return; } @@ -1226,25 +1235,28 @@ void rlc_am_lte::rlc_am_lte_rx::handle_data_pdu(uint8_t* payload, uint32_t nof_b // check available space for payload if (nof_bytes > pdu.buf->get_tailroom()) { log->error("%s Discarding SN: %d of size %d B (available space %d B)\n", - RB_NAME, header.sn, nof_bytes, pdu.buf->get_tailroom()); + RB_NAME, + header.sn, + nof_bytes, + pdu.buf->get_tailroom()); return; } memcpy(pdu.buf->msg, payload, nof_bytes); - pdu.buf->N_bytes = nof_bytes; - pdu.header = header; + pdu.buf->N_bytes = nof_bytes; + pdu.header = header; rx_window[header.sn] = std::move(pdu); // Update vr_h - if(RX_MOD_BASE(header.sn) >= RX_MOD_BASE(vr_h)) { + if (RX_MOD_BASE(header.sn) >= RX_MOD_BASE(vr_h)) { vr_h = (header.sn + 1) % MOD; } // Update vr_ms it = rx_window.find(vr_ms); - while(rx_window.end() != it) { - vr_ms = (vr_ms + 1)%MOD; - it = rx_window.find(vr_ms); + while (rx_window.end() != it) { + vr_ms = (vr_ms + 1) % MOD; + it = rx_window.find(vr_ms); } // Check poll bit @@ -1295,18 +1307,23 @@ void rlc_am_lte::rlc_am_lte_rx::handle_data_pdu_segment(uint8_t* pa { std::map::iterator it; - log->info_hex(payload, nof_bytes, "%s Rx data PDU segment of SN=%d (%d B), SO=%d, N_li=%d", - RB_NAME, header.sn, nof_bytes, header.so, header.N_li); + log->info_hex(payload, + nof_bytes, + "%s Rx data PDU segment of SN=%d (%d B), SO=%d, N_li=%d", + RB_NAME, + header.sn, + nof_bytes, + header.so, + header.N_li); log->debug("%s\n", rlc_amd_pdu_header_to_string(header).c_str()); // Check inside rx window - if(!inside_rx_window(header.sn)) { - if(header.p) { + if (!inside_rx_window(header.sn)) { + if (header.p) { log->info("%s Status packet requested through polling bit\n", RB_NAME); do_status = true; } - log->info("%s SN: %d outside rx window [%d:%d] - discarding\n", - RB_NAME, header.sn, vr_r, vr_mr); + log->info("%s SN: %d outside rx window [%d:%d] - discarding\n", RB_NAME, header.sn, vr_r, vr_mr); return; } @@ -1342,7 +1359,7 @@ void rlc_am_lte::rlc_am_lte_rx::handle_data_pdu_segment(uint8_t* pa // Add segment to PDU list and check for complete // NOTE: MAY MOVE. Preference would be to capture by value, and then move; but header is stack allocated - if(add_segment_and_check(&it->second, &segment)) { + if (add_segment_and_check(&it->second, &segment)) { rx_segments.erase(it); } @@ -1364,9 +1381,7 @@ void rlc_am_lte::rlc_am_lte_rx::handle_data_pdu_segment(uint8_t* pa poll_received = true; // 36.322 v10 Section 5.2.3 - if(RX_MOD_BASE(header.sn) < RX_MOD_BASE(vr_ms) || - RX_MOD_BASE(header.sn) >= RX_MOD_BASE(vr_mr)) - { + if (RX_MOD_BASE(header.sn) < RX_MOD_BASE(vr_ms) || RX_MOD_BASE(header.sn) >= RX_MOD_BASE(vr_mr)) { do_status = true; } // else delay for reordering timer @@ -1395,14 +1410,18 @@ void rlc_am_lte::rlc_am_lte_rx::reassemble_rx_sdus() } // Iterate through rx_window, assembling and delivering SDUs - while(rx_window.end() != rx_window.find(vr_r)) - { + while (rx_window.end() != rx_window.find(vr_r)) { // Handle any SDU segments - for(uint32_t i=0; idebug_hex(rx_window[vr_r].buf->msg, len, "Handling segment %d/%d of length %d B of SN=%d\n", i+1, rx_window[vr_r].header.N_li, len, vr_r); + log->debug_hex(rx_window[vr_r].buf->msg, + len, + "Handling segment %d/%d of length %d B of SN=%d\n", + i + 1, + rx_window[vr_r].header.N_li, + len, + vr_r); // sanity check to avoid zero-size SDUs if (len == 0) { @@ -1431,7 +1450,7 @@ void rlc_am_lte::rlc_am_lte_rx::reassemble_rx_sdus() if (rx_sdu == nullptr) { #ifdef RLC_AM_BUFFER_DEBUG log->console("Fatal Error: Could not allocate PDU in reassemble_rx_sdus() (2)\n"); - exit(-1); + exit(-1); #else log->error("Fatal Error: Could not allocate PDU in reassemble_rx_sdus() (2)\n"); return; @@ -1481,30 +1500,34 @@ void rlc_am_lte::rlc_am_lte_rx::reassemble_rx_sdus() } } -exit: + exit: // Move the rx_window log->debug("Erasing SN=%d.\n", vr_r); // also erase any segments of this SN std::map::iterator it; it = rx_segments.find(vr_r); - if(rx_segments.end() != it) { + if (rx_segments.end() != it) { log->debug("Erasing segments of SN=%d\n", vr_r); std::list::iterator segit; - for(segit = it->second.segments.begin(); segit != it->second.segments.end(); ++segit) { - log->debug(" Erasing segment of SN=%d SO=%d Len=%d N_li=%d\n", segit->header.sn, segit->header.so, segit->buf->N_bytes, segit->header.N_li); + for (segit = it->second.segments.begin(); segit != it->second.segments.end(); ++segit) { + log->debug(" Erasing segment of SN=%d SO=%d Len=%d N_li=%d\n", + segit->header.sn, + segit->header.so, + segit->buf->N_bytes, + segit->header.N_li); } it->second.segments.clear(); } rx_window.erase(vr_r); - vr_r = (vr_r + 1)%MOD; - vr_mr = (vr_mr + 1)%MOD; + vr_r = (vr_r + 1) % MOD; + vr_mr = (vr_mr + 1) % MOD; } } void rlc_am_lte::rlc_am_lte_rx::reset_status() { pthread_mutex_lock(&mutex); - do_status = false; + do_status = false; poll_received = false; pthread_mutex_unlock(&mutex); } @@ -1528,7 +1551,8 @@ void rlc_am_lte::rlc_am_lte_rx::reset_metrics() void rlc_am_lte::rlc_am_lte_rx::write_pdu(uint8_t* payload, const uint32_t nof_bytes) { - if (nof_bytes < 1) return; + if (nof_bytes < 1) + return; pthread_mutex_lock(&mutex); num_rx_bytes += nof_bytes; @@ -1548,7 +1572,7 @@ void rlc_am_lte::rlc_am_lte_rx::write_pdu(uint8_t* payload, const uint32_t nof_b } if (header.rf) { handle_data_pdu_segment(payload, payload_len, header); - } else{ + } else { handle_data_pdu(payload, payload_len, header); } pthread_mutex_unlock(&mutex); @@ -1632,12 +1656,12 @@ int rlc_am_lte::rlc_am_lte_rx::get_status_pdu_length() pthread_mutex_lock(&mutex); rlc_status_pdu_t status = {}; status.ack_sn = vr_ms; - uint32_t i = vr_r; + uint32_t i = vr_r; while (RX_MOD_BASE(i) < RX_MOD_BASE(vr_ms) && status.N_nack < RLC_AM_WINDOW_SIZE) { - if(rx_window.find(i) == rx_window.end()) { + if (rx_window.find(i) == rx_window.end()) { status.N_nack++; } - i = (i + 1)%MOD; + i = (i + 1) % MOD; } pthread_mutex_unlock(&mutex); return rlc_am_packed_length(&status); @@ -1646,12 +1670,13 @@ int rlc_am_lte::rlc_am_lte_rx::get_status_pdu_length() void rlc_am_lte::rlc_am_lte_rx::print_rx_segments() { std::map::iterator it; - std::stringstream ss; + std::stringstream ss; ss << "rx_segments:" << std::endl; - for(it=rx_segments.begin();it!=rx_segments.end();it++) { + for (it = rx_segments.begin(); it != rx_segments.end(); it++) { std::list::iterator segit; - for(segit = it->second.segments.begin(); segit != it->second.segments.end(); segit++) { - ss << " SN:" << segit->header.sn << " SO:" << segit->header.so << " N:" << segit->buf->N_bytes << " N_li: " << segit->header.N_li << std::endl; + for (segit = it->second.segments.begin(); segit != it->second.segments.end(); segit++) { + ss << " SN:" << segit->header.sn << " SO:" << segit->header.so << " N:" << segit->buf->N_bytes + << " N_li: " << segit->header.N_li << std::endl; } } log->debug("%s\n", ss.str().c_str()); @@ -1661,7 +1686,7 @@ void rlc_am_lte::rlc_am_lte_rx::print_rx_segments() bool rlc_am_lte::rlc_am_lte_rx::add_segment_and_check(rlc_amd_rx_pdu_segments_t* pdu, rlc_amd_rx_pdu_t* segment) { // Check for first segment - if(0 == segment->header.so) { + if (0 == segment->header.so) { pdu->segments.clear(); pdu->segments.push_back(std::move(*segment)); return false; @@ -1669,12 +1694,12 @@ bool rlc_am_lte::rlc_am_lte_rx::add_segment_and_check(rlc_amd_rx_pdu_segments_t* // Check segment offset uint32_t n = 0; - if(!pdu->segments.empty()) { - rlc_amd_rx_pdu_t &back = pdu->segments.back(); - n = back.header.so + back.buf->N_bytes; + if (!pdu->segments.empty()) { + rlc_amd_rx_pdu_t& back = pdu->segments.back(); + n = back.header.so + back.buf->N_bytes; } - if(segment->header.so != n) { + if (segment->header.so != n) { log->warning("Received PDU with SO=%d, expected %d. Discarding PDU.\n", segment->header.so, n); return false; } else { @@ -1682,9 +1707,9 @@ bool rlc_am_lte::rlc_am_lte_rx::add_segment_and_check(rlc_amd_rx_pdu_segments_t* } // Check for complete - uint32_t so = 0; + uint32_t so = 0; std::list::iterator it, tmpit; - for(it = pdu->segments.begin(); it != pdu->segments.end(); it++) { + for (it = pdu->segments.begin(); it != pdu->segments.end(); it++) { if (so != it->header.so) { return false; } @@ -1707,21 +1732,27 @@ bool rlc_am_lte::rlc_am_lte_rx::add_segment_and_check(rlc_amd_rx_pdu_segments_t* // Reconstruct fi field header.fi |= (pdu->segments.front().header.fi & RLC_FI_FIELD_NOT_START_ALIGNED); - header.fi |= (pdu->segments.back().header.fi & RLC_FI_FIELD_NOT_END_ALIGNED); + header.fi |= (pdu->segments.back().header.fi & RLC_FI_FIELD_NOT_END_ALIGNED); log->debug("Starting header reconstruction of %zd segments\n", pdu->segments.size()); // Reconstruct li fields uint16_t count = 0; uint16_t carryover = 0; - for(it = pdu->segments.begin(); it != pdu->segments.end(); it++) { + for (it = pdu->segments.begin(); it != pdu->segments.end(); it++) { log->debug(" Handling %d PDU segments\n", it->header.N_li); - for(uint32_t i=0; iheader.N_li; i++) { + for (uint32_t i = 0; i < it->header.N_li; i++) { header.li[header.N_li] = it->header.li[i]; if (i == 0) { header.li[header.N_li] += carryover; } - log->debug(" - adding segment %d/%d (%d B, SO=%d, carryover=%d, count=%d)\n", i+1, it->header.N_li, header.li[header.N_li], header.so, carryover, count); + log->debug(" - adding segment %d/%d (%d B, SO=%d, carryover=%d, count=%d)\n", + i + 1, + it->header.N_li, + header.li[header.N_li], + header.so, + carryover, + count); header.N_li++; count += it->header.li[i]; carryover = 0; @@ -1729,16 +1760,23 @@ bool rlc_am_lte::rlc_am_lte_rx::add_segment_and_check(rlc_amd_rx_pdu_segments_t* if (count <= it->buf->N_bytes) { carryover += it->buf->N_bytes - count; - log->debug("Incremented carryover (it->buf->N_bytes=%d, count=%d). New carryover=%d\n", it->buf->N_bytes, count, carryover); + log->debug("Incremented carryover (it->buf->N_bytes=%d, count=%d). New carryover=%d\n", + it->buf->N_bytes, + count, + carryover); } else { // Next segment would be too long, recalculate carryover header.N_li--; carryover = it->buf->N_bytes - (count - header.li[header.N_li]); - log->debug("Recalculated carryover=%d (it->buf->N_bytes=%d, count=%d, header.li[header.N_li]=%d)\n", carryover, it->buf->N_bytes, count, header.li[header.N_li]); + log->debug("Recalculated carryover=%d (it->buf->N_bytes=%d, count=%d, header.li[header.N_li]=%d)\n", + carryover, + it->buf->N_bytes, + count, + header.li[header.N_li]); } tmpit = it; - if(rlc_am_end_aligned(it->header.fi) && ++tmpit != pdu->segments.end()) { + if (rlc_am_end_aligned(it->header.fi) && ++tmpit != pdu->segments.end()) { log->debug("Header is end-aligned, overwrite header.li[%d]=%d\n", header.N_li, carryover); header.li[header.N_li] = carryover; header.N_li++; @@ -1760,7 +1798,7 @@ bool rlc_am_lte::rlc_am_lte_rx::add_segment_and_check(rlc_amd_rx_pdu_segments_t* return false; #endif } - for(it = pdu->segments.begin(); it != pdu->segments.end(); it++) { + for (it = pdu->segments.begin(); it != pdu->segments.end(); it++) { memcpy(&full_pdu->msg[full_pdu->N_bytes], it->buf->msg, it->buf->N_bytes); full_pdu->N_bytes += it->buf->N_bytes; } @@ -1780,186 +1818,171 @@ bool rlc_am_lte::rlc_am_lte_rx::inside_rx_window(const int16_t sn) void rlc_am_lte::rlc_am_lte_rx::debug_state() { - log->debug("%s vr_r = %d, vr_mr = %d, vr_x = %d, vr_ms = %d, vr_h = %d\n", - RB_NAME, vr_r, vr_mr, vr_x, vr_ms, vr_h); + log->debug("%s vr_r = %d, vr_mr = %d, vr_x = %d, vr_ms = %d, vr_h = %d\n", RB_NAME, vr_r, vr_mr, vr_x, vr_ms, vr_h); } - /**************************************************************************** * Header pack/unpack helper functions * Ref: 3GPP TS 36.322 v10.0.0 Section 6.2.1 ***************************************************************************/ // Read header from pdu struct, don't strip header -void rlc_am_read_data_pdu_header(byte_buffer_t *pdu, rlc_amd_pdu_header_t *header) +void rlc_am_read_data_pdu_header(byte_buffer_t* pdu, rlc_amd_pdu_header_t* header) { - uint8_t *ptr = pdu->msg; + uint8_t* ptr = pdu->msg; uint32_t n = 0; rlc_am_read_data_pdu_header(&ptr, &n, header); } // Read header from raw pointer, strip header -void rlc_am_read_data_pdu_header(uint8_t **payload, uint32_t *nof_bytes, rlc_amd_pdu_header_t *header) +void rlc_am_read_data_pdu_header(uint8_t** payload, uint32_t* nof_bytes, rlc_amd_pdu_header_t* header) { uint8_t ext; - uint8_t *ptr = *payload; + uint8_t* ptr = *payload; header->dc = static_cast((*ptr >> 7) & 0x01); - if(RLC_DC_FIELD_DATA_PDU == header->dc) - { + if (RLC_DC_FIELD_DATA_PDU == header->dc) { // Fixed part - header->rf = ((*ptr >> 6) & 0x01); - header->p = ((*ptr >> 5) & 0x01); + header->rf = ((*ptr >> 6) & 0x01); + header->p = ((*ptr >> 5) & 0x01); header->fi = static_cast((*ptr >> 3) & 0x03); - ext = ((*ptr >> 2) & 0x01); - header->sn = (*ptr & 0x03) << 8; // 2 bits SN + ext = ((*ptr >> 2) & 0x01); + header->sn = (*ptr & 0x03) << 8; // 2 bits SN ptr++; - header->sn |= (*ptr & 0xFF); // 8 bits SN + header->sn |= (*ptr & 0xFF); // 8 bits SN ptr++; - if(header->rf) - { + if (header->rf) { header->lsf = ((*ptr >> 7) & 0x01); header->so = (*ptr & 0x7F) << 8; // 7 bits of SO ptr++; - header->so |= (*ptr & 0xFF); // 8 bits of SO + header->so |= (*ptr & 0xFF); // 8 bits of SO ptr++; } // Extension part header->N_li = 0; - while(ext) - { - if(header->N_li%2 == 0) - { - ext = ((*ptr >> 7) & 0x01); - header->li[header->N_li] = (*ptr & 0x7F) << 4; // 7 bits of LI + while (ext) { + if (header->N_li % 2 == 0) { + ext = ((*ptr >> 7) & 0x01); + header->li[header->N_li] = (*ptr & 0x7F) << 4; // 7 bits of LI ptr++; header->li[header->N_li] |= (*ptr & 0xF0) >> 4; // 4 bits of LI header->N_li++; - } - else - { - ext = (*ptr >> 3) & 0x01; + } else { + ext = (*ptr >> 3) & 0x01; header->li[header->N_li] = (*ptr & 0x07) << 8; // 3 bits of LI ptr++; - header->li[header->N_li] |= (*ptr & 0xFF); // 8 bits of LI + header->li[header->N_li] |= (*ptr & 0xFF); // 8 bits of LI header->N_li++; ptr++; } } // Account for padding if N_li is odd - if (header->N_li%2 == 1) { + if (header->N_li % 2 == 1) { ptr++; } - *nof_bytes -= ptr-*payload; - *payload = ptr; + *nof_bytes -= ptr - *payload; + *payload = ptr; } } // Write header to pdu struct -void rlc_am_write_data_pdu_header(rlc_amd_pdu_header_t *header, byte_buffer_t *pdu) +void rlc_am_write_data_pdu_header(rlc_amd_pdu_header_t* header, byte_buffer_t* pdu) { - uint8_t *ptr = pdu->msg; + uint8_t* ptr = pdu->msg; rlc_am_write_data_pdu_header(header, &ptr); pdu->N_bytes += ptr - pdu->msg; } // Write header to pointer & move pointer -void rlc_am_write_data_pdu_header(rlc_amd_pdu_header_t *header, uint8_t **payload) +void rlc_am_write_data_pdu_header(rlc_amd_pdu_header_t* header, uint8_t** payload) { uint32_t i; - uint8_t ext = (header->N_li > 0) ? 1 : 0; + uint8_t ext = (header->N_li > 0) ? 1 : 0; - uint8_t *ptr = *payload; + uint8_t* ptr = *payload; // Fixed part - *ptr = (header->dc & 0x01) << 7; + *ptr = (header->dc & 0x01) << 7; *ptr |= (header->rf & 0x01) << 6; - *ptr |= (header->p & 0x01) << 5; + *ptr |= (header->p & 0x01) << 5; *ptr |= (header->fi & 0x03) << 3; - *ptr |= (ext & 0x01) << 2; + *ptr |= (ext & 0x01) << 2; *ptr |= (header->sn & 0x300) >> 8; // 2 bits SN ptr++; - *ptr = (header->sn & 0xFF); // 8 bits SN + *ptr = (header->sn & 0xFF); // 8 bits SN ptr++; // Segment part - if (header->rf) - { - *ptr = (header->lsf & 0x01) << 7; - *ptr |= (header->so & 0x7F00) >> 8; // 7 bits of SO + if (header->rf) { + *ptr = (header->lsf & 0x01) << 7; + *ptr |= (header->so & 0x7F00) >> 8; // 7 bits of SO ptr++; - *ptr = (header->so & 0x00FF); // 8 bits of SO + *ptr = (header->so & 0x00FF); // 8 bits of SO ptr++; } // Extension part i = 0; - while(i < header->N_li) - { - ext = ((i+1) == header->N_li) ? 0 : 1; - *ptr = (ext & 0x01) << 7; // 1 bit header + while (i < header->N_li) { + ext = ((i + 1) == header->N_li) ? 0 : 1; + *ptr = (ext & 0x01) << 7; // 1 bit header *ptr |= (header->li[i] & 0x7F0) >> 4; // 7 bits of LI ptr++; - *ptr = (header->li[i] & 0x00F) << 4; // 4 bits of LI + *ptr = (header->li[i] & 0x00F) << 4; // 4 bits of LI i++; - if(i < header->N_li) - { - ext = ((i+1) == header->N_li) ? 0 : 1; - *ptr |= (ext & 0x01) << 3; // 1 bit header + if (i < header->N_li) { + ext = ((i + 1) == header->N_li) ? 0 : 1; + *ptr |= (ext & 0x01) << 3; // 1 bit header *ptr |= (header->li[i] & 0x700) >> 8; // 3 bits of LI ptr++; - *ptr = (header->li[i] & 0x0FF); // 8 bits of LI + *ptr = (header->li[i] & 0x0FF); // 8 bits of LI ptr++; i++; } } // Pad if N_li is odd - if (header->N_li%2 == 1) { + if (header->N_li % 2 == 1) { ptr++; } *payload = ptr; } -void rlc_am_read_status_pdu(byte_buffer_t *pdu, rlc_status_pdu_t *status) +void rlc_am_read_status_pdu(byte_buffer_t* pdu, rlc_status_pdu_t* status) { rlc_am_read_status_pdu(pdu->msg, pdu->N_bytes, status); } -void rlc_am_read_status_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_status_pdu_t *status) +void rlc_am_read_status_pdu(uint8_t* payload, uint32_t nof_bytes, rlc_status_pdu_t* status) { - uint32_t i; - uint8_t ext1, ext2; + uint32_t i; + uint8_t ext1, ext2; bit_buffer_t tmp; - uint8_t *ptr = tmp.msg; + uint8_t* ptr = tmp.msg; - srslte_bit_unpack_vector(payload, tmp.msg, nof_bytes*8); - tmp.N_bits = nof_bytes*8; + srslte_bit_unpack_vector(payload, tmp.msg, nof_bytes * 8); + tmp.N_bits = nof_bytes * 8; rlc_dc_field_t dc = static_cast(srslte_bit_pack(&ptr, 1)); - if(RLC_DC_FIELD_CONTROL_PDU == dc) - { + if (RLC_DC_FIELD_CONTROL_PDU == dc) { uint8_t cpt = srslte_bit_pack(&ptr, 3); // 3-bit Control PDU Type (0 == status) - if(0 == cpt) - { - status->ack_sn = srslte_bit_pack(&ptr, 10); // 10 bits ACK_SN - ext1 = srslte_bit_pack(&ptr, 1); // 1 bits E1 - status->N_nack = 0; - while(ext1) - { + if (0 == cpt) { + status->ack_sn = srslte_bit_pack(&ptr, 10); // 10 bits ACK_SN + ext1 = srslte_bit_pack(&ptr, 1); // 1 bits E1 + status->N_nack = 0; + while (ext1) { status->nacks[status->N_nack].nack_sn = srslte_bit_pack(&ptr, 10); - ext1 = srslte_bit_pack(&ptr, 1); // 1 bits E1 - ext2 = srslte_bit_pack(&ptr, 1); // 1 bits E2 - if(ext2) - { - status->nacks[status->N_nack].has_so = true; + ext1 = srslte_bit_pack(&ptr, 1); // 1 bits E1 + ext2 = srslte_bit_pack(&ptr, 1); // 1 bits E2 + if (ext2) { + status->nacks[status->N_nack].has_so = true; status->nacks[status->N_nack].so_start = srslte_bit_pack(&ptr, 15); status->nacks[status->N_nack].so_end = srslte_bit_pack(&ptr, 15); } @@ -1969,46 +1992,45 @@ void rlc_am_read_status_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_status_pdu } } -void rlc_am_write_status_pdu(rlc_status_pdu_t *status, byte_buffer_t *pdu ) +void rlc_am_write_status_pdu(rlc_status_pdu_t* status, byte_buffer_t* pdu) { pdu->N_bytes = rlc_am_write_status_pdu(status, pdu->msg); } -int rlc_am_write_status_pdu(rlc_status_pdu_t *status, uint8_t *payload) +int rlc_am_write_status_pdu(rlc_status_pdu_t* status, uint8_t* payload) { - uint32_t i; - uint8_t ext1; + uint32_t i; + uint8_t ext1; bit_buffer_t tmp; - uint8_t *ptr = tmp.msg; + uint8_t* ptr = tmp.msg; - srslte_bit_unpack(RLC_DC_FIELD_CONTROL_PDU, &ptr, 1); // D/C - srslte_bit_unpack(0, &ptr, 3); // CPT (0 == STATUS) - srslte_bit_unpack(status->ack_sn, &ptr, 10); // 10 bit ACK_SN + srslte_bit_unpack(RLC_DC_FIELD_CONTROL_PDU, &ptr, 1); // D/C + srslte_bit_unpack(0, &ptr, 3); // CPT (0 == STATUS) + srslte_bit_unpack(status->ack_sn, &ptr, 10); // 10 bit ACK_SN ext1 = (status->N_nack == 0) ? 0 : 1; - srslte_bit_unpack(ext1, &ptr, 1); // E1 - for(i=0;iN_nack;i++) - { + srslte_bit_unpack(ext1, &ptr, 1); // E1 + for (i = 0; i < status->N_nack; i++) { srslte_bit_unpack(status->nacks[i].nack_sn, &ptr, 10); // 10 bit NACK_SN - ext1 = ((status->N_nack-1) == i) ? 0 : 1; - srslte_bit_unpack(ext1, &ptr, 1); // E1 - if(status->nacks[i].has_so) { - srslte_bit_unpack(1 , &ptr, 1); // E2 - srslte_bit_unpack(status->nacks[i].so_start , &ptr, 15); - srslte_bit_unpack(status->nacks[i].so_end , &ptr, 15); - }else{ - srslte_bit_unpack(0 , &ptr, 1); // E2 + ext1 = ((status->N_nack - 1) == i) ? 0 : 1; + srslte_bit_unpack(ext1, &ptr, 1); // E1 + if (status->nacks[i].has_so) { + srslte_bit_unpack(1, &ptr, 1); // E2 + srslte_bit_unpack(status->nacks[i].so_start, &ptr, 15); + srslte_bit_unpack(status->nacks[i].so_end, &ptr, 15); + } else { + srslte_bit_unpack(0, &ptr, 1); // E2 } } // Pad - tmp.N_bits = ptr - tmp.msg; - uint8_t n_pad = 8 - (tmp.N_bits%8); + tmp.N_bits = ptr - tmp.msg; + uint8_t n_pad = 8 - (tmp.N_bits % 8); srslte_bit_unpack(0, &ptr, n_pad); tmp.N_bits = ptr - tmp.msg; // Pack bits srslte_bit_pack_vector(tmp.msg, payload, tmp.N_bits); - return tmp.N_bits/8; + return tmp.N_bits / 8; } bool rlc_am_is_valid_status_pdu(const rlc_status_pdu_t& status) @@ -2021,49 +2043,47 @@ bool rlc_am_is_valid_status_pdu(const rlc_status_pdu_t& status) return true; } -uint32_t rlc_am_packed_length(rlc_amd_pdu_header_t *header) +uint32_t rlc_am_packed_length(rlc_amd_pdu_header_t* header) { - uint32_t len = 2; // Fixed part is 2 bytes + uint32_t len = 2; // Fixed part is 2 bytes if (header->rf) { len += 2; // Segment header is 2 bytes } - len += header->N_li * 1.5 + 0.5; // Extension part - integer rounding up + len += header->N_li * 1.5 + 0.5; // Extension part - integer rounding up return len; } -uint32_t rlc_am_packed_length(rlc_status_pdu_t *status) +uint32_t rlc_am_packed_length(rlc_status_pdu_t* status) { - uint32_t len_bits = 15; // Fixed part is 15 bits + uint32_t len_bits = 15; // Fixed part is 15 bits for (uint32_t i = 0; i < status->N_nack; i++) { - if(status->nacks[i].has_so) { - len_bits += 42; // 10 bits SN, 2 bits ext, 15 bits so_start, 15 bits so_end - }else{ - len_bits += 12; // 10 bits SN, 2 bits ext + if (status->nacks[i].has_so) { + len_bits += 42; // 10 bits SN, 2 bits ext, 15 bits so_start, 15 bits so_end + } else { + len_bits += 12; // 10 bits SN, 2 bits ext } } - return (len_bits+7)/8; // Convert to bytes - integer rounding up + return (len_bits + 7) / 8; // Convert to bytes - integer rounding up } -bool rlc_am_is_pdu_segment(uint8_t *payload) +bool rlc_am_is_pdu_segment(uint8_t* payload) { return ((*(payload) >> 6) & 0x01) == 1; } -std::string rlc_am_status_pdu_to_string(rlc_status_pdu_t *status) +std::string rlc_am_status_pdu_to_string(rlc_status_pdu_t* status) { std::stringstream ss; ss << "ACK_SN = " << status->ack_sn; ss << ", N_nack = " << status->N_nack; - if(status->N_nack > 0) - { + if (status->N_nack > 0) { ss << ", NACK_SN = "; - for(uint32_t i=0; iN_nack; i++) - { - if(status->nacks[i].has_so) { - ss << "[" << status->nacks[i].nack_sn << " " << status->nacks[i].so_start \ - << ":" << status->nacks[i].so_end << "]"; - }else{ + for (uint32_t i = 0; i < status->N_nack; i++) { + if (status->nacks[i].has_so) { + ss << "[" << status->nacks[i].nack_sn << " " << status->nacks[i].so_start << ":" << status->nacks[i].so_end + << "]"; + } else { ss << "[" << status->nacks[i].nack_sn << "]"; } } @@ -2071,15 +2091,15 @@ std::string rlc_am_status_pdu_to_string(rlc_status_pdu_t *status) return ss.str(); } -std::string rlc_amd_pdu_header_to_string(const rlc_amd_pdu_header_t &header) +std::string rlc_amd_pdu_header_to_string(const rlc_amd_pdu_header_t& header) { std::stringstream ss; ss << "[" << rlc_dc_field_text[header.dc]; - ss << ", RF=" << (header.rf ? "1":"0"); - ss << ", P=" << (header.p ? "1":"0"); - ss << ", FI=" << (header.fi ? "1":"0"); + ss << ", RF=" << (header.rf ? "1" : "0"); + ss << ", P=" << (header.p ? "1" : "0"); + ss << ", FI=" << (header.fi ? "1" : "0"); ss << ", SN=" << header.sn; - ss << ", LSF=" << (header.lsf ? "1":"0"); + ss << ", LSF=" << (header.lsf ? "1" : "0"); ss << ", SO=" << header.so; ss << ", N_li=" << header.N_li; if (header.N_li > 0) { diff --git a/lib/src/upper/rlc_tm.cc b/lib/src/upper/rlc_tm.cc index fa89858a2..1919990b9 100644 --- a/lib/src/upper/rlc_tm.cc +++ b/lib/src/upper/rlc_tm.cc @@ -39,7 +39,8 @@ rlc_tm::rlc_tm(srslte::log* log_, } // Warning: must call stop() to properly deallocate all buffers -rlc_tm::~rlc_tm() { +rlc_tm::~rlc_tm() +{ pool = NULL; } @@ -58,7 +59,8 @@ void rlc_tm::empty_queue() ul_queue.reset(); } -void rlc_tm::reestablish() { +void rlc_tm::reestablish() +{ stop(); tx_enabled = true; } @@ -87,12 +89,16 @@ void rlc_tm::write_sdu(unique_byte_buffer_t sdu, bool blocking) } if (sdu) { if (blocking) { - log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU, queue size=%d, bytes=%d", - rrc->get_rb_name(lcid).c_str(), ul_queue.size(), ul_queue.size_bytes()); + log->info_hex(sdu->msg, + sdu->N_bytes, + "%s Tx SDU, queue size=%d, bytes=%d", + rrc->get_rb_name(lcid).c_str(), + ul_queue.size(), + ul_queue.size_bytes()); ul_queue.write(std::move(sdu)); } else { - uint8_t* msg_ptr = sdu->msg; - uint32_t nof_bytes = sdu->N_bytes; + uint8_t* msg_ptr = sdu->msg; + uint32_t nof_bytes = sdu->N_bytes; std::pair ret = ul_queue.try_write(std::move(sdu)); if (ret.first) { log->info_hex(msg_ptr, @@ -144,11 +150,12 @@ void rlc_tm::reset_metrics() metrics = {}; } -int rlc_tm::read_pdu(uint8_t *payload, uint32_t nof_bytes) +int rlc_tm::read_pdu(uint8_t* payload, uint32_t nof_bytes) { uint32_t pdu_size = ul_queue.size_tail_bytes(); if (pdu_size > nof_bytes) { - log->error("TX %s PDU size larger than MAC opportunity (%d > %d)\n", rrc->get_rb_name(lcid).c_str(), pdu_size, nof_bytes); + log->error( + "TX %s PDU size larger than MAC opportunity (%d > %d)\n", rrc->get_rb_name(lcid).c_str(), pdu_size, nof_bytes); return -1; } unique_byte_buffer_t buf; @@ -156,7 +163,8 @@ int rlc_tm::read_pdu(uint8_t *payload, uint32_t nof_bytes) pdu_size = buf->N_bytes; memcpy(payload, buf->msg, buf->N_bytes); log->debug("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", - rrc->get_rb_name(lcid).c_str(), buf->get_latency_us()); + rrc->get_rb_name(lcid).c_str(), + buf->get_latency_us()); log->info_hex(payload, pdu_size, "TX %s, %s PDU, queue size=%d, bytes=%d", @@ -177,7 +185,7 @@ int rlc_tm::read_pdu(uint8_t *payload, uint32_t nof_bytes) } } -void rlc_tm::write_pdu(uint8_t *payload, uint32_t nof_bytes) +void rlc_tm::write_pdu(uint8_t* payload, uint32_t nof_bytes) { unique_byte_buffer_t buf = allocate_unique_buffer(*pool); if (buf) { diff --git a/lib/src/upper/rlc_um_base.cc b/lib/src/upper/rlc_um_base.cc index 73473b49a..fbe5f1430 100644 --- a/lib/src/upper/rlc_um_base.cc +++ b/lib/src/upper/rlc_um_base.cc @@ -31,7 +31,12 @@ rlc_um_base::rlc_um_base(srslte::log* log_, srsue::pdcp_interface_rlc* pdcp_, srsue::rrc_interface_rlc* rrc_, srslte::timer_handler* timers_) : - log(log_), lcid(lcid_), pdcp(pdcp_), rrc(rrc_), timers(timers_), pool(byte_buffer_pool::get_instance()) + log(log_), + lcid(lcid_), + pdcp(pdcp_), + rrc(rrc_), + timers(timers_), + pool(byte_buffer_pool::get_instance()) { } diff --git a/lib/src/upper/rlc_um_lte.cc b/lib/src/upper/rlc_um_lte.cc index b1f47603e..f148bd251 100644 --- a/lib/src/upper/rlc_um_lte.cc +++ b/lib/src/upper/rlc_um_lte.cc @@ -32,7 +32,7 @@ rlc_um_lte::rlc_um_lte(srslte::log* log_, uint32_t lcid_, srsue::pdcp_interface_rlc* pdcp_, srsue::rrc_interface_rlc* rrc_, - srslte::timer_handler* timers_) : + srslte::timer_handler* timers_) : rlc_um_base(log_, lcid_, pdcp_, rrc_, timers_) { } @@ -115,7 +115,7 @@ bool rlc_um_lte::rlc_um_lte_tx::configure(rlc_config_t cnfg_, std::string rb_nam tx_sdu_queue.resize(cnfg_.tx_queue_length); - rb_name = rb_name_; + rb_name = rb_name_; return true; } @@ -220,13 +220,13 @@ void rlc_um_lte::rlc_um_lte_tx::debug_state() * Rx subclass implementation ***************************************************************************/ -rlc_um_lte::rlc_um_lte_rx::rlc_um_lte_rx(rlc_um_base* parent_) : rlc_um_base_rx(parent_), reordering_timer(timers->get_unique_timer()) +rlc_um_lte::rlc_um_lte_rx::rlc_um_lte_rx(rlc_um_base* parent_) : + rlc_um_base_rx(parent_), + reordering_timer(timers->get_unique_timer()) { } -rlc_um_lte::rlc_um_lte_rx::~rlc_um_lte_rx() -{ -} +rlc_um_lte::rlc_um_lte_rx::~rlc_um_lte_rx() {} bool rlc_um_lte::rlc_um_lte_rx::configure() { diff --git a/lib/src/upper/rlc_um_nr.cc b/lib/src/upper/rlc_um_nr.cc index 09f4c6986..4284fb28c 100644 --- a/lib/src/upper/rlc_um_nr.cc +++ b/lib/src/upper/rlc_um_nr.cc @@ -112,7 +112,7 @@ bool rlc_um_nr::rlc_um_nr_tx::configure(rlc_config_t cnfg_, std::string rb_name_ tx_sdu_queue.resize(cnfg_.tx_queue_length); - rb_name = rb_name_; + rb_name = rb_name_; return true; } @@ -190,8 +190,8 @@ int rlc_um_nr::rlc_um_nr_tx::build_data_pdu(unique_byte_buffer_t pdu, uint8_t* p // Update SN if needed if (header.si == rlc_nr_si_field_t::last_segment) { - TX_Next = (TX_Next + 1) % cfg.um_nr.mod; - next_so = 0; + TX_Next = (TX_Next + 1) % cfg.um_nr.mod; + next_so = 0; } // Add header and TX @@ -216,7 +216,8 @@ void rlc_um_nr::rlc_um_nr_tx::debug_state() ***************************************************************************/ rlc_um_nr::rlc_um_nr_rx::rlc_um_nr_rx(rlc_um_base* parent_) : - rlc_um_base_rx(parent_), reassembly_timer(timers->get_unique_timer()) + rlc_um_base_rx(parent_), + reassembly_timer(timers->get_unique_timer()) { } diff --git a/lib/test/asn1/s1ap_test.cc b/lib/test/asn1/s1ap_test.cc index 217c5b43c..2a8261e3f 100644 --- a/lib/test/asn1/s1ap_test.cc +++ b/lib/test/asn1/s1ap_test.cc @@ -24,30 +24,28 @@ #include #include -void unpack_test_served_gummeis_with_multiple_plmns() { +void unpack_test_served_gummeis_with_multiple_plmns() +{ srslte::log_filter log1("Log"); log1.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(1024); LIBLTE_S1AP_S1AP_PDU_STRUCT compare_pdu; LIBLTE_S1AP_S1AP_PDU_STRUCT output_pdu; - LIBLTE_BYTE_MSG_STRUCT input_pdu; + LIBLTE_BYTE_MSG_STRUCT input_pdu; - uint8_t pdu[] = {0x20, 0x11, 0x00, 0x26, 0x00, 0x00, 0x02, 0x00, 0x69, - 0x00, 0x1a, 0x01, 0x40, 0x00, 0xf1, 0x10, 0x00, 0xf1, - 0x10, 0x00, 0xf1, 0x10, 0x00, 0xf1, 0x10, 0x00, 0xf1, - 0x10, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x88, 0x88, 0x00, - 0x7b, 0x00, 0x57, 0x40, 0x01, 0xff}; + uint8_t pdu[] = {0x20, 0x11, 0x00, 0x26, 0x00, 0x00, 0x02, 0x00, 0x69, 0x00, 0x1a, 0x01, 0x40, 0x00, + 0xf1, 0x10, 0x00, 0xf1, 0x10, 0x00, 0xf1, 0x10, 0x00, 0xf1, 0x10, 0x00, 0xf1, 0x10, + 0x00, 0xf1, 0x10, 0x00, 0x00, 0x88, 0x88, 0x00, 0x7b, 0x00, 0x57, 0x40, 0x01, 0xff}; input_pdu.N_bytes = sizeof(pdu); memcpy(&input_pdu.msg, pdu, sizeof(pdu)); - log1.debug_hex(input_pdu.msg, input_pdu.N_bytes, "Input message len = %d", - input_pdu.N_bytes); - assert(liblte_s1ap_unpack_s1ap_pdu((LIBLTE_BYTE_MSG_STRUCT *)&input_pdu, - &output_pdu) == LIBLTE_SUCCESS); + log1.debug_hex(input_pdu.msg, input_pdu.N_bytes, "Input message len = %d", input_pdu.N_bytes); + assert(liblte_s1ap_unpack_s1ap_pdu((LIBLTE_BYTE_MSG_STRUCT*)&input_pdu, &output_pdu) == LIBLTE_SUCCESS); } -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ unpack_test_served_gummeis_with_multiple_plmns(); } diff --git a/lib/test/asn1/srslte_asn1_m2ap_test.cc b/lib/test/asn1/srslte_asn1_m2ap_test.cc index 51093709a..8d45554e4 100644 --- a/lib/test/asn1/srslte_asn1_m2ap_test.cc +++ b/lib/test/asn1/srslte_asn1_m2ap_test.cc @@ -44,7 +44,7 @@ int m2_setup_request_test() std::unique_ptr m2ap_pdu(new LIBLTE_M2AP_M2AP_PDU_STRUCT); uint32_t m2ap_message_len = 59; - uint8_t m2ap_message[] = {0x00, 0x05, 0x00, 0x37, 0x00, 0x00, 0x03, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x00, 0xf1, 0x10, + uint8_t m2ap_message[] = {0x00, 0x05, 0x00, 0x37, 0x00, 0x00, 0x03, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x00, 0xf1, 0x10, 0x00, 0x1a, 0x2d, 0x00, 0x00, 0x0e, 0x40, 0x0a, 0x03, 0x80, 0x65, 0x6e, 0x62, 0x31, 0x61, 0x32, 0x64, 0x30, 0x00, 0x0f, 0x00, 0x16, 0x00, 0x00, 0x10, 0x00, 0x11, 0x00, 0x00, 0xf1, 0x10, 0x1a, 0x2d, 0x00, 0x10, 0x27, 0x10, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x02}; @@ -60,22 +60,23 @@ int m2_setup_request_test() LIBLTE_M2AP_INITIATINGMESSAGE_STRUCT* in_msg = &m2ap_pdu->choice.initiatingMessage; TESTASSERT(in_msg->choice_type == LIBLTE_M2AP_INITIATINGMESSAGE_CHOICE_M2SETUPREQUEST); - LIBLTE_M2AP_MESSAGE_M2SETUPREQUEST_STRUCT *m2_setup = &in_msg->choice.M2SetupRequest; + LIBLTE_M2AP_MESSAGE_M2SETUPREQUEST_STRUCT* m2_setup = &in_msg->choice.M2SetupRequest; TESTASSERT(m2_setup->ext == false); /*Global eNB-Id*/ // PLMN Identity (MCC = 001 , MNC = 01) - uint8_t *plmn_id = m2_setup->Global_ENB_ID.pLMNidentity.buffer; + uint8_t* plmn_id = m2_setup->Global_ENB_ID.pLMNidentity.buffer; TESTASSERT((plmn_id[0] & 0x0F) == 0 && (plmn_id[0] & 0xF0) >> 4 == 0 && (plmn_id[1] & 0x0F) == 1); // MCC TESTASSERT((plmn_id[1] & 0xF0) >> 4 == 0xF && (plmn_id[2] & 0x0F) == 0 && (plmn_id[2] & 0xF0) >> 4 == 1); // MNC // eNB Identity - uint8_t enb_id_bits[32]; + uint8_t enb_id_bits[32]; uint32_t enb_id; bzero(enb_id_bits, sizeof(enb_id_bits)); - memcpy(&enb_id_bits[32 - LIBLTE_M2AP_ENBID_BIT_STRING_LEN], m2_setup->Global_ENB_ID.eNB_ID.buffer, + memcpy(&enb_id_bits[32 - LIBLTE_M2AP_ENBID_BIT_STRING_LEN], + m2_setup->Global_ENB_ID.eNB_ID.buffer, LIBLTE_M2AP_ENBID_BIT_STRING_LEN); - liblte_pack(enb_id_bits, 32, (uint8_t *)&enb_id); + liblte_pack(enb_id_bits, 32, (uint8_t*)&enb_id); enb_id = ntohl(enb_id); TESTASSERT(enb_id == 0x1a2d0); @@ -88,7 +89,7 @@ int m2_setup_request_test() TESTASSERT(m2_setup->configurationDataList.len == 1); // eNB MBMS Configuration Data Item - LIBLTE_M2AP_ENB_MBMS_CONFIGURATION_DATA_ITEM_STRUCT *conf_item = &m2_setup->configurationDataList.buffer[0]; + LIBLTE_M2AP_ENB_MBMS_CONFIGURATION_DATA_ITEM_STRUCT* conf_item = &m2_setup->configurationDataList.buffer[0]; // eCGI plmn_id = conf_item->eCGI.pLMN_Identity.buffer; @@ -134,7 +135,7 @@ int m2_setup_response_test() std::unique_ptr m2ap_pdu(new LIBLTE_M2AP_M2AP_PDU_STRUCT); uint32_t m2ap_message_len = 40; - uint8_t m2ap_message[] = {0x20, 0x05, 0x00, 0x24, 0x00, 0x00, 0x02, 0x00, 0x11, 0x00, 0x06, 0x00, 0x00, 0xf1, + uint8_t m2ap_message[] = {0x20, 0x05, 0x00, 0x24, 0x00, 0x00, 0x02, 0x00, 0x11, 0x00, 0x06, 0x00, 0x00, 0xf1, 0x10, 0x00, 0x50, 0x00, 0x13, 0x00, 0x13, 0x00, 0x00, 0x14, 0x00, 0x0e, 0x40, 0x01, 0x50, 0x40, 0x00, 0x00, 0x00, 0x00, 0xf1, 0x10, 0x1a, 0x2d, 0x00, 0x14}; @@ -149,12 +150,12 @@ int m2_setup_response_test() LIBLTE_M2AP_SUCCESSFULOUTCOME_STRUCT* succ_out = &m2ap_pdu->choice.successfulOutcome; TESTASSERT(succ_out->choice_type == LIBLTE_M2AP_SUCCESSFULOUTCOME_CHOICE_M2SETUPRESPONSE); - LIBLTE_M2AP_MESSAGE_M2SETUPRESPONSE_STRUCT *m2_setup = &succ_out->choice.M2SetupResponse; + LIBLTE_M2AP_MESSAGE_M2SETUPRESPONSE_STRUCT* m2_setup = &succ_out->choice.M2SetupResponse; TESTASSERT(m2_setup->ext == false); /*Global MCE-Id*/ // PLMN Identity (MCC = 001 , MNC = 01) - uint8_t *plmn_id = m2_setup->Global_MCE_ID.pLMN_Identity.buffer; + uint8_t* plmn_id = m2_setup->Global_MCE_ID.pLMN_Identity.buffer; TESTASSERT((plmn_id[0] & 0x0F) == 0 && (plmn_id[0] & 0xF0) >> 4 == 0 && (plmn_id[1] & 0x0F) == 1); // MCC TESTASSERT((plmn_id[1] & 0xF0) >> 4 == 0xF && (plmn_id[2] & 0x0F) == 0 && (plmn_id[2] & 0xF0) >> 4 == 1); // MNC @@ -172,7 +173,7 @@ int m2_setup_response_test() TESTASSERT(m2_setup->MCCHrelatedBCCHConfigPerMBSFNArea.len == 1); // MCCH Related BCCH Config Per MBSFN Area Configuration Item - LIBLTE_M2AP_MCCH_RELATED_BCCH_CONFIG_PER_MBSFN_AREA_ITEM_STRUCT *conf_item = + LIBLTE_M2AP_MCCH_RELATED_BCCH_CONFIG_PER_MBSFN_AREA_ITEM_STRUCT* conf_item = &m2_setup->MCCHrelatedBCCHConfigPerMBSFNArea.buffer[0]; // MBSFN Area @@ -207,7 +208,7 @@ int m2_setup_response_test() TESTASSERT(conf_item->cellInformationList.len == 1); /*Cell Information*/ - LIBLTE_M2AP_CELL_INFORMATION_STRUCT *cell_info = &conf_item->cellInformationList.buffer[0]; + LIBLTE_M2AP_CELL_INFORMATION_STRUCT* cell_info = &conf_item->cellInformationList.buffer[0]; // eCGI plmn_id = cell_info->eCGI.pLMN_Identity.buffer; @@ -243,7 +244,7 @@ int mbms_session_start_request_test() std::unique_ptr m2ap_pdu(new LIBLTE_M2AP_M2AP_PDU_STRUCT); uint32_t m2ap_message_len = 49; - uint8_t m2ap_message[] = {0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + uint8_t m2ap_message[] = {0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x07, 0x00, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x03, 0x02, 0x00, 0x01, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x7f, 0x00, 0x02, 0x01, 0x00, 0x7f, 0x00, 0x01, 0xc8, 0x00, 0x00, 0x00, 0x01}; @@ -259,13 +260,13 @@ int mbms_session_start_request_test() LIBLTE_M2AP_INITIATINGMESSAGE_STRUCT* in_msg = &m2ap_pdu->choice.initiatingMessage; TESTASSERT(in_msg->choice_type == LIBLTE_M2AP_INITIATINGMESSAGE_CHOICE_MBMSSESSIONSTARTREQUEST); - LIBLTE_M2AP_MESSAGE_MBMSSESSIONSTARTREQUEST_STRUCT *mbms_sess = &in_msg->choice.MbmsSessionStartRequest; + LIBLTE_M2AP_MESSAGE_MBMSSESSIONSTARTREQUEST_STRUCT* mbms_sess = &in_msg->choice.MbmsSessionStartRequest; /*ProtocolIE MCE-MBMS-M2AP-ID*/ TESTASSERT(mbms_sess->MceMbmsM2apId.mce_mbms_m2ap_id == 0); /*ProtocolIE TMGI*/ - uint8_t *plmn_id = mbms_sess->Tmgi.pLMN_Identity.buffer; + uint8_t* plmn_id = mbms_sess->Tmgi.pLMN_Identity.buffer; TESTASSERT((plmn_id[0] & 0x0F) == 0 && (plmn_id[0] & 0xF0) >> 4 == 0 && (plmn_id[1] & 0x0F) == 1); // MCC TESTASSERT((plmn_id[1] & 0xF0) >> 4 == 0xF && (plmn_id[2] & 0x0F) == 0 && (plmn_id[2] & 0xF0) >> 4 == 1); // MNC TESTASSERT(mbms_sess->Tmgi.serviceID.buffer[0] == 0); @@ -318,8 +319,8 @@ int mbms_session_start_response_test() std::unique_ptr m2ap_pdu(new LIBLTE_M2AP_M2AP_PDU_STRUCT); uint32_t m2ap_message_len = 19; - uint8_t m2ap_message[] = {0x20, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00}; + uint8_t m2ap_message[] = { + 0x20, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00}; tst_msg.N_bytes = m2ap_message_len; memcpy(tst_msg.msg, m2ap_message, m2ap_message_len); @@ -333,7 +334,7 @@ int mbms_session_start_response_test() LIBLTE_M2AP_SUCCESSFULOUTCOME_STRUCT* succ_msg = &m2ap_pdu->choice.successfulOutcome; TESTASSERT(succ_msg->choice_type == LIBLTE_M2AP_SUCCESSFULOUTCOME_CHOICE_MBMSSESSIONSTARTRESPONSE); - LIBLTE_M2AP_MESSAGE_MBMSSESSIONSTARTRESPONSE_STRUCT *mbms_sess = &succ_msg->choice.MbmsSessionStartResponse; + LIBLTE_M2AP_MESSAGE_MBMSSESSIONSTARTRESPONSE_STRUCT* mbms_sess = &succ_msg->choice.MbmsSessionStartResponse; /*ProtocolIE MCE-MBMS-M2AP-ID*/ TESTASSERT(mbms_sess->MceMbmsM2apId.mce_mbms_m2ap_id == 0); @@ -366,7 +367,7 @@ int mbms_scheduling_information_test() std::unique_ptr m2ap_pdu(new LIBLTE_M2AP_M2AP_PDU_STRUCT); uint32_t m2ap_message_len = 62; - uint8_t m2ap_message[] = {0x00, 0x02, 0x00, 0x3a, 0x00, 0x00, 0x02, 0x00, 0x19, 0x00, 0x01, 0x00, 0x00, + uint8_t m2ap_message[] = {0x00, 0x02, 0x00, 0x3a, 0x00, 0x00, 0x02, 0x00, 0x19, 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x2e, 0x00, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x12, 0x10, 0x00, 0x0c, 0x00, 0x0d, 0x00, 0x00, 0x3f, 0x13, 0x00, 0x00, 0x00, 0xf1, 0x10, 0x00, 0x00, 0x01, 0x08, 0x00, 0x16, 0x00, 0x07, 0x00, 0x00, 0x17, 0x00, 0x02, 0x00, 0x40, @@ -384,54 +385,54 @@ int mbms_scheduling_information_test() LIBLTE_M2AP_INITIATINGMESSAGE_STRUCT* in_msg = &m2ap_pdu->choice.initiatingMessage; TESTASSERT(in_msg->choice_type == LIBLTE_M2AP_INITIATINGMESSAGE_CHOICE_MBMSSCHEDULINGINFORMATION); - LIBLTE_M2AP_MESSAGE_MBMSSCHEDULINGINFORMATION_STRUCT *sched_info = &in_msg->choice.MbmsSchedulingInformation; + LIBLTE_M2AP_MESSAGE_MBMSSCHEDULINGINFORMATION_STRUCT* sched_info = &in_msg->choice.MbmsSchedulingInformation; /*ProtocolIE MCCH-Update-Time*/ TESTASSERT(sched_info->MCCHUpdateTime.mcchUpdateTime == 0); /*ProtocolIE MBSFN-Area-Configuration-Item*/ TESTASSERT(sched_info->MbsfnAreaConfigurationList.len == 1); - LIBLTE_M2AP_MBSFN_AREA_CONFIGURATION_ITEM_STRUCT *area_conf = &sched_info->MbsfnAreaConfigurationList.buffer[0]; + LIBLTE_M2AP_MBSFN_AREA_CONFIGURATION_ITEM_STRUCT* area_conf = &sched_info->MbsfnAreaConfigurationList.buffer[0]; - //PMCH Configuration List/Item + // PMCH Configuration List/Item TESTASSERT(area_conf->PMCHConfigurationList.len == 1); - LIBLTE_M2AP_PMCH_CONFIGURATION_ITEM_STRUCT *pmch_conf_item = &area_conf->PMCHConfigurationList.buffer[0]; + LIBLTE_M2AP_PMCH_CONFIGURATION_ITEM_STRUCT* pmch_conf_item = &area_conf->PMCHConfigurationList.buffer[0]; // PMCH Configuration - LIBLTE_M2AP_PMCH_CONFIGURATION_STRUCT *pmch_conf = &area_conf->PMCHConfigurationList.buffer[0].PMCHConfiguration; + LIBLTE_M2AP_PMCH_CONFIGURATION_STRUCT* pmch_conf = &area_conf->PMCHConfigurationList.buffer[0].PMCHConfiguration; - //Allocated Subframes End + // Allocated Subframes End TESTASSERT(pmch_conf->allocatedSubframesEnd.allocated_subframes_end == 63); - //Data MCS + // Data MCS TESTASSERT(pmch_conf->dataMCS.dataMCS == 2); - //MCH Scheduling Period + // MCH Scheduling Period TESTASSERT(pmch_conf->mchSchedulingPeriod.e == LIBLTE_M2AP_MCH_SCHEDULING_PERIOD_RF64); - //MBMS Session List Per PMCH Item + // MBMS Session List Per PMCH Item TESTASSERT(pmch_conf_item->MBMSSessionListPerPMCHItem.len == 1); - LIBLTE_M2AP_MBMS_SESSION_LIST_PER_PMCH_ITEM_STRUCT *mbms_sess = &pmch_conf_item->MBMSSessionListPerPMCHItem; + LIBLTE_M2AP_MBMS_SESSION_LIST_PER_PMCH_ITEM_STRUCT* mbms_sess = &pmch_conf_item->MBMSSessionListPerPMCHItem; - //TMGI - uint8_t *plmn_id = mbms_sess->buffer[0].Tmgi.pLMN_Identity.buffer; + // TMGI + uint8_t* plmn_id = mbms_sess->buffer[0].Tmgi.pLMN_Identity.buffer; TESTASSERT((plmn_id[0] & 0x0F) == 0 && (plmn_id[0] & 0xF0) >> 4 == 0 && (plmn_id[1] & 0x0F) == 1); // MCC TESTASSERT((plmn_id[1] & 0xF0) >> 4 == 0xF && (plmn_id[2] & 0x0F) == 0 && (plmn_id[2] & 0xF0) >> 4 == 1); // MNC TESTASSERT(mbms_sess->buffer[0].Tmgi.serviceID.buffer[0] == 0); TESTASSERT(mbms_sess->buffer[0].Tmgi.serviceID.buffer[1] == 0); TESTASSERT(mbms_sess->buffer[0].Tmgi.serviceID.buffer[2] == 1); - //LCID + // LCID TESTASSERT(mbms_sess->buffer[0].Lcid.lcid == 1); /*MBSFN Subframe Configuration List*/ TESTASSERT(area_conf->MBSFNSubframeConfigurationList.len == 1); - LIBLTE_M2AP_MBSFN_SUBFRAME_CONFIGURATION_STRUCT *sub_conf = &area_conf->MBSFNSubframeConfigurationList.buffer[0]; + LIBLTE_M2AP_MBSFN_SUBFRAME_CONFIGURATION_STRUCT* sub_conf = &area_conf->MBSFNSubframeConfigurationList.buffer[0]; /*MBSFN Subframe configuration*/ - //Radioframe Allocation period + // Radioframe Allocation period TESTASSERT(sub_conf->radioFrameAllocationPeriod.e == LIBLTE_M2AP_RADIOFRAME_ALLOCATION_PERIOD_N1); - //Radioframe Allocation Offset + // Radioframe Allocation Offset TESTASSERT(sub_conf->radioFrameAllocationOffset.radioframeAllocationOffset == 0); // Subframe Allocation TESTASSERT(sub_conf->subframeAllocation.choice_type == LIBLTE_M2AP_SUBFRAME_ALLOCATION_ONE_FRAME); @@ -472,8 +473,8 @@ int mbms_scheduling_information_response_test() std::unique_ptr m2ap_pdu(new LIBLTE_M2AP_M2AP_PDU_STRUCT); uint32_t m2ap_message_len = 7; - uint8_t m2ap_message[] = {0x20, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00}; - tst_msg.N_bytes = m2ap_message_len; + uint8_t m2ap_message[] = {0x20, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00}; + tst_msg.N_bytes = m2ap_message_len; memcpy(tst_msg.msg, m2ap_message, m2ap_message_len); log1.info_hex(tst_msg.msg, tst_msg.N_bytes, "MBMS Scheduling Information Response message\n"); @@ -485,7 +486,8 @@ int mbms_scheduling_information_response_test() LIBLTE_M2AP_SUCCESSFULOUTCOME_STRUCT* succ_out = &m2ap_pdu->choice.successfulOutcome; TESTASSERT(succ_out->choice_type == LIBLTE_M2AP_SUCCESSFULOUTCOME_CHOICE_MBMSSCHEDULINGINFORMATIONRESPONSE); - LIBLTE_M2AP_MESSAGE_MBMSSCHEDULINGINFORMATIONRESPONSE_STRUCT *sched_info = &succ_out->choice.MbmsSchedulingInformationResponse; + LIBLTE_M2AP_MESSAGE_MBMSSCHEDULINGINFORMATIONRESPONSE_STRUCT* sched_info = + &succ_out->choice.MbmsSchedulingInformationResponse; /*M2AP Setup Request Pack Test*/ err = liblte_m2ap_pack_m2ap_pdu(m2ap_pdu.get(), &out_msg); @@ -500,7 +502,7 @@ int mbms_scheduling_information_response_test() return 0; } -int main(int argc, char **argv) +int main(int argc, char** argv) { if (m2_setup_request_test()) { return -1; diff --git a/lib/test/asn1/srslte_asn1_rrc_dl_ccch_test.cc b/lib/test/asn1/srslte_asn1_rrc_dl_ccch_test.cc index c074d3432..232e402d7 100644 --- a/lib/test/asn1/srslte_asn1_rrc_dl_ccch_test.cc +++ b/lib/test/asn1/srslte_asn1_rrc_dl_ccch_test.cc @@ -41,8 +41,8 @@ int rrc_conn_setup_test1() log1.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(128); - uint8_t rrc_msg[] = {0x60, 0x12, 0x98, 0x0b, 0xfd, 0xd2, 0x04, 0xfa, 0x18, 0x3e, 0xd5, 0xe6, 0xc2, - 0x59, 0x90, 0xc1, 0xa6, 0x00, 0x01, 0x31, 0x40, 0x42, 0x50, 0x80, 0x00, 0xf8}; + uint8_t rrc_msg[] = {0x60, 0x12, 0x98, 0x0b, 0xfd, 0xd2, 0x04, 0xfa, 0x18, 0x3e, 0xd5, 0xe6, 0xc2, + 0x59, 0x90, 0xc1, 0xa6, 0x00, 0x01, 0x31, 0x40, 0x42, 0x50, 0x80, 0x00, 0xf8}; uint32_t rrc_msg_len = sizeof(rrc_msg); // 6012980bfdd204fa183ed5e6c25990c1a60001314042508000f8 diff --git a/lib/test/asn1/srslte_asn1_rrc_mcch_test.cc b/lib/test/asn1/srslte_asn1_rrc_mcch_test.cc index 2d3e979a0..2012ef6ec 100644 --- a/lib/test/asn1/srslte_asn1_rrc_mcch_test.cc +++ b/lib/test/asn1/srslte_asn1_rrc_mcch_test.cc @@ -117,9 +117,9 @@ int basic_test() TESTASSERT(area_cfg_r9->pmch_info_list_r9[1].mbms_session_info_list_r9[0].session_id_r9.to_string() == "02"); TESTASSERT(area_cfg_r9->pmch_info_list_r9[1].mbms_session_info_list_r9[0].lc_ch_id_r9 == 2); - //log1.info_hex(byte_buf.msg, byte_buf.N_bytes, "MCCH packed message:"); + // log1.info_hex(byte_buf.msg, byte_buf.N_bytes, "MCCH packed message:"); - uint8_t rrc_msg2[known_reference_len]; + uint8_t rrc_msg2[known_reference_len]; bzero(rrc_msg2, sizeof(rrc_msg2)); asn1::bit_ref bref2(&rrc_msg2[0], sizeof(rrc_msg2)); mcch_msg.pack(bref2); @@ -129,9 +129,8 @@ int basic_test() return 0; } -int main(int argc, char **argv) +int main(int argc, char** argv) { TESTASSERT(basic_test() == 0); return 0; } - diff --git a/lib/test/asn1/srslte_asn1_rrc_meas_test.cc b/lib/test/asn1/srslte_asn1_rrc_meas_test.cc index 384772755..b121b18be 100644 --- a/lib/test/asn1/srslte_asn1_rrc_meas_test.cc +++ b/lib/test/asn1/srslte_asn1_rrc_meas_test.cc @@ -44,8 +44,8 @@ int basic_test() log1.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(128); - uint8_t rrc_msg[] = {0x08, 0x10, 0x49, 0x3C, 0x0D, 0x97, 0x89, 0x83, 0xC0, - 0x84, 0x20, 0x82, 0x08, 0x21, 0x00, 0x01, 0xBC, 0x48}; + uint8_t rrc_msg[] = { + 0x08, 0x10, 0x49, 0x3C, 0x0D, 0x97, 0x89, 0x83, 0xC0, 0x84, 0x20, 0x82, 0x08, 0x21, 0x00, 0x01, 0xBC, 0x48}; uint32_t rrc_msg_len = sizeof(rrc_msg); // 0810493C0D978983C084208208210001BC48 diff --git a/lib/test/asn1/srslte_asn1_rrc_ul_dcch_test.cc b/lib/test/asn1/srslte_asn1_rrc_ul_dcch_test.cc index f9377806c..18dd6bc97 100644 --- a/lib/test/asn1/srslte_asn1_rrc_ul_dcch_test.cc +++ b/lib/test/asn1/srslte_asn1_rrc_ul_dcch_test.cc @@ -81,7 +81,7 @@ int rrc_ue_cap_info_test(srslte::mac_pcap* pcap) cap.feature_group_inds_present = true; cap.feature_group_inds.from_number(args.feature_group); - uint8_t buf[64]; + uint8_t buf[64]; bzero(buf, sizeof(buf)); asn1::bit_ref bref(buf, sizeof(buf)); cap.pack(bref); diff --git a/lib/test/common/bcd_helpers_test.cc b/lib/test/common/bcd_helpers_test.cc index 5abd0d4f4..d5bf1fecd 100644 --- a/lib/test/common/bcd_helpers_test.cc +++ b/lib/test/common/bcd_helpers_test.cc @@ -19,17 +19,17 @@ * */ -#include #include "srslte/common/bcd_helpers.h" +#include using namespace srslte; -int main(int argc, char **argv) +int main(int argc, char** argv) { std::string mcc_str = "001"; std::string mnc_str = "001"; - uint16_t mcc; - uint16_t mnc; + uint16_t mcc; + uint16_t mnc; // String to code @@ -47,8 +47,8 @@ int main(int argc, char **argv) mcc_str = ""; mnc_str = ""; - mcc = 0xF001; - mnc = 0xF001; + mcc = 0xF001; + mnc = 0xF001; assert(mcc_to_string(mcc, &mcc_str)); assert(mcc_str.compare("001") == 0); diff --git a/lib/test/common/log_filter_test.cc b/lib/test/common/log_filter_test.cc index 06b209881..55b61d6b4 100644 --- a/lib/test/common/log_filter_test.cc +++ b/lib/test/common/log_filter_test.cc @@ -20,7 +20,7 @@ */ #define NTHREADS 100 -#define NMSGS 100 +#define NMSGS 100 #include "srslte/common/log_filter.h" #include "srslte/common/logger_file.h" @@ -30,20 +30,20 @@ using namespace srslte; typedef struct { - logger_file *l; - int thread_id; -}args_t; + logger_file* l; + int thread_id; +} args_t; -void* thread_loop(void *a) { - args_t *args = (args_t*)a; - char buf[100]; +void* thread_loop(void* a) +{ + args_t* args = (args_t*)a; + char buf[100]; sprintf(buf, "LAYER%d", args->thread_id); log_filter filter(buf, args->l); filter.set_level(LOG_LEVEL_INFO); - for(int i=0;ithread_id, i); filter.warning("Thread %d: %d", args->thread_id, i); filter.info("Thread %d: %d", args->thread_id, i); @@ -52,8 +52,9 @@ void* thread_loop(void *a) { return NULL; } -void* thread_loop_hex(void *a) { - args_t *args = (args_t*)a; +void* thread_loop_hex(void* a) +{ + args_t* args = (args_t*)a; char buf[100]; uint8_t hex[100]; @@ -65,8 +66,7 @@ void* thread_loop_hex(void *a) { filter.set_level(LOG_LEVEL_DEBUG); filter.set_hex_limit(32); - for(int i=0;ithread_id, i); filter.warning_hex(hex, 100, "Thread %d: %d", args->thread_id, i); filter.info_hex(hex, 100, "Thread %d: %d", args->thread_id, i); @@ -75,41 +75,44 @@ void* thread_loop_hex(void *a) { return NULL; } -void write(std::string filename) { +void write(std::string filename) +{ logger_file l; l.init(filename); pthread_t threads[NTHREADS]; args_t args[NTHREADS]; - for(int i=0;i -#include #include "srslte/common/logger_file.h" +#include +#include using namespace srslte; typedef struct { - logger_file *l; - int thread_id; -}args_t; + logger_file* l; + int thread_id; +} args_t; -void* thread_loop(void *a) { - args_t *args = (args_t*)a; - char buf[100]; - for(int i=0;ithread_id, i); args->l->log_char(buf); } return NULL; } -void write(std::string filename) { +void write(std::string filename) +{ logger_file l; l.init(filename); pthread_t threads[NTHREADS]; args_t args[NTHREADS]; - for(int i=0;imsg, &i, 4); b->N_bytes = 4; @@ -44,7 +44,8 @@ void* write_thread(void *a) { return NULL; } -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ bool result; rlc_tx_queue q; unique_byte_buffer_t b; @@ -57,11 +58,10 @@ int main(int argc, char **argv) { pthread_create(&thread, NULL, &write_thread, &args); - for(uint32_t i=0;imsg, 4); - if(r != i) + if (r != i) result = false; } @@ -71,10 +71,10 @@ int main(int argc, char **argv) { result = false; } - if(result) { + if (result) { printf("Passed\n"); exit(0); - }else{ + } else { printf("Failed\n;"); exit(1); } diff --git a/lib/test/common/pdu_test.cc b/lib/test/common/pdu_test.cc index a60b3e4ec..05e15b658 100644 --- a/lib/test/common/pdu_test.cc +++ b/lib/test/common/pdu_test.cc @@ -605,19 +605,18 @@ int mac_sch_pdu_pack_error_test() return SRSLTE_SUCCESS; } -int mac_mch_pdu_pack_test1() { - static uint8_t tv[] = {0x3e, 0x02, 0x20, 0x05, 0x21, 0x0a, 0x1f, 0x0f, - 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x02, 0x04, - 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +int mac_mch_pdu_pack_test1() +{ + static uint8_t tv[] = {0x3e, 0x02, 0x20, 0x05, 0x21, 0x0a, 0x1f, 0x0f, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x02, + 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; srslte::log_filter mac_log("MAC"); mac_log.set_level(srslte::LOG_LEVEL_DEBUG); mac_log.set_hex_limit(100000); - const uint32_t pdu_size = 30; + const uint32_t pdu_size = 30; srslte::mch_pdu mch_pdu(10, &mac_log); - byte_buffer_t buffer; + byte_buffer_t buffer; mch_pdu.init_tx(&buffer, pdu_size, true); TESTASSERT(mch_pdu.rem_size() == pdu_size); @@ -641,8 +640,7 @@ int mac_mch_pdu_pack_test1() { TESTASSERT(mch_pdu.write_packet(&mac_log) == buffer.msg); // log - mac_log.info_hex(buffer.msg, buffer.N_bytes, "MAC PDU (%d B):\n", - buffer.N_bytes); + mac_log.info_hex(buffer.msg, buffer.N_bytes, "MAC PDU (%d B):\n", buffer.N_bytes); #if HAVE_PCAP pcap_handle->write_ul_crnti(buffer.msg, buffer.N_bytes, 0x1001, true, 1); @@ -772,7 +770,7 @@ int main(int argc, char** argv) fprintf(stderr, "mac_sch_pdu_pack_error_test failed.\n"); return SRSLTE_ERROR; } - + if (mac_mch_pdu_pack_test1()) { fprintf(stderr, "mac_mch_pdu_pack_test1 failed.\n"); return SRSLTE_ERROR; diff --git a/lib/test/common/test_eea1.cc b/lib/test/common/test_eea1.cc index eea7ee1ef..805d913eb 100644 --- a/lib/test/common/test_eea1.cc +++ b/lib/test/common/test_eea1.cc @@ -19,27 +19,28 @@ * */ -#include -#include #include +#include +#include #include -#include "srslte/srslte.h" #include "srslte/common/liblte_security.h" +#include "srslte/srslte.h" /* * Prototypes */ -int32 arrcmp(uint8_t const * const a, uint8_t const * const b, uint32 len) { +int32 arrcmp(uint8_t const* const a, uint8_t const* const b, uint32 len) +{ uint32 i = 0; - for (i = 0; i < len; i++) { - if (a[i] != b[i]) { - return a[i] - b[i]; - } - } - return 0; + for (i = 0; i < len; i++) { + if (a[i] != b[i]) { + return a[i] - b[i]; + } + } + return 0; } /* @@ -53,29 +54,22 @@ int32 arrcmp(uint8_t const * const a, uint8_t const * const b, uint32 len) { void test_set_1() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1, - 0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1 }; - uint32_t count = 0x398a59b4; - uint8_t bearer = 0x15; - uint8_t direction = 1; + uint8_t key[] = {0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1, 0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1}; + uint32_t count = 0x398a59b4; + uint8_t bearer = 0x15; + uint8_t direction = 1; uint32_t len_bits = 253, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, - 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80, - 0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f, - 0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0 }; - uint8_t ct[] = { 0x5d, 0x5b, 0xfe, 0x75, 0xeb, 0x04, 0xf6, - 0x8c, 0xe0, 0xa1, 0x23, 0x77, 0xea, 0x00, 0xb3, 0x7d, - 0x47, 0xc6, 0xa0, 0xba, 0x06, 0x30, 0x91, 0x55, 0x08, - 0x6a, 0x85, 0x9c, 0x43, 0x41, 0xb3, 0x78 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80, + 0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f, 0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0}; + uint8_t ct[] = {0x5d, 0x5b, 0xfe, 0x75, 0xeb, 0x04, 0xf6, 0x8c, 0xe0, 0xa1, 0x23, 0x77, 0xea, 0x00, 0xb3, 0x7d, + 0x47, 0xc6, 0xa0, 0xba, 0x06, 0x30, 0x91, 0x55, 0x08, 0x6a, 0x85, 0x9c, 0x43, 0x41, 0xb3, 0x78}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea1(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -83,8 +77,7 @@ void test_set_1() assert(err_cmp == 0); // decryption - err_lte = liblte_security_decryption_eea1(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -97,45 +90,30 @@ void test_set_1() void test_set_2() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0x2b, 0xd6, 0x45, 0x9f, 0x82, 0xc4, 0x40, - 0xe0, 0x95, 0x2c, 0x49, 0x10, 0x48, 0x05, 0xff, 0x48 }; - uint32_t count = 0xc675a64b; - uint8_t bearer = 0x0c; - uint8_t direction = 1; + uint8_t key[] = {0x2b, 0xd6, 0x45, 0x9f, 0x82, 0xc4, 0x40, 0xe0, 0x95, 0x2c, 0x49, 0x10, 0x48, 0x05, 0xff, 0x48}; + uint32_t count = 0xc675a64b; + uint8_t bearer = 0x0c; + uint8_t direction = 1; uint32_t len_bits = 798, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0x7e, 0xc6, 0x12, 0x72, 0x74, 0x3b, 0xf1, - 0x61, 0x47, 0x26, 0x44, 0x6a, 0x6c, 0x38, 0xce, 0xd1, - 0x66, 0xf6, 0xca, 0x76, 0xeb, 0x54, 0x30, 0x04, 0x42, - 0x86, 0x34, 0x6c, 0xef, 0x13, 0x0f, 0x92, 0x92, 0x2b, - 0x03, 0x45, 0x0d, 0x3a, 0x99, 0x75, 0xe5, 0xbd, 0x2e, - 0xa0, 0xeb, 0x55, 0xad, 0x8e, 0x1b, 0x19, 0x9e, 0x3e, - 0xc4, 0x31, 0x60, 0x20, 0xe9, 0xa1, 0xb2, 0x85, 0xe7, - 0x62, 0x79, 0x53, 0x59, 0xb7, 0xbd, 0xfd, 0x39, 0xbe, - 0xf4, 0xb2, 0x48, 0x45, 0x83, 0xd5, 0xaf, 0xe0, 0x82, - 0xae, 0xe6, 0x38, 0xbf, 0x5f, 0xd5, 0xa6, 0x06, 0x19, - 0x39, 0x01, 0xa0, 0x8f, 0x4a, 0xb4, 0x1a, 0xab, 0x9b, - 0x13, 0x48, 0x80 }; - uint8_t ct[] = { 0x3f, 0x67, 0x85, 0x07, 0x14, 0xb8, 0xda, - 0x69, 0xef, 0xb7, 0x27, 0xed, 0x7a, 0x6c, 0x0c, 0x50, - 0x71, 0x4a, 0xd7, 0x36, 0xc4, 0xf5, 0x60, 0x00, 0x06, - 0xe3, 0x52, 0x5b, 0xe8, 0x07, 0xc4, 0x67, 0xc6, 0x77, - 0xff, 0x86, 0x4a, 0xf4, 0x5f, 0xba, 0x09, 0xc2, 0x7c, - 0xde, 0x38, 0xf8, 0x7a, 0x1f, 0x84, 0xd5, 0x9a, 0xb2, - 0x55, 0x40, 0x8f, 0x2c, 0x7b, 0x82, 0xf9, 0xea, 0xd4, - 0x1a, 0x1f, 0xe6, 0x5e, 0xab, 0xeb, 0xfb, 0xc1, 0xf3, - 0xa4, 0xc5, 0x6c, 0x9a, 0x26, 0xfc, 0xf7, 0xb3, 0xd6, - 0x6d, 0x02, 0x20, 0xee, 0x47, 0x75, 0xbc, 0x58, 0x17, - 0x0a, 0x2b, 0x12, 0xf3, 0x43, 0x1d, 0x11, 0xb3, 0x44, - 0xd6, 0xe3, 0x6c }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0x7e, 0xc6, 0x12, 0x72, 0x74, 0x3b, 0xf1, 0x61, 0x47, 0x26, 0x44, 0x6a, 0x6c, 0x38, 0xce, 0xd1, 0x66, + 0xf6, 0xca, 0x76, 0xeb, 0x54, 0x30, 0x04, 0x42, 0x86, 0x34, 0x6c, 0xef, 0x13, 0x0f, 0x92, 0x92, 0x2b, + 0x03, 0x45, 0x0d, 0x3a, 0x99, 0x75, 0xe5, 0xbd, 0x2e, 0xa0, 0xeb, 0x55, 0xad, 0x8e, 0x1b, 0x19, 0x9e, + 0x3e, 0xc4, 0x31, 0x60, 0x20, 0xe9, 0xa1, 0xb2, 0x85, 0xe7, 0x62, 0x79, 0x53, 0x59, 0xb7, 0xbd, 0xfd, + 0x39, 0xbe, 0xf4, 0xb2, 0x48, 0x45, 0x83, 0xd5, 0xaf, 0xe0, 0x82, 0xae, 0xe6, 0x38, 0xbf, 0x5f, 0xd5, + 0xa6, 0x06, 0x19, 0x39, 0x01, 0xa0, 0x8f, 0x4a, 0xb4, 0x1a, 0xab, 0x9b, 0x13, 0x48, 0x80}; + uint8_t ct[] = {0x3f, 0x67, 0x85, 0x07, 0x14, 0xb8, 0xda, 0x69, 0xef, 0xb7, 0x27, 0xed, 0x7a, 0x6c, 0x0c, 0x50, 0x71, + 0x4a, 0xd7, 0x36, 0xc4, 0xf5, 0x60, 0x00, 0x06, 0xe3, 0x52, 0x5b, 0xe8, 0x07, 0xc4, 0x67, 0xc6, 0x77, + 0xff, 0x86, 0x4a, 0xf4, 0x5f, 0xba, 0x09, 0xc2, 0x7c, 0xde, 0x38, 0xf8, 0x7a, 0x1f, 0x84, 0xd5, 0x9a, + 0xb2, 0x55, 0x40, 0x8f, 0x2c, 0x7b, 0x82, 0xf9, 0xea, 0xd4, 0x1a, 0x1f, 0xe6, 0x5e, 0xab, 0xeb, 0xfb, + 0xc1, 0xf3, 0xa4, 0xc5, 0x6c, 0x9a, 0x26, 0xfc, 0xf7, 0xb3, 0xd6, 0x6d, 0x02, 0x20, 0xee, 0x47, 0x75, + 0xbc, 0x58, 0x17, 0x0a, 0x2b, 0x12, 0xf3, 0x43, 0x1d, 0x11, 0xb3, 0x44, 0xd6, 0xe3, 0x6c}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea1(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -143,8 +121,7 @@ void test_set_2() assert(err_cmp == 0); // decryption - err_lte = liblte_security_decryption_eea1(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -157,31 +134,24 @@ void test_set_2() void test_set_3() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0x0a, 0x8b, 0x6b, 0xd8, 0xd9, 0xb0, 0x8b, - 0x08, 0xd6, 0x4e, 0x32, 0xd1, 0x81, 0x77, 0x77, 0xfb }; - uint32_t count = 0x544d49cd; - uint8_t bearer = 0x04; - uint8_t direction = 0; + uint8_t key[] = {0x0a, 0x8b, 0x6b, 0xd8, 0xd9, 0xb0, 0x8b, 0x08, 0xd6, 0x4e, 0x32, 0xd1, 0x81, 0x77, 0x77, 0xfb}; + uint32_t count = 0x544d49cd; + uint8_t bearer = 0x04; + uint8_t direction = 0; uint32_t len_bits = 310, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0xfd, 0x40, 0xa4, 0x1d, 0x37, 0x0a, 0x1f, - 0x65, 0x74, 0x50, 0x95, 0x68, 0x7d, 0x47, 0xba, 0x1d, - 0x36, 0xd2, 0x34, 0x9e, 0x23, 0xf6, 0x44, 0x39, 0x2c, - 0x8e, 0xa9, 0xc4, 0x9d, 0x40, 0xc1, 0x32, 0x71, 0xaf, - 0xf2, 0x64, 0xd0, 0xf2, 0x48, 0x00 }; - uint8_t ct[] = { 0x48, 0x14, 0x8e, 0x54, 0x52, 0xa2, 0x10, - 0xc0, 0x5f, 0x46, 0xbc, 0x80, 0xdc, 0x6f, 0x73, 0x49, - 0x5b, 0x02, 0x04, 0x8c, 0x1b, 0x95, 0x8b, 0x02, 0x61, - 0x02, 0xca, 0x97, 0x28, 0x02, 0x79, 0xa4, 0xc1, 0x8d, - 0x2e, 0xe3, 0x08, 0x92, 0x1c }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0xfd, 0x40, 0xa4, 0x1d, 0x37, 0x0a, 0x1f, 0x65, 0x74, 0x50, 0x95, 0x68, 0x7d, 0x47, + 0xba, 0x1d, 0x36, 0xd2, 0x34, 0x9e, 0x23, 0xf6, 0x44, 0x39, 0x2c, 0x8e, 0xa9, 0xc4, + 0x9d, 0x40, 0xc1, 0x32, 0x71, 0xaf, 0xf2, 0x64, 0xd0, 0xf2, 0x48, 0x00}; + uint8_t ct[] = {0x48, 0x14, 0x8e, 0x54, 0x52, 0xa2, 0x10, 0xc0, 0x5f, 0x46, 0xbc, 0x80, 0xdc, + 0x6f, 0x73, 0x49, 0x5b, 0x02, 0x04, 0x8c, 0x1b, 0x95, 0x8b, 0x02, 0x61, 0x02, + 0xca, 0x97, 0x28, 0x02, 0x79, 0xa4, 0xc1, 0x8d, 0x2e, 0xe3, 0x08, 0x92, 0x1c}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea1(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -189,8 +159,7 @@ void test_set_3() assert(err_cmp == 0); // decryption - err_lte = liblte_security_decryption_eea1(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -203,51 +172,34 @@ void test_set_3() void test_set_4() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0xaa, 0x1f, 0x95, 0xae, 0xa5, 0x33, 0xbc, - 0xb3, 0x2e, 0xb6, 0x3b, 0xf5, 0x2d, 0x8f, 0x83, 0x1a }; - uint32_t count = 0x72d8c671; - uint8_t bearer = 0x10; - uint8_t direction = 1; + uint8_t key[] = {0xaa, 0x1f, 0x95, 0xae, 0xa5, 0x33, 0xbc, 0xb3, 0x2e, 0xb6, 0x3b, 0xf5, 0x2d, 0x8f, 0x83, 0x1a}; + uint32_t count = 0x72d8c671; + uint8_t bearer = 0x10; + uint8_t direction = 1; uint32_t len_bits = 1022, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0xfb, 0x1b, 0x96, 0xc5, 0xc8, 0xba, 0xdf, - 0xb2, 0xe8, 0xe8, 0xed, 0xfd, 0xe7, 0x8e, 0x57, 0xf2, - 0xad, 0x81, 0xe7, 0x41, 0x03, 0xfc, 0x43, 0x0a, 0x53, - 0x4d, 0xcc, 0x37, 0xaf, 0xce, 0xc7, 0x0e, 0x15, 0x17, - 0xbb, 0x06, 0xf2, 0x72, 0x19, 0xda, 0xe4, 0x90, 0x22, - 0xdd, 0xc4, 0x7a, 0x06, 0x8d, 0xe4, 0xc9, 0x49, 0x6a, - 0x95, 0x1a, 0x6b, 0x09, 0xed, 0xbd, 0xc8, 0x64, 0xc7, - 0xad, 0xbd, 0x74, 0x0a, 0xc5, 0x0c, 0x02, 0x2f, 0x30, - 0x82, 0xba, 0xfd, 0x22, 0xd7, 0x81, 0x97, 0xc5, 0xd5, - 0x08, 0xb9, 0x77, 0xbc, 0xa1, 0x3f, 0x32, 0xe6, 0x52, - 0xe7, 0x4b, 0xa7, 0x28, 0x57, 0x60, 0x77, 0xce, 0x62, - 0x8c, 0x53, 0x5e, 0x87, 0xdc, 0x60, 0x77, 0xba, 0x07, - 0xd2, 0x90, 0x68, 0x59, 0x0c, 0x8c, 0xb5, 0xf1, 0x08, - 0x8e, 0x08, 0x2c, 0xfa, 0x0e, 0xc9, 0x61, 0x30, 0x2d, - 0x69, 0xcf, 0x3d, 0x44 }; - uint8_t ct[] = { 0xff, 0xcf, 0xc2, 0xfe, 0xad, 0x6c, 0x09, - 0x4e, 0x96, 0xc5, 0x89, 0xd0, 0xf6, 0x77, 0x9b, 0x67, - 0x84, 0x24, 0x6c, 0x3c, 0x4d, 0x1c, 0xea, 0x20, 0x3d, - 0xb3, 0x90, 0x1f, 0x40, 0xad, 0x4f, 0xd7, 0x13, 0x8b, - 0xc6, 0xd7, 0x7e, 0x83, 0x20, 0xcb, 0x10, 0x2f, 0x49, - 0x7f, 0xdd, 0x44, 0xa2, 0x69, 0xa9, 0x6e, 0xcb, 0x28, - 0x61, 0x77, 0x00, 0xe3, 0x32, 0xeb, 0x2f, 0x73, 0x6b, - 0x34, 0xf4, 0xf2, 0x69, 0x30, 0x94, 0xe2, 0x2f, 0xf9, - 0x4f, 0x9b, 0xe4, 0x72, 0x3d, 0xa4, 0x0c, 0x40, 0xdf, - 0xd3, 0x93, 0x1c, 0xc1, 0xac, 0x97, 0x23, 0xf6, 0xb4, - 0xa9, 0x91, 0x3e, 0x96, 0xb6, 0xdb, 0x7a, 0xbc, 0xac, - 0xe4, 0x15, 0x17, 0x7c, 0x1d, 0x01, 0x15, 0xc5, 0xf0, - 0x9b, 0x5f, 0xde, 0xa0, 0xb3, 0xad, 0xb8, 0xf9, 0xda, - 0x6e, 0x9f, 0x9a, 0x04, 0xc5, 0x43, 0x39, 0x7b, 0x9d, - 0x43, 0xf8, 0x73, 0x30 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0xfb, 0x1b, 0x96, 0xc5, 0xc8, 0xba, 0xdf, 0xb2, 0xe8, 0xe8, 0xed, 0xfd, 0xe7, 0x8e, 0x57, 0xf2, + 0xad, 0x81, 0xe7, 0x41, 0x03, 0xfc, 0x43, 0x0a, 0x53, 0x4d, 0xcc, 0x37, 0xaf, 0xce, 0xc7, 0x0e, + 0x15, 0x17, 0xbb, 0x06, 0xf2, 0x72, 0x19, 0xda, 0xe4, 0x90, 0x22, 0xdd, 0xc4, 0x7a, 0x06, 0x8d, + 0xe4, 0xc9, 0x49, 0x6a, 0x95, 0x1a, 0x6b, 0x09, 0xed, 0xbd, 0xc8, 0x64, 0xc7, 0xad, 0xbd, 0x74, + 0x0a, 0xc5, 0x0c, 0x02, 0x2f, 0x30, 0x82, 0xba, 0xfd, 0x22, 0xd7, 0x81, 0x97, 0xc5, 0xd5, 0x08, + 0xb9, 0x77, 0xbc, 0xa1, 0x3f, 0x32, 0xe6, 0x52, 0xe7, 0x4b, 0xa7, 0x28, 0x57, 0x60, 0x77, 0xce, + 0x62, 0x8c, 0x53, 0x5e, 0x87, 0xdc, 0x60, 0x77, 0xba, 0x07, 0xd2, 0x90, 0x68, 0x59, 0x0c, 0x8c, + 0xb5, 0xf1, 0x08, 0x8e, 0x08, 0x2c, 0xfa, 0x0e, 0xc9, 0x61, 0x30, 0x2d, 0x69, 0xcf, 0x3d, 0x44}; + uint8_t ct[] = {0xff, 0xcf, 0xc2, 0xfe, 0xad, 0x6c, 0x09, 0x4e, 0x96, 0xc5, 0x89, 0xd0, 0xf6, 0x77, 0x9b, 0x67, + 0x84, 0x24, 0x6c, 0x3c, 0x4d, 0x1c, 0xea, 0x20, 0x3d, 0xb3, 0x90, 0x1f, 0x40, 0xad, 0x4f, 0xd7, + 0x13, 0x8b, 0xc6, 0xd7, 0x7e, 0x83, 0x20, 0xcb, 0x10, 0x2f, 0x49, 0x7f, 0xdd, 0x44, 0xa2, 0x69, + 0xa9, 0x6e, 0xcb, 0x28, 0x61, 0x77, 0x00, 0xe3, 0x32, 0xeb, 0x2f, 0x73, 0x6b, 0x34, 0xf4, 0xf2, + 0x69, 0x30, 0x94, 0xe2, 0x2f, 0xf9, 0x4f, 0x9b, 0xe4, 0x72, 0x3d, 0xa4, 0x0c, 0x40, 0xdf, 0xd3, + 0x93, 0x1c, 0xc1, 0xac, 0x97, 0x23, 0xf6, 0xb4, 0xa9, 0x91, 0x3e, 0x96, 0xb6, 0xdb, 0x7a, 0xbc, + 0xac, 0xe4, 0x15, 0x17, 0x7c, 0x1d, 0x01, 0x15, 0xc5, 0xf0, 0x9b, 0x5f, 0xde, 0xa0, 0xb3, 0xad, + 0xb8, 0xf9, 0xda, 0x6e, 0x9f, 0x9a, 0x04, 0xc5, 0x43, 0x39, 0x7b, 0x9d, 0x43, 0xf8, 0x73, 0x30}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea1(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -255,8 +207,7 @@ void test_set_4() assert(err_cmp == 0); // decryption - err_lte = liblte_security_decryption_eea1(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -269,57 +220,38 @@ void test_set_4() void test_set_5() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0x96, 0x18, 0xae, 0x46, 0x89, 0x1f, 0x86, - 0x57, 0x8e, 0xeb, 0xe9, 0x0e, 0xf7, 0xa1, 0x20, 0x2e }; - uint32_t count = 0xc675a64b; - uint8_t bearer = 0x0c; - uint8_t direction = 1; + uint8_t key[] = {0x96, 0x18, 0xae, 0x46, 0x89, 0x1f, 0x86, 0x57, 0x8e, 0xeb, 0xe9, 0x0e, 0xf7, 0xa1, 0x20, 0x2e}; + uint32_t count = 0xc675a64b; + uint8_t bearer = 0x0c; + uint8_t direction = 1; uint32_t len_bits = 1245, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0x8d, 0xaa, 0x17, 0xb1, 0xae, 0x05, 0x05, - 0x29, 0xc6, 0x82, 0x7f, 0x28, 0xc0, 0xef, 0x6a, 0x12, - 0x42, 0xe9, 0x3f, 0x8b, 0x31, 0x4f, 0xb1, 0x8a, 0x77, - 0xf7, 0x90, 0xae, 0x04, 0x9f, 0xed, 0xd6, 0x12, 0x26, - 0x7f, 0xec, 0xae, 0xfc, 0x45, 0x01, 0x74, 0xd7, 0x6d, - 0x9f, 0x9a, 0xa7, 0x75, 0x5a, 0x30, 0xcd, 0x90, 0xa9, - 0xa5, 0x87, 0x4b, 0xf4, 0x8e, 0xaf, 0x70, 0xee, 0xa3, - 0xa6, 0x2a, 0x25, 0x0a, 0x8b, 0x6b, 0xd8, 0xd9, 0xb0, - 0x8b, 0x08, 0xd6, 0x4e, 0x32, 0xd1, 0x81, 0x77, 0x77, - 0xfb, 0x54, 0x4d, 0x49, 0xcd, 0x49, 0x72, 0x0e, 0x21, - 0x9d, 0xbf, 0x8b, 0xbe, 0xd3, 0x39, 0x04, 0xe1, 0xfd, - 0x40, 0xa4, 0x1d, 0x37, 0x0a, 0x1f, 0x65, 0x74, 0x50, - 0x95, 0x68, 0x7d, 0x47, 0xba, 0x1d, 0x36, 0xd2, 0x34, - 0x9e, 0x23, 0xf6, 0x44, 0x39, 0x2c, 0x8e, 0xa9, 0xc4, - 0x9d, 0x40, 0xc1, 0x32, 0x71, 0xaf, 0xf2, 0x64, 0xd0, - 0xf2, 0x48, 0x41, 0xd6, 0x46, 0x5f, 0x09, 0x96, 0xff, - 0x84, 0xe6, 0x5f, 0xc5, 0x17, 0xc5, 0x3e, 0xfc, 0x33, - 0x63, 0xc3, 0x84, 0x92, 0xa8 }; - uint8_t ct[] = { 0x6c, 0xdb, 0x18, 0xa7, 0xca, 0x82, 0x18, - 0xe8, 0x6e, 0x4b, 0x4b, 0x71, 0x6a, 0x4d, 0x04, 0x37, - 0x1f, 0xbe, 0xc2, 0x62, 0xfc, 0x5a, 0xd0, 0xb3, 0x81, - 0x9b, 0x18, 0x7b, 0x97, 0xe5, 0x5b, 0x1a, 0x4d, 0x7c, - 0x19, 0xee, 0x24, 0xc8, 0xb4, 0xd7, 0x72, 0x3c, 0xfe, - 0xdf, 0x04, 0x5b, 0x8a, 0xca, 0xe4, 0x86, 0x95, 0x17, - 0xd8, 0x0e, 0x50, 0x61, 0x5d, 0x90, 0x35, 0xd5, 0xd9, - 0xc5, 0xa4, 0x0a, 0xf6, 0x02, 0x28, 0x0b, 0x54, 0x25, - 0x97, 0xb0, 0xcb, 0x18, 0x61, 0x9e, 0xeb, 0x35, 0x92, - 0x57, 0x59, 0xd1, 0x95, 0xe1, 0x00, 0xe8, 0xe4, 0xaa, - 0x0c, 0x38, 0xa3, 0xc2, 0xab, 0xe0, 0xf3, 0xd8, 0xff, - 0x04, 0xf3, 0xc3, 0x3c, 0x29, 0x50, 0x69, 0xc2, 0x36, - 0x94, 0xb5, 0xbb, 0xea, 0xcd, 0xd5, 0x42, 0xe2, 0x8e, - 0x8a, 0x94, 0xed, 0xb9, 0x11, 0x9f, 0x41, 0x2d, 0x05, - 0x4b, 0xe1, 0xfa, 0x72, 0x72, 0xb5, 0xff, 0xb2, 0xb2, - 0x57, 0x0f, 0x4f, 0x7c, 0xea, 0xf3, 0x83, 0xa8, 0xa9, - 0xd9, 0x35, 0x72, 0xf0, 0x4d, 0x6e, 0x3a, 0x6e, 0x29, - 0x37, 0x26, 0xec, 0x62, 0xc8 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0x8d, 0xaa, 0x17, 0xb1, 0xae, 0x05, 0x05, 0x29, 0xc6, 0x82, 0x7f, 0x28, 0xc0, 0xef, 0x6a, 0x12, + 0x42, 0xe9, 0x3f, 0x8b, 0x31, 0x4f, 0xb1, 0x8a, 0x77, 0xf7, 0x90, 0xae, 0x04, 0x9f, 0xed, 0xd6, + 0x12, 0x26, 0x7f, 0xec, 0xae, 0xfc, 0x45, 0x01, 0x74, 0xd7, 0x6d, 0x9f, 0x9a, 0xa7, 0x75, 0x5a, + 0x30, 0xcd, 0x90, 0xa9, 0xa5, 0x87, 0x4b, 0xf4, 0x8e, 0xaf, 0x70, 0xee, 0xa3, 0xa6, 0x2a, 0x25, + 0x0a, 0x8b, 0x6b, 0xd8, 0xd9, 0xb0, 0x8b, 0x08, 0xd6, 0x4e, 0x32, 0xd1, 0x81, 0x77, 0x77, 0xfb, + 0x54, 0x4d, 0x49, 0xcd, 0x49, 0x72, 0x0e, 0x21, 0x9d, 0xbf, 0x8b, 0xbe, 0xd3, 0x39, 0x04, 0xe1, + 0xfd, 0x40, 0xa4, 0x1d, 0x37, 0x0a, 0x1f, 0x65, 0x74, 0x50, 0x95, 0x68, 0x7d, 0x47, 0xba, 0x1d, + 0x36, 0xd2, 0x34, 0x9e, 0x23, 0xf6, 0x44, 0x39, 0x2c, 0x8e, 0xa9, 0xc4, 0x9d, 0x40, 0xc1, 0x32, + 0x71, 0xaf, 0xf2, 0x64, 0xd0, 0xf2, 0x48, 0x41, 0xd6, 0x46, 0x5f, 0x09, 0x96, 0xff, 0x84, 0xe6, + 0x5f, 0xc5, 0x17, 0xc5, 0x3e, 0xfc, 0x33, 0x63, 0xc3, 0x84, 0x92, 0xa8}; + uint8_t ct[] = {0x6c, 0xdb, 0x18, 0xa7, 0xca, 0x82, 0x18, 0xe8, 0x6e, 0x4b, 0x4b, 0x71, 0x6a, 0x4d, 0x04, 0x37, + 0x1f, 0xbe, 0xc2, 0x62, 0xfc, 0x5a, 0xd0, 0xb3, 0x81, 0x9b, 0x18, 0x7b, 0x97, 0xe5, 0x5b, 0x1a, + 0x4d, 0x7c, 0x19, 0xee, 0x24, 0xc8, 0xb4, 0xd7, 0x72, 0x3c, 0xfe, 0xdf, 0x04, 0x5b, 0x8a, 0xca, + 0xe4, 0x86, 0x95, 0x17, 0xd8, 0x0e, 0x50, 0x61, 0x5d, 0x90, 0x35, 0xd5, 0xd9, 0xc5, 0xa4, 0x0a, + 0xf6, 0x02, 0x28, 0x0b, 0x54, 0x25, 0x97, 0xb0, 0xcb, 0x18, 0x61, 0x9e, 0xeb, 0x35, 0x92, 0x57, + 0x59, 0xd1, 0x95, 0xe1, 0x00, 0xe8, 0xe4, 0xaa, 0x0c, 0x38, 0xa3, 0xc2, 0xab, 0xe0, 0xf3, 0xd8, + 0xff, 0x04, 0xf3, 0xc3, 0x3c, 0x29, 0x50, 0x69, 0xc2, 0x36, 0x94, 0xb5, 0xbb, 0xea, 0xcd, 0xd5, + 0x42, 0xe2, 0x8e, 0x8a, 0x94, 0xed, 0xb9, 0x11, 0x9f, 0x41, 0x2d, 0x05, 0x4b, 0xe1, 0xfa, 0x72, + 0x72, 0xb5, 0xff, 0xb2, 0xb2, 0x57, 0x0f, 0x4f, 0x7c, 0xea, 0xf3, 0x83, 0xa8, 0xa9, 0xd9, 0x35, + 0x72, 0xf0, 0x4d, 0x6e, 0x3a, 0x6e, 0x29, 0x37, 0x26, 0xec, 0x62, 0xc8}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea1(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -327,8 +259,7 @@ void test_set_5() assert(err_cmp == 0); // decryption - err_lte = liblte_security_decryption_eea1(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -341,135 +272,79 @@ void test_set_5() void test_set_6() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0x54, 0xf4, 0xe2, 0xe0, 0x4c, 0x83, 0x78, - 0x6e, 0xec, 0x8f, 0xb5, 0xab, 0xe8, 0xe3, 0x65, 0x66 }; - uint32_t count = 0xaca4f50f; - uint8_t bearer = 0x0b; - uint8_t direction = 0; + uint8_t key[] = {0x54, 0xf4, 0xe2, 0xe0, 0x4c, 0x83, 0x78, 0x6e, 0xec, 0x8f, 0xb5, 0xab, 0xe8, 0xe3, 0x65, 0x66}; + uint32_t count = 0xaca4f50f; + uint8_t bearer = 0x0b; + uint8_t direction = 0; uint32_t len_bits = 3861, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0x40, 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, - 0xfb, 0x42, 0x86, 0xb2, 0x99, 0x78, 0x3d, 0xaf, 0x44, - 0x2c, 0x09, 0x9f, 0x7a, 0xb0, 0xf5, 0x8d, 0x5c, 0x8e, - 0x46, 0xb1, 0x04, 0xf0, 0x8f, 0x01, 0xb4, 0x1a, 0xb4, - 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x36, 0xbd, 0x1a, - 0x3d, 0x90, 0xdc, 0x3a, 0x41, 0xb4, 0x6d, 0x51, 0x67, - 0x2a, 0xc4, 0xc9, 0x66, 0x3a, 0x2b, 0xe0, 0x63, 0xda, - 0x4b, 0xc8, 0xd2, 0x80, 0x8c, 0xe3, 0x3e, 0x2c, 0xcc, - 0xbf, 0xc6, 0x34, 0xe1, 0xb2, 0x59, 0x06, 0x08, 0x76, - 0xa0, 0xfb, 0xb5, 0xa4, 0x37, 0xeb, 0xcc, 0x8d, 0x31, - 0xc1, 0x9e, 0x44, 0x54, 0x31, 0x87, 0x45, 0xe3, 0xfa, - 0x16, 0xbb, 0x11, 0xad, 0xae, 0x24, 0x88, 0x79, 0xfe, - 0x52, 0xdb, 0x25, 0x43, 0xe5, 0x3c, 0xf4, 0x45, 0xd3, - 0xd8, 0x28, 0xce, 0x0b, 0xf5, 0xc5, 0x60, 0x59, 0x3d, - 0x97, 0x27, 0x8a, 0x59, 0x76, 0x2d, 0xd0, 0xc2, 0xc9, - 0xcd, 0x68, 0xd4, 0x49, 0x6a, 0x79, 0x25, 0x08, 0x61, - 0x40, 0x14, 0xb1, 0x3b, 0x6a, 0xa5, 0x11, 0x28, 0xc1, - 0x8c, 0xd6, 0xa9, 0x0b, 0x87, 0x97, 0x8c, 0x2f, 0xf1, - 0xca, 0xbe, 0x7d, 0x9f, 0x89, 0x8a, 0x41, 0x1b, 0xfd, - 0xb8, 0x4f, 0x68, 0xf6, 0x72, 0x7b, 0x14, 0x99, 0xcd, - 0xd3, 0x0d, 0xf0, 0x44, 0x3a, 0xb4, 0xa6, 0x66, 0x53, - 0x33, 0x0b, 0xcb, 0xa1, 0x10, 0x5e, 0x4c, 0xec, 0x03, - 0x4c, 0x73, 0xe6, 0x05, 0xb4, 0x31, 0x0e, 0xaa, 0xad, - 0xcf, 0xd5, 0xb0, 0xca, 0x27, 0xff, 0xd8, 0x9d, 0x14, - 0x4d, 0xf4, 0x79, 0x27, 0x59, 0x42, 0x7c, 0x9c, 0xc1, - 0xf8, 0xcd, 0x8c, 0x87, 0x20, 0x23, 0x64, 0xb8, 0xa6, - 0x87, 0x95, 0x4c, 0xb0, 0x5a, 0x8d, 0x4e, 0x2d, 0x99, - 0xe7, 0x3d, 0xb1, 0x60, 0xde, 0xb1, 0x80, 0xad, 0x08, - 0x41, 0xe9, 0x67, 0x41, 0xa5, 0xd5, 0x9f, 0xe4, 0x18, - 0x9f, 0x15, 0x42, 0x00, 0x26, 0xfe, 0x4c, 0xd1, 0x21, - 0x04, 0x93, 0x2f, 0xb3, 0x8f, 0x73, 0x53, 0x40, 0x43, - 0x8a, 0xaf, 0x7e, 0xca, 0x6f, 0xd5, 0xcf, 0xd3, 0xa1, - 0x95, 0xce, 0x5a, 0xbe, 0x65, 0x27, 0x2a, 0xf6, 0x07, - 0xad, 0xa1, 0xbe, 0x65, 0xa6, 0xb4, 0xc9, 0xc0, 0x69, - 0x32, 0x34, 0x09, 0x2c, 0x4d, 0x01, 0x8f, 0x17, 0x56, - 0xc6, 0xdb, 0x9d, 0xc8, 0xa6, 0xd8, 0x0b, 0x88, 0x81, - 0x38, 0x61, 0x6b, 0x68, 0x12, 0x62, 0xf9, 0x54, 0xd0, - 0xe7, 0x71, 0x17, 0x48, 0x78, 0x0d, 0x92, 0x29, 0x1d, - 0x86, 0x29, 0x99, 0x72, 0xdb, 0x74, 0x1c, 0xfa, 0x4f, - 0x37, 0xb8, 0xb5, 0x6c, 0xdb, 0x18, 0xa7, 0xca, 0x82, - 0x18, 0xe8, 0x6e, 0x4b, 0x4b, 0x71, 0x6a, 0x4d, 0x04, - 0x37, 0x1f, 0xbe, 0xc2, 0x62, 0xfc, 0x5a, 0xd0, 0xb3, - 0x81, 0x9b, 0x18, 0x7b, 0x97, 0xe5, 0x5b, 0x1a, 0x4d, - 0x7c, 0x19, 0xee, 0x24, 0xc8, 0xb4, 0xd7, 0x72, 0x3c, - 0xfe, 0xdf, 0x04, 0x5b, 0x8a, 0xca, 0xe4, 0x86, 0x95, - 0x17, 0xd8, 0x0e, 0x50, 0x61, 0x5d, 0x90, 0x35, 0xd5, - 0xd9, 0xc5, 0xa4, 0x0a, 0xf6, 0x02, 0x28, 0x0b, 0x54, - 0x25, 0x97, 0xb0, 0xcb, 0x18, 0x61, 0x9e, 0xeb, 0x35, - 0x92, 0x57, 0x59, 0xd1, 0x95, 0xe1, 0x00, 0xe8, 0xe4, - 0xaa, 0x0c, 0x38, 0xa3, 0xc2, 0xab, 0xe0, 0xf3, 0xd8, - 0xff, 0x04, 0xf3, 0xc3, 0x3c, 0x29, 0x50, 0x69, 0xc2, - 0x36, 0x94, 0xb5, 0xbb, 0xea, 0xcd, 0xd5, 0x42, 0xe2, - 0x8e, 0x8a, 0x94, 0xed, 0xb9, 0x11, 0x9f, 0x41, 0x2d, - 0x05, 0x4b, 0xe1, 0xfa, 0x72, 0xb0, 0x95, 0x50 }; - uint8_t ct[] = { 0x35, 0x1e, 0x30, 0xd4, 0xd9, 0x10, 0xc5, - 0xdd, 0x5a, 0xd7, 0x83, 0x4c, 0x42, 0x6e, 0x6c, 0x0c, - 0xab, 0x64, 0x86, 0xda, 0x7b, 0x0f, 0xda, 0x4c, 0xd8, - 0x3a, 0xf1, 0xb9, 0x64, 0x71, 0x37, 0xf1, 0xac, 0x43, - 0xb4, 0x34, 0x22, 0x3b, 0x19, 0xbe, 0x07, 0xbd, 0x89, - 0xd1, 0xcc, 0x30, 0x69, 0x44, 0xd3, 0x36, 0x1e, 0xa1, - 0xa2, 0xf8, 0xcd, 0xbd, 0x32, 0x16, 0x55, 0x97, 0x63, - 0x50, 0xd0, 0x0b, 0x80, 0xdd, 0x83, 0x81, 0x20, 0xa7, - 0x75, 0x5c, 0x6d, 0xea, 0x2a, 0xb2, 0xb0, 0xc9, 0x9a, - 0x91, 0x3f, 0x47, 0xda, 0xe2, 0xb8, 0xde, 0xb9, 0xa8, - 0x29, 0xe5, 0x46, 0x9f, 0xf2, 0xe1, 0x87, 0x77, 0x6f, - 0x6f, 0xd0, 0x81, 0xe3, 0x87, 0x1d, 0x11, 0x9a, 0x76, - 0xe2, 0x4c, 0x91, 0x7e, 0xa6, 0x26, 0x48, 0xe0, 0x2e, - 0x90, 0x36, 0x75, 0x64, 0xde, 0x72, 0xae, 0x7e, 0x4f, - 0x0a, 0x42, 0x49, 0xa9, 0xa5, 0xb0, 0xe4, 0x65, 0xa2, - 0xd6, 0xd9, 0xdc, 0x87, 0x84, 0x3b, 0x1b, 0x87, 0x5c, - 0xc9, 0xa3, 0xbe, 0x93, 0xd8, 0xda, 0x8f, 0x56, 0xec, - 0xaf, 0x59, 0x81, 0xfe, 0x93, 0xc2, 0x84, 0x31, 0x8b, - 0x0d, 0xec, 0x7a, 0x3b, 0xa1, 0x08, 0xe2, 0xcb, 0x1a, - 0x61, 0xe9, 0x66, 0xfa, 0x7a, 0xfa, 0x7a, 0xc7, 0xf6, - 0x7f, 0x65, 0xbc, 0x4a, 0x2d, 0xf0, 0x70, 0xd4, 0xe4, - 0x34, 0x84, 0x5f, 0x10, 0x9a, 0xb2, 0xb6, 0x8a, 0xde, - 0x3d, 0xc3, 0x16, 0xca, 0x63, 0x32, 0xa6, 0x28, 0x93, - 0xe0, 0xa7, 0xec, 0x0b, 0x4f, 0xc2, 0x51, 0x91, 0xbf, - 0x2f, 0xf1, 0xb9, 0xf9, 0x81, 0x5e, 0x4b, 0xa8, 0xa9, - 0x9c, 0x64, 0x3b, 0x52, 0x18, 0x04, 0xf7, 0xd5, 0x85, - 0x0d, 0xde, 0x39, 0x52, 0x20, 0x6e, 0xc6, 0xcc, 0xf3, - 0x40, 0xf9, 0xb3, 0x22, 0x0b, 0x30, 0x23, 0xbd, 0xd0, - 0x63, 0x95, 0x6e, 0xa8, 0x33, 0x39, 0x20, 0xfd, 0xe9, - 0x9e, 0x06, 0x75, 0x41, 0x0e, 0x49, 0xef, 0x3b, 0x4d, - 0x3f, 0xb3, 0xdf, 0x51, 0x92, 0xf9, 0x9c, 0xa8, 0x3d, - 0x3b, 0x00, 0x32, 0xde, 0x08, 0xc2, 0x20, 0x77, 0x6a, - 0x58, 0x65, 0xb0, 0xe4, 0xb3, 0xb0, 0xc7, 0x5d, 0xef, - 0xe7, 0x76, 0x2d, 0xff, 0x01, 0x8e, 0xa7, 0xf5, 0xbe, - 0x2b, 0x2f, 0x97, 0x2b, 0x2a, 0x8b, 0xa5, 0x97, 0x0e, - 0x43, 0xbd, 0x6f, 0xdd, 0x63, 0xda, 0xe6, 0x29, 0x78, - 0x4e, 0xc4, 0x8d, 0x61, 0x00, 0x54, 0xee, 0x4e, 0x4b, - 0x5d, 0xbb, 0xf1, 0xfc, 0x2f, 0xa0, 0xb8, 0x30, 0xe9, - 0x4d, 0xcb, 0xb7, 0x01, 0x4e, 0x8a, 0xb4, 0x29, 0xab, - 0x10, 0x0f, 0xc4, 0x8f, 0x83, 0x17, 0x1d, 0x99, 0xfc, - 0x25, 0x8b, 0x7c, 0x2b, 0xa7, 0xc1, 0x76, 0xea, 0xea, - 0xad, 0x37, 0xf8, 0x60, 0xd5, 0x97, 0xa3, 0x1c, 0xe7, - 0x9b, 0x59, 0x47, 0x33, 0xc7, 0x14, 0x1d, 0xf7, 0x91, - 0x51, 0xfc, 0xa9, 0x0c, 0x08, 0x47, 0x8a, 0x5c, 0x6c, - 0x2c, 0xc4, 0x81, 0xd5, 0x1f, 0xfe, 0xce, 0x3c, 0xd7, - 0xd2, 0x58, 0x13, 0x48, 0x82, 0x7a, 0x71, 0xf0, 0x91, - 0x42, 0x8e, 0xbe, 0x38, 0xc9, 0x5a, 0x3f, 0x5c, 0x63, - 0xe0, 0x56, 0xdf, 0xb7, 0xcc, 0x45, 0xa9, 0xb7, 0xc0, - 0x7d, 0x83, 0x4e, 0x7b, 0x20, 0xb9, 0x9e, 0xd2, 0x02, - 0x42, 0x9c, 0x14, 0xbb, 0x85, 0xff, 0xa4, 0x3b, 0x7c, - 0xb6, 0x84, 0x95, 0xcd, 0x75, 0xab, 0x66, 0xd9, 0x64, - 0xd4, 0xca, 0xfe, 0x64, 0xdd, 0x94, 0x04, 0xda, 0xe2, - 0xdc, 0x51, 0x10, 0x61, 0x7f, 0x19, 0x4f, 0xc3, 0xc1, - 0x84, 0xf5, 0x83, 0xcd, 0x0d, 0xef, 0x6d, 0x00 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = { + 0x40, 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, 0x42, 0x86, 0xb2, 0x99, 0x78, 0x3d, 0xaf, 0x44, 0x2c, 0x09, 0x9f, + 0x7a, 0xb0, 0xf5, 0x8d, 0x5c, 0x8e, 0x46, 0xb1, 0x04, 0xf0, 0x8f, 0x01, 0xb4, 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, + 0xb7, 0x1d, 0x36, 0xbd, 0x1a, 0x3d, 0x90, 0xdc, 0x3a, 0x41, 0xb4, 0x6d, 0x51, 0x67, 0x2a, 0xc4, 0xc9, 0x66, 0x3a, + 0x2b, 0xe0, 0x63, 0xda, 0x4b, 0xc8, 0xd2, 0x80, 0x8c, 0xe3, 0x3e, 0x2c, 0xcc, 0xbf, 0xc6, 0x34, 0xe1, 0xb2, 0x59, + 0x06, 0x08, 0x76, 0xa0, 0xfb, 0xb5, 0xa4, 0x37, 0xeb, 0xcc, 0x8d, 0x31, 0xc1, 0x9e, 0x44, 0x54, 0x31, 0x87, 0x45, + 0xe3, 0xfa, 0x16, 0xbb, 0x11, 0xad, 0xae, 0x24, 0x88, 0x79, 0xfe, 0x52, 0xdb, 0x25, 0x43, 0xe5, 0x3c, 0xf4, 0x45, + 0xd3, 0xd8, 0x28, 0xce, 0x0b, 0xf5, 0xc5, 0x60, 0x59, 0x3d, 0x97, 0x27, 0x8a, 0x59, 0x76, 0x2d, 0xd0, 0xc2, 0xc9, + 0xcd, 0x68, 0xd4, 0x49, 0x6a, 0x79, 0x25, 0x08, 0x61, 0x40, 0x14, 0xb1, 0x3b, 0x6a, 0xa5, 0x11, 0x28, 0xc1, 0x8c, + 0xd6, 0xa9, 0x0b, 0x87, 0x97, 0x8c, 0x2f, 0xf1, 0xca, 0xbe, 0x7d, 0x9f, 0x89, 0x8a, 0x41, 0x1b, 0xfd, 0xb8, 0x4f, + 0x68, 0xf6, 0x72, 0x7b, 0x14, 0x99, 0xcd, 0xd3, 0x0d, 0xf0, 0x44, 0x3a, 0xb4, 0xa6, 0x66, 0x53, 0x33, 0x0b, 0xcb, + 0xa1, 0x10, 0x5e, 0x4c, 0xec, 0x03, 0x4c, 0x73, 0xe6, 0x05, 0xb4, 0x31, 0x0e, 0xaa, 0xad, 0xcf, 0xd5, 0xb0, 0xca, + 0x27, 0xff, 0xd8, 0x9d, 0x14, 0x4d, 0xf4, 0x79, 0x27, 0x59, 0x42, 0x7c, 0x9c, 0xc1, 0xf8, 0xcd, 0x8c, 0x87, 0x20, + 0x23, 0x64, 0xb8, 0xa6, 0x87, 0x95, 0x4c, 0xb0, 0x5a, 0x8d, 0x4e, 0x2d, 0x99, 0xe7, 0x3d, 0xb1, 0x60, 0xde, 0xb1, + 0x80, 0xad, 0x08, 0x41, 0xe9, 0x67, 0x41, 0xa5, 0xd5, 0x9f, 0xe4, 0x18, 0x9f, 0x15, 0x42, 0x00, 0x26, 0xfe, 0x4c, + 0xd1, 0x21, 0x04, 0x93, 0x2f, 0xb3, 0x8f, 0x73, 0x53, 0x40, 0x43, 0x8a, 0xaf, 0x7e, 0xca, 0x6f, 0xd5, 0xcf, 0xd3, + 0xa1, 0x95, 0xce, 0x5a, 0xbe, 0x65, 0x27, 0x2a, 0xf6, 0x07, 0xad, 0xa1, 0xbe, 0x65, 0xa6, 0xb4, 0xc9, 0xc0, 0x69, + 0x32, 0x34, 0x09, 0x2c, 0x4d, 0x01, 0x8f, 0x17, 0x56, 0xc6, 0xdb, 0x9d, 0xc8, 0xa6, 0xd8, 0x0b, 0x88, 0x81, 0x38, + 0x61, 0x6b, 0x68, 0x12, 0x62, 0xf9, 0x54, 0xd0, 0xe7, 0x71, 0x17, 0x48, 0x78, 0x0d, 0x92, 0x29, 0x1d, 0x86, 0x29, + 0x99, 0x72, 0xdb, 0x74, 0x1c, 0xfa, 0x4f, 0x37, 0xb8, 0xb5, 0x6c, 0xdb, 0x18, 0xa7, 0xca, 0x82, 0x18, 0xe8, 0x6e, + 0x4b, 0x4b, 0x71, 0x6a, 0x4d, 0x04, 0x37, 0x1f, 0xbe, 0xc2, 0x62, 0xfc, 0x5a, 0xd0, 0xb3, 0x81, 0x9b, 0x18, 0x7b, + 0x97, 0xe5, 0x5b, 0x1a, 0x4d, 0x7c, 0x19, 0xee, 0x24, 0xc8, 0xb4, 0xd7, 0x72, 0x3c, 0xfe, 0xdf, 0x04, 0x5b, 0x8a, + 0xca, 0xe4, 0x86, 0x95, 0x17, 0xd8, 0x0e, 0x50, 0x61, 0x5d, 0x90, 0x35, 0xd5, 0xd9, 0xc5, 0xa4, 0x0a, 0xf6, 0x02, + 0x28, 0x0b, 0x54, 0x25, 0x97, 0xb0, 0xcb, 0x18, 0x61, 0x9e, 0xeb, 0x35, 0x92, 0x57, 0x59, 0xd1, 0x95, 0xe1, 0x00, + 0xe8, 0xe4, 0xaa, 0x0c, 0x38, 0xa3, 0xc2, 0xab, 0xe0, 0xf3, 0xd8, 0xff, 0x04, 0xf3, 0xc3, 0x3c, 0x29, 0x50, 0x69, + 0xc2, 0x36, 0x94, 0xb5, 0xbb, 0xea, 0xcd, 0xd5, 0x42, 0xe2, 0x8e, 0x8a, 0x94, 0xed, 0xb9, 0x11, 0x9f, 0x41, 0x2d, + 0x05, 0x4b, 0xe1, 0xfa, 0x72, 0xb0, 0x95, 0x50}; + uint8_t ct[] = { + 0x35, 0x1e, 0x30, 0xd4, 0xd9, 0x10, 0xc5, 0xdd, 0x5a, 0xd7, 0x83, 0x4c, 0x42, 0x6e, 0x6c, 0x0c, 0xab, 0x64, 0x86, + 0xda, 0x7b, 0x0f, 0xda, 0x4c, 0xd8, 0x3a, 0xf1, 0xb9, 0x64, 0x71, 0x37, 0xf1, 0xac, 0x43, 0xb4, 0x34, 0x22, 0x3b, + 0x19, 0xbe, 0x07, 0xbd, 0x89, 0xd1, 0xcc, 0x30, 0x69, 0x44, 0xd3, 0x36, 0x1e, 0xa1, 0xa2, 0xf8, 0xcd, 0xbd, 0x32, + 0x16, 0x55, 0x97, 0x63, 0x50, 0xd0, 0x0b, 0x80, 0xdd, 0x83, 0x81, 0x20, 0xa7, 0x75, 0x5c, 0x6d, 0xea, 0x2a, 0xb2, + 0xb0, 0xc9, 0x9a, 0x91, 0x3f, 0x47, 0xda, 0xe2, 0xb8, 0xde, 0xb9, 0xa8, 0x29, 0xe5, 0x46, 0x9f, 0xf2, 0xe1, 0x87, + 0x77, 0x6f, 0x6f, 0xd0, 0x81, 0xe3, 0x87, 0x1d, 0x11, 0x9a, 0x76, 0xe2, 0x4c, 0x91, 0x7e, 0xa6, 0x26, 0x48, 0xe0, + 0x2e, 0x90, 0x36, 0x75, 0x64, 0xde, 0x72, 0xae, 0x7e, 0x4f, 0x0a, 0x42, 0x49, 0xa9, 0xa5, 0xb0, 0xe4, 0x65, 0xa2, + 0xd6, 0xd9, 0xdc, 0x87, 0x84, 0x3b, 0x1b, 0x87, 0x5c, 0xc9, 0xa3, 0xbe, 0x93, 0xd8, 0xda, 0x8f, 0x56, 0xec, 0xaf, + 0x59, 0x81, 0xfe, 0x93, 0xc2, 0x84, 0x31, 0x8b, 0x0d, 0xec, 0x7a, 0x3b, 0xa1, 0x08, 0xe2, 0xcb, 0x1a, 0x61, 0xe9, + 0x66, 0xfa, 0x7a, 0xfa, 0x7a, 0xc7, 0xf6, 0x7f, 0x65, 0xbc, 0x4a, 0x2d, 0xf0, 0x70, 0xd4, 0xe4, 0x34, 0x84, 0x5f, + 0x10, 0x9a, 0xb2, 0xb6, 0x8a, 0xde, 0x3d, 0xc3, 0x16, 0xca, 0x63, 0x32, 0xa6, 0x28, 0x93, 0xe0, 0xa7, 0xec, 0x0b, + 0x4f, 0xc2, 0x51, 0x91, 0xbf, 0x2f, 0xf1, 0xb9, 0xf9, 0x81, 0x5e, 0x4b, 0xa8, 0xa9, 0x9c, 0x64, 0x3b, 0x52, 0x18, + 0x04, 0xf7, 0xd5, 0x85, 0x0d, 0xde, 0x39, 0x52, 0x20, 0x6e, 0xc6, 0xcc, 0xf3, 0x40, 0xf9, 0xb3, 0x22, 0x0b, 0x30, + 0x23, 0xbd, 0xd0, 0x63, 0x95, 0x6e, 0xa8, 0x33, 0x39, 0x20, 0xfd, 0xe9, 0x9e, 0x06, 0x75, 0x41, 0x0e, 0x49, 0xef, + 0x3b, 0x4d, 0x3f, 0xb3, 0xdf, 0x51, 0x92, 0xf9, 0x9c, 0xa8, 0x3d, 0x3b, 0x00, 0x32, 0xde, 0x08, 0xc2, 0x20, 0x77, + 0x6a, 0x58, 0x65, 0xb0, 0xe4, 0xb3, 0xb0, 0xc7, 0x5d, 0xef, 0xe7, 0x76, 0x2d, 0xff, 0x01, 0x8e, 0xa7, 0xf5, 0xbe, + 0x2b, 0x2f, 0x97, 0x2b, 0x2a, 0x8b, 0xa5, 0x97, 0x0e, 0x43, 0xbd, 0x6f, 0xdd, 0x63, 0xda, 0xe6, 0x29, 0x78, 0x4e, + 0xc4, 0x8d, 0x61, 0x00, 0x54, 0xee, 0x4e, 0x4b, 0x5d, 0xbb, 0xf1, 0xfc, 0x2f, 0xa0, 0xb8, 0x30, 0xe9, 0x4d, 0xcb, + 0xb7, 0x01, 0x4e, 0x8a, 0xb4, 0x29, 0xab, 0x10, 0x0f, 0xc4, 0x8f, 0x83, 0x17, 0x1d, 0x99, 0xfc, 0x25, 0x8b, 0x7c, + 0x2b, 0xa7, 0xc1, 0x76, 0xea, 0xea, 0xad, 0x37, 0xf8, 0x60, 0xd5, 0x97, 0xa3, 0x1c, 0xe7, 0x9b, 0x59, 0x47, 0x33, + 0xc7, 0x14, 0x1d, 0xf7, 0x91, 0x51, 0xfc, 0xa9, 0x0c, 0x08, 0x47, 0x8a, 0x5c, 0x6c, 0x2c, 0xc4, 0x81, 0xd5, 0x1f, + 0xfe, 0xce, 0x3c, 0xd7, 0xd2, 0x58, 0x13, 0x48, 0x82, 0x7a, 0x71, 0xf0, 0x91, 0x42, 0x8e, 0xbe, 0x38, 0xc9, 0x5a, + 0x3f, 0x5c, 0x63, 0xe0, 0x56, 0xdf, 0xb7, 0xcc, 0x45, 0xa9, 0xb7, 0xc0, 0x7d, 0x83, 0x4e, 0x7b, 0x20, 0xb9, 0x9e, + 0xd2, 0x02, 0x42, 0x9c, 0x14, 0xbb, 0x85, 0xff, 0xa4, 0x3b, 0x7c, 0xb6, 0x84, 0x95, 0xcd, 0x75, 0xab, 0x66, 0xd9, + 0x64, 0xd4, 0xca, 0xfe, 0x64, 0xdd, 0x94, 0x04, 0xda, 0xe2, 0xdc, 0x51, 0x10, 0x61, 0x7f, 0x19, 0x4f, 0xc3, 0xc1, + 0x84, 0xf5, 0x83, 0xcd, 0x0d, 0xef, 0x6d, 0x00}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); struct timeval t[3]; // encryption gettimeofday(&t[1], NULL); - err_lte = liblte_security_encryption_eea1(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); gettimeofday(&t[2], NULL); get_time_interval(t); - printf("encryption: %u bits, t=%d us, rate=%.1f Mbps/s\n", len_bits, (int) t[0].tv_usec, (float) len_bits/t[0].tv_usec); + printf( + "encryption: %u bits, t=%d us, rate=%.1f Mbps/s\n", len_bits, (int)t[0].tv_usec, (float)len_bits / t[0].tv_usec); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -478,11 +353,11 @@ void test_set_6() // decryption gettimeofday(&t[1], NULL); - err_lte = liblte_security_decryption_eea1(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); gettimeofday(&t[2], NULL); get_time_interval(t); - printf("decryption: %u bits, t=%d us, rate=%.1f Mbps/s\n", len_bits, (int) t[0].tv_usec, (float) len_bits/t[0].tv_usec); + printf( + "decryption: %u bits, t=%d us, rate=%.1f Mbps/s\n", len_bits, (int)t[0].tv_usec, (float)len_bits / t[0].tv_usec); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -496,29 +371,22 @@ void test_set_6() void test_set_1_block_size() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1, - 0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1 }; - uint32_t count = 0x398a59b4; - uint8_t bearer = 0x15; - uint8_t direction = 1; + uint8_t key[] = {0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1, 0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1}; + uint32_t count = 0x398a59b4; + uint8_t bearer = 0x15; + uint8_t direction = 1; uint32_t len_bits = 256, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, - 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80, - 0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f, - 0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0 }; - uint8_t ct[] = { 0x5d, 0x5b, 0xfe, 0x75, 0xeb, 0x04, 0xf6, - 0x8c, 0xe0, 0xa1, 0x23, 0x77, 0xea, 0x00, 0xb3, 0x7d, - 0x47, 0xc6, 0xa0, 0xba, 0x06, 0x30, 0x91, 0x55, 0x08, - 0x6a, 0x85, 0x9c, 0x43, 0x41, 0xb3, 0x7c }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80, + 0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f, 0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0}; + uint8_t ct[] = {0x5d, 0x5b, 0xfe, 0x75, 0xeb, 0x04, 0xf6, 0x8c, 0xe0, 0xa1, 0x23, 0x77, 0xea, 0x00, 0xb3, 0x7d, + 0x47, 0xc6, 0xa0, 0xba, 0x06, 0x30, 0x91, 0x55, 0x08, 0x6a, 0x85, 0x9c, 0x43, 0x41, 0xb3, 0x7c}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea1(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -526,8 +394,7 @@ void test_set_1_block_size() assert(err_cmp == 0); // decryption - err_lte = liblte_security_decryption_eea1(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -541,29 +408,22 @@ void test_set_1_block_size() void test_set_1_invalid() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1, - 0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1 }; - uint32_t count = 0x398a59b4; - uint8_t bearer = 0x15; - uint8_t direction = 1; + uint8_t key[] = {0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1, 0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1}; + uint32_t count = 0x398a59b4; + uint8_t bearer = 0x15; + uint8_t direction = 1; uint32_t len_bits = 253, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0x99, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, - 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80, - 0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f, - 0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0 }; - uint8_t ct[] = { 0x5d, 0x5b, 0xfe, 0x75, 0xeb, 0x04, 0xf6, - 0x8c, 0xe0, 0xa1, 0x23, 0x77, 0xea, 0x00, 0xb3, 0x7d, - 0x47, 0xc6, 0xa0, 0xba, 0x06, 0x30, 0x91, 0x55, 0x08, - 0x6a, 0x85, 0x9c, 0x43, 0x41, 0xb3, 0x78 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0x99, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80, + 0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f, 0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0}; + uint8_t ct[] = {0x5d, 0x5b, 0xfe, 0x75, 0xeb, 0x04, 0xf6, 0x8c, 0xe0, 0xa1, 0x23, 0x77, 0xea, 0x00, 0xb3, 0x7d, + 0x47, 0xc6, 0xa0, 0xba, 0x06, 0x30, 0x91, 0x55, 0x08, 0x6a, 0x85, 0x9c, 0x43, 0x41, 0xb3, 0x78}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea1(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -571,8 +431,7 @@ void test_set_1_invalid() assert(err_cmp != 0); // decryption - err_lte = liblte_security_decryption_eea1(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -586,7 +445,8 @@ void test_set_1_invalid() * Functions */ -int main(int argc, char * argv[]) { +int main(int argc, char* argv[]) +{ test_set_1(); test_set_2(); test_set_3(); diff --git a/lib/test/common/test_eea2.cc b/lib/test/common/test_eea2.cc index c3969c080..35d8cf347 100644 --- a/lib/test/common/test_eea2.cc +++ b/lib/test/common/test_eea2.cc @@ -30,15 +30,16 @@ * Prototypes */ -int32 arrcmp(uint8_t const * const a, uint8_t const * const b, uint32 len) { +int32 arrcmp(uint8_t const* const a, uint8_t const* const b, uint32 len) +{ uint32 i = 0; - for (i = 0; i < len; i++) { - if (a[i] != b[i]) { - return a[i] - b[i]; - } - } - return 0; + for (i = 0; i < len; i++) { + if (a[i] != b[i]) { + return a[i] - b[i]; + } + } + return 0; } /* @@ -50,29 +51,22 @@ int32 arrcmp(uint8_t const * const a, uint8_t const * const b, uint32 len) { void test_set_1() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1, - 0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1 }; - uint32_t count = 0x398a59b4; - uint8_t bearer = 0x15; - uint8_t direction = 1; + uint8_t key[] = {0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1, 0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1}; + uint32_t count = 0x398a59b4; + uint8_t bearer = 0x15; + uint8_t direction = 1; uint32_t len_bits = 253, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, - 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80, - 0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f, - 0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0 }; - uint8_t ct[] = { 0xe9, 0xfe, 0xd8, 0xa6, 0x3d, 0x15, 0x53, - 0x04, 0xd7, 0x1d, 0xf2, 0x0b, 0xf3, 0xe8, 0x22, 0x14, - 0xb2, 0x0e, 0xd7, 0xda, 0xd2, 0xf2, 0x33, 0xdc, 0x3c, - 0x22, 0xd7, 0xbd, 0xee, 0xed, 0x8e, 0x78 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80, + 0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f, 0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0}; + uint8_t ct[] = {0xe9, 0xfe, 0xd8, 0xa6, 0x3d, 0x15, 0x53, 0x04, 0xd7, 0x1d, 0xf2, 0x0b, 0xf3, 0xe8, 0x22, 0x14, + 0xb2, 0x0e, 0xd7, 0xda, 0xd2, 0xf2, 0x33, 0xdc, 0x3c, 0x22, 0xd7, 0xbd, 0xee, 0xed, 0x8e, 0x78}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea2(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -80,8 +74,7 @@ void test_set_1() assert(err_cmp == 0); // decryption - err_lte = liblte_security_decryption_eea2(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -94,45 +87,30 @@ void test_set_1() void test_set_2() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0x2b, 0xd6, 0x45, 0x9f, 0x82, 0xc4, 0x40, - 0xe0, 0x95, 0x2c, 0x49, 0x10, 0x48, 0x05, 0xff, 0x48 }; - uint32_t count = 0xc675a64b; - uint8_t bearer = 0x0c; - uint8_t direction = 1; + uint8_t key[] = {0x2b, 0xd6, 0x45, 0x9f, 0x82, 0xc4, 0x40, 0xe0, 0x95, 0x2c, 0x49, 0x10, 0x48, 0x05, 0xff, 0x48}; + uint32_t count = 0xc675a64b; + uint8_t bearer = 0x0c; + uint8_t direction = 1; uint32_t len_bits = 798, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0x7e, 0xc6, 0x12, 0x72, 0x74, 0x3b, 0xf1, - 0x61, 0x47, 0x26, 0x44, 0x6a, 0x6c, 0x38, 0xce, 0xd1, - 0x66, 0xf6, 0xca, 0x76, 0xeb, 0x54, 0x30, 0x04, 0x42, - 0x86, 0x34, 0x6c, 0xef, 0x13, 0x0f, 0x92, 0x92, 0x2b, - 0x03, 0x45, 0x0d, 0x3a, 0x99, 0x75, 0xe5, 0xbd, 0x2e, - 0xa0, 0xeb, 0x55, 0xad, 0x8e, 0x1b, 0x19, 0x9e, 0x3e, - 0xc4, 0x31, 0x60, 0x20, 0xe9, 0xa1, 0xb2, 0x85, 0xe7, - 0x62, 0x79, 0x53, 0x59, 0xb7, 0xbd, 0xfd, 0x39, 0xbe, - 0xf4, 0xb2, 0x48, 0x45, 0x83, 0xd5, 0xaf, 0xe0, 0x82, - 0xae, 0xe6, 0x38, 0xbf, 0x5f, 0xd5, 0xa6, 0x06, 0x19, - 0x39, 0x01, 0xa0, 0x8f, 0x4a, 0xb4, 0x1a, 0xab, 0x9b, - 0x13, 0x48, 0x80 }; - uint8_t ct[] = { 0x59, 0x61, 0x60, 0x53, 0x53, 0xc6, 0x4b, - 0xdc, 0xa1, 0x5b, 0x19, 0x5e, 0x28, 0x85, 0x53, 0xa9, - 0x10, 0x63, 0x25, 0x06, 0xd6, 0x20, 0x0a, 0xa7, 0x90, - 0xc4, 0xc8, 0x06, 0xc9, 0x99, 0x04, 0xcf, 0x24, 0x45, - 0xcc, 0x50, 0xbb, 0x1c, 0xf1, 0x68, 0xa4, 0x96, 0x73, - 0x73, 0x4e, 0x08, 0x1b, 0x57, 0xe3, 0x24, 0xce, 0x52, - 0x59, 0xc0, 0xe7, 0x8d, 0x4c, 0xd9, 0x7b, 0x87, 0x09, - 0x76, 0x50, 0x3c, 0x09, 0x43, 0xf2, 0xcb, 0x5a, 0xe8, - 0xf0, 0x52, 0xc7, 0xb7, 0xd3, 0x92, 0x23, 0x95, 0x87, - 0xb8, 0x95, 0x60, 0x86, 0xbc, 0xab, 0x18, 0x83, 0x60, - 0x42, 0xe2, 0xe6, 0xce, 0x42, 0x43, 0x2a, 0x17, 0x10, - 0x5c, 0x53, 0xd0 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0x7e, 0xc6, 0x12, 0x72, 0x74, 0x3b, 0xf1, 0x61, 0x47, 0x26, 0x44, 0x6a, 0x6c, 0x38, 0xce, 0xd1, 0x66, + 0xf6, 0xca, 0x76, 0xeb, 0x54, 0x30, 0x04, 0x42, 0x86, 0x34, 0x6c, 0xef, 0x13, 0x0f, 0x92, 0x92, 0x2b, + 0x03, 0x45, 0x0d, 0x3a, 0x99, 0x75, 0xe5, 0xbd, 0x2e, 0xa0, 0xeb, 0x55, 0xad, 0x8e, 0x1b, 0x19, 0x9e, + 0x3e, 0xc4, 0x31, 0x60, 0x20, 0xe9, 0xa1, 0xb2, 0x85, 0xe7, 0x62, 0x79, 0x53, 0x59, 0xb7, 0xbd, 0xfd, + 0x39, 0xbe, 0xf4, 0xb2, 0x48, 0x45, 0x83, 0xd5, 0xaf, 0xe0, 0x82, 0xae, 0xe6, 0x38, 0xbf, 0x5f, 0xd5, + 0xa6, 0x06, 0x19, 0x39, 0x01, 0xa0, 0x8f, 0x4a, 0xb4, 0x1a, 0xab, 0x9b, 0x13, 0x48, 0x80}; + uint8_t ct[] = {0x59, 0x61, 0x60, 0x53, 0x53, 0xc6, 0x4b, 0xdc, 0xa1, 0x5b, 0x19, 0x5e, 0x28, 0x85, 0x53, 0xa9, 0x10, + 0x63, 0x25, 0x06, 0xd6, 0x20, 0x0a, 0xa7, 0x90, 0xc4, 0xc8, 0x06, 0xc9, 0x99, 0x04, 0xcf, 0x24, 0x45, + 0xcc, 0x50, 0xbb, 0x1c, 0xf1, 0x68, 0xa4, 0x96, 0x73, 0x73, 0x4e, 0x08, 0x1b, 0x57, 0xe3, 0x24, 0xce, + 0x52, 0x59, 0xc0, 0xe7, 0x8d, 0x4c, 0xd9, 0x7b, 0x87, 0x09, 0x76, 0x50, 0x3c, 0x09, 0x43, 0xf2, 0xcb, + 0x5a, 0xe8, 0xf0, 0x52, 0xc7, 0xb7, 0xd3, 0x92, 0x23, 0x95, 0x87, 0xb8, 0x95, 0x60, 0x86, 0xbc, 0xab, + 0x18, 0x83, 0x60, 0x42, 0xe2, 0xe6, 0xce, 0x42, 0x43, 0x2a, 0x17, 0x10, 0x5c, 0x53, 0xd0}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea2(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -140,8 +118,7 @@ void test_set_2() assert(err_cmp == 0); // decryption - err_lte = liblte_security_decryption_eea2(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -154,31 +131,24 @@ void test_set_2() void test_set_3() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0x0a, 0x8b, 0x6b, 0xd8, 0xd9, 0xb0, 0x8b, - 0x08, 0xd6, 0x4e, 0x32, 0xd1, 0x81, 0x77, 0x77, 0xfb }; - uint32_t count = 0x544d49cd; - uint8_t bearer = 0x04; - uint8_t direction = 0; + uint8_t key[] = {0x0a, 0x8b, 0x6b, 0xd8, 0xd9, 0xb0, 0x8b, 0x08, 0xd6, 0x4e, 0x32, 0xd1, 0x81, 0x77, 0x77, 0xfb}; + uint32_t count = 0x544d49cd; + uint8_t bearer = 0x04; + uint8_t direction = 0; uint32_t len_bits = 310, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0xfd, 0x40, 0xa4, 0x1d, 0x37, 0x0a, 0x1f, - 0x65, 0x74, 0x50, 0x95, 0x68, 0x7d, 0x47, 0xba, 0x1d, - 0x36, 0xd2, 0x34, 0x9e, 0x23, 0xf6, 0x44, 0x39, 0x2c, - 0x8e, 0xa9, 0xc4, 0x9d, 0x40, 0xc1, 0x32, 0x71, 0xaf, - 0xf2, 0x64, 0xd0, 0xf2, 0x48, 0x00 }; - uint8_t ct[] = { 0x75, 0x75, 0x0d, 0x37, 0xb4, 0xbb, 0xa2, - 0xa4, 0xde, 0xdb, 0x34, 0x23, 0x5b, 0xd6, 0x8c, 0x66, - 0x45, 0xac, 0xda, 0xac, 0xa4, 0x81, 0x38, 0xa3, 0xb0, - 0xc4, 0x71, 0xe2, 0xa7, 0x04, 0x1a, 0x57, 0x64, 0x23, - 0xd2, 0x92, 0x72, 0x87, 0xf0, 0x00 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0xfd, 0x40, 0xa4, 0x1d, 0x37, 0x0a, 0x1f, 0x65, 0x74, 0x50, 0x95, 0x68, 0x7d, 0x47, + 0xba, 0x1d, 0x36, 0xd2, 0x34, 0x9e, 0x23, 0xf6, 0x44, 0x39, 0x2c, 0x8e, 0xa9, 0xc4, + 0x9d, 0x40, 0xc1, 0x32, 0x71, 0xaf, 0xf2, 0x64, 0xd0, 0xf2, 0x48, 0x00}; + uint8_t ct[] = {0x75, 0x75, 0x0d, 0x37, 0xb4, 0xbb, 0xa2, 0xa4, 0xde, 0xdb, 0x34, 0x23, 0x5b, 0xd6, + 0x8c, 0x66, 0x45, 0xac, 0xda, 0xac, 0xa4, 0x81, 0x38, 0xa3, 0xb0, 0xc4, 0x71, 0xe2, + 0xa7, 0x04, 0x1a, 0x57, 0x64, 0x23, 0xd2, 0x92, 0x72, 0x87, 0xf0, 0x00}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea2(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -186,8 +156,7 @@ void test_set_3() assert(err_cmp == 0); // decryption - err_lte = liblte_security_decryption_eea2(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -200,51 +169,34 @@ void test_set_3() void test_set_4() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0xaa, 0x1f, 0x95, 0xae, 0xa5, 0x33, 0xbc, - 0xb3, 0x2e, 0xb6, 0x3b, 0xf5, 0x2d, 0x8f, 0x83, 0x1a }; - uint32_t count = 0x72d8c671; - uint8_t bearer = 0x10; - uint8_t direction = 1; + uint8_t key[] = {0xaa, 0x1f, 0x95, 0xae, 0xa5, 0x33, 0xbc, 0xb3, 0x2e, 0xb6, 0x3b, 0xf5, 0x2d, 0x8f, 0x83, 0x1a}; + uint32_t count = 0x72d8c671; + uint8_t bearer = 0x10; + uint8_t direction = 1; uint32_t len_bits = 1022, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0xfb, 0x1b, 0x96, 0xc5, 0xc8, 0xba, 0xdf, - 0xb2, 0xe8, 0xe8, 0xed, 0xfd, 0xe7, 0x8e, 0x57, 0xf2, - 0xad, 0x81, 0xe7, 0x41, 0x03, 0xfc, 0x43, 0x0a, 0x53, - 0x4d, 0xcc, 0x37, 0xaf, 0xce, 0xc7, 0x0e, 0x15, 0x17, - 0xbb, 0x06, 0xf2, 0x72, 0x19, 0xda, 0xe4, 0x90, 0x22, - 0xdd, 0xc4, 0x7a, 0x06, 0x8d, 0xe4, 0xc9, 0x49, 0x6a, - 0x95, 0x1a, 0x6b, 0x09, 0xed, 0xbd, 0xc8, 0x64, 0xc7, - 0xad, 0xbd, 0x74, 0x0a, 0xc5, 0x0c, 0x02, 0x2f, 0x30, - 0x82, 0xba, 0xfd, 0x22, 0xd7, 0x81, 0x97, 0xc5, 0xd5, - 0x08, 0xb9, 0x77, 0xbc, 0xa1, 0x3f, 0x32, 0xe6, 0x52, - 0xe7, 0x4b, 0xa7, 0x28, 0x57, 0x60, 0x77, 0xce, 0x62, - 0x8c, 0x53, 0x5e, 0x87, 0xdc, 0x60, 0x77, 0xba, 0x07, - 0xd2, 0x90, 0x68, 0x59, 0x0c, 0x8c, 0xb5, 0xf1, 0x08, - 0x8e, 0x08, 0x2c, 0xfa, 0x0e, 0xc9, 0x61, 0x30, 0x2d, - 0x69, 0xcf, 0x3d, 0x44 }; - uint8_t ct[] = { 0xdf, 0xb4, 0x40, 0xac, 0xb3, 0x77, 0x35, - 0x49, 0xef, 0xc0, 0x46, 0x28, 0xae, 0xb8, 0xd8, 0x15, - 0x62, 0x75, 0x23, 0x0b, 0xdc, 0x69, 0x0d, 0x94, 0xb0, - 0x0d, 0x8d, 0x95, 0xf2, 0x8c, 0x4b, 0x56, 0x30, 0x7f, - 0x60, 0xf4, 0xca, 0x55, 0xeb, 0xa6, 0x61, 0xeb, 0xba, - 0x72, 0xac, 0x80, 0x8f, 0xa8, 0xc4, 0x9e, 0x26, 0x78, - 0x8e, 0xd0, 0x4a, 0x5d, 0x60, 0x6c, 0xb4, 0x18, 0xde, - 0x74, 0x87, 0x8b, 0x9a, 0x22, 0xf8, 0xef, 0x29, 0x59, - 0x0b, 0xc4, 0xeb, 0x57, 0xc9, 0xfa, 0xf7, 0xc4, 0x15, - 0x24, 0xa8, 0x85, 0xb8, 0x97, 0x9c, 0x42, 0x3f, 0x2f, - 0x8f, 0x8e, 0x05, 0x92, 0xa9, 0x87, 0x92, 0x01, 0xbe, - 0x7f, 0xf9, 0x77, 0x7a, 0x16, 0x2a, 0xb8, 0x10, 0xfe, - 0xb3, 0x24, 0xba, 0x74, 0xc4, 0xc1, 0x56, 0xe0, 0x4d, - 0x39, 0x09, 0x72, 0x09, 0x65, 0x3a, 0xc3, 0x3e, 0x5a, - 0x5f, 0x2d, 0x88, 0x64 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0xfb, 0x1b, 0x96, 0xc5, 0xc8, 0xba, 0xdf, 0xb2, 0xe8, 0xe8, 0xed, 0xfd, 0xe7, 0x8e, 0x57, 0xf2, + 0xad, 0x81, 0xe7, 0x41, 0x03, 0xfc, 0x43, 0x0a, 0x53, 0x4d, 0xcc, 0x37, 0xaf, 0xce, 0xc7, 0x0e, + 0x15, 0x17, 0xbb, 0x06, 0xf2, 0x72, 0x19, 0xda, 0xe4, 0x90, 0x22, 0xdd, 0xc4, 0x7a, 0x06, 0x8d, + 0xe4, 0xc9, 0x49, 0x6a, 0x95, 0x1a, 0x6b, 0x09, 0xed, 0xbd, 0xc8, 0x64, 0xc7, 0xad, 0xbd, 0x74, + 0x0a, 0xc5, 0x0c, 0x02, 0x2f, 0x30, 0x82, 0xba, 0xfd, 0x22, 0xd7, 0x81, 0x97, 0xc5, 0xd5, 0x08, + 0xb9, 0x77, 0xbc, 0xa1, 0x3f, 0x32, 0xe6, 0x52, 0xe7, 0x4b, 0xa7, 0x28, 0x57, 0x60, 0x77, 0xce, + 0x62, 0x8c, 0x53, 0x5e, 0x87, 0xdc, 0x60, 0x77, 0xba, 0x07, 0xd2, 0x90, 0x68, 0x59, 0x0c, 0x8c, + 0xb5, 0xf1, 0x08, 0x8e, 0x08, 0x2c, 0xfa, 0x0e, 0xc9, 0x61, 0x30, 0x2d, 0x69, 0xcf, 0x3d, 0x44}; + uint8_t ct[] = {0xdf, 0xb4, 0x40, 0xac, 0xb3, 0x77, 0x35, 0x49, 0xef, 0xc0, 0x46, 0x28, 0xae, 0xb8, 0xd8, 0x15, + 0x62, 0x75, 0x23, 0x0b, 0xdc, 0x69, 0x0d, 0x94, 0xb0, 0x0d, 0x8d, 0x95, 0xf2, 0x8c, 0x4b, 0x56, + 0x30, 0x7f, 0x60, 0xf4, 0xca, 0x55, 0xeb, 0xa6, 0x61, 0xeb, 0xba, 0x72, 0xac, 0x80, 0x8f, 0xa8, + 0xc4, 0x9e, 0x26, 0x78, 0x8e, 0xd0, 0x4a, 0x5d, 0x60, 0x6c, 0xb4, 0x18, 0xde, 0x74, 0x87, 0x8b, + 0x9a, 0x22, 0xf8, 0xef, 0x29, 0x59, 0x0b, 0xc4, 0xeb, 0x57, 0xc9, 0xfa, 0xf7, 0xc4, 0x15, 0x24, + 0xa8, 0x85, 0xb8, 0x97, 0x9c, 0x42, 0x3f, 0x2f, 0x8f, 0x8e, 0x05, 0x92, 0xa9, 0x87, 0x92, 0x01, + 0xbe, 0x7f, 0xf9, 0x77, 0x7a, 0x16, 0x2a, 0xb8, 0x10, 0xfe, 0xb3, 0x24, 0xba, 0x74, 0xc4, 0xc1, + 0x56, 0xe0, 0x4d, 0x39, 0x09, 0x72, 0x09, 0x65, 0x3a, 0xc3, 0x3e, 0x5a, 0x5f, 0x2d, 0x88, 0x64}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea2(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -252,8 +204,7 @@ void test_set_4() assert(err_cmp == 0); // decryption - err_lte = liblte_security_decryption_eea2(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -266,57 +217,38 @@ void test_set_4() void test_set_5() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0x96, 0x18, 0xae, 0x46, 0x89, 0x1f, 0x86, - 0x57, 0x8e, 0xeb, 0xe9, 0x0e, 0xf7, 0xa1, 0x20, 0x2e }; - uint32_t count = 0xc675a64b; - uint8_t bearer = 0x0c; - uint8_t direction = 1; + uint8_t key[] = {0x96, 0x18, 0xae, 0x46, 0x89, 0x1f, 0x86, 0x57, 0x8e, 0xeb, 0xe9, 0x0e, 0xf7, 0xa1, 0x20, 0x2e}; + uint32_t count = 0xc675a64b; + uint8_t bearer = 0x0c; + uint8_t direction = 1; uint32_t len_bits = 1245, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0x8d, 0xaa, 0x17, 0xb1, 0xae, 0x05, 0x05, - 0x29, 0xc6, 0x82, 0x7f, 0x28, 0xc0, 0xef, 0x6a, 0x12, - 0x42, 0xe9, 0x3f, 0x8b, 0x31, 0x4f, 0xb1, 0x8a, 0x77, - 0xf7, 0x90, 0xae, 0x04, 0x9f, 0xed, 0xd6, 0x12, 0x26, - 0x7f, 0xec, 0xae, 0xfc, 0x45, 0x01, 0x74, 0xd7, 0x6d, - 0x9f, 0x9a, 0xa7, 0x75, 0x5a, 0x30, 0xcd, 0x90, 0xa9, - 0xa5, 0x87, 0x4b, 0xf4, 0x8e, 0xaf, 0x70, 0xee, 0xa3, - 0xa6, 0x2a, 0x25, 0x0a, 0x8b, 0x6b, 0xd8, 0xd9, 0xb0, - 0x8b, 0x08, 0xd6, 0x4e, 0x32, 0xd1, 0x81, 0x77, 0x77, - 0xfb, 0x54, 0x4d, 0x49, 0xcd, 0x49, 0x72, 0x0e, 0x21, - 0x9d, 0xbf, 0x8b, 0xbe, 0xd3, 0x39, 0x04, 0xe1, 0xfd, - 0x40, 0xa4, 0x1d, 0x37, 0x0a, 0x1f, 0x65, 0x74, 0x50, - 0x95, 0x68, 0x7d, 0x47, 0xba, 0x1d, 0x36, 0xd2, 0x34, - 0x9e, 0x23, 0xf6, 0x44, 0x39, 0x2c, 0x8e, 0xa9, 0xc4, - 0x9d, 0x40, 0xc1, 0x32, 0x71, 0xaf, 0xf2, 0x64, 0xd0, - 0xf2, 0x48, 0x41, 0xd6, 0x46, 0x5f, 0x09, 0x96, 0xff, - 0x84, 0xe6, 0x5f, 0xc5, 0x17, 0xc5, 0x3e, 0xfc, 0x33, - 0x63, 0xc3, 0x84, 0x92, 0xa8 }; - uint8_t ct[] = { 0x91, 0x9c, 0x8c, 0x33, 0xd6, 0x67, 0x89, - 0x70, 0x3d, 0x05, 0xa0, 0xd7, 0xce, 0x82, 0xa2, 0xae, - 0xac, 0x4e, 0xe7, 0x6c, 0x0f, 0x4d, 0xa0, 0x50, 0x33, - 0x5e, 0x8a, 0x84, 0xe7, 0x89, 0x7b, 0xa5, 0xdf, 0x2f, - 0x36, 0xbd, 0x51, 0x3e, 0x3d, 0x0c, 0x85, 0x78, 0xc7, - 0xa0, 0xfc, 0xf0, 0x43, 0xe0, 0x3a, 0xa3, 0xa3, 0x9f, - 0xba, 0xad, 0x7d, 0x15, 0xbe, 0x07, 0x4f, 0xaa, 0x5d, - 0x90, 0x29, 0xf7, 0x1f, 0xb4, 0x57, 0xb6, 0x47, 0x83, - 0x47, 0x14, 0xb0, 0xe1, 0x8f, 0x11, 0x7f, 0xca, 0x10, - 0x67, 0x79, 0x45, 0x09, 0x6c, 0x8c, 0x5f, 0x32, 0x6b, - 0xa8, 0xd6, 0x09, 0x5e, 0xb2, 0x9c, 0x3e, 0x36, 0xcf, - 0x24, 0x5d, 0x16, 0x22, 0xaa, 0xfe, 0x92, 0x1f, 0x75, - 0x66, 0xc4, 0xf5, 0xd6, 0x44, 0xf2, 0xf1, 0xfc, 0x0e, - 0xc6, 0x84, 0xdd, 0xb2, 0x13, 0x49, 0x74, 0x76, 0x22, - 0xe2, 0x09, 0x29, 0x5d, 0x27, 0xff, 0x3f, 0x95, 0x62, - 0x33, 0x71, 0xd4, 0x9b, 0x14, 0x7c, 0x0a, 0xf4, 0x86, - 0x17, 0x1f, 0x22, 0xcd, 0x04, 0xb1, 0xcb, 0xeb, 0x26, - 0x58, 0x22, 0x3e, 0x69, 0x38 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0x8d, 0xaa, 0x17, 0xb1, 0xae, 0x05, 0x05, 0x29, 0xc6, 0x82, 0x7f, 0x28, 0xc0, 0xef, 0x6a, 0x12, + 0x42, 0xe9, 0x3f, 0x8b, 0x31, 0x4f, 0xb1, 0x8a, 0x77, 0xf7, 0x90, 0xae, 0x04, 0x9f, 0xed, 0xd6, + 0x12, 0x26, 0x7f, 0xec, 0xae, 0xfc, 0x45, 0x01, 0x74, 0xd7, 0x6d, 0x9f, 0x9a, 0xa7, 0x75, 0x5a, + 0x30, 0xcd, 0x90, 0xa9, 0xa5, 0x87, 0x4b, 0xf4, 0x8e, 0xaf, 0x70, 0xee, 0xa3, 0xa6, 0x2a, 0x25, + 0x0a, 0x8b, 0x6b, 0xd8, 0xd9, 0xb0, 0x8b, 0x08, 0xd6, 0x4e, 0x32, 0xd1, 0x81, 0x77, 0x77, 0xfb, + 0x54, 0x4d, 0x49, 0xcd, 0x49, 0x72, 0x0e, 0x21, 0x9d, 0xbf, 0x8b, 0xbe, 0xd3, 0x39, 0x04, 0xe1, + 0xfd, 0x40, 0xa4, 0x1d, 0x37, 0x0a, 0x1f, 0x65, 0x74, 0x50, 0x95, 0x68, 0x7d, 0x47, 0xba, 0x1d, + 0x36, 0xd2, 0x34, 0x9e, 0x23, 0xf6, 0x44, 0x39, 0x2c, 0x8e, 0xa9, 0xc4, 0x9d, 0x40, 0xc1, 0x32, + 0x71, 0xaf, 0xf2, 0x64, 0xd0, 0xf2, 0x48, 0x41, 0xd6, 0x46, 0x5f, 0x09, 0x96, 0xff, 0x84, 0xe6, + 0x5f, 0xc5, 0x17, 0xc5, 0x3e, 0xfc, 0x33, 0x63, 0xc3, 0x84, 0x92, 0xa8}; + uint8_t ct[] = {0x91, 0x9c, 0x8c, 0x33, 0xd6, 0x67, 0x89, 0x70, 0x3d, 0x05, 0xa0, 0xd7, 0xce, 0x82, 0xa2, 0xae, + 0xac, 0x4e, 0xe7, 0x6c, 0x0f, 0x4d, 0xa0, 0x50, 0x33, 0x5e, 0x8a, 0x84, 0xe7, 0x89, 0x7b, 0xa5, + 0xdf, 0x2f, 0x36, 0xbd, 0x51, 0x3e, 0x3d, 0x0c, 0x85, 0x78, 0xc7, 0xa0, 0xfc, 0xf0, 0x43, 0xe0, + 0x3a, 0xa3, 0xa3, 0x9f, 0xba, 0xad, 0x7d, 0x15, 0xbe, 0x07, 0x4f, 0xaa, 0x5d, 0x90, 0x29, 0xf7, + 0x1f, 0xb4, 0x57, 0xb6, 0x47, 0x83, 0x47, 0x14, 0xb0, 0xe1, 0x8f, 0x11, 0x7f, 0xca, 0x10, 0x67, + 0x79, 0x45, 0x09, 0x6c, 0x8c, 0x5f, 0x32, 0x6b, 0xa8, 0xd6, 0x09, 0x5e, 0xb2, 0x9c, 0x3e, 0x36, + 0xcf, 0x24, 0x5d, 0x16, 0x22, 0xaa, 0xfe, 0x92, 0x1f, 0x75, 0x66, 0xc4, 0xf5, 0xd6, 0x44, 0xf2, + 0xf1, 0xfc, 0x0e, 0xc6, 0x84, 0xdd, 0xb2, 0x13, 0x49, 0x74, 0x76, 0x22, 0xe2, 0x09, 0x29, 0x5d, + 0x27, 0xff, 0x3f, 0x95, 0x62, 0x33, 0x71, 0xd4, 0x9b, 0x14, 0x7c, 0x0a, 0xf4, 0x86, 0x17, 0x1f, + 0x22, 0xcd, 0x04, 0xb1, 0xcb, 0xeb, 0x26, 0x58, 0x22, 0x3e, 0x69, 0x38}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea2(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -324,8 +256,7 @@ void test_set_5() assert(err_cmp == 0); // decryption - err_lte = liblte_security_decryption_eea2(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -338,137 +269,83 @@ void test_set_5() void test_set_6() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0x54, 0xf4, 0xe2, 0xe0, 0x4c, 0x83, 0x78, - 0x6e, 0xec, 0x8f, 0xb5, 0xab, 0xe8, 0xe3, 0x65, 0x66 }; - uint32_t count = 0xaca4f50f; - uint8_t bearer = 0x0b; - uint8_t direction = 0; + uint8_t key[] = {0x54, 0xf4, 0xe2, 0xe0, 0x4c, 0x83, 0x78, 0x6e, 0xec, 0x8f, 0xb5, 0xab, 0xe8, 0xe3, 0x65, 0x66}; + uint32_t count = 0xaca4f50f; + uint8_t bearer = 0x0b; + uint8_t direction = 0; uint32_t len_bits = 3861, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0x40, 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, - 0xfb, 0x42, 0x86, 0xb2, 0x99, 0x78, 0x3d, 0xaf, 0x44, - 0x2c, 0x09, 0x9f, 0x7a, 0xb0, 0xf5, 0x8d, 0x5c, 0x8e, - 0x46, 0xb1, 0x04, 0xf0, 0x8f, 0x01, 0xb4, 0x1a, 0xb4, - 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x36, 0xbd, 0x1a, - 0x3d, 0x90, 0xdc, 0x3a, 0x41, 0xb4, 0x6d, 0x51, 0x67, - 0x2a, 0xc4, 0xc9, 0x66, 0x3a, 0x2b, 0xe0, 0x63, 0xda, - 0x4b, 0xc8, 0xd2, 0x80, 0x8c, 0xe3, 0x3e, 0x2c, 0xcc, - 0xbf, 0xc6, 0x34, 0xe1, 0xb2, 0x59, 0x06, 0x08, 0x76, - 0xa0, 0xfb, 0xb5, 0xa4, 0x37, 0xeb, 0xcc, 0x8d, 0x31, - 0xc1, 0x9e, 0x44, 0x54, 0x31, 0x87, 0x45, 0xe3, 0xfa, - 0x16, 0xbb, 0x11, 0xad, 0xae, 0x24, 0x88, 0x79, 0xfe, - 0x52, 0xdb, 0x25, 0x43, 0xe5, 0x3c, 0xf4, 0x45, 0xd3, - 0xd8, 0x28, 0xce, 0x0b, 0xf5, 0xc5, 0x60, 0x59, 0x3d, - 0x97, 0x27, 0x8a, 0x59, 0x76, 0x2d, 0xd0, 0xc2, 0xc9, - 0xcd, 0x68, 0xd4, 0x49, 0x6a, 0x79, 0x25, 0x08, 0x61, - 0x40, 0x14, 0xb1, 0x3b, 0x6a, 0xa5, 0x11, 0x28, 0xc1, - 0x8c, 0xd6, 0xa9, 0x0b, 0x87, 0x97, 0x8c, 0x2f, 0xf1, - 0xca, 0xbe, 0x7d, 0x9f, 0x89, 0x8a, 0x41, 0x1b, 0xfd, - 0xb8, 0x4f, 0x68, 0xf6, 0x72, 0x7b, 0x14, 0x99, 0xcd, - 0xd3, 0x0d, 0xf0, 0x44, 0x3a, 0xb4, 0xa6, 0x66, 0x53, - 0x33, 0x0b, 0xcb, 0xa1, 0x10, 0x5e, 0x4c, 0xec, 0x03, - 0x4c, 0x73, 0xe6, 0x05, 0xb4, 0x31, 0x0e, 0xaa, 0xad, - 0xcf, 0xd5, 0xb0, 0xca, 0x27, 0xff, 0xd8, 0x9d, 0x14, - 0x4d, 0xf4, 0x79, 0x27, 0x59, 0x42, 0x7c, 0x9c, 0xc1, - 0xf8, 0xcd, 0x8c, 0x87, 0x20, 0x23, 0x64, 0xb8, 0xa6, - 0x87, 0x95, 0x4c, 0xb0, 0x5a, 0x8d, 0x4e, 0x2d, 0x99, - 0xe7, 0x3d, 0xb1, 0x60, 0xde, 0xb1, 0x80, 0xad, 0x08, - 0x41, 0xe9, 0x67, 0x41, 0xa5, 0xd5, 0x9f, 0xe4, 0x18, - 0x9f, 0x15, 0x42, 0x00, 0x26, 0xfe, 0x4c, 0xd1, 0x21, - 0x04, 0x93, 0x2f, 0xb3, 0x8f, 0x73, 0x53, 0x40, 0x43, - 0x8a, 0xaf, 0x7e, 0xca, 0x6f, 0xd5, 0xcf, 0xd3, 0xa1, - 0x95, 0xce, 0x5a, 0xbe, 0x65, 0x27, 0x2a, 0xf6, 0x07, - 0xad, 0xa1, 0xbe, 0x65, 0xa6, 0xb4, 0xc9, 0xc0, 0x69, - 0x32, 0x34, 0x09, 0x2c, 0x4d, 0x01, 0x8f, 0x17, 0x56, - 0xc6, 0xdb, 0x9d, 0xc8, 0xa6, 0xd8, 0x0b, 0x88, 0x81, - 0x38, 0x61, 0x6b, 0x68, 0x12, 0x62, 0xf9, 0x54, 0xd0, - 0xe7, 0x71, 0x17, 0x48, 0x78, 0x0d, 0x92, 0x29, 0x1d, - 0x86, 0x29, 0x99, 0x72, 0xdb, 0x74, 0x1c, 0xfa, 0x4f, - 0x37, 0xb8, 0xb5, 0x6c, 0xdb, 0x18, 0xa7, 0xca, 0x82, - 0x18, 0xe8, 0x6e, 0x4b, 0x4b, 0x71, 0x6a, 0x4d, 0x04, - 0x37, 0x1f, 0xbe, 0xc2, 0x62, 0xfc, 0x5a, 0xd0, 0xb3, - 0x81, 0x9b, 0x18, 0x7b, 0x97, 0xe5, 0x5b, 0x1a, 0x4d, - 0x7c, 0x19, 0xee, 0x24, 0xc8, 0xb4, 0xd7, 0x72, 0x3c, - 0xfe, 0xdf, 0x04, 0x5b, 0x8a, 0xca, 0xe4, 0x86, 0x95, - 0x17, 0xd8, 0x0e, 0x50, 0x61, 0x5d, 0x90, 0x35, 0xd5, - 0xd9, 0xc5, 0xa4, 0x0a, 0xf6, 0x02, 0x28, 0x0b, 0x54, - 0x25, 0x97, 0xb0, 0xcb, 0x18, 0x61, 0x9e, 0xeb, 0x35, - 0x92, 0x57, 0x59, 0xd1, 0x95, 0xe1, 0x00, 0xe8, 0xe4, - 0xaa, 0x0c, 0x38, 0xa3, 0xc2, 0xab, 0xe0, 0xf3, 0xd8, - 0xff, 0x04, 0xf3, 0xc3, 0x3c, 0x29, 0x50, 0x69, 0xc2, - 0x36, 0x94, 0xb5, 0xbb, 0xea, 0xcd, 0xd5, 0x42, 0xe2, - 0x8e, 0x8a, 0x94, 0xed, 0xb9, 0x11, 0x9f, 0x41, 0x2d, - 0x05, 0x4b, 0xe1, 0xfa, 0x72, 0x00, 0xb0, 0x90, 0x00 }; - uint8_t ct[] = { 0x5c, 0xb7, 0x2c, 0x6e, 0xdc, 0x87, 0x8f, - 0x15, 0x66, 0xe1, 0x02, 0x53, 0xaf, 0xc3, 0x64, 0xc9, - 0xfa, 0x54, 0x0d, 0x91, 0x4d, 0xb9, 0x4c, 0xbe, 0xe2, - 0x75, 0xd0, 0x91, 0x7c, 0xa6, 0xaf, 0x0d, 0x77, 0xac, - 0xb4, 0xef, 0x3b, 0xbe, 0x1a, 0x72, 0x2b, 0x2e, 0xf5, - 0xbd, 0x1d, 0x4b, 0x8e, 0x2a, 0xa5, 0x02, 0x4e, 0xc1, - 0x38, 0x8a, 0x20, 0x1e, 0x7b, 0xce, 0x79, 0x20, 0xae, - 0xc6, 0x15, 0x89, 0x5f, 0x76, 0x3a, 0x55, 0x64, 0xdc, - 0xc4, 0xc4, 0x82, 0xa2, 0xee, 0x1d, 0x8b, 0xfe, 0xcc, - 0x44, 0x98, 0xec, 0xa8, 0x3f, 0xbb, 0x75, 0xf9, 0xab, - 0x53, 0x0e, 0x0d, 0xaf, 0xbe, 0xde, 0x2f, 0xa5, 0x89, - 0x5b, 0x82, 0x99, 0x1b, 0x62, 0x77, 0xc5, 0x29, 0xe0, - 0xf2, 0x52, 0x9d, 0x7f, 0x79, 0x60, 0x6b, 0xe9, 0x67, - 0x06, 0x29, 0x6d, 0xed, 0xfa, 0x9d, 0x74, 0x12, 0xb6, - 0x16, 0x95, 0x8c, 0xb5, 0x63, 0xc6, 0x78, 0xc0, 0x28, - 0x25, 0xc3, 0x0d, 0x0a, 0xee, 0x77, 0xc4, 0xc1, 0x46, - 0xd2, 0x76, 0x54, 0x12, 0x42, 0x1a, 0x80, 0x8d, 0x13, - 0xce, 0xc8, 0x19, 0x69, 0x4c, 0x75, 0xad, 0x57, 0x2e, - 0x9b, 0x97, 0x3d, 0x94, 0x8b, 0x81, 0xa9, 0x33, 0x7c, - 0x3b, 0x2a, 0x17, 0x19, 0x2e, 0x22, 0xc2, 0x06, 0x9f, - 0x7e, 0xd1, 0x16, 0x2a, 0xf4, 0x4c, 0xde, 0xa8, 0x17, - 0x60, 0x36, 0x65, 0xe8, 0x07, 0xce, 0x40, 0xc8, 0xe0, - 0xdd, 0x9d, 0x63, 0x94, 0xdc, 0x6e, 0x31, 0x15, 0x3f, - 0xe1, 0x95, 0x5c, 0x47, 0xaf, 0xb5, 0x1f, 0x26, 0x17, - 0xee, 0x0c, 0x5e, 0x3b, 0x8e, 0xf1, 0xad, 0x75, 0x74, - 0xed, 0x34, 0x3e, 0xdc, 0x27, 0x43, 0xcc, 0x94, 0xc9, - 0x90, 0xe1, 0xf1, 0xfd, 0x26, 0x42, 0x53, 0xc1, 0x78, - 0xde, 0xa7, 0x39, 0xc0, 0xbe, 0xfe, 0xeb, 0xcd, 0x9f, - 0x9b, 0x76, 0xd4, 0x9c, 0x10, 0x15, 0xc9, 0xfe, 0xcf, - 0x50, 0xe5, 0x3b, 0x8b, 0x52, 0x04, 0xdb, 0xcd, 0x3e, - 0xed, 0x86, 0x38, 0x55, 0xda, 0xbc, 0xdc, 0xc9, 0x4b, - 0x31, 0xe3, 0x18, 0x02, 0x15, 0x68, 0x85, 0x5c, 0x8b, - 0x9e, 0x52, 0xa9, 0x81, 0x95, 0x7a, 0x11, 0x28, 0x27, - 0xf9, 0x78, 0xba, 0x96, 0x0f, 0x14, 0x47, 0x91, 0x1b, - 0x31, 0x7b, 0x55, 0x11, 0xfb, 0xcc, 0x7f, 0xb1, 0x3a, - 0xc1, 0x53, 0xdb, 0x74, 0x25, 0x11, 0x17, 0xe4, 0x86, - 0x1e, 0xb9, 0xe8, 0x3b, 0xff, 0xff, 0xc4, 0xeb, 0x77, - 0x55, 0x57, 0x90, 0x38, 0xe5, 0x79, 0x24, 0xb1, 0xf7, - 0x8b, 0x3e, 0x1a, 0xd9, 0x0b, 0xab, 0x2a, 0x07, 0x87, - 0x1b, 0x72, 0xdb, 0x5e, 0xef, 0x96, 0xc3, 0x34, 0x04, - 0x49, 0x66, 0xdb, 0x0c, 0x37, 0xca, 0xfd, 0x1a, 0x89, - 0xe5, 0x64, 0x6a, 0x35, 0x80, 0xeb, 0x64, 0x65, 0xf1, - 0x21, 0xdc, 0xe9, 0xcb, 0x88, 0xd8, 0x5b, 0x96, 0xcf, - 0x23, 0xcc, 0xcc, 0xd4, 0x28, 0x07, 0x67, 0xbe, 0xe8, - 0xee, 0xb2, 0x3d, 0x86, 0x52, 0x46, 0x1d, 0xb6, 0x49, - 0x31, 0x03, 0x00, 0x3b, 0xaf, 0x89, 0xf5, 0xe1, 0x82, - 0x61, 0xea, 0x43, 0xc8, 0x4a, 0x92, 0xeb, 0xff, 0xff, - 0xe4, 0x90, 0x9d, 0xc4, 0x6c, 0x51, 0x92, 0xf8, 0x25, - 0xf7, 0x70, 0x60, 0x0b, 0x96, 0x02, 0xc5, 0x57, 0xb5, - 0xf8, 0xb4, 0x31, 0xa7, 0x9d, 0x45, 0x97, 0x7d, 0xd9, - 0xc4, 0x1b, 0x86, 0x3d, 0xa9, 0xe1, 0x42, 0xe9, 0x00, - 0x20, 0xcf, 0xd0, 0x74, 0xd6, 0x92, 0x7b, 0x7a, 0xb3, - 0xb6, 0x72, 0x5d, 0x1a, 0x6f, 0x3f, 0x98, 0xb9, 0xc9, - 0xda, 0xa8, 0x98, 0x2a, 0xff, 0x06, 0x78, 0x28, 0x00 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = { + 0x40, 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, 0x42, 0x86, 0xb2, 0x99, 0x78, 0x3d, 0xaf, 0x44, 0x2c, 0x09, 0x9f, + 0x7a, 0xb0, 0xf5, 0x8d, 0x5c, 0x8e, 0x46, 0xb1, 0x04, 0xf0, 0x8f, 0x01, 0xb4, 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, + 0xb7, 0x1d, 0x36, 0xbd, 0x1a, 0x3d, 0x90, 0xdc, 0x3a, 0x41, 0xb4, 0x6d, 0x51, 0x67, 0x2a, 0xc4, 0xc9, 0x66, 0x3a, + 0x2b, 0xe0, 0x63, 0xda, 0x4b, 0xc8, 0xd2, 0x80, 0x8c, 0xe3, 0x3e, 0x2c, 0xcc, 0xbf, 0xc6, 0x34, 0xe1, 0xb2, 0x59, + 0x06, 0x08, 0x76, 0xa0, 0xfb, 0xb5, 0xa4, 0x37, 0xeb, 0xcc, 0x8d, 0x31, 0xc1, 0x9e, 0x44, 0x54, 0x31, 0x87, 0x45, + 0xe3, 0xfa, 0x16, 0xbb, 0x11, 0xad, 0xae, 0x24, 0x88, 0x79, 0xfe, 0x52, 0xdb, 0x25, 0x43, 0xe5, 0x3c, 0xf4, 0x45, + 0xd3, 0xd8, 0x28, 0xce, 0x0b, 0xf5, 0xc5, 0x60, 0x59, 0x3d, 0x97, 0x27, 0x8a, 0x59, 0x76, 0x2d, 0xd0, 0xc2, 0xc9, + 0xcd, 0x68, 0xd4, 0x49, 0x6a, 0x79, 0x25, 0x08, 0x61, 0x40, 0x14, 0xb1, 0x3b, 0x6a, 0xa5, 0x11, 0x28, 0xc1, 0x8c, + 0xd6, 0xa9, 0x0b, 0x87, 0x97, 0x8c, 0x2f, 0xf1, 0xca, 0xbe, 0x7d, 0x9f, 0x89, 0x8a, 0x41, 0x1b, 0xfd, 0xb8, 0x4f, + 0x68, 0xf6, 0x72, 0x7b, 0x14, 0x99, 0xcd, 0xd3, 0x0d, 0xf0, 0x44, 0x3a, 0xb4, 0xa6, 0x66, 0x53, 0x33, 0x0b, 0xcb, + 0xa1, 0x10, 0x5e, 0x4c, 0xec, 0x03, 0x4c, 0x73, 0xe6, 0x05, 0xb4, 0x31, 0x0e, 0xaa, 0xad, 0xcf, 0xd5, 0xb0, 0xca, + 0x27, 0xff, 0xd8, 0x9d, 0x14, 0x4d, 0xf4, 0x79, 0x27, 0x59, 0x42, 0x7c, 0x9c, 0xc1, 0xf8, 0xcd, 0x8c, 0x87, 0x20, + 0x23, 0x64, 0xb8, 0xa6, 0x87, 0x95, 0x4c, 0xb0, 0x5a, 0x8d, 0x4e, 0x2d, 0x99, 0xe7, 0x3d, 0xb1, 0x60, 0xde, 0xb1, + 0x80, 0xad, 0x08, 0x41, 0xe9, 0x67, 0x41, 0xa5, 0xd5, 0x9f, 0xe4, 0x18, 0x9f, 0x15, 0x42, 0x00, 0x26, 0xfe, 0x4c, + 0xd1, 0x21, 0x04, 0x93, 0x2f, 0xb3, 0x8f, 0x73, 0x53, 0x40, 0x43, 0x8a, 0xaf, 0x7e, 0xca, 0x6f, 0xd5, 0xcf, 0xd3, + 0xa1, 0x95, 0xce, 0x5a, 0xbe, 0x65, 0x27, 0x2a, 0xf6, 0x07, 0xad, 0xa1, 0xbe, 0x65, 0xa6, 0xb4, 0xc9, 0xc0, 0x69, + 0x32, 0x34, 0x09, 0x2c, 0x4d, 0x01, 0x8f, 0x17, 0x56, 0xc6, 0xdb, 0x9d, 0xc8, 0xa6, 0xd8, 0x0b, 0x88, 0x81, 0x38, + 0x61, 0x6b, 0x68, 0x12, 0x62, 0xf9, 0x54, 0xd0, 0xe7, 0x71, 0x17, 0x48, 0x78, 0x0d, 0x92, 0x29, 0x1d, 0x86, 0x29, + 0x99, 0x72, 0xdb, 0x74, 0x1c, 0xfa, 0x4f, 0x37, 0xb8, 0xb5, 0x6c, 0xdb, 0x18, 0xa7, 0xca, 0x82, 0x18, 0xe8, 0x6e, + 0x4b, 0x4b, 0x71, 0x6a, 0x4d, 0x04, 0x37, 0x1f, 0xbe, 0xc2, 0x62, 0xfc, 0x5a, 0xd0, 0xb3, 0x81, 0x9b, 0x18, 0x7b, + 0x97, 0xe5, 0x5b, 0x1a, 0x4d, 0x7c, 0x19, 0xee, 0x24, 0xc8, 0xb4, 0xd7, 0x72, 0x3c, 0xfe, 0xdf, 0x04, 0x5b, 0x8a, + 0xca, 0xe4, 0x86, 0x95, 0x17, 0xd8, 0x0e, 0x50, 0x61, 0x5d, 0x90, 0x35, 0xd5, 0xd9, 0xc5, 0xa4, 0x0a, 0xf6, 0x02, + 0x28, 0x0b, 0x54, 0x25, 0x97, 0xb0, 0xcb, 0x18, 0x61, 0x9e, 0xeb, 0x35, 0x92, 0x57, 0x59, 0xd1, 0x95, 0xe1, 0x00, + 0xe8, 0xe4, 0xaa, 0x0c, 0x38, 0xa3, 0xc2, 0xab, 0xe0, 0xf3, 0xd8, 0xff, 0x04, 0xf3, 0xc3, 0x3c, 0x29, 0x50, 0x69, + 0xc2, 0x36, 0x94, 0xb5, 0xbb, 0xea, 0xcd, 0xd5, 0x42, 0xe2, 0x8e, 0x8a, 0x94, 0xed, 0xb9, 0x11, 0x9f, 0x41, 0x2d, + 0x05, 0x4b, 0xe1, 0xfa, 0x72, 0x00, 0xb0, 0x90, 0x00}; + uint8_t ct[] = { + 0x5c, 0xb7, 0x2c, 0x6e, 0xdc, 0x87, 0x8f, 0x15, 0x66, 0xe1, 0x02, 0x53, 0xaf, 0xc3, 0x64, 0xc9, 0xfa, 0x54, 0x0d, + 0x91, 0x4d, 0xb9, 0x4c, 0xbe, 0xe2, 0x75, 0xd0, 0x91, 0x7c, 0xa6, 0xaf, 0x0d, 0x77, 0xac, 0xb4, 0xef, 0x3b, 0xbe, + 0x1a, 0x72, 0x2b, 0x2e, 0xf5, 0xbd, 0x1d, 0x4b, 0x8e, 0x2a, 0xa5, 0x02, 0x4e, 0xc1, 0x38, 0x8a, 0x20, 0x1e, 0x7b, + 0xce, 0x79, 0x20, 0xae, 0xc6, 0x15, 0x89, 0x5f, 0x76, 0x3a, 0x55, 0x64, 0xdc, 0xc4, 0xc4, 0x82, 0xa2, 0xee, 0x1d, + 0x8b, 0xfe, 0xcc, 0x44, 0x98, 0xec, 0xa8, 0x3f, 0xbb, 0x75, 0xf9, 0xab, 0x53, 0x0e, 0x0d, 0xaf, 0xbe, 0xde, 0x2f, + 0xa5, 0x89, 0x5b, 0x82, 0x99, 0x1b, 0x62, 0x77, 0xc5, 0x29, 0xe0, 0xf2, 0x52, 0x9d, 0x7f, 0x79, 0x60, 0x6b, 0xe9, + 0x67, 0x06, 0x29, 0x6d, 0xed, 0xfa, 0x9d, 0x74, 0x12, 0xb6, 0x16, 0x95, 0x8c, 0xb5, 0x63, 0xc6, 0x78, 0xc0, 0x28, + 0x25, 0xc3, 0x0d, 0x0a, 0xee, 0x77, 0xc4, 0xc1, 0x46, 0xd2, 0x76, 0x54, 0x12, 0x42, 0x1a, 0x80, 0x8d, 0x13, 0xce, + 0xc8, 0x19, 0x69, 0x4c, 0x75, 0xad, 0x57, 0x2e, 0x9b, 0x97, 0x3d, 0x94, 0x8b, 0x81, 0xa9, 0x33, 0x7c, 0x3b, 0x2a, + 0x17, 0x19, 0x2e, 0x22, 0xc2, 0x06, 0x9f, 0x7e, 0xd1, 0x16, 0x2a, 0xf4, 0x4c, 0xde, 0xa8, 0x17, 0x60, 0x36, 0x65, + 0xe8, 0x07, 0xce, 0x40, 0xc8, 0xe0, 0xdd, 0x9d, 0x63, 0x94, 0xdc, 0x6e, 0x31, 0x15, 0x3f, 0xe1, 0x95, 0x5c, 0x47, + 0xaf, 0xb5, 0x1f, 0x26, 0x17, 0xee, 0x0c, 0x5e, 0x3b, 0x8e, 0xf1, 0xad, 0x75, 0x74, 0xed, 0x34, 0x3e, 0xdc, 0x27, + 0x43, 0xcc, 0x94, 0xc9, 0x90, 0xe1, 0xf1, 0xfd, 0x26, 0x42, 0x53, 0xc1, 0x78, 0xde, 0xa7, 0x39, 0xc0, 0xbe, 0xfe, + 0xeb, 0xcd, 0x9f, 0x9b, 0x76, 0xd4, 0x9c, 0x10, 0x15, 0xc9, 0xfe, 0xcf, 0x50, 0xe5, 0x3b, 0x8b, 0x52, 0x04, 0xdb, + 0xcd, 0x3e, 0xed, 0x86, 0x38, 0x55, 0xda, 0xbc, 0xdc, 0xc9, 0x4b, 0x31, 0xe3, 0x18, 0x02, 0x15, 0x68, 0x85, 0x5c, + 0x8b, 0x9e, 0x52, 0xa9, 0x81, 0x95, 0x7a, 0x11, 0x28, 0x27, 0xf9, 0x78, 0xba, 0x96, 0x0f, 0x14, 0x47, 0x91, 0x1b, + 0x31, 0x7b, 0x55, 0x11, 0xfb, 0xcc, 0x7f, 0xb1, 0x3a, 0xc1, 0x53, 0xdb, 0x74, 0x25, 0x11, 0x17, 0xe4, 0x86, 0x1e, + 0xb9, 0xe8, 0x3b, 0xff, 0xff, 0xc4, 0xeb, 0x77, 0x55, 0x57, 0x90, 0x38, 0xe5, 0x79, 0x24, 0xb1, 0xf7, 0x8b, 0x3e, + 0x1a, 0xd9, 0x0b, 0xab, 0x2a, 0x07, 0x87, 0x1b, 0x72, 0xdb, 0x5e, 0xef, 0x96, 0xc3, 0x34, 0x04, 0x49, 0x66, 0xdb, + 0x0c, 0x37, 0xca, 0xfd, 0x1a, 0x89, 0xe5, 0x64, 0x6a, 0x35, 0x80, 0xeb, 0x64, 0x65, 0xf1, 0x21, 0xdc, 0xe9, 0xcb, + 0x88, 0xd8, 0x5b, 0x96, 0xcf, 0x23, 0xcc, 0xcc, 0xd4, 0x28, 0x07, 0x67, 0xbe, 0xe8, 0xee, 0xb2, 0x3d, 0x86, 0x52, + 0x46, 0x1d, 0xb6, 0x49, 0x31, 0x03, 0x00, 0x3b, 0xaf, 0x89, 0xf5, 0xe1, 0x82, 0x61, 0xea, 0x43, 0xc8, 0x4a, 0x92, + 0xeb, 0xff, 0xff, 0xe4, 0x90, 0x9d, 0xc4, 0x6c, 0x51, 0x92, 0xf8, 0x25, 0xf7, 0x70, 0x60, 0x0b, 0x96, 0x02, 0xc5, + 0x57, 0xb5, 0xf8, 0xb4, 0x31, 0xa7, 0x9d, 0x45, 0x97, 0x7d, 0xd9, 0xc4, 0x1b, 0x86, 0x3d, 0xa9, 0xe1, 0x42, 0xe9, + 0x00, 0x20, 0xcf, 0xd0, 0x74, 0xd6, 0x92, 0x7b, 0x7a, 0xb3, 0xb6, 0x72, 0x5d, 0x1a, 0x6f, 0x3f, 0x98, 0xb9, 0xc9, + 0xda, 0xa8, 0x98, 0x2a, 0xff, 0x06, 0x78, 0x28, 0x00}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); struct timeval t[3]; // encryption gettimeofday(&t[1], NULL); - for (int i=0;i<100;i++) { - err_lte = liblte_security_encryption_eea2(key, count, bearer, - direction, msg, len_bits, out); + for (int i = 0; i < 100; i++) { + err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); } gettimeofday(&t[2], NULL); get_time_interval(t); - printf("encryption: %u bits, t=%d us, rate=%.1f Mbps/s\n", len_bits, (int) t[0].tv_usec/100, (float) 100*len_bits/t[0].tv_usec); + printf("encryption: %u bits, t=%d us, rate=%.1f Mbps/s\n", + len_bits, + (int)t[0].tv_usec / 100, + (float)100 * len_bits / t[0].tv_usec); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -477,13 +354,15 @@ void test_set_6() // decryption gettimeofday(&t[1], NULL); - for (int i=0;i<100;i++) { - err_lte = liblte_security_decryption_eea2(key, count, bearer, - direction, ct, len_bits, out); + for (int i = 0; i < 100; i++) { + err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); } gettimeofday(&t[2], NULL); get_time_interval(t); - printf("decryption: %u bits, t=%d us, rate=%.1f Mbps/s\n", len_bits, (int) t[0].tv_usec/100, (float) 100*len_bits/t[0].tv_usec); + printf("decryption: %u bits, t=%d us, rate=%.1f Mbps/s\n", + len_bits, + (int)t[0].tv_usec / 100, + (float)100 * len_bits / t[0].tv_usec); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -497,29 +376,22 @@ void test_set_6() void test_set_1_block_size() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1, - 0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1 }; - uint32_t count = 0x398a59b4; - uint8_t bearer = 0x15; - uint8_t direction = 1; + uint8_t key[] = {0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1, 0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1}; + uint32_t count = 0x398a59b4; + uint8_t bearer = 0x15; + uint8_t direction = 1; uint32_t len_bits = 256, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, - 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80, - 0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f, - 0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0 }; - uint8_t ct[] = { 0xe9, 0xfe, 0xd8, 0xa6, 0x3d, 0x15, 0x53, - 0x04, 0xd7, 0x1d, 0xf2, 0x0b, 0xf3, 0xe8, 0x22, 0x14, - 0xb2, 0x0e, 0xd7, 0xda, 0xd2, 0xf2, 0x33, 0xdc, 0x3c, - 0x22, 0xd7, 0xbd, 0xee, 0xed, 0x8e, 0x78 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0x98, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80, + 0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f, 0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0}; + uint8_t ct[] = {0xe9, 0xfe, 0xd8, 0xa6, 0x3d, 0x15, 0x53, 0x04, 0xd7, 0x1d, 0xf2, 0x0b, 0xf3, 0xe8, 0x22, 0x14, + 0xb2, 0x0e, 0xd7, 0xda, 0xd2, 0xf2, 0x33, 0xdc, 0x3c, 0x22, 0xd7, 0xbd, 0xee, 0xed, 0x8e, 0x78}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea2(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -527,8 +399,7 @@ void test_set_1_block_size() assert(err_cmp == 0); // decryption - err_lte = liblte_security_decryption_eea2(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -542,29 +413,22 @@ void test_set_1_block_size() void test_set_1_invalid() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t key[] = { 0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1, - 0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1 }; - uint32_t count = 0x398a59b4; - uint8_t bearer = 0x15; - uint8_t direction = 1; + uint8_t key[] = {0xd3, 0xc5, 0xd5, 0x92, 0x32, 0x7f, 0xb1, 0x1c, 0x40, 0x35, 0xc6, 0x68, 0x0a, 0xf8, 0xc6, 0xd1}; + uint32_t count = 0x398a59b4; + uint8_t bearer = 0x15; + uint8_t direction = 1; uint32_t len_bits = 253, len_bytes = (len_bits + 7) / 8; - uint8_t msg[] = { 0x99, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, - 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80, - 0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f, - 0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0 }; - uint8_t ct[] = { 0xe9, 0xfe, 0xd8, 0xa6, 0x3d, 0x15, 0x53, - 0x04, 0xd7, 0x1d, 0xf2, 0x0b, 0xf3, 0xe8, 0x22, 0x14, - 0xb2, 0x0e, 0xd7, 0xda, 0xd2, 0xf2, 0x33, 0xdc, 0x3c, - 0x22, 0xd7, 0xbd, 0xee, 0xed, 0x8e, 0x78 }; - - uint8_t * out = (uint8_t *) calloc(len_bytes, - sizeof(uint8_t)); + uint8_t msg[] = {0x99, 0x1b, 0xa6, 0x82, 0x4c, 0x1b, 0xfb, 0x1a, 0xb4, 0x85, 0x47, 0x20, 0x29, 0xb7, 0x1d, 0x80, + 0x8c, 0xe3, 0x3e, 0x2c, 0xc3, 0xc0, 0xb5, 0xfc, 0x1f, 0x3d, 0xe8, 0xa6, 0xdc, 0x66, 0xb1, 0xf0}; + uint8_t ct[] = {0xe9, 0xfe, 0xd8, 0xa6, 0x3d, 0x15, 0x53, 0x04, 0xd7, 0x1d, 0xf2, 0x0b, 0xf3, 0xe8, 0x22, 0x14, + 0xb2, 0x0e, 0xd7, 0xda, 0xd2, 0xf2, 0x33, 0xdc, 0x3c, 0x22, 0xd7, 0xbd, 0xee, 0xed, 0x8e, 0x78}; + + uint8_t* out = (uint8_t*)calloc(len_bytes, sizeof(uint8_t)); // encryption - err_lte = liblte_security_encryption_eea2(key, count, bearer, - direction, msg, len_bits, out); + err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -572,8 +436,7 @@ void test_set_1_invalid() assert(err_cmp != 0); // decryption - err_lte = liblte_security_decryption_eea2(key, count, bearer, - direction, ct, len_bits, out); + err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); assert(err_lte == LIBLTE_SUCCESS); // compare cipher text @@ -587,7 +450,8 @@ void test_set_1_invalid() * Functions */ -int main(int argc, char * argv[]) { +int main(int argc, char* argv[]) +{ test_set_1(); test_set_2(); test_set_3(); diff --git a/lib/test/common/test_eia1.cc b/lib/test/common/test_eia1.cc index c72c86cee..127ed48f2 100644 --- a/lib/test/common/test_eia1.cc +++ b/lib/test/common/test_eia1.cc @@ -19,13 +19,13 @@ * */ -#include -#include #include +#include +#include #include -#include "srslte/srslte.h" #include "srslte/common/security.h" +#include "srslte/srslte.h" /* * Tests @@ -36,10 +36,10 @@ void test_set_1() { - uint8_t key[] = {0x2b, 0xd6, 0x45, 0x9f, 0x82, 0xc5, 0xb3, 0x00, 0x95, 0x2c, 0x49, 0x10, 0x48, 0x81, 0xff, 0x48}; - uint32_t count = 0x38a6f056; - uint8_t bearer = 0x1f; - uint8_t direction = 0; + uint8_t key[] = {0x2b, 0xd6, 0x45, 0x9f, 0x82, 0xc5, 0xb3, 0x00, 0x95, 0x2c, 0x49, 0x10, 0x48, 0x81, 0xff, 0x48}; + uint32_t count = 0x38a6f056; + uint8_t bearer = 0x1f; + uint8_t direction = 0; uint32_t len_bits = 88, len_bytes = (len_bits + 7) / 8; uint8_t msg[] = {0x33, 0x32, 0x34, 0x62, 0x63, 0x39, 0x38, 0x61, 0x37, 0x34, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t mt[] = {0x73, 0x1f, 0x11, 0x65}; @@ -49,17 +49,17 @@ void test_set_1() // gen mac srslte::security_128_eia1(key, count, bearer, direction, msg, len_bytes, mac); - for(int i=0; i<4; i++) { + for (int i = 0; i < 4; i++) { assert(mac[i] == mt[i]); } } void test_set_4() { - uint8_t key[] = {0x83, 0xfd, 0x23, 0xa2, 0x44, 0xa7, 0x4c, 0xf3, 0x58, 0xda, 0x30, 0x19, 0xf1, 0x72, 0x26, 0x35}; - uint32_t count = 0x36af6144; - uint8_t bearer = 0x0f; - uint8_t direction = 1; + uint8_t key[] = {0x83, 0xfd, 0x23, 0xa2, 0x44, 0xa7, 0x4c, 0xf3, 0x58, 0xda, 0x30, 0x19, 0xf1, 0x72, 0x26, 0x35}; + uint32_t count = 0x36af6144; + uint8_t bearer = 0x0f; + uint8_t direction = 1; uint32_t len_bits = 768, len_bytes = (len_bits + 7) / 8; uint8_t msg[] = {0x35, 0xc6, 0x87, 0x16, 0x63, 0x3c, 0x66, 0xfb, 0x75, 0x0c, 0x26, 0x68, 0x65, 0xd5, 0x3c, 0x11, 0xea, 0x05, 0xb1, 0xe9, 0xfa, 0x49, 0xc8, 0x39, 0x8d, 0x48, 0xe1, 0xef, 0xa5, 0x90, 0x9d, 0x39, @@ -74,17 +74,17 @@ void test_set_4() // gen mac srslte::security_128_eia1(key, count, bearer, direction, msg, len_bytes, mac); - for(int i=0; i<4; i++) { + for (int i = 0; i < 4; i++) { assert(mac[i] == mt[i]); } } void test_set_7() { - uint8_t key[] = {0xb3, 0x12, 0x0f, 0xfd, 0xb2, 0xcf, 0x6a, 0xf4, 0xe7, 0x3e, 0xaf, 0x2e, 0xf4, 0xeb, 0xec, 0x69}; - uint32_t count = 0x296f393c; - uint8_t bearer = 0x0b; - uint8_t direction = 1; + uint8_t key[] = {0xb3, 0x12, 0x0f, 0xfd, 0xb2, 0xcf, 0x6a, 0xf4, 0xe7, 0x3e, 0xaf, 0x2e, 0xf4, 0xeb, 0xec, 0x69}; + uint32_t count = 0x296f393c; + uint8_t bearer = 0x0b; + uint8_t direction = 1; uint32_t len_bits = 16448, len_bytes = (len_bits + 7) / 8; uint8_t msg[] = { @@ -198,15 +198,14 @@ void test_set_7() 0xb3, 0x3d, 0x5d, 0x24, 0xe9, 0xc0, 0x83, 0x11, 0x24, 0xbf, 0x1a, 0xd5, 0x4b, 0x79, 0x25, 0x32, 0x98, 0x3d, 0xd6, 0xc3, 0xa8, 0xb7, 0xd0}; - uint8_t mt[] = {0xab, 0xf3, 0xe6, 0x51}; + uint8_t mt[] = {0xab, 0xf3, 0xe6, 0x51}; uint8_t mac[4]; - // gen mac srslte::security_128_eia1(key, count, bearer, direction, msg, len_bytes, mac); - for(int i=0; i<4; i++) { + for (int i = 0; i < 4; i++) { assert(mac[i] == mt[i]); } } @@ -214,7 +213,8 @@ void test_set_7() * Functions */ -int main(int argc, char * argv[]) { +int main(int argc, char* argv[]) +{ test_set_1(); test_set_4(); test_set_7(); diff --git a/lib/test/common/test_f12345.cc b/lib/test/common/test_f12345.cc index 82f878862..47519fd24 100644 --- a/lib/test/common/test_f12345.cc +++ b/lib/test/common/test_f12345.cc @@ -19,86 +19,77 @@ * */ -#include -#include #include +#include +#include #include "srslte/common/liblte_security.h" - /* * Prototypes */ -int32 arrcmp(uint8_t const * const a, uint8_t const * const b, uint32 len) { +int32 arrcmp(uint8_t const* const a, uint8_t const* const b, uint32 len) +{ uint32 i = 0; - for (i = 0; i < len; i++) { - if (a[i] != b[i]) { - return a[i] - b[i]; - } - } - return 0; + for (i = 0; i < len; i++) { + if (a[i] != b[i]) { + return a[i] - b[i]; + } + } + return 0; } -void arrprint(uint8_t const * const a, uint32 len) { +void arrprint(uint8_t const* const a, uint32 len) +{ uint32 i = 0; - for (i = 0; i < len; i++) { + for (i = 0; i < len; i++) { printf("0x%02x ", a[i]); - if ((i%16==0) && i) + if ((i % 16 == 0) && i) printf("\n"); - } + } printf("\n"); - return; + return; } - - /* * Tests * * Document Reference: 35.208 e00 */ - - /* * Functions */ - void test_set_2() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; - int32 err_cmp = 0; + int32 err_cmp = 0; - uint8_t k[] = {0x46, 0x5b, 0x5c, 0xe8, 0xb1, 0x99, 0xb4, 0x9f, 0xaa, 0x5f, 0x0a, 0x2e, 0xe2, 0x38, 0xa6, 0xbc}; + uint8_t k[] = {0x46, 0x5b, 0x5c, 0xe8, 0xb1, 0x99, 0xb4, 0x9f, 0xaa, 0x5f, 0x0a, 0x2e, 0xe2, 0x38, 0xa6, 0xbc}; uint8_t rand[] = {0x23, 0x55, 0x3c, 0xbe, 0x96, 0x37, 0xa8, 0x9d, 0x21, 0x8a, 0xe6, 0x4d, 0xae, 0x47, 0xbf, 0x35}; - uint8_t sqn[] = {0xff, 0x9b, 0xb4, 0xd0, 0xb6, 0x07}; - uint8_t amf[] = {0xb9, 0xb9}; - uint8_t op[] = {0xcd, 0xc2, 0x02, 0xd5, 0x12, 0x3e, 0x20, 0xf6, 0x2b, 0x6d, 0x67, 0x6a, 0xc7, 0x2c, 0xb3, 0x18}; + uint8_t sqn[] = {0xff, 0x9b, 0xb4, 0xd0, 0xb6, 0x07}; + uint8_t amf[] = {0xb9, 0xb9}; + uint8_t op[] = {0xcd, 0xc2, 0x02, 0xd5, 0x12, 0x3e, 0x20, 0xf6, 0x2b, 0x6d, 0x67, 0x6a, 0xc7, 0x2c, 0xb3, 0x18}; // f1 uint8_t opc_o[16]; - err_lte = liblte_compute_opc(k,op,opc_o); + err_lte = liblte_compute_opc(k, op, opc_o); assert(err_lte == LIBLTE_SUCCESS); arrprint(opc_o, sizeof(opc_o)); uint8_t opc_a[] = {0xcd, 0x63, 0xcb, 0x71, 0x95, 0x4a, 0x9f, 0x4e, 0x48, 0xa5, 0x99, 0x4e, 0x37, 0xa0, 0x2b, 0xaf}; - err_cmp = arrcmp(opc_o,opc_a,sizeof(opc_o)); + err_cmp = arrcmp(opc_o, opc_a, sizeof(opc_o)); assert(err_cmp == 0); uint8_t mac_o[8]; - err_lte = liblte_security_milenage_f1(k, - opc_o, - rand, - sqn, - amf, - mac_o); + err_lte = liblte_security_milenage_f1(k, opc_o, rand, sqn, amf, mac_o); assert(err_lte == LIBLTE_SUCCESS); - + arrprint(mac_o, sizeof(mac_o)); uint8_t mac_a[] = {0x4a, 0x9f, 0xfa, 0xc3, 0x54, 0xdf, 0xaf, 0xb3}; @@ -107,15 +98,10 @@ void test_set_2() err_cmp = arrcmp(mac_o, mac_a, sizeof(mac_a)); assert(err_cmp == 0); - // f1 star + // f1 star uint8_t mac_so[8]; - err_lte = liblte_security_milenage_f1_star(k, - opc_o, - rand, - sqn, - amf, - mac_so); + err_lte = liblte_security_milenage_f1_star(k, opc_o, rand, sqn, amf, mac_so); assert(err_lte == LIBLTE_SUCCESS); @@ -132,20 +118,14 @@ void test_set_2() uint8_t ik_o[16]; uint8_t ak_o[6]; - err_lte = liblte_security_milenage_f2345(k, - opc_o, - rand, - res_o, - ck_o, - ik_o, - ak_o); + err_lte = liblte_security_milenage_f2345(k, opc_o, rand, res_o, ck_o, ik_o, ak_o); assert(err_lte == LIBLTE_SUCCESS); uint8_t res[] = {0xa5, 0x42, 0x11, 0xd5, 0xe3, 0xba, 0x50, 0xbf}; - uint8_t ck[] = {0xb4, 0x0b, 0xa9, 0xa3, 0xc5, 0x8b, 0x2a, 0x05, 0xbb, 0xf0, 0xd9, 0x87, 0xb2, 0x1b, 0xf8, 0xcb}; - uint8_t ik[] = {0xf7, 0x69, 0xbc, 0xd7, 0x51, 0x04, 0x46, 0x04, 0x12, 0x76, 0x72, 0x71, 0x1c, 0x6d, 0x34, 0x41}; - uint8_t ak[] = {0xaa, 0x68, 0x9c, 0x64, 0x83, 0x70}; + uint8_t ck[] = {0xb4, 0x0b, 0xa9, 0xa3, 0xc5, 0x8b, 0x2a, 0x05, 0xbb, 0xf0, 0xd9, 0x87, 0xb2, 0x1b, 0xf8, 0xcb}; + uint8_t ik[] = {0xf7, 0x69, 0xbc, 0xd7, 0x51, 0x04, 0x46, 0x04, 0x12, 0x76, 0x72, 0x71, 0x1c, 0x6d, 0x34, 0x41}; + uint8_t ak[] = {0xaa, 0x68, 0x9c, 0x64, 0x83, 0x70}; // RESPONSE arrprint(res_o, sizeof(res_o)); @@ -177,16 +157,17 @@ void test_set_2() arrprint(ak_star_o, sizeof(ak_star_o)); uint8_t ak_star[] = {0x45, 0x1e, 0x8b, 0xec, 0xa4, 0x3b}; - err_cmp = arrcmp(ak_star_o, ak_star, sizeof(ak_star)); + err_cmp = arrcmp(ak_star_o, ak_star, sizeof(ak_star)); assert(err_cmp == 0); return; } /* - Own test sets + Own test sets */ -int main(int argc, char * argv[]) { +int main(int argc, char* argv[]) +{ test_set_2(); /* diff --git a/lib/test/common/timeout_test.cc b/lib/test/common/timeout_test.cc index 41f594b30..9863140df 100644 --- a/lib/test/common/timeout_test.cc +++ b/lib/test/common/timeout_test.cc @@ -19,55 +19,55 @@ * */ +#include "srslte/common/timeout.h" #include #include -#include "srslte/common/timeout.h" using namespace srslte; -class callback - : public timeout_callback +class callback : public timeout_callback { public: - callback() { - finished = false; + callback() + { + finished = false; pthread_mutex_init(&mutex, NULL); pthread_cond_init(&cvar, NULL); bzero(&start_time, sizeof(start_time)); } - + void timeout_expired(uint32_t timeout_id) { pthread_mutex_lock(&mutex); - finished = true; + finished = true; pthread_cond_signal(&cvar); pthread_mutex_unlock(&mutex); } void wait() { pthread_mutex_lock(&mutex); - while(!finished) { + while (!finished) { pthread_cond_wait(&cvar, &mutex); } pthread_mutex_unlock(&mutex); } struct timeval start_time[3]; + private: - bool finished; - pthread_cond_t cvar; - pthread_mutex_t mutex; + bool finished; + pthread_cond_t cvar; + pthread_mutex_t mutex; }; - int timer_thread_test() { - bool result; - uint32_t id = 0; - uint32_t duration_msec = 5; + bool result; + uint32_t id = 0; + uint32_t duration_msec = 5; uint32_t result_tolerance = 1; callback c; - timeout t; + timeout t; gettimeofday(&c.start_time[1], NULL); t.start(duration_msec); @@ -79,50 +79,59 @@ int timer_thread_test() gettimeofday(&c.start_time[2], NULL); get_time_interval(c.start_time); - uint32_t diff_ms = c.start_time[0].tv_usec*1e-3; + uint32_t diff_ms = c.start_time[0].tv_usec * 1e-3; printf("Target duration: %dms, started: %ld:%ld, ended: %ld:%ld, actual duration %dms\n", - duration_msec, c.start_time[1].tv_sec, c.start_time[1].tv_usec, c.start_time[2].tv_sec, c.start_time[2].tv_usec, diff_ms); + duration_msec, + c.start_time[1].tv_sec, + c.start_time[1].tv_usec, + c.start_time[2].tv_sec, + c.start_time[2].tv_usec, + diff_ms); result = ((duration_msec - result_tolerance) < diff_ms || diff_ms < (duration_msec + result_tolerance)); - if(result) { + if (result) { printf("Timer thread test passed\n"); return 0; - }else{ + } else { return -1; } } int single_thread_test() { - bool result; - uint32_t id = 0; + bool result; + uint32_t id = 0; uint32_t duration_msec = 5; callback c; - timeout t; + timeout t; gettimeofday(&c.start_time[1], NULL); t.start(duration_msec, 0, &c); c.wait(); gettimeofday(&c.start_time[2], NULL); get_time_interval(c.start_time); - uint32_t diff_ms = c.start_time[0].tv_usec*1e-3; + uint32_t diff_ms = c.start_time[0].tv_usec * 1e-3; printf("Target duration: %dms, started: %ld:%ld, ended: %ld:%ld, actual duration %dms\n", - duration_msec, c.start_time[1].tv_sec, c.start_time[1].tv_usec, c.start_time[2].tv_sec, c.start_time[2].tv_usec, diff_ms); + duration_msec, + c.start_time[1].tv_sec, + c.start_time[1].tv_usec, + c.start_time[2].tv_sec, + c.start_time[2].tv_usec, + diff_ms); result = (diff_ms == duration_msec); - if(result) { + if (result) { printf("Single thread test passed\n"); return 0; - }else{ + } else { return -1; } } - -int main(int argc, char **argv) +int main(int argc, char** argv) { if (single_thread_test()) { printf("Single thread test failed.\n"); diff --git a/lib/test/phy/phy_dl_test.c b/lib/test/phy/phy_dl_test.c index 0da304c5e..b16d7487c 100644 --- a/lib/test/phy/phy_dl_test.c +++ b/lib/test/phy/phy_dl_test.c @@ -28,14 +28,12 @@ #define MAX_DATABUFFER_SIZE (6144 * 16 * 3 / 8) -srslte_cell_t cell = { - .nof_prb = 100, - .nof_ports = 1, - .id = 1, - .cp = SRSLTE_CP_NORM, - .phich_resources = SRSLTE_PHICH_R_1, - .phich_length = SRSLTE_PHICH_NORM -}; +srslte_cell_t cell = {.nof_prb = 100, + .nof_ports = 1, + .id = 1, + .cp = SRSLTE_CP_NORM, + .phich_resources = SRSLTE_PHICH_R_1, + .phich_length = SRSLTE_PHICH_NORM}; static uint32_t transmission_mode = 1; static uint32_t cfi = 1; @@ -47,7 +45,8 @@ static uint32_t mcs = 20; static int cross_carrier_indicator = -1; static bool enable_256qam = false; -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s [cfpndvs]\n", prog); printf("\t-c cell id [Default %d]\n", cell.id); printf("\t-f cfi [Default %d]\n", cfi); @@ -81,7 +80,8 @@ void parse_extensive_param(char* param, char* arg) } } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; // Load default transmission mode to avoid wrong number of ports/antennas @@ -102,7 +102,7 @@ void parse_args(int argc, char **argv) { nof_rx_ant = 1; } else if (transmission_mode < 4) { cell.nof_ports = 2; - nof_rx_ant = 2; + nof_rx_ant = 2; } break; case 'f': @@ -250,8 +250,8 @@ int work_ue(srslte_ue_dl_t* ue_dl, return 0; } -unsigned int -reverse(register unsigned int x) { +unsigned int reverse(register unsigned int x) +{ x = (((x & (uint32_t)0xaaaaaaaa) >> (uint32_t)1) | ((x & (uint32_t)0x55555555) << (uint32_t)1)); x = (((x & (uint32_t)0xcccccccc) >> (uint32_t)2) | ((x & (uint32_t)0x33333333) << (uint32_t)2)); x = (((x & (uint32_t)0xf0f0f0f0) >> (uint32_t)4) | ((x & (uint32_t)0x0f0f0f0f) << (uint32_t)4)); @@ -259,7 +259,8 @@ reverse(register unsigned int x) { return ((x >> (uint32_t)16) | (x << (uint32_t)16)); } -uint32_t prbset_to_bitmask() { +uint32_t prbset_to_bitmask() +{ uint32_t mask = 0; uint32_t nb = (uint32_t)ceilf((float)cell.nof_prb / srslte_ra_type0_P(cell.nof_prb)); for (uint32_t i = 0; i < nb; i++) { @@ -322,25 +323,26 @@ static int check_evm(srslte_enb_dl_t* enb_dl, srslte_ue_dl_t* ue_dl, srslte_ue_d return ret; } -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ srslte_enb_dl_t* enb_dl = srslte_vec_malloc(sizeof(srslte_enb_dl_t)); srslte_ue_dl_t* ue_dl = srslte_vec_malloc(sizeof(srslte_ue_dl_t)); srslte_random_t random = srslte_random_init(0); - struct timeval t[3] = {}; - size_t tx_nof_bits = 0, rx_nof_bits = 0; - srslte_softbuffer_tx_t *softbuffer_tx[SRSLTE_MAX_TB] = {}; - srslte_softbuffer_rx_t *softbuffer_rx[SRSLTE_MAX_TB] = {}; - uint8_t *data_tx[SRSLTE_MAX_TB] = {}; - uint8_t *data_rx[SRSLTE_MAX_TB] = {}; - uint32_t count_failures = 0, count_tbs = 0; - size_t pdsch_decode_us = 0; + struct timeval t[3] = {}; + size_t tx_nof_bits = 0, rx_nof_bits = 0; + srslte_softbuffer_tx_t* softbuffer_tx[SRSLTE_MAX_TB] = {}; + srslte_softbuffer_rx_t* softbuffer_rx[SRSLTE_MAX_TB] = {}; + uint8_t* data_tx[SRSLTE_MAX_TB] = {}; + uint8_t* data_rx[SRSLTE_MAX_TB] = {}; + uint32_t count_failures = 0, count_tbs = 0; + size_t pdsch_decode_us = 0; size_t pdsch_encode_us = 0; int ret = -1; parse_args(argc, argv); - cf_t *signal_buffer[SRSLTE_MAX_PORTS] = {NULL}; + cf_t* signal_buffer[SRSLTE_MAX_PORTS] = {NULL}; /* * Allocate Memory @@ -354,7 +356,7 @@ int main(int argc, char **argv) { } for (int i = 0; i < SRSLTE_MAX_TB; i++) { - softbuffer_tx[i] = (srslte_softbuffer_tx_t *) calloc(sizeof(srslte_softbuffer_tx_t), 1); + softbuffer_tx[i] = (srslte_softbuffer_tx_t*)calloc(sizeof(srslte_softbuffer_tx_t), 1); if (!softbuffer_tx[i]) { ERROR("Error allocating softbuffer_tx\n"); goto quit; @@ -365,7 +367,7 @@ int main(int argc, char **argv) { goto quit; } - softbuffer_rx[i] = (srslte_softbuffer_rx_t *) calloc(sizeof(srslte_softbuffer_rx_t), 1); + softbuffer_rx[i] = (srslte_softbuffer_rx_t*)calloc(sizeof(srslte_softbuffer_rx_t), 1); if (!softbuffer_rx[i]) { ERROR("Error allocating softbuffer_rx\n"); goto quit; @@ -647,28 +649,26 @@ int main(int argc, char **argv) { printf("%zd were transmitted, %zd bits were received.\n", tx_nof_bits, rx_nof_bits); printf("[Rates in Mbps] Granted Processed\n"); printf(" eNb: %5.1f %5.1f\n", - (float) tx_nof_bits / (float) nof_subframes / 1000.0f, - (float) rx_nof_bits / pdsch_encode_us); + (float)tx_nof_bits / (float)nof_subframes / 1000.0f, + (float)rx_nof_bits / pdsch_encode_us); printf(" UE: %5.1f %5.1f\n", - (float) rx_nof_bits / (float) nof_subframes / 1000.0f, - (float) rx_nof_bits / pdsch_decode_us); + (float)rx_nof_bits / (float)nof_subframes / 1000.0f, + (float)rx_nof_bits / pdsch_decode_us); - printf("BLER: %5.1f%%\n", (float) count_failures / (float) count_tbs * 100.0f); + printf("BLER: %5.1f%%\n", (float)count_failures / (float)count_tbs * 100.0f); - quit: - srslte_enb_dl_free(enb_dl); - srslte_ue_dl_free(ue_dl); - srslte_random_free(random); +quit: + srslte_enb_dl_free(enb_dl); + srslte_ue_dl_free(ue_dl); + srslte_random_free(random); - for (int i = 0; i < cell.nof_ports; i++) { - if (signal_buffer[i]) { - free(signal_buffer[i]); - } + for (int i = 0; i < cell.nof_ports; i++) { + if (signal_buffer[i]) { + free(signal_buffer[i]); + } } - for ( - int i = 0; - i < SRSLTE_MAX_TB; i++) { + for (int i = 0; i < SRSLTE_MAX_TB; i++) { if (softbuffer_tx[i]) { srslte_softbuffer_tx_free(softbuffer_tx[i]); free(softbuffer_tx[i]); diff --git a/lib/test/upper/rlc_am_control_test.cc b/lib/test/upper/rlc_am_control_test.cc index 932baf59e..9af8a7bed 100644 --- a/lib/test/upper/rlc_am_control_test.cc +++ b/lib/test/upper/rlc_am_control_test.cc @@ -24,16 +24,17 @@ #include // Simple status PDU -uint8_t pdu1[] = {0x00, 0x78}; +uint8_t pdu1[] = {0x00, 0x78}; uint32_t PDU1_LEN = 2; // Status PDU with 4 NACKs -uint8_t pdu2[] = {0x00 ,0x22 ,0x00 ,0x40 ,0x0C ,0x01 ,0xC0 ,0x20}; +uint8_t pdu2[] = {0x00, 0x22, 0x00, 0x40, 0x0C, 0x01, 0xC0, 0x20}; uint32_t PDU2_LEN = 8; -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ srslte::rlc_status_pdu_t s1, s2; - srslte::byte_buffer_t b1,b2; + srslte::byte_buffer_t b1, b2; memcpy(b1.msg, &pdu1[0], PDU1_LEN); b1.N_bytes = PDU1_LEN; @@ -42,7 +43,7 @@ int main(int argc, char **argv) { assert(s1.N_nack == 0); rlc_am_write_status_pdu(&s1, &b2); assert(b2.N_bytes == PDU1_LEN); - for(uint32_t i=0;i // Fixed header only -uint8_t pdu1[] = {0x88, 0x06}; +uint8_t pdu1[] = {0x88, 0x06}; uint32_t PDU1_LEN = 2; // Fixed + 2 LI fields (each 1500) -uint8_t pdu2[] = {0x8C, 0x00, 0xDD, 0xC5, 0xDC}; +uint8_t pdu2[] = {0x8C, 0x00, 0xDD, 0xC5, 0xDC}; uint32_t PDU2_LEN = 5; // Fixed + 3 LI fields (each 1500) -uint8_t pdu3[] = {0x8C, 0x00, 0xDD, 0xCD, 0xDC, 0x5D, 0xC0}; +uint8_t pdu3[] = {0x8C, 0x00, 0xDD, 0xCD, 0xDC, 0x5D, 0xC0}; uint32_t PDU3_LEN = 7; // D/C = 1 = Data PDU @@ -46,7 +46,7 @@ uint32_t PDU3_LEN = 7; // LI1 = 1010011 1110 (1342 Dec) // E = 0 // LI2 = 10111011100 (1500 Dec) -uint8_t pdu4[] = {0x9C, 0x02, 0xD3, 0xE5, 0xDC }; +uint8_t pdu4[] = {0x9C, 0x02, 0xD3, 0xE5, 0xDC}; uint32_t PDU4_LEN = 5; using namespace srslte; diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index 192f16b0a..4e4c6ca1a 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -37,10 +37,10 @@ using namespace asn1::rrc; class rlc_am_tester : public pdcp_interface_rlc, public rrc_interface_rlc { public: - rlc_am_tester(rlc_pcap *pcap_ = NULL) + rlc_am_tester(rlc_pcap* pcap_ = NULL) { n_sdus = 0; - pcap = pcap_; + pcap = pcap_; } // PDCP interface @@ -55,12 +55,12 @@ public: void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) {} // RRC interface - void max_retx_attempted(){} + void max_retx_attempted() {} std::string get_rb_name(uint32_t lcid) { return std::string(""); } unique_byte_buffer_t sdus[10]; - int n_sdus; - rlc_pcap *pcap; + int n_sdus; + rlc_pcap* pcap; }; class ul_writer : public thread @@ -71,8 +71,8 @@ public: void stop() { running = false; - int cnt=0; - while(running && cnt<100) { + int cnt = 0; + while (running && cnt < 100) { usleep(10000); cnt++; } @@ -80,11 +80,12 @@ public: } private: - void run_thread() { - int sn = 0; + void run_thread() + { + int sn = 0; running = true; - while(running) { - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + while (running) { + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t pdu = srslte::allocate_unique_buffer(*pool, "rlc_tester::run_thread", true); if (!pdu) { printf("Error: Could not allocate PDU in rlc_tester::run_thread\n\n\n"); @@ -103,7 +104,7 @@ private: } rlc_am_lte* rlc; - bool running; + bool running; }; void basic_test_tx(rlc_am_lte* rlc, byte_buffer_t pdu_bufs[NBUFS]) @@ -160,8 +161,7 @@ bool basic_test() basic_test_tx(&rlc1, pdu_bufs); // Write 5 PDUs into RLC2 - for(int i=0;iN_bytes == 1); - assert(*(tester.sdus[i]->msg) == i); + assert(*(tester.sdus[i]->msg) == i); } // Check statistics @@ -221,10 +220,9 @@ bool concat_test() } // Push 5 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[NBUFS]; - for(int i=0;imsg[0] = i; // Write the index into the buffer sdu_bufs[i]->N_bytes = 1; // Give each buffer a size of 1 byte @@ -236,7 +234,7 @@ bool concat_test() // Read 1 PDUs from RLC1 containing all 5 SDUs byte_buffer_t pdu_buf; int len = rlc1.read_pdu(pdu_buf.msg, 13); // 8 bytes for header + payload - pdu_buf.N_bytes = len; + pdu_buf.N_bytes = len; assert(0 == rlc1.get_buffer_state()); @@ -246,10 +244,9 @@ bool concat_test() // No status report as we haven't crossed polling thresholds assert(tester.n_sdus == 5); - for(int i=0; iN_bytes == 1); - assert(*(tester.sdus[i]->msg) == i); + assert(*(tester.sdus[i]->msg) == i); } // Check statistics @@ -291,12 +288,11 @@ bool segment_test(bool in_seq_rx) } // Push 5 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[NBUFS]; - for(int i=0;imsg[j] = j; sdu_bufs[i]->N_bytes = 10; // Give each buffer a size of 10 bytes rlc1.write_sdu(std::move(sdu_bufs[i])); @@ -306,9 +302,9 @@ bool segment_test(bool in_seq_rx) // Read PDUs from RLC1 (force segmentation) byte_buffer_t pdu_bufs[20]; - int n_pdus = 0; - while(rlc1.get_buffer_state() > 0){ - len = rlc1.read_pdu(pdu_bufs[n_pdus].msg, 10); // 2 header + payload + int n_pdus = 0; + while (rlc1.get_buffer_state() > 0) { + len = rlc1.read_pdu(pdu_bufs[n_pdus].msg, 10); // 2 header + payload pdu_bufs[n_pdus++].N_bytes = len; } @@ -334,7 +330,7 @@ bool segment_test(bool in_seq_rx) // Read status PDU from RLC2 byte_buffer_t status_buf; - len = rlc2.read_pdu(status_buf.msg, 10); // 10 bytes is enough to hold the status + len = rlc2.read_pdu(status_buf.msg, 10); // 10 bytes is enough to hold the status status_buf.N_bytes = len; // Write status PDU to RLC1 @@ -344,11 +340,10 @@ bool segment_test(bool in_seq_rx) assert(0 == rlc2.get_buffer_state()); assert(tester.n_sdus == 5); - for(int i=0; iN_bytes == 10); - for(int j=0;j<10;j++) - assert(tester.sdus[i]->msg[j] == j); + for (int j = 0; j < 10; j++) + assert(tester.sdus[i]->msg[j] == j); } // Check statistics @@ -390,10 +385,9 @@ bool retx_test() } // Push 5 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[NBUFS]; - for(int i=0;imsg[0] = i; // Write the index into the buffer sdu_bufs[i]->N_bytes = 1; // Give each buffer a size of 1 byte @@ -404,18 +398,16 @@ bool retx_test() // Read 5 PDUs from RLC1 (1 byte each) byte_buffer_t pdu_bufs[NBUFS]; - for(int i=0;iN_bytes != 1) return -1; - if (*(tester.sdus[i]->msg) != i) return -1; + for (int i = 0; i < tester.n_sdus; i++) { + if (tester.sdus[i]->N_bytes != 1) + return -1; + if (*(tester.sdus[i]->msg) != i) + return -1; } return 0; @@ -484,12 +477,11 @@ bool resegment_test_1() } // Push 5 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[NBUFS]; - for(int i=0;imsg[j] = j; sdu_bufs[i]->N_bytes = 10; // Give each buffer a size of 10 bytes rlc1.write_sdu(std::move(sdu_bufs[i])); @@ -499,18 +491,16 @@ bool resegment_test_1() // Read 5 PDUs from RLC1 (10 bytes each) byte_buffer_t pdu_bufs[NBUFS]; - for(int i=0;iN_bytes != 10) return -1; - for(int j=0;j<10;j++) - if (tester.sdus[i]->msg[j] != j) return -1; + for (int i = 0; i < tester.n_sdus; i++) { + if (tester.sdus[i]->N_bytes != 10) + return -1; + for (int j = 0; j < 10; j++) + if (tester.sdus[i]->msg[j] != j) + return -1; } return 0; @@ -590,12 +581,11 @@ bool resegment_test_2() } // Push 5 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[NBUFS]; - for(int i=0;imsg[j] = j; sdu_bufs[i]->N_bytes = 10; // Give each buffer a size of 10 bytes rlc1.write_sdu(std::move(sdu_bufs[i])); @@ -614,9 +604,8 @@ bool resegment_test_2() assert(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 (skip SN 2) - for(int i=0;iN_bytes != 10) return -1; - for(int j=0;j<10;j++) - if (tester.sdus[i]->msg[j] != j) return -1; + for (int i = 0; i < tester.n_sdus; i++) { + if (tester.sdus[i]->N_bytes != 10) + return -1; + for (int j = 0; j < 10; j++) + if (tester.sdus[i]->msg[j] != j) + return -1; } return 0; @@ -692,12 +682,11 @@ bool resegment_test_3() } // Push 5 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[NBUFS]; - for(int i=0;imsg[j] = j; sdu_bufs[i]->N_bytes = 10; // Give each buffer a size of 10 bytes rlc1.write_sdu(std::move(sdu_bufs[i])); @@ -716,9 +705,8 @@ bool resegment_test_3() assert(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 (skip SN 2) - for(int i=0;iN_bytes != 10) return -1; - for(int j=0;j<10;j++) - if (tester.sdus[i]->msg[j] != j) return -1; + for (int i = 0; i < tester.n_sdus; i++) { + if (tester.sdus[i]->N_bytes != 10) + return -1; + for (int j = 0; j < 10; j++) + if (tester.sdus[i]->msg[j] != j) + return -1; } return 0; @@ -789,12 +778,11 @@ bool resegment_test_4() } // Push 5 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[NBUFS]; - for(int i=0;imsg[j] = j; sdu_bufs[i]->N_bytes = 10; // Give each buffer a size of 10 bytes rlc1.write_sdu(std::move(sdu_bufs[i])); @@ -813,9 +801,8 @@ bool resegment_test_4() assert(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 (skip SN 2) - for(int i=0;iN_bytes != 10) return -1; - for(int j=0;j<10;j++) - if (tester.sdus[i]->msg[j] != j) return -1; + for (int i = 0; i < tester.n_sdus; i++) { + if (tester.sdus[i]->N_bytes != 10) + return -1; + for (int j = 0; j < 10; j++) + if (tester.sdus[i]->msg[j] != j) + return -1; } return 0; @@ -888,12 +876,11 @@ bool resegment_test_5() } // Push 5 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[NBUFS]; - for(int i=0;imsg[j] = j; sdu_bufs[i]->N_bytes = 10; // Give each buffer a size of 10 bytes rlc1.write_sdu(std::move(sdu_bufs[i])); @@ -912,9 +899,8 @@ bool resegment_test_5() assert(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 (skip SN 2) - for(int i=0;iN_bytes != 10) return -1; - for(int j=0;j<10;j++) - if (tester.sdus[i]->msg[j] != j) return -1; + for (int i = 0; i < tester.n_sdus; i++) { + if (tester.sdus[i]->N_bytes != 10) + return -1; + for (int j = 0; j < 10; j++) + if (tester.sdus[i]->msg[j] != j) + return -1; } return 0; @@ -988,20 +975,18 @@ bool resegment_test_6() } // Push SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[9]; - for(int i=0;i<3;i++) - { + for (int i = 0; i < 3; i++) { sdu_bufs[i] = srslte::allocate_unique_buffer(*pool, true); - for(int j=0;j<10;j++) + for (int j = 0; j < 10; j++) sdu_bufs[i]->msg[j] = j; sdu_bufs[i]->N_bytes = 10; // Give each buffer a size of 10 bytes rlc1.write_sdu(std::move(sdu_bufs[i])); } - for(int i=3;i<9;i++) - { + for (int i = 3; i < 9; i++) { sdu_bufs[i] = srslte::allocate_unique_buffer(*pool, true); - for(int j=0;j<54;j++) + for (int j = 0; j < 54; j++) sdu_bufs[i]->msg[j] = j; sdu_bufs[i]->N_bytes = 54; rlc1.write_sdu(std::move(sdu_bufs[i])); @@ -1011,21 +996,20 @@ bool resegment_test_6() // Read PDUs from RLC1 (10, 10, 10, 270, 54) byte_buffer_t pdu_bufs[5]; - for(int i=0;i<3;i++) { - len = rlc1.read_pdu(pdu_bufs[i].msg, 12); + for (int i = 0; i < 3; i++) { + len = rlc1.read_pdu(pdu_bufs[i].msg, 12); pdu_bufs[i].N_bytes = len; } - len = rlc1.read_pdu(pdu_bufs[3].msg, 278); + len = rlc1.read_pdu(pdu_bufs[3].msg, 278); pdu_bufs[3].N_bytes = len; - len = rlc1.read_pdu(pdu_bufs[4].msg, 56); + len = rlc1.read_pdu(pdu_bufs[4].msg, 56); pdu_bufs[4].N_bytes = len; assert(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 (skip SN 3) - for(int i=0;i<5;i++) - { - if(i != 3) + for (int i = 0; i < 5; i++) { + if (i != 3) rlc2.write_pdu(pdu_bufs[i].msg, pdu_bufs[i].N_bytes); } @@ -1039,7 +1023,7 @@ bool resegment_test_6() // Read status PDU from RLC2 byte_buffer_t status_buf; - len = rlc2.read_pdu(status_buf.msg, 10); // 10 bytes is enough to hold the status + len = rlc2.read_pdu(status_buf.msg, 10); // 10 bytes is enough to hold the status status_buf.N_bytes = len; // Write status PDU to RLC1 @@ -1049,7 +1033,7 @@ bool resegment_test_6() // Read the retx PDU from RLC1 and force resegmentation byte_buffer_t retx1; - len = rlc1.read_pdu(retx1.msg, 129); + len = rlc1.read_pdu(retx1.msg, 129); retx1.N_bytes = len; // Write the retx PDU to RLC2 @@ -1059,25 +1043,26 @@ bool resegment_test_6() // Read the remaining segment byte_buffer_t retx2; - len = rlc1.read_pdu(retx2.msg, 162); + len = rlc1.read_pdu(retx2.msg, 162); retx2.N_bytes = len; // Write the retx PDU to RLC2 rlc2.write_pdu(retx2.msg, retx2.N_bytes); assert(tester.n_sdus == 9); - for(int i=0;i<3;i++) - { + for (int i = 0; i < 3; i++) { assert(tester.sdus[i]->N_bytes == 10); - for(int j=0;j<10;j++) - assert(tester.sdus[i]->msg[j] == j); + for (int j = 0; j < 10; j++) + assert(tester.sdus[i]->msg[j] == j); } - for(int i=3;i<9;i++) - { - if (i >= tester.n_sdus) return -1; - if(tester.sdus[i]->N_bytes != 54) return -1; - for(int j=0;j<54;j++) { - if (tester.sdus[i]->msg[j] != j) return -1; + for (int i = 3; i < 9; i++) { + if (i >= tester.n_sdus) + return -1; + if (tester.sdus[i]->N_bytes != 54) + return -1; + for (int j = 0; j < 54; j++) { + if (tester.sdus[i]->msg[j] != j) + return -1; } } @@ -1094,7 +1079,7 @@ bool resegment_test_7() // Retx PDU segments: |3|3]3|2| const uint32_t N_SDU_BUFS = 2; const uint32_t N_PDU_BUFS = 5; - const uint32_t sdu_size = 30; + const uint32_t sdu_size = 30; srslte::log_filter log1("RLC_AM_1"); srslte::log_filter log2("RLC_AM_2"); @@ -1124,12 +1109,11 @@ bool resegment_test_7() } // Push 2 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[N_SDU_BUFS]; - for(uint32_t i=0;imsg[j] = i; } sdu_bufs[i]->N_bytes = sdu_size; // Give each buffer a size of 15 bytes @@ -1140,8 +1124,7 @@ bool resegment_test_7() // Read PDUs from RLC1 (15 bytes each) byte_buffer_t pdu_bufs[N_PDU_BUFS]; - for(uint32_t i=0;iN_bytes != sdu_size) return -1; - for(uint32_t j=0;jmsg[j] != i) return -1; + for (int i = 0; i < tester.n_sdus; i++) { + if (tester.sdus[i]->N_bytes != sdu_size) + return -1; + for (uint32_t j = 0; j < N_SDU_BUFS; j++) { + if (tester.sdus[i]->msg[j] != i) + return -1; } } @@ -1256,7 +1240,6 @@ bool resegment_test_7() return 0; } - // Retransmission of PDU segments with different size bool resegment_test_8() { @@ -1267,7 +1250,7 @@ bool resegment_test_8() // Retx PDU segments: | 6 | 6 ] 6 | 6 | 6 | 6 | 6 | 6 | const uint32_t N_SDU_BUFS = 2; const uint32_t N_PDU_BUFS = 5; - const uint32_t sdu_size = 30; + const uint32_t sdu_size = 30; srslte::log_filter log1("RLC_AM_1"); srslte::log_filter log2("RLC_AM_2"); @@ -1297,12 +1280,11 @@ bool resegment_test_8() } // Push 2 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[N_SDU_BUFS]; - for(uint32_t i=0;imsg[j] = i; } sdu_bufs[i]->N_bytes = sdu_size; // Give each buffer a size of 15 bytes @@ -1313,8 +1295,7 @@ bool resegment_test_8() // Read PDUs from RLC1 (15 bytes each) byte_buffer_t pdu_bufs[N_PDU_BUFS]; - for(uint32_t i=0;i 2) { rlc2.write_pdu(pdu_bufs[i].msg, pdu_bufs[i].N_bytes); #if HAVE_PCAP @@ -1406,10 +1387,12 @@ bool resegment_test_8() // Check number of SDUs and their content assert(tester.n_sdus == N_SDU_BUFS); - for(int i=0; iN_bytes != sdu_size) return -1; - for(uint32_t j=0;jmsg[j] != i) return -1; + for (int i = 0; i < tester.n_sdus; i++) { + if (tester.sdus[i]->N_bytes != sdu_size) + return -1; + for (uint32_t j = 0; j < N_SDU_BUFS; j++) { + if (tester.sdus[i]->msg[j] != i) + return -1; } } @@ -1420,7 +1403,6 @@ bool resegment_test_8() return 0; } - bool reset_test() { srslte::log_filter log1("RLC_AM_1"); @@ -1437,26 +1419,26 @@ bool reset_test() } // Push 1 SDU of size 10 into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_buf = srslte::allocate_unique_buffer(*pool, true); - sdu_buf->msg[0] = 1; // Write the index into the buffer - sdu_buf->N_bytes = 100; + sdu_buf->msg[0] = 1; // Write the index into the buffer + sdu_buf->N_bytes = 100; rlc1.write_sdu(std::move(sdu_buf)); // read 1 PDU from RLC1 and force segmentation byte_buffer_t pdu_bufs; - len = rlc1.read_pdu(pdu_bufs.msg, 4); + len = rlc1.read_pdu(pdu_bufs.msg, 4); pdu_bufs.N_bytes = len; // reset RLC1 rlc1.stop(); // read another PDU segment from RLC1 - len = rlc1.read_pdu(pdu_bufs.msg, 4); + len = rlc1.read_pdu(pdu_bufs.msg, 4); pdu_bufs.N_bytes = len; // now empty RLC buffer - len = rlc1.read_pdu(pdu_bufs.msg, 100); + len = rlc1.read_pdu(pdu_bufs.msg, 100); pdu_bufs.N_bytes = len; if (0 != rlc1.get_buffer_state()) { @@ -1663,7 +1645,7 @@ bool status_pdu_test() return 0; } -int main(int argc, char **argv) +int main(int argc, char** argv) { if (basic_test()) { printf("basic_test failed\n"); @@ -1748,7 +1730,7 @@ int main(int argc, char **argv) exit(-1); }; byte_buffer_pool::get_instance()->cleanup(); - + if (stop_test()) { printf("stop_test failed\n"); exit(-1); diff --git a/lib/test/upper/rlc_stress_test.cc b/lib/test/upper/rlc_stress_test.cc index b29f1bb5f..c03ea9422 100644 --- a/lib/test/upper/rlc_stress_test.cc +++ b/lib/test/upper/rlc_stress_test.cc @@ -90,14 +90,13 @@ typedef struct { bool pedantic_sdu_check; } stress_test_args_t; -void parse_args(stress_test_args_t *args, int argc, char *argv[]) { +void parse_args(stress_test_args_t* args, int argc, char* argv[]) +{ // Command line only options bpo::options_description general("General options"); - general.add_options() - ("help,h", "Produce help message") - ("version,v", "Print version information and exit"); + general.add_options()("help,h", "Produce help message")("version,v", "Print version information and exit"); // clang-format off @@ -175,9 +174,9 @@ public: } private: - void run_tti(rlc_interface_mac *tx_rlc, rlc_interface_mac *rx_rlc, bool is_dl) + void run_tti(rlc_interface_mac* tx_rlc, rlc_interface_mac* rx_rlc, bool is_dl) { - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t pdu = srslte::allocate_unique_buffer(*pool, __PRETTY_FUNCTION__, true); if (!pdu) { printf("Fatal Error: Could not allocate PDU in mac_reader::run_thread\n"); @@ -188,10 +187,10 @@ private: if (args.random_opp) { factor = 0.5 + real_dist(mt19937); } - int opp_size = args.avg_opp_size * factor; + int opp_size = args.avg_opp_size * factor; uint32_t buf_state = tx_rlc->get_buffer_state(lcid); if (buf_state > 0) { - int read = tx_rlc->read_pdu(lcid, pdu->msg, opp_size); + int read = tx_rlc->read_pdu(lcid, pdu->msg, opp_size); pdu->N_bytes = read; if (args.pdu_tx_delay_usec > 0) { usleep(args.pdu_tx_delay_usec); @@ -287,16 +286,17 @@ public: void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t sdu) {} // RRC interface - void max_retx_attempted(){} + void max_retx_attempted() {} std::string get_rb_name(uint32_t rx_lcid) { return std::string("DRB1"); } int get_nof_rx_pdus() { return rx_pdus; } private: - void run_thread() { - uint8_t sn = 0; + void run_thread() + { + uint8_t sn = 0; byte_buffer_pool* pool = byte_buffer_pool::get_instance(); - while(run_enable) { + while (run_enable) { unique_byte_buffer_t pdu = srslte::allocate_unique_buffer(*pool, "rlc_tester::run_thread", true); if (pdu == NULL) { printf("Error: Could not allocate PDU in rlc_tester::run_thread\n\n\n"); @@ -316,16 +316,16 @@ private: } } - bool run_enable; - uint64_t rx_pdus; - uint32_t lcid; + bool run_enable; + uint64_t rx_pdus; + uint32_t lcid; srslte::log_filter log; std::string name; stress_test_args_t args; - rlc_interface_pdcp *rlc; + rlc_interface_pdcp* rlc; }; void stress_test(stress_test_args_t args) @@ -467,8 +467,7 @@ void stress_test(stress_test_args_t args) metrics.bearer[lcid].num_rx_bytes); } - -int main(int argc, char **argv) +int main(int argc, char** argv) { srslte_debug_handle_crash(argc, argv); diff --git a/lib/test/upper/rlc_um_data_test.cc b/lib/test/upper/rlc_um_data_test.cc index 06d3cc641..f2839bd61 100644 --- a/lib/test/upper/rlc_um_data_test.cc +++ b/lib/test/upper/rlc_um_data_test.cc @@ -24,26 +24,27 @@ #include // Fixed header only -uint8_t pdu1[] = {0x18 ,0xE2}; +uint8_t pdu1[] = {0x18, 0xE2}; uint32_t PDU1_LEN = 2; // Fixed + 1 LI field (value 104) -uint8_t pdu2[] = {0x1C ,0xE1 ,0x06 ,0x80}; +uint8_t pdu2[] = {0x1C, 0xE1, 0x06, 0x80}; uint32_t PDU2_LEN = 4; -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ srslte::rlc_umd_pdu_header_t h; - srslte::byte_buffer_t b1,b2; + srslte::byte_buffer_t b1, b2; memcpy(b1.msg, &pdu1[0], PDU1_LEN); b1.N_bytes = PDU1_LEN; rlc_um_read_data_pdu_header(&b1, srslte::rlc_umd_sn_size_t::size10bits, &h); assert(0x03 == h.fi); - assert(0 == h.N_li); - assert(226 == h.sn); + assert(0 == h.N_li); + assert(226 == h.sn); rlc_um_write_data_pdu_header(&h, &b2); assert(b2.N_bytes == PDU1_LEN); - for(uint32_t i=0;i tv = {0x00, 0x11, 0x22, 0x33, 0x44}; - srslte::byte_buffer_t pdu = make_pdu_and_log(tv); + srslte::byte_buffer_t pdu = make_pdu_and_log(tv); // unpack PDU rlc_um_nr_pdu_header_t header = {}; @@ -113,7 +113,7 @@ int rlc_um_nr_pdu_test2() // SN = 1 const int header_len = 3, payload_len = 4; const std::array tv = {0x81, 0x01, 0x02, 0x11, 0x22, 0x33, 0x44}; - srslte::byte_buffer_t pdu = make_pdu_and_log(tv); + srslte::byte_buffer_t pdu = make_pdu_and_log(tv); // unpack PDU rlc_um_nr_pdu_header_t header = {}; @@ -141,7 +141,7 @@ int rlc_um_nr_pdu_test3() // SN = 3 const int header_len = 3, payload_len = 4; const std::array tv = {0xc3, 0x01, 0x02, 0x11, 0x22, 0x33, 0x44}; - srslte::byte_buffer_t pdu = make_pdu_and_log(tv); + srslte::byte_buffer_t pdu = make_pdu_and_log(tv); // unpack PDU rlc_um_nr_pdu_header_t header = {}; @@ -169,7 +169,7 @@ int rlc_um_nr_pdu_test4() // SN = 31 const int header_len = 1, payload_len = 4; std::array tv = {0x5f, 0x11, 0x22, 0x33, 0x44}; - srslte::byte_buffer_t pdu = make_pdu_and_log(tv); + srslte::byte_buffer_t pdu = make_pdu_and_log(tv); // unpack PDU rlc_um_nr_pdu_header_t header = {}; diff --git a/lib/test/upper/rlc_um_test.cc b/lib/test/upper/rlc_um_test.cc index e439b864f..fdcea3cf8 100644 --- a/lib/test/upper/rlc_um_test.cc +++ b/lib/test/upper/rlc_um_test.cc @@ -68,10 +68,10 @@ public: tester.set_expected_sdu_len(1); } - srslte::log_filter log1, log2; - srslte::timer_handler timers; - rlc_um_tester tester; - rlc_um_lte rlc1, rlc2; + srslte::log_filter log1, log2; + srslte::timer_handler timers; + rlc_um_tester tester; + rlc_um_lte rlc1, rlc2; }; int basic_test() @@ -79,10 +79,9 @@ int basic_test() rlc_um_lte_test_context1 ctxt; // Push 5 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[NBUFS]; - for(int i=0;imsg = i; // Write the index into the buffer sdu_bufs[i]->N_bytes = 1; // Give each buffer a size of 1 byte @@ -121,7 +120,7 @@ int loss_test() rlc_um_lte_test_context1 ctxt; // Push 5 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[NBUFS]; for (int i = 0; i < NBUFS; i++) { sdu_bufs[i] = srslte::allocate_unique_buffer(*pool, true); @@ -167,10 +166,9 @@ int basic_mbsfn_test() ctxt.rlc2.configure(rlc_config_t::mch_config()); // Push 5 SDUs into RLC1 - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[NBUFS * 2]; - for(int i=0;imsg[0] = i; // Write the index into the buffer sdu_bufs[i]->N_bytes = 1; // Give each buffer a size of 1 byte @@ -180,9 +178,8 @@ int basic_mbsfn_test() TESTASSERT(13 == ctxt.rlc1.get_buffer_state()); // Read 5 PDUs from RLC1 (1 byte each) - byte_buffer_t pdu_bufs[NBUFS*2]; - for(int i=0;imsg[k] = i; @@ -245,11 +241,10 @@ int reassmble_test() } // Read PDUs from RLC1 (use smaller grant for first PDU and large for the rest) - const int max_n_pdus = 100; - int n_pdus = 0; + const int max_n_pdus = 100; + int n_pdus = 0; byte_buffer_t* pdu_bufs[max_n_pdus]; - for(int i=0;iallocate(); int len = ctxt.rlc1.read_pdu(pdu_bufs[i]->msg, (i == 0) ? sdu_len * 3 / 4 : sdu_len * 1.25); pdu_bufs[i]->N_bytes = len; @@ -289,9 +284,8 @@ int reassmble_test() printf("Generated %d PDUs in total\n", n_pdus); // Write all PDUs into RLC2 except first one - for(int i=0;imsg, pdu_bufs[i]->N_bytes); } } @@ -322,15 +316,15 @@ int reassmble_test2() ctxt.rlc2.configure(cnfg); // Push SDUs into RLC1 - const int n_sdus = 25; + const int n_sdus = 25; const int sdu_len = 100; ctxt.tester.set_expected_sdu_len(sdu_len); - const int n_sdu_first_batch = 17; - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + const int n_sdu_first_batch = 17; + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t sdu_bufs[n_sdus]; - for(int i=0;imsg[k] = i; @@ -339,8 +333,8 @@ int reassmble_test2() ctxt.rlc1.write_sdu(std::move(sdu_bufs[i])); } - const int max_n_pdus = 100; - int n_pdus = 0; + const int max_n_pdus = 100; + int n_pdus = 0; byte_buffer_t* pdu_bufs[max_n_pdus]; for (int i = 0; i < max_n_pdus; i++) { pdu_bufs[i] = byte_buffer_pool::get_instance()->allocate(); @@ -367,8 +361,7 @@ int reassmble_test2() } // Read second batch of PDUs - for(int i=n_pdus;iallocate(); int len = ctxt.rlc1.read_pdu(pdu_bufs[i]->msg, sdu_len * 1.25); pdu_bufs[i]->N_bytes = len; @@ -382,8 +375,8 @@ int reassmble_test2() printf("Generated %d PDUs in total\n", n_pdus); // Write all PDUs into RLC2 except first one - for(int i=0;imsg, pdu_bufs[i]->N_bytes); } } @@ -424,4 +417,3 @@ int main(int argc, char** argv) } byte_buffer_pool::get_instance()->cleanup(); } - diff --git a/srsenb/hdr/cfg_parser.h b/srsenb/hdr/cfg_parser.h index 161ccdd67..357e793c1 100644 --- a/srsenb/hdr/cfg_parser.h +++ b/srsenb/hdr/cfg_parser.h @@ -28,9 +28,9 @@ namespace srsenb { class cfg_parser { public: - void parse_sibs(all_args_t *args, rrc_cfg_t *rrc_cfg, phy_cfg_t *phy_config_common); + void parse_sibs(all_args_t* args, rrc_cfg_t* rrc_cfg, phy_cfg_t* phy_config_common); }; -} +} // namespace srsenb #endif // CFG_PARSER_H diff --git a/srsenb/hdr/enb.h b/srsenb/hdr/enb.h index 73bf7cc4e..3a824c2b1 100644 --- a/srsenb/hdr/enb.h +++ b/srsenb/hdr/enb.h @@ -28,9 +28,9 @@ #ifndef SRSENB_ENB_H #define SRSENB_ENB_H +#include #include #include -#include #include "phy/phy.h" #include "srsenb/hdr/stack/rrc/rrc.h" @@ -59,13 +59,13 @@ namespace srsenb { *******************************************************************************/ struct enb_args_t { - uint32_t dl_earfcn; - uint32_t ul_earfcn; - uint32_t n_prb; - uint32_t pci; - uint32_t nof_ports; - uint32_t transmission_mode; - float p_a; + uint32_t dl_earfcn; + uint32_t ul_earfcn; + uint32_t n_prb; + uint32_t pci; + uint32_t nof_ports; + uint32_t transmission_mode; + float p_a; }; struct enb_files_t { @@ -115,7 +115,7 @@ struct all_args_t { class enb : public enb_metrics_interface { public: - static enb *get_instance(void); + static enb* get_instance(void); static void cleanup(void); @@ -137,7 +137,7 @@ public: private: static enb* instance; - const static int ENB_POOL_SIZE = 1024*10; + const static int ENB_POOL_SIZE = 1024 * 10; enb(); @@ -155,7 +155,7 @@ private: srslte::logger* logger = nullptr; srslte::log_filter log; // Own logger for eNB - srslte::log_filter pool_log; + srslte::log_filter pool_log; srslte::byte_buffer_pool* pool = nullptr; @@ -178,4 +178,3 @@ private: } // namespace srsenb #endif // SRSENB_ENB_H - diff --git a/srsenb/hdr/metrics_csv.h b/srsenb/hdr/metrics_csv.h index cd68ed76c..7c089ad20 100644 --- a/srsenb/hdr/metrics_csv.h +++ b/srsenb/hdr/metrics_csv.h @@ -27,11 +27,11 @@ #ifndef SRSENB_METRICS_CSV_H #define SRSENB_METRICS_CSV_H +#include +#include #include #include #include -#include -#include #include "srslte/common/metrics_hub.h" #include "srslte/interfaces/enb_metrics_interface.h" @@ -44,8 +44,8 @@ public: metrics_csv(std::string filename); ~metrics_csv(); - void set_metrics(enb_metrics_t &m, const uint32_t period_usec); - void set_handle(enb_metrics_interface *enb_); + void set_metrics(enb_metrics_t& m, const uint32_t period_usec); + void set_handle(enb_metrics_interface* enb_); void stop(); private: diff --git a/srsenb/hdr/metrics_stdout.h b/srsenb/hdr/metrics_stdout.h index b5dbbe5b0..f91806b54 100644 --- a/srsenb/hdr/metrics_stdout.h +++ b/srsenb/hdr/metrics_stdout.h @@ -41,9 +41,9 @@ public: metrics_stdout(); void toggle_print(bool b); - void set_metrics(enb_metrics_t &m, const uint32_t period_usec); - void set_handle(enb_metrics_interface *enb_); - void stop() {}; + void set_metrics(enb_metrics_t& m, const uint32_t period_usec); + void set_handle(enb_metrics_interface* enb_); + void stop(){}; private: std::string float_to_string(float f, int digits); diff --git a/srsenb/hdr/phy/phy.h b/srsenb/hdr/phy/phy.h index 4e80d47a9..89e751e95 100644 --- a/srsenb/hdr/phy/phy.h +++ b/srsenb/hdr/phy/phy.h @@ -69,7 +69,7 @@ public: static uint32_t tti_to_SFN(uint32_t tti); static uint32_t tti_to_subf(uint32_t tti); - + void start_plot(); void set_config_dedicated(uint16_t rnti, asn1::rrc::phys_cfg_ded_s* dedicated); @@ -82,12 +82,12 @@ private: phy_rrc_cfg_t phy_rrc_config = {}; uint32_t nof_workers = 0; - const static int MAX_WORKERS = 4; - const static int DEFAULT_WORKERS = 2; - + const static int MAX_WORKERS = 4; + const static int DEFAULT_WORKERS = 2; + const static int PRACH_WORKER_THREAD_PRIO = 3; - const static int SF_RECV_THREAD_PRIO = 1; - const static int WORKERS_THREAD_PRIO = 2; + const static int SF_RECV_THREAD_PRIO = 1; + const static int WORKERS_THREAD_PRIO = 2; srslte::radio_interface_phy* radio = nullptr; diff --git a/srsenb/hdr/phy/phy_common.h b/srsenb/hdr/phy/phy_common.h index b42fe7d43..118ded324 100644 --- a/srsenb/hdr/phy/phy_common.h +++ b/srsenb/hdr/phy/phy_common.h @@ -27,10 +27,10 @@ #include "srslte/common/log.h" #include "srslte/common/thread_pool.h" #include "srslte/common/threads.h" -#include "srslte/phy/channel/channel.h" #include "srslte/interfaces/common_interfaces.h" #include "srslte/interfaces/enb_interfaces.h" #include "srslte/interfaces/enb_metrics_interface.h" +#include "srslte/phy/channel/channel.h" #include "srslte/radio/radio.h" #include #include @@ -66,10 +66,11 @@ public: void set_nof_workers(uint32_t nof_workers); bool init(const srslte_cell_t& cell_, srslte::radio_interface_phy* radio_handler, stack_interface_phy_lte* mac); - void reset(); + void reset(); void stop(); - - void worker_end(uint32_t tx_mutex_cnt, cf_t *buffer[SRSLTE_MAX_PORTS], uint32_t nof_samples, srslte_timestamp_t tx_time); + + void + worker_end(uint32_t tx_mutex_cnt, cf_t* buffer[SRSLTE_MAX_PORTS], uint32_t nof_samples, srslte_timestamp_t tx_time); // Common objects srslte_cell_t cell = {}; @@ -81,25 +82,26 @@ public: // Physical Downlink Config common srslte_dl_cfg_t dl_cfg_com = {}; - srslte::radio_interface_phy* radio = nullptr; - stack_interface_phy_lte* stack = nullptr; + srslte::radio_interface_phy* radio = nullptr; + stack_interface_phy_lte* stack = nullptr; srslte::channel_ptr dl_channel = nullptr; // Common objects for schedulign grants stack_interface_phy_lte::ul_sched_t ul_grants[TTIMOD_SZ] = {}; stack_interface_phy_lte::dl_sched_t dl_grants[TTIMOD_SZ] = {}; - // Map of pending ACKs for each user + // Map of pending ACKs for each user typedef struct { - bool is_pending[TTIMOD_SZ][SRSLTE_MAX_TB]; + bool is_pending[TTIMOD_SZ][SRSLTE_MAX_TB]; uint16_t n_pdcch[TTIMOD_SZ]; } pending_ack_t; - class common_ue { - public: - pending_ack_t pending_ack = {}; - uint8_t ri = 0; - srslte_ra_tb_t last_tb[SRSLTE_MAX_HARQ_PROC] = {}; + class common_ue + { + public: + pending_ack_t pending_ack = {}; + uint8_t ri = 0; + srslte_ra_tb_t last_tb[SRSLTE_MAX_HARQ_PROC] = {}; }; std::map common_ue_db; @@ -122,8 +124,8 @@ public: void set_mch_period_stop(uint32_t stop); private: - std::vector tx_sem; - bool is_first_tx = false; + std::vector tx_sem; + bool is_first_tx = false; uint32_t nof_workers = 0; uint32_t max_workers = 0; @@ -136,15 +138,14 @@ private: phy_interface_stack_lte::phy_cfg_mbsfn_t mbsfn; bool sib13_configured = false; bool mcch_configured = false; - uint8_t mch_table[40] = {}; - uint8_t mcch_table[10] = {}; + uint8_t mch_table[40] = {}; + uint8_t mcch_table[10] = {}; uint32_t mch_period_stop = 0; uint8_t mch_sf_idx_lut[10] = {}; - bool is_mch_subframe(srslte_mbsfn_cfg_t* cfg, uint32_t phy_tti); - bool is_mcch_subframe(srslte_mbsfn_cfg_t* cfg, uint32_t phy_tti); + bool is_mch_subframe(srslte_mbsfn_cfg_t* cfg, uint32_t phy_tti); + bool is_mcch_subframe(srslte_mbsfn_cfg_t* cfg, uint32_t phy_tti); void add_rnti(uint16_t rnti); - }; } // namespace srsenb diff --git a/srsenb/hdr/phy/phy_metrics.h b/srsenb/hdr/phy/phy_metrics.h index b794f1860..946368511 100644 --- a/srsenb/hdr/phy/phy_metrics.h +++ b/srsenb/hdr/phy/phy_metrics.h @@ -22,31 +22,27 @@ #ifndef SRSENB_PHY_METRICS_H #define SRSENB_PHY_METRICS_H - namespace srsenb { -// PHY metrics per user +// PHY metrics per user -struct ul_metrics_t -{ +struct ul_metrics_t { float n; float sinr; float rssi; float turbo_iters; float mcs; - int n_samples; + int n_samples; }; -struct dl_metrics_t -{ +struct dl_metrics_t { float mcs; - int n_samples; + int n_samples; }; -struct phy_metrics_t -{ - dl_metrics_t dl; - ul_metrics_t ul; +struct phy_metrics_t { + dl_metrics_t dl; + ul_metrics_t ul; }; } // namespace srsenb diff --git a/srsenb/hdr/phy/prach_worker.h b/srsenb/hdr/phy/prach_worker.h index 578eaeadd..506934ca9 100644 --- a/srsenb/hdr/phy/prach_worker.h +++ b/srsenb/hdr/phy/prach_worker.h @@ -22,11 +22,11 @@ #ifndef SRSENB_PRACH_WORKER_H #define SRSENB_PRACH_WORKER_H -#include "srslte/interfaces/enb_interfaces.h" -#include "srslte/common/log.h" -#include "srslte/common/threads.h" #include "srslte/common/block_queue.h" #include "srslte/common/buffer_pool.h" +#include "srslte/common/log.h" +#include "srslte/common/threads.h" +#include "srslte/interfaces/enb_interfaces.h" namespace srsenb { @@ -40,10 +40,10 @@ public: stack_interface_phy_lte* mac, srslte::log* log_h, int priority); - int new_tti(uint32_t tti, cf_t *buffer); + int new_tti(uint32_t tti, cf_t* buffer); void set_max_prach_offset_us(float delay_us); void stop(); - + private: uint32_t cc_idx = 0; uint32_t prach_nof_det = 0; @@ -55,8 +55,9 @@ private: srslte_prach_cfg_t prach_cfg = {}; srslte_prach_t prach = {}; - const static int sf_buffer_sz = 128*1024; - class sf_buffer { + const static int sf_buffer_sz = 128 * 1024; + class sf_buffer + { public: sf_buffer() = default; void reset() @@ -84,9 +85,7 @@ private: uint32_t sf_cnt = 0; void run_thread() final; - int run_tti(sf_buffer *b); - - + int run_tti(sf_buffer* b); }; class prach_worker_pool @@ -136,5 +135,5 @@ public: return ret; } }; -} +} // namespace srsenb #endif // SRSENB_PRACH_WORKER_H diff --git a/srsenb/hdr/phy/sf_worker.h b/srsenb/hdr/phy/sf_worker.h index 6394bc88b..6a3102f4b 100644 --- a/srsenb/hdr/phy/sf_worker.h +++ b/srsenb/hdr/phy/sf_worker.h @@ -34,7 +34,7 @@ namespace srsenb { class sf_worker : public srslte::thread_pool::worker { public: - sf_worker() = default; + sf_worker() = default; ~sf_worker(); void init(phy_common* phy, srslte::log* log_h); void stop() final; @@ -61,10 +61,10 @@ private: void work_imp() final; /* Common objects */ - srslte::log* log_h = nullptr; - phy_common* phy = nullptr; - bool initiated = false; - bool running = false; + srslte::log* log_h = nullptr; + phy_common* phy = nullptr; + bool initiated = false; + bool running = false; std::mutex work_mutex; uint32_t tti_rx = 0, tti_tx_dl = 0, tti_tx_ul = 0; @@ -75,7 +75,6 @@ private: std::vector > cc_workers; srslte_softbuffer_tx_t temp_mbsfn_softbuffer = {}; - }; } // namespace srsenb diff --git a/srsenb/hdr/phy/txrx.h b/srsenb/hdr/phy/txrx.h index cea0eb0f2..28a8eb106 100644 --- a/srsenb/hdr/phy/txrx.h +++ b/srsenb/hdr/phy/txrx.h @@ -27,12 +27,12 @@ #include "srslte/common/log.h" #include "srslte/common/thread_pool.h" #include "srslte/common/threads.h" -#include "srslte/radio/radio.h" #include "srslte/phy/channel/channel.h" +#include "srslte/radio/radio.h" namespace srsenb { - -typedef _Complex float cf_t; + +typedef _Complex float cf_t; class txrx : public thread { @@ -45,7 +45,7 @@ public: srslte::log* log_h, uint32_t prio); void stop(); - + private: void run_thread() final; diff --git a/srsenb/hdr/stack/enb_stack_base.h b/srsenb/hdr/stack/enb_stack_base.h index 6aef89764..a4c7e3cc1 100644 --- a/srsenb/hdr/stack/enb_stack_base.h +++ b/srsenb/hdr/stack/enb_stack_base.h @@ -54,11 +54,11 @@ typedef struct { } stack_log_args_t; typedef struct { - mac_args_t mac; - s1ap_args_t s1ap; - pcap_args_t pcap; - stack_log_args_t log; - embms_args_t embms; + mac_args_t mac; + s1ap_args_t s1ap; + pcap_args_t pcap; + stack_log_args_t log; + embms_args_t embms; } stack_args_t; struct stack_metrics_t; diff --git a/srsenb/hdr/stack/mac/mac.h b/srsenb/hdr/stack/mac/mac.h index ea7717c24..c92e059b9 100644 --- a/srsenb/hdr/stack/mac/mac.h +++ b/srsenb/hdr/stack/mac/mac.h @@ -82,15 +82,15 @@ public: void reset(); /* Manages UE scheduling context */ - int ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t *cfg); + int ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t* cfg); int ue_rem(uint16_t rnti); - + // Indicates that the PHY config dedicated has been enabled or not - void phy_config_enabled(uint16_t rnti, bool enabled); + void phy_config_enabled(uint16_t rnti, bool enabled); /* Manages UE bearers and associated configuration */ - int bearer_ue_cfg(uint16_t rnti, uint32_t lc_id, sched_interface::ue_bearer_cfg_t *cfg); - int bearer_ue_rem(uint16_t rnti, uint32_t lc_id); + int bearer_ue_cfg(uint16_t rnti, uint32_t lc_id, sched_interface::ue_bearer_cfg_t* cfg); + int bearer_ue_rem(uint16_t rnti, uint32_t lc_id); int rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue); bool process_pdus(); @@ -124,37 +124,39 @@ private: /* Scheduler unit */ sched scheduler; - dl_metric_rr sched_metric_dl_rr; - ul_metric_rr sched_metric_ul_rr; + dl_metric_rr sched_metric_dl_rr; + ul_metric_rr sched_metric_ul_rr; sched_interface::cell_cfg_t cell_config; - - + sched_interface::dl_pdu_mch_t mch; - - + /* Map of active UEs */ - std::map ue_db; - uint16_t last_rnti; - - uint8_t* assemble_rar(sched_interface::dl_sched_rar_grant_t *grants, uint32_t nof_grants, int rar_idx, uint32_t pdu_len, uint32_t tti); + std::map ue_db; + uint16_t last_rnti; + + uint8_t* assemble_rar(sched_interface::dl_sched_rar_grant_t* grants, + uint32_t nof_grants, + int rar_idx, + uint32_t pdu_len, + uint32_t tti); uint8_t* assemble_si(uint32_t index); const static int rar_payload_len = 128; std::vector rar_pdu_msg; srslte::byte_buffer_t rar_payload[sched_interface::MAX_RAR_LIST]; - const static int NOF_BCCH_DLSCH_MSG=sched_interface::MAX_SIBS; - uint8_t bcch_dlsch_payload[sched_interface::MAX_SIB_PAYLOAD_LEN]; - - const static int pcch_payload_buffer_len = 1024; - uint8_t pcch_payload_buffer[pcch_payload_buffer_len]; + const static int NOF_BCCH_DLSCH_MSG = sched_interface::MAX_SIBS; + uint8_t bcch_dlsch_payload[sched_interface::MAX_SIB_PAYLOAD_LEN]; + + const static int pcch_payload_buffer_len = 1024; + uint8_t pcch_payload_buffer[pcch_payload_buffer_len]; srslte_softbuffer_tx_t bcch_softbuffer_tx[NOF_BCCH_DLSCH_MSG]; srslte_softbuffer_tx_t pcch_softbuffer_tx; srslte_softbuffer_tx_t rar_softbuffer_tx; - - const static int mcch_payload_len = 3000; //TODO FIND OUT MAX LENGTH - int current_mcch_length; - uint8_t mcch_payload_buffer[mcch_payload_len]; + + const static int mcch_payload_len = 3000; // TODO FIND OUT MAX LENGTH + int current_mcch_length; + uint8_t mcch_payload_buffer[mcch_payload_len]; asn1::rrc::mcch_msg_s mcch; asn1::rrc::sib_type2_s sib2; asn1::rrc::sib_type13_r9_s sib13; diff --git a/srsenb/hdr/stack/mac/mac_metrics.h b/srsenb/hdr/stack/mac/mac_metrics.h index e012ede2d..61511dd4f 100644 --- a/srsenb/hdr/stack/mac/mac_metrics.h +++ b/srsenb/hdr/stack/mac/mac_metrics.h @@ -22,26 +22,24 @@ #ifndef SRSENB_MAC_METRICS_H #define SRSENB_MAC_METRICS_H - namespace srsenb { -// MAC metrics per user - -struct mac_metrics_t -{ - uint16_t rnti; - int tx_pkts; - int tx_errors; - int tx_brate; - int rx_pkts; - int rx_errors; - int rx_brate; - int ul_buffer; - int dl_buffer; - float dl_cqi; - float dl_ri; - float dl_pmi; - float phr; +// MAC metrics per user + +struct mac_metrics_t { + uint16_t rnti; + int tx_pkts; + int tx_errors; + int tx_brate; + int rx_pkts; + int rx_errors; + int rx_brate; + int ul_buffer; + int dl_buffer; + float dl_cqi; + float dl_ri; + float dl_pmi; + float phr; }; } // namespace srsenb diff --git a/srsenb/hdr/stack/mac/ue.h b/srsenb/hdr/stack/mac/ue.h index 28f7befe1..b6d61d3aa 100644 --- a/srsenb/hdr/stack/mac/ue.h +++ b/srsenb/hdr/stack/mac/ue.h @@ -22,21 +22,20 @@ #ifndef SRSENB_UE_H #define SRSENB_UE_H +#include "mac_metrics.h" +#include "srslte/common/block_queue.h" #include "srslte/common/log.h" -#include "srslte/common/pdu.h" #include "srslte/common/mac_pcap.h" +#include "srslte/common/pdu.h" #include "srslte/common/pdu_queue.h" -#include "srslte/common/block_queue.h" #include "srslte/interfaces/enb_interfaces.h" #include "srslte/interfaces/sched_interface.h" #include #include -#include "mac_metrics.h" namespace srsenb { - -class ue : public srslte::read_pdu_interface, - public srslte::pdu_queue::process_callback + +class ue : public srslte::read_pdu_interface, public srslte::pdu_queue::process_callback { public: ue(uint16_t rnti, @@ -49,15 +48,20 @@ public: uint32_t nof_tx_harq_proc = SRSLTE_FDD_NOF_HARQ * SRSLTE_MAX_TB); virtual ~ue(); - void reset(); - - void start_pcap(srslte::mac_pcap* pcap_); + void reset(); + + void start_pcap(srslte::mac_pcap* pcap_); - void set_tti(uint32_t tti); + void set_tti(uint32_t tti); uint32_t set_ta(int ta); - - void config(uint16_t rnti, uint32_t nof_prb, sched_interface *sched, rrc_interface_mac *rrc_, rlc_interface_mac *rlc, srslte::log *log_h); + + void config(uint16_t rnti, + uint32_t nof_prb, + sched_interface* sched, + rrc_interface_mac* rrc_, + rlc_interface_mac* rlc, + srslte::log* log_h); uint8_t* generate_pdu(uint32_t harq_pid, uint32_t tb_idx, sched_interface::dl_sched_pdu_t pdu[sched_interface::MAX_RLC_PDU_LIST], @@ -74,7 +78,7 @@ public: void process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channel_t channel); void push_pdu(uint32_t tti, uint32_t len); void deallocate_pdu(uint32_t tti); - + uint32_t rl_failure(); void rl_failure_reset(); @@ -89,12 +93,12 @@ public: void metrics_dl_cqi(uint32_t dl_cqi); bool is_phy_added = false; - int read_pdu(uint32_t lcid, uint8_t *payload, uint32_t requested_bytes); -private: - - void allocate_sdu(srslte::sch_pdu *pdu, uint32_t lcid, uint32_t sdu_len); - bool process_ce(srslte::sch_subh *subh); - void allocate_ce(srslte::sch_pdu *pdu, uint32_t lcid); + int read_pdu(uint32_t lcid, uint8_t* payload, uint32_t requested_bytes); + +private: + void allocate_sdu(srslte::sch_pdu* pdu, uint32_t lcid, uint32_t sdu_len); + bool process_ce(srslte::sch_subh* subh); + void allocate_ce(srslte::sch_pdu* pdu, uint32_t lcid); std::vector lc_groups[4]; @@ -116,8 +120,8 @@ private: srslte::block_queue pending_ta_commands; - int nof_rx_harq_proc = 0; - int nof_tx_harq_proc = 0; + int nof_rx_harq_proc = 0; + int nof_tx_harq_proc = 0; std::vector softbuffer_tx; std::vector softbuffer_rx; std::vector pending_buffers; @@ -126,9 +130,9 @@ private: srslte::byte_buffer_t tx_payload_buffer[SRSLTE_FDD_NOF_HARQ][SRSLTE_MAX_TB]; // For UL there are multiple buffers per PID and are managed by pdu_queue - srslte::pdu_queue pdus; - srslte::sch_pdu mac_msg_dl, mac_msg_ul; - srslte::mch_pdu mch_mac_msg_dl; + srslte::pdu_queue pdus; + srslte::sch_pdu mac_msg_dl, mac_msg_ul; + srslte::mch_pdu mch_mac_msg_dl; rlc_interface_mac* rlc = nullptr; rrc_interface_mac* rrc = nullptr; @@ -139,10 +143,8 @@ private: // Mutexes pthread_mutex_t mutex; - }; -} +} // namespace srsenb #endif // SRSENB_UE_H - diff --git a/srsenb/hdr/stack/rrc/rrc_metrics.h b/srsenb/hdr/stack/rrc/rrc_metrics.h index 90d625a74..6a1fa209e 100644 --- a/srsenb/hdr/stack/rrc/rrc_metrics.h +++ b/srsenb/hdr/stack/rrc/rrc_metrics.h @@ -26,7 +26,7 @@ namespace srsenb { -typedef enum{ +typedef enum { RRC_STATE_IDLE = 0, RRC_STATE_WAIT_FOR_CON_SETUP_COMPLETE, RRC_STATE_WAIT_FOR_SECURITY_MODE_COMPLETE, @@ -35,16 +35,14 @@ typedef enum{ RRC_STATE_REGISTERED, RRC_STATE_RELEASE_REQUEST, RRC_STATE_N_ITEMS, -}rrc_state_t; +} rrc_state_t; -struct rrc_ue_metrics_t -{ +struct rrc_ue_metrics_t { rrc_state_t state; }; -struct rrc_metrics_t -{ - uint16_t n_ues; +struct rrc_metrics_t { + uint16_t n_ues; rrc_ue_metrics_t ues[ENB_METRICS_MAX_USERS]; }; diff --git a/srsenb/hdr/stack/upper/common_enb.h b/srsenb/hdr/stack/upper/common_enb.h index c2b155c28..44349c424 100644 --- a/srsenb/hdr/stack/upper/common_enb.h +++ b/srsenb/hdr/stack/upper/common_enb.h @@ -30,14 +30,14 @@ namespace srsenb { -#define ENB_METRICS_MAX_USERS 64 +#define ENB_METRICS_MAX_USERS 64 #define SRSENB_RRC_MAX_N_PLMN_IDENTITIES 6 -#define SRSENB_N_SRB 3 -#define SRSENB_N_DRB 8 +#define SRSENB_N_SRB 3 +#define SRSENB_N_DRB 8 #define SRSENB_N_RADIO_BEARERS 11 -typedef enum{ +typedef enum { RB_ID_SRB0 = 0, RB_ID_SRB1, RB_ID_SRB2, @@ -50,24 +50,15 @@ typedef enum{ RB_ID_DRB7, RB_ID_DRB8, RB_ID_N_ITEMS, -}rb_id_t; -static const char rb_id_text[RB_ID_N_ITEMS][20] = { "SRB0", - "SRB1", - "SRB2", - "DRB1", - "DRB2", - "DRB3", - "DRB4", - "DRB5", - "DRB6", - "DRB7", - "DRB8"}; +} rb_id_t; +static const char rb_id_text[RB_ID_N_ITEMS][20] = + {"SRB0", "SRB1", "SRB2", "DRB1", "DRB2", "DRB3", "DRB4", "DRB5", "DRB6", "DRB7", "DRB8"}; // Cat 3 UE - Max number of DL-SCH transport block bits received within a TTI // 3GPP 36.306 Table 4.1.1 -#define SRSENB_MAX_BUFFER_SIZE_BITS 102048 +#define SRSENB_MAX_BUFFER_SIZE_BITS 102048 #define SRSENB_MAX_BUFFER_SIZE_BYTES 12756 -#define SRSENB_BUFFER_HEADER_OFFSET 1024 +#define SRSENB_BUFFER_HEADER_OFFSET 1024 } // namespace srsenb #endif // SRSENB_COMMON_ENB_H diff --git a/srsenb/hdr/stack/upper/s1ap_metrics.h b/srsenb/hdr/stack/upper/s1ap_metrics.h index 0d13bd6ab..001f66316 100644 --- a/srsenb/hdr/stack/upper/s1ap_metrics.h +++ b/srsenb/hdr/stack/upper/s1ap_metrics.h @@ -22,17 +22,15 @@ #ifndef SRSENB_S1AP_METRICS_H #define SRSENB_S1AP_METRICS_H - namespace srsenb { -typedef enum{ +typedef enum { S1AP_ATTACHING = 0, // Attempting to create S1 connection S1AP_READY, // S1 connected S1AP_ERROR // Failure -}S1AP_STATUS_ENUM; +} S1AP_STATUS_ENUM; -struct s1ap_metrics_t -{ +struct s1ap_metrics_t { S1AP_STATUS_ENUM status; }; diff --git a/srsenb/src/main.cc b/srsenb/src/main.cc index 3ad70f3ac..ec4e12786 100644 --- a/srsenb/src/main.cc +++ b/srsenb/src/main.cc @@ -19,23 +19,23 @@ * */ -#include +#include +#include #include #include -#include -#include +#include #include "srslte/common/config_file.h" #include "srslte/common/crash_handler.h" -#include -#include #include #include +#include +#include #include "srsenb/hdr/enb.h" -#include "srsenb/hdr/metrics_stdout.h" #include "srsenb/hdr/metrics_csv.h" +#include "srsenb/hdr/metrics_stdout.h" using namespace std; using namespace srsenb; @@ -46,7 +46,8 @@ namespace bpo = boost::program_options; ***********************************************************************/ string config_file; -void parse_args(all_args_t *args, int argc, char* argv[]) { +void parse_args(all_args_t* args, int argc, char* argv[]) +{ string enb_id; string cell_id; @@ -212,23 +213,21 @@ void parse_args(all_args_t *args, int argc, char* argv[]) { try { bpo::store(bpo::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm); bpo::notify(vm); - } catch(bpo::error &e) { - cerr<< e.what() << endl; + } catch (bpo::error& e) { + cerr << e.what() << endl; exit(1); } // help option was given - print usage and exit if (vm.count("help")) { - cout << "Usage: " << argv[0] << " [OPTIONS] config_file" << endl << endl; - cout << common << endl << general << endl; - exit(0); + cout << "Usage: " << argv[0] << " [OPTIONS] config_file" << endl << endl; + cout << common << endl << general << endl; + exit(0); } // print version number and exit if (vm.count("version")) { - cout << "Version " << - srslte_get_version_major() << "." << - srslte_get_version_minor() << "." << - srslte_get_version_patch() << endl; + cout << "Version " << srslte_get_version_major() << "." << srslte_get_version_minor() << "." + << srslte_get_version_patch() << endl; exit(0); } @@ -242,7 +241,7 @@ void parse_args(all_args_t *args, int argc, char* argv[]) { cout << "Reading configuration file " << config_file << "..." << endl; ifstream conf(config_file.c_str(), ios::in); - if(conf.fail()) { + if (conf.fail()) { cout << "Failed to read configuration file " << config_file << " - exiting" << endl; exit(1); } @@ -316,53 +315,53 @@ void parse_args(all_args_t *args, int argc, char* argv[]) { if (!vm.count("log.rf_level")) { args->rf.log_level = args->log.all_level; } - if(!vm.count("log.phy_level")) { + if (!vm.count("log.phy_level")) { args->phy.log.phy_level = args->log.all_level; } if (!vm.count("log.phy_lib_level")) { args->phy.log.phy_lib_level = args->log.all_level; } - if(!vm.count("log.mac_level")) { + if (!vm.count("log.mac_level")) { args->stack.log.mac_level = args->log.all_level; } - if(!vm.count("log.rlc_level")) { + if (!vm.count("log.rlc_level")) { args->stack.log.rlc_level = args->log.all_level; } - if(!vm.count("log.pdcp_level")) { + if (!vm.count("log.pdcp_level")) { args->stack.log.pdcp_level = args->log.all_level; } - if(!vm.count("log.rrc_level")) { + if (!vm.count("log.rrc_level")) { args->stack.log.rrc_level = args->log.all_level; } - if(!vm.count("log.gtpu_level")) { + if (!vm.count("log.gtpu_level")) { args->stack.log.gtpu_level = args->log.all_level; } - if(!vm.count("log.s1ap_level")) { + if (!vm.count("log.s1ap_level")) { args->stack.log.s1ap_level = args->log.all_level; } } // Apply all_hex_limit to any unset layers if (vm.count("log.all_hex_limit")) { - if(!vm.count("log.phy_hex_limit")) { + if (!vm.count("log.phy_hex_limit")) { args->log.phy_hex_limit = args->log.all_hex_limit; } - if(!vm.count("log.mac_hex_limit")) { + if (!vm.count("log.mac_hex_limit")) { args->stack.log.mac_hex_limit = args->log.all_hex_limit; } - if(!vm.count("log.rlc_hex_limit")) { + if (!vm.count("log.rlc_hex_limit")) { args->stack.log.rlc_hex_limit = args->log.all_hex_limit; } - if(!vm.count("log.pdcp_hex_limit")) { + if (!vm.count("log.pdcp_hex_limit")) { args->stack.log.pdcp_hex_limit = args->log.all_hex_limit; } - if(!vm.count("log.rrc_hex_limit")) { + if (!vm.count("log.rrc_hex_limit")) { args->stack.log.rrc_hex_limit = args->log.all_hex_limit; } - if(!vm.count("log.gtpu_hex_limit")) { + if (!vm.count("log.gtpu_hex_limit")) { args->stack.log.gtpu_hex_limit = args->log.all_hex_limit; } - if(!vm.count("log.s1ap_hex_limit")) { + if (!vm.count("log.s1ap_hex_limit")) { args->stack.log.s1ap_hex_limit = args->log.all_hex_limit; } } @@ -384,7 +383,7 @@ void parse_args(all_args_t *args, int argc, char* argv[]) { } } -static int sigcnt = 0; +static int sigcnt = 0; static bool running = true; static bool do_metrics = false; @@ -398,19 +397,19 @@ void sig_int_handler(int signo) } } -void *input_loop(void *m) +void* input_loop(void* m) { - metrics_stdout *metrics = (metrics_stdout*) m; - char key; - while(running) { + metrics_stdout* metrics = (metrics_stdout*)m; + char key; + while (running) { cin >> key; if (cin.eof() || cin.bad()) { cout << "Closing stdin thread." << endl; break; } else { - if('t' == key) { + if ('t' == key) { do_metrics = !do_metrics; - if(do_metrics) { + if (do_metrics) { cout << "Enter t to stop trace." << endl; } else { cout << "Enter t to restart trace." << endl; @@ -424,15 +423,15 @@ void *input_loop(void *m) return nullptr; } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { signal(SIGINT, sig_int_handler); signal(SIGTERM, sig_int_handler); all_args_t args = {}; srslte::metrics_hub metricshub; - metrics_stdout metrics_screen; + metrics_stdout metrics_screen; - enb *enb = enb::get_instance(); + enb* enb = enb::get_instance(); srslte_debug_handle_crash(argc, argv); @@ -464,12 +463,12 @@ int main(int argc, char *argv[]) enb->start_plot(); } } - int cnt=0; + int cnt = 0; while (running) { if (args.general.print_buffer_state) { cnt++; - if (cnt==1000) { - cnt=0; + if (cnt == 1000) { + cnt = 0; enb->print_pool(); } } diff --git a/srsenb/src/metrics_csv.cc b/srsenb/src/metrics_csv.cc index e234a53ee..6145128c6 100644 --- a/srsenb/src/metrics_csv.cc +++ b/srsenb/src/metrics_csv.cc @@ -21,24 +21,21 @@ #include "srsenb/hdr/metrics_csv.h" -#include -#include -#include -#include #include #include #include +#include +#include +#include +#include #include using namespace std; -namespace srsenb{ +namespace srsenb { -metrics_csv::metrics_csv(std::string filename) - :n_reports(0) - ,metrics_report_period(1.0) - ,enb(NULL) +metrics_csv::metrics_csv(std::string filename) : n_reports(0), metrics_report_period(1.0), enb(NULL) { file.open(filename.c_str(), std::ios_base::out); } @@ -48,7 +45,7 @@ metrics_csv::~metrics_csv() stop(); } -void metrics_csv::set_handle(enb_metrics_interface *enb_) +void metrics_csv::set_handle(enb_metrics_interface* enb_) { enb = enb_; } @@ -62,15 +59,15 @@ void metrics_csv::stop() } } -void metrics_csv::set_metrics(enb_metrics_t &metrics, const uint32_t period_usec) +void metrics_csv::set_metrics(enb_metrics_t& metrics, const uint32_t period_usec) { if (file.is_open() && enb != NULL) { - if(n_reports == 0) { + if (n_reports == 0) { file << "time;nof_ue;dl_brate;ul_brate\n"; } // Time - file << (metrics_report_period*n_reports) << ";"; + file << (metrics_report_period * n_reports) << ";"; // UEs file << (metrics.stack.rrc.n_ues) << ";"; @@ -84,14 +81,14 @@ void metrics_csv::set_metrics(enb_metrics_t &metrics, const uint32_t period_usec // DL rate if (dl_rate_sum > 0) { - file << float_to_string(SRSLTE_MAX(0.1,(float)dl_rate_sum/period_usec*1e6), 2); + file << float_to_string(SRSLTE_MAX(0.1, (float)dl_rate_sum / period_usec * 1e6), 2); } else { file << float_to_string(0, 2); } // UL rate if (ul_rate_sum > 0) { - file << float_to_string(SRSLTE_MAX(0.1,(float)ul_rate_sum/period_usec*1e6), 2, false); + file << float_to_string(SRSLTE_MAX(0.1, (float)ul_rate_sum / period_usec * 1e6), 2, false); } else { file << float_to_string(0, 2, false); } diff --git a/srsenb/src/metrics_stdout.cc b/srsenb/src/metrics_stdout.cc index c4c64a881..d639a84c2 100644 --- a/srsenb/src/metrics_stdout.cc +++ b/srsenb/src/metrics_stdout.cc @@ -21,36 +21,49 @@ #include "srsenb/hdr/metrics_stdout.h" -#include -#include -#include -#include #include #include #include +#include +#include +#include +#include #include #include using namespace std; -namespace srsenb{ - -char const * const prefixes[2][9] = -{ - { "", "m", "u", "n", "p", "f", "a", "z", "y", }, - { "", "k", "M", "G", "T", "P", "E", "Z", "Y", }, +namespace srsenb { + +char const* const prefixes[2][9] = { + { + "", + "m", + "u", + "n", + "p", + "f", + "a", + "z", + "y", + }, + { + "", + "k", + "M", + "G", + "T", + "P", + "E", + "Z", + "Y", + }, }; +metrics_stdout::metrics_stdout() : do_print(false), n_reports(10), enb(NULL) {} -metrics_stdout::metrics_stdout() - :do_print(false) - ,n_reports(10) - ,enb(NULL) -{ -} - -void metrics_stdout::set_handle(enb_metrics_interface *enb_) +void metrics_stdout::set_handle(enb_metrics_interface* enb_) { enb = enb_; } @@ -60,7 +73,7 @@ void metrics_stdout::toggle_print(bool b) do_print = b; } -void metrics_stdout::set_metrics(enb_metrics_t &metrics, const uint32_t period_usec) +void metrics_stdout::set_metrics(enb_metrics_t& metrics, const uint32_t period_usec) { if (!do_print || enb == nullptr) { return; @@ -144,12 +157,11 @@ void metrics_stdout::set_metrics(enb_metrics_t &metrics, const uint32_t period_u std::string metrics_stdout::float_to_string(float f, int digits) { std::ostringstream os; - int precision; + int precision; if (isnan(f) or fabs(f) < 0.0001) { - f = 0.0; - precision = digits-1; - } - else { + f = 0.0; + precision = digits - 1; + } else { precision = digits - (int)(log10f(fabs(f)) - 2 * DBL_EPSILON); } os << std::setw(6) << std::fixed << std::setprecision(precision) << f; @@ -162,17 +174,16 @@ std::string metrics_stdout::float_to_eng_string(float f, int digits) std::string factor; - if ( abs( degree ) < 9 ) - { - if(degree < 0) - factor = prefixes[0][ abs( degree ) ]; + if (abs(degree) < 9) { + if (degree < 0) + factor = prefixes[0][abs(degree)]; else - factor = prefixes[1][ abs( degree ) ]; + factor = prefixes[1][abs(degree)]; } else { return "failed"; } - const double scaled = f * pow( 1000.0, -degree ); + const double scaled = f * pow(1000.0, -degree); if (degree != 0) { return float_to_string(scaled, digits) + factor; } else { @@ -180,4 +191,4 @@ std::string metrics_stdout::float_to_eng_string(float f, int digits) } } -} // namespace srsue +} // namespace srsenb diff --git a/srsenb/src/phy/cc_worker.cc b/srsenb/src/phy/cc_worker.cc index 9761d5a87..62f1648e5 100644 --- a/srsenb/src/phy/cc_worker.cc +++ b/srsenb/src/phy/cc_worker.cc @@ -492,7 +492,7 @@ int cc_worker::decode_pusch(stack_interface_phy_lte::ul_sched_grant_t* grants, u phy->ue_db_set_last_ul_tb(rnti, ul_pid, grant->tb); // Run PUSCH decoder - pusch_res = {}; + pusch_res = {}; ue_db[rnti]->ul_cfg.pusch.softbuffers.rx = grants[i].softbuffer_rx; pusch_res.data = grants[i].data; if (pusch_res.data) { @@ -726,7 +726,7 @@ int cc_worker::encode_pdsch(stack_interface_phy_lte::dl_sched_grant_t* grants, u uint32_t cc_worker::get_metrics(phy_metrics_t metrics[ENB_METRICS_MAX_USERS]) { std::lock_guard lock(mutex); - uint32_t cnt = 0; + uint32_t cnt = 0; for (auto& ue : ue_db) { if (SRSLTE_RNTI_ISUSER(ue.first) && cnt < ENB_METRICS_MAX_USERS) { ue.second->metrics_read(&metrics[cnt]); @@ -761,7 +761,7 @@ void cc_worker::ue::metrics_ul(uint32_t mcs, float rssi, float sinr, float turbo int cc_worker::read_ce_abs(float* ce_abs) { - int sz = srslte_symbol_sz(phy->cell.nof_prb); + int sz = srslte_symbol_sz(phy->cell.nof_prb); bzero(ce_abs, sizeof(float) * sz); int g = (sz - 12 * phy->cell.nof_prb) / 2; srslte_vec_abs_dB_cf(enb_ul.chest_res.ce, -80.0f, &ce_abs[g], SRSLTE_NRE * phy->cell.nof_prb); @@ -770,7 +770,7 @@ int cc_worker::read_ce_abs(float* ce_abs) int cc_worker::read_ce_arg(float* ce_arg) { - int sz = srslte_symbol_sz(phy->cell.nof_prb); + int sz = srslte_symbol_sz(phy->cell.nof_prb); bzero(ce_arg, sizeof(float) * sz); int g = (sz - 12 * phy->cell.nof_prb) / 2; srslte_vec_arg_deg_cf(enb_ul.chest_res.ce, -80.0f, &ce_arg[g], SRSLTE_NRE * phy->cell.nof_prb); diff --git a/srsenb/src/phy/phy.cc b/srsenb/src/phy/phy.cc index fb00edacf..68d1bd439 100644 --- a/srsenb/src/phy/phy.cc +++ b/srsenb/src/phy/phy.cc @@ -19,22 +19,30 @@ * */ -#include +#include #include #include +#include #include -#include -#include #include +#include -#include "srslte/common/threads.h" -#include "srslte/common/log.h" #include "srsenb/hdr/phy/phy.h" +#include "srslte/common/log.h" +#include "srslte/common/threads.h" -#define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->debug(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->error(fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->warning(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->debug(fmt, ##__VA_ARGS__) using namespace std; using namespace asn1::rrc; @@ -136,11 +144,11 @@ int phy::init(const phy_args_t& args, workers_common.init(cfg.cell, radio, stack_); parse_config(cfg); - + // Add workers to workers pool and start threads - for (uint32_t i=0;iPHY interface **********/ @@ -187,9 +197,9 @@ int phy::add_rnti(uint16_t rnti, bool is_temporal) workers_common.ue_db_add_rnti(rnti); } - for (uint32_t i=0;iPHY interface **********/ void phy::set_config_dedicated(uint16_t rnti, phys_cfg_ded_s* dedicated) { - for (uint32_t i=0;i -#define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->debug(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->error(fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->warning(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->debug(fmt, ##__VA_ARGS__) using namespace std; using namespace asn1::rrc; @@ -82,8 +90,7 @@ bool phy_common::init(const srslte_cell_t& cell_, // Instantiate UL channel emulator if (params.ul_channel_args.enable) { - dl_channel = - srslte::channel_ptr(new srslte::channel(params.dl_channel_args, 1)); + dl_channel = srslte::channel_ptr(new srslte::channel(params.dl_channel_args, 1)); dl_channel->set_srate((uint32_t)srslte_sampling_freq_hz(cell.nof_prb)); } @@ -92,20 +99,19 @@ bool phy_common::init(const srslte_cell_t& cell_, // Instantiate UL channel emulator if (params.ul_channel_args.enable) { - dl_channel = - srslte::channel_ptr(new srslte::channel(params.dl_channel_args, 1)); + dl_channel = srslte::channel_ptr(new srslte::channel(params.dl_channel_args, 1)); dl_channel->set_srate((uint32_t)srslte_sampling_freq_hz(cell.nof_prb)); } is_first_tx = true; reset(); - return true; + return true; } void phy_common::stop() { - for (uint32_t i=0;irun(buffer, buffer, nof_samples, tx_time); @@ -142,7 +148,7 @@ void phy_common::worker_end(uint32_t tti, radio->tx(0, buffer, nof_samples, tx_time); // Allow next TTI to transmit - sem_post(&tx_sem[(tti+1)%nof_workers]); + sem_post(&tx_sem[(tti + 1) % nof_workers]); // Trigger MAC clock stack->tti_clock(); @@ -151,7 +157,7 @@ void phy_common::worker_end(uint32_t tti, void phy_common::ue_db_clear(uint32_t tti) { for (auto iter = common_ue_db.begin(); iter != common_ue_db.end(); ++iter) { - pending_ack_t *p = &((common_ue*)&iter->second)->pending_ack; + pending_ack_t* p = &((common_ue*)&iter->second)->pending_ack; for (uint32_t tb_idx = 0; tb_idx < SRSLTE_MAX_TB; tb_idx++) { p->is_pending[TTIMOD(tti)][tb_idx] = false; } @@ -269,7 +275,7 @@ void phy_common::configure_mbsfn(phy_interface_stack_lte::phy_cfg_mbsfn_t* cfg) build_mch_table(); build_mcch_table(); sib13_configured = true; - mcch_configured = true; + mcch_configured = true; } void phy_common::build_mch_table() @@ -291,8 +297,8 @@ void phy_common::build_mch_table() // Debug std::stringstream ss; ss << "|"; - for(uint32_t j=0; j<40; j++) { - ss << (int) mch_table[j] << "|"; + for (uint32_t j = 0; j < 40; j++) { + ss << (int)mch_table[j] << "|"; } stack->set_sched_dl_tti_mask(mch_table, nof_sfs); @@ -306,20 +312,20 @@ void phy_common::build_mcch_table() std::stringstream ss; ss << "|"; - for(uint32_t j=0; j<10; j++) { - ss << (int) mcch_table[j] << "|"; + for (uint32_t j = 0; j < 10; j++) { + ss << (int)mcch_table[j] << "|"; } } bool phy_common::is_mcch_subframe(srslte_mbsfn_cfg_t* cfg, uint32_t phy_tti) { - uint32_t sfn; // System Frame Number - uint8_t sf; // Subframe + uint32_t sfn; // System Frame Number + uint8_t sf; // Subframe uint8_t offset; uint8_t period; - sfn = phy_tti/10; - sf = phy_tti%10; + sfn = phy_tti / 10; + sf = phy_tti % 10; if (sib13_configured) { mbsfn_area_info_r9_s* area_info = &mbsfn.mbsfn_area_info; @@ -327,8 +333,8 @@ bool phy_common::is_mcch_subframe(srslte_mbsfn_cfg_t* cfg, uint32_t phy_tti) offset = area_info->mcch_cfg_r9.mcch_offset_r9; period = area_info->mcch_cfg_r9.mcch_repeat_period_r9.to_number(); - if((sfn%period == offset) && mcch_table[sf] > 0) { - cfg->mbsfn_area_id = area_info->mbsfn_area_id_r9; + if ((sfn % period == offset) && mcch_table[sf] > 0) { + cfg->mbsfn_area_id = area_info->mbsfn_area_id_r9; cfg->non_mbsfn_region_length = area_info->non_mbsfn_region_len.to_number(); cfg->mbsfn_mcs = area_info->mcch_cfg_r9.sig_mcs_r9.to_number(); cfg->enable = true; @@ -342,20 +348,20 @@ bool phy_common::is_mcch_subframe(srslte_mbsfn_cfg_t* cfg, uint32_t phy_tti) bool phy_common::is_mch_subframe(srslte_mbsfn_cfg_t* cfg, uint32_t phy_tti) { - uint32_t sfn; // System Frame Number - uint8_t sf; // Subframe + uint32_t sfn; // System Frame Number + uint8_t sf; // Subframe uint8_t offset; uint8_t period; sfn = phy_tti / 10; - sf = phy_tti%10; + sf = phy_tti % 10; // Set some defaults - cfg->mbsfn_area_id = 0; - cfg->non_mbsfn_region_length = 1; - cfg->mbsfn_mcs = 2; - cfg->enable = false; - cfg->is_mcch = false; + cfg->mbsfn_area_id = 0; + cfg->non_mbsfn_region_length = 1; + cfg->mbsfn_mcs = 2; + cfg->enable = false; + cfg->is_mcch = false; // Check for MCCH if (is_mcch_subframe(cfg, phy_tti)) { return true; @@ -372,13 +378,13 @@ bool phy_common::is_mch_subframe(srslte_mbsfn_cfg_t* cfg, uint32_t phy_tti) period = subfr_cnfg->radioframe_alloc_period.to_number(); if (subfr_cnfg->sf_alloc.type() == mbsfn_sf_cfg_s::sf_alloc_c_::types::one_frame) { - if ((sfn%period == offset) && (mch_table[sf] > 0)) { + if ((sfn % period == offset) && (mch_table[sf] > 0)) { if (sib13_configured) { - cfg->mbsfn_area_id = area_info->mbsfn_area_id_r9; + cfg->mbsfn_area_id = area_info->mbsfn_area_id_r9; cfg->non_mbsfn_region_length = area_info->non_mbsfn_region_len.to_number(); if (mcch_configured) { // Iterate through PMCH configs to see which one applies in the current frame - mbsfn_area_cfg_r9_s* area_r9 = &mbsfn.mcch.msg.c1().mbsfn_area_cfg_r9(); + mbsfn_area_cfg_r9_s* area_r9 = &mbsfn.mcch.msg.c1().mbsfn_area_cfg_r9(); uint32_t frame_alloc_idx = sfn % area_r9->common_sf_alloc_period_r9.to_number(); uint32_t mbsfn_per_frame = area_r9->pmch_info_list_r9[0].pmch_cfg_r9.sf_alloc_end_r9 / @@ -394,20 +400,18 @@ bool phy_common::is_mch_subframe(srslte_mbsfn_cfg_t* cfg, uint32_t phy_tti) cfg->enable = true; } } - } } return true; } } else if (subfr_cnfg->sf_alloc.type() == mbsfn_sf_cfg_s::sf_alloc_c_::types::four_frames) { - uint8_t idx = sfn%period; - if ((idx >= offset) && (idx < offset+4)) { - if (mch_table[(idx*10)+sf] > 0){ + uint8_t idx = sfn % period; + if ((idx >= offset) && (idx < offset + 4)) { + if (mch_table[(idx * 10) + sf] > 0) { if (sib13_configured) { - cfg->mbsfn_area_id = area_info->mbsfn_area_id_r9; + cfg->mbsfn_area_id = area_info->mbsfn_area_id_r9; cfg->non_mbsfn_region_length = area_info->non_mbsfn_region_len.to_number(); // TODO: check for MCCH configuration, set MCS and decode - } return true; } @@ -421,4 +425,4 @@ bool phy_common::is_mbsfn_sf(srslte_mbsfn_cfg_t* cfg, uint32_t phy_tti) { return is_mch_subframe(cfg, phy_tti); } -} +} // namespace srsenb diff --git a/srsenb/src/phy/prach_worker.cc b/srsenb/src/phy/prach_worker.cc index d43cabce2..785fc639c 100644 --- a/srsenb/src/phy/prach_worker.cc +++ b/srsenb/src/phy/prach_worker.cc @@ -19,8 +19,8 @@ * */ -#include "srslte/srslte.h" #include "srsenb/hdr/phy/prach_worker.h" +#include "srslte/srslte.h" namespace srsenb { @@ -30,8 +30,8 @@ int prach_worker::init(const srslte_cell_t& cell_, srslte::log* log_h_, int priority) { - log_h = log_h_; - stack = stack_; + log_h = log_h_; + stack = stack_; prach_cfg = prach_cfg_; cell = cell_; @@ -43,12 +43,12 @@ int prach_worker::init(const srslte_cell_t& cell_, if (srslte_prach_set_cfg(&prach, &prach_cfg, cell.nof_prb)) { ERROR("Error initiating PRACH\n"); - return -1; + return -1; } - srslte_prach_set_detect_factor(&prach, 60); + srslte_prach_set_detect_factor(&prach, 60); - nof_sf = (uint32_t) ceilf(prach.T_tot*1000); + nof_sf = (uint32_t)ceilf(prach.T_tot * 1000); start(priority); initiated = true; @@ -61,7 +61,7 @@ void prach_worker::stop() { srslte_prach_free(&prach); - running = false; + running = false; sf_buffer* s = nullptr; pending_buffers.push(s); wait_thread_finish(); @@ -69,7 +69,7 @@ void prach_worker::stop() void prach_worker::set_max_prach_offset_us(float delay_us) { - max_prach_offset_us = delay_us; + max_prach_offset_us = delay_us; } int prach_worker::new_tti(uint32_t tti_rx, cf_t* buffer_rx) @@ -87,8 +87,10 @@ int prach_worker::new_tti(uint32_t tti_rx, cf_t* buffer_rx) log_h->error("PRACH: Expected available current_buffer\n"); return -1; } - if (current_buffer->nof_samples+SRSLTE_SF_LEN_PRB(cell.nof_prb) < sf_buffer_sz) { - memcpy(¤t_buffer->samples[sf_cnt*SRSLTE_SF_LEN_PRB(cell.nof_prb)], buffer_rx, sizeof(cf_t)*SRSLTE_SF_LEN_PRB(cell.nof_prb)); + if (current_buffer->nof_samples + SRSLTE_SF_LEN_PRB(cell.nof_prb) < sf_buffer_sz) { + memcpy(¤t_buffer->samples[sf_cnt * SRSLTE_SF_LEN_PRB(cell.nof_prb)], + buffer_rx, + sizeof(cf_t) * SRSLTE_SF_LEN_PRB(cell.nof_prb)); current_buffer->nof_samples += SRSLTE_SF_LEN_PRB(cell.nof_prb); if (sf_cnt == 0) { current_buffer->tti = tti_rx; @@ -103,30 +105,27 @@ int prach_worker::new_tti(uint32_t tti_rx, cf_t* buffer_rx) pending_buffers.push(current_buffer); } } - return 0; + return 0; } - -int prach_worker::run_tti(sf_buffer *b) +int prach_worker::run_tti(sf_buffer* b) { - if (srslte_prach_tti_opportunity(&prach, b->tti, -1)) - { + if (srslte_prach_tti_opportunity(&prach, b->tti, -1)) { // Detect possible PRACHs if (srslte_prach_detect_offset(&prach, prach_cfg.freq_offset, &b->samples[prach.N_cp], - nof_sf*SRSLTE_SF_LEN_PRB(cell.nof_prb)-prach.N_cp, - prach_indices, + nof_sf * SRSLTE_SF_LEN_PRB(cell.nof_prb) - prach.N_cp, + prach_indices, prach_offsets, prach_p2avg, - &prach_nof_det)) - { + &prach_nof_det)) { log_h->error("Error detecting PRACH\n"); - return SRSLTE_ERROR; + return SRSLTE_ERROR; } - + if (prach_nof_det) { - for (uint32_t i=0;iinfo("PRACH: cc=%d, %d/%d, preamble=%d, offset=%.1f us, peak2avg=%.1f, max_offset=%.1f us\n", cc_idx, i, @@ -136,19 +135,19 @@ int prach_worker::run_tti(sf_buffer *b) prach_p2avg[i], max_prach_offset_us); - if (prach_offsets[i]*1e6 < max_prach_offset_us) { + if (prach_offsets[i] * 1e6 < max_prach_offset_us) { stack->rach_detected(b->tti, cc_idx, prach_indices[i], (uint32_t)(prach_offsets[i] * 1e6)); } } } } - return 0; + return 0; } void prach_worker::run_thread() { - running = true; - while(running) { + running = true; + while (running) { sf_buffer* b = pending_buffers.wait_pop(); if (running && b) { int ret = run_tti(b); @@ -161,5 +160,4 @@ void prach_worker::run_thread() } } - -} +} // namespace srsenb diff --git a/srsenb/src/phy/sf_worker.cc b/srsenb/src/phy/sf_worker.cc index a7e21a89b..f57fe99f5 100644 --- a/srsenb/src/phy/sf_worker.cc +++ b/srsenb/src/phy/sf_worker.cc @@ -258,7 +258,6 @@ void sf_worker::work_imp() sem_post(&plot_sem); } #endif - } /************ METRICS interface ********************/ @@ -400,7 +399,7 @@ void init_plots(srsenb::sf_worker* worker) pthread_attr_t attr; struct sched_param param = {}; - param.sched_priority = 0; + param.sched_priority = 0; pthread_attr_init(&attr); pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); pthread_attr_setschedpolicy(&attr, SCHED_OTHER); diff --git a/srsenb/src/phy/txrx.cc b/srsenb/src/phy/txrx.cc index b8982e928..7e9aae481 100644 --- a/srsenb/src/phy/txrx.cc +++ b/srsenb/src/phy/txrx.cc @@ -28,13 +28,20 @@ #include "srsenb/hdr/phy/sf_worker.h" #include "srsenb/hdr/phy/txrx.h" -#define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->debug(fmt, ##__VA_ARGS__) - -using namespace std; - +#define Error(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->error(fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->warning(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->debug(fmt, ##__VA_ARGS__) + +using namespace std; namespace srsenb { @@ -50,14 +57,14 @@ bool txrx::init(srslte::radio_interface_phy* radio_h_, srslte::log* log_h_, uint32_t prio_) { - radio_h = radio_h_; - log_h = log_h_; - workers_pool = workers_pool_; - worker_com = worker_com_; - prach = prach_; - tx_worker_cnt = 0; - running = true; - + radio_h = radio_h_; + log_h = log_h_; + workers_pool = workers_pool_; + worker_com = worker_com_; + prach = prach_; + tx_worker_cnt = 0; + running = true; + nof_workers = workers_pool->get_nof_workers(); worker_com->set_nof_workers(nof_workers); @@ -66,7 +73,7 @@ bool txrx::init(srslte::radio_interface_phy* radio_h_, } start(prio_); - return true; + return true; } void txrx::stop() @@ -84,7 +91,7 @@ void txrx::run_thread() uint32_t sf_len = SRSLTE_SF_LEN_PRB(worker_com->cell.nof_prb); float samp_rate = srslte_sampling_freq_hz(worker_com->cell.nof_prb); - log_h->console("Setting Sampling frequency %.2f MHz\n", (float) samp_rate/1000000); + log_h->console("Setting Sampling frequency %.2f MHz\n", (float)samp_rate / 1000000); // Configure radio radio_h->set_rx_srate(0, samp_rate); @@ -128,8 +135,8 @@ void txrx::run_thread() worker->get_id()); worker->set_time(tti, tx_worker_cnt, tx_time); - tx_worker_cnt = (tx_worker_cnt+1)%nof_workers; - + tx_worker_cnt = (tx_worker_cnt + 1) % nof_workers; + // Trigger phy worker execution workers_pool->start_worker(worker); @@ -139,11 +146,9 @@ void txrx::run_thread() } } else { // wait_worker() only returns NULL if it's being closed. Quit now to avoid unnecessary loops here - running = false; + running = false; } } } - - -} +} // namespace srsenb diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index ec58e0acc..e1cff6105 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -19,16 +19,16 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#include +#include #include #include -#include #include -#include #include "srsenb/hdr/stack/mac/mac.h" #include "srslte/common/log.h" @@ -78,18 +78,18 @@ bool mac::init(const mac_args_t& args_, scheduler.init(rrc, log_h); // Set default scheduler (RR) scheduler.set_metric(&sched_metric_dl_rr, &sched_metric_ul_rr); - - // Set default scheduler configuration + + // Set default scheduler configuration scheduler.set_sched_cfg(&args.sched); - + // Init softbuffer for SI messages - for (int i=0;iset_lcg(lc_id, (uint32_t) cfg->group); + ue_db[rnti]->set_lcg(lc_id, (uint32_t)cfg->group); ret = scheduler.bearer_ue_cfg(rnti, lc_id, cfg); } else { Error("User rnti=0x%x not found\n", rnti); @@ -265,9 +265,9 @@ int mac::cell_cfg(sched_interface::cell_cfg_t* cell_cfg) void mac::get_metrics(mac_metrics_t metrics[ENB_METRICS_MAX_USERS]) { pthread_rwlock_rdlock(&rwlock); - int cnt=0; + int cnt = 0; for (auto& u : ue_db) { - if(u.first != SRSLTE_MRNTI) { + if (u.first != SRSLTE_MRNTI) { u.second->metrics_read(&metrics[cnt]); cnt++; } @@ -275,7 +275,6 @@ void mac::get_metrics(mac_metrics_t metrics[ENB_METRICS_MAX_USERS]) pthread_rwlock_unlock(&rwlock); } - /******************************************************** * * PHY interface @@ -287,7 +286,7 @@ void mac::rl_failure(uint16_t rnti) pthread_rwlock_rdlock(&rwlock); if (ue_db.count(rnti)) { uint32_t nof_fails = ue_db[rnti]->rl_failure(); - if (nof_fails >= (uint32_t) args.link_failure_nof_err && args.link_failure_nof_err > 0) { + if (nof_fails >= (uint32_t)args.link_failure_nof_err && args.link_failure_nof_err > 0) { Info("Detected Uplink failure for rnti=0x%x\n", rnti); rrc_h->rl_failure(rnti); ue_db[rnti]->rl_failure_reset(); @@ -469,8 +468,7 @@ int mac::rach_detected(uint32_t tti, uint32_t enb_cc_idx, uint32_t preamble_idx, // Create new UE if (!ue_db.count(rnti)) { - ue_db[rnti] = new ue(rnti, cell.nof_prb, &scheduler, rrc_h, rlc_h, log_h, - SRSLTE_FDD_NOF_HARQ); + ue_db[rnti] = new ue(rnti, cell.nof_prb, &scheduler, rrc_h, rlc_h, log_h, SRSLTE_FDD_NOF_HARQ); } // Set PCAP if available @@ -482,11 +480,11 @@ int mac::rach_detected(uint32_t tti, uint32_t enb_cc_idx, uint32_t preamble_idx, // Generate RAR data sched_interface::dl_sched_rar_info_t rar_info = {}; - rar_info.preamble_idx = preamble_idx; - rar_info.ta_cmd = time_adv; - rar_info.temp_crnti = rnti; - rar_info.msg3_size = 7; - rar_info.prach_tti = tti; + rar_info.preamble_idx = preamble_idx; + rar_info.ta_cmd = time_adv; + rar_info.temp_crnti = rnti; + rar_info.msg3_size = 7; + rar_info.prach_tti = tti; // Add new user to the scheduler so that it can RX/TX SRB0 sched_interface::ue_cfg_t uecfg; @@ -518,7 +516,7 @@ int mac::rach_detected(uint32_t tti, uint32_t enb_cc_idx, uint32_t preamble_idx, return 0; } -int mac::get_dl_sched(uint32_t tti, dl_sched_t *dl_sched_res) +int mac::get_dl_sched(uint32_t tti, dl_sched_t* dl_sched_res) { if (!started) { return 0; @@ -542,7 +540,7 @@ int mac::get_dl_sched(uint32_t tti, dl_sched_t *dl_sched_res) pthread_rwlock_rdlock(&rwlock); // Copy data grants - for (uint32_t i=0;ipdsch[n].dci = sched_result.rar[i].dci; @@ -642,13 +640,12 @@ int mac::get_dl_sched(uint32_t tti, dl_sched_t *dl_sched_res) void mac::build_mch_sched(uint32_t tbs) { int sfs_per_sched_period = mcch.msg.c1().mbsfn_area_cfg_r9().pmch_info_list_r9[0].pmch_cfg_r9.sf_alloc_end_r9; - int bytes_per_sf = tbs/8 - 6;// leave 6 bytes for header + int bytes_per_sf = tbs / 8 - 6; // leave 6 bytes for header - int total_space_avail_bytes = sfs_per_sched_period*bytes_per_sf; + int total_space_avail_bytes = sfs_per_sched_period * bytes_per_sf; int total_bytes_to_tx = 0; - // calculate total bytes to be scheduled for (uint32_t i = 0; i < mch.num_mtch_sched; i++) { total_bytes_to_tx += mch.mtch_sched[i].lcid_buffer_size; @@ -658,17 +655,17 @@ void mac::build_mch_sched(uint32_t tbs) int last_mtch_stop = 0; if (total_bytes_to_tx > 0 && total_bytes_to_tx >= total_space_avail_bytes) { - for(uint32_t i = 0; i < mch.num_mtch_sched;i++){ - double ratio = mch.mtch_sched[i].lcid_buffer_size/total_bytes_to_tx; - float assigned_sfs = floor(sfs_per_sched_period*ratio); - mch.mtch_sched[i].stop = last_mtch_stop + (uint32_t)assigned_sfs; - last_mtch_stop = mch.mtch_sched[i].stop; + for (uint32_t i = 0; i < mch.num_mtch_sched; i++) { + double ratio = mch.mtch_sched[i].lcid_buffer_size / total_bytes_to_tx; + float assigned_sfs = floor(sfs_per_sched_period * ratio); + mch.mtch_sched[i].stop = last_mtch_stop + (uint32_t)assigned_sfs; + last_mtch_stop = mch.mtch_sched[i].stop; } } else { - for(uint32_t i = 0; i < mch.num_mtch_sched;i++){ - float assigned_sfs = ceil(((float)mch.mtch_sched[i].lcid_buffer_size)/((float)bytes_per_sf)); + for (uint32_t i = 0; i < mch.num_mtch_sched; i++) { + float assigned_sfs = ceil(((float)mch.mtch_sched[i].lcid_buffer_size) / ((float)bytes_per_sf)); mch.mtch_sched[i].stop = last_mtch_stop + (uint32_t)assigned_sfs; - last_mtch_stop = mch.mtch_sched[i].stop; + last_mtch_stop = mch.mtch_sched[i].stop; } } } @@ -679,15 +676,16 @@ int mac::get_mch_sched(uint32_t tti, bool is_mcch, dl_sched_t* dl_sched_res) srslte_ra_tb_t mcs = {}; srslte_ra_tb_t mcs_data = {}; mcs.mcs_idx = this->sib13.mbsfn_area_info_list_r9[0].mcch_cfg_r9.sig_mcs_r9.to_number(); - mcs_data.mcs_idx = this->mcch.msg.c1().mbsfn_area_cfg_r9().pmch_info_list_r9[0].pmch_cfg_r9.data_mcs_r9; + mcs_data.mcs_idx = this->mcch.msg.c1().mbsfn_area_cfg_r9().pmch_info_list_r9[0].pmch_cfg_r9.data_mcs_r9; srslte_dl_fill_ra_mcs(&mcs, 0, this->cell_config.cell.nof_prb, false); srslte_dl_fill_ra_mcs(&mcs_data, 0, this->cell_config.cell.nof_prb, false); if (is_mcch) { build_mch_sched(mcs_data.tbs); - mch.mcch_payload = mcch_payload_buffer; + mch.mcch_payload = mcch_payload_buffer; mch.current_sf_allocation_num = 1; Info("MCH Sched Info: LCID: %d, Stop: %d, tti is %d \n", - mch.mtch_sched[0].lcid, mch.mtch_sched[mch.num_mtch_sched - 1].stop, + mch.mtch_sched[0].lcid, + mch.mtch_sched[mch.num_mtch_sched - 1].stop, tti); phy_h->set_mch_period_stop(mch.mtch_sched[mch.num_mtch_sched - 1].stop); for (uint32_t i = 0; i < mch.num_mtch_sched; i++) { @@ -705,21 +703,23 @@ int mac::get_mch_sched(uint32_t tti, bool is_mcch, dl_sched_t* dl_sched_res) } else { uint32_t current_lcid = 1; - uint32_t mtch_index = 0; - uint32_t mtch_stop = mch.mtch_sched[mch.num_mtch_sched -1].stop; + uint32_t mtch_index = 0; + uint32_t mtch_stop = mch.mtch_sched[mch.num_mtch_sched - 1].stop; - for(uint32_t i = 0;i < mch.num_mtch_sched;i++) { - if(mch.current_sf_allocation_num <= mch.mtch_sched[i].stop){ + for (uint32_t i = 0; i < mch.num_mtch_sched; i++) { + if (mch.current_sf_allocation_num <= mch.mtch_sched[i].stop) { current_lcid = mch.mtch_sched[i].lcid; - mtch_index = i; + mtch_index = i; break; } } - if(mch.current_sf_allocation_num <= mtch_stop) { - int requested_bytes = (mcs_data.tbs/8 > (int)mch.mtch_sched[mtch_index].lcid_buffer_size)?(mch.mtch_sched[mtch_index].lcid_buffer_size):((mcs_data.tbs/8) - 2); - int bytes_received = ue_db[SRSLTE_MRNTI]->read_pdu(current_lcid, mtch_payload_buffer, requested_bytes); - mch.pdu[0].lcid = current_lcid; - mch.pdu[0].nbytes = bytes_received; + if (mch.current_sf_allocation_num <= mtch_stop) { + int requested_bytes = (mcs_data.tbs / 8 > (int)mch.mtch_sched[mtch_index].lcid_buffer_size) + ? (mch.mtch_sched[mtch_index].lcid_buffer_size) + : ((mcs_data.tbs / 8) - 2); + int bytes_received = ue_db[SRSLTE_MRNTI]->read_pdu(current_lcid, mtch_payload_buffer, requested_bytes); + mch.pdu[0].lcid = current_lcid; + mch.pdu[0].nbytes = bytes_received; mch.mtch_sched[0].mtch_payload = mtch_payload_buffer; dl_sched_res->pdsch[0].dci.rnti = SRSLTE_MRNTI; if (bytes_received) { @@ -733,14 +733,18 @@ int mac::get_mch_sched(uint32_t tti, bool is_mcch, dl_sched_t* dl_sched_res) mch.current_sf_allocation_num++; } - return SRSLTE_SUCCESS; + return SRSLTE_SUCCESS; } -uint8_t* mac::assemble_rar(sched_interface::dl_sched_rar_grant_t* grants, uint32_t nof_grants, int rar_idx, uint32_t pdu_len, uint32_t tti) +uint8_t* mac::assemble_rar(sched_interface::dl_sched_rar_grant_t* grants, + uint32_t nof_grants, + int rar_idx, + uint32_t pdu_len, + uint32_t tti) { uint8_t grant_buffer[64] = {}; if (pdu_len < rar_payload_len) { - srslte::rar_pdu *pdu = &rar_pdu_msg[rar_idx]; + srslte::rar_pdu* pdu = &rar_pdu_msg[rar_idx]; rar_payload[rar_idx].clear(); pdu->init_tx(&rar_payload[rar_idx], pdu_len); for (uint32_t i = 0; i < nof_grants; i++) { @@ -766,7 +770,7 @@ uint8_t* mac::assemble_si(uint32_t index) return bcch_dlsch_payload; } -int mac::get_ul_sched(uint32_t tti, ul_sched_t *ul_sched_res) +int mac::get_ul_sched(uint32_t tti, ul_sched_t* ul_sched_res) { log_h->step(tti); @@ -790,8 +794,8 @@ int mac::get_ul_sched(uint32_t tti, ul_sched_t *ul_sched_res) // Copy DCI grants ul_sched_res->nof_grants = 0; - int n = 0; - for (uint32_t i=0;i 0) { // Get UE @@ -823,7 +827,7 @@ int mac::get_ul_sched(uint32_t tti, ul_sched_t *ul_sched_res) pthread_rwlock_unlock(&rwlock); // Copy PHICH actions - for (uint32_t i=0;iphich[i].ack = sched_result.phich[i].phich == sched_interface::ul_sched_phich_t::ACK; ul_sched_res->phich[i].rnti = sched_result.phich[i].rnti; } @@ -844,7 +848,7 @@ bool mac::process_pdus() void mac::write_mcch(sib_type2_s* sib2_, sib_type13_r9_s* sib13_, mcch_msg_s* mcch_) { - mcch = *mcch_; + mcch = *mcch_; mch.num_mtch_sched = this->mcch.msg.c1().mbsfn_area_cfg_r9().pmch_info_list_r9[0].mbms_session_info_list_r9.size(); for (uint32_t i = 0; i < mch.num_mtch_sched; ++i) { mch.mtch_sched[i].lcid = @@ -857,13 +861,10 @@ void mac::write_mcch(sib_type2_s* sib2_, sib_type13_r9_s* sib13_, mcch_msg_s* mc asn1::bit_ref bref(&mcch_payload_buffer[rlc_header_len], sizeof(mcch_payload_buffer) - rlc_header_len); mcch.pack(bref); current_mcch_length = bref.distance_bytes(&mcch_payload_buffer[1]); - current_mcch_length = current_mcch_length + rlc_header_len; + current_mcch_length = current_mcch_length + rlc_header_len; ue_db[SRSLTE_MRNTI] = new ue(SRSLTE_MRNTI, cell.nof_prb, &scheduler, rrc_h, rlc_h, log_h); rrc_h->add_user(SRSLTE_MRNTI); } -} - - - +} // namespace srsenb diff --git a/srsenb/src/stack/mac/ue.cc b/srsenb/src/stack/mac/ue.cc index c0dbb5496..3fd7c1b2e 100644 --- a/srsenb/src/stack/mac/ue.cc +++ b/srsenb/src/stack/mac/ue.cc @@ -26,11 +26,10 @@ #include "srsenb/hdr/stack/mac/ue.h" #include "srslte/interfaces/enb_interfaces.h" -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) - +#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) namespace srsenb { @@ -48,7 +47,8 @@ ue::ue(uint16_t rnti_, rlc(rlc_), log_h(log_), mac_msg_dl(20, log_), - mch_mac_msg_dl(10, log_), mac_msg_ul(20, log_), + mch_mac_msg_dl(10, log_), + mac_msg_ul(20, log_), pdus(128), nof_rx_harq_proc(nof_rx_harq_proc_), nof_tx_harq_proc(nof_tx_harq_proc_) @@ -103,7 +103,7 @@ void ue::reset() void ue::start_pcap(srslte::mac_pcap* pcap_) { - pcap = pcap_; + pcap = pcap_; } uint32_t ue::rl_failure() @@ -111,7 +111,7 @@ uint32_t ue::rl_failure() nof_failures++; return nof_failures; } - + void ue::rl_failure_reset() { nof_failures = 0; @@ -120,7 +120,7 @@ void ue::rl_failure_reset() void ue::set_lcg(uint32_t lcid, uint32_t lcg) { // find and remove if already exists - for (int i=0;i<4;i++) { + for (int i = 0; i < 4; i++) { lc_groups[lcg].erase(std::remove(lc_groups[lcg].begin(), lc_groups[lcg].end(), lcid), lc_groups[lcg].end()); } lc_groups[lcg].push_back(lcid); @@ -141,7 +141,7 @@ uint8_t* ue::request_buffer(uint32_t tti, uint32_t len) uint8_t* ret = NULL; if (len > 0) { if (!pending_buffers[tti % nof_rx_harq_proc]) { - ret = pdus.request(len); + ret = pdus.request(len); pending_buffers[tti % nof_rx_harq_proc] = ret; } else { log_h->console("Error requesting buffer for pid %d, not pushed yet\n", tti % nof_rx_harq_proc); @@ -155,21 +155,23 @@ uint8_t* ue::request_buffer(uint32_t tti, uint32_t len) bool ue::process_pdus() { - return pdus.process_pdus(); + return pdus.process_pdus(); } -void ue::set_tti(uint32_t tti) { - last_tti = tti; +void ue::set_tti(uint32_t tti) +{ + last_tti = tti; } -uint32_t ue::set_ta(int ta_) { - int ta = ta_; - uint32_t nof_cmd = 0; - int ta_value = 0; +uint32_t ue::set_ta(int ta_) +{ + int ta = ta_; + uint32_t nof_cmd = 0; + int ta_value = 0; do { - ta_value = SRSLTE_MAX(-31, SRSLTE_MIN(32, ta)); - ta -= ta_value; - uint32_t ta_cmd = (uint32_t) (ta_value + 31); + ta_value = SRSLTE_MAX(-31, SRSLTE_MIN(32, ta)); + ta -= ta_value; + uint32_t ta_cmd = (uint32_t)(ta_value + 31); pending_ta_commands.try_push(ta_cmd); nof_cmd++; Info("Added TA CMD: rnti=0x%x, ta=%d, ta_value=%d, ta_cmd=%d\n", rnti, ta_, ta_value, ta_cmd); @@ -181,7 +183,7 @@ uint32_t ue::set_ta(int ta_) { void ue::process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channel_t channel) { - // Unpack ULSCH MAC PDU + // Unpack ULSCH MAC PDU mac_msg_ul.init_rx(nof_bytes, true); mac_msg_ul.parse_packet(pdu); @@ -192,23 +194,25 @@ void ue::process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channe pdus.deallocate(pdu); uint32_t lcid_most_data = 0; - int most_data = -99; - - while(mac_msg_ul.next()) { + int most_data = -99; + + while (mac_msg_ul.next()) { assert(mac_msg_ul.get()); if (mac_msg_ul.get()->is_sdu()) { - // Route logical channel - log_h->debug_hex(mac_msg_ul.get()->get_sdu_ptr(), mac_msg_ul.get()->get_payload_size(), + // Route logical channel + log_h->debug_hex(mac_msg_ul.get()->get_sdu_ptr(), + mac_msg_ul.get()->get_payload_size(), "PDU: rnti=0x%x, lcid=%d, %d bytes\n", - rnti, mac_msg_ul.get()->get_sdu_lcid(), mac_msg_ul.get()->get_payload_size()); - + rnti, + mac_msg_ul.get()->get_sdu_lcid(), + mac_msg_ul.get()->get_payload_size()); - /* In some cases, an uplink transmission with only CQI has all zeros and gets routed to RRC - * Compute the checksum if lcid=0 and avoid routing in that case + /* In some cases, an uplink transmission with only CQI has all zeros and gets routed to RRC + * Compute the checksum if lcid=0 and avoid routing in that case */ bool route_pdu = true; if (mac_msg_ul.get()->get_sdu_lcid() == 0) { - uint8_t *x = mac_msg_ul.get()->get_sdu_ptr(); + uint8_t* x = mac_msg_ul.get()->get_sdu_ptr(); uint32_t sum = 0; for (uint32_t i = 0; i < mac_msg_ul.get()->get_payload_size(); i++) { sum += x[i]; @@ -226,8 +230,8 @@ void ue::process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channe mac_msg_ul.get()->get_payload_size()); } - // Indicate scheduler to update BSR counters - //sched->ul_recv_len(rnti, mac_msg_ul.get()->get_sdu_lcid(), mac_msg_ul.get()->get_payload_size()); + // Indicate scheduler to update BSR counters + // sched->ul_recv_len(rnti, mac_msg_ul.get()->get_sdu_lcid(), mac_msg_ul.get()->get_payload_size()); // Indicate RRC about successful activity if valid RLC message is received if (mac_msg_ul.get()->get_payload_size() > 64) { // do not count RLC status messages only @@ -235,8 +239,8 @@ void ue::process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channe log_h->debug("UL activity rnti=0x%x, n_bytes=%d\n", rnti, nof_bytes); } - if ((int) mac_msg_ul.get()->get_payload_size() > most_data) { - most_data = (int) mac_msg_ul.get()->get_payload_size(); + if ((int)mac_msg_ul.get()->get_payload_size() > most_data) { + most_data = (int)mac_msg_ul.get()->get_payload_size(); lcid_most_data = mac_msg_ul.get()->get_sdu_lcid(); } @@ -244,8 +248,8 @@ void ue::process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channe if (mac_msg_ul.get()->get_sdu_lcid() == 0 && route_pdu) { int nbytes = srslte::sch_subh::MAC_CE_CONTRES_LEN; if (mac_msg_ul.get()->get_payload_size() >= (uint32_t)nbytes) { - uint8_t *ue_cri_ptr = (uint8_t *) &conres_id; - uint8_t *pkt_ptr = mac_msg_ul.get()->get_sdu_ptr(); // Warning here: we want to include the + uint8_t* ue_cri_ptr = (uint8_t*)&conres_id; + uint8_t* pkt_ptr = mac_msg_ul.get()->get_sdu_ptr(); // Warning here: we want to include the for (int i = 0; i < nbytes; i++) { ue_cri_ptr[nbytes - i - 1] = pkt_ptr[i]; } @@ -259,7 +263,7 @@ void ue::process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channe /* Process CE after all SDUs because we need to update BSR after */ bool bsr_received = false; - while(mac_msg_ul.next()) { + while (mac_msg_ul.next()) { assert(mac_msg_ul.get()); if (!mac_msg_ul.get()->is_sdu()) { // Process MAC Control Element @@ -275,7 +279,6 @@ void ue::process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channe } Debug("MAC PDU processed\n"); - } void ue::deallocate_pdu(uint32_t tti) @@ -298,56 +301,64 @@ void ue::push_pdu(uint32_t tti, uint32_t len) } } -bool ue::process_ce(srslte::sch_subh *subh) { +bool ue::process_ce(srslte::sch_subh* subh) +{ uint32_t buff_size[4] = {0, 0, 0, 0}; - float phr = 0; - int32_t idx = 0; - uint16_t old_rnti = 0; - bool is_bsr = false; - switch(subh->ce_type()) { - case srslte::sch_subh::PHR_REPORT: - phr = subh->get_phr(); + float phr = 0; + int32_t idx = 0; + uint16_t old_rnti = 0; + bool is_bsr = false; + switch (subh->ce_type()) { + case srslte::sch_subh::PHR_REPORT: + phr = subh->get_phr(); Info("CE: Received PHR from rnti=0x%x, value=%.0f\n", rnti, phr); - sched->ul_phr(rnti, (int) phr); + sched->ul_phr(rnti, (int)phr); metrics_phr(phr); break; - case srslte::sch_subh::CRNTI: - old_rnti = subh->get_c_rnti(); + case srslte::sch_subh::CRNTI: + old_rnti = subh->get_c_rnti(); Info("CE: Received C-RNTI from temp_rnti=0x%x, rnti=0x%x\n", rnti, old_rnti); if (sched->ue_exists(old_rnti)) { rrc->upd_user(rnti, old_rnti); - rnti = old_rnti; + rnti = old_rnti; } else { Error("Updating user C-RNTI: rnti=0x%x already released\n", old_rnti); } break; - case srslte::sch_subh::TRUNC_BSR: + case srslte::sch_subh::TRUNC_BSR: case srslte::sch_subh::SHORT_BSR: idx = subh->get_bsr(buff_size); - if(idx == -1){ + if (idx == -1) { Error("Invalid Index Passed to lc groups\n"); break; } - for (uint32_t i=0;iul_bsr(rnti, lc_groups[idx][i], buff_size[idx]); } Info("CE: Received %s BSR rnti=0x%x, lcg=%d, value=%d\n", - subh->ce_type()==srslte::sch_subh::SHORT_BSR?"Short":"Trunc", rnti, idx, buff_size[idx]); + subh->ce_type() == srslte::sch_subh::SHORT_BSR ? "Short" : "Trunc", + rnti, + idx, + buff_size[idx]); is_bsr = true; break; case srslte::sch_subh::LONG_BSR: subh->get_bsr(buff_size); - for (idx=0;idx<4;idx++) { - for (uint32_t i=0;iul_bsr(rnti, lc_groups[idx][i], buff_size[idx]); } } is_bsr = true; - Info("CE: Received Long BSR rnti=0x%x, value=%d,%d,%d,%d\n", rnti, - buff_size[0], buff_size[1], buff_size[2], buff_size[3]); + Info("CE: Received Long BSR rnti=0x%x, value=%d,%d,%d,%d\n", + rnti, + buff_size[0], + buff_size[1], + buff_size[2], + buff_size[3]); break; - case srslte::sch_subh::PADDING: + case srslte::sch_subh::PADDING: Debug("CE: Received padding for rnti=0x%x\n", rnti); break; default: @@ -357,40 +368,38 @@ bool ue::process_ce(srslte::sch_subh *subh) { return is_bsr; } - -int ue::read_pdu(uint32_t lcid, uint8_t *payload, uint32_t requested_bytes) +int ue::read_pdu(uint32_t lcid, uint8_t* payload, uint32_t requested_bytes) { - return rlc->read_pdu(rnti, lcid, payload, requested_bytes); + return rlc->read_pdu(rnti, lcid, payload, requested_bytes); } -void ue::allocate_sdu(srslte::sch_pdu *pdu, uint32_t lcid, uint32_t total_sdu_len) +void ue::allocate_sdu(srslte::sch_pdu* pdu, uint32_t lcid, uint32_t total_sdu_len) { int sdu_space = pdu->get_sdu_space(); if (sdu_space > 0) { - int sdu_len = SRSLTE_MIN(total_sdu_len, (uint32_t) sdu_space); - int n=1; - while(sdu_len >= 2 && n > 0) { // minimum size is a single RLC AM status PDU (2 Byte) - if (pdu->new_subh()) { // there is space for a new subheader + int sdu_len = SRSLTE_MIN(total_sdu_len, (uint32_t)sdu_space); + int n = 1; + while (sdu_len >= 2 && n > 0) { // minimum size is a single RLC AM status PDU (2 Byte) + if (pdu->new_subh()) { // there is space for a new subheader log_h->debug("SDU: set_sdu(), lcid=%d, sdu_len=%d, sdu_space=%d\n", lcid, sdu_len, sdu_space); - n = pdu->get()->set_sdu(lcid, sdu_len, this); - if (n > 0) { // new SDU could be added - sdu_len -= n; - log_h->debug("SDU: rnti=0x%x, lcid=%d, nbytes=%d, rem_len=%d\n", - rnti, lcid, n, sdu_len); + n = pdu->get()->set_sdu(lcid, sdu_len, this); + if (n > 0) { // new SDU could be added + sdu_len -= n; + log_h->debug("SDU: rnti=0x%x, lcid=%d, nbytes=%d, rem_len=%d\n", rnti, lcid, n, sdu_len); } else { Debug("Could not add SDU lcid=%d nbytes=%d, space=%d\n", lcid, sdu_len, sdu_space); pdu->del_subh(); } } else { - n=0; + n = 0; } - } + } } } -void ue::allocate_ce(srslte::sch_pdu *pdu, uint32_t lcid) +void ue::allocate_ce(srslte::sch_pdu* pdu, uint32_t lcid) { - switch((srslte::sch_subh::cetype) lcid) { + switch ((srslte::sch_subh::cetype)lcid) { case srslte::sch_subh::TA_CMD: if (pdu->new_subh()) { uint32_t ta_cmd = 31; @@ -414,7 +423,7 @@ void ue::allocate_ce(srslte::sch_pdu *pdu, uint32_t lcid) } else { Error("CE: Setting Contention Resolution ID CE. No space for a subheader\n"); } - break; + break; default: Error("CE: Allocating CE=0x%x. Not supported\n", lcid); break; @@ -427,27 +436,27 @@ uint8_t* ue::generate_pdu(uint32_t harq_pid, uint32_t nof_pdu_elems, uint32_t grant_size) { - uint8_t *ret = NULL; + uint8_t* ret = NULL; pthread_mutex_lock(&mutex); if (rlc) { tx_payload_buffer[harq_pid][tb_idx].clear(); mac_msg_dl.init_tx(&tx_payload_buffer[harq_pid][tb_idx], grant_size, false); - for (uint32_t i=0;iget_ul_buffer(rnti); metrics.dl_buffer = sched->get_dl_buffer(rnti); - + memcpy(metrics_, &metrics, sizeof(mac_metrics_t)); - phr_counter = 0; + phr_counter = 0; dl_cqi_counter = 0; - bzero(&metrics, sizeof(mac_metrics_t)); + bzero(&metrics, sizeof(mac_metrics_t)); } -void ue::metrics_phr(float phr) { +void ue::metrics_phr(float phr) +{ metrics.phr = SRSLTE_VEC_CMA(phr, metrics.phr, phr_counter); phr_counter++; } -void ue::metrics_dl_ri(uint32_t dl_ri) { +void ue::metrics_dl_ri(uint32_t dl_ri) +{ if (metrics.dl_ri == 0.0f) { - metrics.dl_ri = (float) dl_ri + 1.0f; + metrics.dl_ri = (float)dl_ri + 1.0f; } else { - metrics.dl_ri = SRSLTE_VEC_EMA((float) dl_ri + 1.0f, metrics.dl_ri, 0.5f); + metrics.dl_ri = SRSLTE_VEC_EMA((float)dl_ri + 1.0f, metrics.dl_ri, 0.5f); } dl_ri_counter++; } -void ue::metrics_dl_pmi(uint32_t dl_ri) { - metrics.dl_pmi = SRSLTE_VEC_CMA((float) dl_ri, metrics.dl_pmi, dl_pmi_counter); +void ue::metrics_dl_pmi(uint32_t dl_ri) +{ + metrics.dl_pmi = SRSLTE_VEC_CMA((float)dl_ri, metrics.dl_pmi, dl_pmi_counter); dl_pmi_counter++; } -void ue::metrics_dl_cqi(uint32_t dl_cqi) { - metrics.dl_cqi = SRSLTE_VEC_CMA((float) dl_cqi, metrics.dl_cqi, dl_cqi_counter); +void ue::metrics_dl_cqi(uint32_t dl_cqi) +{ + metrics.dl_cqi = SRSLTE_VEC_CMA((float)dl_cqi, metrics.dl_cqi, dl_cqi_counter); dl_cqi_counter++; } void ue::metrics_rx(bool crc, uint32_t tbs) { if (crc) { - metrics.rx_brate += tbs*8; + metrics.rx_brate += tbs * 8; } else { metrics.rx_errors++; } @@ -531,13 +542,11 @@ void ue::metrics_rx(bool crc, uint32_t tbs) void ue::metrics_tx(bool crc, uint32_t tbs) { if (crc) { - metrics.tx_brate += tbs*8; + metrics.tx_brate += tbs * 8; } else { metrics.tx_errors++; } metrics.tx_pkts++; } - -} - +} // namespace srsenb diff --git a/srsenb/src/stack/upper/gtpu.cc b/srsenb/src/stack/upper/gtpu.cc index 96c781ee5..7c0f2eb23 100644 --- a/srsenb/src/stack/upper/gtpu.cc +++ b/srsenb/src/stack/upper/gtpu.cc @@ -55,13 +55,13 @@ bool gtpu::init(std::string gtp_bind_addr_, return false; } int enable = 1; -#if defined (SO_REUSEADDR) +#if defined(SO_REUSEADDR) if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) - gtpu_log->error("setsockopt(SO_REUSEADDR) failed\n"); + gtpu_log->error("setsockopt(SO_REUSEADDR) failed\n"); #endif -#if defined (SO_REUSEPORT) +#if defined(SO_REUSEPORT) if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(int)) < 0) - gtpu_log->error("setsockopt(SO_REUSEPORT) failed\n"); + gtpu_log->error("setsockopt(SO_REUSEPORT) failed\n"); #endif struct sockaddr_in bindaddr; @@ -70,7 +70,7 @@ bool gtpu::init(std::string gtp_bind_addr_, bindaddr.sin_addr.s_addr = inet_addr(gtp_bind_addr.c_str()); bindaddr.sin_port = htons(GTPU_PORT); - if (bind(fd, (struct sockaddr *)&bindaddr, sizeof(struct sockaddr_in))) { + if (bind(fd, (struct sockaddr*)&bindaddr, sizeof(struct sockaddr_in))) { gtpu_log->error("Failed to bind on address %s, port %d\n", gtp_bind_addr.c_str(), GTPU_PORT); gtpu_log->console("Failed to bind on address %s, port %d\n", gtp_bind_addr.c_str(), GTPU_PORT); return false; @@ -129,35 +129,39 @@ void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer_t gtpu_log->error("Error writing GTP-U Header. Flags 0x%x, Message Type 0x%x\n", header.flags, header.message_type); return; } - if (sendto(fd, pdu->msg, pdu->N_bytes, MSG_EOR, (struct sockaddr*)&servaddr, sizeof(struct sockaddr_in))<0) { + if (sendto(fd, pdu->msg, pdu->N_bytes, MSG_EOR, (struct sockaddr*)&servaddr, sizeof(struct sockaddr_in)) < 0) { perror("sendto"); } - } /* Warning: This function is called before calling gtpu::init() during MCCH initialization. * If access to any element created in init (such as gtpu_log) is required, it must be considered * the case of it being NULL. */ -void gtpu::add_bearer(uint16_t rnti, uint32_t lcid, uint32_t addr, uint32_t teid_out, uint32_t *teid_in) +void gtpu::add_bearer(uint16_t rnti, uint32_t lcid, uint32_t addr, uint32_t teid_out, uint32_t* teid_in) { // Allocate a TEID for the incoming tunnel rntilcid_to_teidin(rnti, lcid, teid_in); if (gtpu_log) { - gtpu_log->info("Adding bearer for rnti: 0x%x, lcid: %d, addr: 0x%x, teid_out: 0x%x, teid_in: 0x%x\n", rnti, lcid, addr, teid_out, *teid_in); + gtpu_log->info("Adding bearer for rnti: 0x%x, lcid: %d, addr: 0x%x, teid_out: 0x%x, teid_in: 0x%x\n", + rnti, + lcid, + addr, + teid_out, + *teid_in); } // Initialize maps if it's a new RNTI - if(rnti_bearers.count(rnti) == 0) { - for(int i=0;iinfo("TX GTPU Echo Response, Seq: %d\n", seq); - gtpu_header_t header; + gtpu_header_t header; unique_byte_buffer_t pdu = allocate_unique_buffer(*pool); - //header - header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL | GTPU_FLAGS_SEQUENCE; - header.message_type = GTPU_MSG_ECHO_RESPONSE; - header.teid = 0; - header.length = 4; - header.seq_number = seq; - header.n_pdu = 0; + // header + header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL | GTPU_FLAGS_SEQUENCE; + header.message_type = GTPU_MSG_ECHO_RESPONSE; + header.teid = 0; + header.length = 4; + header.seq_number = seq; + header.n_pdu = 0; header.next_ext_hdr_type = 0; gtpu_write_header(&header, pdu.get(), gtpu_log); @@ -258,15 +262,15 @@ void gtpu::echo_response(in_addr_t addr, in_port_t port, uint16_t seq) } /**************************************************************************** -* TEID to RNIT/LCID helper functions -***************************************************************************/ -void gtpu::teidin_to_rntilcid(uint32_t teidin, uint16_t *rnti, uint16_t *lcid) + * TEID to RNIT/LCID helper functions + ***************************************************************************/ +void gtpu::teidin_to_rntilcid(uint32_t teidin, uint16_t* rnti, uint16_t* lcid) { *lcid = teidin & 0xFFFF; *rnti = (teidin >> 16) & 0xFFFF; } -void gtpu::rntilcid_to_teidin(uint16_t rnti, uint16_t lcid, uint32_t *teidin) +void gtpu::rntilcid_to_teidin(uint16_t rnti, uint16_t lcid, uint32_t* teidin) { *teidin = (rnti << 16) | lcid; } @@ -299,9 +303,9 @@ bool gtpu::m1u_handler::init(std::string m1u_multiaddr_, std::string m1u_if_addr } /* Bind socket */ - bindaddr.sin_family = AF_INET; + bindaddr.sin_family = AF_INET; bindaddr.sin_addr.s_addr = htonl(INADDR_ANY); // Multicast sockets require bind to INADDR_ANY - bindaddr.sin_port = htons(GTPU_PORT + 1); + bindaddr.sin_port = htons(GTPU_PORT + 1); if (bind(m1u_sd, (struct sockaddr*)&bindaddr, sizeof(bindaddr)) < 0) { gtpu_log->error("Failed to bind multicast socket\n"); return false; @@ -314,7 +318,7 @@ bool gtpu::m1u_handler::init(std::string m1u_multiaddr_, std::string m1u_if_addr mreq.imr_interface.s_addr = inet_addr(m1u_if_addr.c_str()); // Address of the IF the socket will listen to. if (setsockopt(m1u_sd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { gtpu_log->error("Register musticast group for M1-U\n"); - gtpu_log->error("M1-U infterface IP: %s, M1-U Multicast Address %s\n", m1u_if_addr.c_str(),m1u_multiaddr.c_str()); + gtpu_log->error("M1-U infterface IP: %s, M1-U Multicast Address %s\n", m1u_if_addr.c_str(), m1u_multiaddr.c_str()); return false; } gtpu_log->info("M1-U initialized\n"); diff --git a/srsenb/test/mac/scheduler_test.cc b/srsenb/test/mac/scheduler_test.cc index bdfa189b6..7bcaa2a76 100644 --- a/srsenb/test/mac/scheduler_test.cc +++ b/srsenb/test/mac/scheduler_test.cc @@ -24,42 +24,37 @@ #include "srsenb/hdr/phy/phy.h" #include "srsenb/hdr/stack/mac/mac.h" +#include "srslte/common/log_filter.h" #include "srslte/interfaces/enb_interfaces.h" #include "srslte/interfaces/sched_interface.h" -#include "srslte/common/log_filter.h" -#include "srslte/radio/radio.h" #include "srslte/phy/utils/debug.h" - -uint8_t sib1_payload[18] = {0x60,0x40,0x04,0x03,0x00,0x01,0x1a,0x2d,0x00,0x18,0x02,0x81,0x80,0x42,0x0c,0x80,0x00,0x00}; -uint8_t sib2_payload[41] = {0x00,0x80,0x1c,0x31,0x18,0x6f,0xe1,0x20,0x00,0x35,0x84,0x8c, - 0xe2,0xd0,0x00,0x02,0x00,0x78,0xee,0x31,0x6a,0xa5,0x37,0x30, - 0xa0,0x70,0xc9,0x49,0xfa,0x8d,0xd2,0x78,0x1a,0x02,0x77,0x4a, - 0x92,0x40,0x00,0x00,0x00}; +#include "srslte/radio/radio.h" + +uint8_t sib1_payload[18] = + {0x60, 0x40, 0x04, 0x03, 0x00, 0x01, 0x1a, 0x2d, 0x00, 0x18, 0x02, 0x81, 0x80, 0x42, 0x0c, 0x80, 0x00, 0x00}; +uint8_t sib2_payload[41] = {0x00, 0x80, 0x1c, 0x31, 0x18, 0x6f, 0xe1, 0x20, 0x00, 0x35, 0x84, 0x8c, 0xe2, 0xd0, + 0x00, 0x02, 0x00, 0x78, 0xee, 0x31, 0x6a, 0xa5, 0x37, 0x30, 0xa0, 0x70, 0xc9, 0x49, + 0xfa, 0x8d, 0xd2, 0x78, 0x1a, 0x02, 0x77, 0x4a, 0x92, 0x40, 0x00, 0x00, 0x00}; // Define dummy RLC always transmitts class rlc : public srsenb::rlc_interface_mac { public: - uint32_t get_buffer_state(uint16_t rnti, uint32_t lcid) - { - return 1; - } + uint32_t get_buffer_state(uint16_t rnti, uint32_t lcid) { return 1; } - int read_pdu(uint16_t rnti, uint32_t lcid, uint8_t *payload, uint32_t nof_bytes) + int read_pdu(uint16_t rnti, uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) { - for (uint32_t i=0;i 50) { running = false; diff --git a/srsenb/test/upper/plmn_test.cc b/srsenb/test/upper/plmn_test.cc index 82ac5ef85..4f2209a2d 100644 --- a/srsenb/test/upper/plmn_test.cc +++ b/srsenb/test/upper/plmn_test.cc @@ -114,7 +114,7 @@ int s1ap_plmn_test() return 0; } -int main(int argc, char **argv) +int main(int argc, char** argv) { TESTASSERT(rrc_plmn_test() == 0); TESTASSERT(s1ap_plmn_test() == 0); diff --git a/srsue/hdr/metrics_csv.h b/srsue/hdr/metrics_csv.h index 7359436d9..f61137c18 100644 --- a/srsue/hdr/metrics_csv.h +++ b/srsue/hdr/metrics_csv.h @@ -27,11 +27,11 @@ #ifndef SRSUE_METRICS_CSV_H #define SRSUE_METRICS_CSV_H +#include +#include #include #include #include -#include -#include #include "srslte/common/metrics_hub.h" #include "ue_metrics_interface.h" @@ -44,8 +44,8 @@ public: metrics_csv(std::string filename); ~metrics_csv(); - void set_metrics(ue_metrics_t &m, const uint32_t period_usec); - void set_ue_handle(ue_metrics_interface *ue_); + void set_metrics(ue_metrics_t& m, const uint32_t period_usec); + void set_ue_handle(ue_metrics_interface* ue_); void stop(); private: diff --git a/srsue/hdr/metrics_stdout.h b/srsue/hdr/metrics_stdout.h index c999ad965..6553683ed 100644 --- a/srsue/hdr/metrics_stdout.h +++ b/srsue/hdr/metrics_stdout.h @@ -42,9 +42,9 @@ public: metrics_stdout(); void toggle_print(bool b); - void set_metrics(ue_metrics_t &m, const uint32_t period_usec); - void set_ue_handle(ue_metrics_interface *ue_); - void stop() {}; + void set_metrics(ue_metrics_t& m, const uint32_t period_usec); + void set_ue_handle(ue_metrics_interface* ue_); + void stop(){}; private: std::string float_to_string(float f, int digits); diff --git a/srsue/hdr/phy/phy.h b/srsue/hdr/phy/phy.h index 3ba0588b0..c6f6e31fa 100644 --- a/srsue/hdr/phy/phy.h +++ b/srsue/hdr/phy/phy.h @@ -50,9 +50,7 @@ public: int init(const phy_args_t& args_) final; // Init for LTE PHYs - int init(const phy_args_t& args_, - stack_interface_phy_lte* stack_, - srslte::radio_interface_phy* radio_) final; + int init(const phy_args_t& args_, stack_interface_phy_lte* stack_, srslte::radio_interface_phy* radio_) final; void stop() final; @@ -60,7 +58,7 @@ public: bool is_initiated(); void get_metrics(phy_metrics_t* m) final; - void srslte_phy_logger(phy_logger_level_t log_level, char *str); + void srslte_phy_logger(phy_logger_level_t log_level, char* str); void enable_pregen_signals(bool enable) final; @@ -150,12 +148,12 @@ private: srslte::log* log_phy_lib_h = nullptr; srsue::stack_interface_phy_lte* stack = nullptr; - srslte::thread_pool workers_pool; + srslte::thread_pool workers_pool; std::vector > workers; - phy_common common; - sync sfsync; - scell::async_recv_vector scell_sync; - prach prach_buffer; + phy_common common; + sync sfsync; + scell::async_recv_vector scell_sync; + prach prach_buffer; srslte_prach_cfg_t prach_cfg = {}; srslte_tdd_config_t tdd_config = {}; @@ -166,7 +164,7 @@ private: /* Current time advance */ uint32_t n_ta = 0; - void set_default_args(phy_args_t *args); + void set_default_args(phy_args_t* args); bool check_args(const phy_args_t& args); }; diff --git a/srsue/hdr/phy/phy_common.h b/srsue/hdr/phy/phy_common.h index a96eebc0a..4b88f2c44 100644 --- a/srsue/hdr/phy/phy_common.h +++ b/srsue/hdr/phy/phy_common.h @@ -114,8 +114,11 @@ public: bool is_any_ul_pending_ack(); bool get_ul_received_ack(srslte_ul_sf_cfg_t* sf, uint32_t cc_idx, bool* ack_value, srslte_dci_ul_t* dci_ul); - void set_ul_received_ack( - srslte_dl_sf_cfg_t* sf, uint32_t cc_idx, bool ack_value, uint32_t I_phich, srslte_dci_ul_t* dci_ul); + void set_ul_received_ack(srslte_dl_sf_cfg_t* sf, + uint32_t cc_idx, + bool ack_value, + uint32_t I_phich, + srslte_dci_ul_t* dci_ul); void set_ul_pending_grant(srslte_dl_sf_cfg_t* sf, uint32_t cc_idx, srslte_dci_ul_t* dci); bool get_ul_pending_grant(srslte_ul_sf_cfg_t* sf, uint32_t cc_idx, uint32_t* pid, srslte_dci_ul_t* dci); diff --git a/srsue/hdr/phy/phy_metrics.h b/srsue/hdr/phy/phy_metrics.h index 9731769aa..bdf499f35 100644 --- a/srsue/hdr/phy/phy_metrics.h +++ b/srsue/hdr/phy/phy_metrics.h @@ -31,15 +31,13 @@ struct info_metrics_t { uint32_t dl_earfcn; }; -struct sync_metrics_t -{ +struct sync_metrics_t { float ta_us; float cfo; float sfo; }; -struct dl_metrics_t -{ +struct dl_metrics_t { float n; float sinr; float rsrp; @@ -52,14 +50,12 @@ struct dl_metrics_t float sync_err; }; -struct ul_metrics_t -{ +struct ul_metrics_t { float mcs; float power; }; -struct phy_metrics_t -{ +struct phy_metrics_t { info_metrics_t info[SRSLTE_MAX_CARRIERS]; sync_metrics_t sync[SRSLTE_MAX_CARRIERS]; dl_metrics_t dl[SRSLTE_MAX_CARRIERS]; diff --git a/srsue/hdr/phy/prach.h b/srsue/hdr/phy/prach.h index c3d378c79..e17d02968 100644 --- a/srsue/hdr/phy/prach.h +++ b/srsue/hdr/phy/prach.h @@ -24,55 +24,56 @@ #include -#include "srslte/srslte.h" -#include "srslte/radio/radio.h" #include "srslte/common/log.h" #include "srslte/interfaces/ue_interfaces.h" +#include "srslte/radio/radio.h" +#include "srslte/srslte.h" namespace srsue { - class prach { - public: - prach() { - bzero(&prach_obj, sizeof(srslte_prach_t)); - bzero(&cell, sizeof(srslte_cell_t)); - bzero(&cfo_h, sizeof(srslte_cfo_t)); +class prach +{ +public: + prach() + { + bzero(&prach_obj, sizeof(srslte_prach_t)); + bzero(&cell, sizeof(srslte_cell_t)); + bzero(&cfo_h, sizeof(srslte_cfo_t)); - transmitted_tti = 0; - target_power_dbm = 0; - mem_initiated = false; - cell_initiated = false; - signal_buffer = NULL; - } - ~prach(); - void init(uint32_t max_prb, srslte::log* log_h); - void stop(); - bool set_cell(srslte_cell_t cell, srslte_prach_cfg_t prach_cfg); - bool prepare_to_send(uint32_t preamble_idx, int allowed_subframe = -1, float target_power_dbm = -1); - bool is_ready_to_send(uint32_t current_tti); - bool is_pending(); - cf_t* generate(float cfo, uint32_t *nof_sf, float *target_power = NULL); + transmitted_tti = 0; + target_power_dbm = 0; + mem_initiated = false; + cell_initiated = false; + signal_buffer = NULL; + } + ~prach(); + void init(uint32_t max_prb, srslte::log* log_h); + void stop(); + bool set_cell(srslte_cell_t cell, srslte_prach_cfg_t prach_cfg); + bool prepare_to_send(uint32_t preamble_idx, int allowed_subframe = -1, float target_power_dbm = -1); + bool is_ready_to_send(uint32_t current_tti); + bool is_pending(); + cf_t* generate(float cfo, uint32_t* nof_sf, float* target_power = NULL); - phy_interface_mac_lte::prach_info_t get_info(); + phy_interface_mac_lte::prach_info_t get_info(); - private: - const static int MAX_LEN_SF = 3; +private: + const static int MAX_LEN_SF = 3; - srslte::log *log_h; - int preamble_idx; - int allowed_subframe; - bool mem_initiated; - bool cell_initiated; - uint32_t len; - cf_t* buffer[12][64]; - srslte_prach_t prach_obj; - int transmitted_tti; - srslte_cell_t cell; - cf_t *signal_buffer; - srslte_cfo_t cfo_h; - float target_power_dbm; - - }; + srslte::log* log_h; + int preamble_idx; + int allowed_subframe; + bool mem_initiated; + bool cell_initiated; + uint32_t len; + cf_t* buffer[12][64]; + srslte_prach_t prach_obj; + int transmitted_tti; + srslte_cell_t cell; + cf_t* signal_buffer; + srslte_cfo_t cfo_h; + float target_power_dbm; +}; } // namespace srsue diff --git a/srsue/hdr/phy/scell/async_scell_recv.h b/srsue/hdr/phy/scell/async_scell_recv.h index 9f57b1eb3..ce5eeae34 100644 --- a/srsue/hdr/phy/scell/async_scell_recv.h +++ b/srsue/hdr/phy/scell/async_scell_recv.h @@ -72,7 +72,7 @@ private: public: phch_scell_recv_buffer() { - tti = 0; + tti = 0; next_offset = 0; bzero(×tamp, sizeof(timestamp)); for (cf_t*& b : buffer) { @@ -102,7 +102,7 @@ private: void set_sf(uint32_t _tti, srslte_timestamp_t* _timestamp, const int& _next_offset) { - tti = _tti; + tti = _tti; next_offset = _next_offset; srslte_timestamp_copy(×tamp, _timestamp); } @@ -140,9 +140,9 @@ private: uint32_t radio_idx; // Pointers to other classes - srslte::log* log_h; + srslte::log* log_h; srslte::radio_interface_phy* radio_h; - phy_common* worker_com; + phy_common* worker_com; // pthread objects pthread_mutex_t mutex_uesync; @@ -162,7 +162,7 @@ private: uint32_t out_of_sync_cnt; uint32_t in_sync_cnt; - cf_t* sf_buffer[SRSLTE_MAX_PORTS]; + cf_t* sf_buffer[SRSLTE_MAX_PORTS]; uint32_t current_sflen; int next_radio_offset; diff --git a/srsue/hdr/phy/sf_worker.h b/srsue/hdr/phy/sf_worker.h index 8ba4e31c3..ebfed6f8b 100644 --- a/srsue/hdr/phy/sf_worker.h +++ b/srsue/hdr/phy/sf_worker.h @@ -41,8 +41,11 @@ namespace srsue { class sf_worker : public srslte::thread_pool::worker { public: - sf_worker( - uint32_t max_prb, phy_common* phy, srslte::log* log, srslte::log* log_phy_lib_h, chest_feedback_itf* chest_loop); + sf_worker(uint32_t max_prb, + phy_common* phy, + srslte::log* log, + srslte::log* log_phy_lib_h, + chest_feedback_itf* chest_loop); virtual ~sf_worker(); void reset(); diff --git a/srsue/hdr/phy/ue_phy_base.h b/srsue/hdr/phy/ue_phy_base.h index 1644af8b6..4542ef075 100644 --- a/srsue/hdr/phy/ue_phy_base.h +++ b/srsue/hdr/phy/ue_phy_base.h @@ -43,7 +43,7 @@ public: virtual int init(const phy_args_t& args_) = 0; - virtual void stop() = 0; + virtual void stop() = 0; virtual void set_earfcn(std::vector earfcns) = 0; diff --git a/srsue/hdr/stack/mac/demux.h b/srsue/hdr/stack/mac/demux.h index 4f15f6150..c809d90f5 100644 --- a/srsue/hdr/stack/mac/demux.h +++ b/srsue/hdr/stack/mac/demux.h @@ -22,14 +22,13 @@ #ifndef SRSUE_DEMUX_H #define SRSUE_DEMUX_H -#include "srslte/interfaces/ue_interfaces.h" -#include "srslte/common/pdu_queue.h" #include "srslte/common/log.h" -#include "srslte/common/timers.h" #include "srslte/common/pdu.h" +#include "srslte/common/pdu_queue.h" +#include "srslte/common/timers.h" +#include "srslte/interfaces/ue_interfaces.h" -/* Logical Channel Demultiplexing and MAC CE dissassemble */ - +/* Logical Channel Demultiplexing and MAC CE dissassemble */ namespace srsue { @@ -59,15 +58,15 @@ public: void push_pdu_mch(uint8_t* buff, uint32_t nof_bytes); void push_pdu_temp_crnti(uint8_t* buff, uint32_t nof_bytes); - bool get_uecrid_successful(); + bool get_uecrid_successful(); - void process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channel_t channel); - void mch_start_rx(uint32_t lcid); + void process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channel_t channel); + void mch_start_rx(uint32_t lcid); private: const static int MAX_PDU_LEN = 150 * 1024 / 8; // ~ 150 Mbps const static int MAX_BCCH_PDU_LEN = 1024; - uint8_t bcch_buffer[MAX_BCCH_PDU_LEN]; // BCCH PID has a dedicated buffer + uint8_t bcch_buffer[MAX_BCCH_PDU_LEN]; // BCCH PID has a dedicated buffer srslte::sch_pdu mac_msg; srslte::mch_pdu mch_mac_msg; @@ -94,6 +93,3 @@ private: } // namespace srsue #endif // SRSUE_DEMUX_H - - - diff --git a/srsue/hdr/stack/mac/dl_harq.h b/srsue/hdr/stack/mac/dl_harq.h index 4c90d62e2..d141e6907 100644 --- a/srsue/hdr/stack/mac/dl_harq.h +++ b/srsue/hdr/stack/mac/dl_harq.h @@ -22,12 +22,11 @@ #ifndef SRSUE_DL_HARQ_H #define SRSUE_DL_HARQ_H - -#include "srslte/common/log.h" -#include "srslte/common/timers.h" #include "demux.h" #include "dl_sps.h" +#include "srslte/common/log.h" #include "srslte/common/mac_pcap.h" +#include "srslte/common/timers.h" #include "srslte/interfaces/ue_interfaces.h" @@ -72,7 +71,8 @@ private: private: const static int RESET_DUPLICATE_TIMEOUT = 6; - class dl_tb_process { + class dl_tb_process + { public: dl_tb_process(void); ~dl_tb_process(); @@ -90,23 +90,23 @@ private: pthread_mutex_t mutex; - bool is_initiated; - dl_harq_entity *harq_entity; - srslte::log *log_h; + bool is_initiated; + dl_harq_entity* harq_entity; + srslte::log* log_h; bool is_first_tb; bool is_new_transmission; bool is_bcch; - uint32_t pid; /* HARQ Proccess ID */ - uint32_t tid; /* Transport block ID */ - uint8_t *payload_buffer_ptr; - bool ack; + uint32_t pid; /* HARQ Proccess ID */ + uint32_t tid; /* Transport block ID */ + uint8_t* payload_buffer_ptr; + bool ack; uint32_t n_retx; mac_interface_phy_lte::mac_grant_dl_t cur_grant; - srslte_softbuffer_rx_t softbuffer; + srslte_softbuffer_rx_t softbuffer; }; /* Transport blocks */ diff --git a/srsue/hdr/stack/mac/dl_sps.h b/srsue/hdr/stack/mac/dl_sps.h index 2b9289e5c..72bd828f3 100644 --- a/srsue/hdr/stack/mac/dl_sps.h +++ b/srsue/hdr/stack/mac/dl_sps.h @@ -27,19 +27,16 @@ /* Downlink Semi-Persistent schedulign (Section 5.10.1) */ - namespace srsue { - + class dl_sps { public: + void clear() {} + void reset() {} + bool get_pending_grant(uint32_t tti, mac_interface_phy_lte::mac_grant_dl_t* grant) { return false; } - void clear() {} - void reset() {} - bool get_pending_grant(uint32_t tti, mac_interface_phy_lte::mac_grant_dl_t* grant) { return false; } - -private: - +private: }; } // namespace srsue diff --git a/srsue/hdr/stack/mac/mac.h b/srsue/hdr/stack/mac/mac.h index 575aedcc0..1c7455b43 100644 --- a/srsue/hdr/stack/mac/mac.h +++ b/srsue/hdr/stack/mac/mac.h @@ -138,8 +138,8 @@ private: ue_rnti_t uernti; /* Multiplexing/Demultiplexing Units */ - mux mux_unit; - demux demux_unit; + mux mux_unit; + demux demux_unit; /* DL/UL HARQ */ dl_harq_entity_vector dl_harq; @@ -147,13 +147,13 @@ private: ul_harq_cfg_t ul_harq_cfg; /* MAC Uplink-related Procedures */ - ra_proc ra_procedure; - sr_proc sr_procedure; - bsr_proc bsr_procedure; - phr_proc phr_procedure; - + ra_proc ra_procedure; + sr_proc sr_procedure; + bsr_proc bsr_procedure; + phr_proc phr_procedure; + /* Buffers for PCH reception (not included in DL HARQ) */ - const static uint32_t pch_payload_buffer_sz = 8*1024; + const static uint32_t pch_payload_buffer_sz = 8 * 1024; srslte_softbuffer_rx_t pch_softbuffer; uint8_t pch_payload_buffer[pch_payload_buffer_sz]; @@ -175,7 +175,7 @@ private: mac_metrics_t metrics[SRSLTE_MAX_CARRIERS] = {}; - bool initialized = false; + bool initialized = false; bool enable_ra_proc = true; }; diff --git a/srsue/hdr/stack/mac/mac_metrics.h b/srsue/hdr/stack/mac/mac_metrics.h index f77d7d34f..5fbf0a5ce 100644 --- a/srsue/hdr/stack/mac/mac_metrics.h +++ b/srsue/hdr/stack/mac/mac_metrics.h @@ -22,18 +22,16 @@ #ifndef SRSUE_MAC_METRICS_H #define SRSUE_MAC_METRICS_H - namespace srsue { -struct mac_metrics_t -{ - int tx_pkts; - int tx_errors; - int tx_brate; - int rx_pkts; - int rx_errors; - int rx_brate; - int ul_buffer; +struct mac_metrics_t { + int tx_pkts; + int tx_errors; + int tx_brate; + int rx_pkts; + int rx_errors; + int rx_brate; + int ul_buffer; float dl_retx_avg; float ul_retx_avg; }; diff --git a/srsue/hdr/stack/mac/mux.h b/srsue/hdr/stack/mac/mux.h index c30bd4fe8..018189003 100644 --- a/srsue/hdr/stack/mac/mux.h +++ b/srsue/hdr/stack/mac/mux.h @@ -34,8 +34,7 @@ #include "srslte/interfaces/ue_interfaces.h" #include -/* Logical Channel Multiplexing and Prioritization + Msg3 Buffer */ - +/* Logical Channel Multiplexing and Prioritization + Msg3 Buffer */ typedef struct { uint8_t lcid; @@ -50,28 +49,28 @@ typedef struct { } logical_channel_config_t; namespace srsue { - + class mux { public: mux(srslte::log* log_); ~mux(){}; - void reset(); - void init(rlc_interface_mac* rlc, bsr_interface_mux* bsr_procedure, phr_proc* phr_procedure_); + void reset(); + void init(rlc_interface_mac* rlc, bsr_interface_mux* bsr_procedure, phr_proc* phr_procedure_); void step(const uint32_t tti); - bool is_pending_any_sdu(); - bool is_pending_sdu(uint32_t lcid); + bool is_pending_any_sdu(); + bool is_pending_sdu(uint32_t lcid); uint8_t* pdu_get(srslte::byte_buffer_t* payload, uint32_t pdu_sz); uint8_t* msg3_get(srslte::byte_buffer_t* payload, uint32_t pdu_sz); - void msg3_flush(); - bool msg3_is_transmitted(); - void msg3_prepare(); - bool msg3_is_pending(); - bool msg3_is_empty(); + void msg3_flush(); + bool msg3_is_transmitted(); + void msg3_prepare(); + bool msg3_is_pending(); + bool msg3_is_empty(); void append_crnti_ce_next_tx(uint16_t crnti); @@ -80,10 +79,10 @@ public: void print_logical_channel_state(const std::string& info); private: - bool has_logical_channel(const uint32_t& lcid); - bool pdu_move_to_msg3(uint32_t pdu_sz); - bool allocate_sdu(uint32_t lcid, srslte::sch_pdu *pdu, int max_sdu_sz); - bool sched_sdu(logical_channel_config_t* ch, int* sdu_space, int max_sdu_sz); + bool has_logical_channel(const uint32_t& lcid); + bool pdu_move_to_msg3(uint32_t pdu_sz); + bool allocate_sdu(uint32_t lcid, srslte::sch_pdu* pdu, int max_sdu_sz); + bool sched_sdu(logical_channel_config_t* ch, int* sdu_space, int max_sdu_sz); const static int MAX_NOF_SUBHEADERS = 20; @@ -112,4 +111,3 @@ private: } // namespace srsue #endif // SRSUE_MUX_H - diff --git a/srsue/hdr/stack/mac/proc.h b/srsue/hdr/stack/mac/proc.h index cf105463a..032250e54 100644 --- a/srsue/hdr/stack/mac/proc.h +++ b/srsue/hdr/stack/mac/proc.h @@ -26,27 +26,19 @@ /* Interface for a MAC procedure */ - namespace srsue { - + class proc { public: - proc() { - running = false; - } - void run() { - running = true; - } - void stop() { - running = false; - } - bool is_running() { - return running; - } - virtual void step(uint32_t tti) = 0; + proc() { running = false; } + void run() { running = true; } + void stop() { running = false; } + bool is_running() { return running; } + virtual void step(uint32_t tti) = 0; + private: - bool running; + bool running; }; } // namespace srsue diff --git a/srsue/hdr/stack/mac/proc_bsr.h b/srsue/hdr/stack/mac/proc_bsr.h index ad71f58c7..e7df8d5c6 100644 --- a/srsue/hdr/stack/mac/proc_bsr.h +++ b/srsue/hdr/stack/mac/proc_bsr.h @@ -26,8 +26,8 @@ #include #include "srslte/common/log.h" -#include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/timers.h" +#include "srslte/interfaces/ue_interfaces.h" /* Buffer status report procedure */ @@ -61,11 +61,11 @@ public: void set_config(srslte::bsr_cfg_t& bsr_cfg); void setup_lcid(uint32_t lcid, uint32_t lcg, uint32_t priority); - void timer_expired(uint32_t timer_id); + void timer_expired(uint32_t timer_id); uint32_t get_buffer_state(); - bool need_to_send_bsr_on_ul_grant(uint32_t grant_size, bsr_t *bsr); - bool generate_padding_bsr(uint32_t nof_padding_bytes, bsr_t *bsr); - bool need_to_send_sr(uint32_t tti); + bool need_to_send_bsr_on_ul_grant(uint32_t grant_size, bsr_t* bsr); + bool generate_padding_bsr(uint32_t nof_padding_bytes, bsr_t* bsr); + bool need_to_send_sr(uint32_t tti); bool need_to_reset_sr(); private: @@ -93,10 +93,10 @@ private: std::map lcgs[NOF_LCG]; // groups LCID in LCG uint32_t find_max_priority_lcg_with_data(); - typedef enum {NONE, REGULAR, PADDING, PERIODIC} triggered_bsr_type_t; - triggered_bsr_type_t triggered_bsr_type; - - bool sr_is_sent; + typedef enum { NONE, REGULAR, PADDING, PERIODIC } triggered_bsr_type_t; + triggered_bsr_type_t triggered_bsr_type; + + bool sr_is_sent; uint32_t last_print; uint32_t current_tti; uint32_t trigger_tti; diff --git a/srsue/hdr/stack/mac/proc_phr.h b/srsue/hdr/stack/mac/proc_phr.h index 680df145b..54d343c7f 100644 --- a/srsue/hdr/stack/mac/proc_phr.h +++ b/srsue/hdr/stack/mac/proc_phr.h @@ -22,15 +22,13 @@ #ifndef SRSUE_PROC_PHR_H #define SRSUE_PROC_PHR_H -#include +#include "srslte/common/log.h" #include "srslte/common/timers.h" #include "srslte/interfaces/ue_interfaces.h" -#include "srslte/common/log.h" - +#include /* Power headroom report procedure */ - namespace srsue { class phr_proc : public srslte::timer_callback diff --git a/srsue/hdr/stack/mac/proc_ra.h b/srsue/hdr/stack/mac/proc_ra.h index 739b64d55..d47c7b07b 100644 --- a/srsue/hdr/stack/mac/proc_ra.h +++ b/srsue/hdr/stack/mac/proc_ra.h @@ -25,24 +25,24 @@ #include #include -#include "srslte/common/log.h" -#include "srslte/common/timers.h" -#include "mux.h" #include "demux.h" -#include "srslte/common/pdu.h" +#include "mux.h" +#include "srslte/common/log.h" #include "srslte/common/mac_pcap.h" +#include "srslte/common/pdu.h" +#include "srslte/common/timers.h" /* Random access procedure as specified in Section 5.1 of 36.321 */ - namespace srsue { class ra_proc : public srslte::timer_callback { public: - ra_proc() : rar_pdu_msg(20) { + ra_proc() : rar_pdu_msg(20) + { bzero(&softbuffer_rar, sizeof(srslte_softbuffer_rx_t)); - pcap = NULL; + pcap = NULL; backoff_interval_start = 0; backoff_interval = 0; received_target_power_dbm = 0; @@ -162,7 +162,7 @@ private: void read_params(); phy_interface_mac_lte* phy_h; - srslte::log* log_h; + srslte::log* log_h; mux* mux_unit; srslte::mac_pcap* pcap; rrc_interface_mac* rrc; @@ -179,9 +179,9 @@ private: std::mutex mutex; bool ra_is_ho; - bool started_by_pdcch; + bool started_by_pdcch; uint32_t rar_grant_nbytes; - bool rar_received; + bool rar_received; }; } // namespace srsue diff --git a/srsue/hdr/stack/mac/proc_sr.h b/srsue/hdr/stack/mac/proc_sr.h index 4a6fe4dd0..63dc4505a 100644 --- a/srsue/hdr/stack/mac/proc_sr.h +++ b/srsue/hdr/stack/mac/proc_sr.h @@ -22,13 +22,12 @@ #ifndef SRSUE_PROC_SR_H #define SRSUE_PROC_SR_H -#include -#include "srslte/interfaces/ue_interfaces.h" #include "srslte/common/log.h" +#include "srslte/interfaces/ue_interfaces.h" +#include /* Scheduling Request procedure as defined in 5.4.4 of 36.321 */ - namespace srsue { class sr_proc @@ -40,22 +39,22 @@ public: void set_config(srslte::sr_cfg_t& cfg); void reset(); void start(); - bool need_random_access(); - + bool need_random_access(); + private: bool need_tx(uint32_t tti); - int sr_counter; - bool is_pending_sr; + int sr_counter; + bool is_pending_sr; srslte::sr_cfg_t sr_cfg; - rrc_interface_mac *rrc; + rrc_interface_mac* rrc; phy_interface_mac_lte* phy_h; - srslte::log *log_h; - - bool initiated; - bool do_ra; + srslte::log* log_h; + + bool initiated; + bool do_ra; }; } // namespace srsue diff --git a/srsue/hdr/stack/mac/ul_harq.h b/srsue/hdr/stack/mac/ul_harq.h index f422cb11d..1614bd46a 100644 --- a/srsue/hdr/stack/mac/ul_harq.h +++ b/srsue/hdr/stack/mac/ul_harq.h @@ -22,10 +22,10 @@ #ifndef SRSUE_UL_HARQ_H #define SRSUE_UL_HARQ_H -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) #include "mux.h" #include "proc_ra.h" @@ -40,7 +40,8 @@ using namespace srslte; namespace srsue { -class ul_harq_entity { +class ul_harq_entity +{ public: ul_harq_entity(); @@ -94,9 +95,9 @@ private: ul_harq_entity* harq_entity; srslte_softbuffer_tx_t softbuffer; - const static int payload_buffer_len = 128 * 1024; + const static int payload_buffer_len = 128 * 1024; std::unique_ptr payload_buffer = nullptr; - uint8_t* pdu_ptr; + uint8_t* pdu_ptr; void generate_tx(mac_interface_phy_lte::tb_action_ul_t* action); void generate_retx(mac_interface_phy_lte::mac_grant_ul_t grant, mac_interface_phy_lte::tb_action_ul_t* action); @@ -111,8 +112,8 @@ private: srslte::mac_pcap* pcap; srslte::log* log_h; - mac_interface_rrc_common::ue_rnti_t* rntis; - srslte::ul_harq_cfg_t harq_cfg; + mac_interface_rrc_common::ue_rnti_t* rntis; + srslte::ul_harq_cfg_t harq_cfg; float average_retx; uint64_t nof_pkts; diff --git a/srsue/hdr/stack/mac/ul_sps.h b/srsue/hdr/stack/mac/ul_sps.h index ec6d9cafe..678914432 100644 --- a/srsue/hdr/stack/mac/ul_sps.h +++ b/srsue/hdr/stack/mac/ul_sps.h @@ -27,21 +27,18 @@ /* Uplink Semi-Persistent schedulign (Section 5.10.2) */ - namespace srsue { - -typedef _Complex float cf_t; + +typedef _Complex float cf_t; class ul_sps { public: + void clear() {} + void reset(uint32_t tti) {} + bool get_pending_grant(uint32_t tti, mac_interface_phy_lte::mac_grant_ul_t* grant) { return false; } - void clear() {} - void reset(uint32_t tti) {} - bool get_pending_grant(uint32_t tti, mac_interface_phy_lte::mac_grant_ul_t* grant) { return false; } - -private: - +private: }; } // namespace srsue diff --git a/srsue/hdr/stack/rrc/rrc_common.h b/srsue/hdr/stack/rrc/rrc_common.h index b248ef553..98d7acb54 100644 --- a/srsue/hdr/stack/rrc/rrc_common.h +++ b/srsue/hdr/stack/rrc/rrc_common.h @@ -24,17 +24,14 @@ namespace srsue { - // RRC states (3GPP 36.331 v10.0.0) typedef enum { RRC_STATE_IDLE = 0, RRC_STATE_CONNECTED, RRC_STATE_N_ITEMS, } rrc_state_t; -static const char rrc_state_text[RRC_STATE_N_ITEMS][100] = {"IDLE", - "CONNECTED"}; +static const char rrc_state_text[RRC_STATE_N_ITEMS][100] = {"IDLE", "CONNECTED"}; } // namespace srsue - #endif // SRSUE_RRC_COMMON_H diff --git a/srsue/hdr/stack/rrc/rrc_procedures.h b/srsue/hdr/stack/rrc/rrc_procedures.h index e76f84df1..863d7f6b0 100644 --- a/srsue/hdr/stack/rrc/rrc_procedures.h +++ b/srsue/hdr/stack/rrc/rrc_procedures.h @@ -50,7 +50,7 @@ private: srslte::proc_outcome_t handle_cell_found(const phy_interface_rrc_lte::phy_cell_t& new_cell); // conts - rrc* rrc_ptr; + rrc* rrc_ptr; // state vars cell_search_event_t search_result; diff --git a/srsue/hdr/stack/ue_stack_base.h b/srsue/hdr/stack/ue_stack_base.h index 8041a05dc..cfd17c127 100644 --- a/srsue/hdr/stack/ue_stack_base.h +++ b/srsue/hdr/stack/ue_stack_base.h @@ -76,9 +76,9 @@ public: virtual std::string get_type() = 0; - virtual void stop() = 0; - virtual bool switch_on() = 0; - virtual bool switch_off() = 0; + virtual void stop() = 0; + virtual bool switch_on() = 0; + virtual bool switch_off() = 0; // UE metrics interface virtual bool get_metrics(stack_metrics_t* metrics) = 0; diff --git a/srsue/hdr/stack/upper/gw.h b/srsue/hdr/stack/upper/gw.h index 5da437573..9ab03b895 100644 --- a/srsue/hdr/stack/upper/gw.h +++ b/srsue/hdr/stack/upper/gw.h @@ -52,7 +52,7 @@ public: int init(const gw_args_t& args_, srslte::logger* logger_, stack_interface_gw* stack); void stop(); - void get_metrics(gw_metrics_t &m); + void get_metrics(gw_metrics_t& m); // PDCP interface void write_pdu(uint32_t lcid, srslte::unique_byte_buffer_t pdu); @@ -76,22 +76,22 @@ private: gw_args_t args = {}; - bool running = false; - bool run_enable = false; - int32_t tun_fd = 0; - struct ifreq ifr = {}; - int32_t sock = 0; - bool if_up = false; - uint32_t default_lcid = 0; + bool running = false; + bool run_enable = false; + int32_t tun_fd = 0; + struct ifreq ifr = {}; + int32_t sock = 0; + bool if_up = false; + uint32_t default_lcid = 0; srslte::log_filter log; - uint32_t current_ip_addr = 0; - uint8_t current_if_id[8]; + uint32_t current_ip_addr = 0; + uint8_t current_if_id[8]; - long ul_tput_bytes = 0; - long dl_tput_bytes = 0; - struct timeval metrics_time[3]; + long ul_tput_bytes = 0; + long dl_tput_bytes = 0; + struct timeval metrics_time[3]; void run_thread(); int init_if(char* err_str); diff --git a/srsue/hdr/stack/upper/gw_metrics.h b/srsue/hdr/stack/upper/gw_metrics.h index 7af50317b..5b6659f88 100644 --- a/srsue/hdr/stack/upper/gw_metrics.h +++ b/srsue/hdr/stack/upper/gw_metrics.h @@ -22,11 +22,9 @@ #ifndef SRSUE_GW_METRICS_H #define SRSUE_GW_METRICS_H - namespace srsue { -struct gw_metrics_t -{ +struct gw_metrics_t { double dl_tput_mbps; double ul_tput_mbps; }; diff --git a/srsue/hdr/stack/upper/nas.h b/srsue/hdr/stack/upper/nas.h index 62967dcbb..9668fa36c 100644 --- a/srsue/hdr/stack/upper/nas.h +++ b/srsue/hdr/stack/upper/nas.h @@ -71,7 +71,7 @@ public: void timer_expired(uint32_t timeout_id); // PCAP - void start_pcap(srslte::nas_pcap *pcap_); + void start_pcap(srslte::nas_pcap* pcap_); private: srslte::byte_buffer_pool* pool = nullptr; @@ -86,19 +86,19 @@ private: nas_interface_rrc::barring_t current_barring = BARRING_NONE; - bool plmn_is_selected = false; - srslte::plmn_id_t current_plmn; - srslte::plmn_id_t home_plmn; + bool plmn_is_selected = false; + srslte::plmn_id_t current_plmn; + srslte::plmn_id_t home_plmn; std::vector known_plmns; // Security context - struct nas_sec_ctxt{ - uint8_t ksi; - uint8_t k_asme[32]; - uint32_t tx_count; - uint32_t rx_count; - uint32_t k_enb_count; + struct nas_sec_ctxt { + uint8_t ksi; + uint8_t k_asme[32]; + uint32_t tx_count; + uint32_t rx_count; + uint32_t k_enb_count; srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo; srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo; LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT guti; @@ -147,18 +147,14 @@ private: bool running = false; - void integrity_generate(uint8_t *key_128, - uint32_t count, - uint8_t direction, - uint8_t *msg, - uint32_t msg_len, - uint8_t *mac); + void + integrity_generate(uint8_t* key_128, uint32_t count, uint8_t direction, uint8_t* msg, uint32_t msg_len, uint8_t* mac); bool integrity_check(srslte::byte_buffer_t* pdu); void cipher_encrypt(srslte::byte_buffer_t* pdu); void cipher_decrypt(srslte::byte_buffer_t* pdu); void set_k_enb_count(uint32_t count); - bool check_cap_replay(LIBLTE_MME_UE_SECURITY_CAPABILITIES_STRUCT *caps); + bool check_cap_replay(LIBLTE_MME_UE_SECURITY_CAPABILITIES_STRUCT* caps); void select_plmn(); @@ -190,7 +186,7 @@ private: void send_esm_information_response(const uint8 proc_transaction_id); void send_authentication_response(const uint8_t* res, const size_t res_len, const uint8_t sec_hdr_type); void send_authentication_failure(const uint8_t cause, const uint8_t* auth_fail_param); - void gen_pdn_connectivity_request(LIBLTE_BYTE_MSG_STRUCT *msg); + void gen_pdn_connectivity_request(LIBLTE_BYTE_MSG_STRUCT* msg); void send_security_mode_reject(uint8_t cause); void send_detach_request(bool switch_off); void send_detach_accept(); @@ -209,32 +205,32 @@ private: // ctxt file helpers std::string hex_to_string(uint8_t* hex, int size); - bool string_to_hex(std::string hex_str, uint8_t *hex, uint32_t len); - std::string emm_info_str(LIBLTE_MME_EMM_INFORMATION_MSG_STRUCT *info); + bool string_to_hex(std::string hex_str, uint8_t* hex, uint32_t len); + std::string emm_info_str(LIBLTE_MME_EMM_INFORMATION_MSG_STRUCT* info); template - bool readvar(std::istream &file, const char *key, T *var) + bool readvar(std::istream& file, const char* key, T* var) { std::string line; - size_t len = strlen(key); + size_t len = strlen(key); std::getline(file, line); - if(line.substr(0,len).compare(key)) { + if (line.substr(0, len).compare(key)) { return false; } *var = (T)strtol(line.substr(len).c_str(), NULL, 10); return true; } - bool readvar(std::istream &file, const char *key, uint8_t *var, int varlen) + bool readvar(std::istream& file, const char* key, uint8_t* var, int varlen) { std::string line; - size_t len = strlen(key); + size_t len = strlen(key); std::getline(file, line); - if(line.substr(0,len).compare(key)) { + if (line.substr(0, len).compare(key)) { return false; } std::string tmp = line.substr(len); - if(!string_to_hex(tmp, var, varlen)) { + if (!string_to_hex(tmp, var, varlen)) { return false; } return true; diff --git a/srsue/hdr/stack/upper/nas_common.h b/srsue/hdr/stack/upper/nas_common.h index 60df32020..007784bfb 100644 --- a/srsue/hdr/stack/upper/nas_common.h +++ b/srsue/hdr/stack/upper/nas_common.h @@ -47,8 +47,11 @@ typedef enum { EMM_STATE_TAU_INITIATED, EMM_STATE_N_ITEMS, } emm_state_t; -static const char emm_state_text[EMM_STATE_N_ITEMS][100] = { - "NULL", "DEREGISTERED", "REGISTERED", "DEREGISTERED INITIATED", "TRACKING AREA UPDATE INITIATED"}; +static const char emm_state_text[EMM_STATE_N_ITEMS][100] = {"NULL", + "DEREGISTERED", + "REGISTERED", + "DEREGISTERED INITIATED", + "TRACKING AREA UPDATE INITIATED"}; } // namespace srsue diff --git a/srsue/hdr/stack/upper/pcsc_usim.h b/srsue/hdr/stack/upper/pcsc_usim.h index a20deeb34..968962c26 100644 --- a/srsue/hdr/stack/upper/pcsc_usim.h +++ b/srsue/hdr/stack/upper/pcsc_usim.h @@ -35,27 +35,23 @@ namespace srsue { #define AKA_RAND_LEN 16 #define AKA_AUTN_LEN 16 #define AKA_AUTS_LEN 14 -#define RES_MAX_LEN 16 -#define MAC_LEN 8 -#define IK_LEN 16 -#define CK_LEN 16 -#define AK_LEN 6 -#define SQN_LEN 6 +#define RES_MAX_LEN 16 +#define MAC_LEN 8 +#define IK_LEN 16 +#define CK_LEN 16 +#define AK_LEN 6 +#define SQN_LEN 6 -#define KEY_LEN 32 +#define KEY_LEN 32 -typedef enum { - SCARD_GSM_SIM, - SCARD_USIM -} sim_types_t; +typedef enum { SCARD_GSM_SIM, SCARD_USIM } sim_types_t; -static inline uint16_t to_uint16(const uint8_t *a) +static inline uint16_t to_uint16(const uint8_t* a) { return (a[0] << 8) | a[1]; } -class pcsc_usim - :public usim_base +class pcsc_usim : public usim_base { public: pcsc_usim(srslte::log* log_); @@ -71,41 +67,40 @@ public: bool get_imei_vec(uint8_t* imei_, uint32_t n); bool get_home_plmn_id(srslte::plmn_id_t* home_plmn_id); - auth_result_t generate_authentication_response(uint8_t *rand, - uint8_t *autn_enb, - uint16_t mcc, - uint16_t mnc, - uint8_t *res, - int *res_len, - uint8_t *k_asme); - - void generate_nas_keys(uint8_t *k_asme, - uint8_t *k_nas_enc, - uint8_t *k_nas_int, + auth_result_t generate_authentication_response(uint8_t* rand, + uint8_t* autn_enb, + uint16_t mcc, + uint16_t mnc, + uint8_t* res, + int* res_len, + uint8_t* k_asme); + + void generate_nas_keys(uint8_t* k_asme, + uint8_t* k_nas_enc, + uint8_t* k_nas_int, srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo); // RRC interface - void generate_as_keys(uint8_t *k_asme, - uint32_t count_ul, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int, - uint8_t *k_up_enc, - uint8_t *k_up_int, + void generate_as_keys(uint8_t* k_asme, + uint32_t count_ul, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int, + uint8_t* k_up_enc, + uint8_t* k_up_int, srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo); - void generate_as_keys_ho(uint32_t pci, - uint32_t earfcn, - int ncc, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int, - uint8_t *k_up_enc, - uint8_t *k_up_int, + void generate_as_keys_ho(uint32_t pci, + uint32_t earfcn, + int ncc, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int, + uint8_t* k_up_enc, + uint8_t* k_up_int, srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo); - private: srslte::log* log = nullptr; @@ -141,123 +136,132 @@ private: // Smartcard sub-class which is a port of the PC/SC smartcard implementation // of WPA Supplicant written by Jouni Malinen and licensed under BSD // Source: https://w1.fi/cvs.html - class scard { + class scard + { public: - scard() : log(NULL) {}; - ~scard() {}; + scard() : log(NULL){}; + ~scard(){}; - int init(usim_args_t *args, srslte::log *log_); + int init(usim_args_t* args, srslte::log* log_); void deinit(); - int select_file(unsigned short file_id,unsigned char *buf, size_t *buf_len); - int _select_file(unsigned short file_id, unsigned char *buf, size_t *buf_len, sim_types_t sim_type, unsigned char *aid, size_t aidlen); + int select_file(unsigned short file_id, unsigned char* buf, size_t* buf_len); + int _select_file(unsigned short file_id, + unsigned char* buf, + size_t* buf_len, + sim_types_t sim_type, + unsigned char* aid, + size_t aidlen); - long transmit(unsigned char *_send, size_t send_len, unsigned char *_recv, size_t *recv_len); + long transmit(unsigned char* _send, size_t send_len, unsigned char* _recv, size_t* recv_len); - int get_aid(unsigned char *aid, size_t maxlen); + int get_aid(unsigned char* aid, size_t maxlen); int get_record_len(unsigned char recnum, unsigned char mode); - int read_record(unsigned char *data, size_t len, unsigned char recnum, unsigned char mode); - int get_imsi(char *imsi, size_t *len); - int parse_fsp_templ(unsigned char *buf, size_t buf_len, int *ps_do, int *file_len); - int read_file(unsigned char *data, size_t len); + int read_record(unsigned char* data, size_t len, unsigned char recnum, unsigned char mode); + int get_imsi(char* imsi, size_t* len); + int parse_fsp_templ(unsigned char* buf, size_t buf_len, int* ps_do, int* file_len); + int read_file(unsigned char* data, size_t len); int get_mnc_len(); - int umts_auth(const unsigned char *_rand, - const unsigned char *autn, - unsigned char *res, int *res_len, - unsigned char *ik, unsigned char *ck, unsigned char *auts); - int pin_needed(unsigned char *hdr, size_t hlen); - int verify_pin(const char *pin); + int umts_auth(const unsigned char* _rand, + const unsigned char* autn, + unsigned char* res, + int* res_len, + unsigned char* ik, + unsigned char* ck, + unsigned char* auts); + int pin_needed(unsigned char* hdr, size_t hlen); + int verify_pin(const char* pin); int get_pin_retry_counter(); private: - /* See ETSI GSM 11.11 and ETSI TS 102 221 for details. - * SIM commands: - * Command APDU: CLA INS P1 P2 P3 Data - * CLA (class of instruction): A0 for GSM, 00 for USIM - * INS (instruction) - * P1 P2 P3 (parameters, P3 = length of Data) - * Response APDU: Data SW1 SW2 - * SW1 SW2 (Status words) - * Commands (INS P1 P2 P3): - * SELECT: A4 00 00 02 - * GET RESPONSE: C0 00 00 - * RUN GSM ALG: 88 00 00 00 - * RUN UMTS ALG: 88 00 81 data: 0x10 | RAND | 0x10 | AUTN - * P1 = ID of alg in card - * P2 = ID of secret key - * READ BINARY: B0 - * READ RECORD: B2 - * P2 (mode) = '02' (next record), '03' (previous record), - * '04' (absolute mode) - * VERIFY CHV: 20 00 08 - * CHANGE CHV: 24 00 10 - * DISABLE CHV: 26 00 01 08 - * ENABLE CHV: 28 00 01 08 - * UNBLOCK CHV: 2C 00 <00=CHV1, 02=CHV2> 10 - * SLEEP: FA 00 00 00 - */ - - /* GSM SIM commands */ - #define SIM_CMD_SELECT 0xa0, 0xa4, 0x00, 0x00, 0x02 - #define SIM_CMD_RUN_GSM_ALG 0xa0, 0x88, 0x00, 0x00, 0x10 - #define SIM_CMD_GET_RESPONSE 0xa0, 0xc0, 0x00, 0x00 - #define SIM_CMD_READ_BIN 0xa0, 0xb0, 0x00, 0x00 - #define SIM_CMD_READ_RECORD 0xa0, 0xb2, 0x00, 0x00 - #define SIM_CMD_VERIFY_CHV1 0xa0, 0x20, 0x00, 0x01, 0x08 - - /* USIM commands */ - #define USIM_CLA 0x00 - #define USIM_CMD_RUN_UMTS_ALG 0x00, 0x88, 0x00, 0x81, 0x22 - #define USIM_CMD_GET_RESPONSE 0x00, 0xc0, 0x00, 0x00 - - #define SIM_RECORD_MODE_ABSOLUTE 0x04 - - #define USIM_FSP_TEMPL_TAG 0x62 - - #define USIM_TLV_FILE_DESC 0x82 - #define USIM_TLV_FILE_ID 0x83 - #define USIM_TLV_DF_NAME 0x84 - #define USIM_TLV_PROPR_INFO 0xA5 - #define USIM_TLV_LIFE_CYCLE_STATUS 0x8A - #define USIM_TLV_FILE_SIZE 0x80 - #define USIM_TLV_TOTAL_FILE_SIZE 0x81 - #define USIM_TLV_PIN_STATUS_TEMPLATE 0xC6 - #define USIM_TLV_SHORT_FILE_ID 0x88 - #define USIM_TLV_SECURITY_ATTR_8B 0x8B - #define USIM_TLV_SECURITY_ATTR_8C 0x8C - #define USIM_TLV_SECURITY_ATTR_AB 0xAB - - #define USIM_PS_DO_TAG 0x90 - - /* GSM files - * File type in first octet: - * 3F = Master File - * 7F = Dedicated File - * 2F = Elementary File under the Master File - * 6F = Elementary File under a Dedicated File - */ - #define SCARD_FILE_MF 0x3F00 - #define SCARD_FILE_GSM_DF 0x7F20 - #define SCARD_FILE_UMTS_DF 0x7F50 - #define SCARD_FILE_GSM_EF_IMSI 0x6F07 - #define SCARD_FILE_GSM_EF_AD 0x6FAD - #define SCARD_FILE_EF_DIR 0x2F00 - #define SCARD_FILE_EF_ICCID 0x2FE2 - #define SCARD_FILE_EF_CK 0x6FE1 - #define SCARD_FILE_EF_IK 0x6FE2 - - #define SCARD_CHV1_OFFSET 13 - #define SCARD_CHV1_FLAG 0x80 - - SCARDCONTEXT scard_context; - SCARDHANDLE scard_handle; +/* See ETSI GSM 11.11 and ETSI TS 102 221 for details. + * SIM commands: + * Command APDU: CLA INS P1 P2 P3 Data + * CLA (class of instruction): A0 for GSM, 00 for USIM + * INS (instruction) + * P1 P2 P3 (parameters, P3 = length of Data) + * Response APDU: Data SW1 SW2 + * SW1 SW2 (Status words) + * Commands (INS P1 P2 P3): + * SELECT: A4 00 00 02 + * GET RESPONSE: C0 00 00 + * RUN GSM ALG: 88 00 00 00 + * RUN UMTS ALG: 88 00 81 data: 0x10 | RAND | 0x10 | AUTN + * P1 = ID of alg in card + * P2 = ID of secret key + * READ BINARY: B0 + * READ RECORD: B2 + * P2 (mode) = '02' (next record), '03' (previous record), + * '04' (absolute mode) + * VERIFY CHV: 20 00 08 + * CHANGE CHV: 24 00 10 + * DISABLE CHV: 26 00 01 08 + * ENABLE CHV: 28 00 01 08 + * UNBLOCK CHV: 2C 00 <00=CHV1, 02=CHV2> 10 + * SLEEP: FA 00 00 00 + */ + +/* GSM SIM commands */ +#define SIM_CMD_SELECT 0xa0, 0xa4, 0x00, 0x00, 0x02 +#define SIM_CMD_RUN_GSM_ALG 0xa0, 0x88, 0x00, 0x00, 0x10 +#define SIM_CMD_GET_RESPONSE 0xa0, 0xc0, 0x00, 0x00 +#define SIM_CMD_READ_BIN 0xa0, 0xb0, 0x00, 0x00 +#define SIM_CMD_READ_RECORD 0xa0, 0xb2, 0x00, 0x00 +#define SIM_CMD_VERIFY_CHV1 0xa0, 0x20, 0x00, 0x01, 0x08 + +/* USIM commands */ +#define USIM_CLA 0x00 +#define USIM_CMD_RUN_UMTS_ALG 0x00, 0x88, 0x00, 0x81, 0x22 +#define USIM_CMD_GET_RESPONSE 0x00, 0xc0, 0x00, 0x00 + +#define SIM_RECORD_MODE_ABSOLUTE 0x04 + +#define USIM_FSP_TEMPL_TAG 0x62 + +#define USIM_TLV_FILE_DESC 0x82 +#define USIM_TLV_FILE_ID 0x83 +#define USIM_TLV_DF_NAME 0x84 +#define USIM_TLV_PROPR_INFO 0xA5 +#define USIM_TLV_LIFE_CYCLE_STATUS 0x8A +#define USIM_TLV_FILE_SIZE 0x80 +#define USIM_TLV_TOTAL_FILE_SIZE 0x81 +#define USIM_TLV_PIN_STATUS_TEMPLATE 0xC6 +#define USIM_TLV_SHORT_FILE_ID 0x88 +#define USIM_TLV_SECURITY_ATTR_8B 0x8B +#define USIM_TLV_SECURITY_ATTR_8C 0x8C +#define USIM_TLV_SECURITY_ATTR_AB 0xAB + +#define USIM_PS_DO_TAG 0x90 + +/* GSM files + * File type in first octet: + * 3F = Master File + * 7F = Dedicated File + * 2F = Elementary File under the Master File + * 6F = Elementary File under a Dedicated File + */ +#define SCARD_FILE_MF 0x3F00 +#define SCARD_FILE_GSM_DF 0x7F20 +#define SCARD_FILE_UMTS_DF 0x7F50 +#define SCARD_FILE_GSM_EF_IMSI 0x6F07 +#define SCARD_FILE_GSM_EF_AD 0x6FAD +#define SCARD_FILE_EF_DIR 0x2F00 +#define SCARD_FILE_EF_ICCID 0x2FE2 +#define SCARD_FILE_EF_CK 0x6FE1 +#define SCARD_FILE_EF_IK 0x6FE2 + +#define SCARD_CHV1_OFFSET 13 +#define SCARD_CHV1_FLAG 0x80 + + SCARDCONTEXT scard_context; + SCARDHANDLE scard_handle; long unsigned scard_protocol; - sim_types_t sim_type; - bool pin1_needed; - srslte::log *log; + sim_types_t sim_type; + bool pin1_needed; + srslte::log* log; }; - scard sc; + scard sc; }; } // namespace srsue diff --git a/srsue/hdr/stack/upper/tft_packet_filter.h b/srsue/hdr/stack/upper/tft_packet_filter.h index 92ba516fc..fbefc3ae9 100644 --- a/srsue/hdr/stack/upper/tft_packet_filter.h +++ b/srsue/hdr/stack/upper/tft_packet_filter.h @@ -70,7 +70,7 @@ public: uint8_t lcid_, const LIBLTE_MME_PACKET_FILTER_STRUCT& tft_, srslte::log* log_); - bool match(const srslte::unique_byte_buffer_t& pdu); + bool match(const srslte::unique_byte_buffer_t& pdu); uint8_t eps_bearer_id; uint8_t lcid; diff --git a/srsue/hdr/stack/upper/usim.h b/srsue/hdr/stack/upper/usim.h index 551ec617c..a6efa2493 100644 --- a/srsue/hdr/stack/upper/usim.h +++ b/srsue/hdr/stack/upper/usim.h @@ -22,17 +22,16 @@ #ifndef SRSUE_USIM_H #define SRSUE_USIM_H -#include -#include "usim_base.h" -#include "srslte/common/log.h" #include "srslte/common/common.h" -#include "srslte/interfaces/ue_interfaces.h" +#include "srslte/common/log.h" #include "srslte/common/security.h" +#include "srslte/interfaces/ue_interfaces.h" +#include "usim_base.h" +#include namespace srsue { -class usim - :public usim_base +class usim : public usim_base { public: usim(srslte::log* log_); @@ -47,57 +46,56 @@ public: bool get_imei_vec(uint8_t* imei_, uint32_t n); bool get_home_plmn_id(srslte::plmn_id_t* home_plmn_id); - auth_result_t generate_authentication_response(uint8_t *rand, - uint8_t *autn_enb, - uint16_t mcc, - uint16_t mnc, - uint8_t *res, - int *res_len, - uint8_t *k_asme); - - void generate_nas_keys(uint8_t *k_asme, - uint8_t *k_nas_enc, - uint8_t *k_nas_int, + auth_result_t generate_authentication_response(uint8_t* rand, + uint8_t* autn_enb, + uint16_t mcc, + uint16_t mnc, + uint8_t* res, + int* res_len, + uint8_t* k_asme); + + void generate_nas_keys(uint8_t* k_asme, + uint8_t* k_nas_enc, + uint8_t* k_nas_int, srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo); // RRC interface - void generate_as_keys(uint8_t *k_asme, - uint32_t count_ul, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int, - uint8_t *k_up_enc, - uint8_t *k_up_int, + void generate_as_keys(uint8_t* k_asme, + uint32_t count_ul, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int, + uint8_t* k_up_enc, + uint8_t* k_up_int, srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo); - void generate_as_keys_ho(uint32_t pci, - uint32_t earfcn, - int ncc, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int, - uint8_t *k_up_enc, - uint8_t *k_up_int, + void generate_as_keys_ho(uint32_t pci, + uint32_t earfcn, + int ncc, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int, + uint8_t* k_up_enc, + uint8_t* k_up_int, srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo); - private: - auth_result_t gen_auth_res_milenage(uint8_t *rand, - uint8_t *autn_enb, - uint16_t mcc, - uint16_t mnc, - uint8_t *res, - int *res_len, - uint8_t *k_asme); - auth_result_t gen_auth_res_xor(uint8_t *rand, - uint8_t *autn_enb, - uint16_t mcc, - uint16_t mnc, - uint8_t *res, - int *res_len, - uint8_t *k_asme); - void str_to_hex(std::string str, uint8_t *hex); + auth_result_t gen_auth_res_milenage(uint8_t* rand, + uint8_t* autn_enb, + uint16_t mcc, + uint16_t mnc, + uint8_t* res, + int* res_len, + uint8_t* k_asme); + auth_result_t gen_auth_res_xor(uint8_t* rand, + uint8_t* autn_enb, + uint16_t mcc, + uint16_t mnc, + uint8_t* res, + int* res_len, + uint8_t* k_asme); + void str_to_hex(std::string str, uint8_t* hex); srslte::log* usim_log = nullptr; @@ -134,5 +132,4 @@ private: } // namespace srsue - #endif // SRSUE_USIM_H diff --git a/srsue/hdr/stack/upper/usim_base.h b/srsue/hdr/stack/upper/usim_base.h index 85ff3b891..d66dc75ff 100644 --- a/srsue/hdr/stack/upper/usim_base.h +++ b/srsue/hdr/stack/upper/usim_base.h @@ -22,18 +22,18 @@ #ifndef SRSUE_USIM_BASE_H #define SRSUE_USIM_BASE_H -#include -#include "srslte/common/log.h" #include "srslte/common/common.h" -#include "srslte/interfaces/ue_interfaces.h" +#include "srslte/common/log.h" #include "srslte/common/security.h" +#include "srslte/interfaces/ue_interfaces.h" +#include namespace srsue { -typedef enum{ +typedef enum { auth_algo_milenage = 0, auth_algo_xor, -}auth_algo_t; +} auth_algo_t; class usim_args_t { @@ -41,7 +41,7 @@ public: usim_args_t() : using_op(false) {} std::string mode; std::string algo; - bool using_op; + bool using_op; std::string op; std::string opc; std::string imsi; @@ -51,9 +51,7 @@ public: std::string reader; }; -class usim_base - :public usim_interface_nas - ,public usim_interface_rrc +class usim_base : public usim_interface_nas, public usim_interface_rrc { public: usim_base(); @@ -61,49 +59,49 @@ public: static std::unique_ptr get_instance(usim_args_t* args, srslte::log* log_); virtual int init(usim_args_t* args) = 0; - virtual void stop() = 0; + virtual void stop() = 0; // NAS interface virtual std::string get_imsi_str() = 0; virtual std::string get_imei_str() = 0; - virtual bool get_imsi_vec(uint8_t* imsi_, uint32_t n) = 0; - virtual bool get_imei_vec(uint8_t* imei_, uint32_t n) = 0; + virtual bool get_imsi_vec(uint8_t* imsi_, uint32_t n) = 0; + virtual bool get_imei_vec(uint8_t* imei_, uint32_t n) = 0; virtual bool get_home_plmn_id(srslte::plmn_id_t* home_plmn_id) = 0; - virtual auth_result_t generate_authentication_response(uint8_t *rand, - uint8_t *autn_enb, - uint16_t mcc, - uint16_t mnc, - uint8_t *res, - int *res_len, - uint8_t *k_asme) = 0; + virtual auth_result_t generate_authentication_response(uint8_t* rand, + uint8_t* autn_enb, + uint16_t mcc, + uint16_t mnc, + uint8_t* res, + int* res_len, + uint8_t* k_asme) = 0; - virtual void generate_nas_keys(uint8_t *k_asme, - uint8_t *k_nas_enc, - uint8_t *k_nas_int, - srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, - srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo) = 0; + virtual void generate_nas_keys(uint8_t* k_asme, + uint8_t* k_nas_enc, + uint8_t* k_nas_int, + srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, + srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo) = 0; // RRC interface - virtual void generate_as_keys(uint8_t *k_asme, - uint32_t count_ul, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int, - uint8_t *k_up_enc, - uint8_t *k_up_int, - srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, - srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo) = 0; + virtual void generate_as_keys(uint8_t* k_asme, + uint32_t count_ul, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int, + uint8_t* k_up_enc, + uint8_t* k_up_int, + srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, + srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo) = 0; - virtual void generate_as_keys_ho(uint32_t pci, - uint32_t earfcn, - int ncc, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int, - uint8_t *k_up_enc, - uint8_t *k_up_int, - srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, - srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo) = 0; + virtual void generate_as_keys_ho(uint32_t pci, + uint32_t earfcn, + int ncc, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int, + uint8_t* k_up_enc, + uint8_t* k_up_int, + srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, + srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo) = 0; }; } // namespace srsue diff --git a/srsue/hdr/ue.h b/srsue/hdr/ue.h index e3469459c..7b44d3892 100644 --- a/srsue/hdr/ue.h +++ b/srsue/hdr/ue.h @@ -107,10 +107,10 @@ public: private: // UE consists of a radio, a PHY and a stack element - std::unique_ptr phy; + std::unique_ptr phy; std::unique_ptr radio; - std::unique_ptr stack; - std::unique_ptr gw_inst; + std::unique_ptr stack; + std::unique_ptr gw_inst; // Generic logger members srslte::logger* logger = nullptr; diff --git a/srsue/hdr/ue_metrics_interface.h b/srsue/hdr/ue_metrics_interface.h index 28292cc7c..be5dadc62 100644 --- a/srsue/hdr/ue_metrics_interface.h +++ b/srsue/hdr/ue_metrics_interface.h @@ -44,9 +44,9 @@ typedef struct { typedef struct { srslte::rf_metrics_t rf; - phy_metrics_t phy; - gw_metrics_t gw; - stack_metrics_t stack; + phy_metrics_t phy; + gw_metrics_t gw; + stack_metrics_t stack; } ue_metrics_t; // UE interface diff --git a/srsue/src/main.cc b/srsue/src/main.cc index 5e0e355d3..74cbfbc72 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -19,28 +19,28 @@ * */ -#include +#include +#include #include #include -#include -#include +#include -#include -#include -#include #include #include +#include +#include +#include -#include "srsue/hdr/ue.h" #include "srslte/common/config_file.h" #include "srslte/common/crash_handler.h" -#include "srslte/srslte.h" -#include "srsue/hdr/metrics_stdout.h" -#include "srsue/hdr/metrics_csv.h" #include "srslte/common/metrics_hub.h" +#include "srslte/srslte.h" #include "srslte/version.h" +#include "srsue/hdr/metrics_csv.h" +#include "srsue/hdr/metrics_stdout.h" +#include "srsue/hdr/ue.h" -extern bool simulate_rlf; +extern bool simulate_rlf; using namespace std; using namespace srsue; @@ -65,9 +65,7 @@ static int parse_args(all_args_t* args, int argc, char* argv[]) // Command line only options bpo::options_description general("General options"); - general.add_options() - ("help,h", "Produce help message") - ("version,v", "Print version information and exit"); + general.add_options()("help,h", "Produce help message")("version,v", "Print version information and exit"); // Command line or config file options bpo::options_description common("Configuration options"); @@ -366,11 +364,11 @@ static int parse_args(all_args_t* args, int argc, char* argv[]) // parse the command line and store result in vm bpo::variables_map vm; - try{ + try { bpo::store(bpo::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm); bpo::notify(vm); - } catch(bpo::error &e) { - cerr<< e.what() << endl; + } catch (bpo::error& e) { + cerr << e.what() << endl; running = false; return SRSLTE_ERROR; } @@ -384,10 +382,8 @@ static int parse_args(all_args_t* args, int argc, char* argv[]) // print version number and exit if (vm.count("version")) { - cout << "Version " << - srslte_get_version_major() << "." << - srslte_get_version_minor() << "." << - srslte_get_version_patch() << endl; + cout << "Version " << srslte_get_version_major() << "." << srslte_get_version_minor() << "." + << srslte_get_version_patch() << endl; running = false; return SRSLTE_SUCCESS; } diff --git a/srsue/src/metrics_csv.cc b/srsue/src/metrics_csv.cc index 8c9401cbd..a02542e39 100644 --- a/srsue/src/metrics_csv.cc +++ b/srsue/src/metrics_csv.cc @@ -21,24 +21,21 @@ #include "srsue/hdr/metrics_csv.h" -#include -#include -#include -#include #include #include #include +#include +#include +#include +#include #include using namespace std; -namespace srsue{ +namespace srsue { -metrics_csv::metrics_csv(std::string filename) - :n_reports(0) - ,metrics_report_period(1.0) - ,ue(NULL) +metrics_csv::metrics_csv(std::string filename) : n_reports(0), metrics_report_period(1.0), ue(NULL) { file.open(filename.c_str(), std::ios_base::out); pthread_mutex_init(&mutex, NULL); @@ -50,7 +47,7 @@ metrics_csv::~metrics_csv() pthread_mutex_destroy(&mutex); } -void metrics_csv::set_ue_handle(ue_metrics_interface *ue_) +void metrics_csv::set_ue_handle(ue_metrics_interface* ue_) { ue = ue_; } @@ -66,12 +63,13 @@ void metrics_csv::stop() pthread_mutex_unlock(&mutex); } -void metrics_csv::set_metrics(ue_metrics_t &metrics, const uint32_t period_usec) +void metrics_csv::set_metrics(ue_metrics_t& metrics, const uint32_t period_usec) { pthread_mutex_lock(&mutex); if (file.is_open() && ue != NULL) { - if(n_reports == 0) { - file << "time;rsrp;pl;cfo;dl_mcs;dl_snr;dl_turbo;dl_brate;dl_bler;ul_ta;ul_mcs;ul_buff;ul_brate;ul_bler;rf_o;rf_u;rf_l;is_attached\n"; + if (n_reports == 0) { + file << "time;rsrp;pl;cfo;dl_mcs;dl_snr;dl_turbo;dl_brate;dl_bler;ul_ta;ul_mcs;ul_buff;ul_brate;ul_bler;rf_o;rf_" + "u;rf_l;is_attached\n"; } file << (metrics_report_period * n_reports) << ";"; diff --git a/srsue/src/metrics_stdout.cc b/srsue/src/metrics_stdout.cc index 799567fe9..80b9250f8 100644 --- a/srsue/src/metrics_stdout.cc +++ b/srsue/src/metrics_stdout.cc @@ -21,24 +21,43 @@ #include "srsue/hdr/metrics_stdout.h" -#include -#include -#include -#include #include #include #include +#include +#include +#include +#include #include using namespace std; -namespace srsue{ - -char const * const prefixes[2][9] = -{ - { "", "m", "u", "n", "p", "f", "a", "z", "y", }, - { "", "k", "M", "G", "T", "P", "E", "Z", "Y", }, +namespace srsue { + +char const* const prefixes[2][9] = { + { + "", + "m", + "u", + "n", + "p", + "f", + "a", + "z", + "y", + }, + { + "", + "k", + "M", + "G", + "T", + "P", + "E", + "Z", + "Y", + }, }; metrics_stdout::metrics_stdout() : do_print(false), n_reports(10), ue(nullptr) @@ -46,7 +65,7 @@ metrics_stdout::metrics_stdout() : do_print(false), n_reports(10), ue(nullptr) // Do nothing } -void metrics_stdout::set_ue_handle(ue_metrics_interface *ue_) +void metrics_stdout::set_ue_handle(ue_metrics_interface* ue_) { ue = ue_; } @@ -56,7 +75,7 @@ void metrics_stdout::toggle_print(bool b) do_print = b; } -void metrics_stdout::set_metrics(ue_metrics_t &metrics, const uint32_t period_usec) +void metrics_stdout::set_metrics(ue_metrics_t& metrics, const uint32_t period_usec) { if (ue == nullptr) { return; @@ -76,8 +95,7 @@ void metrics_stdout::set_metrics(ue_metrics_t &metrics, const uint32_t period_us return; } - if(++n_reports > 10) - { + if (++n_reports > 10) { n_reports = 0; cout << endl; cout << "--------Signal--------------DL-------------------------------------UL----------------------" << endl; @@ -133,15 +151,15 @@ std::string metrics_stdout::float_to_eng_string(float f, int digits) std::string factor; if (abs(degree) < 9) { - if(degree < 0) - factor = prefixes[0][ abs( degree ) ]; + if (degree < 0) + factor = prefixes[0][abs(degree)]; else - factor = prefixes[1][ abs( degree ) ]; + factor = prefixes[1][abs(degree)]; } else { return "failed"; } - const double scaled = f * pow( 1000.0, -degree ); + const double scaled = f * pow(1000.0, -degree); if (degree != 0) { return float_to_string(scaled, digits) + factor; } else { diff --git a/srsue/src/phy/cc_worker.cc b/srsue/src/phy/cc_worker.cc index 114d67f87..3465ea039 100644 --- a/srsue/src/phy/cc_worker.cc +++ b/srsue/src/phy/cc_worker.cc @@ -20,6 +20,7 @@ */ #include "srslte/srslte.h" + #include "srsue/hdr/phy/cc_worker.h" #define Error(fmt, ...) \ @@ -304,7 +305,7 @@ bool cc_worker::work_dl_mbsfn(srslte_mbsfn_cfg_t mbsfn_cfg) // Set MBSFN channel estimation chest_mbsfn_cfg.mbsfn_area_id = mbsfn_cfg.mbsfn_area_id; - ue_dl_cfg.chest_cfg = chest_mbsfn_cfg; + ue_dl_cfg.chest_cfg = chest_mbsfn_cfg; /* Do FFT and extract PDCCH LLR, or quit if no actions are required in this subframe */ if (srslte_ue_dl_decode_fft_estimate(&ue_dl, &sf_cfg_dl, &ue_dl_cfg) < 0) { @@ -371,7 +372,7 @@ int cc_worker::decode_pdcch_dl() for (int i = 0; i < (ue_dl_cfg.cfg.dci.cif_present ? 2 : 1) && !nof_grants; i++) { Debug("PDCCH looking for rnti=0x%x\n", dl_rnti); ue_dl_cfg.cfg.dci.cif_enabled = i > 0; - nof_grants = srslte_ue_dl_find_dl_dci(&ue_dl, &sf_cfg_dl, &ue_dl_cfg, dl_rnti, dci); + nof_grants = srslte_ue_dl_find_dl_dci(&ue_dl, &sf_cfg_dl, &ue_dl_cfg, dl_rnti, dci); if (nof_grants < 0) { Error("Looking for DL grants\n"); return -1; @@ -404,7 +405,7 @@ int cc_worker::decode_pdsch(srslte_pdsch_ack_resource_t ack_resource, srslte_pdsch_res_t pdsch_dec[SRSLTE_MAX_CODEWORDS] = {}; // See if at least 1 codeword needs to be decoded. If not need to be decode, resend ACK - bool decode_enable = false; + bool decode_enable = false; bool tb_enable[SRSLTE_MAX_CODEWORDS] = {}; for (uint32_t tb = 0; tb < SRSLTE_MAX_CODEWORDS; tb++) { tb_enable[tb] = ue_dl_cfg.cfg.pdsch.grant.tb[tb].enabled; @@ -433,7 +434,7 @@ int cc_worker::decode_pdsch(srslte_pdsch_ack_resource_t ack_resource, // Generate ACKs for MAC and PUCCH uint32_t nof_tb = 0; - uint8_t pending_acks[SRSLTE_MAX_CODEWORDS] = {}; + uint8_t pending_acks[SRSLTE_MAX_CODEWORDS] = {}; for (uint32_t tb = 0; tb < SRSLTE_MAX_CODEWORDS; tb++) { // For MAC, set to true if it's a duplicate mac_acks[tb] = action->tb[tb].enabled ? pdsch_dec[tb].crc : true; @@ -493,7 +494,6 @@ int cc_worker::decode_pmch(mac_interface_phy_lte::tb_action_dl_t* action, srslte ue_dl.chest_res.snr_db, pmch_dec.avg_iterations_block); - if (pmch_dec.crc) { return 1; } @@ -618,10 +618,10 @@ bool cc_worker::work_ul(srslte_uci_data_t* uci_data) bool signal_ready; - srslte_dci_ul_t dci_ul = {}; + srslte_dci_ul_t dci_ul = {}; mac_interface_phy_lte::mac_grant_ul_t ul_mac_grant = {}; mac_interface_phy_lte::tb_action_ul_t ul_action = {}; - uint32_t pid = 0; + uint32_t pid = 0; bool ul_grant_available = phy->get_ul_pending_grant(&sf_cfg_ul, cc_idx, &pid, &dci_ul); ul_mac_grant.phich_available = @@ -736,7 +736,7 @@ int cc_worker::decode_pdcch_ul() /* Blind search first without cross scheduling then with it if enabled */ for (int i = 0; i < (ue_dl_cfg.cfg.dci.cif_present ? 2 : 1) && !nof_grants; i++) { ue_dl_cfg.cfg.dci.cif_enabled = i > 0; - nof_grants = srslte_ue_dl_find_ul_dci(&ue_dl, &sf_cfg_dl, &ue_dl_cfg, ul_rnti, dci); + nof_grants = srslte_ue_dl_find_ul_dci(&ue_dl, &sf_cfg_dl, &ue_dl_cfg, ul_rnti, dci); if (nof_grants < 0) { Error("Looking for UL grants\n"); return -1; @@ -909,7 +909,7 @@ void cc_worker::set_config(srslte::phy_cfg_t& phy_cfg) int cc_worker::read_ce_abs(float* ce_abs, uint32_t tx_antenna, uint32_t rx_antenna) { - int sz = srslte_symbol_sz(cell.nof_prb); + int sz = srslte_symbol_sz(cell.nof_prb); bzero(ce_abs, sizeof(float) * sz); int g = (sz - 12 * cell.nof_prb) / 2; srslte_vec_abs_dB_cf(ue_dl.chest_res.ce[tx_antenna][rx_antenna], -80, &ce_abs[g], SRSLTE_NRE * cell.nof_prb); diff --git a/srsue/src/phy/phy.cc b/srsue/src/phy/phy.cc index eef86868f..82ba3970a 100644 --- a/srsue/src/phy/phy.cc +++ b/srsue/src/phy/phy.cc @@ -19,36 +19,45 @@ * */ -#include +#include #include #include +#include #include -#include -#include #include +#include -#include "srslte/srslte.h" -#include "srslte/common/threads.h" #include "srslte/common/log.h" +#include "srslte/common/threads.h" +#include "srslte/srslte.h" #include "srsue/hdr/phy/phy.h" -#define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->debug(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->error(fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->warning(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->debug(fmt, ##__VA_ARGS__) using namespace std; using namespace asn1::rrc; namespace srsue { - -static void srslte_phy_handler(phy_logger_level_t log_level, void *ctx, char *str) { - phy *r = (phy *) ctx; +static void srslte_phy_handler(phy_logger_level_t log_level, void* ctx, char* str) +{ + phy* r = (phy*)ctx; r->srslte_phy_logger(log_level, str); } -void phy::srslte_phy_logger(phy_logger_level_t log_level, char *str) { +void phy::srslte_phy_logger(phy_logger_level_t log_level, char* str) +{ if (log_phy_lib_h) { switch (log_level) { case LOG_LEVEL_INFO_S: @@ -68,22 +77,22 @@ void phy::srslte_phy_logger(phy_logger_level_t log_level, char *str) { } } -void phy::set_default_args(phy_args_t *args) -{ - args->nof_rx_ant = 1; - args->ul_pwr_ctrl_en = false; - args->prach_gain = -1; - args->cqi_max = -1; - args->cqi_fixed = -1; - args->snr_ema_coeff = 0.1; - args->snr_estim_alg = "refs"; - args->pdsch_max_its = 4; - args->nof_phy_threads = DEFAULT_WORKERS; - args->equalizer_mode = "mmse"; - args->cfo_integer_enabled = false; - args->cfo_correct_tol_hz = 50; - args->sss_algorithm = "full"; - args->estimator_fil_auto = false; +void phy::set_default_args(phy_args_t* args) +{ + args->nof_rx_ant = 1; + args->ul_pwr_ctrl_en = false; + args->prach_gain = -1; + args->cqi_max = -1; + args->cqi_fixed = -1; + args->snr_ema_coeff = 0.1; + args->snr_estim_alg = "refs"; + args->pdsch_max_its = 4; + args->nof_phy_threads = DEFAULT_WORKERS; + args->equalizer_mode = "mmse"; + args->cfo_integer_enabled = false; + args->cfo_correct_tol_hz = 50; + args->sss_algorithm = "full"; + args->estimator_fil_auto = false; args->estimator_fil_stddev = 1.0f; args->estimator_fil_order = 4; } @@ -92,21 +101,19 @@ bool phy::check_args(const phy_args_t& args) { if (args.nof_phy_threads > MAX_WORKERS) { log_h->console("Error in PHY args: nof_phy_threads must be 1, 2 or 3\n"); - return false; + return false; } if (args.snr_ema_coeff > 1.0) { log_h->console("Error in PHY args: snr_ema_coeff must be 0<=w<=1\n"); - return false; + return false; } - return true; + return true; } -int phy::init(const phy_args_t& args_, - stack_interface_phy_lte* stack_, - srslte::radio_interface_phy* radio_) +int phy::init(const phy_args_t& args_, stack_interface_phy_lte* stack_, srslte::radio_interface_phy* radio_) { - stack = stack_; - radio = radio_; + stack = stack_; + radio = radio_; init(args_); @@ -128,8 +135,8 @@ int phy::init(const phy_args_t& args_) // Create array of pointers to phy_logs for (int i = 0; i < args.nof_phy_threads; i++) { - auto* mylog = new srslte::log_filter; - char tmp[16]; + auto* mylog = new srslte::log_filter; + char tmp[16]; sprintf(tmp, "PHY%d", i); mylog->init(tmp, logger, true); mylog->set_level(args.log.phy_level); @@ -139,8 +146,8 @@ int phy::init(const phy_args_t& args_) // Add PHY lib log if (log_vec.at(0)->get_level_from_string(args.log.phy_lib_level) != srslte::LOG_LEVEL_NONE) { - auto* lib_log = new srslte::log_filter; - char tmp[16]; + auto* lib_log = new srslte::log_filter; + char tmp[16]; sprintf(tmp, "PHY_LIB"); lib_log->init(tmp, logger, true); lib_log->set_level(args.log.phy_lib_level); @@ -177,7 +184,7 @@ void phy::run_thread() common.init(&args, (srslte::log*)log_vec[0].get(), radio, stack); // Add workers to workers pool and start threads - for (uint32_t i=0;i(new sf_worker( SRSLTE_MAX_PRB, &common, (srslte::log*)log_vec[i].get(), (srslte::log*)log_vec[nof_workers].get(), &sfsync)); workers_pool.init_worker(i, w.get(), WORKERS_THREAD_PRIO, args.worker_cpu_mask); @@ -203,13 +210,14 @@ void phy::run_thread() SF_RECV_THREAD_PRIO, args.sync_cpu_affinity); - // Disable UL signal pregeneration until the attachment + // Disable UL signal pregeneration until the attachment enable_pregen_signals(false); initiated = true; } -void phy::wait_initialize() { +void phy::wait_initialize() +{ wait_thread_finish(); } @@ -252,13 +260,15 @@ void phy::get_metrics(phy_metrics_t* m) m->nof_active_cc = args.nof_carriers; } -void phy::set_timeadv_rar(uint32_t ta_cmd) { +void phy::set_timeadv_rar(uint32_t ta_cmd) +{ n_ta = srslte_N_ta_new_rar(ta_cmd); sfsync.set_time_adv_sec(((float)n_ta) * SRSLTE_LTE_TS); - Info("PHY: Set TA RAR: ta_cmd: %d, n_ta: %d, ta_usec: %.1f\n", ta_cmd, n_ta, ((float) n_ta)*SRSLTE_LTE_TS*1e6); + Info("PHY: Set TA RAR: ta_cmd: %d, n_ta: %d, ta_usec: %.1f\n", ta_cmd, n_ta, ((float)n_ta) * SRSLTE_LTE_TS * 1e6); } -void phy::set_timeadv(uint32_t ta_cmd) { +void phy::set_timeadv(uint32_t ta_cmd) +{ uint32_t new_nta = srslte_N_ta_new(n_ta, ta_cmd); sfsync.set_time_adv_sec(((float)new_nta) * SRSLTE_LTE_TS); Info("PHY: Set TA: ta_cmd: %d, n_ta: %d, old_n_ta: %d, ta_usec: %.1f\n", @@ -297,19 +307,23 @@ void phy::configure_prach_params() } } -void phy::meas_reset() { +void phy::meas_reset() +{ sfsync.meas_reset(); } -int phy::meas_start(uint32_t earfcn, int pci) { +int phy::meas_start(uint32_t earfcn, int pci) +{ return sfsync.meas_start(earfcn, pci); } -int phy::meas_stop(uint32_t earfcn, int pci) { +int phy::meas_stop(uint32_t earfcn, int pci) +{ return sfsync.meas_stop(earfcn, pci); } -bool phy::cell_select(phy_cell_t *cell) { +bool phy::cell_select(phy_cell_t* cell) +{ return sfsync.cell_select(cell); } @@ -318,14 +332,15 @@ phy_interface_rrc_lte::cell_search_ret_t phy::cell_search(phy_cell_t* cell) return sfsync.cell_search(cell); } -bool phy::cell_is_camping() { +bool phy::cell_is_camping() +{ return sfsync.cell_is_camping(); } float phy::get_phr() { float phr = radio->get_max_tx_power() - common.cur_pusch_power; - return phr; + return phr; } float phy::get_pathloss_db() @@ -338,13 +353,15 @@ void phy::get_current_cell(srslte_cell_t* cell, uint32_t* current_earfcn) sfsync.get_current_cell(cell, current_earfcn); } -uint32_t phy::get_current_pci() { +uint32_t phy::get_current_pci() +{ srslte_cell_t cell; sfsync.get_current_cell(&cell); return cell.id; } -uint32_t phy::get_current_earfcn() { +uint32_t phy::get_current_earfcn() +{ uint32_t earfcn; sfsync.get_current_cell(nullptr, &earfcn); return earfcn; @@ -405,7 +422,7 @@ int phy::sr_last_tx_tti() return common.sr_last_tx_tti; } -void phy::set_earfcn(vector< uint32_t > earfcns) +void phy::set_earfcn(vector earfcns) { sfsync.set_earfcn(earfcns); } @@ -417,13 +434,14 @@ void phy::set_rar_grant(uint8_t grant_payload[SRSLTE_RAR_GRANT_LEN], uint16_t rn void phy::set_crnti(uint16_t rnti) { - for(uint32_t i=0;iset_crnti(rnti); - } + } } // Start GUI -void phy::start_plot() { +void phy::start_plot() +{ workers[0]->start_plot(); } @@ -443,7 +461,7 @@ void phy::set_config(srslte::phy_cfg_t& config_, uint32_t cc_idx, uint32_t earfc // Component carrier index zero should be reserved for PCell if (cc_idx < args.nof_carriers) { - carrier_map_t* m = &args.carrier_map[cc_idx]; + carrier_map_t* m = &args.carrier_map[cc_idx]; // Send configuration to workers for (uint32_t i = 0; i < nof_workers; i++) { @@ -535,4 +553,4 @@ void phy::set_mch_period_stop(uint32_t stop) common.set_mch_period_stop(stop); } -} +} // namespace srsue diff --git a/srsue/src/phy/phy_common.cc b/srsue/src/phy/phy_common.cc index 095e4ccbd..a46499241 100644 --- a/srsue/src/phy/phy_common.cc +++ b/srsue/src/phy/phy_common.cc @@ -134,7 +134,7 @@ void phy_common::set_ue_ul_cfg(srslte_ue_ul_cfg_t* ue_ul_cfg) { // Setup uplink configuration bzero(ue_ul_cfg, sizeof(srslte_ue_ul_cfg_t)); - ue_ul_cfg->cfo_en = true; + ue_ul_cfg->cfo_en = true; if (args->force_ul_amplitude > 0.0f) { ue_ul_cfg->force_peak_amplitude = args->force_ul_amplitude; ue_ul_cfg->normalize_mode = SRSLTE_UE_UL_NORMALIZE_MODE_FORCE_AMPLITUDE; @@ -303,7 +303,7 @@ bool phy_common::get_ul_pending_ack(srslte_dl_sf_cfg_t* sf, srslte_dci_ul_t* dci_ul) { std::lock_guard lock(pending_ul_ack_mutex); - bool ret = false; + bool ret = false; if (pending_ul_ack[TTIMOD(sf->tti)][cc_idx][phich_grant->I_phich].enable) { *phich_grant = pending_ul_ack[TTIMOD(sf->tti)][cc_idx][phich_grant->I_phich].phich_grant; *dci_ul = pending_ul_ack[TTIMOD(sf->tti)][cc_idx][phich_grant->I_phich].dci_ul; @@ -317,7 +317,7 @@ bool phy_common::get_ul_pending_ack(srslte_dl_sf_cfg_t* sf, bool phy_common::is_any_ul_pending_ack() { std::lock_guard lock(pending_ul_ack_mutex); - bool ret = false; + bool ret = false; for (int i = 0; i < TTIMOD_SZ && !ret; i++) { for (int n = 0; n < SRSLTE_MAX_CARRIERS && !ret; n++) { for (int j = 0; j < 2 && !ret; j++) { @@ -362,7 +362,7 @@ void phy_common::set_ul_pending_grant(srslte_dl_sf_cfg_t* sf, uint32_t cc_idx, s bool phy_common::get_ul_pending_grant(srslte_ul_sf_cfg_t* sf, uint32_t cc_idx, uint32_t* pid, srslte_dci_ul_t* dci) { std::lock_guard lock(pending_ul_grant_mutex); - bool ret = false; + bool ret = false; if (pending_ul_grant[TTIMOD(sf->tti)][cc_idx].enable) { Debug("Reading grant sf->tti=%d idx=%d\n", sf->tti, TTIMOD(sf->tti)); if (pid) { @@ -379,8 +379,11 @@ bool phy_common::get_ul_pending_grant(srslte_ul_sf_cfg_t* sf, uint32_t cc_idx, u } // SF->TTI at which PHICH is received -void phy_common::set_ul_received_ack( - srslte_dl_sf_cfg_t* sf, uint32_t cc_idx, bool ack_value, uint32_t I_phich, srslte_dci_ul_t* dci_ul) +void phy_common::set_ul_received_ack(srslte_dl_sf_cfg_t* sf, + uint32_t cc_idx, + bool ack_value, + uint32_t I_phich, + srslte_dci_ul_t* dci_ul) { std::lock_guard lock(received_ul_ack_mutex); received_ul_ack[TTIMOD(tti_pusch_hi(sf))][cc_idx].hi_present = true; @@ -393,7 +396,7 @@ void phy_common::set_ul_received_ack( bool phy_common::get_ul_received_ack(srslte_ul_sf_cfg_t* sf, uint32_t cc_idx, bool* ack_value, srslte_dci_ul_t* dci_ul) { std::lock_guard lock(received_ul_ack_mutex); - bool ret = false; + bool ret = false; if (received_ul_ack[TTIMOD(sf->tti)][cc_idx].hi_present) { if (ack_value) { *ack_value = received_ul_ack[TTIMOD(sf->tti)][cc_idx].hi_value; @@ -490,8 +493,8 @@ das_index_t das_table[7][10] = { bool phy_common::get_dl_pending_ack(srslte_ul_sf_cfg_t* sf, uint32_t cc_idx, srslte_pdsch_ack_cc_t* ack) { std::lock_guard lock(pending_dl_ack_mutex); - bool ret = false; - uint32_t M; + bool ret = false; + uint32_t M; if (cell.frame_type == SRSLTE_FDD) { M = 1; } else { @@ -646,7 +649,7 @@ void phy_common::set_sync_metrics(const uint32_t& cc_idx, const sync_metrics_t& { if (sync_metrics_read) { sync_metrics[cc_idx] = m; - sync_metrics_count = 1; + sync_metrics_count = 1; if (cc_idx == 0) sync_metrics_read = false; } else { @@ -794,8 +797,8 @@ bool phy_common::is_mch_subframe(srslte_mbsfn_cfg_t* cfg, uint32_t phy_tti) srslte::mcch_msg_t& mcch = mbsfn_config.mcch; uint32_t mbsfn_per_frame = mcch.pmch_info_list[0].sf_alloc_end / enum_to_number(mcch.pmch_info_list[0].mch_sched_period); - uint32_t frame_alloc_idx = sfn % enum_to_number(mcch.common_sf_alloc_period); - uint32_t sf_alloc_idx = frame_alloc_idx * mbsfn_per_frame + ((sf < 4) ? sf - 1 : sf - 3); + uint32_t frame_alloc_idx = sfn % enum_to_number(mcch.common_sf_alloc_period); + uint32_t sf_alloc_idx = frame_alloc_idx * mbsfn_per_frame + ((sf < 4) ? sf - 1 : sf - 3); std::unique_lock lock(mtch_mutex); while (!have_mtch_stop) { mtch_cvar.wait(lock); diff --git a/srsue/src/phy/prach.cc b/srsue/src/phy/prach.cc index 0fa4c84d0..1c4ca653c 100644 --- a/srsue/src/phy/prach.cc +++ b/srsue/src/phy/prach.cc @@ -19,33 +19,41 @@ * */ +#include #include #include -#include -#include "srslte/srslte.h" #include "srslte/common/log.h" -#include "srsue/hdr/phy/prach.h" -#include "srsue/hdr/phy/phy.h" #include "srslte/interfaces/ue_interfaces.h" +#include "srslte/srslte.h" +#include "srsue/hdr/phy/phy.h" +#include "srsue/hdr/phy/prach.h" -#define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->debug(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->error(fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->warning(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->debug(fmt, ##__VA_ARGS__) namespace srsue { - -prach::~prach() { +prach::~prach() +{ stop(); } void prach::init(uint32_t max_prb, srslte::log* log_h_) { - log_h = log_h_; + log_h = log_h_; - for (int i=0;i<64;i++) { + for (int i = 0; i < 64; i++) { for (int f = 0; f < 12; f++) { buffer[f][i] = (cf_t*)srslte_vec_malloc(SRSLTE_PRACH_MAX_LEN * sizeof(cf_t)); if (!buffer[f][i]) { @@ -59,7 +67,7 @@ void prach::init(uint32_t max_prb, srslte::log* log_h_) return; } srslte_cfo_set_tol(&cfo_h, 0); - signal_buffer = (cf_t *) srslte_vec_malloc(MAX_LEN_SF * 30720 * sizeof(cf_t)); + signal_buffer = (cf_t*)srslte_vec_malloc(MAX_LEN_SF * 30720 * sizeof(cf_t)); if (!signal_buffer) { perror("malloc"); return; @@ -144,9 +152,9 @@ bool prach::set_cell(srslte_cell_t cell, srslte_prach_cfg_t prach_cfg) } } - len = prach_obj.N_seq + prach_obj.N_cp; + len = prach_obj.N_seq + prach_obj.N_cp; transmitted_tti = -1; - cell_initiated = true; + cell_initiated = true; } return true; } else { @@ -158,27 +166,29 @@ bool prach::set_cell(srslte_cell_t cell, srslte_prach_cfg_t prach_cfg) bool prach::prepare_to_send(uint32_t preamble_idx_, int allowed_subframe_, float target_power_dbm_) { if (cell_initiated && preamble_idx_ < 64) { - preamble_idx = preamble_idx_; + preamble_idx = preamble_idx_; target_power_dbm = target_power_dbm_; - allowed_subframe = allowed_subframe_; - transmitted_tti = -1; + allowed_subframe = allowed_subframe_; + transmitted_tti = -1; Debug("PRACH: prepare to send preamble %d\n", preamble_idx); - return true; + return true; } else { if (!cell_initiated) { Error("PRACH: Cell not configured\n"); } else { Error("PRACH: Invalid preamble %d\n", preamble_idx_); } - return false; + return false; } } -bool prach::is_pending() { +bool prach::is_pending() +{ return cell_initiated && preamble_idx >= 0 && preamble_idx < 64; } -bool prach::is_ready_to_send(uint32_t current_tti_) { +bool prach::is_ready_to_send(uint32_t current_tti_) +{ if (is_pending()) { // consider the number of subframes the transmission must be anticipated uint32_t tti_tx = TTI_TX(current_tti_); @@ -234,8 +244,8 @@ cf_t* prach::generate(float cfo, uint32_t* nof_sf, float* target_power) srslte_cfo_correct(&cfo_h, buffer[f_idx][preamble_idx], signal_buffer, cfo / srslte_symbol_sz(cell.nof_prb)); // pad guard symbols with zeros - uint32_t nsf = (len-1)/SRSLTE_SF_LEN_PRB(cell.nof_prb)+1; - bzero(&signal_buffer[len], (nsf*SRSLTE_SF_LEN_PRB(cell.nof_prb)-len)*sizeof(cf_t)); + uint32_t nsf = (len - 1) / SRSLTE_SF_LEN_PRB(cell.nof_prb) + 1; + bzero(&signal_buffer[len], (nsf * SRSLTE_SF_LEN_PRB(cell.nof_prb) - len) * sizeof(cf_t)); *nof_sf = nsf; @@ -254,10 +264,12 @@ cf_t* prach::generate(float cfo, uint32_t* nof_sf, float* target_power) return signal_buffer; } else { Error("PRACH: Invalid parameters: cell_initiated=%d, preamble_idx=%d, cell.nof_prb=%d, len=%d\n", - cell_initiated, preamble_idx, cell.nof_prb, len); + cell_initiated, + preamble_idx, + cell.nof_prb, + len); return NULL; } } - -} // namespace srsue +} // namespace srsue diff --git a/srsue/src/phy/scell/intra_measure.cc b/srsue/src/phy/scell/intra_measure.cc index b62f7f031..407bc27f2 100644 --- a/srsue/src/phy/scell/intra_measure.cc +++ b/srsue/src/phy/scell/intra_measure.cc @@ -36,9 +36,7 @@ namespace srsue { namespace scell { -intra_measure::intra_measure() : scell(), thread("SYNC_INTRA_MEASURE") -{ -} +intra_measure::intra_measure() : scell(), thread("SYNC_INTRA_MEASURE") {} intra_measure::~intra_measure() { diff --git a/srsue/src/phy/scell/scell_recv.cc b/srsue/src/phy/scell/scell_recv.cc index c5c8a5169..bcedc6a4d 100644 --- a/srsue/src/phy/scell/scell_recv.cc +++ b/srsue/src/phy/scell/scell_recv.cc @@ -95,8 +95,11 @@ void scell_recv::reset() measure_p.reset(); } -int scell_recv::find_cells( - cf_t* input_buffer, float rx_gain_offset, srslte_cell_t cell, uint32_t nof_sf, cell_info_t cells[MAX_CELLS]) +int scell_recv::find_cells(cf_t* input_buffer, + float rx_gain_offset, + srslte_cell_t cell, + uint32_t nof_sf, + cell_info_t cells[MAX_CELLS]) { uint32_t fft_sz = srslte_symbol_sz(cell.nof_prb); uint32_t sf_len = SRSLTE_SF_LEN(fft_sz); diff --git a/srsue/src/phy/sf_worker.cc b/srsue/src/phy/sf_worker.cc index 87cd3d8a2..cdbf6fc56 100644 --- a/srsue/src/phy/sf_worker.cc +++ b/srsue/src/phy/sf_worker.cc @@ -19,9 +19,10 @@ * */ +#include "srslte/interfaces/ue_interfaces.h" #include "srslte/srslte.h" + #include "srsue/hdr/phy/sf_worker.h" -#include "srslte/interfaces/ue_interfaces.h" #include #include @@ -60,10 +61,10 @@ sf_worker::sf_worker(uint32_t max_prb, srslte::log* log_phy_lib_h_, chest_feedback_itf* chest_loop_) { - phy = phy_; - log_h = log_h_; - log_phy_lib_h = log_phy_lib_h_; - chest_loop = chest_loop_; + phy = phy_; + log_h = log_h_; + log_phy_lib_h = log_phy_lib_h_; + chest_loop = chest_loop_; // ue_sync in phy.cc requires a buffer for 3 subframes for (uint32_t r = 0; r < phy->args->nof_carriers; r++) { @@ -89,7 +90,7 @@ void sf_worker::reset() bool sf_worker::set_cell(uint32_t cc_idx, srslte_cell_t cell_) { - bool ret = false; + bool ret = false; std::lock_guard lock(mutex); if (cc_idx < cc_workers.size()) { @@ -258,7 +259,6 @@ void sf_worker::work_imp() } } - // Call worker_end to transmit the signal phy->worker_end(tx_sem_id, tx_signal_ready, tx_signal_ptr, nof_samples, tx_time); @@ -425,8 +425,8 @@ static float sync_buffer[SYNC_PLOT_LEN]; void* plot_thread_run(void* arg) { - auto worker = (srsue::sf_worker*)arg; - uint32_t row_count = 0; + auto worker = (srsue::sf_worker*)arg; + uint32_t row_count = 0; sdrgui_init(); for (uint32_t tx = 0; tx < worker->get_cell_nof_ports(); tx++) { @@ -510,7 +510,7 @@ void init_plots(srsue::sf_worker* worker) pthread_attr_t attr; struct sched_param param = {}; - param.sched_priority = 0; + param.sched_priority = 0; pthread_attr_init(&attr); pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); pthread_attr_setschedpolicy(&attr, SCHED_OTHER); diff --git a/srsue/src/phy/sync.cc b/srsue/src/phy/sync.cc index 03b685d3b..aa540455d 100644 --- a/srsue/src/phy/sync.cc +++ b/srsue/src/phy/sync.cc @@ -27,10 +27,18 @@ #include #include -#define Error(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->error(fmt, ##__VA_ARGS__) -#define Warning(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->debug(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->error(fmt, ##__VA_ARGS__) +#define Warning(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->warning(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) \ + if (SRSLTE_DEBUG_ENABLED) \ + log_h->debug(fmt, ##__VA_ARGS__) namespace srsue { @@ -55,14 +63,14 @@ void sync::init(srslte::radio_interface_phy* _radio, uint32_t prio, int sync_cpu_affinity) { - radio_h = _radio; - log_h = _log_h; + radio_h = _radio; + log_h = _log_h; log_phy_lib_h = _log_phy_lib_h; - stack = _stack; - scell_sync = scell_sync_; - workers_pool = _workers_pool; - worker_com = _worker_com; - prach_buffer = _prach_buffer; + stack = _stack; + scell_sync = scell_sync_; + workers_pool = _workers_pool; + worker_com = _worker_com; + prach_buffer = _prach_buffer; uint32_t nof_rf_channels = worker_com->args->nof_rf_channels * worker_com->args->nof_rx_ant; for (uint32_t r = 0; r < worker_com->args->nof_radios; r++) { @@ -134,27 +142,20 @@ void sync::stop() void sync::reset() { - radio_is_overflow = false; + radio_is_overflow = false; radio_overflow_return = false; - in_sync_cnt = 0; - out_of_sync_cnt = 0; - tx_worker_cnt = 0; - time_adv_sec = 0; - next_offset = 0; + in_sync_cnt = 0; + out_of_sync_cnt = 0; + tx_worker_cnt = 0; + time_adv_sec = 0; + next_offset = 0; ZERO_OBJECT(next_radio_offset); - srate_mode = SRATE_NONE; + srate_mode = SRATE_NONE; current_earfcn = -1; sfn_p.reset(); search_p.reset(); - } - - - - - - /** * Higher layers API. * @@ -168,7 +169,8 @@ void sync::reset() * * Cell Search: * It's the process of searching for cells in the bands or set of EARFCNs supported by the UE. Cell search is performed - * at 1.92 MHz sampling rate and involves PSS/SSS synchronization (PCI extraction) and MIB decoding for number of Ports and PRB. + * at 1.92 MHz sampling rate and involves PSS/SSS synchronization (PCI extraction) and MIB decoding for number of Ports + * and PRB. * * * Cell Select: @@ -177,15 +179,15 @@ void sync::reset() * * If it is a new cell, the reconfiguration must take place while sync_state is on IDLE. * - * cell_search() and cell_select() functions can not be called concurrently. A mutex is used to prevent it from happening. + * cell_search() and cell_select() functions can not be called concurrently. A mutex is used to prevent it from + * happening. * */ - /* A call to cell_search() finds the strongest cell in the set of supported EARFCNs. When the first cell is found, - * returns 1 and stores cell information and RSRP values in the pointers (if provided). If a cell is not found in the current - * frequency it moves to the next one and the next call to cell_search() will look in the next EARFCN in the set. - * If no cells are found in any frequency it returns 0. If error returns -1. + * returns 1 and stores cell information and RSRP values in the pointers (if provided). If a cell is not found in the + * current frequency it moves to the next one and the next call to cell_search() will look in the next EARFCN in the + * set. If no cells are found in any frequency it returns 0. If error returns -1. */ phy_interface_rrc_lte::cell_search_ret_t sync::cell_search(phy_interface_rrc_lte::phy_cell_t* found_cell) @@ -218,7 +220,7 @@ phy_interface_rrc_lte::cell_search_ret_t sync::cell_search(phy_interface_rrc_lte phy_state.run_cell_search(); // Check return state - switch(cell_search_ret) { + switch (cell_search_ret) { case search::CELL_FOUND: // If a cell is found, configure it, synchronize and measure it if (set_cell()) { @@ -274,7 +276,7 @@ bool sync::cell_select(phy_interface_rrc_lte::phy_cell_t* new_cell) std::unique_lock ul(rrc_mutex); bool ret = false; - int cnt = 0; + int cnt = 0; // Move state to IDLE if (!new_cell) { @@ -317,7 +319,7 @@ bool sync::cell_select(phy_interface_rrc_lte::phy_cell_t* new_cell) } /* Select new frequency if necessary */ - if ((int) new_cell->earfcn != current_earfcn) { + if ((int)new_cell->earfcn != current_earfcn) { current_earfcn = new_cell->earfcn; Info("Cell Select: Setting new frequency EARFCN=%d\n", new_cell->earfcn); if (!set_frequency()) { @@ -376,10 +378,10 @@ void sync::run_thread() sf_worker* last_worker = NULL; cf_t* buffer[SRSLTE_MAX_RADIOS][SRSLTE_MAX_PORTS] = {NULL}; - bool is_end_of_burst = false; + bool is_end_of_burst = false; bool force_camping_sfn_sync = false; - cf_t *dummy_buffer[SRSLTE_MAX_PORTS]; + cf_t* dummy_buffer[SRSLTE_MAX_PORTS]; uint32_t nof_rf_channels = worker_com->args->nof_rf_channels * worker_com->args->nof_rx_ant; for (uint32_t i = 0; i < nof_rf_channels; i++) { dummy_buffer[i] = (cf_t*)malloc(sizeof(cf_t) * SRSLTE_SF_LEN_PRB(100)); @@ -387,11 +389,10 @@ void sync::run_thread() uint32_t prach_nof_sf = 0; uint32_t prach_sf_cnt = 0; - cf_t *prach_ptr = NULL; + cf_t* prach_ptr = NULL; float prach_power = 0; - while (running) - { + while (running) { Debug("SYNC: state=%s, tti=%d\n", phy_state.to_string(), tti); // If not camping, clear SFN sync @@ -415,7 +416,7 @@ void sync::run_thread() phy_state.state_exit(); break; case sync_state::SFN_SYNC: - + /* SFN synchronization using MIB. run_subframe() receives and processes 1 subframe * and returns */ @@ -459,7 +460,7 @@ void sync::run_thread() // Force decode MIB if required if (force_camping_sfn_sync) { - uint32_t _tti = 0; + uint32_t _tti = 0; srslte_cell_t temp_cell = {}; sync::sfn_sync::ret_code ret = sfn_p.decode_mib(&temp_cell, &_tti, buffer[0], mib); @@ -491,8 +492,8 @@ void sync::run_thread() worker->set_tx_time(i + 1, tx_time, next_radio_offset[i + 1] + next_offset); } - metrics.sfo = srslte_ue_sync_get_sfo(&ue_sync); - metrics.cfo = srslte_ue_sync_get_cfo(&ue_sync); + metrics.sfo = srslte_ue_sync_get_sfo(&ue_sync); + metrics.cfo = srslte_ue_sync_get_cfo(&ue_sync); metrics.ta_us = time_adv_sec * 1e6f; for (uint32_t i = 0; i < worker_com->args->nof_carriers; i++) { if (worker_com->args->carrier_map[i].radio_idx == 0) { @@ -514,7 +515,8 @@ void sync::run_thread() srslte_timestamp_copy(&tx_time, &rx_time); srslte_timestamp_add(&tx_time, 0, TX_DELAY * 1e-3 - time_adv_sec); - worker->set_prach(prach_ptr?&prach_ptr[prach_sf_cnt*SRSLTE_SF_LEN_PRB(cell.nof_prb)]:NULL, prach_power); + worker->set_prach(prach_ptr ? &prach_ptr[prach_sf_cnt * SRSLTE_SF_LEN_PRB(cell.nof_prb)] : NULL, + prach_power); // Set CFO for all Carriers for (uint32_t cc = 0; cc < worker_com->args->nof_carriers; cc++) { @@ -536,14 +538,14 @@ void sync::run_thread() worker->set_tti(tti, tx_worker_cnt); worker->set_tx_time(0, tx_time, next_radio_offset[0] + next_offset); - next_offset = 0; + next_offset = 0; ZERO_OBJECT(next_radio_offset); // Process time aligment command if (next_time_adv_sec != time_adv_sec) { time_adv_sec = next_time_adv_sec; } - tx_worker_cnt = (tx_worker_cnt+1) % nof_workers; + tx_worker_cnt = (tx_worker_cnt + 1) % nof_workers; // Advance/reset prach subframe pointer if (prach_ptr) { @@ -556,12 +558,11 @@ void sync::run_thread() is_end_of_burst = true; - // Start worker workers_pool->start_worker(worker); // Save signal for Intra-frequency measurement - if ((tti%5) == 0 && worker_com->args->sic_pss_enabled) { + if ((tti % 5) == 0 && worker_com->args->sic_pss_enabled) { srslte_pss_sic(&ue_sync.strack.pss, &buffer[0][0][SRSLTE_SF_LEN_PRB(cell.nof_prb) / 2 - ue_sync.strack.fft_size]); } @@ -594,7 +595,7 @@ void sync::run_thread() if (radio_h->is_init()) { uint32_t nsamples = 1920; if (current_srate > 0) { - nsamples = current_srate/1000; + nsamples = current_srate / 1000; } Debug("Discarting %d samples\n", nsamples); srslte_timestamp_t rx_time = {}; @@ -650,7 +651,7 @@ void sync::run_thread() } // Increase TTI counter - tti = (tti+1) % 10240; + tti = (tti + 1) % 10240; } for (uint32_t p = 0; p < nof_rf_channels; p++) { @@ -660,21 +661,10 @@ void sync::run_thread() } } - - - - - - - - - - - /*************** - * + * * Utility functions called by the main thread or by functions called by other threads - * + * */ void sync::radio_overflow() { @@ -694,7 +684,7 @@ void sync::in_sync() // Send RRC in-sync signal after 100 ms consecutive subframes if (in_sync_cnt == NOF_IN_SYNC_SF) { stack->in_sync(); - in_sync_cnt = 0; + in_sync_cnt = 0; out_of_sync_cnt = 0; } } @@ -709,7 +699,7 @@ void sync::out_of_sync() Info("Sending to RRC\n"); stack->out_of_sync(); out_of_sync_cnt = 0; - in_sync_cnt = 0; + in_sync_cnt = 0; } } @@ -739,26 +729,26 @@ void sync::set_time_adv_sec(float time_adv_sec) // If transmitting earlier, transmit less samples to align time advance. If transmit later just delay next TX next_offset = (int)round((this->time_adv_sec - time_adv_sec) * srslte_sampling_freq_hz(cell.nof_prb)); this->next_time_adv_sec = time_adv_sec; - Info("Applying time_adv_sec=%.1f us, next_offset=%d\n", time_adv_sec*1e6, next_offset); + Info("Applying time_adv_sec=%.1f us, next_offset=%d\n", time_adv_sec * 1e6, next_offset); } float sync::get_tx_cfo() { float cfo = srslte_ue_sync_get_cfo(&ue_sync); - float ret = cfo*ul_dl_factor; + float ret = cfo * ul_dl_factor; if (worker_com->args->cfo_is_doppler) { ret *= -1; } else { /* Compensates the radio frequency offset applied equally to DL and UL. Does not work in doppler mode */ if (radio_h->get_freq_offset() != 0.0f) { - const float offset_hz = (float) radio_h->get_freq_offset() * (1.0f - ul_dl_factor); - ret = cfo - offset_hz; + const float offset_hz = (float)radio_h->get_freq_offset() * (1.0f - ul_dl_factor); + ret = cfo - offset_hz; } } - return ret/15000; + return ret / 15000; } void sync::set_ue_sync_opts(srslte_ue_sync_t* q, float cfo) @@ -769,7 +759,9 @@ void sync::set_ue_sync_opts(srslte_ue_sync_t* q, float cfo) srslte_ue_sync_set_cfo_ema(q, worker_com->args->cfo_pss_ema); srslte_ue_sync_set_cfo_tol(q, worker_com->args->cfo_correct_tol_hz); - srslte_ue_sync_set_cfo_loop_bw(q, worker_com->args->cfo_loop_bw_pss, worker_com->args->cfo_loop_bw_ref, + srslte_ue_sync_set_cfo_loop_bw(q, + worker_com->args->cfo_loop_bw_pss, + worker_com->args->cfo_loop_bw_ref, worker_com->args->cfo_loop_pss_tol, worker_com->args->cfo_loop_ref_min, worker_com->args->cfo_loop_pss_tol, @@ -779,8 +771,8 @@ void sync::set_ue_sync_opts(srslte_ue_sync_t* q, float cfo) // Disable CP based CFO estimation during find if (cfo != 0) { - q->cfo_current_value = cfo/15000; - q->cfo_is_copied = true; + q->cfo_current_value = cfo / 15000; + q->cfo_is_copied = true; q->cfo_correct_enable_find = true; srslte_sync_set_cfo_cp_enable(&q->sfind, false, 0); } @@ -799,8 +791,8 @@ void sync::set_ue_sync_opts(srslte_ue_sync_t* q, float cfo) } else { Warning("SYNC: Invalid SSS algorithm %s. Using 'full'\n", worker_com->args->sss_algorithm.c_str()); } - srslte_sync_set_sss_algorithm(&q->strack, (sss_alg_t) sss_alg); - srslte_sync_set_sss_algorithm(&q->sfind, (sss_alg_t) sss_alg); + srslte_sync_set_sss_algorithm(&q->strack, (sss_alg_t)sss_alg); + srslte_sync_set_sss_algorithm(&q->sfind, (sss_alg_t)sss_alg); } bool sync::set_cell() @@ -855,7 +847,7 @@ bool sync::set_frequency() set_dl_freq = this->dl_freq; set_ul_freq = this->ul_freq; } else { - set_dl_freq = 1e6*srslte_band_fd(current_earfcn); + set_dl_freq = 1e6 * srslte_band_fd(current_earfcn); if (srslte_band_is_tdd(srslte_band_get_band(current_earfcn))) { set_ul_freq = set_dl_freq; } else { @@ -864,10 +856,14 @@ bool sync::set_frequency() } if (set_dl_freq > 0 && set_ul_freq > 0) { log_h->info("SYNC: Set DL EARFCN=%d, f_dl=%.1f MHz, f_ul=%.1f MHz\n", - current_earfcn, set_dl_freq / 1e6, set_ul_freq / 1e6); + current_earfcn, + set_dl_freq / 1e6, + set_ul_freq / 1e6); log_h->console("Searching cell in DL EARFCN=%d, f_dl=%.1f MHz, f_ul=%.1f MHz\n", - current_earfcn, set_dl_freq / 1e6, set_ul_freq / 1e6); + current_earfcn, + set_dl_freq / 1e6, + set_ul_freq / 1e6); carrier_map_t* m = &worker_com->args->carrier_map[0]; for (uint32_t i = 0; i < worker_com->args->nof_rx_ant; i++) { @@ -894,10 +890,10 @@ void sync::set_sampling_rate() return; } - current_sflen = (uint32_t)SRSLTE_SF_LEN_PRB(cell.nof_prb); + current_sflen = (uint32_t)SRSLTE_SF_LEN_PRB(cell.nof_prb); if (current_srate != new_srate || srate_mode != SRATE_CAMP) { current_srate = new_srate; - Info("SYNC: Setting sampling rate %.2f MHz\n", current_srate/1000000); + Info("SYNC: Setting sampling rate %.2f MHz\n", current_srate / 1000000); srate_mode = SRATE_CAMP; radio_h->set_rx_srate(0, current_srate); @@ -973,12 +969,6 @@ double sync::set_rx_gain(double gain) return radio_h->set_rx_gain_th(gain); } - - - - - - /********* * Cell search class */ @@ -993,7 +983,7 @@ void sync::search::init(cf_t* buffer[SRSLTE_MAX_PORTS], srslte::log* log_h, uint this->log_h = log_h; this->p = parent; - for (int i=0;ibuffer[i] = buffer[i]; } @@ -1056,13 +1046,13 @@ sync::search::ret_code sync::search::run(srslte_cell_t* cell, std::arrayconsole("."); if (force_N_id_2 >= 0 && force_N_id_2 < 3) { - ret = srslte_ue_cellsearch_scan_N_id_2(&cs, force_N_id_2, &found_cells[force_N_id_2]); + ret = srslte_ue_cellsearch_scan_N_id_2(&cs, force_N_id_2, &found_cells[force_N_id_2]); max_peak_cell = force_N_id_2; } else { ret = srslte_ue_cellsearch_scan(&cs, found_cells, &max_peak_cell); @@ -1079,7 +1069,7 @@ sync::search::ret_code sync::search::run(srslte_cell_t* cell, std::arrayid = found_cells[max_peak_cell].cell_id; cell->cp = found_cells[max_peak_cell].cp; cell->frame_type = found_cells[max_peak_cell].frame_type; - float cfo = found_cells[max_peak_cell].cfo; + float cfo = found_cells[max_peak_cell].cfo; log_h->console("\n"); Info("SYNC: PSS/SSS detected: Mode=%s, PCI=%d, CFO=%.1f KHz, CP=%s\n", @@ -1137,13 +1127,6 @@ sync::search::ret_code sync::search::run(srslte_cell_t* cell, std::array #include #include +#include #include #include -#include using namespace std; -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { - if (argc != 2) { - std::cout << "Please call with the binary to provide net admin capabilities to as a parameter." << std::endl; - std::cout << "E.g. ./set_net_admin_caps myprogCalling " << std::endl; - return -1; - } + if (argc != 2) { + std::cout << "Please call with the binary to provide net admin capabilities to as a parameter." << std::endl; + std::cout << "E.g. ./set_net_admin_caps myprogCalling " << std::endl; + return -1; + } - std::string command("setcap 'cap_net_admin=eip' "); - command += argv[1]; + std::string command("setcap 'cap_net_admin=eip' "); + command += argv[1]; - std::cout << "Calling " << command << " with root rights." << std::endl; - setuid(0); - system(command.c_str()); + std::cout << "Calling " << command << " with root rights." << std::endl; + setuid(0); + system(command.c_str()); - return 0; + return 0; } - diff --git a/srsue/src/stack/mac/demux.cc b/srsue/src/stack/mac/demux.cc index 173cf1981..1a45a9055 100644 --- a/srsue/src/stack/mac/demux.cc +++ b/srsue/src/stack/mac/demux.cc @@ -19,10 +19,10 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) #include "srsue/hdr/stack/mac/demux.h" #include "srslte/interfaces/ue_interfaces.h" @@ -56,7 +56,8 @@ void demux::init(phy_interface_mac_common* phy_, bzero(&mch_lcids, SRSLTE_N_MCH_LCIDS); } -bool demux::get_uecrid_successful() { +bool demux::get_uecrid_successful() +{ return is_uecrid_successful; } @@ -76,29 +77,29 @@ uint8_t* demux::request_buffer_bcch(uint32_t len) } uint8_t* demux::request_buffer(uint32_t len) -{ +{ return pdus.request(len); } -/* Demultiplexing of MAC PDU associated with a Temporal C-RNTI. The PDU will - * remain in buffer until demultiplex_pending_pdu() is called. - * This features is provided to enable the Random Access Procedure to decide - * wether the PDU shall pass to upper layers or not, which depends on the - * Contention Resolution result. - * - * Warning: this function does some processing here assuming ACK deadline is not an +/* Demultiplexing of MAC PDU associated with a Temporal C-RNTI. The PDU will + * remain in buffer until demultiplex_pending_pdu() is called. + * This features is provided to enable the Random Access Procedure to decide + * wether the PDU shall pass to upper layers or not, which depends on the + * Contention Resolution result. + * + * Warning: this function does some processing here assuming ACK deadline is not an * issue here because Temp C-RNTI messages have small payloads */ -void demux::push_pdu_temp_crnti(uint8_t *buff, uint32_t nof_bytes) +void demux::push_pdu_temp_crnti(uint8_t* buff, uint32_t nof_bytes) { if (nof_bytes > 0) { - // Unpack DLSCH MAC PDU + // Unpack DLSCH MAC PDU pending_mac_msg.init_rx(nof_bytes); pending_mac_msg.parse_packet(buff); // Look for Contention Resolution UE ID is_uecrid_successful = false; - while(pending_mac_msg.next() && !is_uecrid_successful) { + while (pending_mac_msg.next() && !is_uecrid_successful) { if (pending_mac_msg.get()->ce_type() == srslte::sch_subh::CON_RES_ID) { Debug("Found Contention Resolution ID CE\n"); is_uecrid_successful = mac->contention_resolution_id_rcv(pending_mac_msg.get()->get_con_res_id()); @@ -139,7 +140,7 @@ void demux::push_pdu_bcch(uint8_t* buff, uint32_t nof_bytes) void demux::push_pdu_mch(uint8_t* buff, uint32_t nof_bytes) { - uint8_t *mch_buffer_ptr = request_buffer(nof_bytes); + uint8_t* mch_buffer_ptr = request_buffer(nof_bytes); memcpy(mch_buffer_ptr, buff, nof_bytes); pdus.push(mch_buffer_ptr, nof_bytes, srslte::pdu_queue::MCH); mch_buffer_ptr = NULL; @@ -153,7 +154,7 @@ bool demux::process_pdus() void demux::process_pdu(uint8_t* mac_pdu, uint32_t nof_bytes, srslte::pdu_queue::channel_t channel) { Debug("Processing MAC PDU channel %d\n", channel); - switch(channel) { + switch (channel) { case srslte::pdu_queue::DCH: // Unpack DLSCH MAC PDU mac_msg.init_rx(nof_bytes); @@ -193,15 +194,15 @@ void demux::process_sch_pdu_rt(uint8_t* buff, uint32_t nof_bytes) } } -void demux::process_sch_pdu(srslte::sch_pdu *pdu_msg) -{ - while(pdu_msg->next()) { +void demux::process_sch_pdu(srslte::sch_pdu* pdu_msg) +{ + while (pdu_msg->next()) { if (pdu_msg->get()->is_sdu()) { - bool route_pdu = true; + bool route_pdu = true; if (pdu_msg->get()->get_sdu_lcid() == 0) { - uint8_t *x = pdu_msg->get()->get_sdu_ptr(); - uint32_t sum = 0; - for (uint32_t i=0;iget()->get_payload_size();i++) { + uint8_t* x = pdu_msg->get()->get_sdu_ptr(); + uint32_t sum = 0; + for (uint32_t i = 0; i < pdu_msg->get()->get_payload_size(); i++) { sum += x[i]; } if (sum == 0) { @@ -209,28 +210,32 @@ void demux::process_sch_pdu(srslte::sch_pdu *pdu_msg) Warning("Received all zero PDU\n"); } } - // Route logical channel + // Route logical channel if (route_pdu) { Info("Delivering PDU for lcid=%d, %d bytes\n", pdu_msg->get()->get_sdu_lcid(), pdu_msg->get()->get_payload_size()); if (pdu_msg->get()->get_payload_size() < MAX_PDU_LEN) { - rlc->write_pdu(pdu_msg->get()->get_sdu_lcid(), pdu_msg->get()->get_sdu_ptr(), pdu_msg->get()->get_payload_size()); + rlc->write_pdu( + pdu_msg->get()->get_sdu_lcid(), pdu_msg->get()->get_sdu_ptr(), pdu_msg->get()->get_payload_size()); } else { char tmp[1024]; srslte_vec_sprint_hex(tmp, sizeof(tmp), pdu_msg->get()->get_sdu_ptr(), 32); Error("PDU size %d exceeds maximum PDU buffer size, lcid=%d, hex=[%s]\n", - pdu_msg->get()->get_payload_size(), pdu_msg->get()->get_sdu_lcid(), tmp); + pdu_msg->get()->get_payload_size(), + pdu_msg->get()->get_sdu_lcid(), + tmp); } } } else { // Ignore MAC Control Element } - } + } } -void demux::process_mch_pdu(srslte::mch_pdu *mch_msg){ - //disgarding headers that have already been processed - while(mch_msg->next()){ +void demux::process_mch_pdu(srslte::mch_pdu* mch_msg) +{ + // disgarding headers that have already been processed + while (mch_msg->next()) { if (srslte::sch_subh::MCH_SCHED_INFO == mch_msg->get()->ce_type()) { uint16_t stop; @@ -239,24 +244,24 @@ void demux::process_mch_pdu(srslte::mch_pdu *mch_msg){ Info("MCH Sched Info: LCID: %d, Stop: %d, tti is %d \n", lcid, stop, phy_h->get_current_tti()); } } - if(mch_msg->get()->is_sdu()) { + if (mch_msg->get()->is_sdu()) { uint32_t lcid = mch_msg->get()->get_sdu_lcid(); - if(lcid >= SRSLTE_N_MCH_LCIDS) { + if (lcid >= SRSLTE_N_MCH_LCIDS) { Error("Radio bearer id must be in [0:%d] - %d\n", SRSLTE_N_MCH_LCIDS, lcid); return; } Debug("Wrote MCH LCID=%d to RLC\n", lcid); - if(1 == mch_lcids[lcid]) { + if (1 == mch_lcids[lcid]) { rlc->write_pdu_mch(lcid, mch_msg->get()->get_sdu_ptr(), mch_msg->get()->get_payload_size()); - } + } } } } void demux::mch_start_rx(uint32_t lcid) { - if(lcid < 32) { + if (lcid < 32) { Info("MCH Channel Setup: LCID=%d\n", lcid); mch_lcids[lcid] = 1; } else { @@ -264,9 +269,10 @@ void demux::mch_start_rx(uint32_t lcid) } } -bool demux::process_ce(srslte::sch_subh *subh) { +bool demux::process_ce(srslte::sch_subh* subh) +{ uint32_t cc_idx = 0; - switch(subh->ce_type()) { + switch (subh->ce_type()) { case srslte::sch_subh::CON_RES_ID: // Do nothing break; @@ -292,8 +298,7 @@ bool demux::process_ce(srslte::sch_subh *subh) { Error("MAC CE 0x%x not supported\n", subh->ce_type()); break; } - return true; + return true; } - -} +} // namespace srsue diff --git a/srsue/src/stack/mac/mac.cc b/srsue/src/stack/mac/mac.cc index 44f96ac33..0005d2a11 100644 --- a/srsue/src/stack/mac/mac.cc +++ b/srsue/src/stack/mac/mac.cc @@ -19,14 +19,14 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#include #include #include -#include #include #include "srslte/common/log.h" @@ -148,10 +148,11 @@ void mac::reconfiguration(const uint32_t& cc_idx, const bool& enable) } } -void mac::wait_uplink() { - int cnt=0; +void mac::wait_uplink() +{ + int cnt = 0; Info("Waiting to uplink...\n"); - while(mux_unit.is_pending_any_sdu() && cnt<20) { + while (mux_unit.is_pending_any_sdu() && cnt < 20) { usleep(1000); cnt++; } @@ -264,8 +265,8 @@ void mac::pcch_start_rx() void mac::clear_rntis() { - p_window_start = 0; - si_window_start = 0; + p_window_start = 0; + si_window_start = 0; ra_window_start = -1; ra_window_length = -1; bzero(&uernti, sizeof(ue_rnti_t)); diff --git a/srsue/src/stack/mac/mux.cc b/srsue/src/stack/mac/mux.cc index b67ee4283..6bda877ba 100644 --- a/srsue/src/stack/mac/mux.cc +++ b/srsue/src/stack/mac/mux.cc @@ -19,16 +19,16 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) #include "srsue/hdr/stack/mac/mux.h" #include "srsue/hdr/stack/mac/mac.h" -#include #include +#include namespace srsue { @@ -39,7 +39,7 @@ mux::mux(srslte::log* log_) : pdu_msg(MAX_NOF_SUBHEADERS, log_), log_h(log_) void mux::init(rlc_interface_mac* rlc_, bsr_interface_mux* bsr_procedure_, phr_proc* phr_procedure_) { - rlc = rlc_; + rlc = rlc_; bsr_procedure = bsr_procedure_; phr_procedure = phr_procedure_; reset(); @@ -52,7 +52,7 @@ void mux::reset() for (auto& channel : logical_channels) { channel.Bj = 0; } - msg3_pending = false; + msg3_pending = false; pending_crnti_ce = 0; } @@ -78,7 +78,7 @@ bool mux::is_pending_any_sdu() return true; } } - return false; + return false; } bool mux::has_logical_channel(const uint32_t& lcid) @@ -151,9 +151,10 @@ void mux::print_logical_channel_state(const std::string& info) log_h->debug("%s\n", logline.c_str()); } -srslte::sch_subh::cetype bsr_format_convert(bsr_proc::bsr_format_t format) { - switch(format) { - case bsr_proc::LONG_BSR: +srslte::sch_subh::cetype bsr_format_convert(bsr_proc::bsr_format_t format) +{ + switch (format) { + case bsr_proc::LONG_BSR: return srslte::sch_subh::LONG_BSR; case bsr_proc::TRUNC_BSR: return srslte::sch_subh::TRUNC_BSR; @@ -172,7 +173,7 @@ uint8_t* mux::pdu_get(srslte::byte_buffer_t* payload, uint32_t pdu_sz) for (auto& channel : logical_channels) { channel.sched_len = 0; } - + // Logical Channel Procedure payload->clear(); pdu_msg.init_tx(payload, pdu_sz, true); @@ -193,13 +194,13 @@ uint8_t* mux::pdu_get(srslte::byte_buffer_t* payload, uint32_t pdu_sz) } pending_crnti_ce = 0; - bsr_proc::bsr_t bsr; - bool regular_bsr = bsr_procedure->need_to_send_bsr_on_ul_grant(pdu_msg.rem_size(), &bsr); + bsr_proc::bsr_t bsr; + bool regular_bsr = bsr_procedure->need_to_send_bsr_on_ul_grant(pdu_msg.rem_size(), &bsr); // MAC control element for BSR, with exception of BSR included for padding; if (regular_bsr) { if (pdu_msg.new_subh()) { - pdu_msg.get()->set_bsr(bsr.buff_size, bsr_format_convert(bsr.format)); + pdu_msg.get()->set_bsr(bsr.buff_size, bsr_format_convert(bsr.format)); } } @@ -256,13 +257,13 @@ uint8_t* mux::pdu_get(srslte::byte_buffer_t* payload, uint32_t pdu_sz) } } } - - log_h->debug("Assembled MAC PDU msg size %d/%d bytes\n", pdu_msg.get_pdu_len()-pdu_msg.rem_size(), pdu_sz); + + log_h->debug("Assembled MAC PDU msg size %d/%d bytes\n", pdu_msg.get_pdu_len() - pdu_msg.rem_size(), pdu_sz); /* Generate MAC PDU and save to buffer */ - uint8_t *ret = pdu_msg.write_packet(log_h); + uint8_t* ret = pdu_msg.write_packet(log_h); - return ret; + return ret; } void mux::append_crnti_ce_next_tx(uint16_t crnti) @@ -274,7 +275,7 @@ bool mux::sched_sdu(logical_channel_config_t* ch, int* sdu_space, int max_sdu_sz { if (sdu_space != nullptr && *sdu_space > 0) { // Get n-th pending SDU pointer and length - int sched_len = ch->buffer_len; + int sched_len = ch->buffer_len; if (sched_len > 0) { // there is pending SDU to allocate if (sched_len > max_sdu_sz && max_sdu_sz >= 0) { sched_len = max_sdu_sz; @@ -289,7 +290,7 @@ bool mux::sched_sdu(logical_channel_config_t* ch, int* sdu_space, int max_sdu_sz sched_len, sdu_space ? *sdu_space : 0); - *sdu_space -= sched_len; + *sdu_space -= sched_len; ch->buffer_len -= sched_len; if (ch->sched_len == 0) { @@ -297,17 +298,17 @@ bool mux::sched_sdu(logical_channel_config_t* ch, int* sdu_space, int max_sdu_sz *sdu_space -= sch_pdu::size_header_sdu(sched_len); } - ch->sched_len += sched_len; - return true; + ch->sched_len += sched_len; + return true; } } - return false; + return false; } -bool mux::allocate_sdu(uint32_t lcid, srslte::sch_pdu* pdu_msg, int max_sdu_sz) +bool mux::allocate_sdu(uint32_t lcid, srslte::sch_pdu* pdu_msg, int max_sdu_sz) { - bool sdu_added = false; - int sdu_space = max_sdu_sz; + bool sdu_added = false; + int sdu_space = max_sdu_sz; int buffer_state = rlc->get_buffer_state(lcid); while (buffer_state > 0 && sdu_space > 0) { // there is pending SDU to allocate @@ -362,20 +363,22 @@ void mux::msg3_flush() } msg3_buff.clear(); msg3_has_been_transmitted = false; - msg3_pending = false; + msg3_pending = false; } bool mux::msg3_is_transmitted() { - return msg3_has_been_transmitted; + return msg3_has_been_transmitted; } -void mux::msg3_prepare() { +void mux::msg3_prepare() +{ msg3_has_been_transmitted = false; - msg3_pending = true; + msg3_pending = true; } -bool mux::msg3_is_pending() { +bool mux::msg3_is_pending() +{ return msg3_pending; } @@ -404,4 +407,4 @@ uint8_t* mux::msg3_get(srslte::byte_buffer_t* payload, uint32_t pdu_sz) } } -} +} // namespace srsue diff --git a/srsue/src/stack/mac/proc_bsr.cc b/srsue/src/stack/mac/proc_bsr.cc index 136165c56..f22cb404d 100644 --- a/srsue/src/stack/mac/proc_bsr.cc +++ b/srsue/src/stack/mac/proc_bsr.cc @@ -19,10 +19,10 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) #include "srsue/hdr/stack/mac/proc_bsr.h" #include "srsue/hdr/stack/mac/mac.h" @@ -32,8 +32,8 @@ namespace srsue { bsr_proc::bsr_proc() { - log_h = NULL; - initiated = false; + log_h = NULL; + initiated = false; last_print = 0; current_tti = 0; trigger_tti = 0; @@ -124,7 +124,8 @@ uint32_t bsr_proc::get_buffer_state() } // Checks if data is available for a a channel with higher priority than others -bool bsr_proc::check_highest_channel() { +bool bsr_proc::check_highest_channel() +{ for (int i = 0; i < NOF_LCG; i++) { for (std::map::iterator iter = lcgs[i].begin(); iter != lcgs[i].end(); ++iter) { @@ -225,14 +226,14 @@ bool bsr_proc::generate_bsr(bsr_t* bsr, uint32_t nof_padding_bytes) uint32_t max_prio_lcg = find_max_priority_lcg_with_data(); for (uint32_t i = 0; i < NOF_LCG; i++) { if (max_prio_lcg != i) { - bsr->buff_size[i] = 0; + bsr->buff_size[i] = 0; } } } else { bsr->format = SHORT_BSR; } } else { - // If space for long BSR + // If space for long BSR bsr->format = LONG_BSR; } } else { @@ -289,34 +290,36 @@ void bsr_proc::step(uint32_t tti) } } Info("BSR: triggered_bsr_type=%d, LCID QUEUE status: %s\n", triggered_bsr_type, str); - last_print = tti; + last_print = tti; } pthread_mutex_unlock(&mutex); } -char* bsr_proc::bsr_type_tostring(triggered_bsr_type_t type) { - switch(type) { - case bsr_proc::REGULAR: - return (char*) "Regular"; +char* bsr_proc::bsr_type_tostring(triggered_bsr_type_t type) +{ + switch (type) { + case bsr_proc::REGULAR: + return (char*)"Regular"; case bsr_proc::PADDING: - return (char*) "Padding"; - case bsr_proc::PERIODIC: - return (char*) "Periodic"; + return (char*)"Padding"; + case bsr_proc::PERIODIC: + return (char*)"Periodic"; default: - return (char*) "Regular"; + return (char*)"Regular"; } } -char* bsr_proc::bsr_format_tostring(bsr_format_t format) { - switch(format) { - case bsr_proc::LONG_BSR: - return (char*) "Long"; +char* bsr_proc::bsr_format_tostring(bsr_format_t format) +{ + switch (format) { + case bsr_proc::LONG_BSR: + return (char*)"Long"; case bsr_proc::SHORT_BSR: - return (char*) "Short"; - case bsr_proc::TRUNC_BSR: - return (char*) "Truncated"; + return (char*)"Short"; + case bsr_proc::TRUNC_BSR: + return (char*)"Truncated"; default: - return (char*) "Short"; + return (char*)"Short"; } } @@ -389,7 +392,8 @@ bool bsr_proc::generate_padding_bsr(uint32_t nof_padding_bytes, bsr_t* bsr) return ret; } -bool bsr_proc::need_to_reset_sr() { +bool bsr_proc::need_to_reset_sr() +{ bool ret = false; pthread_mutex_lock(&mutex); if (reset_sr) { @@ -402,7 +406,8 @@ bool bsr_proc::need_to_reset_sr() { return ret; } -bool bsr_proc::need_to_send_sr(uint32_t tti) { +bool bsr_proc::need_to_send_sr(uint32_t tti) +{ bool ret = false; pthread_mutex_lock(&mutex); if (!sr_is_sent && triggered_bsr_type == REGULAR) { @@ -449,4 +454,4 @@ uint32_t bsr_proc::find_max_priority_lcg_with_data() return max_idx; } -} +} // namespace srsue diff --git a/srsue/src/stack/mac/proc_phr.cc b/srsue/src/stack/mac/proc_phr.cc index 58e62a343..751627cf2 100644 --- a/srsue/src/stack/mac/proc_phr.cc +++ b/srsue/src/stack/mac/proc_phr.cc @@ -19,10 +19,10 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) #include "srsue/hdr/stack/mac/proc_phr.h" #include "srslte/interfaces/ue_interfaces.h" @@ -84,7 +84,8 @@ void phr_proc::set_config(srslte::phr_cfg_t& cfg) } } -bool phr_proc::pathloss_changed() { +bool phr_proc::pathloss_changed() +{ if (!phr_cfg.enabled) { return false; } @@ -160,4 +161,4 @@ bool phr_proc::is_extended() { return phr_cfg.extended; } -} +} // namespace srsue diff --git a/srsue/src/stack/mac/proc_ra.cc b/srsue/src/stack/mac/proc_ra.cc index 0e828322c..505fceb83 100644 --- a/srsue/src/stack/mac/proc_ra.cc +++ b/srsue/src/stack/mac/proc_ra.cc @@ -19,10 +19,10 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) #include // for printing uint64_t #include @@ -111,14 +111,14 @@ void ra_proc::read_params() rach_cfg = new_cfg; mutex.unlock(); - // Read initialization parameters + // Read initialization parameters if (noncontention_enabled) { - preambleIndex = next_preamble_idx; - maskIndex = next_prach_mask; - noncontention_enabled = false; + preambleIndex = next_preamble_idx; + maskIndex = next_prach_mask; + noncontention_enabled = false; } else { - preambleIndex = 0; // pass when called from higher layers for non-contention based RA - maskIndex = 0; // same + preambleIndex = 0; // pass when called from higher layers for non-contention based RA + maskIndex = 0; // same } if (rach_cfg.nof_groupA_preambles == 0) { @@ -256,7 +256,7 @@ void ra_proc::initialization() { read_params(); transmitted_contention_id = 0; - preambleTransmissionCounter = 1; + preambleTransmissionCounter = 1; mux_unit->msg3_flush(); backoff_param_ms = 0; @@ -280,15 +280,15 @@ void ra_proc::resource_selection() if (preambleIndex > 0) { // Preamble is chosen by Higher layers (ie Network) sel_maskIndex = maskIndex; - sel_preamble = (uint32_t) preambleIndex; + sel_preamble = (uint32_t)preambleIndex; } else { // Preamble is chosen by MAC UE if (!mux_unit->msg3_is_transmitted()) { if (nof_groupB_preambles && new_ra_msg_len > rach_cfg.messageSizeGroupA) { // Check also pathloss (Pcmax,deltaPreamble and powerOffset) - sel_group = RA_GROUP_B; + sel_group = RA_GROUP_B; } else { - sel_group = RA_GROUP_A; + sel_group = RA_GROUP_A; } last_msg3_group = sel_group; } else { @@ -301,7 +301,7 @@ void ra_proc::resource_selection() } else { rError("Selected group preamble A but nof_groupA_preambles=0\n"); state = IDLE; - return; + return; } } else { if (nof_groupB_preambles) { @@ -310,10 +310,10 @@ void ra_proc::resource_selection() } else { rError("Selected group preamble B but nof_groupA_preambles=0\n"); state = IDLE; - return; + return; } } - sel_maskIndex = 0; + sel_maskIndex = 0; } rDebug("Selected preambleIndex=%d maskIndex=%d GroupA=%d, GroupB=%d\n", @@ -396,29 +396,29 @@ void ra_proc::tb_decoded_ok(const uint32_t tti) if (pcap) { pcap->write_dl_ranti(rar_pdu_buffer, rar_grant_nbytes, ra_rnti, true, tti); } - + rDebug("RAR decoded successfully TBS=%d\n", rar_grant_nbytes); - + rar_pdu_msg.init_rx(rar_grant_nbytes); rar_pdu_msg.parse_packet(rar_pdu_buffer); // Set Backoff parameter if (rar_pdu_msg.has_backoff()) { - backoff_param_ms = backoff_table[rar_pdu_msg.get_backoff()%16]; + backoff_param_ms = backoff_table[rar_pdu_msg.get_backoff() % 16]; } else { - backoff_param_ms = 0; + backoff_param_ms = 0; } - - current_ta = 0; - - while(rar_pdu_msg.next()) { + + current_ta = 0; + + while (rar_pdu_msg.next()) { if (rar_pdu_msg.get()->has_rapid() && rar_pdu_msg.get()->get_rapid() == sel_preamble) { - rar_received = true; + rar_received = true; process_timeadv_cmd(rar_pdu_msg.get()->get_ta_cmd()); - + // FIXME: Indicate received target power - //phy_h->set_target_power_rar(iniReceivedTargetPower, (preambleTransmissionCounter-1)*powerRampingStep); + // phy_h->set_target_power_rar(iniReceivedTargetPower, (preambleTransmissionCounter-1)*powerRampingStep); uint8_t grant[srslte::rar_subh::RAR_GRANT_LEN]; rar_pdu_msg.get()->get_sched_grant(grant); @@ -526,8 +526,8 @@ void ra_proc::complete() void ra_proc::start_noncont(uint32_t preamble_index, uint32_t prach_mask) { - next_preamble_idx = preamble_index; - next_prach_mask = prach_mask; + next_preamble_idx = preamble_index; + next_prach_mask = prach_mask; noncontention_enabled = true; start_mac_order(56, true); } @@ -535,7 +535,7 @@ void ra_proc::start_noncont(uint32_t preamble_index, uint32_t prach_mask) void ra_proc::start_mac_order(uint32_t msg_len_bits, bool is_ho) { if (state == IDLE) { - ra_is_ho = is_ho; + ra_is_ho = is_ho; started_by_pdcch = false; new_ra_msg_len = msg_len_bits; rInfo("Starting PRACH by MAC order\n"); @@ -634,5 +634,4 @@ void ra_proc::harq_max_retx() Warning("Contention Resolution is considered not successful. Stopping PDCCH Search and going to Response Error\n"); response_error(); } -} - +} // namespace srsue diff --git a/srsue/src/stack/mac/proc_sr.cc b/srsue/src/stack/mac/proc_sr.cc index 97d516815..59a79d8da 100644 --- a/srsue/src/stack/mac/proc_sr.cc +++ b/srsue/src/stack/mac/proc_sr.cc @@ -19,51 +19,52 @@ * */ -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) #include "srsue/hdr/stack/mac/proc_sr.h" namespace srsue { -sr_proc::sr_proc() { +sr_proc::sr_proc() +{ initiated = false; } void sr_proc::init(phy_interface_mac_lte* phy_h_, rrc_interface_mac* rrc_, srslte::log* log_h_) { - log_h = log_h_; - rrc = rrc_; - phy_h = phy_h_; - initiated = true; - sr_counter = 0; - do_ra = false; + log_h = log_h_; + rrc = rrc_; + phy_h = phy_h_; + initiated = true; + sr_counter = 0; + do_ra = false; } - + void sr_proc::reset() { is_pending_sr = false; } -bool sr_proc::need_tx(uint32_t tti) +bool sr_proc::need_tx(uint32_t tti) { int last_tx_tti = phy_h->sr_last_tx_tti(); Debug("SR: need_tx(): last_tx_tti=%d, tti=%d\n", last_tx_tti, tti); - if (last_tx_tti >= 0) { + if (last_tx_tti >= 0) { if (tti > (uint32_t)last_tx_tti) { if (tti - last_tx_tti > 8) { - return true; + return true; } } else { - uint32_t interval = 10240-last_tx_tti+tti; + uint32_t interval = 10240 - last_tx_tti + tti; if (interval > 8 && tti < 8) { - return true; + return true; } } } - return false; + return false; } void sr_proc::set_config(srslte::sr_cfg_t& cfg) @@ -89,26 +90,27 @@ void sr_proc::step(uint32_t tti) sr_cfg.dsr_transmax); log_h->console("Scheduling request failed: releasing RRC connection...\n"); rrc->release_pucch_srs(); - do_ra = true; - is_pending_sr = false; + do_ra = true; + is_pending_sr = false; } } } else { Info("SR: PUCCH not configured. Starting RA procedure\n"); - do_ra = true; + do_ra = true; reset(); } } } } -bool sr_proc::need_random_access() { +bool sr_proc::need_random_access() +{ if (initiated) { if (do_ra) { - do_ra = false; - return true; + do_ra = false; + return true; } else { - return false; + return false; } } return false; @@ -118,7 +120,7 @@ void sr_proc::start() { if (initiated) { if (!is_pending_sr) { - sr_counter = 0; + sr_counter = 0; is_pending_sr = true; } if (sr_cfg.enabled) { @@ -127,5 +129,4 @@ void sr_proc::start() } } -} - +} // namespace srsue diff --git a/srsue/src/stack/rrc/rrc.cc b/srsue/src/stack/rrc/rrc.cc index bda2c8c4b..2e58ae906 100644 --- a/srsue/src/stack/rrc/rrc.cc +++ b/srsue/src/stack/rrc/rrc.cc @@ -41,11 +41,11 @@ using namespace asn1::rrc; namespace srsue { -const static uint32_t NOF_REQUIRED_SIBS = 4; -const static uint32_t required_sibs[NOF_REQUIRED_SIBS] = {0,1,2,12}; // SIB1, SIB2, SIB3 and SIB13 (eMBMS) +const static uint32_t NOF_REQUIRED_SIBS = 4; +const static uint32_t required_sibs[NOF_REQUIRED_SIBS] = {0, 1, 2, 12}; // SIB1, SIB2, SIB3 and SIB13 (eMBMS) /******************************************************************************* - Base functions + Base functions *******************************************************************************/ rrc::rrc(srslte::log* rrc_log_) : @@ -104,10 +104,10 @@ void rrc::init(phy_interface_rrc_lte* phy_, const rrc_args_t& args_) { pool = byte_buffer_pool::get_instance(); - phy = phy_; - mac = mac_; - rlc = rlc_; - pdcp = pdcp_; + phy = phy_; + mac = mac_; + rlc = rlc_; + pdcp = pdcp_; nas = nas_; usim = usim_; gw = gw_; @@ -152,11 +152,12 @@ void rrc::init(phy_interface_rrc_lte* phy_, // initiate unique procedures ue_required_sibs.assign(&required_sibs[0], &required_sibs[NOF_REQUIRED_SIBS]); - running = true; + running = true; initiated = true; } -void rrc::stop() { +void rrc::stop() +{ running = false; stop_timers(); cmd_msg_t msg; @@ -264,29 +265,23 @@ void rrc::run_tti(uint32_t tti) } } - - - - - - - - /******************************************************************************* -* -* -* -* NAS interface: PLMN search and RRC connection establishment -* -* -* -*******************************************************************************/ + * + * + * + * NAS interface: PLMN search and RRC connection establishment + * + * + * + *******************************************************************************/ -uint16_t rrc::get_mcc() { +uint16_t rrc::get_mcc() +{ return serving_cell->get_mcc(); } -uint16_t rrc::get_mnc() { +uint16_t rrc::get_mnc() +{ return serving_cell->get_mnc(); } @@ -345,30 +340,31 @@ void rrc::set_ue_identity(srslte::s_tmsi_t s_tmsi) } /******************************************************************************* -* -* -* -* PHY interface: neighbour and serving cell measurements and out-of-sync/in-sync -* -* -* -*******************************************************************************/ + * + * + * + * PHY interface: neighbour and serving cell measurements and out-of-sync/in-sync + * + * + * + *******************************************************************************/ /* This function is called from a PHY worker thus must return very quickly. * Queue the values of the measurements and process them from the RRC thread */ -void rrc::new_phy_meas(float rsrp, float rsrq, uint32_t tti, int earfcn_i, int pci_i) { +void rrc::new_phy_meas(float rsrp, float rsrq, uint32_t tti, int earfcn_i, int pci_i) +{ uint32_t pci = 0; uint32_t earfcn = 0; if (earfcn_i < 0) { - earfcn = (uint32_t) serving_cell->get_earfcn(); + earfcn = (uint32_t)serving_cell->get_earfcn(); } else { - earfcn = (uint32_t) earfcn_i; + earfcn = (uint32_t)earfcn_i; } if (pci_i < 0) { - pci = (uint32_t) serving_cell->get_pci(); + pci = (uint32_t)serving_cell->get_pci(); } else { - pci = (uint32_t) pci_i; + pci = (uint32_t)pci_i; } phy_meas_t new_meas = {rsrp, rsrq, tti, earfcn, pci}; phy_meas_q.push(new_meas); @@ -381,9 +377,10 @@ void rrc::new_phy_meas(float rsrp, float rsrq, uint32_t tti, int earfcn_i, int p /* Processes all pending PHY measurements in queue. Must be called from a mutexed function */ -void rrc::process_phy_meas() { +void rrc::process_phy_meas() +{ phy_meas_t m; - while(phy_meas_q.try_pop(&m)) { + while (phy_meas_q.try_pop(&m)) { rrc_log->debug("MEAS: Processing measurement. %zd measurements in queue\n", phy_meas_q.size()); process_new_phy_meas(m); } @@ -391,9 +388,9 @@ void rrc::process_phy_meas() { void rrc::process_new_phy_meas(phy_meas_t meas) { - float rsrp = meas.rsrp; - float rsrq = meas.rsrq; - uint32_t tti = meas.tti; + float rsrp = meas.rsrp; + float rsrq = meas.rsrq; + uint32_t tti = meas.tti; uint32_t earfcn = meas.earfcn; uint32_t pci = meas.pci; @@ -454,29 +451,15 @@ void rrc::in_sync() } } - - - - - - - - - - - - - - /******************************************************************************* -* -* -* -* Cell selection, reselection and neighbour cell database management -* -* -* -*******************************************************************************/ + * + * + * + * Cell selection, reselection and neighbour cell database management + * + * + * + *******************************************************************************/ // Cell selection criteria Section 5.2.3.2 of 36.304 bool rrc::cell_selection_criteria(float rsrp, float rsrq) @@ -484,13 +467,15 @@ bool rrc::cell_selection_criteria(float rsrp, float rsrq) return (get_srxlev(rsrp) > 0 || !serving_cell->has_sib3()); } -float rrc::get_srxlev(float Qrxlevmeas) { +float rrc::get_srxlev(float Qrxlevmeas) +{ // TODO: Do max power limitation float Pcompensation = 0; return Qrxlevmeas - (cell_resel_cfg.Qrxlevmin + cell_resel_cfg.Qrxlevminoffset) - Pcompensation; } -float rrc::get_squal(float Qqualmeas) { +float rrc::get_squal(float Qqualmeas) +{ return Qqualmeas - (cell_resel_cfg.Qqualmin + cell_resel_cfg.Qqualminoffset); } @@ -586,7 +571,7 @@ void rrc::sort_neighbour_cells() neighbour_cells[0]->get_earfcn(), neighbour_cells[0]->phy_cell.cell.id, neighbour_cells[0]->get_rsrp()); - for (uint32_t i=1;iwarning("Detected Radio-Link Failure\n"); rrc_log->console("Warning: Detected Radio-Link Failure\n"); @@ -774,19 +760,22 @@ void rrc::radio_link_failure() { } /* Reception of PUCCH/SRS release procedure (Section 5.3.13) */ -void rrc::release_pucch_srs() { +void rrc::release_pucch_srs() +{ // Apply default configuration for PUCCH (CQI and SR) and SRS (release) if (initiated) { set_phy_default_pucch_srs(); } } -void rrc::ra_problem() { +void rrc::ra_problem() +{ radio_link_failure(); } -void rrc::max_retx_attempted() { - //TODO: Handle the radio link failure +void rrc::max_retx_attempted() +{ + // TODO: Handle the radio link failure rrc_log->warning("Max RLC reTx attempted\n"); cmd_msg_t msg; msg.command = cmd_msg_t::RLF; @@ -837,7 +826,7 @@ void rrc::send_con_request(srslte::establishment_cause_t cause) rrc_log->debug("Preparing RRC Connection Request\n"); // Prepare ConnectionRequest packet - ul_ccch_msg_s ul_ccch_msg; + ul_ccch_msg_s ul_ccch_msg; rrc_conn_request_r8_ies_s* rrc_conn_req = &ul_ccch_msg.msg.set_c1().set_rrc_conn_request().crit_exts.set_rrc_conn_request_r8(); @@ -849,7 +838,7 @@ void rrc::send_con_request(srslte::establishment_cause_t cause) // TODO use proper RNG uint64_t random_id = 0; for (uint i = 0; i < 5; i++) { // fill random ID bytewise, 40 bits = 5 bytes - random_id |= ( (uint64_t)rand() & 0xFF ) << i*8; + random_id |= ((uint64_t)rand() & 0xFF) << i * 8; } rrc_conn_req->ue_id.random_value().from_number(random_id); } @@ -864,7 +853,7 @@ void rrc::send_con_restablish_request(asn1::rrc::reest_cause_e cause, uint16_t c uint32_t cellid; // Clean reestablishment type - reestablishment_successful = false; + reestablishment_successful = false; if (cause == asn1::rrc::reest_cause_e::ho_fail) { crnti = ho_src_rnti; @@ -889,19 +878,19 @@ void rrc::send_con_restablish_request(asn1::rrc::reest_cause_e cause, uint16_t c varmac.c_rnti.from_number(crnti); varmac.pack(bref); uint32_t N_bits = (uint32_t)bref.distance(varShortMAC_packed); - uint32_t N_bytes = ((N_bits-1)/8+1); + uint32_t N_bytes = ((N_bits - 1) / 8 + 1); - rrc_log->info("Encoded varShortMAC: cellId=0x%x, PCI=%d, rnti=0x%x (%d bytes, %d bits)\n", - cellid, pci, crnti, N_bytes, N_bits); + rrc_log->info( + "Encoded varShortMAC: cellId=0x%x, PCI=%d, rnti=0x%x (%d bytes, %d bits)\n", cellid, pci, crnti, N_bytes, N_bits); // Compute MAC-I uint8_t mac_key[4] = {}; - switch(integ_algo) { + switch (integ_algo) { case INTEGRITY_ALGORITHM_ID_128_EIA1: security_128_eia1(&k_rrc_int[16], - 0xffffffff, // 32-bit all to ones - 0x1f, // 5-bit all to ones - 1, // 1-bit to one + 0xffffffff, // 32-bit all to ones + 0x1f, // 5-bit all to ones + 1, // 1-bit to one varShortMAC_packed, N_bytes, mac_key); @@ -929,7 +918,7 @@ void rrc::send_con_restablish_request(asn1::rrc::reest_cause_e cause, uint16_t c } // Prepare ConnectionRestalishmentRequest packet - asn1::rrc::ul_ccch_msg_s ul_ccch_msg; + asn1::rrc::ul_ccch_msg_s ul_ccch_msg; rrc_conn_reest_request_r8_ies_s* rrc_conn_reest_req = &ul_ccch_msg.msg.set_c1().set_rrc_conn_reest_request().crit_exts.set_rrc_conn_reest_request_r8(); @@ -942,7 +931,8 @@ void rrc::send_con_restablish_request(asn1::rrc::reest_cause_e cause, uint16_t c send_ul_ccch_msg(ul_ccch_msg); } -void rrc::send_con_restablish_complete() { +void rrc::send_con_restablish_complete() +{ rrc_log->debug("Preparing RRC Connection Reestablishment Complete\n"); rrc_log->console("RRC Connected\n"); @@ -960,7 +950,7 @@ void rrc::send_con_setup_complete(srslte::unique_byte_buffer_t nas_msg) rrc_log->debug("Preparing RRC Connection Setup Complete\n"); // Prepare ConnectionSetupComplete packet - asn1::rrc::ul_dcch_msg_s ul_dcch_msg; + asn1::rrc::ul_dcch_msg_s ul_dcch_msg; rrc_conn_setup_complete_r8_ies_s* rrc_conn_setup_complete = &ul_dcch_msg.msg.set_c1().set_rrc_conn_setup_complete().crit_exts.set_c1().set_rrc_conn_setup_complete_r8(); @@ -978,7 +968,7 @@ void rrc::send_ul_info_transfer(unique_byte_buffer_t nas_msg) uint32_t lcid = rlc->has_bearer(RB_ID_SRB2) ? RB_ID_SRB2 : RB_ID_SRB1; // Prepare UL INFO packet - asn1::rrc::ul_dcch_msg_s ul_dcch_msg; + asn1::rrc::ul_dcch_msg_s ul_dcch_msg; ul_info_transfer_r8_ies_s* rrc_ul_info_transfer = &ul_dcch_msg.msg.set_c1().set_ul_info_transfer().crit_exts.set_c1().set_ul_info_transfer_r8(); @@ -989,7 +979,8 @@ void rrc::send_ul_info_transfer(unique_byte_buffer_t nas_msg) send_ul_dcch_msg(lcid, ul_dcch_msg); } -void rrc::send_security_mode_complete() { +void rrc::send_security_mode_complete() +{ rrc_log->debug("Preparing Security Mode Complete\n"); // Prepare Security Mode Command Complete @@ -1000,7 +991,8 @@ void rrc::send_security_mode_complete() { send_ul_dcch_msg(RB_ID_SRB1, ul_dcch_msg); } -void rrc::send_rrc_con_reconfig_complete() { +void rrc::send_rrc_con_reconfig_complete() +{ rrc_log->debug("Preparing RRC Connection Reconfig Complete\n"); asn1::rrc::ul_dcch_msg_s ul_dcch_msg; @@ -1022,8 +1014,8 @@ bool rrc::ho_prepare() if (not has_neighbour_cell(target_earfcn, mob_ctrl_info->target_pci)) { rrc_log->console("Received HO command to unknown PCI=%d\n", mob_ctrl_info->target_pci); - rrc_log->error("Could not find target cell earfcn=%d, pci=%d\n", serving_cell->get_earfcn(), - mob_ctrl_info->target_pci); + rrc_log->error( + "Could not find target cell earfcn=%d, pci=%d\n", serving_cell->get_earfcn(), mob_ctrl_info->target_pci); return false; } @@ -1069,7 +1061,8 @@ bool rrc::ho_prepare() if (mob_ctrl_info->rach_cfg_ded_present) { rrc_log->info("Starting non-contention based RA with preamble_idx=%d, mask_idx=%d\n", - mob_ctrl_info->rach_cfg_ded.ra_preamb_idx, mob_ctrl_info->rach_cfg_ded.ra_prach_mask_idx); + mob_ctrl_info->rach_cfg_ded.ra_preamb_idx, + mob_ctrl_info->rach_cfg_ded.ra_prach_mask_idx); mac->start_noncont_ho(mob_ctrl_info->rach_cfg_ded.ra_preamb_idx, mob_ctrl_info->rach_cfg_ded.ra_prach_mask_idx); } else { rrc_log->info("Starting contention-based RA\n"); @@ -1094,8 +1087,15 @@ bool rrc::ho_prepare() } } - usim->generate_as_keys_ho(mob_ctrl_info->target_pci, phy->get_current_earfcn(), ncc, k_rrc_enc, k_rrc_int, k_up_enc, - k_up_int, cipher_algo, integ_algo); + usim->generate_as_keys_ho(mob_ctrl_info->target_pci, + phy->get_current_earfcn(), + ncc, + k_rrc_enc, + k_rrc_int, + k_up_enc, + k_up_int, + cipher_algo, + integ_algo); pdcp->config_security_all(k_rrc_enc, k_rrc_int, k_up_enc, cipher_algo, integ_algo); send_rrc_con_reconfig_complete(); @@ -1137,7 +1137,8 @@ bool rrc::con_reconfig_ho(asn1::rrc::rrc_conn_recfg_s* reconfig) } rrc_log->info("Received HO command to target PCell=%d\n", mob_reconf_r8->mob_ctrl_info.target_pci); - rrc_log->console("Received HO command to target PCell=%d, NCC=%d\n", mob_reconf_r8->mob_ctrl_info.target_pci, + rrc_log->console("Received HO command to target PCell=%d, NCC=%d\n", + mob_reconf_r8->mob_ctrl_info.target_pci, mob_reconf_r8->security_cfg_ho.ho_type.intra_lte().next_hop_chaining_count); // store mobilityControlInfo @@ -1274,7 +1275,8 @@ void rrc::handle_rrc_con_reconfig(uint32_t lcid, asn1::rrc::rrc_conn_recfg_s* re } /* Actions upon reception of RRCConnectionRelease 5.3.8.3 */ -void rrc::rrc_connection_release() { +void rrc::rrc_connection_release() +{ // Save idleModeMobilityControlInfo, etc. rrc_log->console("Received RRC Connection Release\n"); start_go_idle(); @@ -1285,8 +1287,8 @@ void rrc::leave_connected() { rrc_log->console("RRC IDLE\n"); rrc_log->info("Leaving RRC_CONNECTED state\n"); - state = RRC_STATE_IDLE; - drb_up = false; + state = RRC_STATE_IDLE; + drb_up = false; security_is_activated = false; measurements.reset(); nas->left_rrc_connected(); @@ -1444,8 +1446,10 @@ void rrc::parse_pdu_bcch_dlsch(unique_byte_buffer_t pdu) void rrc::handle_sib1() { sib_type1_s* sib1 = serving_cell->sib1ptr(); - rrc_log->info("SIB1 received, CellID=%d, si_window=%d, sib2_period=%d\n", serving_cell->get_cell_id() & 0xfff, - sib1->si_win_len.to_number(), sib1->sched_info_list[0].si_periodicity.to_number()); + rrc_log->info("SIB1 received, CellID=%d, si_window=%d, sib2_period=%d\n", + serving_cell->get_cell_id() & 0xfff, + sib1->si_win_len.to_number(), + sib1->sched_info_list[0].si_periodicity.to_number()); // Print SIB scheduling info for (uint32_t i = 0; i < sib1->sched_info_list.size(); ++i) { @@ -1565,14 +1569,14 @@ void rrc::handle_sib13() } /******************************************************************************* -* -* -* -* Reception of Paging messages -* -* -* -*******************************************************************************/ + * + * + * + * Reception of Paging messages + * + * + * + *******************************************************************************/ void rrc::write_pdu_pcch(unique_byte_buffer_t pdu) { cmd_msg_t msg; @@ -1654,17 +1658,13 @@ void rrc::parse_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) } } - - - - /******************************************************************************* -* -* -* Packet processing -* -* -*******************************************************************************/ + * + * + * Packet processing + * + * + *******************************************************************************/ void rrc::send_ul_ccch_msg(const asn1::rrc::ul_ccch_msg_s& msg) { @@ -1755,7 +1755,7 @@ void rrc::process_pdu(uint32_t lcid, srslte::unique_byte_buffer_t pdu) void rrc::parse_dl_ccch(unique_byte_buffer_t pdu) { - asn1::bit_ref bref(pdu->msg, pdu->N_bytes); + asn1::bit_ref bref(pdu->msg, pdu->N_bytes); asn1::rrc::dl_ccch_msg_s dl_ccch_msg; if (dl_ccch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or dl_ccch_msg.msg.type().value != dl_ccch_msg_type_c::types_opts::c1) { @@ -1806,7 +1806,7 @@ void rrc::parse_dl_ccch(unique_byte_buffer_t pdu) void rrc::parse_dl_dcch(uint32_t lcid, unique_byte_buffer_t pdu) { - asn1::bit_ref bref(pdu->msg, pdu->N_bytes); + asn1::bit_ref bref(pdu->msg, pdu->N_bytes); asn1::rrc::dl_dcch_msg_s dl_dcch_msg; if (dl_dcch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or dl_dcch_msg.msg.type().value != dl_dcch_msg_type_c::types_opts::c1) { @@ -1824,7 +1824,8 @@ void rrc::parse_dl_dcch(uint32_t lcid, unique_byte_buffer_t pdu) return; } pdu->N_bytes = c1->dl_info_transfer().crit_exts.c1().dl_info_transfer_r8().ded_info_type.ded_info_nas().size(); - memcpy(pdu->msg, c1->dl_info_transfer().crit_exts.c1().dl_info_transfer_r8().ded_info_type.ded_info_nas().data(), + memcpy(pdu->msg, + c1->dl_info_transfer().crit_exts.c1().dl_info_transfer_r8().ded_info_type.ded_info_nas().data(), pdu->N_bytes); nas->write_pdu(lcid, std::move(pdu)); break; @@ -1840,7 +1841,8 @@ void rrc::parse_dl_dcch(uint32_t lcid, unique_byte_buffer_t pdu) .security_mode_cmd_r8() .security_cfg_smc.security_algorithm_cfg.integrity_prot_algorithm.value; - rrc_log->info("Received Security Mode Command eea: %s, eia: %s\n", ciphering_algorithm_id_text[cipher_algo], + rrc_log->info("Received Security Mode Command eea: %s, eia: %s\n", + ciphering_algorithm_id_text[cipher_algo], integrity_algorithm_id_text[integ_algo]); // Generate AS security keys @@ -1848,8 +1850,8 @@ void rrc::parse_dl_dcch(uint32_t lcid, unique_byte_buffer_t pdu) nas->get_k_asme(k_asme, 32); rrc_log->debug_hex(k_asme, 32, "UE K_asme"); rrc_log->debug("Generating K_enb with UL NAS COUNT: %d\n", nas->get_k_enb_count()); - usim->generate_as_keys(k_asme, nas->get_k_enb_count(), k_rrc_enc, k_rrc_int, k_up_enc, k_up_int, cipher_algo, - integ_algo); + usim->generate_as_keys( + k_asme, nas->get_k_enb_count(), k_rrc_enc, k_rrc_int, k_up_enc, k_up_int, cipher_algo, integ_algo); rrc_log->info_hex(k_rrc_enc, 32, "RRC encryption key - k_rrc_enc"); rrc_log->info_hex(k_rrc_int, 32, "RRC integrity key - k_rrc_int"); rrc_log->info_hex(k_up_enc, 32, "UP encryption key - k_up_enc"); @@ -1880,14 +1882,14 @@ void rrc::parse_dl_dcch(uint32_t lcid, unique_byte_buffer_t pdu) } /******************************************************************************* -* -* -* -* Capabilities Message -* -* -* -*******************************************************************************/ + * + * + * + * Capabilities Message + * + * + * + *******************************************************************************/ void rrc::enable_capabilities() { bool enable_ul_64 = @@ -2317,9 +2319,9 @@ void rrc::apply_phy_scell_config(const asn1::rrc::scell_to_add_mod_r10_s& scell_ // Parse radio resource if (scell_config.rr_cfg_common_scell_r10_present) { - const rr_cfg_common_scell_r10_s* rr_cfg = &scell_config.rr_cfg_common_scell_r10; + const rr_cfg_common_scell_r10_s* rr_cfg = &scell_config.rr_cfg_common_scell_r10; auto non_ul_cfg = &rr_cfg->non_ul_cfg_r10; - scell.frame_type = (rr_cfg->tdd_cfg_v1130.is_present()) ? SRSLTE_TDD : SRSLTE_FDD; + scell.frame_type = (rr_cfg->tdd_cfg_v1130.is_present()) ? SRSLTE_TDD : SRSLTE_FDD; scell.nof_prb = non_ul_cfg->dl_bw_r10.to_number(); scell.nof_ports = non_ul_cfg->ant_info_common_r10.ant_ports_count.to_number(); scell.phich_length = (non_ul_cfg->phich_cfg_r10.phich_dur.value == phich_cfg_s::phich_dur_opts::normal) @@ -2586,7 +2588,7 @@ void rrc::add_srb(srb_to_add_mod_s* srb_cnfg) } } else { if (srb_cnfg->lc_ch_cfg.explicit_value().lc_ch_sr_mask_r9_present) { - //TODO + // TODO } if (srb_cnfg->lc_ch_cfg.explicit_value().ul_specific_params_present) { if (srb_cnfg->lc_ch_cfg.explicit_value().ul_specific_params.lc_ch_group_present) @@ -2634,10 +2636,10 @@ void rrc::add_drb(drb_to_add_mod_s* drb_cnfg) rlc->add_bearer(lcid, make_rlc_config_t(drb_cnfg->rlc_cfg)); // Setup MAC - uint8_t log_chan_group = 0; - uint8_t priority = 1; - int prioritized_bit_rate = -1; - int bucket_size_duration = -1; + uint8_t log_chan_group = 0; + uint8_t priority = 1; + int prioritized_bit_rate = -1; + int bucket_size_duration = -1; if (drb_cnfg->lc_ch_cfg.ul_specific_params_present) { if (drb_cnfg->lc_ch_cfg.ul_specific_params.lc_ch_group_present) { log_chan_group = drb_cnfg->lc_ch_cfg.ul_specific_params.lc_ch_group; @@ -2697,7 +2699,8 @@ void rrc::set_phy_default_pucch_srs() mac->set_config(current_mac_cfg); } -void rrc::set_mac_default() { +void rrc::set_mac_default() +{ apply_mac_config_dedicated_default(); } @@ -2748,9 +2751,9 @@ void rrc::rrc_meas::reset() } /* L3 filtering 5.5.3.2 */ -void rrc::rrc_meas::L3_filter(meas_value_t *value, float values[NOF_MEASUREMENTS]) +void rrc::rrc_meas::L3_filter(meas_value_t* value, float values[NOF_MEASUREMENTS]) { - for (int i=0;ims[i]) { value->ms[i] = SRSLTE_VEC_EMA(values[i], value->ms[i], filter_a[i]); } else { @@ -2779,17 +2782,22 @@ void rrc::rrc_meas::new_phy_meas(uint32_t earfcn, uint32_t pci, float rsrp, floa bool added = parent->add_neighbour_cell(earfcn, pci, rsrp); log_h->debug("MEAS: New measurement %s earfcn=%d, pci=%d, rsrp=%f, rsrq=%f, tti=%d\n", - added?"added":"not added", earfcn, pci, rsrp, rsrq, tti); + added ? "added" : "not added", + earfcn, + pci, + rsrp, + rsrq, + tti); // Only report measurements of 8th strongest cells if (added) { // Save PHY measurement for all active measurements whose earfcn/pci matches - for(std::map::iterator iter=active.begin(); iter!=active.end(); ++iter) { - meas_t *m = &iter->second; + for (std::map::iterator iter = active.begin(); iter != active.end(); ++iter) { + meas_t* m = &iter->second; if (objects[m->object_id].earfcn == earfcn) { // If it's a newly discovered cell, add it to objects if (!m->cell_values.count(pci)) { - uint32_t cell_idx = objects[m->object_id].found_cells.size(); + uint32_t cell_idx = objects[m->object_id].found_cells.size(); objects[m->object_id].found_cells[cell_idx].pci = pci; objects[m->object_id].found_cells[cell_idx].q_offset = 0; } @@ -2802,9 +2810,10 @@ void rrc::rrc_meas::new_phy_meas(uint32_t earfcn, uint32_t pci, float rsrp, floa } // Remove all stored measurements for a given cell -void rrc::rrc_meas::delete_report(uint32_t earfcn, uint32_t pci) { - for(std::map::iterator iter=active.begin(); iter!=active.end(); ++iter) { - meas_t *m = &iter->second; +void rrc::rrc_meas::delete_report(uint32_t earfcn, uint32_t pci) +{ + for (std::map::iterator iter = active.begin(); iter != active.end(); ++iter) { + meas_t* m = &iter->second; if (objects[m->object_id].earfcn == earfcn) { if (m->cell_values.count(pci)) { m->cell_values.erase(pci); @@ -2814,12 +2823,14 @@ void rrc::rrc_meas::delete_report(uint32_t earfcn, uint32_t pci) { } } -void rrc::rrc_meas::run_tti(uint32_t tti) { +void rrc::rrc_meas::run_tti(uint32_t tti) +{ // Measurement Report Triggering Section 5.5.4 calculate_triggers(tti); } -bool rrc::rrc_meas::find_earfcn_cell(uint32_t earfcn, uint32_t pci, meas_obj_t **object, int *cell_idx) { +bool rrc::rrc_meas::find_earfcn_cell(uint32_t earfcn, uint32_t pci, meas_obj_t** object, int* cell_idx) +{ if (object) { *object = NULL; } @@ -2828,7 +2839,9 @@ bool rrc::rrc_meas::find_earfcn_cell(uint32_t earfcn, uint32_t pci, meas_obj_t * if (object) { *object = &obj->second; } - for (std::map::iterator c = obj->second.found_cells.begin(); c != obj->second.found_cells.end(); ++c) { + for (std::map::iterator c = obj->second.found_cells.begin(); + c != obj->second.found_cells.end(); + ++c) { if (c->second.pci == pci) { if (cell_idx) { *cell_idx = c->first; @@ -2853,15 +2866,18 @@ void rrc::rrc_meas::generate_report(uint32_t meas_id) ul_dcch_msg.msg.set_c1().set_meas_report().crit_exts.set_c1().set_meas_report_r8(); meas_results_s* report = &ul_dcch_msg.msg.c1().meas_report().crit_exts.c1().meas_report_r8().meas_results; - meas_t *m = &active[meas_id]; - report_cfg_t *cfg = &reports_cfg[m->report_id]; + meas_t* m = &active[meas_id]; + report_cfg_t* cfg = &reports_cfg[m->report_id]; report->meas_id = (uint8_t)meas_id; report->meas_result_pcell.rsrp_result = value_to_range(RSRP, pcell_measurement.ms[RSRP]); report->meas_result_pcell.rsrq_result = value_to_range(RSRQ, pcell_measurement.ms[RSRQ]); log_h->info("MEAS: Generate report MeasId=%d, nof_reports_send=%d, Pcell rsrp=%f rsrq=%f\n", - report->meas_id, m->nof_reports_sent, pcell_measurement.ms[RSRP], pcell_measurement.ms[RSRQ]); + report->meas_id, + m->nof_reports_sent, + pcell_measurement.ms[RSRP], + pcell_measurement.ms[RSRQ]); meas_result_list_eutra_l& neigh_list = report->meas_result_neigh_cells.set_meas_result_list_eutra(); // TODO: report up to 8 best cells @@ -2903,14 +2919,18 @@ void rrc::rrc_meas::generate_report(uint32_t meas_id) } /* Handle entering/leaving event conditions 5.5.4.1 */ -bool rrc::rrc_meas::process_event(eutra_event_s* event, uint32_t tti, bool enter_condition, bool exit_condition, - meas_t* m, meas_value_t* cell) +bool rrc::rrc_meas::process_event(eutra_event_s* event, + uint32_t tti, + bool enter_condition, + bool exit_condition, + meas_t* m, + meas_value_t* cell) { bool generate_report = false; if (enter_condition && (!m->triggered || !cell->triggered)) { if (!cell->timer_enter_triggered) { cell->timer_enter_triggered = true; - cell->enter_tti = tti; + cell->enter_tti = tti; } else if (srslte_tti_interval(tti, cell->enter_tti) >= event->time_to_trigger.to_number()) { m->triggered = true; cell->triggered = true; @@ -2945,8 +2965,8 @@ bool rrc::rrc_meas::process_event(eutra_event_s* event, uint32_t tti, bool enter /* Calculate trigger conditions for each cell 5.5.4 */ void rrc::rrc_meas::calculate_triggers(uint32_t tti) { - float Ofp = 0, Ocp = 0; - meas_obj_t *serving_object = NULL; + float Ofp = 0, Ocp = 0; + meas_obj_t* serving_object = NULL; int serving_cell_idx = 0; // Get serving cell @@ -2964,9 +2984,9 @@ void rrc::rrc_meas::calculate_triggers(uint32_t tti) } for (std::map::iterator m = active.begin(); m != active.end(); ++m) { - report_cfg_t *cfg = &reports_cfg[m->second.report_id]; + report_cfg_t* cfg = &reports_cfg[m->second.report_id]; double hyst = 0.5 * cfg->event.hysteresis; - float Mp = pcell_measurement.ms[cfg->trigger_quantity]; + float Mp = pcell_measurement.ms[cfg->trigger_quantity]; eutra_event_s::event_id_c_ event_id = cfg->event.event_id; std::string event_str = event_id.type().to_string(); @@ -3006,16 +3026,17 @@ void rrc::rrc_meas::calculate_triggers(uint32_t tti) } // Rest are evaluated for every cell in frequency } else { - meas_obj_t *obj = &objects[m->second.object_id]; - for (std::map::iterator cell = obj->found_cells.begin(); cell != obj->found_cells.end(); ++cell) { + meas_obj_t* obj = &objects[m->second.object_id]; + for (std::map::iterator cell = obj->found_cells.begin(); cell != obj->found_cells.end(); + ++cell) { if (m->second.cell_values.count(cell->second.pci)) { - float Ofn = obj->q_offset; - float Ocn = cell->second.q_offset; - float Mn = m->second.cell_values[cell->second.pci].ms[cfg->trigger_quantity]; + float Ofn = obj->q_offset; + float Ocn = cell->second.q_offset; + float Mn = m->second.cell_values[cell->second.pci].ms[cfg->trigger_quantity]; double Off = 0; float th = 0, th1 = 0, th2 = 0; - bool enter_condition = false; - bool exit_condition = false; + bool enter_condition = false; + bool exit_condition = false; uint8_t range, range2; switch (event_id.type().value) { case eutra_event_s::event_id_c_::types::event_a3: @@ -3052,8 +3073,12 @@ void rrc::rrc_meas::calculate_triggers(uint32_t tti) default: log_h->error("Error event %s not implemented\n", event_str.c_str()); } - gen_report |= process_event(&cfg->event, tti, enter_condition, exit_condition, - &m->second, &m->second.cell_values[cell->second.pci]); + gen_report |= process_event(&cfg->event, + tti, + enter_condition, + exit_condition, + &m->second, + &m->second.cell_values[cell->second.pci]); } } } @@ -3066,7 +3091,8 @@ void rrc::rrc_meas::calculate_triggers(uint32_t tti) } // Procedure upon handover or reestablishment 5.5.6.1 -void rrc::rrc_meas::ho_finish() { +void rrc::rrc_meas::ho_finish() +{ // Remove all measId with trigger periodic std::map::iterator iter = active.begin(); while (iter != active.end()) { @@ -3077,7 +3103,7 @@ void rrc::rrc_meas::ho_finish() { } } - //TODO: Inter-frequency handover + // TODO: Inter-frequency handover // Stop all reports for (std::map::iterator iter = active.begin(); iter != active.end(); ++iter) { @@ -3113,7 +3139,8 @@ void rrc::rrc_meas::stop_reports_object(uint32_t object_id) } } -void rrc::rrc_meas::remove_meas_object(uint32_t object_id) { +void rrc::rrc_meas::remove_meas_object(uint32_t object_id) +{ std::map::iterator iter = active.begin(); while (iter != active.end()) { if (iter->second.object_id == object_id) { @@ -3124,7 +3151,8 @@ void rrc::rrc_meas::remove_meas_object(uint32_t object_id) { } } -void rrc::rrc_meas::remove_meas_report(uint32_t report_id) { +void rrc::rrc_meas::remove_meas_report(uint32_t report_id) +{ std::map::iterator iter = active.begin(); while (iter != active.end()) { if (iter->second.report_id == report_id) { @@ -3173,7 +3201,8 @@ bool rrc::rrc_meas::parse_meas_config(meas_cfg_s* cfg) // Access the object if exists or create it meas_obj_t* dst_obj = &objects[cfg->meas_obj_to_add_mod_list[i].meas_obj_id]; - dst_obj->earfcn = src_obj->carrier_freq;; + dst_obj->earfcn = src_obj->carrier_freq; + ; if (src_obj->offset_freq_present) { dst_obj->q_offset = src_obj->offset_freq.to_number(); } else { @@ -3192,7 +3221,9 @@ bool rrc::rrc_meas::parse_meas_config(meas_cfg_s* cfg) dst_obj->meas_cells[src_obj->cells_to_add_mod_list[j].cell_idx].pci = src_obj->cells_to_add_mod_list[j].pci; log_h->info("MEAS: Added measObjectId=%d, earfcn=%d, q_offset=%f, pci=%d, offset_cell=%f\n", - cfg->meas_obj_to_add_mod_list[i].meas_obj_id, dst_obj->earfcn, dst_obj->q_offset, + cfg->meas_obj_to_add_mod_list[i].meas_obj_id, + dst_obj->earfcn, + dst_obj->q_offset, dst_obj->meas_cells[src_obj->cells_to_add_mod_list[j].cell_idx].pci, dst_obj->meas_cells[src_obj->cells_to_add_mod_list[j].cell_idx].q_offset); } @@ -3243,10 +3274,14 @@ bool rrc::rrc_meas::parse_meas_config(meas_cfg_s* cfg) if (dst_rep->trigger_type == report_cfg_t::EVENT) { log_h->info("MEAS: Added reportConfigId=%d, event=%s, amount=%d, interval=%d\n", cfg->report_cfg_to_add_mod_list[i].report_cfg_id, - dst_rep->event.event_id.type().to_string().c_str(), dst_rep->amount, dst_rep->interval); + dst_rep->event.event_id.type().to_string().c_str(), + dst_rep->amount, + dst_rep->interval); } else { log_h->info("MEAS: Added reportConfigId=%d, type=periodical, amount=%d, interval=%d\n", - cfg->report_cfg_to_add_mod_list[i].report_cfg_id, dst_rep->amount, dst_rep->interval); + cfg->report_cfg_to_add_mod_list[i].report_cfg_id, + dst_rep->amount, + dst_rep->interval); } // Reset reports counter @@ -3345,9 +3380,10 @@ void rrc::rrc_meas::update_phy() } } -uint8_t rrc::rrc_meas::value_to_range(quantity_t quant, float value) { +uint8_t rrc::rrc_meas::value_to_range(quantity_t quant, float value) +{ uint8_t range = 0; - switch(quant) { + switch (quant) { case RSRP: if (value < -140) { range = 0; @@ -3390,9 +3426,7 @@ float rrc::rrc_meas::range_to_value(quantity_t quant, uint8_t range) return val; } -const std::string rrc::rb_id_str[] = {"SRB0", "SRB1", "SRB2", - "DRB1", "DRB2", "DRB3", - "DRB4", "DRB5", "DRB6", - "DRB7", "DRB8"}; +const std::string rrc::rb_id_str[] = + {"SRB0", "SRB1", "SRB2", "DRB1", "DRB2", "DRB3", "DRB4", "DRB5", "DRB6", "DRB7", "DRB8"}; } // namespace srsue diff --git a/srsue/src/stack/upper/gw.cc b/srsue/src/stack/upper/gw.cc index f638951b4..07d3830f2 100644 --- a/srsue/src/stack/upper/gw.cc +++ b/srsue/src/stack/upper/gw.cc @@ -23,14 +23,14 @@ #include "srslte/upper/ipv6.h" #include -#include #include -#include #include -#include -#include +#include #include #include +#include +#include +#include namespace srsue { @@ -61,23 +61,21 @@ int gw::init(const gw_args_t& args_, srslte::logger* logger_, stack_interface_gw } mbsfn_sock_addr.sin_family = AF_INET; - mbsfn_sock_addr.sin_addr.s_addr =inet_addr("127.0.0.1"); + mbsfn_sock_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); return SRSLTE_SUCCESS; } void gw::stop() { - if(run_enable) - { + if (run_enable) { run_enable = false; - if(if_up) - { + if (if_up) { close(tun_fd); - + // Wait thread to exit gracefully otherwise might leave a mutex locked - int cnt=0; - while(running && cnt<100) { + int cnt = 0; + while (running && cnt < 100) { usleep(10000); cnt++; } @@ -95,14 +93,14 @@ void gw::stop() } } -void gw::get_metrics(gw_metrics_t &m) +void gw::get_metrics(gw_metrics_t& m) { gettimeofday(&metrics_time[2], NULL); get_time_interval(metrics_time); - double secs = (double) metrics_time[0].tv_sec+metrics_time[0].tv_usec*1e-6; - - m.dl_tput_mbps = (dl_tput_bytes*8/(double)1e6)/secs; - m.ul_tput_mbps = (ul_tput_bytes*8/(double)1e6)/secs; + double secs = (double)metrics_time[0].tv_sec + metrics_time[0].tv_usec * 1e-6; + + m.dl_tput_mbps = (dl_tput_bytes * 8 / (double)1e6) / secs; + m.ul_tput_mbps = (ul_tput_bytes * 8 / (double)1e6) / secs; log.info("RX throughput: %4.6f Mbps. TX throughput: %4.6f Mbps.\n", m.dl_tput_mbps, m.ul_tput_mbps); memcpy(&metrics_time[1], &metrics_time[2], sizeof(struct timeval)); @@ -139,23 +137,22 @@ void gw::write_pdu(uint32_t lcid, srslte::unique_byte_buffer_t pdu) void gw::write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) { - if(pdu->N_bytes>2) - { + if (pdu->N_bytes > 2) { log.info_hex( pdu->msg, pdu->N_bytes, "RX MCH PDU (%d B). Stack latency: %ld us\n", pdu->N_bytes, pdu->get_latency_us()); dl_tput_bytes += pdu->N_bytes; - //Hack to drop initial 2 bytes - pdu->msg +=2; - pdu->N_bytes-=2; + // Hack to drop initial 2 bytes + pdu->msg += 2; + pdu->N_bytes -= 2; struct in_addr dst_addr; - memcpy(&dst_addr.s_addr, &pdu->msg[16],4); + memcpy(&dst_addr.s_addr, &pdu->msg[16], 4); if (!if_up) { log.warning("TUN/TAP not up - dropping gw RX message\n"); } else { - int n = write(tun_fd, pdu->msg, pdu->N_bytes); - if(n > 0 && (pdu->N_bytes != (uint32_t) n) ) { + int n = write(tun_fd, pdu->msg, pdu->N_bytes); + if (n > 0 && (pdu->N_bytes != (uint32_t)n)) { log.warning("DL TUN/TAP write failure\n"); } } @@ -168,13 +165,13 @@ void gw::write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) int gw::setup_if_addr(uint32_t lcid, uint8_t pdn_type, uint32_t ip_addr, uint8_t* ipv6_if_addr, char* err_str) { int err; - if(pdn_type == LIBLTE_MME_PDN_TYPE_IPV4 || pdn_type == LIBLTE_MME_PDN_TYPE_IPV4V6 ){ + if (pdn_type == LIBLTE_MME_PDN_TYPE_IPV4 || pdn_type == LIBLTE_MME_PDN_TYPE_IPV4V6) { err = setup_if_addr4(ip_addr, err_str); if (err != SRSLTE_SUCCESS) { return err; } } - if(pdn_type == LIBLTE_MME_PDN_TYPE_IPV6 || pdn_type == LIBLTE_MME_PDN_TYPE_IPV4V6 ){ + if (pdn_type == LIBLTE_MME_PDN_TYPE_IPV6 || pdn_type == LIBLTE_MME_PDN_TYPE_IPV4V6) { err = setup_if_addr6(ipv6_if_addr, err_str); if (err != SRSLTE_SUCCESS) { return err; @@ -217,7 +214,7 @@ int gw::apply_traffic_flow_template(const uint8_t& *******************************************************************************/ void gw::add_mch_port(uint32_t lcid, uint32_t port) { - if(lcid > 0 && lcid < SRSLTE_N_MCH_LCIDS) { + if (lcid > 0 && lcid < SRSLTE_N_MCH_LCIDS) { mbsfn_ports[lcid] = port; } } @@ -227,7 +224,7 @@ void gw::add_mch_port(uint32_t lcid, uint32_t port) /********************/ void gw::run_thread() { - uint32 idx = 0; + uint32 idx = 0; int32 N_bytes = 0; srslte::unique_byte_buffer_t pdu = srslte::allocate_unique_buffer(*pool, true); @@ -237,15 +234,14 @@ void gw::run_thread() } const static uint32_t ATTACH_WAIT_TOUT = 40; // 4 sec - uint32_t attach_wait = 0; + uint32_t attach_wait = 0; log.info("GW IP packet receiver thread run_enable\n"); running = true; - while(run_enable) - { - if (SRSLTE_MAX_BUFFER_SIZE_BYTES-SRSLTE_BUFFER_HEADER_OFFSET > idx) { - N_bytes = read(tun_fd, &pdu->msg[idx], SRSLTE_MAX_BUFFER_SIZE_BYTES-SRSLTE_BUFFER_HEADER_OFFSET - idx); + while (run_enable) { + if (SRSLTE_MAX_BUFFER_SIZE_BYTES - SRSLTE_BUFFER_HEADER_OFFSET > idx) { + N_bytes = read(tun_fd, &pdu->msg[idx], SRSLTE_MAX_BUFFER_SIZE_BYTES - SRSLTE_BUFFER_HEADER_OFFSET - idx); } else { log.error("GW pdu buffer full - gw receive thread exiting.\n"); log.console("GW pdu buffer full - gw receive thread exiting.\n"); @@ -253,15 +249,15 @@ void gw::run_thread() } log.debug("Read %d bytes from TUN fd=%d, idx=%d\n", N_bytes, tun_fd, idx); if (N_bytes > 0) { - struct iphdr *ip_pkt = (struct iphdr*)pdu->msg; - struct ipv6hdr *ip6_pkt = (struct ipv6hdr*)pdu->msg; - uint16_t pkt_len = 0; - pdu->N_bytes = idx + N_bytes; + struct iphdr* ip_pkt = (struct iphdr*)pdu->msg; + struct ipv6hdr* ip6_pkt = (struct ipv6hdr*)pdu->msg; + uint16_t pkt_len = 0; + pdu->N_bytes = idx + N_bytes; if (ip_pkt->version == 4 || ip_pkt->version == 6) { - if (ip_pkt->version == 4){ + if (ip_pkt->version == 4) { pkt_len = ntohs(ip_pkt->tot_len); - } else if (ip_pkt->version == 6){ - pkt_len = ntohs(ip6_pkt->payload_len)+40; + } else if (ip_pkt->version == 6) { + pkt_len = ntohs(ip6_pkt->payload_len) + 40; } else { log.error_hex(pdu->msg, pdu->N_bytes, "Unsupported IP version. Dropping packet.\n"); continue; @@ -301,10 +297,10 @@ void gw::run_thread() log.error("Fatal Error: Couldn't allocate PDU in run_thread().\n"); usleep(100000); } - } while(!pdu); + } while (!pdu); idx = 0; } - }else{ + } else { idx += N_bytes; log.debug( "Entire packet not read from socket. Total Length %d, N_Bytes %d.\n", ip_pkt->tot_len, pdu->N_bytes); @@ -312,7 +308,7 @@ void gw::run_thread() } else { log.error("IP Version not handled. Version %d\n", ip_pkt->version); } - }else{ + } else { log.error("Failed to read from TUN interface - gw receive thread exiting.\n"); log.console("Failed to read from TUN interface - gw receive thread exiting.\n"); break; @@ -359,7 +355,7 @@ int gw::init_if(char* err_str) ifr.ifr_flags = IFF_TUN | IFF_NO_PI; strncpy( ifr.ifr_ifrn.ifrn_name, args.tun_dev_name.c_str(), std::min(args.tun_dev_name.length(), (size_t)(IFNAMSIZ - 1))); - ifr.ifr_ifrn.ifrn_name[IFNAMSIZ-1] = 0; + ifr.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = 0; if (0 > ioctl(tun_fd, TUNSETIFF, &ifr)) { err_str = strerror(errno); log.debug("Failed to set TUN device name: %s\n", err_str); @@ -408,16 +404,16 @@ int gw::setup_if_addr4(uint32_t ip_addr, char* err_str) } // Setup the IP address - sock = socket(AF_INET, SOCK_DGRAM, 0); - ifr.ifr_addr.sa_family = AF_INET; - ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr = htonl(ip_addr); + sock = socket(AF_INET, SOCK_DGRAM, 0); + ifr.ifr_addr.sa_family = AF_INET; + ((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr.s_addr = htonl(ip_addr); if (0 > ioctl(sock, SIOCSIFADDR, &ifr)) { err_str = strerror(errno); log.debug("Failed to set socket address: %s\n", err_str); close(tun_fd); return SRSLTE_ERROR_CANT_START; } - ifr.ifr_netmask.sa_family = AF_INET; + ifr.ifr_netmask.sa_family = AF_INET; ((struct sockaddr_in*)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr(args.tun_dev_netmask.c_str()); if (0 > ioctl(sock, SIOCSIFNETMASK, &ifr)) { err_str = strerror(errno); @@ -433,11 +429,11 @@ int gw::setup_if_addr4(uint32_t ip_addr, char* err_str) int gw::setup_if_addr6(uint8_t* ipv6_if_id, char* err_str) { struct sockaddr_in6 sai; - struct in6_ifreq ifr6; - bool match = true; + struct in6_ifreq ifr6; + bool match = true; - for (int i=0; i<8; i++){ - if(ipv6_if_id[i] != current_if_id[i]){ + for (int i = 0; i < 8; i++) { + if (ipv6_if_id[i] != current_if_id[i]) { match = false; break; } @@ -445,17 +441,17 @@ int gw::setup_if_addr6(uint8_t* ipv6_if_id, char* err_str) if (!match) { if (!if_up) { - if( init_if(err_str) ) { + if (init_if(err_str)) { log.error("init_if failed\n"); return SRSLTE_ERROR_CANT_START; } } // Setup the IP address - sock = socket(AF_INET6, SOCK_DGRAM, 0); + sock = socket(AF_INET6, SOCK_DGRAM, 0); ifr.ifr_addr.sa_family = AF_INET6; - if(inet_pton(AF_INET6, "fe80::", (void *)&sai.sin6_addr) <= 0) { + if (inet_pton(AF_INET6, "fe80::", (void*)&sai.sin6_addr) <= 0) { log.error("Bad address\n"); return SRSLTE_ERROR_CANT_START; } @@ -465,10 +461,9 @@ int gw::setup_if_addr6(uint8_t* ipv6_if_id, char* err_str) perror("SIOGIFINDEX"); return SRSLTE_ERROR_CANT_START; } - ifr6.ifr6_ifindex = ifr.ifr_ifindex; + ifr6.ifr6_ifindex = ifr.ifr_ifindex; ifr6.ifr6_prefixlen = 64; - memcpy((char *) &ifr6.ifr6_addr, (char *) &sai.sin6_addr, - sizeof(struct in6_addr)); + memcpy((char*)&ifr6.ifr6_addr, (char*)&sai.sin6_addr, sizeof(struct in6_addr)); if (ioctl(sock, SIOCSIFADDR, &ifr6) < 0) { err_str = strerror(errno); @@ -476,7 +471,7 @@ int gw::setup_if_addr6(uint8_t* ipv6_if_id, char* err_str) return SRSLTE_ERROR_CANT_START; } - for (int i=0; i<8; i++){ + for (int i = 0; i < 8; i++) { current_if_id[i] = ipv6_if_id[i]; } } @@ -484,26 +479,26 @@ int gw::setup_if_addr6(uint8_t* ipv6_if_id, char* err_str) return SRSLTE_SUCCESS; } -bool gw::find_ipv6_addr(struct in6_addr *in6_out) +bool gw::find_ipv6_addr(struct in6_addr* in6_out) { - int n, rtattrlen, fd = -1; - unsigned int if_index; - struct rtattr *rta, *rtatp; - struct nlmsghdr *nlmp; - struct ifaddrmsg *rtmp; - struct in6_addr *in6p; - char buf[2048]; + int n, rtattrlen, fd = -1; + unsigned int if_index; + struct rtattr * rta, *rtatp; + struct nlmsghdr* nlmp; + struct ifaddrmsg* rtmp; + struct in6_addr* in6p; + char buf[2048]; struct { - struct nlmsghdr n; + struct nlmsghdr n; struct ifaddrmsg r; - char buf[1024]; + char buf[1024]; } req; log.debug("Trying to obtain IPv6 addr of %s interface\n", args.tun_dev_name.c_str()); - //Get Interface Index + // Get Interface Index if_index = if_nametoindex(args.tun_dev_name.c_str()); - if(if_index == 0){ + if (if_index == 0) { log.error("Could not find interface index\n"); goto err_out; } @@ -517,19 +512,19 @@ bool gw::find_ipv6_addr(struct in6_addr *in6_out) // We use RTM_GETADDR to get the ip address from the kernel memset(&req, 0, sizeof(req)); - req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH; - req.n.nlmsg_type = RTM_GETADDR; + req.n.nlmsg_type = RTM_GETADDR; - // AF_INET6 is used to signify the kernel to fetch only ipv6 entires. + // AF_INET6 is used to signify the kernel to fetch only ipv6 entires. req.r.ifa_family = AF_INET6; - - // Fill up all the attributes for the rtnetlink header. + + // Fill up all the attributes for the rtnetlink header. // The lenght is important. 16 signifies we are requesting IPv6 addresses - rta = (struct rtattr *)(((char *)&req) + NLMSG_ALIGN(req.n.nlmsg_len)); + rta = (struct rtattr*)(((char*)&req) + NLMSG_ALIGN(req.n.nlmsg_len)); rta->rta_len = RTA_LENGTH(16); - // Time to send and recv the message from kernel + // Time to send and recv the message from kernel n = send(fd, &req, req.n.nlmsg_len, 0); if (n < 0) { log.error("Error sending NETLINK message to kernel -- %s", strerror(errno)); @@ -548,9 +543,9 @@ bool gw::find_ipv6_addr(struct in6_addr *in6_out) } // Parse the reply - for (nlmp = (struct nlmsghdr *)buf; NLMSG_OK (nlmp, n); nlmp = NLMSG_NEXT (nlmp, n)){ - - //Chack NL message type + for (nlmp = (struct nlmsghdr*)buf; NLMSG_OK(nlmp, n); nlmp = NLMSG_NEXT(nlmp, n)) { + + // Chack NL message type if (nlmp->nlmsg_type == NLMSG_DONE) { log.error("Reach end of NETLINK message without finding IPv6 address.\n"); goto err_out; @@ -561,15 +556,15 @@ bool gw::find_ipv6_addr(struct in6_addr *in6_out) } log.debug("NETLINK message type %d\n", nlmp->nlmsg_type); - //Get IFA message - rtmp = (struct ifaddrmsg *)NLMSG_DATA(nlmp); - rtatp = (struct rtattr *)IFA_RTA(rtmp); + // Get IFA message + rtmp = (struct ifaddrmsg*)NLMSG_DATA(nlmp); + rtatp = (struct rtattr*)IFA_RTA(rtmp); rtattrlen = IFA_PAYLOAD(nlmp); for (; RTA_OK(rtatp, rtattrlen); rtatp = RTA_NEXT(rtatp, rtattrlen)) { // We are looking IFA_ADDRESS rt_attribute type. // For more info on the different types see man(7) rtnetlink. if (rtatp->rta_type == IFA_ADDRESS) { - in6p = (struct in6_addr *)RTA_DATA(rtatp); + in6p = (struct in6_addr*)RTA_DATA(rtatp); if (if_index == rtmp->ifa_index) { for (int i = 0; i < 16; i++) { in6_out->s6_addr[i] = in6p->s6_addr[i]; @@ -590,19 +585,19 @@ out: return true; } -void gw::del_ipv6_addr(struct in6_addr *in6p) +void gw::del_ipv6_addr(struct in6_addr* in6p) { - int status, fd =-1; + int status, fd = -1; unsigned int if_index; struct { - struct nlmsghdr n; + struct nlmsghdr n; struct ifaddrmsg ifa; - char buf[1024]; + char buf[1024]; } req; - //Get Interface Index + // Get Interface Index if_index = if_nametoindex(args.tun_dev_name.c_str()); - if(if_index == 0){ + if (if_index == 0) { log.error("Could not find interface index\n"); goto out; } @@ -613,23 +608,23 @@ void gw::del_ipv6_addr(struct in6_addr *in6p) log.error("Error openning NETLINK socket -- %s\n", strerror(errno)); goto out; } - + // We use RTM_DELADDR to delete the ip address from the interface memset(&req, 0, sizeof(req)); - req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); - req.n.nlmsg_type = RTM_DELADDR; + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); + req.n.nlmsg_type = RTM_DELADDR; req.n.nlmsg_flags = NLM_F_REQUEST; - req.ifa.ifa_family = AF_INET6; + req.ifa.ifa_family = AF_INET6; req.ifa.ifa_prefixlen = 64; - req.ifa.ifa_index = if_index; // set the tun_srsue index - req.ifa.ifa_scope = 0; - - //Add RT atribute - struct rtattr *rta; - rta = (struct rtattr *)(((char *)&req.n) + NLMSG_ALIGN(req.n.nlmsg_len)); + req.ifa.ifa_index = if_index; // set the tun_srsue index + req.ifa.ifa_scope = 0; + + // Add RT atribute + struct rtattr* rta; + rta = (struct rtattr*)(((char*)&req.n) + NLMSG_ALIGN(req.n.nlmsg_len)); rta->rta_type = IFA_LOCAL; - rta->rta_len = RTA_LENGTH(16); + rta->rta_len = RTA_LENGTH(16); memcpy(RTA_DATA(rta), in6p, 16); req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) + rta->rta_len; @@ -640,7 +635,7 @@ void gw::del_ipv6_addr(struct in6_addr *in6p) } out: - if (fd<0){ + if (fd < 0) { close(fd); } return; diff --git a/srsue/src/stack/upper/nas.cc b/srsue/src/stack/upper/nas.cc index 8cf3f36e2..58a4926c1 100644 --- a/srsue/src/stack/upper/nas.cc +++ b/srsue/src/stack/upper/nas.cc @@ -276,8 +276,7 @@ void nas::init(usim_interface_nas* usim_, rrc_interface_nas* rrc_, gw_interface_ cfg = cfg_; if ((read_ctxt_file(&ctxt))) { - usim->generate_nas_keys(ctxt.k_asme, k_nas_enc, k_nas_int, - ctxt.cipher_algo, ctxt.integ_algo); + usim->generate_nas_keys(ctxt.k_asme, k_nas_enc, k_nas_int, ctxt.cipher_algo, ctxt.integ_algo); nas_log->debug_hex(k_nas_enc, 32, "NAS encryption key - k_nas_enc"); nas_log->debug_hex(k_nas_int, 32, "NAS integrity key - k_nas_int"); have_guti = true; @@ -512,22 +511,21 @@ void nas::select_plmn() home_plmn.to_string().c_str(), known_plmns[0].to_string().c_str()); plmn_is_selected = true; - current_plmn = known_plmns[0]; + current_plmn = known_plmns[0]; } } void nas::write_pdu(uint32_t lcid, unique_byte_buffer_t pdu) { - uint8 pd = 0; - uint8 msg_type = 0; + uint8 pd = 0; + uint8 msg_type = 0; uint8 sec_hdr_type = 0; nas_log->info_hex(pdu->msg, pdu->N_bytes, "DL %s PDU", rrc->get_rb_name(lcid).c_str()); // Parse the message security header liblte_mme_parse_msg_sec_header((LIBLTE_BYTE_MSG_STRUCT*)pdu.get(), &pd, &sec_hdr_type); - switch (sec_hdr_type) - { + switch (sec_hdr_type) { case LIBLTE_MME_SECURITY_HDR_TYPE_PLAIN_NAS: case LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_WITH_NEW_EPS_SECURITY_CONTEXT: case LIBLTE_MME_SECURITY_HDR_TYPE_SERVICE_REQUEST: @@ -612,18 +610,21 @@ void nas::write_pdu(uint32_t lcid, unique_byte_buffer_t pdu) } } -void nas::set_k_enb_count(uint32_t count) { +void nas::set_k_enb_count(uint32_t count) +{ // UL count for RRC key derivation depends on UL Count of the Attach Request or Service Request. // On the case of an Authentication Request, the UL count used to generate K_enb must be reset to zero. ctxt.k_enb_count = count; } -uint32_t nas::get_k_enb_count() { +uint32_t nas::get_k_enb_count() +{ return ctxt.k_enb_count; } -bool nas::get_k_asme(uint8_t *k_asme_, uint32_t n) { - if(!have_ctxt) { +bool nas::get_k_asme(uint8_t* k_asme_, uint32_t n) +{ + if (!have_ctxt) { nas_log->error("K_asme requested before security context established\n"); return false; } @@ -641,9 +642,9 @@ uint32_t nas::get_ipv4_addr() return ip_addr; } -bool nas::get_ipv6_addr(uint8_t *ipv6_addr) +bool nas::get_ipv6_addr(uint8_t* ipv6_addr) { - uint8_t null_addr[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t null_addr[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; if (memcmp(ipv6_addr, null_addr, 8) != 0) { memcpy(ipv6_addr, ipv6_if_id, 8); return true; @@ -655,7 +656,7 @@ bool nas::get_ipv6_addr(uint8_t *ipv6_addr) PCAP *******************************************************************************/ -void nas::start_pcap(srslte::nas_pcap *pcap_) +void nas::start_pcap(srslte::nas_pcap* pcap_) { pcap = pcap_; } @@ -664,19 +665,20 @@ void nas::start_pcap(srslte::nas_pcap *pcap_) * Security ******************************************************************************/ -void nas::integrity_generate(uint8_t *key_128, +void nas::integrity_generate(uint8_t* key_128, uint32_t count, - uint8_t direction, - uint8_t *msg, + uint8_t direction, + uint8_t* msg, uint32_t msg_len, - uint8_t *mac) { + uint8_t* mac) +{ switch (ctxt.integ_algo) { case INTEGRITY_ALGORITHM_ID_EIA0: break; case INTEGRITY_ALGORITHM_ID_128_EIA1: security_128_eia1(key_128, count, - 0, // Bearer always 0 for NAS + 0, // Bearer always 0 for NAS direction, msg, msg_len, @@ -726,16 +728,23 @@ bool nas::integrity_check(byte_buffer_t* pdu) // Check if expected mac equals the sent mac for (int i = 0; i < 4; i++) { - if(exp_mac[i] != mac[i]){ + if (exp_mac[i] != mac[i]) { nas_log->warning("Integrity check failure. Local: count=%d, [%02x %02x %02x %02x], " - "Received: count=%d, [%02x %02x %02x %02x]\n", - ctxt.rx_count, exp_mac[0], exp_mac[1], exp_mac[2], exp_mac[3], - pdu->msg[5], mac[0], mac[1], mac[2], mac[3]); + "Received: count=%d, [%02x %02x %02x %02x]\n", + ctxt.rx_count, + exp_mac[0], + exp_mac[1], + exp_mac[2], + exp_mac[3], + pdu->msg[5], + mac[0], + mac[1], + mac[2], + mac[3]); return false; } } - nas_log->info("Integrity check ok. Local: count=%d, Received: count=%d\n", - ctxt.rx_count, pdu->msg[5]); + nas_log->info("Integrity check ok. Local: count=%d, Received: count=%d\n", ctxt.rx_count, pdu->msg[5]); // Updated local count (according to TS 24.301 Sec. 4.4.3.3) if (pdu->msg[5] != ctxt.rx_count) { @@ -752,102 +761,99 @@ bool nas::integrity_check(byte_buffer_t* pdu) void nas::cipher_encrypt(byte_buffer_t* pdu) { byte_buffer_t pdu_tmp; - switch(ctxt.cipher_algo) - { - case CIPHERING_ALGORITHM_ID_EEA0: + switch (ctxt.cipher_algo) { + case CIPHERING_ALGORITHM_ID_EEA0: break; - case CIPHERING_ALGORITHM_ID_128_EEA1: + case CIPHERING_ALGORITHM_ID_128_EEA1: security_128_eea1(&k_nas_enc[16], pdu->msg[5], - 0, // Bearer always 0 for NAS + 0, // Bearer always 0 for NAS + SECURITY_DIRECTION_UPLINK, + &pdu->msg[6], + pdu->N_bytes - 6, + &pdu_tmp.msg[6]); + memcpy(&pdu->msg[6], &pdu_tmp.msg[6], pdu->N_bytes - 6); + break; + case CIPHERING_ALGORITHM_ID_128_EEA2: + security_128_eea2(&k_nas_enc[16], + pdu->msg[5], + 0, // Bearer always 0 for NAS + SECURITY_DIRECTION_UPLINK, + &pdu->msg[6], + pdu->N_bytes - 6, + &pdu_tmp.msg[6]); + memcpy(&pdu->msg[6], &pdu_tmp.msg[6], pdu->N_bytes - 6); + break; + case CIPHERING_ALGORITHM_ID_128_EEA3: + security_128_eea3(&k_nas_enc[16], + pdu->msg[5], + 0, // Bearer always 0 for NAS SECURITY_DIRECTION_UPLINK, &pdu->msg[6], - pdu->N_bytes-6, + pdu->N_bytes - 6, &pdu_tmp.msg[6]); memcpy(&pdu->msg[6], &pdu_tmp.msg[6], pdu->N_bytes - 6); break; - case CIPHERING_ALGORITHM_ID_128_EEA2: - security_128_eea2(&k_nas_enc[16], - pdu->msg[5], - 0, // Bearer always 0 for NAS - SECURITY_DIRECTION_UPLINK, - &pdu->msg[6], - pdu->N_bytes - 6, - &pdu_tmp.msg[6]); - memcpy(&pdu->msg[6], &pdu_tmp.msg[6], pdu->N_bytes - 6); - break; - case CIPHERING_ALGORITHM_ID_128_EEA3: - security_128_eea3(&k_nas_enc[16], - pdu->msg[5], - 0, // Bearer always 0 for NAS - SECURITY_DIRECTION_UPLINK, - &pdu->msg[6], - pdu->N_bytes - 6, - &pdu_tmp.msg[6]); - memcpy(&pdu->msg[6], &pdu_tmp.msg[6], pdu->N_bytes - 6); - break; - default: - nas_log->error("Ciphering algorithm not known\n"); - break; + default: + nas_log->error("Ciphering algorithm not known\n"); + break; } } void nas::cipher_decrypt(byte_buffer_t* pdu) { byte_buffer_t tmp_pdu; - switch(ctxt.cipher_algo) - { - case CIPHERING_ALGORITHM_ID_EEA0: + switch (ctxt.cipher_algo) { + case CIPHERING_ALGORITHM_ID_EEA0: break; - case CIPHERING_ALGORITHM_ID_128_EEA1: + case CIPHERING_ALGORITHM_ID_128_EEA1: security_128_eea1(&k_nas_enc[16], pdu->msg[5], - 0, // Bearer always 0 for NAS + 0, // Bearer always 0 for NAS + SECURITY_DIRECTION_DOWNLINK, + &pdu->msg[6], + pdu->N_bytes - 6, + &tmp_pdu.msg[6]); + memcpy(&pdu->msg[6], &tmp_pdu.msg[6], pdu->N_bytes - 6); + break; + case CIPHERING_ALGORITHM_ID_128_EEA2: + security_128_eea2(&k_nas_enc[16], + pdu->msg[5], + 0, // Bearer always 0 for NAS SECURITY_DIRECTION_DOWNLINK, &pdu->msg[6], - pdu->N_bytes-6, + pdu->N_bytes - 6, &tmp_pdu.msg[6]); - memcpy(&pdu->msg[6], &tmp_pdu.msg[6], pdu->N_bytes-6); + nas_log->debug_hex(tmp_pdu.msg, pdu->N_bytes, "Decrypted"); + memcpy(&pdu->msg[6], &tmp_pdu.msg[6], pdu->N_bytes - 6); break; - case CIPHERING_ALGORITHM_ID_128_EEA2: - security_128_eea2(&k_nas_enc[16], - pdu->msg[5], - 0, // Bearer always 0 for NAS - SECURITY_DIRECTION_DOWNLINK, - &pdu->msg[6], - pdu->N_bytes - 6, - &tmp_pdu.msg[6]); - nas_log->debug_hex(tmp_pdu.msg, pdu->N_bytes, "Decrypted"); - memcpy(&pdu->msg[6], &tmp_pdu.msg[6], pdu->N_bytes - 6); - break; - case CIPHERING_ALGORITHM_ID_128_EEA3: - security_128_eea3(&k_nas_enc[16], - pdu->msg[5], - 0, // Bearer always 0 for NAS - SECURITY_DIRECTION_DOWNLINK, - &pdu->msg[6], - pdu->N_bytes - 6, - &tmp_pdu.msg[6]); - nas_log->debug_hex(tmp_pdu.msg, pdu->N_bytes, "Decrypted"); - memcpy(&pdu->msg[6], &tmp_pdu.msg[6], pdu->N_bytes - 6); - break; - default: - nas_log->error("Ciphering algorithms not known\n"); - break; - } -} - -bool nas::check_cap_replay(LIBLTE_MME_UE_SECURITY_CAPABILITIES_STRUCT *caps) -{ - for(uint32_t i=0; i<8; i++) { - if(caps->eea[i] != eea_caps[i] || caps->eia[i] != eia_caps[i]) { + case CIPHERING_ALGORITHM_ID_128_EEA3: + security_128_eea3(&k_nas_enc[16], + pdu->msg[5], + 0, // Bearer always 0 for NAS + SECURITY_DIRECTION_DOWNLINK, + &pdu->msg[6], + pdu->N_bytes - 6, + &tmp_pdu.msg[6]); + nas_log->debug_hex(tmp_pdu.msg, pdu->N_bytes, "Decrypted"); + memcpy(&pdu->msg[6], &tmp_pdu.msg[6], pdu->N_bytes - 6); + break; + default: + nas_log->error("Ciphering algorithms not known\n"); + break; + } +} + +bool nas::check_cap_replay(LIBLTE_MME_UE_SECURITY_CAPABILITIES_STRUCT* caps) +{ + for (uint32_t i = 0; i < 8; i++) { + if (caps->eea[i] != eea_caps[i] || caps->eia[i] != eia_caps[i]) { return false; } } return true; } - /******************************************************************************* * Parsers ******************************************************************************/ @@ -875,8 +881,8 @@ void nas::parse_attach_accept(uint32_t lcid, unique_byte_buffer_t pdu) liblte_mme_unpack_attach_accept_msg((LIBLTE_BYTE_MSG_STRUCT*)pdu.get(), &attach_accept); if (attach_accept.eps_attach_result == LIBLTE_MME_EPS_ATTACH_RESULT_EPS_ONLY) { - //FIXME: Handle t3412.unit - //FIXME: Handle tai_list + // FIXME: Handle t3412.unit + // FIXME: Handle tai_list if (attach_accept.guti_present) { memcpy(&ctxt.guti, &attach_accept.guti.guti, sizeof(LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT)); have_guti = true; @@ -886,30 +892,42 @@ void nas::parse_attach_accept(uint32_t lcid, unique_byte_buffer_t pdu) s_tmsi.m_tmsi = ctxt.guti.m_tmsi; rrc->set_ue_identity(s_tmsi); } - if (attach_accept.lai_present) {} - if (attach_accept.ms_id_present) {} - if (attach_accept.emm_cause_present) {} - if (attach_accept.t3402_present) {} - if (attach_accept.t3412_ext_present) {} - if (attach_accept.t3423_present) {} - if (attach_accept.equivalent_plmns_present) {} - if (attach_accept.emerg_num_list_present) {} - if (attach_accept.eps_network_feature_support_present) {} - if (attach_accept.additional_update_result_present) {} + if (attach_accept.lai_present) { + } + if (attach_accept.ms_id_present) { + } + if (attach_accept.emm_cause_present) { + } + if (attach_accept.t3402_present) { + } + if (attach_accept.t3412_ext_present) { + } + if (attach_accept.t3423_present) { + } + if (attach_accept.equivalent_plmns_present) { + } + if (attach_accept.emerg_num_list_present) { + } + if (attach_accept.eps_network_feature_support_present) { + } + if (attach_accept.additional_update_result_present) { + } LIBLTE_MME_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT act_def_eps_bearer_context_req = {}; liblte_mme_unpack_activate_default_eps_bearer_context_request_msg(&attach_accept.esm_msg, &act_def_eps_bearer_context_req); - if ( (cfg.apn_protocol == "ipv4" && LIBLTE_MME_PDN_TYPE_IPV6 == act_def_eps_bearer_context_req.pdn_addr.pdn_type) || - (cfg.apn_protocol == "ipv6" && LIBLTE_MME_PDN_TYPE_IPV4 == act_def_eps_bearer_context_req.pdn_addr.pdn_type) ){ + if ((cfg.apn_protocol == "ipv4" && LIBLTE_MME_PDN_TYPE_IPV6 == act_def_eps_bearer_context_req.pdn_addr.pdn_type) || + (cfg.apn_protocol == "ipv6" && LIBLTE_MME_PDN_TYPE_IPV4 == act_def_eps_bearer_context_req.pdn_addr.pdn_type)) { nas_log->error("Failed to attach -- Mismatch between PDN protocol and PDN type in attach accept.\n"); return; } - if ( ("ipv4v6" == cfg.apn_protocol && LIBLTE_MME_PDN_TYPE_IPV4 == act_def_eps_bearer_context_req.pdn_addr.pdn_type) || - ("ipv4v6" == cfg.apn_protocol && LIBLTE_MME_PDN_TYPE_IPV6 == act_def_eps_bearer_context_req.pdn_addr.pdn_type) ){ + if (("ipv4v6" == cfg.apn_protocol && + LIBLTE_MME_PDN_TYPE_IPV4 == act_def_eps_bearer_context_req.pdn_addr.pdn_type) || + ("ipv4v6" == cfg.apn_protocol && + LIBLTE_MME_PDN_TYPE_IPV6 == act_def_eps_bearer_context_req.pdn_addr.pdn_type)) { nas_log->warning("Requested IPv4v6, but only received a single PDN address.\n"); - nas_log->warning("EMM Cause: %d\n", attach_accept.emm_cause ); + nas_log->warning("EMM Cause: %d\n", attach_accept.emm_cause); } if (LIBLTE_MME_PDN_TYPE_IPV4 == act_def_eps_bearer_context_req.pdn_addr.pdn_type) { ip_addr = 0; @@ -940,7 +958,7 @@ void nas::parse_attach_accept(uint32_t lcid, unique_byte_buffer_t pdu) err_str)) { nas_log->error("Failed to set gateway address - %s\n", err_str); } - } else if (LIBLTE_MME_PDN_TYPE_IPV6 == act_def_eps_bearer_context_req.pdn_addr.pdn_type){ + } else if (LIBLTE_MME_PDN_TYPE_IPV6 == act_def_eps_bearer_context_req.pdn_addr.pdn_type) { memcpy(ipv6_if_id, act_def_eps_bearer_context_req.pdn_addr.addr, 8); nas_log->info("Network attach successful. APN: %s, IPv6 interface id: %02x%02x:%02x%02x:%02x%02x:%02x%02x\n", act_def_eps_bearer_context_req.apn.apn, @@ -971,9 +989,9 @@ void nas::parse_attach_accept(uint32_t lcid, unique_byte_buffer_t pdu) err_str)) { nas_log->error("Failed to set gateway address - %s\n", err_str); } - } else if (LIBLTE_MME_PDN_TYPE_IPV4V6 == act_def_eps_bearer_context_req.pdn_addr.pdn_type){ + } else if (LIBLTE_MME_PDN_TYPE_IPV4V6 == act_def_eps_bearer_context_req.pdn_addr.pdn_type) { memcpy(ipv6_if_id, act_def_eps_bearer_context_req.pdn_addr.addr, 8); - //IPv6 + // IPv6 nas_log->info("Network attach successful. APN: %s, IPv6 interface id: %02x%02x:%02x%02x:%02x%02x:%02x%02x\n", act_def_eps_bearer_context_req.apn.apn, act_def_eps_bearer_context_req.pdn_addr.addr[0], @@ -1048,18 +1066,18 @@ void nas::parse_attach_accept(uint32_t lcid, unique_byte_buffer_t pdu) } } - //FIXME: Handle the following parameters -// act_def_eps_bearer_context_req.eps_qos.qci -// act_def_eps_bearer_context_req.eps_qos.br_present -// act_def_eps_bearer_context_req.eps_qos.br_ext_present -// act_def_eps_bearer_context_req.apn.apn -// act_def_eps_bearer_context_req.negotiated_qos_present -// act_def_eps_bearer_context_req.llc_sapi_present -// act_def_eps_bearer_context_req.radio_prio_present -// act_def_eps_bearer_context_req.packet_flow_id_present -// act_def_eps_bearer_context_req.apn_ambr_present -// act_def_eps_bearer_context_req.protocol_cnfg_opts_present -// act_def_eps_bearer_context_req.connectivity_type_present + // FIXME: Handle the following parameters + // act_def_eps_bearer_context_req.eps_qos.qci + // act_def_eps_bearer_context_req.eps_qos.br_present + // act_def_eps_bearer_context_req.eps_qos.br_ext_present + // act_def_eps_bearer_context_req.apn.apn + // act_def_eps_bearer_context_req.negotiated_qos_present + // act_def_eps_bearer_context_req.llc_sapi_present + // act_def_eps_bearer_context_req.radio_prio_present + // act_def_eps_bearer_context_req.packet_flow_id_present + // act_def_eps_bearer_context_req.apn_ambr_present + // act_def_eps_bearer_context_req.protocol_cnfg_opts_present + // act_def_eps_bearer_context_req.connectivity_type_present // FIXME: Setup the default EPS bearer context @@ -1122,12 +1140,12 @@ void nas::parse_authentication_request(uint32_t lcid, unique_byte_buffer_t pdu, nas_log->info("MCC=%d, MNC=%d\n", mcc, mnc); uint8_t res[16]; - int res_len = 0; + int res_len = 0; nas_log->debug_hex(auth_req.rand, 16, "Authentication request RAND\n"); nas_log->debug_hex(auth_req.autn, 16, "Authentication request AUTN\n"); - auth_result_t auth_result = usim->generate_authentication_response(auth_req.rand, auth_req.autn, mcc, mnc, - res, &res_len, ctxt.k_asme); - if(LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE == auth_req.nas_ksi.tsc_flag) { + auth_result_t auth_result = + usim->generate_authentication_response(auth_req.rand, auth_req.autn, mcc, mnc, res, &res_len, ctxt.k_asme); + if (LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE == auth_req.nas_ksi.tsc_flag) { ctxt.ksi = auth_req.nas_ksi.nas_ksi; } else { nas_log->error("NAS mapped security context not currently supported\n"); @@ -1197,13 +1215,13 @@ void nas::parse_security_mode_command(uint32_t lcid, unique_byte_buffer_t pdu) ciphering_algorithm_id_text[sec_mode_cmd.selected_nas_sec_algs.type_of_eea], integrity_algorithm_id_text[sec_mode_cmd.selected_nas_sec_algs.type_of_eia]); - if(sec_mode_cmd.nas_ksi.tsc_flag != LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE) { + if (sec_mode_cmd.nas_ksi.tsc_flag != LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE) { nas_log->error("Mapped security context not supported\n"); return; } if (have_ctxt) { - if(sec_mode_cmd.nas_ksi.nas_ksi != ctxt.ksi) { + if (sec_mode_cmd.nas_ksi.nas_ksi != ctxt.ksi) { nas_log->warning("Sending Security Mode Reject due to key set ID mismatch\n"); send_security_mode_reject(LIBLTE_MME_EMM_CAUSE_SECURITY_MODE_REJECTED_UNSPECIFIED); return; @@ -1225,27 +1243,26 @@ void nas::parse_security_mode_command(uint32_t lcid, unique_byte_buffer_t pdu) if (auth_request) { ctxt.rx_count = 0; ctxt.tx_count = 0; - auth_request = false; + auth_request = false; } - ctxt.cipher_algo = (CIPHERING_ALGORITHM_ID_ENUM) sec_mode_cmd.selected_nas_sec_algs.type_of_eea; - ctxt.integ_algo = (INTEGRITY_ALGORITHM_ID_ENUM) sec_mode_cmd.selected_nas_sec_algs.type_of_eia; + ctxt.cipher_algo = (CIPHERING_ALGORITHM_ID_ENUM)sec_mode_cmd.selected_nas_sec_algs.type_of_eea; + ctxt.integ_algo = (INTEGRITY_ALGORITHM_ID_ENUM)sec_mode_cmd.selected_nas_sec_algs.type_of_eia; // Check capabilities - if(!eea_caps[ctxt.cipher_algo] || !eia_caps[ctxt.integ_algo]) { + if (!eea_caps[ctxt.cipher_algo] || !eia_caps[ctxt.integ_algo]) { nas_log->warning("Sending Security Mode Reject due to security capabilities mismatch\n"); send_security_mode_reject(LIBLTE_MME_EMM_CAUSE_UE_SECURITY_CAPABILITIES_MISMATCH); return; } // Generate NAS keys - usim->generate_nas_keys(ctxt.k_asme, k_nas_enc, k_nas_int, - ctxt.cipher_algo, ctxt.integ_algo); + usim->generate_nas_keys(ctxt.k_asme, k_nas_enc, k_nas_int, ctxt.cipher_algo, ctxt.integ_algo); nas_log->info_hex(k_nas_enc, 32, "NAS encryption key - k_nas_enc"); nas_log->info_hex(k_nas_int, 32, "NAS integrity key - k_nas_int"); - nas_log->debug("Generating integrity check. integ_algo:%d, count_dl:%d, lcid:%d\n", - ctxt.integ_algo, ctxt.rx_count, lcid); + nas_log->debug( + "Generating integrity check. integ_algo:%d, count_dl:%d, lcid:%d\n", ctxt.integ_algo, ctxt.rx_count, lcid); if (not integrity_check(pdu.get())) { nas_log->warning("Sending Security Mode Reject due to integrity check failure\n"); @@ -1259,7 +1276,7 @@ void nas::parse_security_mode_command(uint32_t lcid, unique_byte_buffer_t pdu) have_ctxt = true; if (sec_mode_cmd.imeisv_req_present && LIBLTE_MME_IMEISV_REQUESTED == sec_mode_cmd.imeisv_req) { - sec_mode_comp.imeisv_present = true; + sec_mode_comp.imeisv_present = true; sec_mode_comp.imeisv.type_of_id = LIBLTE_MME_MOBILE_ID_TYPE_IMEISV; usim->get_imei_vec(sec_mode_comp.imeisv.imeisv, 15); sec_mode_comp.imeisv.imeisv[14] = 5; @@ -1279,12 +1296,8 @@ void nas::parse_security_mode_command(uint32_t lcid, unique_byte_buffer_t pdu) pcap->write_nas(pdu->msg, pdu->N_bytes); } cipher_encrypt(pdu.get()); - integrity_generate(&k_nas_int[16], - ctxt.tx_count, - SECURITY_DIRECTION_UPLINK, - &pdu->msg[5], - pdu->N_bytes - 5, - &pdu->msg[1]); + integrity_generate( + &k_nas_int[16], ctxt.tx_count, SECURITY_DIRECTION_UPLINK, &pdu->msg[5], pdu->N_bytes - 5, &pdu->msg[1]); nas_log->info("Sending Security Mode Complete nas_current_ctxt.tx_count=%d, RB=%s\n", ctxt.tx_count, rrc->get_rb_name(lcid).c_str()); @@ -1302,8 +1315,8 @@ void nas::parse_service_reject(uint32_t lcid, unique_byte_buffer_t pdu) nas_log->console("Received service reject with EMM cause=0x%x.\n", service_reject.emm_cause); if (service_reject.t3446_present) { - nas_log->info("Received service reject with EMM cause=0x%x and t3446=%d\n", service_reject.emm_cause, - service_reject.t3446); + nas_log->info( + "Received service reject with EMM cause=0x%x and t3446=%d\n", service_reject.emm_cause, service_reject.t3446); } // FIXME: handle NAS backoff-timers correctly @@ -1326,7 +1339,9 @@ void nas::parse_esm_information_request(uint32_t lcid, unique_byte_buffer_t pdu) LIBLTE_MME_ESM_INFORMATION_REQUEST_MSG_STRUCT esm_info_req; liblte_mme_unpack_esm_information_request_msg((LIBLTE_BYTE_MSG_STRUCT*)pdu.get(), &esm_info_req); - nas_log->info("ESM information request received for beaser=%d, transaction_id=%d\n", esm_info_req.eps_bearer_id, esm_info_req.proc_transaction_id); + nas_log->info("ESM information request received for beaser=%d, transaction_id=%d\n", + esm_info_req.eps_bearer_id, + esm_info_req.proc_transaction_id); ctxt.rx_count++; // send response @@ -1526,35 +1541,35 @@ void nas::gen_attach_request(byte_buffer_t* msg) attach_req.ue_network_cap.eia[i] = eia_caps[i]; } - attach_req.ue_network_cap.uea_present = false; // UMTS encryption algos - attach_req.ue_network_cap.uia_present = false; // UMTS integrity algos - attach_req.ue_network_cap.ucs2_present = false; - attach_req.ms_network_cap_present = false; // A/Gb mode (2G) or Iu mode (3G) - attach_req.ue_network_cap.lpp_present = false; - attach_req.ue_network_cap.lcs_present = false; - attach_req.ue_network_cap.onexsrvcc_present = false; - attach_req.ue_network_cap.nf_present = false; - attach_req.old_p_tmsi_signature_present = false; - attach_req.additional_guti_present = false; - attach_req.last_visited_registered_tai_present = false; - attach_req.drx_param_present = false; - attach_req.old_lai_present = false; - attach_req.tmsi_status_present = false; - attach_req.ms_cm2_present = false; - attach_req.ms_cm3_present = false; - attach_req.supported_codecs_present = false; - attach_req.additional_update_type_present = false; + attach_req.ue_network_cap.uea_present = false; // UMTS encryption algos + attach_req.ue_network_cap.uia_present = false; // UMTS integrity algos + attach_req.ue_network_cap.ucs2_present = false; + attach_req.ms_network_cap_present = false; // A/Gb mode (2G) or Iu mode (3G) + attach_req.ue_network_cap.lpp_present = false; + attach_req.ue_network_cap.lcs_present = false; + attach_req.ue_network_cap.onexsrvcc_present = false; + attach_req.ue_network_cap.nf_present = false; + attach_req.old_p_tmsi_signature_present = false; + attach_req.additional_guti_present = false; + attach_req.last_visited_registered_tai_present = false; + attach_req.drx_param_present = false; + attach_req.old_lai_present = false; + attach_req.tmsi_status_present = false; + attach_req.ms_cm2_present = false; + attach_req.ms_cm3_present = false; + attach_req.supported_codecs_present = false; + attach_req.additional_update_type_present = false; attach_req.voice_domain_pref_and_ue_usage_setting_present = false; - attach_req.device_properties_present = false; - attach_req.old_guti_type_present = false; + attach_req.device_properties_present = false; + attach_req.old_guti_type_present = false; // ESM message (PDN connectivity request) for first default bearer gen_pdn_connectivity_request(&attach_req.esm_msg); // GUTI or IMSI attach - if(have_guti && have_ctxt) { - attach_req.tmsi_status_present = true; - attach_req.tmsi_status = LIBLTE_MME_TMSI_STATUS_VALID_TMSI; + if (have_guti && have_ctxt) { + attach_req.tmsi_status_present = true; + attach_req.tmsi_status = LIBLTE_MME_TMSI_STATUS_VALID_TMSI; attach_req.eps_mobile_id.type_of_id = LIBLTE_MME_EPS_MOBILE_ID_TYPE_GUTI; memcpy(&attach_req.eps_mobile_id.guti, &ctxt.guti, sizeof(LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT)); attach_req.old_guti_type = LIBLTE_MME_GUTI_TYPE_NATIVE; @@ -1563,25 +1578,25 @@ void nas::gen_attach_request(byte_buffer_t* msg) attach_req.nas_ksi.nas_ksi = ctxt.ksi; nas_log->info("Requesting GUTI attach. " "m_tmsi: %x, mcc: %x, mnc: %x, mme_group_id: %x, mme_code: %x\n", - ctxt.guti.m_tmsi, ctxt.guti.mcc, ctxt.guti.mnc, ctxt.guti.mme_group_id, ctxt.guti.mme_code); + ctxt.guti.m_tmsi, + ctxt.guti.mcc, + ctxt.guti.mnc, + ctxt.guti.mme_group_id, + ctxt.guti.mme_code); liblte_mme_pack_attach_request_msg( &attach_req, LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY, ctxt.tx_count, (LIBLTE_BYTE_MSG_STRUCT*)msg); // Add MAC if (msg->N_bytes > 5) { - integrity_generate(&k_nas_int[16], - ctxt.tx_count, - SECURITY_DIRECTION_UPLINK, - &msg->msg[5], - msg->N_bytes - 5, - &msg->msg[1]); + integrity_generate( + &k_nas_int[16], ctxt.tx_count, SECURITY_DIRECTION_UPLINK, &msg->msg[5], msg->N_bytes - 5, &msg->msg[1]); } else { nas_log->error("Invalid PDU size %d\n", msg->N_bytes); } } else { attach_req.eps_mobile_id.type_of_id = LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI; - attach_req.nas_ksi.tsc_flag = LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE; - attach_req.nas_ksi.nas_ksi = 0; + attach_req.nas_ksi.tsc_flag = LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE; + attach_req.nas_ksi.nas_ksi = 0; usim->get_imsi_vec(attach_req.eps_mobile_id.imsi, 15); nas_log->info("Requesting IMSI attach (IMSI=%s)\n", usim->get_imsi_str().c_str()); liblte_mme_pack_attach_request_msg(&attach_req, (LIBLTE_BYTE_MSG_STRUCT*)msg); @@ -1620,12 +1635,7 @@ void nas::gen_service_request(byte_buffer_t* msg) msg->N_bytes++; uint8_t mac[4]; - integrity_generate(&k_nas_int[16], - ctxt.tx_count, - SECURITY_DIRECTION_UPLINK, - &msg->msg[0], - 2, - &mac[0]); + integrity_generate(&k_nas_int[16], ctxt.tx_count, SECURITY_DIRECTION_UPLINK, &msg->msg[0], 2, &mac[0]); // Set the short MAC msg->msg[2] = mac[2]; msg->N_bytes++; @@ -1639,16 +1649,17 @@ void nas::gen_service_request(byte_buffer_t* msg) ctxt.tx_count++; } -void nas::gen_pdn_connectivity_request(LIBLTE_BYTE_MSG_STRUCT *msg) { +void nas::gen_pdn_connectivity_request(LIBLTE_BYTE_MSG_STRUCT* msg) +{ LIBLTE_MME_PDN_CONNECTIVITY_REQUEST_MSG_STRUCT pdn_con_req; ZERO_OBJECT(pdn_con_req); nas_log->info("Generating PDN Connectivity Request\n"); // Set the PDN con req parameters - pdn_con_req.eps_bearer_id = 0x00; // Unassigned bearer ID + pdn_con_req.eps_bearer_id = 0x00; // Unassigned bearer ID pdn_con_req.proc_transaction_id = 0x01; // First transaction ID - pdn_con_req.request_type = LIBLTE_MME_REQUEST_TYPE_INITIAL_REQUEST; + pdn_con_req.request_type = LIBLTE_MME_REQUEST_TYPE_INITIAL_REQUEST; pdn_con_req.apn_present = false; // Set PDN protocol type @@ -1673,17 +1684,18 @@ void nas::gen_pdn_connectivity_request(LIBLTE_BYTE_MSG_STRUCT *msg) { } else { // request ESM info transfer is APN is specified pdn_con_req.esm_info_transfer_flag_present = true; - pdn_con_req.esm_info_transfer_flag = LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_REQUIRED; + pdn_con_req.esm_info_transfer_flag = LIBLTE_MME_ESM_INFO_TRANSFER_FLAG_REQUIRED; } pdn_con_req.protocol_cnfg_opts_present = false; - pdn_con_req.device_properties_present = false; + pdn_con_req.device_properties_present = false; // Pack the message liblte_mme_pack_pdn_connectivity_request_msg(&pdn_con_req, msg); } -void nas::send_security_mode_reject(uint8_t cause) { +void nas::send_security_mode_reject(uint8_t cause) +{ unique_byte_buffer_t msg = srslte::allocate_unique_buffer(*pool, true); if (!msg) { nas_log->error("Fatal Error: Couldn't allocate PDU in send_security_mode_reject().\n"); @@ -1711,10 +1723,10 @@ void nas::send_detach_request(bool switch_off) LIBLTE_MME_DETACH_REQUEST_MSG_STRUCT detach_request; bzero(&detach_request, sizeof(detach_request)); if (switch_off) { - detach_request.detach_type.switch_off = 1; + detach_request.detach_type.switch_off = 1; detach_request.detach_type.type_of_detach = LIBLTE_MME_SO_FLAG_SWITCH_OFF; } else { - detach_request.detach_type.switch_off = 0; + detach_request.detach_type.switch_off = 0; detach_request.detach_type.type_of_detach = LIBLTE_MME_TOD_UL_EPS_DETACH; } @@ -1722,8 +1734,8 @@ void nas::send_detach_request(bool switch_off) if (have_guti && have_ctxt) { detach_request.eps_mobile_id.type_of_id = LIBLTE_MME_EPS_MOBILE_ID_TYPE_GUTI; memcpy(&detach_request.eps_mobile_id.guti, &ctxt.guti, sizeof(LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT)); - detach_request.nas_ksi.tsc_flag = LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE; - detach_request.nas_ksi.nas_ksi = ctxt.ksi; + detach_request.nas_ksi.tsc_flag = LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE; + detach_request.nas_ksi.nas_ksi = ctxt.ksi; nas_log->info("Sending detach request with GUTI\n"); // If sent as an Initial UE message, it cannot be chiphered liblte_mme_pack_detach_request_msg(&detach_request, rrc->is_connected() ? LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED @@ -1740,20 +1752,16 @@ void nas::send_detach_request(bool switch_off) if (rrc->is_connected()) { cipher_encrypt(pdu.get()); } - integrity_generate(&k_nas_int[16], - ctxt.tx_count, - SECURITY_DIRECTION_UPLINK, - &pdu->msg[5], - pdu->N_bytes - 5, - &pdu->msg[1]); + integrity_generate( + &k_nas_int[16], ctxt.tx_count, SECURITY_DIRECTION_UPLINK, &pdu->msg[5], pdu->N_bytes - 5, &pdu->msg[1]); ctxt.tx_count++; } else { nas_log->error("Invalid PDU size %d\n", pdu->N_bytes); } } else { detach_request.eps_mobile_id.type_of_id = LIBLTE_MME_EPS_MOBILE_ID_TYPE_IMSI; - detach_request.nas_ksi.tsc_flag = LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE; - detach_request.nas_ksi.nas_ksi = 0; + detach_request.nas_ksi.tsc_flag = LIBLTE_MME_TYPE_OF_SECURITY_CONTEXT_FLAG_NATIVE; + detach_request.nas_ksi.nas_ksi = 0; usim->get_imsi_vec(detach_request.eps_mobile_id.imsi, 15); nas_log->info("Sending detach request with IMSI\n"); liblte_mme_pack_detach_request_msg( @@ -1837,12 +1845,8 @@ void nas::send_detach_accept() // Encrypt and add MAC if (pdu->N_bytes > 5) { cipher_encrypt(pdu.get()); - integrity_generate(&k_nas_int[16], - ctxt.tx_count, - SECURITY_DIRECTION_UPLINK, - &pdu->msg[5], - pdu->N_bytes - 5, - &pdu->msg[1]); + integrity_generate( + &k_nas_int[16], ctxt.tx_count, SECURITY_DIRECTION_UPLINK, &pdu->msg[5], pdu->N_bytes - 5, &pdu->msg[1]); } else { nas_log->error("Invalid PDU size %d\n", pdu->N_bytes); } @@ -1851,8 +1855,8 @@ void nas::send_detach_accept() rrc->write_sdu(std::move(pdu)); } - -void nas::send_authentication_response(const uint8_t* res, const size_t res_len, const uint8_t sec_hdr_type) { +void nas::send_authentication_response(const uint8_t* res, const size_t res_len, const uint8_t sec_hdr_type) +{ unique_byte_buffer_t pdu = srslte::allocate_unique_buffer(*pool, true); if (!pdu) { nas_log->error("Fatal Error: Couldn't allocate PDU in send_authentication_response().\n"); @@ -1875,20 +1879,16 @@ void nas::send_authentication_response(const uint8_t* res, const size_t res_len, if (sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED && pdu->N_bytes > 5) { cipher_encrypt(pdu.get()); - integrity_generate(&k_nas_int[16], - ctxt.tx_count, - SECURITY_DIRECTION_UPLINK, - &pdu->msg[5], - pdu->N_bytes - 5, - &pdu->msg[1]); + integrity_generate( + &k_nas_int[16], ctxt.tx_count, SECURITY_DIRECTION_UPLINK, &pdu->msg[5], pdu->N_bytes - 5, &pdu->msg[1]); } nas_log->info("Sending Authentication Response\n"); rrc->write_sdu(std::move(pdu)); } - -void nas::send_authentication_failure(const uint8_t cause, const uint8_t* auth_fail_param) { +void nas::send_authentication_failure(const uint8_t cause, const uint8_t* auth_fail_param) +{ unique_byte_buffer_t msg = srslte::allocate_unique_buffer(*pool, true); if (!msg) { nas_log->error("Fatal Error: Couldn't allocate PDU in send_authentication_failure().\n"); @@ -1954,7 +1954,8 @@ void nas::send_identity_response(const uint8 id_type, const uint8_t sec_hdr_type ctxt.tx_count++; } -void nas::send_service_request() { +void nas::send_service_request() +{ unique_byte_buffer_t msg = srslte::allocate_unique_buffer(*pool, true); if (!msg) { nas_log->error("Fatal Error: Couldn't allocate PDU in send_service_request().\n"); @@ -1969,12 +1970,7 @@ void nas::send_service_request() { msg->N_bytes++; uint8_t mac[4]; - integrity_generate(&k_nas_int[16], - ctxt.tx_count, - SECURITY_DIRECTION_UPLINK, - &msg->msg[0], - 2, - &mac[0]); + integrity_generate(&k_nas_int[16], ctxt.tx_count, SECURITY_DIRECTION_UPLINK, &msg->msg[0], 2, &mac[0]); // Set the short MAC msg->msg[2] = mac[2]; msg->N_bytes++; @@ -1990,10 +1986,11 @@ void nas::send_service_request() { ctxt.tx_count++; } -void nas::send_esm_information_response(const uint8 proc_transaction_id) { +void nas::send_esm_information_response(const uint8 proc_transaction_id) +{ LIBLTE_MME_ESM_INFORMATION_RESPONSE_MSG_STRUCT esm_info_resp; esm_info_resp.proc_transaction_id = proc_transaction_id; - esm_info_resp.eps_bearer_id = 0; // respone shall always have no bearer assigned + esm_info_resp.eps_bearer_id = 0; // respone shall always have no bearer assigned if (cfg.apn_name == "") { esm_info_resp.apn_present = false; @@ -2044,17 +2041,17 @@ void nas::send_esm_information_response(const uint8 proc_transaction_id) { // Generate response value uint16_t resp_val_len = 16 /* MD5 len */ + 1 /* ID */ + cfg.apn_pass.length(); - uint8_t resp_val[resp_val_len]; + uint8_t resp_val[resp_val_len]; resp_val[0] = chap_id; // add secret for (size_t i = 0; i < cfg.apn_pass.length(); i++) { const char* pass = cfg.apn_pass.c_str(); - resp_val[1 + i] = pass[i]; + resp_val[1 + i] = pass[i]; } // copy original challenge behind secret - uint8_t *chal_val = &challenge[5]; + uint8_t* chal_val = &challenge[5]; memcpy(&resp_val[1 + cfg.apn_pass.length()], chal_val, 16); // Compute MD5 of resp_val and add to response @@ -2067,7 +2064,7 @@ void nas::send_esm_information_response(const uint8 proc_transaction_id) { } // Add challenge and response to ESM info response - esm_info_resp.protocol_cnfg_opts_present = true; + esm_info_resp.protocol_cnfg_opts_present = true; esm_info_resp.protocol_cnfg_opts.opt[0].id = LIBLTE_MME_CONFIGURATION_PROTOCOL_OPTIONS_CHAP; memcpy(esm_info_resp.protocol_cnfg_opts.opt[0].contents, challenge, sizeof(challenge)); esm_info_resp.protocol_cnfg_opts.opt[0].len = sizeof(challenge); @@ -2075,7 +2072,7 @@ void nas::send_esm_information_response(const uint8 proc_transaction_id) { esm_info_resp.protocol_cnfg_opts.opt[1].id = LIBLTE_MME_CONFIGURATION_PROTOCOL_OPTIONS_CHAP; memcpy(esm_info_resp.protocol_cnfg_opts.opt[1].contents, response, sizeof(response)); esm_info_resp.protocol_cnfg_opts.opt[1].len = sizeof(response); - esm_info_resp.protocol_cnfg_opts.N_opts = 2; + esm_info_resp.protocol_cnfg_opts.N_opts = 2; } else { esm_info_resp.protocol_cnfg_opts_present = false; } @@ -2100,12 +2097,8 @@ void nas::send_esm_information_response(const uint8 proc_transaction_id) { cipher_encrypt(pdu.get()); if (pdu->N_bytes > 5) { - integrity_generate(&k_nas_int[16], - ctxt.tx_count, - SECURITY_DIRECTION_UPLINK, - &pdu->msg[5], - pdu->N_bytes - 5, - &pdu->msg[1]); + integrity_generate( + &k_nas_int[16], ctxt.tx_count, SECURITY_DIRECTION_UPLINK, &pdu->msg[5], pdu->N_bytes - 5, &pdu->msg[1]); } else { nas_log->error("Invalid PDU size %d\n", pdu->N_bytes); return; @@ -2381,35 +2374,34 @@ bool nas::write_ctxt_file(nas_sec_ctxt ctxt_) /********************************************************************* * Conversion helpers ********************************************************************/ -std::string nas::hex_to_string(uint8_t *hex, int size) +std::string nas::hex_to_string(uint8_t* hex, int size) { std::stringstream ss; ss << std::hex << std::setfill('0'); - for(int i=0; i(hex[i]); } return ss.str(); } -bool nas::string_to_hex(std::string hex_str, uint8_t *hex, uint32_t len) +bool nas::string_to_hex(std::string hex_str, uint8_t* hex, uint32_t len) { - static const char* const lut = "0123456789abcdef"; - uint32_t str_len = hex_str.length(); - if(str_len & 1) { + static const char* const lut = "0123456789abcdef"; + uint32_t str_len = hex_str.length(); + if (str_len & 1) { return false; // uneven hex_str length } - if(str_len > len*2) { + if (str_len > len * 2) { return false; // not enough space in hex buffer } - for(uint32_t i=0; ifull_net_name_present) { + if (info->full_net_name_present) { ss << info->full_net_name.name; } - if(info->short_net_name_present) { + if (info->short_net_name_present) { ss << " (" << info->short_net_name.name << ")"; } - if(info->utc_and_local_time_zone_present) { + if (info->utc_and_local_time_zone_present) { ss << " " << (int)info->utc_and_local_time_zone.day; ss << "/" << (int)info->utc_and_local_time_zone.month; ss << "/" << (int)info->utc_and_local_time_zone.year; @@ -2440,5 +2432,4 @@ std::string nas::emm_info_str(LIBLTE_MME_EMM_INFORMATION_MSG_STRUCT *info) return ss.str(); } - } // namespace srsue diff --git a/srsue/src/stack/upper/pcsc_usim.cc b/srsue/src/stack/upper/pcsc_usim.cc index 226338869..63acf936a 100644 --- a/srsue/src/stack/upper/pcsc_usim.cc +++ b/srsue/src/stack/upper/pcsc_usim.cc @@ -56,7 +56,7 @@ int pcsc_usim::init(usim_args_t* args) } // Read IMSI from SIM card - char tmp[15]; + char tmp[15]; size_t tmp_len = 15; // set to max IMSI length if (sc.get_imsi(tmp, &tmp_len)) { log->error("Error reading IMSI from SIM.\n"); @@ -65,11 +65,10 @@ int pcsc_usim::init(usim_args_t* args) imsi_str.assign(tmp, tmp_len); // Check extracted IMSI and convert - if(15 == imsi_str.length()) { - const char *imsi_c = imsi_str.c_str(); - imsi = 0; - for(int i = 0; i < 15; i++) - { + if (15 == imsi_str.length()) { + const char* imsi_c = imsi_str.c_str(); + imsi = 0; + for (int i = 0; i < 15; i++) { imsi *= 10; imsi += imsi_c[i] - '0'; } @@ -80,11 +79,10 @@ int pcsc_usim::init(usim_args_t* args) } // Check IMEI - if(15 == args->imei.length()) { - const char *imei_c = args->imei.c_str(); - imei = 0; - for(int i = 0; i < 15; i++) - { + if (15 == args->imei.length()) { + const char* imei_c = args->imei.c_str(); + imei = 0; + for (int i = 0; i < 15; i++) { imei *= 10; imei += imei_c[i] - '0'; } @@ -99,14 +97,12 @@ int pcsc_usim::init(usim_args_t* args) log->debug("MNC length %d\n", mnc_length); initiated = true; - ret = SRSLTE_SUCCESS; + ret = SRSLTE_SUCCESS; return ret; } -void pcsc_usim::stop() -{} - +void pcsc_usim::stop() {} /******************************************************************************* NAS interface @@ -128,13 +124,13 @@ bool pcsc_usim::get_imsi_vec(uint8_t* imsi_, uint32_t n) return false; } - if(NULL == imsi_ || n < 15) { + if (NULL == imsi_ || n < 15) { log->error("Invalid parameters to get_imsi_vec"); return false; } uint64_t temp = imsi; - for(int i=14;i>=0;i--) { + for (int i = 14; i >= 0; i--) { imsi_[i] = temp % 10; temp /= 10; } @@ -148,14 +144,13 @@ bool pcsc_usim::get_imei_vec(uint8_t* imei_, uint32_t n) return false; } - if(NULL == imei_ || n < 15) { + if (NULL == imei_ || n < 15) { log->error("Invalid parameters to get_imei_vec"); return false; } uint64 temp = imei; - for(int i=14;i>=0;i--) - { + for (int i = 14; i >= 0; i--) { imei_[i] = temp % 10; temp /= 10; } @@ -175,12 +170,12 @@ bool pcsc_usim::get_home_plmn_id(srslte::plmn_id_t* home_plmn_id) std::ostringstream plmn_str; int mcc_len = 3; - for (int i=0;idebug_hex(ak, AK_LEN, "AK:\n"); log->debug_hex(sqn, SQN_LEN, "SQN:\n"); log->debug("mcc=%d, mnc=%d\n", mcc, mnc); - security_generate_k_asme( ck, - ik, - ak, - sqn, - mcc, - mnc, - k_asme); + security_generate_k_asme(ck, ik, ak, sqn, mcc, mnc, k_asme); log->info_hex(k_asme, KEY_LEN, "K_ASME:\n"); ret = AUTH_OK; @@ -256,11 +245,11 @@ auth_result_t pcsc_usim::generate_authentication_response(uint8_t *rand, return ret; } -void pcsc_usim::generate_nas_keys(uint8_t *k_asme, - uint8_t *k_nas_enc, - uint8_t *k_nas_int, - CIPHERING_ALGORITHM_ID_ENUM cipher_algo, - INTEGRITY_ALGORITHM_ID_ENUM integ_algo) +void pcsc_usim::generate_nas_keys(uint8_t* k_asme, + uint8_t* k_nas_enc, + uint8_t* k_nas_int, + CIPHERING_ALGORITHM_ID_ENUM cipher_algo, + INTEGRITY_ALGORITHM_ID_ENUM integ_algo) { if (!initiated) { ERROR("USIM not initiated!\n"); @@ -268,25 +257,21 @@ void pcsc_usim::generate_nas_keys(uint8_t *k_asme, } // Generate K_nas_enc and K_nas_int - security_generate_k_nas( k_asme, - cipher_algo, - integ_algo, - k_nas_enc, - k_nas_int); + security_generate_k_nas(k_asme, cipher_algo, integ_algo, k_nas_enc, k_nas_int); } /******************************************************************************* RRC interface *******************************************************************************/ -void pcsc_usim::generate_as_keys(uint8_t *k_asme, - uint32_t count_ul, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int, - uint8_t *k_up_enc, - uint8_t *k_up_int, - CIPHERING_ALGORITHM_ID_ENUM cipher_algo, - INTEGRITY_ALGORITHM_ID_ENUM integ_algo) +void pcsc_usim::generate_as_keys(uint8_t* k_asme, + uint32_t count_ul, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int, + uint8_t* k_up_enc, + uint8_t* k_up_int, + CIPHERING_ALGORITHM_ID_ENUM cipher_algo, + INTEGRITY_ALGORITHM_ID_ENUM integ_algo) { if (!initiated) { ERROR("USIM not initiated!\n"); @@ -294,62 +279,50 @@ void pcsc_usim::generate_as_keys(uint8_t *k_asme, } // Generate K_enb - security_generate_k_enb( k_asme, - count_ul, - k_enb); + security_generate_k_enb(k_asme, count_ul, k_enb); memcpy(this->k_asme, k_asme, 32); // Generate K_rrc_enc and K_rrc_int - security_generate_k_rrc( k_enb, - cipher_algo, - integ_algo, - k_rrc_enc, - k_rrc_int); + security_generate_k_rrc(k_enb, cipher_algo, integ_algo, k_rrc_enc, k_rrc_int); // Generate K_up_enc and K_up_int - security_generate_k_up( k_enb, - cipher_algo, - integ_algo, - k_up_enc, - k_up_int); + security_generate_k_up(k_enb, cipher_algo, integ_algo, k_up_enc, k_up_int); current_ncc = 0; } -void pcsc_usim::generate_as_keys_ho(uint32_t pci, - uint32_t earfcn, - int ncc, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int, - uint8_t *k_up_enc, - uint8_t *k_up_int, - CIPHERING_ALGORITHM_ID_ENUM cipher_algo, - INTEGRITY_ALGORITHM_ID_ENUM integ_algo) +void pcsc_usim::generate_as_keys_ho(uint32_t pci, + uint32_t earfcn, + int ncc, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int, + uint8_t* k_up_enc, + uint8_t* k_up_int, + CIPHERING_ALGORITHM_ID_ENUM cipher_algo, + INTEGRITY_ALGORITHM_ID_ENUM integ_algo) { if (!initiated) { ERROR("USIM not initiated!\n"); return; } - uint8_t *enb_star_key = k_enb; + uint8_t* enb_star_key = k_enb; if (ncc < 0) { ncc = current_ncc; } // Generate successive NH - while(current_ncc != (uint32_t) ncc) { - uint8_t *sync = NULL; + while (current_ncc != (uint32_t)ncc) { + uint8_t* sync = NULL; if (current_ncc) { sync = nh; } else { sync = k_enb; } // Generate NH - security_generate_nh(k_asme, - sync, - nh); + security_generate_nh(k_asme, sync, nh); current_ncc++; if (current_ncc == 7) { @@ -359,45 +332,33 @@ void pcsc_usim::generate_as_keys_ho(uint32_t pci, } // Generate K_enb - security_generate_k_enb_star( enb_star_key, - pci, - earfcn, - k_enb_star); + security_generate_k_enb_star(enb_star_key, pci, earfcn, k_enb_star); // K_enb becomes K_enb* memcpy(k_enb, k_enb_star, 32); // Generate K_rrc_enc and K_rrc_int - security_generate_k_rrc( k_enb, - cipher_algo, - integ_algo, - k_rrc_enc, - k_rrc_int); + security_generate_k_rrc(k_enb, cipher_algo, integ_algo, k_rrc_enc, k_rrc_int); // Generate K_up_enc and K_up_int - security_generate_k_up( k_enb, - cipher_algo, - integ_algo, - k_up_enc, - k_up_int); + security_generate_k_up(k_enb, cipher_algo, integ_algo, k_up_enc, k_up_int); } /******************************************************************************* Helpers *******************************************************************************/ - /********************************* * PC/SC class ********************************/ // return 0 if initialization was successfull, -1 otherwies -int pcsc_usim::scard::init(usim_args_t *args, srslte::log *log_) +int pcsc_usim::scard::init(usim_args_t* args, srslte::log* log_) { - int ret_value = SRSLTE_ERROR; - uint pos = 0; // SC reader + int ret_value = SRSLTE_ERROR; + uint pos = 0; // SC reader bool reader_found = false; - //int transaction = 1; + // int transaction = 1; size_t blen; log = log_; @@ -409,13 +370,13 @@ int pcsc_usim::scard::init(usim_args_t *args, srslte::log *log_) } unsigned long len = 0; - ret = SCardListReaders(scard_context, NULL, NULL, &len); + ret = SCardListReaders(scard_context, NULL, NULL, &len); if (ret != SCARD_S_SUCCESS) { log->error("SCardListReaders(): %s\n", pcsc_stringify_error(ret)); return ret_value; } - char *readers = (char *)malloc(len); + char* readers = (char*)malloc(len); if (readers == NULL) { log->error("Malloc failed\n"); return ret_value; @@ -431,26 +392,30 @@ int pcsc_usim::scard::init(usim_args_t *args, srslte::log *log_) return ret_value; } - /* readers: NULL-separated list of reader names, and terminating NULL */ pos = 0; - while (pos < len-1) { - log->info("Available Card Reader: %s\n", &readers[pos]); - while (readers[pos] != '\0' && pos < len) { - pos++; - } - pos++; // skip separator + while (pos < len - 1) { + log->info("Available Card Reader: %s\n", &readers[pos]); + while (readers[pos] != '\0' && pos < len) { + pos++; + } + pos++; // skip separator } reader_found = false; - pos = 0; + pos = 0; // If no reader specified, test all available readers for SIM cards. Otherwise consider specified reader only. if (args->reader.length() == 0) { while (pos < len && !reader_found) { log->info("Trying Card Reader: %s\n", &readers[pos]); // Connect to card - ret = SCardConnect(scard_context, &readers[pos], SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &scard_handle, &scard_protocol); + ret = SCardConnect(scard_context, + &readers[pos], + SCARD_SHARE_SHARED, + SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, + &scard_handle, + &scard_protocol); if (ret == SCARD_S_SUCCESS) { reader_found = true; } else { @@ -462,7 +427,7 @@ int pcsc_usim::scard::init(usim_args_t *args, srslte::log *log_) log->info("Failed to use Card Reader: %s\n", &readers[pos]); // proceed to next reader - while (pos < len && readers[pos] != '\0' ) { + while (pos < len && readers[pos] != '\0') { pos++; } pos++; // skip separator @@ -476,7 +441,7 @@ int pcsc_usim::scard::init(usim_args_t *args, srslte::log *log_) log->info("Card Reader found: %s\n", args->reader.c_str()); } else { // next reader - while (pos < len && readers[pos] != '\0' ) { + while (pos < len && readers[pos] != '\0') { pos++; } pos++; // skip separator @@ -485,7 +450,12 @@ int pcsc_usim::scard::init(usim_args_t *args, srslte::log *log_) if (!reader_found) { log->error("Cannot find reader: %s\n", args->reader.c_str()); } else { - ret = SCardConnect(scard_context, &readers[pos], SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &scard_handle, &scard_protocol); + ret = SCardConnect(scard_context, + &readers[pos], + SCARD_SHARE_SHARED, + SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, + &scard_handle, + &scard_protocol); if (ret == SCARD_S_SUCCESS) { // successfully connected to card } else { @@ -504,7 +474,9 @@ int pcsc_usim::scard::init(usim_args_t *args, srslte::log *log_) readers = NULL; log->info("Card=0x%x active_protocol=%lu (%s)\n", - (unsigned int)scard_handle, (unsigned long)scard_protocol, scard_protocol == SCARD_PROTOCOL_T0 ? "T0" : "T1"); + (unsigned int)scard_handle, + (unsigned long)scard_protocol, + scard_protocol == SCARD_PROTOCOL_T0 ? "T0" : "T1"); ret = SCardBeginTransaction(scard_handle); if (ret != SCARD_S_SUCCESS) { @@ -537,7 +509,7 @@ int pcsc_usim::scard::init(usim_args_t *args, srslte::log *log_) } } else { unsigned char aid[32]; - int aid_len; + int aid_len; aid_len = get_aid(aid, sizeof(aid)); if (aid_len < 0) { @@ -593,7 +565,7 @@ int pcsc_usim::scard::init(usim_args_t *args, srslte::log *log_) ret = SCardEndTransaction(scard_handle, SCARD_LEAVE_CARD); if (ret != SCARD_S_SUCCESS) { - log->debug("SCARD: Could not end transaction: 0x%x\n", (unsigned int) ret); + log->debug("SCARD: Could not end transaction: 0x%x\n", (unsigned int)ret); goto clean_exit; } @@ -607,19 +579,23 @@ clean_exit: return ret_value; } - -int pcsc_usim::scard::_select_file(unsigned short file_id, unsigned char *buf, size_t *buf_len, sim_types_t sim_type, unsigned char *aid, size_t aidlen) +int pcsc_usim::scard::_select_file(unsigned short file_id, + unsigned char* buf, + size_t* buf_len, + sim_types_t sim_type, + unsigned char* aid, + size_t aidlen) { - long ret; + long ret; unsigned char resp[3]; - unsigned char cmd[50] = { SIM_CMD_SELECT }; - int cmdlen; - unsigned char get_resp[5] = { SIM_CMD_GET_RESPONSE }; - size_t len, rlen; + unsigned char cmd[50] = {SIM_CMD_SELECT}; + int cmdlen; + unsigned char get_resp[5] = {SIM_CMD_GET_RESPONSE}; + size_t len, rlen; if (sim_type == SCARD_USIM) { - cmd[0] = USIM_CLA; - cmd[3] = 0x04; + cmd[0] = USIM_CLA; + cmd[3] = 0x04; get_resp[0] = USIM_CLA; } @@ -628,7 +604,7 @@ int pcsc_usim::scard::_select_file(unsigned short file_id, unsigned char *buf, s log->debug_hex(aid, aidlen, "SCARD: select file by AID"); if (5 + aidlen > sizeof(cmd)) return -1; - cmd[2] = 0x04; /* Select by AID */ + cmd[2] = 0x04; /* Select by AID */ cmd[4] = aidlen; /* len */ memcpy(cmd + 5, aid, aidlen); cmdlen = 5 + aidlen; @@ -670,7 +646,7 @@ int pcsc_usim::scard::_select_file(unsigned short file_id, unsigned char *buf, s log->debug("SCARD: trying to get response (%d bytes)\n", resp[1]); rlen = *buf_len; - ret = transmit(get_resp, sizeof(get_resp), buf, &rlen); + ret = transmit(get_resp, sizeof(get_resp), buf, &rlen); if (ret == SCARD_S_SUCCESS) { *buf_len = resp[1] < rlen ? resp[1] : rlen; return 0; @@ -680,25 +656,25 @@ int pcsc_usim::scard::_select_file(unsigned short file_id, unsigned char *buf, s return -1; } - -int pcsc_usim::scard::select_file(unsigned short file_id,unsigned char *buf, size_t *buf_len) +int pcsc_usim::scard::select_file(unsigned short file_id, unsigned char* buf, size_t* buf_len) { return _select_file(file_id, buf, buf_len, sim_type, NULL, 0); } - -long pcsc_usim::scard::transmit(unsigned char *_send, size_t send_len, unsigned char *_recv, size_t *recv_len) +long pcsc_usim::scard::transmit(unsigned char* _send, size_t send_len, unsigned char* _recv, size_t* recv_len) { - long ret; + long ret; unsigned long rlen; log->debug_hex(_send, send_len, "SCARD: scard_transmit: send\n"); - rlen = *recv_len; - ret = SCardTransmit(scard_handle, - scard_protocol == SCARD_PROTOCOL_T1 ? - SCARD_PCI_T1 : SCARD_PCI_T0, - _send, (unsigned long) send_len, - NULL, _recv, &rlen); + rlen = *recv_len; + ret = SCardTransmit(scard_handle, + scard_protocol == SCARD_PROTOCOL_T1 ? SCARD_PCI_T1 : SCARD_PCI_T0, + _send, + (unsigned long)send_len, + NULL, + _recv, + &rlen); *recv_len = rlen; if (ret == SCARD_S_SUCCESS) { log->debug_hex(_recv, rlen, "SCARD: SCardTransmit: recv\n"); @@ -708,7 +684,7 @@ long pcsc_usim::scard::transmit(unsigned char *_send, size_t send_len, unsigned return ret; } -int pcsc_usim::scard::pin_needed(unsigned char *hdr, size_t hlen) +int pcsc_usim::scard::pin_needed(unsigned char* hdr, size_t hlen) { if (sim_type == SCARD_GSM_SIM) { if (hlen > SCARD_CHV1_OFFSET && !(hdr[SCARD_CHV1_OFFSET] & SCARD_CHV1_FLAG)) @@ -730,15 +706,13 @@ int pcsc_usim::scard::pin_needed(unsigned char *hdr, size_t hlen) return -1; } - - int pcsc_usim::scard::get_pin_retry_counter() { - long ret; + long ret; unsigned char resp[3]; - unsigned char cmd[5] = { SIM_CMD_VERIFY_CHV1 }; - size_t len; - uint16_t val; + unsigned char cmd[5] = {SIM_CMD_VERIFY_CHV1}; + size_t len; + uint16_t val; log->info("SCARD: fetching PIN retry counter\n"); @@ -769,9 +743,7 @@ int pcsc_usim::scard::get_pin_retry_counter() return 0; } - - -int pcsc_usim::scard::get_aid(unsigned char *aid, size_t maxlen) +int pcsc_usim::scard::get_aid(unsigned char* aid, size_t maxlen) { int rlen, rec; struct efdir { @@ -781,14 +753,14 @@ int pcsc_usim::scard::get_aid(unsigned char *aid, size_t maxlen) unsigned char aid_len; unsigned char rid[5]; unsigned char appl_code[2]; /* 0x1002 for 3G USIM */ - } *efdir; + } * efdir; unsigned char buf[127], *aid_pos; - size_t blen; - unsigned int aid_len = 0; + size_t blen; + unsigned int aid_len = 0; - efdir = (struct efdir *) buf; + efdir = (struct efdir*)buf; aid_pos = &buf[4]; - blen = sizeof(buf); + blen = sizeof(buf); if (select_file(SCARD_FILE_EF_DIR, buf, &blen)) { log->debug("SCARD: Failed to read EF_DIR\n"); return -1; @@ -802,7 +774,7 @@ int pcsc_usim::scard::get_aid(unsigned char *aid, size_t maxlen) return -1; } blen = sizeof(buf); - if (rlen > (int) blen) { + if (rlen > (int)blen) { log->debug("SCARD: Too long EF_DIR record\n"); return -1; } @@ -859,9 +831,9 @@ int pcsc_usim::scard::get_aid(unsigned char *aid, size_t maxlen) int pcsc_usim::scard::get_record_len(unsigned char recnum, unsigned char mode) { unsigned char buf[255]; - unsigned char cmd[5] = { SIM_CMD_READ_RECORD /* , len */ }; - size_t blen; - long ret; + unsigned char cmd[5] = {SIM_CMD_READ_RECORD /* , len */}; + size_t blen; + long ret; if (sim_type == SCARD_USIM) cmd[0] = USIM_CLA; @@ -870,7 +842,7 @@ int pcsc_usim::scard::get_record_len(unsigned char recnum, unsigned char mode) cmd[4] = sizeof(buf); blen = sizeof(buf); - ret = transmit(cmd, sizeof(cmd), buf, &blen); + ret = transmit(cmd, sizeof(cmd), buf, &blen); if (ret != SCARD_S_SUCCESS) { log->debug("SCARD: failed to determine file length for record %d\n", recnum); return -1; @@ -886,13 +858,12 @@ int pcsc_usim::scard::get_record_len(unsigned char recnum, unsigned char mode) return buf[1]; } - -int pcsc_usim::scard::read_record(unsigned char *data, size_t len, unsigned char recnum, unsigned char mode) +int pcsc_usim::scard::read_record(unsigned char* data, size_t len, unsigned char recnum, unsigned char mode) { - unsigned char cmd[5] = { SIM_CMD_READ_RECORD /* , len */ }; - size_t blen = len + 3; - unsigned char *buf; - long ret; + unsigned char cmd[5] = {SIM_CMD_READ_RECORD /* , len */}; + size_t blen = len + 3; + unsigned char* buf; + long ret; if (sim_type == SCARD_USIM) cmd[0] = USIM_CLA; @@ -910,7 +881,7 @@ int pcsc_usim::scard::read_record(unsigned char *data, size_t len, unsigned char return -2; } if (blen != len + 2) { - log->debug("SCARD: record read returned unexpected length %ld (expected %ld)\n", (long) blen, (long) len + 2); + log->debug("SCARD: record read returned unexpected length %ld (expected %ld)\n", (long)blen, (long)len + 2); free(buf); return -3; } @@ -927,7 +898,6 @@ int pcsc_usim::scard::read_record(unsigned char *data, size_t len, unsigned char return 0; } - /** * scard_get_imsi - Read IMSI from SIM/USIM card * @scard: Pointer to private data from scard_init() @@ -942,18 +912,18 @@ int pcsc_usim::scard::read_record(unsigned char *data, size_t len, unsigned char * file is PIN protected, scard_set_pin() must have been used to set the * correct PIN code before calling scard_get_imsi(). */ -int pcsc_usim::scard::get_imsi(char *imsi, size_t *len) +int pcsc_usim::scard::get_imsi(char* imsi, size_t* len) { unsigned char buf[100]; - size_t blen, imsilen, i; - char *pos; + size_t blen, imsilen, i; + char* pos; log->debug("SCARD: reading IMSI from (GSM) EF-IMSI\n"); blen = sizeof(buf); if (select_file(SCARD_FILE_GSM_EF_IMSI, buf, &blen)) return -1; if (blen < 4) { - log->warning("SCARD: too short (GSM) EF-IMSI header (len=%ld)\n", (long) blen); + log->warning("SCARD: too short (GSM) EF-IMSI header (len=%ld)\n", (long)blen); return -2; } @@ -966,12 +936,12 @@ int pcsc_usim::scard::get_imsi(char *imsi, size_t *len) blen = file_size; } if (blen < 2 || blen > sizeof(buf)) { - log->debug("SCARD: invalid IMSI file length=%ld\n", (long) blen); + log->debug("SCARD: invalid IMSI file length=%ld\n", (long)blen); return -3; } imsilen = (blen - 2) * 2 + 1; - log->debug("SCARD: IMSI file length=%ld imsilen=%ld\n", (long) blen, (long) imsilen); + log->debug("SCARD: IMSI file length=%ld imsilen=%ld\n", (long)blen, (long)imsilen); if (blen < 2 || imsilen > *len) { *len = imsilen; return -4; @@ -980,7 +950,7 @@ int pcsc_usim::scard::get_imsi(char *imsi, size_t *len) if (read_file(buf, blen)) return -5; - pos = imsi; + pos = imsi; *pos++ = '0' + (buf[1] >> 4 & 0x0f); for (i = 2; i < blen; i++) { unsigned char digit; @@ -1002,12 +972,12 @@ int pcsc_usim::scard::get_imsi(char *imsi, size_t *len) return 0; } -int pcsc_usim::scard::read_file(unsigned char *data, size_t len) +int pcsc_usim::scard::read_file(unsigned char* data, size_t len) { - unsigned char cmd[5] = { SIM_CMD_READ_BIN /* , len */ }; - size_t blen = len + 3; - unsigned char *buf; - long ret; + unsigned char cmd[5] = {SIM_CMD_READ_BIN /* , len */}; + size_t blen = len + 3; + unsigned char* buf; + long ret; cmd[4] = len; @@ -1023,7 +993,7 @@ int pcsc_usim::scard::read_file(unsigned char *data, size_t len) return -2; } if (blen != len + 2) { - log->error("SCARD: file read returned unexpected length %ld (expected %ld)\n", (long) blen, (long) len + 2); + log->error("SCARD: file read returned unexpected length %ld (expected %ld)\n", (long)blen, (long)len + 2); free(buf); return -3; } @@ -1040,8 +1010,7 @@ int pcsc_usim::scard::read_file(unsigned char *data, size_t len) return 0; } - -int pcsc_usim::scard::parse_fsp_templ(unsigned char *buf, size_t buf_len, int *ps_do, int *file_len) +int pcsc_usim::scard::parse_fsp_templ(unsigned char* buf, size_t buf_len, int* ps_do, int* file_len) { unsigned char *pos, *end; @@ -1068,11 +1037,11 @@ int pcsc_usim::scard::parse_fsp_templ(unsigned char *buf, size_t buf_len, int *p unsigned char type, len; type = pos[0]; - len = pos[1]; + len = pos[1]; log->debug("SCARD: file header TLV 0x%02x len=%d\n", type, len); pos += 2; - if (len > (unsigned int) (end - pos)) + if (len > (unsigned int)(end - pos)) break; switch (type) { @@ -1086,7 +1055,7 @@ int pcsc_usim::scard::parse_fsp_templ(unsigned char *buf, size_t buf_len, int *p log->debug_hex(pos, len, "SCARD: DF name (AID) TLV\n"); break; case USIM_TLV_PROPR_INFO: - log->debug_hex(pos, len,"SCARD: Proprietary information TLV\n"); + log->debug_hex(pos, len, "SCARD: Proprietary information TLV\n"); break; case USIM_TLV_LIFE_CYCLE_STATUS: log->debug_hex(pos, len, "SCARD: Life Cycle Status Integer TLV\n"); @@ -1095,7 +1064,7 @@ int pcsc_usim::scard::parse_fsp_templ(unsigned char *buf, size_t buf_len, int *p log->debug_hex(pos, len, "SCARD: File size TLV\n"); if ((len == 1 || len == 2) && file_len) { if (len == 1) { - *file_len = (int) pos[0]; + *file_len = (int)pos[0]; } else { *file_len = to_uint16(pos); } @@ -1107,10 +1076,9 @@ int pcsc_usim::scard::parse_fsp_templ(unsigned char *buf, size_t buf_len, int *p break; case USIM_TLV_PIN_STATUS_TEMPLATE: log->debug_hex(pos, len, "SCARD: PIN Status Template DO TLV\n"); - if (len >= 2 && pos[0] == USIM_PS_DO_TAG && - pos[1] >= 1 && ps_do) { + if (len >= 2 && pos[0] == USIM_PS_DO_TAG && pos[1] >= 1 && ps_do) { log->debug("SCARD: PS_DO=0x%02x\n", pos[2]); - *ps_do = (int) pos[2]; + *ps_do = (int)pos[2]; } break; case USIM_TLV_SHORT_FILE_ID: @@ -1122,7 +1090,7 @@ int pcsc_usim::scard::parse_fsp_templ(unsigned char *buf, size_t buf_len, int *p log->debug_hex(pos, len, "SCARD: Security attribute TLV\n"); break; default: - log->debug_hex(pos, len,"SCARD: Unrecognized TLV\n"); + log->debug_hex(pos, len, "SCARD: Unrecognized TLV\n"); break; } @@ -1134,8 +1102,6 @@ int pcsc_usim::scard::parse_fsp_templ(unsigned char *buf, size_t buf_len, int *p return -1; } - - /** * scard_deinit - Deinitialize SIM/USIM connection * @scard: Pointer to private data from scard_init() @@ -1159,8 +1125,6 @@ void pcsc_usim::scard::deinit() } } - - /** * scard_get_mnc_len - Read length of MNC in the IMSI from SIM/USIM card * @scard: Pointer to private data from scard_init() @@ -1174,15 +1138,15 @@ void pcsc_usim::scard::deinit() int pcsc_usim::scard::get_mnc_len() { unsigned char buf[100]; - size_t blen; - int file_size; + size_t blen; + int file_size; log->debug("SCARD: reading MNC len from (GSM) EF-AD\n"); blen = sizeof(buf); if (select_file(SCARD_FILE_GSM_EF_AD, buf, &blen)) return -1; if (blen < 4) { - log->debug("SCARD: too short (GSM) EF-AD header (len=%ld)\n", (long) blen); + log->debug("SCARD: too short (GSM) EF-AD header (len=%ld)\n", (long)blen); return -2; } @@ -1196,8 +1160,8 @@ int pcsc_usim::scard::get_mnc_len() log->debug("SCARD: MNC length not available\n"); return -7; } - if (file_size < 4 || file_size > (int) sizeof(buf)) { - log->debug("SCARD: invalid file length=%ld\n", (long) file_size); + if (file_size < 4 || file_size > (int)sizeof(buf)) { + log->debug("SCARD: invalid file length=%ld\n", (long)file_size); return -4; } @@ -1205,14 +1169,13 @@ int pcsc_usim::scard::get_mnc_len() return -5; buf[3] = buf[3] & 0x0f; /* upper nibble reserved for future use */ if (buf[3] < 2 || buf[3] > 3) { - log->debug("SCARD: invalid MNC length=%ld\n", (long) buf[3]); + log->debug("SCARD: invalid MNC length=%ld\n", (long)buf[3]); return -6; } - log->debug("SCARD: MNC length=%ld\n", (long) buf[3]); + log->debug("SCARD: MNC length=%ld\n", (long)buf[3]); return buf[3]; } - /** * scard_umts_auth - Run UMTS authentication command on USIM card * @scard: Pointer to private data from scard_init() @@ -1233,17 +1196,19 @@ int pcsc_usim::scard::get_mnc_len() * synchronization failure, the received AUTS value will be written into auts * buffer. In this case, RES, IK, and CK are not valid. */ -int pcsc_usim::scard::umts_auth(const unsigned char *_rand, - const unsigned char *autn, - unsigned char *res, int *res_len, - unsigned char *ik, unsigned char *ck, unsigned char *auts) +int pcsc_usim::scard::umts_auth(const unsigned char* _rand, + const unsigned char* autn, + unsigned char* res, + int* res_len, + unsigned char* ik, + unsigned char* ck, + unsigned char* auts) { - unsigned char cmd[5 + 1 + AKA_RAND_LEN + 1 + AKA_AUTN_LEN] = { USIM_CMD_RUN_UMTS_ALG }; - unsigned char get_resp[5] = { USIM_CMD_GET_RESPONSE }; + unsigned char cmd[5 + 1 + AKA_RAND_LEN + 1 + AKA_AUTN_LEN] = {USIM_CMD_RUN_UMTS_ALG}; + unsigned char get_resp[5] = {USIM_CMD_GET_RESPONSE}; unsigned char resp[3], buf[64], *pos, *end; - size_t len; - long ret; - + size_t len; + long ret; if (sim_type == SCARD_GSM_SIM) { log->debug("SCARD: Non-USIM card - cannot do UMTS auth\n"); @@ -1270,8 +1235,8 @@ int pcsc_usim::scard::umts_auth(const unsigned char *_rand, log->warning("SCARD: UMTS auth failed - MAC != XMAC\n"); return -1; } else if (len != 2 || resp[0] != 0x61) { - log->warning("SCARD: unexpected response for UMTS auth request (len=%ld resp=%02x %02x)\n", - (long) len, resp[0], resp[1]); + log->warning( + "SCARD: unexpected response for UMTS auth request (len=%ld resp=%02x %02x)\n", (long)len, resp[0], resp[1]); return -1; } get_resp[4] = resp[1]; @@ -1333,13 +1298,12 @@ int pcsc_usim::scard::umts_auth(const unsigned char *_rand, return -1; } - -int pcsc_usim::scard::verify_pin(const char *pin) +int pcsc_usim::scard::verify_pin(const char* pin) { - long ret; + long ret; unsigned char resp[3]; - unsigned char cmd[5 + 8] = { SIM_CMD_VERIFY_CHV1 }; - size_t len; + unsigned char cmd[5 + 8] = {SIM_CMD_VERIFY_CHV1}; + size_t len; log->debug("SCARD: verifying PIN\n"); @@ -1365,5 +1329,4 @@ int pcsc_usim::scard::verify_pin(const char *pin) return SCARD_S_SUCCESS; } - } // namespace srsue diff --git a/srsue/src/stack/upper/tft_packet_filter.cc b/srsue/src/stack/upper/tft_packet_filter.cc index 488e68232..4ddff7f39 100644 --- a/srsue/src/stack/upper/tft_packet_filter.cc +++ b/srsue/src/stack/upper/tft_packet_filter.cc @@ -39,7 +39,7 @@ tft_packet_filter_t::tft_packet_filter_t(uint8_t { int idx = 0; while (idx < tft.filter_size) { - uint8_t filter_type = tft.filter[idx]; + uint8_t filter_type = tft.filter[idx]; idx++; switch (filter_type) { // IPv4 @@ -53,7 +53,7 @@ tft_packet_filter_t::tft_packet_filter_t(uint8_t memcpy(&ipv4_remote_addr, &tft.filter[idx], IPV4_ADDR_SIZE); idx += IPV4_ADDR_SIZE; break; - //IPv6 + // IPv6 case IPV6_REMOTE_ADDR_TYPE: break; case IPV6_REMOTE_ADDR_LENGTH_TYPE: @@ -82,11 +82,11 @@ tft_packet_filter_t::tft_packet_filter_t(uint8_t case TYPE_OF_SERVICE_TYPE: active_filters = TYPE_OF_SERVICE_FLAG; memcpy(&type_of_service, &tft.filter[idx], 1); - idx += 1; + idx += 1; memcpy(&type_of_service_mask, &tft.filter[idx], 1); - idx += 1; + idx += 1; break; - //Flow label + // Flow label case FLOW_LABEL_TYPE: break; // IPsec security parameter @@ -222,7 +222,7 @@ bool tft_packet_filter_t::match_port(const srslte::unique_byte_buffer_t& pdu) { struct iphdr* ip_pkt = (struct iphdr*)pdu->msg; struct ipv6hdr* ip6_pkt = (struct ipv6hdr*)pdu->msg; - struct udphdr* udp_pkt; + struct udphdr* udp_pkt; if (ip_pkt->version == 4) { switch (ip_pkt->protocol) { diff --git a/srsue/src/stack/upper/usim.cc b/srsue/src/stack/upper/usim.cc index 2aa28da17..7594bf0f2 100644 --- a/srsue/src/stack/upper/usim.cc +++ b/srsue/src/stack/upper/usim.cc @@ -26,7 +26,7 @@ using namespace srslte; using namespace asn1::rrc; -namespace srsue{ +namespace srsue { usim::usim(srslte::log* log_) : usim_log(log_) {} @@ -35,15 +35,15 @@ int usim::init(usim_args_t* args) imsi_str = args->imsi; imei_str = args->imei; - const char *imsi_c = args->imsi.c_str(); - const char *imei_c = args->imei.c_str(); + const char* imsi_c = args->imsi.c_str(); + const char* imei_c = args->imei.c_str(); auth_algo = auth_algo_milenage; if ("xor" == args->algo) { auth_algo = auth_algo_xor; } - if(32 == args->k.length()) { + if (32 == args->k.length()) { str_to_hex(args->k, k); } else { usim_log->error("Invalid length for K: %zu should be %d\n", args->k.length(), 32); @@ -69,7 +69,7 @@ int usim::init(usim_args_t* args) } } - if(15 == args->imsi.length()) { + if (15 == args->imsi.length()) { imsi = 0; for (int i = 0; i < 15; i++) { imsi *= 10; @@ -80,7 +80,7 @@ int usim::init(usim_args_t* args) usim_log->console("Invalid length for IMSI: %zu should be %d\n", args->imsi.length(), 15); } - if(15 == args->imei.length()) { + if (15 == args->imei.length()) { imei = 0; for (int i = 0; i < 15; i++) { imei *= 10; @@ -96,8 +96,7 @@ int usim::init(usim_args_t* args) return SRSLTE_SUCCESS; } -void usim::stop() -{} +void usim::stop() {} /******************************************************************************* NAS interface @@ -119,13 +118,13 @@ bool usim::get_imsi_vec(uint8_t* imsi_, uint32_t n) return false; } - if(NULL == imsi_ || n < 15) { + if (NULL == imsi_ || n < 15) { usim_log->error("Invalid parameters to get_imsi_vec\n"); return false; } uint64_t temp = imsi; - for(int i=14;i>=0;i--) { + for (int i = 14; i >= 0; i--) { imsi_[i] = temp % 10; temp /= 10; } @@ -139,14 +138,13 @@ bool usim::get_imei_vec(uint8_t* imei_, uint32_t n) return false; } - if(NULL == imei_ || n < 15) { + if (NULL == imei_ || n < 15) { usim_log->error("Invalid parameters to get_imei_vec\n"); return false; } uint64 temp = imei; - for(int i=14;i>=0;i--) - { + for (int i = 14; i >= 0; i--) { imei_[i] = temp % 10; temp /= 10; } @@ -168,21 +166,17 @@ bool usim::get_home_plmn_id(srslte::plmn_id_t* home_plmn_id) std::ostringstream mcc_str, mnc_str; - for (int i=0;ifrom_string(mcc_str.str() + mnc_str.str()); @@ -192,47 +186,41 @@ bool usim::get_home_plmn_id(srslte::plmn_id_t* home_plmn_id) return true; } -auth_result_t usim::generate_authentication_response(uint8_t *rand, - uint8_t *autn_enb, - uint16_t mcc, - uint16_t mnc, - uint8_t *res, - int *res_len, - uint8_t *k_asme) +auth_result_t usim::generate_authentication_response(uint8_t* rand, + uint8_t* autn_enb, + uint16_t mcc, + uint16_t mnc, + uint8_t* res, + int* res_len, + uint8_t* k_asme) { - if(auth_algo_xor == auth_algo) { + if (auth_algo_xor == auth_algo) { return gen_auth_res_xor(rand, autn_enb, mcc, mnc, res, res_len, k_asme); } else { return gen_auth_res_milenage(rand, autn_enb, mcc, mnc, res, res_len, k_asme); } } -void usim::generate_nas_keys(uint8_t *k_asme, - uint8_t *k_nas_enc, - uint8_t *k_nas_int, +void usim::generate_nas_keys(uint8_t* k_asme, + uint8_t* k_nas_enc, + uint8_t* k_nas_int, CIPHERING_ALGORITHM_ID_ENUM cipher_algo, INTEGRITY_ALGORITHM_ID_ENUM integ_algo) { // Generate K_nas_enc and K_nas_int - security_generate_k_nas( k_asme, - cipher_algo, - integ_algo, - k_nas_enc, - k_nas_int); - - + security_generate_k_nas(k_asme, cipher_algo, integ_algo, k_nas_enc, k_nas_int); } /******************************************************************************* RRC interface *******************************************************************************/ -void usim::generate_as_keys(uint8_t *k_asme, - uint32_t count_ul, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int, - uint8_t *k_up_enc, - uint8_t *k_up_int, +void usim::generate_as_keys(uint8_t* k_asme, + uint32_t count_ul, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int, + uint8_t* k_up_enc, + uint8_t* k_up_int, CIPHERING_ALGORITHM_ID_ENUM cipher_algo, INTEGRITY_ALGORITHM_ID_ENUM integ_algo) { @@ -246,52 +234,42 @@ void usim::generate_as_keys(uint8_t *k_asme, memcpy(k_enb_initial, k_enb, 32); // Generate K_rrc_enc and K_rrc_int - security_generate_k_rrc( k_enb, - cipher_algo, - integ_algo, - k_rrc_enc, - k_rrc_int); + security_generate_k_rrc(k_enb, cipher_algo, integ_algo, k_rrc_enc, k_rrc_int); // Generate K_up_enc and K_up_int - security_generate_k_up( k_enb, - cipher_algo, - integ_algo, - k_up_enc, - k_up_int); + security_generate_k_up(k_enb, cipher_algo, integ_algo, k_up_enc, k_up_int); current_ncc = 0; is_first_ncc = true; } -void usim::generate_as_keys_ho(uint32_t pci, - uint32_t earfcn, - int ncc, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int, - uint8_t *k_up_enc, - uint8_t *k_up_int, +void usim::generate_as_keys_ho(uint32_t pci, + uint32_t earfcn, + int ncc, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int, + uint8_t* k_up_enc, + uint8_t* k_up_int, CIPHERING_ALGORITHM_ID_ENUM cipher_algo, INTEGRITY_ALGORITHM_ID_ENUM integ_algo) { - uint8_t *enb_star_key = k_enb; + uint8_t* enb_star_key = k_enb; if (ncc < 0) { ncc = current_ncc; } // Generate successive NH - while(current_ncc != (uint32_t) ncc) { - uint8_t *sync = NULL; + while (current_ncc != (uint32_t)ncc) { + uint8_t* sync = NULL; if (is_first_ncc) { - sync = k_enb_initial; + sync = k_enb_initial; is_first_ncc = false; } else { sync = nh; } // Generate NH - security_generate_nh(k_asme, - sync, - nh); + security_generate_nh(k_asme, sync, nh); current_ncc++; if (current_ncc == 8) { @@ -301,221 +279,172 @@ void usim::generate_as_keys_ho(uint32_t pci, } // Generate K_enb - security_generate_k_enb_star( enb_star_key, - pci, - earfcn, - k_enb_star); + security_generate_k_enb_star(enb_star_key, pci, earfcn, k_enb_star); // K_enb becomes K_enb* memcpy(k_enb, k_enb_star, 32); // Generate K_rrc_enc and K_rrc_int - security_generate_k_rrc( k_enb, - cipher_algo, - integ_algo, - k_rrc_enc, - k_rrc_int); + security_generate_k_rrc(k_enb, cipher_algo, integ_algo, k_rrc_enc, k_rrc_int); // Generate K_up_enc and K_up_int - security_generate_k_up( k_enb, - cipher_algo, - integ_algo, - k_up_enc, - k_up_int); + security_generate_k_up(k_enb, cipher_algo, integ_algo, k_up_enc, k_up_int); } /******************************************************************************* Helpers *******************************************************************************/ -auth_result_t usim::gen_auth_res_milenage(uint8_t *rand, - uint8_t *autn_enb, - uint16_t mcc, - uint16_t mnc, - uint8_t *res, - int *res_len, - uint8_t *k_asme) +auth_result_t usim::gen_auth_res_milenage(uint8_t* rand, + uint8_t* autn_enb, + uint16_t mcc, + uint16_t mnc, + uint8_t* res, + int* res_len, + uint8_t* k_asme) { - auth_result_t result = AUTH_OK; - uint32_t i; - uint8_t sqn[6]; + auth_result_t result = AUTH_OK; + uint32_t i; + uint8_t sqn[6]; // Use RAND and K to compute RES, CK, IK and AK - security_milenage_f2345( k, - opc, - rand, - res, - ck, - ik, - ak); + security_milenage_f2345(k, opc, rand, res, ck, ik, ak); *res_len = 8; // Extract sqn from autn - for(i=0;i<6;i++) - { + for (i = 0; i < 6; i++) { sqn[i] = autn_enb[i] ^ ak[i]; } // Extract AMF from autn - for(int i=0;i<2;i++) - { - amf[i]=autn_enb[6+i]; + for (int i = 0; i < 2; i++) { + amf[i] = autn_enb[6 + i]; } // Generate MAC - security_milenage_f1( k, - opc, - rand, - sqn, - amf, - mac); + security_milenage_f1(k, opc, rand, sqn, amf, mac); // Construct AUTN - for(i=0; i<6; i++) - { + for (i = 0; i < 6; i++) { autn[i] = sqn[i] ^ ak[i]; } - for(i=0; i<2; i++) - { - autn[6+i] = amf[i]; + for (i = 0; i < 2; i++) { + autn[6 + i] = amf[i]; } - for(i=0; i<8; i++) - { - autn[8+i] = mac[i]; + for (i = 0; i < 8; i++) { + autn[8 + i] = mac[i]; } // Compare AUTNs - for(i=0; i<16; i++) - { - if(autn[i] != autn_enb[i]) - { + for (i = 0; i < 16; i++) { + if (autn[i] != autn_enb[i]) { result = AUTH_FAILED; } } // Generate K_asme - security_generate_k_asme( ck, - ik, - ak, - sqn, - mcc, - mnc, - k_asme); + security_generate_k_asme(ck, ik, ak, sqn, mcc, mnc, k_asme); return result; } // 3GPP TS 34.108 version 10.0.0 Section 8 -auth_result_t usim::gen_auth_res_xor(uint8_t *rand, - uint8_t *autn_enb, - uint16_t mcc, - uint16_t mnc, - uint8_t *res, - int *res_len, - uint8_t *k_asme) +auth_result_t usim::gen_auth_res_xor(uint8_t* rand, + uint8_t* autn_enb, + uint16_t mcc, + uint16_t mnc, + uint8_t* res, + int* res_len, + uint8_t* k_asme) { auth_result_t result = AUTH_OK; - uint32_t i; - uint8_t sqn[6]; - uint8_t xdout[16]; - uint8_t cdout[8]; + uint32_t i; + uint8_t sqn[6]; + uint8_t xdout[16]; + uint8_t cdout[8]; // Use RAND and K to compute RES, CK, IK and AK - for(i=0; i<16; i++) { - xdout[i] = k[i]^rand[i]; + for (i = 0; i < 16; i++) { + xdout[i] = k[i] ^ rand[i]; } - for(i=0; i<16; i++) { - res[i] = xdout[i]; - ck[i] = xdout[(i+1)%16]; - ik[i] = xdout[(i+2)%16]; + for (i = 0; i < 16; i++) { + res[i] = xdout[i]; + ck[i] = xdout[(i + 1) % 16]; + ik[i] = xdout[(i + 2) % 16]; } - for(i=0; i<6; i++) { - ak[i] = xdout[i+3]; + for (i = 0; i < 6; i++) { + ak[i] = xdout[i + 3]; } *res_len = 8; // Extract sqn from autn - for(i=0;i<6;i++) { + for (i = 0; i < 6; i++) { sqn[i] = autn_enb[i] ^ ak[i]; } // Extract AMF from autn - for(int i=0;i<2;i++){ - amf[i]=autn_enb[6+i]; + for (int i = 0; i < 2; i++) { + amf[i] = autn_enb[6 + i]; } // Generate cdout - for(i=0; i<6; i++) { + for (i = 0; i < 6; i++) { cdout[i] = sqn[i]; } - for(i=0; i<2; i++) { - cdout[6+i] = amf[i]; + for (i = 0; i < 2; i++) { + cdout[6 + i] = amf[i]; } // Generate MAC - for(i=0;i<8;i++) { + for (i = 0; i < 8; i++) { mac[i] = xdout[i] ^ cdout[i]; } // Construct AUTN - for(i=0; i<6; i++) - { + for (i = 0; i < 6; i++) { autn[i] = sqn[i] ^ ak[i]; } - for(i=0; i<2; i++) - { - autn[6+i] = amf[i]; + for (i = 0; i < 2; i++) { + autn[6 + i] = amf[i]; } - for(i=0; i<8; i++) - { - autn[8+i] = mac[i]; + for (i = 0; i < 8; i++) { + autn[8 + i] = mac[i]; } // Compare AUTNs - for(i=0; i<16; i++) - { - if(autn[i] != autn_enb[i]) - { + for (i = 0; i < 16; i++) { + if (autn[i] != autn_enb[i]) { result = AUTH_FAILED; } } // Generate K_asme - security_generate_k_asme( ck, - ik, - ak, - sqn, - mcc, - mnc, - k_asme); + security_generate_k_asme(ck, ik, ak, sqn, mcc, mnc, k_asme); return result; } -void usim::str_to_hex(std::string str, uint8_t *hex) +void usim::str_to_hex(std::string str, uint8_t* hex) { uint32_t i; - const char *h_str = str.c_str(); - uint32_t len = str.length(); - - for(i=0; i= '0' && h_str[i*2+0] <= '9') - { - hex[i] = ( h_str[i*2+0] - '0') << 4; - }else if( h_str[i*2+0] >= 'A' && h_str[i*2+0] <= 'F'){ - hex[i] = (( h_str[i*2+0] - 'A') + 0xA) << 4; - }else{ - hex[i] = (( h_str[i*2+0] - 'a') + 0xA) << 4; + const char* h_str = str.c_str(); + uint32_t len = str.length(); + + for (i = 0; i < len / 2; i++) { + if (h_str[i * 2 + 0] >= '0' && h_str[i * 2 + 0] <= '9') { + hex[i] = (h_str[i * 2 + 0] - '0') << 4; + } else if (h_str[i * 2 + 0] >= 'A' && h_str[i * 2 + 0] <= 'F') { + hex[i] = ((h_str[i * 2 + 0] - 'A') + 0xA) << 4; + } else { + hex[i] = ((h_str[i * 2 + 0] - 'a') + 0xA) << 4; } - if( h_str[i*2+1] >= '0' && h_str[i*2+1] <= '9') - { - hex[i] |= h_str[i*2+1] - '0'; - }else if( h_str[i*2+1] >= 'A' && h_str[i*2+1] <= 'F'){ - hex[i] |= ( h_str[i*2+1] - 'A') + 0xA; - }else{ - hex[i] |= ( h_str[i*2+1] - 'a') + 0xA; + if (h_str[i * 2 + 1] >= '0' && h_str[i * 2 + 1] <= '9') { + hex[i] |= h_str[i * 2 + 1] - '0'; + } else if (h_str[i * 2 + 1] >= 'A' && h_str[i * 2 + 1] <= 'F') { + hex[i] |= (h_str[i * 2 + 1] - 'A') + 0xA; + } else { + hex[i] |= (h_str[i * 2 + 1] - 'a') + 0xA; } } } diff --git a/srsue/src/stack/upper/usim_base.cc b/srsue/src/stack/upper/usim_base.cc index 294dd8667..762d2f6f1 100644 --- a/srsue/src/stack/upper/usim_base.cc +++ b/srsue/src/stack/upper/usim_base.cc @@ -40,10 +40,8 @@ std::unique_ptr usim_base::get_instance(usim_args_t* args, srslte::lo return std::unique_ptr(new usim(log_)); } -usim_base::usim_base() { -} +usim_base::usim_base() {} -usim_base::~usim_base() { -} +usim_base::~usim_base() {} } // namespace srsue diff --git a/srsue/src/ue.cc b/srsue/src/ue.cc index 7d3c5b9f9..b37f4aff6 100644 --- a/srsue/src/ue.cc +++ b/srsue/src/ue.cc @@ -55,7 +55,6 @@ ue::~ue() // destruct stack components before cleaning buffer pool stack.reset(); byte_buffer_pool::cleanup(); - } int ue::init(const all_args_t& args_, srslte::logger* logger_) @@ -164,8 +163,8 @@ int ue::parse_args(const all_args_t& args_) } // replicate some RF parameter to make them available to PHY - args.phy.nof_rx_ant = args.rf.nof_rx_ant; - args.phy.agc_enable = args.rf.rx_gain < 0.0f; + args.phy.nof_rx_ant = args.rf.nof_rx_ant; + args.phy.agc_enable = args.rf.rx_gain < 0.0f; // Calculate number of carriers available in all radios args.phy.nof_radios = args.rf.nof_radios; diff --git a/srsue/test/mac_test.cc b/srsue/test/mac_test.cc index 045e7f494..dc9cdf7af 100644 --- a/srsue/test/mac_test.cc +++ b/srsue/test/mac_test.cc @@ -121,7 +121,7 @@ public: } // phy_interface_mac_lte - void configure_prach_params(){}; + void configure_prach_params(){}; void prach_send(uint32_t preamble_idx, int allowed_subframe, float target_power_dbm) { @@ -153,11 +153,11 @@ public: void set_mch_period_stop(uint32_t stop){}; // phy_interface_mac_common - void set_crnti(uint16_t rnti) { last_crnti = rnti; } - void set_timeadv_rar(uint32_t ta_cmd) { rar_time_adv = ta_cmd; } - void set_timeadv(uint32_t ta_cmd){}; - void set_activation_deactivation_scell(uint32_t cmd) { scell_cmd = cmd; }; - void set_rar_grant(uint8_t grant_payload[SRSLTE_RAR_GRANT_LEN], uint16_t rnti) + void set_crnti(uint16_t rnti) { last_crnti = rnti; } + void set_timeadv_rar(uint32_t ta_cmd) { rar_time_adv = ta_cmd; } + void set_timeadv(uint32_t ta_cmd){}; + void set_activation_deactivation_scell(uint32_t cmd) { scell_cmd = cmd; }; + void set_rar_grant(uint8_t grant_payload[SRSLTE_RAR_GRANT_LEN], uint16_t rnti) { memcpy(rar_payload, grant_payload, SRSLTE_RAR_GRANT_LEN); rar_temp_rnti = rnti; @@ -319,8 +319,8 @@ public: ho_finish = true; ho_finish_successful = ra_successful; } - void release_pucch_srs() { printf("%s\n", __FUNCTION__); } - void run_tti(uint32_t tti) { printf("%s\n", __FUNCTION__); } + void release_pucch_srs() { printf("%s\n", __FUNCTION__); } + void run_tti(uint32_t tti) { printf("%s\n", __FUNCTION__); } void ra_problem() { rach_problem++; } bool ho_finish = false; bool ho_finish_successful = false; @@ -1375,7 +1375,7 @@ int mac_random_access_test() stack_dummy stack; // Configure default RACH parameters - asn1::rrc::rach_cfg_common_s rach_cfg = {}; + asn1::rrc::rach_cfg_common_s rach_cfg = {}; rach_cfg.preamb_info.nof_ra_preambs = asn1::rrc::rach_cfg_common_s::preamb_info_s_::nof_ra_preambs_opts::n12; rach_cfg.ra_supervision_info.preamb_trans_max = asn1::rrc::preamb_trans_max_opts::n8; rach_cfg.ra_supervision_info.ra_resp_win_size = @@ -1417,7 +1417,7 @@ int mac_random_access_test() // Structure that defines the test to be executed struct ra_test my_test = {}; - uint32_t test_id = 1; + uint32_t test_id = 1; my_test.temp_rnti = 100; my_test.assume_prach_transmitted = -1; diff --git a/srsue/test/metrics_test.cc b/srsue/test/metrics_test.cc index c946777a8..6bdd75e22 100644 --- a/srsue/test/metrics_test.cc +++ b/srsue/test/metrics_test.cc @@ -34,7 +34,7 @@ using namespace srsue; namespace srsue { -char *csv_file_name = NULL; +char* csv_file_name = NULL; // fake classes class ue_dummy : public ue_metrics_interface @@ -59,17 +59,19 @@ public: bool is_rrc_connected() { return (rand() % 2 == 0); } }; -} +} // namespace srsue -void usage(char *prog) { +void usage(char* prog) +{ printf("Usage: %s -o csv_output_file\n", prog); } -void parse_args(int argc, char **argv) { +void parse_args(int argc, char** argv) +{ int opt; while ((opt = getopt(argc, argv, "o")) != -1) { - switch(opt) { + switch (opt) { case 'o': csv_file_name = argv[optind]; break; @@ -84,10 +86,9 @@ void parse_args(int argc, char **argv) { } } - -int main(int argc, char **argv) +int main(int argc, char** argv) { - float period = 1.0; + float period = 1.0; ue_dummy ue; if (argc < 3) { @@ -95,7 +96,7 @@ int main(int argc, char **argv) exit(-1); } - parse_args(argc,argv); + parse_args(argc, argv); // the default metrics type for stdout output metrics_stdout metrics_screen; diff --git a/srsue/test/phy/scell_search_test.cc b/srsue/test/phy/scell_search_test.cc index 777568536..62bf7b03b 100644 --- a/srsue/test/phy/scell_search_test.cc +++ b/srsue/test/phy/scell_search_test.cc @@ -31,17 +31,17 @@ #include // Common execution parameters -static uint32_t duration_execution_s; -static srslte_cell_t cell_base = {.nof_prb = 6, +static uint32_t duration_execution_s; +static srslte_cell_t cell_base = {.nof_prb = 6, .nof_ports = 1, .id = 0, .cp = SRSLTE_CP_NORM, .phich_length = SRSLTE_PHICH_NORM, .phich_resources = SRSLTE_PHICH_R_1_6, .frame_type = SRSLTE_FDD}; -static std::string intra_meas_log_level; -static std::string cell_list; -static int phy_lib_log_level; +static std::string intra_meas_log_level; +static std::string cell_list; +static int phy_lib_log_level; // On the Fly parameters static int earfcn_dl; @@ -170,7 +170,7 @@ public: // Enable power allocation pdsch_cfg.power_scale = true; - pdsch_cfg.p_a = 0.0f; // 0 dB + pdsch_cfg.p_a = 0.0f; // 0 dB pdsch_cfg.p_b = (serving_cell_pdsch_tm > SRSLTE_TM1) ? 1 : 0; // 0 dB pdsch_cfg.rnti = serving_cell_pdsch_rnti; pdsch_cfg.meas_time_en = false; @@ -249,7 +249,7 @@ public: cells[pci].rsrq_min = rsrq; cells[pci].rsrq_max = rsrq; cells[pci].rsrq_avg = rsrq; - cells[pci].count = 1; + cells[pci].count = 1; } else { cells[pci].rsrp_min = SRSLTE_MIN(cells[pci].rsrp_min, rsrp); cells[pci].rsrp_max = SRSLTE_MAX(cells[pci].rsrp_max, rsrp); @@ -362,7 +362,7 @@ int parse_args(int argc, char** argv, srsue::phy_args_t* phy_args) int main(int argc, char** argv) { - int ret = SRSLTE_SUCCESS; + int ret = SRSLTE_SUCCESS; srsue::phy_args_t phy_args = {}; // Parse args diff --git a/srsue/test/ttcn3/hdr/ttcn3_interfaces.h b/srsue/test/ttcn3/hdr/ttcn3_interfaces.h index e0172cc70..88d9d7ead 100644 --- a/srsue/test/ttcn3/hdr/ttcn3_interfaces.h +++ b/srsue/test/ttcn3/hdr/ttcn3_interfaces.h @@ -29,13 +29,13 @@ class ss_ut_interface { public: - virtual void tc_start(const char* name) = 0; - virtual void tc_end() = 0; - virtual void power_off_ue() = 0; - virtual void switch_on_ue() = 0; - virtual void switch_off_ue() = 0; - virtual void enable_data() = 0; - virtual void disable_data() = 0; + virtual void tc_start(const char* name) = 0; + virtual void tc_end() = 0; + virtual void power_off_ue() = 0; + virtual void switch_on_ue() = 0; + virtual void switch_off_ue() = 0; + virtual void enable_data() = 0; + virtual void disable_data() = 0; }; class ss_sys_interface @@ -67,8 +67,8 @@ public: class syssim_interface_phy { public: - virtual void prach_indication(uint32_t preamble_index, const uint32_t& cell_id) = 0; - virtual void sr_req(uint32_t tti_tx) = 0; + virtual void prach_indication(uint32_t preamble_index, const uint32_t& cell_id) = 0; + virtual void sr_req(uint32_t tti_tx) = 0; virtual void tx_pdu(const uint8_t* payload, const int len, const uint32_t tx_tti) = 0; }; diff --git a/srsue/test/ttcn3/hdr/ttcn3_syssim.h b/srsue/test/ttcn3/hdr/ttcn3_syssim.h index ace0825fe..f992fe263 100644 --- a/srsue/test/ttcn3/hdr/ttcn3_syssim.h +++ b/srsue/test/ttcn3/hdr/ttcn3_syssim.h @@ -906,21 +906,21 @@ private: uint32_t run_id = 0; - int32_t tti = 0; - int32_t prach_tti = -1; - int32_t rar_tti = -1; - int32_t msg3_tti = -1; - int32_t sr_tti = -1; - uint32_t prach_preamble_index = 0; - uint16_t dl_rnti = 0; - uint16_t crnti = TTCN3_CRNTI; - srslte::timer_handler timers; - bool last_dl_ndi[2 * FDD_HARQ_DELAY_MS] = {}; - bool last_ul_ndi[2 * FDD_HARQ_DELAY_MS] = {}; + int32_t tti = 0; + int32_t prach_tti = -1; + int32_t rar_tti = -1; + int32_t msg3_tti = -1; + int32_t sr_tti = -1; + uint32_t prach_preamble_index = 0; + uint16_t dl_rnti = 0; + uint16_t crnti = TTCN3_CRNTI; + srslte::timer_handler timers; + bool last_dl_ndi[2 * FDD_HARQ_DELAY_MS] = {}; + bool last_ul_ndi[2 * FDD_HARQ_DELAY_MS] = {}; // Map between the cellId (name) used by 3GPP test suite and srsLTE cell struct typedef struct { - std::string name; + std::string name; srslte_cell_t cell = {}; float initial_power = 0.0; float attenuation = 0.0; @@ -945,8 +945,8 @@ private: srslte::rlc rlc; srslte::pdcp pdcp; - std::vector rb_id_vec = { - "SRB0", "SRB1", "SRB2", "DRB1", "DRB2", "DRB3", "DRB4", "DRB5", "DRB6", "DRB7", "DRB8"}; + std::vector rb_id_vec = + {"SRB0", "SRB1", "SRB2", "DRB1", "DRB2", "DRB3", "DRB4", "DRB5", "DRB6", "DRB7", "DRB8"}; }; #endif // SRSUE_TTCN3_SYSSIM_H diff --git a/srsue/test/ttcn3/hdr/ttcn3_ue.h b/srsue/test/ttcn3/hdr/ttcn3_ue.h index b21b78ed9..efcb0c238 100644 --- a/srsue/test/ttcn3/hdr/ttcn3_ue.h +++ b/srsue/test/ttcn3/hdr/ttcn3_ue.h @@ -61,10 +61,10 @@ public: args.stack.rrc.release = 8; args.stack.rrc.mbms_service_id = -1; - args.phy.dl_earfcn = "3400"; - args.rf.type = "none"; - args.stack.type = "lte"; - args.phy.type = "lte_ttcn3"; + args.phy.dl_earfcn = "3400"; + args.rf.type = "none"; + args.stack.type = "lte"; + args.phy.type = "lte_ttcn3"; // Instantiate layers and stack together our UE if (args.stack.type == "lte") { diff --git a/srsue/test/ttcn3/src/lte_ttcn3_phy.cc b/srsue/test/ttcn3/src/lte_ttcn3_phy.cc index b7f04e0da..8cb620b6a 100644 --- a/srsue/test/ttcn3/src/lte_ttcn3_phy.cc +++ b/srsue/test/ttcn3/src/lte_ttcn3_phy.cc @@ -216,7 +216,7 @@ std::string lte_ttcn3_phy::get_type() phy_interface_mac_lte::prach_info_t lte_ttcn3_phy::prach_get_info() { std::lock_guard lock(mutex); - prach_info_t info = {}; + prach_info_t info = {}; if (prach_tti_tx != -1) { info.is_transmitted = true; info.tti_ra = prach_tti_tx; diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index 8ef0d274b..3cd295dc4 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -92,7 +92,8 @@ public: class rrc_dummy : public rrc_interface_nas { public: - rrc_dummy() : last_sdu_len(0) { + rrc_dummy() : last_sdu_len(0) + { plmns.plmn_id.from_number(mcc, mnc); plmns.tac = 0xffff; } @@ -100,12 +101,12 @@ public: void write_sdu(unique_byte_buffer_t sdu) { last_sdu_len = sdu->N_bytes; - //printf("NAS generated SDU (len=%d):\n", sdu->N_bytes); - //srslte_vec_fprint_byte(stdout, sdu->msg, sdu->N_bytes); + // printf("NAS generated SDU (len=%d):\n", sdu->N_bytes); + // srslte_vec_fprint_byte(stdout, sdu->msg, sdu->N_bytes); } std::string get_rb_name(uint32_t lcid) { return std::string("lcid"); } - uint32_t get_last_sdu_len() { return last_sdu_len; } - void reset() { last_sdu_len = 0; } + uint32_t get_last_sdu_len() { return last_sdu_len; } + void reset() { last_sdu_len = 0; } bool plmn_search() { @@ -127,7 +128,7 @@ public: uint16_t get_mcc() { return mcc; } uint16_t get_mnc() { return mnc; } - void enable_capabilities() {} + void enable_capabilities() {} uint32_t get_lcid_for_eps_bearer(const uint32_t& eps_bearer_id) { return 0; } void paging_completed(bool outcome) {} @@ -187,15 +188,15 @@ class gw_dummy : public gw_interface_nas, public gw_interface_pdcp { return SRSLTE_SUCCESS; } - void write_pdu(uint32_t lcid, unique_byte_buffer_t pdu) {} - void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t sdu) {} + void write_pdu(uint32_t lcid, unique_byte_buffer_t pdu) {} + void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t sdu) {} }; -} +} // namespace srslte int security_command_test() { - int ret = SRSLTE_ERROR; + int ret = SRSLTE_ERROR; srslte::log_filter nas_log("NAS"); srslte::log_filter rrc_log("RRC"); srslte::log_filter mac_log("MAC"); @@ -234,7 +235,7 @@ int security_command_test() rrc_dummy.init(&nas); // push auth request PDU to NAS to generate security context - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t tmp = srslte::allocate_unique_buffer(*pool, true); memcpy(tmp->msg, auth_request_pdu, sizeof(auth_request_pdu)); tmp->N_bytes = sizeof(auth_request_pdu); @@ -262,7 +263,7 @@ int security_command_test() int mme_attach_request_test() { - int ret = SRSLTE_ERROR; + int ret = SRSLTE_ERROR; srslte::log_filter nas_log("NAS"); srslte::log_filter rrc_log("RRC"); srslte::log_filter mac_log("MAC"); @@ -298,7 +299,7 @@ int mme_attach_request_test() nas_cfg.force_imsi_attach = true; nas_cfg.apn_name = "test123"; srsue::nas nas(&nas_log, &timers); - srsue::gw gw; + srsue::gw gw; stack_dummy stack(&pdcp_dummy, &nas); nas.init(&usim, &rrc_dummy, &gw, nas_cfg); @@ -323,7 +324,7 @@ int mme_attach_request_test() rrc_dummy.reset(); // finally push attach accept - byte_buffer_pool* pool = byte_buffer_pool::get_instance(); + byte_buffer_pool* pool = byte_buffer_pool::get_instance(); unique_byte_buffer_t tmp = srslte::allocate_unique_buffer(*pool, true); memcpy(tmp->msg, attach_accept_pdu, sizeof(attach_accept_pdu)); tmp->N_bytes = sizeof(attach_accept_pdu); @@ -347,7 +348,7 @@ int mme_attach_request_test() int esm_info_request_test() { - int ret = SRSLTE_ERROR; + int ret = SRSLTE_ERROR; srslte::log_filter nas_log("NAS"); srslte::log_filter rrc_log("RRC"); srslte::log_filter mac_log("MAC"); @@ -367,13 +368,13 @@ int esm_info_request_test() args.algo = "xor"; args.imei = "353490069873319"; args.imsi = "001010123456789"; - args.k = "00112233445566778899aabbccddeeff"; - args.op = "63BFA50EE6523365FF14C1F45F88737D"; + args.k = "00112233445566778899aabbccddeeff"; + args.op = "63BFA50EE6523365FF14C1F45F88737D"; // init USIM srsue::usim usim(&usim_log); - bool net_valid; - uint8_t res[16]; + bool net_valid; + uint8_t res[16]; usim.init(&args); srslte::byte_buffer_pool* pool; @@ -490,7 +491,7 @@ int dedicated_eps_bearer_test() return SRSLTE_SUCCESS; } -int main(int argc, char **argv) +int main(int argc, char** argv) { if (security_command_test()) { printf("Security command test failed.\n"); diff --git a/srsue/test/upper/pcsc_usim_test.cc b/srsue/test/upper/pcsc_usim_test.cc index a0bffcbf1..aa78be73a 100644 --- a/srsue/test/upper/pcsc_usim_test.cc +++ b/srsue/test/upper/pcsc_usim_test.cc @@ -28,23 +28,22 @@ using namespace srsue; using namespace std; - uint8_t rand_enb[] = {0xbc, 0x4c, 0xb0, 0x27, 0xb3, 0x4b, 0x7f, 0x51, 0x21, 0x5e, 0x56, 0x5f, 0x67, 0x3f, 0xde, 0x4f}; uint8_t autn_enb[] = {0x5a, 0x17, 0x77, 0x3c, 0x62, 0x57, 0x90, 0x01, 0xcf, 0x47, 0xf7, 0x6d, 0xb3, 0xa0, 0x19, 0x46}; -int main(int argc, char **argv) +int main(int argc, char** argv) { srslte::log_filter usim_log("USIM"); usim_log.set_level(srslte::LOG_LEVEL_DEBUG); usim_log.set_hex_limit(100000); uint8_t res[16]; - int res_len; + int res_len; uint8_t k_asme[32]; - uint16 mcc = 0; - uint16 mnc = 0; + uint16 mcc = 0; + uint16 mnc = 0; usim_args_t args; - args.pin = "6129"; + args.pin = "6129"; args.imei = "353490069873319"; srsue::pcsc_usim usim(&usim_log); diff --git a/srsue/test/upper/rrc_reconfig_test.cc b/srsue/test/upper/rrc_reconfig_test.cc index 2df22aec5..07bbeebdc 100644 --- a/srsue/test/upper/rrc_reconfig_test.cc +++ b/srsue/test/upper/rrc_reconfig_test.cc @@ -36,21 +36,17 @@ using namespace asn1; using namespace asn1::rrc; -void nas_test() { +void nas_test() +{ srslte::log_filter log1("NAS"); log1.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(-1); - uint8_t nas_message[128] = {0x27, 0x4f, 0xab, 0xef, 0x59, 0x01, 0x07, 0x42, - 0x01, 0x49, 0x06, 0x40, 0x00, 0xf1, 0x10, 0x31, - 0x32, 0x00, 0x22, 0x52, 0x01, 0xc1, 0x05, 0x07, - 0xff, 0xff, 0xff, 0xff, 0x0c, 0x0b, 0x76, 0x7a, - 0x77, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, - 0x74, 0x05, 0x01, 0x0e, 0x0e, 0x0e, 0x01, 0x5e, - 0x04, 0xfe, 0xfe, 0x81, 0x4e, 0x50, 0x0b, 0xf6, - 0x00, 0xf1, 0x10, 0x00, 0x02, 0x01, 0x01, 0x00, - 0x00, 0x62, 0x17, 0x2c, 0x59, 0x49, 0x64, 0x01, - 0x03}; + uint8_t nas_message[128] = {0x27, 0x4f, 0xab, 0xef, 0x59, 0x01, 0x07, 0x42, 0x01, 0x49, 0x06, 0x40, 0x00, 0xf1, 0x10, + 0x31, 0x32, 0x00, 0x22, 0x52, 0x01, 0xc1, 0x05, 0x07, 0xff, 0xff, 0xff, 0xff, 0x0c, 0x0b, + 0x76, 0x7a, 0x77, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x05, 0x01, 0x0e, 0x0e, + 0x0e, 0x01, 0x5e, 0x04, 0xfe, 0xfe, 0x81, 0x4e, 0x50, 0x0b, 0xf6, 0x00, 0xf1, 0x10, 0x00, + 0x02, 0x01, 0x01, 0x00, 0x00, 0x62, 0x17, 0x2c, 0x59, 0x49, 0x64, 0x01, 0x03}; uint32_t nas_message_len = sizeof(nas_message); uint8 pd; @@ -58,43 +54,43 @@ void nas_test() { LIBLTE_BYTE_MSG_STRUCT buf; LIBLTE_MME_ATTACH_ACCEPT_MSG_STRUCT attach_accept; bzero(&attach_accept, sizeof(LIBLTE_MME_ATTACH_ACCEPT_MSG_STRUCT)); - LIBLTE_MME_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT act_def_eps_bearer_context_req; + LIBLTE_MME_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT act_def_eps_bearer_context_req; bzero(&act_def_eps_bearer_context_req, sizeof(LIBLTE_MME_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT)); bzero(&buf, sizeof(LIBLTE_BYTE_MSG_STRUCT)); memcpy(buf.msg, nas_message, nas_message_len); buf.N_bytes = nas_message_len; liblte_mme_parse_msg_header(&buf, &pd, &msg_type); - switch(msg_type) - { - case LIBLTE_MME_MSG_TYPE_ATTACH_ACCEPT: + switch (msg_type) { + case LIBLTE_MME_MSG_TYPE_ATTACH_ACCEPT: liblte_mme_unpack_attach_accept_msg(&buf, &attach_accept); - liblte_mme_unpack_activate_default_eps_bearer_context_request_msg(&attach_accept.esm_msg, &act_def_eps_bearer_context_req); + liblte_mme_unpack_activate_default_eps_bearer_context_request_msg(&attach_accept.esm_msg, + &act_def_eps_bearer_context_req); break; - case LIBLTE_MME_MSG_TYPE_ATTACH_REJECT: + case LIBLTE_MME_MSG_TYPE_ATTACH_REJECT: break; - case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_REQUEST: + case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_REQUEST: break; - case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_REJECT: + case LIBLTE_MME_MSG_TYPE_AUTHENTICATION_REJECT: break; - case LIBLTE_MME_MSG_TYPE_IDENTITY_REQUEST: + case LIBLTE_MME_MSG_TYPE_IDENTITY_REQUEST: break; - case LIBLTE_MME_MSG_TYPE_SECURITY_MODE_COMMAND: + case LIBLTE_MME_MSG_TYPE_SECURITY_MODE_COMMAND: break; - case LIBLTE_MME_MSG_TYPE_SERVICE_REJECT: + case LIBLTE_MME_MSG_TYPE_SERVICE_REJECT: break; - case LIBLTE_MME_MSG_TYPE_ESM_INFORMATION_REQUEST: + case LIBLTE_MME_MSG_TYPE_ESM_INFORMATION_REQUEST: break; - case LIBLTE_MME_MSG_TYPE_EMM_INFORMATION: + case LIBLTE_MME_MSG_TYPE_EMM_INFORMATION: break; - default: + default: break; } } @@ -157,8 +153,8 @@ int basic_test() return 0; } - -int main(int argc, char **argv) { +int main(int argc, char** argv) +{ TESTASSERT(basic_test() == 0); nas_test(); } diff --git a/srsue/test/upper/tft_test.cc b/srsue/test/upper/tft_test.cc index 616e97154..f684ee0d2 100644 --- a/srsue/test/upper/tft_test.cc +++ b/srsue/test/upper/tft_test.cc @@ -72,7 +72,7 @@ int tft_filter_test_single_local_port() log1.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(128); - srslte::byte_buffer_pool *pool = srslte::byte_buffer_pool::get_instance(); + srslte::byte_buffer_pool* pool = srslte::byte_buffer_pool::get_instance(); srslte::unique_byte_buffer_t ip_msg1, ip_msg2; ip_msg1 = allocate_unique_buffer(*pool); ip_msg2 = allocate_unique_buffer(*pool); @@ -84,13 +84,11 @@ int tft_filter_test_single_local_port() filter_message[0] = SINGLE_LOCAL_PORT_TYPE; srslte::uint16_to_uint8(2222, &filter_message[1]); - // Set IP test message ip_msg1->N_bytes = ip_message_len1; memcpy(ip_msg1->msg, ip_tst_message1, ip_message_len1); log1.info_hex(ip_msg1->msg, ip_msg1->N_bytes, "IP test message\n"); - // Set IP test message ip_msg2->N_bytes = ip_message_len2; memcpy(ip_msg2->msg, ip_tst_message2, ip_message_len1); @@ -99,10 +97,10 @@ int tft_filter_test_single_local_port() // Packet filter LIBLTE_MME_PACKET_FILTER_STRUCT packet_filter; - packet_filter.dir = LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_BIDIRECTIONAL; - packet_filter.id = 1; + packet_filter.dir = LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_BIDIRECTIONAL; + packet_filter.id = 1; packet_filter.eval_precedence = 0; - packet_filter.filter_size = 3; + packet_filter.filter_size = 3; memcpy(packet_filter.filter, filter_message, 3); srsue::tft_packet_filter_t filter(EPS_BEARER_ID, LCID, packet_filter, &log1); @@ -121,7 +119,7 @@ int tft_filter_test_single_remote_port() log1.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(128); - srslte::byte_buffer_pool *pool = srslte::byte_buffer_pool::get_instance(); + srslte::byte_buffer_pool* pool = srslte::byte_buffer_pool::get_instance(); srslte::unique_byte_buffer_t ip_msg1, ip_msg2; ip_msg1 = allocate_unique_buffer(*pool); ip_msg2 = allocate_unique_buffer(*pool); @@ -138,7 +136,6 @@ int tft_filter_test_single_remote_port() memcpy(ip_msg1->msg, ip_tst_message1, ip_message_len1); log1.info_hex(ip_msg1->msg, ip_msg1->N_bytes, "IP test message\n"); - // Set IP test message ip_msg2->N_bytes = ip_message_len2; memcpy(ip_msg2->msg, ip_tst_message2, ip_message_len1); @@ -147,10 +144,10 @@ int tft_filter_test_single_remote_port() // Packet filter LIBLTE_MME_PACKET_FILTER_STRUCT packet_filter; - packet_filter.dir = LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_BIDIRECTIONAL; - packet_filter.id = 1; + packet_filter.dir = LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_BIDIRECTIONAL; + packet_filter.id = 1; packet_filter.eval_precedence = 0; - packet_filter.filter_size = 3; + packet_filter.filter_size = 3; memcpy(packet_filter.filter, filter_message, 3); srsue::tft_packet_filter_t filter(EPS_BEARER_ID, LCID, packet_filter, &log1); @@ -169,7 +166,7 @@ int tft_filter_test_ipv4_local_addr() log1.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(128); - srslte::byte_buffer_pool *pool = srslte::byte_buffer_pool::get_instance(); + srslte::byte_buffer_pool* pool = srslte::byte_buffer_pool::get_instance(); srslte::unique_byte_buffer_t ip_msg1, ip_msg2; ip_msg1 = allocate_unique_buffer(*pool); ip_msg2 = allocate_unique_buffer(*pool); @@ -179,7 +176,7 @@ int tft_filter_test_ipv4_local_addr() // Local address: 127.0.0.1 uint8_t filter_message[5]; uint8_t filter_size = 5; - filter_message[0] = IPV4_LOCAL_ADDR_TYPE; + filter_message[0] = IPV4_LOCAL_ADDR_TYPE; inet_pton(AF_INET, "127.0.0.1", &filter_message[1]); // Set IP test message @@ -187,7 +184,6 @@ int tft_filter_test_ipv4_local_addr() memcpy(ip_msg1->msg, ip_tst_message1, ip_message_len1); log1.info_hex(ip_msg1->msg, ip_msg1->N_bytes, "IP test message\n"); - // Set IP test message ip_msg2->N_bytes = ip_message_len2; memcpy(ip_msg2->msg, ip_tst_message2, ip_message_len2); @@ -196,10 +192,10 @@ int tft_filter_test_ipv4_local_addr() // Packet filter LIBLTE_MME_PACKET_FILTER_STRUCT packet_filter; - packet_filter.dir = LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_BIDIRECTIONAL; - packet_filter.id = 1; + packet_filter.dir = LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_BIDIRECTIONAL; + packet_filter.id = 1; packet_filter.eval_precedence = 0; - packet_filter.filter_size = filter_size; + packet_filter.filter_size = filter_size; memcpy(packet_filter.filter, filter_message, filter_size); srsue::tft_packet_filter_t filter(EPS_BEARER_ID, LCID, packet_filter, &log1); @@ -218,7 +214,7 @@ int tft_filter_test_ipv4_remote_addr() log1.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(128); - srslte::byte_buffer_pool *pool = srslte::byte_buffer_pool::get_instance(); + srslte::byte_buffer_pool* pool = srslte::byte_buffer_pool::get_instance(); srslte::unique_byte_buffer_t ip_msg1, ip_msg2; ip_msg1 = allocate_unique_buffer(*pool); ip_msg2 = allocate_unique_buffer(*pool); @@ -228,7 +224,7 @@ int tft_filter_test_ipv4_remote_addr() // Remote address: 127.0.0.2 uint8_t filter_message[5]; uint8_t filter_size = 5; - filter_message[0] = IPV4_REMOTE_ADDR_TYPE; + filter_message[0] = IPV4_REMOTE_ADDR_TYPE; inet_pton(AF_INET, "127.0.0.2", &filter_message[1]); // Set IP test message @@ -236,7 +232,6 @@ int tft_filter_test_ipv4_remote_addr() memcpy(ip_msg1->msg, ip_tst_message1, ip_message_len1); log1.info_hex(ip_msg1->msg, ip_msg1->N_bytes, "IP test message\n"); - // Set IP test message ip_msg2->N_bytes = ip_message_len2; memcpy(ip_msg2->msg, ip_tst_message2, ip_message_len2); @@ -245,10 +240,10 @@ int tft_filter_test_ipv4_remote_addr() // Packet filter LIBLTE_MME_PACKET_FILTER_STRUCT packet_filter; - packet_filter.dir = LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_BIDIRECTIONAL; - packet_filter.id = 1; + packet_filter.dir = LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_BIDIRECTIONAL; + packet_filter.id = 1; packet_filter.eval_precedence = 0; - packet_filter.filter_size = filter_size; + packet_filter.filter_size = filter_size; memcpy(packet_filter.filter, filter_message, filter_size); srsue::tft_packet_filter_t filter(EPS_BEARER_ID, LCID, packet_filter, &log1); @@ -267,7 +262,7 @@ int tft_filter_test_ipv4_tos() log1.set_level(srslte::LOG_LEVEL_DEBUG); log1.set_hex_limit(128); - srslte::byte_buffer_pool *pool = srslte::byte_buffer_pool::get_instance(); + srslte::byte_buffer_pool* pool = srslte::byte_buffer_pool::get_instance(); srslte::unique_byte_buffer_t ip_msg1, ip_msg2; ip_msg1 = allocate_unique_buffer(*pool); ip_msg2 = allocate_unique_buffer(*pool); @@ -277,8 +272,8 @@ int tft_filter_test_ipv4_tos() // ToS: 4 uint8_t filter_message[2]; uint8_t filter_size = 2; - filter_message[0] = TYPE_OF_SERVICE_TYPE; - filter_message[1] = 4; + filter_message[0] = TYPE_OF_SERVICE_TYPE; + filter_message[1] = 4; // Set IP test message ip_msg1->N_bytes = ip_message_len1; @@ -293,10 +288,10 @@ int tft_filter_test_ipv4_tos() // Packet filter LIBLTE_MME_PACKET_FILTER_STRUCT packet_filter; - packet_filter.dir = LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_BIDIRECTIONAL; - packet_filter.id = 1; + packet_filter.dir = LIBLTE_MME_TFT_PACKET_FILTER_DIRECTION_BIDIRECTIONAL; + packet_filter.id = 1; packet_filter.eval_precedence = 0; - packet_filter.filter_size = filter_size; + packet_filter.filter_size = filter_size; memcpy(packet_filter.filter, filter_message, filter_size); srsue::tft_packet_filter_t filter(EPS_BEARER_ID, LCID, packet_filter, &log1); @@ -309,7 +304,7 @@ int tft_filter_test_ipv4_tos() return 0; } -int main(int argc, char **argv) +int main(int argc, char** argv) { srslte::byte_buffer_pool::get_instance(); if (tft_filter_test_single_local_port()) { diff --git a/srsue/test/upper/usim_test.cc b/srsue/test/upper/usim_test.cc index 251aa2add..a42db657a 100644 --- a/srsue/test/upper/usim_test.cc +++ b/srsue/test/upper/usim_test.cc @@ -60,20 +60,20 @@ uint8_t autn_enb[] = {0xd7, 0x44, 0x51, 0x9b, 0x25, 0xaa, 0x80, 0x00, 0x84, 0xba uint16 mcc = 208; uint16 mnc = 93; -int main(int argc, char **argv) +int main(int argc, char** argv) { srslte::log_filter usim_log("USIM"); - uint8_t res[16]; - int res_len; - uint8_t k_asme[32]; + uint8_t res[16]; + int res_len; + uint8_t k_asme[32]; usim_args_t args; - args.algo = "milenage"; - args.imei = "356092040793011"; - args.imsi = "208930000000001"; - args.k = "8BAF473F2F8FD09487CCCBD7097C6862"; + args.algo = "milenage"; + args.imei = "356092040793011"; + args.imsi = "208930000000001"; + args.k = "8BAF473F2F8FD09487CCCBD7097C6862"; args.using_op = true; - args.op = "11111111111111111111111111111111"; + args.op = "11111111111111111111111111111111"; srsue::usim usim(&usim_log); usim.init(&args);