pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30979 )
Change subject: layer23: Let each app allocate its ms obj and start layer2 when needed ......................................................................
layer23: Let each app allocate its ms obj and start layer2 when needed
This allows apps to allocate the objects as they please: simple apps can statically allocate it at startup. Others may want to allocate them through VTY. Some apps may also want to dynamically start and stop layer2.
Change-Id: I32f99df76a5513eff9df5489d28d60aedf96dec3 --- M src/host/layer23/include/osmocom/bb/common/l23_app.h M src/host/layer23/include/osmocom/bb/common/ms.h M src/host/layer23/src/common/main.c M src/host/layer23/src/common/ms.c M src/host/layer23/src/misc/app_bcch_scan.c M src/host/layer23/src/misc/app_cbch_sniff.c M src/host/layer23/src/misc/app_ccch_scan.c M src/host/layer23/src/misc/app_cell_log.c M src/host/layer23/src/misc/app_echo_test.c M src/host/layer23/src/modem/app_modem.c 10 files changed, 114 insertions(+), 48 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/src/host/layer23/include/osmocom/bb/common/l23_app.h b/src/host/layer23/include/osmocom/bb/common/l23_app.h index 633c764..3c07f70 100644 --- a/src/host/layer23/include/osmocom/bb/common/l23_app.h +++ b/src/host/layer23/include/osmocom/bb/common/l23_app.h @@ -16,14 +16,14 @@ extern void *l23_ctx;
/* initialization, called once when starting the app, before reading VTY config */ -extern int l23_app_init(struct osmocom_ms *ms); +extern int l23_app_init(void);
/* Start work after reading VTY config and starting layer23 components, * immediately before entering main select loop */ -extern int (*l23_app_start)(struct osmocom_ms *ms); +extern int (*l23_app_start)(void);
-extern int (*l23_app_work)(struct osmocom_ms *ms); -extern int (*l23_app_exit)(struct osmocom_ms *ms); +extern int (*l23_app_work)(void); +extern int (*l23_app_exit)(void);
/* configuration options */ struct l23_app_info { diff --git a/src/host/layer23/include/osmocom/bb/common/ms.h b/src/host/layer23/include/osmocom/bb/common/ms.h index 9fd4c7a..f40e181 100644 --- a/src/host/layer23/include/osmocom/bb/common/ms.h +++ b/src/host/layer23/include/osmocom/bb/common/ms.h @@ -99,3 +99,5 @@ };
struct osmocom_ms *osmocom_ms_alloc(void *ctx, const char *name); + +extern uint16_t cfg_test_arfcn; diff --git a/src/host/layer23/src/common/main.c b/src/host/layer23/src/common/main.c index c0064c5..eecd29f 100644 --- a/src/host/layer23/src/common/main.c +++ b/src/host/layer23/src/common/main.c @@ -54,13 +54,12 @@
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 *config_file = NULL;
-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; +int (*l23_app_start)(void) = NULL; +int (*l23_app_work)(void) = NULL; +int (*l23_app_exit)(void) = NULL; int quit = 0; struct gsmtap_inst *gsmtap_inst;
@@ -169,7 +168,7 @@ sap_socket_path = talloc_strdup(l23_ctx, optarg); break; case 'a': - ms->test_arfcn = atoi(optarg); + cfg_test_arfcn = atoi(optarg); break; case 'i': gsmtap_ip = optarg; @@ -200,7 +199,7 @@
fprintf(stderr, "Signal %d received.\n", sigset); if (l23_app_exit) - rc = l23_app_exit(ms); + rc = l23_app_exit();
if (rc != -EBUSY) exit (0); @@ -270,10 +269,7 @@
print_copyright();
- ms = osmocom_ms_alloc(l23_ctx, "1"); - OSMO_ASSERT(ms); - - rc = l23_app_init(ms); + rc = l23_app_init(); if (rc < 0) { fprintf(stderr, "Failed during l23_app_init()\n"); exit(1); @@ -290,12 +286,6 @@ exit(1); }
- rc = layer2_open(ms, ms->settings.layer2_socket_path); - if (rc < 0) { - fprintf(stderr, "Failed during layer2_open()\n"); - exit(1); - } - if (gsmtap_ip) { gsmtap_inst = gsmtap_source_init(gsmtap_ip, GSMTAP_UDP_PORT, 1); if (!gsmtap_inst) { @@ -306,7 +296,7 @@ }
if (l23_app_start) { - rc = l23_app_start(ms); + rc = l23_app_start(); if (rc < 0) { fprintf(stderr, "Failed during l23_app_start()\n"); exit(1); @@ -320,7 +310,7 @@
while (!quit) { if (l23_app_work) - l23_app_work(ms); + l23_app_work(); osmo_select_main(0); }
diff --git a/src/host/layer23/src/common/ms.c b/src/host/layer23/src/common/ms.c index 9851ebe..558505a 100644 --- a/src/host/layer23/src/common/ms.c +++ b/src/host/layer23/src/common/ms.c @@ -21,6 +21,9 @@
extern struct llist_head ms_list;
+/* Default value be configured by cmdline arg: */ +uint16_t cfg_test_arfcn = 871; + struct osmocom_ms *osmocom_ms_alloc(void *ctx, const char *name) { struct osmocom_ms *ms; @@ -31,7 +34,7 @@ talloc_set_name(ms, "ms_%s", name);
ms->name = talloc_strdup(ms, name); - ms->test_arfcn = 871; + ms->test_arfcn = cfg_test_arfcn; ms->lapdm_channel.lapdm_dcch.l1_ctx = ms; ms->lapdm_channel.lapdm_dcch.l3_ctx = ms; ms->lapdm_channel.lapdm_acch.l1_ctx = ms; diff --git a/src/host/layer23/src/misc/app_bcch_scan.c b/src/host/layer23/src/misc/app_bcch_scan.c index fc9bca8..274c4df 100644 --- a/src/host/layer23/src/misc/app_bcch_scan.c +++ b/src/host/layer23/src/misc/app_bcch_scan.c @@ -21,6 +21,8 @@ #include <osmocom/bb/common/l1ctl.h> #include <osmocom/bb/common/logging.h> #include <osmocom/bb/common/l23_app.h> +#include <osmocom/bb/common/l1l2_interface.h> +#include <osmocom/bb/common/ms.h> #include <osmocom/bb/misc/layer3.h>
#include <osmocom/core/msgb.h> @@ -31,6 +33,8 @@ #include <l1ctl_proto.h> #include "bcch_scan.h"
+static struct osmocom_ms *g_ms; + static int signal_cb(unsigned int subsys, unsigned int signal, void *handler_data, void *signal_data) { @@ -47,14 +51,24 @@ return 0; }
-static int _bcch_scan_start(struct osmocom_ms *ms) +static int _bcch_scan_start(void) { - l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); + int rc; + + rc = layer2_open(g_ms, g_ms->settings.layer2_socket_path); + if (rc < 0) { + fprintf(stderr, "Failed during layer2_open()\n"); + return rc; + } + + l1ctl_tx_reset_req(g_ms, L1CTL_RES_T_FULL); return 0; }
-int l23_app_init(struct osmocom_ms *ms) +int l23_app_init(void) { + g_ms = osmocom_ms_alloc(l23_ctx, "1"); + OSMO_ASSERT(g_ms); /* don't do layer3_init() as we don't want an actual L3 */ fps_init(); l23_app_start = _bcch_scan_start; diff --git a/src/host/layer23/src/misc/app_cbch_sniff.c b/src/host/layer23/src/misc/app_cbch_sniff.c index d04faa9..64850db 100644 --- a/src/host/layer23/src/misc/app_cbch_sniff.c +++ b/src/host/layer23/src/misc/app_cbch_sniff.c @@ -25,6 +25,8 @@ #include <osmocom/bb/common/l23_app.h> #include <osmocom/bb/misc/layer3.h> #include <osmocom/bb/common/sysinfo.h> +#include <osmocom/bb/common/l1l2_interface.h> +#include <osmocom/bb/common/ms.h>
#include <osmocom/core/msgb.h> #include <osmocom/core/talloc.h> @@ -36,7 +38,7 @@
#include <l1ctl_proto.h>
-struct osmocom_ms *g_ms; +static struct osmocom_ms *g_ms; struct gsm48_sysinfo g_sysinfo = {};
static int try_cbch(struct osmocom_ms *ms, struct gsm48_sysinfo *s) @@ -196,22 +198,32 @@ return 0; }
-static int _cbch_sniff_start(struct osmocom_ms *ms) +static int _cbch_sniff_start(void) { - l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); + int rc; + + rc = layer2_open(g_ms, g_ms->settings.layer2_socket_path); + if (rc < 0) { + fprintf(stderr, "Failed during layer2_open()\n"); + return rc; + } + + l1ctl_tx_reset_req(g_ms, L1CTL_RES_T_FULL); /* FIXME: L1CTL_RES_T_FULL doesn't reset dedicated mode * (if previously set), so we release it here. */ - l1ctl_tx_dm_rel_req(ms); + l1ctl_tx_dm_rel_req(g_ms); return 0; }
-int l23_app_init(struct osmocom_ms *ms) +int l23_app_init(void) { /* don't do layer3_init() as we don't want an actual L3 */ l23_app_start = _cbch_sniff_start; - g_ms = ms;
- lapdm_channel_set_l3(&ms->lapdm_channel, &rcv_rsl, ms); + g_ms = osmocom_ms_alloc(l23_ctx, "1"); + OSMO_ASSERT(g_ms); + + lapdm_channel_set_l3(&g_ms->lapdm_channel, &rcv_rsl, g_ms); return osmo_signal_register_handler(SS_L1CTL, &signal_cb, NULL); }
diff --git a/src/host/layer23/src/misc/app_ccch_scan.c b/src/host/layer23/src/misc/app_ccch_scan.c index da8223c..be35b5b 100644 --- a/src/host/layer23/src/misc/app_ccch_scan.c +++ b/src/host/layer23/src/misc/app_ccch_scan.c @@ -35,10 +35,13 @@ #include <osmocom/bb/common/ms.h> #include <osmocom/bb/common/l1ctl.h> #include <osmocom/bb/common/l23_app.h> +#include <osmocom/bb/common/l1l2_interface.h> +#include <osmocom/bb/common/ms.h>
#include <l1ctl_proto.h>
static struct { + struct osmocom_ms *ms; int ccch_mode; } app_state;
@@ -491,18 +494,29 @@ return 0; }
-static int _ccch_scan_start(struct osmocom_ms *ms) +static int _ccch_scan_start(void) { - l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); + int rc; + + rc = layer2_open(app_state.ms, app_state.ms->settings.layer2_socket_path); + if (rc < 0) { + fprintf(stderr, "Failed during layer2_open()\n"); + return rc; + } + + l1ctl_tx_reset_req(app_state.ms, L1CTL_RES_T_FULL); return 0; }
-int l23_app_init(struct osmocom_ms *ms) +int l23_app_init(void) { l23_app_start = _ccch_scan_start;
+ app_state.ms = osmocom_ms_alloc(l23_ctx, "1"); + OSMO_ASSERT(app_state.ms); + osmo_signal_register_handler(SS_L1CTL, &signal_cb, NULL); - return layer3_init(ms); + return layer3_init(app_state.ms); }
static struct l23_app_info info = { diff --git a/src/host/layer23/src/misc/app_cell_log.c b/src/host/layer23/src/misc/app_cell_log.c index 43980e9..8c925af 100644 --- a/src/host/layer23/src/misc/app_cell_log.c +++ b/src/host/layer23/src/misc/app_cell_log.c @@ -26,6 +26,8 @@ #include <osmocom/bb/common/l23_app.h> #include <osmocom/bb/common/logging.h> #include <osmocom/bb/common/gps.h> +#include <osmocom/bb/common/l1l2_interface.h> +#include <osmocom/bb/common/ms.h> #include <osmocom/bb/misc/cell_log.h>
#include <osmocom/core/application.h> @@ -39,20 +41,29 @@
char *logname = "/dev/null"; int RACH_MAX = 2; +static struct osmocom_ms *g_ms;
-int _scan_start(struct osmocom_ms *ms) +int _scan_start(void) { - l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); + int rc; + + rc = layer2_open(g_ms, g_ms->settings.layer2_socket_path); + if (rc < 0) { + fprintf(stderr, "Failed during layer2_open()\n"); + return rc; + } + + l1ctl_tx_reset_req(g_ms, L1CTL_RES_T_FULL); return 0; }
-int _scan_work(struct osmocom_ms *ms) +int _scan_work(void) { return 0; }
-int _scan_exit(struct osmocom_ms *ms) +int _scan_exit(void) { /* in case there is a lockup during exit */ signal(SIGINT, SIG_DFL); @@ -65,7 +76,7 @@ return 0; }
-int l23_app_init(struct osmocom_ms *ms) +int l23_app_init(void) { int rc;
@@ -79,7 +90,10 @@ l23_app_work = _scan_work; l23_app_exit = _scan_exit;
- rc = scan_init(ms); + g_ms = osmocom_ms_alloc(l23_ctx, "1"); + OSMO_ASSERT(g_ms); + + rc = scan_init(g_ms); if (rc) return rc;
diff --git a/src/host/layer23/src/misc/app_echo_test.c b/src/host/layer23/src/misc/app_echo_test.c index 3cf854a..f8899e6 100644 --- a/src/host/layer23/src/misc/app_echo_test.c +++ b/src/host/layer23/src/misc/app_echo_test.c @@ -21,6 +21,7 @@ #include <osmocom/bb/common/l1ctl.h> #include <osmocom/bb/common/logging.h> #include <osmocom/bb/common/l23_app.h> +#include <osmocom/bb/common/ms.h> #include <osmocom/bb/misc/layer3.h>
#include <osmocom/core/msgb.h> @@ -40,8 +41,11 @@ osmo_timer_schedule(&test_data.timer, 1, 0); }
-int l23_app_init(struct osmocom_ms *ms) +int l23_app_init(void) { + struct osmocom_ms *ms = osmocom_ms_alloc(l23_ctx, "1"); + OSMO_ASSERT(ms); + test_data.timer.cb = &test_tmr_cb; test_data.timer.data = ms;
diff --git a/src/host/layer23/src/modem/app_modem.c b/src/host/layer23/src/modem/app_modem.c index a1bb27a..93f3b54 100644 --- a/src/host/layer23/src/modem/app_modem.c +++ b/src/host/layer23/src/modem/app_modem.c @@ -40,12 +40,14 @@ #include <osmocom/bb/common/logging.h> #include <osmocom/bb/common/l1ctl.h> #include <osmocom/bb/common/l23_app.h> +#include <osmocom/bb/common/l1l2_interface.h> #include <osmocom/bb/common/sysinfo.h> #include <osmocom/bb/modem/vty.h>
#include <l1ctl_proto.h>
static struct { + struct osmocom_ms *ms; enum ccch_mode ccch_mode; struct gsm48_sysinfo si;
@@ -467,13 +469,21 @@ return 0; }
-static int _modem_start(struct osmocom_ms *ms) +static int _modem_start(void) { - l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); + int rc; + + rc = layer2_open(app_data.ms, app_data.ms->settings.layer2_socket_path); + if (rc < 0) { + fprintf(stderr, "Failed during layer2_open()\n"); + return rc; + } + + l1ctl_tx_reset_req(app_data.ms, L1CTL_RES_T_FULL); return 0; }
-int l23_app_init(struct osmocom_ms *ms) +int l23_app_init(void) { l23_app_start = _modem_start;
@@ -481,8 +491,11 @@ log_set_category_filter(osmo_stderr_target, DLCSN1, 1, LOGL_DEBUG); log_set_category_filter(osmo_stderr_target, DRR, 1, LOGL_INFO);
+ app_data.ms = osmocom_ms_alloc(l23_ctx, "1"); + OSMO_ASSERT(app_data.ms); + osmo_signal_register_handler(SS_L1CTL, &signal_cb, NULL); - lapdm_channel_set_l3(&ms->lapdm_channel, &modem_rslms_cb, ms); + lapdm_channel_set_l3(&app_data.ms->lapdm_channel, &modem_rslms_cb, app_data.ms); return 0; }