diff options
Diffstat (limited to 'src/host')
-rw-r--r-- | src/host/layer23/include/osmocom/bb/mobile/app_mobile.h | 7 | ||||
-rw-r--r-- | src/host/layer23/src/mobile/app_mobile.c | 47 | ||||
-rw-r--r-- | src/host/layer23/src/mobile/vty_interface.c | 53 |
3 files changed, 70 insertions, 37 deletions
diff --git a/src/host/layer23/include/osmocom/bb/mobile/app_mobile.h b/src/host/layer23/include/osmocom/bb/mobile/app_mobile.h index 704c9726..7abfda1f 100644 --- a/src/host/layer23/include/osmocom/bb/mobile/app_mobile.h +++ b/src/host/layer23/include/osmocom/bb/mobile/app_mobile.h @@ -13,12 +13,15 @@ int l23_app_exit(void); int l23_app_work(int *quit); int mobile_delete(struct osmocom_ms *ms, int force); struct osmocom_ms *mobile_new(char *name); -int mobile_init(struct osmocom_ms *ms); -int mobile_exit(struct osmocom_ms *ms, int force); int mobile_work(struct osmocom_ms *ms); +int mobile_start(struct osmocom_ms *ms, char **other_name); +int mobile_stop(struct osmocom_ms *ms, int force); void mobile_set_started(struct osmocom_ms *ms, bool state); void mobile_set_shutdown(struct osmocom_ms *ms, int state); + +/* Internal code. Don't call directly */ +int mobile_exit(struct osmocom_ms *ms, int force); #endif diff --git a/src/host/layer23/src/mobile/app_mobile.c b/src/host/layer23/src/mobile/app_mobile.c index c5c84e62..b2900ad5 100644 --- a/src/host/layer23/src/mobile/app_mobile.c +++ b/src/host/layer23/src/mobile/app_mobile.c @@ -181,7 +181,7 @@ int mobile_exit(struct osmocom_ms *ms, int force) } /* power-on ms instance */ -int mobile_init(struct osmocom_ms *ms) +static int mobile_init(struct osmocom_ms *ms) { int rc; @@ -245,6 +245,51 @@ int mobile_init(struct osmocom_ms *ms) return 0; } +int mobile_start(struct osmocom_ms *ms, char **other_name) +{ + struct osmocom_ms *tmp; + int rc; + + if (ms->shutdown != MS_SHUTDOWN_COMPL) + return 0; + + llist_for_each_entry(tmp, &ms_list, entity) { + if (tmp->shutdown == MS_SHUTDOWN_COMPL) + continue; + if (!strcmp(ms->settings.layer2_socket_path, + tmp->settings.layer2_socket_path)) { + LOGP(DMOB, LOGL_ERROR, "Cannot start MS '%s', because MS '%s' " + "use the same layer2-socket.\nPlease shutdown " + "MS '%s' first.\n", ms->name, tmp->name, tmp->name); + *other_name = tmp->name; + return -1; + } + if (!strcmp(ms->settings.sap_socket_path, + tmp->settings.sap_socket_path)) { + LOGP(DMOB, LOGL_ERROR, "Cannot start MS '%s', because MS '%s' " + "use the same sap-socket.\nPlease shutdown " + "MS '%s' first.\n", ms->name, tmp->name, tmp->name); + *other_name = tmp->name; + return -2; + } + } + + rc = mobile_init(ms); + if (rc < 0) + return -3; + return 0; +} + +int mobile_stop(struct osmocom_ms *ms, int force) +{ + if (force && ms->shutdown <= MS_SHUTDOWN_IMSI_DETACH) + return mobile_exit(ms, 1); + if (!force && ms->shutdown == MS_SHUTDOWN_NONE) + return mobile_exit(ms, 0); + return 0; +} + + /* create ms instance */ struct osmocom_ms *mobile_new(char *name) { diff --git a/src/host/layer23/src/mobile/vty_interface.c b/src/host/layer23/src/mobile/vty_interface.c index eafed6ea..81c20fe9 100644 --- a/src/host/layer23/src/mobile/vty_interface.c +++ b/src/host/layer23/src/mobile/vty_interface.c @@ -2696,35 +2696,25 @@ DEFUN(cfg_test_hplmn, cfg_test_hplmn_cmd, "hplmn-search (everywhere|foreign-coun DEFUN(cfg_no_shutdown, cfg_ms_no_shutdown_cmd, "no shutdown", NO_STR "Activate and run MS") { - struct osmocom_ms *ms = vty->index, *tmp; + struct osmocom_ms *ms = vty->index; + char *other_name = NULL; int rc; - if (ms->shutdown != MS_SHUTDOWN_COMPL) - return CMD_SUCCESS; - - llist_for_each_entry(tmp, &ms_list, entity) { - if (tmp->shutdown == MS_SHUTDOWN_COMPL) - continue; - if (!strcmp(ms->settings.layer2_socket_path, - tmp->settings.layer2_socket_path)) { - vty_out(vty, "Cannot start MS '%s', because MS '%s' " - "use the same layer2-socket.%sPlease shutdown " - "MS '%s' first.%s", ms->name, tmp->name, - VTY_NEWLINE, tmp->name, VTY_NEWLINE); - return CMD_WARNING; - } - if (!strcmp(ms->settings.sap_socket_path, - tmp->settings.sap_socket_path)) { - vty_out(vty, "Cannot start MS '%s', because MS '%s' " - "use the same sap-socket.%sPlease shutdown " - "MS '%s' first.%s", ms->name, tmp->name, - VTY_NEWLINE, tmp->name, VTY_NEWLINE); - return CMD_WARNING; - } - } - - rc = mobile_init(ms); - if (rc < 0) { + 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; @@ -2737,10 +2727,7 @@ DEFUN(cfg_shutdown, cfg_ms_shutdown_cmd, "shutdown", "Shut down and deactivate MS") { struct osmocom_ms *ms = vty->index; - - if (ms->shutdown == MS_SHUTDOWN_NONE) - mobile_exit(ms, 0); - + mobile_stop(ms, 0); return CMD_SUCCESS; } @@ -2749,9 +2736,7 @@ DEFUN(cfg_shutdown_force, cfg_ms_shutdown_force_cmd, "shutdown force", { struct osmocom_ms *ms = vty->index; - if (ms->shutdown <= MS_SHUTDOWN_IMSI_DETACH) - mobile_exit(ms, 1); - + mobile_stop(ms, 1); return CMD_SUCCESS; } |