pespin has uploaded this change for review. ( 
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, 152 insertions(+), 62 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/72/30972/1

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..86351a5 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,24 @@
        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;
+       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 815f1f2..4aeb6cb 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;

@@ -13,13 +14,13 @@
 };

 int l23_vty_go_parent(struct vty *vty);
-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, struct osmocom_ms *ms, 
const char *prefix);
 void l23_vty_config_write_ms_node_contents(struct vty *vty, struct osmocom_ms 
*ms, const char *prefix);
-
+void l23_vty_config_write_ms_node_contents_final(struct vty *vty, 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 46606c7..2d71c53 100644
--- a/src/host/layer23/src/common/vty.c
+++ b/src/host/layer23/src/common/vty.c
@@ -151,6 +151,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, struct osmocom_ms *ms, 
const char *prefix)
 {
        size_t prefix_len = strlen(prefix);
@@ -162,6 +212,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, struct osmocom_ms 
*ms, const char *prefix)
@@ -169,6 +220,16 @@
        /* placeholder for shared VTY commands */
 }

+void l23_vty_config_write_ms_node_contents_final(struct vty *vty, struct 
osmocom_ms *ms, const char *prefix)
+{
+       /* placeholder for shared VTY commands. Must be put at the end of the 
node: */
+
+       /* no shutdown must be written to config, because shutdown is default */
+       vty_out(vty, " %sshutdown%s", (ms->shutdown != MS_SHUTDOWN_NONE) ? "" : 
"no ",
+               VTY_NEWLINE);
+       vty_out(vty, "!%s", VTY_NEWLINE);
+}
+
 int l23_vty_go_parent(struct vty *vty)
 {
        switch (vty->node) {
@@ -183,13 +244,18 @@
        return vty->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)
 {
+       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 0945faa..706ddec 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")
 {
@@ -2996,12 +2947,56 @@
        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);

 int ms_vty_init(void)
 {
-       l23_vty_init(config_write);
+       l23_vty_init(config_write, l23_vty_signal_cb);

        install_element_ve(&show_ms_cmd);
        install_element_ve(&show_subscr_cmd);
@@ -3168,9 +3163,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 88f7e7a..a28c5fd 100644
--- a/src/host/layer23/src/modem/vty.c
+++ b/src/host/layer23/src/modem/vty.c
@@ -31,8 +31,9 @@
 static int config_write(struct vty *vty)
 {
        struct osmocom_ms *ms;
-       llist_for_each_entry(ms, &ms_list, entity)
+       llist_for_each_entry(ms, &ms_list, entity) {
                l23_vty_config_write_ms_node(vty, ms, "");
+       }
        return CMD_SUCCESS;
 }

@@ -48,7 +49,7 @@

 int modem_vty_init(void)
 {
-       l23_vty_init(config_write);
+       l23_vty_init(config_write, NULL);
        install_element_ve(&l23_show_ms_cmd);
        install_element(CONFIG_NODE, &l23_cfg_ms_cmd);


--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30972
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: Ib5c9b6f3efa255d67980945db9f98dd8a112af0e
Gerrit-Change-Number: 30972
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>
Gerrit-MessageType: newchange

Reply via email to