support library for C027 helper functions for Buffer Pipes, Buffered Serial Port (rtos capable) and GPS parsing. It includes modem APIs for USSD, SMS and Sockets.

Dependents:   HTTPClient_Cellular_HelloWorld Cellular_HelloMQTT MbedSmartRestMain Car_Bon_car_module ... more

This library is intended to be used with u-blox products such as the C027 or a shield with u-blox cellular and GPS modules like the cellular and positioning shield from Embedded Artist.

For 2G/GSM and 3G/UMTS you need to:

  • have a SIM card and know its PIN number
  • need to know you network operators APN setting These setting should be passed to the connect or init and join functions. You can also extend the APN database in MDMAPN.h.

For CDMA products you need to make sure that you have provisioned and activated the modem with either Sprint or Verizon.

Committer:
mazgch
Date:
Fri Jun 06 10:33:13 2014 +0000
Revision:
88:135fb4bb7aac
Parent:
87:64f54572ea74
Child:
89:ea396f9f90a2
improve apn lookup

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 85:dd8f4f0d0ca9 1 #pragma once
mazgch 85:dd8f4f0d0ca9 2
mazgch 85:dd8f4f0d0ca9 3 /* ----------------------------------------------------------------
mazgch 85:dd8f4f0d0ca9 4 APN stands for Access Point Name, a setting on your modem or phone
mazgch 85:dd8f4f0d0ca9 5 that identifies an external network your phone can access for data
mazgch 85:dd8f4f0d0ca9 6 (e.g., 3G or 4G Internet service on your phone).
mazgch 85:dd8f4f0d0ca9 7
mazgch 85:dd8f4f0d0ca9 8 The APN settings can be forced when calling the join function.
mazgch 85:dd8f4f0d0ca9 9 Below is a list of known APNs that us used if no apn config
mazgch 85:dd8f4f0d0ca9 10 is forced. This list could be extended by other settings.
mazgch 85:dd8f4f0d0ca9 11
mazgch 85:dd8f4f0d0ca9 12 For further reading:
mazgch 85:dd8f4f0d0ca9 13 wiki apn: http://en.wikipedia.org/wiki/Access_Point_Name
mazgch 85:dd8f4f0d0ca9 14 wiki mcc/mnc: http://en.wikipedia.org/wiki/Mobile_country_code
mazgch 85:dd8f4f0d0ca9 15 google: https://www.google.de/search?q=APN+list
mazgch 85:dd8f4f0d0ca9 16 ---------------------------------------------------------------- */
mazgch 85:dd8f4f0d0ca9 17
mazgch 85:dd8f4f0d0ca9 18 //! helper to generate the APN string
mazgch 85:dd8f4f0d0ca9 19 #define _APN(apn,username,password) apn "\0" username "\0" password "\0"
mazgch 85:dd8f4f0d0ca9 20
mazgch 85:dd8f4f0d0ca9 21 //! helper to extract a field from the config string
mazgch 85:dd8f4f0d0ca9 22 #define _APN_GET(cfg) \
mazgch 85:dd8f4f0d0ca9 23 *cfg ? cfg : ""; \
mazgch 85:dd8f4f0d0ca9 24 cfg += strlen(cfg) + 1
mazgch 85:dd8f4f0d0ca9 25
mazgch 85:dd8f4f0d0ca9 26 //! APN lookup struct
mazgch 85:dd8f4f0d0ca9 27 typedef struct {
mazgch 85:dd8f4f0d0ca9 28 const char* mccmnc; //!< mobile country code (MCC) and mobile network code MNC
mazgch 85:dd8f4f0d0ca9 29 const char* cfg; //!< APN configuartion string, use _APN macro to generate
mazgch 85:dd8f4f0d0ca9 30 } APN_t;
mazgch 85:dd8f4f0d0ca9 31
mazgch 85:dd8f4f0d0ca9 32 //! default APN settings used by many networks
mazgch 85:dd8f4f0d0ca9 33 static const char* apndef = _APN("internet",,);
mazgch 85:dd8f4f0d0ca9 34
mazgch 85:dd8f4f0d0ca9 35 //! this is a list of special APNs for different network operators
mazgch 85:dd8f4f0d0ca9 36 static const APN_t apnlut[] = {
mazgch 88:135fb4bb7aac 37 // MCC Country
mazgch 88:135fb4bb7aac 38 // { /* Operator */ "MCC-MNC[,MNC]" _APN(APN,USERNAME,PASSWORD) },
mazgch 88:135fb4bb7aac 39 // MCC must be 3 digits
mazgch 88:135fb4bb7aac 40 // MNC must be either 2 or 3 digits
mazgch 85:dd8f4f0d0ca9 41
mazgch 88:135fb4bb7aac 42 // 262 Germany
mazgch 88:135fb4bb7aac 43 { /* T-Mobile */ "262-01", _APN("internet.t-mobile","t-mobile","tm") },
mazgch 88:135fb4bb7aac 44
mazgch 88:135fb4bb7aac 45 // 222 Italy
mazgch 88:135fb4bb7aac 46 { /* TIM */ "222-01", _APN("ibox.tim.it",,) },
mazgch 88:135fb4bb7aac 47 { /* Vodafone */ "222-10", _APN("web.omnitel.it",,) },
mazgch 85:dd8f4f0d0ca9 48
mazgch 88:135fb4bb7aac 49 // 228 Switzerland
mazgch 88:135fb4bb7aac 50 { /* Swisscom */ "228-01", _APN("gprs.swisscom.ch",,) },
mazgch 88:135fb4bb7aac 51 { /* Orange */ "228-03", _APN("internet",,) /* contract */
mazgch 88:135fb4bb7aac 52 _APN("click",,) /* pre-pay */ },
mazgch 88:135fb4bb7aac 53
mazgch 88:135fb4bb7aac 54 // 234 United Kingdom - GB
mazgch 88:135fb4bb7aac 55 { /* O2 */ "234-02,10,11",
mazgch 88:135fb4bb7aac 56 _APN("mobile.o2.co.uk","faster","web") /* contract */
mazgch 88:135fb4bb7aac 57 _APN("mobile.o2.co.uk","bypass","web") /* pre-pay */
mazgch 88:135fb4bb7aac 58 _APN("payandgo.o2.co.uk","payandgo","payandgo") },
mazgch 88:135fb4bb7aac 59 { /* Vodafone */ "234-15", _APN("internet","web","web") /* contract */
mazgch 88:135fb4bb7aac 60 _APN("pp.vodafone.co.uk","wap","wap") /* pre-pay */ },
mazgch 88:135fb4bb7aac 61
mazgch 88:135fb4bb7aac 62 // 310 USA
mazgch 88:135fb4bb7aac 63 { /* T-Mobile */ "310-026,260,490",
mazgch 85:dd8f4f0d0ca9 64 _APN("epc.tmobile.com",,)
mazgch 88:135fb4bb7aac 65 _APN("fast.tmobile.com",,) /* LTE */ },
mazgch 88:135fb4bb7aac 66 { /* AT&T */ "310-030,150,170,260,410,560,680",
mazgch 85:dd8f4f0d0ca9 67 _APN("phone",,)
mazgch 85:dd8f4f0d0ca9 68 _APN("wap.cingular","WAP@CINGULARGPRS.COM","CINGULAR1")
mazgch 85:dd8f4f0d0ca9 69 _APN("isp.cingular","ISP@CINGULARGPRS.COM","CINGULAR1") },
mazgch 85:dd8f4f0d0ca9 70 };
mazgch 88:135fb4bb7aac 71
mazgch 88:135fb4bb7aac 72 inline const char* apnconfig(const char* imsi)
mazgch 88:135fb4bb7aac 73 {
mazgch 88:135fb4bb7aac 74 const char* config = NULL;
mazgch 88:135fb4bb7aac 75 if (imsi && *imsi) {
mazgch 88:135fb4bb7aac 76 // many carriers use internet without username and password, os use this as default
mazgch 88:135fb4bb7aac 77 // now try to lookup the setting for our table
mazgch 88:135fb4bb7aac 78 for (int i = 0; i < sizeof(apnlut)/sizeof(*apnlut) && !config; i ++) {
mazgch 88:135fb4bb7aac 79 const char* p = apnlut[i].mccmnc;
mazgch 88:135fb4bb7aac 80 // check the MCC
mazgch 88:135fb4bb7aac 81 if ((0 == memcmp(imsi, p, 3))) {
mazgch 88:135fb4bb7aac 82 p += 3;
mazgch 88:135fb4bb7aac 83 // check all the MNC, MNC length can be 2 or 3 digits
mazgch 88:135fb4bb7aac 84 while (((p[0] == '-') || (p[0] == ',')) &&
mazgch 88:135fb4bb7aac 85 (p[1] >= '0') && (p[1] <= '9') &&
mazgch 88:135fb4bb7aac 86 (p[2] >= '0') && (p[2] <= '9') && !config) {
mazgch 88:135fb4bb7aac 87 int l = ((p[3] >= '0') && (p[3] <= '9')) ? 3 : 2;
mazgch 88:135fb4bb7aac 88 if (0 == memcmp(imsi+3,p+1,l))
mazgch 88:135fb4bb7aac 89 config = apnlut[i].cfg;
mazgch 88:135fb4bb7aac 90 p += 1 + l;
mazgch 88:135fb4bb7aac 91 }
mazgch 88:135fb4bb7aac 92 }
mazgch 88:135fb4bb7aac 93 }
mazgch 88:135fb4bb7aac 94 }
mazgch 88:135fb4bb7aac 95 // use default if not found
mazgch 88:135fb4bb7aac 96 if (!config)
mazgch 88:135fb4bb7aac 97 config = apndef;
mazgch 88:135fb4bb7aac 98 return config;
mazgch 88:135fb4bb7aac 99 }