diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-01-13 18:07:03 +0100 |
---|---|---|
committer | pespin <pespin@sysmocom.de> | 2023-01-17 18:16:34 +0000 |
commit | 3d3505b72655e23d820b79d48f1f7bb321836953 (patch) | |
tree | 83855b56f47eee8fdb7e73e87a71b64387edd18c | |
parent | 8f59b1a0b94fe591ed4f3163d32127e93ccc10b7 (diff) |
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
-rw-r--r-- | src/host/layer23/include/osmocom/bb/common/l23_app.h | 8 | ||||
-rw-r--r-- | src/host/layer23/include/osmocom/bb/common/ms.h | 2 | ||||
-rw-r--r-- | src/host/layer23/src/common/main.c | 26 | ||||
-rw-r--r-- | src/host/layer23/src/common/ms.c | 5 | ||||
-rw-r--r-- | src/host/layer23/src/misc/app_bcch_scan.c | 20 | ||||
-rw-r--r-- | src/host/layer23/src/misc/app_cbch_sniff.c | 26 | ||||
-rw-r--r-- | src/host/layer23/src/misc/app_ccch_scan.c | 22 | ||||
-rw-r--r-- | src/host/layer23/src/misc/app_cell_log.c | 26 | ||||
-rw-r--r-- | src/host/layer23/src/misc/app_echo_test.c | 6 | ||||
-rw-r--r-- | src/host/layer23/src/modem/app_modem.c | 21 |
10 files changed, 114 insertions, 48 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 633c7646..3c07f705 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 @@ enum { 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 9fd4c7aa..f40e1818 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 { }; 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 c0064c50..eecd29f3 100644 --- a/src/host/layer23/src/common/main.c +++ b/src/host/layer23/src/common/main.c @@ -54,13 +54,12 @@ void *l23_ctx = NULL; 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 @@ static void handle_options(int argc, char **argv, struct l23_app_info *app) 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 @@ void sighandler(int sigset) 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 @@ int main(int argc, char **argv) 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 @@ int main(int argc, char **argv) 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 @@ int main(int argc, char **argv) } 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 @@ int main(int argc, char **argv) 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 9851ebe0..558505ab 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 @@ struct osmocom_ms *osmocom_ms_alloc(void *ctx, const char *name) 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 fc9bca81..274c4dfa 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 @@ static int signal_cb(unsigned int subsys, unsigned int signal, 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 d04faa93..64850dbb 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 @@ static int signal_cb(unsigned int subsys, unsigned int signal, 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 da8223cf..be35b5b3 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 @@ static int signal_cb(unsigned int subsys, unsigned int signal, 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 43980e98..8c925af1 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 @@ extern uint16_t (*band_range)[][2]; 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 @@ int _scan_exit(struct osmocom_ms *ms) return 0; } -int l23_app_init(struct osmocom_ms *ms) +int l23_app_init(void) { int rc; @@ -79,7 +90,10 @@ int l23_app_init(struct osmocom_ms *ms) 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 3cf854a8..f8899e6d 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 @@ static void test_tmr_cb(void *data) 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 a1bb27ab..93f3b541 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 @@ static int signal_cb(unsigned int subsys, unsigned int signal, 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 @@ int l23_app_init(struct osmocom_ms *ms) 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; } |