From 3f102247293db603704ce0feecdfd4cef764c85b Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 20 Mar 2020 20:47:58 +0100 Subject: [PATCH] refactor airplane mode simulation and move to NAS - move handling to NAS - use switch off to enable airplane mode (don't wait for EPC response) - add tiny FSM to control airplane mode activation/deactivation - only start on/off counter after state has been entered --- srsue/hdr/stack/ue_stack_base.h | 6 ----- srsue/hdr/stack/ue_stack_lte.h | 1 + srsue/hdr/stack/upper/nas.h | 5 +++++ srsue/hdr/stack/upper/nas_common.h | 20 +++++++++++------ srsue/src/main.cc | 4 ++-- srsue/src/stack/ue_stack_lte.cc | 19 +--------------- srsue/src/stack/upper/nas.cc | 36 ++++++++++++++++++++++++++++++ 7 files changed, 58 insertions(+), 33 deletions(-) diff --git a/srsue/hdr/stack/ue_stack_base.h b/srsue/hdr/stack/ue_stack_base.h index 8fb2bef09..e402403d7 100644 --- a/srsue/hdr/stack/ue_stack_base.h +++ b/srsue/hdr/stack/ue_stack_base.h @@ -57,11 +57,6 @@ typedef struct { int usim_hex_limit; } stack_log_args_t; -typedef struct { - int airplane_t_on_ms; - int airplane_t_off_ms; -} ue_sim_args_t; - typedef struct { std::string type; pcap_args_t pcap; @@ -72,7 +67,6 @@ typedef struct { nas_args_t nas; gw_args_t gw; bool have_tti_time_stats; - ue_sim_args_t sim; } stack_args_t; class ue_stack_base diff --git a/srsue/hdr/stack/ue_stack_lte.h b/srsue/hdr/stack/ue_stack_lte.h index 0c6694e8b..573d6e8e8 100644 --- a/srsue/hdr/stack/ue_stack_lte.h +++ b/srsue/hdr/stack/ue_stack_lte.h @@ -141,6 +141,7 @@ private: bool running; srsue::stack_args_t args; + srslte::tti_point current_tti; // timers diff --git a/srsue/hdr/stack/upper/nas.h b/srsue/hdr/stack/upper/nas.h index 204a05606..3951ff3b2 100644 --- a/srsue/hdr/stack/upper/nas.h +++ b/srsue/hdr/stack/upper/nas.h @@ -152,6 +152,10 @@ private: uint8_t k_nas_enc[32] = {}; uint8_t k_nas_int[32] = {}; + // Airplane mode simulation + typedef enum { DISABLED = 0, ENABLED } airplane_mode_state_t; + airplane_mode_state_t airplane_mode_state = {}; + // PCAP srslte::nas_pcap* pcap = nullptr; @@ -209,6 +213,7 @@ private: void send_activate_test_mode_complete(const uint8_t sec_hdr_type); // Other internal helpers + void handle_airplane_mode_sim(); void enter_emm_deregistered(); // security context persistence file diff --git a/srsue/hdr/stack/upper/nas_common.h b/srsue/hdr/stack/upper/nas_common.h index f603c1d0d..c15b7ed80 100644 --- a/srsue/hdr/stack/upper/nas_common.h +++ b/srsue/hdr/stack/upper/nas_common.h @@ -24,18 +24,24 @@ namespace srsue { +typedef struct { + int airplane_t_on_ms; + int airplane_t_off_ms; +} nas_sim_args_t; + class nas_args_t { public: nas_args_t() : force_imsi_attach(false) {} - std::string apn_name; - std::string apn_protocol; - std::string apn_user; - std::string apn_pass; - bool force_imsi_attach; - std::string eia; - std::string eea; + std::string apn_name; + std::string apn_protocol; + std::string apn_user; + std::string apn_pass; + bool force_imsi_attach; + std::string eia; + std::string eea; + nas_sim_args_t sim; }; // EMM states (3GPP 24.302 v10.0.0) diff --git a/srsue/src/main.cc b/srsue/src/main.cc index b9edb1f14..3fa71f023 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -370,11 +370,11 @@ static int parse_args(all_args_t* args, int argc, char* argv[]) // UE simulation args ("sim.airplane_t_on_ms", - bpo::value(&args->stack.sim.airplane_t_on_ms)->default_value(-1), + bpo::value(&args->stack.nas.sim.airplane_t_on_ms)->default_value(-1), "On-time for airplane mode (in ms)") ("sim.airplane_t_off_ms", - bpo::value(&args->stack.sim.airplane_t_off_ms)->default_value(-1), + bpo::value(&args->stack.nas.sim.airplane_t_off_ms)->default_value(-1), "Off-time for airplane mode (in ms)") /* general options */ diff --git a/srsue/src/stack/ue_stack_lte.cc b/srsue/src/stack/ue_stack_lte.cc index 1dec0b855..0cb7419a3 100644 --- a/srsue/src/stack/ue_stack_lte.cc +++ b/srsue/src/stack/ue_stack_lte.cc @@ -176,14 +176,6 @@ bool ue_stack_lte::switch_on() if (running) { pending_tasks.try_push(ue_queue_id, [this]() { nas.start_attach_request(nullptr, srslte::establishment_cause_t::mo_sig); }); - - // schedule airplane mode on command - if (args.sim.airplane_t_on_ms > 0) { - timers.defer_callback(args.sim.airplane_t_on_ms, [&]() { - // Enable air-plane mode - disable_data(); - }); - } return true; } return false; @@ -221,16 +213,7 @@ bool ue_stack_lte::disable_data() { // generate detach request stack_log->console("Turning on airplane mode.\n"); - int ret = nas.detach_request(false); - - // schedule airplane mode off command - if (args.sim.airplane_t_off_ms > 0) { - timers.defer_callback(args.sim.airplane_t_off_ms, [&]() { - // Disable airplane mode again - enable_data(); - }); - } - return ret; + return nas.detach_request(false); } bool ue_stack_lte::get_metrics(stack_metrics_t* metrics) diff --git a/srsue/src/stack/upper/nas.cc b/srsue/src/stack/upper/nas.cc index 6dccee1ff..1748c00ab 100644 --- a/srsue/src/stack/upper/nas.cc +++ b/srsue/src/stack/upper/nas.cc @@ -302,6 +302,8 @@ void nas::init(usim_interface_nas* usim_, rrc_interface_nas* rrc_, gw_interface_ t3421.set(t3421_duration_ms, [this](uint32_t tid) { timer_expired(tid); }); reattach_timer.set(reattach_timer_duration_ms, [this](uint32_t tid) { timer_expired(tid); }); + handle_airplane_mode_sim(); + running = true; } @@ -2323,6 +2325,40 @@ void nas::send_activate_test_mode_complete(const uint8_t sec_hdr_type) ctxt.tx_count++; } +/* + * Handles the airplane mode simulation by triggering a UE switch off/on + * in user-definable time intervals + */ +void nas::handle_airplane_mode_sim() +{ + if (cfg.sim.airplane_t_on_ms > 0 && airplane_mode_state == DISABLED) { + // check if we're already attached, if so, schedule airplane mode command + if (state == EMM_STATE_REGISTERED) { + // NAS is attached + task_handler->defer_callback(cfg.sim.airplane_t_on_ms, [&]() { + // Enabling air-plane mode + send_detach_request(true); + airplane_mode_state = ENABLED; + }); + } + } else if (cfg.sim.airplane_t_off_ms > 0 && airplane_mode_state == ENABLED) { + // check if we are already deregistered, if so, schedule command to turn off airplone mode again + if (state == EMM_STATE_DEREGISTERED) { + // NAS is deregistered + task_handler->defer_callback(cfg.sim.airplane_t_off_ms, [&]() { + // Disabling airplane mode again + start_attach_request(nullptr, srslte::establishment_cause_t::mo_sig); + airplane_mode_state = DISABLED; + }); + } + } + + // schedule another call + if (cfg.sim.airplane_t_on_ms > 0 || cfg.sim.airplane_t_off_ms > 0) { + task_handler->defer_callback(1000, [&]() { handle_airplane_mode_sim(); }); + } +} + /******************************************************************************* * Security context persistence file ******************************************************************************/