aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2014-10-01 16:18:11 +0800
committerHarald Welte <laforge@gnumonks.org>2014-10-01 16:19:13 +0800
commit711dacdca574c0a4bea87a5ff04717e01aacb358 (patch)
tree7e6226a737d9d69b1d0383f6d30495ddcd6e6d6a
parent96af78650d1de134ebb37ddb829508cf0bd30c51 (diff)
Add APN utility function to libosmogsm
The current functions are used to 'qualify' an APN from the user-supplied APN name (name identifier) towards the fully-qualified APN name which is used in the .grps DNS zone.
-rw-r--r--include/Makefile.am1
-rw-r--r--include/osmocom/gsm/apn.h13
-rw-r--r--src/gsm/Makefile.am2
-rw-r--r--src/gsm/apn.c38
-rw-r--r--src/gsm/libosmogsm.map3
5 files changed, 56 insertions, 1 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index c59f9b21..9f5c9662 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -49,6 +49,7 @@ nobase_include_HEADERS = \
osmocom/gprs/protocol/gsm_08_18.h \
osmocom/gsm/a5.h \
osmocom/gsm/abis_nm.h \
+ osmocom/gsm/apn.h \
osmocom/gsm/comp128.h \
osmocom/gsm/comp128v23.h \
osmocom/gsm/gan.h \
diff --git a/include/osmocom/gsm/apn.h b/include/osmocom/gsm/apn.h
new file mode 100644
index 00000000..d8d73996
--- /dev/null
+++ b/include/osmocom/gsm/apn.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <stdint.h>
+
+/* 23.003 Section 9.1.1, excluding any terminating zero byte */
+#define APN_NI_MAXLEN 63
+
+/* 23.003 Section 9.1, excluding any terminating zero byte */
+#define APN_MAXLEN 100
+
+char *osmo_apn_qualify(unsigned int mcc, unsigned int mnc, const char *ni);
+char *osmo_apn_qualify_from_imsi(const char *imsi,
+ const char *ni, int have_3dig_mnc);
diff --git a/src/gsm/Makefile.am b/src/gsm/Makefile.am
index 9c7df5a3..7a4cdc57 100644
--- a/src/gsm/Makefile.am
+++ b/src/gsm/Makefile.am
@@ -19,7 +19,7 @@ libosmogsm_la_SOURCES = a5.c rxlev_stat.c tlv_parser.c comp128.c comp128v23.c \
auth_core.c auth_comp128v1.c auth_comp128v23.c \
auth_milenage.c milenage/aes-encblock.c \
milenage/aes-internal.c milenage/aes-internal-enc.c \
- milenage/milenage.c gan.c ipa.c
+ milenage/milenage.c gan.c ipa.c apn.c
libosmogsm_la_LDFLAGS = $(LTLDFLAGS_OSMOGSM) -version-info $(LIBVERSION) -no-undefined
libosmogsm_la_LIBADD = $(top_builddir)/src/libosmocore.la
diff --git a/src/gsm/apn.c b/src/gsm/apn.c
new file mode 100644
index 00000000..413130aa
--- /dev/null
+++ b/src/gsm/apn.c
@@ -0,0 +1,38 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <osmocom/gsm/apn.h>
+
+#define APN_OI_GPRS_FMT "mnc%03u.mcc%03u.gprs"
+#define APN_GPRS_FMT "%s.mnc%03u.mcc%03u.gprs"
+
+static char apn_strbuf[APN_MAXLEN+1];
+
+char *osmo_apn_qualify(unsigned int mcc, unsigned int mnc, const char *ni)
+{
+ snprintf(apn_strbuf, sizeof(apn_strbuf)-1, APN_GPRS_FMT,
+ ni, mnc, mcc);
+ apn_strbuf[sizeof(apn_strbuf)-1] = '\0';
+
+ return apn_strbuf;
+}
+
+char *osmo_apn_qualify_from_imsi(const char *imsi,
+ const char *ni, int have_3dig_mnc)
+{
+ char cbuf[3+1], nbuf[3+1];
+
+ strncpy(cbuf, imsi, 3);
+ cbuf[3] = '\0';
+
+ if (have_3dig_mnc) {
+ strncpy(nbuf, imsi+3, 3);
+ nbuf[3] = '\0';
+ } else {
+ strncpy(nbuf, imsi+3, 2);
+ nbuf[2] = '\0';
+ }
+ return osmo_apn_qualify(atoi(cbuf), atoi(nbuf), ni);
+}
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index d82c8a06..64bb062a 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -262,5 +262,8 @@ ipa_prepend_header;
ipa_prepend_header_ext;
ipa_send;
+osmo_apn_qualify;
+osmo_apn_qualify_from_imsi;
+
local: *;
};