layer23: Move osmocom_ms to a separate file

This way we can extend its API and contents more easily,
and keep most of it together in one place.

Change-Id: Icb4891cc1e4a0ecb5f09cb8a84b0ebe1b91a46b8
This commit is contained in:
Pau Espin 2023-01-12 17:17:19 +01:00
parent ed9ae46f1d
commit 1953a21515
33 changed files with 176 additions and 118 deletions

View File

@ -3,6 +3,7 @@ noinst_HEADERS = \
l1l2_interface.h \
l23_app.h \
logging.h \
ms.h \
networks.h \
gps.h \
sysinfo.h \

View File

@ -0,0 +1,102 @@
/* Mobile Station */
#pragma once
#include <osmocom/core/select.h>
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/core/write_queue.h>
/* FIXME no 'mobile' specific stuff should be here */
#include <osmocom/bb/mobile/support.h>
#include <osmocom/bb/mobile/settings.h>
#include <osmocom/bb/mobile/subscriber.h>
#include <osmocom/gsm/lapdm.h>
#include <osmocom/bb/common/sap_interface.h>
#include <osmocom/bb/common/sap_proto.h>
#include <osmocom/bb/mobile/gsm48_rr.h>
#include <osmocom/bb/common/sysinfo.h>
#include <osmocom/bb/mobile/gsm322.h>
#include <osmocom/bb/mobile/gsm48_mm.h>
#include <osmocom/bb/mobile/gsm48_cc.h>
#include <osmocom/bb/mobile/mncc_sock.h>
#include <osmocom/bb/common/sim.h>
#include <osmocom/bb/common/l1ctl.h>
struct osmosap_entity {
struct osmo_fsm_inst *fi;
uint16_t max_msg_size;
/* Current state of remote SIM card */
enum sap_card_status_type card_status;
/* Optional SAP message call-back */
sap_msg_cb_t sap_msg_cb;
/* Optional response call-back */
sap_rsp_cb_t sap_rsp_cb;
};
struct osmol1_entity {
int (*l1_traffic_ind)(struct osmocom_ms *ms, struct msgb *msg);
};
struct osmomncc_entity {
int (*mncc_recv)(struct osmocom_ms *ms, int msg_type, void *arg);
struct mncc_sock_state *sock_state;
uint32_t ref;
};
/* RX measurement statistics */
struct rx_meas_stat {
uint32_t last_fn;
/* cumulated values of current cell from SACCH dl */
uint32_t frames;
uint32_t snr;
uint32_t berr;
uint32_t rxlev;
/* counters loss criterion */
int16_t dsc, ds_fail;
int16_t s, rl_fail;
};
enum {
MS_SHUTDOWN_NONE = 0,
MS_SHUTDOWN_IMSI_DETACH = 1,
MS_SHUTDOWN_WAIT_RESET = 2,
MS_SHUTDOWN_COMPL = 3,
};
struct osmocom_ms {
struct llist_head entity;
char *name;
struct osmo_wqueue l2_wq, sap_wq;
uint16_t test_arfcn;
struct osmol1_entity l1_entity;
bool started, deleting;
uint8_t shutdown;
struct gsm_support support;
struct gsm_settings settings;
struct gsm_subscriber subscr;
struct gsm_sim sim;
struct lapdm_channel lapdm_channel;
struct osmosap_entity sap_entity;
struct rx_meas_stat meas;
struct gsm48_rrlayer rrlayer;
struct gsm322_plmn plmn;
struct gsm322_cellsel cellsel;
struct gsm48_mmlayer mmlayer;
struct gsm48_cclayer cclayer;
struct osmomncc_entity mncc_entity;
struct llist_head trans_list;
/* Audio I/O */
struct gapk_io_state *gapk_io;
void *lua_state;
int lua_cb_ref;
char *lua_script;
};
struct osmocom_ms *osmocom_ms_alloc(void *ctx);

View File

@ -1,108 +1,10 @@
#ifndef osmocom_data_h
#define osmocom_data_h
#pragma once
#include <osmocom/core/select.h>
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/core/write_queue.h>
#include <stdint.h>
struct osmocom_ms;
struct gapk_io_state;
/* FIXME no 'mobile' specific stuff should be here */
#include <osmocom/bb/mobile/support.h>
#include <osmocom/bb/mobile/settings.h>
#include <osmocom/bb/mobile/subscriber.h>
#include <osmocom/gsm/lapdm.h>
#include <osmocom/bb/common/sap_interface.h>
#include <osmocom/bb/common/sap_proto.h>
#include <osmocom/bb/mobile/gsm48_rr.h>
#include <osmocom/bb/common/sysinfo.h>
#include <osmocom/bb/mobile/gsm322.h>
#include <osmocom/bb/mobile/gsm48_mm.h>
#include <osmocom/bb/mobile/gsm48_cc.h>
#include <osmocom/bb/mobile/mncc_sock.h>
#include <osmocom/bb/common/sim.h>
#include <osmocom/bb/common/l1ctl.h>
struct osmosap_entity {
struct osmo_fsm_inst *fi;
uint16_t max_msg_size;
/* Current state of remote SIM card */
enum sap_card_status_type card_status;
/* Optional SAP message call-back */
sap_msg_cb_t sap_msg_cb;
/* Optional response call-back */
sap_rsp_cb_t sap_rsp_cb;
};
struct osmol1_entity {
int (*l1_traffic_ind)(struct osmocom_ms *ms, struct msgb *msg);
};
struct osmomncc_entity {
int (*mncc_recv)(struct osmocom_ms *ms, int msg_type, void *arg);
struct mncc_sock_state *sock_state;
uint32_t ref;
};
/* RX measurement statistics */
struct rx_meas_stat {
uint32_t last_fn;
/* cumulated values of current cell from SACCH dl */
uint32_t frames;
uint32_t snr;
uint32_t berr;
uint32_t rxlev;
/* counters loss criterion */
int16_t dsc, ds_fail;
int16_t s, rl_fail;
};
enum {
MS_SHUTDOWN_NONE = 0,
MS_SHUTDOWN_IMSI_DETACH = 1,
MS_SHUTDOWN_WAIT_RESET = 2,
MS_SHUTDOWN_COMPL = 3,
};
/* One Mobilestation for osmocom */
struct osmocom_ms {
struct llist_head entity;
char *name;
struct osmo_wqueue l2_wq, sap_wq;
uint16_t test_arfcn;
struct osmol1_entity l1_entity;
bool started, deleting;
uint8_t shutdown;
struct gsm_support support;
struct gsm_settings settings;
struct gsm_subscriber subscr;
struct gsm_sim sim;
struct lapdm_channel lapdm_channel;
struct osmosap_entity sap_entity;
struct rx_meas_stat meas;
struct gsm48_rrlayer rrlayer;
struct gsm322_plmn plmn;
struct gsm322_cellsel cellsel;
struct gsm48_mmlayer mmlayer;
struct gsm48_cclayer cclayer;
struct osmomncc_entity mncc_entity;
struct llist_head trans_list;
/* Audio I/O */
struct gapk_io_state *gapk_io;
void *lua_state;
int lua_cb_ref;
char *lua_script;
};
enum osmobb_sig_subsys {
SS_L1CTL,
SS_GLOBAL,
@ -153,5 +55,3 @@ struct osmobb_neigh_pm_ind {
uint16_t band_arfcn;
uint8_t rx_lev;
};
#endif

View File

@ -18,6 +18,7 @@ liblayer23_a_SOURCES = \
l1l2_interface.c \
l1ctl_lapdm_glue.c \
logging.c \
ms.c \
networks.c \
sap_fsm.c \
sap_proto.c \

View File

@ -40,6 +40,7 @@
#include <osmocom/bb/common/l1ctl.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/l1l2_interface.h>
#include <osmocom/gsm/lapdm.h>
#include <osmocom/bb/common/logging.h>

View File

@ -18,6 +18,7 @@
*/
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/l1ctl.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/l1l2_interface.h>

View File

@ -18,6 +18,7 @@
*/
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/l1ctl.h>
#include <osmocom/bb/common/l1l2_interface.h>
#include <osmocom/bb/common/sap_interface.h>
@ -265,25 +266,12 @@ int main(int argc, char **argv)
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_BASENAME);
log_set_print_filename_pos(osmo_stderr_target, LOG_FILENAME_POS_HEADER_END);
ms = talloc_zero(l23_ctx, struct osmocom_ms);
if (!ms) {
fprintf(stderr, "Failed to allocate MS\n");
exit(1);
}
print_copyright();
ms = osmocom_ms_alloc(l23_ctx);
OSMO_ASSERT(ms);
llist_add_tail(&ms->entity, &ms_list);
ms->name = talloc_strdup(ms, "1");
ms->test_arfcn = 871;
ms->lapdm_channel.lapdm_dcch.l1_ctx = ms;
ms->lapdm_channel.lapdm_dcch.l3_ctx = ms;
ms->lapdm_channel.lapdm_acch.l1_ctx = ms;
ms->lapdm_channel.lapdm_acch.l3_ctx = ms;
lapdm_channel_init(&ms->lapdm_channel, LAPDM_MODE_MS);
lapdm_channel_set_l1(&ms->lapdm_channel, l1ctl_ph_prim_cb, ms);
rc = l23_app_init(ms);
if (rc < 0) {
fprintf(stderr, "Failed during l23_app_init()\n");

View File

@ -0,0 +1,40 @@
/* Mobile Station */
/* (C) 2010 by Holger Hans Peter Freyther
* (C) 2010 by Harald Welte <laforge@gnumonks.org>
* (C) 2023 by sysmocom - s.m.f.c. GmbH <info@sysmocom.de>
*
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <osmocom/bb/common/ms.h>
struct osmocom_ms *osmocom_ms_alloc(void *ctx)
{
struct osmocom_ms *ms;
ms = talloc_zero(ctx, struct osmocom_ms);
if (!ms)
return NULL;
ms->name = talloc_strdup(ms, "1");
ms->test_arfcn = 871;
ms->lapdm_channel.lapdm_dcch.l1_ctx = ms;
ms->lapdm_channel.lapdm_dcch.l3_ctx = ms;
ms->lapdm_channel.lapdm_acch.l1_ctx = ms;
ms->lapdm_channel.lapdm_acch.l3_ctx = ms;
lapdm_channel_init(&ms->lapdm_channel, LAPDM_MODE_MS);
lapdm_channel_set_l1(&ms->lapdm_channel, l1ctl_ph_prim_cb, ms);
return ms;
}

View File

@ -30,6 +30,7 @@
#include <osmocom/core/write_queue.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/sap_interface.h>

View File

@ -34,7 +34,7 @@
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/sap_interface.h>
#include <osmocom/bb/common/sap_proto.h>
#include <osmocom/bb/common/sap_fsm.h>

View File

@ -25,6 +25,7 @@
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/l1ctl.h>
extern struct gsmtap_inst *gsmtap_inst;

View File

@ -19,6 +19,7 @@
*/
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/l1ctl.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/l23_app.h>

View File

@ -32,6 +32,7 @@
#include <osmocom/bb/misc/rslms.h>
#include <osmocom/bb/misc/layer3.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/l1ctl.h>
#include <osmocom/bb/common/l23_app.h>

View File

@ -37,6 +37,7 @@
#include <osmocom/bb/common/l1ctl.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/networks.h>
#include <osmocom/bb/common/gps.h>

View File

@ -30,6 +30,7 @@
#include <osmocom/bb/misc/rslms.h>
#include <osmocom/bb/misc/layer3.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/l1ctl.h>
/* Send a 'simple' RLL request to L2 */

View File

@ -22,6 +22,7 @@
#include <signal.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/l1l2_interface.h>
#include <osmocom/bb/common/l1ctl.h>
#include <osmocom/bb/common/logging.h>

View File

@ -33,6 +33,7 @@
#include <osmocom/gapk/common.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/mobile/voice.h>

View File

@ -32,6 +32,7 @@
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/l1ctl.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/networks.h>
#include <osmocom/bb/common/utils.h>
#include <osmocom/bb/mobile/vty.h>

View File

@ -30,6 +30,7 @@
#include <osmocom/core/msgb.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/mobile/mncc.h>
#include <osmocom/bb/mobile/transaction.h>
#include <osmocom/bb/mobile/gsm411_sms.h>

View File

@ -33,6 +33,7 @@
#include <osmocom/gsm/protocol/gsm_08_58.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/mobile/gsm48_rr.h>

View File

@ -24,6 +24,7 @@
#include <osmocom/core/msgb.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/mobile/mncc.h>
#include <osmocom/bb/mobile/transaction.h>
#include <osmocom/bb/mobile/gsm480_ss.h>

View File

@ -28,6 +28,7 @@
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/mobile/mncc.h>
#include <osmocom/bb/mobile/transaction.h>
#include <osmocom/bb/mobile/gsm48_cc.h>

View File

@ -30,6 +30,7 @@
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/networks.h>
#include <osmocom/bb/common/l1ctl.h>
#include <osmocom/bb/common/utils.h>

View File

@ -69,6 +69,7 @@
#include <osmocom/core/bitvec.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/l1l2_interface.h>
#include <osmocom/bb/common/l23_app.h>
#include <osmocom/bb/common/logging.h>

View File

@ -25,6 +25,7 @@
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/mobile/mncc.h>
#include <osmocom/bb/mobile/mncc_ms.h>
#include <osmocom/bb/mobile/vty.h>

View File

@ -19,6 +19,7 @@
#include <lauxlib.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/mobile/app_mobile.h>
#include <osmocom/bb/common/logging.h>

View File

@ -25,6 +25,7 @@
#include <osmocom/bb/common/utils.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/networks.h>
static char *layer2_socket_path = "/tmp/osmocom_l2";

View File

@ -24,6 +24,7 @@
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/sap_interface.h>
#include <osmocom/bb/common/sap_proto.h>
#include <osmocom/bb/common/networks.h>

View File

@ -20,6 +20,7 @@
#include <string.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
void gsm_support_init(struct osmocom_ms *ms)
{

View File

@ -22,6 +22,7 @@
#include <osmocom/core/msgb.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/mobile/mncc.h>
#include <osmocom/bb/mobile/transaction.h>

View File

@ -27,6 +27,7 @@
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/mobile/gapk_io.h>
#include <osmocom/bb/mobile/mncc.h>
#include <osmocom/bb/mobile/mncc_sock.h>

View File

@ -28,6 +28,7 @@
#include <osmocom/crypt/auth.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/networks.h>
#include <osmocom/bb/common/gps.h>
#include <osmocom/bb/mobile/mncc.h>

View File

@ -36,6 +36,7 @@
#include <osmocom/gprs/rlcmac/gprs_rlcmac.h>
#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/ms.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/l1ctl.h>
#include <osmocom/bb/common/l23_app.h>