From f43985b6cd86a9a17a1fa9d6df79ae15394e9f91 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Wed, 13 May 2020 16:23:54 +0100 Subject: [PATCH] small updates for testing handover and configuring the rrc --- lib/include/srslte/common/fsm.h | 9 ++++- .../srslte/interfaces/enb_interfaces.h | 1 + srsenb/hdr/stack/rrc/rrc_bearer_cfg.h | 9 ++++- srsenb/hdr/stack/upper/pdcp.h | 1 + srsenb/src/phy/cc_worker.cc | 1 - srsenb/src/stack/mac/scheduler_ue.cc | 2 +- srsenb/src/stack/rrc/rrc_bearer_cfg.cc | 40 +++++++++++++++---- srsenb/src/stack/upper/pdcp.cc | 10 ++++- srsenb/test/common/dummy_classes.h | 1 + srsenb/test/upper/test_helpers.h | 7 ++++ 10 files changed, 67 insertions(+), 14 deletions(-) diff --git a/lib/include/srslte/common/fsm.h b/lib/include/srslte/common/fsm.h index 54efb4aed..6ccbe1133 100644 --- a/lib/include/srslte/common/fsm.h +++ b/lib/include/srslte/common/fsm.h @@ -103,13 +103,13 @@ auto call_enter(FSM* f, State* s) -> decltype(s->enter(f)) { s->enter(f); } -void call_enter(...) {} +inline void call_enter(...) {} template auto call_exit(FSM* f, State* s) -> decltype(s->exit(f)) { s->exit(f); } -void call_exit(...) {} +inline void call_exit(...) {} //! Find State in FSM recursively (e.g. find State in FSM,FSM::parentFSM,FSM::parentFSM::parentFSM,...) template @@ -604,6 +604,11 @@ private: int launch_counter = 0; }; +// Generic events + +struct success_ev {}; +struct failure_ev {}; + } // namespace srslte #endif // SRSLTE_FSM_H diff --git a/lib/include/srslte/interfaces/enb_interfaces.h b/lib/include/srslte/interfaces/enb_interfaces.h index 5a1193e1a..851ffbdc6 100644 --- a/lib/include/srslte/interfaces/enb_interfaces.h +++ b/lib/include/srslte/interfaces/enb_interfaces.h @@ -369,6 +369,7 @@ public: virtual void rem_user(uint16_t rnti) = 0; virtual void write_sdu(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer_t sdu) = 0; virtual void add_bearer(uint16_t rnti, uint32_t lcid, srslte::pdcp_config_t cnfg) = 0; + virtual void del_bearer(uint16_t rnti, uint32_t lcid) = 0; virtual void config_security(uint16_t rnti, uint32_t lcid, srslte::as_security_config_t sec_cfg) = 0; virtual void enable_integrity(uint16_t rnti, uint32_t lcid) = 0; virtual void enable_encryption(uint16_t rnti, uint32_t lcid) = 0; diff --git a/srsenb/hdr/stack/rrc/rrc_bearer_cfg.h b/srsenb/hdr/stack/rrc/rrc_bearer_cfg.h index eaef47334..5f8c44181 100644 --- a/srsenb/hdr/stack/rrc/rrc_bearer_cfg.h +++ b/srsenb/hdr/stack/rrc/rrc_bearer_cfg.h @@ -36,13 +36,18 @@ public: bool set_security_capabilities(const asn1::s1ap::ue_security_cap_s& caps); void set_security_key(const asn1::fixed_bitstring<256, false, true>& key); + void regenerate_keys_handover(uint32_t new_pci, uint32_t new_dl_earfcn); asn1::rrc::security_algorithm_cfg_s get_security_algorithm_cfg(); const srslte::as_security_config_t& get_as_sec_cfg() const { return sec_cfg; } + bool is_as_sec_cfg_valid() const { return k_enb_present; } private: + void generate_as_keys(); + srslte::log_ref log_h{"RRC"}; const rrc_cfg_t* cfg; + bool k_enb_present = false; asn1::s1ap::ue_security_cap_s security_capabilities; uint8_t k_enb[32] = {}; // Provided by MME srslte::as_security_config_t sec_cfg = {}; @@ -69,6 +74,7 @@ public: const asn1::unbounded_octstring* nas_pdu); void release_erab(uint8_t erab_id); void release_erabs(); + void reest_bearers(); bool fill_rr_cfg_ded(asn1::rrc::rr_cfg_ded_s& msg); void rr_ded_cfg_complete(); @@ -79,7 +85,8 @@ public: void apply_rlc_bearer_updates(rlc_interface_rrc* rlc); void fill_pending_nas_info(asn1::rrc::rrc_conn_recfg_r8_ies_s* msg); - const std::map& get_erabs() const { return erabs; } + const std::map& get_erabs() const { return erabs; } + const asn1::rrc::drb_to_add_mod_list_l& established_drbs() const { return last_drbs; } private: srslte::log_ref log_h{"RRC"}; diff --git a/srsenb/hdr/stack/upper/pdcp.h b/srsenb/hdr/stack/upper/pdcp.h index c55e7acbb..33e360359 100644 --- a/srsenb/hdr/stack/upper/pdcp.h +++ b/srsenb/hdr/stack/upper/pdcp.h @@ -48,6 +48,7 @@ public: void rem_user(uint16_t rnti) override; void write_sdu(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer_t sdu) override; void add_bearer(uint16_t rnti, uint32_t lcid, srslte::pdcp_config_t cnfg) override; + void del_bearer(uint16_t rnti, uint32_t lcid) override; void config_security(uint16_t rnti, uint32_t lcid, srslte::as_security_config_t cfg_sec) override; void enable_integrity(uint16_t rnti, uint32_t lcid) override; void enable_encryption(uint16_t rnti, uint32_t lcid) override; diff --git a/srsenb/src/phy/cc_worker.cc b/srsenb/src/phy/cc_worker.cc index 74fa81cfc..a6b9d51d9 100644 --- a/srsenb/src/phy/cc_worker.cc +++ b/srsenb/src/phy/cc_worker.cc @@ -206,7 +206,6 @@ void cc_worker::rem_rnti(uint16_t rnti) { std::lock_guard lock(mutex); if (ue_db.count(rnti)) { - delete ue_db[rnti]; ue_db.erase(rnti); diff --git a/srsenb/src/stack/mac/scheduler_ue.cc b/srsenb/src/stack/mac/scheduler_ue.cc index b2a25f87b..96e6cd6eb 100644 --- a/srsenb/src/stack/mac/scheduler_ue.cc +++ b/srsenb/src/stack/mac/scheduler_ue.cc @@ -140,7 +140,7 @@ void sched_ue::set_cfg(const sched_interface::ue_cfg_t& cfg_) // One carrier was added in the place of another carriers[ue_idx] = sched_ue_carrier{cfg, (*cell_params_list)[cc_cfg.enb_cc_idx], rnti, ue_idx}; if (ue_idx == 0) { - log_h->info("SCHED: PCell has changed for rnti=0x%x.\n", rnti); + log_h->info("SCHED: rnti=0x%x PCell is now %d.\n", rnti, cc_cfg.enb_cc_idx); } } else { // The SCell internal configuration may have changed diff --git a/srsenb/src/stack/rrc/rrc_bearer_cfg.cc b/srsenb/src/stack/rrc/rrc_bearer_cfg.cc index 704f7950b..f47eb48c7 100644 --- a/srsenb/src/stack/rrc/rrc_bearer_cfg.cc +++ b/srsenb/src/stack/rrc/rrc_bearer_cfg.cc @@ -167,11 +167,17 @@ bool security_cfg_handler::set_security_capabilities(const asn1::s1ap::ue_securi void security_cfg_handler::set_security_key(const asn1::fixed_bitstring<256, false, true>& key) { + k_enb_present = true; for (uint32_t i = 0; i < key.nof_octets(); ++i) { k_enb[i] = key.data()[key.nof_octets() - 1 - i]; } log_h->info_hex(k_enb, 32, "Key eNodeB (k_enb)"); + generate_as_keys(); +} + +void security_cfg_handler::generate_as_keys() +{ log_h->info("Selected security algorithms EEA: EEA%d EIA: EIA%d\n", sec_cfg.cipher_algo, sec_cfg.integ_algo); // Generate K_rrc_enc and K_rrc_int @@ -187,6 +193,18 @@ void security_cfg_handler::set_security_key(const asn1::fixed_bitstring<256, fal log_h->info_hex(sec_cfg.k_up_enc.data(), 32, "UP Encryption Key (k_up_enc)"); } +void security_cfg_handler::regenerate_keys_handover(uint32_t new_pci, uint32_t new_dl_earfcn) +{ + // Generate K_enb* + uint8_t k_enb_star[32]; + srslte::security_generate_k_enb_star(k_enb, new_pci, new_dl_earfcn, k_enb_star); + + // K_enb becomes K_enb* + memcpy(k_enb, k_enb_star, 32); + + generate_as_keys(); +} + /***************************** * Bearer Handler ****************************/ @@ -295,6 +313,13 @@ void bearer_cfg_handler::release_erabs() } } +void bearer_cfg_handler::reest_bearers() +{ + // Re-add all SRBs/DRBs + srbs_to_add = last_srbs; + drbs_to_add = last_drbs; +} + void bearer_cfg_handler::rr_ded_cfg_complete() { // Apply changes in internal bearer_handler DRB/SRBtoAddModLists @@ -347,17 +372,16 @@ void bearer_cfg_handler::apply_pdcp_bearer_updates(pdcp_interface_rrc* pdcp, con pdcp->add_bearer(rnti, srb.srb_id, srslte::make_srb_pdcp_config_t(srb.srb_id, false)); // For SRB2, enable security/encryption/integrity - if (srb.srb_id > 1) { + if (ue_sec_cfg.is_as_sec_cfg_valid()) { pdcp->config_security(rnti, srb.srb_id, ue_sec_cfg.get_as_sec_cfg()); pdcp->enable_integrity(rnti, srb.srb_id); pdcp->enable_encryption(rnti, srb.srb_id); } } - if (drbs_to_release.size() > 0) { - log_h->warning("Removing DRBs not currently supported\n"); + for (uint8_t drb_id : drbs_to_release) { + pdcp->del_bearer(rnti, drb_id + 2); } - for (const drb_to_add_mod_s& drb : drbs_to_add) { // Configure DRB1 in PDCP if (drb.pdcp_cfg_present) { @@ -368,9 +392,11 @@ void bearer_cfg_handler::apply_pdcp_bearer_updates(pdcp_interface_rrc* pdcp, con pdcp->add_bearer(rnti, drb.lc_ch_id, pdcp_cnfg_drb); } - pdcp->config_security(rnti, drb.lc_ch_id, ue_sec_cfg.get_as_sec_cfg()); - pdcp->enable_integrity(rnti, drb.lc_ch_id); - pdcp->enable_encryption(rnti, drb.lc_ch_id); + if (ue_sec_cfg.is_as_sec_cfg_valid()) { + pdcp->config_security(rnti, drb.lc_ch_id, ue_sec_cfg.get_as_sec_cfg()); + pdcp->enable_integrity(rnti, drb.lc_ch_id); + pdcp->enable_encryption(rnti, drb.lc_ch_id); + } } } diff --git a/srsenb/src/stack/upper/pdcp.cc b/srsenb/src/stack/upper/pdcp.cc index bf9a942bb..56f69cf95 100644 --- a/srsenb/src/stack/upper/pdcp.cc +++ b/srsenb/src/stack/upper/pdcp.cc @@ -28,8 +28,7 @@ pdcp::pdcp(srslte::task_handler_interface* task_executor_, const char* logname) task_executor(task_executor_), log_h(logname), pool(srslte::byte_buffer_pool::get_instance()) -{ -} +{} void pdcp::init(rlc_interface_pdcp* rlc_, rrc_interface_pdcp* rrc_, gtpu_interface_pdcp* gtpu_) { @@ -89,6 +88,13 @@ void pdcp::add_bearer(uint16_t rnti, uint32_t lcid, srslte::pdcp_config_t cfg) } } +void pdcp::del_bearer(uint16_t rnti, uint32_t lcid) +{ + if (users.count(rnti)) { + users[rnti].pdcp->del_bearer(lcid); + } +} + void pdcp::reset(uint16_t rnti) { if (users.count(rnti)) { diff --git a/srsenb/test/common/dummy_classes.h b/srsenb/test/common/dummy_classes.h index a8b997c97..0f7b7f2a0 100644 --- a/srsenb/test/common/dummy_classes.h +++ b/srsenb/test/common/dummy_classes.h @@ -66,6 +66,7 @@ public: void rem_user(uint16_t rnti) override {} void write_sdu(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer_t sdu) override {} void add_bearer(uint16_t rnti, uint32_t lcid, srslte::pdcp_config_t cnfg) override {} + void del_bearer(uint16_t rnti, uint32_t lcid) override {} void config_security(uint16_t rnti, uint32_t lcid, srslte::as_security_config_t sec_cfg_) override {} void enable_integrity(uint16_t rnti, uint32_t lcid) override {} void enable_encryption(uint16_t rnti, uint32_t lcid) override {} diff --git a/srsenb/test/upper/test_helpers.h b/srsenb/test/upper/test_helpers.h index 5dc5eb7b8..499ed8da2 100644 --- a/srsenb/test/upper/test_helpers.h +++ b/srsenb/test/upper/test_helpers.h @@ -76,6 +76,7 @@ public: srslte::unique_byte_buffer_t rrc_container; } last_ho_required = {}; struct enb_status_transfer_info { + bool status_present; uint16_t rnti; std::vector bearer_list; } last_enb_status = {}; @@ -89,6 +90,11 @@ public: last_ho_required = ho_req_data{rnti, target_eci, target_plmn, std::move(rrc_container)}; return true; } + bool send_enb_status_transfer_proc(uint16_t rnti, std::vector& bearer_status_list) override + { + last_enb_status = {true, rnti, bearer_status_list}; + return true; + } void ue_erab_setup_complete(uint16_t rnti, const asn1::s1ap::erab_setup_resp_s& res) override { if (res.protocol_ies.erab_setup_list_bearer_su_res_present) { @@ -129,6 +135,7 @@ int parse_default_cfg(rrc_cfg_t* rrc_cfg, srsenb::all_args_t& args) args.enb_files.drb_config = argparse::repository_dir + "/drb.conf.example"; srslte::logmap::get("TEST")->debug("sib file path=%s\n", args.enb_files.sib_config.c_str()); + args.enb.enb_id = 0x19B; args.enb.dl_earfcn = 3400; args.enb.n_prb = 50; TESTASSERT(srslte::string_to_mcc("001", &args.stack.s1ap.mcc));