1 /* VodafoneUSBModem.h */
2 /* Copyright (C) 2012 mbed.org, MIT License
4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in all copies or
11 * substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "at/ATCommandsInterface.h"
26 #include "ip/PPPIPInterface.h"
27 #include "sms/GSMSMSInterface.h"
28 #include "sms/CDMASMSInterface.h"
29 #include "ussd/USSDInterface.h"
30 #include "link/LinkMonitor.h"
31 #include "CellularModem.h"
33 class genericAtProcessor
: public IATCommandsProcessor
37 const char* getResponse(void);
39 virtual int onNewATResponseLine(ATCommandsInterface
* pInst
, const char* line
);
40 virtual int onNewEntryPrompt(ATCommandsInterface
* pInst
);
46 /** u-blox WCDMA modem (LISA-U200)
48 class UbloxModem
: public CellularModem
51 /** Create u-blox API instance
52 @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line
53 @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true
55 UbloxModem(IOStream
* atStream
, IOStream
* pppStream
);
57 //Internet-related functions
59 /** Open a 3G internet connection
60 @return 0 on success, error code on failure
62 virtual int connect(const char* apn
= NULL
, const char* user
= NULL
, const char* password
= NULL
);
64 /** Close the internet connection
65 @return 0 on success, error code on failure
67 virtual int disconnect();
71 @param number The receiver's phone number
72 @param message The message to send
73 @return 0 on success, error code on failure
75 virtual int sendSM(const char* number
, const char* message
);
79 @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)
80 @param message Pointer to a buffer to store the the incoming message
81 @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
82 @return 0 on success, error code on failure
84 virtual int getSM(char* number
, char* message
, size_t maxLength
);
86 /** Get the number of SMs in the incoming box
87 @param pCount pointer to store the number of unprocessed SMs on
88 @return 0 on success, error code on failure
90 virtual int getSMCount(size_t* pCount
);
92 /** Send a USSD command & wait for its result
93 @param command The command to send
94 @param result Buffer in which to store the result
95 @param maxLength Maximum result length that can be stored in buffer (including null-terminating character)
96 @return 0 on success, error code on failure
98 int sendUSSD(const char* command
, char* result
, size_t maxLength
);
101 @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
102 @param pRegistrationState pointer to store the current registration state
103 @param pBearer pointer to store the current bearer
104 @return 0 on success, error code on failure
106 int getLinkState(int* pRssi
, LinkMonitor::REGISTRATION_STATE
* pRegistrationState
, LinkMonitor::BEARER
* pBearer
);
108 int getPhoneNumber(char* phoneNumber
);
110 /** Get the ATCommandsInterface instance
111 @return Pointer to the ATCommandsInterface instance
113 virtual ATCommandsInterface
* getATCommandsInterface();
116 /** Initialise dongle.
117 * The following actions are performed:
118 * 1) Start AT interface thread
119 * 2) Wait for network registration
123 /** De-initialise dongle.
124 * The following actions are performed:
125 * 1) Tear down PPP session
126 * 2) Set SMS,USSD, and LinkMonitor subsystems to un-initialised
127 * 3) Close the AT commands interface
129 virtual int cleanup();
132 ATCommandsInterface m_at
; //< Interface to AT commands processing
134 CDMASMSInterface m_CdmaSms
; //< Interface to SMS manager (send/receive etc)
135 GSMSMSInterface m_GsmSms
; //< Interface to SMS manager (send/receive etc)
136 USSDInterface m_ussd
; //< Interface to USSD manager (send etc)
137 LinkMonitor m_linkMonitor
; //< Interface to link monitor (RSSI)
139 PPPIPInterface m_ppp
; //< Interface to PPP conection manager (IP assignment etc)
141 bool m_ipInit
; //< Has PPIPInterface object (m_ppp) been initialised? true/false
142 bool m_smsInit
; //< Has SMSInterface object (m_sms) been initialised? true/false
143 bool m_ussdInit
; //< Has USSDInterface object (m_ussd) been initialised? true/false
144 bool m_linkMonitorInit
; //< Has LinkMonitor object (m_linkMonitor) been initialised? true/false
145 bool m_atOpen
; //< Is the interface to the ATCommandsInterface open? true/false
148 enum { LISA_C200
, LISA_U200
, SARA_G350
, UNKNOWN
} m_type
;
151 #include "WANDongle.h"
152 #include "serial/usb/USBSerialStream.h"
154 class UbloxUSBModem
: public UbloxModem
159 virtual int cleanup();
160 virtual int power(bool enable
) { return 1; }
163 WANDongle m_dongle
; //< Interface to USB connected WAN dongle
165 USBSerialStream m_atStream
; //< Serial interface to AT channel on modem
166 USBSerialStream m_pppStream
; //< Serial interface to PPP channel on modem
168 bool m_dongleConnected
; //< Is the dongle physically connected (does the USB stack respond)? true/false
171 #include "serial/io/IOSerialStream.h"
173 class UbloxSerModem
: public UbloxModem
177 virtual int power(bool enable
) { return 1; }
180 IOSerialStream m_atStream
; //< Serial interface to AT channel on modem
183 #endif /* UBLOXMODEM_H_ */