aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/mtp/Makefile.am4
-rw-r--r--tests/mtp/mtp_parse_test.c628
-rw-r--r--tests/patching/Makefile.am8
-rw-r--r--tests/patching/patching_test.c279
5 files changed, 920 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..b38aa6a
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = mtp patching
diff --git a/tests/mtp/Makefile.am b/tests/mtp/Makefile.am
new file mode 100644
index 0000000..1f364b6
--- /dev/null
+++ b/tests/mtp/Makefile.am
@@ -0,0 +1,4 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include -Wall
+noinst_PROGRAMS = mtp_parse_test
+
+mtp_parse_test_SOURCES = mtp_parse_test.c
diff --git a/tests/mtp/mtp_parse_test.c b/tests/mtp/mtp_parse_test.c
new file mode 100644
index 0000000..f1f218b
--- /dev/null
+++ b/tests/mtp/mtp_parse_test.c
@@ -0,0 +1,628 @@
+/* MTP Layer3 parsing tests */
+#include <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 u_int8_t *input;
+ const u_int16_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 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 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 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 pkt7[] = {
+0x80, 0x88, 0xc0, 0x16, 0x00, 0x14, 0x56, 0x00 };
+
+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 };
+
+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 u_int8_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 u_int8_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 u_int8_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)
+{
+ u_int32_t addr;
+ int i;
+
+ /* 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);
+ }
+
+ /* check the SCCP unitdata */
+ {
+ struct sccp_con_ctrl_prt_mgt prt = {
+ .sst = 0x03,
+ .assn = 254,
+ .apoc = MTP_MAKE_APOC(91),
+ .mul_ind = 1,
+ };
+
+ u_int8_t data[] = { 0x03, 0xfe, 0x5b, 0x00, 0x01 };
+ if (memcmp(&prt, data, 5) != 0) {
+ u_int8_t *d = (u_int8_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();
+ }
+ }
+
+ return 0;
+}
diff --git a/tests/patching/Makefile.am b/tests/patching/Makefile.am
new file mode 100644
index 0000000..d99a55a
--- /dev/null
+++ b/tests/patching/Makefile.am
@@ -0,0 +1,8 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include $(LAFORGE_CFLAGS) -Wall
+noinst_PROGRAMS = patching_test
+
+patching_test_SOURCES = patching_test.c $(top_srcdir)/src/bss_patch.c \
+ $(top_srcdir)/src/openbsc_nat/tlv_parser.c \
+ $(top_srcdir)/src/openbsc_nat/bssap.c
+patching_test_LDADD = $(LAFORGE_LIBS) $(SCCP_LIBS)
+
diff --git a/tests/patching/patching_test.c b/tests/patching/patching_test.c
new file mode 100644
index 0000000..8bd0d17
--- /dev/null
+++ b/tests/patching/patching_test.c
@@ -0,0 +1,279 @@
+#include <bss_patch.h>
+
+#include <laf0rge1/debug.h>
+
+#include <stdio.h>
+#include <string.h>
+
+u_int8_t pkt125[] = {
+0x06, 0x01, 0x04,
+0x00, 0x00, 0x01, 0x0b, 0x00, 0x09, 0x01, 0x0b,
+0x03, 0x01, 0x0b, 0x25, 0x01, 0x00, 0x02 };
+
+u_int8_t pkt125_res[] = {
+0x06, 0x01, 0x04,
+0x00, 0x00, 0x01, 0x0b, 0x00, 0x09, 0x01, 0x0b,
+0x03, 0x01, 0x0a, 0x11, 0x01, 0x00, 0x02 };
+
+u_int8_t pkt28[] = {
+0x06, 0x01, 0x05,
+0x2b, 0x00, 0x01, 0x09, 0x00, 0x07, 0x02, 0x21,
+0x08, 0x2c, 0x02, 0x40, 0x11 };
+u_int8_t pkt28_res[] = {
+0x06, 0x01, 0x05,
+0x2b, 0x00, 0x01, 0x09, 0x00, 0x07, 0x02, 0x21,
+0x09, 0x2c, 0x02, 0x40, 0x25 };
+
+u_int8_t reset_ack[] = {
+0x09, 0x00, 0x03,
+0x07, 0x0b, 0x04, 0x43, 0x0a, 0x00, 0xfe, 0x04,
+0x43, 0x5c, 0x00, 0xfe, 0x03, 0x00, 0x01, 0x31 };
+
+u_int8_t cc[] = {
+0x02, 0x01, 0x04,
+0x00, 0x01, 0x01, 0xb4, 0x02, 0x01, 0x00 };
+
+
+struct result {
+ u_int8_t *input;
+ int inp_len;
+ const u_int8_t *expected;
+ int exp_len;
+ int result;
+};
+
+
+static struct result results[] = {
+ {
+ .input = pkt125,
+ .inp_len = sizeof(pkt125),
+ .expected = pkt125_res,
+ .exp_len = sizeof(pkt125),
+ },
+
+ {
+ .input = pkt28,
+ .inp_len = sizeof(pkt28),
+ .expected = pkt28_res,
+ .exp_len = sizeof(pkt28_res),
+ },
+
+ {
+ .input = reset_ack,
+ .inp_len = sizeof(reset_ack),
+ .expected = reset_ack,
+ .exp_len = sizeof(reset_ack),
+ .result = BSS_FILTER_RESET_ACK,
+ },
+
+ {
+ .input = cc,
+ .inp_len = sizeof(cc),
+ .expected = cc,
+ .exp_len = sizeof(cc),
+ .result = 0,
+ },
+};
+
+static u_int8_t udt_with_poi[] = {
+0x09, 0x00, 0x03,
+0x07, 0x0b, 0x04, 0x43, 0x0a, 0x00, 0xfe, 0x04,
+0x43, 0x5c, 0x00, 0xfe, 0x10, 0x00, 0x0e, 0x44,
+0x04, 0x01, 0x00, 0x01, 0x00, 0x01, 0x1e, 0x05,
+0x1e, 0x00, 0x00, 0x00, 0x40 };
+
+static const u_int8_t udt_without_poi[] = {
+0x09, 0x00, 0x03,
+0x05, 0x07, 0x02, 0x42, 0xfe,
+ 0x02, 0x42, 0xfe,
+0x10, 0x00, 0x0e, 0x44,
+0x04, 0x01, 0x00, 0x01, 0x00, 0x01, 0x1e, 0x05,
+0x1e, 0x00, 0x00, 0x00, 0x40 };
+
+static u_int8_t cr_with_poi [] = {
+0x01, 0x01, 0x04,
+0x00, 0x02, 0x02, 0x06, 0x04, 0xc3, 0x5c, 0x00,
+0xfe, 0x0f, 0x21, 0x00, 0x1f, 0x57, 0x05, 0x08,
+0x00, 0x72, 0xf4, 0x80, 0x23, 0x29, 0xc3, 0x50,
+0x17, 0x10, 0x05, 0x24, 0x11, 0x03, 0x33, 0x19,
+0x81, 0x08, 0x29, 0x47, 0x80, 0x00, 0x00, 0x00,
+0x00, 0x80, 0x21, 0x01, 0x00 };
+
+static const u_int8_t cr_without_poi [] = {
+0x01, 0x01, 0x04,
+0x00, 0x02, 0x02, 0x04, 0x02, 0x42, 0xfe,
+0x0f, 0x21, 0x00, 0x1f, 0x57, 0x05, 0x08,
+0x00, 0x72, 0xf4, 0x80, 0x23, 0x29, 0xc3, 0x50,
+0x17, 0x10, 0x05, 0x24, 0x11, 0x03, 0x33, 0x19,
+0x81, 0x08, 0x29, 0x47, 0x80, 0x00, 0x00, 0x00,
+0x00, 0x80, 0x21, 0x01, 0x00 };
+
+static u_int8_t cr2_without_poi[] = {
+0x01, 0x00, 0x00, 0x03, 0x02, 0x02, 0x04, 0x02,
+0x42, 0xfe, 0x0f, 0x1f, 0x00, 0x1d, 0x57, 0x05,
+0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x1d, 0xc3,
+0x50, 0x17, 0x10, 0x05, 0x24, 0x31, 0x03, 0x50,
+0x18, 0x93, 0x08, 0x29, 0x47, 0x80, 0x00, 0x00,
+0x00, 0x00, 0x80, 0x00};
+
+static struct result rewrite_results_to_msc[] = {
+ {
+ .input = udt_with_poi,
+ .inp_len = sizeof(udt_with_poi),
+ .expected = udt_without_poi,
+ .exp_len = sizeof(udt_without_poi),
+ },
+
+ {
+ .input = cr_with_poi,
+ .inp_len = sizeof(cr_with_poi),
+ .expected = cr_without_poi,
+ .exp_len = sizeof(cr_without_poi),
+ },
+
+ {
+ .input = cr2_without_poi,
+ .inp_len = sizeof(cr2_without_poi),
+ .expected = cr2_without_poi,
+ .exp_len = sizeof(cr2_without_poi),
+ },
+};
+
+
+u_int8_t paging_cmd[] = {
+ 0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x0a,
+ 0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x10,
+ 0x00, 0x0e, 0x52, 0x08, 0x08, 0x29, 0x80, 0x10,
+ 0x76, 0x10, 0x77, 0x46, 0x05, 0x1a, 0x01, 0x06 };
+u_int8_t paging_cmd_patched[] = {
+ 0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x02,
+ 0x00, 0xfe, 0x04, 0x43, 0x01, 0x00, 0xfe, 0x10,
+ 0x00, 0x0e, 0x52, 0x08, 0x08, 0x29, 0x80, 0x10,
+ 0x76, 0x10, 0x77, 0x46, 0x05, 0x1a, 0x01, 0x06 };
+
+static struct result rewrite_results_to_bsc[] = {
+ {
+ .input = paging_cmd,
+ .inp_len = sizeof(paging_cmd),
+ .expected = paging_cmd_patched,
+ .exp_len = sizeof(paging_cmd_patched),
+ },
+};
+
+static void test_patch_filter(void)
+{
+ int i;
+
+ printf("Testing patching of GSM messages to the MSC.\n");
+
+ for (i = 0; i < sizeof(results)/sizeof(results[0]); ++i) {
+ struct sccp_parse_result result;
+ struct msgb *msg;
+ int rc;
+
+ msg = msgb_alloc_headroom(256, 8, "test");
+ msgb_put(msg, 1);
+ msg->l2h = msgb_put(msg, results[i].inp_len);
+ memcpy(msg->l2h, results[i].input, msgb_l2len(msg));
+ rc = bss_patch_filter_msg(msg, &result);
+
+ if (memcmp(msg->l2h, results[i].expected, results[i].exp_len) != 0) {
+ printf("Failed to patch the packet.\n");
+ abort();
+ }
+ if (rc != results[i].result) {
+ printf("Didn't get the result we wanted on %d\n", i),
+ abort();
+ }
+
+ msgb_free(msg);
+ }
+}
+
+static void test_rewrite_msc(void)
+{
+ int i;
+
+ printf("Testing rewriting the SCCP header.\n");
+ for (i = 0; i < sizeof(rewrite_results_to_msc)/sizeof(rewrite_results_to_msc[0]); ++i) {
+ struct sccp_parse_result result;
+ struct msgb *inp;
+ struct msgb *outp;
+ int rc;
+
+ outp = msgb_alloc_headroom(256, 8, "test2");
+ inp = msgb_alloc_headroom(256, 8, "test1");
+ msgb_put(inp, 1);
+ inp->l2h = msgb_put(inp, rewrite_results_to_msc[i].inp_len);
+ memcpy(inp->l2h, rewrite_results_to_msc[i].input, msgb_l2len(inp));
+
+ rc = bss_patch_filter_msg(inp, &result);
+ if (rc < 0) {
+ printf("Failed to parse header msg: %d\n", i);
+ abort();
+ }
+
+ bss_rewrite_header_for_msc(rc, outp, inp, &result);
+
+ memset(&result, 0, sizeof(result));
+ rc = bss_patch_filter_msg(outp, &result);
+ if (rc < 0) {
+ printf("Patched message doesn't work: %d\n", i);
+ printf("hex: %s\n", hexdump(outp->l2h, msgb_l2len(outp)));
+ abort();
+ }
+
+ if (msgb_l2len(outp) != rewrite_results_to_msc[i].exp_len) {
+ printf("The length's don#t match on %d %u != %u\n",
+ i, msgb_l2len(outp), rewrite_results_to_msc[i].exp_len);
+ printf("hex: %s\n", hexdump(outp->l2h, msgb_l2len(outp)));
+ abort();
+ }
+
+ if (memcmp(outp->l2h, rewrite_results_to_msc[i].expected, rewrite_results_to_msc[i].exp_len) != 0) {
+ printf("Expected results don't match for: %d\n", i);
+ printf("hex: %s\n", hexdump(outp->l2h, msgb_l2len(outp)));
+ abort();
+ }
+
+ msgb_free(outp);
+ msgb_free(inp);
+ }
+}
+
+static void test_rewrite_bsc(void)
+{
+ int i;
+
+ printf("Testing rewriting the SCCP header for BSC.\n");
+ for (i = 0; i < sizeof(rewrite_results_to_bsc)/sizeof(rewrite_results_to_bsc[0]); ++i) {
+ struct msgb *inp;
+
+ inp = msgb_alloc_headroom(256, 8, "test1");
+ msgb_put(inp, 1);
+ inp->l2h = msgb_put(inp, rewrite_results_to_bsc[i].inp_len);
+ memcpy(inp->l2h, rewrite_results_to_bsc[i].input, msgb_l2len(inp));
+
+ if (bss_rewrite_header_to_bsc(inp, 1, 2) != 0) {
+ fprintf(stderr, "Failed to rewrite header\n");
+ abort();
+ }
+
+ if (memcmp(inp->l2h, rewrite_results_to_bsc[i].expected, msgb_l2len(inp))!= 0) {
+ fprintf(stderr, "Content does not match\n");
+ printf("got: %s\n", hexdump(inp->l2h, msgb_l2len(inp)));
+ abort();
+ }
+
+ msgb_free(inp);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ test_patch_filter();
+ test_rewrite_msc();
+ test_rewrite_bsc();
+ printf("DONE!\n");
+ return 0;
+}