aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac1
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/testsuite.at6
-rw-r--r--tests/xua/Makefile.am13
-rw-r--r--tests/xua/sccp_test_data.c102
-rw-r--r--tests/xua/sccp_test_data.h14
-rw-r--r--tests/xua/xua_test.c386
-rw-r--r--tests/xua/xua_test.ok131
8 files changed, 654 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 116e168..ed3e25a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -67,6 +67,7 @@ AC_OUTPUT(
tests/mtp/Makefile
tests/m2ua/Makefile
tests/sigtran/Makefile
+ tests/xua/Makefile
tests/ss7/Makefile
Makefile)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9c251fe..6d3c96f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = sccp mtp m2ua sigtran ss7
+SUBDIRS = xua sccp mtp m2ua sigtran ss7
# 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/testsuite.at b/tests/testsuite.at
index 171f488..b810bdf 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -19,6 +19,12 @@ 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
+AT_CHECK([$abs_top_builddir/tests/xua/xua_test], [], [expout], [ignore])
+AT_CLEANUP
+
AT_SETUP([ss7])
AT_KEYWORDS([ss7])
cat $abs_srcdir/ss7/ss7_test.ok > expout
diff --git a/tests/xua/Makefile.am b/tests/xua/Makefile.am
new file mode 100644
index 0000000..8a75e6c
--- /dev/null
+++ b/tests/xua/Makefile.am
@@ -0,0 +1,13 @@
+AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -Wall
+AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS)
+
+AM_LDFLAGS = -static
+LDADD = $(top_builddir)/src/libosmo-sigtran.la \
+ $(LIBOSMOCORE_LIBS) $(LIBOSMONETIF_LIBS) $(LIBSCTP_LIBS)
+
+EXTRA_DIST = xua_test.ok
+
+noinst_HEADERS = sccp_test_data.h
+noinst_PROGRAMS = xua_test
+
+xua_test_SOURCES = xua_test.c sccp_test_data.c
diff --git a/tests/xua/sccp_test_data.c b/tests/xua/sccp_test_data.c
new file mode 100644
index 0000000..c7c8f27
--- /dev/null
+++ b/tests/xua/sccp_test_data.c
@@ -0,0 +1,102 @@
+#include <stdint.h>
+
+/* BSC -> MSC */
+const uint8_t bssmap_reset[18] = {
+ 0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42, 0xfe,
+ 0x02, 0x42, 0xfe, 0x06, 0x00, 0x04, 0x30, 0x04,
+ 0x01, 0x20,
+};
+
+/* MSC -> BSC reset ack */
+const uint8_t bssmap_reset_ack[19] = {
+ 0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
+ 0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x03,
+ 0x00, 0x01, 0x31,
+};
+
+/* MSC -> BSC paging, connection less */
+const uint8_t bssmap_paging[32] = {
+ 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 */
+const uint8_t bssmap_udt[28] = {
+ 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 */
+const uint8_t bssmap_cr[44] = {
+ 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 */
+const uint8_t bssmap_cc[10] = {
+ 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..
+ */
+const uint8_t bssmap_dtap[22] = {
+ 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 */
+const uint8_t bssmap_clear[13] = {
+ 0x06, 0x00, 0x00, 0x03, 0x00, 0x01, 0x06, 0x00, 0x04, 0x20,
+ 0x04, 0x01, 0x09,
+};
+
+/* MSC -> BSC released */
+const uint8_t bssmap_released[14] = {
+ 0x04, 0x00, 0x00, 0x03, 0x01, 0x02, 0x03, 0x00, 0x01, 0x0f,
+ 0x02, 0x23, 0x42, 0x00,
+};
+
+/* BSC -> MSC released */
+const uint8_t bssmap_release_complete[7] = {
+ 0x05, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03
+};
+
+/* message with a SCCP global title */
+const uint8_t tcap_global_title[183] = {
+ 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
+};
diff --git a/tests/xua/sccp_test_data.h b/tests/xua/sccp_test_data.h
new file mode 100644
index 0000000..3d70549
--- /dev/null
+++ b/tests/xua/sccp_test_data.h
@@ -0,0 +1,14 @@
+#pragma once
+#include <stdint.h>
+
+extern const uint8_t bssmap_reset[18];
+extern const uint8_t bssmap_reset_ack[19];
+extern const uint8_t bssmap_paging[32];
+extern const uint8_t bssmap_udt[28];
+extern const uint8_t bssmap_cr[44];
+extern const uint8_t bssmap_cc[10];
+extern const uint8_t bssmap_dtap[22];
+extern const uint8_t bssmap_clear[13];
+extern const uint8_t bssmap_released[14];
+extern const uint8_t bssmap_release_complete[7];
+extern const uint8_t tcap_global_title[183];
diff --git a/tests/xua/xua_test.c b/tests/xua/xua_test.c
new file mode 100644
index 0000000..74d91c4
--- /dev/null
+++ b/tests/xua/xua_test.c
@@ -0,0 +1,386 @@
+/* (C) 2011 by Holger Hans Peter Freyther <zecke@selfish.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "sccp_test_data.h"
+
+#include "../src/xua_internal.h"
+
+#include <osmocom/sigtran/xua_msg.h>
+#include <osmocom/sigtran/protocol/sua.h>
+#include <osmocom/sigtran/sccp_sap.h>
+#include <osmocom/sigtran/sccp_helpers.h>
+
+#include <osmocom/core/utils.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/logging.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+
+static void test_isup_parse(void)
+{
+ const uint8_t party0[] = { 0x10, 0x32, 0x54, 0x76 };
+ char digits[23] = "";
+ int rc;
+
+ rc = osmo_isup_party_parse(digits, party0, ARRAY_SIZE(party0), false);
+ printf("digits='%s' (%d)\n", digits, rc);
+ OSMO_ASSERT(rc == 8);
+ OSMO_ASSERT(!strcmp(digits, "01234567"));
+
+ rc = osmo_isup_party_parse(digits, party0, ARRAY_SIZE(party0), true);
+ printf("digits='%s' (%d)\n", digits, rc);
+ OSMO_ASSERT(rc == 7);
+ OSMO_ASSERT(!strcmp(digits, "0123456"));
+}
+
+/* SCCP Address Parsing */
+
+static struct sccp_addr_testcase {
+ struct osmo_sccp_addr expected;
+ uint8_t *bin;
+ unsigned int bin_len;
+};
+
+static uint8_t addr_bin0[] = { 0x92, 0x06, 0x00, 0x12, 0x04, 0x19, 0x99, 0x96, 0x76, 0x39, 0x98 };
+static uint8_t addr_bin1[] = { 0x12, 0x08, 0x00, 0x12, 0x04, 0x19, 0x89, 0x96, 0x92, 0x99, 0x29 };
+static uint8_t addr_bin2[] = { 0x42, 0xfe };
+
+static const struct sccp_addr_testcase sccp_addr_testcases[] = {
+ {
+ .expected = {
+ .presence = OSMO_SCCP_ADDR_T_GT | OSMO_SCCP_ADDR_T_SSN,
+ .ri = OSMO_SCCP_RI_GT,
+ .gt = {
+ .gti = OSMO_SCCP_GTI_TT_NPL_ENC_NAI,
+ .tt = 0,
+ .npi = OSMO_SCCP_NPI_E164_ISDN,
+ .nai = OSMO_SCCP_NAI_INTL,
+ .digits = "919969679389",
+ },
+ .ssn = 6,
+ },
+ .bin = addr_bin0,
+ .bin_len = ARRAY_SIZE(addr_bin0),
+ }, {
+ .expected = {
+ .presence = OSMO_SCCP_ADDR_T_GT | OSMO_SCCP_ADDR_T_SSN,
+ .ri = OSMO_SCCP_RI_GT,
+ .gt = {
+ .gti = OSMO_SCCP_GTI_TT_NPL_ENC_NAI,
+ .tt = 0,
+ .npi = OSMO_SCCP_NPI_E164_ISDN,
+ .nai = OSMO_SCCP_NAI_INTL,
+ .digits = "919869299992",
+ },
+ .ssn = 8,
+ },
+ .bin = addr_bin1,
+ .bin_len = ARRAY_SIZE(addr_bin1),
+ }, {
+ .expected = {
+ .presence = OSMO_SCCP_ADDR_T_SSN,
+ .ri = OSMO_SCCP_RI_SSN_PC,
+ .ssn = 254,
+ },
+ .bin = addr_bin2,
+ .bin_len = ARRAY_SIZE(addr_bin2),
+
+ },
+};
+
+static int test_sccp_addr_parse(const struct osmo_sccp_addr *cmp,
+ const uint8_t *in, unsigned int in_len)
+{
+ struct osmo_sccp_addr osa;
+ int rc;
+
+ memset(&osa, 0, sizeof(osa));
+ rc = osmo_sccp_addr_parse(&osa, in, in_len);
+ if (rc < 0)
+ return rc;
+
+ printf("expected: %s\n", osmo_sccp_addr_dump(cmp));
+ printf("parsed: %s\n", osmo_sccp_addr_dump(&osa));
+
+ if (memcmp(&osa, cmp, sizeof(osa))) {
+ fprintf(stderr, "expected: %s\n", osmo_hexdump_nospc((uint8_t *)cmp, sizeof(*cmp)));
+ fprintf(stderr, "parsed: %s\n", osmo_hexdump_nospc((uint8_t *)&osa, sizeof(osa)));
+ }
+
+ return 0;
+}
+
+static void test_sccp_addr_parser(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(sccp_addr_testcases); i++) {
+ const struct sccp_addr_testcase *tcase = &sccp_addr_testcases[i];
+ printf("sccp_addr_parse test case %u\n", i);
+ test_sccp_addr_parse(&tcase->expected, tcase->bin, tcase->bin_len);
+ }
+}
+
+/* sccp_addr_testcases[0].expected.gt transcoded into a SUA Global Title IE */
+static const uint8_t expected_sua_gt[] = {
+ 0x80, 0x01, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04,
+ 0x0c, 0x00, 0x01, 0x04, 0x19, 0x99, 0x96, 0x76,
+ 0x39, 0x98, 0x00, 0x00
+};
+
+static void test_helpers(void)
+{
+ struct msgb *msg = msgb_alloc(1024, "foo");
+ const struct osmo_sccp_gt *gt_in = &sccp_addr_testcases[0].expected.gt;
+ struct osmo_sccp_gt gt_out;
+
+ printf("Testing Decoded GT -> SUA encoding\n");
+ printf("IN: %s\n", osmo_sccp_gt_dump(gt_in));
+
+ /* encode sccp_addr to SUA GT */
+ xua_part_add_gt(msg, gt_in);
+ OSMO_ASSERT(msgb_length(msg) == sizeof(expected_sua_gt));
+ OSMO_ASSERT(!memcmp(msg->data, expected_sua_gt, sizeof(expected_sua_gt)));
+
+ /* pull the tag+length value */
+ msgb_pull(msg, 4);
+
+ /* parse + compare */
+ sua_parse_gt(&gt_out, msgb_data(msg), msgb_length(msg));
+ printf("OUT:%s\n", osmo_sccp_gt_dump(&gt_out));
+ OSMO_ASSERT(!memcmp(gt_in, &gt_out, sizeof(gt_out)));
+
+ msgb_free(msg);
+}
+
+/* SCCP Message Transcoding */
+
+struct sccp2sua_testcase {
+ const char *name;
+ struct {
+ const uint8_t *bin;
+ unsigned int length;
+ } sccp;
+ struct {
+ struct xua_common_hdr hdr;
+ const struct xua_msg_part parts[32];
+ } sua;
+};
+
+#define PANDSIZ(x) { x, ARRAY_SIZE(x) }
+#define PARTU32(x, data) { .tag = x, .len = 4, .dat = (uint8_t *) data }
+#define PARTARR(x, data) { .tag = x, .len = ARRAY_SIZE(data), .dat = (uint8_t *) data }
+
+const uint32_t sua_proto_class0 = 0;
+const uint32_t sua_proto_class2 = 2;
+const uint32_t sua_loc_ref_bsc = 0x10203;
+const uint32_t sua_loc_ref_msc = 0x00003;
+const uint32_t sua_cause0 = 0x00003;
+const uint8_t sua_addr_ssn_bssmap[] = { 0x00, 0x02, 0x00, 0x07, 0x80, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0xfe };
+const uint8_t sua_addr_ssn_bssmap_pc1[] = { 0x00, 0x01, 0x00, 0x07, 0x80, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x80, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0xfe };
+const uint8_t sua_addr_ssn_bssmap_pc92[] = { 0x00, 0x01, 0x00, 0x07, 0x80, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x5c, 0x80, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0xfe };
+
+static const struct sccp2sua_testcase sccp2sua_testcases[] = {
+ {
+ .name = "BSSMAP-RESET",
+ .sccp = PANDSIZ(bssmap_reset),
+ .sua = {
+ .hdr = XUA_HDR(SUA_MSGC_CL, SUA_CL_CLDT),
+ .parts = {
+ PARTU32(SUA_IEI_PROTO_CLASS, &sua_proto_class0),
+ PARTARR(SUA_IEI_DEST_ADDR, &sua_addr_ssn_bssmap),
+ PARTARR(SUA_IEI_SRC_ADDR, &sua_addr_ssn_bssmap),
+ },
+ },
+ }, {
+ .name = "BSSMAP-RESET-ACK",
+ .sccp = PANDSIZ(bssmap_reset_ack),
+ .sua = {
+ .hdr = XUA_HDR(SUA_MSGC_CL, SUA_CL_CLDT),
+ .parts = {
+ PARTU32(SUA_IEI_PROTO_CLASS, &sua_proto_class0),
+ PARTARR(SUA_IEI_DEST_ADDR, &sua_addr_ssn_bssmap_pc1),
+ PARTARR(SUA_IEI_SRC_ADDR, &sua_addr_ssn_bssmap_pc92),
+ },
+ },
+ }, {
+ .name = "BSSMAP-PAGING",
+ .sccp = PANDSIZ(bssmap_paging),
+ .sua = {
+ .hdr = XUA_HDR(SUA_MSGC_CL, SUA_CL_CLDT),
+ .parts = {
+ PARTU32(SUA_IEI_PROTO_CLASS, &sua_proto_class0),
+ PARTARR(SUA_IEI_DEST_ADDR, &sua_addr_ssn_bssmap_pc1),
+ PARTARR(SUA_IEI_SRC_ADDR, &sua_addr_ssn_bssmap_pc92),
+ },
+ },
+ }, {
+ .name = "BSSMAP-UDT",
+ .sccp = PANDSIZ(bssmap_udt),
+ .sua = {
+ .hdr = XUA_HDR(SUA_MSGC_CL, SUA_CL_CLDT),
+ .parts = {
+ PARTU32(SUA_IEI_PROTO_CLASS, &sua_proto_class0),
+ PARTARR(SUA_IEI_DEST_ADDR, &sua_addr_ssn_bssmap),
+ PARTARR(SUA_IEI_SRC_ADDR, &sua_addr_ssn_bssmap),
+ },
+ },
+ }, {
+ .name = "BSSMAP-CR",
+ .sccp = PANDSIZ(bssmap_cr),
+ .sua = {
+ .hdr = XUA_HDR(SUA_MSGC_CO, SUA_CO_CORE),
+ .parts = {
+ PARTU32(SUA_IEI_PROTO_CLASS, &sua_proto_class2),
+ PARTU32(SUA_IEI_SRC_REF, &sua_loc_ref_bsc),
+ PARTARR(SUA_IEI_DEST_ADDR, &sua_addr_ssn_bssmap),
+ },
+ },
+ }, {
+ .name = "BSSMAP-CC",
+ .sccp = PANDSIZ(bssmap_cc),
+ .sua = {
+ .hdr = XUA_HDR(SUA_MSGC_CO, SUA_CO_COAK),
+ .parts = {
+ PARTU32(SUA_IEI_PROTO_CLASS, &sua_proto_class2),
+ PARTU32(SUA_IEI_SRC_REF, &sua_loc_ref_msc),
+ PARTARR(SUA_IEI_DEST_ADDR, &sua_loc_ref_bsc),
+ },
+ },
+ }, {
+ .name = "BSSMAP-DTAP",
+ .sccp = PANDSIZ(bssmap_dtap),
+ .sua = {
+ .hdr = XUA_HDR(SUA_MSGC_CO, SUA_CO_CODT),
+ .parts = {
+ PARTU32(SUA_IEI_SRC_REF, &sua_loc_ref_msc),
+ },
+ },
+ }, {
+ .name = "BSSMAP-CLEAR",
+ .sccp = PANDSIZ(bssmap_clear),
+ .sua = {
+ .hdr = XUA_HDR(SUA_MSGC_CO, SUA_CO_CODT),
+ .parts = {
+ PARTU32(SUA_IEI_SRC_REF, &sua_loc_ref_msc),
+ },
+ },
+ }, {
+ .name = "BSSMAP-RELEASED",
+ .sccp = PANDSIZ(bssmap_released),
+ .sua = {
+ .hdr = XUA_HDR(SUA_MSGC_CO, SUA_CO_RELRE),
+ .parts = {
+ PARTU32(SUA_IEI_DEST_REF, &sua_loc_ref_msc),
+ PARTU32(SUA_IEI_SRC_REF, &sua_loc_ref_bsc),
+ PARTU32(SUA_IEI_CAUSE, &sua_cause0),
+ },
+ },
+ }, {
+ .name = "BSSMAP-RELEASE_COMPLETE",
+ .sccp = PANDSIZ(bssmap_release_complete),
+ .sua = {
+ .hdr = XUA_HDR(SUA_MSGC_CO, SUA_CO_RELCO),
+ .parts = {
+ PARTU32(SUA_IEI_DEST_REF, &sua_loc_ref_bsc),
+ PARTU32(SUA_IEI_SRC_REF, &sua_loc_ref_msc),
+ },
+ },
+ }, {
+ .name = "TCAP",
+ .sccp = PANDSIZ(tcap_global_title),
+ .sua = {
+ .hdr = XUA_HDR(SUA_MSGC_CL, SUA_CL_CLDT),
+ .parts = {
+ },
+ },
+ },
+};
+
+static void test_sccp2sua_case(const struct sccp2sua_testcase *tcase)
+{
+ struct xua_msg *xua;
+ struct msgb *msg = msgb_alloc(300, "SCCP2SUA Test Input");
+ struct msgb *msg2;
+
+ printf("\n=> %s\n", tcase->name);
+ msg->l2h = msgb_put(msg, tcase->sccp.length);
+ memcpy(msg->l2h, tcase->sccp.bin, tcase->sccp.length);
+ printf("SCCP Input: %s\n", msgb_hexdump(msg));
+ printf("Transcoding message SCCP -> XUA\n");
+ xua = osmo_sccp_to_xua(msg);
+ OSMO_ASSERT(xua);
+
+ printf("Decoded SUA: ");
+ printf("%s\n", xua_msg_dump(xua, &xua_dialect_sua));
+
+ printf("Re-Encoding decoded SUA to SCCP\n");
+ msg2 = osmo_sua_to_sccp(xua);
+ OSMO_ASSERT(msg2);
+ /* Re-encode xUA to SCCP */
+ printf("SCCP Output: %s\n", msgb_hexdump(msg2));
+
+ if (msgb_length(msg) != msgb_length(msg2) ||
+ memcmp(msgb_data(msg), msgb_data(msg2), msgb_length(msg)))
+ printf("Input != re-encoded output!\n");
+
+ /* free related data */
+ msgb_free(msg);
+ msgb_free(msg2);
+ xua_msg_free(xua);
+}
+
+static void test_sccp2sua(void)
+{
+ unsigned int i;
+ for (i = 0; i < ARRAY_SIZE(sccp2sua_testcases); i++) {
+ test_sccp2sua_case(&sccp2sua_testcases[i]);
+ }
+}
+
+
+static const struct log_info_cat default_categories[] = {
+ [0] = {
+ .name = "DSCCP",
+ .description = "DSCP",
+ .enabled = 1, .loglevel = LOGL_DEBUG,
+ },
+};
+
+static const struct log_info log_info = {
+ .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);
+
+ test_isup_parse();
+ test_sccp_addr_parser();
+ test_helpers();
+ test_sccp2sua();
+
+ printf("All tests passed.\n");
+ return 0;
+}
diff --git a/tests/xua/xua_test.ok b/tests/xua/xua_test.ok
new file mode 100644
index 0000000..a9fba1d
--- /dev/null
+++ b/tests/xua/xua_test.ok
@@ -0,0 +1,131 @@
+digits='01234567' (8)
+digits='0123456' (7)
+sccp_addr_parse test case 0
+expected: RI=7,SSN=6,GTI=4,GT=(TT=0,NPL=1,NAI=4,DIG=919969679389)
+parsed: RI=7,SSN=6,GTI=4,GT=(TT=0,NPL=1,NAI=4,DIG=919969679389)
+sccp_addr_parse test case 1
+expected: RI=7,SSN=8,GTI=4,GT=(TT=0,NPL=1,NAI=4,DIG=919869299992)
+parsed: RI=7,SSN=8,GTI=4,GT=(TT=0,NPL=1,NAI=4,DIG=919869299992)
+sccp_addr_parse test case 2
+expected: RI=7,SSN=254,GTI=0
+parsed: RI=7,SSN=254,GTI=0
+Testing Decoded GT -> SUA encoding
+IN: TT=0,NPL=1,NAI=4,DIG=919969679389
+OUT:TT=0,NPL=1,NAI=4,DIG=919969679389
+
+=> BSSMAP-RESET
+SCCP Input: [L2]> 09 00 03 05 07 02 42 fe 02 42 fe 06 00 04 30 04 01 20
+Transcoding message SCCP -> XUA
+Decoded SUA: HDR=(CL:CLDT,V=0,LEN=0),
+ PART(T=Protocol Class,L=4,D=00000000),
+ PART(T=Destination Address,L=12,D=0002000180030008000000fe),
+ PART(T=Source Address,L=12,D=0002000180030008000000fe),
+ PART(T=Data,L=6,D=000430040120)
+Re-Encoding decoded SUA to SCCP
+SCCP Output: 09 00 03 05 07 02 42 fe 02 42 fe 06 00 04 30 04 01 20
+
+=> BSSMAP-RESET-ACK
+SCCP Input: [L2]> 09 00 03 07 0b 04 43 01 00 fe 04 43 5c 00 fe 03 00 01 31
+Transcoding message SCCP -> XUA
+Decoded SUA: HDR=(CL:CLDT,V=0,LEN=0),
+ PART(T=Protocol Class,L=4,D=00000000),
+ PART(T=Destination Address,L=20,D=00020003800200080000000180030008000000fe),
+ PART(T=Source Address,L=20,D=00020003800200080000005c80030008000000fe),
+ PART(T=Data,L=3,D=000131)
+Re-Encoding decoded SUA to SCCP
+SCCP Output: 09 00 03 07 0b 04 43 01 00 fe 04 43 5c 00 fe 03 00 01 31
+
+=> BSSMAP-PAGING
+SCCP Input: [L2]> 09 00 03 07 0b 04 43 01 00 fe 04 43 5c 00 fe 10 00 0e 52 08 08 29 47 10 02 01 31 97 61 1a 01 06
+Transcoding message SCCP -> XUA
+Decoded SUA: HDR=(CL:CLDT,V=0,LEN=0),
+ PART(T=Protocol Class,L=4,D=00000000),
+ PART(T=Destination Address,L=20,D=00020003800200080000000180030008000000fe),
+ PART(T=Source Address,L=20,D=00020003800200080000005c80030008000000fe),
+ PART(T=Data,L=16,D=000e52080829471002013197611a0106)
+Re-Encoding decoded SUA to SCCP
+SCCP Output: 09 00 03 07 0b 04 43 01 00 fe 04 43 5c 00 fe 10 00 0e 52 08 08 29 47 10 02 01 31 97 61 1a 01 06
+
+=> BSSMAP-UDT
+SCCP Input: [L2]> 09 00 03 05 07 02 42 fe 02 42 fe 10 00 0e 52 08 08 29 47 10 02 01 31 97 61 1a 01 06
+Transcoding message SCCP -> XUA
+Decoded SUA: HDR=(CL:CLDT,V=0,LEN=0),
+ PART(T=Protocol Class,L=4,D=00000000),
+ PART(T=Destination Address,L=12,D=0002000180030008000000fe),
+ PART(T=Source Address,L=12,D=0002000180030008000000fe),
+ PART(T=Data,L=16,D=000e52080829471002013197611a0106)
+Re-Encoding decoded SUA to SCCP
+SCCP Output: 09 00 03 05 07 02 42 fe 02 42 fe 10 00 0e 52 08 08 29 47 10 02 01 31 97 61 1a 01 06
+
+=> BSSMAP-CR
+SCCP Input: [L2]> 01 01 02 03 02 02 04 02 42 fe 0f 1f 00 1d 57 05 08 00 72 f4 80 20 12 c3 50 17 10 05 24 11 03 33 19 a2 08 29 47 10 02 01 31 97 61 00
+Transcoding message SCCP -> XUA
+Decoded SUA: HDR=(CO:CORE,V=0,LEN=0),
+ PART(T=Protocol Class,L=4,D=00000002),
+ PART(T=Source Reference,L=4,D=00010203),
+ PART(T=Destination Address,L=12,D=0002000180030008000000fe),
+ PART(T=Data,L=31,D=001d5705080072f4802012c3501710052411033319a2082947100201319761)
+Re-Encoding decoded SUA to SCCP
+SCCP Output: 01 01 02 03 02 02 04 02 42 fe 0f 1f 00 1d 57 05 08 00 72 f4 80 20 12 c3 50 17 10 05 24 11 03 33 19 a2 08 29 47 10 02 01 31 97 61 00
+
+=> BSSMAP-CC
+SCCP Input: [L2]> 02 01 02 03 00 00 03 02 01 00
+Transcoding message SCCP -> XUA
+Decoded SUA: HDR=(CO:COAK,V=0,LEN=0),
+ PART(T=Protocol Class,L=4,D=00000002),
+ PART(T=Destination Reference,L=4,D=00010203),
+ PART(T=Source Reference,L=4,D=00000003)
+Re-Encoding decoded SUA to SCCP
+SCCP Output: 02 01 02 03 00 00 03 02 01 00
+
+=> BSSMAP-DTAP
+SCCP Input: [L2]> 06 00 00 03 00 01 0f 01 00 0c 03 05 5c 08 11 81 33 66 02 13 45 f4
+Transcoding message SCCP -> XUA
+Decoded SUA: HDR=(CO:CODT,V=0,LEN=0),
+ PART(T=Destination Reference,L=4,D=00000003),
+ PART(T=Segmentation,L=4,D=00000000),
+ PART(T=Data,L=15,D=01000c03055c0811813366021345f4)
+Re-Encoding decoded SUA to SCCP
+SCCP Output: 06 00 00 03 00 01 0f 01 00 0c 03 05 5c 08 11 81 33 66 02 13 45 f4
+
+=> BSSMAP-CLEAR
+SCCP Input: [L2]> 06 00 00 03 00 01 06 00 04 20 04 01 09
+Transcoding message SCCP -> XUA
+Decoded SUA: HDR=(CO:CODT,V=0,LEN=0),
+ PART(T=Destination Reference,L=4,D=00000003),
+ PART(T=Segmentation,L=4,D=00000000),
+ PART(T=Data,L=6,D=000420040109)
+Re-Encoding decoded SUA to SCCP
+SCCP Output: 06 00 00 03 00 01 06 00 04 20 04 01 09
+
+=> BSSMAP-RELEASED
+SCCP Input: [L2]> 04 00 00 03 01 02 03 00 01 0f 02 23 42 00
+Transcoding message SCCP -> XUA
+Decoded SUA: HDR=(CO:RELRE,V=0,LEN=0),
+ PART(T=Destination Reference,L=4,D=00000003),
+ PART(T=Source Reference,L=4,D=00010203),
+ PART(T=Cause,L=4,D=00000300),
+ PART(T=Data,L=2,D=2342)
+Re-Encoding decoded SUA to SCCP
+SCCP Output: 04 00 00 03 01 02 03 00 01 0f 02 23 42 00
+
+=> BSSMAP-RELEASE_COMPLETE
+SCCP Input: [L2]> 05 01 02 03 00 00 03
+Transcoding message SCCP -> XUA
+Decoded SUA: HDR=(CO:RELCO,V=0,LEN=0),
+ PART(T=Destination Reference,L=4,D=00010203),
+ PART(T=Source Reference,L=4,D=00000003)
+Re-Encoding decoded SUA to SCCP
+SCCP Output: 05 01 02 03 00 00 03
+
+=> TCAP
+SCCP Input: [L2]> 09 81 03 0d 18 0a 12 07 00 12 04 53 84 09 00 17 0b 12 06 00 12 04 44 87 20 00 20 65 9a 65 81 97 48 04 26 00 01 98 49 04 51 01 03 df 6c 81 88 a1 81 85 02 01 44 02 01 07 30 80 a7 80 a0 80 04 01 2b 30 80 30 12 83 01 10 84 01 07 85 07 91 44 57 76 67 16 97 86 01 20 30 06 82 01 18 84 01 04 00 00 00 00 a3 06 04 01 42 84 01 05 a3 06 04 01 51 84 01 05 a3 06 04 01 31 84 01 05 a3 09 04 01 12 84 01 05 82 01 02 a3 09 04 01 11 84 01 05 81 01 01 a3 06 04 01 14 84 01 00 a3 0b 04 01 41 84 01 04 30 03 83 01 10 a3 0b 04 01 41 84 01 04 30 03 82 01 18 00 00 00 00
+Transcoding message SCCP -> XUA
+Decoded SUA: HDR=(CL:CLDT,V=0,LEN=0),
+ PART(T=Protocol Class,L=4,D=00000081),
+ PART(T=Destination Address,L=32,D=0001000580010014000000040a00010453840900170000008003000800000007),
+ PART(T=Source Address,L=32,D=0001000580010014000000040c00010444872000206500008003000800000006),
+ PART(T=Data,L=154,D=6581974804260001984904510103df6c8188a181850201440201073080a780a08004012b30803012830110840107850791445776671697860120300682011884010400000000a306040142840105a306040151840105a306040131840105a309040112840105820102a309040111840105810101a306040114840100a30b0401418401043003830110a30b040141840104300382011800000000)
+Re-Encoding decoded SUA to SCCP
+SCCP Output: 09 81 03 0d 18 0a 12 07 00 12 04 53 84 09 00 17 0b 12 06 00 12 04 44 87 20 00 20 65 9a 65 81 97 48 04 26 00 01 98 49 04 51 01 03 df 6c 81 88 a1 81 85 02 01 44 02 01 07 30 80 a7 80 a0 80 04 01 2b 30 80 30 12 83 01 10 84 01 07 85 07 91 44 57 76 67 16 97 86 01 20 30 06 82 01 18 84 01 04 00 00 00 00 a3 06 04 01 42 84 01 05 a3 06 04 01 51 84 01 05 a3 06 04 01 31 84 01 05 a3 09 04 01 12 84 01 05 82 01 02 a3 09 04 01 11 84 01 05 81 01 01 a3 06 04 01 14 84 01 00 a3 0b 04 01 41 84 01 04 30 03 83 01 10 a3 0b 04 01 41 84 01 04 30 03 82 01 18 00 00 00 00
+All tests passed.