![](/media/cache/profiles/dcee66ccb49a492ae42c446c0cc01b3a.jpg.50x50_q85.jpg)
Axeda demo software for u-blox C027 (GSM)
C027_Support/MDMAPN.h@0:a725e8eab383, 2014-08-11 (annotated)
- Committer:
- AxedaCorp
- Date:
- Mon Aug 11 19:02:42 2014 +0000
- Revision:
- 0:a725e8eab383
1st commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AxedaCorp | 0:a725e8eab383 | 1 | #pragma once |
AxedaCorp | 0:a725e8eab383 | 2 | |
AxedaCorp | 0:a725e8eab383 | 3 | /* ---------------------------------------------------------------- |
AxedaCorp | 0:a725e8eab383 | 4 | APN stands for Access Point Name, a setting on your modem or phone |
AxedaCorp | 0:a725e8eab383 | 5 | that identifies an external network your phone can access for data |
AxedaCorp | 0:a725e8eab383 | 6 | (e.g. 3G or 4G Internet service on your phone). |
AxedaCorp | 0:a725e8eab383 | 7 | |
AxedaCorp | 0:a725e8eab383 | 8 | The APN settings can be forced when calling the join function. |
AxedaCorp | 0:a725e8eab383 | 9 | Below is a list of known APNs that us used if no apn config |
AxedaCorp | 0:a725e8eab383 | 10 | is forced. This list could be extended by other settings. |
AxedaCorp | 0:a725e8eab383 | 11 | |
AxedaCorp | 0:a725e8eab383 | 12 | For further reading: |
AxedaCorp | 0:a725e8eab383 | 13 | wiki apn: http://en.wikipedia.org/wiki/Access_Point_Name |
AxedaCorp | 0:a725e8eab383 | 14 | wiki mcc/mnc: http://en.wikipedia.org/wiki/Mobile_country_code |
AxedaCorp | 0:a725e8eab383 | 15 | google: https://www.google.de/search?q=APN+list |
AxedaCorp | 0:a725e8eab383 | 16 | ---------------------------------------------------------------- */ |
AxedaCorp | 0:a725e8eab383 | 17 | |
AxedaCorp | 0:a725e8eab383 | 18 | //! helper to generate the APN string |
AxedaCorp | 0:a725e8eab383 | 19 | #define _APN(apn,username,password) apn "\0" username "\0" password "\0" |
AxedaCorp | 0:a725e8eab383 | 20 | |
AxedaCorp | 0:a725e8eab383 | 21 | //! helper to extract a field from the config string |
AxedaCorp | 0:a725e8eab383 | 22 | #define _APN_GET(cfg) \ |
AxedaCorp | 0:a725e8eab383 | 23 | *cfg ? cfg : ""; \ |
AxedaCorp | 0:a725e8eab383 | 24 | cfg += strlen(cfg) + 1 |
AxedaCorp | 0:a725e8eab383 | 25 | |
AxedaCorp | 0:a725e8eab383 | 26 | //! APN lookup struct |
AxedaCorp | 0:a725e8eab383 | 27 | typedef struct { |
AxedaCorp | 0:a725e8eab383 | 28 | const char* mccmnc; //!< mobile country code (MCC) and mobile network code MNC |
AxedaCorp | 0:a725e8eab383 | 29 | const char* cfg; //!< APN configuartion string, use _APN macro to generate |
AxedaCorp | 0:a725e8eab383 | 30 | } APN_t; |
AxedaCorp | 0:a725e8eab383 | 31 | |
AxedaCorp | 0:a725e8eab383 | 32 | //! default APN settings used by many networks |
AxedaCorp | 0:a725e8eab383 | 33 | static const char* apndef = _APN(,,) |
AxedaCorp | 0:a725e8eab383 | 34 | _APN("internet",,); |
AxedaCorp | 0:a725e8eab383 | 35 | |
AxedaCorp | 0:a725e8eab383 | 36 | /*! this is a list of special APNs for different network operators |
AxedaCorp | 0:a725e8eab383 | 37 | There is no need to enter the default apn internet in the table; |
AxedaCorp | 0:a725e8eab383 | 38 | apndef will be used if no entry matches. |
AxedaCorp | 0:a725e8eab383 | 39 | |
AxedaCorp | 0:a725e8eab383 | 40 | The APN without username/password have to be listed first. |
AxedaCorp | 0:a725e8eab383 | 41 | */ |
AxedaCorp | 0:a725e8eab383 | 42 | static const APN_t apnlut[] = { |
AxedaCorp | 0:a725e8eab383 | 43 | // MCC Country |
AxedaCorp | 0:a725e8eab383 | 44 | // { /* Operator */ "MCC-MNC[,MNC]" _APN(APN,USERNAME,PASSWORD) }, |
AxedaCorp | 0:a725e8eab383 | 45 | // MCC must be 3 digits |
AxedaCorp | 0:a725e8eab383 | 46 | // MNC must be either 2 or 3 digits |
AxedaCorp | 0:a725e8eab383 | 47 | // MCC must be separated by '-' from MNC, multiple MNC can be separated by ',' |
AxedaCorp | 0:a725e8eab383 | 48 | |
AxedaCorp | 0:a725e8eab383 | 49 | // 460 China - CN |
AxedaCorp | 0:a725e8eab383 | 50 | { /* CN Mobile */"460-00", _APN("cmnet",,) |
AxedaCorp | 0:a725e8eab383 | 51 | _APN("cmwap",,) }, |
AxedaCorp | 0:a725e8eab383 | 52 | { /* Unicom */ "460-01", _APN("3gnet",,) |
AxedaCorp | 0:a725e8eab383 | 53 | _APN("uninet","uninet","uninet") }, |
AxedaCorp | 0:a725e8eab383 | 54 | |
AxedaCorp | 0:a725e8eab383 | 55 | // 262 Germany - DE |
AxedaCorp | 0:a725e8eab383 | 56 | { /* T-Mobile */ "262-01", _APN("internet.t-mobile","t-mobile","tm") }, |
AxedaCorp | 0:a725e8eab383 | 57 | |
AxedaCorp | 0:a725e8eab383 | 58 | // 222 Italy - IT |
AxedaCorp | 0:a725e8eab383 | 59 | { /* TIM */ "222-01", _APN("ibox.tim.it",,) }, |
AxedaCorp | 0:a725e8eab383 | 60 | { /* Vodafone */ "222-10", _APN("web.omnitel.it",,) }, |
AxedaCorp | 0:a725e8eab383 | 61 | { /* Wind */ "222-88", _APN("internet.wind.biz",,) }, |
AxedaCorp | 0:a725e8eab383 | 62 | |
AxedaCorp | 0:a725e8eab383 | 63 | // 440 Japan - JP |
AxedaCorp | 0:a725e8eab383 | 64 | { /* Softbank */ "440-04,06,20,40,41,42,43,44,45,46,47,48,90,91,92,93,94,95" |
AxedaCorp | 0:a725e8eab383 | 65 | ",96,97,98" |
AxedaCorp | 0:a725e8eab383 | 66 | _APN("open.softbank.ne.jp","opensoftbank","ebMNuX1FIHg9d3DA") |
AxedaCorp | 0:a725e8eab383 | 67 | _APN("smile.world","dna1trop","so2t3k3m2a") }, |
AxedaCorp | 0:a725e8eab383 | 68 | { /* NTTDoCoMo */"440-09,10,11,12,13,14,15,16,17,18,19,21,22,23,24,25,26,27," |
AxedaCorp | 0:a725e8eab383 | 69 | "28,29,30,31,32,33,34,35,36,37,38,39,58,59,60,61,62,63," |
AxedaCorp | 0:a725e8eab383 | 70 | "64,65,66,67,68,69,87,99", |
AxedaCorp | 0:a725e8eab383 | 71 | _APN("bmobilewap",,) /*BMobile*/ |
AxedaCorp | 0:a725e8eab383 | 72 | _APN("mpr2.bizho.net","Mopera U",) /* DoCoMo */ |
AxedaCorp | 0:a725e8eab383 | 73 | _APN("bmobile.ne.jp","bmobile@wifi2","bmobile") /*BMobile*/ }, |
AxedaCorp | 0:a725e8eab383 | 74 | |
AxedaCorp | 0:a725e8eab383 | 75 | // 293 Slovenia - SI |
AxedaCorp | 0:a725e8eab383 | 76 | { /* Si.mobil */ "293-40", _APN("internet.simobil.si",,) }, |
AxedaCorp | 0:a725e8eab383 | 77 | { /* Tusmobil */ "293-70", _APN("internet.tusmobil.si",,) }, |
AxedaCorp | 0:a725e8eab383 | 78 | |
AxedaCorp | 0:a725e8eab383 | 79 | // 228 Switzerland - CH |
AxedaCorp | 0:a725e8eab383 | 80 | { /* Swisscom */ "228-01", _APN("gprs.swisscom.ch",,) }, |
AxedaCorp | 0:a725e8eab383 | 81 | { /* Orange */ "228-03", _APN("internet",,) /* contract */ |
AxedaCorp | 0:a725e8eab383 | 82 | _APN("click",,) /* pre-pay */ }, |
AxedaCorp | 0:a725e8eab383 | 83 | |
AxedaCorp | 0:a725e8eab383 | 84 | // 234 United Kingdom - GB |
AxedaCorp | 0:a725e8eab383 | 85 | { /* O2 */ "234-02,10,11", |
AxedaCorp | 0:a725e8eab383 | 86 | _APN("mobile.o2.co.uk","faster","web") /* contract */ |
AxedaCorp | 0:a725e8eab383 | 87 | _APN("mobile.o2.co.uk","bypass","web") /* pre-pay */ |
AxedaCorp | 0:a725e8eab383 | 88 | _APN("payandgo.o2.co.uk","payandgo","payandgo") }, |
AxedaCorp | 0:a725e8eab383 | 89 | { /* Vodafone */ "234-15", _APN("internet","web","web") /* contract */ |
AxedaCorp | 0:a725e8eab383 | 90 | _APN("pp.vodafone.co.uk","wap","wap") /* pre-pay */ }, |
AxedaCorp | 0:a725e8eab383 | 91 | |
AxedaCorp | 0:a725e8eab383 | 92 | // 310 United States of America - US |
AxedaCorp | 0:a725e8eab383 | 93 | { /* T-Mobile */ "310-026,260,490", |
AxedaCorp | 0:a725e8eab383 | 94 | _APN("epc.tmobile.com",,) |
AxedaCorp | 0:a725e8eab383 | 95 | _APN("fast.tmobile.com",,) /* LTE */ }, |
AxedaCorp | 0:a725e8eab383 | 96 | { /* AT&T */ "310-030,150,170,260,410,560,680", |
AxedaCorp | 0:a725e8eab383 | 97 | _APN("phone",,) |
AxedaCorp | 0:a725e8eab383 | 98 | _APN("wap.cingular","WAP@CINGULARGPRS.COM","CINGULAR1") |
AxedaCorp | 0:a725e8eab383 | 99 | _APN("isp.cingular","ISP@CINGULARGPRS.COM","CINGULAR1") }, |
AxedaCorp | 0:a725e8eab383 | 100 | }; |
AxedaCorp | 0:a725e8eab383 | 101 | |
AxedaCorp | 0:a725e8eab383 | 102 | inline const char* apnconfig(const char* imsi) |
AxedaCorp | 0:a725e8eab383 | 103 | { |
AxedaCorp | 0:a725e8eab383 | 104 | const char* config = NULL; |
AxedaCorp | 0:a725e8eab383 | 105 | if (imsi && *imsi) { |
AxedaCorp | 0:a725e8eab383 | 106 | // many carriers use internet without username and password, os use this as default |
AxedaCorp | 0:a725e8eab383 | 107 | // now try to lookup the setting for our table |
AxedaCorp | 0:a725e8eab383 | 108 | for (int i = 0; i < sizeof(apnlut)/sizeof(*apnlut) && !config; i ++) { |
AxedaCorp | 0:a725e8eab383 | 109 | const char* p = apnlut[i].mccmnc; |
AxedaCorp | 0:a725e8eab383 | 110 | // check the MCC |
AxedaCorp | 0:a725e8eab383 | 111 | if ((0 == memcmp(imsi, p, 3))) { |
AxedaCorp | 0:a725e8eab383 | 112 | p += 3; |
AxedaCorp | 0:a725e8eab383 | 113 | // check all the MNC, MNC length can be 2 or 3 digits |
AxedaCorp | 0:a725e8eab383 | 114 | while (((p[0] == '-') || (p[0] == ',')) && |
AxedaCorp | 0:a725e8eab383 | 115 | (p[1] >= '0') && (p[1] <= '9') && |
AxedaCorp | 0:a725e8eab383 | 116 | (p[2] >= '0') && (p[2] <= '9') && !config) { |
AxedaCorp | 0:a725e8eab383 | 117 | int l = ((p[3] >= '0') && (p[3] <= '9')) ? 3 : 2; |
AxedaCorp | 0:a725e8eab383 | 118 | if (0 == memcmp(imsi+3,p+1,l)) |
AxedaCorp | 0:a725e8eab383 | 119 | config = apnlut[i].cfg; |
AxedaCorp | 0:a725e8eab383 | 120 | p += 1 + l; |
AxedaCorp | 0:a725e8eab383 | 121 | } |
AxedaCorp | 0:a725e8eab383 | 122 | } |
AxedaCorp | 0:a725e8eab383 | 123 | } |
AxedaCorp | 0:a725e8eab383 | 124 | } |
AxedaCorp | 0:a725e8eab383 | 125 | // use default if not found |
AxedaCorp | 0:a725e8eab383 | 126 | if (!config) |
AxedaCorp | 0:a725e8eab383 | 127 | config = apndef; |
AxedaCorp | 0:a725e8eab383 | 128 | return config; |
AxedaCorp | 0:a725e8eab383 | 129 | } |