diff options
author | Harald Welte <laforge@gnumonks.org> | 2014-10-01 16:18:11 +0800 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2015-05-25 11:12:16 +0800 |
commit | 908085ccbc6383e95f2c80134bcaf2e9816b7187 (patch) | |
tree | 9f5dfce6293ca3120da4fd09122482a50143f38d /src/gsm/apn.c | |
parent | 0d86c21f6af7452291f4148c166e145fb65dc0b9 (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.
Diffstat (limited to 'src/gsm/apn.c')
-rw-r--r-- | src/gsm/apn.c | 38 |
1 files changed, 38 insertions, 0 deletions
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); +} |