Changes to support Vodafone K4606

Dependencies:   Socket USBHostWANDongle lwip-sys lwip

Fork of VodafoneUSBModem by mbed official

Committer:
donatien
Date:
Wed Jul 11 21:25:03 2012 +0000
Revision:
12:66dc2c8eba2d
Parent:
11:565b2ec40dea
Child:
18:1789a11d1892
Link Monitoring / Dual serial port support

Who changed what in which revision?

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