layer23: Move layer2-socket VTY command to common/

This allows configuring layer2-socket for other apps than mobile, like
the "modem" one.

Change-Id: If7419f8fc54a54eed68a076968d93dba5ac977b7
This commit is contained in:
Pau Espin 2023-01-13 16:32:06 +01:00 committed by pespin
parent 3b8d5bb26a
commit 8f59b1a0b9
9 changed files with 51 additions and 25 deletions

View File

@ -3,6 +3,8 @@
#include <osmocom/core/msgb.h>
#define L2_DEFAULT_SOCKET_PATH "/tmp/osmocom_l2"
int layer2_open(struct osmocom_ms *ms, const char *socket_path);
int layer2_close(struct osmocom_ms *ms);
int osmo_send_l1(struct osmocom_ms *ms, struct msgb *msg);

View File

@ -180,5 +180,7 @@ int gsm_settings_exit(struct osmocom_ms *ms);
char *gsm_check_imei(const char *imei, const char *sv);
int gsm_random_imei(struct gsm_settings *set);
extern char *layer2_socket_path;
#endif /* _settings_h */

View File

@ -20,6 +20,9 @@ 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 bool l23_vty_reading;
extern struct llist_head ms_list;
extern struct cmd_element l23_show_ms_cmd;

View File

@ -25,6 +25,7 @@
#include <osmocom/bb/misc/layer3.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/l23_app.h>
#include <osmocom/bb/common/vty.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/talloc.h>
@ -51,7 +52,6 @@
void *l23_ctx = NULL;
static char *layer2_socket_path = "/tmp/osmocom_l2";
static char *sap_socket_path = "/tmp/osmocom_sap";
struct llist_head ms_list;
static struct osmocom_ms *ms = NULL;
@ -163,7 +163,7 @@ static void handle_options(int argc, char **argv, struct l23_app_info *app)
exit(0);
break;
case 's':
layer2_socket_path = talloc_strdup(l23_ctx, optarg);
layer2_socket_path = optarg;
break;
case 'S':
sap_socket_path = talloc_strdup(l23_ctx, optarg);
@ -230,7 +230,9 @@ static int _vty_init(struct l23_app_info *app)
if (app->vty_init)
app->vty_init();
if (config_file) {
l23_vty_reading = true;
rc = vty_read_config_file(config_file, NULL);
l23_vty_reading = false;
if (rc < 0) {
LOGP(DLGLOBAL, LOGL_FATAL,
"Failed to parse the configuration file '%s'\n", config_file);
@ -288,7 +290,7 @@ int main(int argc, char **argv)
exit(1);
}
rc = layer2_open(ms, layer2_socket_path);
rc = layer2_open(ms, ms->settings.layer2_socket_path);
if (rc < 0) {
fprintf(stderr, "Failed during layer2_open()\n");
exit(1);

View File

@ -45,5 +45,8 @@ struct osmocom_ms *osmocom_ms_alloc(void *ctx, const char *name)
/* Register a new MS */
llist_add_tail(&ms->entity, &ms_list);
gsm_support_init(ms);
gsm_settings_init(ms);
return ms;
}

View File

@ -27,8 +27,11 @@
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/networks.h>
#include <osmocom/bb/common/l1l2_interface.h>
/* Used to set default path globally through cmdline */
char *layer2_socket_path = L2_DEFAULT_SOCKET_PATH;
static char *layer2_socket_path = "/tmp/osmocom_l2";
static char *sap_socket_path = "/tmp/osmocom_sap";
static char *mncc_socket_path = "/tmp/ms_mncc";
static char *alsa_dev_default = "default";

View File

@ -33,6 +33,7 @@
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/networks.h>
#include <osmocom/bb/common/gps.h>
#include <osmocom/bb/common/l1l2_interface.h>
#include <osmocom/bb/mobile/mncc.h>
#include <osmocom/bb/mobile/mncc_ms.h>
#include <osmocom/bb/mobile/transaction.h>
@ -43,12 +44,24 @@
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/misc.h>
bool l23_vty_reading = false;
static struct cmd_node ms_node = {
MS_NODE,
"%s(ms)# ",
1
};
static void l23_vty_restart_required_warn(struct vty *vty, struct osmocom_ms *ms)
{
if (l23_vty_reading)
return;
if (ms->shutdown != MS_SHUTDOWN_NONE)
return;
vty_out(vty, "You must restart MS '%s' ('shutdown / no shutdown') for "
"change to take effect!%s", ms->name, VTY_NEWLINE);
}
struct osmocom_ms *l23_vty_get_ms(const char *name, struct vty *vty)
{
struct osmocom_ms *ms;
@ -152,6 +165,19 @@ gDEFUN(l23_cfg_ms, l23_cfg_ms_cmd, "ms MS_NAME",
return CMD_WARNING;
}
DEFUN(cfg_ms_layer2, cfg_ms_layer2_cmd, "layer2-socket PATH",
"Define socket path to connect between layer 2 and layer 1\n"
"Unix socket, default '" L2_DEFAULT_SOCKET_PATH "'")
{
struct osmocom_ms *ms = vty->index;
struct gsm_settings *set = &ms->settings;
OSMO_STRLCPY_ARRAY(set->layer2_socket_path, argv[0]);
l23_vty_restart_required_warn(vty, ms);
return CMD_SUCCESS;
}
DEFUN(cfg_ms_no_shutdown, cfg_ms_no_shutdown_cmd, "no shutdown",
NO_STR "Activate and run MS")
{
@ -216,9 +242,13 @@ void l23_vty_config_write_ms_node(struct vty *vty, const struct osmocom_ms *ms,
l23_vty_config_write_ms_node_contents_final(vty, ms, prefix_content);
}
/* placeholder for shared VTY commands */
void l23_vty_config_write_ms_node_contents(struct vty *vty, const struct osmocom_ms *ms, const char *prefix)
{
/* placeholder for shared VTY commands */
const struct gsm_settings *set = &ms->settings;
vty_out(vty, "%slayer2-socket %s%s", prefix, set->layer2_socket_path,
VTY_NEWLINE);
}
/* placeholder for shared VTY commands. Must be put at the end of the node: */
@ -234,6 +264,7 @@ int l23_vty_init(int (*config_write_ms_node_cb)(struct vty *), osmo_signal_cbfn
{
int rc = 0;
install_node(&ms_node, config_write_ms_node_cb);
install_element(MS_NODE, &cfg_ms_layer2_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);

View File

@ -341,11 +341,7 @@ struct osmocom_ms *mobile_new(char *name)
return NULL;
}
gsm_support_init(ms);
gsm_settings_init(ms);
mobile_set_shutdown(ms, MS_SHUTDOWN_COMPL);
return ms;
}

View File

@ -1300,8 +1300,6 @@ static void config_write_ms(struct vty *vty, struct osmocom_ms *ms)
l23_vty_config_write_ms_node_contents(vty, ms, " ");
vty_out(vty, " layer2-socket %s%s", set->layer2_socket_path,
VTY_NEWLINE);
vty_out(vty, " sap-socket %s%s", set->sap_socket_path, VTY_NEWLINE);
vty_out(vty, " mncc-socket %s%s", set->mncc_socket_path, VTY_NEWLINE);
switch (set->mncc_handler) {
@ -1574,19 +1572,6 @@ DEFUN(cfg_ms_show_this, cfg_ms_show_this_cmd, "show this",
return CMD_SUCCESS;
}
DEFUN(cfg_ms_layer2, cfg_ms_layer2_cmd, "layer2-socket PATH",
"Define socket path to connect between layer 2 and layer 1\n"
"Unix socket, default '/tmp/osmocom_l2'")
{
struct osmocom_ms *ms = vty->index;
struct gsm_settings *set = &ms->settings;
OSMO_STRLCPY_ARRAY(set->layer2_socket_path, argv[0]);
vty_restart(vty, ms);
return CMD_SUCCESS;
}
DEFUN(cfg_ms_sap, cfg_ms_sap_cmd, "sap-socket PATH",
"Define socket path to connect to SIM reader\n"
"Unix socket, default '/tmp/osmocom_sap'")
@ -3039,7 +3024,6 @@ int ms_vty_init(void)
/* MS_NODE is installed by l23_vty_init(). App specific commands below: */
install_element(MS_NODE, &cfg_ms_show_this_cmd);
install_element(MS_NODE, &cfg_ms_layer2_cmd);
install_element(MS_NODE, &cfg_ms_sap_cmd);
install_element(MS_NODE, &cfg_ms_mncc_sock_cmd);
install_element(MS_NODE, &cfg_ms_mncc_handler_cmd);