C027_SupportTest_xively_locationで使用しているC027用ライブラリ

Fork of C027_Support by u-blox

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MDMAPN.h Source File

MDMAPN.h

00001 #pragma once 
00002 
00003 /* ----------------------------------------------------------------
00004    APN stands for Access Point Name, a setting on your modem or phone
00005    that identifies an external network your phone can access for data 
00006    (e.g. 3G or 4G Internet service on your phone). 
00007    
00008    The APN settings can be forced when calling the join function.
00009    Below is a list of known APNs that us used if no apn config 
00010    is forced. This list could be extended by other settings.
00011    
00012    For further reading:
00013    wiki apn: http://en.wikipedia.org/wiki/Access_Point_Name
00014    wiki mcc/mnc: http://en.wikipedia.org/wiki/Mobile_country_code
00015    google: https://www.google.de/search?q=APN+list   
00016 ---------------------------------------------------------------- */
00017 
00018 //! helper to generate the APN string
00019 #define _APN(apn,username,password) apn "\0" username "\0" password "\0"
00020 
00021 //! helper to extract a field from the config string 
00022 #define _APN_GET(cfg) \
00023     *cfg ? cfg : ""; \
00024     cfg  += strlen(cfg) + 1
00025                     
00026 //! APN lookup struct
00027 typedef struct { 
00028     const char* mccmnc; //!< mobile country code (MCC) and mobile network code MNC  
00029     const char* cfg;    //!< APN configuartion string, use _APN macro to generate
00030 } APN_t;
00031 
00032 //! default APN settings used by many networks
00033 static const char* apndef = _APN(,,)
00034                             _APN("internet",,);
00035 
00036 /*! this is a list of special APNs for different network operators 
00037     There is no need to enter the default apn internet in the table; 
00038     apndef will be used if no entry matches.
00039     
00040     The APN without username/password have to be listed first.
00041 */
00042 static const APN_t apnlut[] = {
00043 // MCC Country
00044 //  { /* Operator */ "MCC-MNC[,MNC]" _APN(APN,USERNAME,PASSWORD) },
00045 // MCC must be 3 digits
00046 // MNC must be either 2 or 3 digits
00047 // MCC must be separated by '-' from MNC, multiple MNC can be separated by ','
00048 
00049 // 460 China - CN
00050     { /* CN Mobile */"460-00",  _APN("cmnet",,)
00051                                 _APN("cmwap",,) },
00052     { /* Unicom */   "460-01",  _APN("3gnet",,)
00053                                 _APN("uninet","uninet","uninet") },
00054                                 
00055 // 262 Germany - DE
00056     { /* T-Mobile */ "262-01",  _APN("internet.t-mobile","t-mobile","tm") },
00057 
00058 // 222 Italy - IT
00059     { /* TIM */      "222-01",  _APN("ibox.tim.it",,) },
00060     { /* Vodafone */ "222-10",  _APN("web.omnitel.it",,) },
00061     { /* Wind */     "222-88",  _APN("internet.wind.biz",,) },
00062 
00063 // 440 Japan - JP
00064     { /* Softbank */ "440-04,06,20,40,41,42,43,44,45,46,47,48,90,91,92,93,94,95"
00065                          ",96,97,98"
00066                                 _APN("open.softbank.ne.jp","opensoftbank","ebMNuX1FIHg9d3DA")
00067                                 _APN("smile.world","dna1trop","so2t3k3m2a") },
00068     { /* NTTDoCoMo */"440-09,10,11,12,13,14,15,16,17,18,19,21,22,23,24,25,26,27,"
00069                          "28,29,30,31,32,33,34,35,36,37,38,39,58,59,60,61,62,63,"
00070                          "64,65,66,67,68,69,87,99",
00071                                 _APN("bmobilewap",,) /*BMobile*/
00072                                 _APN("mpr2.bizho.net","Mopera U",) /* DoCoMo */
00073                                 _APN("bmobile.ne.jp","bmobile@wifi2","bmobile") /*BMobile*/ },
00074 
00075 // 293 Slovenia - SI
00076     { /* Si.mobil */ "293-40",  _APN("internet.simobil.si",,) },
00077     { /* Tusmobil */ "293-70",  _APN("internet.tusmobil.si",,) },
00078 
00079 // 228 Switzerland - CH
00080     { /* Swisscom */ "228-01",  _APN("gprs.swisscom.ch",,) },
00081     { /* Orange */   "228-03",  _APN("internet",,) /* contract */
00082                                 _APN("click",,)    /* pre-pay */ },
00083 
00084 // 234 United Kingdom - GB
00085     { /* O2 */       "234-02,10,11",
00086                                 _APN("mobile.o2.co.uk","faster","web") /* contract */
00087                                 _APN("mobile.o2.co.uk","bypass","web") /* pre-pay */
00088                                 _APN("payandgo.o2.co.uk","payandgo","payandgo") },
00089     { /* Vodafone */ "234-15",  _APN("internet","web","web")          /* contract */
00090                                 _APN("pp.vodafone.co.uk","wap","wap")  /* pre-pay */ },
00091 
00092 // 310 United States of America - US
00093     { /* T-Mobile */ "310-026,260,490",
00094                                 _APN("epc.tmobile.com",,)
00095                                 _APN("fast.tmobile.com",,) /* LTE */ },
00096     { /* AT&T */     "310-030,150,170,260,410,560,680",
00097                                 _APN("phone",,)
00098                                 _APN("wap.cingular","WAP@CINGULARGPRS.COM","CINGULAR1")
00099                                 _APN("isp.cingular","ISP@CINGULARGPRS.COM","CINGULAR1") },
00100 };
00101 
00102 inline const char* apnconfig(const char* imsi)
00103 {
00104     const char* config = NULL;
00105     if (imsi && *imsi) {
00106         // many carriers use internet without username and password, os use this as default
00107         // now try to lookup the setting for our table
00108         for (int i = 0; i < sizeof(apnlut)/sizeof(*apnlut) && !config; i ++) {
00109             const char* p = apnlut[i].mccmnc;
00110             // check the MCC
00111             if ((0 == memcmp(imsi, p, 3))) {
00112                 p += 3;
00113                 // check all the MNC, MNC length can be 2 or 3 digits
00114                 while (((p[0] == '-') || (p[0] == ',')) && 
00115                         (p[1] >= '0') && (p[1] <= '9') && 
00116                         (p[2] >= '0') && (p[2] <= '9') && !config) {
00117                     int l = ((p[3] >= '0') && (p[3] <= '9')) ? 3 : 2;
00118                     if (0 == memcmp(imsi+3,p+1,l))
00119                         config = apnlut[i].cfg;
00120                     p += 1 + l;
00121                 } 
00122             }
00123         }
00124     }
00125     // use default if not found
00126     if (!config)
00127         config = apndef;
00128     return config;
00129 }