Changes to support Vodafone K4606
Dependencies: Socket USBHostWANDongle lwip-sys lwip
Fork of VodafoneUSBModem by
VodafoneUSBModem.cpp@22:06fb2a93a1f6, 2012-08-17 (annotated)
- Committer:
- donatien
- Date:
- Fri Aug 17 14:31:27 2012 +0000
- Revision:
- 22:06fb2a93a1f6
- Parent:
- VodafoneK3770.cpp@18:1789a11d1892
- Child:
- 23:21046ba01b7b
Fork with names/headers changes to prepare for pre-built version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 22:06fb2a93a1f6 | 1 | /* VodafoneUSBModem.cpp */ |
donatien | 22:06fb2a93a1f6 | 2 | /* Copyright (C) 2012 mbed.org, MIT License |
donatien | 22:06fb2a93a1f6 | 3 | * |
donatien | 22:06fb2a93a1f6 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
donatien | 22:06fb2a93a1f6 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
donatien | 22:06fb2a93a1f6 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
donatien | 22:06fb2a93a1f6 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
donatien | 22:06fb2a93a1f6 | 8 | * furnished to do so, subject to the following conditions: |
donatien | 22:06fb2a93a1f6 | 9 | * |
donatien | 22:06fb2a93a1f6 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
donatien | 22:06fb2a93a1f6 | 11 | * substantial portions of the Software. |
donatien | 22:06fb2a93a1f6 | 12 | * |
donatien | 22:06fb2a93a1f6 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
donatien | 22:06fb2a93a1f6 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
donatien | 22:06fb2a93a1f6 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
donatien | 22:06fb2a93a1f6 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
donatien | 22:06fb2a93a1f6 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
donatien | 22:06fb2a93a1f6 | 18 | */ |
donatien | 8:04b6a042595f | 19 | |
donatien | 18:1789a11d1892 | 20 | #define __DEBUG__ 3 |
donatien | 8:04b6a042595f | 21 | #ifndef __MODULE__ |
donatien | 22:06fb2a93a1f6 | 22 | #define __MODULE__ "VodafoneUSBModem.cpp" |
donatien | 8:04b6a042595f | 23 | #endif |
donatien | 8:04b6a042595f | 24 | |
donatien | 8:04b6a042595f | 25 | #include "core/fwk.h" |
donatien | 8:04b6a042595f | 26 | |
donatien | 22:06fb2a93a1f6 | 27 | #include "VodafoneUSBModem.h" |
donatien | 8:04b6a042595f | 28 | |
donatien | 22:06fb2a93a1f6 | 29 | VodafoneUSBModem::VodafoneUSBModem() : m_dongle(), |
donatien | 10:21a6f09d5631 | 30 | m_atStream(m_dongle.getSerial(1)), m_pppStream(m_dongle.getSerial(0)), m_at(&m_atStream), |
donatien | 12:66dc2c8eba2d | 31 | m_sms(&m_at), m_ussd(&m_at), m_linkMonitor(&m_at), m_ppp(&m_pppStream), |
donatien | 12:66dc2c8eba2d | 32 | m_dongleConnected(false), m_ipInit(false), m_smsInit(false), m_ussdInit(false), m_linkMonitorInit(false), m_atOpen(false) |
donatien | 8:04b6a042595f | 33 | { |
donatien | 8:04b6a042595f | 34 | |
donatien | 8:04b6a042595f | 35 | } |
donatien | 8:04b6a042595f | 36 | |
donatien | 8:04b6a042595f | 37 | class CREGProcessor : public IATCommandsProcessor |
donatien | 8:04b6a042595f | 38 | { |
donatien | 8:04b6a042595f | 39 | public: |
donatien | 8:04b6a042595f | 40 | CREGProcessor() : status(STATUS_REGISTERING) |
donatien | 8:04b6a042595f | 41 | { |
donatien | 8:04b6a042595f | 42 | |
donatien | 8:04b6a042595f | 43 | } |
donatien | 8:04b6a042595f | 44 | enum REGISTERING_STATUS { STATUS_REGISTERING, STATUS_OK, STATUS_FAILED }; |
donatien | 8:04b6a042595f | 45 | REGISTERING_STATUS getStatus() |
donatien | 8:04b6a042595f | 46 | { |
donatien | 8:04b6a042595f | 47 | return status; |
donatien | 8:04b6a042595f | 48 | } |
donatien | 8:04b6a042595f | 49 | private: |
donatien | 8:04b6a042595f | 50 | virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line) |
donatien | 8:04b6a042595f | 51 | { |
donatien | 8:04b6a042595f | 52 | int r; |
donatien | 8:04b6a042595f | 53 | if( sscanf(line, "+CREG: %*d,%d", &r) == 1 ) |
donatien | 8:04b6a042595f | 54 | { |
donatien | 8:04b6a042595f | 55 | switch(r) |
donatien | 8:04b6a042595f | 56 | { |
donatien | 8:04b6a042595f | 57 | case 1: |
donatien | 8:04b6a042595f | 58 | case 5: |
donatien | 8:04b6a042595f | 59 | status = STATUS_OK; |
donatien | 8:04b6a042595f | 60 | break; |
donatien | 8:04b6a042595f | 61 | case 0: |
donatien | 8:04b6a042595f | 62 | case 2: |
donatien | 8:04b6a042595f | 63 | status = STATUS_REGISTERING; |
donatien | 8:04b6a042595f | 64 | break; |
donatien | 8:04b6a042595f | 65 | case 3: |
donatien | 8:04b6a042595f | 66 | default: |
donatien | 8:04b6a042595f | 67 | status = STATUS_FAILED; |
donatien | 8:04b6a042595f | 68 | break; |
donatien | 8:04b6a042595f | 69 | } |
donatien | 8:04b6a042595f | 70 | } |
donatien | 8:04b6a042595f | 71 | return OK; |
donatien | 8:04b6a042595f | 72 | } |
donatien | 8:04b6a042595f | 73 | virtual int onNewEntryPrompt(ATCommandsInterface* pInst) |
donatien | 8:04b6a042595f | 74 | { |
donatien | 8:04b6a042595f | 75 | return OK; |
donatien | 8:04b6a042595f | 76 | } |
donatien | 8:04b6a042595f | 77 | volatile REGISTERING_STATUS status; |
donatien | 8:04b6a042595f | 78 | }; |
donatien | 8:04b6a042595f | 79 | |
donatien | 12:66dc2c8eba2d | 80 | #if 0 |
donatien | 8:04b6a042595f | 81 | class COPSProcessor : public IATCommandsProcessor |
donatien | 8:04b6a042595f | 82 | { |
donatien | 8:04b6a042595f | 83 | public: |
donatien | 8:04b6a042595f | 84 | COPSProcessor() : valid(false) |
donatien | 8:04b6a042595f | 85 | { |
donatien | 8:04b6a042595f | 86 | network[0] = '\0'; |
donatien | 8:04b6a042595f | 87 | apn[0] = '\0'; |
donatien | 8:04b6a042595f | 88 | bearer[0] = '\0'; |
donatien | 8:04b6a042595f | 89 | } |
donatien | 8:04b6a042595f | 90 | char* getNetwork() |
donatien | 8:04b6a042595f | 91 | { |
donatien | 8:04b6a042595f | 92 | return network; |
donatien | 8:04b6a042595f | 93 | } |
donatien | 8:04b6a042595f | 94 | char* getAPN() |
donatien | 8:04b6a042595f | 95 | { |
donatien | 8:04b6a042595f | 96 | return apn; |
donatien | 8:04b6a042595f | 97 | } |
donatien | 8:04b6a042595f | 98 | char* getBearer() |
donatien | 8:04b6a042595f | 99 | { |
donatien | 8:04b6a042595f | 100 | return bearer; |
donatien | 8:04b6a042595f | 101 | } |
donatien | 8:04b6a042595f | 102 | bool isValid() |
donatien | 8:04b6a042595f | 103 | { |
donatien | 8:04b6a042595f | 104 | return valid; |
donatien | 8:04b6a042595f | 105 | } |
donatien | 8:04b6a042595f | 106 | private: |
donatien | 8:04b6a042595f | 107 | virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line) |
donatien | 8:04b6a042595f | 108 | { |
donatien | 8:04b6a042595f | 109 | int networkId; |
donatien | 8:04b6a042595f | 110 | int bearerId; |
donatien | 8:04b6a042595f | 111 | int s = sscanf(line, "+COPS: %*d,%*d,\"%d\",%d", &networkId, &bearerId); |
donatien | 8:04b6a042595f | 112 | if( s == 2 ) |
donatien | 8:04b6a042595f | 113 | { |
donatien | 8:04b6a042595f | 114 | switch(networkId) |
donatien | 8:04b6a042595f | 115 | { |
donatien | 8:04b6a042595f | 116 | case 23415: |
donatien | 8:04b6a042595f | 117 | strcpy(network, "Vodafone UK"); |
donatien | 8:04b6a042595f | 118 | strcpy(apn, "pp.vodafone.co.uk"); |
donatien | 8:04b6a042595f | 119 | valid = true; |
donatien | 8:04b6a042595f | 120 | break; |
donatien | 8:04b6a042595f | 121 | case 20810: |
donatien | 8:04b6a042595f | 122 | strcpy(network, "SFR FR"); |
donatien | 8:04b6a042595f | 123 | strcpy(apn, "websfr"); |
donatien | 8:04b6a042595f | 124 | valid = true; |
donatien | 8:04b6a042595f | 125 | break; |
donatien | 8:04b6a042595f | 126 | default: |
donatien | 8:04b6a042595f | 127 | break; |
donatien | 8:04b6a042595f | 128 | } |
donatien | 8:04b6a042595f | 129 | } |
donatien | 8:04b6a042595f | 130 | else |
donatien | 8:04b6a042595f | 131 | { |
donatien | 8:04b6a042595f | 132 | return OK; |
donatien | 8:04b6a042595f | 133 | } |
donatien | 8:04b6a042595f | 134 | switch(bearerId) |
donatien | 8:04b6a042595f | 135 | { |
donatien | 8:04b6a042595f | 136 | case 0: strcpy(bearer, "GSM"); break; |
donatien | 8:04b6a042595f | 137 | case 1: strcpy(bearer, "GSM Compact"); break; |
donatien | 8:04b6a042595f | 138 | case 2: strcpy(bearer, "UTRAN"); break; |
donatien | 8:04b6a042595f | 139 | case 3: strcpy(bearer, "GSM w/EGPRS"); break; |
donatien | 8:04b6a042595f | 140 | case 4: strcpy(bearer, "UTRAN w/HSDPA"); break; |
donatien | 8:04b6a042595f | 141 | case 5: strcpy(bearer, "UTRAN w/HSUPA"); break; |
donatien | 8:04b6a042595f | 142 | case 6: strcpy(bearer, "UTRAN w/HSDPA and HSUPA"); break; |
donatien | 8:04b6a042595f | 143 | case 7: strcpy(bearer, "E-UTRAN"); break; |
donatien | 8:04b6a042595f | 144 | |
donatien | 8:04b6a042595f | 145 | default: |
donatien | 8:04b6a042595f | 146 | break; |
donatien | 8:04b6a042595f | 147 | } |
donatien | 8:04b6a042595f | 148 | return OK; |
donatien | 8:04b6a042595f | 149 | } |
donatien | 8:04b6a042595f | 150 | virtual int onNewEntryPrompt(ATCommandsInterface* pInst) |
donatien | 8:04b6a042595f | 151 | { |
donatien | 8:04b6a042595f | 152 | return OK; |
donatien | 8:04b6a042595f | 153 | } |
donatien | 8:04b6a042595f | 154 | char network[24]; |
donatien | 8:04b6a042595f | 155 | char bearer[24]; |
donatien | 8:04b6a042595f | 156 | char apn[24]; |
donatien | 8:04b6a042595f | 157 | volatile bool valid; |
donatien | 8:04b6a042595f | 158 | }; |
donatien | 12:66dc2c8eba2d | 159 | #endif |
donatien | 8:04b6a042595f | 160 | |
donatien | 22:06fb2a93a1f6 | 161 | int VodafoneUSBModem::connect(const char* apn, const char* user, const char* password) |
donatien | 8:04b6a042595f | 162 | { |
donatien | 8:04b6a042595f | 163 | if( !m_ipInit ) |
donatien | 8:04b6a042595f | 164 | { |
donatien | 8:04b6a042595f | 165 | m_ipInit = true; |
donatien | 8:04b6a042595f | 166 | m_ppp.init(); |
donatien | 8:04b6a042595f | 167 | } |
donatien | 8:04b6a042595f | 168 | m_ppp.setup(user, password); |
donatien | 8:04b6a042595f | 169 | |
donatien | 8:04b6a042595f | 170 | int ret = init(); |
donatien | 8:04b6a042595f | 171 | if(ret) |
donatien | 8:04b6a042595f | 172 | { |
donatien | 8:04b6a042595f | 173 | return ret; |
donatien | 8:04b6a042595f | 174 | } |
donatien | 8:04b6a042595f | 175 | |
donatien | 9:3f077dde13c9 | 176 | #if USE_ONE_PORT |
donatien | 8:04b6a042595f | 177 | m_smsInit = false; //SMS status reset |
donatien | 8:04b6a042595f | 178 | m_ussdInit = false; //USSD status reset |
donatien | 12:66dc2c8eba2d | 179 | m_linkMonitorInit = false; //Link monitor status reset |
donatien | 9:3f077dde13c9 | 180 | #endif |
donatien | 8:04b6a042595f | 181 | |
donatien | 8:04b6a042595f | 182 | ATCommandsInterface::ATResult result; |
donatien | 8:04b6a042595f | 183 | |
donatien | 9:3f077dde13c9 | 184 | #if 0 |
donatien | 8:04b6a042595f | 185 | //Get network info & select corresponding APN |
donatien | 8:04b6a042595f | 186 | COPSProcessor copsProcessor; |
donatien | 8:04b6a042595f | 187 | DBG("Get network info & select APN from DB"); |
donatien | 8:04b6a042595f | 188 | ret = m_at.execute("AT+COPS=,2;+COPS?", &copsProcessor, &result); //Configure to get operator's info in numeric code & get operator's id |
donatien | 8:04b6a042595f | 189 | DBG("Result of command: Err code=%d", ret); |
donatien | 8:04b6a042595f | 190 | DBG("ATResult: AT return=%d (code %d)", result.result, result.code); |
donatien | 8:04b6a042595f | 191 | |
donatien | 8:04b6a042595f | 192 | if(!copsProcessor.isValid()) |
donatien | 8:04b6a042595f | 193 | { |
donatien | 8:04b6a042595f | 194 | WARN("Connected to an unknown network, try to connect with default parameters"); |
donatien | 8:04b6a042595f | 195 | DBG("Connected with %s", copsProcessor.getBearer()); |
donatien | 8:04b6a042595f | 196 | } |
donatien | 8:04b6a042595f | 197 | else |
donatien | 8:04b6a042595f | 198 | { |
donatien | 8:04b6a042595f | 199 | DBG("Connected to %s with %s", copsProcessor.getNetwork(), copsProcessor.getBearer()); |
donatien | 8:04b6a042595f | 200 | char cmd[48]; |
donatien | 8:04b6a042595f | 201 | sprintf(cmd, "AT+CGDCONT=1,\"IP\",\"%s\"", copsProcessor.getAPN()); |
donatien | 8:04b6a042595f | 202 | ret = m_at.executeSimple(cmd, &result); |
donatien | 8:04b6a042595f | 203 | DBG("Result of command: Err code=%d", ret); |
donatien | 8:04b6a042595f | 204 | DBG("ATResult: AT return=%d (code %d)", result.result, result.code); |
donatien | 8:04b6a042595f | 205 | DBG("APN set to %s", copsProcessor.getAPN()); |
donatien | 8:04b6a042595f | 206 | } |
donatien | 8:04b6a042595f | 207 | #else |
donatien | 8:04b6a042595f | 208 | if(apn != NULL) |
donatien | 8:04b6a042595f | 209 | { |
donatien | 8:04b6a042595f | 210 | char cmd[48]; |
donatien | 8:04b6a042595f | 211 | sprintf(cmd, "AT+CGDCONT=1,\"IP\",\"%s\"", apn); |
donatien | 8:04b6a042595f | 212 | ret = m_at.executeSimple(cmd, &result); |
donatien | 8:04b6a042595f | 213 | DBG("Result of command: Err code=%d", ret); |
donatien | 8:04b6a042595f | 214 | DBG("ATResult: AT return=%d (code %d)", result.result, result.code); |
donatien | 8:04b6a042595f | 215 | DBG("APN set to %s", apn); |
donatien | 8:04b6a042595f | 216 | } |
donatien | 8:04b6a042595f | 217 | #endif |
donatien | 8:04b6a042595f | 218 | |
donatien | 8:04b6a042595f | 219 | |
donatien | 8:04b6a042595f | 220 | //Connect |
donatien | 8:04b6a042595f | 221 | DBG("Connecting"); |
donatien | 9:3f077dde13c9 | 222 | #if 0 |
donatien | 8:04b6a042595f | 223 | ret = m_at.executeSimple("ATDT *99#", &result); |
donatien | 8:04b6a042595f | 224 | DBG("Result of command: Err code=%d", ret); |
donatien | 8:04b6a042595f | 225 | DBG("ATResult: AT return=%d (code %d)", result.result, result.code); |
donatien | 9:3f077dde13c9 | 226 | #endif |
donatien | 9:3f077dde13c9 | 227 | #if USE_ONE_PORT |
donatien | 8:04b6a042595f | 228 | m_at.close(); // Closing AT parser |
donatien | 8:04b6a042595f | 229 | m_atOpen = false; //Will need to be reinitialized afterwards |
donatien | 9:3f077dde13c9 | 230 | #endif |
donatien | 8:04b6a042595f | 231 | |
donatien | 9:3f077dde13c9 | 232 | #if 0 |
donatien | 8:04b6a042595f | 233 | DBG("AT Parser closed"); |
donatien | 8:04b6a042595f | 234 | if( (ret!=NET_MOREINFO) || (result.result != ATCommandsInterface::ATResult::AT_CONNECT)) |
donatien | 8:04b6a042595f | 235 | { |
donatien | 8:04b6a042595f | 236 | ERR("Could not connect"); |
donatien | 8:04b6a042595f | 237 | return ret; //Could not connect |
donatien | 8:04b6a042595f | 238 | } |
donatien | 9:3f077dde13c9 | 239 | #endif |
donatien | 8:04b6a042595f | 240 | DBG("Connecting PPP"); |
donatien | 8:04b6a042595f | 241 | |
donatien | 12:66dc2c8eba2d | 242 | ret = m_ppp.connect(); |
donatien | 8:04b6a042595f | 243 | DBG("Result of connect: Err code=%d", ret); |
donatien | 8:04b6a042595f | 244 | return ret; |
donatien | 8:04b6a042595f | 245 | } |
donatien | 8:04b6a042595f | 246 | |
donatien | 8:04b6a042595f | 247 | |
donatien | 22:06fb2a93a1f6 | 248 | int VodafoneUSBModem::disconnect() |
donatien | 8:04b6a042595f | 249 | { |
donatien | 8:04b6a042595f | 250 | DBG("Disconnecting from PPP"); |
donatien | 8:04b6a042595f | 251 | int ret = m_ppp.disconnect(); |
donatien | 8:04b6a042595f | 252 | if(ret) |
donatien | 8:04b6a042595f | 253 | { |
donatien | 8:04b6a042595f | 254 | ERR("Disconnect returned %d, still trying to disconnect", ret); |
donatien | 8:04b6a042595f | 255 | } |
donatien | 8:04b6a042595f | 256 | |
donatien | 8:04b6a042595f | 257 | //Ugly but leave dongle time to recover |
donatien | 8:04b6a042595f | 258 | Thread::wait(500); |
donatien | 8:04b6a042595f | 259 | |
donatien | 9:3f077dde13c9 | 260 | #if USE_ONE_PORT |
donatien | 8:04b6a042595f | 261 | ATCommandsInterface::ATResult result; |
donatien | 8:04b6a042595f | 262 | DBG("Starting AT thread"); |
donatien | 8:04b6a042595f | 263 | ret = m_at.open(); |
donatien | 8:04b6a042595f | 264 | if(ret) |
donatien | 8:04b6a042595f | 265 | { |
donatien | 8:04b6a042595f | 266 | return ret; |
donatien | 8:04b6a042595f | 267 | } |
donatien | 9:3f077dde13c9 | 268 | #endif |
donatien | 8:04b6a042595f | 269 | |
donatien | 8:04b6a042595f | 270 | DBG("Trying to hangup"); |
donatien | 8:04b6a042595f | 271 | |
donatien | 9:3f077dde13c9 | 272 | #if 0 //Does not appear to work |
donatien | 8:04b6a042595f | 273 | int tries = 10; |
donatien | 8:04b6a042595f | 274 | do |
donatien | 8:04b6a042595f | 275 | { |
donatien | 8:04b6a042595f | 276 | ret = m_at.executeSimple("+++", &result, 1000); |
donatien | 8:04b6a042595f | 277 | DBG("Result of command: Err code=%d\n", ret); |
donatien | 8:04b6a042595f | 278 | DBG("ATResult: AT return=%d (code %d)\n", result.result, result.code); |
donatien | 8:04b6a042595f | 279 | } while(tries-- && ret); |
donatien | 8:04b6a042595f | 280 | if(!ret) |
donatien | 8:04b6a042595f | 281 | { |
donatien | 8:04b6a042595f | 282 | ret = m_at.executeSimple("ATH", &result); |
donatien | 8:04b6a042595f | 283 | DBG("Result of command: Err code=%d\n", ret); |
donatien | 8:04b6a042595f | 284 | DBG("ATResult: AT return=%d (code %d)\n", result.result, result.code); |
donatien | 8:04b6a042595f | 285 | } |
donatien | 9:3f077dde13c9 | 286 | #endif |
donatien | 8:04b6a042595f | 287 | |
donatien | 9:3f077dde13c9 | 288 | #if USE_ONE_PORT |
donatien | 8:04b6a042595f | 289 | //Reinit AT parser |
donatien | 8:04b6a042595f | 290 | ret = m_at.init(); |
donatien | 8:04b6a042595f | 291 | DBG("Result of command: Err code=%d\n", ret); |
donatien | 8:04b6a042595f | 292 | if(ret) |
donatien | 8:04b6a042595f | 293 | { |
donatien | 8:04b6a042595f | 294 | m_at.close(); // Closing AT parser |
donatien | 8:04b6a042595f | 295 | DBG("AT Parser closed, could not complete disconnection"); |
donatien | 8:04b6a042595f | 296 | return NET_TIMEOUT; |
donatien | 8:04b6a042595f | 297 | } |
donatien | 8:04b6a042595f | 298 | |
donatien | 9:3f077dde13c9 | 299 | #if 0 |
donatien | 8:04b6a042595f | 300 | m_at.close(); // Closing AT parser |
donatien | 8:04b6a042595f | 301 | DBG("AT Parser closed"); |
donatien | 9:3f077dde13c9 | 302 | #endif |
donatien | 9:3f077dde13c9 | 303 | #endif |
donatien | 8:04b6a042595f | 304 | return OK; |
donatien | 8:04b6a042595f | 305 | } |
donatien | 8:04b6a042595f | 306 | |
donatien | 22:06fb2a93a1f6 | 307 | int VodafoneUSBModem::sendSM(const char* number, const char* message) |
donatien | 8:04b6a042595f | 308 | { |
donatien | 8:04b6a042595f | 309 | int ret = init(); |
donatien | 8:04b6a042595f | 310 | if(ret) |
donatien | 8:04b6a042595f | 311 | { |
donatien | 8:04b6a042595f | 312 | return ret; |
donatien | 8:04b6a042595f | 313 | } |
donatien | 8:04b6a042595f | 314 | |
donatien | 8:04b6a042595f | 315 | if(!m_smsInit) |
donatien | 8:04b6a042595f | 316 | { |
donatien | 8:04b6a042595f | 317 | ret = m_sms.init(); |
donatien | 8:04b6a042595f | 318 | if(ret) |
donatien | 8:04b6a042595f | 319 | { |
donatien | 8:04b6a042595f | 320 | return ret; |
donatien | 8:04b6a042595f | 321 | } |
donatien | 8:04b6a042595f | 322 | m_smsInit = true; |
donatien | 8:04b6a042595f | 323 | } |
donatien | 8:04b6a042595f | 324 | |
donatien | 8:04b6a042595f | 325 | ret = m_sms.send(number, message); |
donatien | 8:04b6a042595f | 326 | if(ret) |
donatien | 8:04b6a042595f | 327 | { |
donatien | 8:04b6a042595f | 328 | return ret; |
donatien | 8:04b6a042595f | 329 | } |
donatien | 8:04b6a042595f | 330 | |
donatien | 8:04b6a042595f | 331 | return OK; |
donatien | 8:04b6a042595f | 332 | } |
donatien | 8:04b6a042595f | 333 | |
donatien | 22:06fb2a93a1f6 | 334 | int VodafoneUSBModem::getSM(char* number, char* message, size_t maxLength) |
donatien | 8:04b6a042595f | 335 | { |
donatien | 8:04b6a042595f | 336 | int ret = init(); |
donatien | 8:04b6a042595f | 337 | if(ret) |
donatien | 8:04b6a042595f | 338 | { |
donatien | 8:04b6a042595f | 339 | return ret; |
donatien | 8:04b6a042595f | 340 | } |
donatien | 8:04b6a042595f | 341 | |
donatien | 8:04b6a042595f | 342 | if(!m_smsInit) |
donatien | 8:04b6a042595f | 343 | { |
donatien | 8:04b6a042595f | 344 | ret = m_sms.init(); |
donatien | 8:04b6a042595f | 345 | if(ret) |
donatien | 8:04b6a042595f | 346 | { |
donatien | 8:04b6a042595f | 347 | return ret; |
donatien | 8:04b6a042595f | 348 | } |
donatien | 8:04b6a042595f | 349 | m_smsInit = true; |
donatien | 8:04b6a042595f | 350 | } |
donatien | 8:04b6a042595f | 351 | |
donatien | 8:04b6a042595f | 352 | ret = m_sms.get(number, message, maxLength); |
donatien | 8:04b6a042595f | 353 | if(ret) |
donatien | 8:04b6a042595f | 354 | { |
donatien | 8:04b6a042595f | 355 | return ret; |
donatien | 8:04b6a042595f | 356 | } |
donatien | 8:04b6a042595f | 357 | |
donatien | 8:04b6a042595f | 358 | return OK; |
donatien | 8:04b6a042595f | 359 | } |
donatien | 8:04b6a042595f | 360 | |
donatien | 22:06fb2a93a1f6 | 361 | int VodafoneUSBModem::getSMCount(size_t* pCount) |
donatien | 8:04b6a042595f | 362 | { |
donatien | 8:04b6a042595f | 363 | int ret = init(); |
donatien | 8:04b6a042595f | 364 | if(ret) |
donatien | 8:04b6a042595f | 365 | { |
donatien | 8:04b6a042595f | 366 | return ret; |
donatien | 8:04b6a042595f | 367 | } |
donatien | 8:04b6a042595f | 368 | |
donatien | 8:04b6a042595f | 369 | if(!m_smsInit) |
donatien | 8:04b6a042595f | 370 | { |
donatien | 8:04b6a042595f | 371 | ret = m_sms.init(); |
donatien | 8:04b6a042595f | 372 | if(ret) |
donatien | 8:04b6a042595f | 373 | { |
donatien | 8:04b6a042595f | 374 | return ret; |
donatien | 8:04b6a042595f | 375 | } |
donatien | 8:04b6a042595f | 376 | m_smsInit = true; |
donatien | 8:04b6a042595f | 377 | } |
donatien | 8:04b6a042595f | 378 | |
donatien | 8:04b6a042595f | 379 | ret = m_sms.getCount(pCount); |
donatien | 8:04b6a042595f | 380 | if(ret) |
donatien | 8:04b6a042595f | 381 | { |
donatien | 8:04b6a042595f | 382 | return ret; |
donatien | 8:04b6a042595f | 383 | } |
donatien | 8:04b6a042595f | 384 | |
donatien | 8:04b6a042595f | 385 | return OK; |
donatien | 8:04b6a042595f | 386 | } |
donatien | 8:04b6a042595f | 387 | |
donatien | 22:06fb2a93a1f6 | 388 | int VodafoneUSBModem::sendUSSD(const char* command, char* result, size_t maxLength) |
donatien | 8:04b6a042595f | 389 | { |
donatien | 8:04b6a042595f | 390 | int ret = init(); |
donatien | 8:04b6a042595f | 391 | if(ret) |
donatien | 8:04b6a042595f | 392 | { |
donatien | 8:04b6a042595f | 393 | return ret; |
donatien | 8:04b6a042595f | 394 | } |
donatien | 8:04b6a042595f | 395 | |
donatien | 8:04b6a042595f | 396 | if(!m_ussdInit) |
donatien | 8:04b6a042595f | 397 | { |
donatien | 8:04b6a042595f | 398 | ret = m_ussd.init(); |
donatien | 8:04b6a042595f | 399 | if(ret) |
donatien | 8:04b6a042595f | 400 | { |
donatien | 8:04b6a042595f | 401 | return ret; |
donatien | 8:04b6a042595f | 402 | } |
donatien | 8:04b6a042595f | 403 | m_ussdInit = true; |
donatien | 8:04b6a042595f | 404 | } |
donatien | 8:04b6a042595f | 405 | |
donatien | 8:04b6a042595f | 406 | ret = m_ussd.send(command, result, maxLength); |
donatien | 8:04b6a042595f | 407 | if(ret) |
donatien | 8:04b6a042595f | 408 | { |
donatien | 8:04b6a042595f | 409 | return ret; |
donatien | 8:04b6a042595f | 410 | } |
donatien | 8:04b6a042595f | 411 | |
donatien | 8:04b6a042595f | 412 | return OK; |
donatien | 8:04b6a042595f | 413 | } |
donatien | 8:04b6a042595f | 414 | |
donatien | 22:06fb2a93a1f6 | 415 | int VodafoneUSBModem::getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer) |
donatien | 12:66dc2c8eba2d | 416 | { |
donatien | 12:66dc2c8eba2d | 417 | int ret = init(); |
donatien | 12:66dc2c8eba2d | 418 | if(ret) |
donatien | 12:66dc2c8eba2d | 419 | { |
donatien | 12:66dc2c8eba2d | 420 | return ret; |
donatien | 12:66dc2c8eba2d | 421 | } |
donatien | 12:66dc2c8eba2d | 422 | |
donatien | 12:66dc2c8eba2d | 423 | if(!m_linkMonitorInit) |
donatien | 12:66dc2c8eba2d | 424 | { |
donatien | 12:66dc2c8eba2d | 425 | ret = m_linkMonitor.init(); |
donatien | 12:66dc2c8eba2d | 426 | if(ret) |
donatien | 12:66dc2c8eba2d | 427 | { |
donatien | 12:66dc2c8eba2d | 428 | return ret; |
donatien | 12:66dc2c8eba2d | 429 | } |
donatien | 12:66dc2c8eba2d | 430 | m_linkMonitorInit = true; |
donatien | 12:66dc2c8eba2d | 431 | } |
donatien | 12:66dc2c8eba2d | 432 | |
donatien | 12:66dc2c8eba2d | 433 | ret = m_linkMonitor.getState(pRssi, pRegistrationState, pBearer); |
donatien | 12:66dc2c8eba2d | 434 | if(ret) |
donatien | 12:66dc2c8eba2d | 435 | { |
donatien | 12:66dc2c8eba2d | 436 | return ret; |
donatien | 12:66dc2c8eba2d | 437 | } |
donatien | 12:66dc2c8eba2d | 438 | |
donatien | 12:66dc2c8eba2d | 439 | return OK; |
donatien | 12:66dc2c8eba2d | 440 | } |
donatien | 12:66dc2c8eba2d | 441 | |
donatien | 12:66dc2c8eba2d | 442 | |
donatien | 22:06fb2a93a1f6 | 443 | ATCommandsInterface* VodafoneUSBModem::getATCommandsInterface() |
donatien | 8:04b6a042595f | 444 | { |
donatien | 8:04b6a042595f | 445 | return &m_at; |
donatien | 8:04b6a042595f | 446 | } |
donatien | 8:04b6a042595f | 447 | |
donatien | 22:06fb2a93a1f6 | 448 | int VodafoneUSBModem::init() |
donatien | 8:04b6a042595f | 449 | { |
donatien | 8:04b6a042595f | 450 | if( !m_dongleConnected ) |
donatien | 8:04b6a042595f | 451 | { |
donatien | 8:04b6a042595f | 452 | m_dongleConnected = true; |
donatien | 8:04b6a042595f | 453 | while( !m_dongle.connected() ) |
donatien | 8:04b6a042595f | 454 | { |
donatien | 8:04b6a042595f | 455 | m_dongle.tryConnect(); |
donatien | 8:04b6a042595f | 456 | Thread::wait(10); |
donatien | 8:04b6a042595f | 457 | } |
donatien | 8:04b6a042595f | 458 | } |
donatien | 8:04b6a042595f | 459 | |
donatien | 8:04b6a042595f | 460 | if(m_atOpen) |
donatien | 8:04b6a042595f | 461 | { |
donatien | 8:04b6a042595f | 462 | return OK; |
donatien | 8:04b6a042595f | 463 | } |
donatien | 8:04b6a042595f | 464 | |
donatien | 8:04b6a042595f | 465 | DBG("Starting AT thread if needed"); |
donatien | 8:04b6a042595f | 466 | int ret = m_at.open(); |
donatien | 8:04b6a042595f | 467 | if(ret) |
donatien | 8:04b6a042595f | 468 | { |
donatien | 8:04b6a042595f | 469 | return ret; |
donatien | 8:04b6a042595f | 470 | } |
donatien | 8:04b6a042595f | 471 | |
donatien | 8:04b6a042595f | 472 | DBG("Sending initialisation commands"); |
donatien | 8:04b6a042595f | 473 | ret = m_at.init(); |
donatien | 8:04b6a042595f | 474 | if(ret) |
donatien | 8:04b6a042595f | 475 | { |
donatien | 8:04b6a042595f | 476 | return ret; |
donatien | 8:04b6a042595f | 477 | } |
donatien | 8:04b6a042595f | 478 | |
donatien | 22:06fb2a93a1f6 | 479 | if(m_dongle.getDongleType() == WAN_DONGLE_TYPE_VodafoneUSBModem) |
donatien | 8:04b6a042595f | 480 | { |
donatien | 18:1789a11d1892 | 481 | INFO("Using a Vodafone K3770 Dongle"); |
donatien | 18:1789a11d1892 | 482 | #if USE_ONE_PORT |
donatien | 18:1789a11d1892 | 483 | DBG("Configuring unsolicited result codes support properly"); |
donatien | 18:1789a11d1892 | 484 | //Configuring port to enable 3GPP-compliant unsollicited response codes but disable Huawei-specific unsollicited response codes |
donatien | 18:1789a11d1892 | 485 | ret = m_at.executeSimple("AT^CURC=0;^PORTSEL=1", NULL); //Huawei-specific, not 3GPP-compliant |
donatien | 18:1789a11d1892 | 486 | if(ret != OK) |
donatien | 18:1789a11d1892 | 487 | { |
donatien | 18:1789a11d1892 | 488 | return NET_PROTOCOL; |
donatien | 18:1789a11d1892 | 489 | } |
donatien | 18:1789a11d1892 | 490 | #else |
donatien | 18:1789a11d1892 | 491 | //Configuring port to disable Huawei-specific unsollicited response codes |
donatien | 18:1789a11d1892 | 492 | ret = m_at.executeSimple("AT^CURC=0", NULL); //Huawei-specific, not 3GPP-compliant |
donatien | 18:1789a11d1892 | 493 | if(ret != OK) |
donatien | 18:1789a11d1892 | 494 | { |
donatien | 18:1789a11d1892 | 495 | return NET_PROTOCOL; |
donatien | 18:1789a11d1892 | 496 | } |
donatien | 18:1789a11d1892 | 497 | #endif |
donatien | 8:04b6a042595f | 498 | } |
donatien | 18:1789a11d1892 | 499 | else if(m_dongle.getDongleType() == WAN_DONGLE_TYPE_VODAFONEK3772Z) |
donatien | 12:66dc2c8eba2d | 500 | { |
donatien | 18:1789a11d1892 | 501 | INFO("Using a Vodafone K3772-Z Dongle"); |
donatien | 18:1789a11d1892 | 502 | //FIXME this returns %USBMODEM: [0] MODEM DRIVER<CR><LF><CR><LF><CR><LF>OK<CR><LF> which is not a compliant response |
donatien | 18:1789a11d1892 | 503 | /* |
donatien | 18:1789a11d1892 | 504 | //Configuring modem to directly boot into modem mode |
donatien | 18:1789a11d1892 | 505 | ret = m_at.executeSimple("AT%USBMODEM=0", NULL); //Icera-specific, not 3GPP-compliant |
donatien | 18:1789a11d1892 | 506 | if(ret != OK) |
donatien | 18:1789a11d1892 | 507 | { |
donatien | 18:1789a11d1892 | 508 | return NET_PROTOCOL; |
donatien | 18:1789a11d1892 | 509 | } |
donatien | 18:1789a11d1892 | 510 | */ |
donatien | 18:1789a11d1892 | 511 | } |
donatien | 18:1789a11d1892 | 512 | else |
donatien | 18:1789a11d1892 | 513 | { |
donatien | 18:1789a11d1892 | 514 | WARN("Using an Unknown Dongle"); |
donatien | 18:1789a11d1892 | 515 | } |
donatien | 8:04b6a042595f | 516 | |
donatien | 8:04b6a042595f | 517 | ATCommandsInterface::ATResult result; |
donatien | 8:04b6a042595f | 518 | |
donatien | 8:04b6a042595f | 519 | //Wait for network registration |
donatien | 8:04b6a042595f | 520 | CREGProcessor cregProcessor; |
donatien | 8:04b6a042595f | 521 | do |
donatien | 8:04b6a042595f | 522 | { |
donatien | 8:04b6a042595f | 523 | DBG("Waiting for network registration"); |
donatien | 8:04b6a042595f | 524 | ret = m_at.execute("AT+CREG?", &cregProcessor, &result); |
donatien | 8:04b6a042595f | 525 | DBG("Result of command: Err code=%d\n", ret); |
donatien | 8:04b6a042595f | 526 | DBG("ATResult: AT return=%d (code %d)\n", result.result, result.code); |
donatien | 8:04b6a042595f | 527 | if(cregProcessor.getStatus() == CREGProcessor::STATUS_REGISTERING) |
donatien | 8:04b6a042595f | 528 | { |
donatien | 8:04b6a042595f | 529 | Thread::wait(3000); |
donatien | 8:04b6a042595f | 530 | } |
donatien | 8:04b6a042595f | 531 | } while(cregProcessor.getStatus() == CREGProcessor::STATUS_REGISTERING); |
donatien | 8:04b6a042595f | 532 | if(cregProcessor.getStatus() == CREGProcessor::STATUS_FAILED) |
donatien | 8:04b6a042595f | 533 | { |
donatien | 8:04b6a042595f | 534 | ERR("Registration denied"); |
donatien | 8:04b6a042595f | 535 | return NET_AUTH; |
donatien | 8:04b6a042595f | 536 | } |
donatien | 8:04b6a042595f | 537 | |
donatien | 8:04b6a042595f | 538 | m_atOpen = true; |
donatien | 8:04b6a042595f | 539 | |
donatien | 8:04b6a042595f | 540 | return OK; |
donatien | 8:04b6a042595f | 541 | } |
donatien | 8:04b6a042595f | 542 | |
donatien | 8:04b6a042595f | 543 |