[PATCH] convert literal APN name to protocol encoded version before use

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Andreas Schultz aschultz at tpip.net
Fri Nov 13 14:57:37 UTC 2015


The definition of the APN field format in GTPv1 is hidden in a chain
of documents.

3GPP TS 29.060 (the GTPv1-C specification) Section 7.7.30:

> The Access Point Name contains a logical name (see 3GPP TS 23.060 [4]).
> It is coded as in the value part defined in 3GPP TS 24.008

3GPP TS 24.008 Section 10.5.6.1:

> The value part is defined in 3GPP TS 23.003.

3GPP TS 23.003 Section 9.1:

> The APN consists of one or more labels. Each label is coded as a one
> octet length field followed by that number of octets coded as 8 bit
> ASCII characters

This converts a literal APN (e.g. Label1.Label2.Label3) to a structured
field (e.g. \006Label1\006Label2\006Label3)

Signed-off-by: Andreas Schultz <aschultz at tpip.net>
---
 sgsnemu/sgsnemu.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/sgsnemu/sgsnemu.c b/sgsnemu/sgsnemu.c
index 5b56751..832bd97 100644
--- a/sgsnemu/sgsnemu.c
+++ b/sgsnemu/sgsnemu.c
@@ -231,6 +231,7 @@ int process_options(int argc, char **argv)
 	char *type;
 	char *mcc;
 	char *mnc;
+	char *tok, *apn;
 	char *lac;
 	int lac_d;
 	char *rest;
@@ -534,10 +535,19 @@ int process_options(int argc, char **argv)
 		printf("Invalid APN\n");
 		return -1;
 	}
-	options.apn.l = strlen(args_info.apn_arg);
-	strncpy((char *)options.apn.v, args_info.apn_arg,
-		sizeof(options.apn.v));
-	options.apn.v[sizeof(options.apn.v) - 1] = 0;
+	options.apn.l = strlen(args_info.apn_arg) + 1;
+
+	apn = (char *)options.apn.v;
+	for (tok = strtok(args_info.apn_arg, ".");
+	     tok != NULL;
+	     tok = strtok(NULL, ".")) {
+		     size_t len = strlen(tok);
+
+		     *apn++ = (char)len;
+		     strncpy(apn, tok, len);
+		     apn += len;
+	     }
+
 	printf("Using APN:             %s\n", args_info.apn_arg);
 
 	/* selmode */
-- 
2.5.0




More information about the OpenBSC mailing list