From a6423442c237d84a59acc061651c0095338d5960 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Wed, 20 Jan 2021 15:46:46 +0100 Subject: [PATCH] Refactor NR RA files and fix header includes all over library (#2162) * Refactor NR resource allocation classes. Use DCI instead of grant for dummy PDSCH UE/eNB test * Minor refactors in NR workers and ue_dl * Fix include issues * fix compilation issues --- lib/include/srslte/common/common.h | 3 +- lib/include/srslte/common/common_helper.h | 1 + lib/include/srslte/common/config_file.h | 1 + lib/include/srslte/common/interfaces_common.h | 1 + lib/include/srslte/common/metrics_hub.h | 1 - lib/include/srslte/common/network_utils.h | 4 + lib/include/srslte/common/timeout.h | 2 +- lib/include/srslte/common/timers.h | 3 +- .../srslte/interfaces/gnb_interfaces.h | 35 ++- .../srslte/interfaces/pdcp_interface_types.h | 3 +- lib/include/srslte/mac/mac_nr_pdu.h | 1 + lib/include/srslte/mac/pdu.h | 1 + .../srslte/phy/ch_estimation/dmrs_pdcch.h | 11 +- .../srslte/phy/ch_estimation/dmrs_sch.h | 10 +- lib/include/srslte/phy/channel/channel.h | 4 +- lib/include/srslte/phy/channel/delay.h | 5 +- lib/include/srslte/phy/channel/fading.h | 5 +- lib/include/srslte/phy/channel/hst.h | 4 +- lib/include/srslte/phy/channel/rlf.h | 4 +- lib/include/srslte/phy/common/phy_common_nr.h | 4 + lib/include/srslte/phy/enb/enb_dl_nr.h | 38 +-- lib/include/srslte/phy/modem/evm.h | 3 +- lib/include/srslte/phy/phch/dci_nr.h | 11 +- lib/include/srslte/phy/phch/pdcch_nr.h | 3 +- lib/include/srslte/phy/phch/pdsch_nr.h | 2 + lib/include/srslte/phy/phch/phch_cfg_nr.h | 18 +- lib/include/srslte/phy/phch/pusch_nr.h | 2 + .../{ue/ue_dl_nr_data.h => phch/ra_dl_nr.h} | 52 ++-- lib/include/srslte/phy/phch/ra_nr.h | 26 +- lib/include/srslte/phy/ue/ue_dl_nr.h | 17 +- lib/include/srslte/phy/ue/ue_ul_nr_data.h | 7 - lib/include/srslte/srslte.h | 9 + lib/include/srslte/upper/ipv6.h | 2 + lib/src/common/mac_pcap.cc | 6 +- lib/src/common/security.cc | 1 + lib/src/phy/CMakeLists.txt | 4 +- lib/src/phy/ch_estimation/dmrs_pdcch.c | 7 + lib/src/phy/ch_estimation/dmrs_sch.c | 1 + .../phy/ch_estimation/test/dmrs_pdsch_test.c | 4 +- lib/src/phy/channel/hst.c | 3 + lib/src/phy/enb/enb_dl_nr.c | 54 ++-- lib/src/phy/phch/dci_nr.c | 28 ++ lib/src/phy/phch/pdcch_nr.c | 4 + lib/src/phy/phch/pdsch_nr.c | 4 + lib/src/phy/phch/pusch_nr.c | 3 + lib/src/phy/phch/ra_dl_nr.c | 256 ++++++++++++++++++ lib/src/phy/phch/ra_nr.c | 45 ++- lib/src/phy/phch/test/pdcch_nr_test.c | 1 + lib/src/phy/phch/test/pdsch_nr_test.c | 8 +- lib/src/phy/phch/test/pusch_nr_test.c | 1 + lib/src/phy/phch/test/ra_nr_test.c | 101 +++++++ lib/src/phy/phch/test/sch_nr_test.c | 4 +- lib/src/phy/ue/ue_dl_nr.c | 18 +- lib/src/phy/ue/ue_dl_nr_data.c | 157 ----------- lib/src/phy/utils/debug.c | 2 +- lib/src/upper/gtpu.cc | 2 + lib/test/asn1/nas_decoder.cc | 1 + lib/test/asn1/s1ap_test.cc | 2 + lib/test/common/timeout_test.cc | 3 + lib/test/phy/phy_dl_nr_test.c | 19 +- srsenb/hdr/phy/nr/cc_worker.h | 10 +- srsenb/hdr/phy/nr/sf_worker.h | 6 +- srsenb/hdr/stack/rrc/rrc_config.h | 1 + srsenb/src/metrics_csv.cc | 1 + srsenb/src/metrics_stdout.cc | 1 + srsenb/src/phy/nr/cc_worker.cc | 113 ++++---- srsenb/src/phy/nr/sf_worker.cc | 43 ++- srsenb/src/stack/rrc/rrc_cell_cfg.cc | 1 + srsepc/src/hss/hss.cc | 1 + srsepc/src/main.cc | 1 + srsepc/src/spgw/gtpc.cc | 1 + srsepc/src/spgw/gtpu.cc | 1 + srsue/hdr/phy/nr/cc_worker.h | 9 +- srsue/hdr/stack/rrc/rrc.h | 2 +- srsue/src/phy/nr/cc_worker.cc | 65 +++-- srsue/src/stack/rrc/rrc.cc | 2 +- srsue/src/stack/rrc/rrc_nr.cc | 4 +- srsue/src/stack/upper/tft_packet_filter.cc | 4 +- 78 files changed, 872 insertions(+), 426 deletions(-) rename lib/include/srslte/phy/{ue/ue_dl_nr_data.h => phch/ra_dl_nr.h} (54%) create mode 100644 lib/src/phy/phch/ra_dl_nr.c create mode 100644 lib/src/phy/phch/test/ra_nr_test.c delete mode 100644 lib/src/phy/ue/ue_dl_nr_data.c diff --git a/lib/include/srslte/common/common.h b/lib/include/srslte/common/common.h index 48d85cd63..4b8c727b7 100644 --- a/lib/include/srslte/common/common.h +++ b/lib/include/srslte/common/common.h @@ -22,6 +22,7 @@ #include #include #include +#include /******************************************************************************* DEFINES @@ -75,8 +76,6 @@ #define pool_allocate_blocking (srslte::allocate_unique_buffer(*pool, true)) #endif -#include "srslte/srslte.h" - /******************************************************************************* TYPEDEFS *******************************************************************************/ diff --git a/lib/include/srslte/common/common_helper.h b/lib/include/srslte/common/common_helper.h index 0e11afbdf..45c637907 100644 --- a/lib/include/srslte/common/common_helper.h +++ b/lib/include/srslte/common/common_helper.h @@ -20,6 +20,7 @@ #include "srslte/common/logmap.h" #include +#include #include namespace srslte { diff --git a/lib/include/srslte/common/config_file.h b/lib/include/srslte/common/config_file.h index 91122df1a..6882f4f33 100644 --- a/lib/include/srslte/common/config_file.h +++ b/lib/include/srslte/common/config_file.h @@ -14,6 +14,7 @@ #define SRSLTE_CONFIG_FILE_H #include "common.h" +#include "srslte/phy/common/phy_common.h" #include #include #include diff --git a/lib/include/srslte/common/interfaces_common.h b/lib/include/srslte/common/interfaces_common.h index 2efedca6b..c515afb07 100644 --- a/lib/include/srslte/common/interfaces_common.h +++ b/lib/include/srslte/common/interfaces_common.h @@ -14,6 +14,7 @@ #define SRSLTE_INTERFACES_COMMON_H #include "srslte/common/security.h" +#include "srslte/phy/common/phy_common.h" #include namespace srslte { diff --git a/lib/include/srslte/common/metrics_hub.h b/lib/include/srslte/common/metrics_hub.h index 90841d4fa..e51b903a9 100644 --- a/lib/include/srslte/common/metrics_hub.h +++ b/lib/include/srslte/common/metrics_hub.h @@ -20,7 +20,6 @@ #define SRSLTE_METRICS_HUB_H #include "srslte/common/threads.h" -#include "srslte/srslte.h" #include #include #include diff --git a/lib/include/srslte/common/network_utils.h b/lib/include/srslte/common/network_utils.h index 899fbd4ce..af56a2823 100644 --- a/lib/include/srslte/common/network_utils.h +++ b/lib/include/srslte/common/network_utils.h @@ -17,10 +17,14 @@ #include "srslte/common/logmap.h" #include "srslte/common/threads.h" +#include #include #include #include +#include #include +#include +#include #include #include #include diff --git a/lib/include/srslte/common/timeout.h b/lib/include/srslte/common/timeout.h index ca28789a8..5de6e5fab 100644 --- a/lib/include/srslte/common/timeout.h +++ b/lib/include/srslte/common/timeout.h @@ -20,7 +20,7 @@ #ifndef SRSLTE_TIMEOUT_H #define SRSLTE_TIMEOUT_H -#include "srslte/srslte.h" +#include "srslte/phy/utils/debug.h" #include #include #include diff --git a/lib/include/srslte/common/timers.h b/lib/include/srslte/common/timers.h index 81ca86c7c..7c0b0fce1 100644 --- a/lib/include/srslte/common/timers.h +++ b/lib/include/srslte/common/timers.h @@ -20,6 +20,7 @@ #ifndef SRSLTE_TIMERS_H #define SRSLTE_TIMERS_H +#include "srslte/phy/utils/debug.h" #include #include #include @@ -30,8 +31,6 @@ #include #include -#include "srslte/srslte.h" - namespace srslte { class timer_callback diff --git a/lib/include/srslte/interfaces/gnb_interfaces.h b/lib/include/srslte/interfaces/gnb_interfaces.h index 9eaa6ea14..04de849ed 100644 --- a/lib/include/srslte/interfaces/gnb_interfaces.h +++ b/lib/include/srslte/interfaces/gnb_interfaces.h @@ -13,6 +13,8 @@ #ifndef SRSLTE_GNB_INTERFACES_H #define SRSLTE_GNB_INTERFACES_H +#include "srslte/srslte.h" + #include "srslte/common/interfaces_common.h" #include "srslte/common/security.h" #include "srslte/interfaces/pdcp_interface_types.h" @@ -210,7 +212,35 @@ public: virtual void process_pdus() = 0; }; -class stack_interface_phy_nr : public srslte::stack_interface_phy_nr +class mac_interface_phy_nr +{ +public: + const static int MAX_GRANTS = 64; + + /** + * DL grant structure per UE + */ + struct dl_sched_grant_t { + srslte_dci_dl_nr_t dci = {}; + uint8_t* data[SRSLTE_MAX_TB] = {}; + srslte_softbuffer_tx_t* softbuffer_tx[SRSLTE_MAX_TB] = {}; + }; + + /** + * DL Scheduling result per cell/carrier + */ + typedef struct { + dl_sched_grant_t pdsch[MAX_GRANTS]; //< DL Grants + uint32_t nof_grants; //< Number of DL grants + } dl_sched_t; + + /** + * List of DL scheduling results, one entry per cell/carrier + */ + typedef std::vector dl_sched_list_t; +}; + +class stack_interface_phy_nr : public mac_interface_phy_nr, public srslte::stack_interface_phy_nr { public: struct rx_data_ind_t { @@ -223,9 +253,6 @@ public: virtual int rx_data_indication(rx_data_ind_t& grant) = 0; }; -class mac_interface_phy_nr -{}; - } // namespace srsenb #endif // SRSLTE_GNB_INTERFACES_H diff --git a/lib/include/srslte/interfaces/pdcp_interface_types.h b/lib/include/srslte/interfaces/pdcp_interface_types.h index bc246c69a..71b594db8 100644 --- a/lib/include/srslte/interfaces/pdcp_interface_types.h +++ b/lib/include/srslte/interfaces/pdcp_interface_types.h @@ -19,6 +19,7 @@ #define SRSLTE_PDCP_INTERFACE_TYPES_H #include "srslte/common/security.h" +#include #include namespace srslte { @@ -119,7 +120,7 @@ public: t_reordering(t_reordering_), discard_timer(discard_timer_) { - hdr_len_bytes = ceil((float)sn_len / 8); + hdr_len_bytes = ceilf((float)sn_len / 8); } uint8_t bearer_id = 1; diff --git a/lib/include/srslte/mac/mac_nr_pdu.h b/lib/include/srslte/mac/mac_nr_pdu.h index 03b0d41ca..c35e9c68e 100644 --- a/lib/include/srslte/mac/mac_nr_pdu.h +++ b/lib/include/srslte/mac/mac_nr_pdu.h @@ -15,6 +15,7 @@ #include "srslte/common/common.h" #include "srslte/common/logmap.h" +#include "srslte/config.h" #include #include #include diff --git a/lib/include/srslte/mac/pdu.h b/lib/include/srslte/mac/pdu.h index 6fe2d082e..07c14ef11 100644 --- a/lib/include/srslte/mac/pdu.h +++ b/lib/include/srslte/mac/pdu.h @@ -15,6 +15,7 @@ #include "srslte/common/interfaces_common.h" #include "srslte/common/logmap.h" +#include #include #include #include diff --git a/lib/include/srslte/phy/ch_estimation/dmrs_pdcch.h b/lib/include/srslte/phy/ch_estimation/dmrs_pdcch.h index 66ed51cea..f917f1b9f 100644 --- a/lib/include/srslte/phy/ch_estimation/dmrs_pdcch.h +++ b/lib/include/srslte/phy/ch_estimation/dmrs_pdcch.h @@ -14,12 +14,9 @@ #define SRSLTE_DMRS_PDCCH_H #include "srslte/phy/common/phy_common_nr.h" +#include "srslte/phy/phch/dci_nr.h" +#include "srslte/phy/resampling/interp.h" #include "srslte/phy/resampling/resampler.h" -#include "srslte/srslte.h" - -#ifdef __cplusplus -extern "C" { -#endif /** * @brief Puts in the resource grid the DeModulation Reference Signals for decoding PDCCH. @@ -182,8 +179,4 @@ SRSLTE_API int srslte_dmrs_pdcch_get_ce(const srslte_dmrs_pdcch_estimator_t* q, const srslte_dci_location_t* location, srslte_dmrs_pdcch_ce_t* ce); -#ifdef __cplusplus -} -#endif - #endif // SRSLTE_DMRS_PDCCH_H diff --git a/lib/include/srslte/phy/ch_estimation/dmrs_sch.h b/lib/include/srslte/phy/ch_estimation/dmrs_sch.h index 56abf30a1..6dc7493f6 100644 --- a/lib/include/srslte/phy/ch_estimation/dmrs_sch.h +++ b/lib/include/srslte/phy/ch_estimation/dmrs_sch.h @@ -13,15 +13,11 @@ #ifndef SRSLTE_DMRS_SCH_H #define SRSLTE_DMRS_SCH_H +#include "srslte/phy/ch_estimation/chest_dl.h" #include "srslte/phy/common/phy_common_nr.h" #include "srslte/phy/phch/phch_cfg_nr.h" -#include "srslte/srslte.h" #include -#ifdef __cplusplus -extern "C" { -#endif - #define SRSLTE_DMRS_SCH_MAX_SYMBOLS 4 /** @@ -156,8 +152,4 @@ SRSLTE_API int srslte_dmrs_sch_estimate(srslte_dmrs_sch_t* q, const cf_t* sf_symbols, srslte_chest_dl_res_t* chest_res); -#ifdef __cplusplus -} -#endif - #endif // SRSLTE_DMRS_SCH_H diff --git a/lib/include/srslte/phy/channel/channel.h b/lib/include/srslte/phy/channel/channel.h index df6a5cd90..2ba2c0d8a 100644 --- a/lib/include/srslte/phy/channel/channel.h +++ b/lib/include/srslte/phy/channel/channel.h @@ -13,12 +13,14 @@ #ifndef SRSLTE_CHANNEL_H #define SRSLTE_CHANNEL_H +#include "ch_awgn.h" #include "delay.h" #include "fading.h" #include "hst.h" #include "rlf.h" +#include "srslte/common/log_filter.h" +#include "srslte/phy/common/phy_common.h" #include -#include #include namespace srslte { diff --git a/lib/include/srslte/phy/channel/delay.h b/lib/include/srslte/phy/channel/delay.h index f85cd0418..88b9371ab 100644 --- a/lib/include/srslte/phy/channel/delay.h +++ b/lib/include/srslte/phy/channel/delay.h @@ -13,7 +13,10 @@ #ifndef SRSLTE_DELAY_H #define SRSLTE_DELAY_H -#include +#include "srslte/config.h" +#include "srslte/phy/common/timestamp.h" +#include "srslte/phy/utils/ringbuffer.h" +#include typedef struct { float delay_min_us; diff --git a/lib/include/srslte/phy/channel/fading.h b/lib/include/srslte/phy/channel/fading.h index 3a05ba82f..42fb32f25 100644 --- a/lib/include/srslte/phy/channel/fading.h +++ b/lib/include/srslte/phy/channel/fading.h @@ -13,8 +13,11 @@ #ifndef SRSLTE_FADING_H #define SRSLTE_FADING_H +#include "srslte/config.h" +#include "srslte/phy/common/timestamp.h" +#include "srslte/phy/dft/dft.h" #include -#include +#include #define SRSLTE_CHANNEL_FADING_MAXTAPS 9 #define SRSLTE_CHANNEL_FADING_NTERMS 16 diff --git a/lib/include/srslte/phy/channel/hst.h b/lib/include/srslte/phy/channel/hst.h index 9e5edc278..9b50741dc 100644 --- a/lib/include/srslte/phy/channel/hst.h +++ b/lib/include/srslte/phy/channel/hst.h @@ -13,7 +13,9 @@ #ifndef SRSLTE_HST_H_ #define SRSLTE_HST_H_ -#include +#include "srslte/config.h" +#include "srslte/phy/common/timestamp.h" +#include typedef struct { // System parameters diff --git a/lib/include/srslte/phy/channel/rlf.h b/lib/include/srslte/phy/channel/rlf.h index 59c8cc8ab..142e310b8 100644 --- a/lib/include/srslte/phy/channel/rlf.h +++ b/lib/include/srslte/phy/channel/rlf.h @@ -13,7 +13,9 @@ #ifndef SRSLTE_RLF_H #define SRSLTE_RLF_H -#include +#include "srslte/config.h" +#include "srslte/phy/common/timestamp.h" +#include typedef struct { uint32_t t_on_ms; diff --git a/lib/include/srslte/phy/common/phy_common_nr.h b/lib/include/srslte/phy/common/phy_common_nr.h index 3449f21f2..47a01866f 100644 --- a/lib/include/srslte/phy/common/phy_common_nr.h +++ b/lib/include/srslte/phy/common/phy_common_nr.h @@ -132,6 +132,10 @@ typedef enum SRSLTE_API { srslte_sch_mapping_type_A = 0, srslte_sch_mapping_type typedef enum SRSLTE_API { srslte_search_space_type_common = 0, + srslte_search_space_type_common_0, + srslte_search_space_type_common_0A, + srslte_search_space_type_common_1, + srslte_search_space_type_common_2, srslte_search_space_type_ue, } srslte_search_space_type_t; diff --git a/lib/include/srslte/phy/enb/enb_dl_nr.h b/lib/include/srslte/phy/enb/enb_dl_nr.h index 6d37f2119..e3f00255c 100644 --- a/lib/include/srslte/phy/enb/enb_dl_nr.h +++ b/lib/include/srslte/phy/enb/enb_dl_nr.h @@ -18,10 +18,6 @@ #include "srslte/phy/phch/pdcch_nr.h" #include "srslte/phy/phch/pdsch_nr.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct SRSLTE_API { srslte_pdsch_nr_args_t pdsch; srslte_pdcch_nr_args_t pdcch; @@ -57,27 +53,17 @@ SRSLTE_API int srslte_enb_dl_nr_base_zero(srslte_enb_dl_nr_t* q); SRSLTE_API void srslte_enb_dl_nr_gen_signal(srslte_enb_dl_nr_t* q); -SRSLTE_API int srslte_enb_dl_nr_pdcch_put(srslte_enb_dl_nr_t* q, - const srslte_dl_slot_cfg_t* slot_cfg, - const srslte_search_space_t* search_space, - const srslte_dci_dl_nr_t* dci_dl, - const srslte_dci_location_t* dci_location, - uint16_t rnti); - -SRSLTE_API int srslte_enb_dl_nr_pdsch_put(srslte_enb_dl_nr_t* q, - const srslte_dl_slot_cfg_t* slot, - const srslte_sch_cfg_nr_t* cfg, - const srslte_sch_grant_nr_t* grant, - uint8_t* data[SRSLTE_MAX_TB]); - -SRSLTE_API int srslte_enb_dl_nr_pdsch_info(const srslte_enb_dl_nr_t* q, - const srslte_sch_cfg_nr_t* cfg, - const srslte_sch_grant_nr_t* grant, - char* str, - uint32_t str_len); - -#ifdef __cplusplus -} -#endif +SRSLTE_API int srslte_enb_dl_nr_pdcch_put(srslte_enb_dl_nr_t* q, + const srslte_dl_slot_cfg_t* slot_cfg, + const srslte_dci_dl_nr_t* dci_dl); + +SRSLTE_API int srslte_enb_dl_nr_pdsch_put(srslte_enb_dl_nr_t* q, + const srslte_dl_slot_cfg_t* slot, + const srslte_sch_cfg_nr_t* cfg, + uint8_t* data[SRSLTE_MAX_TB]); + +SRSLTE_API int +srslte_enb_dl_nr_pdsch_info(const srslte_enb_dl_nr_t* q, const srslte_sch_cfg_nr_t* cfg, char* str, uint32_t str_len); + #endif // SRSLTE_ENB_DL_NR_H diff --git a/lib/include/srslte/phy/modem/evm.h b/lib/include/srslte/phy/modem/evm.h index 1aec640a7..69f81dd62 100644 --- a/lib/include/srslte/phy/modem/evm.h +++ b/lib/include/srslte/phy/modem/evm.h @@ -13,7 +13,8 @@ #ifndef SRSLTE_EVM_H_ #define SRSLTE_EVM_H_ -#include "srslte/config.h" +#include "srslte/phy/modem/mod.h" +#include "srslte/phy/modem/modem_table.h" #include "srslte/phy/phch/ra.h" #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" diff --git a/lib/include/srslte/phy/phch/dci_nr.h b/lib/include/srslte/phy/phch/dci_nr.h index d7fe44625..bdf388c0b 100644 --- a/lib/include/srslte/phy/phch/dci_nr.h +++ b/lib/include/srslte/phy/phch/dci_nr.h @@ -28,7 +28,11 @@ typedef struct SRSLTE_API { } srslte_dci_msg_nr_t; typedef struct SRSLTE_API { - srslte_rnti_type_t rnti_type; + uint16_t rnti; + srslte_rnti_type_t rnti_type; + srslte_dci_format_nr_t format; + srslte_dci_location_t location; + srslte_search_space_t search_space; // Common fields uint32_t freq_domain_assigment; ///< Frequency domain resource assignment @@ -56,6 +60,11 @@ typedef struct SRSLTE_API { } srslte_dci_dl_nr_t; +SRSLTE_API int srslte_dci_nr_pack(const srslte_carrier_nr_t* carrier, + const srslte_coreset_t* coreset, + const srslte_dci_dl_nr_t* dci, + srslte_dci_msg_nr_t* msg); + SRSLTE_API SRSLTE_API int srslte_dci_nr_format_1_0_sizeof(const srslte_carrier_nr_t* carrier, const srslte_coreset_t* coreset, srslte_rnti_type_t rnti_type); diff --git a/lib/include/srslte/phy/phch/pdcch_nr.h b/lib/include/srslte/phy/phch/pdcch_nr.h index 1f0669064..385e9c617 100644 --- a/lib/include/srslte/phy/phch/pdcch_nr.h +++ b/lib/include/srslte/phy/phch/pdcch_nr.h @@ -22,7 +22,6 @@ #define SRSLTE_PDCCH_NR_H #include "dci_nr.h" -#include "srslte/config.h" #include "srslte/phy/ch_estimation/dmrs_pdcch.h" #include "srslte/phy/common/phy_common_nr.h" #include "srslte/phy/fec/crc.h" @@ -30,6 +29,8 @@ #include "srslte/phy/fec/polar/polar_decoder.h" #include "srslte/phy/fec/polar/polar_encoder.h" #include "srslte/phy/fec/polar/polar_rm.h" +#include "srslte/phy/modem/evm.h" +#include "srslte/phy/modem/modem_table.h" /** * @brief PDCCH configuration initialization arguments diff --git a/lib/include/srslte/phy/phch/pdsch_nr.h b/lib/include/srslte/phy/phch/pdsch_nr.h index a4b079f2e..e6a96f31d 100644 --- a/lib/include/srslte/phy/phch/pdsch_nr.h +++ b/lib/include/srslte/phy/phch/pdsch_nr.h @@ -23,6 +23,8 @@ #include "srslte/config.h" #include "srslte/phy/ch_estimation/dmrs_sch.h" +#include "srslte/phy/modem/evm.h" +#include "srslte/phy/modem/modem_table.h" #include "srslte/phy/phch/phch_cfg_nr.h" #include "srslte/phy/phch/regs.h" #include "srslte/phy/phch/sch_nr.h" diff --git a/lib/include/srslte/phy/phch/phch_cfg_nr.h b/lib/include/srslte/phy/phch/phch_cfg_nr.h index 5de15cea0..aa73c9540 100644 --- a/lib/include/srslte/phy/phch/phch_cfg_nr.h +++ b/lib/include/srslte/phy/phch/phch_cfg_nr.h @@ -24,10 +24,6 @@ #include "srslte/phy/common/phy_common_nr.h" #include "srslte/phy/phch/sch_cfg_nr.h" -#ifdef __cplusplus -extern "C" { -#endif - /** * @brief PDSCH DMRS type */ @@ -100,7 +96,7 @@ typedef struct SRSLTE_API { /// (SLIV). The network configures the field so that the allocation does not cross the slot boundary uint32_t sliv; -} srslte_pdsch_allocation_t; +} srslte_pdsch_time_ra_t; /** * @brief PDSCH grant information provided by the Downlink Control Information (DCI) @@ -119,6 +115,7 @@ typedef struct SRSLTE_API { /// Frequency domain resources bool prb_idx[SRSLTE_MAX_PRB_NR]; + uint32_t nof_prb; /// Number of DMRS groups without data /// Described in TS 38.214 Section 5.1.6.2 @@ -153,6 +150,13 @@ typedef struct SRSLTE_API { srslte_dmrs_sch_cfg_t dmrs_typeA; srslte_dmrs_sch_cfg_t dmrs_typeB; + srslte_sch_grant_nr_t grant; + + bool pdsch_time_is_default; ///< Set to true if pdsch_time_ra contains the configuration from pdsch-ConfigCommon or + ///< pdsch-Config + srslte_pdsch_time_ra_t pdsch_time_ra[SRSLTE_MAX_NOF_DL_ALLOCATION]; + + bool rbg_size_cfg_1; ///< RBG size configuration (1 or 2) srslte_sch_cfg_t sch_cfg; ///< Common shared channel parameters @@ -160,8 +164,4 @@ typedef struct SRSLTE_API { bool enable_transform_precoder; } srslte_sch_cfg_nr_t; -#ifdef __cplusplus -} -#endif - #endif // SRSLTE_PHCH_CFG_NR_H diff --git a/lib/include/srslte/phy/phch/pusch_nr.h b/lib/include/srslte/phy/phch/pusch_nr.h index 64b99012e..1ccf7e16d 100644 --- a/lib/include/srslte/phy/phch/pusch_nr.h +++ b/lib/include/srslte/phy/phch/pusch_nr.h @@ -15,6 +15,8 @@ #include "srslte/config.h" #include "srslte/phy/ch_estimation/dmrs_sch.h" +#include "srslte/phy/modem/evm.h" +#include "srslte/phy/modem/modem_table.h" #include "srslte/phy/phch/phch_cfg_nr.h" #include "srslte/phy/phch/regs.h" #include "srslte/phy/phch/sch_nr.h" diff --git a/lib/include/srslte/phy/ue/ue_dl_nr_data.h b/lib/include/srslte/phy/phch/ra_dl_nr.h similarity index 54% rename from lib/include/srslte/phy/ue/ue_dl_nr_data.h rename to lib/include/srslte/phy/phch/ra_dl_nr.h index b4c2266e5..5437aa962 100644 --- a/lib/include/srslte/phy/ue/ue_dl_nr_data.h +++ b/lib/include/srslte/phy/phch/ra_dl_nr.h @@ -20,28 +20,31 @@ * Reference: *****************************************************************************/ -#ifndef SRSLTE_UE_DL_NR_DATA_H -#define SRSLTE_UE_DL_NR_DATA_H +#ifndef SRSLTE_RA_DL_NR_H +#define SRSLTE_RA_DL_NR_H #include "srslte/phy/common/phy_common_nr.h" +#include "srslte/phy/phch/dci_nr.h" #include "srslte/phy/phch/phch_cfg_nr.h" -#ifdef __cplusplus -extern "C" { -#endif - /** - * @brief Calculates the PDSCH time resource provided by higher layers and stores it in the provided PDSCH NR grant. + * @brief Calculates the PDSCH time resource allocation and stores it in the provided PDSCH NR grant. * * @remark Defined by TS 38.214 V15.10.0 section 5.1.2.1.1 Determination of the resource allocation table to be used for * PDSCH * - * @param pdsch_alloc Flattened PHY PDSCH allocation configuration provided from higher layers - * @param[out] grant PDSCH mapping type + * @param pdsch_cfg Flattened PDSCH configuration provided from higher layers + * @param rnti_type Type of the RNTI of the corresponding DCI + * @param ss_type Type of the SS for PDCCH + * @param m Time domain resource assignment field value m provided in DCI + * @param[out] Provides grant pointer to fill * @return Returns SRSLTE_SUCCESS if the provided allocation is valid, otherwise it returns SRSLTE_ERROR code */ -SRSLTE_API int srslte_ue_dl_nr_pdsch_time_resource_hl(const srslte_pdsch_allocation_t* pdsch_alloc, - srslte_sch_grant_nr_t* grant); +SRSLTE_API int srslte_ra_dl_nr_time(const srslte_sch_cfg_nr_t* pdsch_cfg, + const srslte_rnti_type_t rnti_type, + const srslte_search_space_type_t ss_type, + const uint8_t m, + srslte_sch_grant_nr_t* grant); /** * @brief Calculates the PDSCH time resource default A and stores it in the provided PDSCH NR grant. This can be used by @@ -55,9 +58,8 @@ SRSLTE_API int srslte_ue_dl_nr_pdsch_time_resource_hl(const srslte_pdsch_allocat * @param[out] grant PDSCH mapping type * @return Returns SRSLTE_SUCCESS if the provided allocation is valid, otherwise it returns SRSLTE_ERROR code */ -SRSLTE_API int srslte_ue_dl_nr_pdsch_time_resource_default_A(uint32_t m, - srslte_dmrs_sch_typeA_pos_t dmrs_typeA_pos, - srslte_sch_grant_nr_t* grant); +SRSLTE_API int +srslte_ra_dl_nr_time_default_A(uint32_t m, srslte_dmrs_sch_typeA_pos_t dmrs_typeA_pos, srslte_sch_grant_nr_t* grant); /** * @brief Calculates the number of PDSCH-DMRS CDM groups without data for DCI format 1_0 * @@ -67,11 +69,23 @@ SRSLTE_API int srslte_ue_dl_nr_pdsch_time_resource_default_A(uint32_t * @param[out] grant Provides grant pointer to fill * @return Returns SRSLTE_SUCCESS if the provided data is valid, otherwise it returns SRSLTE_ERROR code */ -SRSLTE_API int srslte_ue_dl_nr_nof_dmrs_cdm_groups_without_data_format_1_0(const srslte_sch_cfg_nr_t* pdsch_cfg, +SRSLTE_API int srslte_ra_dl_nr_nof_dmrs_cdm_groups_without_data_format_1_0(const srslte_sch_cfg_nr_t* pdsch_cfg, srslte_sch_grant_nr_t* grant); -#ifdef __cplusplus -} -#endif +/** + * @brief Calculates the PDSCH frequency resource allocation and stores it in the provided PDSCH NR grant. + * + * @remark Defined by TS 38.214 V15.10.0 section 5.1.2.2 + * @param carrier Carrier information + * @param cfg PDSCH NR configuration by upper layers + * @param dci_dl Unpacked DCI used to schedule the PDSCH grant + * @param[out] grant Provides grant pointer to fill + * @return + */ +SRSLTE_API int srslte_ra_dl_nr_freq(const srslte_carrier_nr_t* carrier, + const srslte_sch_cfg_nr_t* cfg, + const srslte_dci_dl_nr_t* dci_dl, + srslte_sch_grant_nr_t* grant); + -#endif // SRSLTE_UE_DL_NR_DATA_H +#endif // SRSLTE_RA_DL_NR_H diff --git a/lib/include/srslte/phy/phch/ra_nr.h b/lib/include/srslte/phy/phch/ra_nr.h index 291cabec2..5fdc0a944 100644 --- a/lib/include/srslte/phy/phch/ra_nr.h +++ b/lib/include/srslte/phy/phch/ra_nr.h @@ -26,12 +26,9 @@ #include "srslte/config.h" #include "srslte/phy/common/phy_common_nr.h" +#include "srslte/phy/phch/dci_nr.h" #include "srslte/phy/phch/phch_cfg_nr.h" -#ifdef __cplusplus -extern "C" { -#endif - /** * @brief Determines target rate * @param mcs_table Configured MCS table @@ -85,9 +82,22 @@ SRSLTE_API int srslte_ra_nr_fill_tb(const srslte_sch_cfg_nr_t* pdsch_cfg, const srslte_sch_grant_nr_t* grant, uint32_t mcs_idx, srslte_sch_tb_t* tb); - -#ifdef __cplusplus -} -#endif +/** + * @brief Converts an unpacked DL DCI message to a PDSCH grant structure. + * Implements the procedures defined in Section 5 of 38.214 to compute the resource allocation (5.1.2) + * and modulation order, target rate, redundancy version and TBS (5.1.3) + * + * Note: Only TypeA PDSCH mapping type is supported + * + * @param carrier Carrier information struct + * @param pdsch_cfg PDSCH configuration indicated by higher layers + * @param dci_dl DCI downlink (format 1_0 or 1_1) + * @param pdsch_grant Generated PDSCH grant + * @return 0 on success, -1 on error + */ +SRSLTE_API int srslte_ra_dl_dci_to_grant_nr(const srslte_carrier_nr_t* carrier, + const srslte_sch_cfg_nr_t* pdsch_cfg, + const srslte_dci_dl_nr_t* dci_dl, + srslte_sch_grant_nr_t* pdsch_grant); #endif // SRSLTE_RA_NR_H diff --git a/lib/include/srslte/phy/ue/ue_dl_nr.h b/lib/include/srslte/phy/ue/ue_dl_nr.h index 3eadf2639..df1063d28 100644 --- a/lib/include/srslte/phy/ue/ue_dl_nr.h +++ b/lib/include/srslte/phy/ue/ue_dl_nr.h @@ -20,10 +20,6 @@ #include "srslte/phy/phch/pdcch_nr.h" #include "srslte/phy/phch/pdsch_nr.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct SRSLTE_API { srslte_pdsch_nr_args_t pdsch; srslte_pdcch_nr_args_t pdcch; @@ -71,21 +67,16 @@ SRSLTE_API int srslte_ue_dl_nr_find_dl_dci(srslte_ue_dl_nr_t* q, srslte_dci_dl_nr_t* dci_dl_list, uint32_t nof_dci_msg); -SRSLTE_API int srslte_ue_dl_nr_pdsch_get(srslte_ue_dl_nr_t* q, - const srslte_dl_slot_cfg_t* slot, - const srslte_sch_cfg_nr_t* cfg, - const srslte_sch_grant_nr_t* grant, - srslte_pdsch_res_nr_t* res); +SRSLTE_API int srslte_ue_dl_nr_decode_pdsch(srslte_ue_dl_nr_t* q, + const srslte_dl_slot_cfg_t* slot, + const srslte_sch_cfg_nr_t* cfg, + srslte_pdsch_res_nr_t* res); SRSLTE_API int srslte_ue_dl_nr_pdsch_info(const srslte_ue_dl_nr_t* q, const srslte_sch_cfg_nr_t* cfg, - const srslte_sch_grant_nr_t* grant, const srslte_pdsch_res_nr_t res[SRSLTE_MAX_CODEWORDS], char* str, uint32_t str_len); -#ifdef __cplusplus -} -#endif #endif // SRSLTE_UE_DL_NR_H diff --git a/lib/include/srslte/phy/ue/ue_ul_nr_data.h b/lib/include/srslte/phy/ue/ue_ul_nr_data.h index fe25f47e7..3dbcae6fd 100644 --- a/lib/include/srslte/phy/ue/ue_ul_nr_data.h +++ b/lib/include/srslte/phy/ue/ue_ul_nr_data.h @@ -26,10 +26,6 @@ #include "srslte/phy/common/phy_common_nr.h" #include "srslte/phy/phch/phch_cfg_nr.h" -#ifdef __cplusplus -extern "C" { -#endif - /** * @brief Calculates the PUSCH time resource default A and stores it in the provided PUSCH NR grant. * @@ -54,8 +50,5 @@ SRSLTE_API int srslte_ue_ul_nr_pdsch_time_resource_default_A(uint32_t m, srslte_ SRSLTE_API int srslte_ue_ul_nr_nof_dmrs_cdm_groups_without_data_format_0_0(const srslte_sch_cfg_nr_t* cfg, srslte_sch_grant_nr_t* grant); -#ifdef __cplusplus -} -#endif #endif // SRSLTE_UE_UL_DATA_H diff --git a/lib/include/srslte/srslte.h b/lib/include/srslte/srslte.h index 61cbee03f..fdfbcb1d1 100644 --- a/lib/include/srslte/srslte.h +++ b/lib/include/srslte/srslte.h @@ -39,6 +39,8 @@ extern "C" { #include "srslte/phy/ch_estimation/chest_dl.h" #include "srslte/phy/ch_estimation/chest_ul.h" +#include "srslte/phy/ch_estimation/dmrs_pdcch.h" +#include "srslte/phy/ch_estimation/dmrs_sch.h" #include "srslte/phy/ch_estimation/refsignal_dl.h" #include "srslte/phy/ch_estimation/refsignal_ul.h" #include "srslte/phy/ch_estimation/wiener_dl.h" @@ -70,6 +72,7 @@ extern "C" { #include "srslte/phy/modem/demod_hard.h" #include "srslte/phy/modem/demod_soft.h" +#include "srslte/phy/modem/evm.h" #include "srslte/phy/modem/mod.h" #include "srslte/phy/modem/modem_table.h" @@ -79,9 +82,11 @@ extern "C" { #include "srslte/phy/fec/softbuffer.h" #include "srslte/phy/phch/cqi.h" #include "srslte/phy/phch/dci.h" +#include "srslte/phy/phch/dci_nr.h" #include "srslte/phy/phch/pbch.h" #include "srslte/phy/phch/pcfich.h" #include "srslte/phy/phch/pdcch.h" +#include "srslte/phy/phch/pdcch_nr.h" #include "srslte/phy/phch/pdsch.h" #include "srslte/phy/phch/phich.h" #include "srslte/phy/phch/prach.h" @@ -90,6 +95,8 @@ extern "C" { #include "srslte/phy/phch/pusch.h" #include "srslte/phy/phch/ra.h" #include "srslte/phy/phch/ra_dl.h" +#include "srslte/phy/phch/ra_dl_nr.h" +#include "srslte/phy/phch/ra_nr.h" #include "srslte/phy/phch/ra_ul.h" #include "srslte/phy/phch/regs.h" #include "srslte/phy/phch/sch.h" @@ -97,11 +104,13 @@ extern "C" { #include "srslte/phy/ue/ue_cell_search.h" #include "srslte/phy/ue/ue_dl.h" +#include "srslte/phy/ue/ue_dl_nr.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" +#include "srslte/phy/enb/enb_dl_nr.h" #include "srslte/phy/enb/enb_ul.h" #include "srslte/phy/scrambling/scrambling.h" diff --git a/lib/include/srslte/upper/ipv6.h b/lib/include/srslte/upper/ipv6.h index 66259f2a6..21fdda835 100644 --- a/lib/include/srslte/upper/ipv6.h +++ b/lib/include/srslte/upper/ipv6.h @@ -13,6 +13,8 @@ #ifndef SRSLTE_IPV6_H #define SRSLTE_IPV6_H +#include + // as of glibc 2.19, the IPv6 issue seems to be fixed https://sourceware.org/bugzilla/show_bug.cgi?id=15850 #if __GLIBC_PREREQ(2, 19) #include diff --git a/lib/src/common/mac_pcap.cc b/lib/src/common/mac_pcap.cc index ca5581c99..432b441c6 100644 --- a/lib/src/common/mac_pcap.cc +++ b/lib/src/common/mac_pcap.cc @@ -11,6 +11,8 @@ */ #include "srslte/common/mac_pcap.h" +#include "srslte/config.h" +#include "srslte/phy/common/phy_common.h" #include namespace srslte { @@ -44,8 +46,8 @@ uint32_t mac_pcap::open(const char* filename, uint32_t ue_id_) return SRSLTE_ERROR; } - ue_id = ue_id_; - running = true; + ue_id = ue_id_; + running = true; // start writer thread start(); diff --git a/lib/src/common/security.cc b/lib/src/common/security.cc index 00c61b8fe..8be620ba2 100644 --- a/lib/src/common/security.cc +++ b/lib/src/common/security.cc @@ -13,6 +13,7 @@ #include "srslte/common/security.h" #include "srslte/common/liblte_security.h" #include "srslte/common/s3g.h" +#include "srslte/config.h" #ifdef HAVE_MBEDTLS #include "mbedtls/md5.h" diff --git a/lib/src/phy/CMakeLists.txt b/lib/src/phy/CMakeLists.txt index f2dc3b6b0..d3cdd43c3 100644 --- a/lib/src/phy/CMakeLists.txt +++ b/lib/src/phy/CMakeLists.txt @@ -41,6 +41,6 @@ set(srslte_srcs $ $ ) -add_library(srslte_phy STATIC ${srslte_srcs}) +add_library(srslte_phy STATIC ${srslte_srcs} ) target_link_libraries(srslte_phy pthread m ${FFT_LIBRARIES}) -INSTALL(TARGETS srslte_phy DESTINATION ${LIBRARY_DIR}) \ No newline at end of file +INSTALL(TARGETS srslte_phy DESTINATION ${LIBRARY_DIR}) diff --git a/lib/src/phy/ch_estimation/dmrs_pdcch.c b/lib/src/phy/ch_estimation/dmrs_pdcch.c index 9daeea9dd..345e8dd17 100644 --- a/lib/src/phy/ch_estimation/dmrs_pdcch.c +++ b/lib/src/phy/ch_estimation/dmrs_pdcch.c @@ -11,6 +11,13 @@ */ #include "srslte/phy/ch_estimation/dmrs_pdcch.h" +#include "srslte/phy/ch_estimation/chest_common.h" +#include "srslte/phy/common/sequence.h" +#include "srslte/phy/utils/convolution.h" +#include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/vector.h" +#include +#include /// @brief Every frequency resource is 6 Resource blocks, every resource block carries 3 pilots. So 18 possible pilots /// per frequency resource. diff --git a/lib/src/phy/ch_estimation/dmrs_sch.c b/lib/src/phy/ch_estimation/dmrs_sch.c index 4bd0eddc7..9914b3949 100644 --- a/lib/src/phy/ch_estimation/dmrs_sch.c +++ b/lib/src/phy/ch_estimation/dmrs_sch.c @@ -11,6 +11,7 @@ */ #include "srslte/phy/ch_estimation/dmrs_sch.h" +#include "srslte/phy/common/sequence.h" #include #define SRSLTE_DMRS_SCH_TYPEA_SINGLE_DURATION_MIN 3 diff --git a/lib/src/phy/ch_estimation/test/dmrs_pdsch_test.c b/lib/src/phy/ch_estimation/test/dmrs_pdsch_test.c index 00568a422..4d2ceb6b2 100644 --- a/lib/src/phy/ch_estimation/test/dmrs_pdsch_test.c +++ b/lib/src/phy/ch_estimation/test/dmrs_pdsch_test.c @@ -12,7 +12,7 @@ #include "srslte/common/test_common.h" #include "srslte/phy/ch_estimation/dmrs_sch.h" -#include "srslte/phy/ue/ue_dl_nr_data.h" +#include "srslte/phy/phch/ra_dl_nr.h" #include "srslte/srslte.h" #include #include @@ -312,7 +312,7 @@ int main(int argc, char** argv) grant.nof_dmrs_cdm_groups_without_data++) { // Load default type A grant - srslte_ue_dl_nr_pdsch_time_resource_default_A(0, pdsch_cfg.dmrs_typeA.typeA_pos, &grant); + srslte_ra_dl_nr_time_default_A(0, pdsch_cfg.dmrs_typeA.typeA_pos, &grant); // Copy configuration pdsch_cfg.dmrs_typeB = pdsch_cfg.dmrs_typeA; diff --git a/lib/src/phy/channel/hst.c b/lib/src/phy/channel/hst.c index 864cb08b2..bb788c74b 100644 --- a/lib/src/phy/channel/hst.c +++ b/lib/src/phy/channel/hst.c @@ -11,6 +11,9 @@ */ #include "srslte/phy/channel/hst.h" +#include "srslte/phy/utils/vector.h" +#include +#include int srslte_channel_hst_init(srslte_channel_hst_t* q, float fd_hz, float period_d, float init_time_s) { diff --git a/lib/src/phy/enb/enb_dl_nr.c b/lib/src/phy/enb/enb_dl_nr.c index 2f7a4a542..10610ca3e 100644 --- a/lib/src/phy/enb/enb_dl_nr.c +++ b/lib/src/phy/enb/enb_dl_nr.c @@ -167,37 +167,23 @@ int srslte_enb_dl_nr_base_zero(srslte_enb_dl_nr_t* q) return SRSLTE_SUCCESS; } -int srslte_enb_dl_nr_pdcch_put(srslte_enb_dl_nr_t* q, - const srslte_dl_slot_cfg_t* slot_cfg, - const srslte_search_space_t* search_space, - const srslte_dci_dl_nr_t* dci_dl, - const srslte_dci_location_t* dci_location, - uint16_t rnti) +int srslte_enb_dl_nr_pdcch_put(srslte_enb_dl_nr_t* q, + const srslte_dl_slot_cfg_t* slot_cfg, + const srslte_dci_dl_nr_t* dci_dl) { - if (q == NULL || search_space == NULL || slot_cfg == NULL || dci_dl == NULL) { + if (q == NULL || slot_cfg == NULL || dci_dl == NULL) { return SRSLTE_ERROR_INVALID_INPUTS; } - // Hard-coded values - srslte_dci_format_nr_t dci_format = srslte_dci_format_nr_1_0; - srslte_rnti_type_t rnti_type = srslte_rnti_type_c; - // Put DMRS - if (srslte_dmrs_pdcch_put(&q->carrier, &q->coreset, slot_cfg, dci_location, q->sf_symbols[0]) < SRSLTE_SUCCESS) { + if (srslte_dmrs_pdcch_put(&q->carrier, &q->coreset, slot_cfg, &dci_dl->location, q->sf_symbols[0]) < SRSLTE_SUCCESS) { ERROR("Error putting PDCCH DMRS\n"); return SRSLTE_ERROR; } - // Initialise DCI MSG fields - srslte_dci_msg_nr_t dci_msg = {}; - dci_msg.location = *dci_location; - dci_msg.search_space = search_space->type; - dci_msg.rnti_type = rnti_type; - dci_msg.rnti = rnti; - dci_msg.format = dci_format; - // Pack DCI - if (srslte_dci_nr_format_1_0_pack(&q->carrier, &q->coreset, dci_dl, &dci_msg) < SRSLTE_SUCCESS) { + srslte_dci_msg_nr_t dci_msg = {}; + if (srslte_dci_nr_pack(&q->carrier, &q->coreset, dci_dl, &dci_msg) < SRSLTE_SUCCESS) { ERROR("Error packing DL DCI\n"); return SRSLTE_ERROR; } @@ -208,39 +194,37 @@ int srslte_enb_dl_nr_pdcch_put(srslte_enb_dl_nr_t* q, return SRSLTE_ERROR; } - INFO("DCI DL NR: L=%d; ncce=%d;\n", dci_location->L, dci_location->ncce); + INFO("DCI DL NR: L=%d; ncce=%d;\n", dci_dl->location.L, dci_dl->location.ncce); return SRSLTE_SUCCESS; } -int srslte_enb_dl_nr_pdsch_put(srslte_enb_dl_nr_t* q, - const srslte_dl_slot_cfg_t* slot, - const srslte_sch_cfg_nr_t* cfg, - const srslte_sch_grant_nr_t* grant, - uint8_t* data[SRSLTE_MAX_TB]) +int srslte_enb_dl_nr_pdsch_put(srslte_enb_dl_nr_t* q, + const srslte_dl_slot_cfg_t* slot, + const srslte_sch_cfg_nr_t* cfg, + uint8_t* data[SRSLTE_MAX_TB]) { - if (srslte_dmrs_sch_put_sf(&q->dmrs, slot, cfg, grant, q->sf_symbols[0]) < SRSLTE_SUCCESS) { + if (srslte_dmrs_sch_put_sf(&q->dmrs, slot, cfg, &cfg->grant, q->sf_symbols[0]) < SRSLTE_SUCCESS) { return SRSLTE_ERROR; } - if (srslte_pdsch_nr_encode(&q->pdsch, cfg, grant, data, q->sf_symbols) < SRSLTE_SUCCESS) { + if (srslte_pdsch_nr_encode(&q->pdsch, cfg, &cfg->grant, data, q->sf_symbols) < SRSLTE_SUCCESS) { return SRSLTE_ERROR; } return SRSLTE_SUCCESS; } -int srslte_enb_dl_nr_pdsch_info(const srslte_enb_dl_nr_t* q, - const srslte_sch_cfg_nr_t* cfg, - const srslte_sch_grant_nr_t* grant, - char* str, - uint32_t str_len) +int srslte_enb_dl_nr_pdsch_info(const srslte_enb_dl_nr_t* q, + const srslte_sch_cfg_nr_t* cfg, + char* str, + uint32_t str_len) { int len = 0; // Append PDSCH info - len += srslte_pdsch_nr_tx_info(&q->pdsch, cfg, grant, &str[len], str_len - len); + len += srslte_pdsch_nr_tx_info(&q->pdsch, cfg, &cfg->grant, &str[len], str_len - len); return len; } diff --git a/lib/src/phy/phch/dci_nr.c b/lib/src/phy/phch/dci_nr.c index 62fdef55e..60c5c4932 100644 --- a/lib/src/phy/phch/dci_nr.c +++ b/lib/src/phy/phch/dci_nr.c @@ -35,6 +35,34 @@ static int dci_nr_format_1_0_freq_resource_size(const srslte_carrier_nr_t* carri return (int)ceil(log2(N_DL_BWP_RB * (N_DL_BWP_RB + 1) / 2.0)); } +int srslte_dci_nr_pack(const srslte_carrier_nr_t* carrier, + const srslte_coreset_t* coreset, + const srslte_dci_dl_nr_t* dci, + srslte_dci_msg_nr_t* msg) +{ + // Copy DCI MSG fields + msg->location = dci->location; + msg->search_space = dci->search_space.type; + msg->rnti_type = dci->rnti_type; + msg->rnti = dci->rnti; + msg->format = dci->format; + + // Pack DCI + switch (msg->format) { + case srslte_dci_format_nr_1_0: + if (srslte_dci_nr_format_1_0_pack(carrier, coreset, dci, msg) < SRSLTE_SUCCESS) { + ERROR("Error packing DL DCI\n"); + return SRSLTE_ERROR; + } + break; + default: + ERROR("Unsupported DCI format %d\n", msg->format); + return SRSLTE_ERROR; + } + + return SRSLTE_SUCCESS; +} + int srslte_dci_nr_format_1_0_pack(const srslte_carrier_nr_t* carrier, const srslte_coreset_t* coreset, const srslte_dci_dl_nr_t* dci, diff --git a/lib/src/phy/phch/pdcch_nr.c b/lib/src/phy/phch/pdcch_nr.c index 943276f3f..7ec569120 100644 --- a/lib/src/phy/phch/pdcch_nr.c +++ b/lib/src/phy/phch/pdcch_nr.c @@ -11,8 +11,12 @@ */ #include "srslte/phy/phch/pdcch_nr.h" +#include "srslte/phy/common/sequence.h" #include "srslte/phy/fec/polar/polar_chanalloc.h" #include "srslte/phy/fec/polar/polar_interleaver.h" +#include "srslte/phy/mimo/precoding.h" +#include "srslte/phy/modem/demod_soft.h" +#include "srslte/phy/utils/bit.h" #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" diff --git a/lib/src/phy/phch/pdsch_nr.c b/lib/src/phy/phch/pdsch_nr.c index a6d79e926..5a17af34c 100644 --- a/lib/src/phy/phch/pdsch_nr.c +++ b/lib/src/phy/phch/pdsch_nr.c @@ -9,8 +9,12 @@ * the distribution. * */ + #include "srslte/phy/phch/pdsch_nr.h" #include "srslte/phy/common/phy_common_nr.h" +#include "srslte/phy/mimo/layermap.h" +#include "srslte/phy/mimo/precoding.h" +#include "srslte/phy/modem/demod_soft.h" #include "srslte/phy/phch/ra_nr.h" int pdsch_nr_init_common(srslte_pdsch_nr_t* q, const srslte_pdsch_nr_args_t* args) diff --git a/lib/src/phy/phch/pusch_nr.c b/lib/src/phy/phch/pusch_nr.c index 0d391d804..d7f146fb0 100644 --- a/lib/src/phy/phch/pusch_nr.c +++ b/lib/src/phy/phch/pusch_nr.c @@ -11,6 +11,9 @@ */ #include "srslte/phy/phch/pusch_nr.h" #include "srslte/phy/common/phy_common_nr.h" +#include "srslte/phy/mimo/layermap.h" +#include "srslte/phy/mimo/precoding.h" +#include "srslte/phy/modem/demod_soft.h" #include "srslte/phy/phch/ra_nr.h" int pusch_nr_init_common(srslte_pusch_nr_t* q, const srslte_pusch_nr_args_t* args) diff --git a/lib/src/phy/phch/ra_dl_nr.c b/lib/src/phy/phch/ra_dl_nr.c new file mode 100644 index 000000000..68b6009a2 --- /dev/null +++ b/lib/src/phy/phch/ra_dl_nr.c @@ -0,0 +1,256 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2020 Software Radio Systems Limited + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the distribution. + * + */ +#include "srslte/phy/phch/ra_dl_nr.h" +#include "srslte/phy/utils/debug.h" + +static void sliv_to_s_and_l(uint32_t sliv, uint32_t* S, uint32_t* L) +{ + // S values can be 0 to 3 + uint32_t low = sliv % 14; + if (low < 7) { + *S = low; + *L = sliv / 14 + 1; + } else { + *S = 14 - 1 - low; + *L = 14 - sliv / 14 + 1; + } +} + +// Validate S and L combination for TypeA time domain resource allocation +static bool check_time_ra_typeA(uint32_t* S, uint32_t* L) +{ + // Check values using Table 5.1.2.1-1 + if (*S > 3) { + ERROR("S (%d) is out-of-range {0,1,2,3}\n", *S); + return false; + } + + if (*L < 3 || *L > 14) { + ERROR("L (%d) is out-of-range {3,...,14}\n", *L); + return false; + } + + uint32_t sum = *S + *L; + if (sum < 3) { + ERROR("The sum of S (%d) and L (%d) is lower than 3\n", *S, *L); + return false; + } + + if (sum > 14) { + ERROR("The sum of S (%d) and L (%d) is greater than 14\n", *S, *L); + return false; + } + + return true; +} + +static bool check_time_ra_typeB(uint32_t* S, uint32_t* L) +{ + ERROR("Not implemented\n"); + return false; +} + +bool srslte_ra_dl_nr_time_validate(srslte_sch_grant_nr_t* grant) +{ + if (grant->mapping == srslte_sch_mapping_type_A) { + return check_time_ra_typeA(&grant->S, &grant->L); + } else { + return check_time_ra_typeB(&grant->S, &grant->L); + } +} + +int srslte_ra_dl_nr_time_default_A(uint32_t m, srslte_dmrs_sch_typeA_pos_t dmrs_typeA_pos, srslte_sch_grant_nr_t* grant) +{ + if (grant == NULL) { + return SRSLTE_ERROR_INVALID_INPUTS; + } + + if (m >= SRSLTE_MAX_NOF_DL_ALLOCATION) { + ERROR("m (%d) is out-of-range\n", m); + return SRSLTE_ERROR_INVALID_INPUTS; + } + + // Select k0 + grant->k0 = 0; + + // Select PDSCH mapping + static srslte_sch_mapping_type_t pdsch_mapping_lut[16] = {srslte_sch_mapping_type_A, + srslte_sch_mapping_type_A, + srslte_sch_mapping_type_A, + srslte_sch_mapping_type_A, + srslte_sch_mapping_type_A, + srslte_sch_mapping_type_B, + srslte_sch_mapping_type_B, + srslte_sch_mapping_type_B, + srslte_sch_mapping_type_B, + srslte_sch_mapping_type_B, + srslte_sch_mapping_type_B, + srslte_sch_mapping_type_A, + srslte_sch_mapping_type_A, + srslte_sch_mapping_type_A, + srslte_sch_mapping_type_B, + srslte_sch_mapping_type_B}; + grant->mapping = pdsch_mapping_lut[m]; + + static uint32_t S_pos2[SRSLTE_MAX_NOF_DL_ALLOCATION] = {2, 2, 2, 2, 2, 9, 4, 5, 5, 9, 12, 1, 1, 2, 4, 8}; + static uint32_t L_pos2[SRSLTE_MAX_NOF_DL_ALLOCATION] = {12, 10, 9, 7, 5, 4, 4, 7, 2, 2, 2, 13, 6, 4, 7, 4}; + static uint32_t S_pos3[SRSLTE_MAX_NOF_DL_ALLOCATION] = {3, 3, 3, 3, 3, 10, 6, 5, 5, 9, 12, 1, 1, 2, 4, 8}; + static uint32_t L_pos3[SRSLTE_MAX_NOF_DL_ALLOCATION] = {11, 9, 8, 6, 4, 4, 4, 7, 2, 2, 2, 13, 6, 4, 7, 4}; + + // Select start symbol (S) and length (L) + switch (dmrs_typeA_pos) { + + case srslte_dmrs_sch_typeA_pos_2: + grant->S = S_pos2[m]; + grant->L = L_pos2[m]; + break; + case srslte_dmrs_sch_typeA_pos_3: + grant->S = S_pos3[m]; + grant->L = L_pos3[m]; + break; + default: + ERROR("Undefined case (%d)\n", dmrs_typeA_pos); + return SRSLTE_ERROR; + } + + return SRSLTE_SUCCESS; +} + +void srslte_ra_dl_nr_time_hl(const srslte_pdsch_time_ra_t* hl_ra_cfg, srslte_sch_grant_nr_t* grant) +{ + // Compute S and L from SLIV from higher layers + sliv_to_s_and_l(hl_ra_cfg->sliv, &grant->S, &grant->L); + grant->k0 = hl_ra_cfg->k0; + grant->mapping = hl_ra_cfg->mapping_type; +} + +int srslte_ra_dl_nr_time(const srslte_sch_cfg_nr_t* cfg, + const srslte_rnti_type_t rnti_type, + const srslte_search_space_type_t ss_type, + const uint8_t m, + srslte_sch_grant_nr_t* grant) +{ + + if (cfg == NULL || grant == NULL) { + return SRSLTE_ERROR_INVALID_INPUTS; + } + + if (m >= SRSLTE_MAX_NOF_DL_ALLOCATION) { + ERROR("m (%d) is out-of-range\n", m); + return SRSLTE_ERROR_INVALID_INPUTS; + } + + // Determine which PDSCH Time domain RA configuration to apply (Table 5.1.2.1.1-1) + if (cfg->pdsch_time_is_default) { + // Note: Only Default A is supported, which corresponds SS/PBCH block and coreset mux pattern 1 + srslte_ra_dl_nr_time_default_A(m, cfg->dmrs_typeA.typeA_pos, grant); + } else { + srslte_ra_dl_nr_time_hl(&cfg->pdsch_time_ra[m], grant); + } + + // Validate S and L parameters + if (!srslte_ra_dl_nr_time_validate(grant)) { + ERROR("Invalid Time RA\n"); + return SRSLTE_ERROR; + } + + return SRSLTE_SUCCESS; +} + +int srslte_ra_dl_nr_nof_dmrs_cdm_groups_without_data_format_1_0(const srslte_sch_cfg_nr_t* pdsch_cfg, + srslte_sch_grant_nr_t* grant) +{ + if (pdsch_cfg == NULL || grant == NULL) { + return SRSLTE_ERROR_INVALID_INPUTS; + } + + const srslte_dmrs_sch_cfg_t* dmrs_cfg = + grant->mapping == srslte_sch_mapping_type_A ? &pdsch_cfg->dmrs_typeA : &pdsch_cfg->dmrs_typeB; + + /* According to TS 38.214 V15.10.0 5.1.6.1.3 CSI-RS for mobility: + * When receiving PDSCH scheduled by DCI format 1_0, the UE shall assume the number of DM-RS CDM groups without data + * is 1 which corresponds to CDM group 0 for the case of PDSCH with allocation duration of 2 symbols, and the UE shall + * assume that the number of DM-RS CDM groups without data is 2 which corresponds to CDM group {0,1} for all other + * cases. + */ + if (dmrs_cfg->length == srslte_dmrs_sch_len_2) { + grant->nof_dmrs_cdm_groups_without_data = 1; + } else { + grant->nof_dmrs_cdm_groups_without_data = 2; + } + + return SRSLTE_SUCCESS; +} + +/* RBG size for type0 scheduling as in table 5.1.2.2.1-1 of 36.214 */ +uint32_t srslte_ra_dl_nr_type0_P(uint32_t bwp_size, bool config_is_1) +{ + if (bwp_size <= 36) { + return config_is_1 ? 2 : 4; + } else if (bwp_size <= 72) { + return config_is_1 ? 4 : 8; + } else if (bwp_size <= 144) { + return config_is_1 ? 8 : 16; + } else { + return 16; + } +} + +static int ra_freq_type0(const srslte_carrier_nr_t* carrier, + const srslte_sch_cfg_nr_t* cfg, + const srslte_dci_dl_nr_t* dci_dl, + srslte_sch_grant_nr_t* grant) +{ + uint32_t P = srslte_ra_dl_nr_type0_P(carrier->nof_prb, cfg->rbg_size_cfg_1); + + uint32_t N_rbg = (int)ceilf((float)(carrier->nof_prb + (carrier->start % P)) / P); + uint32_t rbg_offset = 0; + for (uint32_t i = 0; i < N_rbg; i++) { + uint32_t rbg_size = P; + if (i == 0) { + rbg_size -= (carrier->start % P); + } else if ((i == N_rbg - 1) && ((carrier->nof_prb + carrier->start) % P) > 0) { + rbg_size = (carrier->nof_prb + carrier->start) % P; + } + if (dci_dl->freq_domain_assigment & (1 << (N_rbg - i - 1))) { + for (uint32_t j = 0; j < rbg_size; j++) { + if (rbg_offset + j < carrier->nof_prb) { + grant->prb_idx[rbg_offset + j] = true; + grant->nof_prb++; + } + } + } + rbg_offset += rbg_size; + } + return 0; +} + +int srslte_ra_dl_nr_freq(const srslte_carrier_nr_t* carrier, + const srslte_sch_cfg_nr_t* cfg, + const srslte_dci_dl_nr_t* dci_dl, + srslte_sch_grant_nr_t* grant) +{ + + if (cfg == NULL || grant == NULL || dci_dl == NULL) { + return SRSLTE_ERROR_INVALID_INPUTS; + } + + // RA scheme + if (dci_dl->format == srslte_dci_format_nr_1_0) { + ra_freq_type0(carrier, cfg, dci_dl, grant); + } else { + ERROR("Only DCI Format 1_0 is supported\n"); + return SRSLTE_ERROR; + } + + return SRSLTE_SUCCESS; +} diff --git a/lib/src/phy/phch/ra_nr.c b/lib/src/phy/phch/ra_nr.c index 9ad8f5a37..8125f151d 100644 --- a/lib/src/phy/phch/ra_nr.c +++ b/lib/src/phy/phch/ra_nr.c @@ -12,6 +12,7 @@ #include "srslte/phy/phch/ra_nr.h" #include "srslte/phy/phch/pdsch_nr.h" +#include "srslte/phy/phch/ra_dl_nr.h" #include "srslte/phy/utils/debug.h" typedef struct { @@ -452,4 +453,46 @@ int srslte_ra_nr_fill_tb(const srslte_sch_cfg_nr_t* pdsch_cfg, tb->enabled = true; return SRSLTE_SUCCESS; -} \ No newline at end of file +} + +int srslte_ra_dl_dci_to_grant_nr(const srslte_carrier_nr_t* carrier, + const srslte_sch_cfg_nr_t* pdsch_cfg, + const srslte_dci_dl_nr_t* dci_dl, + srslte_sch_grant_nr_t* pdsch_grant) +{ + // Time domain resource allocation + if (srslte_ra_dl_nr_time( + pdsch_cfg, dci_dl->rnti_type, dci_dl->search_space.type, dci_dl->time_domain_assigment, pdsch_grant) < + SRSLTE_SUCCESS) { + ERROR("Error computing time domain resource allocation\n"); + return SRSLTE_ERROR; + } + + // Frequency domain resource allocation + if (srslte_ra_dl_nr_freq(carrier, pdsch_cfg, dci_dl, pdsch_grant) < SRSLTE_SUCCESS) { + ERROR("Error computing time domain resource allocation\n"); + return SRSLTE_ERROR; + } + + //??? + if (srslte_ra_dl_nr_nof_dmrs_cdm_groups_without_data_format_1_0(pdsch_cfg, pdsch_grant) < SRSLTE_SUCCESS) { + ERROR("Error loading number of DMRS CDM groups\n"); + return SRSLTE_ERROR; + } + + pdsch_grant->nof_layers = 1; + pdsch_grant->dci_format = dci_dl->format; + pdsch_grant->rnti = dci_dl->rnti; + + for (uint32_t i = 0; i < carrier->nof_prb; i++) { + pdsch_grant->prb_idx[i] = true; + } + + // Compute TB size + if (srslte_ra_nr_fill_tb(pdsch_cfg, pdsch_grant, dci_dl->mcs, &pdsch_grant->tb[0]) < SRSLTE_SUCCESS) { + ERROR("Error filing tb\n"); + return SRSLTE_ERROR; + } + + return SRSLTE_SUCCESS; +} diff --git a/lib/src/phy/phch/test/pdcch_nr_test.c b/lib/src/phy/phch/test/pdcch_nr_test.c index 9112cead2..4df7285a1 100644 --- a/lib/src/phy/phch/test/pdcch_nr_test.c +++ b/lib/src/phy/phch/test/pdcch_nr_test.c @@ -12,6 +12,7 @@ #include "srslte/common/test_common.h" #include "srslte/phy/phch/pdcch_nr.h" +#include "srslte/phy/utils/random.h" #include static srslte_carrier_nr_t carrier = { diff --git a/lib/src/phy/phch/test/pdsch_nr_test.c b/lib/src/phy/phch/test/pdsch_nr_test.c index ea6e2d9a2..b02921a95 100644 --- a/lib/src/phy/phch/test/pdsch_nr_test.c +++ b/lib/src/phy/phch/test/pdsch_nr_test.c @@ -11,12 +11,14 @@ */ #include "srslte/phy/phch/pdsch_nr.h" +#include "srslte/phy/phch/ra_dl_nr.h" #include "srslte/phy/phch/ra_nr.h" -#include "srslte/phy/ue/ue_dl_nr_data.h" #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/random.h" #include "srslte/phy/utils/vector.h" +#include #include +#include static srslte_carrier_nr_t carrier = { 1, // cell_id @@ -151,13 +153,13 @@ int main(int argc, char** argv) } // Use grant default A time resources with m=0 - if (srslte_ue_dl_nr_pdsch_time_resource_default_A(0, pdsch_cfg.dmrs_typeA.typeA_pos, &pdsch_grant) < SRSLTE_SUCCESS) { + if (srslte_ra_dl_nr_time_default_A(0, pdsch_cfg.dmrs_typeA.typeA_pos, &pdsch_grant) < SRSLTE_SUCCESS) { ERROR("Error loading default grant\n"); goto clean_exit; } // Load number of DMRS CDM groups without data - if (srslte_ue_dl_nr_nof_dmrs_cdm_groups_without_data_format_1_0(&pdsch_cfg, &pdsch_grant) < SRSLTE_SUCCESS) { + if (srslte_ra_dl_nr_nof_dmrs_cdm_groups_without_data_format_1_0(&pdsch_cfg, &pdsch_grant) < SRSLTE_SUCCESS) { ERROR("Error loading number of DMRS CDM groups without data\n"); goto clean_exit; } diff --git a/lib/src/phy/phch/test/pusch_nr_test.c b/lib/src/phy/phch/test/pusch_nr_test.c index 1002968de..097dc1f87 100644 --- a/lib/src/phy/phch/test/pusch_nr_test.c +++ b/lib/src/phy/phch/test/pusch_nr_test.c @@ -16,6 +16,7 @@ #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/random.h" #include "srslte/phy/utils/vector.h" +#include #include static srslte_carrier_nr_t carrier = { diff --git a/lib/src/phy/phch/test/ra_nr_test.c b/lib/src/phy/phch/test/ra_nr_test.c new file mode 100644 index 000000000..f43ab5c26 --- /dev/null +++ b/lib/src/phy/phch/test/ra_nr_test.c @@ -0,0 +1,101 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2020 Software Radio Systems Limited + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the distribution. + * + */ + +#include "srslte/common/test_common.h" +#include "srslte/phy/phch/ra_dl_nr.h" +#include "srslte/phy/phch/ra_nr.h" +#include "srslte/phy/utils/debug.h" +#include "srslte/phy/utils/random.h" +#include + +static srslte_carrier_nr_t carrier = { + 1, // cell_id + 0, // numerology + SRSLTE_MAX_PRB_NR, // nof_prb + 0, // start + 1 // max_mimo_layers +}; + +int test_type0_multiple() +{ + srslte_sch_cfg_nr_t sch_cfg = {}; + srslte_dci_dl_nr_t dci_dl = {}; + srslte_sch_grant_nr_t grant = {}; + + carrier.nof_prb = 32; + carrier.start = 48; + + sch_cfg.rbg_size_cfg_1 = false; + dci_dl.format = srslte_dci_format_nr_1_0; + + dci_dl.freq_domain_assigment = 0xC0; // RBG 0 and 1 + + TESTASSERT(srslte_ra_dl_nr_freq(&carrier, &sch_cfg, &dci_dl, &grant) == SRSLTE_SUCCESS); + + TESTASSERT(grant.nof_prb == 8); // P * 2 RBG + for (uint32_t i = 0; i < grant.nof_prb; i++) { + TESTASSERT(grant.prb_idx[i] == true); + } + for (uint32_t i = grant.nof_prb; i < carrier.nof_prb; i++) { + TESTASSERT(grant.prb_idx[i] == false); + } + + return SRSLTE_SUCCESS; +} + +int test_type0_not_multiple() +{ + srslte_sch_cfg_nr_t sch_cfg = {}; + srslte_dci_dl_nr_t dci_dl = {}; + srslte_sch_grant_nr_t grant = {}; + + carrier.nof_prb = 33; + carrier.start = 49; + + sch_cfg.rbg_size_cfg_1 = false; + dci_dl.format = srslte_dci_format_nr_1_0; + + dci_dl.freq_domain_assigment = 0x1C0; // RBG 0, 1 and 2 + + TESTASSERT(srslte_ra_dl_nr_freq(&carrier, &sch_cfg, &dci_dl, &grant) == SRSLTE_SUCCESS); + + TESTASSERT(grant.nof_prb == 11); // P + (P-1) RBG + for (uint32_t i = 0; i < grant.nof_prb; i++) { + TESTASSERT(grant.prb_idx[i] == true); + } + for (uint32_t i = grant.nof_prb; i < carrier.nof_prb; i++) { + TESTASSERT(grant.prb_idx[i] == false); + } + + bzero(&grant, sizeof(srslte_sch_grant_nr_t)); + + dci_dl.freq_domain_assigment = 0x3; // RBG 8 and 9 + + TESTASSERT(srslte_ra_dl_nr_freq(&carrier, &sch_cfg, &dci_dl, &grant) == SRSLTE_SUCCESS); + + TESTASSERT(grant.nof_prb == 6); // P + (P-1) RBG + for (uint32_t i = 0; i < carrier.nof_prb - grant.nof_prb; i++) { + TESTASSERT(grant.prb_idx[i] == false); + } + for (uint32_t i = carrier.nof_prb - grant.nof_prb; i < carrier.nof_prb; i++) { + TESTASSERT(grant.prb_idx[i] == true); + } + + return SRSLTE_SUCCESS; +} + +int main(int argc, char** argv) +{ + // TESTASSERT(test_type0_multiple() == SRSLTE_SUCCESS); + TESTASSERT(test_type0_not_multiple() == SRSLTE_SUCCESS); + return SRSLTE_SUCCESS; +} diff --git a/lib/src/phy/phch/test/sch_nr_test.c b/lib/src/phy/phch/test/sch_nr_test.c index aa3221957..96f6a4589 100644 --- a/lib/src/phy/phch/test/sch_nr_test.c +++ b/lib/src/phy/phch/test/sch_nr_test.c @@ -10,9 +10,9 @@ * */ +#include "srslte/phy/phch/ra_dl_nr.h" #include "srslte/phy/phch/ra_nr.h" #include "srslte/phy/phch/sch_nr.h" -#include "srslte/phy/ue/ue_dl_nr_data.h" #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" #include @@ -132,7 +132,7 @@ int main(int argc, char** argv) } // Use grant default A time resources with m=0 - if (srslte_ue_dl_nr_pdsch_time_resource_default_A(0, pdsch_cfg.dmrs_typeA.typeA_pos, &pdsch_grant) < SRSLTE_SUCCESS) { + if (srslte_ra_dl_nr_time_default_A(0, pdsch_cfg.dmrs_typeA.typeA_pos, &pdsch_grant) < SRSLTE_SUCCESS) { ERROR("Error loading default grant\n"); goto clean_exit; } diff --git a/lib/src/phy/ue/ue_dl_nr.c b/lib/src/phy/ue/ue_dl_nr.c index 4ebc7d21a..79896631e 100644 --- a/lib/src/phy/ue/ue_dl_nr.c +++ b/lib/src/phy/ue/ue_dl_nr.c @@ -305,24 +305,23 @@ int srslte_ue_dl_nr_find_dl_dci(srslte_ue_dl_nr_t* q, return (int)count; } -int srslte_ue_dl_nr_pdsch_get(srslte_ue_dl_nr_t* q, - const srslte_dl_slot_cfg_t* slot, - const srslte_sch_cfg_nr_t* cfg, - const srslte_sch_grant_nr_t* grant, - srslte_pdsch_res_nr_t* res) +int srslte_ue_dl_nr_decode_pdsch(srslte_ue_dl_nr_t* q, + const srslte_dl_slot_cfg_t* slot, + const srslte_sch_cfg_nr_t* cfg, + srslte_pdsch_res_nr_t* res) { - if (srslte_dmrs_sch_estimate(&q->dmrs_pdsch, slot, cfg, grant, q->sf_symbols[0], &q->chest) < SRSLTE_SUCCESS) { + if (srslte_dmrs_sch_estimate(&q->dmrs_pdsch, slot, cfg, &cfg->grant, q->sf_symbols[0], &q->chest) < SRSLTE_SUCCESS) { return SRSLTE_ERROR; } - if (srslte_pdsch_nr_decode(&q->pdsch, cfg, grant, &q->chest, q->sf_symbols, res) < SRSLTE_SUCCESS) { + if (srslte_pdsch_nr_decode(&q->pdsch, cfg, &cfg->grant, &q->chest, q->sf_symbols, res) < SRSLTE_SUCCESS) { return SRSLTE_ERROR; } if (SRSLTE_DEBUG_ENABLED && srslte_verbose >= SRSLTE_VERBOSE_INFO && !handler_registered) { char str[512]; - srslte_ue_dl_nr_pdsch_info(q, cfg, grant, res, str, sizeof(str)); + srslte_ue_dl_nr_pdsch_info(q, cfg, res, str, sizeof(str)); INFO("PDSCH: %s\n", str); } @@ -331,7 +330,6 @@ int srslte_ue_dl_nr_pdsch_get(srslte_ue_dl_nr_t* q, int srslte_ue_dl_nr_pdsch_info(const srslte_ue_dl_nr_t* q, const srslte_sch_cfg_nr_t* cfg, - const srslte_sch_grant_nr_t* grant, const srslte_pdsch_res_nr_t* res, char* str, uint32_t str_len) @@ -342,7 +340,7 @@ int srslte_ue_dl_nr_pdsch_info(const srslte_ue_dl_nr_t* q, // ... // Append PDSCH info - len += srslte_pdsch_nr_rx_info(&q->pdsch, cfg, grant, res, &str[len], str_len - len); + len += srslte_pdsch_nr_rx_info(&q->pdsch, cfg, &cfg->grant, res, &str[len], str_len - len); return len; } diff --git a/lib/src/phy/ue/ue_dl_nr_data.c b/lib/src/phy/ue/ue_dl_nr_data.c deleted file mode 100644 index bb0e7bcf8..000000000 --- a/lib/src/phy/ue/ue_dl_nr_data.c +++ /dev/null @@ -1,157 +0,0 @@ -/** - * - * \section COPYRIGHT - * - * Copyright 2013-2020 Software Radio Systems Limited - * - * By using this file, you agree to the terms and conditions set - * forth in the LICENSE file which can be found at the top level of - * the distribution. - * - */ -#include "srslte/phy/ue/ue_dl_nr_data.h" -#include "srslte/phy/utils/debug.h" - -static int srslte_ue_dl_nr_pdsch_time_resource_hl_A(uint32_t sliv, uint32_t* S, uint32_t* L) -{ - // S values can be 0 to 3 - uint32_t low = sliv % 14; - if (low < 7) { - *S = low; - *L = sliv / 14 + 1; - } else { - *S = 14 - 1 - low; - *L = 14 - sliv / 14 + 1; - } - - // Check values using Table 5.1.2.1-1 - if (*S > 3) { - ERROR("Invalid SLIV %d. S (%d) is out-of-range {0,1,2,3}\n", sliv, *S); - return SRSLTE_ERROR; - } - - if (*L < 3 || *L > 14) { - ERROR("Invalid SLIV %d. L (%d) is out-of-range {3,...,14}\n", sliv, *L); - return SRSLTE_ERROR; - } - - uint32_t sum = *S + *L; - if (sum < 3) { - ERROR("Invalid SLIV %d. The sum of S (%d) and L (%d) is lower than 3\n", sliv, *S, *L); - return SRSLTE_ERROR; - } - - if (sum > 14) { - ERROR("Invalid SLIV %d. The sum of S (%d) and L (%d) is greater than 14\n", sliv, *S, *L); - return SRSLTE_ERROR; - } - - return SRSLTE_SUCCESS; -} - -static int srslte_ue_dl_nr_pdsch_time_resource_hl_B(uint32_t sliv, uint32_t* S, uint32_t* L) -{ - ERROR("Not implemented\n"); - return SRSLTE_ERROR; -} - -int srslte_ue_dl_nr_pdsch_time_resource_hl(const srslte_pdsch_allocation_t* pdsch_alloc, srslte_sch_grant_nr_t* grant) -{ - - if (pdsch_alloc == NULL || grant == NULL) { - return SRSLTE_ERROR_INVALID_INPUTS; - } - - grant->k0 = pdsch_alloc->k0; - grant->mapping = pdsch_alloc->mapping_type; - - if (pdsch_alloc->mapping_type == srslte_sch_mapping_type_A) { - return srslte_ue_dl_nr_pdsch_time_resource_hl_A(pdsch_alloc->sliv, &grant->S, &grant->L); - } - - return srslte_ue_dl_nr_pdsch_time_resource_hl_B(pdsch_alloc->sliv, &grant->S, &grant->L); -} - -int srslte_ue_dl_nr_pdsch_time_resource_default_A(uint32_t m, - srslte_dmrs_sch_typeA_pos_t dmrs_typeA_pos, - srslte_sch_grant_nr_t* grant) -{ - if (grant == NULL) { - return SRSLTE_ERROR_INVALID_INPUTS; - } - - if (m >= 16) { - ERROR("m (%d) is out-of-range\n", m); - return SRSLTE_ERROR_INVALID_INPUTS; - } - - // Select k0 - grant->k0 = 0; - - // Select PDSCH mapping - static srslte_sch_mapping_type_t pdsch_mapping_lut[16] = {srslte_sch_mapping_type_A, - srslte_sch_mapping_type_A, - srslte_sch_mapping_type_A, - srslte_sch_mapping_type_A, - srslte_sch_mapping_type_A, - srslte_sch_mapping_type_B, - srslte_sch_mapping_type_B, - srslte_sch_mapping_type_B, - srslte_sch_mapping_type_B, - srslte_sch_mapping_type_B, - srslte_sch_mapping_type_B, - srslte_sch_mapping_type_A, - srslte_sch_mapping_type_A, - srslte_sch_mapping_type_A, - srslte_sch_mapping_type_B, - srslte_sch_mapping_type_B}; - grant->mapping = pdsch_mapping_lut[m]; - - static uint32_t S_pos2[16] = {2, 2, 2, 2, 2, 9, 4, 5, 5, 9, 12, 1, 1, 2, 4, 8}; - static uint32_t L_pos2[16] = {12, 10, 9, 7, 5, 4, 4, 7, 2, 2, 2, 13, 6, 4, 7, 4}; - static uint32_t S_pos3[16] = {3, 3, 3, 3, 3, 10, 6, 5, 5, 9, 12, 1, 1, 2, 4, 8}; - static uint32_t L_pos3[16] = {11, 9, 8, 6, 4, 4, 4, 7, 2, 2, 2, 13, 6, 4, 7, 4}; - - // Select start symbol (S) and length (L) - switch (dmrs_typeA_pos) { - - case srslte_dmrs_sch_typeA_pos_2: - grant->S = S_pos2[m]; - grant->L = L_pos2[m]; - break; - case srslte_dmrs_sch_typeA_pos_3: - grant->S = S_pos3[m]; - grant->L = L_pos3[m]; - break; - default: - ERROR("Undefined case (%d)\n", dmrs_typeA_pos); - return SRSLTE_ERROR; - } - - return SRSLTE_SUCCESS; -} - -int srslte_ue_dl_nr_nof_dmrs_cdm_groups_without_data_format_1_0(const srslte_sch_cfg_nr_t* pdsch_cfg, - srslte_sch_grant_nr_t* grant) -{ - if (pdsch_cfg == NULL || grant == NULL) { - return SRSLTE_ERROR_INVALID_INPUTS; - } - - const srslte_dmrs_sch_cfg_t* dmrs_cfg = - grant->mapping == srslte_sch_mapping_type_A ? &pdsch_cfg->dmrs_typeA : &pdsch_cfg->dmrs_typeB; - - /* According to TS 38.214 V15.10.0 5.1.6.1.3 CSI-RS for mobility: - * When receiving PDSCH scheduled by DCI format 1_0, the UE shall assume the number of DM-RS CDM groups without data - * is 1 which corresponds to CDM group 0 for the case of PDSCH with allocation duration of 2 symbols, and the UE shall - * assume that the number of DM-RS CDM groups without data is 2 which corresponds to CDM group {0,1} for all other - * cases. - */ - if (dmrs_cfg->length == srslte_dmrs_sch_len_2) { - grant->nof_dmrs_cdm_groups_without_data = 1; - } else { - grant->nof_dmrs_cdm_groups_without_data = 2; - } - - return SRSLTE_SUCCESS; -} \ No newline at end of file diff --git a/lib/src/phy/utils/debug.c b/lib/src/phy/utils/debug.c index 44b3bb636..45f140e0b 100644 --- a/lib/src/phy/utils/debug.c +++ b/lib/src/phy/utils/debug.c @@ -24,4 +24,4 @@ void get_time_interval(struct timeval* tdata) tdata[0].tv_sec--; tdata[0].tv_usec += 1000000; } -} \ No newline at end of file +} diff --git a/lib/src/upper/gtpu.cc b/lib/src/upper/gtpu.cc index 8b22cbcd0..ba687a386 100644 --- a/lib/src/upper/gtpu.cc +++ b/lib/src/upper/gtpu.cc @@ -12,6 +12,8 @@ #include "srslte/upper/gtpu.h" #include "srslte/common/int_helpers.h" +#include +#include namespace srslte { diff --git a/lib/test/asn1/nas_decoder.cc b/lib/test/asn1/nas_decoder.cc index 997ee6ab9..4af0ecaf2 100644 --- a/lib/test/asn1/nas_decoder.cc +++ b/lib/test/asn1/nas_decoder.cc @@ -12,6 +12,7 @@ #include "srslte/asn1/liblte_mme.h" #include "srslte/common/common.h" +#include "srslte/phy/common/phy_common.h" #include #include diff --git a/lib/test/asn1/s1ap_test.cc b/lib/test/asn1/s1ap_test.cc index cacd6c7a5..778b08091 100644 --- a/lib/test/asn1/s1ap_test.cc +++ b/lib/test/asn1/s1ap_test.cc @@ -12,6 +12,8 @@ #include "srslte/asn1/s1ap.h" #include "srslte/common/test_common.h" +#include +#include using namespace asn1; using namespace asn1::s1ap; diff --git a/lib/test/common/timeout_test.cc b/lib/test/common/timeout_test.cc index c8ab081bd..d11970081 100644 --- a/lib/test/common/timeout_test.cc +++ b/lib/test/common/timeout_test.cc @@ -10,7 +10,10 @@ * */ +extern "C" { #include "srslte/common/timeout.h" +#include "srslte/config.h" +} #include #include diff --git a/lib/test/phy/phy_dl_nr_test.c b/lib/test/phy/phy_dl_nr_test.c index cd9186d90..a04c64757 100644 --- a/lib/test/phy/phy_dl_nr_test.c +++ b/lib/test/phy/phy_dl_nr_test.c @@ -11,9 +11,9 @@ */ #include "srslte/phy/enb/enb_dl_nr.h" +#include "srslte/phy/phch/ra_dl_nr.h" #include "srslte/phy/phch/ra_nr.h" #include "srslte/phy/ue/ue_dl_nr.h" -#include "srslte/phy/ue/ue_dl_nr_data.h" #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/random.h" #include "srslte/phy/utils/vector.h" @@ -95,14 +95,22 @@ int work_gnb_dl(srslte_enb_dl_nr_t* enb_dl, return SRSLTE_ERROR; } + // Hard-coded values + dci_dl->format = srslte_dci_format_nr_1_0; + dci_dl->rnti_type = srslte_rnti_type_c; + dci_dl->location = *dci_location; + dci_dl->search_space = *search_space; + dci_dl->rnti = rnti; + // Put actual DCI - if (srslte_enb_dl_nr_pdcch_put(enb_dl, slot, search_space, dci_dl, dci_location, rnti) < SRSLTE_SUCCESS) { + if (srslte_enb_dl_nr_pdcch_put(enb_dl, slot, dci_dl) < SRSLTE_SUCCESS) { ERROR("Error putting PDCCH\n"); return SRSLTE_ERROR; } // Put PDSCH transmission - if (srslte_enb_dl_nr_pdsch_put(enb_dl, slot, &pdsch_cfg, &pdsch_grant, data_tx) < SRSLTE_SUCCESS) { + pdsch_cfg.grant = pdsch_grant; + if (srslte_enb_dl_nr_pdsch_put(enb_dl, slot, &pdsch_cfg, data_tx) < SRSLTE_SUCCESS) { ERROR("Error putting PDSCH\n"); return SRSLTE_ERROR; } @@ -131,7 +139,8 @@ int work_ue_dl(srslte_ue_dl_nr_t* ue_dl, return SRSLTE_ERROR; } - if (srslte_ue_dl_nr_pdsch_get(ue_dl, slot, &pdsch_cfg, &pdsch_grant, pdsch_res) < SRSLTE_SUCCESS) { + pdsch_cfg.grant = pdsch_grant; + if (srslte_ue_dl_nr_decode_pdsch(ue_dl, slot, &pdsch_cfg, pdsch_res) < SRSLTE_SUCCESS) { ERROR("Error decoding\n"); return SRSLTE_ERROR; } @@ -254,7 +263,7 @@ int main(int argc, char** argv) } // Use grant default A time resources with m=0 - if (srslte_ue_dl_nr_pdsch_time_resource_default_A(0, pdsch_cfg.dmrs_typeA.typeA_pos, &pdsch_grant) < SRSLTE_SUCCESS) { + if (srslte_ra_dl_nr_time_default_A(0, pdsch_cfg.dmrs_typeA.typeA_pos, &pdsch_grant) < SRSLTE_SUCCESS) { ERROR("Error loading default grant\n"); goto clean_exit; } diff --git a/srsenb/hdr/phy/nr/cc_worker.h b/srsenb/hdr/phy/nr/cc_worker.h index 2b74a19d2..a60cbddb0 100644 --- a/srsenb/hdr/phy/nr/cc_worker.h +++ b/srsenb/hdr/phy/nr/cc_worker.h @@ -23,6 +23,7 @@ #define SRSENB_NR_CC_WORKER_H #include "srslte/common/log.h" +#include "srslte/interfaces/gnb_interfaces.h" #include "srslte/phy/enb/enb_dl_nr.h" #include #include @@ -69,9 +70,12 @@ public: cf_t* get_rx_buffer(uint32_t antenna_idx); uint32_t get_buffer_len(); - bool work_dl(); + bool work_dl(const srslte_dl_slot_cfg_t& dl_slot_cfg, stack_interface_phy_nr::dl_sched_t& dl_grants); private: + int encode_pdsch(stack_interface_phy_nr::dl_sched_grant_t* grants, uint32_t nof_grants); + int encode_pdcch_dl(stack_interface_phy_nr::dl_sched_grant_t* grants, uint32_t nof_grants); + srslte_dl_slot_cfg_t dl_slot_cfg = {}; uint32_t cc_idx = 0; std::array tx_buffer = {}; @@ -80,10 +84,6 @@ private: phy_nr_state* phy_state; srslte_enb_dl_nr_t enb_dl = {}; srslte::log* log_h = nullptr; - - // Temporal attributes - srslte_softbuffer_tx_t softbuffer_tx = {}; - std::vector data; }; } // namespace nr diff --git a/srsenb/hdr/phy/nr/sf_worker.h b/srsenb/hdr/phy/nr/sf_worker.h index 809531467..d01a70359 100644 --- a/srsenb/hdr/phy/nr/sf_worker.h +++ b/srsenb/hdr/phy/nr/sf_worker.h @@ -41,7 +41,7 @@ class sf_worker final : public srslte::thread_pool::worker { public: sf_worker(phy_common* phy_, phy_nr_state* phy_state_, srslte::log* log); - ~sf_worker() = default; + ~sf_worker(); bool set_carrier_unlocked(uint32_t cc_idx, const srslte_carrier_nr_t* carrier_); @@ -60,6 +60,10 @@ private: phy_common* phy = nullptr; phy_nr_state* phy_state = nullptr; srslte::log* log_h = nullptr; + + // Temporal attributes + srslte_softbuffer_tx_t softbuffer_tx = {}; + std::vector data; }; } // namespace nr diff --git a/srsenb/hdr/stack/rrc/rrc_config.h b/srsenb/hdr/stack/rrc/rrc_config.h index ee6e6b3b8..fc1cded79 100644 --- a/srsenb/hdr/stack/rrc/rrc_config.h +++ b/srsenb/hdr/stack/rrc/rrc_config.h @@ -17,6 +17,7 @@ #include "srslte/asn1/rrc.h" #include "srslte/common/security.h" #include "srslte/interfaces/enb_rrc_interface_types.h" +#include "srslte/phy/common/phy_common.h" #include namespace srsenb { diff --git a/srsenb/src/metrics_csv.cc b/srsenb/src/metrics_csv.cc index 9507dffd8..6385730fb 100644 --- a/srsenb/src/metrics_csv.cc +++ b/srsenb/src/metrics_csv.cc @@ -11,6 +11,7 @@ */ #include "srsenb/hdr/metrics_csv.h" +#include "srslte/phy/utils/vector.h" #include #include diff --git a/srsenb/src/metrics_stdout.cc b/srsenb/src/metrics_stdout.cc index 22928554e..cf44bde1b 100644 --- a/srsenb/src/metrics_stdout.cc +++ b/srsenb/src/metrics_stdout.cc @@ -11,6 +11,7 @@ */ #include "srsenb/hdr/metrics_stdout.h" +#include "srslte/phy/utils/vector.h" #include #include diff --git a/srsenb/src/phy/nr/cc_worker.cc b/srsenb/src/phy/nr/cc_worker.cc index 73b64f00c..3feb80514 100644 --- a/srsenb/src/phy/nr/cc_worker.cc +++ b/srsenb/src/phy/nr/cc_worker.cc @@ -20,10 +20,7 @@ */ #include "srsenb/hdr/phy/nr/cc_worker.h" -#include "srslte/common/common.h" -#include "srslte/phy/enb/enb_dl_nr.h" -#include "srslte/phy/phch/ra_nr.h" -#include "srslte/phy/ue/ue_dl_nr_data.h" +#include "srslte/srslte.h" namespace srsenb { namespace nr { @@ -44,21 +41,11 @@ cc_worker::cc_worker(uint32_t cc_idx_, srslte::log* log, phy_nr_state* phy_state ERROR("Error initiating UE DL NR\n"); return; } - - if (srslte_softbuffer_tx_init_guru(&softbuffer_tx, SRSLTE_SCH_NR_MAX_NOF_CB_LDPC, SRSLTE_LDPC_MAX_LEN_ENCODED_CB) < - SRSLTE_SUCCESS) { - ERROR("Error init soft-buffer\n"); - return; - } - data.resize(SRSLTE_SCH_NR_MAX_NOF_CB_LDPC * SRSLTE_LDPC_MAX_LEN_ENCODED_CB / 8); - srslte_vec_u8_zero(data.data(), SRSLTE_SCH_NR_MAX_NOF_CB_LDPC * SRSLTE_LDPC_MAX_LEN_ENCODED_CB / 8); - snprintf((char*)data.data(), SRSLTE_SCH_NR_MAX_NOF_CB_LDPC * SRSLTE_LDPC_MAX_LEN_ENCODED_CB / 8, "hello world!"); } cc_worker::~cc_worker() { srslte_enb_dl_nr_free(&enb_dl); - srslte_softbuffer_tx_free(&softbuffer_tx); for (cf_t* p : rx_buffer) { if (p != nullptr) { free(p); @@ -74,6 +61,16 @@ cc_worker::~cc_worker() bool cc_worker::set_carrier(const srslte_carrier_nr_t* carrier) { if (srslte_enb_dl_nr_set_carrier(&enb_dl, carrier) < SRSLTE_SUCCESS) { + ERROR("Error setting carrier\n"); + return false; + } + + srslte_coreset_t coreset = {}; + coreset.freq_resources[0] = true; // Enable the bottom 6 PRB for PDCCH + coreset.duration = 2; + + if (srslte_enb_dl_nr_set_coreset(&enb_dl, &coreset) < SRSLTE_SUCCESS) { + ERROR("Error setting coreset\n"); return false; } @@ -108,50 +105,74 @@ uint32_t cc_worker::get_buffer_len() return tx_buffer.size(); } -bool cc_worker::work_dl() +int cc_worker::encode_pdcch_dl(stack_interface_phy_nr::dl_sched_grant_t* grants, uint32_t nof_grants) { - srslte_sch_grant_nr_t pdsch_grant = {}; - srslte_sch_cfg_nr_t pdsch_cfg = phy_state->cfg.pdsch; - // Use grant default A time resources with m=0 - if (srslte_ue_dl_nr_pdsch_time_resource_default_A(0, pdsch_cfg.dmrs_typeA.typeA_pos, &pdsch_grant) < SRSLTE_SUCCESS) { - ERROR("Error loading default grant\n"); - return false; - } + for (uint32_t i = 0; i < nof_grants; i++) { - if (srslte_ue_dl_nr_nof_dmrs_cdm_groups_without_data_format_1_0(&pdsch_cfg, &pdsch_grant) < SRSLTE_SUCCESS) { - ERROR("Error loading number of DMRS CDM groups\n"); - return false; - } + // Get PHY config for UE + // ... - pdsch_grant.nof_layers = enb_dl.carrier.max_mimo_layers; - pdsch_grant.dci_format = srslte_dci_format_nr_1_0; - pdsch_grant.rnti = 0x1234; + // Put actual DCI + if (srslte_enb_dl_nr_pdcch_put(&enb_dl, &dl_slot_cfg, &grants[i].dci) < SRSLTE_SUCCESS) { + ERROR("Error putting PDCCH\n"); + return SRSLTE_ERROR; + } - for (uint32_t i = 0; i < enb_dl.carrier.nof_prb; i++) { - pdsch_grant.prb_idx[i] = true; + if (log_h->get_level() >= srslte::LOG_LEVEL_INFO) { + log_h->info("PDCCH: cc=%d, ...\n", cc_idx); + } } - if (srslte_ra_nr_fill_tb(&pdsch_cfg, &pdsch_grant, 27, &pdsch_grant.tb[0]) < SRSLTE_SUCCESS) { - ERROR("Error filing tb\n"); - return false; - } + return SRSLTE_SUCCESS; +} + +int cc_worker::encode_pdsch(stack_interface_phy_nr::dl_sched_grant_t* grants, uint32_t nof_grants) +{ + for (uint32_t i = 0; i < nof_grants; i++) { - uint8_t* data2[SRSLTE_MAX_TB] = {data.data(), data.data()}; - pdsch_grant.tb[0].softbuffer.tx = &softbuffer_tx; - srslte_softbuffer_tx_reset(pdsch_grant.tb[0].softbuffer.tx); + // Get PHY config for UE + // ... + srslte_sch_cfg_nr_t pdsch_cfg = phy_state->cfg.pdsch; - if (srslte_enb_dl_nr_pdsch_put(&enb_dl, &dl_slot_cfg, &pdsch_cfg, &pdsch_grant, data2) < SRSLTE_SUCCESS) { - ERROR("Error decoding PDSCH\n"); - return false; + // Compute DL grant + if (srslte_ra_dl_dci_to_grant_nr(&enb_dl.carrier, &pdsch_cfg, &grants[i].dci, &pdsch_cfg.grant)) { + ERROR("Computing DL grant\n"); + } + + // Set soft buffer + for (uint32_t j = 0; j < SRSLTE_MAX_CODEWORDS; j++) { + pdsch_cfg.grant.tb[j].softbuffer.tx = grants[i].softbuffer_tx[j]; + } + + if (srslte_enb_dl_nr_pdsch_put(&enb_dl, &dl_slot_cfg, &pdsch_cfg, grants[i].data) < SRSLTE_SUCCESS) { + ERROR("Error putting PDSCH\n"); + return false; + } + + // Logging + if (log_h->get_level() >= srslte::LOG_LEVEL_INFO) { + char str[512]; + srslte_enb_dl_nr_pdsch_info(&enb_dl, &pdsch_cfg, str, sizeof(str)); + log_h->info("PDSCH: cc=%d, %s\n", cc_idx, str); + } } - // Logging - if (log_h->get_level() >= srslte::LOG_LEVEL_INFO) { - char str[512]; - srslte_enb_dl_nr_pdsch_info(&enb_dl, &pdsch_cfg, &pdsch_grant, str, sizeof(str)); - log_h->info("PDSCH: cc=%d, %s\n", cc_idx, str); + return SRSLTE_SUCCESS; +} + +bool cc_worker::work_dl(const srslte_dl_slot_cfg_t& dl_sf_cfg, stack_interface_phy_nr::dl_sched_t& dl_grants) +{ + // Reset resource grid + if (srslte_enb_dl_nr_base_zero(&enb_dl) < SRSLTE_SUCCESS) { + ERROR("Error setting base to zero\n"); + return SRSLTE_ERROR; } + // Put DL grants to resource grid. PDSCH data will be encoded as well. + encode_pdcch_dl(dl_grants.pdsch, dl_grants.nof_grants); + encode_pdsch(dl_grants.pdsch, dl_grants.nof_grants); + + // Generate signal srslte_enb_dl_nr_gen_signal(&enb_dl); return true; diff --git a/srsenb/src/phy/nr/sf_worker.cc b/srsenb/src/phy/nr/sf_worker.cc index 5b0de8804..19bed3f0c 100644 --- a/srsenb/src/phy/nr/sf_worker.cc +++ b/srsenb/src/phy/nr/sf_worker.cc @@ -30,6 +30,20 @@ sf_worker::sf_worker(phy_common* phy_, phy_nr_state* phy_state_, srslte::log* lo cc_worker* w = new cc_worker(i, log, phy_state); cc_workers.push_back(std::unique_ptr(w)); } + + if (srslte_softbuffer_tx_init_guru(&softbuffer_tx, SRSLTE_SCH_NR_MAX_NOF_CB_LDPC, SRSLTE_LDPC_MAX_LEN_ENCODED_CB) < + SRSLTE_SUCCESS) { + ERROR("Error init soft-buffer\n"); + return; + } + data.resize(SRSLTE_SCH_NR_MAX_NOF_CB_LDPC * SRSLTE_LDPC_MAX_LEN_ENCODED_CB / 8); + srslte_vec_u8_zero(data.data(), SRSLTE_SCH_NR_MAX_NOF_CB_LDPC * SRSLTE_LDPC_MAX_LEN_ENCODED_CB / 8); + snprintf((char*)data.data(), SRSLTE_SCH_NR_MAX_NOF_CB_LDPC * SRSLTE_LDPC_MAX_LEN_ENCODED_CB / 8, "hello world!"); +} + +sf_worker::~sf_worker() +{ + srslte_softbuffer_tx_free(&softbuffer_tx); } bool sf_worker::set_carrier_unlocked(uint32_t cc_idx, const srslte_carrier_nr_t* carrier_) @@ -83,8 +97,35 @@ void sf_worker::work_imp() } } + // Configure user + phy_state->cfg.pdsch.rbg_size_cfg_1 = false; + phy_state->cfg.pdsch.pdsch_time_is_default = true; + + // Fill grant (this comes from the scheduler) + srslte_dl_slot_cfg_t dl_cfg = {}; + stack_interface_phy_nr::dl_sched_t grants = {}; + + grants.nof_grants = 1; + grants.pdsch[0].data[0] = data.data(); + grants.pdsch[0].softbuffer_tx[0] = &softbuffer_tx; + srslte_softbuffer_tx_reset(&softbuffer_tx); + + grants.pdsch[0].dci.rnti = 0x1234; + grants.pdsch[0].dci.format = srslte_dci_format_nr_1_0; + + grants.pdsch[0].dci.freq_domain_assigment = 0x1FFF; + grants.pdsch[0].dci.time_domain_assigment = 0; + grants.pdsch[0].dci.mcs = 27; + + grants.pdsch[0].dci.search_space.type = srslte_search_space_type_ue; + for (uint32_t L = 0; L < SRSLTE_SEARCH_SPACE_NOF_AGGREGATION_LEVELS_NR; L++) { + grants.pdsch[0].dci.search_space.nof_candidates[L] = 1; + } + grants.pdsch[0].dci.location.L = 0; + grants.pdsch[0].dci.location.ncce = 0; + for (auto& w : cc_workers) { - w->work_dl(); + w->work_dl(dl_cfg, grants); } phy->worker_end(this, tx_buffer, dummy_ts, true); diff --git a/srsenb/src/stack/rrc/rrc_cell_cfg.cc b/srsenb/src/stack/rrc/rrc_cell_cfg.cc index 10f58b15e..a71a9f471 100644 --- a/srsenb/src/stack/rrc/rrc_cell_cfg.cc +++ b/srsenb/src/stack/rrc/rrc_cell_cfg.cc @@ -11,6 +11,7 @@ */ #include "srsenb/hdr/stack/rrc/rrc_cell_cfg.h" +#include "srslte/phy/utils/vector.h" using namespace asn1::rrc; diff --git a/srsepc/src/hss/hss.cc b/srsepc/src/hss/hss.cc index ae984f0be..1528dd062 100644 --- a/srsepc/src/hss/hss.cc +++ b/srsepc/src/hss/hss.cc @@ -11,6 +11,7 @@ */ #include "srsepc/hdr/hss/hss.h" #include "srslte/common/security.h" +#include #include // for printing uint64_t #include #include diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index 36dd1be73..e6a4abccb 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -21,6 +21,7 @@ #include "srslte/common/logger_srslog_wrapper.h" #include "srslte/common/signal_handler.h" #include "srslte/srslog/srslog.h" +#include "srslte/srslte.h" #include #include #include diff --git a/srsepc/src/spgw/gtpc.cc b/srsepc/src/spgw/gtpc.cc index ed528bccf..124377e4f 100644 --- a/srsepc/src/spgw/gtpc.cc +++ b/srsepc/src/spgw/gtpc.cc @@ -12,6 +12,7 @@ #include "srsepc/hdr/spgw/gtpc.h" #include +#include #include #include #include // for printing uint64_t diff --git a/srsepc/src/spgw/gtpu.cc b/srsepc/src/spgw/gtpu.cc index cd2a21f15..cd6b19e8b 100644 --- a/srsepc/src/spgw/gtpu.cc +++ b/srsepc/src/spgw/gtpu.cc @@ -14,6 +14,7 @@ #include "srsepc/hdr/mme/mme_gtpc.h" #include "srslte/upper/gtpu.h" #include +#include #include #include // for printing uint64_t #include diff --git a/srsue/hdr/phy/nr/cc_worker.h b/srsue/hdr/phy/nr/cc_worker.h index df3100ff7..613f40107 100644 --- a/srsue/hdr/phy/nr/cc_worker.h +++ b/srsue/hdr/phy/nr/cc_worker.h @@ -23,7 +23,7 @@ #define SRSLTE_NR_CC_WORKER_H #include "srslte/common/log.h" -#include "srslte/phy/ue/ue_dl_nr.h" +#include "srslte/srslte.h" #include "srsue/hdr/phy/phy_common.h" #include #include @@ -84,6 +84,13 @@ private: // Temporal attributes srslte_softbuffer_rx_t softbuffer_rx = {}; std::vector data; + + // Current rnti + uint16_t rnti = 0; + + // Current coreset and search space + srslte_coreset_t coreset = {}; + srslte_search_space_t search_space = {}; }; } // namespace nr diff --git a/srsue/hdr/stack/rrc/rrc.h b/srsue/hdr/stack/rrc/rrc.h index 3cdd7b3a1..74d71d6d1 100644 --- a/srsue/hdr/stack/rrc/rrc.h +++ b/srsue/hdr/stack/rrc/rrc.h @@ -114,7 +114,7 @@ public: void set_ue_identity(srslte::s_tmsi_t s_tmsi); void paging_completed(bool outcome) final; bool has_nr_dc(); - + // NR interface #ifdef HAVE_5GNR void new_cell_meas_nr(const std::vector& meas); diff --git a/srsue/src/phy/nr/cc_worker.cc b/srsue/src/phy/nr/cc_worker.cc index e7c4fb354..6573585b0 100644 --- a/srsue/src/phy/nr/cc_worker.cc +++ b/srsue/src/phy/nr/cc_worker.cc @@ -20,8 +20,7 @@ */ #include "srsue/hdr/phy/nr/cc_worker.h" -#include "srslte/phy/phch/ra_nr.h" -#include "srslte/phy/ue/ue_dl_nr_data.h" +#include "srslte/srslte.h" namespace srsue { namespace nr { @@ -74,7 +73,6 @@ bool cc_worker::set_carrier(const srslte_carrier_nr_t* carrier) return false; } - srslte_coreset_t coreset = {}; coreset.freq_resources[0] = true; // Enable the bottom 6 PRB for PDCCH coreset.duration = 2; @@ -83,6 +81,10 @@ bool cc_worker::set_carrier(const srslte_carrier_nr_t* carrier) return false; } + // Set default PDSCH config + phy_state->cfg.pdsch.rbg_size_cfg_1 = false; + phy_state->cfg.pdsch.pdsch_time_is_default = true; + return true; } @@ -107,41 +109,50 @@ uint32_t cc_worker::get_buffer_len() bool cc_worker::work_dl() { - srslte_sch_grant_nr_t pdsch_grant = {}; + srslte_dci_dl_nr_t dci_dl = {}; srslte_sch_cfg_nr_t pdsch_cfg = phy_state->cfg.pdsch; std::array pdsch_res = {}; - // Use grant default A time resources with m=0 - if (srslte_ue_dl_nr_pdsch_time_resource_default_A(0, pdsch_cfg.dmrs_typeA.typeA_pos, &pdsch_grant) < SRSLTE_SUCCESS) { - ERROR("Error loading default grant\n"); - return false; - } + // Run FFT + srslte_ue_dl_nr_estimate_fft(&ue_dl, &dl_slot_cfg); - if (srslte_ue_dl_nr_nof_dmrs_cdm_groups_without_data_format_1_0(&pdsch_cfg, &pdsch_grant) < SRSLTE_SUCCESS) { - ERROR("Error loading number of DMRS CDM groups\n"); - return false; - } + // Set rnti + rnti = 0x1234; - pdsch_grant.nof_layers = ue_dl.carrier.max_mimo_layers; - pdsch_grant.dci_format = srslte_dci_format_nr_1_0; - pdsch_grant.rnti = 0x1234; + // Configure Search space + search_space.type = srslte_search_space_type_ue; + for (uint32_t L = 0; L < SRSLTE_SEARCH_SPACE_NOF_AGGREGATION_LEVELS_NR; L++) { + search_space.nof_candidates[L] = srslte_pdcch_nr_max_candidates_coreset(&coreset, L); + } - for (uint32_t i = 0; i < ue_dl.carrier.nof_prb; i++) { - pdsch_grant.prb_idx[i] = true; + srslte_dci_dl_nr_t dci_dl_rx = {}; + int nof_found_dci = srslte_ue_dl_nr_find_dl_dci(&ue_dl, &search_space, &dl_slot_cfg, rnti, &dci_dl_rx, 1); + if (nof_found_dci < SRSLTE_SUCCESS) { + ERROR("Error decoding\n"); + return SRSLTE_ERROR; } - if (srslte_ra_nr_fill_tb(&pdsch_cfg, &pdsch_grant, 27, &pdsch_grant.tb[0]) < SRSLTE_SUCCESS) { - ERROR("Error filing tb\n"); - return false; + if (nof_found_dci < 1) { + ERROR("Error DCI not found\n"); } - pdsch_res[0].payload = data.data(); - pdsch_grant.tb[0].softbuffer.rx = &softbuffer_rx; - srslte_softbuffer_rx_reset(pdsch_grant.tb[0].softbuffer.rx); + dci_dl.rnti = 0x1234; + dci_dl.format = srslte_dci_format_nr_1_0; - srslte_ue_dl_nr_estimate_fft(&ue_dl, &dl_slot_cfg); + dci_dl.freq_domain_assigment = 0x1FFF; + dci_dl.time_domain_assigment = 0; + dci_dl.mcs = 27; + + // Compute DL grant + if (srslte_ra_dl_dci_to_grant_nr(&ue_dl.carrier, &pdsch_cfg, &dci_dl, &pdsch_cfg.grant)) { + ERROR("Computing DL grant\n"); + } + + pdsch_res[0].payload = data.data(); + pdsch_cfg.grant.tb[0].softbuffer.rx = &softbuffer_rx; + srslte_softbuffer_rx_reset(pdsch_cfg.grant.tb[0].softbuffer.rx); - if (srslte_ue_dl_nr_pdsch_get(&ue_dl, &dl_slot_cfg, &pdsch_cfg, &pdsch_grant, pdsch_res.data()) < SRSLTE_SUCCESS) { + if (srslte_ue_dl_nr_decode_pdsch(&ue_dl, &dl_slot_cfg, &pdsch_cfg, pdsch_res.data()) < SRSLTE_SUCCESS) { ERROR("Error decoding PDSCH\n"); return false; } @@ -149,7 +160,7 @@ bool cc_worker::work_dl() // Logging if (log_h->get_level() >= srslte::LOG_LEVEL_INFO) { char str[512]; - srslte_ue_dl_nr_pdsch_info(&ue_dl, &pdsch_cfg, &pdsch_grant, pdsch_res.data(), str, sizeof(str)); + srslte_ue_dl_nr_pdsch_info(&ue_dl, &pdsch_cfg, pdsch_res.data(), str, sizeof(str)); log_h->info("PDSCH: cc=%d, %s\n", cc_idx, str); } diff --git a/srsue/src/stack/rrc/rrc.cc b/srsue/src/stack/rrc/rrc.cc index a94ba86b0..0e32cfb47 100644 --- a/srsue/src/stack/rrc/rrc.cc +++ b/srsue/src/stack/rrc/rrc.cc @@ -1972,7 +1972,7 @@ void rrc::handle_ue_capability_enquiry(const ue_cap_enquiry_s& enquiry) if (args.release > 14) { ue_eutra_cap_v1450_ies = &ue_eutra_cap_v1360_ies->non_crit_ext.non_crit_ext.non_crit_ext; // 14.60 - ue_eutra_cap_v1450_ies->non_crit_ext_present = true; + ue_eutra_cap_v1450_ies->non_crit_ext_present = true; ue_eutra_cap_v1450_ies->non_crit_ext.non_crit_ext_present = true; irat_params_nr_r15_s irat_params_nr_r15; diff --git a/srsue/src/stack/rrc/rrc_nr.cc b/srsue/src/stack/rrc/rrc_nr.cc index faf2aa22f..852e5ee92 100644 --- a/srsue/src/stack/rrc/rrc_nr.cc +++ b/srsue/src/stack/rrc/rrc_nr.cc @@ -181,8 +181,8 @@ void rrc_nr::get_eutra_nr_capabilities(srslte::byte_buffer_t* eutra_nr_caps_pdu) band_combination_v1540_s band_combination_v1540; band_params_v1540_s band_params_a; - band_params_a.srs_tx_switch_present = true; - band_params_a.srs_carrier_switch_present = false; + band_params_a.srs_tx_switch_present = true; + band_params_a.srs_carrier_switch_present = false; band_params_a.srs_tx_switch.supported_srs_tx_port_switch = band_params_v1540_s::srs_tx_switch_s_::supported_srs_tx_port_switch_opts::not_supported; band_combination_v1540.band_list_v1540.push_back(band_params_a); diff --git a/srsue/src/stack/upper/tft_packet_filter.cc b/srsue/src/stack/upper/tft_packet_filter.cc index 8a4a8d92d..d7e2643a7 100644 --- a/srsue/src/stack/upper/tft_packet_filter.cc +++ b/srsue/src/stack/upper/tft_packet_filter.cc @@ -29,7 +29,7 @@ tft_packet_filter_t::tft_packet_filter_t(uint8_t active_filters(0), log(log_) { - int idx = 0; + int idx = 0; uint32_t length_in_bytes = 0; uint32_t remaining_bits = 0; while (idx < tft.filter_size) { @@ -237,7 +237,7 @@ bool tft_packet_filter_t::match_ip(const srslte::unique_byte_buffer_t& pdu) if (filter_contains(IPV6_REMOTE_ADDR_FLAG | IPV6_REMOTE_ADDR_LENGTH_FLAG)) { bool match = true; for (int i = 0; i < ipv6_remote_addr_length; i++) { - match &= ((ipv6_remote_addr[i] ^ ip6_pkt->daddr.__in6_u.__u6_addr8[i]) & ipv6_remote_addr_mask[i]) == 0; + match &= ((ipv6_remote_addr[i] ^ ip6_pkt->daddr.in6_u.u6_addr8[i]) & ipv6_remote_addr_mask[i]) == 0; if (!match) { return false; }