laforge has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmo-sccp/+/38041?usp=email )
Change subject: remove old static libsccp.a, libmtp.a, libxua.a
......................................................................
remove old static libsccp.a, libmtp.a, libxua.a
Those static libraries were not used or maintained a long time ago.
We have a much more complete implementation of SCCP and xUA in
libosmo-sigtran. That has been the basis of osmo-stp, as well as in
osmo-sgsn.git, osmo-bsc.git, osmo-msc.git.
The only user of the old static libraries was osmo-bsc-sccplite from
openbsc.git, which is unsupported for many years.
Change-Id: I299a32a2f8f61477cf49c8126567fef2092d5407
---
M Makefile.am
M TODO-RELEASE
M configure.ac
M debian/control
D debian/libosmo-sccp-dev.install
M debian/libosmo-sigtran-dev.install
M include/osmocom/Makefile.am
D include/osmocom/mtp/Makefile.am
D include/osmocom/mtp/mtp_level3.h
D include/osmocom/mtp/mtp_pcap.h
M include/osmocom/sccp/Makefile.am
D include/osmocom/sccp/sccp.h
D libosmo-mtp.pc.in
D libosmo-sccp.pc.in
D libosmo-xua.pc.in
M src/Makefile.am
D src/mtp_pcap.c
D src/sccp.c
M tests/Makefile.am
D tests/mtp/Makefile.am
D tests/mtp/mtp_parse_test.c
D tests/mtp/mtp_parse_test.ok
D tests/sccp/Makefile.am
D tests/sccp/sccp_test.c
D tests/sccp/sccp_test.ok
M tests/testsuite.at
26 files changed, 8 insertions(+), 3,966 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/41/38041/1
diff --git a/Makefile.am b/Makefile.am
index 5a2cad4..051f3c3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,7 +4,7 @@
SUBDIRS = include src tests examples stp doc contrib
pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = libosmo-sccp.pc libosmo-mtp.pc libosmo-sigtran.pc libosmo-xua.pc
+pkgconfig_DATA = libosmo-sigtran.pc
EXTRA_DIST = \
.version \
diff --git a/TODO-RELEASE b/TODO-RELEASE
index 0ed7189..2f0dcec 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,3 +7,6 @@
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public release: c:r:0.
#library what description / commit summary line
+libsccp.a removed ancient library not used for decades
+libmtp.a removed ancient library not used for decades
+libsccp.a removed ancient library not used for decades
diff --git a/configure.ac b/configure.ac
index 7311ffa..e98476e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -183,9 +183,6 @@
AC_OUTPUT(
libosmo-sigtran.pc
- libosmo-sccp.pc
- libosmo-mtp.pc
- libosmo-xua.pc
include/osmocom/Makefile
include/osmocom/sccp/Makefile
include/osmocom/mtp/Makefile
@@ -193,8 +190,6 @@
include/Makefile
src/Makefile
tests/Makefile
- tests/sccp/Makefile
- tests/mtp/Makefile
tests/m2ua/Makefile
tests/xua/Makefile
tests/ss7/Makefile
diff --git a/debian/control b/debian/control
index de425de..68abbe8 100644
--- a/debian/control
+++ b/debian/control
@@ -21,19 +21,6 @@
Vcs-Browser:
https://gitea.osmocom.org/osmocom/libosmo-sccp
Homepage:
https://projects.osmocom.org/projects/libosmo-sccp
-Package: libosmo-sccp-dev
-Architecture: any
-Depends: ${misc:Depends}
-Multi-Arch: same
-Section: libdevel
-Description: Development files for libsccp, libmtp and libxua
- SCCP is a network layer protocol that provides extended routing, flow control,
- segmentation, connection-orientation, and error correction facilities in
- Signaling System 7 telecommunications networks.
- It is heavily used in cellular networks such as GSM.
- .
- This package contains the development files for the library.
-
Package: libosmo-sigtran10
Section: libs
Architecture: any
diff --git a/debian/libosmo-sccp-dev.install b/debian/libosmo-sccp-dev.install
deleted file mode 100644
index 0404a9c..0000000
--- a/debian/libosmo-sccp-dev.install
+++ /dev/null
@@ -1,7 +0,0 @@
-usr/include/osmocom/sccp
-usr/lib/*/libsccp.a
-usr/lib/*/libmtp.a
-usr/lib/*/libxua.a
-usr/lib/*/pkgconfig/libosmo-sccp.pc
-usr/lib/*/pkgconfig/libosmo-mtp.pc
-usr/lib/*/pkgconfig/libosmo-xua.pc
diff --git a/debian/libosmo-sigtran-dev.install b/debian/libosmo-sigtran-dev.install
index a556f90..b4628e2 100644
--- a/debian/libosmo-sigtran-dev.install
+++ b/debian/libosmo-sigtran-dev.install
@@ -1,4 +1,5 @@
usr/include/osmocom/sigtran
+usr/include/osmocom/sccp
usr/lib/*/libosmo-sigtran*.a
usr/lib/*/libosmo-sigtran*.so
usr/lib/*/libosmo-sigtran*.la
diff --git a/include/osmocom/Makefile.am b/include/osmocom/Makefile.am
index c4535f3..a08ab02 100644
--- a/include/osmocom/Makefile.am
+++ b/include/osmocom/Makefile.am
@@ -1 +1 @@
-SUBDIRS = mtp sccp sigtran
+SUBDIRS = sccp sigtran
diff --git a/include/osmocom/mtp/Makefile.am b/include/osmocom/mtp/Makefile.am
deleted file mode 100644
index dbd0e79..0000000
--- a/include/osmocom/mtp/Makefile.am
+++ /dev/null
@@ -1,2 +0,0 @@
-mtp_HEADERS = mtp_level3.h mtp_pcap.h
-mtpdir = $(includedir)/osmocom/mtp
diff --git a/include/osmocom/mtp/mtp_level3.h b/include/osmocom/mtp/mtp_level3.h
deleted file mode 100644
index 8ea54a9..0000000
--- a/include/osmocom/mtp/mtp_level3.h
+++ /dev/null
@@ -1,177 +0,0 @@
-/* Q.701-Q.704, Q.706, Q.707 handling code */
-/*
- * (C) 2010 by Holger Hans Peter Freyther <zecke(a)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.
- *
- */
-
-#pragma once
-
-#include <osmocom/core/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
-#define MTP_SI_MNT_ISUP 0x05
-
-/*
- * h0 contains the group, h1 the semantic of it
- */
-
-#define MTP_TST_MSG_GRP 0x01
-#define MTP_PROHIBIT_MSG_GRP 0x04
-#define MTP_SROUTE_MSG_GRP 0x05
-#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
-
-/* For the prohibit group */
-#define MTP_PROHIBIT_MSG_SIG 0x01
-#define MTP_PROHIBIT_MSG_TFA 0x05
-
-/* For the Signalling-route-set-test */
-#define MTP_SROUTE_MSG_TEST 0x01
-
-
-#define SCCP_SST 0x03
-#define SCCP_SSP 0x02
-#define SCCP_SSA 0x01
-
-#define MTP_LINK_MASK 0x0F
-#define MTP_ADDR_MASK 0x3FFF
-#define MTP_APOC_MASK 0x3f
-
-
-#if OSMO_IS_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)
-#define MTP_READ_DPC(addr) \
- (((addr) >> 0) & MTP_ADDR_MASK)
-#define MTP_READ_OPC(addr) \
- (((addr) >> 14) & MTP_ADDR_MASK)
-#elif OSMO_IS_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))
-#define MTP_READ_DPC(addr) \
- (c_swap_32(addr) & MTP_ADDR_MASK)
-#define MTP_READ_OPC(addr) \
- ((c_swap_32(addr) >> 14) & MTP_ADDR_MASK)
-#else
-#error "Unknown endian"
-#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 OSMO_IS_LITTLE_ENDIAN
- uint8_t ser_ind : 4,
- spare : 2,
- ni : 2;
-#elif OSMO_IS_BIG_ENDIAN
-/* auto-generated from the little endian part above
(libosmocore/contrib/struct_endianness.py) */
- 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 OSMO_IS_LITTLE_ENDIAN
- uint8_t h0 : 4,
- h1 : 4;
-#elif OSMO_IS_BIG_ENDIAN
-/* auto-generated from the little endian part above
(libosmocore/contrib/struct_endianness.py) */
- uint8_t h1:4, h0:4;
-#endif
-} __attribute__((packed));
-
-struct mtp_level_3_mng {
- struct mtp_level_3_cmn cmn;
-#if OSMO_IS_LITTLE_ENDIAN
- uint8_t spare : 4,
- length : 4;
-#elif OSMO_IS_BIG_ENDIAN
-/* auto-generated from the little endian part above
(libosmocore/contrib/struct_endianness.py) */
- 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 OSMO_IS_LITTLE_ENDIAN
- uint8_t mul_ind : 2,
- spare : 6;
-#elif OSMO_IS_BIG_ENDIAN
-/* auto-generated from the little endian part above
(libosmocore/contrib/struct_endianness.py) */
- uint8_t spare:6, mul_ind:2;
-#endif
-} __attribute__((packed));
-
diff --git a/include/osmocom/mtp/mtp_pcap.h b/include/osmocom/mtp/mtp_pcap.h
deleted file mode 100644
index 4e400e2..0000000
--- a/include/osmocom/mtp/mtp_pcap.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * (C) 2010 by Holger Hans Peter Freyther <zecke(a)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.
- *
- */
-#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
diff --git a/include/osmocom/sccp/Makefile.am b/include/osmocom/sccp/Makefile.am
index c64db26..6bbeec4 100644
--- a/include/osmocom/sccp/Makefile.am
+++ b/include/osmocom/sccp/Makefile.am
@@ -1,2 +1,2 @@
-sccp_HEADERS = sccp_types.h sccp.h
+sccp_HEADERS = sccp_types.h
sccpdir = $(includedir)/osmocom/sccp
diff --git a/include/osmocom/sccp/sccp.h b/include/osmocom/sccp/sccp.h
deleted file mode 100644
index fd911da..0000000
--- a/include/osmocom/sccp/sccp.h
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * SCCP management code
- *
- * (C) 2009, 2010, 2013 by Holger Hans Peter Freyther <zecke(a)selfish.org>
- * (C) 2009, 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 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.
- *
- */
-
-#ifndef SCCP_H
-#define SCCP_H
-
-#include <stdlib.h>
-
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <osmocom/core/linuxlist.h>
-
-#include "sccp_types.h"
-
-struct msgb;
-struct sccp_system;
-
-enum {
- SCCP_CONNECTION_STATE_NONE,
- SCCP_CONNECTION_STATE_REQUEST,
- SCCP_CONNECTION_STATE_CONFIRM,
- SCCP_CONNECTION_STATE_ESTABLISHED,
- SCCP_CONNECTION_STATE_RELEASE,
- SCCP_CONNECTION_STATE_RELEASE_COMPLETE,
- SCCP_CONNECTION_STATE_REFUSED,
- SCCP_CONNECTION_STATE_SETUP_ERROR,
-};
-
-struct sockaddr_sccp {
- sa_family_t sccp_family; /* AF_SCCP in the future??? */
- uint8_t sccp_ssn; /* subssystem number for routing */
-
- /* TODO fill in address indicator... if that is ever needed */
-
- /* optional gti information */
- uint8_t *gti;
- int gti_len;
-
- /* any of SCCP_TITLE_IND_* */
- uint8_t gti_ind;
-
- int use_poi;
- uint8_t poi[2];
-
- /* not sure about these */
- /* uint8_t sccp_class; */
-};
-
-/*
- * parsed structure of an address
- */
-struct sccp_address {
- struct sccp_called_party_address address;
- uint8_t ssn;
- uint8_t poi[2];
-
- uint8_t *gti_data;
- int gti_len;
-};
-
-struct sccp_optional_data {
- uint8_t data_len;
- uint8_t data_start;
-};
-
-struct sccp_connection {
- /* public */
- void *data_ctx;
- void (*data_cb)(struct sccp_connection *conn, struct msgb *msg, unsigned int len);
-
- void *state_ctx;
- void (*state_cb)(struct sccp_connection *, int old_state);
-
- struct sccp_source_reference source_local_reference;
- struct sccp_source_reference destination_local_reference;
-
- int connection_state;
-
- /* private */
- /* list of active connections */
- struct llist_head list;
- struct sccp_system *system;
- int incoming;
-};
-
-/**
- * system functionality to implement on top of any other transport layer:
- * call sccp_system_incoming for incoming data (from the network)
- * sccp will call outgoing whenever outgoing data exists
- * The conn is NULL for UDT and other messages without a connection
- */
-int sccp_system_init(void (*outgoing)(struct sccp_connection *conn, struct msgb *data,
void *gctx, void *ctx), void *context);
-int sccp_system_incoming_ctx(struct msgb *data, void *ctx);
-int sccp_system_incoming(struct msgb *data);
-
-/**
- * Send data on an existing connection
- */
-int sccp_connection_write(struct sccp_connection *connection, struct msgb *data);
-int sccp_connection_send_it(struct sccp_connection *connection);
-int sccp_connection_close(struct sccp_connection *connection, int cause);
-int sccp_connection_free(struct sccp_connection *connection);
-
-/**
- * internal..
- */
-int sccp_connection_force_free(struct sccp_connection *conn);
-
-/**
- * Create a new socket. Set your callbacks and then call bind to open
- * the connection.
- */
-struct sccp_connection *sccp_connection_socket(void);
-
-/**
- * Open the connection and send additional data
- */
-int sccp_connection_connect(struct sccp_connection *conn,
- const struct sockaddr_sccp *sccp_called,
- struct msgb *data);
-
-/**
- * mostly for testing purposes only. Set the accept callback.
- * TODO: add true routing information... in analogy to socket, bind, accept
- */
-int sccp_connection_set_incoming(const struct sockaddr_sccp *sock,
- int (*accept_cb)(struct sccp_connection *connection, void *data),
- void *user_data);
-
-/**
- * Send data in terms of unit data. A fixed address indicator will be used.
- */
-int sccp_write(struct msgb *data,
- const struct sockaddr_sccp *sock_sender,
- const struct sockaddr_sccp *sock_target,
- int class, void *ctx);
-int sccp_set_read(const struct sockaddr_sccp *sock,
- int (*read_cb)(struct msgb *msgb, unsigned int, void *user_data),
- void *user_data);
-
-/* generic sock addresses */
-extern const struct sockaddr_sccp sccp_ssn_bssap;
-
-/* helpers */
-uint32_t sccp_src_ref_to_int(struct sccp_source_reference *ref);
-struct sccp_source_reference sccp_src_ref_from_int(uint32_t);
-
-struct msgb *sccp_create_cr(const struct sccp_source_reference *src_ref, const struct
sockaddr_sccp *called, const uint8_t *data, size_t length);
-struct msgb *sccp_create_refuse(struct sccp_source_reference *src_ref, int cause, uint8_t
*data, int length);
-struct msgb *sccp_create_cc(struct sccp_source_reference *src_ref, struct
sccp_source_reference *dst_ref);
-struct msgb *sccp_create_rlsd(struct sccp_source_reference *src_ref, struct
sccp_source_reference *dst_ref, int cause);
-struct msgb *sccp_create_dt1(struct sccp_source_reference *dst_ref, uint8_t *data,
uint8_t len);
-struct msgb *sccp_create_udt(int _class, const struct sockaddr_sccp *sock_sender,
- const struct sockaddr_sccp *sock_target, uint8_t *data, int len);
-
-/**
- * Below this are helper functions and structs for parsing SCCP messages
- */
-struct sccp_parse_result {
- struct sccp_address called;
- struct sccp_address calling;
-
- /* point to the msg packet */
- struct sccp_source_reference *source_local_reference;
- struct sccp_source_reference *destination_local_reference;
-
- /* data pointer */
- int data_len;
-};
-
-/*
- * helper functions for the nat code
- */
-int sccp_determine_msg_type(struct msgb *msg);
-int sccp_parse_header(struct msgb *msg, struct sccp_parse_result *result);
-
-/*
- * osmocore logging features
- */
-void sccp_set_log_area(int log_area);
-
-#endif
diff --git a/libosmo-mtp.pc.in b/libosmo-mtp.pc.in
deleted file mode 100644
index 675d0d3..0000000
--- a/libosmo-mtp.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: Osmo MTP Lib
-Description: Osmo MTP Lib
-Version: @VERSION@
-Libs: -L${libdir} -lmtp
-Cflags: -I${includedir}/
diff --git a/libosmo-sccp.pc.in b/libosmo-sccp.pc.in
deleted file mode 100644
index eda8d49..0000000
--- a/libosmo-sccp.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: OpenBSC SCCP Lib
-Description: OpenBSC SCCP Lib
-Version: @VERSION@
-Libs: -L${libdir} -lsccp
-Cflags: -I${includedir}/
diff --git a/libosmo-xua.pc.in b/libosmo-xua.pc.in
deleted file mode 100644
index 28f8285..0000000
--- a/libosmo-xua.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: Osmo XUA Lib
-Description: Osmo XUA Lib
-Version: @VERSION@
-Libs: -L${libdir} -losmo-xua
-Cflags: -I${includedir}/
diff --git a/src/Makefile.am b/src/Makefile.am
index 40a0ed1..8e69e19 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,22 +10,6 @@
xua_internal.h \
$(NULL)
-# Legacy static libs
-
-sccpdir = $(libdir)
-sccp_LIBRARIES = libsccp.a libmtp.a libxua.a
-
-libsccp_a_SOURCES = sccp.c
-libmtp_a_SOURCES = mtp_pcap.c
-libxua_a_SOURCES = xua_msg.c
-# ensure that the file for the static lib is built with different C
-# flags, working around automake complaining that xua_msg.o is built
-# both with libtool (below) and without (here)
-libxua_a_CPPFLAGS = $(AM_CPPFLAGS) -DDUMMY -UDUMMY
-
-
-# New shared lib
-
lib_LTLIBRARIES = libosmo-sigtran.la
# This is _NOT_ the library release version, it's an API version.
diff --git a/src/mtp_pcap.c b/src/mtp_pcap.c
deleted file mode 100644
index f677581..0000000
--- a/src/mtp_pcap.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/* PCAP code from OpenBSC done by Holger Freyther */
-/*
- * (C) 2010 by Holger Hans Peter Freyther <zecke(a)selfish.org>
- * (C) 2010 by On-Waves
- * All Rights Reserved
- *
- * SPDX-License-Identifier: GPL-2.0+
- *
- * 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.
- *
- */
-
-#include <osmocom/mtp/mtp_pcap.h>
-
-#include <sys/time.h>
-
-#include <unistd.h>
-
-/*
- * pcap writing of the misdn load
- * pcap format is from
http://wiki.wireshark.org/Development/LibpcapFileFormat
- */
-struct pcap_hdr {
- uint32_t magic_number;
- uint16_t version_major;
- uint16_t version_minor;
- int32_t thiszone;
- uint32_t sigfigs;
- uint32_t snaplen;
- uint32_t network;
-} __attribute__((packed));
-
-struct pcaprec_hdr {
- uint32_t ts_sec;
- uint32_t ts_usec;
- uint32_t incl_len;
- uint32_t orig_len;
-} __attribute__((packed));
-
-int mtp_pcap_write_header(int fd)
-{
- static struct pcap_hdr hdr = {
- .magic_number = 0xa1b2c3d4,
- .version_major = 2,
- .version_minor = 4,
- .thiszone = 0,
- .sigfigs = 0,
- .snaplen = 65535,
- .network = 141,
- };
-
- return write(fd, &hdr, sizeof(hdr));
-}
-
-int mtp_pcap_write_msu(int fd, const uint8_t *data, int length)
-{
- int rc_h, rc_d;
- struct timeval tv;
- struct pcaprec_hdr payload_header = {
- .ts_sec = 0,
- .ts_usec = 0,
- .incl_len = length,
- .orig_len = length,
- };
-
- gettimeofday(&tv, NULL);
- payload_header.ts_sec = tv.tv_sec;
- payload_header.ts_usec = tv.tv_usec;
-
- rc_h = write(fd, &payload_header, sizeof(payload_header));
- rc_d = write(fd, data, length);
-
- return rc_h == sizeof(payload_header) && rc_d == length;
-}
diff --git a/src/sccp.c b/src/sccp.c
deleted file mode 100644
index 85bea6d..0000000
--- a/src/sccp.c
+++ /dev/null
@@ -1,1572 +0,0 @@
-/*
- * SCCP management code
- *
- * (C) 2009, 2010, 2013 by Holger Hans Peter Freyther <zecke(a)selfish.org>
- * (C) 2009, 2010, 2013 by On-Waves
- *
- * All Rights Reserved
- *
- * SPDX-License-Identifier: GPL-2.0+
- *
- * 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.
- *
- */
-
-#include <errno.h>
-#include <string.h>
-
-#include <osmocom/core/msgb.h>
-#include <osmocom/core/talloc.h>
-#include <osmocom/core/logging.h>
-#include <osmocom/core/endian.h>
-#include <osmocom/gsm/tlv.h>
-#include <osmocom/sccp/sccp_types.h>
-#include <osmocom/sccp/sccp.h>
-
-// Unassigned debug area
-static int DSCCP = 0;
-
-static void *tall_sccp_ctx;
-static LLIST_HEAD(sccp_connections);
-
-#define SCCP_MSG_SIZE 4096
-#define SCCP_MSG_HEADROOM 128
-
-/* global data */
-const struct sockaddr_sccp sccp_ssn_bssap = {
- .sccp_family = 0,
- .sccp_ssn = SCCP_SSN_BSSAP,
-};
-
-struct sccp_system {
- /* layer3 -> layer2 */
- void (*write_data)(struct sccp_connection *conn, struct msgb *data,
- void *gctx, void *ctx);
- void *write_context;
-};
-
-
-static struct sccp_system sccp_system = {
- .write_data = NULL,
-};
-
-struct sccp_data_callback {
- /* connection based */
- int (*accept_cb)(struct sccp_connection *, void *);
- void *accept_context;
-
- /* connection less */
- int (*read_cb)(struct msgb *, unsigned int, void *);
- void *read_context;
-
- uint8_t ssn;
- struct llist_head callback;
-};
-
-static LLIST_HEAD(sccp_callbacks);
-
-static struct sccp_data_callback *_find_ssn(uint8_t ssn)
-{
- struct sccp_data_callback *cb;
-
- llist_for_each_entry(cb, &sccp_callbacks, callback) {
- if (cb->ssn == ssn)
- return cb;
- }
-
- /* need to add one */
- cb = talloc_zero(tall_sccp_ctx, struct sccp_data_callback);
- if (!cb) {
- LOGP(DSCCP, LOGL_ERROR, "Failed to allocate sccp callback.\n");
- return NULL;
- }
-
- cb->ssn = ssn;
- llist_add_tail(&cb->callback, &sccp_callbacks);
- return cb;
-}
-
-
-static void _send_msg(struct sccp_connection *conn, struct msgb *msg, void *ctx)
-{
- sccp_system.write_data(conn, msg, sccp_system.write_context, ctx);
-}
-
-/*
- * parsing routines
- */
-static int copy_address(struct sccp_address *addr, uint8_t offset, struct msgb *msgb)
-{
- struct sccp_called_party_address *party;
-
- int room = msgb_l2len(msgb) - offset;
- uint8_t read = 0;
- uint8_t length;
-
- if (room <= 0) {
- LOGP(DSCCP, LOGL_ERROR, "Not enough room for an address: %u\n", room);
- return -1;
- }
-
- length = msgb->l2h[offset];
- if (room <= length) {
- LOGP(DSCCP, LOGL_ERROR, "Not enough room for optional data %u %u\n", room,
length);
- return -1;
- }
-
-
- party = (struct sccp_called_party_address *)(msgb->l2h + offset + 1);
- if (party->point_code_indicator) {
- if (length <= read + 2) {
- LOGP(DSCCP, LOGL_ERROR, "POI does not fit %u\n", length);
- return -1;
- }
-
-
- memcpy(&addr->poi, &party->data[read], 2);
- read += 2;
- }
-
- if (party->ssn_indicator) {
- if (length <= read + 1) {
- LOGP(DSCCP, LOGL_ERROR, "SSN does not fit %u\n", length);
- return -1;
- }
-
- addr->ssn = party->data[read];
- read += 1;
- }
-
- /* copy the GTI over */
- if (party->global_title_indicator) {
- addr->gti_len = length - read - 1;
- addr->gti_data = &party->data[read];
- }
-
- addr->address = *party;
- return 0;
-}
-
-static int _sccp_parse_optional_data(const int offset,
- struct msgb *msgb, struct sccp_optional_data *data)
-{
- uint16_t room = msgb_l2len(msgb) - offset;
- uint16_t read = 0;
-
- while (room > read) {
- uint8_t type = msgb->l2h[offset + read];
- if (type == SCCP_PNC_END_OF_OPTIONAL)
- return 0;
-
- if (read + 1 >= room) {
- LOGP(DSCCP, LOGL_ERROR, "no place for length\n");
- return 0;
- }
-
- uint8_t length = msgb->l2h[offset + read + 1];
- read += 2 + length;
-
-
- if (room <= read) {
- LOGP(DSCCP, LOGL_ERROR,
- "no space for the data: type: %d read: %d room: %d l2: %d\n",
- type, read, room, msgb_l2len(msgb));
- return 0;
- }
-
- if (type == SCCP_PNC_DATA) {
- data->data_len = length;
- data->data_start = offset + read - length;
- }
-
- }
-
- return -1;
-}
-
-int _sccp_parse_connection_request(struct msgb *msgb, struct sccp_parse_result *result)
-{
- static const uint32_t header_size =
- sizeof(struct sccp_connection_request);
- static const uint32_t optional_offset =
- offsetof(struct sccp_connection_request, optional_start);
- static const uint32_t called_offset =
- offsetof(struct sccp_connection_request, variable_called);
-
- struct sccp_connection_request *req = (struct sccp_connection_request *)msgb->l2h;
- struct sccp_optional_data optional_data;
-
- /* header check */
- if (msgb_l2len(msgb) < header_size) {
- LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
- msgb_l2len(msgb), header_size);
- return -1;
- }
-
- /* copy out the calling and called address. Add the offset */
- if (copy_address(&result->called, called_offset + req->variable_called, msgb)
!= 0)
- return -1;
-
- result->source_local_reference = &req->source_local_reference;
-
- /*
- * parse optional data.
- */
- memset(&optional_data, 0, sizeof(optional_data));
- if (_sccp_parse_optional_data(optional_offset + req->optional_start, msgb,
&optional_data) != 0) {
- LOGP(DSCCP, LOGL_ERROR, "parsing of optional data failed.\n");
- return -1;
- }
-
- if (optional_data.data_len != 0) {
- if (optional_data.data_len > SCCP_MAX_OPTIONAL_DATA) {
- LOGP(DSCCP, LOGL_ERROR,
- "optional data has length %u exceeding max of %u according to ITU-T Rec. Q.713
§4.2\n",
- optional_data.data_len, SCCP_MAX_OPTIONAL_DATA);
- return -EMSGSIZE;
- }
- msgb->l3h = &msgb->l2h[optional_data.data_start];
- result->data_len = optional_data.data_len;
- } else {
- result->data_len = 0;
- }
-
- return 0;
-}
-
-int _sccp_parse_connection_released(struct msgb *msgb, struct sccp_parse_result *result)
-{
- static size_t header_size = sizeof(struct sccp_connection_released);
- static size_t optional_offset = offsetof(struct sccp_connection_released,
optional_start);
-
- struct sccp_optional_data optional_data;
- struct sccp_connection_released *rls = (struct sccp_connection_released *)
msgb->l2h;
-
- /* we don't have enough size for the struct */
- if (msgb_l2len(msgb) < header_size) {
- LOGP(DSCCP, LOGL_ERROR, "msgb > header_size %u %zu\n",
- msgb_l2len(msgb), header_size);
- return -1;
- }
-
- memset(&optional_data, 0, sizeof(optional_data));
- if (_sccp_parse_optional_data(optional_offset + rls->optional_start, msgb,
&optional_data) != 0) {
- LOGP(DSCCP, LOGL_ERROR, "parsing of optional data failed.\n");
- return -1;
- }
-
- result->source_local_reference = &rls->source_local_reference;
- result->destination_local_reference = &rls->destination_local_reference;
-
- if (optional_data.data_len != 0) {
- if (optional_data.data_len > SCCP_MAX_OPTIONAL_DATA) {
- LOGP(DSCCP, LOGL_ERROR,
- "optional data has length %u exceeding max of %u according to ITU-T Rec. Q.713
§4.5\n",
- optional_data.data_len, SCCP_MAX_OPTIONAL_DATA);
- return -EMSGSIZE;
- }
- msgb->l3h = &msgb->l2h[optional_data.data_start];
- result->data_len = optional_data.data_len;
- } else {
- result->data_len = 0;
- }
-
- return 0;
-}
-
-int _sccp_parse_connection_refused(struct msgb *msgb, struct sccp_parse_result *result)
-{
- static const uint32_t header_size =
- sizeof(struct sccp_connection_refused);
- static int optional_offset = offsetof(struct sccp_connection_refused, optional_start);
-
- struct sccp_optional_data optional_data;
- struct sccp_connection_refused *ref;
-
- /* header check */
- if (msgb_l2len(msgb) < header_size) {
- LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
- msgb_l2len(msgb), header_size);
- return -1;
- }
-
- ref = (struct sccp_connection_refused *) msgb->l2h;
-
- result->destination_local_reference = &ref->destination_local_reference;
-
- memset(&optional_data, 0, sizeof(optional_data));
- if (_sccp_parse_optional_data(optional_offset + ref->optional_start, msgb,
&optional_data) != 0) {
- LOGP(DSCCP, LOGL_ERROR, "parsing of optional data failed.\n");
- return -1;
- }
-
- /* optional data */
- if (optional_data.data_len != 0) {
- if (optional_data.data_len > SCCP_MAX_OPTIONAL_DATA) {
- LOGP(DSCCP, LOGL_ERROR,
- "optional data has length %u exceeding max of %u according to ITU-T Rec. Q.713
§4.4\n",
- optional_data.data_len, SCCP_MAX_OPTIONAL_DATA);
- return -EMSGSIZE;
- }
- msgb->l3h = &msgb->l2h[optional_data.data_start];
- result->data_len = optional_data.data_len;
- } else {
- result->data_len = 0;
- }
-
- return 0;
-}
-
-int _sccp_parse_connection_confirm(struct msgb *msgb, struct sccp_parse_result *result)
-{
- static uint32_t header_size =
- sizeof(struct sccp_connection_confirm);
- static const uint32_t optional_offset =
- offsetof(struct sccp_connection_confirm, optional_start);
-
- struct sccp_optional_data optional_data;
- struct sccp_connection_confirm *con;
-
- /* header check */
- if (msgb_l2len(msgb) < header_size) {
- LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
- msgb_l2len(msgb), header_size);
- return -1;
- }
-
- con = (struct sccp_connection_confirm *) msgb->l2h;
- result->destination_local_reference = &con->destination_local_reference;
- result->source_local_reference = &con->source_local_reference;
-
- memset(&optional_data, 0, sizeof(optional_data));
- if (_sccp_parse_optional_data(optional_offset + con->optional_start, msgb,
&optional_data) != 0) {
- LOGP(DSCCP, LOGL_ERROR, "parsing of optional data failed.\n");
- return -1;
- }
-
- if (optional_data.data_len != 0) {
- if (optional_data.data_len > SCCP_MAX_OPTIONAL_DATA) {
- LOGP(DSCCP, LOGL_ERROR,
- "optional data has length %u exceeding max of %u according to ITU-T Rec. Q.713
§4.3\n",
- optional_data.data_len, SCCP_MAX_OPTIONAL_DATA);
- return -EMSGSIZE;
- }
- msgb->l3h = &msgb->l2h[optional_data.data_start];
- result->data_len = optional_data.data_len;
- } else {
- result->data_len = 0;
- }
-
- return 0;
-}
-
-int _sccp_parse_connection_release_complete(struct msgb *msgb, struct sccp_parse_result
*result)
-{
- static size_t header_size = sizeof(struct sccp_connection_release_complete);
-
- struct sccp_connection_release_complete *cmpl;
-
- /* header check */
- if (msgb_l2len(msgb) < header_size) {
- LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %zu\n",
- msgb_l2len(msgb), header_size);
- return -1;
- }
-
- cmpl = (struct sccp_connection_release_complete *) msgb->l2h;
- result->source_local_reference = &cmpl->source_local_reference;
- result->destination_local_reference = &cmpl->destination_local_reference;
-
- return 0;
-}
-
-int _sccp_parse_connection_dt1(struct msgb *msgb, struct sccp_parse_result *result)
-{
- static size_t header_size = sizeof(struct sccp_data_form1);
- static size_t variable_offset = offsetof(struct sccp_data_form1, variable_start);
-
- struct sccp_data_form1 *dt1 = (struct sccp_data_form1 *)msgb->l2h;
-
- /* we don't have enough size for the struct */
- if (msgb_l2len(msgb) < header_size) {
- LOGP(DSCCP, LOGL_ERROR, "msgb > header_size %u %zu\n",
- msgb_l2len(msgb), header_size);
- return -1;
- }
-
- if (dt1->segmenting != 0) {
- LOGP(DSCCP, LOGL_ERROR, "This packet has segmenting, not supported: %d\n",
dt1->segmenting);
- return -1;
- }
-
- result->destination_local_reference = &dt1->destination_local_reference;
-
- /* some more size checks in here */
- if (msgb_l2len(msgb) < variable_offset + dt1->variable_start + 1) {
- LOGP(DSCCP, LOGL_ERROR, "Not enough space for variable start: %u %u\n",
- msgb_l2len(msgb), dt1->variable_start);
- return -1;
- }
-
- result->data_len = msgb->l2h[variable_offset + dt1->variable_start];
- msgb->l3h = &msgb->l2h[dt1->variable_start + variable_offset + 1];
-
- if (msgb_l3len(msgb) < result->data_len) {
- LOGP(DSCCP, LOGL_ERROR, "Not enough room for the payload: %u %u\n",
- msgb_l3len(msgb), result->data_len);
- return -1;
- }
-
- return 0;
-}
-
-struct udt_offsets {
- uint32_t header_size;
- uint32_t called_offset;
- uint32_t calling_offset;
- uint32_t data_offset;
-};
-
-static int _sccp_parse_unitdata(struct msgb *msgb, struct sccp_parse_result *result,
- const struct udt_offsets *offs)
-{
- uint8_t variable_called;
- uint8_t variable_calling;
- uint8_t variable_data;
-
- if (msgb_l2len(msgb) < offs->header_size) {
- LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
- msgb_l2len(msgb), offs->header_size);
- return -1;
- }
-
- variable_called = msgb->l2h[offs->called_offset];
- variable_calling = msgb->l2h[offs->calling_offset];
- variable_data = msgb->l2h[offs->data_offset];
-
- /* copy out the calling and called address. Add the off */
- if (copy_address(&result->called, offs->called_offset + variable_called, msgb)
!= 0)
- return -1;
-
- if (copy_address(&result->calling, offs->calling_offset + variable_calling,
msgb) != 0)
- return -1;
-
- /* we don't have enough size for the data */
- if (msgb_l2len(msgb) < offs->data_offset + variable_data + 1) {
- LOGP(DSCCP, LOGL_ERROR, "msgb < header + offset %u %u %u\n",
- msgb_l2len(msgb), offs->header_size, variable_data);
- return -1;
- }
-
-
- msgb->l3h = &msgb->l2h[offs->data_offset + variable_data + 1];
- result->data_len = msgb_l3len(msgb);
-
- if (msgb_l3len(msgb) < msgb->l3h[-1]) {
- LOGP(DSCCP, LOGL_ERROR, "msgb is truncated is: %u should: %u\n",
- msgb_l3len(msgb), msgb->l3h[-1]);
- return -1;
- }
-
- return 0;
-}
-
-int _sccp_parse_udt(struct msgb *msgb, struct sccp_parse_result *result)
-{
- static const struct udt_offsets offsets = {
- .header_size = sizeof(struct sccp_data_unitdata),
- .called_offset = offsetof(struct sccp_data_unitdata, variable_called),
- .calling_offset = offsetof(struct sccp_data_unitdata, variable_calling),
- .data_offset = offsetof(struct sccp_data_unitdata, variable_data),
- };
-
- return _sccp_parse_unitdata(msgb, result, &offsets);
-}
-
-int _sccp_parse_udts(struct msgb *msgb, struct sccp_parse_result *result)
-{
- static const struct udt_offsets offsets = {
- .header_size = sizeof(struct sccp_data_unitdata_service),
- .called_offset = offsetof(struct sccp_data_unitdata_service, variable_called),
- .calling_offset = offsetof(struct sccp_data_unitdata_service, variable_calling),
- .data_offset = offsetof(struct sccp_data_unitdata_service, variable_data),
- };
-
- return _sccp_parse_unitdata(msgb, result, &offsets);
-}
-
-static int _sccp_parse_xudt(struct msgb *msgb, struct sccp_parse_result *result)
-{
- static const struct udt_offsets offsets = {
- .header_size = sizeof(struct sccp_data_ext_unitdata),
- .called_offset = offsetof(struct sccp_data_ext_unitdata, variable_called),
- .calling_offset = offsetof(struct sccp_data_ext_unitdata, variable_calling),
- .data_offset = offsetof(struct sccp_data_ext_unitdata, variable_data),
- };
-
- return _sccp_parse_unitdata(msgb, result, &offsets);
-}
-
-static int _sccp_parse_xudts(struct msgb *msgb, struct sccp_parse_result *result)
-{
- static const struct udt_offsets offsets = {
- .header_size = sizeof(struct sccp_data_ext_unitdata_service),
- .called_offset = offsetof(struct sccp_data_ext_unitdata_service, variable_called),
- .calling_offset = offsetof(struct sccp_data_ext_unitdata_service, variable_calling),
- .data_offset = offsetof(struct sccp_data_ext_unitdata_service, variable_data),
- };
-
- return _sccp_parse_unitdata(msgb, result, &offsets);
-}
-
-static int _sccp_parse_it(struct msgb *msgb, struct sccp_parse_result *result)
-{
- static const uint32_t header_size = sizeof(struct sccp_data_it);
-
- struct sccp_data_it *it;
-
- if (msgb_l2len(msgb) < header_size) {
- LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
- msgb_l2len(msgb), header_size);
- return -1;
- }
-
- it = (struct sccp_data_it *) msgb->l2h;
- result->data_len = 0;
- result->source_local_reference = &it->source_local_reference;
- result->destination_local_reference = &it->destination_local_reference;
- return 0;
-}
-
-static int _sccp_parse_err(struct msgb *msgb, struct sccp_parse_result *result)
-{
- static const uint32_t header_size = sizeof(struct sccp_proto_err);
-
- struct sccp_proto_err *err;
-
- if (msgb_l2len(msgb) < header_size) {
- LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
- msgb_l2len(msgb), header_size);
- return -1;
- }
-
- err = (struct sccp_proto_err *) msgb->l2h;
- result->data_len = 0;
- result->destination_local_reference = &err->destination_local_reference;
- return 0;
-}
-
-int sccp_create_sccp_addr(struct msgb *msg, const struct sockaddr_sccp *sock)
-{
- uint8_t *len, *ai, *gti;
-
- len = msgb_put(msg, 1);
- ai = msgb_put(msg, 1);
-
-
- if (sock->gti)
- ai[0] = 0 << 6 | (sock->gti_ind & 0x0f) << 2 | 1 << 1;
- else
- ai[0] = 1 << 6 | 1 << 1;
-
- /* store a point code */
- if (sock->use_poi) {
- uint8_t *poi;
-
- ai[0] |= 0x01;
- poi = msgb_put(msg, 2);
- poi[0] = sock->poi[0];
- poi[1] = sock->poi[1];
- }
-
- /* copy the SSN */
- msgb_v_put(msg, sock->sccp_ssn);
-
- /* copy the gti if it is present */
- if (sock->gti) {
- gti = msgb_put(msg, sock->gti_len);
- memcpy(gti, sock->gti, sock->gti_len);
- }
-
- /* update the length now */
- len[0] = msg->tail - len - 1;
- return len[0] + 1;
-}
-
-/*
- * Send UDT. Currently we have a fixed address...
- */
-struct msgb *sccp_create_udt(int class, const struct sockaddr_sccp *in,
- const struct sockaddr_sccp *out, uint8_t *in_data, int len)
-{
- struct sccp_data_unitdata *udt;
- uint8_t *data;
- int out_len, inp_len;
-
- if (len > 256) {
- LOGP(DSCCP, LOGL_ERROR, "The payload is too big for one udt\n");
- return NULL;
- }
-
- struct msgb *msg = msgb_alloc_headroom(SCCP_MSG_SIZE,
- SCCP_MSG_HEADROOM, "sccp: udt");
- if (!msg)
- return NULL;
-
- msg->l2h = &msg->data[0];
- udt = (struct sccp_data_unitdata *)msgb_put(msg, sizeof(*udt));
-
- udt->type = SCCP_MSG_TYPE_UDT;
- udt->proto_class = class;
-
- /* for variable data we start with a size and the data */
- out_len = sccp_create_sccp_addr(msg, out);
- inp_len = sccp_create_sccp_addr(msg, in);
-
- /* update the offsets now */
- udt->variable_called = 3;
- udt->variable_calling = 2 + out_len;
- udt->variable_data = 1 + out_len + inp_len;
-
- /* copy the payload */
- data = msgb_put(msg, 1 + len);
- data[0] = len;
- memcpy(&data[1], in_data, len);
-
- return msg;
-}
-
-static int _sccp_send_data(int class, const struct sockaddr_sccp *in,
- const struct sockaddr_sccp *out,
- struct msgb *payload, void *ctx)
-{
- struct msgb *msg;
-
- msg = sccp_create_udt(class, in, out, payload->l3h, msgb_l3len(payload));
- if (!msg)
- return -1;
-
- _send_msg(NULL, msg, ctx);
- return 0;
-}
-
-static int _sccp_handle_read(struct msgb *msgb)
-{
- struct sccp_data_callback *cb;
- struct sccp_parse_result result;
-
- if (_sccp_parse_udt(msgb, &result) != 0)
- return -1;
-
- cb = _find_ssn(result.called.ssn);
- if (!cb || !cb->read_cb) {
- LOGP(DSCCP, LOGL_ERROR, "No routing for UDT for called SSN: %u\n",
result.called.ssn);
- return -1;
- }
-
- /* sanity check */
- return cb->read_cb(msgb, msgb_l3len(msgb), cb->read_context);
-}
-
-/*
- * handle connection orientated methods
- */
-static int source_local_reference_is_free(struct sccp_source_reference *reference)
-{
- struct sccp_connection *connection;
-
- llist_for_each_entry(connection, &sccp_connections, list) {
- if (memcmp(reference, &connection->source_local_reference, sizeof(*reference))
== 0)
- return -1;
- }
-
- return 0;
-}
-
-static int destination_local_reference_is_free(struct sccp_source_reference *reference)
-{
- struct sccp_connection *connection;
-
- llist_for_each_entry(connection, &sccp_connections, list) {
- if (memcmp(reference, &connection->destination_local_reference,
sizeof(*reference)) == 0)
- return -1;
- }
-
- return 0;
-}
-
-static int assign_source_local_reference(struct sccp_connection *connection)
-{
- static uint32_t last_ref = 0x30000;
- int wrapped = 0;
-
- do {
- struct sccp_source_reference reference;
- reference.octet1 = (last_ref >> 0) & 0xff;
- reference.octet2 = (last_ref >> 8) & 0xff;
- reference.octet3 = (last_ref >> 16) & 0xff;
-
- ++last_ref;
- /* do not use the reversed word and wrap around */
- if ((last_ref & 0x00FFFFFF) == 0x00FFFFFF) {
- LOGP(DSCCP, LOGL_DEBUG, "Wrapped searching for a free code\n");
- last_ref = 0;
- ++wrapped;
- }
-
- if (source_local_reference_is_free(&reference) == 0) {
- connection->source_local_reference = reference;
- return 0;
- }
- } while (wrapped != 2);
-
- LOGP(DSCCP, LOGL_ERROR, "Finding a free reference failed\n");
- return -1;
-}
-
-static void _sccp_set_connection_state(struct sccp_connection *connection, int
new_state)
-{
- int old_state = connection->connection_state;
-
- connection->connection_state = new_state;
- if (connection->state_cb)
- connection->state_cb(connection, old_state);
-}
-
-struct msgb *sccp_create_refuse(struct sccp_source_reference *src_ref, int cause, uint8_t
*inp, int length)
-{
- struct msgb *msgb;
- struct sccp_connection_refused *ref;
- uint8_t *data;
-
- msgb = msgb_alloc_headroom(SCCP_MSG_SIZE,
- SCCP_MSG_HEADROOM, "sccp ref");
- if (!msgb) {
- LOGP(DSCCP, LOGL_ERROR, "Failed to allocate refusal msg.\n");
- return NULL;
- }
-
- msgb->l2h = &msgb->data[0];
-
- ref = (struct sccp_connection_refused *) msgb_put(msgb, sizeof(*ref));
- ref->type = SCCP_MSG_TYPE_CREF;
- memcpy(&ref->destination_local_reference, src_ref,
- sizeof(struct sccp_source_reference));
- ref->cause = cause;
- ref->optional_start = 1;
-
- if (inp) {
- data = msgb_put(msgb, 1 + 1 + length);
- data[0] = SCCP_PNC_DATA;
- data[1] = length;
- memcpy(&data[2], inp, length);
- }
-
- data = msgb_put(msgb, 1);
- data[0] = SCCP_PNC_END_OF_OPTIONAL;
- return msgb;
-}
-
-static int _sccp_send_refuse(struct sccp_source_reference *src_ref, int cause, void
*ctx)
-{
- struct msgb *msgb = sccp_create_refuse(src_ref, cause, NULL, 0);
- if (!msgb)
- return -1;
-
- _send_msg(NULL, msgb, ctx);
- return 0;
-}
-
-struct msgb *sccp_create_cc(struct sccp_source_reference *src_ref,
- struct sccp_source_reference *dst_ref)
-{
- struct msgb *response;
- struct sccp_connection_confirm *confirm;
- uint8_t *optional_data;
-
- response = msgb_alloc_headroom(SCCP_MSG_SIZE,
- SCCP_MSG_HEADROOM, "sccp confirm");
- if (!response) {
- LOGP(DSCCP, LOGL_ERROR, "Failed to create SCCP Confirm.\n");
- return NULL;
- }
-
- response->l2h = &response->data[0];
-
- confirm = (struct sccp_connection_confirm *) msgb_put(response, sizeof(*confirm));
-
- confirm->type = SCCP_MSG_TYPE_CC;
- memcpy(&confirm->destination_local_reference,
- dst_ref, sizeof(*dst_ref));
- memcpy(&confirm->source_local_reference,
- src_ref, sizeof(*src_ref));
- confirm->proto_class = 2;
- confirm->optional_start = 1;
-
- optional_data = (uint8_t *) msgb_put(response, 1);
- optional_data[0] = SCCP_PNC_END_OF_OPTIONAL;
- return response;
-}
-
-static int _sccp_send_connection_confirm(struct sccp_connection *connection)
-{
- struct msgb *response;
-
- if (assign_source_local_reference(connection) != 0)
- return -1;
-
- response = sccp_create_cc(&connection->source_local_reference,
- &connection->destination_local_reference);
- if (!response)
- return -1;
-
- _send_msg(connection, response, NULL);
- _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_ESTABLISHED);
- return 0;
-}
-
-struct msgb *sccp_create_cr(const struct sccp_source_reference *src_ref,
- const struct sockaddr_sccp *called,
- const uint8_t *l3_data, size_t l3_length)
-{
- struct msgb *request;
- struct sccp_connection_request *req;
- uint8_t *data;
- int called_len;
-
- if (l3_data) {
- if (l3_length < 3 || l3_length > SCCP_MAX_OPTIONAL_DATA) {
- LOGP(DSCCP, LOGL_ERROR, "Invalid amount of data... %zu\n", l3_length);
- return NULL;
- }
- }
-
- request = msgb_alloc_headroom(SCCP_MSG_SIZE,
- SCCP_MSG_HEADROOM, "sccp connection request");
- request->l2h = &request->data[0];
- req = (struct sccp_connection_request *) msgb_put(request, sizeof(*req));
-
- req->type = SCCP_MSG_TYPE_CR;
- memcpy(&req->source_local_reference, src_ref, sizeof(*src_ref));
- req->proto_class = 2;
-
- /* write the called party address */
- called_len = sccp_create_sccp_addr(request, called);
-
- /* update the offsets */
- req->variable_called = 2;
- req->optional_start = 1 + called_len;
-
- /* write the payload */
- if (l3_data) {
- data = msgb_put(request, 2 + l3_length);
- data[0] = SCCP_PNC_DATA;
- data[1] = l3_length;
- memcpy(&data[2], l3_data, l3_length);
- }
-
- data = msgb_put(request, 1);
- data[0] = SCCP_PNC_END_OF_OPTIONAL;
-
- return request;
-}
-
-static int _sccp_send_connection_request(struct sccp_connection *connection,
- const struct sockaddr_sccp *called, struct msgb *msg)
-{
- struct msgb *request;
-
- /* try to find an id */
- if (assign_source_local_reference(connection) != 0) {
- LOGP(DSCCP, LOGL_ERROR, "Assigning a local reference failed.\n");
- _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_SETUP_ERROR);
- return -1;
- }
-
- request = sccp_create_cr(&connection->source_local_reference, called,
- msg ? msg->l3h : NULL,
- msg ? msgb_l3len(msg) : 0);
- if (!request) {
- _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_SETUP_ERROR);
- return -1;
- }
-
- llist_add_tail(&connection->list, &sccp_connections);
- _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_REQUEST);
-
- _send_msg(connection, request, NULL);
- return 0;
-}
-
-struct msgb *sccp_create_dt1(struct sccp_source_reference *dst_ref, uint8_t *inp_data,
uint8_t len)
-{
- struct msgb *msgb;
- struct sccp_data_form1 *dt1;
- uint8_t *data;
-
- msgb = msgb_alloc_headroom(SCCP_MSG_SIZE,
- SCCP_MSG_HEADROOM, "sccp dt1");
- if (!msgb) {
- LOGP(DSCCP, LOGL_ERROR, "Failed to create DT1 msg.\n");
- return NULL;
- }
-
- msgb->l2h = &msgb->data[0];
-
- dt1 = (struct sccp_data_form1 *) msgb_put(msgb, sizeof(*dt1));
- dt1->type = SCCP_MSG_TYPE_DT1;
- memcpy(&dt1->destination_local_reference, dst_ref,
- sizeof(struct sccp_source_reference));
- dt1->segmenting = 0;
-
- /* copy the data */
- dt1->variable_start = 1;
- data = msgb_put(msgb, 1 + len);
- data[0] = len;
- memcpy(&data[1], inp_data, len);
-
- return msgb;
-}
-
-static int _sccp_send_connection_data(struct sccp_connection *conn, struct msgb *_data)
-{
- struct msgb *msgb;
-
- if (msgb_l3len(_data) < 2 || msgb_l3len(_data) > 256) {
- LOGP(DSCCP, LOGL_ERROR, "data size too big, segmenting unimplemented.\n");
- return -1;
- }
-
- msgb = sccp_create_dt1(&conn->destination_local_reference,
- _data->l3h, msgb_l3len(_data));
- if (!msgb)
- return -1;
-
- _send_msg(conn, msgb, NULL);
- return 0;
-}
-
-static int _sccp_send_connection_it(struct sccp_connection *conn)
-{
- struct msgb *msgb;
- struct sccp_data_it *it;
-
- msgb = msgb_alloc_headroom(SCCP_MSG_SIZE,
- SCCP_MSG_HEADROOM, "sccp it");
- msgb->l2h = &msgb->data[0];
- it = (struct sccp_data_it *) msgb_put(msgb, sizeof(*it));
- it->type = SCCP_MSG_TYPE_IT;
- memcpy(&it->destination_local_reference,
&conn->destination_local_reference,
- sizeof(struct sccp_source_reference));
- memcpy(&it->source_local_reference, &conn->source_local_reference,
- sizeof(struct sccp_source_reference));
-
- it->proto_class = 0x2;
- it->sequencing[0] = it->sequencing[1] = 0;
- it->credit = 0;
-
- _send_msg(conn, msgb, NULL);
- return 0;
-}
-
-struct msgb *sccp_create_rlsd(struct sccp_source_reference *src_ref,
- struct sccp_source_reference *dst_ref, int cause)
-{
- struct msgb *msg;
- struct sccp_connection_released *rel;
- uint8_t *data;
-
- msg = msgb_alloc_headroom(SCCP_MSG_SIZE, SCCP_MSG_HEADROOM,
- "sccp: connection released");
- if (!msg) {
- LOGP(DSCCP, LOGL_ERROR, "Failed to allocate RLSD.\n");
- return NULL;
- }
-
- msg->l2h = &msg->data[0];
- rel = (struct sccp_connection_released *) msgb_put(msg, sizeof(*rel));
- rel->type = SCCP_MSG_TYPE_RLSD;
- rel->release_cause = cause;
-
- /* copy the source references */
- memcpy(&rel->destination_local_reference, dst_ref,
- sizeof(struct sccp_source_reference));
- memcpy(&rel->source_local_reference, src_ref,
- sizeof(struct sccp_source_reference));
-
- data = msgb_put(msg, 1);
- data[0] = SCCP_PNC_END_OF_OPTIONAL;
- return msg;
-}
-
-static int _sccp_send_connection_released(struct sccp_connection *conn, int cause)
-{
- struct msgb *msg;
-
- msg = sccp_create_rlsd(&conn->source_local_reference,
- &conn->destination_local_reference,
- cause);
- if (!msg)
- return -1;
-
- _sccp_set_connection_state(conn, SCCP_CONNECTION_STATE_RELEASE);
- _send_msg(conn, msg, NULL);
- return 0;
-}
-
-/*
- * Open a connection. The following is going to happen:
- *
- * - Verify the packet, e.g. that we have no other connection
- * that id.
- * - Ask the user if he wants to accept the connection
- * - Try to open the connection by assigning a source local reference
- * and sending the packet
- */
-static int _sccp_handle_connection_request(struct msgb *msgb, void *ctx)
-{
- struct sccp_parse_result result;
-
- struct sccp_data_callback *cb;
- struct sccp_connection *connection;
-
- if (_sccp_parse_connection_request(msgb, &result) != 0)
- return -1;
-
- cb = _find_ssn(result.called.ssn);
- if (!cb || !cb->accept_cb) {
- LOGP(DSCCP, LOGL_ERROR, "No routing for CR for called SSN: %u\n",
result.called.ssn);
- return -1;
- }
-
- /* check if the system wants this connection */
- connection = talloc_zero(tall_sccp_ctx, struct sccp_connection);
- if (!connection) {
- LOGP(DSCCP, LOGL_ERROR, "Allocation failed\n");
- return -1;
- }
-
- /*
- * sanity checks:
- * - Is the source_local_reference in any other connection?
- * then will call accept, assign a "destination" local reference
- * and send a connection confirm, otherwise we will send a refuseed
- * one....
- */
- if (destination_local_reference_is_free(result.source_local_reference) != 0) {
- LOGP(DSCCP, LOGL_ERROR, "Need to reject connection with existing
reference\n");
- _sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_SCCP_FAILURE, ctx);
- talloc_free(connection);
- return -1;
- }
-
- connection->incoming = 1;
- connection->destination_local_reference = *result.source_local_reference;
-
- if (cb->accept_cb(connection, cb->accept_context) != 0) {
- _sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_END_USER_ORIGINATED,
ctx);
- _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_REFUSED);
- talloc_free(connection);
- return 0;
- }
-
-
- llist_add_tail(&connection->list, &sccp_connections);
-
- if (_sccp_send_connection_confirm(connection) != 0) {
- LOGP(DSCCP, LOGL_ERROR, "Sending confirm failed... no available source
reference?\n");
-
- _sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_SCCP_FAILURE, ctx);
- _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_REFUSED);
- llist_del(&connection->list);
- talloc_free(connection);
-
- return -1;
- }
-
- /*
- * If we have data let us forward things.
- */
- if (result.data_len != 0 && connection->data_cb) {
- connection->data_cb(connection, msgb, result.data_len);
- }
-
- return 0;
-}
-
-/* Handle the release confirmed */
-static int _sccp_handle_connection_release_complete(struct msgb *msgb)
-{
- struct sccp_parse_result result = {};
- struct sccp_connection *conn;
-
- if (_sccp_parse_connection_release_complete(msgb, &result) != 0)
- return -1;
-
- /* find the connection */
- llist_for_each_entry(conn, &sccp_connections, list) {
- if (conn->data_cb
- && memcmp(&conn->source_local_reference,
- result.destination_local_reference,
- sizeof(conn->source_local_reference)) == 0
- && memcmp(&conn->destination_local_reference,
- result.source_local_reference,
- sizeof(conn->destination_local_reference)) == 0) {
- goto found;
- }
- }
-
-
- LOGP(DSCCP, LOGL_ERROR, "Release complete of unknown connection\n");
- return -1;
-
-found:
- llist_del(&conn->list);
- _sccp_set_connection_state(conn, SCCP_CONNECTION_STATE_RELEASE_COMPLETE);
- return 0;
-}
-
-/* Handle the Data Form 1 message */
-static int _sccp_handle_connection_dt1(struct msgb *msgb)
-{
- struct sccp_parse_result result;
- struct sccp_connection *conn;
-
- if (_sccp_parse_connection_dt1(msgb, &result) != 0)
- return -1;
-
- /* lookup if we have a connection with the given reference */
- llist_for_each_entry(conn, &sccp_connections, list) {
- if (conn->data_cb
- && memcmp(&conn->source_local_reference,
- result.destination_local_reference,
- sizeof(conn->source_local_reference)) == 0) {
- goto found;
- }
- }
-
- LOGP(DSCCP, LOGL_ERROR, "No connection found for dt1 data\n");
- return -1;
-
-found:
- conn->data_cb(conn, msgb, result.data_len);
- return 0;
-}
-
-/* confirm a connection release */
-static int _sccp_send_connection_release_complete(struct sccp_connection *connection)
-{
- struct msgb *msgb;
- struct sccp_connection_release_complete *rlc;
-
- msgb = msgb_alloc_headroom(SCCP_MSG_SIZE,
- SCCP_MSG_HEADROOM, "sccp rlc");
- msgb->l2h = &msgb->data[0];
-
- rlc = (struct sccp_connection_release_complete *) msgb_put(msgb, sizeof(*rlc));
- rlc->type = SCCP_MSG_TYPE_RLC;
- memcpy(&rlc->destination_local_reference,
- &connection->destination_local_reference, sizeof(struct
sccp_source_reference));
- memcpy(&rlc->source_local_reference,
- &connection->source_local_reference, sizeof(struct
sccp_source_reference));
-
- _send_msg(connection, msgb, NULL);
-
- /*
- * Remove from the list of active connections and set the state. User code
- * should now free the entry.
- */
- llist_del(&connection->list);
- _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_RELEASE_COMPLETE);
- return 0;
-}
-
-/* connection released, send a released confirm */
-static int _sccp_handle_connection_released(struct msgb *msgb)
-{
- struct sccp_parse_result result;
- struct sccp_connection *conn;
-
- if (_sccp_parse_connection_released(msgb, &result) == -1)
- return -1;
-
- /* lookup if we have a connection with the given reference */
- llist_for_each_entry(conn, &sccp_connections, list) {
- if (conn->data_cb
- && memcmp(&conn->source_local_reference,
- result.destination_local_reference,
- sizeof(conn->source_local_reference)) == 0
- && memcmp(&conn->destination_local_reference,
- result.source_local_reference,
- sizeof(conn->destination_local_reference)) == 0) {
- goto found;
- }
- }
-
-
- LOGP(DSCCP, LOGL_ERROR, "Unknown connection was released.\n");
- return -1;
-
- /* we have found a connection */
-found:
- /* optional data */
- if (result.data_len != 0 && conn->data_cb) {
- conn->data_cb(conn, msgb, result.data_len);
- }
-
- /* generate a response */
- if (_sccp_send_connection_release_complete(conn) != 0) {
- LOGP(DSCCP, LOGL_ERROR, "Sending release confirmed failed\n");
- return -1;
- }
-
- return 0;
-}
-
-static int _sccp_handle_connection_refused(struct msgb *msgb)
-{
- struct sccp_parse_result result;
- struct sccp_connection *conn;
-
- if (_sccp_parse_connection_refused(msgb, &result) != 0)
- return -1;
-
- /* lookup if we have a connection with the given reference */
- llist_for_each_entry(conn, &sccp_connections, list) {
- if (conn->incoming == 0 && conn->data_cb
- && memcmp(&conn->source_local_reference,
- result.destination_local_reference,
- sizeof(conn->source_local_reference)) == 0) {
- goto found;
- }
- }
-
- LOGP(DSCCP, LOGL_ERROR, "Refused but no connection found\n");
- return -1;
-
-found:
- /* optional data */
- if (result.data_len != 0 && conn->data_cb) {
- conn->data_cb(conn, msgb, result.data_len);
- }
-
-
- llist_del(&conn->list);
- _sccp_set_connection_state(conn, SCCP_CONNECTION_STATE_REFUSED);
- return 0;
-}
-
-static int _sccp_handle_connection_confirm(struct msgb *msgb)
-{
- struct sccp_parse_result result;
- struct sccp_connection *conn;
-
- if (_sccp_parse_connection_confirm(msgb, &result) != 0)
- return -1;
-
- /* lookup if we have a connection with the given reference */
- llist_for_each_entry(conn, &sccp_connections, list) {
- if (conn->incoming == 0 && conn->data_cb
- && memcmp(&conn->source_local_reference,
- result.destination_local_reference,
- sizeof(conn->source_local_reference)) == 0) {
- goto found;
- }
- }
-
- LOGP(DSCCP, LOGL_ERROR, "Confirmed but no connection found\n");
- return -1;
-
-found:
- /* copy the addresses of the connection */
- conn->destination_local_reference = *result.source_local_reference;
- _sccp_set_connection_state(conn, SCCP_CONNECTION_STATE_ESTABLISHED);
-
- /* optional data */
- if (result.data_len != 0 && conn->data_cb) {
- conn->data_cb(conn, msgb, result.data_len);
- }
-
- return 0;
-}
-
-
-int sccp_system_init(void (*outgoing)(struct sccp_connection *conn, struct msgb *data,
void *, void *), void *ctx)
-{
- sccp_system.write_data = outgoing;
- sccp_system.write_context = ctx;
-
- return 0;
-}
-
-/* oh my god a real SCCP packet. need to dispatch it now */
-int sccp_system_incoming(struct msgb *msgb)
-{
- return sccp_system_incoming_ctx(msgb, NULL);
-}
-
-int sccp_system_incoming_ctx(struct msgb *msgb, void *ctx)
-{
- if (msgb_l2len(msgb) < 1 ) {
- LOGP(DSCCP, LOGL_ERROR, "Too short packet\n");
- return -1;
- }
-
- int type = msgb->l2h[0];
-
- switch(type) {
- case SCCP_MSG_TYPE_CR:
- return _sccp_handle_connection_request(msgb, ctx);
- break;
- case SCCP_MSG_TYPE_RLSD:
- return _sccp_handle_connection_released(msgb);
- break;
- case SCCP_MSG_TYPE_CREF:
- return _sccp_handle_connection_refused(msgb);
- break;
- case SCCP_MSG_TYPE_CC:
- return _sccp_handle_connection_confirm(msgb);
- break;
- case SCCP_MSG_TYPE_RLC:
- return _sccp_handle_connection_release_complete(msgb);
- break;
- case SCCP_MSG_TYPE_DT1:
- return _sccp_handle_connection_dt1(msgb);
- break;
- case SCCP_MSG_TYPE_UDT:
- return _sccp_handle_read(msgb);
- break;
- default:
- LOGP(DSCCP, LOGL_ERROR, "unimplemented msg type: %d\n", type);
- };
-
- return -1;
-}
-
-/* create a packet from the data */
-int sccp_connection_write(struct sccp_connection *connection, struct msgb *data)
-{
- if (connection->connection_state < SCCP_CONNECTION_STATE_CONFIRM
- || connection->connection_state > SCCP_CONNECTION_STATE_ESTABLISHED) {
- LOGP(DSCCP, LOGL_ERROR, "sccp_connection_write: Wrong connection state: %p
%d\n",
- connection, connection->connection_state);
- return -1;
- }
-
- return _sccp_send_connection_data(connection, data);
-}
-
-/*
- * Send a Inactivity Test message. The owner of the connection
- * should start a timer and call this method regularily. Calling
- * this every 60 seconds should be good enough.
- */
-int sccp_connection_send_it(struct sccp_connection *connection)
-{
- if (connection->connection_state < SCCP_CONNECTION_STATE_CONFIRM
- || connection->connection_state > SCCP_CONNECTION_STATE_ESTABLISHED) {
- LOGP(DSCCP, LOGL_ERROR, "sccp_connection_write: Wrong connection state: %p
%d\n",
- connection, connection->connection_state);
- return -1;
- }
-
- return _sccp_send_connection_it(connection);
-}
-
-/* send a connection release and wait for the connection released */
-int sccp_connection_close(struct sccp_connection *connection, int cause)
-{
- if (connection->connection_state < SCCP_CONNECTION_STATE_CONFIRM
- || connection->connection_state > SCCP_CONNECTION_STATE_ESTABLISHED) {
- LOGP(DSCCP, LOGL_ERROR, "Can not close the connection. It was never opened: %p
%d\n",
- connection, connection->connection_state);
- return -1;
- }
-
- return _sccp_send_connection_released(connection, cause);
-}
-
-int sccp_connection_free(struct sccp_connection *connection)
-{
- if (connection->connection_state > SCCP_CONNECTION_STATE_NONE
- && connection->connection_state <
SCCP_CONNECTION_STATE_RELEASE_COMPLETE) {
- LOGP(DSCCP, LOGL_ERROR, "The connection needs to be released before it is
freed");
- return -1;
- }
-
- talloc_free(connection);
- return 0;
-}
-
-int sccp_connection_force_free(struct sccp_connection *con)
-{
- if (con->connection_state > SCCP_CONNECTION_STATE_NONE &&
- con->connection_state < SCCP_CONNECTION_STATE_RELEASE_COMPLETE)
- llist_del(&con->list);
-
- con->connection_state = SCCP_CONNECTION_STATE_REFUSED;
- sccp_connection_free(con);
- return 0;
-}
-
-struct sccp_connection *sccp_connection_socket(void)
-{
- return talloc_zero(tall_sccp_ctx, struct sccp_connection);
-}
-
-int sccp_connection_connect(struct sccp_connection *conn,
- const struct sockaddr_sccp *local,
- struct msgb *data)
-{
- return _sccp_send_connection_request(conn, local, data);
-}
-
-int sccp_connection_set_incoming(const struct sockaddr_sccp *sock,
- int (*accept_cb)(struct sccp_connection *, void *), void *context)
-{
- struct sccp_data_callback *cb;
-
- if (!sock)
- return -2;
-
- cb = _find_ssn(sock->sccp_ssn);
- if (!cb)
- return -1;
-
- cb->accept_cb = accept_cb;
- cb->accept_context = context;
- return 0;
-}
-
-int sccp_write(struct msgb *data, const struct sockaddr_sccp *in,
- const struct sockaddr_sccp *out, int class, void *ctx)
-{
- return _sccp_send_data(class, in, out, data, ctx);
-}
-
-int sccp_set_read(const struct sockaddr_sccp *sock,
- int (*read_cb)(struct msgb *, unsigned int, void *), void *context)
-{
- struct sccp_data_callback *cb;
-
- if (!sock)
- return -2;
-
- cb = _find_ssn(sock->sccp_ssn);
- if (!cb)
- return -1;
-
- cb->read_cb = read_cb;
- cb->read_context = context;
- return 0;
-}
-
-osmo_static_assert(sizeof(struct sccp_source_reference) <= sizeof(uint32_t),
enough_space);
-
-uint32_t sccp_src_ref_to_int(struct sccp_source_reference *ref)
-{
- uint32_t src_ref = 0;
-#if OSMO_IS_LITTLE_ENDIAN
- memcpy(&src_ref, ref, sizeof(*ref));
-#elif OSMO_IS_BIG_ENDIAN
- *(((uint8_t*)(&src_ref))+3) = ref->octet1;
- *(((uint8_t*)(&src_ref))+2) = ref->octet2;
- *(((uint8_t*)(&src_ref))+1) = ref->octet3;
-#endif
- return src_ref;
-}
-
-struct sccp_source_reference sccp_src_ref_from_int(uint32_t int_ref)
-{
- struct sccp_source_reference ref;
-#if OSMO_IS_LITTLE_ENDIAN
- memcpy(&ref, &int_ref, sizeof(ref));
-#elif OSMO_IS_BIG_ENDIAN
- ref.octet1 = *(((uint8_t*)(&int_ref))+3);
- ref.octet2 = *(((uint8_t*)(&int_ref))+2);
- ref.octet3 = *(((uint8_t*)(&int_ref))+1);
-#endif
- return ref;
-}
-
-int sccp_determine_msg_type(struct msgb *msg)
-{
- if (msgb_l2len(msg) < 1)
- return -1;
-
- return msg->l2h[0];
-}
-
-int sccp_parse_header(struct msgb *msg, struct sccp_parse_result *result)
-{
- int type;
-
- if (msgb_l2len(msg) < 1)
- return -1;
-
- type = msg->l2h[0];
- switch(type) {
- case SCCP_MSG_TYPE_CR:
- return _sccp_parse_connection_request(msg, result);
- break;
- case SCCP_MSG_TYPE_RLSD:
- return _sccp_parse_connection_released(msg, result);
- break;
- case SCCP_MSG_TYPE_CREF:
- return _sccp_parse_connection_refused(msg, result);
- break;
- case SCCP_MSG_TYPE_CC:
- return _sccp_parse_connection_confirm(msg, result);
- break;
- case SCCP_MSG_TYPE_RLC:
- return _sccp_parse_connection_release_complete(msg, result);
- break;
- case SCCP_MSG_TYPE_DT1:
- return _sccp_parse_connection_dt1(msg, result);
- break;
- case SCCP_MSG_TYPE_UDT:
- return _sccp_parse_udt(msg, result);
- break;
- case SCCP_MSG_TYPE_UDTS:
- return _sccp_parse_udts(msg, result);
- break;
- case SCCP_MSG_TYPE_XUDT:
- return _sccp_parse_xudt(msg, result);
- break;
- case SCCP_MSG_TYPE_XUDTS:
- return _sccp_parse_xudts(msg, result);
- break;
- case SCCP_MSG_TYPE_IT:
- return _sccp_parse_it(msg, result);
- break;
- case SCCP_MSG_TYPE_ERR:
- return _sccp_parse_err(msg, result);
- break;
- };
-
- LOGP(DSCCP, LOGL_ERROR, "Unimplemented MSG Type: 0x%x\n", type);
- return -1;
-}
-
-static __attribute__((constructor)) void on_dso_load(void)
-{
- tall_sccp_ctx = talloc_named_const(NULL, 1, "sccp");
-}
-
-static __attribute__((destructor)) void on_dso_unload(void)
-{
- talloc_report_full(tall_sccp_ctx, stderr);
-}
-
-void sccp_set_log_area(int log_area)
-{
- DSCCP = log_area;
-}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 34bba67..6a150e1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = xua sccp mtp m2ua ss7 vty
+SUBDIRS = xua m2ua ss7 vty
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
$(srcdir)/package.m4: $(top_srcdir)/configure.ac
diff --git a/tests/mtp/Makefile.am b/tests/mtp/Makefile.am
deleted file mode 100644
index a3f22f1..0000000
--- a/tests/mtp/Makefile.am
+++ /dev/null
@@ -1,9 +0,0 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
-AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS)
-AM_LDFLAGS = -no-install
-
-check_PROGRAMS = mtp_parse_test
-
-EXTRA_DIST = mtp_parse_test.ok
-
-mtp_parse_test_SOURCES = mtp_parse_test.c
diff --git a/tests/mtp/mtp_parse_test.c b/tests/mtp/mtp_parse_test.c
deleted file mode 100644
index 92c34ca..0000000
--- a/tests/mtp/mtp_parse_test.c
+++ /dev/null
@@ -1,643 +0,0 @@
-/* MTP Layer3 parsing tests */
-#include <osmocom/mtp/mtp_level3.h>
-
-#include <arpa/inet.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
-
-struct mtp_test {
- const uint8_t *input;
- const uint16_t length;
- struct mtp_level_3_hdr hdr;
-
- int has_mng;
- struct mtp_level_3_mng mng;
-
- int has_prohib;
- struct mtp_level_3_prohib prohib;
-};
-
-static const unsigned char pkt1[] = {
-0x81, 0x88, 0xc0, 0x16, 0x00, 0x11, 0xe0, 0x62,
-0x61, 0x72, 0x62, 0x61, 0x6e, 0x6f, 0x62, 0x61,
-0x72, 0x6e, 0x61, 0x62, 0x6f };
-
-static const unsigned char pkt3[] = {
-0x81, 0x88, 0xc0, 0x16, 0x00, 0x21, 0xe0, 0x41,
-0x6d, 0x69, 0x74, 0x20, 0x43, 0x68, 0x61, 0x6e,
-0x64, 0x72, 0x61, 0x00, 0x00 };
-
-static const unsigned char pkt7[] = {
-0x80, 0x88, 0xc0, 0x16, 0x00, 0x14, 0x56, 0x00 };
-
-#if 0
-static const unsigned char pkt2[] = {
-0x81, 0x5b, 0x00, 0x22, 0x00, 0x11, 0xe0, 0x41,
-0x6d, 0x69, 0x74, 0x20, 0x43, 0x68, 0x61, 0x6e,
-0x64, 0x72, 0x61, 0x00, 0x00 };
-
-static const unsigned char pkt4[] = {
-0x81, 0x5b, 0x00, 0x22, 0x00, 0x21, 0xe0, 0x62,
-0x61, 0x72, 0x62, 0x61, 0x6e, 0x6f, 0x62, 0x61,
-0x72, 0x6e, 0x61, 0x62, 0x6f };
-
-static const unsigned char pkt5[] = {
-0x81, 0x88, 0xc0, 0x16, 0x00, 0x21, 0xe0, 0x62,
-0x61, 0x72, 0x62, 0x61, 0x6e, 0x6f, 0x62, 0x61,
-0x72, 0x6e, 0x61, 0x62, 0x6f };
-
-static const unsigned char pkt6[] = {
-0x80, 0x5b, 0x00, 0x22, 0x00, 0x17 };
-
-static const unsigned char pkt8[] = {
-0x80, 0x88, 0xc0, 0x16, 0x00, 0x14, 0x00, 0x00 };
-
-static const unsigned char pkt9[] = {
-0x80, 0x88, 0xc0, 0x16, 0x00, 0x17 };
-
-static const unsigned char pkt10[] = {
-0x83, 0x5b, 0x00, 0x22, 0x20, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0x01, 0x04,
-0xc3, 0x88, 0x00, 0x01, 0x05, 0x03, 0xfe, 0x5b,
-0x00, 0x01 };
-
-static const unsigned char pkt11[] = {
-0x83, 0x88, 0xc0, 0x16, 0xd0, 0x09, 0x00, 0x03,
-0x05, 0x07, 0x02, 0x42, 0x01, 0x02, 0x42, 0x01,
-0x05, 0x01, 0xfe, 0x5b, 0x00, 0x00 };
-
-static const unsigned char pkt12[] = {
-0x83, 0x5b, 0x00, 0x22, 0x30, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x30,
-0x04, 0x01, 0x20 };
-
-static const unsigned char pkt13[] = {
-0x83, 0x5b, 0x00, 0x22, 0x40, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x0f, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt14[] = {
-0x83, 0x5b, 0x00, 0x22, 0x50, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x10, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt15[] = {
-0x83, 0x5b, 0x00, 0x22, 0x60, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x11, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt16[] = {
-0x83, 0x5b, 0x00, 0x22, 0x70, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x12, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt17[] = {
-0x83, 0x5b, 0x00, 0x22, 0x80, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x13, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt18[] = {
-0x83, 0x5b, 0x00, 0x22, 0x90, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x14, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt19[] = {
-0x83, 0x5b, 0x00, 0x22, 0xa0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x15, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt20[] = {
-0x83, 0x5b, 0x00, 0x22, 0xb0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x16, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt21[] = {
-0x83, 0x5b, 0x00, 0x22, 0xc0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x17, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt22[] = {
-0x83, 0x5b, 0x00, 0x22, 0xd0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x18, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt23[] = {
-0x83, 0x5b, 0x00, 0x22, 0xe0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x19, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt24[] = {
-0x83, 0x5b, 0x00, 0x22, 0xf0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x1a, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt25[] = {
-0x83, 0x5b, 0x00, 0x22, 0x00, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x1b, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt26[] = {
-0x83, 0x5b, 0x00, 0x22, 0x10, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x1c, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt27[] = {
-0x83, 0x5b, 0x00, 0x22, 0x20, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x1d, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt28[] = {
-0x83, 0x5b, 0x00, 0x22, 0x30, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x1e, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt29[] = {
-0x83, 0x88, 0xc0, 0x16, 0x60, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x0f };
-
-static const unsigned char pkt30[] = {
-0x83, 0x88, 0xc0, 0x16, 0x70, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x10 };
-
-static const unsigned char pkt31[] = {
-0x83, 0x88, 0xc0, 0x16, 0x80, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x11 };
-
-static const unsigned char pkt32[] = {
-0x83, 0x88, 0xc0, 0x16, 0x90, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x12 };
-
-static const unsigned char pkt33[] = {
-0x83, 0x88, 0xc0, 0x16, 0xa0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x13 };
-
-static const unsigned char pkt34[] = {
-0x83, 0x88, 0xc0, 0x16, 0xb0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x14 };
-
-static const unsigned char pkt35[] = {
-0x83, 0x88, 0xc0, 0x16, 0xc0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x15 };
-
-static const unsigned char pkt36[] = {
-0x83, 0x88, 0xc0, 0x16, 0xd0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x16 };
-
-static const unsigned char pkt37[] = {
-0x83, 0x88, 0xc0, 0x16, 0xe0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x17 };
-
-static const unsigned char pkt38[] = {
-0x83, 0x88, 0xc0, 0x16, 0xf0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x18 };
-
-static const unsigned char pkt39[] = {
-0x83, 0x88, 0xc0, 0x16, 0x00, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x19 };
-
-static const unsigned char pkt40[] = {
-0x83, 0x88, 0xc0, 0x16, 0x10, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x1a };
-
-static const unsigned char pkt41[] = {
-0x83, 0x88, 0xc0, 0x16, 0x20, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x1b };
-
-static const unsigned char pkt42[] = {
-0x83, 0x88, 0xc0, 0x16, 0x30, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x1c };
-
-static const unsigned char pkt43[] = {
-0x83, 0x88, 0xc0, 0x16, 0x40, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x1d };
-
-static const unsigned char pkt44[] = {
-0x83, 0x88, 0xc0, 0x16, 0x50, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x1e };
-
-static const unsigned char pkt45[] = {
-0x83, 0x5b, 0x00, 0x22, 0x40, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x0f, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt46[] = {
-0x83, 0x5b, 0x00, 0x22, 0x50, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x10, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt47[] = {
-0x83, 0x5b, 0x00, 0x22, 0x60, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x11, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt48[] = {
-0x83, 0x5b, 0x00, 0x22, 0x70, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x12, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt49[] = {
-0x83, 0x5b, 0x00, 0x22, 0x80, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x13, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt50[] = {
-0x83, 0x5b, 0x00, 0x22, 0x90, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x14, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt51[] = {
-0x83, 0x5b, 0x00, 0x22, 0xa0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x15, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt52[] = {
-0x83, 0x5b, 0x00, 0x22, 0xb0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x16, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt53[] = {
-0x83, 0x5b, 0x00, 0x22, 0xc0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x17, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt54[] = {
-0x83, 0x5b, 0x00, 0x22, 0xd0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x18, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt55[] = {
-0x83, 0x5b, 0x00, 0x22, 0xe0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x19, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt56[] = {
-0x83, 0x5b, 0x00, 0x22, 0xf0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x1a, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt57[] = {
-0x83, 0x5b, 0x00, 0x22, 0x00, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x1b, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt58[] = {
-0x83, 0x5b, 0x00, 0x22, 0x10, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x1c, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt59[] = {
-0x83, 0x5b, 0x00, 0x22, 0x20, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x1d, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt60[] = {
-0x83, 0x5b, 0x00, 0x22, 0x30, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0xc3, 0x5b, 0x00, 0xfe, 0x04,
-0x43, 0x88, 0x00, 0xfe, 0x09, 0x00, 0x07, 0x40,
-0x01, 0x00, 0x1e, 0x04, 0x01, 0x07 };
-
-static const unsigned char pkt61[] = {
-0x83, 0x88, 0xc0, 0x16, 0x60, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x0f };
-
-static const unsigned char pkt62[] = {
-0x83, 0x88, 0xc0, 0x16, 0x70, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x10 };
-
-static const unsigned char pkt63[] = {
-0x83, 0x88, 0xc0, 0x16, 0x80, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x11 };
-
-static const unsigned char pkt64[] = {
-0x83, 0x88, 0xc0, 0x16, 0x90, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x12 };
-
-static const unsigned char pkt65[] = {
-0x83, 0x88, 0xc0, 0x16, 0xa0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x13 };
-
-static const unsigned char pkt66[] = {
-0x83, 0x88, 0xc0, 0x16, 0xb0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x14 };
-
-static const unsigned char pkt67[] = {
-0x83, 0x88, 0xc0, 0x16, 0xc0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x15 };
-
-static const unsigned char pkt68[] = {
-0x83, 0x88, 0xc0, 0x16, 0xd0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x16 };
-
-static const unsigned char pkt69[] = {
-0x83, 0x88, 0xc0, 0x16, 0xe0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x17 };
-
-static const unsigned char pkt70[] = {
-0x83, 0x88, 0xc0, 0x16, 0xf0, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x18 };
-
-static const unsigned char pkt71[] = {
-0x83, 0x88, 0xc0, 0x16, 0x00, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x19 };
-
-static const unsigned char pkt72[] = {
-0x83, 0x88, 0xc0, 0x16, 0x10, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x1a };
-
-static const unsigned char pkt73[] = {
-0x83, 0x88, 0xc0, 0x16, 0x20, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x1b };
-
-static const unsigned char pkt74[] = {
-0x83, 0x88, 0xc0, 0x16, 0x30, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x1c };
-
-static const unsigned char pkt75[] = {
-0x83, 0x88, 0xc0, 0x16, 0x40, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x1d };
-
-static const unsigned char pkt76[] = {
-0x83, 0x88, 0xc0, 0x16, 0x50, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x06, 0x00, 0x04, 0x48,
-0x01, 0x00, 0x1e };
-
-static const unsigned char pkt77[] = {
-0x83, 0x88, 0xc0, 0x16, 0x60, 0x09, 0x00, 0x03,
-0x07, 0x0b, 0x04, 0x43, 0x88, 0x00, 0xfe, 0x04,
-0x43, 0x5b, 0x00, 0xfe, 0x03, 0x00, 0x01, 0x31 };
-#endif
-
-static struct mtp_test tests[] = {
- {
- .input = pkt1,
- .length = sizeof(pkt1),
- .hdr = {
- .ni = 0x02,
- .spare = 0x00,
- .ser_ind = 0x01,
- },
- .has_mng = 1,
- .mng = {
- .cmn = {
- .h0 = 0x01,
- .h1 = 0x01,
- },
- .length = 14,
- },
- },
-
- {
- .input = pkt3,
- .length = sizeof(pkt3),
- .hdr = {
- .ni = 0x02,
- .spare = 0x00,
- .ser_ind = 0x01,
- },
- .has_mng = 1,
- .mng = {
- .cmn = {
- .h0 = 0x01,
- .h1 = 0x02,
- },
-
- .length = 14,
- },
- },
-
- {
- .input = pkt7,
- .length = sizeof(pkt7),
- .hdr = {
- .ni = 2,
- .spare = 0,
- .ser_ind = 0,
- },
-
- .has_prohib = 1,
- .prohib = {
- .cmn = {
- .h0 = 0x04,
- .h1 = 0x1,
- },
-
- },
- }
-};
-
-static void check_hdr(const uint8_t *data, const struct mtp_level_3_hdr *t_hdr)
-{
- struct mtp_level_3_hdr *hdr;
- hdr = (struct mtp_level_3_hdr *) data;
- if (memcmp(hdr, t_hdr, sizeof(*hdr)) == 0)
- return;
-
- if (hdr->ni != t_hdr->ni)
- fprintf(stderr, "NI failed.\n");
- if (hdr->spare != t_hdr->spare)
- fprintf(stderr, "spare not equal\n");
- if (hdr->ser_ind != t_hdr->ser_ind)
- fprintf(stderr, "ser_ind not equal\n");
- if (hdr->addr != t_hdr->addr)
- fprintf(stderr, "routing data not equal\n");
-
- fprintf(stderr, "FAIL: Comparing headers failed.\n");
- abort();
-}
-
-static void check_mng(const uint8_t *data, const struct mtp_level_3_mng *t_mng)
-{
- struct mtp_level_3_hdr *hdr = (struct mtp_level_3_hdr *) data;
- struct mtp_level_3_mng *mng = (struct mtp_level_3_mng *) &hdr->data[0];
-
- if (memcmp(mng, t_mng, sizeof(*mng)) == 0)
- return;
-
- if (mng->cmn.h0 != t_mng->cmn.h0)
- fprintf(stderr, "h0 not equal.\n");
- if (mng->cmn.h1 != t_mng->cmn.h1)
- fprintf(stderr, "h1 not equal.\n");
- if (mng->length != t_mng->length)
- fprintf(stderr, "length not euqal.\n");
- fprintf(stderr, "FAIL: Comparing the mtp_level_3_mng\n");
- abort();
-}
-
-static void check_prohib(const uint8_t *data, const struct mtp_level_3_prohib *t_prohib)
-{
- struct mtp_level_3_hdr *hdr = (struct mtp_level_3_hdr *) data;
- struct mtp_level_3_prohib *prohib = (struct mtp_level_3_prohib *) &hdr->data[0];
-
- if (memcmp(prohib, t_prohib, sizeof(*prohib)) == 0)
- return;
-
- if (prohib->cmn.h0 != t_prohib->cmn.h0)
- fprintf(stderr, "h0 not equal.\n");
- if (prohib->cmn.h1 != t_prohib->cmn.h1)
- fprintf(stderr, "h1 not equal.\n");
- if (ntohs(prohib->apoc) != t_prohib->apoc)
- fprintf(stderr, "apoc not euqal.\n");
- fprintf(stderr, "FAIL: Comparing the mtp_level_3_prohib\n");
- abort();
-}
-
-int main(int argc, char **argv)
-{
- uint32_t addr;
- int i;
-
- printf("Basic MTP Structure testing.\n");
-
- /* set the addresses here due big endian MTP_ADDRESS macro */
- tests[0].hdr.addr = MTP_ADDR(0x00, 136, 91);
- tests[1].hdr.addr = MTP_ADDR(0x00, 136, 91);
- tests[2].hdr.addr = MTP_ADDR(0x00, 136, 91);
- tests[2].prohib.apoc = MTP_MAKE_APOC(86);
-
- for (i = 0; i < ARRAY_SIZE(tests); ++i) {
- check_hdr(tests[i].input, &tests[i].hdr);
- if (tests[i].has_mng)
- check_mng(tests[i].input, &tests[i].mng);
- if (tests[i].has_prohib)
- check_prohib(tests[i].input, &tests[i].prohib);
- }
-
- if (MTP_READ_OPC(tests[0].hdr.addr) != 91) {
- fprintf(stderr, "Failed to read OPC address\n");
- abort();
- }
-
- if (MTP_READ_DPC(tests[1].hdr.addr) != 136) {
- fprintf(stderr, "Failed to read DPC address\n");
- abort();
- }
-
- /* check the SCCP unitdata */
- {
- struct sccp_con_ctrl_prt_mgt prt = {
- .sst = 0x03,
- .assn = 254,
- .apoc = MTP_MAKE_APOC(91),
- .mul_ind = 1,
- };
-
- uint8_t data[] = { 0x03, 0xfe, 0x5b, 0x00, 0x01 };
- if (memcmp(&prt, data, 5) != 0) {
- uint8_t *d = (uint8_t *) &prt;
- fprintf(stderr, "GOT: 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n",
- d[0], d[1], d[2], d[3], d[4]);
- abort();
- }
- }
-
- /* verify decoding of the sls */
- for (i = 0; i < 16; ++i) {
- addr = MTP_ADDR(i, 136, 91);
- if (MTP_LINK_SLS(addr) != i) {
- fprintf(stderr, "0x%x/0x%x does not match 0x%x\n", addr, MTP_LINK_SLS(addr),
i);
- abort();
- }
- }
-
- printf("All tests passed.\n");
- return 0;
-}
diff --git a/tests/mtp/mtp_parse_test.ok b/tests/mtp/mtp_parse_test.ok
deleted file mode 100644
index cee2aeb..0000000
--- a/tests/mtp/mtp_parse_test.ok
+++ /dev/null
@@ -1,2 +0,0 @@
-Basic MTP Structure testing.
-All tests passed.
diff --git a/tests/sccp/Makefile.am b/tests/sccp/Makefile.am
deleted file mode 100644
index fc4f0c8..0000000
--- a/tests/sccp/Makefile.am
+++ /dev/null
@@ -1,14 +0,0 @@
-AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
-AM_CFLAGS=-Wall -ggdb3 $(LIBOSMOCORE_CFLAGS)
-AM_LDFLAGS = -no-install
-
-EXTRA_DIST = sccp_test.ok
-
-check_PROGRAMS = sccp_test
-
-sccp_test_SOURCES = sccp_test.c
-sccp_test_LDADD = \
- $(LIBOSMOCORE_LIBS) \
- $(top_builddir)/src/sccp.o \
- $(NULL)
-
diff --git a/tests/sccp/sccp_test.c b/tests/sccp/sccp_test.c
deleted file mode 100644
index 1fe353d..0000000
--- a/tests/sccp/sccp_test.c
+++ /dev/null
@@ -1,1067 +0,0 @@
-/*
- * SCCP testing code
- *
- * (C) 2009,2011 by Holger Hans Peter Freyther <zecke(a)selfish.org>
- * (C) 2009,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 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.
- *
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <arpa/inet.h>
-
-#include <osmocom/core/logging.h>
-#include <osmocom/core/msgb.h>
-#include <osmocom/core/utils.h>
-
-#include <osmocom/sccp/sccp.h>
-
-#define MIN(x, y) ((x) < (y) ? (x) : (y))
-
-/* BSC -> MSC */
-static const uint8_t bssmap_reset[] = {
- 0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42, 0xfe,
- 0x02, 0x42, 0xfe, 0x06, 0x00, 0x04, 0x30, 0x04,
- 0x01, 0x20,
-};
-
-/* MSC -> BSC reset ack */
-static const uint8_t bssmap_reset_ack[] = {
- 0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
- 0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x03,
- 0x00, 0x01, 0x31,
-};
-
-/* MSC -> BSC paging, connection less */
-static const uint8_t bssmap_paging[] = {
- 0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
- 0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x10,
- 0x00, 0x0e, 0x52, 0x08, 0x08, 0x29, 0x47, 0x10,
- 0x02, 0x01, 0x31, 0x97, 0x61, 0x1a, 0x01, 0x06,
-};
-
-/* MSC -> BSC paging, UDT without PC */
-static const uint8_t bssmap_udt[] = {
- 0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42, 0xfe,
- 0x02, 0x42, 0xfe, 0x10, 0x00, 0x0e, 0x52, 0x08,
- 0x08, 0x29, 0x47, 0x10, 0x02, 0x01, 0x31, 0x97,
- 0x61, 0x1a, 0x01, 0x06,
-};
-
-/* BSC -> MSC connection open */
-static const uint8_t bssmap_cr[] = {
- 0x01, 0x01, 0x02, 0x03, 0x02, 0x02, 0x04, 0x02,
- 0x42, 0xfe, 0x0f, 0x1f, 0x00, 0x1d, 0x57, 0x05,
- 0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x12, 0xc3,
- 0x50, 0x17, 0x10, 0x05, 0x24, 0x11, 0x03, 0x33,
- 0x19, 0xa2, 0x08, 0x29, 0x47, 0x10, 0x02, 0x01,
- 0x31, 0x97, 0x61, 0x00
-};
-
-/* MSC -> BSC connection confirm */
-static const uint8_t bssmap_cc[] = {
- 0x02, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00,
-};
-
-/* MSC -> BSC DTAP
- *
- * we fake a bit and make it BSC -> MSC... so the
- * payload does not make any sense..
- */
-static const uint8_t bssmap_dtap[] = {
- 0x06, 0x00, 0x00, 0x03, 0x00, 0x01, 0x0f, 0x01, 0x00, 0x0c,
- 0x03, 0x05, 0x5c, 0x08, 0x11, 0x81, 0x33, 0x66, 0x02, 0x13,
- 0x45, 0xf4,
-};
-
-/* MSC -> BSC clear command */
-static const uint8_t bssmap_clear[] = {
- 0x06, 0x00, 0x00, 0x03, 0x00, 0x01, 0x06, 0x00, 0x04, 0x20,
- 0x04, 0x01, 0x09,
-};
-
-/* MSC -> BSC released */
-static const uint8_t bssmap_released[] = {
- 0x04, 0x00, 0x00, 0x03, 0x01, 0x02, 0x03, 0x00, 0x01, 0x0f,
- 0x02, 0x23, 0x42, 0x00,
-};
-
-/* BSC -> MSC released */
-static const uint8_t bssmap_release_complete[] = {
- 0x05, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03
-};
-
-/* message with a SCCP global title */
-static const uint8_t tcap_global_title[] = {
- 0x09,
- 0x81, 0x03, 0x0d, 0x18, 0x0a, 0x12, 0x07, 0x00,
- 0x12, 0x04, 0x53, 0x84, 0x09, 0x00, 0x17, 0x0b,
- 0x12, 0x06, 0x00, 0x12, 0x04, 0x44, 0x87, 0x20,
- 0x00, 0x20, 0x65, 0x9a, 0x65, 0x81, 0x97, 0x48,
- 0x04, 0x26, 0x00, 0x01, 0x98, 0x49, 0x04, 0x51,
- 0x01, 0x03, 0xdf, 0x6c, 0x81, 0x88, 0xa1, 0x81,
- 0x85, 0x02, 0x01, 0x44, 0x02, 0x01, 0x07, 0x30,
- 0x80, 0xa7, 0x80, 0xa0, 0x80, 0x04, 0x01, 0x2b,
- 0x30, 0x80, 0x30, 0x12, 0x83, 0x01, 0x10, 0x84,
- 0x01, 0x07, 0x85, 0x07, 0x91, 0x44, 0x57, 0x76,
- 0x67, 0x16, 0x97, 0x86, 0x01, 0x20, 0x30, 0x06,
- 0x82, 0x01, 0x18, 0x84, 0x01, 0x04, 0x00, 0x00,
- 0x00, 0x00, 0xa3, 0x06, 0x04, 0x01, 0x42, 0x84,
- 0x01, 0x05, 0xa3, 0x06, 0x04, 0x01, 0x51, 0x84,
- 0x01, 0x05, 0xa3, 0x06, 0x04, 0x01, 0x31, 0x84,
- 0x01, 0x05, 0xa3, 0x09, 0x04, 0x01, 0x12, 0x84,
- 0x01, 0x05, 0x82, 0x01, 0x02, 0xa3, 0x09, 0x04,
- 0x01, 0x11, 0x84, 0x01, 0x05, 0x81, 0x01, 0x01,
- 0xa3, 0x06, 0x04, 0x01, 0x14, 0x84, 0x01, 0x00,
- 0xa3, 0x0b, 0x04, 0x01, 0x41, 0x84, 0x01, 0x04,
- 0x30, 0x03, 0x83, 0x01, 0x10, 0xa3, 0x0b, 0x04,
- 0x01, 0x41, 0x84, 0x01, 0x04, 0x30, 0x03, 0x82,
- 0x01, 0x18, 0x00, 0x00, 0x00, 0x00
-};
-
-static const uint8_t tcap_global_dst_gti[] = {
- 0x00, 0x12, 0x04, 0x53, 0x84, 0x09, 0x00, 0x17,
-};
-
-static const uint8_t tcap_global_src_gti[] = {
- 0x00, 0x12, 0x04, 0x44, 0x87, 0x20, 0x00, 0x20, 0x65,
-};
-
-
-struct test_data {
- int length;
- const uint8_t *data;
- int payload_start;
- int payload_length;
- uint8_t first_byte;
-
- /* in case it should trigger a sccp response */
- int write;
- const uint8_t *response;
- int response_length;
-};
-
-static const struct test_data test_data[] = {
- {
- .length = ARRAY_SIZE(bssmap_reset),
- .data = &bssmap_reset[0],
- .payload_start = 12,
- .payload_length = ARRAY_SIZE(bssmap_reset) - 12,
- .first_byte = 0x0,
- },
- {
- .length = ARRAY_SIZE(bssmap_reset_ack),
- .data = &bssmap_reset_ack[0],
- .payload_start = 16,
- .payload_length = ARRAY_SIZE(bssmap_reset_ack) - 16,
- .first_byte = 0x0,
- },
- {
- .length = ARRAY_SIZE(bssmap_paging),
- .data = &bssmap_paging[0],
- .payload_start = 16,
- .payload_length = ARRAY_SIZE(bssmap_paging) - 16,
- .first_byte = 0x0,
- },
- {
- .length = ARRAY_SIZE(bssmap_cr),
- .data = &bssmap_cr[0],
- .payload_start = 12,
- /* 0x00 is end of optional data, subtract this byte */
- .payload_length = 31,
- .first_byte = 0x0,
-
- /* the connection request should trigger a connection confirm */
- .write = 1,
- .response = &bssmap_cc[0],
- .response_length= ARRAY_SIZE(bssmap_cc),
- },
- {
- .length = ARRAY_SIZE(bssmap_dtap),
- .data = &bssmap_dtap[0],
- .payload_start = 7,
- .payload_length = 15,
- .first_byte = 0x01,
- },
- {
- .length = ARRAY_SIZE(bssmap_clear),
- .data = &bssmap_clear[0],
- .payload_start = 7,
- .payload_length = 6,
- .first_byte = 0x00,
- },
- {
- .length = ARRAY_SIZE(bssmap_released),
- .data = &bssmap_released[0],
- .payload_length = 2,
- .payload_start = 11,
- .first_byte = 0x23,
-
- .write = 1,
- .response = &bssmap_release_complete[0],
- .response_length= ARRAY_SIZE(bssmap_release_complete),
- },
-};
-
-/* we will send UDTs and verify they look like this */
-static const struct test_data send_data[] = {
- {
- .length = ARRAY_SIZE(bssmap_udt),
- .data = &bssmap_udt[0],
- .payload_start = 12,
- .payload_length = ARRAY_SIZE(bssmap_udt) - 12,
- .first_byte = 0x0,
- },
- {
- .length = ARRAY_SIZE(bssmap_reset),
- .data = &bssmap_reset[0],
- .payload_start = 12,
- .payload_length = ARRAY_SIZE(bssmap_reset) - 12,
- .first_byte = 0x0,
- },
-};
-
-struct connection_test {
- /* should the connection be refused? */
- int refuse;
-
- int with_data;
-
- /* on which side to close the connection? */
- int close_side;
- int close_cause;
-};
-
-/* sccp connection handling we want to test */
-static const struct connection_test connection_tests[] = {
- {
- .refuse = 1,
- },
- {
- .refuse = 1,
- .with_data = 1,
- },
- {
- .refuse = 0,
- .close_side = 0,
- .close_cause = 5,
- },
- {
- .refuse = 0,
- .close_side = 0,
- .close_cause = 5,
- .with_data = 1,
- },
- {
- .refuse = 0,
- .close_side = 1,
- .close_cause = 5,
- },
- {
- .refuse = 0,
- .close_side = 1,
- .close_cause = 5,
- .with_data = 1,
- },
-};
-
-struct sccp_parse_header_result {
- /* results */
- int msg_type;
- int wanted_len;
- int src_ssn;
- int dst_ssn;
-
- int has_src_ref, has_dst_ref;
- struct sccp_source_reference src_ref;
- struct sccp_source_reference dst_ref;
-
- /* global title len */
- int src_gti_len;
- const uint8_t *src_gti_data;
- int dst_gti_len;
- const uint8_t *dst_gti_data;
-
- /* the input */
- const uint8_t *input;
- int input_len;
-};
-
-static const uint8_t it_test[] = {
-0x10, 0x01, 0x07,
-0x94, 0x01, 0x04, 0x00, 0x02, 0x00, 0x00, 0x00 };
-
-static const uint8_t proto_err[] = {
-0x0f, 0x0c, 0x04, 0x00, 0x00,
-};
-
-static const uint8_t xudt_test_src_gt[] = {
-0x00, 0x11, 0x04, 0x26, 0x18, 0x01, 0x30, 0x08,
-0x01
-};
-
-static const uint8_t xudt_test_dst_gt[] = {
-0x00, 0x61, 0x04, 0x15, 0x10, 0x80, 0x21, 0x35,
-0x98, 0x55, 0x08
-};
-
-static const uint8_t xudt_test[] = {
-0x11, 0x81, 0x02, 0x04, 0x11, 0x1C, 0x00, 0x0D,
-0x52, 0x06, 0x00, 0x61, 0x04, 0x15, 0x10, 0x80,
-0x21, 0x35, 0x98, 0x55, 0x08, 0x0B, 0x12, 0x95,
-0x00, 0x11, 0x04, 0x26, 0x18, 0x01, 0x30, 0x08,
-0x01, 0x44, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
-0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
-0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
-0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
-0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
-0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E,
-0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
-0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E,
-0x3F, 0x40, 0x41, 0x42, 0x43, 0x44
-};
-
-static const struct sccp_parse_header_result parse_result[] = {
- {
- .msg_type = SCCP_MSG_TYPE_IT,
- .wanted_len = 0,
- .src_ssn = -1,
- .dst_ssn = -1,
- .has_src_ref = 1,
- .has_dst_ref = 1,
-
- .src_ref = {
- .octet1 = 0x01,
- .octet2 = 0x04,
- .octet3 = 0x00
- },
- .dst_ref = {
- .octet1 = 0x01,
- .octet2 = 0x07,
- .octet3 = 0x94,
- },
-
- .input = it_test,
- .input_len = sizeof(it_test),
- },
- {
- .msg_type = SCCP_MSG_TYPE_ERR,
- .wanted_len = 0,
- .src_ssn = -1,
- .dst_ssn = -1,
- .has_src_ref = 0,
- .has_dst_ref = 1,
- .dst_ref = {
- .octet1 = 0x0c,
- .octet2 = 0x04,
- .octet3 = 0x00,
- },
- .input = proto_err,
- .input_len = sizeof(proto_err),
- },
- {
- .msg_type = SCCP_MSG_TYPE_UDT,
- .input = tcap_global_title,
- .input_len = sizeof(tcap_global_title),
- .wanted_len = 154,
- .dst_ssn = SCCP_SSN_VLR,
- .dst_gti_data = tcap_global_dst_gti,
- .dst_gti_len = 8,
- .src_ssn = SCCP_SSN_HLR,
- .src_gti_data = tcap_global_src_gti,
- .src_gti_len = 9,
- },
- {
- .msg_type = SCCP_MSG_TYPE_XUDT,
- .input = xudt_test,
- .input_len = sizeof(xudt_test),
- .wanted_len = 68,
- .dst_ssn = 6,
- .dst_gti_data = xudt_test_dst_gt,
- .dst_gti_len = 11,
- .src_ssn = 149,
- .src_gti_data = xudt_test_src_gt,
- .src_gti_len = 9,
- },
-};
-
-
-/* testing procedure:
- * - we will use sccp_write and see what will be set in the
- * outgoing callback
- * - we will call sccp_system_incoming and see which calls
- * are made. And then compare it to the ones we expect. We
- * want the payload to arrive, or callbacks to be called.
- * - we will use sccp_connection_socket and sccp_connection_write
- * and verify state handling of connections
- */
-
-static int current_test;
-
-/*
- * test state...
- */
-static int called = 0;
-static int matched = 0;
-static int write_called = 0;
-
-#define FAIL(x, args...) do { \
- printf("FAILURE in %s:%d: " x, __FILE__, __LINE__, ## args); \
- abort(); } while (0)
-
-/*
- * writing these packets and expecting a result
- */
-int sccp_read_cb(struct msgb *data, unsigned len, void *gctx)
-{
- uint16_t payload_length = test_data[current_test].payload_length;
- const uint8_t *got, *wanted;
- int i;
-
- called = 1;
-
- if (msgb_l3len(data) < len) {
- /* this should never be reached */
- FAIL("Something horrible happened.. invalid packet..\n");
- }
-
- if (len == 0 || len != payload_length) {
- FAIL("length mismatch: got: %d wanted: %d\n", msgb_l3len(data),
payload_length);
- }
-
- if (data->l3h[0] != test_data[current_test].first_byte) {
- FAIL("The first bytes of l3 do not match: 0x%x 0x%x\n",
- data->l3h[0], test_data[current_test].first_byte);
- }
-
- got = &data->l3h[0];
- wanted = test_data[current_test].data + test_data[current_test].payload_start;
-
- for (i = 0; i < len; ++i) {
- if (got[i] != wanted[i]) {
- FAIL("Failed to compare byte. Got: 0x%x Wanted: 0x%x at %d\n",
- got[i], wanted[i], i);
- }
- }
-
- matched = 1;
- return 0;
-}
-
-void sccp_write_cb(struct sccp_connection *conn, struct msgb *data, void *gctx, void
*ctx)
-{
- int i = 0;
- const uint8_t *got, *wanted;
-
- if (test_data[current_test].response == NULL) {
- FAIL("Didn't expect write callback\n");
- } else if (test_data[current_test].response_length != msgb_l2len(data)) {
- FAIL("Size does not match. Got: %d Wanted: %d\n",
- msgb_l2len(data), test_data[current_test].response_length);
- }
-
- got = &data->l2h[0];
- wanted = test_data[current_test].response;
-
- for (i = 0; i < msgb_l2len(data); ++i) {
- if (got[i] != wanted[i]) {
- FAIL("Failed to compare byte. Got: 0x%x Wanted: 0x%x at %d\n",
- got[i], wanted[i], i);
- }
- }
-
- write_called = 1;
- msgb_free(data);
-}
-
-void sccp_c_read(struct sccp_connection *connection, struct msgb *msgb, unsigned int
len)
-{
- sccp_read_cb(msgb, len, connection->data_ctx);
-}
-
-void sccp_c_state(struct sccp_connection *connection, int old_state)
-{
- if (connection->connection_state >= SCCP_CONNECTION_STATE_RELEASE_COMPLETE)
- sccp_connection_free(connection);
-}
-
-int sccp_accept_cb(struct sccp_connection *connection, void *user_data)
-{
- called = 1;
- unsigned int ref = 0;
- ref |= connection->destination_local_reference.octet1 << 24;
- ref |= connection->destination_local_reference.octet2 << 16;
- ref |= connection->destination_local_reference.octet3 << 8;
- ref = ntohl(ref);
-
- connection->data_cb = sccp_c_read;
- connection->state_cb = sccp_c_state;
-
- /* accept this */
- return 0;
-}
-
-static void sccp_udt_write_cb(struct sccp_connection *conn, struct msgb *data, void *gtx,
void *ctx)
-{
- const uint8_t *got, *wanted;
- int i;
-
- write_called = 1;
-
- if (send_data[current_test].length != msgb_l2len(data)) {
- FAIL("Size does not match. Got: %d Wanted: %d\n",
- msgb_l2len(data), send_data[current_test].length);
- }
-
- got = &data->l2h[0];
- wanted = send_data[current_test].data;
-
- for (i = 0; i < msgb_l2len(data); ++i) {
- if (got[i] != wanted[i]) {
- FAIL("Failed to compare byte. Got: 0x%x Wanted: 0x%x at %d\n",
- got[i], wanted[i], i);
- }
- }
-
- matched = 1;
- msgb_free(data);
-}
-
-static void test_sccp_system(void)
-{
- printf("Testing SCCP System\n");
-
- sccp_system_init(sccp_write_cb, NULL);
- sccp_set_read(&sccp_ssn_bssap, sccp_read_cb, NULL);
- sccp_connection_set_incoming(&sccp_ssn_bssap, sccp_accept_cb, NULL);
-
- for (current_test = 0; current_test < ARRAY_SIZE(test_data); ++current_test) {
- unsigned int length = test_data[current_test].length;
- struct msgb *msg = msgb_alloc_headroom(length + 2, 2, __func__);
- msg->l2h = msgb_put(msg, length);
- memcpy(msg->l2h, test_data[current_test].data, length);
-
- called = matched = write_called = 0;
- printf("Testing packet: %d\n", current_test);
- sccp_system_incoming(msg);
-
- if (!called || !matched || (test_data[current_test].write != write_called))
- FAIL("current test: %d called: %d matched: %d write: %d\n",
- current_test, called, matched, write_called);
-
- msgb_free(msg);
- }
-}
-
-/* test sending of udt */
-static void test_sccp_send_udt(void)
-{
- printf("Testing send UDT\n");
-
- sccp_system_init(sccp_udt_write_cb, NULL);
- sccp_set_read(NULL, NULL, NULL);
- sccp_connection_set_incoming(NULL, NULL, NULL);
-
- for (current_test = 0; current_test < ARRAY_SIZE(send_data); ++current_test) {
- const struct test_data *test = &send_data[current_test];
-
- struct msgb *msg = msgb_alloc(test->payload_length, __func__);
- msg->l3h = msgb_put(msg, test->payload_length);
- memcpy(msg->l3h, test->data + test->payload_start, test->payload_length);
-
- matched = write_called = 0;
- printf("Testing packet: %d\n", current_test);
- sccp_write(msg, &sccp_ssn_bssap, &sccp_ssn_bssap, 0, NULL);
-
- if (!matched || !write_called)
- FAIL("current test: %d matched: %d write: %d\n",
- current_test, matched, write_called);
-
- msgb_free(msg);
- }
-}
-
-/* send udt from one end to another */
-static unsigned int test_value = 0x2442;
-static int sccp_udt_read(struct msgb *data, unsigned int len, void *gctx)
-{
- unsigned int *val;
-
- if (len != 4) {
- FAIL("Wrong size: %d\n", msgb_l3len(data));
- }
-
- val = (unsigned int*)data->l3h;
- matched = test_value == *val;
-
- return 0;
-}
-
-static void sccp_write_loop(struct sccp_connection *conn, struct msgb *data, void *gctx,
void *ctx)
-{
- /* send it back to us */
- sccp_system_incoming(data);
- msgb_free(data);
-}
-
-static void test_sccp_udt_communication(void)
-{
- struct msgb *data;
- unsigned int *val;
-
- printf("Testing UDT Communication.\n");
-
- sccp_system_init(sccp_write_loop, NULL);
- sccp_set_read(&sccp_ssn_bssap, sccp_udt_read, NULL);
- sccp_connection_set_incoming(NULL, NULL, NULL);
-
-
- data = msgb_alloc(4, "test data");
- data->l3h = &data->data[0];
- val = (unsigned int *)msgb_put(data, 4);
- *val = test_value;
-
- matched = 0;
- sccp_write(data, &sccp_ssn_bssap, &sccp_ssn_bssap, 0, NULL);
-
- if (!matched)
- FAIL("Talking with us didn't work\n");
-
- msgb_free(data);
-}
-
-
-/* connection testing... open, send, close */
-static const struct connection_test *current_con_test;
-static struct sccp_connection *outgoing_con;
-static struct sccp_connection *incoming_con;
-static int outgoing_data, incoming_data, incoming_state, outgoing_state;
-
-static struct msgb *test_data1, *test_data2, *test_data3;
-
-static void sccp_conn_in_state(struct sccp_connection *conn, int old_state)
-{
- printf("\tincome: %d -> %d\n", old_state, conn->connection_state);
- if (conn->connection_state >= SCCP_CONNECTION_STATE_RELEASE_COMPLETE) {
- if (conn == incoming_con) {
- sccp_connection_free(conn);
- incoming_con = NULL;
- }
- }
-}
-
-static void sccp_conn_in_data(struct sccp_connection *conn, struct msgb *msg, unsigned
int len)
-{
- /* compare the data */
- ++incoming_data;
- printf("\tincoming data: %d\n", len);
-
- /* compare the data */
- if (len != 4) {
- FAIL("Length of packet is wrong: %u %u\n", msgb_l3len(msg), len);
- }
-
- if (incoming_data == 1) {
- if (memcmp(msg->l3h, test_data1->l3h, len) != 0) {
- FAIL("Comparing the data failed: %d\n", incoming_data);
-
- }
- } else if (incoming_data == 2) {
- if (memcmp(msg->l3h, test_data2->l3h, len) != 0) {
- FAIL("Comparing the data failed: %d\n", incoming_data);
- }
- }
-
- /* sending out data */
- if (incoming_data == 2) {
- printf("\tReturning data3\n");
- sccp_connection_write(conn, test_data3);
- }
-}
-
-static int sccp_conn_accept(struct sccp_connection *conn, void *ctx)
-{
- printf("\taccept: srcref(%u)\n",
- sccp_src_ref_to_int(&conn->source_local_reference));
- conn->state_cb = sccp_conn_in_state;
- conn->data_cb = sccp_conn_in_data;
-
- if (current_con_test->refuse)
- return -1;
-
- incoming_con = conn;
- return 0;
-}
-
-/* callbacks for the outgoing side */
-static void sccp_conn_out_state(struct sccp_connection *conn, int old_state)
-{
- printf("\toutgoing: dstref(%u) %d -> %d\n",
- sccp_src_ref_to_int(&conn->destination_local_reference),
- old_state, conn->connection_state);
-
- if (conn->connection_state >= SCCP_CONNECTION_STATE_RELEASE_COMPLETE) {
- if (conn == outgoing_con) {
- sccp_connection_free(conn);
- outgoing_con = NULL;
- }
- }
-}
-
-static void sccp_conn_out_data(struct sccp_connection *conn, struct msgb *msg, unsigned
int len)
-{
- ++outgoing_data;
- printf("\toutgoing data: dstref(%u) %d\n",
- sccp_src_ref_to_int(&conn->destination_local_reference), len);
-
- if (len != 4)
- FAIL("Length of packet is wrong: %u %u\n", msgb_l3len(msg), len);
-
- if (outgoing_data == 1) {
- if (memcmp(msg->l3h, test_data3->l3h, len) != 0) {
- FAIL("Comparing the data failed\n");
- }
- }
-}
-
-static void do_test_sccp_connection(const struct connection_test *test)
-{
- int ret;
-
- current_con_test = test;
- outgoing_con = incoming_con = 0;
-
- outgoing_con = sccp_connection_socket();
- if (!outgoing_con) {
- FAIL("Connection is NULL\n");
- }
-
- outgoing_con->state_cb = sccp_conn_out_state;
- outgoing_con->data_cb = sccp_conn_out_data;
- outgoing_data = incoming_data = 0;
- incoming_state = outgoing_state = 1;
-
- /* start testing */
- if (test->with_data) {
- if (sccp_connection_connect(outgoing_con, &sccp_ssn_bssap, test_data1) != 0)
- FAIL("Binding failed\n");
- } else {
- ++incoming_data;
- if (sccp_connection_connect(outgoing_con, &sccp_ssn_bssap, NULL) != 0)
- FAIL("Binding failed\n");
- }
-
- if (test->refuse) {
- if (outgoing_con)
- FAIL("Outgoing connection should have been refused.\n");
- } else {
- if (!incoming_con)
- FAIL("Creating incoming didn't work.\n");
-
- printf("\tWriting test data2\n");
- sccp_connection_write(outgoing_con, test_data2);
- sccp_connection_send_it(outgoing_con);
-
- /* closing connection */
- if (test->close_side == 0)
- ret = sccp_connection_close(outgoing_con, 0);
- else
- ret = sccp_connection_close(incoming_con, 0);
-
- if (ret != 0)
- FAIL("Closing the connection failed\n");
- }
-
- /* outgoing should be gone now */
- if (outgoing_con)
- FAIL("Outgoing connection was not properly closed\n");
-
- if (incoming_con)
- FAIL("Incoming connection was not propery closed.\n");
-
- if (test->refuse == 0) {
- if (outgoing_data != 1 || incoming_data != 2) {
- FAIL("Data sending failed: %d/%d %d/%d\n",
- outgoing_data, 1,
- incoming_data, 2);
- }
- }
-
- if (!incoming_state || !outgoing_state)
- FAIL("Failure with the state transition. %d %d\n",
- outgoing_state, incoming_state);
-}
-
-static void test_sccp_connection(void)
-{
- printf("Testing SCCP connection.\n");
-
- sccp_system_init(sccp_write_loop, NULL);
- sccp_set_read(NULL, NULL, NULL);
- sccp_connection_set_incoming(&sccp_ssn_bssap, sccp_conn_accept, NULL);
-
- test_data1 = msgb_alloc(4, "data1");
- test_data1->l3h = msgb_put(test_data1, 4);
- *((unsigned int*)test_data1->l3h) = 0x23421122;
-
- test_data2 = msgb_alloc(4, "data2");
- test_data2->l3h = msgb_put(test_data2, 4);
- *((unsigned int*)test_data2->l3h) = 0x42232211;
-
- test_data3 = msgb_alloc(4, "data3");
- test_data3->l3h = msgb_put(test_data3, 4);
- *((unsigned int*)test_data3->l3h) = 0x2323ff55;
-
-
- for (current_test = 0; current_test < ARRAY_SIZE(connection_tests); ++current_test)
{
- printf("Testing %d refuse: %d with_data: %d\n",
- current_test, connection_tests[current_test].refuse,
- connection_tests[current_test].with_data);
- do_test_sccp_connection(&connection_tests[current_test]);
- }
-
- msgb_free(test_data1);
- msgb_free(test_data2);
- msgb_free(test_data3);
-}
-
-/* invalid input */
-static void test_sccp_system_crash(void)
-{
- printf("trying to provoke a crash with invalid input\n");
- sccp_set_read(&sccp_ssn_bssap, sccp_read_cb, NULL);
- sccp_connection_set_incoming(&sccp_ssn_bssap, sccp_accept_cb, NULL);
-
- for (current_test = 0; current_test < ARRAY_SIZE(test_data); ++current_test) {
- int original_length = test_data[current_test].length;
- int length = original_length + 2;
- int i;
-
- printf("Testing packet: %d\n", current_test);
-
- for (i = length; i >= 0; --i) {
- unsigned int length = MIN(test_data[current_test].length, i);
- struct msgb *msg = msgb_alloc_headroom(length + 2, 2, __func__);
- msg->l2h = msgb_put(msg, length);
- memcpy(msg->l2h, test_data[current_test].data, length);
- sccp_system_incoming(msg);
- msgb_free(msg);
- }
- }
-
- printf("survived\n");
-}
-
-static void test_sccp_parsing(void)
-{
- printf("Test SCCP Parsing.\n");
-
- for (current_test = 0; current_test < ARRAY_SIZE(parse_result); ++current_test) {
- struct msgb *msg;
- struct sccp_parse_result result;
-
- msg = msgb_alloc_headroom(1024, 128, "parse-test");
- msgb_put(msg, 1);
- msg->l2h = msgb_put(msg, parse_result[current_test].input_len);
- memcpy(msg->l2h, parse_result[current_test].input, msgb_l2len(msg));
-
- memset(&result, 0, sizeof(result));
- if (sccp_parse_header(msg, &result) != 0) {
- FAIL("Failed to sccp parse test: %d\n", current_test);
- } else {
- if (parse_result[current_test].wanted_len != result.data_len) {
- FAIL("Unexpected data length. Got: %d\n", result.data_len);
- }
-
- if (parse_result[current_test].has_src_ref) {
- if (memcmp(result.source_local_reference,
- &parse_result[current_test].src_ref,
- sizeof(struct sccp_source_reference)) != 0) {
- FAIL("SRC REF did not match\n");
- }
- }
-
- if (parse_result[current_test].has_dst_ref) {
- if (memcmp(result.destination_local_reference,
- &parse_result[current_test].dst_ref,
- sizeof(struct sccp_source_reference)) != 0) {
- FAIL("DST REF did not match\n");
- }
- }
-
- if (parse_result[current_test].src_ssn != -1 &&
- parse_result[current_test].src_ssn != result.calling.ssn) {
- FAIL("Calling SSN is wrong..\n");
- }
-
- if (parse_result[current_test].dst_ssn != -1 &&
- parse_result[current_test].dst_ssn != result.called.ssn) {
- FAIL("Called SSN is wrong..\n");
- }
-
- if (parse_result[current_test].src_gti_len != result.calling.gti_len) {
- FAIL("GTI length is wrong: %d\n", result.calling.gti_len);
- }
-
- if (parse_result[current_test].dst_gti_len != result.called.gti_len) {
- FAIL("GTI length is wrong: %d\n", result.called.gti_len);
- }
-
- if (parse_result[current_test].dst_gti_data
- && memcmp(&parse_result[current_test].dst_gti_data[0],
- result.called.gti_data, result.called.gti_len) != 0) {
- FAIL("GTI data is wrong: %d '%s'\n",
- result.called.gti_len,
- osmo_hexdump(result.called.gti_data, result.called.gti_len));
- }
-
- if (parse_result[current_test].src_gti_data
- && memcmp(&parse_result[current_test].src_gti_data[0],
- result.calling.gti_data, result.calling.gti_len) != 0) {
- FAIL("GTI data is wrong: %d\n", result.calling.gti_len);
- }
- }
-
- msgb_free(msg);
- }
-}
-
-/*
- * Test the creation of SCCP addresses
- */
-int sccp_create_sccp_addr(struct msgb *msg, const struct sockaddr_sccp *sock);
-
-struct sccp_addr_tst {
- const struct sockaddr_sccp *addr;
-
- const uint8_t *output;
- const int output_len;
-};
-
-static uint8_t ssn_out[] = {
- 0x02, 0x42, 0xfe,
-};
-
-const struct sockaddr_sccp sccp_poi_bssap = {
- .sccp_family = 0,
- .sccp_ssn = SCCP_SSN_BSSAP,
- .poi = {0x01, 0x00},
- .use_poi = 1,
-};
-
-static uint8_t poi_out[] = {
- 0x04, 0x43, 0x01, 0x00, 0xfe,
-};
-
-static uint8_t gti_dat[] = {
- 0x00, 0x12, 0x04, 0x53, 0x84, 0x09, 0x00, 0x17,
-};
-
-const struct sockaddr_sccp sccp_gti_bssap = {
- .sccp_family = 0,
- .sccp_ssn = 7,
- .gti_ind = 4,
- .gti_len = ARRAY_SIZE(gti_dat),
- .gti = gti_dat,
-};
-
-static uint8_t gti_out[] = {
- 0x0a, 0x12, 0x07, 0x00, 0x12, 0x04, 0x53, 0x84, 0x09, 0x00, 0x17,
-};
-
-static struct sccp_addr_tst sccp_addr_tst[] = {
- {
- .addr = &sccp_ssn_bssap,
- .output = ssn_out,
- .output_len = ARRAY_SIZE(ssn_out),
- },
- {
- .addr = &sccp_poi_bssap,
- .output = poi_out,
- .output_len = ARRAY_SIZE(poi_out),
- },
- {
- .addr = &sccp_gti_bssap,
- .output = gti_out,
- .output_len = ARRAY_SIZE(gti_out),
- },
-};
-
-static void test_sccp_address(void)
-{
- int i, ret;
- struct msgb *msg = msgb_alloc(128, "sccp-addr");
-
- printf("Test SCCP Address\n");
-
- for (i = 0; i < ARRAY_SIZE(sccp_addr_tst); ++i) {
- msgb_reset(msg);
- ret = sccp_create_sccp_addr(msg, sccp_addr_tst[i].addr);
- if (ret != sccp_addr_tst[i].output_len) {
- FAIL("Length is from for %d\n", i);
- }
-
- if (memcmp(msg->data, sccp_addr_tst[i].output, ret) != 0) {
- FAIL("Unexpected data for %d '%s'\n", i,
- osmo_hexdump(msg->data, ret));
- }
- }
-
- talloc_free(msg);
-}
-
-static const struct log_info_cat default_categories[] = {
- [0] = {
- .name = "DSCCP",
- .description = "DSCP",
- .enabled = 1, .loglevel = LOGL_DEBUG,
- },
-};
-
-static int null_flt(const struct log_context *ctx, struct log_target *target)
-{
- return 1;
-}
-
-const struct log_info log_info = {
- .filter_fn = null_flt,
- .cat = default_categories,
- .num_cat = ARRAY_SIZE(default_categories),
-};
-
-int main(int argc, char **argv)
-{
- struct log_target *stderr_target;
- log_init(&log_info, NULL);
- stderr_target = log_target_create_stderr();
- log_add_target(stderr_target);
-
- printf("Testing SCCP handling.\n");
-
- sccp_set_log_area(0);
-
- test_sccp_system();
- test_sccp_send_udt();
- test_sccp_udt_communication();
- test_sccp_connection();
- test_sccp_system_crash();
- test_sccp_parsing();
- test_sccp_address();
- printf("All tests passed.\n");
- return 0;
-}
-
-void db_store_counter(void) {}
diff --git a/tests/sccp/sccp_test.ok b/tests/sccp/sccp_test.ok
deleted file mode 100644
index 2b55a16..0000000
--- a/tests/sccp/sccp_test.ok
+++ /dev/null
@@ -1,86 +0,0 @@
-Testing SCCP handling.
-Testing SCCP System
-Testing packet: 0
-Testing packet: 1
-Testing packet: 2
-Testing packet: 3
-Testing packet: 4
-Testing packet: 5
-Testing packet: 6
-Testing send UDT
-Testing packet: 0
-Testing packet: 1
-Testing UDT Communication.
-Testing SCCP connection.
-Testing 0 refuse: 1 with_data: 0
- outgoing: dstref(0) 0 -> 1
- accept: srcref(0)
- outgoing: dstref(0) 1 -> 6
- income: 0 -> 6
-Testing 1 refuse: 1 with_data: 1
- outgoing: dstref(0) 0 -> 1
- accept: srcref(0)
- outgoing: dstref(0) 1 -> 6
- income: 0 -> 6
-Testing 2 refuse: 0 with_data: 0
- outgoing: dstref(0) 0 -> 1
- accept: srcref(0)
- outgoing: dstref(196612) 1 -> 3
- income: 0 -> 3
- Writing test data2
- incoming data: 4
- Returning data3
- outgoing data: dstref(196612) 4
- outgoing: dstref(196612) 3 -> 4
- outgoing: dstref(196612) 4 -> 5
- income: 3 -> 5
-Testing 3 refuse: 0 with_data: 1
- outgoing: dstref(0) 0 -> 1
- accept: srcref(0)
- outgoing: dstref(196614) 1 -> 3
- income: 0 -> 3
- incoming data: 4
- Writing test data2
- incoming data: 4
- Returning data3
- outgoing data: dstref(196614) 4
- outgoing: dstref(196614) 3 -> 4
- outgoing: dstref(196614) 4 -> 5
- income: 3 -> 5
-Testing 4 refuse: 0 with_data: 0
- outgoing: dstref(0) 0 -> 1
- accept: srcref(0)
- outgoing: dstref(196616) 1 -> 3
- income: 0 -> 3
- Writing test data2
- incoming data: 4
- Returning data3
- outgoing data: dstref(196616) 4
- income: 3 -> 4
- income: 4 -> 5
- outgoing: dstref(196616) 3 -> 5
-Testing 5 refuse: 0 with_data: 1
- outgoing: dstref(0) 0 -> 1
- accept: srcref(0)
- outgoing: dstref(196618) 1 -> 3
- income: 0 -> 3
- incoming data: 4
- Writing test data2
- incoming data: 4
- Returning data3
- outgoing data: dstref(196618) 4
- income: 3 -> 4
- income: 4 -> 5
- outgoing: dstref(196618) 3 -> 5
-trying to provoke a crash with invalid input
-Testing packet: 0
-Testing packet: 1
-Testing packet: 2
-Testing packet: 3
-Testing packet: 4
-Testing packet: 5
-Testing packet: 6
-survived
-Test SCCP Parsing.
-Test SCCP Address
-All tests passed.
diff --git a/tests/testsuite.at b/tests/testsuite.at
index ebc43e7..ce1fd87 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -7,18 +7,6 @@
AT_CHECK([$abs_top_builddir/tests/m2ua/m2ua_test], [], [expout], [ignore])
AT_CLEANUP
-AT_SETUP([mtp])
-AT_KEYWORDS([mtp])
-cat $abs_srcdir/mtp/mtp_parse_test.ok > expout
-AT_CHECK([$abs_top_builddir/tests/mtp/mtp_parse_test], [], [expout], [ignore])
-AT_CLEANUP
-
-AT_SETUP([sccp])
-AT_KEYWORDS([sccp])
-cat $abs_srcdir/sccp/sccp_test.ok > expout
-AT_CHECK([$abs_top_builddir/tests/sccp/sccp_test], [], [expout], [ignore])
-AT_CLEANUP
-
AT_SETUP([xua])
AT_KEYWORDS([xua])
cat $abs_srcdir/xua/xua_test.ok > expout
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-sccp/+/38041?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Change-Id: I299a32a2f8f61477cf49c8126567fef2092d5407
Gerrit-Change-Number: 38041
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>