Vodafone K3770/K3772-Z modems driver & networking library

Dependencies:   Socket USBHostWANDongle lwip-sys lwip

Dependents:   VodafoneUSBModemHTTPClientTest VodafoneUSBModemNTPClientTest VodafoneUSBModemSMSTest VodafoneUSBModemUSSDTest ... more

Fork of VodafoneUSBModem_bleedingedge by Donatien Garnier

This is the driver for the Vodafone K3700 & K3772-Z Dongles:

K3770

More details and instructions can be found here.

Committer:
donatien
Date:
Fri Sep 14 10:13:48 2012 +0000
Revision:
33:f505faeda8e7
Parent:
27:37d3ac289e86
Child:
41:8bec5a8ea878
Added parameter for power gating pin config

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 22:06fb2a93a1f6 1 /* VodafoneUSBModem.h */
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 22:06fb2a93a1f6 20 #ifndef VODAFONEUSBMODEM_H_
donatien 22:06fb2a93a1f6 21 #define VODAFONEUSBMODEM_H_
donatien 8:04b6a042595f 22
donatien 8:04b6a042595f 23 #include "core/fwk.h"
donatien 8:04b6a042595f 24
donatien 8:04b6a042595f 25 #include "WANDongle.h"
donatien 8:04b6a042595f 26 #include "at/ATCommandsInterface.h"
donatien 8:04b6a042595f 27 #include "serial/usb/USBSerialStream.h"
donatien 8:04b6a042595f 28 #include "ip/PPPIPInterface.h"
donatien 8:04b6a042595f 29 #include "sms/SMSInterface.h"
donatien 8:04b6a042595f 30 #include "ussd/USSDInterface.h"
donatien 12:66dc2c8eba2d 31 #include "link/LinkMonitor.h"
donatien 8:04b6a042595f 32
donatien 22:06fb2a93a1f6 33 /** Vodafone USB Modem (K3770/K3772-Z) dongle
donatien 8:04b6a042595f 34 */
donatien 22:06fb2a93a1f6 35 class VodafoneUSBModem
donatien 8:04b6a042595f 36 {
donatien 8:04b6a042595f 37 public:
donatien 22:06fb2a93a1f6 38 /** Create Vodafone USB Modem (K3770/K3772-Z) dongle API instance
donatien 26:d37501dc6c61 39 @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line
donatien 33:f505faeda8e7 40 @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true
donatien 8:04b6a042595f 41 */
donatien 33:f505faeda8e7 42 VodafoneUSBModem(PinName powerGatingPin = NC, bool powerGatingOnWhenPinHigh = true);
donatien 8:04b6a042595f 43
donatien 8:04b6a042595f 44 //Internet-related functions
donatien 8:04b6a042595f 45
donatien 8:04b6a042595f 46 /** Open a 3G internet connection
donatien 8:04b6a042595f 47 @return 0 on success, error code on failure
donatien 8:04b6a042595f 48 */
donatien 8:04b6a042595f 49 int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
donatien 8:04b6a042595f 50
donatien 8:04b6a042595f 51 /** Close the internet connection
donatien 8:04b6a042595f 52 @return 0 on success, error code on failure
donatien 8:04b6a042595f 53 */
donatien 8:04b6a042595f 54 int disconnect();
donatien 8:04b6a042595f 55
donatien 8:04b6a042595f 56
donatien 8:04b6a042595f 57 /** Send a SM
donatien 8:04b6a042595f 58 @param number The receiver's phone number
donatien 8:04b6a042595f 59 @param message The message to send
donatien 8:04b6a042595f 60 @return 0 on success, error code on failure
donatien 8:04b6a042595f 61 */
donatien 8:04b6a042595f 62 int sendSM(const char* number, const char* message);
donatien 8:04b6a042595f 63
donatien 8:04b6a042595f 64
donatien 8:04b6a042595f 65 /** Receive a SM
donatien 8:04b6a042595f 66 @param number Pointer to a buffer to store the sender's phone number (must be at least 17 characters-long, including the sapce for the null-terminating char)
donatien 8:04b6a042595f 67 @param message Pointer to a buffer to store the the incoming message
donatien 8:04b6a042595f 68 @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
donatien 8:04b6a042595f 69 @return 0 on success, error code on failure
donatien 8:04b6a042595f 70 */
donatien 8:04b6a042595f 71 int getSM(char* number, char* message, size_t maxLength);
donatien 8:04b6a042595f 72
donatien 8:04b6a042595f 73 /** Get the number of SMs in the incoming box
donatien 8:04b6a042595f 74 @param pCount pointer to store the number of unprocessed SMs on
donatien 8:04b6a042595f 75 @return 0 on success, error code on failure
donatien 8:04b6a042595f 76 */
donatien 8:04b6a042595f 77 int getSMCount(size_t* pCount);
donatien 8:04b6a042595f 78
donatien 8:04b6a042595f 79 /** Send a USSD command & wait for its result
donatien 8:04b6a042595f 80 @param command The command to send
donatien 8:04b6a042595f 81 @param result Buffer in which to store the result
donatien 8:04b6a042595f 82 @param maxLength Maximum result length that can be stored in buffer (including null-terminating character)
donatien 8:04b6a042595f 83 @return 0 on success, error code on failure
donatien 8:04b6a042595f 84 */
donatien 8:04b6a042595f 85 int sendUSSD(const char* command, char* result, size_t maxLength);
donatien 12:66dc2c8eba2d 86
donatien 12:66dc2c8eba2d 87 /** Get link state
donatien 12:66dc2c8eba2d 88 @param pRssi pointer to store the current RSSI in dBm, between -51 dBm and -113 dBm if known; -51 dBm means -51 dBm or more; -113 dBm means -113 dBm or less; 0 if unknown
donatien 12:66dc2c8eba2d 89 @param pRegistrationState pointer to store the current registration state
donatien 12:66dc2c8eba2d 90 @param pBearer pointer to store the current bearer
donatien 12:66dc2c8eba2d 91 @return 0 on success, error code on failure
donatien 12:66dc2c8eba2d 92 */
donatien 12:66dc2c8eba2d 93 int getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer);
donatien 8:04b6a042595f 94
donatien 8:04b6a042595f 95 /** Get the ATCommandsInterface instance
donatien 26:d37501dc6c61 96 @return Pointer to the ATCommandsInterface instance
donatien 8:04b6a042595f 97 */
donatien 8:04b6a042595f 98 ATCommandsInterface* getATCommandsInterface();
donatien 26:d37501dc6c61 99
donatien 26:d37501dc6c61 100 /** Switch power on or off
donatien 26:d37501dc6c61 101 In order to use this function, a pin name must have been entered in the constructor
donatien 26:d37501dc6c61 102 @param enable true to switch the dongle on, false to switch it off
donatien 26:d37501dc6c61 103 @return 0 on success, error code on failure
donatien 26:d37501dc6c61 104 */
donatien 26:d37501dc6c61 105 int power(bool enable);
donatien 8:04b6a042595f 106
donatien 8:04b6a042595f 107 protected:
donatien 26:d37501dc6c61 108 bool power();
donatien 26:d37501dc6c61 109
donatien 8:04b6a042595f 110 int init();
donatien 27:37d3ac289e86 111 int cleanup();
donatien 8:04b6a042595f 112
donatien 8:04b6a042595f 113 private:
donatien 8:04b6a042595f 114 WANDongle m_dongle;
donatien 8:04b6a042595f 115
donatien 8:04b6a042595f 116 USBSerialStream m_atStream;
donatien 8:04b6a042595f 117 USBSerialStream m_pppStream;
donatien 8:04b6a042595f 118
donatien 8:04b6a042595f 119 ATCommandsInterface m_at;
donatien 8:04b6a042595f 120
donatien 8:04b6a042595f 121 SMSInterface m_sms;
donatien 8:04b6a042595f 122 USSDInterface m_ussd;
donatien 12:66dc2c8eba2d 123 LinkMonitor m_linkMonitor;
donatien 8:04b6a042595f 124
donatien 8:04b6a042595f 125 PPPIPInterface m_ppp;
donatien 8:04b6a042595f 126
donatien 8:04b6a042595f 127 bool m_dongleConnected;
donatien 8:04b6a042595f 128 bool m_ipInit;
donatien 8:04b6a042595f 129 bool m_smsInit;
donatien 8:04b6a042595f 130 bool m_ussdInit;
donatien 12:66dc2c8eba2d 131 bool m_linkMonitorInit;
donatien 8:04b6a042595f 132 bool m_atOpen;
donatien 26:d37501dc6c61 133
donatien 26:d37501dc6c61 134 PinName m_powerGatingPin;
donatien 33:f505faeda8e7 135 bool m_powerGatingOnWhenPinHigh;
donatien 8:04b6a042595f 136 };
donatien 8:04b6a042595f 137
donatien 8:04b6a042595f 138
donatien 22:06fb2a93a1f6 139 #endif /* VODAFONEUSBMODEM_H_ */