Move osmo_gsup_messages.[ch] to libosmocore

This requires the corresponding commit in libosmocore.
diff --git a/openbsc/tests/gprs/Makefile.am b/openbsc/tests/gprs/Makefile.am
index 633c362..902313f 100644
--- a/openbsc/tests/gprs/Makefile.am
+++ b/openbsc/tests/gprs/Makefile.am
@@ -5,7 +5,6 @@
 
 noinst_PROGRAMS = gprs_test
 
-gprs_test_SOURCES = gprs_test.c $(top_srcdir)/src/gprs/gprs_utils.c \
-		$(top_srcdir)/src/gprs/gprs_gsup_messages.c
+gprs_test_SOURCES = gprs_test.c $(top_srcdir)/src/gprs/gprs_utils.c
 
 gprs_test_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS)
diff --git a/openbsc/tests/gprs/gprs_test.c b/openbsc/tests/gprs/gprs_test.c
index 24e44cf..ff77404 100644
--- a/openbsc/tests/gprs/gprs_test.c
+++ b/openbsc/tests/gprs/gprs_test.c
@@ -5,17 +5,14 @@
 #include <openbsc/gprs_llc.h>
 #include <openbsc/gprs_utils.h>
 
-#include <openbsc/gprs_gsup_messages.h>
-
 #include <openbsc/debug.h>
 
 #include <osmocom/core/application.h>
+#include <osmocom/gsm/gsup.h>
 
 #define ASSERT_FALSE(x) if (x)  { printf("Should have returned false.\n"); abort(); }
 #define ASSERT_TRUE(x)  if (!x) { printf("Should have returned true.\n"); abort(); }
 
-#define VERBOSE_FPRINTF(...)
-
 /**
  * GSM 04.64 8.4.2 Receipt of unacknowledged information
  */
@@ -146,239 +143,6 @@
 	}
 }
 
-/* Tests for osmo_gsup_messages.c */
-
-#define TEST_IMSI_IE 0x01, 0x08, 0x21, 0x43, 0x65, 0x87, 0x09, 0x21, 0x43, 0xf5
-#define TEST_IMSI_STR "123456789012345"
-
-static void test_gsup_messages_dec_enc(void)
-{
-	int test_idx;
-	int rc;
-	uint8_t buf[1024];
-
-	static const uint8_t send_auth_info_req[] = {
-		0x08,
-		TEST_IMSI_IE
-	};
-
-	static const uint8_t send_auth_info_err[] = {
-		0x09,
-		TEST_IMSI_IE,
-		0x02, 0x01, 0x07 /* GPRS no allowed */
-	};
-
-	static const uint8_t send_auth_info_res[] = {
-		0x0a,
-		TEST_IMSI_IE,
-		0x03, 0x22, /* Auth tuple */
-			0x20, 0x10,
-				0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
-				0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
-			0x21, 0x04,
-				0x21, 0x22, 0x23, 0x24,
-			0x22, 0x08,
-				0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
-		0x03, 0x22, /* Auth tuple */
-			0x20, 0x10,
-				0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
-				0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90,
-			0x21, 0x04,
-				0xa1, 0xa2, 0xa3, 0xa4,
-			0x22, 0x08,
-				0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8,
-	};
-
-	static const uint8_t update_location_req[] = {
-		0x04,
-		TEST_IMSI_IE,
-	};
-
-	static const uint8_t update_location_err[] = {
-		0x05,
-		TEST_IMSI_IE,
-		0x02, 0x01, 0x07 /* GPRS no allowed */
-	};
-
-	static const uint8_t update_location_res[] = {
-		0x06,
-		TEST_IMSI_IE,
-		0x08, 0x07, /* MSISDN of the subscriber */
-			0x91, 0x94, 0x61, 0x46, 0x32, 0x24, 0x43,
-		0x09, 0x07, /* HLR-Number of the subscriber */
-			0x91, 0x83, 0x52, 0x38, 0x48, 0x83, 0x93,
-		0x04, 0x00, /* PDP info complete */
-		0x05, 0x15,
-			0x10, 0x01, 0x01,
-			0x11, 0x02, 0xf1, 0x21, /* IPv4 */
-			0x12, 0x09, 0x04, 't', 'e', 's', 't', 0x03, 'a', 'p', 'n',
-			0x13, 0x01, 0x02,
-		0x05, 0x11,
-			0x10, 0x01, 0x02,
-			0x11, 0x02, 0xf1, 0x21, /* IPv4 */
-			0x12, 0x08, 0x03, 'f', 'o', 'o', 0x03, 'a', 'p', 'n',
-	};
-
-	static const uint8_t location_cancellation_req[] = {
-		0x1c,
-		TEST_IMSI_IE,
-		0x06, 0x01, 0x00,
-	};
-
-	static const uint8_t location_cancellation_err[] = {
-		0x1d,
-		TEST_IMSI_IE,
-		0x02, 0x01, 0x03 /* Illegal MS */
-	};
-
-	static const uint8_t location_cancellation_res[] = {
-		0x1e,
-		TEST_IMSI_IE,
-	};
-
-	static const uint8_t purge_ms_req[] = {
-		0x0c,
-		TEST_IMSI_IE,
-	};
-
-	static const uint8_t purge_ms_err[] = {
-		0x0d,
-		TEST_IMSI_IE,
-		0x02, 0x01, 0x03, /* Illegal MS */
-	};
-
-	static const uint8_t purge_ms_res[] = {
-		0x0e,
-		TEST_IMSI_IE,
-		0x07, 0x00,
-	};
-
-	static const struct test {
-		char *name;
-		const uint8_t *data;
-		size_t data_len;
-	} test_messages[] = {
-		{"Send Authentication Info Request",
-			send_auth_info_req, sizeof(send_auth_info_req)},
-		{"Send Authentication Info Error",
-			send_auth_info_err, sizeof(send_auth_info_err)},
-		{"Send Authentication Info Result",
-			send_auth_info_res, sizeof(send_auth_info_res)},
-		{"Update Location Request",
-			update_location_req, sizeof(update_location_req)},
-		{"Update Location Error",
-			update_location_err, sizeof(update_location_err)},
-		{"Update Location Result",
-			update_location_res, sizeof(update_location_res)},
-		{"Location Cancellation Request",
-			location_cancellation_req, sizeof(location_cancellation_req)},
-		{"Location Cancellation Error",
-			location_cancellation_err, sizeof(location_cancellation_err)},
-		{"Location Cancellation Result",
-			location_cancellation_res, sizeof(location_cancellation_res)},
-		{"Purge MS Request",
-			purge_ms_req, sizeof(purge_ms_req)},
-		{"Purge MS Error",
-			purge_ms_err, sizeof(purge_ms_err)},
-		{"Purge MS Result",
-			purge_ms_res, sizeof(purge_ms_res)},
-	};
-
-	printf("Test GSUP message decoding/encoding\n");
-
-	for (test_idx = 0; test_idx < ARRAY_SIZE(test_messages); test_idx++) {
-		const struct test *t = &test_messages[test_idx];
-		struct gprs_gsup_message gm = {0};
-		struct msgb *msg = msgb_alloc(4096, "gsup_test");
-
-		printf("  Testing %s\n", t->name);
-
-		rc = gprs_gsup_decode(t->data, t->data_len, &gm);
-		OSMO_ASSERT(rc >= 0);
-
-		gprs_gsup_encode(msg, &gm);
-
-		fprintf(stderr, "  generated message: %s\n", msgb_hexdump(msg));
-		fprintf(stderr, "  original message:  %s\n", osmo_hexdump(t->data, t->data_len));
-		fprintf(stderr, "  IMSI:              %s\n", gm.imsi);
-		OSMO_ASSERT(strcmp(gm.imsi, TEST_IMSI_STR) == 0);
-		OSMO_ASSERT(msgb_length(msg) == t->data_len);
-		OSMO_ASSERT(memcmp(msgb_data(msg), t->data, t->data_len) == 0);
-
-		msgb_free(msg);
-	}
-
-	/* simple truncation test */
-	for (test_idx = 0; test_idx < ARRAY_SIZE(test_messages); test_idx++) {
-		int j;
-		const struct test *t = &test_messages[test_idx];
-		int ie_end = t->data_len;
-		struct gprs_gsup_message gm = {0};
-		int counter = 0;
-		int parse_err = 0;
-
-		for (j = t->data_len - 1; j >= 0; --j) {
-			rc = gprs_gsup_decode(t->data, j, &gm);
-			counter += 1;
-
-			VERBOSE_FPRINTF(stderr,
-				"  partial message decoding: "
-				"orig_len = %d, trunc = %d, rc = %d, ie_end = %d\n",
-				t->data_len, j, rc, ie_end);
-			if (rc >= 0) {
-				VERBOSE_FPRINTF(stderr,
-					"    remaing partial message: %s\n",
-					osmo_hexdump(t->data + j, ie_end - j));
-
-				OSMO_ASSERT(j <= ie_end - 2);
-				OSMO_ASSERT(t->data[j+0] <= GPRS_GSUP_KC_IE);
-				OSMO_ASSERT(t->data[j+1] <= ie_end - j - 2);
-
-				ie_end = j;
-			} else {
-				parse_err += 1;
-			}
-		}
-
-		fprintf(stderr,
-			"  message %d: tested %d truncations, %d parse failures\n",
-			test_idx, counter, parse_err);
-	}
-
-	/* message modification test (relies on ASAN or valgrind being used) */
-	for (test_idx = 0; test_idx < ARRAY_SIZE(test_messages); test_idx++) {
-		int j;
-		const struct test *t = &test_messages[test_idx];
-		struct gprs_gsup_message gm = {0};
-		uint8_t val;
-		int counter = 0;
-		int parse_err = 0;
-
-		OSMO_ASSERT(sizeof(buf) >= t->data_len);
-
-		for (j = t->data_len - 1; j >= 0; --j) {
-			memcpy(buf, t->data, t->data_len);
-			val = 0;
-			do {
-				VERBOSE_FPRINTF(stderr,
-					"t = %d, len = %d, val = %d\n",
-					test_idx, j, val);
-				buf[j] = val;
-				rc = gprs_gsup_decode(buf, t->data_len, &gm);
-				counter += 1;
-				if (rc < 0)
-					parse_err += 1;
-
-				val += 1;
-			} while (val != (uint8_t)256);
-		}
-
-		fprintf(stderr,
-			"  message %d: tested %d modifications, %d parse failures\n",
-			test_idx, counter, parse_err);
-	}
-}
-
 static void test_gprs_timer_enc_dec(void)
 {
 	int i, u, secs, tmr;
@@ -465,7 +229,6 @@
 
 	test_8_4_2();
 	test_gsm_03_03_apn();
-	test_gsup_messages_dec_enc();
 	test_gprs_timer_enc_dec();
 
 	printf("Done.\n");
diff --git a/openbsc/tests/gprs/gprs_test.ok b/openbsc/tests/gprs/gprs_test.ok
index 688d44b..da7888c 100644
--- a/openbsc/tests/gprs/gprs_test.ok
+++ b/openbsc/tests/gprs/gprs_test.ok
@@ -13,18 +13,5 @@
 N(U) = 510, V(UR) = 511 => retransmit
 N(U) = 481, V(UR) = 511 => retransmit
 N(U) = 479, V(UR) = 511 => new
-Test GSUP message decoding/encoding
-  Testing Send Authentication Info Request
-  Testing Send Authentication Info Error
-  Testing Send Authentication Info Result
-  Testing Update Location Request
-  Testing Update Location Error
-  Testing Update Location Result
-  Testing Location Cancellation Request
-  Testing Location Cancellation Error
-  Testing Location Cancellation Result
-  Testing Purge MS Request
-  Testing Purge MS Error
-  Testing Purge MS Result
 Test GPRS timer decoding/encoding
 Done.
diff --git a/openbsc/tests/sgsn/Makefile.am b/openbsc/tests/sgsn/Makefile.am
index aebcf01..e3cec50 100644
--- a/openbsc/tests/sgsn/Makefile.am
+++ b/openbsc/tests/sgsn/Makefile.am
@@ -23,7 +23,6 @@
 	$(top_builddir)/src/gprs/sgsn_libgtp.o \
 	$(top_builddir)/src/gprs/sgsn_auth.o \
 	$(top_builddir)/src/gprs/sgsn_ares.o \
-	$(top_builddir)/src/gprs/gprs_gsup_messages.o \
 	$(top_builddir)/src/gprs/gprs_gsup_client.o \
 	$(top_builddir)/src/gprs/gprs_utils.o \
 	$(top_builddir)/src/gprs/gprs_subscriber.o \
diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c
index 94c277f..5cffff2 100644
--- a/openbsc/tests/sgsn/sgsn_test.c
+++ b/openbsc/tests/sgsn/sgsn_test.c
@@ -24,7 +24,7 @@
 #include <openbsc/gprs_gmm.h>
 #include <openbsc/debug.h>
 #include <openbsc/gsm_subscriber.h>
-#include <openbsc/gprs_gsup_messages.h>
+#include <osmocom/gsm/gsup.h>
 #include <openbsc/gprs_gsup_client.h>
 #include <openbsc/gprs_utils.h>
 #include <openbsc/gprs_gb_parse.h>
@@ -1266,13 +1266,13 @@
 
 int my_gprs_gsup_client_send(struct gprs_gsup_client *gsupc, struct msgb *msg)
 {
-	struct gprs_gsup_message to_peer = {0};
-	struct gprs_gsup_message from_peer = {0};
+	struct osmo_gsup_message to_peer = {0};
+	struct osmo_gsup_message from_peer = {0};
 	struct msgb *reply_msg;
 	int rc;
 
 	/* Simulate the GSUP peer */
-	rc = gprs_gsup_decode(msgb_data(msg), msgb_length(msg), &to_peer);
+	rc = osmo_gsup_decode(msgb_data(msg), msgb_length(msg), &to_peer);
 	OSMO_ASSERT(rc >= 0);
 	OSMO_ASSERT(to_peer.imsi[0] != 0);
 	strncpy(from_peer.imsi, to_peer.imsi, sizeof(from_peer.imsi));
@@ -1281,16 +1281,16 @@
 	msgb_free(msg);
 
 	switch (to_peer.message_type) {
-	case GPRS_GSUP_MSGT_UPDATE_LOCATION_REQUEST:
+	case OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST:
 		/* Send UPDATE_LOCATION_RESULT */
 		return my_subscr_request_update_gsup_auth(NULL);
 
-	case GPRS_GSUP_MSGT_SEND_AUTH_INFO_REQUEST:
+	case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST:
 		/* Send SEND_AUTH_INFO_RESULT */
 		return my_subscr_request_auth_info_gsup_auth(NULL);
 
-	case GPRS_GSUP_MSGT_PURGE_MS_REQUEST:
-		from_peer.message_type = GPRS_GSUP_MSGT_PURGE_MS_RESULT;
+	case OSMO_GSUP_MSGT_PURGE_MS_REQUEST:
+		from_peer.message_type = OSMO_GSUP_MSGT_PURGE_MS_RESULT;
 		break;
 
 	default:
@@ -1308,7 +1308,7 @@
 
 	reply_msg = gprs_gsup_msgb_alloc();
 	reply_msg->l2h = reply_msg->data;
-	gprs_gsup_encode(reply_msg, &from_peer);
+	osmo_gsup_encode(reply_msg, &from_peer);
 	gprs_subscr_rx_gsup_message(reply_msg);
 	msgb_free(reply_msg);