diff mbox

[1/3] gprs: Remove gprs_apn_to_str and gprs_str_to_apn

Message ID 1451990563-4184-2-git-send-email-jerlbeck@sysmocom.de
State New
Headers show

Commit Message

Jacob Erlbeck Jan. 5, 2016, 10:42 a.m. UTC
These functions are moved to libosmocore.

This commit removes the definitions and changes the
names to the corresponding libosmogsm ones:

  gprs_str_to_apn -> osmo_apn_from_str
  gprs_apn_to_str -> osmo_apn_to_str

Sponsored-by: On-Waves ehf
---
 openbsc/include/openbsc/gprs_utils.h |  4 +--
 openbsc/src/gprs/gb_proxy_patch.c    |  7 ++--
 openbsc/src/gprs/gb_proxy_vty.c      |  6 ++--
 openbsc/src/gprs/gprs_sgsn.c         |  4 +--
 openbsc/src/gprs/gprs_subscriber.c   |  5 +--
 openbsc/src/gprs/gprs_utils.c        | 62 ------------------------------------
 openbsc/src/gprs/gtphub.c            |  4 +--
 openbsc/src/gprs/sgsn_cdr.c          |  5 +--
 openbsc/src/gprs/sgsn_vty.c          |  2 +-
 openbsc/tests/gbproxy/gbproxy_test.c | 13 ++++----
 openbsc/tests/gprs/gprs_test.c       | 29 +++++++++--------
 openbsc/tests/gtphub/Makefile.am     |  1 +
 openbsc/tests/sgsn/sgsn_test.c       | 13 ++++----
 13 files changed, 49 insertions(+), 106 deletions(-)
diff mbox

Patch

diff --git a/openbsc/include/openbsc/gprs_utils.h b/openbsc/include/openbsc/gprs_utils.h
index 6880e05..7af83ba 100644
--- a/openbsc/include/openbsc/gprs_utils.h
+++ b/openbsc/include/openbsc/gprs_utils.h
@@ -23,15 +23,13 @@ 
 
 #include <stdint.h>
 #include <sys/types.h>
+#include <osmocom/core/defs.h>
 
 struct msgb;
 
 struct msgb *gprs_msgb_copy(const struct msgb *msg, const char *name);
 int gprs_msgb_resize_area(struct msgb *msg, uint8_t *area,
 			    size_t old_size, size_t new_size);
-char *gprs_apn_to_str(char *out_str, const uint8_t *apn_enc, size_t rest_chars);
-int gprs_str_to_apn(uint8_t *apn_enc, size_t max_len, const char *str);
-
 /* GSM 04.08, 10.5.7.3 GPRS Timer */
 int gprs_tmr_to_secs(uint8_t tmr);
 uint8_t gprs_secs_to_tmr_floor(int secs);
diff --git a/openbsc/src/gprs/gb_proxy_patch.c b/openbsc/src/gprs/gb_proxy_patch.c
index c1d2497..725a863 100644
--- a/openbsc/src/gprs/gb_proxy_patch.c
+++ b/openbsc/src/gprs/gb_proxy_patch.c
@@ -28,6 +28,7 @@ 
 #include <openbsc/debug.h>
 
 #include <osmocom/gprs/protocol/gsm_08_18.h>
+#include <osmocom/gsm/apn.h>
 #include <osmocom/core/rate_ctr.h>
 
 /* patch RA identifier in place */
@@ -102,7 +103,7 @@  static void gbproxy_patch_apn_ie(struct msgb *msg,
 		LOGP(DGPRS, LOGL_DEBUG,
 		     "Patching %s to SGSN: Removing APN '%s'\n",
 		     log_text,
-		     gprs_apn_to_str(str1, apn, apn_len));
+		     osmo_apn_to_str(str1, apn, apn_len));
 
 		*new_apn_ie_len = 0;
 		gprs_msgb_resize_area(msg, apn_ie, apn_ie_len, 0);
@@ -117,8 +118,8 @@  static void gbproxy_patch_apn_ie(struct msgb *msg,
 		     "Patching %s to SGSN: "
 		     "Replacing APN '%s' -> '%s'\n",
 		     log_text,
-		     gprs_apn_to_str(str1, apn, apn_len),
-		     gprs_apn_to_str(str2, peer->cfg->core_apn,
+		     osmo_apn_to_str(str1, apn, apn_len),
+		     osmo_apn_to_str(str2, peer->cfg->core_apn,
 				       peer->cfg->core_apn_size));
 
 		*new_apn_ie_len = peer->cfg->core_apn_size + 2;
diff --git a/openbsc/src/gprs/gb_proxy_vty.c b/openbsc/src/gprs/gb_proxy_vty.c
index 933b6b0..bf11a6d 100644
--- a/openbsc/src/gprs/gb_proxy_vty.c
+++ b/openbsc/src/gprs/gb_proxy_vty.c
@@ -29,10 +29,10 @@ 
 
 #include <openbsc/gsm_04_08.h>
 #include <osmocom/gprs/gprs_ns.h>
+#include <osmocom/gsm/apn.h>
 
 #include <openbsc/debug.h>
 #include <openbsc/gb_proxy.h>
-#include <openbsc/gprs_utils.h>
 #include <openbsc/vty.h>
 
 #include <osmocom/vty/command.h>
@@ -107,7 +107,7 @@  static int config_write_gbproxy(struct vty *vty)
 	       if (g_cfg->core_apn_size > 0) {
 		       char str[500] = {0};
 		       vty_out(vty, " core-access-point-name %s%s",
-			       gprs_apn_to_str(str, g_cfg->core_apn,
+			       osmo_apn_to_str(str, g_cfg->core_apn,
 						 g_cfg->core_apn_size),
 			       VTY_NEWLINE);
 	       } else {
@@ -279,7 +279,7 @@  static int set_core_apn(struct vty *vty, const char *apn)
 		g_cfg->core_apn =
 			talloc_realloc_size(NULL, g_cfg->core_apn, apn_len + 1);
 		g_cfg->core_apn_size =
-			gprs_str_to_apn(g_cfg->core_apn, apn_len + 1, apn);
+			osmo_apn_from_str(g_cfg->core_apn, apn_len + 1, apn);
 	}
 
 	return CMD_SUCCESS;
diff --git a/openbsc/src/gprs/gprs_sgsn.c b/openbsc/src/gprs/gprs_sgsn.c
index c4dc9d7..b770a3a 100644
--- a/openbsc/src/gprs/gprs_sgsn.c
+++ b/openbsc/src/gprs/gprs_sgsn.c
@@ -29,6 +29,7 @@ 
 #include <osmocom/core/backtrace.h>
 #include <osmocom/gprs/gprs_ns.h>
 #include <osmocom/gprs/gprs_bssgp.h>
+#include <osmocom/gsm/apn.h>
 
 #include <openbsc/gsm_subscriber.h>
 #include <openbsc/debug.h>
@@ -36,7 +37,6 @@ 
 #include <openbsc/sgsn.h>
 #include <openbsc/gsm_04_08_gprs.h>
 #include <openbsc/gprs_gmm.h>
-#include <openbsc/gprs_utils.h>
 #include <openbsc/signal.h>
 #include "openbsc/gprs_llc.h"
 
@@ -650,7 +650,7 @@  struct sgsn_ggsn_ctx *sgsn_mm_ctx_find_ggsn_ctx(struct sgsn_mm_ctx *mmctx,
 			return NULL;
 		}
 
-		gprs_apn_to_str(req_apn_str,
+		osmo_apn_to_str(req_apn_str,
 				TLVP_VAL(tp, GSM48_IE_GSM_APN),
 				TLVP_LEN(tp, GSM48_IE_GSM_APN));
 
diff --git a/openbsc/src/gprs/gprs_subscriber.c b/openbsc/src/gprs/gprs_subscriber.c
index 3467293..8f5dc9d 100644
--- a/openbsc/src/gprs/gprs_subscriber.c
+++ b/openbsc/src/gprs/gprs_subscriber.c
@@ -27,10 +27,11 @@ 
 #include <openbsc/gprs_sgsn.h>
 #include <openbsc/gprs_gmm.h>
 #include <openbsc/gprs_gsup_messages.h>
-#include <openbsc/gprs_utils.h>
 
 #include <openbsc/debug.h>
 
+#include <osmocom/gsm/apn.h>
+
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
@@ -328,7 +329,7 @@  static void gprs_subscr_gsup_insert_data(struct gsm_subscriber *subscr,
 
 		OSMO_ASSERT(pdp_data != NULL);
 		pdp_data->pdp_type = pdp_info->pdp_type;
-		gprs_apn_to_str(pdp_data->apn_str,
+		osmo_apn_to_str(pdp_data->apn_str,
 				pdp_info->apn_enc, pdp_info->apn_enc_len);
 		memcpy(pdp_data->qos_subscribed, pdp_info->qos_enc, pdp_info->qos_enc_len);
 		pdp_data->qos_subscribed_len = pdp_info->qos_enc_len;
diff --git a/openbsc/src/gprs/gprs_utils.c b/openbsc/src/gprs/gprs_utils.c
index ad479db..8a98ae6 100644
--- a/openbsc/src/gprs/gprs_utils.c
+++ b/openbsc/src/gprs/gprs_utils.c
@@ -113,68 +113,6 @@  int gprs_msgb_resize_area(struct msgb *msg, uint8_t *area,
 	return 0;
 }
 
-/* TODO: Move these conversion functions to a utils file. */
-/* TODO: consolidate with gprs_apn2str(). */
-/** memmove apn_enc to out_str, replacing the length octets in apn_enc with '.'
- * (omitting the first one) and terminating with a '\0'.
- * out_str needs to have rest_chars amount of bytes or 1 whatever is bigger.
- */
-char * gprs_apn_to_str(char *out_str, const uint8_t *apn_enc, size_t rest_chars)
-{
-	char *str = out_str;
-
-	while (rest_chars > 0 && apn_enc[0]) {
-		size_t label_size = apn_enc[0];
-		if (label_size + 1 > rest_chars)
-			return NULL;
-
-		memmove(str, apn_enc + 1, label_size);
-		str += label_size;
-		rest_chars -= label_size + 1;
-		apn_enc += label_size + 1;
-
-		if (rest_chars)
-			*(str++) = '.';
-	}
-	str[0] = '\0';
-
-	return out_str;
-}
-
-int gprs_str_to_apn(uint8_t *apn_enc, size_t max_len, const char *str)
-{
-	uint8_t *last_len_field;
-	int len;
-
-	/* Can we even write the length field to the output? */
-	if (max_len == 0)
-		return -1;
-
-	/* Remember where we need to put the length once we know it */
-	last_len_field = apn_enc;
-	len = 1;
-	apn_enc += 1;
-
-	while (str[0]) {
-		if (len >= max_len)
-			return -1;
-
-		if (str[0] == '.') {
-			*last_len_field = (apn_enc - last_len_field) - 1;
-			last_len_field = apn_enc;
-		} else {
-			*apn_enc = str[0];
-		}
-		apn_enc += 1;
-		str += 1;
-		len += 1;
-	}
-
-	*last_len_field = (apn_enc - last_len_field) - 1;
-
-	return len;
-}
-
 /* GSM 04.08, 10.5.7.3 GPRS Timer */
 int gprs_tmr_to_secs(uint8_t tmr)
 {
diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c
index f26a56a..09175eb 100644
--- a/openbsc/src/gprs/gtphub.c
+++ b/openbsc/src/gprs/gtphub.c
@@ -34,13 +34,13 @@ 
 
 #include <openbsc/gtphub.h>
 #include <openbsc/debug.h>
-#include <openbsc/gprs_utils.h>
 
 #include <osmocom/core/utils.h>
 #include <osmocom/core/logging.h>
 #include <osmocom/core/socket.h>
 #include <osmocom/core/rate_ctr.h>
 #include <osmocom/core/stats.h>
+#include <osmocom/gsm/apn.h>
 
 
 static const int GTPH_GC_TICK_SECONDS = 1;
@@ -498,7 +498,7 @@  static int get_ie_apn_str(union gtpie_member *ie[], const char **apn_str)
 		len = sizeof(apn_buf) - 1;
 	apn_buf[len] = '\0';
 
-	*apn_str = gprs_apn_to_str(apn_buf, (uint8_t*)apn_buf, len);
+	*apn_str = osmo_apn_to_str(apn_buf, (uint8_t*)apn_buf, len);
 	if (!(*apn_str)) {
 		LOG(LOGL_ERROR, "APN IE: present but cannot be decoded: %s\n",
 		    osmo_hexdump((uint8_t*)apn_buf, len));
diff --git a/openbsc/src/gprs/sgsn_cdr.c b/openbsc/src/gprs/sgsn_cdr.c
index d0cb712..5d16249 100644
--- a/openbsc/src/gprs/sgsn_cdr.c
+++ b/openbsc/src/gprs/sgsn_cdr.c
@@ -20,11 +20,12 @@ 
 
 #include <openbsc/sgsn.h>
 #include <openbsc/signal.h>
-#include <openbsc/gprs_utils.h>
 #include <openbsc/debug.h>
 
 #include <openbsc/vty.h>
 
+#include <osmocom/gsm/apn.h>
+
 #include <gtp.h>
 #include <pdp.h>
 
@@ -145,7 +146,7 @@  static void cdr_log_pdp(struct sgsn_instance *inst, const char *ev,
 
 
 	if (pdp->lib) {
-		gprs_apn_to_str(apni, pdp->lib->apn_use.v, pdp->lib->apn_use.l);
+		osmo_apn_to_str(apni, pdp->lib->apn_use.v, pdp->lib->apn_use.l);
 		inet_ntop(AF_INET, &pdp->lib->hisaddr0.s_addr, ggsn_addr, sizeof(ggsn_addr));
 		extract_eua(&pdp->lib->eua, eua_addr);
 	}
diff --git a/openbsc/src/gprs/sgsn_vty.c b/openbsc/src/gprs/sgsn_vty.c
index 3f61163..706c9ea 100644
--- a/openbsc/src/gprs/sgsn_vty.c
+++ b/openbsc/src/gprs/sgsn_vty.c
@@ -110,7 +110,7 @@  DECLARE_TIMER(3397, "Wait for DEACT AA PDP CTX ACK timer (s)")
 
 
 #define GSM48_MAX_APN_LEN	102	/* 10.5.6.1 */
-/* TODO: consolidate with gprs_apn_to_str(). */
+/* TODO: consolidate with osmo_apn_to_str(). */
 /** Copy apn to a static buffer, replacing the length octets in apn_enc with '.'
  * and terminating with a '\0'. Return the static buffer.
  * len: the length of the encoded APN (which has no terminating zero).
diff --git a/openbsc/tests/gbproxy/gbproxy_test.c b/openbsc/tests/gbproxy/gbproxy_test.c
index 0ba827f..97aa32f 100644
--- a/openbsc/tests/gbproxy/gbproxy_test.c
+++ b/openbsc/tests/gbproxy/gbproxy_test.c
@@ -26,6 +26,7 @@ 
 #include <osmocom/core/rate_ctr.h>
 #include <osmocom/gsm/tlv.h>
 #include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/apn.h>
 #include <osmocom/gprs/gprs_msgb.h>
 #include <osmocom/gprs/gprs_ns.h>
 #include <osmocom/gprs/gprs_bssgp.h>
@@ -1660,7 +1661,7 @@  static void test_gbproxy_ra_patching()
 	gbcfg.core_mcc = 123;
 	gbcfg.core_mnc = 456;
 	gbcfg.core_apn = talloc_zero_size(NULL, 100);
-	gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
+	gbcfg.core_apn_size = osmo_apn_from_str(gbcfg.core_apn, 100, "foo.bar");
 	gbcfg.patch_ptmsi = 0;
 
 	configure_sgsn_peer(&sgsn_peer);
@@ -2001,7 +2002,7 @@  static void test_gbproxy_ptmsi_assignment()
 	gbcfg.core_mcc = 0;
 	gbcfg.core_mnc = 0;
 	gbcfg.core_apn = talloc_zero_size(NULL, 100);
-	gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
+	gbcfg.core_apn_size = osmo_apn_from_str(gbcfg.core_apn, 100, "foo.bar");
 	gbcfg.patch_ptmsi = 0;
 
 	configure_sgsn_peer(&sgsn_peer);
@@ -2235,7 +2236,7 @@  static void test_gbproxy_ptmsi_patching()
 	gbcfg.core_mcc = 123;
 	gbcfg.core_mnc = 456;
 	gbcfg.core_apn = talloc_zero_size(NULL, 100);
-	gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
+	gbcfg.core_apn_size = osmo_apn_from_str(gbcfg.core_apn, 100, "foo.bar");
 	gbcfg.patch_ptmsi = 1;
 
 	configure_sgsn_peer(&sgsn_peer);
@@ -2554,7 +2555,7 @@  static void test_gbproxy_ptmsi_patching_bad_cases()
 	gbcfg.core_mcc = 123;
 	gbcfg.core_mnc = 456;
 	gbcfg.core_apn = talloc_zero_size(NULL, 100);
-	gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
+	gbcfg.core_apn_size = osmo_apn_from_str(gbcfg.core_apn, 100, "foo.bar");
 	gbcfg.patch_ptmsi = 1;
 
 	configure_sgsn_peer(&sgsn_peer);
@@ -2738,7 +2739,7 @@  static void test_gbproxy_imsi_acquisition()
 	gbcfg.core_mcc = 123;
 	gbcfg.core_mnc = 456;
 	gbcfg.core_apn = talloc_zero_size(NULL, 100);
-	gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
+	gbcfg.core_apn_size = osmo_apn_from_str(gbcfg.core_apn, 100, "foo.bar");
 	gbcfg.patch_ptmsi = 1;
 	gbcfg.acquire_imsi = 1;
 
@@ -3064,7 +3065,7 @@  static void test_gbproxy_secondary_sgsn()
 	gbcfg.core_mcc = 123;
 	gbcfg.core_mnc = 456;
 	gbcfg.core_apn = talloc_zero_size(NULL, 100);
-	gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
+	gbcfg.core_apn_size = osmo_apn_from_str(gbcfg.core_apn, 100, "foo.bar");
 	gbcfg.patch_ptmsi = 1;
 	gbcfg.acquire_imsi = 1;
 
diff --git a/openbsc/tests/gprs/gprs_test.c b/openbsc/tests/gprs/gprs_test.c
index c78b98a..20b0bb4 100644
--- a/openbsc/tests/gprs/gprs_test.c
+++ b/openbsc/tests/gprs/gprs_test.c
@@ -10,6 +10,7 @@ 
 #include <openbsc/debug.h>
 
 #include <osmocom/core/application.h>
+#include <osmocom/gsm/apn.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(); }
@@ -59,7 +60,7 @@  static void apn_round_trip(const uint8_t *input, size_t len, const char *wanted_
 	int enc_len;
 
 	/* decode and verify we have what we want */
-	out_str = gprs_apn_to_str(output, input, len);
+	out_str = osmo_apn_to_str(output, input, len);
 	OSMO_ASSERT(out_str);
 	OSMO_ASSERT(out_str == &output[0]);
 	OSMO_ASSERT(strlen(out_str) == strlen(wanted_output));
@@ -67,11 +68,11 @@  static void apn_round_trip(const uint8_t *input, size_t len, const char *wanted_
 
 	/* encode and verify it */
 	if (len != 0) {
-		enc_len = gprs_str_to_apn(encoded, ARRAY_SIZE(encoded), wanted_output);
+		enc_len = osmo_apn_from_str(encoded, ARRAY_SIZE(encoded), wanted_output);
 		OSMO_ASSERT(enc_len == len);
 		OSMO_ASSERT(memcmp(encoded, input, enc_len) == 0);
 	} else {
-		enc_len = gprs_str_to_apn(encoded, 0, wanted_output);
+		enc_len = osmo_apn_from_str(encoded, 0, wanted_output);
 		OSMO_ASSERT(enc_len == -1);
 	}
 }
@@ -86,27 +87,27 @@  static void test_gsm_03_03_apn(void)
 		int enc_len;
 
 		memcpy(output, ref, ARRAY_SIZE(output));
-		enc_len = gprs_str_to_apn(output, 0, "");
+		enc_len = osmo_apn_from_str(output, 0, "");
 		OSMO_ASSERT(enc_len == -1);
 		OSMO_ASSERT(memcmp(ref, output, ARRAY_SIZE(ref)) == 0);
 
 		memcpy(output, ref, ARRAY_SIZE(output));
-		enc_len = gprs_str_to_apn(output, 0, "foo");
+		enc_len = osmo_apn_from_str(output, 0, "foo");
 		OSMO_ASSERT(enc_len == -1);
 		OSMO_ASSERT(memcmp(ref, output, ARRAY_SIZE(ref)) == 0);
 
 		memcpy(output, ref, ARRAY_SIZE(output));
-		enc_len = gprs_str_to_apn(output, 1, "foo");
+		enc_len = osmo_apn_from_str(output, 1, "foo");
 		OSMO_ASSERT(enc_len == -1);
 		OSMO_ASSERT(memcmp(ref + 1, output + 1, ARRAY_SIZE(ref) - 1) == 0);
 
 		memcpy(output, ref, ARRAY_SIZE(output));
-		enc_len = gprs_str_to_apn(output, 2, "foo");
+		enc_len = osmo_apn_from_str(output, 2, "foo");
 		OSMO_ASSERT(enc_len == -1);
 		OSMO_ASSERT(memcmp(ref + 2, output + 2, ARRAY_SIZE(ref) - 2) == 0);
 
 		memcpy(output, ref, ARRAY_SIZE(output));
-		enc_len = gprs_str_to_apn(output, 3, "foo");
+		enc_len = osmo_apn_from_str(output, 3, "foo");
 		OSMO_ASSERT(enc_len == -1);
 		OSMO_ASSERT(memcmp(ref + 3, output + 3, ARRAY_SIZE(ref) - 3) == 0);
 	}
@@ -130,7 +131,7 @@  static void test_gsm_03_03_apn(void)
 		uint8_t input[] = { 0x1, 65 };
 		const char *output = "A";
 		apn_round_trip(input, ARRAY_SIZE(input), output);
-		OSMO_ASSERT(gprs_apn_to_str(NULL, input, ARRAY_SIZE(input) - 1) == NULL);
+		OSMO_ASSERT(osmo_apn_to_str(NULL, input, ARRAY_SIZE(input) - 1) == NULL);
 	}
 
 	{
@@ -138,11 +139,11 @@  static void test_gsm_03_03_apn(void)
 		const char *output = "ABC.Zz";
 		char tmp[strlen(output) + 1];
 		apn_round_trip(input, ARRAY_SIZE(input), output);
-		OSMO_ASSERT(gprs_apn_to_str(tmp, input, ARRAY_SIZE(input) - 1) == NULL);
-		OSMO_ASSERT(gprs_apn_to_str(tmp, input, ARRAY_SIZE(input) - 2) == NULL);
-		OSMO_ASSERT(gprs_apn_to_str(tmp, input, ARRAY_SIZE(input) - 4) == NULL);
-		OSMO_ASSERT(gprs_apn_to_str(tmp, input, ARRAY_SIZE(input) - 5) == NULL);
-		OSMO_ASSERT(gprs_apn_to_str(tmp, input, ARRAY_SIZE(input) - 6) == NULL);
+		OSMO_ASSERT(osmo_apn_to_str(tmp, input, ARRAY_SIZE(input) - 1) == NULL);
+		OSMO_ASSERT(osmo_apn_to_str(tmp, input, ARRAY_SIZE(input) - 2) == NULL);
+		OSMO_ASSERT(osmo_apn_to_str(tmp, input, ARRAY_SIZE(input) - 4) == NULL);
+		OSMO_ASSERT(osmo_apn_to_str(tmp, input, ARRAY_SIZE(input) - 5) == NULL);
+		OSMO_ASSERT(osmo_apn_to_str(tmp, input, ARRAY_SIZE(input) - 6) == NULL);
 	}
 }
 
diff --git a/openbsc/tests/gtphub/Makefile.am b/openbsc/tests/gtphub/Makefile.am
index dcb7211..7599119 100644
--- a/openbsc/tests/gtphub/Makefile.am
+++ b/openbsc/tests/gtphub/Makefile.am
@@ -20,5 +20,6 @@  gtphub_test_LDADD = \
 	$(top_builddir)/src/gprs/gtphub.o \
 	$(top_builddir)/src/gprs/gprs_utils.o \
 	$(LIBOSMOCORE_LIBS) \
+	$(LIBOSMOGSM_LIBS) \
 	-lgtp -lrt
 
diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c
index 859223f..5df7688 100644
--- a/openbsc/tests/sgsn/sgsn_test.c
+++ b/openbsc/tests/sgsn/sgsn_test.c
@@ -31,7 +31,8 @@ 
 
 #include <osmocom/gprs/gprs_bssgp.h>
 
-#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/apn.h>
+
 #include <openbsc/gsm_04_08_gprs.h>
 
 #include <osmocom/core/application.h>
@@ -1957,7 +1958,7 @@  static void test_ggsn_selection(void)
 	/* Resolve GGSNs */
 
 	tp.lv[GSM48_IE_GSM_APN].len =
-		gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Test.Apn");
+		osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Test.Apn");
 
 	ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str);
 	OSMO_ASSERT(ggc != NULL);
@@ -1965,7 +1966,7 @@  static void test_ggsn_selection(void)
 	OSMO_ASSERT(strcmp(apn_str, "Test.Apn") == 0);
 
 	tp.lv[GSM48_IE_GSM_APN].len =
-		gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Other.Apn");
+		osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Other.Apn");
 
 	ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str);
 	OSMO_ASSERT(ggc != NULL);
@@ -1991,7 +1992,7 @@  static void test_ggsn_selection(void)
 	tp.lv[GSM48_IE_GSM_APN].val = apn_enc;
 
 	tp.lv[GSM48_IE_GSM_APN].len =
-		gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Foo.Bar");
+		osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Foo.Bar");
 
 	ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str);
 	OSMO_ASSERT(ggc == NULL);
@@ -2008,7 +2009,7 @@  static void test_ggsn_selection(void)
 	strncpy(pdp_data->apn_str, "Test.Apn", sizeof(pdp_data->apn_str)-1);
 
 	tp.lv[GSM48_IE_GSM_APN].len =
-		gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Test.Apn");
+		osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Test.Apn");
 
 	ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str);
 	OSMO_ASSERT(ggc != NULL);
@@ -2016,7 +2017,7 @@  static void test_ggsn_selection(void)
 	OSMO_ASSERT(strcmp(apn_str, "Test.Apn") == 0);
 
 	tp.lv[GSM48_IE_GSM_APN].len =
-		gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Other.Apn");
+		osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Other.Apn");
 
 	ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str);
 	OSMO_ASSERT(ggc == NULL);