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
This commit is contained in:
Pau Espin 2023-01-12 12:04:26 +01:00
parent 522b92eae4
commit cd76fcc4ec
7 changed files with 66 additions and 24 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}