|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * Copyright (c) 2017 ublox, ARM Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +/* ---------------------------------------------------------------- |
| 18 | + APN stands for Access Point Name, a setting on your modem or phone |
| 19 | + that identifies an external network your phone can access for data |
| 20 | + (e.g. 3G or 4G Internet service on your phone). |
| 21 | +
|
| 22 | + The APN settings can be forced when calling the join function. |
| 23 | + Below is a list of known APNs that us used if no apn config |
| 24 | + is forced. This list could be extended by other settings. |
| 25 | +
|
| 26 | + For further reading: |
| 27 | + wiki apn: http://en.wikipedia.org/wiki/Access_Point_Name |
| 28 | + wiki mcc/mnc: http://en.wikipedia.org/wiki/Mobile_country_code |
| 29 | + google: https://www.google.de/search?q=APN+list |
| 30 | +---------------------------------------------------------------- */ |
| 31 | + |
| 32 | +#include "APN_db.h" |
| 33 | + |
| 34 | +#if (MBED_CONF_CELLULAR_USE_APN_LOOKUP || (NSAPI_PPP_AVAILABLE && MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP)) |
| 35 | + |
| 36 | +/** |
| 37 | + * Helper to generate the APN string |
| 38 | + */ |
| 39 | +#define _APN(apn,username,password) apn "\0" username "\0" password "\0" |
| 40 | + |
| 41 | +/** |
| 42 | + * APN lookup struct |
| 43 | + */ |
| 44 | +typedef struct { |
| 45 | + const char *mccmnc; /**< mobile country code (MCC) and mobile network code MNC */ |
| 46 | + const char *cfg; /**< APN configuartion string, use _APN macro to generate */ |
| 47 | +} APN_t; |
| 48 | + |
| 49 | +/** |
| 50 | + * Default APN settings used by many networks |
| 51 | + */ |
| 52 | +static const char *apndef = _APN("internet",,); |
| 53 | + |
| 54 | +/** |
| 55 | + * List of special APNs for different network operators. |
| 56 | + * |
| 57 | + * No need to add default, "internet" will be used as a default if no entry matches. |
| 58 | + * The APN without username/password have to be listed first. |
| 59 | + */ |
| 60 | + |
| 61 | +static const APN_t apnlut[] = { |
| 62 | +// MCC Country |
| 63 | +// { /* Operator */ "MCC-MNC[,MNC]" _APN(APN,USERNAME,PASSWORD) }, |
| 64 | +// MCC must be 3 digits |
| 65 | +// MNC must be either 2 or 3 digits |
| 66 | +// MCC must be separated by '-' from MNC, multiple MNC can be separated by ',' |
| 67 | + |
| 68 | +// 232 Austria - AUT |
| 69 | + { /* T-Mobile */ "232-03", _APN("m2m.business",,) }, |
| 70 | + |
| 71 | +// 460 China - CN |
| 72 | + { /* CN Mobile */"460-00", _APN("cmnet",,) |
| 73 | + _APN("cmwap",,) |
| 74 | + }, |
| 75 | + { /* Unicom */ "460-01", _APN("3gnet",,) |
| 76 | + _APN("uninet", "uninet", "uninet") |
| 77 | + }, |
| 78 | + |
| 79 | +// 262 Germany - DE |
| 80 | + { /* T-Mobile */ "262-01", _APN("internet.t-mobile", "t-mobile", "tm") }, |
| 81 | + { /* T-Mobile */ "262-02,06", |
| 82 | + _APN("m2m.business",,) |
| 83 | + }, |
| 84 | + |
| 85 | +// 222 Italy - IT |
| 86 | + { /* TIM */ "222-01", _APN("ibox.tim.it",,) }, |
| 87 | + { /* Vodafone */ "222-10", _APN("web.omnitel.it",,) }, |
| 88 | + { /* Wind */ "222-88", _APN("internet.wind.biz",,) }, |
| 89 | + |
| 90 | +// 440 Japan - JP |
| 91 | + { /* Softbank */ "440-04,06,20,40,41,42,43,44,45,46,47,48,90,91,92,93,94,95" |
| 92 | + ",96,97,98" |
| 93 | + _APN("open.softbank.ne.jp", "opensoftbank", "ebMNuX1FIHg9d3DA") |
| 94 | + _APN("smile.world", "dna1trop", "so2t3k3m2a") |
| 95 | + }, |
| 96 | + { /* NTTDoCoMo */"440-09,10,11,12,13,14,15,16,17,18,19,21,22,23,24,25,26,27," |
| 97 | + "28,29,30,31,32,33,34,35,36,37,38,39,58,59,60,61,62,63," |
| 98 | + "64,65,66,67,68,69,87,99", |
| 99 | + _APN("bmobilewap",,) /*BMobile*/ |
| 100 | + _APN("mpr2.bizho.net", "Mopera U",) /* DoCoMo */ |
| 101 | + _APN("bmobile.ne.jp", "bmobile@wifi2", "bmobile") /*BMobile*/ |
| 102 | + }, |
| 103 | + |
| 104 | +// 204 Netherlands - NL |
| 105 | + { /* Vodafone */ "204-04", _APN("public4.m2minternet.com",,) }, |
| 106 | + |
| 107 | +// 293 Slovenia - SI |
| 108 | + { /* Si.mobil */ "293-40", _APN("internet.simobil.si",,) }, |
| 109 | + { /* Tusmobil */ "293-70", _APN("internet.tusmobil.si",,) }, |
| 110 | + |
| 111 | +// 240 Sweden SE |
| 112 | + { /* Telia */ "240-01", _APN("online.telia.se",,) }, |
| 113 | + { /* Telenor */ "240-06,08", |
| 114 | + _APN("services.telenor.se",,) |
| 115 | + }, |
| 116 | + { /* Tele2 */ "240-07", _APN("mobileinternet.tele2.se",,) }, |
| 117 | + |
| 118 | +// 228 Switzerland - CH |
| 119 | + { /* Swisscom */ "228-01", _APN("gprs.swisscom.ch",,) }, |
| 120 | + { /* Orange */ "228-03", _APN("internet",,) /* contract */ |
| 121 | + _APN("click",,) /* pre-pay */ |
| 122 | + }, |
| 123 | + |
| 124 | +// 234 United Kingdom - GB |
| 125 | + { /* O2 */ "234-02,10,11", |
| 126 | + _APN("mobile.o2.co.uk", "faster", "web") /* contract */ |
| 127 | + _APN("mobile.o2.co.uk", "bypass", "web") /* pre-pay */ |
| 128 | + _APN("payandgo.o2.co.uk", "payandgo", "payandgo") |
| 129 | + }, |
| 130 | + { /* Vodafone */ "234-15", _APN("internet", "web", "web") /* contract */ |
| 131 | + _APN("pp.vodafone.co.uk", "wap", "wap") /* pre-pay */ |
| 132 | + }, |
| 133 | + { /* Three */ "234-20", _APN("three.co.uk",,) }, |
| 134 | + { /* Jersey */ "234-50", _APN("jtm2m",,) /* as used on u-blox C030 U201 boards */ }, |
| 135 | + |
| 136 | +// 310 United States of America - US |
| 137 | + { /* T-Mobile */ "310-026,260,490", |
| 138 | + _APN("epc.tmobile.com",,) |
| 139 | + _APN("fast.tmobile.com",,) /* LTE */ |
| 140 | + }, |
| 141 | + { /* AT&T */ "310-030,150,170,260,410,560,680", |
| 142 | + _APN("phone",,) |
| 143 | + _APN( "wap.cingular", "[email protected]", "CINGULAR1") |
| 144 | + _APN( "isp.cingular", "[email protected]", "CINGULAR1") |
| 145 | + }, |
| 146 | + |
| 147 | +// 901 International - INT |
| 148 | + { /* Transatel */ "901-37", _APN("netgprs.com", "tsl", "tsl") }, |
| 149 | +}; |
| 150 | + |
| 151 | +const char *apnconfig(const char *imsi) |
| 152 | +{ |
| 153 | + const char *config = NULL; |
| 154 | + if (imsi && *imsi) { |
| 155 | + // many carriers use internet without username and password, os use this as default |
| 156 | + // now try to lookup the setting for our table |
| 157 | + for (size_t i = 0; i < sizeof(apnlut) / sizeof(*apnlut) && !config; i ++) { |
| 158 | + const char *p = apnlut[i].mccmnc; |
| 159 | + // check the MCC |
| 160 | + if ((0 == memcmp(imsi, p, 3))) { |
| 161 | + p += 3; |
| 162 | + // check all the MNC, MNC length can be 2 or 3 digits |
| 163 | + while (((p[0] == '-') || (p[0] == ',')) && |
| 164 | + (p[1] >= '0') && (p[1] <= '9') && |
| 165 | + (p[2] >= '0') && (p[2] <= '9') && !config) { |
| 166 | + int l = ((p[3] >= '0') && (p[3] <= '9')) ? 3 : 2; |
| 167 | + if (0 == memcmp(imsi + 3, p + 1, l)) { |
| 168 | + config = apnlut[i].cfg; |
| 169 | + } |
| 170 | + p += 1 + l; |
| 171 | + } |
| 172 | + } |
| 173 | + } |
| 174 | + } |
| 175 | + // use default if not found |
| 176 | + if (!config) { |
| 177 | + config = apndef; |
| 178 | + } |
| 179 | + return config; |
| 180 | +} |
| 181 | + |
| 182 | +#endif |
0 commit comments