Changes to support Vodafone K4606

Dependencies:   Socket USBHostWANDongle lwip-sys lwip

Fork of VodafoneUSBModem by mbed official

Committer:
dmitryp
Date:
Wed Jan 28 11:45:24 2015 +0000
Revision:
97:5fac418852e0
Parent:
92:ed0443728c60
Changes to support Vodafone K4606

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
ashleymills 85:d74a2a9d2b01 25 #include "USB3GModule/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);
ashleymills 92:ed0443728c60 106
ashleymills 92:ed0443728c60 107 /** Get the IP address of a connected device
ashleymills 92:ed0443728c60 108 @return A pointer to a string containing the IP address.
ashleymills 92:ed0443728c60 109 */
ashleymills 92:ed0443728c60 110 char* getIPAddress();
donatien 8:04b6a042595f 111
donatien 8:04b6a042595f 112 protected:
ashleymills 41:8bec5a8ea878 113 bool power(); //< Turn power to USB dongle ON.
donatien 26:d37501dc6c61 114
ashleymills 41:8bec5a8ea878 115 /** Initialise dongle.
ashleymills 41:8bec5a8ea878 116 * The following actions are performed:
ashleymills 41:8bec5a8ea878 117 * 1) Power up
ashleymills 41:8bec5a8ea878 118 * 2) Establish USB connection to dongle
ashleymills 41:8bec5a8ea878 119 * 3) Start AT interface thread
ashleymills 41:8bec5a8ea878 120 * 4) Wait for network registration
ashleymills 41:8bec5a8ea878 121 */
donatien 8:04b6a042595f 122 int init();
ashleymills 41:8bec5a8ea878 123
ashleymills 41:8bec5a8ea878 124 /** De-initialise dongle.
ashleymills 41:8bec5a8ea878 125 * The following actions are performed:
ashleymills 41:8bec5a8ea878 126 * 1) Tear down PPP session
ashleymills 41:8bec5a8ea878 127 * 2) Set SMS,USSD, and LinkMonitor subsystems to un-initialised
ashleymills 41:8bec5a8ea878 128 * 3) Close the AT commands interface
ashleymills 41:8bec5a8ea878 129 * 4) Tear down the USB connection to dongle
ashleymills 41:8bec5a8ea878 130 */
donatien 27:37d3ac289e86 131 int cleanup();
donatien 8:04b6a042595f 132
donatien 8:04b6a042595f 133 private:
ashleymills 41:8bec5a8ea878 134 WANDongle m_dongle; //< Interface to USB connected WAN dongle
donatien 8:04b6a042595f 135
ashleymills 41:8bec5a8ea878 136 USBSerialStream m_atStream; //< Serial interface to AT channel on modem
ashleymills 41:8bec5a8ea878 137 USBSerialStream m_pppStream; //< Serial interface to PPP channel on modem
donatien 8:04b6a042595f 138
ashleymills 41:8bec5a8ea878 139 ATCommandsInterface m_at; //< Interface to AT commands processing
donatien 8:04b6a042595f 140
ashleymills 41:8bec5a8ea878 141 SMSInterface m_sms; //< Interface to SMS manager (send/receive etc)
ashleymills 41:8bec5a8ea878 142 USSDInterface m_ussd; //< Interface to USSD manager (send etc)
ashleymills 41:8bec5a8ea878 143 LinkMonitor m_linkMonitor; //< Interface to link monitor (RSSI)
donatien 8:04b6a042595f 144
ashleymills 41:8bec5a8ea878 145 PPPIPInterface m_ppp; //< Interface to PPP conection manager (IP assignment etc)
donatien 8:04b6a042595f 146
ashleymills 41:8bec5a8ea878 147 bool m_dongleConnected; //< Is the dongle physically connected (does the USB stack respond)? true/false
ashleymills 41:8bec5a8ea878 148 bool m_ipInit; //< Has PPIPInterface object (m_ppp) been initialised? true/false
ashleymills 41:8bec5a8ea878 149 bool m_smsInit; //< Has SMSInterface object (m_sms) been initialised? true/false
ashleymills 41:8bec5a8ea878 150 bool m_ussdInit; //< Has USSDInterface object (m_ussd) been initialised? true/false
ashleymills 41:8bec5a8ea878 151 bool m_linkMonitorInit; //< Has LinkMonitor object (m_linkMonitor) been initialised? true/false
ashleymills 41:8bec5a8ea878 152 bool m_atOpen; //< Is the interface to the ATCommandsInterface open? true/false
donatien 26:d37501dc6c61 153
ashleymills 41:8bec5a8ea878 154 PinName m_powerGatingPin; //< Pin which toggles power gating
ashleymills 41:8bec5a8ea878 155 bool m_powerGatingOnWhenPinHigh; //< Semantics of power gating (whether high or low toggles power gating)
donatien 8:04b6a042595f 156 };
donatien 8:04b6a042595f 157
donatien 8:04b6a042595f 158
donatien 22:06fb2a93a1f6 159 #endif /* VODAFONEUSBMODEM_H_ */