blob: 413130aa39dec583e83e18ba8e2985875ccd330a [file] [log] [blame]
Harald Welte908085c2014-10-01 16:18:11 +08001#include <stdio.h>
2#include <stdint.h>
3#include <stdlib.h>
4#include <string.h>
5
6#include <osmocom/gsm/apn.h>
7
8#define APN_OI_GPRS_FMT "mnc%03u.mcc%03u.gprs"
9#define APN_GPRS_FMT "%s.mnc%03u.mcc%03u.gprs"
10
11static char apn_strbuf[APN_MAXLEN+1];
12
13char *osmo_apn_qualify(unsigned int mcc, unsigned int mnc, const char *ni)
14{
15 snprintf(apn_strbuf, sizeof(apn_strbuf)-1, APN_GPRS_FMT,
16 ni, mnc, mcc);
17 apn_strbuf[sizeof(apn_strbuf)-1] = '\0';
18
19 return apn_strbuf;
20}
21
22char *osmo_apn_qualify_from_imsi(const char *imsi,
23 const char *ni, int have_3dig_mnc)
24{
25 char cbuf[3+1], nbuf[3+1];
26
27 strncpy(cbuf, imsi, 3);
28 cbuf[3] = '\0';
29
30 if (have_3dig_mnc) {
31 strncpy(nbuf, imsi+3, 3);
32 nbuf[3] = '\0';
33 } else {
34 strncpy(nbuf, imsi+3, 2);
35 nbuf[2] = '\0';
36 }
37 return osmo_apn_qualify(atoi(cbuf), atoi(nbuf), ni);
38}