summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-01-12 13:54:14 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2023-01-13 12:16:47 +0100
commit73abbc235e136c094249927642f0c7cc94209808 (patch)
tree091fc78c6f871fbeeb3c42a4e876879ad14bfb54
parent2b9191f08bb981bec553d3ee9ba0a98a470c2254 (diff)
layer23: Add initial VTY support for l23_apps
Initial VTY "boilerplate" code for modem app is already added in this commit as a showcase what's needed by an app to have the VTY config file read and VTY interface initialized. Change-Id: Ife3a3373e5a9c0c8e5959ac714e140e72d6c363a
-rw-r--r--src/host/layer23/include/osmocom/bb/common/l23_app.h4
-rw-r--r--src/host/layer23/src/common/main.c76
-rw-r--r--src/host/layer23/src/misc/Makefile.am2
-rw-r--r--src/host/layer23/src/modem/app_modem.c16
4 files changed, 76 insertions, 22 deletions
diff --git a/src/host/layer23/include/osmocom/bb/common/l23_app.h b/src/host/layer23/include/osmocom/bb/common/l23_app.h
index cb68d433..633c7646 100644
--- a/src/host/layer23/include/osmocom/bb/common/l23_app.h
+++ b/src/host/layer23/include/osmocom/bb/common/l23_app.h
@@ -2,6 +2,7 @@
#define _L23_APP_H
struct option;
+struct vty_app_info;
/* Options supported by the l23 app */
enum {
@@ -10,7 +11,6 @@ enum {
L23_OPT_TAP = 4,
L23_OPT_VTY = 8,
L23_OPT_DBG = 16,
- L23_OPT_VTYIP = 32,
};
extern void *l23_ctx;
@@ -29,12 +29,14 @@ extern int (*l23_app_exit)(struct osmocom_ms *ms);
struct l23_app_info {
const char *copyright;
const char *contribution;
+ struct vty_app_info *vty_info; /* L23_OPT_VTY */
char *getopt_string;
int (*cfg_supported)();
int (*cfg_print_help)();
int (*cfg_getopt_opt)(struct option **options);
int (*cfg_handle_opt)(int c,const char *optarg);
+ int (*vty_init)(void);
};
extern struct l23_app_info *l23_app_info();
diff --git a/src/host/layer23/src/common/main.c b/src/host/layer23/src/common/main.c
index dcf557f3..ae4932a5 100644
--- a/src/host/layer23/src/common/main.c
+++ b/src/host/layer23/src/common/main.c
@@ -33,6 +33,10 @@
#include <osmocom/core/gsmtap_util.h>
#include <osmocom/core/gsmtap.h>
#include <osmocom/core/utils.h>
+#include <osmocom/vty/vty.h>
+#include <osmocom/vty/logging.h>
+#include <osmocom/vty/telnet_interface.h>
+#include <osmocom/vty/ports.h>
#include <arpa/inet.h>
@@ -51,9 +55,8 @@ static char *sap_socket_path = "/tmp/osmocom_sap";
struct llist_head ms_list;
static struct osmocom_ms *ms = NULL;
static char *gsmtap_ip = NULL;
-static char *vty_ip = "127.0.0.1";
+static char *config_file = NULL;
-unsigned short vty_port = 4247;
int (*l23_app_start)(struct osmocom_ms *ms) = NULL;
int (*l23_app_work)(struct osmocom_ms *ms) = NULL;
int (*l23_app_exit)(struct osmocom_ms *ms) = NULL;
@@ -97,16 +100,11 @@ static void print_help(void)
printf(" -i --gsmtap-ip The destination IP used for GSMTAP.\n");
if (options & L23_OPT_VTY)
- printf(" -v --vty-port The VTY port number to telnet "
- "to. (default %u)\n", vty_port);
+ printf(" -c --config-file The path to the VTY configuration file.\n");
if (options & L23_OPT_DBG)
printf(" -d --debug Change debug flags.\n");
- if (options & L23_OPT_VTYIP)
- printf(" -u --vty-ip The VTY IP to bind telnet to. "
- "(default %s)\n", vty_ip);
-
if (app && app->cfg_print_help)
app->cfg_print_help();
}
@@ -123,14 +121,13 @@ static void build_config(char **opt, struct option **option)
{"sap", 1, 0, 'S'},
{"arfcn", 1, 0, 'a'},
{"gsmtap-ip", 1, 0, 'i'},
- {"vty-ip", 1, 0, 'u'},
- {"vty-port", 1, 0, 'v'},
+ {"config-file", 1, 0, 'c'},
{"debug", 1, 0, 'd'},
};
app = l23_app_info();
- *opt = talloc_asprintf(l23_ctx, "hs:S:a:i:v:d:u:%s",
+ *opt = talloc_asprintf(l23_ctx, "hs:S:a:i:c:d:%s",
app && app->getopt_string ? app->getopt_string : "");
len = ARRAY_SIZE(long_options);
@@ -143,9 +140,8 @@ static void build_config(char **opt, struct option **option)
memcpy(*option + len, app_opp, app_len * sizeof(struct option));
}
-static void handle_options(int argc, char **argv)
+static void handle_options(int argc, char **argv, struct l23_app_info *app)
{
- struct l23_app_info *app = l23_app_info();
struct option *long_options;
char *opt;
@@ -177,11 +173,8 @@ static void handle_options(int argc, char **argv)
case 'i':
gsmtap_ip = optarg;
break;
- case 'u':
- vty_ip = optarg;
- break;
- case 'v':
- vty_port = atoi(optarg);
+ case 'c':
+ config_file = optarg;
break;
case 'd':
log_parse_category_mask(osmo_stderr_target, optarg);
@@ -221,9 +214,43 @@ static void print_copyright(void)
app && app->contribution ? app->contribution : "");
}
+static int _vty_init(struct l23_app_info *app)
+{
+ static struct vty_app_info l23_vty_info = {
+ .name = "OsmocomBB",
+ .version = PACKAGE_VERSION,
+ };
+ int rc;
+
+ OSMO_ASSERT(app->vty_info);
+ app->vty_info->tall_ctx = l23_ctx;
+ vty_init(app->vty_info ? : &l23_vty_info);
+ logging_vty_add_cmds();
+ if (app->vty_init)
+ app->vty_init();
+ if (config_file) {
+ rc = vty_read_config_file(config_file, NULL);
+ if (rc < 0) {
+ LOGP(DLGLOBAL, LOGL_FATAL,
+ "Failed to parse the configuration file '%s'\n", config_file);
+ return rc;
+ }
+ LOGP(DLGLOBAL, LOGL_INFO, "Using configuration from '%s'\n", config_file);
+ }
+ rc = telnet_init_default(l23_ctx, NULL, OSMO_VTY_PORT_BB);
+ if (rc < 0) {
+ LOGP(DMOB, LOGL_FATAL, "Cannot init VTY on %s port %u: %s\n",
+ vty_get_bind_addr(), OSMO_VTY_PORT_BB, strerror(errno));
+ return rc;
+ }
+ return rc;
+}
+
int main(int argc, char **argv)
{
int rc;
+ struct l23_app_info *app;
+ unsigned int app_supp_opt = 0x00;
INIT_LLIST_HEAD(&ms_list);
@@ -257,14 +284,23 @@ int main(int argc, char **argv)
lapdm_channel_init(&ms->lapdm_channel, LAPDM_MODE_MS);
lapdm_channel_set_l1(&ms->lapdm_channel, l1ctl_ph_prim_cb, ms);
- handle_options(argc, argv);
-
rc = l23_app_init(ms);
if (rc < 0) {
fprintf(stderr, "Failed during l23_app_init()\n");
exit(1);
}
+ app = l23_app_info();
+ if (app && app->cfg_supported != NULL)
+ app_supp_opt = app->cfg_supported();
+
+ handle_options(argc, argv, app);
+
+ if (app_supp_opt & L23_OPT_VTY) {
+ if (_vty_init(app) < 0)
+ exit(1);
+ }
+
rc = layer2_open(ms, layer2_socket_path);
if (rc < 0) {
fprintf(stderr, "Failed during layer2_open()\n");
diff --git a/src/host/layer23/src/misc/Makefile.am b/src/host/layer23/src/misc/Makefile.am
index 869fe7be..358be744 100644
--- a/src/host/layer23/src/misc/Makefile.am
+++ b/src/host/layer23/src/misc/Makefile.am
@@ -6,6 +6,7 @@ AM_CPPFLAGS = \
AM_CFLAGS = \
-Wall \
$(LIBOSMOCORE_CFLAGS) \
+ $(LIBOSMOVTY_CFLAGS) \
$(LIBOSMOGSM_CFLAGS) \
$(LIBOSMOGPRSRLCMAC_CFLAGS) \
$(LIBGPS_CFLAGS) \
@@ -14,6 +15,7 @@ AM_CFLAGS = \
LDADD = \
$(top_builddir)/src/common/liblayer23.a \
$(LIBOSMOCORE_LIBS) \
+ $(LIBOSMOVTY_LIBS) \
$(LIBOSMOGSM_LIBS) \
$(LIBOSMOCODEC_LIBS) \
$(LIBOSMOGPRSRLCMAC_LIBS) \
diff --git a/src/host/layer23/src/modem/app_modem.c b/src/host/layer23/src/modem/app_modem.c
index 4529642e..1852a0db 100644
--- a/src/host/layer23/src/modem/app_modem.c
+++ b/src/host/layer23/src/modem/app_modem.c
@@ -26,6 +26,7 @@
#include <osmocom/core/msgb.h>
#include <osmocom/core/signal.h>
#include <osmocom/core/application.h>
+#include <osmocom/vty/vty.h>
#include <osmocom/gsm/rsl.h>
#include <osmocom/gsm/tlv.h>
@@ -485,12 +486,25 @@ int l23_app_init(struct osmocom_ms *ms)
static int l23_cfg_supported(void)
{
- return L23_OPT_ARFCN | L23_OPT_TAP | L23_OPT_DBG;
+ return L23_OPT_ARFCN | L23_OPT_TAP | L23_OPT_VTY | L23_OPT_DBG;
}
+static int l23_vty_init(void)
+{
+ /* TODO: add sample specific vty nodes/cmds */
+ return 0;
+}
+
+static struct vty_app_info _modem_vty_info = {
+ .name = "modem",
+ .version = PACKAGE_VERSION,
+};
+
static struct l23_app_info info = {
.copyright = "Copyright (C) 2022 by sysmocom - s.m.f.c. GmbH <info@sysmocom.de>\n",
.cfg_supported = &l23_cfg_supported,
+ .vty_info = &_modem_vty_info,
+ .vty_init = l23_vty_init,
};
struct l23_app_info *l23_app_info(void)