BSC: introduce new "sysmobts" BTS model

so far, osmo-bts/sysmobts used to be entered as "sysmobts" type in the
configuration file.  However, there are some differences in the
protocol/behaviour and we should reflect that by a new BTS plugin (with
lots of code reuse from the nanobts driver).
diff --git a/openbsc/include/openbsc/bss.h b/openbsc/include/openbsc/bss.h
index 2317bd2..1c6b5c3 100644
--- a/openbsc/include/openbsc/bss.h
+++ b/openbsc/include/openbsc/bss.h
@@ -15,4 +15,5 @@
 extern int bts_model_nanobts_init(void);
 extern int bts_model_hslfemto_init(void);
 extern int bts_model_nokia_site_init(void);
+extern int bts_model_sysmobts_init(void);
 #endif
diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h
index 7883253..e2ba9b6 100644
--- a/openbsc/include/openbsc/gsm_data.h
+++ b/openbsc/include/openbsc/gsm_data.h
@@ -308,10 +308,12 @@
 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;
diff --git a/openbsc/include/openbsc/gsm_data_shared.h b/openbsc/include/openbsc/gsm_data_shared.h
index b3ea20b..7db41c3 100644
--- a/openbsc/include/openbsc/gsm_data_shared.h
+++ b/openbsc/include/openbsc/gsm_data_shared.h
@@ -362,6 +362,7 @@
 	GSM_BTS_TYPE_RBS2000,
 	GSM_BTS_TYPE_HSL_FEMTO,
 	GSM_BTS_TYPE_NOKIA_SITE,
+	GSM_BTS_TYPE_OSMO_SYSMO,
 };
 
 struct vty;
diff --git a/openbsc/src/libbsc/Makefile.am b/openbsc/src/libbsc/Makefile.am
index 6f170e0..7cb1e6e 100644
--- a/openbsc/src/libbsc/Makefile.am
+++ b/openbsc/src/libbsc/Makefile.am
@@ -14,6 +14,7 @@
 			bts_nokia_site.c \
 			bts_hsl_femtocell.c \
 			bts_unknown.c \
+			bts_sysmobts.c \
 			chan_alloc.c \
 			gsm_subscriber_base.c \
 			handover_decision.c handover_logic.c meas_rep.c \
diff --git a/openbsc/src/libbsc/abis_nm.c b/openbsc/src/libbsc/abis_nm.c
index 6568b53..673f43e 100644
--- a/openbsc/src/libbsc/abis_nm.c
+++ b/openbsc/src/libbsc/abis_nm.c
@@ -610,6 +610,7 @@
 
 	switch (bts_type) {
 	case GSM_BTS_TYPE_NANOBTS:
+	case GSM_BTS_TYPE_OSMO_SYSMO:
 		rc = abis_nm_rx_ipacc(mb);
 		abis_nm_queue_send_next(sign_link->trx->bts);
 		break;
@@ -1531,6 +1532,9 @@
 			break;
 		}
 		return -EINVAL;
+	case GSM_BTS_TYPE_OSMO_SYSMO:
+		/* no known restrictions */
+		return 0;
 	default:
 		/* unknown BTS type */
 		return 0;
diff --git a/openbsc/src/libbsc/bsc_vty.c b/openbsc/src/libbsc/bsc_vty.c
index 413eac4..f306488 100644
--- a/openbsc/src/libbsc/bsc_vty.c
+++ b/openbsc/src/libbsc/bsc_vty.c
@@ -517,6 +517,7 @@
 	}
 	switch (bts->type) {
 	case GSM_BTS_TYPE_NANOBTS:
+	case GSM_BTS_TYPE_OSMO_SYSMO:
 		vty_out(vty, "  ip.access unit_id %u %u%s",
 			bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE);
 		vty_out(vty, "  oml ip.access stream_id %u line %u%s",
diff --git a/openbsc/src/libbsc/bts_init.c b/openbsc/src/libbsc/bts_init.c
index 693eca8..ae41ecc 100644
--- a/openbsc/src/libbsc/bts_init.c
+++ b/openbsc/src/libbsc/bts_init.c
@@ -25,6 +25,7 @@
 	bts_model_nanobts_init();
 	bts_model_hslfemto_init();
 	bts_model_nokia_site_init();
+	bts_model_sysmobts_init();
 	/* Your new BTS here. */
 	return 0;
 }
diff --git a/openbsc/src/libbsc/bts_ipaccess_nanobts.c b/openbsc/src/libbsc/bts_ipaccess_nanobts.c
index b2b648d..bc246f1 100644
--- a/openbsc/src/libbsc/bts_ipaccess_nanobts.c
+++ b/openbsc/src/libbsc/bts_ipaccess_nanobts.c
@@ -41,7 +41,7 @@
 static int bts_model_nanobts_start(struct gsm_network *net);
 static void bts_model_nanobts_e1line_bind_ops(struct e1inp_line *line);
 
-static struct gsm_bts_model model_nanobts = {
+struct gsm_bts_model bts_model_nanobts = {
 	.type = GSM_BTS_TYPE_NANOBTS,
 	.name = "nanobts",
 	.start = bts_model_nanobts_start,
@@ -438,7 +438,7 @@
 }
 
 /* Callback function to be called every time we receive a signal from NM */
-static int nm_sig_cb(unsigned int subsys, unsigned int signal,
+int bts_ipa_nm_sig_cb(unsigned int subsys, unsigned int signal,
 		     void *handler_data, void *signal_data)
 {
 	if (subsys != SS_NM)
@@ -460,13 +460,14 @@
 
 static int bts_model_nanobts_start(struct gsm_network *net)
 {
-	model_nanobts.features.data = &model_nanobts._features_data[0];
-	model_nanobts.features.data_len = sizeof(model_nanobts._features_data);
+	bts_model_nanobts.features.data = &bts_model_nanobts._features_data[0];
+	bts_model_nanobts.features.data_len =
+				sizeof(bts_model_nanobts._features_data);
 
-	gsm_btsmodel_set_feature(&model_nanobts, BTS_FEAT_GPRS);
-	gsm_btsmodel_set_feature(&model_nanobts, BTS_FEAT_EGPRS);
+	gsm_btsmodel_set_feature(&bts_model_nanobts, BTS_FEAT_GPRS);
+	gsm_btsmodel_set_feature(&bts_model_nanobts, BTS_FEAT_EGPRS);
 
-	osmo_signal_register_handler(SS_NM, nm_sig_cb, NULL);
+	osmo_signal_register_handler(SS_NM, bts_ipa_nm_sig_cb, NULL);
 
 	ipaccess_gsmnet = net;
 	return 0;
@@ -474,7 +475,7 @@
 
 int bts_model_nanobts_init(void)
 {
-	return gsm_bts_model_register(&model_nanobts);
+	return gsm_bts_model_register(&bts_model_nanobts);
 }
 
 #define OML_UP         0x0001
diff --git a/openbsc/src/libbsc/bts_sysmobts.c b/openbsc/src/libbsc/bts_sysmobts.c
new file mode 100644
index 0000000..9479206
--- /dev/null
+++ b/openbsc/src/libbsc/bts_sysmobts.c
@@ -0,0 +1,71 @@
+/* sysmocom sysmoBTS specific code */
+
+/* (C) 2010-2012 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 <arpa/inet.h>
+
+#include <osmocom/gsm/tlv.h>
+
+#include <openbsc/gsm_data.h>
+#include <openbsc/signal.h>
+#include <openbsc/abis_nm.h>
+#include <osmocom/abis/e1_input.h>
+#include <osmocom/gsm/tlv.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/talloc.h>
+#include <openbsc/gsm_data.h>
+#include <openbsc/abis_nm.h>
+#include <openbsc/abis_rsl.h>
+#include <openbsc/debug.h>
+#include <osmocom/abis/subchan_demux.h>
+#include <osmocom/abis/ipaccess.h>
+#include <osmocom/core/logging.h>
+
+extern int bts_ipa_nm_sig_cb(unsigned int subsys, unsigned int signal,
+			     void *handler_data, void *signal_data);
+
+extern struct gsm_bts_model bts_model_nanobts;
+
+static struct gsm_bts_model model_sysmobts;
+
+static int bts_model_sysmobts_start(struct gsm_network *net)
+{
+	model_sysmobts.features.data = &model_sysmobts._features_data[0];
+	model_sysmobts.features.data_len =
+				sizeof(model_sysmobts._features_data);
+
+	gsm_btsmodel_set_feature(&model_sysmobts, BTS_FEAT_GPRS);
+	gsm_btsmodel_set_feature(&model_sysmobts, BTS_FEAT_EGPRS);
+
+	osmo_signal_register_handler(SS_NM, bts_ipa_nm_sig_cb, NULL);
+
+	return 0;
+}
+
+int bts_model_sysmobts_init(void)
+{
+	memcpy(&model_sysmobts, &bts_model_nanobts, sizeof(model_sysmobts));
+
+	model_sysmobts.name = "sysmobts";
+	model_sysmobts.start = bts_model_sysmobts_start;
+	model_sysmobts.type = GSM_BTS_TYPE_OSMO_SYSMO;
+
+	return gsm_bts_model_register(&model_sysmobts);
+}
diff --git a/openbsc/src/libbsc/e1_config.c b/openbsc/src/libbsc/e1_config.c
index cda1318..d3dff48 100644
--- a/openbsc/src/libbsc/e1_config.c
+++ b/openbsc/src/libbsc/e1_config.c
@@ -185,6 +185,7 @@
 
 	/* skip signal link initialization, this is done later for these BTS. */
 	if (bts->type == GSM_BTS_TYPE_NANOBTS ||
+	    bts->type == GSM_BTS_TYPE_OSMO_SYSMO ||
 	    bts->type == GSM_BTS_TYPE_HSL_FEMTO)
 		return e1inp_line_update(line);
 
diff --git a/openbsc/src/libbsc/system_information.c b/openbsc/src/libbsc/system_information.c
index 360d229..1c16ec0 100644
--- a/openbsc/src/libbsc/system_information.c
+++ b/openbsc/src/libbsc/system_information.c
@@ -470,6 +470,7 @@
 	/* ip.access nanoBTS needs l2_plen!! */
 	switch (bts->type) {
 	case GSM_BTS_TYPE_NANOBTS:
+	case GSM_BTS_TYPE_OSMO_SYSMO:
 	case GSM_BTS_TYPE_HSL_FEMTO:
 		*output++ = (l2_plen << 2) | 1;
 		l2_plen++;
@@ -505,6 +506,7 @@
 	/* ip.access nanoBTS needs l2_plen!! */
 	switch (bts->type) {
 	case GSM_BTS_TYPE_NANOBTS:
+	case GSM_BTS_TYPE_OSMO_SYSMO:
 	case GSM_BTS_TYPE_HSL_FEMTO:
 		*output++ = (l2_plen << 2) | 1;
 		l2_plen++;
@@ -549,6 +551,7 @@
 	/* ip.access nanoBTS needs l2_plen!! */
 	switch (bts->type) {
 	case GSM_BTS_TYPE_NANOBTS:
+	case GSM_BTS_TYPE_OSMO_SYSMO:
 	case GSM_BTS_TYPE_HSL_FEMTO:
 		*output++ = (l2_plen << 2) | 1;
 		l2_plen++;
@@ -585,6 +588,7 @@
 	/* ip.access nanoBTS needs l2_plen!! */
 	switch (bts->type) {
 	case GSM_BTS_TYPE_NANOBTS:
+	case GSM_BTS_TYPE_OSMO_SYSMO:
 	case GSM_BTS_TYPE_HSL_FEMTO:
 		*output++ = (l2_plen << 2) | 1;
 		l2_plen++;
diff --git a/openbsc/src/libcommon/gsm_data.c b/openbsc/src/libcommon/gsm_data.c
index a235c9d..5c58bf3 100644
--- a/openbsc/src/libcommon/gsm_data.c
+++ b/openbsc/src/libcommon/gsm_data.c
@@ -189,6 +189,7 @@
 	{ GSM_BTS_TYPE_RBS2000,	"rbs2000" },
 	{ GSM_BTS_TYPE_HSL_FEMTO, "hsl_femto" },
 	{ GSM_BTS_TYPE_NOKIA_SITE, "nokia_site" },
+	{ GSM_BTS_TYPE_OSMO_SYSMO, "sysmobts" },
 	{ 0,			NULL }
 };
 
@@ -338,6 +339,7 @@
 	case GSM_BTS_TYPE_HSL_FEMTO:
 		bts->c0->rsl_tei = 0;
 	case GSM_BTS_TYPE_NANOBTS:
+	case GSM_BTS_TYPE_OSMO_SYSMO:
 		/* Set the default OML Stream ID to 0xff */
 		bts->oml_tei = 0xff;
 		bts->c0->nominal_power = 23;
diff --git a/openbsc/src/libmsc/gsm_04_08.c b/openbsc/src/libmsc/gsm_04_08.c
index e596b21..c6a5436 100644
--- a/openbsc/src/libmsc/gsm_04_08.c
+++ b/openbsc/src/libmsc/gsm_04_08.c
@@ -1500,6 +1500,7 @@
 	// todo: map between different bts types
 	switch (bts->type) {
 	case GSM_BTS_TYPE_NANOBTS:
+	case GSM_BTS_TYPE_OSMO_SYSMO:
 		if (!ipacc_rtp_direct) {
 			/* connect the TCH's to our RTP proxy */
 			rc = rsl_ipacc_mdcx_to_rtpsock(lchan);
@@ -1571,6 +1572,7 @@
 
 	switch (bts->type) {
 	case GSM_BTS_TYPE_NANOBTS:
+	case GSM_BTS_TYPE_OSMO_SYSMO:
 		if (ipacc_rtp_direct) {
 			LOGP(DCC, LOGL_ERROR, "Error: RTP proxy is disabled\n");
 			return -EINVAL;
@@ -2879,6 +2881,7 @@
 		bts = trans->conn->lchan->ts->trx->bts;
 		switch (bts->type) {
 		case GSM_BTS_TYPE_NANOBTS:
+		case GSM_BTS_TYPE_OSMO_SYSMO:
 			if (!trans->conn->lchan->abis_ip.rtp_socket) {
 				DEBUGP(DMNCC, "TCH frame to lchan without RTP connection\n");
 				return 0;