summaryrefslogtreecommitdiffstats
path: root/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common
diff options
context:
space:
mode:
Diffstat (limited to 'Src/osmoconbb/src/host/layer23/include/osmocom/bb/common')
-rw-r--r--Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/Makefile.am2
-rw-r--r--Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/gps.h53
-rw-r--r--Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/l1ctl.h76
-rw-r--r--Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/l1l2_interface.h8
-rw-r--r--Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/l23_app.h35
-rw-r--r--Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/lapdm.h186
-rw-r--r--Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/logging.h29
-rw-r--r--Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/networks.h24
-rw-r--r--Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/osmocom_data.h129
-rw-r--r--Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/sap_interface.h11
-rw-r--r--Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/sim.h274
-rw-r--r--Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/sysinfo.h158
12 files changed, 985 insertions, 0 deletions
diff --git a/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/Makefile.am b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/Makefile.am
new file mode 100644
index 0000000..26e63cf
--- /dev/null
+++ b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/Makefile.am
@@ -0,0 +1,2 @@
+noinst_HEADERS = l1ctl.h l1l2_interface.h l23_app.h lapdm.h logging.h \
+ networks.h gps.h sysinfo.h osmocom_data.h
diff --git a/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/gps.h b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/gps.h
new file mode 100644
index 0000000..58c0c53
--- /dev/null
+++ b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/gps.h
@@ -0,0 +1,53 @@
+/*
+ * (C) 2010 by Andreas Eversberg <jolly@eversberg.eu>
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+enum {
+ GPS_TYPE_UNDEF,
+ GPS_TYPE_GPSD,
+ GPS_TYPE_SERIAL
+};
+
+struct osmo_gps {
+ /* GPS device */
+ uint8_t enable;
+ uint8_t gps_type;
+
+#ifdef _HAVE_GPSD
+ char gpsd_host[32];
+ char gpsd_port[6];
+#endif
+
+ char device[32];
+ uint32_t baud;
+
+ /* current data */
+ uint8_t valid; /* we have a fix */
+ time_t gmt; /* GMT time when position was received */
+ double latitude, longitude;
+};
+
+extern struct osmo_gps g;
+
+int osmo_gps_open(void);
+void osmo_gps_close(void);
+void osmo_gps_init(void);
+
+
diff --git a/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/l1ctl.h b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/l1ctl.h
new file mode 100644
index 0000000..5ebea96
--- /dev/null
+++ b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/l1ctl.h
@@ -0,0 +1,76 @@
+#ifndef osmocom_l1ctl_h
+#define osmocom_l1ctl_h
+
+#include <osmocom/core/msgb.h>
+#include <osmocom/bb/common/osmocom_data.h>
+
+struct osmocom_ms;
+
+/* Receive incoming data from L1 using L1CTL format */
+int l1ctl_recv(struct osmocom_ms *ms, struct msgb *msg);
+
+/* Transmit L1CTL_DATA_REQ */
+int l1ctl_tx_data_req(struct osmocom_ms *ms, struct msgb *msg, uint8_t chan_nr,
+ uint8_t link_id);
+
+/* Transmit L1CTL_PARAM_REQ */
+int l1ctl_tx_param_req(struct osmocom_ms *ms, uint8_t ta, uint8_t tx_power);
+
+int l1ctl_tx_crypto_req(struct osmocom_ms *ms, uint8_t algo, uint8_t *key,
+ uint8_t len);
+
+/* Transmit L1CTL_RACH_REQ */
+int l1ctl_tx_rach_req(struct osmocom_ms *ms, uint8_t ra, uint16_t offset,
+ uint8_t combined);
+
+/* Transmit L1CTL_DM_EST_REQ */
+int l1ctl_tx_dm_est_req_h0(struct osmocom_ms *ms, uint16_t band_arfcn,
+ uint8_t chan_nr, uint8_t tsc, uint8_t tch_mode, uint8_t audio_mode);
+int l1ctl_tx_dm_est_req_h1(struct osmocom_ms *ms, uint8_t maio, uint8_t hsn,
+ uint16_t *ma, uint8_t ma_len, uint8_t chan_nr, uint8_t tsc,
+ uint8_t tch_mode, uint8_t audio_mode);
+
+/* Transmit L1CTL_DM_FREQ_REQ */
+int l1ctl_tx_dm_freq_req_h0(struct osmocom_ms *ms, uint16_t band_arfcn,
+ uint8_t tsc, uint16_t fn);
+int l1ctl_tx_dm_freq_req_h1(struct osmocom_ms *ms, uint8_t maio, uint8_t hsn,
+ uint16_t *ma, uint8_t ma_len, uint8_t tsc, uint16_t fn);
+
+/* Transmit L1CTL_DM_REL_REQ */
+int l1ctl_tx_dm_rel_req(struct osmocom_ms *ms);
+
+/* Transmit FBSB_REQ */
+int l1ctl_tx_fbsb_req(struct osmocom_ms *ms, uint16_t arfcn,
+ uint8_t flags, uint16_t timeout, uint8_t sync_info_idx,
+ uint8_t ccch_mode);
+
+/* Transmit CCCH_MODE_REQ */
+int l1ctl_tx_ccch_mode_req(struct osmocom_ms *ms, uint8_t ccch_mode);
+
+/* Transmit TCH_MODE_REQ */
+int l1ctl_tx_tch_mode_req(struct osmocom_ms *ms, uint8_t tch_mode,
+ uint8_t audio_mode);
+
+/* Transmit ECHO_REQ */
+int l1ctl_tx_echo_req(struct osmocom_ms *ms, unsigned int len);
+
+/* Transmit L1CTL_RESET_REQ */
+int l1ctl_tx_reset_req(struct osmocom_ms *ms, uint8_t type);
+
+/* Transmit L1CTL_PM_REQ */
+int l1ctl_tx_pm_req_range(struct osmocom_ms *ms, uint16_t arfcn_from,
+ uint16_t arfcm_to);
+
+int l1ctl_tx_sim_req(struct osmocom_ms *ms, uint8_t *data, uint16_t length);
+
+/* Transmit L1CTL_VOICE_REQ */
+int l1ctl_tx_traffic_req(struct osmocom_ms *ms, struct msgb *msg,
+ uint8_t chan_nr, uint8_t link_id);
+
+/* LAPDm wants to send a PH-* primitive to the physical layer (L1) */
+int l1ctl_ph_prim_cb(struct osmo_prim_hdr *oph, void *ctx);
+
+/* Transmit L1CTL_NEIGH_PM_REQ */
+int l1ctl_tx_neigh_pm_req(struct osmocom_ms *ms, int num, uint16_t *arfcn);
+
+#endif
diff --git a/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/l1l2_interface.h b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/l1l2_interface.h
new file mode 100644
index 0000000..41403d8
--- /dev/null
+++ b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/l1l2_interface.h
@@ -0,0 +1,8 @@
+#ifndef _L1L2_INTERFACE_H
+#define _L1L2_INTERFACE_H
+
+int layer2_open(struct osmocom_ms *ms, const char *socket_path);
+int layer2_close(struct osmocom_ms *ms);
+int osmo_send_l1(struct osmocom_ms *ms, struct msgb *msg);
+
+#endif /* _L1L2_INTERFACE_H */
diff --git a/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/l23_app.h b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/l23_app.h
new file mode 100644
index 0000000..e4c5d55
--- /dev/null
+++ b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/l23_app.h
@@ -0,0 +1,35 @@
+#ifndef _L23_APP_H
+#define _L23_APP_H
+
+struct option;
+
+/* Options supported by the l23 app */
+enum {
+ L23_OPT_SAP = 1,
+ L23_OPT_ARFCN = 2,
+ L23_OPT_TAP = 4,
+ L23_OPT_VTY = 8,
+ L23_OPT_DBG = 16,
+};
+
+/* initialization, called once when starting the app, before entering
+ * select loop */
+extern int l23_app_init(struct osmocom_ms *ms);
+extern int (*l23_app_work) (struct osmocom_ms *ms);
+extern int (*l23_app_exit) (struct osmocom_ms *ms);
+
+/* configuration options */
+struct l23_app_info {
+ const char *copyright;
+ const char *contribution;
+
+ char *getopt_string;
+ int (*cfg_supported)();
+ int (*cfg_print_help)();
+ int (*cfg_getopt_opt)(struct option **options);
+ int (*cfg_handle_opt)(int c,const char *optarg);
+};
+
+extern struct l23_app_info *l23_app_info();
+
+#endif /* _L23_APP_H */
diff --git a/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/lapdm.h b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/lapdm.h
new file mode 100644
index 0000000..2e78aee
--- /dev/null
+++ b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/lapdm.h
@@ -0,0 +1,186 @@
+#ifndef _OSMOCOM_LAPDM_H
+#define _OSMOCOM_LAPDM_H
+
+#include <stdint.h>
+
+#include <osmocom/core/timer.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/gsm/prim.h>
+
+/* primitive related sutff */
+
+enum osmo_ph_prim {
+ PRIM_PH_DATA, /* PH-DATA */
+ PRIM_PH_RACH, /* PH-RANDOM_ACCESS */
+ PRIM_PH_CONN, /* PH-CONNECT */
+ PRIM_PH_EMPTY_FRAME, /* PH-EMPTY_FRAME */
+ PRIM_PH_RTS, /* PH-RTS */
+};
+
+/* for PH-RANDOM_ACCESS.req */
+struct ph_rach_req_param {
+ uint8_t ra;
+ uint8_t ta;
+ uint8_t tx_power;
+ uint8_t is_combined_ccch;
+ uint16_t offset;
+};
+
+/* for PH-RANDOM_ACCESS.ind */
+struct ph_rach_ind_param {
+ uint8_t ra;
+ uint8_t acc_delay;
+ uint32_t fn;
+};
+
+/* for PH-[UNIT]DATA.{req,ind} */
+struct ph_data_param {
+ uint8_t link_id;
+ uint8_t chan_nr;
+};
+
+struct ph_conn_ind_param {
+ uint32_t fn;
+};
+
+struct osmo_phsap_prim {
+ struct osmo_prim_hdr oph;
+ union {
+ struct ph_data_param data;
+ struct ph_rach_req_param rach_req;
+ struct ph_rach_ind_param rach_ind;
+ struct ph_conn_ind_param conn_ind;
+ } u;
+};
+
+enum lapdm_mode {
+ LAPDM_MODE_MS,
+ LAPDM_MODE_BTS,
+};
+
+enum lapdm_state {
+ LAPDm_STATE_NULL = 0,
+ LAPDm_STATE_IDLE,
+ LAPDm_STATE_SABM_SENT,
+ LAPDm_STATE_MF_EST,
+ LAPDm_STATE_TIMER_RECOV,
+ LAPDm_STATE_DISC_SENT,
+};
+
+struct lapdm_entity;
+
+struct lapdm_msg_ctx {
+ struct lapdm_datalink *dl;
+ int lapdm_fmt;
+ uint8_t n201;
+ uint8_t chan_nr;
+ uint8_t link_id;
+ uint8_t addr;
+ uint8_t ctrl;
+ uint8_t ta_ind;
+ uint8_t tx_power_ind;
+};
+
+/* TS 04.06 / Section 3.5.2 */
+struct lapdm_datalink {
+ uint8_t V_send; /* seq nr of next I frame to be transmitted */
+ uint8_t V_ack; /* last frame ACKed by peer */
+ uint8_t N_send; /* ? set to V_send at Tx time*/
+ uint8_t V_recv; /* seq nr of next I frame expected to be received */
+ uint8_t N_recv; /* expected send seq nr of the next received I frame */
+ uint32_t state;
+ int seq_err_cond; /* condition of sequence error */
+ uint8_t own_busy, peer_busy;
+ struct osmo_timer_list t200;
+ uint8_t retrans_ctr;
+ struct llist_head send_queue; /* frames from L3 */
+ struct msgb *send_buffer; /* current frame transmitting */
+ int send_out; /* how much was sent from send_buffer */
+ uint8_t tx_hist[8][200]; /* tx history buffer */
+ int tx_length[8]; /* length in history buffer */
+ struct llist_head tx_queue; /* frames to L1 */
+ struct lapdm_msg_ctx mctx; /* context of established connection */
+ struct msgb *rcv_buffer; /* buffer to assemble the received message */
+
+ struct lapdm_entity *entity;
+};
+
+enum lapdm_dl_sapi {
+ DL_SAPI0 = 0,
+ DL_SAPI3 = 1,
+ _NR_DL_SAPI
+};
+
+typedef int (*lapdm_cb_t)(struct msgb *msg, struct lapdm_entity *le, void *ctx);
+
+struct lapdm_cr_ent {
+ uint8_t cmd;
+ uint8_t resp;
+};
+
+#define LAPDM_ENT_F_EMPTY_FRAME 0x0001
+#define LAPDM_ENT_F_POLLING_ONLY 0x0002
+
+/* register message handler for messages that are sent from L2->L3 */
+struct lapdm_entity {
+ struct lapdm_datalink datalink[_NR_DL_SAPI];
+ int last_tx_dequeue; /* last entity that was dequeued */
+ int tx_pending; /* currently a pending frame not confirmed by L1 */
+ enum lapdm_mode mode; /* are we in BTS mode or MS mode */
+ unsigned int flags;
+
+ struct {
+ /* filled-in once we set the lapdm_mode above */
+ struct lapdm_cr_ent loc2rem;
+ struct lapdm_cr_ent rem2loc;
+ } cr;
+
+ void *l1_ctx; /* context for layer1 instance */
+ void *l3_ctx; /* context for layer3 instance */
+
+ osmo_prim_cb l1_prim_cb;
+ lapdm_cb_t l3_cb; /* callback for sending stuff to L3 */
+
+ struct lapdm_channel *lapdm_ch;
+};
+
+/* the two lapdm_entities that form a GSM logical channel (ACCH + DCCH) */
+struct lapdm_channel {
+ struct llist_head list;
+ char *name;
+ struct lapdm_entity lapdm_acch;
+ struct lapdm_entity lapdm_dcch;
+};
+
+const char *get_rsl_name(int value);
+extern const char *lapdm_state_names[];
+
+/* initialize a LAPDm entity */
+void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode);
+void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode);
+
+/* deinitialize a LAPDm entity */
+void lapdm_entity_exit(struct lapdm_entity *le);
+void lapdm_channel_exit(struct lapdm_channel *lc);
+
+/* input into layer2 (from layer 1) */
+int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le);
+
+/* input into layer2 (from layer 3) */
+int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc);
+
+void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx);
+void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx);
+
+int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode);
+int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode);
+
+void lapdm_entity_reset(struct lapdm_entity *le);
+void lapdm_channel_reset(struct lapdm_channel *lc);
+
+void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags);
+void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags);
+
+int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp);
+
+#endif /* _OSMOCOM_LAPDM_H */
diff --git a/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/logging.h b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/logging.h
new file mode 100644
index 0000000..554b767
--- /dev/null
+++ b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/logging.h
@@ -0,0 +1,29 @@
+#ifndef _LOGGING_H
+#define _LOGGING_H
+
+#define DEBUG
+#include <osmocom/core/logging.h>
+
+enum {
+ DRSL,
+ DRR,
+ DPLMN,
+ DCS,
+ DNB,
+ DMM,
+ DCC,
+ DSMS,
+ DMNCC,
+ DMEAS,
+ DPAG,
+ DLAPDM,
+ DL1C,
+ DSAP,
+ DSUM,
+ DSIM,
+ DGPS,
+};
+
+extern const struct log_info log_info;
+
+#endif /* _LOGGING_H */
diff --git a/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/networks.h b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/networks.h
new file mode 100644
index 0000000..e681216
--- /dev/null
+++ b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/networks.h
@@ -0,0 +1,24 @@
+#ifndef _NETWORKS_H
+#define _NETWORKS_H
+
+#define GSM_INPUT_INVALID 0xffff
+
+struct gsm_networks {
+ uint16_t mcc;
+ int16_t mnc;
+ const char *name;
+};
+
+int gsm_match_mcc(uint16_t mcc, char *imsi);
+int gsm_match_mnc(uint16_t mcc, uint8_t mnc, char *imsi);
+const char *gsm_print_mcc(uint16_t mcc);
+const char *gsm_print_mnc(uint16_t mcc);
+const char *gsm_get_mcc(uint16_t mcc);
+const char *gsm_get_mnc(uint16_t mcc, uint16_t mnc);
+const char *gsm_imsi_mcc(char *imsi);
+const char *gsm_imsi_mnc(char *imsi);
+const uint16_t gsm_input_mcc(char *string);
+const uint16_t gsm_input_mnc(char *string);
+
+#endif /* _NETWORKS_H */
+
diff --git a/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/osmocom_data.h b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/osmocom_data.h
new file mode 100644
index 0000000..6ad89cd
--- /dev/null
+++ b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/osmocom_data.h
@@ -0,0 +1,129 @@
+#ifndef osmocom_data_h
+#define osmocom_data_h
+
+#include <osmocom/core/select.h>
+#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/core/write_queue.h>
+
+struct osmocom_ms;
+
+ /* 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/bb/common/lapdm.h>
+#include <osmocom/bb/common/sap_interface.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/common/sim.h>
+#include <osmocom/bb/common/l1ctl.h>
+
+struct osmosap_entity {
+ osmosap_cb_t msg_handler;
+};
+
+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);
+ 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;
+};
+
+/* One Mobilestation for osmocom */
+struct osmocom_ms {
+ struct llist_head entity;
+ char name[32];
+ struct osmo_wqueue l2_wq, sap_wq;
+ uint16_t test_arfcn;
+ struct osmol1_entity l1_entity;
+
+ uint8_t deleting, shutdown, started;
+ 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;
+};
+
+enum osmobb_sig_subsys {
+ SS_L1CTL,
+ SS_GLOBAL,
+};
+
+enum osmobb_l1ctl_sig {
+ S_L1CTL_FBSB_ERR,
+ S_L1CTL_FBSB_RESP,
+ S_L1CTL_RESET,
+ S_L1CTL_PM_RES,
+ S_L1CTL_PM_DONE,
+ S_L1CTL_CCCH_MODE_CONF,
+ S_L1CTL_TCH_MODE_CONF,
+ S_L1CTL_LOSS_IND,
+ S_L1CTL_NEIGH_PM_IND,
+};
+
+enum osmobb_global_sig {
+ S_GLOBAL_SHUTDOWN,
+};
+
+struct osmobb_fbsb_res {
+ struct osmocom_ms *ms;
+ int8_t snr;
+ uint8_t bsic;
+ uint16_t band_arfcn;
+};
+
+struct osmobb_meas_res {
+ struct osmocom_ms *ms;
+ uint16_t band_arfcn;
+ uint8_t rx_lev;
+};
+
+struct osmobb_ccch_mode_conf {
+ struct osmocom_ms *ms;
+ uint8_t ccch_mode;
+};
+
+struct osmobb_tch_mode_conf {
+ struct osmocom_ms *ms;
+ uint8_t tch_mode;
+ uint8_t audio_mode;
+};
+
+struct osmobb_neigh_pm_ind {
+ struct osmocom_ms *ms;
+ uint16_t band_arfcn;
+ uint8_t rx_lev;
+};
+
+#endif
diff --git a/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/sap_interface.h b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/sap_interface.h
new file mode 100644
index 0000000..f2f577a
--- /dev/null
+++ b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/sap_interface.h
@@ -0,0 +1,11 @@
+#ifndef _SAP_INTERFACE_H
+#define _SAP_INTERFACE_H
+
+typedef int (*osmosap_cb_t)(struct msgb *msg, struct osmocom_ms *ms);
+
+int sap_open(struct osmocom_ms *ms, const char *socket_path);
+int sap_close(struct osmocom_ms *ms);
+int osmosap_send(struct osmocom_ms *ms, struct msgb *msg);
+int osmosap_register_handler(struct osmocom_ms *ms, osmosap_cb_t cb);
+
+#endif /* _SAP_INTERFACE_H */
diff --git a/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/sim.h b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/sim.h
new file mode 100644
index 0000000..a676b92
--- /dev/null
+++ b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/sim.h
@@ -0,0 +1,274 @@
+/*
+ * (C) 2010 by Andreas Eversberg <jolly@eversberg.eu>
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+
+/* 9.2 commands */
+#define GSM1111_CLASS_GSM 0xa0
+#define GSM1111_INST_SELECT 0xa4
+#define GSM1111_INST_STATUS 0xf2
+#define GSM1111_INST_READ_BINARY 0xb0
+#define GSM1111_INST_UPDATE_BINARY 0xd6
+#define GSM1111_INST_READ_RECORD 0xb2
+#define GSM1111_INST_UPDATE_RECORD 0xdc
+#define GSM1111_INST_SEEK 0xa2
+#define GSM1111_INST_INCREASE 0x32
+#define GSM1111_INST_VERIFY_CHV 0x20
+#define GSM1111_INST_CHANGE_CHV 0x24
+#define GSM1111_INST_DISABLE_CHV 0x26
+#define GSM1111_INST_ENABLE_CHV 0x28
+#define GSM1111_INST_UNBLOCK_CHV 0x2c
+#define GSM1111_INST_INVALIDATE 0x04
+#define GSM1111_INST_REHABLILITATE 0x44
+#define GSM1111_INST_RUN_GSM_ALGO 0x88
+#define GSM1111_INST_SLEEP 0xfa
+#define GSM1111_INST_GET_RESPONSE 0xc0
+#define GSM1111_INST_TERMINAL_PROFILE 0x10
+#define GSM1111_INST_ENVELOPE 0xc2
+#define GSM1111_INST_FETCH 0x12
+#define GSM1111_INST_TERMINAL_RESPONSE 0x14
+
+/* 9.3 access conditions */
+#define GSM1111_ACC_ALWAYS 0x0
+#define GSM1111_ACC_CHV1 0x1
+#define GSM1111_ACC_CHV2 0x2
+#define GSM1111_ACC_RFU 0x3
+#define GSM1111_ACC_NEW 0xf
+/* others are ADM */
+
+/* 9.3 type of file */
+#define GSM1111_TOF_RFU 0x00
+#define GSM1111_TOF_MF 0x01
+#define GSM1111_TOF_DF 0x02
+#define GSM1111_TOF_EF 0x04
+
+/* 9.3 struct of file */
+#define GSM1111_SOF_TRANSPARENT 0x00
+#define GSM1111_SOF_LINEAR 0x01
+#define GSM1111_SOF_CYCLIC 0x03
+
+/* 9.4 status */
+#define GSM1111_STAT_NORMAL 0x90
+#define GSM1111_STAT_PROACTIVE 0x91
+#define GSM1111_STAT_DL_ERROR 0x9e
+#define GSM1111_STAT_RESPONSE 0x9f
+#define GSM1111_STAT_RESPONSE_TOO 0x61
+#define GSM1111_STAT_APP_TK_BUSY 0x93
+#define GSM1111_STAT_MEM_PROBLEM 0x92
+#define GSM1111_STAT_REFERENCING 0x94
+#define GSM1111_STAT_SECURITY 0x98
+#define GSM1111_STAT_INCORR_P3 0x67
+#define GSM1111_STAT_INCORR_P1_P2 0x6b
+#define GSM1111_STAT_UKN_INST 0x6d
+#define GSM1111_STAT_WRONG_CLASS 0x6e
+#define GSM1111_STAT_TECH_PROBLEM 0x6f
+
+/* 9.4.4 Referencing management SW2 */
+#define GSM1111_REF_NO_EF 0x00
+#define GSM1111_REF_OUT_OF_RANGE 0x02
+#define GSM1111_REF_FILE_NOT_FOUND 0x04
+#define GSM1111_REF_FILE_INCONSI 0x08
+
+/* 9.4.5 Security management SW2 */
+#define GSM1111_SEC_NO_CHV 0x02
+#define GSM1111_SEC_NO_ACCESS 0x04
+#define GSM1111_SEC_CONTRA_CHV 0x08
+#define GSM1111_SEC_CONTRA_INVAL 0x10
+#define GSM1111_SEC_BLOCKED 0x40
+#define GSM1111_SEC_MAX_VALUE 0x50
+
+/* messages from application to sim client */
+enum {
+ /* requests */
+ SIM_JOB_READ_BINARY,
+ SIM_JOB_UPDATE_BINARY,
+ SIM_JOB_READ_RECORD,
+ SIM_JOB_UPDATE_RECORD,
+ SIM_JOB_SEEK_RECORD,
+ SIM_JOB_INCREASE,
+ SIM_JOB_INVALIDATE,
+ SIM_JOB_REHABILITATE,
+ SIM_JOB_RUN_GSM_ALGO,
+ SIM_JOB_PIN1_UNLOCK,
+ SIM_JOB_PIN1_CHANGE,
+ SIM_JOB_PIN1_DISABLE,
+ SIM_JOB_PIN1_ENABLE,
+ SIM_JOB_PIN1_UNBLOCK,
+ SIM_JOB_PIN2_UNLOCK,
+ SIM_JOB_PIN2_CHANGE,
+ SIM_JOB_PIN2_UNBLOCK,
+
+ /* results */
+ SIM_JOB_OK,
+ SIM_JOB_ERROR,
+};
+
+/* messages from sim client to application */
+#define SIM_JOB_OK 0
+#define SIM_JOB_ERROR 1
+
+/* error causes */
+#define SIM_CAUSE_NO_SIM 0 /* no SIM present, if detectable */
+#define SIM_CAUSE_SIM_ERROR 1 /* any error while reading SIM */
+#define SIM_CAUSE_REQUEST_ERROR 2 /* error in request */
+#define SIM_CAUSE_PIN1_REQUIRED 3 /* CHV1 is required for access */
+#define SIM_CAUSE_PIN2_REQUIRED 4 /* CHV2 is required for access */
+#define SIM_CAUSE_PIN1_BLOCKED 5 /* CHV1 was entered too many times */
+#define SIM_CAUSE_PIN2_BLOCKED 6 /* CHV2 was entered too many times */
+#define SIM_CAUSE_PUC_BLOCKED 7 /* unblock entered too many times */
+
+/* job states */
+enum {
+ SIM_JST_IDLE = 0,
+ SIM_JST_SELECT_MFDF, /* SELECT sent */
+ SIM_JST_SELECT_MFDF_RESP, /* GET RESPONSE sent */
+ SIM_JST_SELECT_EF, /* SELECT sent */
+ SIM_JST_SELECT_EF_RESP, /* GET RESPONSE sent */
+ SIM_JST_WAIT_FILE, /* file command sent */
+ SIM_JST_RUN_GSM_ALGO, /* wait for algorithm to process */
+ SIM_JST_RUN_GSM_ALGO_RESP, /* wait for response */
+ SIM_JST_PIN1_UNLOCK,
+ SIM_JST_PIN1_CHANGE,
+ SIM_JST_PIN1_DISABLE,
+ SIM_JST_PIN1_ENABLE,
+ SIM_JST_PIN1_UNBLOCK,
+ SIM_JST_PIN2_UNLOCK,
+ SIM_JST_PIN2_CHANGE,
+ SIM_JST_PIN2_UNBLOCK,
+};
+
+#define MAX_SIM_PATH_LENGTH 6 + 1 /* one for the termination */
+
+struct gsm_sim_handler {
+ struct llist_head entry;
+
+ uint32_t handle;
+ void (*cb)(struct osmocom_ms *ms, struct msgb *msg);
+};
+
+struct gsm_sim {
+ struct llist_head handlers; /* gsm_sim_handler */
+ struct llist_head jobs; /* messages */
+ uint16_t path[MAX_SIM_PATH_LENGTH];
+ uint16_t file;
+
+ struct msgb *job_msg;
+ uint32_t job_handle;
+ int job_state;
+
+ uint8_t reset;
+ uint8_t chv1_remain, chv2_remain;
+ uint8_t unblk1_remain, unblk2_remain;
+};
+
+struct sim_hdr {
+ int handle;
+ uint8_t job_type;
+ uint16_t path[MAX_SIM_PATH_LENGTH];
+ uint16_t file;
+ uint8_t rec_no, rec_mode; /* in case of record */
+ uint8_t seek_type_mode; /* in case of seek command */
+};
+
+#define SIM_ALLOC_SIZE 512
+#define SIM_ALLOC_HEADROOM 64
+
+struct msgb *gsm_sim_msgb_alloc(uint32_t handle, uint8_t job_type);
+uint32_t sim_open(struct osmocom_ms *ms,
+ void (*cb)(struct osmocom_ms *ms, struct msgb *msg));
+void sim_close(struct osmocom_ms *ms, uint32_t handle);
+void sim_job(struct osmocom_ms *ms, struct msgb *msg);
+
+/* Section 9.2.1 (response to selecting DF or MF) */
+struct gsm1111_response_mfdf {
+ uint16_t rfu1;
+ uint16_t free_mem;
+ uint16_t file_id;
+ uint8_t tof;
+ uint8_t rfu2[5];
+ uint8_t length;
+ uint8_t gsm_data[0];
+} __attribute__ ((packed));
+
+struct gsm1111_response_mfdf_gsm {
+ uint8_t file_char;
+ uint8_t num_df;
+ uint8_t num_ef;
+ uint8_t num_codes;
+ uint8_t rfu1;
+ uint8_t chv1_remain:4,
+ rfu2:3,
+ chv1_init:1;
+ uint8_t unblk1_remain:4,
+ rfu3:3,
+ unblk1_init:1;
+ uint8_t chv2_remain:4,
+ rfu4:3,
+ chv2_init:1;
+ uint8_t unblk2_remain:4,
+ rfu5:3,
+ unblk2_init:1;
+ uint8_t more_data[0];
+} __attribute__ ((packed));
+
+/* Section 9.2.1 (response to selecting EF) */
+struct gsm1111_response_ef {
+ uint16_t rfu1;
+ uint16_t file_size;
+ uint16_t file_id;
+ uint8_t tof;
+ uint8_t inc_allowed;
+ uint8_t acc_update:4,
+ acc_read:4;
+ uint8_t rfu2:4,
+ acc_inc:4;
+ uint8_t acc_inval:4,
+ acc_reha:4;
+ uint8_t not_inval:1,
+ rfu3:1,
+ ru_inval:1,
+ rfu4:5;
+ uint8_t length;
+ uint8_t structure;
+} __attribute__ ((packed));
+
+/* Section 10.3.17 */
+struct gsm1111_ef_loci {
+ uint32_t tmsi;
+ struct gsm48_loc_area_id lai;
+ uint8_t tmsi_time;
+ uint8_t lupd_status;
+} __attribute__ ((packed));
+
+/* Section 10.5.1 */
+struct gsm1111_ef_adn {
+ uint8_t len_bcd;
+ uint8_t ton_npi;
+ uint8_t number[10];
+ uint8_t capa_conf;
+ uint8_t ext_id;
+} __attribute__ ((packed));
+
+int sim_apdu_resp(struct osmocom_ms *ms, struct msgb *msg);
+int gsm_sim_init(struct osmocom_ms *ms);
+int gsm_sim_exit(struct osmocom_ms *ms);
+int gsm_sim_job_dequeue(struct osmocom_ms *ms);
+
+
diff --git a/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/sysinfo.h b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/sysinfo.h
new file mode 100644
index 0000000..5d3ed59
--- /dev/null
+++ b/Src/osmoconbb/src/host/layer23/include/osmocom/bb/common/sysinfo.h
@@ -0,0 +1,158 @@
+#ifndef _SYSINFO_H
+#define _SYSINFO_H
+
+#include <osmocom/gsm/gsm48_ie.h>
+
+/* collection of system information of the current cell */
+
+/* frequency mask flags of frequency type */
+#define FREQ_TYPE_SERV 0x01 /* frequency of the serving cell */
+#define FREQ_TYPE_HOPP 0x02 /* frequency used for channel hopping */
+#define FREQ_TYPE_NCELL 0x1c /* frequency of the neighbor cell */
+#define FREQ_TYPE_NCELL_2 0x04 /* sub channel of SI 2 */
+#define FREQ_TYPE_NCELL_2bis 0x08 /* sub channel of SI 2bis */
+#define FREQ_TYPE_NCELL_2ter 0x10 /* sub channel of SI 2ter */
+#define FREQ_TYPE_REP 0xe0 /* frequency to be reported */
+#define FREQ_TYPE_REP_5 0x20 /* sub channel of SI 5 */
+#define FREQ_TYPE_REP_5bis 0x40 /* sub channel of SI 5bis */
+#define FREQ_TYPE_REP_5ter 0x80 /* sub channel of SI 5ter */
+
+/* structure of all received system informations */
+struct gsm48_sysinfo {
+ /* flags of available information */
+ uint8_t si1, si2, si2bis, si2ter, si3,
+ si4, si5, si5bis, si5ter, si6;
+
+ /* memory maps to simply detect change in system info messages */
+ uint8_t si1_msg[23];
+ uint8_t si2_msg[23];
+ uint8_t si2b_msg[23];
+ uint8_t si2t_msg[23];
+ uint8_t si3_msg[23];
+ uint8_t si4_msg[23];
+ uint8_t si5_msg[18];
+ uint8_t si5b_msg[18];
+ uint8_t si5t_msg[18];
+ uint8_t si6_msg[18];
+
+ struct gsm_sysinfo_freq freq[1024]; /* all frequencies */
+ uint16_t hopping[64]; /* hopping arfcn */
+ uint8_t hopp_len;
+
+ /* serving cell */
+ uint8_t bsic;
+ uint16_t cell_id;
+ uint16_t mcc, mnc, lac; /* LAI */
+ uint8_t max_retrans; /* decoded */
+ uint8_t tx_integer; /* decoded */
+ uint8_t reest_denied; /* 1 = denied */
+ uint8_t cell_barr; /* 1 = barred */
+ uint16_t class_barr; /* bit 10 is emergency */
+
+ /* si1 rest */
+ uint8_t nch;
+ uint8_t nch_position;
+ uint8_t band_ind; /* set for DCS */
+
+ /* si3 rest */
+ uint8_t sp;
+ uint8_t sp_cbq;
+ uint8_t sp_cro;
+ uint8_t sp_to;
+ uint8_t sp_pt;
+ uint8_t po;
+ uint8_t po_value;
+ uint8_t si2ter_ind;
+ uint8_t ecsm;
+ uint8_t sched;
+ uint8_t sched_where;
+ uint8_t gprs;
+ uint8_t gprs_ra_colour;
+ uint8_t gprs_si13_pos;
+
+ /* cell selection */
+ int8_t ms_txpwr_max_cch;
+ int8_t cell_resel_hyst_db;
+ int8_t rxlev_acc_min_db;
+ uint8_t neci;
+ uint8_t acs;
+ /* bcch options */
+ uint8_t bcch_radio_link_timeout;
+ uint8_t bcch_dtx;
+ uint8_t bcch_pwrc;
+ /* sacch options */
+ uint8_t sacch_radio_link_timeout;
+ uint8_t sacch_dtx;
+ uint8_t sacch_pwrc;
+ /* control channel */
+ uint8_t ccch_conf;
+ uint8_t bs_ag_blks_res;
+ uint8_t att_allowed;
+ uint8_t pag_mf_periods;
+ int32_t t3212; /* real value in seconds */
+ /* channel description */
+ uint8_t tsc;
+ uint8_t h; /* using hopping */
+ uint16_t arfcn;
+ uint8_t maio;
+ uint8_t hsn;
+ uint8_t chan_nr; /* type, slot, sub slot */
+
+ /* neighbor cell */
+ uint8_t nb_ext_ind_si2;
+ uint8_t nb_ba_ind_si2;
+ uint8_t nb_ext_ind_si2bis;
+ uint8_t nb_ba_ind_si2bis;
+ uint8_t nb_multi_rep_si2ter; /* see GSM 05.08 8.4.3 */
+ uint8_t nb_ba_ind_si2ter;
+ uint8_t nb_ext_ind_si5;
+ uint8_t nb_ba_ind_si5;
+ uint8_t nb_ext_ind_si5bis;
+ uint8_t nb_ba_ind_si5bis;
+ uint8_t nb_multi_rep_si5ter;
+ uint8_t nb_ba_ind_si5ter;
+ uint8_t nb_ncc_permitted_si2;
+ uint8_t nb_ncc_permitted_si6;
+ uint8_t nb_max_retrans; /* decoded */
+ uint8_t nb_tx_integer; /* decoded */
+ uint8_t nb_reest_denied; /* 1 = denied */
+ uint8_t nb_cell_barr; /* 1 = barred */
+ uint16_t nb_class_barr; /* bit 10 is emergency */
+};
+
+char *gsm_print_arfcn(uint16_t arfcn);
+uint8_t gsm_refer_pcs(uint16_t arfcn, struct gsm48_sysinfo *s);
+int gsm48_sysinfo_dump(struct gsm48_sysinfo *s, uint16_t arfcn,
+ void (*print)(void *, const char *, ...), void *priv,
+ uint8_t *freq_map);
+int gsm48_decode_lai(struct gsm48_loc_area_id *lai, uint16_t *mcc,
+ uint16_t *mnc, uint16_t *lac);
+int gsm48_decode_chan_h0(struct gsm48_chan_desc *cd, uint8_t *tsc,
+ uint16_t *arfcn);
+int gsm48_decode_chan_h1(struct gsm48_chan_desc *cd, uint8_t *tsc,
+ uint8_t *maio, uint8_t *hsn);
+int gsm48_decode_sysinfo1(struct gsm48_sysinfo *s,
+ struct gsm48_system_information_type_1 *si, int len);
+int gsm48_decode_sysinfo2(struct gsm48_sysinfo *s,
+ struct gsm48_system_information_type_2 *si, int len);
+int gsm48_decode_sysinfo2bis(struct gsm48_sysinfo *s,
+ struct gsm48_system_information_type_2bis *si, int len);
+int gsm48_decode_sysinfo2ter(struct gsm48_sysinfo *s,
+ struct gsm48_system_information_type_2ter *si, int len);
+int gsm48_decode_sysinfo3(struct gsm48_sysinfo *s,
+ struct gsm48_system_information_type_3 *si, int len);
+int gsm48_decode_sysinfo4(struct gsm48_sysinfo *s,
+ struct gsm48_system_information_type_4 *si, int len);
+int gsm48_decode_sysinfo5(struct gsm48_sysinfo *s,
+ struct gsm48_system_information_type_5 *si, int len);
+int gsm48_decode_sysinfo5bis(struct gsm48_sysinfo *s,
+ struct gsm48_system_information_type_5bis *si, int len);
+int gsm48_decode_sysinfo5ter(struct gsm48_sysinfo *s,
+ struct gsm48_system_information_type_5ter *si, int len);
+int gsm48_decode_sysinfo6(struct gsm48_sysinfo *s,
+ struct gsm48_system_information_type_6 *si, int len);
+int gsm48_decode_mobile_alloc(struct gsm_sysinfo_freq *freq,
+ uint8_t *ma, uint8_t len, uint16_t *hopping, uint8_t *hopp_len,
+ int si4);
+
+#endif /* _SYSINFO_H */