From 61e225d7622747b2e5a2b5b586c3db4c1c34b731 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Sat, 8 Jan 2022 13:11:38 +0100 Subject: [PATCH] asn1: move setup_release_c from rrc_nr_asn1 to asn1_utils and improved interface --- lib/include/srsran/asn1/asn1_utils.h | 80 ++++++++++++++++++++ lib/include/srsran/asn1/rrc_nr.h | 95 ------------------------ lib/src/asn1/rrc_nr_utils.cc | 11 +-- lib/test/asn1/srsran_asn1_rrc_nr_test.cc | 10 +-- srsue/src/stack/rrc_nr/rrc_nr.cc | 5 +- 5 files changed, 89 insertions(+), 112 deletions(-) diff --git a/lib/include/srsran/asn1/asn1_utils.h b/lib/include/srsran/asn1/asn1_utils.h index 84633c787..f95f6a03f 100644 --- a/lib/include/srsran/asn1/asn1_utils.h +++ b/lib/include/srsran/asn1/asn1_utils.h @@ -1458,6 +1458,86 @@ struct setup_release_opts { }; using setup_release_e = enumerated; +// SetupRelease{ElementTypeParam} ::= CHOICE +template +struct setup_release_c { + using types_opts = setup_release_opts; + using types = setup_release_e; + + // choice methods + setup_release_c() = default; + void set(typename types::options e = types::nulltype) { type_ = e; } + types type() const { return type_; } + SRSASN_CODE pack(bit_ref& bref) const + { + type_.pack(bref); + switch (type_) { + case types::release: + break; + case types::setup: + HANDLE_CODE(c.pack(bref)); + break; + default: + log_invalid_choice_id(type_, "setup_release_c"); + return SRSASN_ERROR_ENCODE_FAIL; + } + return SRSASN_SUCCESS; + } + SRSASN_CODE unpack(cbit_ref& bref) + { + types e; + e.unpack(bref); + set(e); + switch (type_) { + case types::release: + break; + case types::setup: + HANDLE_CODE(c.unpack(bref)); + break; + default: + log_invalid_choice_id(type_, "setup_release_c"); + return SRSASN_ERROR_DECODE_FAIL; + } + return SRSASN_SUCCESS; + } + void to_json(json_writer& j) const + { + j.start_obj(); + switch (type_) { + case types::release: + break; + case types::setup: + asn1::to_json(j, setup()); + break; + default: + log_invalid_choice_id(type_, "setup_release_c"); + } + j.end_obj(); + } + // getters + bool is_setup() const { return type_.value == setup_release_opts::setup; } + T& setup() + { + assert_choice_type(types::setup, type_, "SetupRelease"); + return c; + } + const T& setup() const + { + assert_choice_type(types::setup, type_, "SetupRelease"); + return c; + } + void set_release() { set(types::release); } + T& set_setup() + { + set(types::setup); + return c; + } + +private: + types type_; + T c; +}; + // Criticality ::= ENUMERATED struct crit_opts { enum options { reject, ignore, notify, nulltype } value; diff --git a/lib/include/srsran/asn1/rrc_nr.h b/lib/include/srsran/asn1/rrc_nr.h index 2eba2ff82..16d5d0f51 100644 --- a/lib/include/srsran/asn1/rrc_nr.h +++ b/lib/include/srsran/asn1/rrc_nr.h @@ -2238,101 +2238,6 @@ struct sib_type_info_s { void to_json(json_writer& j) const; }; -// SetupRelease{ElementTypeParam} ::= CHOICE -template -struct setup_release_c { - struct types_opts { - enum options { release, setup, nulltype } value; - - const char* to_string() const - { - static const char* options[] = {"release", "setup"}; - return convert_enum_idx(options, 2, value, "setup_release_c::types"); - } - }; - typedef enumerated types; - - // choice methods - setup_release_c() = default; - types type() const { return type_; } - - // getters - elem_type_paramT_& setup() - { - assert_choice_type(types::setup, type_, "SetupRelease"); - return c; - } - const elem_type_paramT_& setup() const - { - assert_choice_type(types::setup, type_, "SetupRelease"); - return c; - } - void set_release() { set(types::release); } - - void set(typename types::options e) { type_ = e; } - - void to_json(json_writer& j) const - { - j.start_obj(); - switch (type_) { - case types::release: - j.write_null("release"); - break; - case types::setup: - j.write_fieldname("setup"); - asn1::to_json(j, setup()); - break; - default: - log_invalid_choice_id(type_, "setup_release_c"); - } - j.end_obj(); - } - - SRSASN_CODE pack(bit_ref& bref) const - { - type_.pack(bref); - switch (type_) { - case types::release: - break; - case types::setup: - HANDLE_CODE(c.pack(bref)); - break; - default: - log_invalid_choice_id(type_, "setup_release_c"); - return SRSASN_ERROR_ENCODE_FAIL; - } - return SRSASN_SUCCESS; - } - - SRSASN_CODE unpack(cbit_ref& bref) - { - types e; - e.unpack(bref); - set(e); - switch (type_) { - case types::release: - break; - case types::setup: - HANDLE_CODE(c.unpack(bref)); - break; - default: - log_invalid_choice_id(type_, "setup_release_c"); - return SRSASN_ERROR_DECODE_FAIL; - } - return SRSASN_SUCCESS; - } - - elem_type_paramT_& set_setup() - { - set(types::setup); - return c; - } - -private: - types type_; - elem_type_paramT_ c; -}; - // UAC-BarringPerCat ::= SEQUENCE struct uac_barr_per_cat_s { uint8_t access_category = 1; diff --git a/lib/src/asn1/rrc_nr_utils.cc b/lib/src/asn1/rrc_nr_utils.cc index 5fe352581..00abac0ad 100644 --- a/lib/src/asn1/rrc_nr_utils.cc +++ b/lib/src/asn1/rrc_nr_utils.cc @@ -1530,9 +1530,7 @@ bool make_phy_mib(const asn1::rrc_nr::mib_s& mib_cfg, srsran_mib_nr_t* mib) bool make_pdsch_cfg_from_serv_cell(const asn1::rrc_nr::serving_cell_cfg_s& serv_cell, srsran_sch_hl_cfg_nr_t* sch_hl) { - if (serv_cell.csi_meas_cfg_present and - serv_cell.csi_meas_cfg.type().value == - setup_release_c< ::asn1::rrc_nr::csi_meas_cfg_s>::types_opts::options::setup) { + if (serv_cell.csi_meas_cfg_present and serv_cell.csi_meas_cfg.is_setup()) { auto& setup = serv_cell.csi_meas_cfg.setup(); // Configure NZP-CSI @@ -1552,8 +1550,7 @@ bool make_pdsch_cfg_from_serv_cell(const asn1::rrc_nr::serving_cell_cfg_s& serv_ } } - if (serv_cell.init_dl_bwp.pdsch_cfg_present and - serv_cell.init_dl_bwp.pdsch_cfg.type() == setup_release_c::types_opts::setup) { + if (serv_cell.init_dl_bwp.pdsch_cfg_present and serv_cell.init_dl_bwp.pdsch_cfg.is_setup()) { const auto& setup = serv_cell.init_dl_bwp.pdsch_cfg.setup(); if (setup.p_zp_csi_rs_res_set_present) { auto& setup_set = setup.p_zp_csi_rs_res_set.setup(); @@ -1573,9 +1570,7 @@ bool make_pdsch_cfg_from_serv_cell(const asn1::rrc_nr::serving_cell_cfg_s& serv_ bool make_csi_cfg_from_serv_cell(const asn1::rrc_nr::serving_cell_cfg_s& serv_cell, srsran_csi_hl_cfg_t* csi_hl) { - if (serv_cell.csi_meas_cfg_present and - serv_cell.csi_meas_cfg.type().value == - setup_release_c< ::asn1::rrc_nr::csi_meas_cfg_s>::types_opts::options::setup) { + if (serv_cell.csi_meas_cfg_present and serv_cell.csi_meas_cfg.is_setup()) { auto& setup = serv_cell.csi_meas_cfg.setup(); // Configure CSI-Report diff --git a/lib/test/asn1/srsran_asn1_rrc_nr_test.cc b/lib/test/asn1/srsran_asn1_rrc_nr_test.cc index 0006e9e14..99e148606 100644 --- a/lib/test/asn1/srsran_asn1_rrc_nr_test.cc +++ b/lib/test/asn1/srsran_asn1_rrc_nr_test.cc @@ -362,9 +362,8 @@ int test_cell_group_config_tdd() cell_group_cfg.sp_cell_cfg.recfg_with_sync.sp_cell_cfg_common.ul_cfg_common.init_ul_bwp.rach_cfg_common_present == true); - TESTASSERT( - cell_group_cfg.sp_cell_cfg.recfg_with_sync.sp_cell_cfg_common.ul_cfg_common.init_ul_bwp.rach_cfg_common.type() == - asn1::rrc_nr::setup_release_c::types_opts::setup); + TESTASSERT(cell_group_cfg.sp_cell_cfg.recfg_with_sync.sp_cell_cfg_common.ul_cfg_common.init_ul_bwp.rach_cfg_common + .is_setup()); asn1::rrc_nr::rach_cfg_common_s& rach_cfg_common = cell_group_cfg.sp_cell_cfg.recfg_with_sync.sp_cell_cfg_common.ul_cfg_common.init_ul_bwp.rach_cfg_common.setup(); @@ -980,9 +979,8 @@ int test_cell_group_config_fdd() cell_group_cfg.sp_cell_cfg.recfg_with_sync.sp_cell_cfg_common.ul_cfg_common.init_ul_bwp.rach_cfg_common_present == true); - TESTASSERT( - cell_group_cfg.sp_cell_cfg.recfg_with_sync.sp_cell_cfg_common.ul_cfg_common.init_ul_bwp.rach_cfg_common.type() == - asn1::rrc_nr::setup_release_c::types_opts::setup); + TESTASSERT(cell_group_cfg.sp_cell_cfg.recfg_with_sync.sp_cell_cfg_common.ul_cfg_common.init_ul_bwp.rach_cfg_common + .is_setup()); asn1::rrc_nr::rach_cfg_common_s& rach_cfg_common = cell_group_cfg.sp_cell_cfg.recfg_with_sync.sp_cell_cfg_common.ul_cfg_common.init_ul_bwp.rach_cfg_common.setup(); diff --git a/srsue/src/stack/rrc_nr/rrc_nr.cc b/srsue/src/stack/rrc_nr/rrc_nr.cc index 345f02805..86efd5980 100644 --- a/srsue/src/stack/rrc_nr/rrc_nr.cc +++ b/srsue/src/stack/rrc_nr/rrc_nr.cc @@ -974,7 +974,7 @@ bool rrc_nr::apply_mac_cell_group(const mac_cell_group_cfg_s& mac_cell_group_cfg } if (mac_cell_group_cfg.phr_cfg_present) { - if (mac_cell_group_cfg.phr_cfg.type() == setup_release_c::types_opts::setup) { + if (mac_cell_group_cfg.phr_cfg.is_setup()) { phr_cfg_nr_t phr_cfg_nr; if (make_mac_phr_cfg_t(mac_cell_group_cfg.phr_cfg.setup(), &phr_cfg_nr) != true) { logger.warning("Unable to build PHR config"); @@ -1196,8 +1196,7 @@ bool rrc_nr::apply_dl_common_cfg(const asn1::rrc_nr::dl_cfg_common_s& dl_cfg_com } if (dl_cfg_common.init_dl_bwp_present) { if (dl_cfg_common.init_dl_bwp.pdsch_cfg_common_present) { - if (dl_cfg_common.init_dl_bwp.pdsch_cfg_common.type() == - asn1::rrc_nr::setup_release_c::types_opts::setup) { + if (dl_cfg_common.init_dl_bwp.pdsch_cfg_common.is_setup()) { const pdcch_cfg_common_s& pdcch_cfg_common = dl_cfg_common.init_dl_bwp.pdcch_cfg_common.setup(); // Load CORESET Zero