summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-08-01 16:58:34 +0800
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-08-01 17:01:26 +0800
commit00e6f692e9ee7bc7001e5c31b519abe711585503 (patch)
tree064c86fd25485cad21f0d3a8200169bb12f42334 /include
parent68b7e8bd60d0d5b39b8ac19ec5a33689486ac117 (diff)
mtp: Add the MTP Level3 code to the SCCP repoistory
SCCP can be wrapped inside the MTP Level3, and one can use it for link testing as well. This repository should be renamed to libosmo-itu or libosmo-ss7 and be a host to SS7 related encapsulation... The code is coming from the cellmgr-ng code.
Diffstat (limited to 'include')
-rw-r--r--include/Makefile.am2
-rw-r--r--include/mtp/Makefile.am2
-rw-r--r--include/mtp/mtp_data.h85
-rw-r--r--include/mtp/mtp_level3.h165
-rw-r--r--include/mtp/mtp_pcap.h29
5 files changed, 282 insertions, 1 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index d0ed7f4..bf7855d 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1 +1 @@
-SUBDIRS = sccp
+SUBDIRS = sccp mtp
diff --git a/include/mtp/Makefile.am b/include/mtp/Makefile.am
new file mode 100644
index 0000000..077805b
--- /dev/null
+++ b/include/mtp/Makefile.am
@@ -0,0 +1,2 @@
+mtp_HEADERS = mtp_data.h mtp_level3.h mtp_pcap.h
+mtpdir = $(includedir)/mtp
diff --git a/include/mtp/mtp_data.h b/include/mtp/mtp_data.h
new file mode 100644
index 0000000..b8f6af0
--- /dev/null
+++ b/include/mtp/mtp_data.h
@@ -0,0 +1,85 @@
+/*
+ * (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 General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#ifndef mtp_data_h
+#define mtp_data_h
+
+#include <osmocore/msgb.h>
+#include <osmocore/timer.h>
+#include <osmocore/utils.h>
+
+/* MTP Level3 timers */
+
+/* Timers for SS7 */
+#define MTP_T1 12, 0
+#define MTP_T2 30, 0
+#define START_DELAY 8, 0
+
+/**
+ * The state of the mtp_link in terms of layer3 and upwards
+ */
+struct mtp_link {
+ /* routing info.. */
+ int dpc, opc;
+
+ /* internal state */
+ /* the MTP1 link is up */
+ int available;
+ int running;
+ int sccp_up;
+
+ /* misc data */
+ uint8_t test_ptrn[14];
+
+ int sltm_pending;
+ struct llist_head pending_msgs;
+ int sltm_once;
+ int was_up;
+
+
+ /* the associated link */
+ int link;
+
+ int slta_misses;
+ struct timer_list t1_timer;
+ struct timer_list t2_timer;
+
+ struct timer_list delay_timer;
+};
+
+
+struct mtp_link *mtp_link_alloc(void);
+void mtp_link_stop(struct mtp_link *link);
+void mtp_link_reset(struct mtp_link *link);
+int mtp_link_data(struct mtp_link *link, struct msgb *msg);
+int mtp_link_submit_sccp_data(struct mtp_link *link, int sls, const uint8_t *data, unsigned int length);
+
+
+/* one time init function */
+void mtp_link_init(void);
+
+/* to be implemented for MSU sending */
+void mtp_link_submit(struct mtp_link *link, struct msgb *msg);
+void mtp_link_forward_sccp(struct mtp_link *link, struct msgb *msg, int sls);
+void mtp_link_restart(struct mtp_link *link);
+void mtp_link_slta_recv(struct mtp_link *link);
+void mtp_link_sccp_down(struct mtp_link *link);
+
+#endif
diff --git a/include/mtp/mtp_level3.h b/include/mtp/mtp_level3.h
new file mode 100644
index 0000000..7d72d9e
--- /dev/null
+++ b/include/mtp/mtp_level3.h
@@ -0,0 +1,165 @@
+/* Q.701-Q.704, Q.706, Q.707 handling code */
+/*
+ * (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 General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#ifndef mtp_level3_h
+#define mtp_level3_h
+
+#include <endian.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+
+/*
+ * pssible service information octets..
+ */
+#define MTP_NI_NATION_NET 0x02
+
+#define MTP_SI_MNT_SNM_MSG 0x00
+#define MTP_SI_MNT_REG_MSG 0x01
+#define MTP_SI_MNT_SCCP 0x03
+
+/*
+ * h0 contains the group, h1 the semantic of it
+ */
+
+#define MTP_TST_MSG_GRP 0x01
+#define MTP_PROHIBIT_MSG_GRP 0x04
+#define MTP_TRF_RESTR_MSG_GRP 0x07
+
+/* h1 values for different groups */
+#define MTP_TST_MSG_SLTM 0x01
+#define MTP_TST_MSG_SLTA 0x02
+
+#define MTP_RESTR_MSG_ALLWED 0x01
+
+#define MTP_PROHIBIT_MSG_SIG 0x01
+
+
+#define SCCP_SST 0x03
+#define SCCP_SSA 0x01
+
+#define MTP_LINK_MASK 0x0F
+#define MTP_ADDR_MASK 0x0FFF
+#define MTP_APOC_MASK 0x3f
+
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define MTP_LINK_SLS(addr) ((addr >>28) & MTP_LINK_MASK)
+#define MTP_ADDR(link, dpc, opc) \
+ (((dpc) & MTP_ADDR_MASK) << 0 | \
+ ((opc) & MTP_ADDR_MASK) << 14| \
+ ((link) & MTP_LINK_MASK) << 28)
+#define MTP_MAKE_APOC(apoc) \
+ (apoc & 0x3fff)
+#elif __BYTE_ORDER == __BIG_ENDIAN
+static inline uint32_t c_swap_32(uint32_t in)
+{
+ return (((in & 0x000000ff) << 24) |
+ ((in & 0x0000ff00) << 8) |
+ ((in & 0x00ff0000) >> 8) |
+ ((in & 0xff000000) >> 24));
+}
+static inline uint16_t c_swap_16(uint16_t in)
+{
+ return (((in & 0x00ff) << 8) |
+ (in & 0xff00) >> 8);
+}
+#define MTP_LINK_SLS(addr) ((c_swap_32(addr)>>28) & MTP_LINK_MASK)
+#define MTP_ADDR(link, dpc, opc) \
+ c_swap_32(((dpc) & MTP_ADDR_MASK) << 0 | \
+ ((opc) & MTP_ADDR_MASK) << 14| \
+ ((link) & MTP_LINK_MASK) << 28)
+#define MTP_MAKE_APOC(apoc) \
+ c_swap_16((apoc & 0x3fff))
+#endif
+
+
+
+/*
+ * not the on wire address...
+ */
+struct mtp_addr {
+ uint16_t dpc;
+ uint16_t opc;
+ uint8_t link;
+} __attribute__((packed));
+
+/*
+ * the struct is defined in Q.704 and can be seen in the
+ * wireshark dissectors too
+ */
+struct mtp_level_3_hdr {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ uint8_t ser_ind : 4,
+ spare : 2,
+ ni : 2;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ uint8_t ni : 2,
+ spare : 2,
+ ser_ind : 4;
+#endif
+ uint32_t addr;
+ uint8_t data[0];
+} __attribute__((packed));
+
+struct mtp_level_3_cmn {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ uint8_t h0 : 4,
+ h1 : 4;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ uint8_t h1 : 4,
+ h0 : 4;
+#endif
+} __attribute__((packed));
+
+struct mtp_level_3_mng {
+ struct mtp_level_3_cmn cmn;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ uint8_t spare : 4,
+ length : 4;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ uint8_t length : 4,
+ spare : 4;
+#endif
+ uint8_t data[0];
+} __attribute__((packed));
+
+struct mtp_level_3_prohib {
+ struct mtp_level_3_cmn cmn;
+
+ uint16_t apoc;
+} __attribute__((packed));
+
+struct sccp_con_ctrl_prt_mgt {
+ uint8_t sst;
+ uint8_t assn; /* affected sub system number */
+ uint16_t apoc;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ uint8_t mul_ind : 2,
+ spare : 6;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ uint8_t spare : 6,
+ mul_ind : 2;
+#endif
+} __attribute__((packed));
+
+#endif
diff --git a/include/mtp/mtp_pcap.h b/include/mtp/mtp_pcap.h
new file mode 100644
index 0000000..5e8f7d3
--- /dev/null
+++ b/include/mtp/mtp_pcap.h
@@ -0,0 +1,29 @@
+/*
+ * (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 General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#ifndef mtp_pcap_h
+#define mtp_pcap_h
+
+#include <stdint.h>
+
+int mtp_pcap_write_header(int fd);
+int mtp_pcap_write_msu(int fd, const uint8_t *data, int length);
+
+#endif