pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30972 )
Change subject: layer23: Move '(no) shutdown' VTY code to common/vty.c ......................................................................
layer23: Move '(no) shutdown' VTY code to common/vty.c
Change-Id: Ib5c9b6f3efa255d67980945db9f98dd8a112af0e --- A doc/examples/modem/modem.cfg M src/host/layer23/include/osmocom/bb/common/osmocom_data.h M src/host/layer23/include/osmocom/bb/common/vty.h M src/host/layer23/src/common/vty.c M src/host/layer23/src/mobile/vty_interface.c M src/host/layer23/src/modem/vty.c 6 files changed, 151 insertions(+), 61 deletions(-)
Approvals: laforge: Looks good to me, but someone else must approve pespin: Looks good to me, approved osmith: Looks good to me, but someone else must approve Jenkins Builder: Verified
diff --git a/doc/examples/modem/modem.cfg b/doc/examples/modem/modem.cfg new file mode 100644 index 0000000..d2cb81f --- /dev/null +++ b/doc/examples/modem/modem.cfg @@ -0,0 +1,9 @@ +! +! OsmocomBB example configuration for modem application +!! +! +line vty + no login +! +ms 1 + no shutdown diff --git a/src/host/layer23/include/osmocom/bb/common/osmocom_data.h b/src/host/layer23/include/osmocom/bb/common/osmocom_data.h index d78edc3..600c412 100644 --- a/src/host/layer23/include/osmocom/bb/common/osmocom_data.h +++ b/src/host/layer23/include/osmocom/bb/common/osmocom_data.h @@ -1,13 +1,16 @@ #pragma once
#include <stdint.h> +#include <stdbool.h>
struct osmocom_ms; struct gapk_io_state; +struct vty;
enum osmobb_sig_subsys { SS_L1CTL, SS_GLOBAL, + SS_L23_VTY, };
enum osmobb_l1ctl_sig { @@ -26,6 +29,26 @@ S_GLOBAL_SHUTDOWN, };
+enum osmobb_l23_vty_sig { + S_L23_VTY_MS_START, + S_L23_VTY_MS_STOP, +}; + +struct osmobb_l23_vty_sig_data { + struct vty *vty; + union { + struct { + struct osmocom_ms *ms; + int rc; /* CMD_SUCCESS/CMD_WARNING */ + } ms_start; + struct { + struct osmocom_ms *ms; + bool force; + int rc; /* CMD_SUCCESS/CMD_WARNING */ + } ms_stop; + }; +}; + struct osmobb_fbsb_res { struct osmocom_ms *ms; int8_t snr; diff --git a/src/host/layer23/include/osmocom/bb/common/vty.h b/src/host/layer23/include/osmocom/bb/common/vty.h index dd5e7f2..f345260 100644 --- a/src/host/layer23/include/osmocom/bb/common/vty.h +++ b/src/host/layer23/include/osmocom/bb/common/vty.h @@ -4,6 +4,7 @@ #include <osmocom/vty/vty.h> #include <osmocom/vty/buffer.h> #include <osmocom/vty/command.h> +#include <osmocom/core/signal.h>
struct osmocom_ms;
@@ -12,13 +13,13 @@ _LAST_L23VTY_NODE, };
-int l23_vty_init(int (*config_write_ms_node_cb)(struct vty *)); +int l23_vty_init(int (*config_write_ms_node_cb)(struct vty *), osmo_signal_cbfn *l23_vty_signal_cb);
struct osmocom_ms *l23_vty_get_ms(const char *name, struct vty *vty); void l23_ms_dump(struct osmocom_ms *ms, struct vty *vty); void l23_vty_config_write_ms_node(struct vty *vty, const struct osmocom_ms *ms, const char *prefix); void l23_vty_config_write_ms_node_contents(struct vty *vty, const struct osmocom_ms *ms, const char *prefix); - +void l23_vty_config_write_ms_node_contents_final(struct vty *vty, const struct osmocom_ms *ms, const char *prefix); extern struct llist_head ms_list;
extern struct cmd_element l23_show_ms_cmd; diff --git a/src/host/layer23/src/common/vty.c b/src/host/layer23/src/common/vty.c index 34d39b0..a7b65b3 100644 --- a/src/host/layer23/src/common/vty.c +++ b/src/host/layer23/src/common/vty.c @@ -152,6 +152,56 @@ return CMD_WARNING; }
+DEFUN(cfg_ms_no_shutdown, cfg_ms_no_shutdown_cmd, "no shutdown", + NO_STR "Activate and run MS") +{ + struct osmocom_ms *ms = vty->index; + + struct osmobb_l23_vty_sig_data data; + memset(&data, 0, sizeof(data)); + + data.vty = vty; + data.ms_start.ms = ms; + data.ms_start.rc = CMD_SUCCESS; + osmo_signal_dispatch(SS_L23_VTY, S_L23_VTY_MS_START, &data); + + return data.ms_start.rc; +} + +DEFUN(cfg_ms_shutdown, cfg_ms_shutdown_cmd, "shutdown", + "Shut down and deactivate MS") +{ + struct osmocom_ms *ms = vty->index; + + struct osmobb_l23_vty_sig_data data; + memset(&data, 0, sizeof(data)); + + data.vty = vty; + data.ms_stop.ms = ms; + data.ms_stop.force = false; + data.ms_stop.rc = CMD_SUCCESS; + osmo_signal_dispatch(SS_L23_VTY, S_L23_VTY_MS_STOP, &data); + + return data.ms_stop.rc; +} + +DEFUN(cfg_ms_shutdown_force, cfg_ms_shutdown_force_cmd, "shutdown force", + "Shut down and deactivate MS\nDo not perform IMSI detach") +{ + struct osmocom_ms *ms = vty->index; + + struct osmobb_l23_vty_sig_data data; + memset(&data, 0, sizeof(data)); + + data.vty = vty; + data.ms_stop.ms = ms; + data.ms_stop.force = true; + data.ms_stop.rc = CMD_SUCCESS; + osmo_signal_dispatch(SS_L23_VTY, S_L23_VTY_MS_STOP, &data); + + return data.ms_stop.rc; +} + void l23_vty_config_write_ms_node(struct vty *vty, const struct osmocom_ms *ms, const char *prefix) { size_t prefix_len = strlen(prefix); @@ -163,6 +213,7 @@
vty_out(vty, "%sms %s%s", prefix, ms->name, VTY_NEWLINE); l23_vty_config_write_ms_node_contents(vty, ms, prefix_content); + l23_vty_config_write_ms_node_contents_final(vty, ms, prefix_content); }
void l23_vty_config_write_ms_node_contents(struct vty *vty, const struct osmocom_ms *ms, const char *prefix) @@ -170,13 +221,27 @@ /* placeholder for shared VTY commands */ }
-int l23_vty_init(int (*config_write_ms_node_cb)(struct vty *)) +/* placeholder for shared VTY commands. Must be put at the end of the node: */ +void l23_vty_config_write_ms_node_contents_final(struct vty *vty, const struct osmocom_ms *ms, const char *prefix) { + /* no shutdown must be written to config, because shutdown is default */ + vty_out(vty, "%s%sshutdown%s", prefix, (ms->shutdown != MS_SHUTDOWN_NONE) ? "" : "no ", + VTY_NEWLINE); + vty_out(vty, "!%s", VTY_NEWLINE); +} + +int l23_vty_init(int (*config_write_ms_node_cb)(struct vty *), osmo_signal_cbfn *l23_vty_signal_cb) +{ + int rc = 0; install_node(&ms_node, config_write_ms_node_cb); + install_element(MS_NODE, &cfg_ms_shutdown_cmd); + install_element(MS_NODE, &cfg_ms_shutdown_force_cmd); + install_element(MS_NODE, &cfg_ms_no_shutdown_cmd);
/* Register the talloc context introspection command */ osmo_talloc_vty_add_cmds(); - - return 0; + if (l23_vty_signal_cb) + rc = osmo_signal_register_handler(SS_L23_VTY, l23_vty_signal_cb, NULL); + return rc; }
diff --git a/src/host/layer23/src/mobile/vty_interface.c b/src/host/layer23/src/mobile/vty_interface.c index 39a64fd..ae0e95e 100644 --- a/src/host/layer23/src/mobile/vty_interface.c +++ b/src/host/layer23/src/mobile/vty_interface.c @@ -1533,12 +1533,10 @@ set->audio.alsa_input_dev, VTY_NEWLINE); }
- /* no shutdown must be written to config, because shutdown is default */ - vty_out(vty, " %sshutdown%s", (ms->shutdown != MS_SHUTDOWN_NONE) ? "" : "no ", - VTY_NEWLINE); if (ms->lua_script) vty_out(vty, " lua-script %s%s", ms->lua_script, VTY_NEWLINE); - vty_out(vty, "!%s", VTY_NEWLINE); + + l23_vty_config_write_ms_node_contents_final(vty, ms, " "); }
static int config_write(struct vty *vty) @@ -2902,53 +2900,6 @@ return CMD_SUCCESS; }
-DEFUN(cfg_no_shutdown, cfg_ms_no_shutdown_cmd, "no shutdown", - NO_STR "Activate and run MS") -{ - struct osmocom_ms *ms = vty->index; - char *other_name = NULL; - int rc; - - rc = mobile_start(ms, &other_name); - switch (rc) { - case -1: - vty_out(vty, "Cannot start MS '%s', because MS '%s' " - "use the same layer2-socket.%sPlease shutdown " - "MS '%s' first.%s", ms->name, other_name, - VTY_NEWLINE, other_name, VTY_NEWLINE); - return CMD_WARNING; - case -2: - vty_out(vty, "Cannot start MS '%s', because MS '%s' " - "use the same sap-socket.%sPlease shutdown " - "MS '%s' first.%s", ms->name, other_name, - VTY_NEWLINE, other_name, VTY_NEWLINE); - return CMD_WARNING; - case -3: - vty_out(vty, "Connection to layer 1 failed!%s", - VTY_NEWLINE); - return CMD_WARNING; - } - - return CMD_SUCCESS; -} - -DEFUN(cfg_shutdown, cfg_ms_shutdown_cmd, "shutdown", - "Shut down and deactivate MS") -{ - struct osmocom_ms *ms = vty->index; - mobile_stop(ms, 0); - return CMD_SUCCESS; -} - -DEFUN(cfg_shutdown_force, cfg_ms_shutdown_force_cmd, "shutdown force", - "Shut down and deactivate MS\nDo not perform IMSI detach") -{ - struct osmocom_ms *ms = vty->index; - - mobile_stop(ms, 1); - return CMD_SUCCESS; -} - DEFUN(cfg_ms_script_load_run, cfg_ms_script_load_run_cmd, "lua-script FILENAME", "Load and execute a LUA script\nFilename for lua script") { @@ -2981,6 +2932,50 @@ return CMD_SUCCESS; }
+/* run ms instance, if layer1 is available */ +static int l23_vty_signal_cb(unsigned int subsys, unsigned int signal, + void *handler_data, void *signal_data) +{ + struct osmobb_l23_vty_sig_data *d = signal_data; + struct vty *vty = d->vty; + char *other_name = NULL; + int rc; + + if (subsys != SS_L23_VTY) + return 0; + + switch (signal) { + case S_L23_VTY_MS_START: + rc = mobile_start(d->ms_start.ms, &other_name); + switch (rc) { + case -1: + vty_out(vty, "Cannot start MS '%s', because MS '%s' " + "use the same layer2-socket.%sPlease shutdown " + "MS '%s' first.%s", d->ms_start.ms->name, other_name, + VTY_NEWLINE, other_name, VTY_NEWLINE); + break; + case -2: + vty_out(vty, "Cannot start MS '%s', because MS '%s' " + "use the same sap-socket.%sPlease shutdown " + "MS '%s' first.%s", d->ms_start.ms->name, other_name, + VTY_NEWLINE, other_name, VTY_NEWLINE); + break; + case -3: + vty_out(vty, "Connection to layer 1 failed!%s", + VTY_NEWLINE); + break; + } + d->ms_start.rc = (rc == 0) ? CMD_SUCCESS : CMD_WARNING; + break; + case S_L23_VTY_MS_STOP: + mobile_stop(d->ms_stop.ms, d->ms_stop.force); + d->ms_start.rc = CMD_SUCCESS; + break; + } + return 0; +} + + #define SUP_NODE(item) \ install_element(SUPPORT_NODE, &cfg_ms_sup_item_cmd);
@@ -2988,7 +2983,7 @@ { int rc;
- if ((rc = l23_vty_init(config_write)) < 0) + if ((rc = l23_vty_init(config_write, l23_vty_signal_cb)) < 0) return rc;
install_element_ve(&show_ms_cmd); @@ -3156,9 +3151,6 @@ install_element(TESTSIM_NODE, &cfg_test_rplmn_cmd); install_element(TESTSIM_NODE, &cfg_test_rplmn_att_cmd); install_element(TESTSIM_NODE, &cfg_test_hplmn_cmd); - install_element(MS_NODE, &cfg_ms_shutdown_cmd); - install_element(MS_NODE, &cfg_ms_shutdown_force_cmd); - install_element(MS_NODE, &cfg_ms_no_shutdown_cmd); install_element(MS_NODE, &cfg_ms_script_load_run_cmd); install_element(MS_NODE, &cfg_ms_no_script_load_run_cmd);
diff --git a/src/host/layer23/src/modem/vty.c b/src/host/layer23/src/modem/vty.c index 2320efc..4304876 100644 --- a/src/host/layer23/src/modem/vty.c +++ b/src/host/layer23/src/modem/vty.c @@ -40,7 +40,7 @@ { int rc;
- if ((rc = l23_vty_init(config_write)) < 0) + if ((rc = l23_vty_init(config_write, NULL)) < 0) return rc; install_element_ve(&l23_show_ms_cmd); install_element(CONFIG_NODE, &l23_cfg_ms_cmd);