aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-12-01 03:37:38 +0100
committerNeels Hofmeyr <neels@hofmeyr.de>2017-12-01 03:37:38 +0100
commit43c30d0e439053881070d5ceb70f46cfecf5c221 (patch)
treeba975a8be418c09ca6b2755a968210e01ca727f5 /include/osmocom
parentce28c210871a248ec6d836adeaa75e2c3c665faf (diff)
RENAME include/openbsc TO include/osmocom/bsc FOR MERGING
Diffstat (limited to 'include/osmocom')
-rw-r--r--include/osmocom/bsc/Makefile.am19
-rw-r--r--include/osmocom/bsc/abis_nm.h186
-rw-r--r--include/osmocom/bsc/abis_om2000.h98
-rw-r--r--include/osmocom/bsc/abis_rsl.h107
-rw-r--r--include/osmocom/bsc/arfcn_range_encode.h26
-rw-r--r--include/osmocom/bsc/auth.h17
-rw-r--r--include/osmocom/bsc/bsc_api.h55
-rw-r--r--include/osmocom/bsc/bsc_msc.h59
-rw-r--r--include/osmocom/bsc/bsc_nat.h480
-rw-r--r--include/osmocom/bsc/bsc_nat_callstats.h55
-rw-r--r--include/osmocom/bsc/bsc_nat_sccp.h101
-rw-r--r--include/osmocom/bsc/bsc_rll.h19
-rw-r--r--include/osmocom/bsc/bss.h18
-rw-r--r--include/osmocom/bsc/chan_alloc.h65
-rw-r--r--include/osmocom/bsc/control_cmd.h163
-rw-r--r--include/osmocom/bsc/control_if.h21
-rw-r--r--include/osmocom/bsc/crc24.h10
-rw-r--r--include/osmocom/bsc/db.h82
-rw-r--r--include/osmocom/bsc/debug.h65
-rw-r--r--include/osmocom/bsc/e1_config.h11
-rw-r--r--include/osmocom/bsc/gb_proxy.h38
-rw-r--r--include/osmocom/bsc/gprs_gmm.h19
-rw-r--r--include/osmocom/bsc/gprs_llc.h202
-rw-r--r--include/osmocom/bsc/gprs_sgsn.h222
-rw-r--r--include/osmocom/bsc/gsm_04_08.h75
-rw-r--r--include/osmocom/bsc/gsm_04_08_gprs.h381
-rw-r--r--include/osmocom/bsc/gsm_04_11.h40
-rw-r--r--include/osmocom/bsc/gsm_04_80.h20
-rw-r--r--include/osmocom/bsc/gsm_data.h408
-rw-r--r--include/osmocom/bsc/gsm_data_shared.h757
-rw-r--r--include/osmocom/bsc/gsm_subscriber.h111
-rw-r--r--include/osmocom/bsc/handover.h17
-rw-r--r--include/osmocom/bsc/handover_decision.h7
-rw-r--r--include/osmocom/bsc/ipaccess.h65
-rw-r--r--include/osmocom/bsc/meas_rep.h87
-rw-r--r--include/osmocom/bsc/mgcp.h203
-rw-r--r--include/osmocom/bsc/mgcp_internal.h172
-rw-r--r--include/osmocom/bsc/misdn.h27
-rw-r--r--include/osmocom/bsc/mncc.h191
-rw-r--r--include/osmocom/bsc/mncc_int.h12
-rw-r--r--include/osmocom/bsc/network_listen.h16
-rw-r--r--include/osmocom/bsc/openbscdefines.h34
-rw-r--r--include/osmocom/bsc/osmo_bsc.h51
-rw-r--r--include/osmocom/bsc/osmo_bsc_grace.h31
-rw-r--r--include/osmocom/bsc/osmo_bsc_rf.h64
-rw-r--r--include/osmocom/bsc/osmo_msc.h11
-rw-r--r--include/osmocom/bsc/osmo_msc_data.h116
-rw-r--r--include/osmocom/bsc/paging.h75
-rw-r--r--include/osmocom/bsc/rest_octets.h132
-rw-r--r--include/osmocom/bsc/rrlp.h7
-rw-r--r--include/osmocom/bsc/rs232.h9
-rw-r--r--include/osmocom/bsc/rtp_proxy.h91
-rw-r--r--include/osmocom/bsc/sgsn.h69
-rw-r--r--include/osmocom/bsc/signal.h244
-rw-r--r--include/osmocom/bsc/silent_call.h12
-rw-r--r--include/osmocom/bsc/sms_queue.h17
-rw-r--r--include/osmocom/bsc/socket.h14
-rw-r--r--include/osmocom/bsc/system_information.h10
-rw-r--r--include/osmocom/bsc/token_auth.h7
-rw-r--r--include/osmocom/bsc/transaction.h75
-rw-r--r--include/osmocom/bsc/trau_mux.h55
-rw-r--r--include/osmocom/bsc/trau_upqueue.h7
-rw-r--r--include/osmocom/bsc/ussd.h10
-rw-r--r--include/osmocom/bsc/vty.h49
64 files changed, 5917 insertions, 0 deletions
diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
new file mode 100644
index 000000000..93b30bb0c
--- /dev/null
+++ b/include/osmocom/bsc/Makefile.am
@@ -0,0 +1,19 @@
+noinst_HEADERS = abis_nm.h abis_rsl.h db.h gsm_04_08.h gsm_data.h \
+ gsm_subscriber.h gsm_04_11.h debug.h signal.h \
+ misdn.h chan_alloc.h paging.h \
+ trau_mux.h rs232.h openbscdefines.h rtp_proxy.h \
+ bsc_rll.h mncc.h transaction.h ussd.h gsm_04_80.h \
+ silent_call.h mgcp.h meas_rep.h rest_octets.h \
+ system_information.h handover.h mgcp_internal.h \
+ vty.h socket.h e1_config.h trau_upqueue.h token_auth.h \
+ handover_decision.h rrlp.h control_if.h \
+ crc24.h gprs_llc.h gprs_gmm.h \
+ gb_proxy.h gprs_sgsn.h gsm_04_08_gprs.h sgsn.h \
+ auth.h osmo_msc.h bsc_msc.h bsc_nat.h \
+ osmo_bsc_rf.h osmo_bsc.h network_listen.h bsc_nat_sccp.h \
+ osmo_msc_data.h osmo_bsc_grace.h sms_queue.h abis_om2000.h \
+ bss.h gsm_data_shared.h control_cmd.h ipaccess.h mncc_int.h \
+ arfcn_range_encode.h
+
+openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h
+openbscdir = $(includedir)/openbsc
diff --git a/include/osmocom/bsc/abis_nm.h b/include/osmocom/bsc/abis_nm.h
new file mode 100644
index 000000000..4d6f866ee
--- /dev/null
+++ b/include/osmocom/bsc/abis_nm.h
@@ -0,0 +1,186 @@
+/* GSM Network Management messages on the A-bis interface
+ * 3GPP TS 12.21 version 8.0.0 Release 1999 / ETSI TS 100 623 V8.0.0 */
+
+/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _NM_H
+#define _NM_H
+
+#include <osmocom/gsm/tlv.h>
+#include <osmocom/gsm/abis_nm.h>
+#include <osmocom/gsm/protocol/gsm_12_21.h>
+
+struct cell_global_id {
+ uint16_t mcc;
+ uint16_t mnc;
+ uint16_t lac;
+ uint16_t ci;
+};
+
+/* The BCCH info from an ip.access test, in host byte order
+ * and already parsed... */
+struct ipac_bcch_info {
+ struct llist_head list;
+
+ uint16_t info_type;
+ uint8_t freq_qual;
+ uint16_t arfcn;
+ uint8_t rx_lev;
+ uint8_t rx_qual;
+ int16_t freq_err;
+ uint16_t frame_offset;
+ uint32_t frame_nr_offset;
+ uint8_t bsic;
+ struct cell_global_id cgi;
+ uint8_t ba_list_si2[16];
+ uint8_t ba_list_si2bis[16];
+ uint8_t ba_list_si2ter[16];
+ uint8_t ca_list_si1[16];
+};
+
+/* PUBLIC */
+
+struct msgb;
+
+struct abis_nm_cfg {
+ /* callback for unidirectional reports */
+ int (*report_cb)(struct msgb *,
+ struct abis_om_fom_hdr *);
+ /* callback for software activate requests from BTS */
+ int (*sw_act_req)(struct msgb *);
+};
+
+struct abis_nm_sw_descr {
+ /* where does it start? how long is it? */
+ const uint8_t *start;
+ size_t len;
+
+ /* the parsed data */
+ const uint8_t *file_id;
+ uint16_t file_id_len;
+ const uint8_t *file_ver;
+ uint16_t file_ver_len;
+};
+
+extern int abis_nm_rcvmsg(struct msgb *msg);
+
+int abis_nm_tlv_parse(struct tlv_parsed *tp, struct gsm_bts *bts, const uint8_t *buf, int len);
+int abis_nm_rx(struct msgb *msg);
+int abis_nm_opstart(struct gsm_bts *bts, uint8_t obj_class, uint8_t i0, uint8_t i1, uint8_t i2);
+int abis_nm_chg_adm_state(struct gsm_bts *bts, uint8_t obj_class, uint8_t i0,
+ uint8_t i1, uint8_t i2, enum abis_nm_adm_state adm_state);
+int abis_nm_establish_tei(struct gsm_bts *bts, uint8_t trx_nr,
+ uint8_t e1_port, uint8_t e1_timeslot, uint8_t e1_subslot,
+ uint8_t tei);
+int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx,
+ uint8_t e1_port, uint8_t e1_timeslot, uint8_t e1_subslot);
+int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts,
+ uint8_t e1_port, uint8_t e1_timeslot,
+ uint8_t e1_subslot);
+int abis_nm_get_attr(struct gsm_bts *bts, uint8_t obj_class,
+ uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
+ uint8_t *attr, uint8_t attr_len);
+int abis_nm_set_bts_attr(struct gsm_bts *bts, uint8_t *attr, int attr_len);
+int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, uint8_t *attr, int attr_len);
+int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, uint8_t chan_comb);
+int abis_nm_sw_act_req_ack(struct gsm_bts *bts, uint8_t obj_class, uint8_t i1,
+ uint8_t i2, uint8_t i3, int nack, uint8_t *attr, int att_len);
+int abis_nm_raw_msg(struct gsm_bts *bts, int len, uint8_t *msg);
+int abis_nm_event_reports(struct gsm_bts *bts, int on);
+int abis_nm_reset_resource(struct gsm_bts *bts);
+int abis_nm_software_load(struct gsm_bts *bts, int trx_nr, const char *fname,
+ uint8_t win_size, int forced,
+ gsm_cbfn *cbfn, void *cb_data);
+int abis_nm_software_load_status(struct gsm_bts *bts);
+int abis_nm_software_activate(struct gsm_bts *bts, const char *fname,
+ gsm_cbfn *cbfn, void *cb_data);
+
+int abis_nm_conn_mdrop_link(struct gsm_bts *bts, uint8_t e1_port0, uint8_t ts0,
+ uint8_t e1_port1, uint8_t ts1);
+
+int abis_nm_perform_test(struct gsm_bts *bts, uint8_t obj_class,
+ uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
+ uint8_t test_nr, uint8_t auton_report, struct msgb *msg);
+
+/* Siemens / BS-11 specific */
+int abis_nm_bs11_reset_resource(struct gsm_bts *bts);
+int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin);
+int abis_nm_bs11_create_object(struct gsm_bts *bts, enum abis_bs11_objtype type,
+ uint8_t idx, uint8_t attr_len, const uint8_t *attr);
+int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, uint8_t idx);
+int abis_nm_bs11_create_bport(struct gsm_bts *bts, uint8_t idx);
+int abis_nm_bs11_delete_object(struct gsm_bts *bts,
+ enum abis_bs11_objtype type, uint8_t idx);
+int abis_nm_bs11_delete_bport(struct gsm_bts *bts, uint8_t idx);
+int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, uint8_t e1_port,
+ uint8_t e1_timeslot, uint8_t e1_subslot, uint8_t tei);
+int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts);
+int abis_nm_bs11_get_serno(struct gsm_bts *bts);
+int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, uint8_t level);
+int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx);
+int abis_nm_bs11_logon(struct gsm_bts *bts, uint8_t level, const char *name, int on);
+int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on);
+int abis_nm_bs11_infield_logon(struct gsm_bts *bts, int on);
+int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password);
+int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked);
+int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts);
+int abis_nm_bs11_set_pll(struct gsm_bts *bts, int value);
+int abis_nm_bs11_get_cclk(struct gsm_bts *bts);
+int abis_nm_bs11_get_state(struct gsm_bts *bts);
+int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname,
+ uint8_t win_size, int forced, gsm_cbfn *cbfn);
+int abis_nm_bs11_set_ext_time(struct gsm_bts *bts);
+int abis_nm_bs11_get_bport_line_cfg(struct gsm_bts *bts, uint8_t bport);
+int abis_nm_bs11_set_bport_line_cfg(struct gsm_bts *bts, uint8_t bport, enum abis_bs11_line_cfg line_cfg);
+int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect);
+int abis_nm_bs11_restart(struct gsm_bts *bts);
+
+/* ip.access nanoBTS specific commands */
+int abis_nm_ipaccess_msg(struct gsm_bts *bts, uint8_t msg_type,
+ uint8_t obj_class, uint8_t bts_nr,
+ uint8_t trx_nr, uint8_t ts_nr,
+ uint8_t *attr, int attr_len);
+int abis_nm_ipaccess_set_nvattr(struct gsm_bts_trx *trx, uint8_t *attr,
+ int attr_len);
+int abis_nm_ipaccess_restart(struct gsm_bts_trx *trx);
+int abis_nm_ipaccess_set_attr(struct gsm_bts *bts, uint8_t obj_class,
+ uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
+ uint8_t *attr, uint8_t attr_len);
+int abis_nm_ipaccess_rsl_connect(struct gsm_bts_trx *trx,
+ uint32_t ip, uint16_t port, uint8_t stream);
+void abis_nm_ipaccess_cgi(uint8_t *buf, struct gsm_bts *bts);
+int ipac_parse_bcch_info(struct ipac_bcch_info *binf, uint8_t *buf);
+const char *ipacc_testres_name(uint8_t res);
+
+/* Functions calling into other code parts */
+int nm_is_running(struct gsm_nm_state *s);
+
+int abis_nm_vty_init(void);
+
+void abis_nm_clear_queue(struct gsm_bts *bts);
+
+int _abis_nm_sendmsg(struct msgb *msg);
+
+void abis_nm_queue_send_next(struct gsm_bts *bts); /* for bs11_config. */
+
+int abis_nm_parse_sw_config(const uint8_t *data, const size_t len,
+ struct abis_nm_sw_descr *res, const int res_len);
+int abis_nm_select_newest_sw(const struct abis_nm_sw_descr *sw, const size_t len);
+
+#endif /* _NM_H */
diff --git a/include/osmocom/bsc/abis_om2000.h b/include/osmocom/bsc/abis_om2000.h
new file mode 100644
index 000000000..2ff72705b
--- /dev/null
+++ b/include/osmocom/bsc/abis_om2000.h
@@ -0,0 +1,98 @@
+#ifndef OPENBSC_ABIS_OM2K_H
+#define OPENBSC_ABIS_OM2K_H
+/* Ericsson RBS 2xxx GSM O&M (OM2000) messages on the A-bis interface
+ * implemented based on protocol trace analysis, no formal documentation */
+
+/* (C) 2010-2011 by Harald Welte <laforge@gnumonks.org>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+enum abis_om2k_mo_cls {
+ OM2K_MO_CLS_TRXC = 0x01,
+ OM2K_MO_CLS_TS = 0x03,
+ OM2K_MO_CLS_TF = 0x04,
+ OM2K_MO_CLS_IS = 0x05,
+ OM2K_MO_CLS_CON = 0x06,
+ OM2K_MO_CLS_DP = 0x07,
+ OM2K_MO_CLS_CF = 0x0a,
+ OM2K_MO_CLS_TX = 0x0b,
+ OM2K_MO_CLS_RX = 0x0c,
+};
+
+enum om2k_mo_state {
+ OM2K_MO_S_RESET = 0,
+ OM2K_MO_S_STARTED,
+ OM2K_MO_S_ENABLED,
+ OM2K_MO_S_DISABLED,
+};
+
+struct abis_om2k_mo {
+ uint8_t class;
+ uint8_t bts;
+ uint8_t assoc_so;
+ uint8_t inst;
+} __attribute__ ((packed));
+
+/* on-wire format for IS conn group */
+struct om2k_is_conn_grp {
+ uint16_t icp1;
+ uint16_t icp2;
+ uint8_t cont_idx;
+} __attribute__ ((packed));
+
+/* internal data formant for IS conn group */
+struct is_conn_group {
+ struct llist_head list;
+ uint16_t icp1;
+ uint16_t icp2;
+ uint8_t ci;
+};
+
+extern const struct abis_om2k_mo om2k_mo_cf;
+extern const struct abis_om2k_mo om2k_mo_is;
+extern const struct abis_om2k_mo om2k_mo_con;
+extern const struct abis_om2k_mo om2k_mo_tf;
+
+extern const struct value_string om2k_mo_class_short_vals[];
+
+int abis_om2k_rcvmsg(struct msgb *msg);
+
+extern const struct abis_om2k_mo om2k_mo_cf;
+
+int abis_om2k_tx_reset_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo);
+int abis_om2k_tx_start_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo);
+int abis_om2k_tx_status_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo);
+int abis_om2k_tx_connect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo);
+int abis_om2k_tx_disconnect_cmd(struct gsm_bts *bts, const struct abis_om2k_mo *mo);
+int abis_om2k_tx_enable_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo);
+int abis_om2k_tx_disable_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo);
+int abis_om2k_tx_test_req(struct gsm_bts *bts, const struct abis_om2k_mo *mo);
+int abis_om2k_tx_op_info(struct gsm_bts *bts, const struct abis_om2k_mo *mo,
+ uint8_t operational);
+int abis_om2k_tx_is_conf_req(struct gsm_bts *bts);
+int abis_om2k_tx_tf_conf_req(struct gsm_bts *bts);
+int abis_om2k_tx_rx_conf_req(struct gsm_bts_trx *trx);
+int abis_om2k_tx_tx_conf_req(struct gsm_bts_trx *trx);
+int abis_om2k_tx_ts_conf_req(struct gsm_bts_trx_ts *ts);
+
+int abis_om2k_vty_init(void);
+
+struct vty;
+void abis_om2k_config_write_bts(struct vty *vty, struct gsm_bts *bts);
+
+#endif /* OPENBCS_ABIS_OM2K_H */
diff --git a/include/osmocom/bsc/abis_rsl.h b/include/osmocom/bsc/abis_rsl.h
new file mode 100644
index 000000000..06f0a721c
--- /dev/null
+++ b/include/osmocom/bsc/abis_rsl.h
@@ -0,0 +1,107 @@
+/* GSM Radio Signalling Link messages on the A-bis interface
+ * 3GPP TS 08.58 version 8.6.0 Release 1999 / ETSI TS 100 596 V8.6.0 */
+
+/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _RSL_H
+#define _RSL_H
+
+#include <osmocom/gsm/protocol/gsm_08_58.h>
+
+#include <osmocom/core/msgb.h>
+
+struct gsm_bts;
+struct gsm_lchan;
+struct gsm_subscriber;
+struct gsm_bts_trx_ts;
+
+
+int rsl_bcch_info(struct gsm_bts_trx *trx, uint8_t type,
+ const uint8_t *data, int len);
+int rsl_sacch_filling(struct gsm_bts_trx *trx, uint8_t type,
+ const uint8_t *data, int len);
+int rsl_chan_activate(struct gsm_bts_trx *trx, uint8_t chan_nr,
+ uint8_t act_type,
+ struct rsl_ie_chan_mode *chan_mode,
+ struct rsl_ie_chan_ident *chan_ident,
+ uint8_t bs_power, uint8_t ms_power,
+ uint8_t ta);
+int rsl_chan_activate_lchan(struct gsm_lchan *lchan, uint8_t act_type,
+ uint8_t ta, uint8_t ho_ref);
+int rsl_chan_mode_modify_req(struct gsm_lchan *ts);
+int rsl_encryption_cmd(struct msgb *msg);
+int rsl_paging_cmd(struct gsm_bts *bts, uint8_t paging_group, uint8_t len,
+ uint8_t *ms_ident, uint8_t chan_needed);
+int rsl_imm_assign_cmd(struct gsm_bts *bts, uint8_t len, uint8_t *val);
+
+int rsl_data_request(struct msgb *msg, uint8_t link_id);
+int rsl_establish_request(struct gsm_lchan *lchan, uint8_t link_id);
+int rsl_relase_request(struct gsm_lchan *lchan, uint8_t link_id);
+
+/* Siemens vendor-specific RSL extensions */
+int rsl_siemens_mrpci(struct gsm_lchan *lchan, struct rsl_mrpci *mrpci);
+
+/* ip.access specfic RSL extensions */
+int rsl_ipacc_crcx(struct gsm_lchan *lchan);
+int rsl_ipacc_mdcx(struct gsm_lchan *lchan, uint32_t ip,
+ uint16_t port, uint8_t rtp_payload2);
+int rsl_ipacc_mdcx_to_rtpsock(struct gsm_lchan *lchan);
+int rsl_ipacc_pdch_activate(struct gsm_bts_trx_ts *ts, int act);
+
+int abis_rsl_rcvmsg(struct msgb *msg);
+
+uint64_t str_to_imsi(const char *imsi_str);
+int rsl_release_request(struct gsm_lchan *lchan, uint8_t link_id,
+ enum rsl_rel_mode release_mode);
+
+int rsl_lchan_set_state(struct gsm_lchan *lchan, int);
+
+/* to be provided by external code */
+int rsl_deact_sacch(struct gsm_lchan *lchan);
+
+/* BCCH related code */
+int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf);
+int rsl_ccch_conf_to_bs_ccch_sdcch_comb(int ccch_conf);
+
+int rsl_sacch_info_modify(struct gsm_lchan *lchan, uint8_t type,
+ const uint8_t *data, int len);
+
+int rsl_chan_bs_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int db);
+int rsl_chan_ms_power_ctrl(struct gsm_lchan *lchan, unsigned int fpc, int dbm);
+
+/* SMSCB functionality */
+int rsl_sms_cb_command(struct gsm_bts *bts, uint8_t chan_number,
+ uint8_t cb_command, const uint8_t *data, int len);
+
+/* some Nokia specific stuff */
+int rsl_nokia_si_begin(struct gsm_bts_trx *trx);
+int rsl_nokia_si_end(struct gsm_bts_trx *trx);
+
+/* required for Nokia BTS power control */
+int rsl_bs_power_control(struct gsm_bts_trx *trx, uint8_t channel, uint8_t reduction);
+
+
+int rsl_release_sapis_from(struct gsm_lchan *lchan, int start,
+ enum rsl_rel_mode release_mode);
+int rsl_start_t3109(struct gsm_lchan *lchan);
+
+int rsl_direct_rf_release(struct gsm_lchan *lchan);
+
+#endif /* RSL_MT_H */
+
diff --git a/include/osmocom/bsc/arfcn_range_encode.h b/include/osmocom/bsc/arfcn_range_encode.h
new file mode 100644
index 000000000..7a6fff000
--- /dev/null
+++ b/include/osmocom/bsc/arfcn_range_encode.h
@@ -0,0 +1,26 @@
+#ifndef ARFCN_RANGE_ENCODE_H
+#define ARFCN_RANGE_ENCODE_H
+
+#include <stdint.h>
+
+enum {
+ ARFCN_RANGE_INVALID = -1,
+ ARFCN_RANGE_128 = 127,
+ ARFCN_RANGE_256 = 255,
+ ARFCN_RANGE_512 = 511,
+ ARFCN_RANGE_1024 = 1023,
+};
+
+#define RANGE_ENC_MAX_ARFCNS 29
+
+int range_enc_determine_range(const int *arfcns, int size, int *f0_out);
+int range_enc_arfcns(const int rng, const int *arfcns, int sze, int *out, int idx);
+int range_enc_find_index(const int rng, const int *arfcns, int size);
+int range_enc_filter_arfcns(const int rng, int *arfcns, const int sze, const int f0, int *f0_included);
+
+int range_enc_range128(uint8_t *chan_list, int f0, int *w);
+int range_enc_range256(uint8_t *chan_list, int f0, int *w);
+int range_enc_range512(uint8_t *chan_list, int f0, int *w);
+int range_enc_range1024(uint8_t *chan_list, int f0, int f0_incl, int *w);
+
+#endif
diff --git a/include/osmocom/bsc/auth.h b/include/osmocom/bsc/auth.h
new file mode 100644
index 000000000..2364fb3d2
--- /dev/null
+++ b/include/osmocom/bsc/auth.h
@@ -0,0 +1,17 @@
+#ifndef _AUTH_H
+#define _AUTH_H
+
+struct gsm_auth_tuple;
+struct gsm_subscriber;
+
+enum auth_action {
+ AUTH_NOT_AVAIL = 0, /* No auth tuple available */
+ AUTH_DO_AUTH_THAN_CIPH = 1, /* Firsth authenticate, then cipher */
+ AUTH_DO_CIPH = 2, /* Only ciphering */
+ AUTH_DO_AUTH = 3, /* Only authentication, no ciphering */
+};
+
+int auth_get_tuple_for_subscr(struct gsm_auth_tuple *atuple,
+ struct gsm_subscriber *subscr, int key_seq);
+
+#endif /* _AUTH_H */
diff --git a/include/osmocom/bsc/bsc_api.h b/include/osmocom/bsc/bsc_api.h
new file mode 100644
index 000000000..f52984f39
--- /dev/null
+++ b/include/osmocom/bsc/bsc_api.h
@@ -0,0 +1,55 @@
+/* GSM 08.08 like API for OpenBSC */
+
+#ifndef OPENBSC_BSC_API_H
+#define OPENBSC_BSC_API_H
+
+#include "gsm_data.h"
+
+#define BSC_API_CONN_POL_ACCEPT 0
+#define BSC_API_CONN_POL_REJECT 1
+
+struct bsc_api {
+ /*! \brief BTS->MSC: tell MSC a SAPI was not established */
+ void (*sapi_n_reject)(struct gsm_subscriber_connection *conn, int dlci);
+ /*! \brief MS->MSC: Tell MSC that ciphering has been enabled */
+ void (*cipher_mode_compl)(struct gsm_subscriber_connection *conn,
+ struct msgb *msg, uint8_t chosen_encr);
+ /*! \brief MS->MSC: New MM context with L3 payload */
+ int (*compl_l3)(struct gsm_subscriber_connection *conn,
+ struct msgb *msg, uint16_t chosen_channel);
+ /*! \brief MS->BSC/MSC: Um L3 message */
+ void (*dtap)(struct gsm_subscriber_connection *conn, uint8_t link_id,
+ struct msgb *msg);
+ /*! \brief BSC->MSC: Assignment of lchan successful */
+ void (*assign_compl)(struct gsm_subscriber_connection *conn,
+ uint8_t rr_cause, uint8_t chosen_channel,
+ uint8_t encr_alg_id, uint8_t speech_mode);
+ /*! \brief BSC->MSC: Assignment of lchan failed */
+ void (*assign_fail)(struct gsm_subscriber_connection *conn,
+ uint8_t cause, uint8_t *rr_cause);
+ /*! \brief BSC->MSC: RR conn has been cleared */
+ int (*clear_request)(struct gsm_subscriber_connection *conn,
+ uint32_t cause);
+ /*! \brief BSC->MSC: Classmark Update */
+ void (*classmark_chg)(struct gsm_subscriber_connection *conn,
+ const uint8_t *cm2, uint8_t cm2_len,
+ const uint8_t *cm3, uint8_t cm3_len);
+
+ /**
+ * Configure the multirate setting on this channel. If it is
+ * not implemented AMR5.9 will be used.
+ */
+ void (*mr_config)(struct gsm_subscriber_connection *conn,
+ struct gsm48_multi_rate_conf *conf);
+};
+
+int bsc_api_init(struct gsm_network *network, struct bsc_api *api);
+int gsm0808_submit_dtap(struct gsm_subscriber_connection *conn, struct msgb *msg, int link_id, int allow_sacch);
+int gsm0808_assign_req(struct gsm_subscriber_connection *conn, int chan_mode, int full_rate);
+int gsm0808_cipher_mode(struct gsm_subscriber_connection *conn, int cipher,
+ const uint8_t *key, int len, int include_imeisv);
+int gsm0808_page(struct gsm_bts *bts, unsigned int page_group,
+ unsigned int mi_len, uint8_t *mi, int chan_type);
+int gsm0808_clear(struct gsm_subscriber_connection *conn);
+
+#endif
diff --git a/include/osmocom/bsc/bsc_msc.h b/include/osmocom/bsc/bsc_msc.h
new file mode 100644
index 000000000..9543002a7
--- /dev/null
+++ b/include/osmocom/bsc/bsc_msc.h
@@ -0,0 +1,59 @@
+/* Routines to talk to the MSC using the IPA Protocol */
+/*
+ * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2010 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef BSC_MSC_H
+#define BSC_MSC_H
+
+#include <osmocom/core/write_queue.h>
+#include <osmocom/core/timer.h>
+
+struct bsc_msc_dest {
+ struct llist_head list;
+
+ char *ip;
+ int port;
+ int dscp;
+};
+
+
+struct bsc_msc_connection {
+ struct osmo_wqueue write_queue;
+ int is_connected;
+ int is_authenticated;
+ int first_contact;
+
+ struct llist_head *dests;
+
+ void (*connection_loss) (struct bsc_msc_connection *);
+ void (*connected) (struct bsc_msc_connection *);
+ struct osmo_timer_list reconnect_timer;
+ struct osmo_timer_list timeout_timer;
+};
+
+struct bsc_msc_connection *bsc_msc_create(void *ctx, struct llist_head *dest);
+int bsc_msc_connect(struct bsc_msc_connection *);
+void bsc_msc_schedule_connect(struct bsc_msc_connection *);
+
+void bsc_msc_lost(struct bsc_msc_connection *);
+
+struct msgb *bsc_msc_id_get_resp(const char *token);
+
+#endif
diff --git a/include/osmocom/bsc/bsc_nat.h b/include/osmocom/bsc/bsc_nat.h
new file mode 100644
index 000000000..195031822
--- /dev/null
+++ b/include/osmocom/bsc/bsc_nat.h
@@ -0,0 +1,480 @@
+/*
+ * (C) 2010-2012 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2010-2012 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef BSC_NAT_H
+#define BSC_NAT_H
+
+#include "mgcp.h"
+
+
+#include <osmocom/core/select.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/msgfile.h>
+#include <osmocom/core/timer.h>
+#include <osmocom/core/write_queue.h>
+#include <osmocom/core/rate_ctr.h>
+#include <osmocom/core/statistics.h>
+#include <osmocom/gsm/protocol/gsm_04_08.h>
+
+#include <regex.h>
+
+#define DIR_BSC 1
+#define DIR_MSC 2
+
+#define PAGIN_GROUP_UNASSIGNED -1
+
+struct sccp_source_reference;
+struct nat_sccp_connection;
+struct bsc_nat_parsed;
+struct bsc_nat;
+struct bsc_nat_ussd_con;
+
+enum {
+ NAT_CON_TYPE_NONE,
+ NAT_CON_TYPE_LU,
+ NAT_CON_TYPE_CM_SERV_REQ,
+ NAT_CON_TYPE_PAG_RESP,
+ NAT_CON_TYPE_SSA,
+ NAT_CON_TYPE_LOCAL_REJECT,
+ NAT_CON_TYPE_OTHER,
+};
+
+/*
+ * Is this terminated to the MSC, to the local machine (release
+ * handling for IMSI filtering) or to a USSD provider?
+ */
+enum {
+ NAT_CON_END_MSC,
+ NAT_CON_END_LOCAL,
+ NAT_CON_END_USSD,
+};
+
+/*
+ * Pending command entry
+ */
+struct bsc_cmd_list {
+ struct llist_head list_entry;
+
+ struct osmo_timer_list timeout;
+
+ /* The NATed ID used on the bsc_con*/
+ int nat_id;
+
+ /* The control connection from which the command originated */
+ struct ctrl_connection *ccon;
+
+ /* The command from the control connection */
+ struct ctrl_cmd *cmd;
+};
+
+/*
+ * Per BSC data structure
+ */
+struct bsc_connection {
+ struct llist_head list_entry;
+
+ /* do we know anything about this BSC? */
+ int authenticated;
+
+ /* the fd we use to communicate */
+ struct osmo_wqueue write_queue;
+
+ /* the BSS associated */
+ struct bsc_config *cfg;
+
+ /* a timeout node */
+ struct osmo_timer_list id_timeout;
+
+ /* pong timeout */
+ struct osmo_timer_list ping_timeout;
+ struct osmo_timer_list pong_timeout;
+
+ /* mgcp related code */
+ char *_endpoint_status;
+ int number_multiplexes;
+ int max_endpoints;
+ int last_endpoint;
+ int next_transaction;
+ uint32_t pending_dlcx_count;
+ struct llist_head pending_dlcx;
+
+ /* track the pending commands for this BSC */
+ struct llist_head cmd_pending;
+ int last_id;
+
+ /* a back pointer */
+ struct bsc_nat *nat;
+};
+
+/**
+ * Stats per BSC
+ */
+struct bsc_config_stats {
+ struct rate_ctr_group *ctrg;
+};
+
+enum bsc_cfg_ctr {
+ BCFG_CTR_SCCP_CONN,
+ BCFG_CTR_SCCP_CALLS,
+ BCFG_CTR_NET_RECONN,
+ BCFG_CTR_DROPPED_SCCP,
+ BCFG_CTR_DROPPED_CALLS,
+ BCFG_CTR_REJECTED_CR,
+ BCFG_CTR_REJECTED_MSG,
+ BCFG_CTR_ILL_PACKET,
+ BCFG_CTR_CON_TYPE_LU,
+ BCFG_CTR_CON_CMSERV_RQ,
+ BCFG_CTR_CON_PAG_RESP,
+ BCFG_CTR_CON_SSA,
+ BCFG_CTR_CON_OTHER,
+};
+
+/**
+ * One BSC entry in the config
+ */
+struct bsc_config {
+ struct llist_head entry;
+
+ char *token;
+ int nr;
+
+ char *description;
+
+ /* imsi white and blacklist */
+ char *acc_lst_name;
+
+ int forbid_paging;
+ int paging_group;
+
+ /* audio handling */
+ int max_endpoints;
+
+ /* backpointer */
+ struct bsc_nat *nat;
+
+ struct bsc_config_stats stats;
+
+ struct llist_head lac_list;
+};
+
+struct bsc_lac_entry {
+ struct llist_head entry;
+ uint16_t lac;
+};
+
+struct bsc_nat_paging_group {
+ struct llist_head entry;
+
+ /* list of lac entries */
+ struct llist_head lists;
+ int nr;
+};
+
+/**
+ * BSCs point of view of endpoints
+ */
+struct bsc_endpoint {
+ /* the operation that is carried out */
+ int transaction_state;
+ /* the pending transaction id */
+ char *transaction_id;
+ /* the bsc we are talking to */
+ struct bsc_connection *bsc;
+};
+
+/**
+ * Statistic for the nat.
+ */
+struct bsc_nat_statistics {
+ struct {
+ struct osmo_counter *conn;
+ struct osmo_counter *calls;
+ } sccp;
+
+ struct {
+ struct osmo_counter *reconn;
+ struct osmo_counter *auth_fail;
+ } bsc;
+
+ struct {
+ struct osmo_counter *reconn;
+ } msc;
+
+ struct {
+ struct osmo_counter *reconn;
+ } ussd;
+};
+
+enum bsc_nat_acc_ctr {
+ ACC_LIST_BSC_FILTER,
+ ACC_LIST_NAT_FILTER,
+};
+
+struct bsc_nat_acc_lst {
+ struct llist_head list;
+
+ /* counter */
+ struct rate_ctr_group *stats;
+
+ /* the name of the list */
+ const char *name;
+ struct llist_head fltr_list;
+};
+
+struct bsc_nat_acc_lst_entry {
+ struct llist_head list;
+
+ /* the filter */
+ char *imsi_allow;
+ regex_t imsi_allow_re;
+ char *imsi_deny;
+ regex_t imsi_deny_re;
+};
+
+/**
+ * the structure of the "nat" network
+ */
+struct bsc_nat {
+ /* active SCCP connections that need patching */
+ struct llist_head sccp_connections;
+
+ /* active BSC connections that need patching */
+ struct llist_head bsc_connections;
+
+ /* access lists */
+ struct llist_head access_lists;
+
+ /* paging groups */
+ struct llist_head paging_groups;
+
+ /* known BSC's */
+ struct llist_head bsc_configs;
+ int num_bsc;
+ int bsc_ip_dscp;
+
+ /* MGCP config */
+ struct mgcp_config *mgcp_cfg;
+ uint8_t mgcp_msg[4096];
+ int mgcp_length;
+ int mgcp_ipa;
+
+ /* msc things */
+ struct llist_head dests;
+ struct bsc_msc_dest *main_dest;
+ struct bsc_msc_connection *msc_con;
+ char *token;
+
+ /* timeouts */
+ int auth_timeout;
+ int ping_timeout;
+ int pong_timeout;
+
+ struct bsc_endpoint *bsc_endpoints;
+
+ /* filter */
+ char *acc_lst_name;
+
+ /* Barring of subscribers with a rb tree */
+ struct rb_root imsi_black_list;
+ char *imsi_black_list_fn;
+
+ /* number rewriting */
+ char *num_rewr_name;
+ struct llist_head num_rewr;
+
+ char *smsc_rewr_name;
+ struct llist_head smsc_rewr;
+ char *tpdest_match_name;
+ struct llist_head tpdest_match;
+ char *sms_clear_tp_srr_name;
+ struct llist_head sms_clear_tp_srr;
+ char *sms_num_rewr_name;
+ struct llist_head sms_num_rewr;
+
+ /* USSD messages we want to match */
+ char *ussd_lst_name;
+ char *ussd_query;
+ regex_t ussd_query_re;
+ char *ussd_token;
+ char *ussd_local;
+ struct osmo_fd ussd_listen;
+ struct bsc_nat_ussd_con *ussd_con;
+
+ /* for maintainenance */
+ int blocked;
+
+ /* statistics */
+ struct bsc_nat_statistics stats;
+
+ /* control interface */
+ struct ctrl_handle *ctrl;
+};
+
+struct bsc_nat_ussd_con {
+ struct osmo_wqueue queue;
+ struct bsc_nat *nat;
+ int authorized;
+
+ struct osmo_timer_list auth_timeout;
+};
+
+struct bsc_nat_reject_cause {
+ int lu_reject_cause;
+ int cm_reject_cause;
+};
+
+/* create and init the structures */
+struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token);
+struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num);
+void bsc_config_free(struct bsc_config *);
+void bsc_config_add_lac(struct bsc_config *cfg, int lac);
+void bsc_config_del_lac(struct bsc_config *cfg, int lac);
+int bsc_config_handles_lac(struct bsc_config *cfg, int lac);
+
+struct bsc_nat *bsc_nat_alloc(void);
+struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat);
+void bsc_nat_set_msc_ip(struct bsc_nat *bsc, const char *ip);
+
+void sccp_connection_destroy(struct nat_sccp_connection *);
+void bsc_close_connection(struct bsc_connection *);
+
+const char *bsc_con_type_to_string(int type);
+
+/**
+ * parse the given message into the above structure
+ */
+struct bsc_nat_parsed *bsc_nat_parse(struct msgb *msg);
+
+/**
+ * filter based on IP Access header in both directions
+ */
+int bsc_nat_filter_ipa(int direction, struct msgb *msg, struct bsc_nat_parsed *parsed);
+int bsc_nat_vty_init(struct bsc_nat *nat);
+int bsc_nat_find_paging(struct msgb *msg, const uint8_t **,int *len);
+
+/**
+ * Content filtering.
+ */
+int bsc_nat_filter_sccp_cr(struct bsc_connection *bsc, struct msgb *msg,
+ struct bsc_nat_parsed *, int *con_type, char **imsi,
+ struct bsc_nat_reject_cause *cause);
+int bsc_nat_filter_dt(struct bsc_connection *bsc, struct msgb *msg,
+ struct nat_sccp_connection *con, struct bsc_nat_parsed *parsed,
+ struct bsc_nat_reject_cause *cause);
+
+/**
+ * SCCP patching and handling
+ */
+struct nat_sccp_connection *create_sccp_src_ref(struct bsc_connection *bsc, struct bsc_nat_parsed *parsed);
+int update_sccp_src_ref(struct nat_sccp_connection *sccp, struct bsc_nat_parsed *parsed);
+void remove_sccp_src_ref(struct bsc_connection *bsc, struct msgb *msg, struct bsc_nat_parsed *parsed);
+struct nat_sccp_connection *patch_sccp_src_ref_to_bsc(struct msgb *, struct bsc_nat_parsed *, struct bsc_nat *);
+struct nat_sccp_connection *patch_sccp_src_ref_to_msc(struct msgb *, struct bsc_nat_parsed *, struct bsc_connection *);
+struct nat_sccp_connection *bsc_nat_find_con_by_bsc(struct bsc_nat *, struct sccp_source_reference *);
+
+/**
+ * MGCP/Audio handling
+ */
+int bsc_mgcp_nr_multiplexes(int max_endpoints);
+int bsc_write_mgcp(struct bsc_connection *bsc, const uint8_t *data, unsigned int length);
+int bsc_mgcp_assign_patch(struct nat_sccp_connection *, struct msgb *msg);
+void bsc_mgcp_init(struct nat_sccp_connection *);
+void bsc_mgcp_dlcx(struct nat_sccp_connection *);
+void bsc_mgcp_free_endpoints(struct bsc_nat *nat);
+int bsc_mgcp_nat_init(struct bsc_nat *nat);
+
+struct nat_sccp_connection *bsc_mgcp_find_con(struct bsc_nat *, int endpoint_number);
+struct msgb *bsc_mgcp_rewrite(char *input, int length, int endp, const char *ip, int port);
+void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg);
+
+void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc);
+int bsc_mgcp_parse_response(const char *str, int *code, char transaction[60]);
+uint32_t bsc_mgcp_extract_ci(const char *resp);
+
+
+int bsc_write(struct bsc_connection *bsc, struct msgb *msg, int id);
+int bsc_do_write(struct osmo_wqueue *queue, struct msgb *msg, int id);
+int bsc_write_msg(struct osmo_wqueue *queue, struct msgb *msg);
+int bsc_write_cb(struct osmo_fd *bfd, struct msgb *msg);
+
+/* IMSI allow/deny handling */
+struct bsc_nat_acc_lst *bsc_nat_acc_lst_find(struct bsc_nat *nat, const char *name);
+struct bsc_nat_acc_lst *bsc_nat_acc_lst_get(struct bsc_nat *nat, const char *name);
+void bsc_nat_acc_lst_delete(struct bsc_nat_acc_lst *lst);
+
+struct bsc_nat_acc_lst_entry *bsc_nat_acc_lst_entry_create(struct bsc_nat_acc_lst *);
+int bsc_nat_lst_check_allow(struct bsc_nat_acc_lst *lst, const char *imsi);
+
+int bsc_nat_msc_is_connected(struct bsc_nat *nat);
+
+int bsc_conn_type_to_ctr(struct nat_sccp_connection *conn);
+
+struct gsm48_hdr *bsc_unpack_dtap(struct bsc_nat_parsed *parsed, struct msgb *msg, uint32_t *len);
+
+/** USSD filtering */
+int bsc_ussd_init(struct bsc_nat *nat);
+int bsc_check_ussd(struct nat_sccp_connection *con, struct bsc_nat_parsed *parsed, struct msgb *msg);
+int bsc_close_ussd_connections(struct bsc_nat *nat);
+
+struct msgb *bsc_nat_rewrite_msg(struct bsc_nat *nat, struct msgb *msg, struct bsc_nat_parsed *, const char *imsi);
+
+/** paging group handling */
+struct bsc_nat_paging_group *bsc_nat_paging_group_num(struct bsc_nat *nat, int group);
+struct bsc_nat_paging_group *bsc_nat_paging_group_create(struct bsc_nat *nat, int group);
+void bsc_nat_paging_group_delete(struct bsc_nat_paging_group *);
+void bsc_nat_paging_group_add_lac(struct bsc_nat_paging_group *grp, int lac);
+void bsc_nat_paging_group_del_lac(struct bsc_nat_paging_group *grp, int lac);
+
+/**
+ * Number rewriting support below
+ */
+struct bsc_nat_num_rewr_entry {
+ struct llist_head list;
+
+ regex_t msisdn_reg;
+ regex_t num_reg;
+
+ char *replace;
+};
+
+void bsc_nat_num_rewr_entry_adapt(void *ctx, struct llist_head *head, const struct osmo_config_list *);
+
+struct bsc_nat_barr_entry {
+ struct rb_node node;
+
+ char *imsi;
+ int cm_reject_cause;
+ int lu_reject_cause;
+};
+
+int bsc_nat_barr_adapt(void *ctx, struct rb_root *rbtree, const struct osmo_config_list *);
+int bsc_nat_barr_find(struct rb_root *root, const char *imsi, int *cm, int *lu);
+
+void bsc_nat_send_mgcp_to_msc(struct bsc_nat *bsc_nat, struct msgb *msg);
+void bsc_nat_handle_mgcp(struct bsc_nat *bsc, struct msgb *msg);
+
+struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, int port);
+void bsc_nat_ctrl_del_pending(struct bsc_cmd_list *pending);
+int bsc_nat_handle_ctrlif_msg(struct bsc_connection *bsc, struct msgb *msg);
+
+int bsc_nat_extract_lac(struct bsc_connection *bsc, struct nat_sccp_connection *con,
+ struct bsc_nat_parsed *parsed, struct msgb *msg);
+
+#endif
diff --git a/include/osmocom/bsc/bsc_nat_callstats.h b/include/osmocom/bsc/bsc_nat_callstats.h
new file mode 100644
index 000000000..64f9bfc0a
--- /dev/null
+++ b/include/osmocom/bsc/bsc_nat_callstats.h
@@ -0,0 +1,55 @@
+/*
+ * (C) 2010-2012 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2010-2012 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef BSC_NAT_CALLSTATS_H
+#define BSC_NAT_CALLSTATS_H
+
+#include <osmocom/core/linuxlist.h>
+
+#include <osmocom/sccp/sccp_types.h>
+
+struct bsc_nat_call_stats {
+ struct llist_head entry;
+
+ struct sccp_source_reference remote_ref;
+ struct sccp_source_reference src_ref; /* as seen by the MSC */
+
+ /* mgcp options */
+ uint32_t ci;
+ int bts_rtp_port;
+ int net_rtp_port;
+ struct in_addr bts_addr;
+ struct in_addr net_addr;
+
+
+ /* as witnessed by the NAT */
+ uint32_t net_ps;
+ uint32_t net_os;
+ uint32_t bts_pr;
+ uint32_t bts_or;
+ uint32_t bts_expected;
+ uint32_t bts_jitter;
+ int bts_loss;
+
+ uint32_t trans_id;
+ int msc_endpoint;
+};
+
+#endif
diff --git a/include/osmocom/bsc/bsc_nat_sccp.h b/include/osmocom/bsc/bsc_nat_sccp.h
new file mode 100644
index 000000000..34aa6320a
--- /dev/null
+++ b/include/osmocom/bsc/bsc_nat_sccp.h
@@ -0,0 +1,101 @@
+/* NAT utilities using SCCP types */
+/*
+ * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2010 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef BSC_NAT_SCCP_H
+#define BSC_NAT_SCCP_H
+
+#include <osmocom/sccp/sccp_types.h>
+
+/*
+ * For the NAT we will need to analyze and later patch
+ * the received message. This would require us to parse
+ * the IPA and SCCP header twice. Instead of doing this
+ * we will have one analyze structure and have the patching
+ * and filter operate on the same structure.
+ */
+struct bsc_nat_parsed {
+ /* ip access prototype */
+ int ipa_proto;
+
+ /* source local reference */
+ struct sccp_source_reference *src_local_ref;
+
+ /* destination local reference */
+ struct sccp_source_reference *dest_local_ref;
+
+ /* called ssn number */
+ int called_ssn;
+
+ /* calling ssn number */
+ int calling_ssn;
+
+ /* sccp message type */
+ int sccp_type;
+
+ /* bssap type, e.g. 0 for BSS Management */
+ int bssap;
+
+ /* the gsm0808 message type */
+ int gsm_type;
+};
+
+/*
+ * Per SCCP source local reference patch table. It needs to
+ * be updated on new SCCP connections, connection confirm and reject,
+ * and on the loss of the BSC connection.
+ */
+struct nat_sccp_connection {
+ struct llist_head list_entry;
+
+ struct bsc_connection *bsc;
+ struct bsc_msc_connection *msc_con;
+
+ struct sccp_source_reference real_ref;
+ struct sccp_source_reference patched_ref;
+ struct sccp_source_reference remote_ref;
+ int has_remote_ref;
+
+ /* status */
+ int con_type;
+ int con_local;
+ int authorized;
+ int imsi_checked;
+ char *imsi;
+
+ uint16_t lac;
+ uint16_t ci;
+
+ /* remember which Transactions we run over the bypass */
+ char ussd_ti[8];
+
+ /*
+ * audio handling. Remember if we have ever send a CRCX,
+ * remember the endpoint used by the MSC and BSC.
+ */
+ int msc_endp;
+ int bsc_endp;
+
+ /* timeout handling */
+ struct timespec creation_time;
+};
+
+
+#endif
diff --git a/include/osmocom/bsc/bsc_rll.h b/include/osmocom/bsc/bsc_rll.h
new file mode 100644
index 000000000..729ba6037
--- /dev/null
+++ b/include/osmocom/bsc/bsc_rll.h
@@ -0,0 +1,19 @@
+#ifndef _BSC_RLL_H
+#define _BSC_RLL_H
+
+#include <openbsc/gsm_data.h>
+
+enum bsc_rllr_ind {
+ BSC_RLLR_IND_EST_CONF,
+ BSC_RLLR_IND_REL_IND,
+ BSC_RLLR_IND_ERR_IND,
+ BSC_RLLR_IND_TIMEOUT,
+};
+
+int rll_establish(struct gsm_lchan *lchan, uint8_t link_id,
+ void (*cb)(struct gsm_lchan *, uint8_t, void *,
+ enum bsc_rllr_ind),
+ void *data);
+void rll_indication(struct gsm_lchan *lchan, uint8_t link_id, uint8_t type);
+
+#endif /* _BSC_RLL_H */
diff --git a/include/osmocom/bsc/bss.h b/include/osmocom/bsc/bss.h
new file mode 100644
index 000000000..49df547a1
--- /dev/null
+++ b/include/osmocom/bsc/bss.h
@@ -0,0 +1,18 @@
+#ifndef _BSS_H_
+#define _BSS_H_
+
+struct gsm_network;
+struct msgb;
+
+/* start and stop network */
+extern int bsc_bootstrap_network(int (*mncc_recv)(struct gsm_network *, struct msgb *), const char *cfg_file);
+extern int bsc_shutdown_net(struct gsm_network *net);
+
+/* register all supported BTS */
+extern int bts_init(void);
+extern int bts_model_bs11_init(void);
+extern int bts_model_rbs2k_init(void);
+extern int bts_model_nanobts_init(void);
+extern int bts_model_nokia_site_init(void);
+extern int bts_model_sysmobts_init(void);
+#endif
diff --git a/include/osmocom/bsc/chan_alloc.h b/include/osmocom/bsc/chan_alloc.h
new file mode 100644
index 000000000..f2d3c781d
--- /dev/null
+++ b/include/osmocom/bsc/chan_alloc.h
@@ -0,0 +1,65 @@
+/* Management functions to allocate/release struct gsm_lchan */
+/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#ifndef _CHAN_ALLOC_H
+#define _CHAN_ALLOC_H
+
+#include "gsm_data.h"
+
+struct gsm_subscriber_connection;
+
+/* Special allocator for C0 of BTS */
+struct gsm_bts_trx_ts *ts_c0_alloc(struct gsm_bts *bts,
+ enum gsm_phys_chan_config pchan);
+
+/* Regular physical channel allocator */
+struct gsm_bts_trx_ts *ts_alloc(struct gsm_bts *bts,
+ enum gsm_phys_chan_config pchan);
+
+/* Regular physical channel (TS) */
+void ts_free(struct gsm_bts_trx_ts *ts);
+
+/* Find an allocated channel for a specified subscriber */
+struct gsm_subscriber_connection *connection_for_subscr(struct gsm_subscriber *subscr);
+
+/* Allocate a logical channel (SDCCH, TCH, ...) */
+struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type, int allow_bigger);
+
+/* Free a logical channel (SDCCH, TCH, ...) */
+void lchan_free(struct gsm_lchan *lchan);
+void lchan_reset(struct gsm_lchan *lchan);
+
+/* Release the given lchan */
+int lchan_release(struct gsm_lchan *lchan, int sacch_deact, enum rsl_rel_mode release_mode);
+
+struct load_counter {
+ unsigned int total;
+ unsigned int used;
+};
+
+struct pchan_load {
+ struct load_counter pchan[GSM_PCHAN_UNKNOWN];
+};
+
+void bts_chan_load(struct pchan_load *cl, const struct gsm_bts *bts);
+void network_chan_load(struct pchan_load *pl, struct gsm_network *net);
+
+int trx_is_usable(struct gsm_bts_trx *trx);
+
+#endif /* _CHAN_ALLOC_H */
diff --git a/include/osmocom/bsc/control_cmd.h b/include/osmocom/bsc/control_cmd.h
new file mode 100644
index 000000000..a0ea055ce
--- /dev/null
+++ b/include/osmocom/bsc/control_cmd.h
@@ -0,0 +1,163 @@
+#ifndef _CONTROL_CMD_H
+#define _CONTROL_CMD_H
+
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/write_queue.h>
+
+#include <osmocom/vty/vector.h>
+
+#include <openbsc/vty.h>
+
+#define CTRL_CMD_ERROR -1
+#define CTRL_CMD_HANDLED 0
+#define CTRL_CMD_REPLY 1
+
+struct ctrl_handle;
+
+enum ctrl_node_type {
+ CTRL_NODE_ROOT, /* Root elements */
+ CTRL_NODE_BTS, /* BTS specific (net.btsN.) */
+ CTRL_NODE_TRX, /* TRX specific (net.btsN.trxM.) */
+ CTRL_NODE_TS, /* TS specific (net.btsN.trxM.tsI.) */
+ _LAST_CTRL_NODE
+};
+
+enum ctrl_type {
+ CTRL_TYPE_UNKNOWN,
+ CTRL_TYPE_GET,
+ CTRL_TYPE_SET,
+ CTRL_TYPE_GET_REPLY,
+ CTRL_TYPE_SET_REPLY,
+ CTRL_TYPE_TRAP,
+ CTRL_TYPE_ERROR
+};
+
+struct ctrl_connection {
+ struct llist_head list_entry;
+
+ /* The queue for sending data back */
+ struct osmo_wqueue write_queue;
+
+ /* Callback if the connection was closed */
+ void (*closed_cb)(struct ctrl_connection *conn);
+
+ /* Pending commands for this connection */
+ struct llist_head cmds;
+};
+
+struct ctrl_cmd {
+ struct ctrl_connection *ccon;
+ enum ctrl_type type;
+ char *id;
+ void *node;
+ char *variable;
+ char *value;
+ char *reply;
+};
+
+struct ctrl_cmd_struct {
+ int nr_commands;
+ char **command;
+};
+
+struct ctrl_cmd_element {
+ const char *name;
+ const char *param;
+ struct ctrl_cmd_struct strcmd;
+ int (*set)(struct ctrl_cmd *cmd, void *data);
+ int (*get)(struct ctrl_cmd *cmd, void *data);
+ int (*verify)(struct ctrl_cmd *cmd, const char *value, void *data);
+};
+
+struct ctrl_cmd_map {
+ char *cmd;
+ enum ctrl_type type;
+};
+
+int ctrl_cmd_exec(vector vline, struct ctrl_cmd *command, vector node, void *data);
+int ctrl_cmd_install(enum ctrl_node_type node, struct ctrl_cmd_element *cmd);
+int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data);
+int ctrl_cmd_send(struct osmo_wqueue *queue, struct ctrl_cmd *cmd);
+int ctrl_cmd_send_to_all(struct ctrl_handle *ctrl, struct ctrl_cmd *cmd);
+struct ctrl_cmd *ctrl_cmd_parse(void *ctx, struct msgb *msg);
+struct msgb *ctrl_cmd_make(struct ctrl_cmd *cmd);
+struct ctrl_cmd *ctrl_cmd_cpy(void *ctx, struct ctrl_cmd *cmd);
+struct ctrl_cmd *ctrl_cmd_create(void *ctx, enum ctrl_type);
+struct ctrl_cmd *ctrl_cmd_trap(struct ctrl_cmd *cmd);
+
+#define CTRL_CMD_DEFINE_RANGE(cmdname, cmdstr, dtype, element, min, max) \
+static int get_##cmdname(struct ctrl_cmd *cmd, void *_data) \
+{ \
+ dtype *node = cmd->node; \
+ cmd->reply = talloc_asprintf(cmd, "%i", node->element); \
+ if (!cmd->reply) { \
+ cmd->reply = "OOM"; \
+ return CTRL_CMD_ERROR; \
+ } \
+ return CTRL_CMD_REPLY; \
+} \
+static int set_##cmdname(struct ctrl_cmd *cmd, void *_data) \
+{ \
+ dtype *node = cmd->node; \
+ int tmp = atoi(cmd->value); \
+ node->element = tmp; \
+ return get_##cmdname(cmd, _data); \
+} \
+static int verify_##cmdname(struct ctrl_cmd *cmd, const char *value, void *_data) \
+{ \
+ int tmp = atoi(value); \
+ if ((tmp >= min)&&(tmp <= max)) { \
+ return 0; \
+ } \
+ cmd->reply = "Input not within the range"; \
+ return -1; \
+} \
+static struct ctrl_cmd_element cmd_##cmdname = { \
+ .name = cmdstr, \
+ .param = NULL, \
+ .get = &get_##cmdname, \
+ .set = &set_##cmdname, \
+ .verify = &verify_##cmdname, \
+}
+
+#define CTRL_CMD_DEFINE_STRING(cmdname, cmdstr, dtype, element) \
+static int get_##cmdname(struct ctrl_cmd *cmd, void *_data) \
+{ \
+ dtype *data = cmd->node; \
+ cmd->reply = talloc_asprintf(cmd, "%s", data->element); \
+ if (!cmd->reply) { \
+ cmd->reply = "OOM"; \
+ return CTRL_CMD_ERROR; \
+ } \
+ return CTRL_CMD_REPLY; \
+} \
+static int set_##cmdname(struct ctrl_cmd *cmd, void *_data) \
+{ \
+ dtype *data = cmd->node; \
+ bsc_replace_string(cmd->node, &data->element, cmd->value); \
+ return get_##cmdname(cmd, _data); \
+} \
+static struct ctrl_cmd_element cmd_##cmdname = { \
+ .name = cmdstr, \
+ .param = NULL, \
+ .get = &get_##cmdname, \
+ .set = &set_##cmdname, \
+ .verify = NULL, \
+}
+
+#define CTRL_CMD_DEFINE(cmdname, cmdstr) \
+static int get_##cmdname(struct ctrl_cmd *cmd, void *data); \
+static int set_##cmdname(struct ctrl_cmd *cmd, void *data); \
+static int verify_##cmdname(struct ctrl_cmd *cmd, const char *value, void *data); \
+static struct ctrl_cmd_element cmd_##cmdname = { \
+ .name = cmdstr, \
+ .param = NULL, \
+ .get = &get_##cmdname, \
+ .set = &set_##cmdname, \
+ .verify = &verify_##cmdname, \
+}
+
+struct gsm_network;
+
+#endif /* _CONTROL_CMD_H */
diff --git a/include/osmocom/bsc/control_if.h b/include/osmocom/bsc/control_if.h
new file mode 100644
index 000000000..6afc86d76
--- /dev/null
+++ b/include/osmocom/bsc/control_if.h
@@ -0,0 +1,21 @@
+#ifndef _CONTROL_IF_H
+#define _CONTROL_IF_H
+
+#include <osmocom/core/write_queue.h>
+#include <openbsc/control_cmd.h>
+#include <openbsc/gsm_data.h>
+
+struct ctrl_handle {
+ struct osmo_fd listen_fd;
+ struct gsm_network *gsmnet;
+
+ /* List of control connections */
+ struct llist_head ccon_list;
+};
+
+int ctrl_cmd_send(struct osmo_wqueue *queue, struct ctrl_cmd *cmd);
+int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data);
+struct ctrl_handle *controlif_setup(struct gsm_network *gsmnet, uint16_t port);
+
+#endif /* _CONTROL_IF_H */
+
diff --git a/include/osmocom/bsc/crc24.h b/include/osmocom/bsc/crc24.h
new file mode 100644
index 000000000..756638c03
--- /dev/null
+++ b/include/osmocom/bsc/crc24.h
@@ -0,0 +1,10 @@
+#ifndef _CRC24_H
+#define _CRC24_H
+
+#include <stdint.h>
+
+#define INIT_CRC24 0xffffff
+
+uint32_t crc24_calc(uint32_t fcs, uint8_t *cp, unsigned int len);
+
+#endif
diff --git a/include/osmocom/bsc/db.h b/include/osmocom/bsc/db.h
new file mode 100644
index 000000000..25c2aea70
--- /dev/null
+++ b/include/osmocom/bsc/db.h
@@ -0,0 +1,82 @@
+/* (C) 2008 by Jan Luebbe <jluebbe@debian.org>
+ * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _DB_H
+#define _DB_H
+
+#include "gsm_subscriber.h"
+
+struct gsm_equipment;
+struct gsm_network;
+struct gsm_auth_info;
+struct gsm_auth_tuple;
+struct gsm_sms;
+struct gsm_subscriber;
+
+/* one time initialisation */
+int db_init(const char *name);
+int db_prepare(void);
+int db_fini(void);
+
+/* subscriber management */
+struct gsm_subscriber *db_create_subscriber(struct gsm_network *net,
+ char *imsi);
+struct gsm_subscriber *db_get_subscriber(struct gsm_network *net,
+ enum gsm_subscriber_field field,
+ const char *subscr);
+int db_sync_subscriber(struct gsm_subscriber *subscriber);
+int db_subscriber_expire(void *priv, void (*callback)(void *priv, long long unsigned int id));
+int db_subscriber_alloc_tmsi(struct gsm_subscriber *subscriber);
+int db_subscriber_alloc_exten(struct gsm_subscriber *subscriber);
+int db_subscriber_alloc_token(struct gsm_subscriber *subscriber, uint32_t* token);
+int db_subscriber_assoc_imei(struct gsm_subscriber *subscriber, char *imei);
+int db_sync_equipment(struct gsm_equipment *equip);
+int db_subscriber_update(struct gsm_subscriber *subscriber);
+
+/* auth info */
+int db_get_authinfo_for_subscr(struct gsm_auth_info *ainfo,
+ struct gsm_subscriber *subscr);
+int db_sync_authinfo_for_subscr(struct gsm_auth_info *ainfo,
+ struct gsm_subscriber *subscr);
+int db_get_lastauthtuple_for_subscr(struct gsm_auth_tuple *atuple,
+ struct gsm_subscriber *subscr);
+int db_sync_lastauthtuple_for_subscr(struct gsm_auth_tuple *atuple,
+ struct gsm_subscriber *subscr);
+
+/* SMS store-and-forward */
+int db_sms_store(struct gsm_sms *sms);
+struct gsm_sms *db_sms_get(struct gsm_network *net, unsigned long long id);
+struct gsm_sms *db_sms_get_unsent(struct gsm_network *net, unsigned long long min_id);
+struct gsm_sms *db_sms_get_unsent_by_subscr(struct gsm_network *net, unsigned long long min_subscr_id, unsigned int failed);
+struct gsm_sms *db_sms_get_unsent_for_subscr(struct gsm_subscriber *subscr);
+int db_sms_mark_sent(struct gsm_sms *sms);
+int db_sms_inc_deliver_attempts(struct gsm_sms *sms);
+
+/* APDU blob storage */
+int db_apdu_blob_store(struct gsm_subscriber *subscr,
+ uint8_t apdu_id_flags, uint8_t len,
+ uint8_t *apdu);
+
+/* Statistics counter storage */
+struct osmo_counter;
+int db_store_counter(struct osmo_counter *ctr);
+struct rate_ctr_group;
+int db_store_rate_ctr_group(struct rate_ctr_group *ctrg);
+
+#endif /* _DB_H */
diff --git a/include/osmocom/bsc/debug.h b/include/osmocom/bsc/debug.h
new file mode 100644
index 000000000..d851181c7
--- /dev/null
+++ b/include/osmocom/bsc/debug.h
@@ -0,0 +1,65 @@
+#ifndef _DEBUG_H
+#define _DEBUG_H
+
+#include <stdio.h>
+#include <osmocom/core/linuxlist.h>
+
+#define DEBUG
+#include <osmocom/core/logging.h>
+
+/* Debug Areas of the code */
+enum {
+ DRLL,
+ DCC,
+ DMM,
+ DRR,
+ DRSL,
+ DNM,
+ DMNCC,
+ DPAG,
+ DMEAS,
+ DSCCP,
+ DMSC,
+ DMGCP,
+ DHO,
+ DDB,
+ DREF,
+ DGPRS,
+ DNS,
+ DBSSGP,
+ DLLC,
+ DSNDCP,
+ DNAT,
+ DCTRL,
+ DSMPP,
+ Debug_LastEntry,
+};
+
+/* context */
+#define BSC_CTX_LCHAN 0
+#define BSC_CTX_SUBSCR 1
+#define BSC_CTX_BTS 2
+#define BSC_CTX_SCCP 3
+
+/* target */
+
+enum {
+ //DEBUG_FILTER_ALL = 1 << 0,
+ LOG_FILTER_IMSI = 1 << 1,
+ LOG_FILTER_NSVC = 1 << 2,
+ LOG_FILTER_BVC = 1 << 3,
+};
+
+/* we don't need a header dependency for this... */
+struct gprs_nsvc;
+struct bssgp_bvc_ctx;
+
+void log_set_imsi_filter(struct log_target *target, const char *imsi);
+void log_set_nsvc_filter(struct log_target *target,
+ struct gprs_nsvc *nsvc);
+void log_set_bvc_filter(struct log_target *target,
+ struct bssgp_bvc_ctx *bctx);
+
+extern const struct log_info log_info;
+
+#endif /* _DEBUG_H */
diff --git a/include/osmocom/bsc/e1_config.h b/include/osmocom/bsc/e1_config.h
new file mode 100644
index 000000000..538c0b09d
--- /dev/null
+++ b/include/osmocom/bsc/e1_config.h
@@ -0,0 +1,11 @@
+#ifndef _E1_CONFIG_H
+#define _E1_CONFIG_H
+
+#include <openbsc/gsm_data_shared.h>
+
+int e1_reconfig_ts(struct gsm_bts_trx_ts *ts);
+int e1_reconfig_trx(struct gsm_bts_trx *trx);
+int e1_reconfig_bts(struct gsm_bts *bts);
+
+#endif /* _E1_CONFIG_H */
+
diff --git a/include/osmocom/bsc/gb_proxy.h b/include/osmocom/bsc/gb_proxy.h
new file mode 100644
index 000000000..2c8ddb334
--- /dev/null
+++ b/include/osmocom/bsc/gb_proxy.h
@@ -0,0 +1,38 @@
+#ifndef _GB_PROXY_H
+#define _GB_PROXY_H
+
+
+#include <osmocom/core/msgb.h>
+
+#include <osmocom/gprs/gprs_ns.h>
+#include <osmocom/vty/command.h>
+
+struct gbproxy_config {
+ /* parsed from config file */
+ uint16_t nsip_sgsn_nsei;
+
+ /* misc */
+ struct gprs_ns_inst *nsi;
+};
+
+extern struct gbproxy_config gbcfg;
+extern struct cmd_element show_gbproxy_cmd;
+
+/* gb_proxy_vty .c */
+
+int gbproxy_vty_init(void);
+int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg);
+
+
+/* gb_proxy.c */
+
+/* Main input function for Gb proxy */
+int gbprox_rcvmsg(struct msgb *msg, struct gprs_nsvc *nsvc, uint16_t ns_bvci);
+
+int gbprox_signal(unsigned int subsys, unsigned int signal,
+ void *handler_data, void *signal_data);
+
+/* Reset all persistent NS-VC's */
+int gbprox_reset_persistent_nsvcs(struct gprs_ns_inst *nsi);
+
+#endif
diff --git a/include/osmocom/bsc/gprs_gmm.h b/include/osmocom/bsc/gprs_gmm.h
new file mode 100644
index 000000000..f6b3e5e7c
--- /dev/null
+++ b/include/osmocom/bsc/gprs_gmm.h
@@ -0,0 +1,19 @@
+#ifndef _GPRS_GMM_H
+#define _GPRS_GMM_H
+
+#include <osmocom/core/msgb.h>
+#include <openbsc/gprs_sgsn.h>
+
+int gsm48_tx_gsm_deact_pdp_req(struct sgsn_pdp_ctx *pdp, uint8_t sm_cause);
+int gsm48_tx_gsm_act_pdp_rej(struct sgsn_mm_ctx *mm, uint8_t tid,
+ uint8_t cause, uint8_t pco_len, uint8_t *pco_v);
+int gsm48_tx_gsm_act_pdp_acc(struct sgsn_pdp_ctx *pdp);
+int gsm48_tx_gsm_deact_pdp_acc(struct sgsn_pdp_ctx *pdp);
+
+int gsm0408_gprs_rcvmsg(struct msgb *msg, struct gprs_llc_llme *llme);
+
+int gprs_gmm_rx_suspend(struct gprs_ra_id *raid, uint32_t tlli);
+int gprs_gmm_rx_resume(struct gprs_ra_id *raid, uint32_t tlli,
+ uint8_t suspend_ref);
+
+#endif /* _GPRS_GMM_H */
diff --git a/include/osmocom/bsc/gprs_llc.h b/include/osmocom/bsc/gprs_llc.h
new file mode 100644
index 000000000..4be7b1f18
--- /dev/null
+++ b/include/osmocom/bsc/gprs_llc.h
@@ -0,0 +1,202 @@
+#ifndef _GPRS_LLC_H
+#define _GPRS_LLC_H
+
+#include <stdint.h>
+#include <openbsc/gprs_sgsn.h>
+
+/* Section 4.7 LLC Layer Structure */
+enum gprs_llc_sapi {
+ GPRS_SAPI_GMM = 1,
+ GPRS_SAPI_TOM2 = 2,
+ GPRS_SAPI_SNDCP3 = 3,
+ GPRS_SAPI_SNDCP5 = 5,
+ GPRS_SAPI_SMS = 7,
+ GPRS_SAPI_TOM8 = 8,
+ GPRS_SAPI_SNDCP9 = 9,
+ GPRS_SAPI_SNDCP11 = 11,
+};
+
+/* Section 6.4 Commands and Responses */
+enum gprs_llc_u_cmd {
+ GPRS_LLC_U_DM_RESP = 0x01,
+ GPRS_LLC_U_DISC_CMD = 0x04,
+ GPRS_LLC_U_UA_RESP = 0x06,
+ GPRS_LLC_U_SABM_CMD = 0x07,
+ GPRS_LLC_U_FRMR_RESP = 0x08,
+ GPRS_LLC_U_XID = 0x0b,
+ GPRS_LLC_U_NULL_CMD = 0x00,
+};
+
+/* Section 6.4.1.6 / Table 6 */
+enum gprs_llc_xid_type {
+ GPRS_LLC_XID_T_VERSION = 0,
+ GPRS_LLC_XID_T_IOV_UI = 1,
+ GPRS_LLC_XID_T_IOV_I = 2,
+ GPRS_LLC_XID_T_T200 = 3,
+ GPRS_LLC_XID_T_N200 = 4,
+ GPRS_LLC_XID_T_N201_U = 5,
+ GPRS_LLC_XID_T_N201_I = 6,
+ GPRS_LLC_XID_T_mD = 7,
+ GPRS_LLC_XID_T_mU = 8,
+ GPRS_LLC_XID_T_kD = 9,
+ GPRS_LLC_XID_T_kU = 10,
+ GPRS_LLC_XID_T_L3_PAR = 11,
+ GPRS_LLC_XID_T_RESET = 12,
+};
+
+/* TS 04.64 Section 7.1.2 Table 7: LLC layer primitives (GMM/SNDCP/SMS/TOM) */
+/* TS 04.65 Section 5.1.2 Table 2: Service primitives used by SNDCP */
+enum gprs_llc_primitive {
+ /* GMM <-> LLME */
+ LLGMM_ASSIGN_REQ, /* GMM tells us new TLLI: TLLI old, TLLI new, Kc, CiphAlg */
+ LLGMM_RESET_REQ, /* GMM tells us to perform XID negotiation: TLLI */
+ LLGMM_RESET_CNF, /* LLC informs GMM that XID has completed: TLLI */
+ LLGMM_SUSPEND_REQ, /* GMM tells us MS has suspended: TLLI, Page */
+ LLGMM_RESUME_REQ, /* GMM tells us MS has resumed: TLLI */
+ LLGMM_PAGE_IND, /* LLC asks GMM to page MS: TLLI */
+ LLGMM_IOV_REQ, /* GMM tells us to perform XID: TLLI */
+ LLGMM_STATUS_IND, /* LLC informs GMM about error: TLLI, Cause */
+ /* LLE <-> (GMM/SNDCP/SMS/TOM) */
+ LL_RESET_IND, /* TLLI */
+ LL_ESTABLISH_REQ, /* TLLI, XID Req */
+ LL_ESTABLISH_IND, /* TLLI, XID Req, N201-I, N201-U */
+ LL_ESTABLISH_RESP, /* TLLI, XID Negotiated */
+ LL_ESTABLISH_CONF, /* TLLI, XID Neg, N201-i, N201-U */
+ LL_RELEASE_REQ, /* TLLI, Local */
+ LL_RELEASE_IND, /* TLLI, Cause */
+ LL_RELEASE_CONF, /* TLLI */
+ LL_XID_REQ, /* TLLI, XID Requested */
+ LL_XID_IND, /* TLLI, XID Req, N201-I, N201-U */
+ LL_XID_RESP, /* TLLI, XID Negotiated */
+ LL_XID_CONF, /* TLLI, XID Neg, N201-I, N201-U */
+ LL_DATA_REQ, /* TLLI, SN-PDU, Ref, QoS, Radio Prio, Ciph */
+ LL_DATA_IND, /* TLLI, SN-PDU */
+ LL_DATA_CONF, /* TLLI, Ref */
+ LL_UNITDATA_REQ, /* TLLI, SN-PDU, Ref, QoS, Radio Prio, Ciph */
+ LL_UNITDATA_IND, /* TLLI, SN-PDU */
+ LL_STATUS_IND, /* TLLI, Cause */
+};
+
+/* Section 4.5.2 Logical Link States + Annex C.2 */
+enum gprs_llc_lle_state {
+ GPRS_LLES_UNASSIGNED = 1, /* No TLLI yet */
+ GPRS_LLES_ASSIGNED_ADM = 2, /* TLLI assigned */
+ GPRS_LLES_LOCAL_EST = 3, /* Local Establishment */
+ GPRS_LLES_REMOTE_EST = 4, /* Remote Establishment */
+ GPRS_LLES_ABM = 5,
+ GPRS_LLES_LOCAL_REL = 6, /* Local Release */
+ GPRS_LLES_TIMER_REC = 7, /* Timer Recovery */
+};
+
+enum gprs_llc_llme_state {
+ GPRS_LLMS_UNASSIGNED = 1, /* No TLLI yet */
+ GPRS_LLMS_ASSIGNED = 2, /* TLLI assigned */
+};
+
+/* Section 8.9.9 LLC layer parameter default values */
+struct gprs_llc_params {
+ uint16_t iov_i_exp;
+ uint16_t t200_201;
+ uint16_t n200;
+ uint16_t n201_u;
+ uint16_t n201_i;
+ uint16_t mD;
+ uint16_t mU;
+ uint16_t kD;
+ uint16_t kU;
+};
+
+/* Section 4.7.1: Logical Link Entity: One per DLCI (TLLI + SAPI) */
+struct gprs_llc_lle {
+ struct llist_head list;
+
+ uint32_t sapi;
+
+ struct gprs_llc_llme *llme;
+
+ enum gprs_llc_lle_state state;
+
+ struct osmo_timer_list t200;
+ struct osmo_timer_list t201; /* wait for acknowledgement */
+
+ uint16_t v_sent;
+ uint16_t v_ack;
+ uint16_t v_recv;
+
+ uint16_t vu_send;
+ uint16_t vu_recv;
+
+ /* non-standard LLC state */
+ uint16_t vu_recv_last;
+ uint16_t vu_recv_duplicates;
+
+ /* Overflow Counter for ABM */
+ uint32_t oc_i_send;
+ uint32_t oc_i_recv;
+
+ /* Overflow Counter for unconfirmed transfer */
+ uint32_t oc_ui_send;
+ uint32_t oc_ui_recv;
+
+ unsigned int retrans_ctr;
+
+ struct gprs_llc_params params;
+};
+
+#define NUM_SAPIS 16
+
+struct gprs_llc_llme {
+ struct llist_head list;
+
+ enum gprs_llc_llme_state state;
+
+ uint32_t tlli;
+ uint32_t old_tlli;
+
+ /* Crypto parameters */
+ enum gprs_ciph_algo algo;
+ uint8_t kc[8];
+
+ /* over which BSSGP BTS ctx do we need to transmit */
+ uint16_t bvci;
+ uint16_t nsei;
+ struct gprs_llc_lle lle[NUM_SAPIS];
+};
+
+extern struct llist_head gprs_llc_llmes;
+
+/* BSSGP-UL-UNITDATA.ind */
+int gprs_llc_rcvmsg(struct msgb *msg, struct tlv_parsed *tv);
+
+/* LL-UNITDATA.req */
+int gprs_llc_tx_ui(struct msgb *msg, uint8_t sapi, int command,
+ void *mmctx);
+
+/* Chapter 7.2.1.2 LLGMM-RESET.req */
+int gprs_llgmm_reset(struct gprs_llc_llme *llme);
+
+/* 04.64 Chapter 7.2.1.1 LLGMM-ASSIGN */
+int gprs_llgmm_assign(struct gprs_llc_llme *llme,
+ uint32_t old_tlli, uint32_t new_tlli,
+ enum gprs_ciph_algo alg, const uint8_t *kc);
+
+int gprs_llc_init(const char *cipher_plugin_path);
+int gprs_llc_vty_init(void);
+
+/**
+ * \short Check if N(U) should be considered a retransmit
+ *
+ * Implements the range check as of GSM 04.64 8.4.2
+ * Receipt of unacknowledged information.
+ *
+ * @returns Returns 1 if (V(UR)-32) <= N(U) < V(UR)
+ * @param nu N(U) unconfirmed sequence number of the UI frame
+ * @param vur V(UR) unconfirmend received state variable
+ */
+static inline int gprs_llc_is_retransmit(uint16_t nu, uint16_t vur)
+{
+ int delta = (vur - nu) & 0x1ff;
+ return 0 < delta && delta < 32;
+}
+
+#endif
diff --git a/include/osmocom/bsc/gprs_sgsn.h b/include/osmocom/bsc/gprs_sgsn.h
new file mode 100644
index 000000000..8074d8f9b
--- /dev/null
+++ b/include/osmocom/bsc/gprs_sgsn.h
@@ -0,0 +1,222 @@
+#ifndef _GPRS_SGSN_H
+#define _GPRS_SGSN_H
+
+#include <stdint.h>
+#include <netinet/in.h>
+
+#include <osmocom/core/timer.h>
+
+#include <osmocom/gsm/gsm48.h>
+
+#include <osmocom/crypt/gprs_cipher.h>
+
+#define GSM_IMSI_LENGTH 17
+#define GSM_IMEI_LENGTH 17
+#define GSM_EXTENSION_LENGTH 15
+
+struct gprs_llc_lle;
+
+/* TS 04.08 4.1.3.3 GMM mobility management states on the network side */
+enum gprs_mm_state {
+ GMM_DEREGISTERED, /* 4.1.3.3.1.1 */
+ GMM_COMMON_PROC_INIT, /* 4.1.3.3.1.2 */
+ GMM_REGISTERED_NORMAL, /* 4.1.3.3.2.1 */
+ GMM_REGISTERED_SUSPENDED, /* 4.1.3.3.2.2 */
+ GMM_DEREGISTERED_INIT, /* 4.1.3.3.1.4 */
+};
+
+enum gprs_mm_ctr {
+ GMM_CTR_PKTS_SIG_IN,
+ GMM_CTR_PKTS_SIG_OUT,
+ GMM_CTR_PKTS_UDATA_IN,
+ GMM_CTR_PKTS_UDATA_OUT,
+ GMM_CTR_BYTES_UDATA_IN,
+ GMM_CTR_BYTES_UDATA_OUT,
+ GMM_CTR_PDP_CTX_ACT,
+ GMM_CTR_SUSPEND,
+ GMM_CTR_PAGING_PS,
+ GMM_CTR_PAGING_CS,
+ GMM_CTR_RA_UPDATE,
+};
+
+enum gprs_pdp_ctx {
+ PDP_CTR_PKTS_UDATA_IN,
+ PDP_CTR_PKTS_UDATA_OUT,
+ PDP_CTR_BYTES_UDATA_IN,
+ PDP_CTR_BYTES_UDATA_OUT,
+};
+
+enum gprs_t3350_mode {
+ GMM_T3350_MODE_ATT,
+ GMM_T3350_MODE_RAU,
+ GMM_T3350_MODE_PTMSI_REALL,
+};
+
+#define MS_RADIO_ACCESS_CAPA
+
+/* According to TS 03.60, Table 5: SGSN MM and PDP Contexts */
+/* Extended by 3GPP TS 23.060, Table 6: SGSN MM and PDP Contexts */
+struct sgsn_mm_ctx {
+ struct llist_head list;
+
+ char imsi[GSM_IMSI_LENGTH];
+ enum gprs_mm_state mm_state;
+ uint32_t p_tmsi;
+ uint32_t p_tmsi_old; /* old P-TMSI before new is confirmed */
+ uint32_t p_tmsi_sig;
+ char imei[GSM_IMEI_LENGTH];
+ /* Opt: Software Version Numbber / TS 23.195 */
+ char msisdn[GSM_EXTENSION_LENGTH];
+ struct gprs_ra_id ra;
+ uint16_t cell_id;
+ uint32_t cell_id_age;
+ uint16_t sac; /* Iu: Service Area Code */
+ uint32_t sac_age;/* Iu: Service Area Code age */
+ /* VLR number */
+ uint32_t new_sgsn_addr;
+ /* Authentication Triplets */
+ /* Kc */
+ /* Iu: CK, IK, KSI */
+ /* CKSN */
+ enum gprs_ciph_algo ciph_algo;
+ struct {
+ uint8_t len;
+ uint8_t buf[50]; /* GSM 04.08 10.5.5.12a, extended in TS 24.008 */
+ } ms_radio_access_capa;
+ struct {
+ uint8_t len;
+ uint8_t buf[8]; /* GSM 04.08 10.5.5.12, extended in TS 24.008 */
+ } ms_network_capa;
+ uint16_t drx_parms;
+ int mnrg; /* MS reported to HLR? */
+ int ngaf; /* MS reported to MSC/VLR? */
+ int ppf; /* paging for GPRS + non-GPRS? */
+ /* SMS Parameters */
+ int recovery;
+ uint8_t radio_prio_sms;
+
+ struct llist_head pdp_list;
+
+ /* Additional bits not present in the GSM TS */
+ struct gprs_llc_llme *llme;
+ uint32_t tlli;
+ uint32_t tlli_new;
+ uint16_t nsei;
+ uint16_t bvci;
+ struct rate_ctr_group *ctrg;
+ struct osmo_timer_list timer;
+ unsigned int T; /* Txxxx number */
+ unsigned int num_T_exp; /* number of consecutive T expirations */
+
+ enum gprs_t3350_mode t3350_mode;
+ uint8_t t3370_id_type;
+};
+
+/* look-up a SGSN MM context based on TLLI + RAI */
+struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli(uint32_t tlli,
+ const struct gprs_ra_id *raid);
+struct sgsn_mm_ctx *sgsn_mm_ctx_by_ptmsi(uint32_t tmsi);
+struct sgsn_mm_ctx *sgsn_mm_ctx_by_imsi(const char *imsi);
+
+/* Allocate a new SGSN MM context */
+struct sgsn_mm_ctx *sgsn_mm_ctx_alloc(uint32_t tlli,
+ const struct gprs_ra_id *raid);
+void sgsn_mm_ctx_free(struct sgsn_mm_ctx *mm);
+
+
+enum pdp_ctx_state {
+ PDP_STATE_NONE,
+ PDP_STATE_CR_REQ,
+ PDP_STATE_CR_CONF,
+
+ /* 04.08 / Figure 6.2 / 6.1.2.2 */
+ PDP_STATE_INACT_PEND,
+ PDP_STATE_INACTIVE = PDP_STATE_NONE,
+};
+
+enum pdp_type {
+ PDP_TYPE_NONE,
+ PDP_TYPE_ETSI_PPP,
+ PDP_TYPE_IANA_IPv4,
+ PDP_TYPE_IANA_IPv6,
+};
+
+struct sgsn_pdp_ctx {
+ struct llist_head list; /* list_head for mmctx->pdp_list */
+ struct llist_head g_list; /* list_head for global list */
+ struct sgsn_mm_ctx *mm; /* back pointer to MM CTX */
+ struct sgsn_ggsn_ctx *ggsn; /* which GGSN serves this PDP */
+ struct rate_ctr_group *ctrg;
+
+ //unsigned int id;
+ struct pdp_t *lib; /* pointer to libgtp PDP ctx */
+ enum pdp_ctx_state state;
+ enum pdp_type type;
+ uint32_t address;
+ char *apn_subscribed;
+ //char *apn_used;
+ uint16_t nsapi; /* SNDCP */
+ uint16_t sapi; /* LLC */
+ uint8_t ti; /* transaction identifier */
+ int vplmn_allowed;
+ uint32_t qos_profile_subscr;
+ //uint32_t qos_profile_req;
+ //uint32_t qos_profile_neg;
+ uint8_t radio_prio;
+ uint32_t tx_npdu_nr;
+ uint32_t rx_npdu_nr;
+ uint32_t tx_gtp_snd;
+ uint32_t rx_gtp_snu;
+ //uint32_t charging_id;
+ int reordering_reqd;
+
+ struct osmo_timer_list timer;
+ unsigned int T; /* Txxxx number */
+ unsigned int num_T_exp; /* number of consecutive T expirations */
+};
+
+
+/* look up PDP context by MM context and NSAPI */
+struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_nsapi(const struct sgsn_mm_ctx *mm,
+ uint8_t nsapi);
+/* look up PDP context by MM context and transaction ID */
+struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_tid(const struct sgsn_mm_ctx *mm,
+ uint8_t tid);
+
+struct sgsn_pdp_ctx *sgsn_pdp_ctx_alloc(struct sgsn_mm_ctx *mm,
+ uint8_t nsapi);
+void sgsn_pdp_ctx_free(struct sgsn_pdp_ctx *pdp);
+
+
+struct sgsn_ggsn_ctx {
+ struct llist_head list;
+ uint32_t id;
+ unsigned int gtp_version;
+ struct in_addr remote_addr;
+ int remote_restart_ctr;
+ struct gsn_t *gsn;
+};
+struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(uint32_t id);
+struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(uint32_t id);
+struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct in_addr *addr);
+struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(uint32_t id);
+
+struct apn_ctx {
+ struct llist_head list;
+ struct sgsn_ggsn_ctx *ggsn;
+ char *name;
+ char *description;
+};
+
+extern struct llist_head sgsn_mm_ctxts;
+extern struct llist_head sgsn_ggsn_ctxts;
+extern struct llist_head sgsn_apn_ctxts;
+extern struct llist_head sgsn_pdp_ctxts;
+
+uint32_t sgsn_alloc_ptmsi(void);
+
+/* High-level function to be called in case a GGSN has disappeared or
+ * ottherwise lost state (recovery procedure) */
+int drop_all_pdp_for_ggsn(struct sgsn_ggsn_ctx *ggsn);
+
+#endif /* _GPRS_SGSN_H */
diff --git a/include/osmocom/bsc/gsm_04_08.h b/include/osmocom/bsc/gsm_04_08.h
new file mode 100644
index 000000000..2f5aaa98c
--- /dev/null
+++ b/include/osmocom/bsc/gsm_04_08.h
@@ -0,0 +1,75 @@
+#ifndef _GSM_04_08_H
+#define _GSM_04_08_H
+
+#include <osmocom/gsm/gsm48.h>
+#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/protocol/gsm_04_08.h>
+
+#include <openbsc/meas_rep.h>
+
+struct msgb;
+struct gsm_bts;
+struct gsm_subscriber;
+struct gsm_network;
+struct gsm_trans;
+struct gsm_subscriber_connection;
+
+#define GSM48_ALLOC_SIZE 2048
+#define GSM48_ALLOC_HEADROOM 256
+
+static inline struct msgb *gsm48_msgb_alloc(void)
+{
+ return msgb_alloc_headroom(GSM48_ALLOC_SIZE, GSM48_ALLOC_HEADROOM,
+ "GSM 04.08");
+}
+
+/* config options controlling the behaviour of the lower leves */
+void gsm0408_allow_everyone(int allow);
+void gsm0408_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause);
+void gsm0408_clear_all_trans(struct gsm_network *net, int protocol);
+int gsm0408_dispatch(struct gsm_subscriber_connection *conn, struct msgb *msg);
+
+int gsm0408_rcvmsg(struct msgb *msg, uint8_t link_id);
+int gsm0408_new_conn(struct gsm_subscriber_connection *conn);
+enum gsm_chan_t get_ctype_by_chreq(struct gsm_network *bts, uint8_t ra);
+/* don't use "enum gsm_chreq_reason_t" to avoid circular dependency */
+int get_reason_by_chreq(uint8_t ra, int neci);
+void gsm_net_update_ctype(struct gsm_network *net);
+
+int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn);
+int gsm48_tx_mm_auth_req(struct gsm_subscriber_connection *conn, uint8_t *rand, int key_seq);
+int gsm48_tx_mm_auth_rej(struct gsm_subscriber_connection *conn);
+int gsm48_send_rr_release(struct gsm_lchan *lchan);
+int gsm48_send_rr_ciph_mode(struct gsm_lchan *lchan, int want_imeisv);
+int gsm48_send_rr_app_info(struct gsm_subscriber_connection *conn, uint8_t apdu_id,
+ uint8_t apdu_len, const uint8_t *apdu);
+int gsm48_send_rr_ass_cmd(struct gsm_lchan *dest_lchan, struct gsm_lchan *lchan, uint8_t power_class);
+int gsm48_send_ho_cmd(struct gsm_lchan *old_lchan, struct gsm_lchan *new_lchan,
+ uint8_t power_command, uint8_t ho_ref);
+
+int mncc_tx_to_cc(struct gsm_network *net, int msg_type, void *arg);
+
+/* convert a ASCII phone number to call-control BCD */
+int encode_bcd_number(uint8_t *bcd_lv, uint8_t max_len,
+ int h_len, const char *input);
+int decode_bcd_number(char *output, int output_len, const uint8_t *bcd_lv,
+ int h_len);
+
+int send_siemens_mrpci(struct gsm_lchan *lchan, uint8_t *classmark2_lv);
+int gsm48_extract_mi(uint8_t *classmark2, int length, char *mi_string, uint8_t *mi_type);
+int gsm48_paging_extract_mi(struct gsm48_pag_resp *pag, int length, char *mi_string, uint8_t *mi_type);
+int gsm48_handle_paging_resp(struct gsm_subscriber_connection *conn, struct msgb *msg, struct gsm_subscriber *subscr);
+
+int gsm48_lchan_modify(struct gsm_lchan *lchan, uint8_t lchan_mode);
+int gsm48_rx_rr_modif_ack(struct msgb *msg);
+int gsm48_parse_meas_rep(struct gsm_meas_rep *rep, struct msgb *msg);
+
+struct msgb *gsm48_create_mm_serv_rej(enum gsm48_reject_value value);
+struct msgb *gsm48_create_loc_upd_rej(uint8_t cause);
+void gsm48_lchan2chan_desc(struct gsm48_chan_desc *cd,
+ const struct gsm_lchan *lchan);
+
+void release_security_operation(struct gsm_subscriber_connection *conn);
+void allocate_security_operation(struct gsm_subscriber_connection *conn);
+
+#endif
diff --git a/include/osmocom/bsc/gsm_04_08_gprs.h b/include/osmocom/bsc/gsm_04_08_gprs.h
new file mode 100644
index 000000000..cd2a08c59
--- /dev/null
+++ b/include/osmocom/bsc/gsm_04_08_gprs.h
@@ -0,0 +1,381 @@
+#ifndef _GSM48_GPRS_H
+#define _GSM48_GPRS_H
+
+#include <stdint.h>
+#include <osmocom/gsm/protocol/gsm_04_08.h>
+
+/* Table 10.4 / 10.4a, GPRS Mobility Management (GMM) */
+#define GSM48_MT_GMM_ATTACH_REQ 0x01
+#define GSM48_MT_GMM_ATTACH_ACK 0x02
+#define GSM48_MT_GMM_ATTACH_COMPL 0x03
+#define GSM48_MT_GMM_ATTACH_REJ 0x04
+#define GSM48_MT_GMM_DETACH_REQ 0x05
+#define GSM48_MT_GMM_DETACH_ACK 0x06
+
+#define GSM48_MT_GMM_RA_UPD_REQ 0x08
+#define GSM48_MT_GMM_RA_UPD_ACK 0x09
+#define GSM48_MT_GMM_RA_UPD_COMPL 0x0a
+#define GSM48_MT_GMM_RA_UPD_REJ 0x0b
+
+#define GSM48_MT_GMM_PTMSI_REALL_CMD 0x10
+#define GSM48_MT_GMM_PTMSI_REALL_COMPL 0x11
+#define GSM48_MT_GMM_AUTH_CIPH_REQ 0x12
+#define GSM48_MT_GMM_AUTH_CIPH_RESP 0x13
+#define GSM48_MT_GMM_AUTH_CIPH_REJ 0x14
+#define GSM48_MT_GMM_ID_REQ 0x15
+#define GSM48_MT_GMM_ID_RESP 0x16
+#define GSM48_MT_GMM_STATUS 0x20
+#define GSM48_MT_GMM_INFO 0x21
+
+/* Table 10.4a, GPRS Session Management (GSM) */
+#define GSM48_MT_GSM_ACT_PDP_REQ 0x41
+#define GSM48_MT_GSM_ACT_PDP_ACK 0x42
+#define GSM48_MT_GSM_ACT_PDP_REJ 0x43
+#define GSM48_MT_GSM_REQ_PDP_ACT 0x44
+#define GSM48_MT_GSM_REQ_PDP_ACT_REJ 0x45
+#define GSM48_MT_GSM_DEACT_PDP_REQ 0x46
+#define GSM48_MT_GSM_DEACT_PDP_ACK 0x47
+#define GSM48_MT_GSM_ACT_AA_PDP_REQ 0x50
+#define GSM48_MT_GSM_ACT_AA_PDP_ACK 0x51
+#define GSM48_MT_GSM_ACT_AA_PDP_REJ 0x52
+#define GSM48_MT_GSM_DEACT_AA_PDP_REQ 0x53
+#define GSM48_MT_GSM_DEACT_AA_PDP_ACK 0x54
+#define GSM48_MT_GSM_STATUS 0x55
+
+/* Chapter 10.5.5.2 / Table 10.5.135 */
+#define GPRS_ATT_T_ATTACH 1
+#define GPRS_ATT_T_ATT_WHILE_IMSI 2
+#define GPRS_ATT_T_COMBINED 3
+
+/* Chapter 10.5.5.5 / Table 10.5.138 */
+#define GPRS_DET_T_MO_GPRS 1
+#define GPRS_DET_T_MO_IMSI 2
+#define GPRS_DET_T_MO_COMBINED 3
+/* Network to MS direction */
+#define GPRS_DET_T_MT_REATT_REQ 1
+#define GPRS_DET_T_MT_REATT_NOTREQ 2
+#define GPRS_DET_T_MT_IMSI 3
+
+/* Chapter 10.5.5.18 / Table 105.150 */
+#define GPRS_UPD_T_RA 0
+#define GPRS_UPD_T_RA_LA 1
+#define GPRS_UPD_T_RA_LA_IMSI_ATT 2
+#define GPRS_UPD_T_PERIODIC 3
+
+enum gsm48_gprs_ie_mm {
+ GSM48_IE_GMM_CIPH_CKSN = 0x08, /* 10.5.1.2 */
+ GSM48_IE_GMM_TIMER_READY = 0x17, /* 10.5.7.3 */
+ GSM48_IE_GMM_ALLOC_PTMSI = 0x18, /* 10.5.1.4 */
+ GSM48_IE_GMM_PTMSI_SIG = 0x19, /* 10.5.5.8 */
+ GSM48_IE_GMM_AUTH_RAND = 0x21, /* 10.5.3.1 */
+ GSM48_IE_GMM_AUTH_SRES = 0x22, /* 10.5.3.2 */
+ GSM48_IE_GMM_IMEISV = 0x23, /* 10.5.1.4 */
+ GSM48_IE_GMM_DRX_PARAM = 0x27, /* 10.5.5.6 */
+ GSM48_IE_GMM_MS_NET_CAPA = 0x31, /* 10.5.5.12 */
+ GSM48_IE_GMM_PDP_CTX_STATUS = 0x32, /* 10.5.7.1 */
+ GSM48_IE_GMM_PS_LCS_CAPA = 0x33, /* 10.5.5.22 */
+ GSM48_IE_GMM_GMM_MBMS_CTX_ST = 0x35, /* 10.5.7.6 */
+};
+
+enum gsm48_gprs_ie_sm {
+ GSM48_IE_GSM_APN = 0x28, /* 10.5.6.1 */
+ GSM48_IE_GSM_PROTO_CONF_OPT = 0x27, /* 10.5.6.3 */
+ GSM48_IE_GSM_PDP_ADDR = 0x2b, /* 10.5.6.4 */
+ GSM48_IE_GSM_AA_TMR = 0x29, /* 10.5.7.3 */
+ GSM48_IE_GSM_NAME_FULL = 0x43, /* 10.5.3.5a */
+ GSM48_IE_GSM_NAME_SHORT = 0x45, /* 10.5.3.5a */
+ GSM48_IE_GSM_TIMEZONE = 0x46, /* 10.5.3.8 */
+ GSM48_IE_GSM_UTC_AND_TZ = 0x47, /* 10.5.3.9 */
+ GSM48_IE_GSM_LSA_ID = 0x48, /* 10.5.3.11 */
+
+ /* Fake IEs that are not present on the Layer3 air interface,
+ * but which we use to simplify internal APIs */
+ OSMO_IE_GSM_REQ_QOS = 0xfd,
+ OSMO_IE_GSM_REQ_PDP_ADDR = 0xfe,
+};
+
+/* Chapter 9.4.15 / Table 9.4.15 */
+struct gsm48_ra_upd_ack {
+ uint8_t force_stby:4, /* 10.5.5.7 */
+ upd_result:4; /* 10.5.5.17 */
+ uint8_t ra_upd_timer; /* 10.5.7.3 */
+ struct gsm48_ra_id ra_id; /* 10.5.5.15 */
+ uint8_t data[0];
+} __attribute__((packed));
+
+/* Chapter 10.5.7.3 */
+enum gsm48_gprs_tmr_unit {
+ GPRS_TMR_2SECONDS = 0 << 5,
+ GPRS_TMR_MINUTE = 1 << 5,
+ GPRS_TMR_6MINUTE = 2 << 5,
+ GPRS_TMR_DEACTIVATED = 3 << 5,
+};
+
+/* Chapter 9.4.2 / Table 9.4.2 */
+struct gsm48_attach_ack {
+ uint8_t att_result:4, /* 10.5.5.7 */
+ force_stby:4; /* 10.5.5.1 */
+ uint8_t ra_upd_timer; /* 10.5.7.3 */
+ uint8_t radio_prio; /* 10.5.7.2 */
+ struct gsm48_ra_id ra_id; /* 10.5.5.15 */
+ uint8_t data[0];
+} __attribute__((packed));
+
+/* Chapter 9.4.9 / Table 9.4.9 */
+struct gsm48_auth_ciph_req {
+ uint8_t ciph_alg:4, /* 10.5.5.3 */
+ imeisv_req:4; /* 10.5.5.10 */
+ uint8_t force_stby:4, /* 10.5.5.7 */
+ ac_ref_nr:4; /* 10.5.5.19 */
+ uint8_t data[0];
+} __attribute__((packed));
+/* optional: TV RAND, TV CKSN */
+
+struct gsm48_auth_ciph_resp {
+ uint8_t ac_ref_nr:4,
+ spare:4;
+ uint8_t data[0];
+} __attribute__((packed));
+
+/* Chapter 9.5.1 / Table 9.5.1 */
+struct gsm48_act_pdp_ctx_req {
+ uint8_t req_nsapi;
+ uint8_t req_llc_sapi;
+ uint8_t data[0];
+} __attribute__((packed));
+
+/* Chapter 10.5.5.14 / Table 10.5.147 */
+enum gsm48_gmm_cause {
+ GMM_CAUSE_IMSI_UNKNOWN = 0x02,
+ GMM_CAUSE_ILLEGAL_MS = 0x03,
+ GMM_CAUSE_ILLEGAL_ME = 0x06,
+ GMM_CAUSE_GPRS_NOTALLOWED = 0x07,
+ GMM_CAUSE_GPRS_OTHER_NOTALLOWED = 0x08,
+ GMM_CAUSE_MS_ID_NOT_DERIVED = 0x09,
+ GMM_CAUSE_IMPL_DETACHED = 0x0a,
+ GMM_CAUSE_PLMN_NOTALLOWED = 0x0b,
+ GMM_CAUSE_LA_NOTALLOWED = 0x0c,
+ GMM_CAUSE_ROAMING_NOTALLOWED = 0x0d,
+ GMM_CAUSE_NO_GPRS_PLMN = 0x0e,
+ GMM_CAUSE_MSC_TEMP_NOTREACH = 0x10,
+ GMM_CAUSE_NET_FAIL = 0x11,
+ GMM_CAUSE_CONGESTION = 0x16,
+ GMM_CAUSE_SEM_INCORR_MSG = 0x5f,
+ GMM_CAUSE_INV_MAND_INFO = 0x60,
+ GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL = 0x61,
+ GMM_CAUSE_MSGT_INCOMP_P_STATE = 0x62,
+ GMM_CAUSE_IE_NOTEXIST_NOTIMPL = 0x63,
+ GMM_CAUSE_COND_IE_ERR = 0x64,
+ GMM_CAUSE_MSG_INCOMP_P_STATE = 0x65,
+ GMM_CAUSE_PROTO_ERR_UNSPEC = 0x6f,
+};
+
+/* Chapter 10.4.6.6 / Table 10.5.157 */
+enum gsm48_gsm_cause {
+ GSM_CAUSE_INSUFF_RSRC = 0x1a,
+ GSM_CAUSE_MISSING_APN = 0x1b,
+ GSM_CAUSE_UNKNOWN_PDP = 0x1c,
+ GSM_CAUSE_AUTH_FAILED = 0x1d,
+ GSM_CAUSE_ACT_REJ_GGSN = 0x1e,
+ GSM_CAUSE_ACT_REJ_UNSPEC = 0x1f,
+ GSM_CAUSE_SERV_OPT_NOTSUPP = 0x20,
+ GSM_CAUSE_REQ_SERV_OPT_NOTSUB = 0x21,
+ GSM_CAUSE_SERV_OPT_TEMP_OOO = 0x22,
+ GSM_CAUSE_NSAPI_IN_USE = 0x23,
+ GSM_CAUSE_DEACT_REGULAR = 0x24,
+ GSM_CAUSE_QOS_NOT_ACCEPTED = 0x25,
+ GSM_CAUSE_NET_FAIL = 0x26,
+ GSM_CAUSE_REACT_RQD = 0x27,
+ GSM_CAUSE_FEATURE_NOTSUPP = 0x28,
+ GSM_CAUSE_INVALID_TRANS_ID = 0x51,
+ GSM_CAUSE_SEM_INCORR_MSG = 0x5f,
+ GSM_CAUSE_INV_MAND_INFO = 0x60,
+ GSM_CAUSE_MSGT_NOTEXIST_NOTIMPL = 0x61,
+ GSM_CAUSE_MSGT_INCOMP_P_STATE = 0x62,
+ GSM_CAUSE_IE_NOTEXIST_NOTIMPL = 0x63,
+ GSM_CAUSE_COND_IE_ERR = 0x64,
+ GSM_CAUSE_MSG_INCOMP_P_STATE = 0x65,
+ GSM_CAUSE_PROTO_ERR_UNSPEC = 0x6f,
+};
+
+/* Section 6.1.2.2: Session management states on the network side */
+enum gsm48_pdp_state {
+ PDP_S_INACTIVE,
+ PDP_S_ACTIVE_PENDING,
+ PDP_S_ACTIVE,
+ PDP_S_INACTIVE_PENDING,
+ PDP_S_MODIFY_PENDING,
+};
+
+/* Table 10.5.155/3GPP TS 24.008 */
+enum gsm48_pdp_type_org {
+ PDP_TYPE_ORG_ETSI = 0x00,
+ PDP_TYPE_ORG_IETF = 0x01,
+};
+enum gsm48_pdp_type_nr {
+ PDP_TYPE_N_ETSI_RESERVED = 0x00,
+ PDP_TYPE_N_ETSI_PPP = 0x01,
+ PDP_TYPE_N_IETF_IPv4 = 0x21,
+ PDP_TYPE_N_IETF_IPv6 = 0x57,
+};
+
+/* Figure 10.5.138/24.008 / Chapter 10.5.6.5 */
+enum gsm48_qos_reliab_class {
+ GSM48_QOS_RC_LLC_ACK_RLC_ACK_DATA_PROT = 2,
+ GSM48_QOS_RC_LLC_UN_RLC_ACK_DATA_PROT = 3,
+ GSM48_QOS_RC_LLC_UN_RLC_UN_PROT_DATA = 4,
+ GSM48_QOS_RC_LLC_UN_RLC_UN_DATA_UN = 5,
+};
+
+/* Figure 10.5.138/24.008 / Chapter 10.5.6.5 */
+enum gsm48_qos_preced_class {
+ GSM48_QOS_PC_HIGH = 1,
+ GSM48_QOS_PC_NORMAL = 2,
+ GSM48_QOS_PC_LOW = 3,
+};
+
+/* Figure 10.5.138/24.008 / Chapter 10.5.6.5 */
+enum gsm48_qos_peak_tput {
+ GSM48_QOS_PEAK_TPUT_1000bps = 1,
+ GSM48_QOS_PEAK_TPUT_2000bps = 2,
+ GSM48_QOS_PEAK_TPUT_4000bps = 3,
+ GSM48_QOS_PEAK_TPUT_8000bps = 4,
+ GSM48_QOS_PEAK_TPUT_16000bps = 5,
+ GSM48_QOS_PEAK_TPUT_32000bps = 6,
+ GSM48_QOS_PEAK_TPUT_64000bps = 7,
+ GSM48_QOS_PEAK_TPUT_128000bps = 8,
+ GSM48_QOS_PEAK_TPUT_256000bps = 9,
+};
+
+/* Figure 10.5.138/24.008 / Chapter 10.5.6.5 */
+enum gsm48_qos_mean_tput {
+ GSM48_QOS_MEAN_TPUT_100bph = 1,
+ GSM48_QOS_MEAN_TPUT_200bph = 2,
+ GSM48_QOS_MEAN_TPUT_500bph = 3,
+ GSM48_QOS_MEAN_TPUT_1000bph = 4,
+ GSM48_QOS_MEAN_TPUT_2000bph = 5,
+ GSM48_QOS_MEAN_TPUT_5000bph = 6,
+ GSM48_QOS_MEAN_TPUT_10000bph = 7,
+ GSM48_QOS_MEAN_TPUT_20000bph = 8,
+ GSM48_QOS_MEAN_TPUT_50000bph = 9,
+ GSM48_QOS_MEAN_TPUT_100kbph = 10,
+ GSM48_QOS_MEAN_TPUT_200kbph = 11,
+ GSM48_QOS_MEAN_TPUT_500kbph = 0xc,
+ GSM48_QOS_MEAN_TPUT_1Mbph = 0xd,
+ GSM48_QOS_MEAN_TPUT_2Mbph = 0xe,
+ GSM48_QOS_MEAN_TPUT_5Mbph = 0xf,
+ GSM48_QOS_MEAN_TPUT_10Mbph = 0x10,
+ GSM48_QOS_MEAN_TPUT_20Mbph = 0x11,
+ GSM48_QOS_MEAN_TPUT_50Mbph = 0x12,
+ GSM48_QOS_MEAN_TPUT_BEST_EFFORT = 0x1f,
+};
+
+/* Figure 10.5.138/24.008 / Chapter 10.5.6.5 */
+enum gsm48_qos_err_sdu {
+ GSM48_QOS_ERRSDU_NODETECT = 1,
+ GSM48_QOS_ERRSDU_YES = 2,
+ GSM48_QOS_ERRSDU_NO = 3,
+};
+
+/* Figure 10.5.138/24.008 / Chapter 10.5.6.5 */
+enum gsm48_qos_deliv_order {
+ GSM48_QOS_DO_ORDERED = 1,
+ GSM48_QOS_DO_UNORDERED = 2,
+};
+
+/* Figure 10.5.138/24.008 / Chapter 10.5.6.5 */
+enum gsm48_qos_traf_class {
+ GSM48_QOS_TC_CONVERSATIONAL = 1,
+ GSM48_QOS_TC_STREAMING = 2,
+ GSM48_QOS_TC_INTERACTIVE = 3,
+ GSM48_QOS_TC_BACKGROUND = 4,
+};
+
+/* Figure 10.5.138/24.008 / Chapter 10.5.6.5 */
+enum gsm48_qos_max_sdu_size {
+ /* values below in 10 octet granularity */
+ GSM48_QOS_MAXSDU_1502 = 0x97,
+ GSM48_QOS_MAXSDU_1510 = 0x98,
+ GSM48_QOS_MAXSDU_1520 = 0x99,
+};
+
+/* Figure 10.5.138/24.008 / Chapter 10.5.6.5 */
+enum gsm48_qos_max_bitrate {
+ GSM48_QOS_MBRATE_1k = 0x01,
+ GSM48_QOS_MBRATE_63k = 0x3f,
+ GSM48_QOS_MBRATE_64k = 0x40,
+ GSM48_QOS_MBRATE_568k = 0x7f,
+ GSM48_QOS_MBRATE_576k = 0x80,
+ GSM48_QOS_MBRATE_8640k = 0xfe,
+ GSM48_QOS_MBRATE_0k = 0xff,
+};
+
+/* Figure 10.5.138/24.008 / Chapter 10.5.6.5 */
+enum gsm48_qos_resid_ber {
+ GSM48_QOS_RBER_5e_2 = 0x01,
+ GSM48_QOS_RBER_1e_2 = 0x02,
+ GSM48_QOS_RBER_5e_3 = 0x03,
+ GSM48_QOS_RBER_4e_3 = 0x04,
+ GSM48_QOS_RBER_1e_3 = 0x05,
+ GSM48_QOS_RBER_1e_4 = 0x06,
+ GSM48_QOS_RBER_1e_5 = 0x07,
+ GSM48_QOS_RBER_1e_6 = 0x08,
+ GSM48_QOS_RBER_6e_8 = 0x09,
+};
+
+/* Figure 10.5.138/24.008 / Chapter 10.5.6.5 */
+enum gsm48_qos_sdu_err {
+ GSM48_QOS_SERR_1e_2 = 0x01,
+ GSM48_QOS_SERR_7e_2 = 0x02,
+ GSM48_QOS_SERR_1e_3 = 0x03,
+ GSM48_QOS_SERR_1e_4 = 0x04,
+ GSM48_QOS_SERR_1e_5 = 0x05,
+ GSM48_QOS_SERR_1e_6 = 0x06,
+ GSM48_QOS_SERR_1e_1 = 0x07,
+};
+
+/* Figure 10.5.138/24.008 / Chapter 10.5.6.5 */
+struct gsm48_qos {
+ /* octet 3 */
+ uint8_t reliab_class:3;
+ uint8_t delay_class:3;
+ uint8_t spare:2;
+ /* octet 4 */
+ uint8_t preced_class:3;
+ uint8_t spare2:1;
+ uint8_t peak_tput:4;
+ /* octet 5 */
+ uint8_t mean_tput:5;
+ uint8_t spare3:3;
+ /* octet 6 */
+ uint8_t deliv_err_sdu:3;
+ uint8_t deliv_order:2;
+ uint8_t traf_class:3;
+ /* octet 7 */
+ uint8_t max_sdu_size;
+ /* octet 8 */
+ uint8_t max_bitrate_up;
+ /* octet 9 */
+ uint8_t max_bitrate_down;
+ /* octet 10 */
+ uint8_t sdu_err_ratio:4;
+ uint8_t resid_ber:4;
+ /* octet 11 */
+ uint8_t handling_prio:2;
+ uint8_t xfer_delay:6;
+ /* octet 12 */
+ uint8_t guar_bitrate_up;
+ /* octet 13 */
+ uint8_t guar_bitrate_down;
+ /* octet 14 */
+ uint8_t src_stats_desc:4;
+ uint8_t sig_ind:1;
+ uint8_t spare5:3;
+ /* octet 15 */
+ uint8_t max_bitrate_down_ext;
+ /* octet 16 */
+ uint8_t guar_bitrate_down_ext;
+};
+
+
+#endif /* _GSM48_GPRS_H */
diff --git a/include/osmocom/bsc/gsm_04_11.h b/include/osmocom/bsc/gsm_04_11.h
new file mode 100644
index 000000000..72b694825
--- /dev/null
+++ b/include/osmocom/bsc/gsm_04_11.h
@@ -0,0 +1,40 @@
+#ifndef _GSM_04_11_H
+#define _GSM_04_11_H
+
+#include <osmocom/gsm/protocol/gsm_04_11.h>
+
+#define UM_SAPI_SMS 3 /* See GSM 04.05/04.06 */
+
+/* SMS deliver PDU */
+struct sms_deliver {
+ uint8_t mti:2; /* message type indicator */
+ uint8_t mms:1; /* more messages to send */
+ uint8_t rp:1; /* reply path */
+ uint8_t udhi:1; /* user data header indicator */
+ uint8_t sri:1; /* status report indication */
+ uint8_t *orig_addr; /* originating address */
+ uint8_t pid; /* protocol identifier */
+ uint8_t dcs; /* data coding scheme */
+ /* service centre time stamp */
+ uint8_t ud_len; /* user data length */
+ uint8_t *user_data; /* user data */
+
+ uint8_t msg_ref; /* message reference */
+ uint8_t *smsc;
+};
+
+struct msgb;
+
+int gsm0411_rcv_sms(struct gsm_subscriber_connection *conn, struct msgb *msg);
+
+struct gsm_sms *sms_alloc(void);
+void sms_free(struct gsm_sms *sms);
+struct gsm_sms *sms_from_text(struct gsm_subscriber *receiver, struct gsm_subscriber *sender, int dcs, const char *text);
+
+void _gsm411_sms_trans_free(struct gsm_trans *trans);
+int gsm411_send_sms_subscr(struct gsm_subscriber *subscr,
+ struct gsm_sms *sms);
+int gsm411_send_sms(struct gsm_subscriber_connection *conn,
+ struct gsm_sms *sms);
+void gsm411_sapi_n_reject(struct gsm_subscriber_connection *conn);
+#endif
diff --git a/include/osmocom/bsc/gsm_04_80.h b/include/osmocom/bsc/gsm_04_80.h
new file mode 100644
index 000000000..0a6065234
--- /dev/null
+++ b/include/osmocom/bsc/gsm_04_80.h
@@ -0,0 +1,20 @@
+#ifndef _GSM_04_80_H
+#define _GSM_04_80_H
+
+#include <osmocom/core/msgb.h>
+#include <osmocom/gsm/protocol/gsm_04_80.h>
+#include <osmocom/gsm/gsm0480.h>
+
+struct gsm_subscriber_connection;
+
+int gsm0480_send_ussd_response(struct gsm_subscriber_connection *conn,
+ const struct msgb *in_msg, const char* response_text,
+ const struct ussd_request *req);
+int gsm0480_send_ussd_reject(struct gsm_subscriber_connection *conn,
+ const struct msgb *msg,
+ const struct ussd_request *request);
+
+int gsm0480_send_ussdNotify(struct gsm_subscriber_connection *conn, int level, const char *text);
+int gsm0480_send_releaseComplete(struct gsm_subscriber_connection *conn);
+
+#endif
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
new file mode 100644
index 000000000..874150535
--- /dev/null
+++ b/include/osmocom/bsc/gsm_data.h
@@ -0,0 +1,408 @@
+#ifndef _GSM_DATA_H
+#define _GSM_DATA_H
+
+#include <stdint.h>
+
+#include <osmocom/core/timer.h>
+#include <osmocom/core/select.h>
+
+#include <openbsc/rest_octets.h>
+
+/** annotations for msgb ownership */
+#define __uses
+
+#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
+
+struct mncc_sock_state;
+
+#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
+
+enum gsm_security_event {
+ GSM_SECURITY_NOAVAIL,
+ GSM_SECURITY_AUTH_FAILED,
+ GSM_SECURITY_SUCCEEDED,
+ GSM_SECURITY_ALREADY,
+};
+
+struct msgb;
+typedef int gsm_cbfn(unsigned int hooknum,
+ unsigned int event,
+ struct msgb *msg,
+ void *data, void *param);
+
+/* Real authentication information containing Ki */
+enum gsm_auth_algo {
+ AUTH_ALGO_NONE,
+ AUTH_ALGO_XOR,
+ AUTH_ALGO_COMP128v1,
+};
+
+struct gsm_auth_info {
+ enum gsm_auth_algo auth_algo;
+ unsigned int a3a8_ki_len;
+ uint8_t a3a8_ki[16];
+};
+
+struct gsm_auth_tuple {
+ int use_count;
+ int key_seq;
+ uint8_t rand[16];
+ uint8_t sres[4];
+ uint8_t kc[8];
+};
+#define GSM_KEY_SEQ_INVAL 7 /* GSM 04.08 - 10.5.1.2 */
+
+/*
+ * LOCATION UPDATING REQUEST state
+ *
+ * Our current operation is:
+ * - Get imei/tmsi
+ * - Accept/Reject according to global policy
+ */
+struct gsm_loc_updating_operation {
+ struct osmo_timer_list updating_timer;
+ unsigned int waiting_for_imsi : 1;
+ unsigned int waiting_for_imei : 1;
+ unsigned int key_seq : 4;
+};
+
+/*
+ * AUTHENTICATION/CIPHERING state
+ */
+struct gsm_security_operation {
+ struct gsm_auth_tuple atuple;
+ gsm_cbfn *cb;
+ void *cb_data;
+};
+
+/*
+ * A dummy to keep a connection up for at least
+ * a couple of seconds to work around MSC issues.
+ */
+struct gsm_anchor_operation {
+ struct osmo_timer_list timeout;
+};
+
+/* Maximum number of neighbor cells whose average we track */
+#define MAX_NEIGH_MEAS 10
+/* Maximum size of the averaging window for neighbor cells */
+#define MAX_WIN_NEIGH_AVG 10
+
+/* processed neighbor measurements for one cell */
+struct neigh_meas_proc {
+ uint16_t arfcn;
+ uint8_t bsic;
+ uint8_t rxlev[MAX_WIN_NEIGH_AVG];
+ unsigned int rxlev_cnt;
+ uint8_t last_seen_nr;
+};
+
+/* the per subscriber data for lchan */
+struct gsm_subscriber_connection {
+ struct llist_head entry;
+
+ /* To whom we are allocated at the moment */
+ struct gsm_subscriber *subscr;
+
+ /* LU expiration handling */
+ uint8_t expire_timer_stopped;
+
+ /*
+ * Operations that have a state and might be pending
+ */
+ struct gsm_loc_updating_operation *loc_operation;
+ struct gsm_security_operation *sec_operation;
+ struct gsm_anchor_operation *anch_operation;
+
+ /* Are we part of a special "silent" call */
+ int silent_call;
+ int put_channel;
+
+ /* bsc structures */
+ struct osmo_bsc_sccp_con *sccp_con;
+
+ /* back pointers */
+ int in_release;
+ struct gsm_lchan *lchan;
+ struct gsm_lchan *ho_lchan;
+ struct gsm_bts *bts;
+
+ /* for assignment handling */
+ struct osmo_timer_list T10;
+ struct gsm_lchan *secondary_lchan;
+
+};
+
+
+#define ROLE_BSC
+#include "gsm_data_shared.h"
+
+
+/* Some statistics of our network */
+struct gsmnet_stats {
+ struct {
+ struct osmo_counter *total;
+ struct osmo_counter *no_channel;
+ } chreq;
+ struct {
+ struct osmo_counter *attempted;
+ struct osmo_counter *no_channel; /* no channel available */
+ struct osmo_counter *timeout; /* T3103 timeout */
+ struct osmo_counter *completed; /* HO COMPL received */
+ struct osmo_counter *failed; /* HO FAIL received */
+ } handover;
+ struct {
+ struct osmo_counter *attach;
+ struct osmo_counter *normal;
+ struct osmo_counter *periodic;
+ struct osmo_counter *detach;
+ } loc_upd_type;
+ struct {
+ struct osmo_counter *reject;
+ struct osmo_counter *accept;
+ } loc_upd_resp;
+ struct {
+ struct osmo_counter *attempted;
+ struct osmo_counter *detached;
+ struct osmo_counter *completed;
+ struct osmo_counter *expired;
+ } paging;
+ struct {
+ struct osmo_counter *submitted; /* MO SMS submissions */
+ struct osmo_counter *no_receiver;
+ struct osmo_counter *delivered; /* MT SMS deliveries */
+ struct osmo_counter *rp_err_mem;
+ struct osmo_counter *rp_err_other;
+ } sms;
+ struct {
+ struct osmo_counter *mo_setup;
+ struct osmo_counter *mo_connect_ack;
+ struct osmo_counter *mt_setup;
+ struct osmo_counter *mt_connect;
+ } call;
+ struct {
+ struct osmo_counter *rf_fail;
+ struct osmo_counter *rll_err;
+ } chan;
+ struct {
+ struct osmo_counter *oml_fail;
+ struct osmo_counter *rsl_fail;
+ } bts;
+};
+
+enum gsm_auth_policy {
+ GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
+ GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
+ GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
+};
+
+#define GSM_T3101_DEFAULT 10
+#define GSM_T3105_DEFAULT 40
+#define GSM_T3113_DEFAULT 60
+#define GSM_T3122_DEFAULT 10
+
+struct gsm_network {
+ /* global parameters */
+ uint16_t country_code;
+ uint16_t network_code;
+ char *name_long;
+ char *name_short;
+ enum gsm_auth_policy auth_policy;
+ enum gsm48_reject_value reject_cause;
+ int a5_encryption;
+ int neci;
+ int send_mm_info;
+ struct {
+ int active;
+ /* Window RXLEV averaging */
+ unsigned int win_rxlev_avg; /* number of SACCH frames */
+ /* Window RXQUAL averaging */
+ unsigned int win_rxqual_avg; /* number of SACCH frames */
+ /* Window RXLEV neighbouring cells averaging */
+ unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
+
+ /* how often should we check for power budget HO */
+ unsigned int pwr_interval; /* SACCH frames */
+ /* how much better does a neighbor cell have to be ? */
+ unsigned int pwr_hysteresis; /* dBm */
+ /* maximum distacne before we try a handover */
+ unsigned int max_distance; /* TA values */
+ } handover;
+
+ struct gsmnet_stats stats;
+
+ /* layer 4 */
+ struct mncc_sock_state *mncc_state;
+ int (*mncc_recv) (struct gsm_network *net, struct msgb *msg);
+ struct llist_head upqueue;
+ struct llist_head trans_list;
+ struct bsc_api *bsc_api;
+
+ unsigned int num_bts;
+ struct llist_head bts_list;
+
+ /* timer values */
+ int T3101;
+ int T3103;
+ int T3105;
+ int T3107;
+ int T3109;
+ int T3111;
+ int T3113;
+ int T3115;
+ int T3117;
+ int T3119;
+ int T3122;
+ int T3141;
+
+ /* timer to expire old location updates */
+ struct osmo_timer_list subscr_expire_timer;
+
+ /* Radio Resource Location Protocol (TS 04.31) */
+ struct {
+ enum rrlp_mode mode;
+ } rrlp;
+
+ /* enable the DTXu and DTXd for this network */
+ int dtx_enabled;
+
+ enum gsm_chan_t ctype_by_chreq[16];
+
+ /* Use a TCH for handling requests of type paging any */
+ int pag_any_tch;
+
+ /* MSC data in case we are a true BSC */
+ struct osmo_bsc_data *bsc_data;
+
+ /* subscriber related features */
+ int keep_subscr;
+ struct gsm_sms_queue *sms_queue;
+
+ /* control interface */
+ struct ctrl_handle *ctrl;
+};
+
+struct osmo_esme;
+
+enum gsm_sms_source_id {
+ SMS_SOURCE_UNKNOWN = 0,
+ SMS_SOURCE_MS, /* received from MS */
+ SMS_SOURCE_VTY, /* received from VTY */
+ SMS_SOURCE_SMPP, /* received via SMPP */
+};
+
+#define SMS_HDR_SIZE 128
+#define SMS_TEXT_SIZE 256
+
+struct gsm_sms_addr {
+ uint8_t ton;
+ uint8_t npi;
+ char addr[21+1];
+};
+
+struct gsm_sms {
+ unsigned long long id;
+ struct gsm_subscriber *sender;
+ struct gsm_subscriber *receiver;
+ struct gsm_sms_addr src, dst;
+ enum gsm_sms_source_id source;
+
+ struct {
+ struct osmo_esme *esme;
+ uint32_t sequence_nr;
+ int transaction_mode;
+ char msg_id[16];
+ } smpp;
+
+ unsigned long validity_minutes;
+ uint8_t reply_path_req;
+ uint8_t status_rep_req;
+ uint8_t ud_hdr_ind;
+ uint8_t protocol_id;
+ uint8_t data_coding_scheme;
+ uint8_t msg_ref;
+ uint8_t user_data_len;
+ uint8_t user_data[SMS_TEXT_SIZE];
+
+ char text[SMS_TEXT_SIZE];
+};
+
+struct gsm_network *gsm_network_init(uint16_t country_code, uint16_t network_code,
+ int (*mncc_recv)(struct gsm_network *, struct msgb *));
+int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
+
+struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
+
+/* Get reference to a neighbor cell on a given BCCH ARFCN */
+struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts,
+ uint16_t arfcn, uint8_t bsic);
+
+enum gsm_bts_type parse_btstype(const char *arg);
+const char *btstype2str(enum gsm_bts_type type);
+struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
+ struct gsm_bts *start_bts);
+
+extern void *tall_bsc_ctx;
+extern int ipacc_rtp_direct;
+
+/* this actaully refers to the IPA transport, not the BTS model */
+static inline int is_ipaccess_bts(struct gsm_bts *bts)
+{
+ switch (bts->type) {
+ case GSM_BTS_TYPE_NANOBTS:
+ case GSM_BTS_TYPE_OSMO_SYSMO:
+ return 1;
+ default:
+ break;
+ }
+ return 0;
+}
+
+static inline int is_siemens_bts(struct gsm_bts *bts)
+{
+ switch (bts->type) {
+ case GSM_BTS_TYPE_BS11:
+ return 1;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
+const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
+
+enum rrlp_mode rrlp_mode_parse(const char *arg);
+const char *rrlp_mode_name(enum rrlp_mode mode);
+
+enum bts_gprs_mode bts_gprs_mode_parse(const char *arg);
+const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
+
+int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts);
+void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
+struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan);
+
+int gsm_btsmodel_set_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
+int gsm_bts_model_register(struct gsm_bts_model *model);
+
+struct gsm_subscriber_connection *subscr_con_allocate(struct gsm_lchan *lchan);
+void subscr_con_free(struct gsm_subscriber_connection *conn);
+
+struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net,
+ enum gsm_bts_type type,
+ uint8_t tsc, uint8_t bsic);
+void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
+ uint8_t e1_ts, uint8_t e1_ts_ss);
+
+void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
+int gsm_bts_has_feature(struct gsm_bts *bts, enum gsm_bts_features feat);
+struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
+
+/* generic E1 line operations for all ISDN-based BTS. */
+extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
+
+extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
+extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
+
+#endif /* _GSM_DATA_H */
diff --git a/include/osmocom/bsc/gsm_data_shared.h b/include/osmocom/bsc/gsm_data_shared.h
new file mode 100644
index 000000000..3ef145765
--- /dev/null
+++ b/include/osmocom/bsc/gsm_data_shared.h
@@ -0,0 +1,757 @@
+#ifndef _GSM_DATA_SHAREDH
+#define _GSM_DATA_SHAREDH
+
+#include <regex.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <osmocom/core/timer.h>
+#include <osmocom/core/bitvec.h>
+#include <osmocom/core/statistics.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/tlv.h>
+#include <osmocom/gsm/rxlev_stat.h>
+#include <osmocom/gsm/sysinfo.h>
+
+#include <osmocom/gsm/protocol/gsm_08_58.h>
+#include <osmocom/gsm/protocol/gsm_12_21.h>
+
+#include <osmocom/abis/e1_input.h>
+
+#ifndef ROLE_BSC
+#include <osmocom/gsm/lapdm.h>
+#endif
+
+struct osmo_bsc_data;
+
+struct osmo_bsc_sccp_con;
+struct gsm_sms_queue;
+
+/* RRLP mode of operation */
+enum rrlp_mode {
+ RRLP_MODE_NONE,
+ RRLP_MODE_MS_BASED,
+ RRLP_MODE_MS_PREF,
+ RRLP_MODE_ASS_PREF,
+};
+
+/* Channel Request reason */
+enum gsm_chreq_reason_t {
+ GSM_CHREQ_REASON_EMERG,
+ GSM_CHREQ_REASON_PAG,
+ GSM_CHREQ_REASON_CALL,
+ GSM_CHREQ_REASON_LOCATION_UPD,
+ GSM_CHREQ_REASON_OTHER,
+};
+
+#define TRX_NR_TS 8
+#define TS_MAX_LCHAN 8
+
+#define HARDCODED_ARFCN 123
+#define HARDCODED_TSC 7
+#define HARDCODED_BSIC 0x3f /* NCC = 7 / BCC = 7 */
+
+/* for multi-drop config */
+#define HARDCODED_BTS0_TS 1
+#define HARDCODED_BTS1_TS 6
+#define HARDCODED_BTS2_TS 11
+
+/* reserved according to GSM 03.03 § 2.4 */
+#define GSM_RESERVED_TMSI 0xFFFFFFFF
+
+enum gsm_hooks {
+ GSM_HOOK_NM_SWLOAD,
+ GSM_HOOK_RR_PAGING,
+ GSM_HOOK_RR_SECURITY,
+};
+
+enum gsm_paging_event {
+ GSM_PAGING_SUCCEEDED,
+ GSM_PAGING_EXPIRED,
+ GSM_PAGING_OOM,
+ GSM_PAGING_BUSY,
+};
+
+enum bts_gprs_mode {
+ BTS_GPRS_NONE = 0,
+ BTS_GPRS_GPRS = 1,
+ BTS_GPRS_EGPRS = 2,
+};
+
+struct gsm_lchan;
+struct gsm_subscriber;
+struct gsm_mncc;
+struct osmo_rtp_socket;
+struct rtp_socket;
+struct bsc_api;
+
+/* Network Management State */
+struct gsm_nm_state {
+ uint8_t operational;
+ uint8_t administrative;
+ uint8_t availability;
+};
+
+struct gsm_abis_mo {
+ uint8_t obj_class;
+ struct abis_om_obj_inst obj_inst;
+ const char *name;
+ struct gsm_nm_state nm_state;
+ struct tlv_parsed *nm_attr;
+ struct gsm_bts *bts;
+};
+
+#define MAX_A5_KEY_LEN (128/8)
+#define A38_XOR_MIN_KEY_LEN 12
+#define A38_XOR_MAX_KEY_LEN 16
+#define A38_COMP128_KEY_LEN 16
+#define RSL_ENC_ALG_A5(x) (x+1)
+
+/* is the data link established? who established it? */
+#define LCHAN_SAPI_UNUSED 0
+#define LCHAN_SAPI_MS 1
+#define LCHAN_SAPI_NET 2
+
+/* state of a logical channel */
+enum gsm_lchan_state {
+ LCHAN_S_NONE, /* channel is not active */
+ LCHAN_S_ACT_REQ, /* channel activation requested */
+ LCHAN_S_ACTIVE, /* channel is active and operational */
+ LCHAN_S_REL_REQ, /* channel release has been requested */
+ LCHAN_S_REL_ERR, /* channel is in an error state */
+ LCHAN_S_BROKEN, /* channel is somehow unusable */
+ LCHAN_S_INACTIVE, /* channel is set inactive */
+};
+
+/* BTS ONLY */
+#define MAX_NUM_UL_MEAS 104
+#define LC_UL_M_F_L1_VALID (1 << 0)
+#define LC_UL_M_F_RES_VALID (1 << 1)
+
+struct bts_ul_meas {
+ /* BER in units of 0.01%: 10.000 == 100% ber, 0 == 0% ber */
+ uint16_t ber10k;
+ /* timing advance offset (in quarter bits) */
+ int16_t ta_offs_qbits;
+ /* C/I ratio in dB */
+ float c_i;
+ /* flags */
+ uint8_t is_sub:1;
+ /* RSSI in dBm * -1 */
+ uint8_t inv_rssi;
+};
+
+struct amr_mode {
+ uint8_t mode;
+ uint8_t threshold;
+ uint8_t hysteresis;
+};
+struct amr_multirate_conf {
+ uint8_t gsm48_ie[2];
+ struct amr_mode mode[4];
+ uint8_t num_modes;
+};
+/* /BTS ONLY */
+
+enum lchan_csd_mode {
+ LCHAN_CSD_M_NT,
+ LCHAN_CSD_M_T_1200_75,
+ LCHAN_CSD_M_T_600,
+ LCHAN_CSD_M_T_1200,
+ LCHAN_CSD_M_T_2400,
+ LCHAN_CSD_M_T_9600,
+ LCHAN_CSD_M_T_14400,
+ LCHAN_CSD_M_T_29000,
+ LCHAN_CSD_M_T_32000,
+};
+
+/* State of the SAPIs in the lchan */
+enum lchan_sapi_state {
+ LCHAN_SAPI_S_NONE,
+ LCHAN_SAPI_S_REQ,
+ LCHAN_SAPI_S_ASSIGNED,
+ LCHAN_SAPI_S_REL,
+ LCHAN_SAPI_S_ERROR,
+};
+
+struct gsm_lchan {
+ /* The TS that we're part of */
+ struct gsm_bts_trx_ts *ts;
+ /* The logical subslot number in the TS */
+ uint8_t nr;
+ /* The logical channel type */
+ enum gsm_chan_t type;
+ /* RSL channel mode */
+ enum rsl_cmod_spd rsl_cmode;
+ /* If TCH, traffic channel mode */
+ enum gsm48_chan_mode tch_mode;
+ enum lchan_csd_mode csd_mode;
+ /* State */
+ enum gsm_lchan_state state;
+ /* Power levels for MS and BTS */
+ uint8_t bs_power;
+ uint8_t ms_power;
+ /* Encryption information */
+ struct {
+ uint8_t alg_id;
+ uint8_t key_len;
+ uint8_t key[MAX_A5_KEY_LEN];
+ } encr;
+
+ /* AMR bits */
+ struct gsm48_multi_rate_conf mr_conf;
+
+ /* Established data link layer services */
+ uint8_t sapis[8];
+ int sacch_deact;
+
+ struct {
+ uint32_t bound_ip;
+ uint32_t connect_ip;
+ uint16_t bound_port;
+ uint16_t connect_port;
+ uint16_t conn_id;
+ uint8_t rtp_payload;
+ uint8_t rtp_payload2;
+ uint8_t speech_mode;
+#ifdef ROLE_BSC
+ struct rtp_socket *rtp_socket;
+#else
+ struct osmo_rtp_socket *rtp_socket;
+#endif
+ } abis_ip;
+
+ uint8_t rqd_ta;
+
+#ifdef ROLE_BSC
+ struct osmo_timer_list T3101;
+ struct osmo_timer_list T3109;
+ struct osmo_timer_list T3111;
+ struct osmo_timer_list error_timer;
+ struct osmo_timer_list act_timer;
+ uint8_t error_cause;
+
+ /* table of neighbor cell measurements */
+ struct neigh_meas_proc neigh_meas[MAX_NEIGH_MEAS];
+
+ /* cache of last measurement reports on this lchan */
+ struct gsm_meas_rep meas_rep[6];
+ int meas_rep_idx;
+
+ /* GSM Random Access data */
+ struct gsm48_req_ref *rqd_ref;
+
+ struct gsm_subscriber_connection *conn;
+#else
+ /* Number of different GsmL1_Sapi_t used in osmo_bts_sysmo is 23.
+ * Currently we don't share these headers so this is a magic number. */
+ struct llist_head sapi_cmds;
+ uint8_t sapis_dl[23];
+ uint8_t sapis_ul[23];
+ struct lapdm_channel lapdm_ch;
+ struct llist_head dl_tch_queue;
+ struct {
+ /* bitmask of all SI that are present/valid in si_buf */
+ uint32_t valid;
+ uint32_t last;
+ /* buffers where we put the pre-computed SI */
+ sysinfo_buf_t buf[_MAX_SYSINFO_TYPE];
+ } si;
+ struct {
+ uint8_t flags;
+ /* RSL measurment result number, 0 at lchan_act */
+ uint8_t res_nr;
+ /* current Tx power level of the BTS */
+ uint8_t bts_tx_pwr;
+ /* number of measurements stored in array below */
+ uint8_t num_ul_meas;
+ struct bts_ul_meas uplink[MAX_NUM_UL_MEAS];
+ /* last L1 header from the MS */
+ uint8_t l1_info[2];
+ struct {
+ uint8_t rxlev_full;
+ uint8_t rxlev_sub;
+ uint8_t rxqual_full;
+ uint8_t rxqual_sub;
+ } res;
+ } meas;
+ struct {
+ struct amr_multirate_conf amr_mr;
+ struct {
+ uint8_t buf[16];
+ uint8_t len;
+ } last_sid;
+ } tch;
+ /* BTS-side ciphering state (rx only, bi-directional, ...) */
+ uint8_t ciph_state;
+ uint8_t loopback;
+ struct {
+ uint8_t active;
+ uint8_t ref;
+ /* T3105: PHYS INF retransmission */
+ struct osmo_timer_list t3105;
+ /* counts up to Ny1 */
+ unsigned int phys_info_count;
+ } ho;
+ /* S counter for link loss */
+ int s;
+#endif
+};
+
+#define TS_F_PDCH_MODE 0x1000
+/* One Timeslot in a TRX */
+struct gsm_bts_trx_ts {
+ struct gsm_bts_trx *trx;
+ /* number of this timeslot at the TRX */
+ uint8_t nr;
+
+ enum gsm_phys_chan_config pchan;
+
+ unsigned int flags;
+ struct gsm_abis_mo mo;
+ struct tlv_parsed nm_attr;
+ uint8_t nm_chan_comb;
+ int tsc; /* -1 == use BTS TSC */
+
+ struct {
+ /* Parameters below are configured by VTY */
+ int enabled;
+ uint8_t maio;
+ uint8_t hsn;
+ struct bitvec arfcns;
+ uint8_t arfcns_data[1024/8];
+ /* This is the pre-computed MA for channel assignments */
+ struct bitvec ma;
+ uint8_t ma_len; /* part of ma_data that is used */
+ uint8_t ma_data[8]; /* 10.5.2.21: max 8 bytes value part */
+ } hopping;
+
+ /* To which E1 subslot are we connected */
+ struct gsm_e1_subslot e1_link;
+
+ struct gsm_lchan lchan[TS_MAX_LCHAN];
+};
+
+/* One TRX in a BTS */
+struct gsm_bts_trx {
+ /* list header in bts->trx_list */
+ struct llist_head list;
+
+ struct gsm_bts *bts;
+ /* number of this TRX in the BTS */
+ uint8_t nr;
+ /* human readable name / description */
+ char *description;
+ /* how do we talk RSL with this TRX? */
+ struct gsm_e1_subslot rsl_e1_link;
+ uint8_t rsl_tei;
+#ifdef ROLE_BSC
+ struct e1inp_sign_link *rsl_link;
+#else
+ struct ipabis_link *rsl_link;
+#endif
+ /* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
+ struct e1inp_sign_link *oml_link;
+
+ struct gsm_abis_mo mo;
+ struct tlv_parsed nm_attr;
+ struct {
+ struct gsm_abis_mo mo;
+ } bb_transc;
+
+ uint16_t arfcn;
+ int nominal_power; /* in dBm */
+ unsigned int max_power_red; /* in actual dB */
+
+ struct {
+ void *l1h;
+ } role_bts;
+
+ union {
+ struct {
+ struct {
+ struct gsm_abis_mo mo;
+ } bbsig;
+ struct {
+ struct gsm_abis_mo mo;
+ } pa;
+ } bs11;
+ struct {
+ unsigned int test_state;
+ uint8_t test_nr;
+ struct rxlev_stats rxlev_stat;
+ } ipaccess;
+ };
+ struct gsm_bts_trx_ts ts[TRX_NR_TS];
+};
+
+#define GSM_BTS_SI(bts, i) (void *)(bts->si_buf[i])
+
+enum gsm_bts_type {
+ GSM_BTS_TYPE_UNKNOWN,
+ GSM_BTS_TYPE_BS11,
+ GSM_BTS_TYPE_NANOBTS,
+ GSM_BTS_TYPE_RBS2000,
+ GSM_BTS_TYPE_NOKIA_SITE,
+ GSM_BTS_TYPE_OSMO_SYSMO,
+ _NUM_GSM_BTS_TYPE
+};
+
+struct vty;
+
+struct gsm_bts_model {
+ struct llist_head list;
+
+ enum gsm_bts_type type;
+ const char *name;
+
+ bool started;
+ int (*start)(struct gsm_network *net);
+ int (*oml_rcvmsg)(struct msgb *msg);
+
+ void (*e1line_bind_ops)(struct e1inp_line *line);
+
+ void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
+ void (*config_write_trx)(struct vty *vty, struct gsm_bts_trx *trx);
+ void (*config_write_ts)(struct vty *vty, struct gsm_bts_trx_ts *ts);
+
+ struct tlv_definition nm_att_tlvdef;
+
+ struct bitvec features;
+ uint8_t _features_data[128/8];
+};
+
+enum gsm_bts_features {
+ BTS_FEAT_HSCSD,
+ BTS_FEAT_GPRS,
+ BTS_FEAT_EGPRS,
+ BTS_FEAT_ECSD,
+ BTS_FEAT_HOPPING,
+};
+
+/*
+ * This keeps track of the paging status of one BTS. It
+ * includes a number of pending requests, a back pointer
+ * to the gsm_bts, a timer and some more state.
+ */
+struct gsm_bts_paging_state {
+ /* pending requests */
+ struct llist_head pending_requests;
+ struct gsm_bts *bts;
+
+ struct osmo_timer_list work_timer;
+ struct osmo_timer_list credit_timer;
+
+ /* free chans needed */
+ int free_chans_need;
+
+ /* load */
+ uint16_t available_slots;
+};
+
+struct gsm_envabtse {
+ struct gsm_abis_mo mo;
+};
+
+struct gsm_bts_gprs_nsvc {
+ struct gsm_bts *bts;
+ /* data read via VTY config file, to configure the BTS
+ * via OML from BSC */
+ int id;
+ uint16_t nsvci;
+ uint16_t local_port; /* on the BTS */
+ uint16_t remote_port; /* on the SGSN */
+ uint32_t remote_ip; /* on the SGSN */
+
+ struct gsm_abis_mo mo;
+};
+
+enum gprs_rlc_par {
+ RLC_T3142,
+ RLC_T3169,
+ RLC_T3191,
+ RLC_T3193,
+ RLC_T3195,
+ RLC_N3101,
+ RLC_N3103,
+ RLC_N3105,
+ CV_COUNTDOWN,
+ T_DL_TBF_EXT, /* ms */
+ T_UL_TBF_EXT, /* ms */
+ _NUM_RLC_PAR
+};
+
+enum gprs_cs {
+ GPRS_CS1,
+ GPRS_CS2,
+ GPRS_CS3,
+ GPRS_CS4,
+ GPRS_MCS1,
+ GPRS_MCS2,
+ GPRS_MCS3,
+ GPRS_MCS4,
+ GPRS_MCS5,
+ GPRS_MCS6,
+ GPRS_MCS7,
+ GPRS_MCS8,
+ GPRS_MCS9,
+ _NUM_GRPS_CS
+};
+
+struct gprs_rlc_cfg {
+ uint16_t parameter[_NUM_RLC_PAR];
+ struct {
+ uint16_t repeat_time; /* ms */
+ uint8_t repeat_count;
+ } paging;
+ uint32_t cs_mask; /* bitmask of gprs_cs */
+ uint8_t initial_cs;
+ uint8_t initial_mcs;
+};
+
+
+enum neigh_list_manual_mode {
+ NL_MODE_AUTOMATIC = 0,
+ NL_MODE_MANUAL = 1,
+ NL_MODE_MANUAL_SI5SEP = 2, /* SI2 and SI5 have separate neighbor lists */
+};
+
+enum bts_loc_fix {
+ BTS_LOC_FIX_INVALID = 0,
+ BTS_LOC_FIX_2D = 1,
+ BTS_LOC_FIX_3D = 2,
+};
+
+extern const struct value_string bts_loc_fix_names[];
+
+struct bts_location {
+ struct llist_head list;
+ time_t tstamp;
+ enum bts_loc_fix valid;
+ double lat;
+ double lon;
+ double height;
+};
+
+/* One BTS */
+struct gsm_bts {
+ /* list header in net->bts_list */
+ struct llist_head list;
+
+ /* Geographical location of the BTS */
+ struct llist_head loc_list;
+
+ /* number of ths BTS in network */
+ uint8_t nr;
+ /* human readable name / description */
+ char *description;
+ /* Cell Identity */
+ uint16_t cell_identity;
+ /* location area code of this BTS */
+ uint16_t location_area_code;
+ /* Training Sequence Code */
+ uint8_t tsc;
+ /* Base Station Identification Code (BSIC) */
+ uint8_t bsic;
+ /* type of BTS */
+ enum gsm_bts_type type;
+ struct gsm_bts_model *model;
+ enum gsm_band band;
+ /* maximum Tx power that the MS is permitted to use in this cell */
+ int ms_max_power;
+
+ /* how do we talk OML with this TRX? */
+ struct gsm_e1_subslot oml_e1_link;
+ uint8_t oml_tei;
+ struct e1inp_sign_link *oml_link;
+
+ /* Abis network management O&M handle */
+ struct abis_nm_h *nmh;
+
+ struct gsm_abis_mo mo;
+
+ /* number of this BTS on given E1 link */
+ uint8_t bts_nr;
+
+ /* paging state and control */
+ struct gsm_bts_paging_state paging;
+
+ /* CCCH is on C0 */
+ struct gsm_bts_trx *c0;
+
+ struct {
+ struct gsm_abis_mo mo;
+ } site_mgr;
+
+ /* bitmask of all SI that are present/valid in si_buf */
+ uint32_t si_valid;
+ /* buffers where we put the pre-computed SI */
+ sysinfo_buf_t si_buf[_MAX_SYSINFO_TYPE];
+
+ /* TimeZone hours, mins, and bts specific */
+ struct {
+ int hr;
+ int mn;
+ int override;
+ } tz;
+
+ /* ip.accesss Unit ID's have Site/BTS/TRX layout */
+ union {
+ struct {
+ uint16_t site_id;
+ uint16_t bts_id;
+ uint32_t flags;
+ uint32_t rsl_ip;
+ } ip_access;
+ struct {
+ struct {
+ struct gsm_abis_mo mo;
+ } cclk;
+ struct {
+ struct gsm_abis_mo mo;
+ } rack;
+ struct gsm_envabtse envabtse[4];
+ } bs11;
+ struct {
+ struct {
+ struct gsm_abis_mo mo;
+ struct llist_head conn_groups;
+ } is;
+ struct {
+ struct gsm_abis_mo mo;
+ struct llist_head conn_groups;
+ } con;
+ struct {
+ struct gsm_abis_mo mo;
+ } dp;
+ struct {
+ struct gsm_abis_mo mo;
+ } tf;
+ } rbs2000;
+ struct {
+ uint8_t bts_type;
+ unsigned int configured:1,
+ skip_reset:1,
+ did_reset:1,
+ wait_reset:1;
+ struct osmo_timer_list reset_timer;
+ } nokia;
+ };
+
+ /* Not entirely sure how ip.access specific this is */
+ struct {
+ enum bts_gprs_mode mode;
+ struct {
+ struct gsm_abis_mo mo;
+ uint16_t nsei;
+ uint8_t timer[7];
+ } nse;
+ struct {
+ struct gsm_abis_mo mo;
+ uint16_t bvci;
+ uint8_t timer[11];
+ struct gprs_rlc_cfg rlc_cfg;
+ } cell;
+ struct gsm_bts_gprs_nsvc nsvc[2];
+ uint8_t rac;
+ uint8_t net_ctrl_ord;
+ } gprs;
+
+ /* RACH NM values */
+ int rach_b_thresh;
+ int rach_ldavg_slots;
+
+ /* transceivers */
+ int num_trx;
+ struct llist_head trx_list;
+
+#ifdef ROLE_BSC
+ /* Abis NM queue */
+ struct llist_head abis_queue;
+ int abis_nm_pend;
+
+ struct gsm_network *network;
+
+ /* should the channel allocator allocate channels from high TRX to TRX0,
+ * rather than starting from TRX0 and go upwards? */
+ int chan_alloc_reverse;
+
+ enum neigh_list_manual_mode neigh_list_manual_mode;
+ /* parameters from which we build SYSTEM INFORMATION */
+ struct {
+ struct gsm48_rach_control rach_control;
+ uint8_t ncc_permitted;
+ struct gsm48_cell_sel_par cell_sel_par;
+ struct gsm48_si_selection_params cell_ro_sel_par; /* rest octet */
+ struct gsm48_cell_options cell_options;
+ struct gsm48_control_channel_descr chan_desc;
+ struct bitvec neigh_list;
+ struct bitvec cell_alloc;
+ struct bitvec si5_neigh_list;
+ struct {
+ /* bitmask large enough for all possible ARFCN's */
+ uint8_t neigh_list[1024/8];
+ uint8_t cell_alloc[1024/8];
+ /* If the user wants a different neighbor list in SI5 than in SI2 */
+ uint8_t si5_neigh_list[1024/8];
+ } data;
+ } si_common;
+
+ /* do we use static (user-defined) system information messages? (bitmask) */
+ uint32_t si_mode_static;
+
+ /* exclude the BTS from the global RF Lock handling */
+ int excl_from_rf_lock;
+#endif /* ROLE_BSC */
+ void *role;
+};
+
+
+struct gsm_bts *gsm_bts_alloc(void *talloc_ctx);
+struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
+
+struct gsm_bts_trx *gsm_bts_trx_num(const struct gsm_bts *bts, int num);
+
+
+const struct value_string gsm_pchant_names[10];
+const struct value_string gsm_pchant_descs[10];
+const struct value_string gsm_lchant_names[6];
+const char *gsm_pchan_name(enum gsm_phys_chan_config c);
+enum gsm_phys_chan_config gsm_pchan_parse(const char *name);
+const char *gsm_lchant_name(enum gsm_chan_t c);
+const char *gsm_chreq_name(enum gsm_chreq_reason_t c);
+char *gsm_trx_name(const struct gsm_bts_trx *trx);
+char *gsm_ts_name(const struct gsm_bts_trx_ts *ts);
+char *gsm_lchan_name(const struct gsm_lchan *lchan);
+const char *gsm_lchans_name(enum gsm_lchan_state s);
+
+
+void gsm_abis_mo_reset(struct gsm_abis_mo *mo);
+
+struct gsm_abis_mo *
+gsm_objclass2mo(struct gsm_bts *bts, uint8_t obj_class,
+ const struct abis_om_obj_inst *obj_inst);
+
+struct gsm_nm_state *
+gsm_objclass2nmstate(struct gsm_bts *bts, uint8_t obj_class,
+ const struct abis_om_obj_inst *obj_inst);
+void *
+gsm_objclass2obj(struct gsm_bts *bts, uint8_t obj_class,
+ const struct abis_om_obj_inst *obj_inst);
+
+/* reset the state of all MO in the BTS */
+void gsm_bts_mo_reset(struct gsm_bts *bts);
+
+uint8_t gsm_ts2chan_nr(const struct gsm_bts_trx_ts *ts, uint8_t lchan_nr);
+uint8_t gsm_lchan2chan_nr(const struct gsm_lchan *lchan);
+
+/*
+ * help with parsing regexps
+ */
+int gsm_parse_reg(void *ctx, regex_t *reg, char **str,
+ int argc, const char **argv) __attribute__ ((warn_unused_result));
+
+
+
+#endif
diff --git a/include/osmocom/bsc/gsm_subscriber.h b/include/osmocom/bsc/gsm_subscriber.h
new file mode 100644
index 000000000..6b577b0bf
--- /dev/null
+++ b/include/osmocom/bsc/gsm_subscriber.h
@@ -0,0 +1,111 @@
+#ifndef _GSM_SUBSCR_H
+#define _GSM_SUBSCR_H
+
+#include "gsm_data.h"
+#include <osmocom/core/linuxlist.h>
+
+#define GSM_IMEI_LENGTH 17
+#define GSM_IMSI_LENGTH 17
+#define GSM_NAME_LENGTH 160
+
+#define GSM_EXTENSION_LENGTH 15 /* MSISDN can only be 15 digits length */
+#define GSM_MIN_EXTEN 20000
+#define GSM_MAX_EXTEN 49999
+
+#define GSM_SUBSCRIBER_FIRST_CONTACT 0x00000001
+#define tmsi_from_string(str) strtoul(str, NULL, 10)
+
+#define GSM_SUBSCRIBER_NO_EXPIRATION 0x0
+
+struct vty;
+
+struct gsm_equipment {
+ long long unsigned int id;
+ char imei[GSM_IMEI_LENGTH];
+ char name[GSM_NAME_LENGTH];
+
+ struct gsm48_classmark1 classmark1;
+ uint8_t classmark2_len;
+ uint8_t classmark2[3];
+ uint8_t classmark3_len;
+ uint8_t classmark3[14];
+};
+
+struct gsm_subscriber {
+ struct gsm_network *net;
+ long long unsigned int id;
+ char imsi[GSM_IMSI_LENGTH];
+ uint32_t tmsi;
+ uint16_t lac;
+ char name[GSM_NAME_LENGTH];
+ char extension[GSM_EXTENSION_LENGTH];
+ int authorized;
+ time_t expire_lu;
+
+ /* Temporary field which is not stored in the DB/HLR */
+ uint32_t flags;
+
+ /* Every user can only have one equipment in use at any given
+ * point in time */
+ struct gsm_equipment equipment;
+
+ /* for internal management */
+ int use_count;
+ struct llist_head entry;
+
+ /* pending requests */
+ int in_callback;
+ struct llist_head requests;
+};
+
+enum gsm_subscriber_field {
+ GSM_SUBSCRIBER_IMSI,
+ GSM_SUBSCRIBER_TMSI,
+ GSM_SUBSCRIBER_EXTENSION,
+ GSM_SUBSCRIBER_ID,
+};
+
+enum gsm_subscriber_update_reason {
+ GSM_SUBSCRIBER_UPDATE_ATTACHED,
+ GSM_SUBSCRIBER_UPDATE_DETACHED,
+ GSM_SUBSCRIBER_UPDATE_EQUIPMENT,
+};
+
+struct gsm_subscriber *subscr_get(struct gsm_subscriber *subscr);
+struct gsm_subscriber *subscr_put(struct gsm_subscriber *subscr);
+struct gsm_subscriber *subscr_get_by_tmsi(struct gsm_network *net,
+ uint32_t tmsi);
+struct gsm_subscriber *subscr_get_by_imsi(struct gsm_network *net,
+ const char *imsi);
+struct gsm_subscriber *subscr_get_by_extension(struct gsm_network *net,
+ const char *ext);
+struct gsm_subscriber *subscr_get_by_id(struct gsm_network *net,
+ unsigned long long id);
+struct gsm_subscriber *subscr_get_or_create(struct gsm_network *net,
+ const char *imsi);
+int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts, int reason);
+void subscr_put_channel(struct gsm_subscriber *subscr);
+void subscr_get_channel(struct gsm_subscriber *subscr,
+ int type, gsm_cbfn *cbfn, void *param);
+struct gsm_subscriber *subscr_active_by_tmsi(struct gsm_network *net,
+ uint32_t tmsi);
+struct gsm_subscriber *subscr_active_by_imsi(struct gsm_network *net,
+ const char *imsi);
+
+int subscr_pending_requests(struct gsm_subscriber *subscr);
+int subscr_pending_clear(struct gsm_subscriber *subscr);
+int subscr_pending_dump(struct gsm_subscriber *subscr, struct vty *vty);
+int subscr_pending_kick(struct gsm_subscriber *subscr);
+
+char *subscr_name(struct gsm_subscriber *subscr);
+
+int subscr_purge_inactive(struct gsm_network *net);
+void subscr_update_from_db(struct gsm_subscriber *subscr);
+void subscr_expire(struct gsm_network *net);
+int subscr_update_expire_lu(struct gsm_subscriber *subscr, struct gsm_bts *bts);
+
+/* internal */
+struct gsm_subscriber *subscr_alloc(void);
+extern struct llist_head active_subscribers;
+
+#endif /* _GSM_SUBSCR_H */
diff --git a/include/osmocom/bsc/handover.h b/include/osmocom/bsc/handover.h
new file mode 100644
index 000000000..bd0d8ad6c
--- /dev/null
+++ b/include/osmocom/bsc/handover.h
@@ -0,0 +1,17 @@
+#ifndef _HANDOVER_H
+#define _HANDOVER_H
+
+struct gsm_subscriber_connection;
+
+/* Hand over the specified logical channel to the specified new BTS.
+ * This is the main entry point for the actual handover algorithm,
+ * after it has decided it wants to initiate HO to a specific BTS */
+int bsc_handover_start(struct gsm_lchan *old_lchan, struct gsm_bts *bts);
+
+/* clear any operation for this connection */
+void bsc_clear_handover(struct gsm_subscriber_connection *conn, int free_lchan);
+
+/* Return the old lchan or NULL. This is meant for audio handling */
+struct gsm_lchan *bsc_handover_pending(struct gsm_lchan *new_lchan);
+
+#endif /* _HANDOVER_H */
diff --git a/include/osmocom/bsc/handover_decision.h b/include/osmocom/bsc/handover_decision.h
new file mode 100644
index 000000000..81078b05d
--- /dev/null
+++ b/include/osmocom/bsc/handover_decision.h
@@ -0,0 +1,7 @@
+#ifndef _HANDOVER_DECISION_H
+#define _HANDOVER_DECISION_H
+
+void on_dso_load_ho_dec(void);
+
+#endif /* _HANDOVER_DECISION_H */
+
diff --git a/include/osmocom/bsc/ipaccess.h b/include/osmocom/bsc/ipaccess.h
new file mode 100644
index 000000000..a25a348b6
--- /dev/null
+++ b/include/osmocom/bsc/ipaccess.h
@@ -0,0 +1,65 @@
+#ifndef _IPACCESS_H
+#define _IPACCESS_H
+
+#include <osmocom/abis/e1_input.h>
+#include "gsm_subscriber.h"
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/gsm/protocol/ipaccess.h>
+
+struct ipac_msgt_sccp_state {
+ uint8_t src_ref[3];
+ uint8_t dst_ref[3];
+ uint8_t trans_id;
+ uint8_t invoke_id;
+ char imsi[GSM_IMSI_LENGTH];
+ uint8_t data[0];
+} __attribute__((packed));
+
+/*
+ * @add_remove 0 for remove, 1 for add, 3 to asK
+ * @nr_lacs Number of extra lacs inside this package
+ * @lac One lac entry
+ */
+struct ipac_ext_lac_cmd {
+ uint8_t add_remove;
+ uint8_t nr_extra_lacs;
+ uint16_t lac;
+ uint8_t data[0];
+} __attribute__((packed));
+
+/*
+ * methods for parsing and sending a message
+ */
+int ipaccess_rcvmsg_base(struct msgb *msg, struct osmo_fd *bfd);
+void ipaccess_prepend_header(struct msgb *msg, int proto);
+void ipaccess_prepend_header_ext(struct msgb *msg, int proto);
+int ipaccess_send_pong(int fd);
+int ipaccess_send_id_ack(int fd);
+int ipaccess_send_id_req(int fd);
+
+const char *ipaccess_idtag_name(uint8_t tag);
+int ipaccess_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len);
+int ipaccess_parse_unitid(const char *str, uint16_t *site_id, uint16_t *bts_id, uint16_t *trx_id);
+
+int ipaccess_drop_oml(struct gsm_bts *bts);
+int ipaccess_drop_rsl(struct gsm_bts_trx *trx);
+
+struct sdp_header_item {
+ struct sdp_header_entry header_entry;
+ struct llist_head entry;
+ off_t absolute_offset;
+};
+
+struct sdp_header {
+ struct sdp_firmware firmware_info;
+
+ /* for more_magic a list of sdp_header_entry_list */
+ struct llist_head header_list;
+
+ /* the entry of the sdp_header */
+ struct llist_head entry;
+};
+
+int ipaccess_analyze_file(int fd, const unsigned int st_size, const unsigned base_offset, struct llist_head *list);
+
+#endif /* _IPACCESS_H */
diff --git a/include/osmocom/bsc/meas_rep.h b/include/osmocom/bsc/meas_rep.h
new file mode 100644
index 000000000..f235df6aa
--- /dev/null
+++ b/include/osmocom/bsc/meas_rep.h
@@ -0,0 +1,87 @@
+#ifndef _MEAS_REP_H
+#define _MEAS_REP_H
+
+#include <stdint.h>
+
+#define MRC_F_PROCESSED 0x0001
+
+/* extracted from a L3 measurement report IE */
+struct gsm_meas_rep_cell {
+ uint8_t rxlev;
+ uint8_t bsic;
+ uint8_t neigh_idx;
+ uint16_t arfcn;
+ unsigned int flags;
+};
+
+/* RX Level and RX Quality */
+struct gsm_rx_lev_qual {
+ uint8_t rx_lev;
+ uint8_t rx_qual;
+};
+
+/* unidirectional measumrement report */
+struct gsm_meas_rep_unidir {
+ struct gsm_rx_lev_qual full;
+ struct gsm_rx_lev_qual sub;
+};
+
+#define MEAS_REP_F_UL_DTX 0x01
+#define MEAS_REP_F_DL_VALID 0x02
+#define MEAS_REP_F_BA1 0x04
+#define MEAS_REP_F_DL_DTX 0x08
+#define MEAS_REP_F_MS_TO 0x10
+#define MEAS_REP_F_MS_L1 0x20
+#define MEAS_REP_F_FPC 0x40
+
+/* parsed uplink and downlink measurement result */
+struct gsm_meas_rep {
+ /* back-pointer to the logical channel */
+ struct gsm_lchan *lchan;
+
+ /* number of the measurement report */
+ uint8_t nr;
+ /* flags, see MEAS_REP_F_* */
+ unsigned int flags;
+
+ /* uplink and downlink rxlev, rxqual; full and sub */
+ struct gsm_meas_rep_unidir ul;
+ struct gsm_meas_rep_unidir dl;
+
+ uint8_t bs_power;
+ uint8_t ms_timing_offset;
+ struct {
+ int8_t pwr; /* MS power in dBm */
+ uint8_t ta; /* MS timing advance */
+ } ms_l1;
+
+ /* neighbor measurement reports for up to 6 cells */
+ int num_cell;
+ struct gsm_meas_rep_cell cell[6];
+};
+
+enum meas_rep_field {
+ MEAS_REP_DL_RXLEV_FULL,
+ MEAS_REP_DL_RXLEV_SUB,
+ MEAS_REP_DL_RXQUAL_FULL,
+ MEAS_REP_DL_RXQUAL_SUB,
+ MEAS_REP_UL_RXLEV_FULL,
+ MEAS_REP_UL_RXLEV_SUB,
+ MEAS_REP_UL_RXQUAL_FULL,
+ MEAS_REP_UL_RXQUAL_SUB,
+};
+
+/* obtain an average over the last 'num' fields in the meas reps */
+int get_meas_rep_avg(const struct gsm_lchan *lchan,
+ enum meas_rep_field field, unsigned int num);
+
+/* Check if N out of M last values for FIELD are >= bd */
+int meas_rep_n_out_of_m_be(const struct gsm_lchan *lchan,
+ enum meas_rep_field field,
+ unsigned int n, unsigned int m, int be);
+
+unsigned int calc_initial_idx(unsigned int array_size,
+ unsigned int meas_rep_idx,
+ unsigned int num_values);
+
+#endif /* _MEAS_REP_H */
diff --git a/include/osmocom/bsc/mgcp.h b/include/osmocom/bsc/mgcp.h
new file mode 100644
index 000000000..811dcfda7
--- /dev/null
+++ b/include/osmocom/bsc/mgcp.h
@@ -0,0 +1,203 @@
+/* A Media Gateway Control Protocol Media Gateway: RFC 3435 */
+
+/*
+ * (C) 2009-2012 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2009-2012 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef OPENBSC_MGCP_H
+#define OPENBSC_MGCP_H
+
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/write_queue.h>
+
+#include "debug.h"
+
+#include <arpa/inet.h>
+
+#define RTP_PORT_DEFAULT 4000
+#define RTP_PORT_NET_DEFAULT 16000
+
+/**
+ * Calculate the RTP audio port for the given multiplex
+ * and the direction. This allows a semi static endpoint
+ * to port calculation removing the need for the BSC
+ * and the MediaGateway to communicate.
+ *
+ * Port usage explained:
+ * base + (multiplex * 2) + 0 == local port to wait for network packets
+ * base + (multiplex * 2) + 1 == local port for rtcp
+ *
+ * The above port will receive packets from the BTS that need
+ * to be patched and forwarded to the network.
+ * The above port will receive packets from the network that
+ * need to be patched and forwarded to the BTS.
+ *
+ * We assume to have a static BTS IP address so we can differentiate
+ * network and BTS.
+ *
+ */
+static inline int rtp_calculate_port(int multiplex, int base)
+{
+ return base + (multiplex * 2);
+}
+
+
+/*
+ * Handling of MGCP Endpoints and the MGCP Config
+ */
+struct mgcp_endpoint;
+struct mgcp_config;
+struct mgcp_trunk_config;
+
+#define MGCP_ENDP_CRCX 1
+#define MGCP_ENDP_DLCX 2
+#define MGCP_ENDP_MDCX 3
+
+/*
+ * what to do with the msg?
+ * - continue as usual?
+ * - reject and send a failure code?
+ * - defer? do not send anything
+ */
+#define MGCP_POLICY_CONT 4
+#define MGCP_POLICY_REJECT 5
+#define MGCP_POLICY_DEFER 6
+
+typedef int (*mgcp_realloc)(struct mgcp_trunk_config *cfg, int endpoint);
+typedef int (*mgcp_change)(struct mgcp_trunk_config *cfg, int endpoint, int state);
+typedef int (*mgcp_policy)(struct mgcp_trunk_config *cfg, int endpoint, int state, const char *transactio_id);
+typedef int (*mgcp_reset)(struct mgcp_trunk_config *cfg);
+typedef int (*mgcp_rqnt)(struct mgcp_endpoint *endp, char tone);
+
+#define PORT_ALLOC_STATIC 0
+#define PORT_ALLOC_DYNAMIC 1
+
+/**
+ * This holds information on how to allocate ports
+ */
+struct mgcp_port_range {
+ int mode;
+
+ /* pre-allocated from a base? */
+ int base_port;
+
+ /* dynamically allocated */
+ int range_start;
+ int range_end;
+ int last_port;
+};
+
+struct mgcp_trunk_config {
+ struct llist_head entry;
+
+ struct mgcp_config *cfg;
+
+ int trunk_nr;
+ int trunk_type;
+
+ char *audio_fmtp_extra;
+ char *audio_name;
+ int audio_payload;
+ int audio_loop;
+
+ int omit_rtcp;
+
+ /* spec handling */
+ int force_realloc;
+
+ unsigned int number_endpoints;
+ struct mgcp_endpoint *endpoints;
+};
+
+struct mgcp_config {
+ int source_port;
+ char *local_ip;
+ char *source_addr;
+ char *bts_ip;
+ char *call_agent_addr;
+
+ struct in_addr bts_in;
+
+ /* transcoder handling */
+ char *transcoder_ip;
+ struct in_addr transcoder_in;
+ int transcoder_remote_base;
+
+ struct osmo_wqueue gw_fd;
+
+ struct mgcp_port_range bts_ports;
+ struct mgcp_port_range net_ports;
+ struct mgcp_port_range transcoder_ports;
+ int endp_dscp;
+
+ mgcp_change change_cb;
+ mgcp_policy policy_cb;
+ mgcp_reset reset_cb;
+ mgcp_realloc realloc_cb;
+ mgcp_rqnt rqnt_cb;
+ void *data;
+
+ uint32_t last_call_id;
+
+ /* trunk handling */
+ struct mgcp_trunk_config trunk;
+ struct llist_head trunks;
+
+ /* only used for start with a static configuration */
+ int last_net_port;
+ int last_bts_port;
+};
+
+/* config management */
+struct mgcp_config *mgcp_config_alloc(void);
+int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg);
+int mgcp_vty_init(void);
+int mgcp_endpoints_allocate(struct mgcp_trunk_config *cfg);
+void mgcp_free_endp(struct mgcp_endpoint *endp);
+int mgcp_reset_transcoder(struct mgcp_config *cfg);
+void mgcp_format_stats(struct mgcp_endpoint *endp, char *stats, size_t size);
+int mgcp_parse_stats(struct msgb *msg, uint32_t *ps, uint32_t *os, uint32_t *pr, uint32_t *_or, int *loss, uint32_t *jitter);
+
+/*
+ * format helper functions
+ */
+struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg);
+
+/* adc helper */
+static inline int mgcp_timeslot_to_endpoint(int multiplex, int timeslot)
+{
+ if (timeslot == 0) {
+ LOGP(DMGCP, LOGL_ERROR, "Timeslot should not be 0\n");
+ timeslot = 255;
+ }
+
+ return timeslot + (32 * multiplex);
+}
+
+static inline void mgcp_endpoint_to_timeslot(int endpoint, int *multiplex, int *timeslot)
+{
+ *multiplex = endpoint / 32;
+ *timeslot = endpoint % 32;
+}
+
+int mgcp_send_reset_ep(struct mgcp_endpoint *endp, int endpoint);
+int mgcp_send_reset_all(struct mgcp_config *cfg);
+
+
+#endif
diff --git a/include/osmocom/bsc/mgcp_internal.h b/include/osmocom/bsc/mgcp_internal.h
new file mode 100644
index 000000000..d5bd3ddc6
--- /dev/null
+++ b/include/osmocom/bsc/mgcp_internal.h
@@ -0,0 +1,172 @@
+/* MGCP Private Data */
+
+/*
+ * (C) 2009-2012 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2009-2012 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef OPENBSC_MGCP_DATA_H
+#define OPENBSC_MGCP_DATA_H
+
+#include <osmocom/core/select.h>
+
+#define CI_UNUSED 0
+
+enum mgcp_connection_mode {
+ MGCP_CONN_NONE = 0,
+ MGCP_CONN_RECV_ONLY = 1,
+ MGCP_CONN_SEND_ONLY = 2,
+ MGCP_CONN_RECV_SEND = MGCP_CONN_RECV_ONLY | MGCP_CONN_SEND_ONLY,
+ MGCP_CONN_LOOPBACK = 4,
+};
+
+enum mgcp_trunk_type {
+ MGCP_TRUNK_VIRTUAL,
+ MGCP_TRUNK_E1,
+};
+
+struct mgcp_rtp_state {
+ int initialized;
+ int patch;
+
+ uint32_t orig_ssrc;
+ uint32_t ssrc;
+
+ uint16_t base_seq;
+ uint16_t max_seq;
+ int seq_offset;
+ int cycles;
+
+ uint32_t last_timestamp;
+ int32_t timestamp_offset;
+ uint32_t jitter;
+ int32_t transit;
+};
+
+struct mgcp_rtp_end {
+ /* statistics */
+ unsigned int packets;
+ unsigned int octets;
+ struct in_addr addr;
+
+ /* in network byte order */
+ int rtp_port, rtcp_port;
+
+ /* per endpoint data */
+ int payload_type;
+ char *fmtp_extra;
+
+ /*
+ * Each end has a socket...
+ */
+ struct osmo_fd rtp;
+ struct osmo_fd rtcp;
+
+ int local_port;
+ int local_alloc;
+};
+
+enum {
+ MGCP_TAP_BTS_IN,
+ MGCP_TAP_BTS_OUT,
+ MGCP_TAP_NET_IN,
+ MGCP_TAP_NET_OUT,
+
+ /* last element */
+ MGCP_TAP_COUNT
+};
+
+struct mgcp_rtp_tap {
+ int enabled;
+ struct sockaddr_in forward;
+};
+
+enum mgcp_type {
+ MGCP_RTP_DEFAULT = 0,
+ MGCP_RTP_TRANSCODED,
+};
+
+struct mgcp_endpoint {
+ int allocated;
+ uint32_t ci;
+ char *callid;
+ char *local_options;
+ int conn_mode;
+ int orig_mode;
+
+ /* backpointer */
+ struct mgcp_config *cfg;
+ struct mgcp_trunk_config *tcfg;
+
+ /* port status for bts/net */
+ struct mgcp_rtp_end bts_end;
+ struct mgcp_rtp_end net_end;
+
+ /*
+ * For transcoding we will send from the local_port
+ * of trans_bts and it will arrive at trans_net from
+ * where we will forward it to the network.
+ */
+ struct mgcp_rtp_end trans_bts;
+ struct mgcp_rtp_end trans_net;
+ enum mgcp_type type;
+
+ /* sequence bits */
+ struct mgcp_rtp_state net_state;
+ struct mgcp_rtp_state bts_state;
+
+ /* SSRC/seq/ts patching for loop */
+ int allow_patch;
+
+ /* fields for re-transmission */
+ char *last_trans;
+ char *last_response;
+
+ /* tap for the endpoint */
+ struct mgcp_rtp_tap taps[MGCP_TAP_COUNT];
+};
+
+#define ENDPOINT_NUMBER(endp) abs(endp - endp->tcfg->endpoints)
+
+struct mgcp_msg_ptr {
+ unsigned int start;
+ unsigned int length;
+};
+
+int mgcp_send_dummy(struct mgcp_endpoint *endp);
+int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
+int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
+int mgcp_bind_trans_bts_rtp_port(struct mgcp_endpoint *enp, int rtp_port);
+int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *enp, int rtp_port);
+int mgcp_free_rtp_port(struct mgcp_rtp_end *end);
+
+/* For transcoding we need to manage an in and an output that are connected */
+static inline int endp_back_channel(int endpoint)
+{
+ return endpoint + 60;
+}
+
+struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, int index);
+struct mgcp_trunk_config *mgcp_trunk_num(struct mgcp_config *cfg, int index);
+
+void mgcp_state_calc_loss(struct mgcp_rtp_state *s, struct mgcp_rtp_end *,
+ uint32_t *expected, int *loss);
+uint32_t mgcp_state_calc_jitter(struct mgcp_rtp_state *);
+
+
+#endif
diff --git a/include/osmocom/bsc/misdn.h b/include/osmocom/bsc/misdn.h
new file mode 100644
index 000000000..9851ad32c
--- /dev/null
+++ b/include/osmocom/bsc/misdn.h
@@ -0,0 +1,27 @@
+/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef MISDN_H
+#define MISDN_H
+
+#include <osmocom/abis/e1_input.h>
+
+int mi_setup(int cardnr, struct e1inp_line *line, int release_l2);
+int mi_e1_line_update(struct e1inp_line *line);
+
+#endif
diff --git a/include/osmocom/bsc/mncc.h b/include/osmocom/bsc/mncc.h
new file mode 100644
index 000000000..4a99bb11b
--- /dev/null
+++ b/include/osmocom/bsc/mncc.h
@@ -0,0 +1,191 @@
+/* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface
+ * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */
+
+/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _MNCC_H
+#define _MNCC_H
+
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/gsm/mncc.h>
+
+#include <stdint.h>
+
+struct gsm_network;
+struct msgb;
+
+
+/* One end of a call */
+struct gsm_call {
+ struct llist_head entry;
+
+ /* network handle */
+ void *net;
+
+ /* the 'local' transaction */
+ uint32_t callref;
+ /* the 'remote' transaction */
+ uint32_t remote_ref;
+};
+
+#define MNCC_SETUP_REQ 0x0101
+#define MNCC_SETUP_IND 0x0102
+#define MNCC_SETUP_RSP 0x0103
+#define MNCC_SETUP_CNF 0x0104
+#define MNCC_SETUP_COMPL_REQ 0x0105
+#define MNCC_SETUP_COMPL_IND 0x0106
+/* MNCC_REJ_* is perfomed via MNCC_REL_* */
+#define MNCC_CALL_CONF_IND 0x0107
+#define MNCC_CALL_PROC_REQ 0x0108
+#define MNCC_PROGRESS_REQ 0x0109
+#define MNCC_ALERT_REQ 0x010a
+#define MNCC_ALERT_IND 0x010b
+#define MNCC_NOTIFY_REQ 0x010c
+#define MNCC_NOTIFY_IND 0x010d
+#define MNCC_DISC_REQ 0x010e
+#define MNCC_DISC_IND 0x010f
+#define MNCC_REL_REQ 0x0110
+#define MNCC_REL_IND 0x0111
+#define MNCC_REL_CNF 0x0112
+#define MNCC_FACILITY_REQ 0x0113
+#define MNCC_FACILITY_IND 0x0114
+#define MNCC_START_DTMF_IND 0x0115
+#define MNCC_START_DTMF_RSP 0x0116
+#define MNCC_START_DTMF_REJ 0x0117
+#define MNCC_STOP_DTMF_IND 0x0118
+#define MNCC_STOP_DTMF_RSP 0x0119
+#define MNCC_MODIFY_REQ 0x011a
+#define MNCC_MODIFY_IND 0x011b
+#define MNCC_MODIFY_RSP 0x011c
+#define MNCC_MODIFY_CNF 0x011d
+#define MNCC_MODIFY_REJ 0x011e
+#define MNCC_HOLD_IND 0x011f
+#define MNCC_HOLD_CNF 0x0120
+#define MNCC_HOLD_REJ 0x0121
+#define MNCC_RETRIEVE_IND 0x0122
+#define MNCC_RETRIEVE_CNF 0x0123
+#define MNCC_RETRIEVE_REJ 0x0124
+#define MNCC_USERINFO_REQ 0x0125
+#define MNCC_USERINFO_IND 0x0126
+#define MNCC_REJ_REQ 0x0127
+#define MNCC_REJ_IND 0x0128
+
+#define MNCC_BRIDGE 0x0200
+#define MNCC_FRAME_RECV 0x0201
+#define MNCC_FRAME_DROP 0x0202
+#define MNCC_LCHAN_MODIFY 0x0203
+
+#define GSM_TCHF_FRAME 0x0300
+#define GSM_TCHF_FRAME_EFR 0x0301
+
+#define MNCC_SOCKET_HELLO 0x0400
+
+#define GSM_MAX_FACILITY 128
+#define GSM_MAX_SSVERSION 128
+#define GSM_MAX_USERUSER 128
+
+#define MNCC_F_BEARER_CAP 0x0001
+#define MNCC_F_CALLED 0x0002
+#define MNCC_F_CALLING 0x0004
+#define MNCC_F_REDIRECTING 0x0008
+#define MNCC_F_CONNECTED 0x0010
+#define MNCC_F_CAUSE 0x0020
+#define MNCC_F_USERUSER 0x0040
+#define MNCC_F_PROGRESS 0x0080
+#define MNCC_F_EMERGENCY 0x0100
+#define MNCC_F_FACILITY 0x0200
+#define MNCC_F_SSVERSION 0x0400
+#define MNCC_F_CCCAP 0x0800
+#define MNCC_F_KEYPAD 0x1000
+#define MNCC_F_SIGNAL 0x2000
+
+struct gsm_mncc {
+ /* context based information */
+ uint32_t msg_type;
+ uint32_t callref;
+
+ /* which fields are present */
+ uint32_t fields;
+
+ /* data derived informations (MNCC_F_ based) */
+ struct gsm_mncc_bearer_cap bearer_cap;
+ struct gsm_mncc_number called;
+ struct gsm_mncc_number calling;
+ struct gsm_mncc_number redirecting;
+ struct gsm_mncc_number connected;
+ struct gsm_mncc_cause cause;
+ struct gsm_mncc_progress progress;
+ struct gsm_mncc_useruser useruser;
+ struct gsm_mncc_facility facility;
+ struct gsm_mncc_cccap cccap;
+ struct gsm_mncc_ssversion ssversion;
+ struct {
+ int sup;
+ int inv;
+ } clir;
+ int signal;
+
+ /* data derived information, not MNCC_F based */
+ int keypad;
+ int more;
+ int notify; /* 0..127 */
+ int emergency;
+ char imsi[16];
+
+ unsigned char lchan_type;
+ unsigned char lchan_mode;
+};
+
+struct gsm_data_frame {
+ uint32_t msg_type;
+ uint32_t callref;
+ unsigned char data[0];
+};
+
+#define MNCC_SOCK_VERSION 2
+struct gsm_mncc_hello {
+ uint32_t msg_type;
+ uint32_t version;
+
+ /* send the sizes of the structs */
+ uint32_t mncc_size;
+ uint32_t data_frame_size;
+
+ /* send some offsets */
+ uint32_t called_offset;
+ uint32_t signal_offset;
+ uint32_t emergency_offset;
+ uint32_t lchan_type_offset;
+};
+
+char *get_mncc_name(int value);
+void mncc_set_cause(struct gsm_mncc *data, int loc, int val);
+void cc_tx_to_mncc(struct gsm_network *net, struct msgb *msg);
+
+/* input from CC code into mncc_builtin */
+int int_mncc_recv(struct gsm_network *net, struct msgb *msg);
+
+/* input from CC code into mncc_sock */
+int mncc_sock_from_cc(struct gsm_network *net, struct msgb *msg);
+
+int mncc_sock_init(struct gsm_network *gsmnet);
+
+#endif
diff --git a/include/osmocom/bsc/mncc_int.h b/include/osmocom/bsc/mncc_int.h
new file mode 100644
index 000000000..4f30f08c0
--- /dev/null
+++ b/include/osmocom/bsc/mncc_int.h
@@ -0,0 +1,12 @@
+#ifndef _MNCC_INT_H
+#define _MNCC_INT_H
+
+#include <stdint.h>
+
+struct mncc_int {
+ uint8_t def_codec[2];
+};
+
+extern struct mncc_int mncc_int;
+
+#endif
diff --git a/include/osmocom/bsc/network_listen.h b/include/osmocom/bsc/network_listen.h
new file mode 100644
index 000000000..67d1f4ef7
--- /dev/null
+++ b/include/osmocom/bsc/network_listen.h
@@ -0,0 +1,16 @@
+#ifndef _OPENBSC_NWL_H
+#define _OPENBSC_NWL_H
+
+#include <stdint.h>
+#include <openbsc/gsm_data.h>
+
+void ipac_nwl_init(void);
+
+/* Start a NWL test. It will raise the S_IPAC_TEST_COMPLETE signal. */
+int ipac_nwl_test_start(struct gsm_bts_trx *trx, uint8_t testnr,
+ const uint8_t *phys_conf, unsigned int phys_conf_len);
+
+int ipac_rxlevstat2whitelist(uint16_t *buf, const struct rxlev_stats *st, uint8_t min_rxlev,
+ uint16_t max_num_arfcns);
+
+#endif /* _OPENBSC_NWL_H */
diff --git a/include/osmocom/bsc/openbscdefines.h b/include/osmocom/bsc/openbscdefines.h
new file mode 100644
index 000000000..c6ac153b8
--- /dev/null
+++ b/include/osmocom/bsc/openbscdefines.h
@@ -0,0 +1,34 @@
+/*
+ * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef OPENBSCDEFINES_H
+#define OPENBSCDEFINES_H
+
+#ifdef BUILDING_ON_WINDOWS
+ #ifdef BUILDING_OPENBSC
+ #define BSC_API __declspec(dllexport)
+ #else
+ #define BSC_API __declspec(dllimport)
+ #endif
+#else
+ #define BSC_API __attribute__((visibility("default")))
+#endif
+
+#endif
diff --git a/include/osmocom/bsc/osmo_bsc.h b/include/osmocom/bsc/osmo_bsc.h
new file mode 100644
index 000000000..1d216ac25
--- /dev/null
+++ b/include/osmocom/bsc/osmo_bsc.h
@@ -0,0 +1,51 @@
+/* OpenBSC BSC code */
+
+#ifndef OSMO_BSC_H
+#define OSMO_BSC_H
+
+#include "bsc_api.h"
+
+#define BSS_SEND_USSD 1
+
+struct sccp_connection;
+struct osmo_msc_data;
+struct bsc_msc_connection;
+
+struct osmo_bsc_sccp_con {
+ struct llist_head entry;
+
+ int ciphering_handled;
+ int rtp_port;
+
+ /* SCCP connection realted */
+ struct sccp_connection *sccp;
+ struct osmo_msc_data *msc;
+ struct osmo_timer_list sccp_it_timeout;
+ struct osmo_timer_list sccp_cc_timeout;
+
+ struct llist_head sccp_queue;
+ unsigned int sccp_queue_size;
+
+ struct gsm_subscriber_connection *conn;
+ uint8_t new_subscriber;
+};
+
+struct bsc_api *osmo_bsc_api();
+
+int bsc_queue_for_msc(struct osmo_bsc_sccp_con *conn, struct msgb *msg);
+int bsc_open_connection(struct osmo_bsc_sccp_con *sccp, struct msgb *msg);
+int bsc_create_new_connection(struct gsm_subscriber_connection *conn,
+ struct osmo_msc_data *msc);
+int bsc_delete_connection(struct osmo_bsc_sccp_con *sccp);
+
+struct osmo_msc_data *bsc_find_msc(struct gsm_subscriber_connection *conn, struct msgb *);
+int bsc_scan_bts_msg(struct gsm_subscriber_connection *conn, struct msgb *msg);
+int bsc_scan_msc_msg(struct gsm_subscriber_connection *conn, struct msgb *msg);
+int bsc_send_welcome_ussd(struct gsm_subscriber_connection *conn);
+
+int bsc_handle_udt(struct osmo_msc_data *msc, struct msgb *msg, unsigned int length);
+int bsc_handle_dt1(struct osmo_bsc_sccp_con *conn, struct msgb *msg, unsigned int len);
+
+int bsc_ctrl_cmds_install();
+
+#endif
diff --git a/include/osmocom/bsc/osmo_bsc_grace.h b/include/osmocom/bsc/osmo_bsc_grace.h
new file mode 100644
index 000000000..e9c1a0a07
--- /dev/null
+++ b/include/osmocom/bsc/osmo_bsc_grace.h
@@ -0,0 +1,31 @@
+/*
+ * (C) 2010-2013 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2010-2013 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef OSMO_BSC_GRACE_H
+#define OSMO_BSC_GRACE_H
+
+#include "gsm_data.h"
+
+struct osmo_msc_data;
+
+int bsc_grace_allow_new_connection(struct gsm_network *net, struct gsm_bts *bts);
+int bsc_grace_paging_request(struct gsm_subscriber *sub, int type, struct osmo_msc_data *msc);
+
+#endif
diff --git a/include/osmocom/bsc/osmo_bsc_rf.h b/include/osmocom/bsc/osmo_bsc_rf.h
new file mode 100644
index 000000000..a67e1bda4
--- /dev/null
+++ b/include/osmocom/bsc/osmo_bsc_rf.h
@@ -0,0 +1,64 @@
+#ifndef OSMO_BSC_RF
+#define OSMO_BSC_RF
+
+#include <openbsc/gsm_data.h>
+#include <osmocom/core/write_queue.h>
+#include <osmocom/core/timer.h>
+
+enum osmo_bsc_rf_opstate {
+ OSMO_BSC_RF_OPSTATE_INOPERATIONAL,
+ OSMO_BSC_RF_OPSTATE_OPERATIONAL,
+};
+
+enum osmo_bsc_rf_adminstate {
+ OSMO_BSC_RF_ADMINSTATE_UNLOCKED,
+ OSMO_BSC_RF_ADMINSTATE_LOCKED,
+};
+
+enum osmo_bsc_rf_policy {
+ OSMO_BSC_RF_POLICY_OFF,
+ OSMO_BSC_RF_POLICY_ON,
+ OSMO_BSC_RF_POLICY_GRACE,
+ OSMO_BSC_RF_POLICY_UNKNOWN,
+};
+
+
+struct gsm_network;
+
+struct osmo_bsc_rf {
+ /* the value of signal.h */
+ int policy;
+ struct osmo_fd listen;
+ struct gsm_network *gsm_network;
+
+ const char *last_state_command;
+
+ /* delay the command */
+ char last_request;
+ struct osmo_timer_list delay_cmd;
+
+ /* verify that RF is up as it should be */
+ struct osmo_timer_list rf_check;
+
+ /* some handling for the automatic grace switch */
+ struct osmo_timer_list grace_timeout;
+
+ /* auto RF switch-off due lack of MSC connection */
+ struct osmo_timer_list auto_off_timer;
+};
+
+struct osmo_bsc_rf_conn {
+ struct osmo_wqueue queue;
+ struct osmo_bsc_rf *rf;
+};
+
+const char *osmo_bsc_rf_get_opstate_name(enum osmo_bsc_rf_opstate opstate);
+const char *osmo_bsc_rf_get_adminstate_name(enum osmo_bsc_rf_adminstate adminstate);
+const char *osmo_bsc_rf_get_policy_name(enum osmo_bsc_rf_policy policy);
+enum osmo_bsc_rf_opstate osmo_bsc_rf_get_opstate_by_bts(struct gsm_bts *bts);
+enum osmo_bsc_rf_adminstate osmo_bsc_rf_get_adminstate_by_bts(struct gsm_bts *bts);
+enum osmo_bsc_rf_policy osmo_bsc_rf_get_policy_by_bts(struct gsm_bts *bts);
+struct osmo_bsc_rf *osmo_bsc_rf_create(const char *path, struct gsm_network *net);
+void osmo_bsc_rf_schedule_lock(struct osmo_bsc_rf *rf, char cmd);
+
+#endif
diff --git a/include/osmocom/bsc/osmo_msc.h b/include/osmocom/bsc/osmo_msc.h
new file mode 100644
index 000000000..beb3f5e4c
--- /dev/null
+++ b/include/osmocom/bsc/osmo_msc.h
@@ -0,0 +1,11 @@
+/* Routines for the MSC handling */
+
+#ifndef OSMO_MSC_H
+#define OSMO_MSC_H
+
+#include "bsc_api.h"
+
+struct bsc_api *msc_bsc_api();
+void msc_release_connection(struct gsm_subscriber_connection *conn);
+
+#endif
diff --git a/include/osmocom/bsc/osmo_msc_data.h b/include/osmocom/bsc/osmo_msc_data.h
new file mode 100644
index 000000000..ba93a089d
--- /dev/null
+++ b/include/osmocom/bsc/osmo_msc_data.h
@@ -0,0 +1,116 @@
+/*
+ * Data for the true BSC
+ *
+ * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2010-2011 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef _OSMO_MSC_DATA_H
+#define _OSMO_MSC_DATA_H
+
+#include "bsc_msc.h"
+
+#include <osmocom/core/timer.h>
+#include <osmocom/gsm/protocol/gsm_04_08.h>
+
+#include <regex.h>
+
+struct osmo_bsc_rf;
+struct gsm_network;
+
+struct gsm_audio_support {
+ uint8_t hr : 1,
+ ver : 7;
+};
+
+enum {
+ MSC_CON_TYPE_NORMAL,
+ MSC_CON_TYPE_LOCAL,
+};
+
+struct osmo_msc_data {
+ struct llist_head entry;
+
+ /* Back pointer */
+ struct gsm_network *network;
+
+ int allow_emerg;
+ int type;
+
+ /* local call routing */
+ char *local_pref;
+ regex_t local_pref_reg;
+
+
+ /* Connection data */
+ char *bsc_token;
+ int ping_timeout;
+ int pong_timeout;
+ struct osmo_timer_list ping_timer;
+ struct osmo_timer_list pong_timer;
+ struct bsc_msc_connection *msc_con;
+ int core_ncc;
+ int core_mcc;
+ int rtp_base;
+
+ /* audio codecs */
+ struct gsm48_multi_rate_conf amr_conf;
+ struct gsm_audio_support **audio_support;
+ int audio_length;
+
+ /* destinations */
+ struct llist_head dests;
+
+ /* ussd welcome text */
+ char *ussd_welcome_txt;
+
+ /* mgcp agent */
+ struct osmo_wqueue mgcp_agent;
+
+ int nr;
+};
+
+/*
+ * Per BSC data.
+ */
+struct osmo_bsc_data {
+ struct gsm_network *network;
+
+ /* msc configuration */
+ struct llist_head mscs;
+
+ /* rf ctl related bits */
+ char *mid_call_txt;
+ int mid_call_timeout;
+ char *rf_ctrl_name;
+ struct osmo_bsc_rf *rf_ctrl;
+ int auto_off_timeout;
+};
+
+
+int osmo_bsc_msc_init(struct osmo_msc_data *msc);
+int osmo_bsc_sccp_init(struct gsm_network *gsmnet);
+int msc_queue_write(struct bsc_msc_connection *conn, struct msgb *msg, int proto);
+
+int osmo_bsc_audio_init(struct gsm_network *network);
+
+struct osmo_msc_data *osmo_msc_data_find(struct gsm_network *, int);
+struct osmo_msc_data *osmo_msc_data_alloc(struct gsm_network *, int);
+
+
+#endif
diff --git a/include/osmocom/bsc/paging.h b/include/osmocom/bsc/paging.h
new file mode 100644
index 000000000..2a10f4ef1
--- /dev/null
+++ b/include/osmocom/bsc/paging.h
@@ -0,0 +1,75 @@
+/* Paging helper and manager.... */
+/* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef PAGING_H
+#define PAGING_H
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <osmocom/core/linuxlist.h>
+#include "gsm_data.h"
+#include "gsm_subscriber.h"
+#include <osmocom/core/timer.h>
+
+/**
+ * A pending paging request
+ */
+struct gsm_paging_request {
+ /* list_head for list of all paging requests */
+ struct llist_head entry;
+ /* the subscriber which we're paging. Later gsm_paging_request
+ * should probably become a part of the gsm_subscriber struct? */
+ struct gsm_subscriber *subscr;
+ /* back-pointer to the BTS on which we are paging */
+ struct gsm_bts *bts;
+ /* what kind of channel type do we ask the MS to establish */
+ int chan_type;
+
+ /* Timer 3113: how long do we try to page? */
+ struct osmo_timer_list T3113;
+
+ /* How often did we ask the BTS to page? */
+ int attempts;
+
+ /* callback to be called in case paging completes */
+ gsm_cbfn *cbfn;
+ void *cbfn_param;
+};
+
+/* schedule paging request */
+int paging_request(struct gsm_network *network, struct gsm_subscriber *subscr,
+ int type, gsm_cbfn *cbfn, void *data);
+int paging_request_bts(struct gsm_bts *bts, struct gsm_subscriber *subscr,
+ int type, gsm_cbfn *cbfn, void *data);
+
+/* stop paging requests */
+void paging_request_stop(struct gsm_bts *bts, struct gsm_subscriber *subscr,
+ struct gsm_subscriber_connection *conn,
+ struct msgb *msg);
+
+/* update paging load */
+void paging_update_buffer_space(struct gsm_bts *bts, uint16_t);
+
+/* pending paging requests */
+unsigned int paging_pending_requests_nr(struct gsm_bts *bts);
+
+void *paging_get_data(struct gsm_bts *bts, struct gsm_subscriber *subscr);
+
+#endif
diff --git a/include/osmocom/bsc/rest_octets.h b/include/osmocom/bsc/rest_octets.h
new file mode 100644
index 000000000..56d4e0de8
--- /dev/null
+++ b/include/osmocom/bsc/rest_octets.h
@@ -0,0 +1,132 @@
+#ifndef _REST_OCTETS_H
+#define _REST_OCTETS_H
+
+#include <openbsc/gsm_04_08.h>
+
+/* generate SI1 rest octets */
+int rest_octets_si1(uint8_t *data, uint8_t *nch_pos, int is1800_net);
+
+struct gsm48_si_selection_params {
+ uint16_t penalty_time:5,
+ temp_offs:3,
+ cell_resel_off:6,
+ cbq:1,
+ present:1;
+};
+
+struct gsm48_si_power_offset {
+ uint8_t power_offset:2,
+ present:1;
+};
+
+struct gsm48_si3_gprs_ind {
+ uint8_t si13_position:1,
+ ra_colour:3,
+ present:1;
+};
+
+struct gsm48_lsa_params {
+ uint32_t prio_thr:3,
+ lsa_offset:3,
+ mcc:12,
+ mnc:12;
+ unsigned int present;
+};
+
+struct gsm48_si_ro_info {
+ struct gsm48_si_selection_params selection_params;
+ struct gsm48_si_power_offset power_offset;
+ uint8_t si2ter_indicator;
+ uint8_t early_cm_ctrl;
+ struct {
+ uint8_t where:3,
+ present:1;
+ } scheduling;
+ struct gsm48_si3_gprs_ind gprs_ind;
+
+ /* SI 4 specific */
+ struct gsm48_lsa_params lsa_params;
+ uint16_t cell_id;
+ uint8_t break_ind; /* do we have SI7 + SI8 ? */
+};
+
+
+/* Generate SI3 Rest Octests (Chapter 10.5.2.34 / Table 10.4.72) */
+int rest_octets_si3(uint8_t *data, const struct gsm48_si_ro_info *si3);
+
+/* Generate SI4 Rest Octets (Chapter 10.5.2.35) */
+int rest_octets_si4(uint8_t *data, const struct gsm48_si_ro_info *si4);
+
+enum pbcch_carrier_type {
+ PBCCH_BCCH,
+ PBCCH_ARFCN,
+ PBCCH_MAIO
+};
+
+/* TS 03.60 Chapter 6.3.3.1: Network Mode of Operation */
+enum gprs_nmo {
+ GPRS_NMO_I = 0, /* CS pagin on GPRS paging or traffic channel */
+ GPRS_NMO_II = 1, /* all paging on CCCH */
+ GPRS_NMO_III = 2, /* no paging coordination */
+};
+
+/* TS 04.60 12.24 */
+struct gprs_cell_options {
+ enum gprs_nmo nmo;
+ /* T3168: wait for packet uplink assignment message */
+ uint32_t t3168; /* in milliseconds */
+ /* T3192: wait for release of the TBF after reception of the final block */
+ uint32_t t3192; /* in milliseconds */
+ uint32_t drx_timer_max;/* in seconds */
+ uint32_t bs_cv_max;
+
+ uint8_t ext_info_present;
+ struct {
+ uint8_t egprs_supported;
+ uint8_t use_egprs_p_ch_req;
+ uint8_t bep_period;
+ uint8_t pfc_supported;
+ uint8_t dtm_supported;
+ uint8_t bss_paging_coordination;
+ } ext_info;
+};
+
+/* TS 04.60 Table 12.9.2 */
+struct gprs_power_ctrl_pars {
+ uint8_t alpha;
+ uint8_t t_avg_w;
+ uint8_t t_avg_t;
+ uint8_t pc_meas_chan;
+ uint8_t n_avg_i;
+};
+
+struct gsm48_si13_info {
+ struct gprs_cell_options cell_opts;
+ struct gprs_power_ctrl_pars pwr_ctrl_pars;
+ uint8_t bcch_change_mark;
+ uint8_t si_change_field;
+ uint8_t pbcch_present;
+
+ union {
+ struct {
+ uint8_t rac;
+ uint8_t spgc_ccch_sup;
+ uint8_t net_ctrl_ord;
+ uint8_t prio_acc_thr;
+ } no_pbcch;
+ struct {
+ uint8_t psi1_rep_per;
+ uint8_t pb;
+ uint8_t tsc;
+ uint8_t tn;
+ enum pbcch_carrier_type carrier_type;
+ uint16_t arfcn;
+ uint8_t maio;
+ } pbcch;
+ };
+};
+
+/* Generate SI13 Rest Octests (Chapter 10.5.2.37b) */
+int rest_octets_si13(uint8_t *data, const struct gsm48_si13_info *si13);
+
+#endif /* _REST_OCTETS_H */
diff --git a/include/osmocom/bsc/rrlp.h b/include/osmocom/bsc/rrlp.h
new file mode 100644
index 000000000..c89402a2d
--- /dev/null
+++ b/include/osmocom/bsc/rrlp.h
@@ -0,0 +1,7 @@
+#ifndef _RRLP_H
+#define _RRLP_H
+
+void on_dso_load_rrlp(void);
+
+#endif /* _RRLP_H */
+
diff --git a/include/osmocom/bsc/rs232.h b/include/osmocom/bsc/rs232.h
new file mode 100644
index 000000000..61187ca62
--- /dev/null
+++ b/include/osmocom/bsc/rs232.h
@@ -0,0 +1,9 @@
+#ifndef _RS232_H
+#define _RS232_H
+
+int rs232_setup(const char *serial_port, unsigned int delay_ms,
+ struct gsm_bts *bts);
+
+int handle_serial_msg(struct msgb *msg);
+
+#endif /* _RS232_H */
diff --git a/include/osmocom/bsc/rtp_proxy.h b/include/osmocom/bsc/rtp_proxy.h
new file mode 100644
index 000000000..26cac0df4
--- /dev/null
+++ b/include/osmocom/bsc/rtp_proxy.h
@@ -0,0 +1,91 @@
+#ifndef _RTP_PROXY_H
+#define _RTP_PROXY_H
+
+/* RTP proxy handling for ip.access nanoBTS */
+
+/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#include <netinet/in.h>
+
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/select.h>
+
+#include <openbsc/mncc.h>
+
+#define RTP_PT_GSM_FULL 3
+#define RTP_PT_GSM_HALF 96
+#define RTP_PT_GSM_EFR 97
+#define RTP_PT_AMR 98
+
+enum rtp_rx_action {
+ RTP_NONE,
+ RTP_PROXY,
+ RTP_RECV_UPSTREAM,
+};
+
+enum rtp_tx_action {
+ RTP_SEND_NONE,
+ RTP_SEND_DOWNSTREAM,
+};
+
+struct rtp_sub_socket {
+ struct sockaddr_in sin_local;
+ struct sockaddr_in sin_remote;
+
+ struct osmo_fd bfd;
+ /* linked list of to-be-transmitted msgb's */
+ struct llist_head tx_queue;
+};
+
+struct rtp_socket {
+ struct llist_head list;
+
+ struct rtp_sub_socket rtp;
+ struct rtp_sub_socket rtcp;
+
+ /* what should we do on receive? */
+ enum rtp_rx_action rx_action;
+ union {
+ struct {
+ struct rtp_socket *other_sock;
+ } proxy;
+ struct {
+ struct gsm_network *net;
+ uint32_t callref;
+ } receive;
+ };
+ enum rtp_tx_action tx_action;
+ struct {
+ uint16_t sequence;
+ uint32_t timestamp;
+ uint32_t ssrc;
+ struct timeval last_tv;
+ } transmit;
+};
+
+struct rtp_socket *rtp_socket_create(void);
+int rtp_socket_bind(struct rtp_socket *rs, uint32_t ip);
+int rtp_socket_connect(struct rtp_socket *rs, uint32_t ip, uint16_t port);
+int rtp_socket_proxy(struct rtp_socket *this, struct rtp_socket *other);
+int rtp_socket_upstream(struct rtp_socket *this, struct gsm_network *net, uint32_t callref);
+int rtp_socket_free(struct rtp_socket *rs);
+int rtp_send_frame(struct rtp_socket *rs, struct gsm_data_frame *frame);
+
+#endif /* _RTP_PROXY_H */
diff --git a/include/osmocom/bsc/sgsn.h b/include/osmocom/bsc/sgsn.h
new file mode 100644
index 000000000..f7af7509b
--- /dev/null
+++ b/include/osmocom/bsc/sgsn.h
@@ -0,0 +1,69 @@
+#ifndef _SGSN_H
+#define _SGSN_H
+
+
+#include <osmocom/core/msgb.h>
+
+#include <osmocom/gprs/gprs_ns.h>
+#include <openbsc/gprs_sgsn.h>
+
+struct sgsn_config {
+ /* parsed from config file */
+
+ char *gtp_statedir;
+ struct sockaddr_in gtp_listenaddr;
+
+ /* misc */
+ struct gprs_ns_inst *nsi;
+
+ int acl_enabled;
+ struct llist_head imsi_acl;
+};
+
+struct sgsn_instance {
+ char *config_file;
+ struct sgsn_config cfg;
+ /* File descriptor wrappers for LibGTP */
+ struct osmo_fd gtp_fd0;
+ struct osmo_fd gtp_fd1c;
+ struct osmo_fd gtp_fd1u;
+ /* Timer for libGTP */
+ struct osmo_timer_list gtp_timer;
+ /* GSN instance for libgtp */
+ struct gsn_t *gsn;
+};
+
+extern struct sgsn_instance *sgsn;
+
+/* sgsn_vty.c */
+
+int sgsn_vty_init(void);
+int sgsn_parse_config(const char *config_file, struct sgsn_config *cfg);
+
+/* sgsn.c */
+
+/* Main input function for Gb proxy */
+int sgsn_rcvmsg(struct msgb *msg, struct gprs_nsvc *nsvc, uint16_t ns_bvci);
+
+
+struct sgsn_pdp_ctx *sgsn_create_pdp_ctx(struct sgsn_ggsn_ctx *ggsn,
+ struct sgsn_mm_ctx *mmctx,
+ uint16_t nsapi,
+ struct tlv_parsed *tp);
+int sgsn_delete_pdp_ctx(struct sgsn_pdp_ctx *pctx);
+
+/* gprs_sndcp.c */
+
+/* Entry point for the SNSM-ACTIVATE.indication */
+int sndcp_sm_activate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
+/* Entry point for the SNSM-DEACTIVATE.indication */
+int sndcp_sm_deactivate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
+/* Called by SNDCP when it has received/re-assembled a N-PDU */
+int sgsn_rx_sndcp_ud_ind(struct gprs_ra_id *ra_id, int32_t tlli, uint8_t nsapi,
+ struct msgb *msg, uint32_t npdu_len, uint8_t *npdu);
+int sndcp_unitdata_req(struct msgb *msg, struct gprs_llc_lle *lle, uint8_t nsapi,
+ void *mmcontext);
+int sndcp_llunitdata_ind(struct msgb *msg, struct gprs_llc_lle *lle,
+ uint8_t *hdr, uint16_t len);
+
+#endif
diff --git a/include/osmocom/bsc/signal.h b/include/osmocom/bsc/signal.h
new file mode 100644
index 000000000..39319f1c9
--- /dev/null
+++ b/include/osmocom/bsc/signal.h
@@ -0,0 +1,244 @@
+/* Generic signalling/notification infrastructure */
+/* (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2009 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2010 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef OPENBSC_SIGNAL_H
+#define OPENBSC_SIGNAL_H
+
+#include <stdlib.h>
+#include <errno.h>
+
+#include <openbsc/gsm_data.h>
+
+#include <osmocom/core/signal.h>
+
+/*
+ * Signalling subsystems
+ */
+enum signal_subsystems {
+ SS_PAGING,
+ SS_SMS,
+ SS_ABISIP,
+ SS_NM,
+ SS_LCHAN,
+ SS_SUBSCR,
+ SS_SCALL,
+ SS_CHALLOC,
+ SS_IPAC_NWL,
+ SS_RF,
+ SS_MSC,
+ SS_HO,
+ SS_CCCH,
+};
+
+/* SS_PAGING signals */
+enum signal_paging {
+ S_PAGING_SUCCEEDED,
+ S_PAGING_EXPIRED,
+};
+
+/* SS_SMS signals */
+enum signal_sms {
+ S_SMS_SUBMITTED, /* A SMS has been successfully submitted to us */
+ S_SMS_DELIVERED, /* A SMS has been successfully delivered to a MS */
+ S_SMS_SMMA, /* A MS tells us it has more space available */
+ S_SMS_MEM_EXCEEDED, /* A MS tells us it has no more space available */
+ S_SMS_UNKNOWN_ERROR, /* A MS tells us it has an error */
+};
+
+/* SS_ABISIP signals */
+enum signal_abisip {
+ S_ABISIP_CRCX_ACK,
+ S_ABISIP_MDCX_ACK,
+ S_ABISIP_DLCX_IND,
+};
+
+/* SS_NM signals */
+enum signal_nm {
+ S_NM_SW_ACTIV_REP, /* GSM 12.21 software activated report */
+ S_NM_FAIL_REP, /* GSM 12.21 failure event report */
+ S_NM_NACK, /* GSM 12.21 various NM_MT_*_NACK happened */
+ S_NM_IPACC_NACK, /* GSM 12.21 nanoBTS extensions NM_MT_IPACC_*_*_NACK happened */
+ S_NM_IPACC_ACK, /* GSM 12.21 nanoBTS extensions NM_MT_IPACC_*_*_ACK happened */
+ S_NM_IPACC_RESTART_ACK, /* nanoBTS has send a restart ack */
+ S_NM_IPACC_RESTART_NACK,/* nanoBTS has send a restart ack */
+ S_NM_TEST_REP, /* GSM 12.21 Test Report */
+ S_NM_STATECHG_OPER, /* Operational State changed*/
+ S_NM_STATECHG_ADM, /* Administrative State changed */
+ S_NM_OM2K_CONF_RES, /* OM2K Configuration Result */
+};
+
+/* SS_LCHAN signals */
+enum signal_lchan {
+ /*
+ * The lchan got freed with an use_count != 0 and error
+ * recovery needs to be carried out from within the
+ * signal handler.
+ */
+ S_LCHAN_UNEXPECTED_RELEASE,
+ S_LCHAN_ACTIVATE_ACK, /* 08.58 Channel Activate ACK */
+ S_LCHAN_ACTIVATE_NACK, /* 08.58 Channel Activate NACK */
+ S_LCHAN_HANDOVER_COMPL, /* 04.08 Handover Completed */
+ S_LCHAN_HANDOVER_FAIL, /* 04.08 Handover Failed */
+ S_LCHAN_HANDOVER_DETECT, /* 08.58 Handover Detect */
+ S_LCHAN_MEAS_REP, /* 08.58 Measurement Report */
+};
+
+/* SS_CHALLOC signals */
+enum signal_challoc {
+ S_CHALLOC_ALLOC_FAIL, /* allocation of lchan has failed */
+ S_CHALLOC_FREED, /* lchan has been successfully freed */
+};
+
+/* SS_SUBSCR signals */
+enum signal_subscr {
+ S_SUBSCR_ATTACHED,
+ S_SUBSCR_DETACHED,
+ S_SUBSCR_IDENTITY, /* we've received some identity information */
+};
+
+/* SS_SCALL signals */
+enum signal_scall {
+ S_SCALL_SUCCESS,
+ S_SCALL_EXPIRED,
+ S_SCALL_DETACHED,
+};
+
+/* SS_IPAC_NWL signals */
+enum signal_ipaccess {
+ S_IPAC_NWL_COMPLETE,
+};
+
+enum signal_global {
+ S_GLOBAL_BTS_CLOSE_OM,
+};
+
+/* SS_RF signals */
+enum signal_rf {
+ S_RF_OFF,
+ S_RF_ON,
+ S_RF_GRACE,
+};
+
+struct gsm_subscriber;
+
+struct paging_signal_data {
+ struct gsm_subscriber *subscr;
+ struct gsm_bts *bts;
+
+ int paging_result;
+
+ /* NULL in case the paging didn't work */
+ struct gsm_subscriber_connection *conn;
+};
+
+struct scall_signal_data {
+ struct gsm_subscriber *subscr;
+ struct gsm_subscriber_connection *conn;
+ void *data;
+};
+
+struct ipacc_ack_signal_data {
+ struct gsm_bts_trx *trx;
+ uint8_t msg_type;
+};
+
+struct abis_om2k_mo;
+
+struct nm_statechg_signal_data {
+ struct gsm_bts *bts;
+ uint8_t obj_class;
+ void *obj;
+ struct gsm_nm_state *old_state;
+ struct gsm_nm_state *new_state;
+
+ /* This pointer is vaold for TS 12.21 MO */
+ struct abis_om_obj_inst *obj_inst;
+ /* This pointer is vaold for RBS2000 MO */
+ struct abis_om2k_mo *om2k_mo;
+};
+
+struct nm_om2k_signal_data {
+ struct gsm_bts *bts;
+ void *obj;
+ struct abis_om2k_mo *om2k_mo;
+
+ uint8_t accordance_ind;
+};
+
+struct nm_nack_signal_data {
+ struct msgb *msg;
+ struct gsm_bts *bts;
+ uint8_t mt;
+};
+
+struct challoc_signal_data {
+ struct gsm_bts *bts;
+ struct gsm_lchan *lchan;
+ enum gsm_chan_t type;
+};
+
+struct rf_signal_data {
+ struct gsm_network *net;
+};
+
+struct sms_signal_data {
+ /* The transaction where this occured */
+ struct gsm_trans *trans;
+ /* Can be NULL for SMMA */
+ struct gsm_sms *sms;
+ /* int paging result. Only the ones with > 0 */
+ int paging_result;
+};
+
+struct lchan_signal_data {
+ /* The lchan the signal happened on */
+ struct gsm_lchan *lchan;
+ /* Measurement reports on this lchan */
+ struct gsm_meas_rep *mr;
+};
+
+/* MSC signals */
+enum signal_msc {
+ S_MSC_LOST,
+ S_MSC_CONNECTED,
+ S_MSC_AUTHENTICATED,
+};
+
+struct osmo_msc_data;
+struct msc_signal_data {
+ struct osmo_msc_data *data;
+};
+
+/* SS_CCCH signals */
+enum signal_ccch {
+ S_CCCH_PAGING_LOAD,
+ S_CCCH_RACH_LOAD,
+};
+
+struct ccch_signal_data {
+ struct gsm_bts *bts;
+ uint16_t pg_buf_space;
+ uint16_t rach_slot_count;
+ uint16_t rach_busy_count;
+ uint16_t rach_access_count;
+};
+
+#endif
diff --git a/include/osmocom/bsc/silent_call.h b/include/osmocom/bsc/silent_call.h
new file mode 100644
index 000000000..2492903c2
--- /dev/null
+++ b/include/osmocom/bsc/silent_call.h
@@ -0,0 +1,12 @@
+#ifndef _SILENT_CALL_H
+#define _SILENT_CALL_H
+
+struct gsm_subscriber_connection;
+
+extern int gsm_silent_call_start(struct gsm_subscriber *subscr,
+ void *data, int type);
+extern int gsm_silent_call_stop(struct gsm_subscriber *subscr);
+extern int silent_call_rx(struct gsm_subscriber_connection *conn, struct msgb *msg);
+extern int silent_call_reroute(struct gsm_subscriber_connection *conn, struct msgb *msg);
+
+#endif /* _SILENT_CALL_H */
diff --git a/include/osmocom/bsc/sms_queue.h b/include/osmocom/bsc/sms_queue.h
new file mode 100644
index 000000000..2a8bd5850
--- /dev/null
+++ b/include/osmocom/bsc/sms_queue.h
@@ -0,0 +1,17 @@
+#ifndef SMS_QUEUE_H
+#define SMS_QUEUE_H
+
+struct gsm_network;
+struct gsm_sms_queue;
+struct vty;
+
+int sms_queue_start(struct gsm_network *, int in_flight);
+int sms_queue_trigger(struct gsm_sms_queue *);
+
+/* vty helper functions */
+int sms_queue_stats(struct gsm_sms_queue *, struct vty* vty);
+int sms_queue_set_max_pending(struct gsm_sms_queue *, int max);
+int sms_queue_set_max_failure(struct gsm_sms_queue *, int fail);
+int sms_queue_clear(struct gsm_sms_queue *);
+
+#endif
diff --git a/include/osmocom/bsc/socket.h b/include/osmocom/bsc/socket.h
new file mode 100644
index 000000000..0fd85f104
--- /dev/null
+++ b/include/osmocom/bsc/socket.h
@@ -0,0 +1,14 @@
+#ifndef _BSC_SOCKET_H
+#define _BSC_SOCKET_H
+
+#include <osmocom/core/select.h>
+
+#ifndef IPPROTO_GRE
+#define IPPROTO_GRE 47
+#endif
+
+int make_sock(struct osmo_fd *bfd, int proto,
+ uint32_t ip, uint16_t port, int priv_nr,
+ int (*cb)(struct osmo_fd *fd, unsigned int what), void *data);
+
+#endif /* _BSC_SOCKET_H */
diff --git a/include/osmocom/bsc/system_information.h b/include/osmocom/bsc/system_information.h
new file mode 100644
index 000000000..6a5684821
--- /dev/null
+++ b/include/osmocom/bsc/system_information.h
@@ -0,0 +1,10 @@
+#ifndef _SYSTEM_INFO_H
+#define _SYSTEM_INFO_H
+
+#include <osmocom/gsm/sysinfo.h>
+
+struct gsm_bts;
+
+int gsm_generate_si(struct gsm_bts *bts, enum osmo_sysinfo_type type);
+
+#endif
diff --git a/include/osmocom/bsc/token_auth.h b/include/osmocom/bsc/token_auth.h
new file mode 100644
index 000000000..47dc7aa94
--- /dev/null
+++ b/include/osmocom/bsc/token_auth.h
@@ -0,0 +1,7 @@
+#ifndef _TOKEN_AUTH_H
+#define _TOKEN_AUTH_H
+
+void on_dso_load_token(void);
+
+#endif /* _TOKEN_AUTH_H */
+
diff --git a/include/osmocom/bsc/transaction.h b/include/osmocom/bsc/transaction.h
new file mode 100644
index 000000000..b6c859c71
--- /dev/null
+++ b/include/osmocom/bsc/transaction.h
@@ -0,0 +1,75 @@
+#ifndef _TRANSACT_H
+#define _TRANSACT_H
+
+#include <openbsc/gsm_data.h>
+#include <openbsc/gsm_subscriber.h>
+#include <osmocom/core/linuxlist.h>
+#include <openbsc/gsm_04_11.h>
+#include <openbsc/mncc.h>
+#include <osmocom/gsm/gsm0411_smc.h>
+#include <osmocom/gsm/gsm0411_smr.h>
+
+/* One transaction */
+struct gsm_trans {
+ /* Entry in list of all transactions */
+ struct llist_head entry;
+
+ /* The protocol within which we live */
+ uint8_t protocol;
+
+ /* The current transaction ID */
+ uint8_t transaction_id;
+
+ /* To whom we belong, unique identifier of remote MM entity */
+ struct gsm_subscriber *subscr;
+
+ /* The associated connection we are using to transmit messages */
+ struct gsm_subscriber_connection *conn;
+
+ /* reference from MNCC or other application */
+ uint32_t callref;
+
+ /* if traffic channel receive was requested */
+ int tch_recv;
+
+ /* is thats one paging? */
+ struct gsm_network **paging_request;
+
+ union {
+ struct {
+
+ /* current call state */
+ int state;
+
+ /* current timer and message queue */
+ int Tcurrent; /* current CC timer */
+ int T308_second; /* used to send release again */
+ struct osmo_timer_list timer;
+ struct gsm_mncc msg; /* stores setup/disconnect/release message */
+ } cc;
+ struct {
+ struct gsm411_smc_inst smc_inst;
+ struct gsm411_smr_inst smr_inst;
+
+ struct gsm_sms *sms;
+ } sms;
+ };
+};
+
+
+
+struct gsm_trans *trans_find_by_id(struct gsm_subscriber *subscr,
+ uint8_t proto, uint8_t trans_id);
+struct gsm_trans *trans_find_by_callref(struct gsm_network *net,
+ uint32_t callref);
+
+struct gsm_trans *trans_alloc(struct gsm_subscriber *subscr,
+ uint8_t protocol, uint8_t trans_id,
+ uint32_t callref);
+void trans_free(struct gsm_trans *trans);
+
+int trans_assign_trans_id(struct gsm_subscriber *subscr,
+ uint8_t protocol, uint8_t ti_flag);
+int trans_has_conn(const struct gsm_subscriber_connection *conn);
+
+#endif
diff --git a/include/osmocom/bsc/trau_mux.h b/include/osmocom/bsc/trau_mux.h
new file mode 100644
index 000000000..2c01b06db
--- /dev/null
+++ b/include/osmocom/bsc/trau_mux.h
@@ -0,0 +1,55 @@
+/* Simple TRAU frame reflector to route voice calls */
+
+/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/* The "TRAU mux map" defines which particular 16kbit sub-slot (in which E1
+ * timeslot on which E1 interface) should be directly muxed to which other
+ * sub-slot. Entries in the mux map are always bi-directional.
+ *
+ * The idea of all this is to directly switch voice channels in the BSC
+ * from one phone to another. We do this right now since we don't support
+ * any external interface for voice channels, and in the future as an
+ * optimization to routing them externally.
+ */
+
+#include <stdint.h>
+#include <openbsc/gsm_data.h>
+#include <openbsc/mncc.h>
+
+/* map a TRAU mux map entry */
+int trau_mux_map(const struct gsm_e1_subslot *src,
+ const struct gsm_e1_subslot *dst);
+int trau_mux_map_lchan(const struct gsm_lchan *src,
+ const struct gsm_lchan *dst);
+
+/* unmap a TRAU mux map entry */
+int trau_mux_unmap(const struct gsm_e1_subslot *ss, uint32_t callref);
+
+/* we get called by subchan_demux */
+int trau_mux_input(struct gsm_e1_subslot *src_e1_ss,
+ const uint8_t *trau_bits, int num_bits);
+
+/* add a trau receiver */
+int trau_recv_lchan(struct gsm_lchan *lchan, uint32_t callref);
+
+/* send trau from application */
+int trau_send_frame(struct gsm_lchan *lchan, struct gsm_data_frame *frame);
+
+/* callback invoked if we receive TRAU frames */
+int subch_cb(struct subch_demux *dmx, int ch, uint8_t *data, int len, void *_priv);
diff --git a/include/osmocom/bsc/trau_upqueue.h b/include/osmocom/bsc/trau_upqueue.h
new file mode 100644
index 000000000..ecc765843
--- /dev/null
+++ b/include/osmocom/bsc/trau_upqueue.h
@@ -0,0 +1,7 @@
+#ifndef _TRAU_UPQUEUE_H
+#define _TRAU_UPQUEUE_H
+
+void trau_tx_to_mncc(struct gsm_network *net, struct msgb *msg);
+
+#endif /* _TRAU_UPQUEUE_H */
+
diff --git a/include/osmocom/bsc/ussd.h b/include/osmocom/bsc/ussd.h
new file mode 100644
index 000000000..266546811
--- /dev/null
+++ b/include/osmocom/bsc/ussd.h
@@ -0,0 +1,10 @@
+#ifndef _USSD_H
+#define _USSD_H
+
+/* Handler function for mobile-originated USSD messages */
+
+#include <osmocom/core/msgb.h>
+
+int handle_rcv_ussd(struct gsm_subscriber_connection *conn, struct msgb *msg);
+
+#endif
diff --git a/include/osmocom/bsc/vty.h b/include/osmocom/bsc/vty.h
new file mode 100644
index 000000000..183fc2510
--- /dev/null
+++ b/include/osmocom/bsc/vty.h
@@ -0,0 +1,49 @@
+#ifndef OPENBSC_VTY_H
+#define OPENBSC_VTY_H
+
+#include <osmocom/vty/vty.h>
+#include <osmocom/vty/buffer.h>
+#include <osmocom/vty/command.h>
+
+struct gsm_network;
+struct vty;
+
+void openbsc_vty_print_statistics(struct vty *vty, struct gsm_network *);
+
+struct buffer *vty_argv_to_buffer(int argc, const char *argv[], int base);
+
+extern struct cmd_element cfg_description_cmd;
+extern struct cmd_element cfg_no_description_cmd;
+extern struct cmd_element ournode_exit_cmd;
+extern struct cmd_element ournode_end_cmd;
+
+enum bsc_vty_node {
+ GSMNET_NODE = _LAST_OSMOVTY_NODE + 1,
+ BTS_NODE,
+ TRX_NODE,
+ TS_NODE,
+ SUBSCR_NODE,
+ MGCP_NODE,
+ GBPROXY_NODE,
+ SGSN_NODE,
+ OML_NODE,
+ NAT_NODE,
+ NAT_BSC_NODE,
+ MSC_NODE,
+ OM2K_NODE,
+ TRUNK_NODE,
+ PGROUP_NODE,
+ MNCC_INT_NODE,
+ BSC_NODE,
+ SMPP_NODE,
+ SMPP_ESME_NODE,
+};
+
+extern int bsc_vty_is_config_node(struct vty *vty, int node);
+extern void bsc_replace_string(void *ctx, char **dst, const char *newstr);
+
+struct log_info;
+int bsc_vty_init(const struct log_info *cat);
+int bsc_vty_init_extra(void);
+
+#endif