summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-06-06 23:31:06 +0800
committerHarald Welte <laforge@gnumonks.org>2012-07-12 15:10:36 +0200
commit68de8ae0a159ee96914032733164c9fbf90d7253 (patch)
tree49e75b0efc368e88036a3cef2525c5455a433d0c
parent1cacf5fac318847de484e722e5965c1dc0d4e732 (diff)
experinmental and incomplete hack trying to build separate MSC
-rw-r--r--openbsc/configure.ac1
-rw-r--r--openbsc/src/Makefile.am2
-rw-r--r--openbsc/src/libbsc/gsm_04_08_utils.c224
-rw-r--r--openbsc/src/libcommon/Makefile.am2
-rw-r--r--openbsc/src/libcommon/gsm_04_08_utils.c262
-rw-r--r--openbsc/src/osmo-mss/Makefile.am15
-rw-r--r--openbsc/src/osmo-mss/mss_hack.c307
-rw-r--r--openbsc/src/osmo-mss/stubs.c104
8 files changed, 691 insertions, 226 deletions
diff --git a/openbsc/configure.ac b/openbsc/configure.ac
index 76a4835..e61cc18 100644
--- a/openbsc/configure.ac
+++ b/openbsc/configure.ac
@@ -124,6 +124,7 @@ AC_OUTPUT(
src/libmgcp/Makefile
src/libcommon/Makefile
src/osmo-nitb/Makefile
+ src/osmo-mss/Makefile
src/osmo-bsc/Makefile
src/osmo-bsc_nat/Makefile
src/osmo-bsc_mgcp/Makefile
diff --git a/openbsc/src/Makefile.am b/openbsc/src/Makefile.am
index 852c442..7037e96 100644
--- a/openbsc/src/Makefile.am
+++ b/openbsc/src/Makefile.am
@@ -2,7 +2,7 @@ INCLUDES = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)
AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(COVERAGE_CFLAGS)
AM_LDFLAGS = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(COVERAGE_LDFLAGS)
-SUBDIRS = libcommon libmgcp libbsc libmsc libtrau libctrl osmo-nitb osmo-bsc_mgcp utils ipaccess gprs
+SUBDIRS = libcommon libmgcp libbsc libmsc libtrau libctrl osmo-nitb osmo-mss osmo-bsc_mgcp utils ipaccess gprs
# Conditional modules
if BUILD_NAT
diff --git a/openbsc/src/libbsc/gsm_04_08_utils.c b/openbsc/src/libbsc/gsm_04_08_utils.c
index 968e62e..fc5232e 100644
--- a/openbsc/src/libbsc/gsm_04_08_utils.c
+++ b/openbsc/src/libbsc/gsm_04_08_utils.c
@@ -37,10 +37,6 @@
#include <openbsc/paging.h>
#include <openbsc/signal.h>
-/* should ip.access BTS use direct RTP streams between each other (1),
- * or should OpenBSC always act as RTP relay/proxy in between (0) ? */
-int ipacc_rtp_direct = 1;
-
static int gsm48_sendmsg(struct msgb *msg)
{
if (msg->lchan)
@@ -50,169 +46,6 @@ static int gsm48_sendmsg(struct msgb *msg)
return rsl_data_request(msg, 0);
}
-/* Section 9.1.8 / Table 9.9 */
-struct chreq {
- uint8_t val;
- uint8_t mask;
- enum chreq_type type;
-};
-
-/* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */
-static const struct chreq chreq_type_neci1[] = {
- { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
- { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F },
- { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H },
- { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL },
- { 0xe0, 0xe0, CHREQ_T_TCH_F },
- { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H },
- { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
- { 0x00, 0xf0, CHREQ_T_LOCATION_UPD },
- { 0x10, 0xf0, CHREQ_T_SDCCH },
- { 0x80, 0xe0, CHREQ_T_PAG_R_ANY_NECI1 },
- { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
- { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
- { 0x67, 0xff, CHREQ_T_LMU },
- { 0x60, 0xf9, CHREQ_T_RESERVED_SDCCH },
- { 0x61, 0xfb, CHREQ_T_RESERVED_SDCCH },
- { 0x63, 0xff, CHREQ_T_RESERVED_SDCCH },
- { 0x7f, 0xff, CHREQ_T_RESERVED_IGNORE },
-};
-
-/* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */
-static const struct chreq chreq_type_neci0[] = {
- { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
- { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H },
- { 0xe0, 0xe0, CHREQ_T_TCH_F },
- { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
- { 0x00, 0xe0, CHREQ_T_LOCATION_UPD },
- { 0x80, 0xe0, CHREQ_T_PAG_R_ANY_NECI0 },
- { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
- { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
- { 0x67, 0xff, CHREQ_T_LMU },
- { 0x60, 0xf9, CHREQ_T_RESERVED_SDCCH },
- { 0x61, 0xfb, CHREQ_T_RESERVED_SDCCH },
- { 0x63, 0xff, CHREQ_T_RESERVED_SDCCH },
- { 0x7f, 0xff, CHREQ_T_RESERVED_IGNORE },
-};
-
-static const enum gsm_chan_t ctype_by_chreq[] = {
- [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F,
- [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F,
- [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H,
- [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H,
- [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH,
- [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F,
- [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H,
- [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H,
- [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH,
- [CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_SDCCH,
- [CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_SDCCH,
- [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F,
- [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F,
- [CHREQ_T_LMU] = GSM_LCHAN_SDCCH,
- [CHREQ_T_RESERVED_SDCCH] = GSM_LCHAN_SDCCH,
- [CHREQ_T_RESERVED_IGNORE] = GSM_LCHAN_UNKNOWN,
-};
-
-static const enum gsm_chreq_reason_t reason_by_chreq[] = {
- [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG,
- [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL,
- [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL,
- [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL,
- [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER,
- [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER,
- [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_CALL,
- [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER,
- [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD,
- [CHREQ_T_PAG_R_ANY_NECI1] = GSM_CHREQ_REASON_PAG,
- [CHREQ_T_PAG_R_ANY_NECI0] = GSM_CHREQ_REASON_PAG,
- [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG,
- [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG,
- [CHREQ_T_LMU] = GSM_CHREQ_REASON_OTHER,
- [CHREQ_T_RESERVED_SDCCH] = GSM_CHREQ_REASON_OTHER,
- [CHREQ_T_RESERVED_IGNORE] = GSM_CHREQ_REASON_OTHER,
-};
-
-/* verify that the two tables match */
-osmo_static_assert(sizeof(ctype_by_chreq) ==
- sizeof(((struct gsm_network *) NULL)->ctype_by_chreq), assert_size);
-
-/*
- * Update channel types for request based on policy. E.g. in the
- * case of a TCH/H network/bsc use TCH/H for the emergency calls,
- * for early assignment assign a SDCCH and some other options.
- */
-void gsm_net_update_ctype(struct gsm_network *network)
-{
- /* copy over the data */
- memcpy(network->ctype_by_chreq, ctype_by_chreq, sizeof(ctype_by_chreq));
-
- /*
- * Use TCH/H for emergency calls when this cell allows TCH/H. Maybe it
- * is better to iterate over the BTS/TRX and check if no TCH/F is available
- * and then set it to TCH/H.
- */
- if (network->neci)
- network->ctype_by_chreq[CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_H;
-
- if (network->pag_any_tch) {
- if (network->neci) {
- network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_TCH_H;
- network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_TCH_H;
- } else {
- network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_TCH_F;
- network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_TCH_F;
- }
- }
-}
-
-enum gsm_chan_t get_ctype_by_chreq(struct gsm_network *network, uint8_t ra)
-{
- int i;
- int length;
- const struct chreq *chreq;
-
- if (network->neci) {
- chreq = chreq_type_neci1;
- length = ARRAY_SIZE(chreq_type_neci1);
- } else {
- chreq = chreq_type_neci0;
- length = ARRAY_SIZE(chreq_type_neci0);
- }
-
-
- for (i = 0; i < length; i++) {
- const struct chreq *chr = &chreq[i];
- if ((ra & chr->mask) == chr->val)
- return network->ctype_by_chreq[chr->type];
- }
- LOGP(DRR, LOGL_ERROR, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra);
- return GSM_LCHAN_SDCCH;
-}
-
-int get_reason_by_chreq(uint8_t ra, int neci)
-{
- int i;
- int length;
- const struct chreq *chreq;
-
- if (neci) {
- chreq = chreq_type_neci1;
- length = ARRAY_SIZE(chreq_type_neci1);
- } else {
- chreq = chreq_type_neci0;
- length = ARRAY_SIZE(chreq_type_neci0);
- }
-
- for (i = 0; i < length; i++) {
- const struct chreq *chr = &chreq[i];
- if ((ra & chr->mask) == chr->val)
- return reason_by_chreq[chr->type];
- }
- LOGP(DRR, LOGL_ERROR, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra);
- return GSM_CHREQ_REASON_OTHER;
-}
-
/* 7.1.7 and 9.1.7: RR CHANnel RELease */
int gsm48_send_rr_release(struct gsm_lchan *lchan)
{
@@ -254,30 +87,6 @@ int send_siemens_mrpci(struct gsm_lchan *lchan,
return rsl_siemens_mrpci(lchan, &mrpci);
}
-int gsm48_extract_mi(uint8_t *classmark2_lv, int length, char *mi_string, uint8_t *mi_type)
-{
- /* Check the size for the classmark */
- if (length < 1 + *classmark2_lv)
- return -1;
-
- uint8_t *mi_lv = classmark2_lv + *classmark2_lv + 1;
- if (length < 2 + *classmark2_lv + mi_lv[0])
- return -2;
-
- *mi_type = mi_lv[1] & GSM_MI_TYPE_MASK;
- return gsm48_mi_to_string(mi_string, GSM48_MI_SIZE, mi_lv+1, *mi_lv);
-}
-
-int gsm48_paging_extract_mi(struct gsm48_pag_resp *resp, int length,
- char *mi_string, uint8_t *mi_type)
-{
- static const uint32_t classmark_offset =
- offsetof(struct gsm48_pag_resp, classmark2);
- uint8_t *classmark2_lv = (uint8_t *) &resp->classmark2;
- return gsm48_extract_mi(classmark2_lv, length - classmark_offset,
- mi_string, mi_type);
-}
-
int gsm48_handle_paging_resp(struct gsm_subscriber_connection *conn,
struct msgb *msg, struct gsm_subscriber *subscr)
{
@@ -620,36 +429,3 @@ int gsm48_parse_meas_rep(struct gsm_meas_rep *rep, struct msgb *msg)
return 0;
}
-
-struct msgb *gsm48_create_mm_serv_rej(enum gsm48_reject_value value)
-{
- struct msgb *msg;
- struct gsm48_hdr *gh;
-
- msg = gsm48_msgb_alloc();
- if (!msg)
- return NULL;
-
- gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
- gh->proto_discr = GSM48_PDISC_MM;
- gh->msg_type = GSM48_MT_MM_CM_SERV_REJ;
- gh->data[0] = value;
-
- return msg;
-}
-
-struct msgb *gsm48_create_loc_upd_rej(uint8_t cause)
-{
- struct gsm48_hdr *gh;
- struct msgb *msg;
-
- msg = gsm48_msgb_alloc();
- if (!msg)
- return NULL;
-
- gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
- gh->proto_discr = GSM48_PDISC_MM;
- gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT;
- gh->data[0] = cause;
- return msg;
-}
diff --git a/openbsc/src/libcommon/Makefile.am b/openbsc/src/libcommon/Makefile.am
index bcdf133..98538fe 100644
--- a/openbsc/src/libcommon/Makefile.am
+++ b/openbsc/src/libcommon/Makefile.am
@@ -4,4 +4,4 @@ AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) \
noinst_LIBRARIES = libcommon.a
-libcommon_a_SOURCES = bsc_version.c common_vty.c debug.c gsm_data.c gsm_data_shared.c socket.c talloc_ctx.c
+libcommon_a_SOURCES = bsc_version.c common_vty.c debug.c gsm_data.c gsm_data_shared.c socket.c talloc_ctx.c gsm_04_08_utils.c
diff --git a/openbsc/src/libcommon/gsm_04_08_utils.c b/openbsc/src/libcommon/gsm_04_08_utils.c
new file mode 100644
index 0000000..1c12462
--- /dev/null
+++ b/openbsc/src/libcommon/gsm_04_08_utils.c
@@ -0,0 +1,262 @@
+/* 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
+ * utility functions
+ */
+
+/* (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/>.
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <netinet/in.h>
+
+#include <osmocom/core/msgb.h>
+#include <osmocom/gsm/gsm48.h>
+
+#include <openbsc/abis_rsl.h>
+#include <openbsc/debug.h>
+#include <openbsc/gsm_04_08.h>
+#include <openbsc/transaction.h>
+#include <openbsc/paging.h>
+#include <openbsc/signal.h>
+
+/* should ip.access BTS use direct RTP streams between each other (1),
+ * or should OpenBSC always act as RTP relay/proxy in between (0) ? */
+int ipacc_rtp_direct = 1;
+
+/* Section 9.1.8 / Table 9.9 */
+struct chreq {
+ uint8_t val;
+ uint8_t mask;
+ enum chreq_type type;
+};
+
+/* If SYSTEM INFORMATION TYPE 4 NECI bit == 1 */
+static const struct chreq chreq_type_neci1[] = {
+ { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
+ { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_F },
+ { 0x68, 0xfc, CHREQ_T_CALL_REEST_TCH_H },
+ { 0x6c, 0xfc, CHREQ_T_CALL_REEST_TCH_H_DBL },
+ { 0xe0, 0xe0, CHREQ_T_TCH_F },
+ { 0x40, 0xf0, CHREQ_T_VOICE_CALL_TCH_H },
+ { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
+ { 0x00, 0xf0, CHREQ_T_LOCATION_UPD },
+ { 0x10, 0xf0, CHREQ_T_SDCCH },
+ { 0x80, 0xe0, CHREQ_T_PAG_R_ANY_NECI1 },
+ { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
+ { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
+ { 0x67, 0xff, CHREQ_T_LMU },
+ { 0x60, 0xf9, CHREQ_T_RESERVED_SDCCH },
+ { 0x61, 0xfb, CHREQ_T_RESERVED_SDCCH },
+ { 0x63, 0xff, CHREQ_T_RESERVED_SDCCH },
+ { 0x7f, 0xff, CHREQ_T_RESERVED_IGNORE },
+};
+
+/* If SYSTEM INFORMATION TYPE 4 NECI bit == 0 */
+static const struct chreq chreq_type_neci0[] = {
+ { 0xa0, 0xe0, CHREQ_T_EMERG_CALL },
+ { 0xc0, 0xe0, CHREQ_T_CALL_REEST_TCH_H },
+ { 0xe0, 0xe0, CHREQ_T_TCH_F },
+ { 0x50, 0xf0, CHREQ_T_DATA_CALL_TCH_H },
+ { 0x00, 0xe0, CHREQ_T_LOCATION_UPD },
+ { 0x80, 0xe0, CHREQ_T_PAG_R_ANY_NECI0 },
+ { 0x20, 0xf0, CHREQ_T_PAG_R_TCH_F },
+ { 0x30, 0xf0, CHREQ_T_PAG_R_TCH_FH },
+ { 0x67, 0xff, CHREQ_T_LMU },
+ { 0x60, 0xf9, CHREQ_T_RESERVED_SDCCH },
+ { 0x61, 0xfb, CHREQ_T_RESERVED_SDCCH },
+ { 0x63, 0xff, CHREQ_T_RESERVED_SDCCH },
+ { 0x7f, 0xff, CHREQ_T_RESERVED_IGNORE },
+};
+
+static const enum gsm_chan_t ctype_by_chreq[] = {
+ [CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_F,
+ [CHREQ_T_CALL_REEST_TCH_F] = GSM_LCHAN_TCH_F,
+ [CHREQ_T_CALL_REEST_TCH_H] = GSM_LCHAN_TCH_H,
+ [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_LCHAN_TCH_H,
+ [CHREQ_T_SDCCH] = GSM_LCHAN_SDCCH,
+ [CHREQ_T_TCH_F] = GSM_LCHAN_TCH_F,
+ [CHREQ_T_VOICE_CALL_TCH_H] = GSM_LCHAN_TCH_H,
+ [CHREQ_T_DATA_CALL_TCH_H] = GSM_LCHAN_TCH_H,
+ [CHREQ_T_LOCATION_UPD] = GSM_LCHAN_SDCCH,
+ [CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_SDCCH,
+ [CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_SDCCH,
+ [CHREQ_T_PAG_R_TCH_F] = GSM_LCHAN_TCH_F,
+ [CHREQ_T_PAG_R_TCH_FH] = GSM_LCHAN_TCH_F,
+ [CHREQ_T_LMU] = GSM_LCHAN_SDCCH,
+ [CHREQ_T_RESERVED_SDCCH] = GSM_LCHAN_SDCCH,
+ [CHREQ_T_RESERVED_IGNORE] = GSM_LCHAN_UNKNOWN,
+};
+
+static const enum gsm_chreq_reason_t reason_by_chreq[] = {
+ [CHREQ_T_EMERG_CALL] = GSM_CHREQ_REASON_EMERG,
+ [CHREQ_T_CALL_REEST_TCH_F] = GSM_CHREQ_REASON_CALL,
+ [CHREQ_T_CALL_REEST_TCH_H] = GSM_CHREQ_REASON_CALL,
+ [CHREQ_T_CALL_REEST_TCH_H_DBL] = GSM_CHREQ_REASON_CALL,
+ [CHREQ_T_SDCCH] = GSM_CHREQ_REASON_OTHER,
+ [CHREQ_T_TCH_F] = GSM_CHREQ_REASON_OTHER,
+ [CHREQ_T_VOICE_CALL_TCH_H] = GSM_CHREQ_REASON_CALL,
+ [CHREQ_T_DATA_CALL_TCH_H] = GSM_CHREQ_REASON_OTHER,
+ [CHREQ_T_LOCATION_UPD] = GSM_CHREQ_REASON_LOCATION_UPD,
+ [CHREQ_T_PAG_R_ANY_NECI1] = GSM_CHREQ_REASON_PAG,
+ [CHREQ_T_PAG_R_ANY_NECI0] = GSM_CHREQ_REASON_PAG,
+ [CHREQ_T_PAG_R_TCH_F] = GSM_CHREQ_REASON_PAG,
+ [CHREQ_T_PAG_R_TCH_FH] = GSM_CHREQ_REASON_PAG,
+ [CHREQ_T_LMU] = GSM_CHREQ_REASON_OTHER,
+ [CHREQ_T_RESERVED_SDCCH] = GSM_CHREQ_REASON_OTHER,
+ [CHREQ_T_RESERVED_IGNORE] = GSM_CHREQ_REASON_OTHER,
+};
+
+/* verify that the two tables match */
+osmo_static_assert(sizeof(ctype_by_chreq) ==
+ sizeof(((struct gsm_network *) NULL)->ctype_by_chreq), assert_size);
+
+/*
+ * Update channel types for request based on policy. E.g. in the
+ * case of a TCH/H network/bsc use TCH/H for the emergency calls,
+ * for early assignment assign a SDCCH and some other options.
+ */
+void gsm_net_update_ctype(struct gsm_network *network)
+{
+ /* copy over the data */
+ memcpy(network->ctype_by_chreq, ctype_by_chreq, sizeof(ctype_by_chreq));
+
+ /*
+ * Use TCH/H for emergency calls when this cell allows TCH/H. Maybe it
+ * is better to iterate over the BTS/TRX and check if no TCH/F is available
+ * and then set it to TCH/H.
+ */
+ if (network->neci)
+ network->ctype_by_chreq[CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_H;
+
+ if (network->pag_any_tch) {
+ if (network->neci) {
+ network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_TCH_H;
+ network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_TCH_H;
+ } else {
+ network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_TCH_F;
+ network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_TCH_F;
+ }
+ }
+}
+
+enum gsm_chan_t get_ctype_by_chreq(struct gsm_network *network, uint8_t ra)
+{
+ int i;
+ int length;
+ const struct chreq *chreq;
+
+ if (network->neci) {
+ chreq = chreq_type_neci1;
+ length = ARRAY_SIZE(chreq_type_neci1);
+ } else {
+ chreq = chreq_type_neci0;
+ length = ARRAY_SIZE(chreq_type_neci0);
+ }
+
+
+ for (i = 0; i < length; i++) {
+ const struct chreq *chr = &chreq[i];
+ if ((ra & chr->mask) == chr->val)
+ return network->ctype_by_chreq[chr->type];
+ }
+ LOGP(DRR, LOGL_ERROR, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra);
+ return GSM_LCHAN_SDCCH;
+}
+
+int get_reason_by_chreq(uint8_t ra, int neci)
+{
+ int i;
+ int length;
+ const struct chreq *chreq;
+
+ if (neci) {
+ chreq = chreq_type_neci1;
+ length = ARRAY_SIZE(chreq_type_neci1);
+ } else {
+ chreq = chreq_type_neci0;
+ length = ARRAY_SIZE(chreq_type_neci0);
+ }
+
+ for (i = 0; i < length; i++) {
+ const struct chreq *chr = &chreq[i];
+ if ((ra & chr->mask) == chr->val)
+ return reason_by_chreq[chr->type];
+ }
+ LOGP(DRR, LOGL_ERROR, "Unknown CHANNEL REQUEST REASON 0x%02x\n", ra);
+ return GSM_CHREQ_REASON_OTHER;
+}
+
+int gsm48_extract_mi(uint8_t *classmark2_lv, int length, char *mi_string, uint8_t *mi_type)
+{
+ /* Check the size for the classmark */
+ if (length < 1 + *classmark2_lv)
+ return -1;
+
+ uint8_t *mi_lv = classmark2_lv + *classmark2_lv + 1;
+ if (length < 2 + *classmark2_lv + mi_lv[0])
+ return -2;
+
+ *mi_type = mi_lv[1] & GSM_MI_TYPE_MASK;
+ return gsm48_mi_to_string(mi_string, GSM48_MI_SIZE, mi_lv+1, *mi_lv);
+}
+
+int gsm48_paging_extract_mi(struct gsm48_pag_resp *resp, int length,
+ char *mi_string, uint8_t *mi_type)
+{
+ static const uint32_t classmark_offset =
+ offsetof(struct gsm48_pag_resp, classmark2);
+ uint8_t *classmark2_lv = (uint8_t *) &resp->classmark2;
+ return gsm48_extract_mi(classmark2_lv, length - classmark_offset,
+ mi_string, mi_type);
+}
+
+struct msgb *gsm48_create_loc_upd_rej(uint8_t cause)
+{
+ struct gsm48_hdr *gh;
+ struct msgb *msg;
+
+ msg = gsm48_msgb_alloc();
+ if (!msg)
+ return NULL;
+
+ gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
+ gh->proto_discr = GSM48_PDISC_MM;
+ gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT;
+ gh->data[0] = cause;
+ return msg;
+}
+
+struct msgb *gsm48_create_mm_serv_rej(enum gsm48_reject_value value)
+{
+ struct msgb *msg;
+ struct gsm48_hdr *gh;
+
+ msg = gsm48_msgb_alloc();
+ if (!msg)
+ return NULL;
+
+ gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
+ gh->proto_discr = GSM48_PDISC_MM;
+ gh->msg_type = GSM48_MT_MM_CM_SERV_REJ;
+ gh->data[0] = value;
+
+ return msg;
+}
diff --git a/openbsc/src/osmo-mss/Makefile.am b/openbsc/src/osmo-mss/Makefile.am
new file mode 100644
index 0000000..450741d
--- /dev/null
+++ b/openbsc/src/osmo-mss/Makefile.am
@@ -0,0 +1,15 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)
+AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOABIS_CFLAGS) $(COVERAGE_CFLAGS)
+AM_LDFLAGS = $(COVERAGE_LDFLAGS)
+
+bin_PROGRAMS = osmo-mss
+
+osmo_mss_SOURCES = mss_hack.c stubs.c
+osmo_mss_LDADD = \
+ $(top_builddir)/src/libbsc/gsm_subscriber_base.o \
+ $(top_builddir)/src/libmsc/libmsc.a \
+ $(top_builddir)/src/libtrau/libtrau.a \
+ $(top_builddir)/src/libctrl/libctrl.a \
+ $(top_builddir)/src/libcommon/libcommon.a \
+ -ldbi -ldl $(LIBCRYPT) $(LIBOSMOGSM_LIBS) \
+ $(LIBOSMOVTY_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOCORE_LIBS)
diff --git a/openbsc/src/osmo-mss/mss_hack.c b/openbsc/src/osmo-mss/mss_hack.c
new file mode 100644
index 0000000..e26e89b
--- /dev/null
+++ b/openbsc/src/osmo-mss/mss_hack.c
@@ -0,0 +1,307 @@
+/* A hackish minimal MSC+HLR implementation */
+
+/* (C) 2008-2012 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2009-2012 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/>.
+ *
+ */
+
+#include <unistd.h>
+#include <time.h>
+#include <errno.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#define _GNU_SOURCE
+#include <getopt.h>
+
+#include <openbsc/db.h>
+#include <osmocom/core/application.h>
+#include <osmocom/core/select.h>
+#include <openbsc/debug.h>
+#include <osmocom/abis/abis.h>
+#include <osmocom/abis/e1_input.h>
+#include <osmocom/core/talloc.h>
+#include <openbsc/signal.h>
+#include <openbsc/osmo_msc.h>
+#include <openbsc/sms_queue.h>
+#include <openbsc/vty.h>
+#include <openbsc/bss.h>
+#include <openbsc/mncc.h>
+#include <openbsc/token_auth.h>
+#include <openbsc/handover_decision.h>
+#include <openbsc/rrlp.h>
+#include <openbsc/control_if.h>
+#include <openbsc/osmo_bsc_rf.h>
+
+#include "../../bscconfig.h"
+
+/* MCC and MNC for the Location Area Identifier */
+struct gsm_network *bsc_gsmnet = 0;
+static struct osmo_bsc_rf *rf_ctrl;
+static const char *database_name = "hlr.sqlite3";
+static const char *config_file = "openbsc.cfg";
+static const char *rf_ctrl_name = NULL;
+extern const char *openbsc_copyright;
+static int daemonize = 0;
+static int use_mncc_sock = 0;
+static int use_db_counter = 1;
+
+/* timer to store statistics */
+#define DB_SYNC_INTERVAL 60, 0
+static struct osmo_timer_list db_sync_timer;
+
+static void create_pcap_file(char *file)
+{
+ mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
+ int fd = open(file, O_WRONLY|O_TRUNC|O_CREAT, mode);
+
+ if (fd < 0) {
+ perror("Failed to open file for pcap");
+ return;
+ }
+
+ e1_set_pcap_fd(fd);
+}
+
+static void print_usage()
+{
+ printf("Usage: bsc_hack\n");
+}
+
+static void print_help()
+{
+ printf(" Some useful help...\n");
+ printf(" -h --help this text\n");
+ printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
+ printf(" -D --daemonize Fork the process into a background daemon\n");
+ printf(" -c --config-file filename The config file to use.\n");
+ printf(" -s --disable-color\n");
+ printf(" -l --database db-name The database to use\n");
+ printf(" -a --authorize-everyone. Authorize every new subscriber. Dangerous!.\n");
+ printf(" -p --pcap file The filename of the pcap file\n");
+ printf(" -T --timestamp Prefix every log line with a timestamp\n");
+ printf(" -V --version. Print the version of OpenBSC.\n");
+ printf(" -e --log-level number. Set a global loglevel.\n");
+ printf(" -m --mncc-sock Disable built-in MNCC handler and offer socket\n");
+ printf(" -C --no-dbcounter Disable regular syncing of counters to database\n");
+ printf(" -r --rf-ctl NAME. A unix domain socket to listen for cmds.\n");
+}
+
+static void handle_options(int argc, char **argv)
+{
+ while (1) {
+ int option_index = 0, c;
+ static struct option long_options[] = {
+ {"help", 0, 0, 'h'},
+ {"debug", 1, 0, 'd'},
+ {"daemonize", 0, 0, 'D'},
+ {"config-file", 1, 0, 'c'},
+ {"disable-color", 0, 0, 's'},
+ {"database", 1, 0, 'l'},
+ {"authorize-everyone", 0, 0, 'a'},
+ {"pcap", 1, 0, 'p'},
+ {"timestamp", 0, 0, 'T'},
+ {"version", 0, 0, 'V' },
+ {"rtp-proxy", 0, 0, 'P'},
+ {"log-level", 1, 0, 'e'},
+ {"mncc-sock", 0, 0, 'm'},
+ {"no-dbcounter", 0, 0, 'C'},
+ {"rf-ctl", 1, 0, 'r'},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long(argc, argv, "hd:Dsl:ar:p:TPVc:e:mCr:",
+ long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ print_usage();
+ print_help();
+ exit(0);
+ case 's':
+ log_set_use_color(osmo_stderr_target, 0);
+ break;
+ case 'd':
+ log_parse_category_mask(osmo_stderr_target, optarg);
+ break;
+ case 'D':
+ daemonize = 1;
+ break;
+ case 'l':
+ database_name = strdup(optarg);
+ break;
+ case 'c':
+ config_file = strdup(optarg);
+ break;
+ case 'p':
+ create_pcap_file(optarg);
+ break;
+ case 'T':
+ log_set_print_timestamp(osmo_stderr_target, 1);
+ break;
+ case 'e':
+ log_set_log_level(osmo_stderr_target, atoi(optarg));
+ break;
+ case 'm':
+ use_mncc_sock = 1;
+ break;
+ case 'C':
+ use_db_counter = 0;
+ break;
+ case 'V':
+ print_version(1);
+ exit(0);
+ break;
+ case 'r':
+ rf_ctrl_name = optarg;
+ break;
+ default:
+ /* ignore */
+ break;
+ }
+ }
+}
+
+extern void *tall_vty_ctx;
+static void signal_handler(int signal)
+{
+ fprintf(stdout, "signal %u received\n", signal);
+
+ switch (signal) {
+ case SIGINT:
+ bsc_shutdown_net(bsc_gsmnet);
+ osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL);
+ sleep(3);
+ exit(0);
+ break;
+ case SIGABRT:
+ /* in case of abort, we want to obtain a talloc report
+ * and then return to the caller, who will abort the process */
+ case SIGUSR1:
+ talloc_report(tall_vty_ctx, stderr);
+ talloc_report_full(tall_bsc_ctx, stderr);
+ break;
+ case SIGUSR2:
+ talloc_report_full(tall_vty_ctx, stderr);
+ break;
+ default:
+ break;
+ }
+}
+
+/* timer handling */
+static int _db_store_counter(struct osmo_counter *counter, void *data)
+{
+ return db_store_counter(counter);
+}
+
+static void db_sync_timer_cb(void *data)
+{
+ /* store counters to database and re-schedule */
+ osmo_counters_for_each(_db_store_counter, NULL);
+ osmo_timer_schedule(&db_sync_timer, DB_SYNC_INTERVAL);
+}
+
+void talloc_ctx_init(void);
+
+extern enum node_type bsc_vty_go_parent(struct vty *vty);
+
+static struct vty_app_info vty_info = {
+ .name = "OsmoMSC",
+ .version = PACKAGE_VERSION,
+ .go_parent_cb = bsc_vty_go_parent,
+ .is_config_node = bsc_vty_is_config_node,
+};
+
+int main(int argc, char **argv)
+{
+ int rc;
+
+ vty_info.copyright = openbsc_copyright;
+
+ tall_bsc_ctx = talloc_named_const(NULL, 1, "openbsc");
+ talloc_ctx_init();
+ on_dso_load_token();
+ on_dso_load_rrlp();
+
+ osmo_init_logging(&log_info);
+
+ /* This needs to precede handle_options() */
+ vty_init(&vty_info);
+
+ /* parse options */
+ handle_options(argc, argv);
+
+ /* internal MNCC handler or MNCC socket? */
+ if (use_mncc_sock) {
+ //rc = bsc_bootstrap_network(mncc_sock_from_cc, config_file);
+ //if (rc >= 0)
+ mncc_sock_init(bsc_gsmnet);
+ } else
+ //rc = bsc_bootstrap_network(int_mncc_recv, config_file);
+ if (rc < 0)
+ exit(1);
+ bsc_api_init(bsc_gsmnet, msc_bsc_api());
+
+ controlif_setup(bsc_gsmnet, 4250);
+ /* seed the PRNG */
+ srand(time(NULL));
+
+ if (db_init(database_name)) {
+ printf("DB: Failed to init database. Please check the option settings.\n");
+ return -1;
+ }
+ printf("DB: Database initialized.\n");
+
+ if (db_prepare()) {
+ printf("DB: Failed to prepare database.\n");
+ return -1;
+ }
+ printf("DB: Database prepared.\n");
+
+ /* setup the timer */
+ db_sync_timer.cb = db_sync_timer_cb;
+ db_sync_timer.data = NULL;
+ if (use_db_counter)
+ osmo_timer_schedule(&db_sync_timer, DB_SYNC_INTERVAL);
+
+ signal(SIGINT, &signal_handler);
+ signal(SIGABRT, &signal_handler);
+ signal(SIGUSR1, &signal_handler);
+ signal(SIGUSR2, &signal_handler);
+ osmo_init_ignore_signals();
+
+ /* start the SMS queue */
+ if (sms_queue_start(bsc_gsmnet, 20) != 0)
+ return -1;
+
+ if (daemonize) {
+ rc = osmo_daemonize();
+ if (rc < 0) {
+ perror("Error during daemonize");
+ exit(1);
+ }
+ }
+
+ while (1) {
+ log_reset_context();
+ osmo_select_main(0);
+ }
+}
diff --git a/openbsc/src/osmo-mss/stubs.c b/openbsc/src/osmo-mss/stubs.c
new file mode 100644
index 0000000..42d5094
--- /dev/null
+++ b/openbsc/src/osmo-mss/stubs.c
@@ -0,0 +1,104 @@
+#include <errno.h>
+
+#include <openbsc/debug.h>
+#include <openbsc/gsm_subscriber.h>
+
+struct gsm_subscriber_connection *connection_for_subscr(struct gsm_subscriber *subscr)
+{
+ struct gsm_bts *bts;
+ struct gsm_network *net = subscr->net;
+ struct gsm_lchan *lchan;
+
+ /* FIXME: iterate over all existing GAN associations and see if we have
+ * any for subscr */
+
+ return NULL;
+}
+
+/*! \brief process incoming 08.08 DTAP from MSC (send via GANC
+ * association to MS) */
+int gsm0808_submit_dtap(struct gsm_subscriber_connection *conn,
+ struct msgb *msg, int link_id, int allow_sacch)
+{
+ /* FIXME */
+
+ return -EINVAL;
+}
+
+/* Release all occupied RF Channels but stay around for more. */
+int gsm0808_clear(struct gsm_subscriber_connection *conn)
+{
+ /* FIXME */
+ conn->lchan = NULL;
+ conn->secondary_lchan = NULL;
+ conn->ho_lchan = NULL;
+ conn->bts = NULL;
+
+ osmo_timer_del(&conn->T10);
+
+ return 0;
+}
+/*! \brief We received a GSM 08.08 CIPHER MODE from the MSC */
+int gsm0808_cipher_mode(struct gsm_subscriber_connection *conn, int cipher,
+ const uint8_t *key, int len, int include_imeisv)
+{
+ if (cipher > 0 && key == NULL) {
+ LOGP(DRSL, LOGL_ERROR, "Need to have an encrytpion key.\n");
+ return -1;
+ }
+
+ if (len > MAX_A5_KEY_LEN) {
+ LOGP(DRSL, LOGL_ERROR, "The key is too long: %d\n", len);
+ return -1;
+ }
+}
+
+/* MSC has requested that we page the given subscriber */
+int paging_request(struct gsm_network *network, struct gsm_subscriber *subscr,
+ int type, gsm_cbfn *cbfn, void *data)
+{
+ /* FIXME */
+ return -EINVAL;
+}
+
+/* Stop paging on all other bts' */
+void paging_request_stop(struct gsm_bts *_bts, struct gsm_subscriber *subscr,
+ struct gsm_subscriber_connection *conn,
+ struct msgb *msg)
+{
+ /* FIXME */
+}
+
+/* cleanup at release subscriber_connection */
+void subscr_con_free(struct gsm_subscriber_connection *conn)
+{
+ /* FIXME: merge with libbsc/bsc_api.c implementation */
+ if (!conn)
+ return;
+
+ if (conn->subscr) {
+ subscr_put(conn->subscr);
+ conn->subscr = NULL;
+ }
+
+ if (conn->lchan) {
+ LOGP(DNM, LOGL_ERROR, "The lchan should have been cleared.\n");
+ conn->lchan->conn = NULL;
+ }
+
+ if (conn->secondary_lchan) {
+ LOGP(DNM, LOGL_ERROR, "The secondary_lchan should have been cleared.\n");
+ conn->secondary_lchan->conn = NULL;
+ }
+
+ llist_del(&conn->entry);
+ talloc_free(conn);
+}
+
+void gsm_net_update_ctype(struct gsm_network *network)
+{
+ /* a MSC doesn't really need this, does it? */
+ return;
+}
+
+