takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers APN_db.h Source File

APN_db.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2017 ublox, ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /* ----------------------------------------------------------------
00018    APN stands for Access Point Name, a setting on your modem or phone
00019    that identifies an external network your phone can access for data
00020    (e.g. 3G or 4G Internet service on your phone).
00021 
00022    The APN settings can be forced when calling the join function.
00023    Below is a list of known APNs that us used if no apn config
00024    is forced. This list could be extended by other settings.
00025 
00026    For further reading:
00027    wiki apn: http://en.wikipedia.org/wiki/Access_Point_Name
00028    wiki mcc/mnc: http://en.wikipedia.org/wiki/Mobile_country_code
00029    google: https://www.google.de/search?q=APN+list
00030 ---------------------------------------------------------------- */
00031 
00032 /**
00033  * Helper to generate the APN string
00034  */
00035 #define _APN(apn,username,password) apn "\0" username "\0" password "\0"
00036 
00037 /**
00038  * Helper to extract a field from the cfg string
00039  */
00040 #define _APN_GET(cfg) \
00041     *cfg ? cfg : NULL; \
00042     cfg  += strlen(cfg) + 1
00043 
00044 /**
00045  * APN lookup struct
00046  */
00047 typedef struct {
00048     const char *mccmnc; /**< mobile country code (MCC) and mobile network code MNC */
00049     const char *cfg;     /**<  APN configuartion string, use _APN macro to generate */
00050 } APN_t;
00051 
00052 /**
00053  * Default APN settings used by many networks
00054  */
00055 static const char *apndef = _APN("internet",,);
00056 
00057 /**
00058  * List of special APNs for different network operators.
00059  *
00060  * No need to add default, "internet" will be used as a default if no entry matches.
00061  * The APN without username/password have to be listed first.
00062  */
00063 
00064 static const APN_t apnlut[] = {
00065 // MCC Country
00066 //  { /* Operator */ "MCC-MNC[,MNC]" _APN(APN,USERNAME,PASSWORD) },
00067 // MCC must be 3 digits
00068 // MNC must be either 2 or 3 digits
00069 // MCC must be separated by '-' from MNC, multiple MNC can be separated by ','
00070 
00071 // 232 Austria - AUT
00072     { /* T-Mobile */ "232-03",  _APN("m2m.business",,) },
00073 
00074 // 460 China - CN
00075     { /* CN Mobile */"460-00",  _APN("cmnet",,)
00076         _APN("cmwap",,)
00077     },
00078     { /* Unicom */   "460-01",  _APN("3gnet",,)
00079         _APN("uninet", "uninet", "uninet")
00080     },
00081 
00082 // 262 Germany - DE
00083     { /* T-Mobile */ "262-01",  _APN("internet.t-mobile", "t-mobile", "tm") },
00084     { /* T-Mobile */ "262-02,06",
00085         _APN("m2m.business",,)
00086     },
00087 
00088 // 222 Italy - IT
00089     { /* TIM */      "222-01",  _APN("ibox.tim.it",,) },
00090     { /* Vodafone */ "222-10",  _APN("web.omnitel.it",,) },
00091     { /* Wind */     "222-88",  _APN("internet.wind.biz",,) },
00092 
00093 // 440 Japan - JP
00094     { /* Softbank */ "440-04,06,20,40,41,42,43,44,45,46,47,48,90,91,92,93,94,95"
00095         ",96,97,98"
00096         _APN("open.softbank.ne.jp", "opensoftbank", "ebMNuX1FIHg9d3DA")
00097         _APN("smile.world", "dna1trop", "so2t3k3m2a")
00098     },
00099     { /* NTTDoCoMo */"440-09,10,11,12,13,14,15,16,17,18,19,21,22,23,24,25,26,27,"
00100         "28,29,30,31,32,33,34,35,36,37,38,39,58,59,60,61,62,63,"
00101         "64,65,66,67,68,69,87,99",
00102         _APN("bmobilewap",,) /*BMobile*/
00103         _APN("mpr2.bizho.net", "Mopera U",) /* DoCoMo */
00104         _APN("bmobile.ne.jp", "bmobile@wifi2", "bmobile") /*BMobile*/
00105     },
00106 
00107 // 204 Netherlands - NL
00108     { /* Vodafone */ "204-04",  _APN("public4.m2minternet.com",,) },
00109 
00110 // 293 Slovenia - SI
00111     { /* Si.mobil */ "293-40",  _APN("internet.simobil.si",,) },
00112     { /* Tusmobil */ "293-70",  _APN("internet.tusmobil.si",,) },
00113 
00114 // 240 Sweden SE
00115     { /* Telia */    "240-01",  _APN("online.telia.se",,) },
00116     { /* Telenor */  "240-06,08",
00117         _APN("services.telenor.se",,)
00118     },
00119     { /* Tele2 */    "240-07",  _APN("mobileinternet.tele2.se",,) },
00120 
00121 // 228 Switzerland - CH
00122     { /* Swisscom */ "228-01",  _APN("gprs.swisscom.ch",,) },
00123     { /* Orange */   "228-03",  _APN("internet",,) /* contract */
00124         _APN("click",,)    /* pre-pay */
00125     },
00126 
00127 // 234 United Kingdom - GB
00128     { /* O2 */       "234-02,10,11",
00129         _APN("mobile.o2.co.uk", "faster", "web") /* contract */
00130         _APN("mobile.o2.co.uk", "bypass", "web") /* pre-pay */
00131         _APN("payandgo.o2.co.uk", "payandgo", "payandgo")
00132     },
00133     { /* Vodafone */ "234-15",  _APN("internet", "web", "web")        /* contract */
00134         _APN("pp.vodafone.co.uk", "wap", "wap")  /* pre-pay */
00135     },
00136     { /* Three */    "234-20",  _APN("three.co.uk",,) },
00137     { /* Jersey */   "234-50",  _APN("jtm2m",,) /* as used on u-blox C030 U201 boards */ },
00138 
00139 // 310 United States of America - US
00140     { /* T-Mobile */ "310-026,260,490",
00141         _APN("epc.tmobile.com",,)
00142         _APN("fast.tmobile.com",,) /* LTE */
00143     },
00144     { /* AT&T */     "310-030,150,170,260,410,560,680",
00145         _APN("phone",,)
00146         _APN("wap.cingular", "WAP@CINGULARGPRS.COM", "CINGULAR1")
00147         _APN("isp.cingular", "ISP@CINGULARGPRS.COM", "CINGULAR1")
00148     },
00149 
00150 // 901 International - INT
00151     { /* Transatel */ "901-37", _APN("netgprs.com", "tsl", "tsl") },
00152 };
00153 
00154 /**
00155  * Configuring APN by extraction from IMSI and matching the table.
00156  *
00157  * @param imsi  strinf containing IMSI
00158  */
00159 inline const char *apnconfig(const char *imsi)
00160 {
00161     const char *config = NULL;
00162     if (imsi && *imsi) {
00163         // many carriers use internet without username and password, os use this as default
00164         // now try to lookup the setting for our table
00165         for (size_t i = 0; i < sizeof(apnlut) / sizeof(*apnlut) && !config; i ++) {
00166             const char *p = apnlut[i].mccmnc;
00167             // check the MCC
00168             if ((0 == memcmp(imsi, p, 3))) {
00169                 p += 3;
00170                 // check all the MNC, MNC length can be 2 or 3 digits
00171                 while (((p[0] == '-') || (p[0] == ',')) &&
00172                         (p[1] >= '0') && (p[1] <= '9') &&
00173                         (p[2] >= '0') && (p[2] <= '9') && !config) {
00174                     int l = ((p[3] >= '0') && (p[3] <= '9')) ? 3 : 2;
00175                     if (0 == memcmp(imsi + 3, p + 1, l)) {
00176                         config = apnlut[i].cfg;
00177                     }
00178                     p += 1 + l;
00179                 }
00180             }
00181         }
00182     }
00183     // use default if not found
00184     if (!config) {
00185         config = apndef;
00186     }
00187     return config;
00188 }