From bb0dbf0f1cb826277bb8e55c1602f69a8fc51eed Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Wed, 3 Jul 2019 16:20:32 +0100 Subject: [PATCH] created a asn1 utils with helper functions and types related to the asn1. These types/functions will help isolate the rrc_asn1 lib from most of the layers, reducing this way the compile times, and leading to better isolation. This will also make the transition to NR smoother. I removed the asn1 types from the NAS and USIM interface so far. --- lib/include/srslte/asn1/rrc_asn1_utils.h | 75 +++++++++++++ lib/include/srslte/common/bcd_helpers.h | 4 +- lib/include/srslte/interfaces/ue_interfaces.h | 15 +-- lib/src/asn1/CMakeLists.txt | 1 + lib/src/asn1/rrc_asn1_utils.cc | 105 ++++++++++++++++++ srsue/hdr/stack/rrc/rrc.h | 21 ++-- srsue/hdr/stack/upper/nas.h | 8 +- srsue/hdr/stack/upper/usim.h | 2 +- srsue/hdr/stack/upper/usim_base.h | 2 +- srsue/src/stack/rrc/rrc.cc | 33 +++--- srsue/src/stack/upper/nas.cc | 48 ++++---- srsue/src/stack/upper/usim.cc | 7 +- srsue/test/upper/CMakeLists.txt | 2 +- srsue/test/upper/nas_test.cc | 10 +- 14 files changed, 255 insertions(+), 78 deletions(-) create mode 100644 lib/include/srslte/asn1/rrc_asn1_utils.h create mode 100644 lib/src/asn1/rrc_asn1_utils.cc diff --git a/lib/include/srslte/asn1/rrc_asn1_utils.h b/lib/include/srslte/asn1/rrc_asn1_utils.h new file mode 100644 index 000000000..16fb1c6b4 --- /dev/null +++ b/lib/include/srslte/asn1/rrc_asn1_utils.h @@ -0,0 +1,75 @@ +/* + * Copyright 2013-2019 Software Radio Systems Limited + * + * This file is part of srsLTE. + * + * srsLTE is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * srsLTE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * A copy of the GNU Affero General Public License can be found in + * the LICENSE file in the top-level directory of this distribution + * and at http://www.gnu.org/licenses/. + * + */ + +#ifndef SRSLTE_RRC_ASN1_UTILS_H +#define SRSLTE_RRC_ASN1_UTILS_H + +#include + +// fwd decls +namespace asn1 { +namespace rrc { + +struct plmn_id_s; +struct s_tmsi_s; + +} // namespace rrc +} // namespace asn1 + +namespace srslte { + +struct plmn_id_t { + uint8_t mcc[3]; + uint8_t mnc[3]; + uint8_t nof_mnc_digits; + + plmn_id_t() : mcc(), mnc(), nof_mnc_digits(0) {} + int from_asn1(const asn1::rrc::plmn_id_s* asn1_type); + void to_asn1(asn1::rrc::plmn_id_s* asn1_type) const; + void from_number(uint16_t mcc_num, uint16_t mnc_num); + int from_string(const std::string& plmn_str); + std::string to_string() const; +}; + +struct s_tmsi_t { + uint8_t mmec; + uint32_t m_tmsi; + + void from_asn1(const asn1::rrc::s_tmsi_s* asn1_type); + void to_asn1(asn1::rrc::s_tmsi_s* asn1_type) const; +}; + +enum class establishment_cause_t { + emergency, + high_prio_access, + mt_access, + mo_sig, + mo_data, + delay_tolerant_access_v1020, + mo_voice_call_v1280, + spare1, + nulltype +}; +std::string to_string(const establishment_cause_t& cause); + +} + +#endif // SRSLTE_RRC_ASN1_UTILS_H diff --git a/lib/include/srslte/common/bcd_helpers.h b/lib/include/srslte/common/bcd_helpers.h index 4c013c012..b4bf50b6d 100644 --- a/lib/include/srslte/common/bcd_helpers.h +++ b/lib/include/srslte/common/bcd_helpers.h @@ -69,7 +69,7 @@ inline bool mcc_to_string(uint16_t mcc, std::string *str) * MCC 001 results in 0xF001 *****************************************************************************/ -inline bool bytes_to_mcc(uint8_t* bytes, uint16_t* mcc) +inline bool bytes_to_mcc(const uint8_t* bytes, uint16_t* mcc) { *mcc = 0xF000; *mcc |= (((uint16_t)bytes[0]) << 8u); @@ -153,7 +153,7 @@ inline bool mnc_to_string(uint16_t mnc, std::string *str) * MNC 001 results in 0xF001 * MNC 01 results in 0xFF01 *****************************************************************************/ -inline bool bytes_to_mnc(uint8_t* bytes, uint16_t* mnc, uint8_t len) +inline bool bytes_to_mnc(const uint8_t* bytes, uint16_t* mnc, uint8_t len) { if (len != 3 && len != 2) { *mnc = 0; diff --git a/lib/include/srslte/interfaces/ue_interfaces.h b/lib/include/srslte/interfaces/ue_interfaces.h index 13c45e780..d39468c09 100644 --- a/lib/include/srslte/interfaces/ue_interfaces.h +++ b/lib/include/srslte/interfaces/ue_interfaces.h @@ -32,6 +32,7 @@ #include "srslte/asn1/liblte_mme.h" #include "srslte/asn1/rrc_asn1.h" +#include "srslte/asn1/rrc_asn1_utils.h" #include "srslte/common/common.h" #include "srslte/common/interfaces_common.h" #include "srslte/common/security.h" @@ -55,7 +56,7 @@ public: virtual std::string get_imei_str() = 0; virtual bool get_imsi_vec(uint8_t* imsi_, uint32_t n) = 0; virtual bool get_imei_vec(uint8_t* imei_, uint32_t n) = 0; - virtual bool get_home_plmn_id(asn1::rrc::plmn_id_s* home_plmn_id) = 0; + virtual bool get_home_plmn_id(srslte::plmn_id_t* home_plmn_id) = 0; virtual auth_result_t generate_authentication_response(uint8_t *rand, uint8_t *autn_enb, uint16_t mcc, @@ -131,7 +132,7 @@ public: } barring_t; virtual void leave_connected() = 0; virtual void set_barring(barring_t barring) = 0; - virtual void paging(asn1::rrc::s_tmsi_s* ue_identiy) = 0; + virtual void paging(srslte::s_tmsi_t* ue_identity) = 0; virtual bool is_attached() = 0; virtual void write_pdu(uint32_t lcid, srslte::unique_byte_buffer_t pdu) = 0; virtual uint32_t get_k_enb_count() = 0; @@ -183,7 +184,7 @@ class rrc_interface_nas { public: typedef struct { - asn1::rrc::plmn_id_s plmn_id; + srslte::plmn_id_t plmn_id; uint16_t tac; } found_plmn_t; @@ -194,10 +195,10 @@ public: virtual uint16_t get_mnc() = 0; virtual void enable_capabilities() = 0; virtual int plmn_search(found_plmn_t found_plmns[MAX_FOUND_PLMNS]) = 0; - virtual void plmn_select(asn1::rrc::plmn_id_s plmn_id) = 0; - virtual bool connection_request(asn1::rrc::establishment_cause_e cause, - srslte::unique_byte_buffer_t dedicatedInfoNAS) = 0; - virtual void set_ue_idenity(asn1::rrc::s_tmsi_s s_tmsi) = 0; + virtual void plmn_select(srslte::plmn_id_t plmn_id) = 0; + virtual bool connection_request(srslte::establishment_cause_t cause, + srslte::unique_byte_buffer_t dedicatedInfoNAS) = 0; + virtual void set_ue_identity(srslte::s_tmsi_t s_tmsi) = 0; virtual bool is_connected() = 0; virtual std::string get_rb_name(uint32_t lcid) = 0; virtual uint32_t get_lcid_for_eps_bearer(const uint32_t& eps_bearer_id) = 0; diff --git a/lib/src/asn1/CMakeLists.txt b/lib/src/asn1/CMakeLists.txt index f88b0ad26..04d753e0b 100644 --- a/lib/src/asn1/CMakeLists.txt +++ b/lib/src/asn1/CMakeLists.txt @@ -32,6 +32,7 @@ add_library(rrc_asn1 STATIC rrc_asn1.cc rrc_asn1_enum.cc asn1_utils.cc + rrc_asn1_utils.cc ) # Compile RRC ASN1 optimized for size target_compile_options(rrc_asn1 PRIVATE "-Os") diff --git a/lib/src/asn1/rrc_asn1_utils.cc b/lib/src/asn1/rrc_asn1_utils.cc new file mode 100644 index 000000000..ed94d38f9 --- /dev/null +++ b/lib/src/asn1/rrc_asn1_utils.cc @@ -0,0 +1,105 @@ +/* + * Copyright 2013-2019 Software Radio Systems Limited + * + * This file is part of srsLTE. + * + * srsLTE is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * srsLTE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * A copy of the GNU Affero General Public License can be found in + * the LICENSE file in the top-level directory of this distribution + * and at http://www.gnu.org/licenses/. + * + */ + +#include "srslte/asn1/rrc_asn1_utils.h" +#include "srslte/asn1/rrc_asn1.h" +#include "srslte/common/bcd_helpers.h" +#include "srslte/config.h" +#include + +namespace srslte { + +int plmn_id_t::from_asn1(const asn1::rrc::plmn_id_s* asn1_type) +{ + if (not asn1_type->mcc_present) { + return SRSLTE_ERROR; + } + std::copy(&asn1_type->mcc[0], &asn1_type->mcc[3], &mcc[0]); + nof_mnc_digits = asn1_type->mnc.size(); + std::copy(&asn1_type->mnc[0], &asn1_type->mnc[nof_mnc_digits], &mnc[0]); + + return SRSLTE_SUCCESS; +} + +void plmn_id_t::to_asn1(asn1::rrc::plmn_id_s* asn1_type) const +{ + asn1_type->mcc_present = true; + std::copy(&mcc[0], &mcc[3], &asn1_type->mcc[0]); + asn1_type->mnc.resize(nof_mnc_digits); + std::copy(&mnc[0], &mnc[nof_mnc_digits], &asn1_type->mnc[0]); +} + +void plmn_id_t::from_number(uint16_t mcc_num, uint16_t mnc_num) +{ + srslte::mcc_to_bytes(mcc_num, &mcc[0]); + srslte::mnc_to_bytes(mnc_num, &mnc[0], &nof_mnc_digits); +} + +int plmn_id_t::from_string(const std::string& plmn_str) +{ + if (plmn_str.size() < 5 or plmn_str.size() > 6) { + return SRSLTE_ERROR; + } + uint16_t mnc_num, mcc_num; + if (not string_to_mcc(std::string(plmn_str.begin(), plmn_str.begin() + 3), &mcc_num)) { + return SRSLTE_ERROR; + } + if (not string_to_mnc(std::string(plmn_str.begin() + 3, plmn_str.end()), &mnc_num)) { + return SRSLTE_ERROR; + } + if (not mcc_to_bytes(mcc_num, &mcc[0])) { + return SRSLTE_ERROR; + } + return mnc_to_bytes(mnc_num, &mnc[0], &nof_mnc_digits) ? SRSLTE_SUCCESS : SRSLTE_ERROR; +} + +std::string plmn_id_t::to_string() const +{ + std::string mcc_str, mnc_str; + uint16_t mnc_num, mcc_num; + bytes_to_mnc(&mnc[0], &mnc_num, nof_mnc_digits); + bytes_to_mcc(&mcc[0], &mcc_num); + mnc_to_string(mnc_num, &mnc_str); + mcc_to_string(mcc_num, &mcc_str); + return mcc_str + mnc_str; +} + +void s_tmsi_t::from_asn1(const asn1::rrc::s_tmsi_s* asn1_type) +{ + mmec = asn1_type->mmec.to_number(); + m_tmsi = asn1_type->m_tmsi.to_number(); +} + +void s_tmsi_t::to_asn1(asn1::rrc::s_tmsi_s* asn1_type) const +{ + asn1_type->mmec.from_number(mmec); + asn1_type->m_tmsi.from_number(m_tmsi); +} + +static_assert((int)establishment_cause_t::nulltype == (int)asn1::rrc::establishment_cause_opts::nulltype, + "Failed conversion of ASN1 type"); +std::string to_string(const establishment_cause_t& cause) +{ + asn1::rrc::establishment_cause_e asn1_cause((asn1::rrc::establishment_cause_opts::options)cause); + return asn1_cause.to_string(); +} + +} // namespace \ No newline at end of file diff --git a/srsue/hdr/stack/rrc/rrc.h b/srsue/hdr/stack/rrc/rrc.h index c48600782..fc38a822a 100644 --- a/srsue/hdr/stack/rrc/rrc.h +++ b/srsue/hdr/stack/rrc/rrc.h @@ -101,15 +101,14 @@ class cell_t } } - asn1::rrc::plmn_id_s get_plmn(uint32_t idx) + srslte::plmn_id_t get_plmn(uint32_t idx) { if (idx < sib1.cell_access_related_info.plmn_id_list.size() && has_valid_sib1) { - return sib1.cell_access_related_info.plmn_id_list[idx].plmn_id; + srslte::plmn_id_t ret; + ret.from_asn1(&sib1.cell_access_related_info.plmn_id_list[idx].plmn_id); + return ret; } else { - asn1::rrc::plmn_id_s null; - bzero(&null.mcc[0], sizeof(null.mcc)); - bzero(&null.mnc[0], sizeof(null.mnc)); - return null; + return {}; } } @@ -321,9 +320,9 @@ public: uint16_t get_mcc(); uint16_t get_mnc(); int plmn_search(found_plmn_t found_plmns[MAX_FOUND_PLMNS]); - void plmn_select(asn1::rrc::plmn_id_s plmn_id); - bool connection_request(asn1::rrc::establishment_cause_e cause, srslte::unique_byte_buffer_t dedicated_info_nas); - void set_ue_idenity(asn1::rrc::s_tmsi_s s_tmsi); + void plmn_select(srslte::plmn_id_t plmn_id); + bool connection_request(srslte::establishment_cause_t cause, srslte::unique_byte_buffer_t dedicated_info_nas); + void set_ue_identity(srslte::s_tmsi_t s_tmsi); // PHY interface void in_sync(); @@ -386,7 +385,7 @@ private: rrc_state_t state, last_state; uint8_t transaction_id; - asn1::rrc::s_tmsi_s ue_identity; + srslte::s_tmsi_t ue_identity; bool ue_identity_configured; bool drb_up; @@ -619,7 +618,7 @@ private: phy_interface_rrc_lte::cell_search_ret_t cell_search(); - asn1::rrc::plmn_id_s selected_plmn_id; + srslte::plmn_id_t selected_plmn_id; bool plmn_is_selected; bool security_is_activated; diff --git a/srsue/hdr/stack/upper/nas.h b/srsue/hdr/stack/upper/nas.h index 8c2c1e8d3..33cfb7640 100644 --- a/srsue/hdr/stack/upper/nas.h +++ b/srsue/hdr/stack/upper/nas.h @@ -54,7 +54,7 @@ public: // RRC interface void leave_connected(); - void paging(asn1::rrc::s_tmsi_s* ue_identiy); + void paging(srslte::s_tmsi_t* ue_identity); void set_barring(barring_t barring); void write_pdu(uint32_t lcid, srslte::unique_byte_buffer_t pdu); uint32_t get_k_enb_count(); @@ -84,10 +84,10 @@ private: nas_interface_rrc::barring_t current_barring; bool plmn_is_selected; - asn1::rrc::plmn_id_s current_plmn; - asn1::rrc::plmn_id_s home_plmn; + srslte::plmn_id_t current_plmn; + srslte::plmn_id_t home_plmn; - std::vector known_plmns; + std::vector known_plmns; LIBLTE_MME_EMM_INFORMATION_MSG_STRUCT emm_info; diff --git a/srsue/hdr/stack/upper/usim.h b/srsue/hdr/stack/upper/usim.h index d28e1828e..8668cdddf 100644 --- a/srsue/hdr/stack/upper/usim.h +++ b/srsue/hdr/stack/upper/usim.h @@ -45,7 +45,7 @@ public: bool get_imsi_vec(uint8_t* imsi_, uint32_t n); bool get_imei_vec(uint8_t* imei_, uint32_t n); - bool get_home_plmn_id(asn1::rrc::plmn_id_s* home_plmn_id); + bool get_home_plmn_id(srslte::plmn_id_t* home_plmn_id); auth_result_t generate_authentication_response(uint8_t *rand, uint8_t *autn_enb, diff --git a/srsue/hdr/stack/upper/usim_base.h b/srsue/hdr/stack/upper/usim_base.h index b59b655f8..85ff3b891 100644 --- a/srsue/hdr/stack/upper/usim_base.h +++ b/srsue/hdr/stack/upper/usim_base.h @@ -69,7 +69,7 @@ public: virtual bool get_imsi_vec(uint8_t* imsi_, uint32_t n) = 0; virtual bool get_imei_vec(uint8_t* imei_, uint32_t n) = 0; - virtual bool get_home_plmn_id(asn1::rrc::plmn_id_s* home_plmn_id) = 0; + virtual bool get_home_plmn_id(srslte::plmn_id_t* home_plmn_id) = 0; virtual auth_result_t generate_authentication_response(uint8_t *rand, uint8_t *autn_enb, diff --git a/srsue/src/stack/rrc/rrc.cc b/srsue/src/stack/rrc/rrc.cc index c4c690dd7..c841c54e6 100644 --- a/srsue/src/stack/rrc/rrc.cc +++ b/srsue/src/stack/rrc/rrc.cc @@ -403,12 +403,12 @@ int rrc::plmn_search(found_plmn_t found_plmns[MAX_FOUND_PLMNS]) /* This is the NAS interface. When NAS requests to select a PLMN we have to * connect to either register or because there is pending higher layer traffic. */ -void rrc::plmn_select(asn1::rrc::plmn_id_s plmn_id) +void rrc::plmn_select(srslte::plmn_id_t plmn_id) { plmn_is_selected = true; selected_plmn_id = plmn_id; - rrc_log->info("PLMN Selected %s\n", plmn_id_to_string(plmn_id).c_str()); + rrc_log->info("PLMN Selected %s\n", plmn_id.to_string().c_str()); } /* 5.3.3.2 Initiation of RRC Connection Establishment procedure @@ -419,7 +419,7 @@ void rrc::plmn_select(asn1::rrc::plmn_id_s plmn_id) * it. Sends connectionRequest message and returns if message transmitted successfully. * It does not wait until completition of Connection Establishment procedure */ -bool rrc::connection_request(asn1::rrc::establishment_cause_e cause, srslte::unique_byte_buffer_t dedicated_info_nas) +bool rrc::connection_request(srslte::establishment_cause_t cause, srslte::unique_byte_buffer_t dedicated_info_nas) { if (!plmn_is_selected) { @@ -464,7 +464,8 @@ bool rrc::connection_request(asn1::rrc::establishment_cause_e cause, srslte::uni mac_timers->timer_get(t300)->run(); // Send connectionRequest message to lower layers - send_con_request(cause); + establishment_cause_e asn1cause((establishment_cause_e::options)cause); + send_con_request(asn1cause); // Save dedicatedInfoNAS SDU if (this->dedicated_info_nas.get()) { @@ -520,12 +521,12 @@ bool rrc::connection_request(asn1::rrc::establishment_cause_e cause, srslte::uni return ret; } -void rrc::set_ue_idenity(asn1::rrc::s_tmsi_s s_tmsi) +void rrc::set_ue_identity(srslte::s_tmsi_t s_tmsi) { ue_identity_configured = true; ue_identity = s_tmsi; - rrc_log->info("Set ue-Identity to 0x%" PRIu64 ":0x%" PRIu64 "\n", ue_identity.mmec.to_number(), - ue_identity.m_tmsi.to_number()); + rrc_log->info( + "Set ue-Identity to 0x%" PRIu64 ":0x%" PRIu64 "\n", (uint64_t)ue_identity.mmec, (uint64_t)ue_identity.m_tmsi); } /* Retrieves all required SIB or configures them if already retrieved before @@ -1287,7 +1288,7 @@ void rrc::send_con_request(asn1::rrc::establishment_cause_e cause) if (ue_identity_configured) { rrc_conn_req->ue_id.set_s_tmsi(); - rrc_conn_req->ue_id.s_tmsi() = ue_identity; + ue_identity.to_asn1(&rrc_conn_req->ue_id.s_tmsi()); } else { rrc_conn_req->ue_id.set_random_value(); // TODO use proper RNG @@ -2085,17 +2086,19 @@ void rrc::process_pcch(unique_byte_buffer_t pdu) return; } - s_tmsi_s* s_tmsi_paged; for (uint32_t i = 0; i < paging->paging_record_list.size(); i++) { - s_tmsi_paged = &paging->paging_record_list[i].ue_id.s_tmsi(); - rrc_log->info("Received paging (%d/%d) for UE %" PRIu64 ":%" PRIu64 "\n", i + 1, - paging->paging_record_list.size(), paging->paging_record_list[i].ue_id.s_tmsi().mmec.to_number(), - paging->paging_record_list[i].ue_id.s_tmsi().m_tmsi.to_number()); - if (ue_identity.mmec == s_tmsi_paged->mmec && ue_identity.m_tmsi == s_tmsi_paged->m_tmsi) { + s_tmsi_t s_tmsi_paged; + s_tmsi_paged.from_asn1(&paging->paging_record_list[i].ue_id.s_tmsi()); + rrc_log->info("Received paging (%d/%d) for UE %" PRIu64 ":%" PRIu64 "\n", + i + 1, + paging->paging_record_list.size(), + (uint64_t)s_tmsi_paged.mmec, + (uint64_t)s_tmsi_paged.m_tmsi); + if (ue_identity.mmec == s_tmsi_paged.mmec && ue_identity.m_tmsi == s_tmsi_paged.m_tmsi) { if (RRC_STATE_IDLE == state) { rrc_log->info("S-TMSI match in paging message\n"); rrc_log->console("S-TMSI match in paging message\n"); - nas->paging(s_tmsi_paged); + nas->paging(&s_tmsi_paged); } else { rrc_log->warning("Received paging while in CONNECT\n"); } diff --git a/srsue/src/stack/upper/nas.cc b/srsue/src/stack/upper/nas.cc index f92d4e110..36c0b4ee6 100644 --- a/srsue/src/stack/upper/nas.cc +++ b/srsue/src/stack/upper/nas.cc @@ -75,11 +75,7 @@ void nas::init(usim_interface_nas* usim_, rrc_interface_nas* rrc_, gw_interface_ if (!usim->get_home_plmn_id(&home_plmn)) { nas_log->error("Getting Home PLMN Id from USIM. Defaulting to 001-01\n"); - uint16_t mcc = 61441; // This is 001 - uint16_t mnc = 65281; // This is 01 - home_plmn.mcc_present = true; - srslte::mcc_to_bytes(mcc, &home_plmn.mcc[0]); - srslte::mnc_to_bytes(mnc, home_plmn.mnc); + home_plmn.from_number(61441, 65281); // This is 001 01 } // parse and sanity check EIA list @@ -164,10 +160,10 @@ bool nas::attach_request() { known_plmns.clear(); for (int i=0;iinfo("Found PLMN: Id=%s, TAC=%d\n", plmn_id_to_string(found_plmns[i].plmn_id).c_str(), - found_plmns[i].tac); - nas_log->console("Found PLMN: Id=%s, TAC=%d\n", plmn_id_to_string(found_plmns[i].plmn_id).c_str(), - found_plmns[i].tac); + nas_log->info( + "Found PLMN: Id=%s, TAC=%d\n", found_plmns[i].plmn_id.to_string().c_str(), found_plmns[i].tac); + nas_log->console( + "Found PLMN: Id=%s, TAC=%d\n", found_plmns[i].plmn_id.to_string().c_str(), found_plmns[i].tac); } select_plmn(); } else if (nof_plmns == 0) { @@ -242,7 +238,7 @@ bool nas::is_attached() { return state == EMM_STATE_REGISTERED; } -void nas::paging(s_tmsi_s* ue_identiy) +void nas::paging(s_tmsi_t* ue_identity) { if (state == EMM_STATE_REGISTERED) { nas_log->info("Received paging: requesting RRC connection establishment\n"); @@ -283,17 +279,17 @@ bool nas::rrc_connect() { // Provide UE-Identity to RRC if have one if (have_guti) { - s_tmsi_s s_tmsi; - s_tmsi.mmec.from_number(ctxt.guti.mme_code); - s_tmsi.m_tmsi.from_number(ctxt.guti.m_tmsi); - rrc->set_ue_idenity(s_tmsi); + s_tmsi_t s_tmsi; + s_tmsi.m_tmsi = ctxt.guti.m_tmsi; + s_tmsi.mmec = ctxt.guti.mme_code; + rrc->set_ue_identity(s_tmsi); } // Set establishment cause - establishment_cause_e establish_cause = establishment_cause_e::mo_sig; + srslte::establishment_cause_t establish_cause = srslte::establishment_cause_t::mo_sig; if (state == EMM_STATE_REGISTERED) { // FIXME: only need to use MT_ACCESS for establishment after paging - establish_cause = establishment_cause_e::mt_access; + establish_cause = establishment_cause_t::mt_access; } if (rrc->connection_request(establish_cause, std::move(dedicatedInfoNAS))) { @@ -329,7 +325,7 @@ void nas::select_plmn() { // First find if Home PLMN is available for (uint32_t i=0;iinfo("Selecting Home PLMN Id=%s\n", plmn_id_to_string(known_plmns[i]).c_str()); + nas_log->info("Selecting Home PLMN Id=%s\n", known_plmns[i].to_string().c_str()); plmn_is_selected = true; current_plmn = known_plmns[i]; return; @@ -339,12 +335,12 @@ void nas::select_plmn() { // If not, select the first available PLMN if (known_plmns.size() > 0) { nas_log->info("Could not find Home PLMN Id=%s, trying to connect to PLMN Id=%s\n", - plmn_id_to_string(home_plmn).c_str(), - plmn_id_to_string(known_plmns[0]).c_str()); + home_plmn.to_string().c_str(), + known_plmns[0].to_string().c_str()); nas_log->console("Could not find Home PLMN Id=%s, trying to connect to PLMN Id=%s\n", - plmn_id_to_string(home_plmn).c_str(), - plmn_id_to_string(known_plmns[0]).c_str()); + home_plmn.to_string().c_str(), + known_plmns[0].to_string().c_str()); plmn_is_selected = true; current_plmn = known_plmns[0]; } @@ -676,10 +672,10 @@ void nas::parse_attach_accept(uint32_t lcid, unique_byte_buffer_t pdu) memcpy(&ctxt.guti, &attach_accept.guti.guti, sizeof(LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT)); have_guti = true; // Update RRC UE-Idenity - s_tmsi_s s_tmsi; - s_tmsi.mmec.from_number(ctxt.guti.mme_code); - s_tmsi.m_tmsi.from_number(ctxt.guti.m_tmsi); - rrc->set_ue_idenity(s_tmsi); + s_tmsi_t s_tmsi; + s_tmsi.mmec = ctxt.guti.mme_code; + s_tmsi.m_tmsi = ctxt.guti.m_tmsi; + rrc->set_ue_identity(s_tmsi); } if (attach_accept.lai_present) {} if (attach_accept.ms_id_present) {} @@ -1542,7 +1538,7 @@ void nas::send_detach_request(bool switch_off) if (rrc->is_connected()) { rrc->write_sdu(std::move(pdu)); } else { - rrc->connection_request(establishment_cause_e::mo_sig, std::move(pdu)); + rrc->connection_request(establishment_cause_t::mo_sig, std::move(pdu)); } } diff --git a/srsue/src/stack/upper/usim.cc b/srsue/src/stack/upper/usim.cc index e5ddedb25..9f479d9fa 100644 --- a/srsue/src/stack/upper/usim.cc +++ b/srsue/src/stack/upper/usim.cc @@ -153,7 +153,7 @@ bool usim::get_imei_vec(uint8_t* imei_, uint32_t n) return true; } -bool usim::get_home_plmn_id(plmn_id_s* home_plmn_id) +bool usim::get_home_plmn_id(srslte::plmn_id_t* home_plmn_id) { if (!initiated) { ERROR("USIM not initiated!\n"); @@ -185,10 +185,9 @@ bool usim::get_home_plmn_id(plmn_id_s* home_plmn_id) mnc_str << (int) imsi_vec[i]; } - string_to_plmn_id(*home_plmn_id, mcc_str.str() + mnc_str.str()); + home_plmn_id->from_string(mcc_str.str() + mnc_str.str()); - usim_log->info("Read Home PLMN Id=%s\n", - plmn_id_to_string(*home_plmn_id).c_str()); + usim_log->info("Read Home PLMN Id=%s\n", home_plmn_id->to_string().c_str()); return true; } diff --git a/srsue/test/upper/CMakeLists.txt b/srsue/test/upper/CMakeLists.txt index 7d10af05a..b55f424cf 100644 --- a/srsue/test/upper/CMakeLists.txt +++ b/srsue/test/upper/CMakeLists.txt @@ -19,7 +19,7 @@ # add_executable(usim_test usim_test.cc) -target_link_libraries(usim_test srsue_upper srslte_upper srslte_phy) +target_link_libraries(usim_test srsue_upper srslte_upper srslte_phy rrc_asn1) add_test(usim_test usim_test) if(HAVE_PCSC) diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index b1db887cd..d8663ad44 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -97,9 +97,7 @@ class rrc_dummy : public rrc_interface_nas { public: rrc_dummy() : last_sdu_len(0) { - plmns.plmn_id.mcc_present = true; - mcc_to_bytes(mcc, plmns.plmn_id.mcc.data()); - mnc_to_bytes(mnc, plmns.plmn_id.mnc); + plmns.plmn_id.from_number(mcc, mnc); plmns.tac = 0xffff; } void write_sdu(unique_byte_buffer_t sdu) @@ -116,9 +114,9 @@ public: memcpy(found, &plmns, sizeof(found_plmn_t)); return 1; }; - void plmn_select(plmn_id_s plmn_id){}; - void set_ue_idenity(s_tmsi_s s_tmsi) {} - bool connection_request(establishment_cause_e cause, srslte::unique_byte_buffer_t sdu) + void plmn_select(srslte::plmn_id_t plmn_id){}; + void set_ue_identity(srslte::s_tmsi_t s_tmsi) {} + bool connection_request(srslte::establishment_cause_t cause, srslte::unique_byte_buffer_t sdu) { printf("NAS generated SDU (len=%d):\n", sdu->N_bytes); last_sdu_len = sdu->N_bytes;