From patchwork Fri Nov 13 14:57:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schultz X-Patchwork-Id: 544324 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (unknown [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id B0093140281 for ; Sat, 14 Nov 2015 01:57:55 +1100 (AEDT) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 020E494DB; Fri, 13 Nov 2015 14:57:50 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail.tpip.net (mail.tpip.net [92.43.49.48]) by lists.osmocom.org (Postfix) with ESMTP id 53DAB94D0 for ; Fri, 13 Nov 2015 14:57:48 +0000 (UTC) Received: from office.tpip.net (office.tpip.net [92.43.51.2]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.tpip.net (Postfix) with ESMTPS id 707994F414; Fri, 13 Nov 2015 14:57:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by office.tpip.net (Postfix) with ESMTP id 2AE94A2F78; Fri, 13 Nov 2015 15:57:55 +0100 (CET) Received: from office.tpip.net ([127.0.0.1]) by localhost (office.tpip.net [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id bZoX7dJK3zQm; Fri, 13 Nov 2015 15:57:54 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by office.tpip.net (Postfix) with ESMTP id CD193A2F7A; Fri, 13 Nov 2015 15:57:54 +0100 (CET) X-Virus-Scanned: amavisd-new at tpip.net Received: from office.tpip.net ([127.0.0.1]) by localhost (office.tpip.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id uoZk6iOGSFsa; Fri, 13 Nov 2015 15:57:54 +0100 (CET) Received: from alice.tpip.org (unknown [192.168.13.53]) by office.tpip.net (Postfix) with ESMTPSA id 844FCA2F78; Fri, 13 Nov 2015 15:57:54 +0100 (CET) From: Andreas Schultz To: openbsc@lists.osmocom.org Subject: [PATCH] convert literal APN name to protocol encoded version before use Date: Fri, 13 Nov 2015 15:57:37 +0100 Message-Id: <1447426657-17954-1-git-send-email-aschultz@tpip.net> X-Mailer: git-send-email 2.5.0 X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" 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 --- 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 */