diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-01-12 12:04:26 +0100 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-01-13 12:16:47 +0100 |
commit | cd76fcc4eca0a9840e9b30c98c20fd806745bf87 (patch) | |
tree | cc09b71842855d221a97b923bc7aab7b96868f47 | |
parent | 522b92eae41f7b5d9bdf928504afd0105e477154 (diff) |
layer23: Introduce l23_app_start() API step
This commit is a preparation towards having shared VTY infrastructure
for layer23 apps. Having 2 steps (first init(), then start()) allows
the apps easily struct allocation & initialization, and then start doing
work after VTY config has been read.
Change-Id: I1d232809764962f82fee86159bc61cdbc3eb3c48
-rw-r--r-- | src/host/layer23/include/osmocom/bb/common/l23_app.h | 8 | ||||
-rw-r--r-- | src/host/layer23/src/common/main.c | 30 | ||||
-rw-r--r-- | src/host/layer23/src/misc/app_bcch_scan.c | 8 | ||||
-rw-r--r-- | src/host/layer23/src/misc/app_cbch_sniff.c | 17 | ||||
-rw-r--r-- | src/host/layer23/src/misc/app_ccch_scan.c | 8 | ||||
-rw-r--r-- | src/host/layer23/src/misc/app_cell_log.c | 9 | ||||
-rw-r--r-- | src/host/layer23/src/modem/app_modem.c | 10 |
7 files changed, 66 insertions, 24 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 d5f0fd3a..a37e1e0d 100644 --- a/src/host/layer23/include/osmocom/bb/common/l23_app.h +++ b/src/host/layer23/include/osmocom/bb/common/l23_app.h @@ -13,9 +13,13 @@ enum { L23_OPT_VTYIP = 32, }; -/* initialization, called once when starting the app, before entering - * select loop */ +/* initialization, called once when starting the app, before reading VTY config */ extern int l23_app_init(struct osmocom_ms *ms); + +/* 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_work)(struct osmocom_ms *ms); extern int (*l23_app_exit)(struct osmocom_ms *ms); diff --git a/src/host/layer23/src/common/main.c b/src/host/layer23/src/common/main.c index 68413130..dcf557f3 100644 --- a/src/host/layer23/src/common/main.c +++ b/src/host/layer23/src/common/main.c @@ -54,6 +54,7 @@ static char *gsmtap_ip = NULL; static char *vty_ip = "127.0.0.1"; 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; int quit = 0; @@ -249,15 +250,6 @@ int main(int argc, char **argv) ms->name = talloc_strdup(ms, "1"); ms->test_arfcn = 871; - - handle_options(argc, argv); - - rc = layer2_open(ms, layer2_socket_path); - if (rc < 0) { - fprintf(stderr, "Failed during layer2_open()\n"); - exit(1); - } - ms->lapdm_channel.lapdm_dcch.l1_ctx = ms; ms->lapdm_channel.lapdm_dcch.l3_ctx = ms; ms->lapdm_channel.lapdm_acch.l1_ctx = ms; @@ -265,9 +257,19 @@ 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) + if (rc < 0) { + fprintf(stderr, "Failed during l23_app_init()\n"); exit(1); + } + + rc = layer2_open(ms, 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); @@ -278,6 +280,14 @@ int main(int argc, char **argv) gsmtap_source_add_sink(gsmtap_inst); } + if (l23_app_start) { + rc = l23_app_start(ms); + if (rc < 0) { + fprintf(stderr, "Failed during l23_app_start()\n"); + exit(1); + } + } + signal(SIGINT, sighandler); signal(SIGHUP, sighandler); signal(SIGTERM, sighandler); diff --git a/src/host/layer23/src/misc/app_bcch_scan.c b/src/host/layer23/src/misc/app_bcch_scan.c index 257469c2..fc9bca81 100644 --- a/src/host/layer23/src/misc/app_bcch_scan.c +++ b/src/host/layer23/src/misc/app_bcch_scan.c @@ -47,11 +47,17 @@ static int signal_cb(unsigned int subsys, unsigned int signal, return 0; } +static int _bcch_scan_start(struct osmocom_ms *ms) +{ + l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); + return 0; +} + int l23_app_init(struct osmocom_ms *ms) { /* don't do layer3_init() as we don't want an actual L3 */ fps_init(); - l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); + l23_app_start = _bcch_scan_start; return osmo_signal_register_handler(SS_L1CTL, &signal_cb, NULL); } diff --git a/src/host/layer23/src/misc/app_cbch_sniff.c b/src/host/layer23/src/misc/app_cbch_sniff.c index 76d4537e..d5424ba3 100644 --- a/src/host/layer23/src/misc/app_cbch_sniff.c +++ b/src/host/layer23/src/misc/app_cbch_sniff.c @@ -194,17 +194,22 @@ static int signal_cb(unsigned int subsys, unsigned int signal, return 0; } -int l23_app_init(struct osmocom_ms *ms) +static int _cbch_sniff_start(struct osmocom_ms *ms) { - /* don't do layer3_init() as we don't want an actual L3 */ - - g_ms = ms; - lapdm_channel_set_l3(&ms->lapdm_channel, &rcv_rsl, ms); - l1ctl_tx_reset_req(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); + return 0; +} + +int l23_app_init(struct osmocom_ms *ms) +{ + /* 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); 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 04afdcf4..cfb43922 100644 --- a/src/host/layer23/src/misc/app_ccch_scan.c +++ b/src/host/layer23/src/misc/app_ccch_scan.c @@ -490,11 +490,17 @@ static int signal_cb(unsigned int subsys, unsigned int signal, return 0; } +static int _ccch_scan_start(struct osmocom_ms *ms) +{ + l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); + return 0; +} int l23_app_init(struct osmocom_ms *ms) { + l23_app_start = _ccch_scan_start; + osmo_signal_register_handler(SS_L1CTL, &signal_cb, NULL); - l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); return layer3_init(ms); } diff --git a/src/host/layer23/src/misc/app_cell_log.c b/src/host/layer23/src/misc/app_cell_log.c index abc472dc..f1596c39 100644 --- a/src/host/layer23/src/misc/app_cell_log.c +++ b/src/host/layer23/src/misc/app_cell_log.c @@ -42,6 +42,13 @@ extern uint16_t (*band_range)[][2]; char *logname = "/dev/null"; int RACH_MAX = 2; + +int _scan_start(struct osmocom_ms *ms) +{ + l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); + return 0; +} + int _scan_work(struct osmocom_ms *ms) { return 0; @@ -70,6 +77,7 @@ int l23_app_init(struct osmocom_ms *ms) log_parse_category_mask(osmo_stderr_target, "DSUM"); log_set_log_level(osmo_stderr_target, LOGL_INFO); + l23_app_start = _scan_start; l23_app_work = _scan_work; l23_app_exit = _scan_exit; @@ -77,7 +85,6 @@ int l23_app_init(struct osmocom_ms *ms) if (rc) return rc; - l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); printf("Mobile initialized, please start phone now!\n"); return 0; } diff --git a/src/host/layer23/src/modem/app_modem.c b/src/host/layer23/src/modem/app_modem.c index 75513512..4529642e 100644 --- a/src/host/layer23/src/modem/app_modem.c +++ b/src/host/layer23/src/modem/app_modem.c @@ -464,18 +464,22 @@ static int signal_cb(unsigned int subsys, unsigned int signal, return 0; } +static int _modem_start(struct osmocom_ms *ms) +{ + l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); + return 0; +} int l23_app_init(struct osmocom_ms *ms) { + l23_app_start = _modem_start; + log_set_category_filter(osmo_stderr_target, DLGLOBAL, 1, LOGL_DEBUG); log_set_category_filter(osmo_stderr_target, DLCSN1, 1, LOGL_DEBUG); log_set_category_filter(osmo_stderr_target, DRR, 1, LOGL_INFO); osmo_signal_register_handler(SS_L1CTL, &signal_cb, NULL); - l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); - lapdm_channel_set_l3(&ms->lapdm_channel, &modem_rslms_cb, ms); - return 0; } |