GNSS

Dependents:   ublox-at-cellular-interface-ext

Fork of ublox-at-cellular-interface by u-blox

Committer:
fahim.alavi@u-blox.com
Date:
Thu Feb 21 15:39:41 2019 +0500
Revision:
26:a16a65a4a06c
Parent:
25:34c79d68667e
Support of R41XM added for PSM

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobMeades 0:7ccf0e7e8a83 1 /* Copyright (c) 2017 ARM Limited
RobMeades 0:7ccf0e7e8a83 2 *
RobMeades 0:7ccf0e7e8a83 3 * Licensed under the Apache License, Version 2.0 (the "License");
RobMeades 0:7ccf0e7e8a83 4 * you may not use this file except in compliance with the License.
RobMeades 0:7ccf0e7e8a83 5 * You may obtain a copy of the License at
RobMeades 0:7ccf0e7e8a83 6 *
RobMeades 0:7ccf0e7e8a83 7 * http://www.apache.org/licenses/LICENSE-2.0
RobMeades 0:7ccf0e7e8a83 8 *
RobMeades 0:7ccf0e7e8a83 9 * Unless required by applicable law or agreed to in writing, software
RobMeades 0:7ccf0e7e8a83 10 * distributed under the License is distributed on an "AS IS" BASIS,
RobMeades 0:7ccf0e7e8a83 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
RobMeades 0:7ccf0e7e8a83 12 * See the License for the specific language governing permissions and
RobMeades 0:7ccf0e7e8a83 13 * limitations under the License.
RobMeades 0:7ccf0e7e8a83 14 */
RobMeades 0:7ccf0e7e8a83 15
rob.meades@u-blox.com 1:bc228becc45d 16 #ifndef _UBLOX_AT_CELLULAR_INTERFACE_
rob.meades@u-blox.com 1:bc228becc45d 17 #define _UBLOX_AT_CELLULAR_INTERFACE_
RobMeades 0:7ccf0e7e8a83 18
rob.meades@u-blox.com 1:bc228becc45d 19 #include "UbloxCellularBase.h"
rob.meades@u-blox.com 1:bc228becc45d 20 #include "CellularBase.h"
RobMeades 0:7ccf0e7e8a83 21 #include "NetworkStack.h"
RobMeades 0:7ccf0e7e8a83 22
RobMeades 0:7ccf0e7e8a83 23 /** UbloxATCellularInterface class.
RobMeades 0:7ccf0e7e8a83 24 *
RobMeades 0:7ccf0e7e8a83 25 * This uses the cellular-tuned IP stack that
RobMeades 0:7ccf0e7e8a83 26 * is on-board the cellular modem instead of the
RobMeades 0:7ccf0e7e8a83 27 * LWIP stack on the mbed MCU.
RobMeades 0:7ccf0e7e8a83 28 *
RobMeades 0:7ccf0e7e8a83 29 * There are three advantages to using this mechanism:
RobMeades 0:7ccf0e7e8a83 30 *
RobMeades 0:7ccf0e7e8a83 31 * 1. Since the modem interface remains in AT mode
RobMeades 0:7ccf0e7e8a83 32 * throughout, it is possible to continue using
RobMeades 0:7ccf0e7e8a83 33 * any AT commands (e.g. send SMS, use the module's
RobMeades 0:7ccf0e7e8a83 34 * file system, etc.) while the connection is up.
RobMeades 0:7ccf0e7e8a83 35 *
RobMeades 0:7ccf0e7e8a83 36 * 2. The UbloxATCellularInterfaceExt class can
RobMeades 0:7ccf0e7e8a83 37 * be used to perform very simple HTTP and FTP
RobMeades 0:7ccf0e7e8a83 38 * operations using the modem's on-board clients.
RobMeades 0:7ccf0e7e8a83 39 *
RobMeades 0:7ccf0e7e8a83 40 * 3. LWIP is not required (and hence RAM is saved).
RobMeades 0:7ccf0e7e8a83 41 *
RobMeades 0:7ccf0e7e8a83 42 * The disadvantage is that some additional parsing
RobMeades 0:7ccf0e7e8a83 43 * (at the AT interface) has to go on in order to exchange
RobMeades 0:7ccf0e7e8a83 44 * IP packets, so this is less efficient under heavy loads.
RobMeades 0:7ccf0e7e8a83 45 * Also TCP Server and getting/setting of socket options is
RobMeades 0:7ccf0e7e8a83 46 * currently not supported.
RobMeades 0:7ccf0e7e8a83 47 */
RobMeades 0:7ccf0e7e8a83 48
RobMeades 0:7ccf0e7e8a83 49 // Forward declaration
RobMeades 0:7ccf0e7e8a83 50 class NetworkStack;
RobMeades 0:7ccf0e7e8a83 51
RobMeades 0:7ccf0e7e8a83 52 /*
RobMeades 0:7ccf0e7e8a83 53 * NOTE: order is important in the inheritance below! PAL takes this class
RobMeades 0:7ccf0e7e8a83 54 * and casts it to CellularInterface and so CellularInterface has to be first
RobMeades 0:7ccf0e7e8a83 55 * in the last for that to work.
RobMeades 0:7ccf0e7e8a83 56 */
RobMeades 0:7ccf0e7e8a83 57
RobMeades 0:7ccf0e7e8a83 58 /** UbloxATCellularInterface class.
RobMeades 0:7ccf0e7e8a83 59 *
RobMeades 0:7ccf0e7e8a83 60 * This class implements the network stack interface into the cellular
RobMeades 0:7ccf0e7e8a83 61 * modems on the C030 and C027 boards for 2G/3G/4G modules using
RobMeades 0:7ccf0e7e8a83 62 * the IP stack running on the cellular module.
RobMeades 0:7ccf0e7e8a83 63 */
RobMeades 0:7ccf0e7e8a83 64 class UbloxATCellularInterface : public CellularBase, public NetworkStack, virtual public UbloxCellularBase {
RobMeades 0:7ccf0e7e8a83 65
RobMeades 0:7ccf0e7e8a83 66 public:
RobMeades 0:7ccf0e7e8a83 67 /** Constructor.
RobMeades 0:7ccf0e7e8a83 68 *
RobMeades 0:7ccf0e7e8a83 69 * @param tx the UART TX data pin to which the modem is attached.
RobMeades 0:7ccf0e7e8a83 70 * @param rx the UART RX data pin to which the modem is attached.
RobMeades 0:7ccf0e7e8a83 71 * @param baud the UART baud rate.
RobMeades 0:7ccf0e7e8a83 72 * @param debug_on true to switch AT interface debug on, otherwise false.
RobMeades 0:7ccf0e7e8a83 73 */
RobMeades 0:7ccf0e7e8a83 74 UbloxATCellularInterface(PinName tx = MDMTXD,
RobMeades 0:7ccf0e7e8a83 75 PinName rx = MDMRXD,
RobMeades 0:7ccf0e7e8a83 76 int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE,
amq 19:2b30a056ae54 77 bool debug_on = false,
amq 19:2b30a056ae54 78 osPriority priority = osPriorityNormal);
RobMeades 0:7ccf0e7e8a83 79
RobMeades 0:7ccf0e7e8a83 80 /* Destructor.
RobMeades 0:7ccf0e7e8a83 81 */
RobMeades 0:7ccf0e7e8a83 82 virtual ~UbloxATCellularInterface();
RobMeades 0:7ccf0e7e8a83 83
RobMeades 0:7ccf0e7e8a83 84 /** The amount of extra space needed in terms of AT interface
RobMeades 0:7ccf0e7e8a83 85 * characters to get a chunk of user data (i.e. one UDP packet
RobMeades 0:7ccf0e7e8a83 86 * or a portion of a TCP packet) across the AT interface.
RobMeades 0:7ccf0e7e8a83 87 */
RobMeades 0:7ccf0e7e8a83 88 #define AT_PACKET_OVERHEAD 77
RobMeades 0:7ccf0e7e8a83 89
RobMeades 0:7ccf0e7e8a83 90 /** The profile to use (on board the modem).
RobMeades 0:7ccf0e7e8a83 91 */
RobMeades 0:7ccf0e7e8a83 92 #define PROFILE "0"
RobMeades 0:7ccf0e7e8a83 93
RobMeades 0:7ccf0e7e8a83 94 /** Translates a host name to an IP address with specific IP version.
RobMeades 0:7ccf0e7e8a83 95 *
RobMeades 0:7ccf0e7e8a83 96 * The host name may be either a domain name or an IP address. If the
RobMeades 0:7ccf0e7e8a83 97 * host name is an IP address, no network transactions will be performed.
RobMeades 0:7ccf0e7e8a83 98 *
RobMeades 0:7ccf0e7e8a83 99 * If no stack-specific DNS resolution is provided, the host name
RobMeades 0:7ccf0e7e8a83 100 * will be resolved using a UDP socket on the stack.
RobMeades 0:7ccf0e7e8a83 101 *
RobMeades 0:7ccf0e7e8a83 102 * @param host Host name to resolve.
RobMeades 0:7ccf0e7e8a83 103 * @param address Destination for the host SocketAddress.
RobMeades 0:7ccf0e7e8a83 104 * @param version IP version of address to resolve, NSAPI_UNSPEC indicates
RobMeades 0:7ccf0e7e8a83 105 * version is chosen by the stack (defaults to NSAPI_UNSPEC).
RobMeades 0:7ccf0e7e8a83 106 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 107 */
RobMeades 0:7ccf0e7e8a83 108 virtual nsapi_error_t gethostbyname(const char *host,
RobMeades 0:7ccf0e7e8a83 109 SocketAddress *address,
RobMeades 0:7ccf0e7e8a83 110 nsapi_version_t version = NSAPI_UNSPEC);
RobMeades 0:7ccf0e7e8a83 111
RobMeades 0:7ccf0e7e8a83 112 /** Set the authentication scheme.
RobMeades 0:7ccf0e7e8a83 113 *
RobMeades 0:7ccf0e7e8a83 114 * @param auth The authentication scheme, chose from
RobMeades 0:7ccf0e7e8a83 115 * NSAPI_SECURITY_NONE, NSAPI_SECURITY_PAP,
RobMeades 0:7ccf0e7e8a83 116 * NSAPI_SECURITY_CHAP or NSAPI_SECURITY_UNKNOWN;
RobMeades 0:7ccf0e7e8a83 117 * use NSAPI_SECURITY_UNKNOWN to try all of none,
RobMeades 0:7ccf0e7e8a83 118 * PAP and CHAP.
RobMeades 0:7ccf0e7e8a83 119 */
RobMeades 0:7ccf0e7e8a83 120 virtual void set_authentication(nsapi_security_t auth);
RobMeades 0:7ccf0e7e8a83 121
RobMeades 0:7ccf0e7e8a83 122 /** Set the cellular network credentials.
RobMeades 0:7ccf0e7e8a83 123 *
RobMeades 0:7ccf0e7e8a83 124 * Please check documentation of connect() for default behaviour of APN settings.
RobMeades 0:7ccf0e7e8a83 125 *
RobMeades 0:7ccf0e7e8a83 126 * @param apn Access point name.
RobMeades 0:7ccf0e7e8a83 127 * @param uname Optionally, user name.
RobMeades 0:7ccf0e7e8a83 128 * @param pwd Optionally, password.
RobMeades 0:7ccf0e7e8a83 129 */
RobMeades 0:7ccf0e7e8a83 130 virtual void set_credentials(const char *apn, const char *uname = 0,
RobMeades 0:7ccf0e7e8a83 131 const char *pwd = 0);
RobMeades 0:7ccf0e7e8a83 132
RobMeades 0:7ccf0e7e8a83 133 /** Set the PIN code for the SIM card.
RobMeades 0:7ccf0e7e8a83 134 *
RobMeades 0:7ccf0e7e8a83 135 * @param sim_pin PIN for the SIM card.
RobMeades 0:7ccf0e7e8a83 136 */
RobMeades 0:7ccf0e7e8a83 137 virtual void set_sim_pin(const char *sim_pin);
RobMeades 0:7ccf0e7e8a83 138
RobMeades 0:7ccf0e7e8a83 139 /** Connect to the cellular network and start the interface.
RobMeades 0:7ccf0e7e8a83 140 *
RobMeades 0:7ccf0e7e8a83 141 * Attempts to connect to a cellular network. Note: if init() has
RobMeades 0:7ccf0e7e8a83 142 * not been called beforehand, connect() will call it first.
RobMeades 0:7ccf0e7e8a83 143 *
RobMeades 0:7ccf0e7e8a83 144 * @param sim_pin PIN for the SIM card.
RobMeades 0:7ccf0e7e8a83 145 * @param apn Optionally, access point name.
RobMeades 0:7ccf0e7e8a83 146 * @param uname Optionally, user name.
RobMeades 0:7ccf0e7e8a83 147 * @param pwd Optionally, password.
RobMeades 0:7ccf0e7e8a83 148 * @return NSAPI_ERROR_OK on success, or negative error code on failure.
RobMeades 0:7ccf0e7e8a83 149 */
RobMeades 0:7ccf0e7e8a83 150 virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0,
RobMeades 0:7ccf0e7e8a83 151 const char *uname = 0, const char *pwd = 0);
RobMeades 0:7ccf0e7e8a83 152
RobMeades 0:7ccf0e7e8a83 153 /** Attempt to connect to the cellular network.
RobMeades 0:7ccf0e7e8a83 154 *
RobMeades 0:7ccf0e7e8a83 155 * Brings up the network interface. Connects to the cellular radio
RobMeades 0:7ccf0e7e8a83 156 * network and then brings up IP stack on the cellular modem to be used
RobMeades 0:7ccf0e7e8a83 157 * indirectly via AT commands, rather than LWIP. Note: if init() has
RobMeades 0:7ccf0e7e8a83 158 * not been called beforehand, connect() will call it first.
RobMeades 0:7ccf0e7e8a83 159 * NOTE: even a failed attempt to connect will cause the modem to remain
RobMeades 0:7ccf0e7e8a83 160 * powered up. To power it down, call deinit().
RobMeades 0:7ccf0e7e8a83 161 *
RobMeades 0:7ccf0e7e8a83 162 * For APN setup, default behaviour is to use 'internet' as APN string
RobMeades 0:7ccf0e7e8a83 163 * and assuming no authentication is required, i.e., user name and password
RobMeades 0:7ccf0e7e8a83 164 * are not set. Optionally, a database lookup can be requested by turning
RobMeades 0:7ccf0e7e8a83 165 * on the APN database lookup feature. The APN database is by no means
RobMeades 0:7ccf0e7e8a83 166 * exhaustive (feel free to submit a pull request with additional values).
RobMeades 0:7ccf0e7e8a83 167 * It contains a short list of some public APNs with publicly available
RobMeades 0:7ccf0e7e8a83 168 * user names and passwords (if required) in some particular countries only.
RobMeades 0:7ccf0e7e8a83 169 * Lookup is done using IMSI (International mobile subscriber identifier).
RobMeades 0:7ccf0e7e8a83 170 *
RobMeades 0:7ccf0e7e8a83 171 * The preferred method is to setup APN using 'set_credentials()' API.
RobMeades 0:7ccf0e7e8a83 172 *
RobMeades 0:7ccf0e7e8a83 173 * If you find that the AT interface returns "CONNECT" but shortly afterwards
RobMeades 0:7ccf0e7e8a83 174 * drops the connection then 99% of the time this will be because the APN
RobMeades 0:7ccf0e7e8a83 175 * is incorrect.
RobMeades 0:7ccf0e7e8a83 176 *
RobMeades 0:7ccf0e7e8a83 177 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 178 */
RobMeades 0:7ccf0e7e8a83 179 virtual nsapi_error_t connect();
RobMeades 0:7ccf0e7e8a83 180
RobMeades 0:7ccf0e7e8a83 181 /** Attempt to disconnect from the network.
RobMeades 0:7ccf0e7e8a83 182 *
RobMeades 0:7ccf0e7e8a83 183 * Brings down the network interface.
RobMeades 0:7ccf0e7e8a83 184 * Does not bring down the Radio network.
RobMeades 0:7ccf0e7e8a83 185 *
RobMeades 0:7ccf0e7e8a83 186 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 187 */
RobMeades 0:7ccf0e7e8a83 188 virtual nsapi_error_t disconnect();
RobMeades 0:7ccf0e7e8a83 189
RobMeades 0:7ccf0e7e8a83 190 /** Adds or removes a SIM facility lock.
RobMeades 0:7ccf0e7e8a83 191 *
RobMeades 0:7ccf0e7e8a83 192 * Can be used to enable or disable SIM PIN check at device startup.
RobMeades 0:7ccf0e7e8a83 193 *
RobMeades 0:7ccf0e7e8a83 194 * @param set Can be set to true if the SIM PIN check is supposed
RobMeades 0:7ccf0e7e8a83 195 * to be enabled and vice versa.
RobMeades 0:7ccf0e7e8a83 196 * @param immediate If true, change the SIM PIN now, else set a flag
RobMeades 0:7ccf0e7e8a83 197 * and make the change only when connect() is called.
RobMeades 0:7ccf0e7e8a83 198 * If this is true and init() has not been called previously,
RobMeades 0:7ccf0e7e8a83 199 * it will be called first.
RobMeades 0:7ccf0e7e8a83 200 * @param sim_pin The current SIM PIN, must be a const. If this is not
RobMeades 0:7ccf0e7e8a83 201 * provided, the SIM PIN must have previously been set by a
RobMeades 0:7ccf0e7e8a83 202 * call to set_sim_pin().
RobMeades 0:7ccf0e7e8a83 203 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 204 */
RobMeades 0:7ccf0e7e8a83 205 nsapi_error_t set_sim_pin_check(bool set, bool immediate = false,
RobMeades 0:7ccf0e7e8a83 206 const char *sim_pin = NULL);
RobMeades 0:7ccf0e7e8a83 207
RobMeades 0:7ccf0e7e8a83 208 /** Change the PIN for the SIM card.
RobMeades 0:7ccf0e7e8a83 209 *
RobMeades 0:7ccf0e7e8a83 210 * Provide the new PIN for your SIM card with this API. It is ONLY possible to
RobMeades 0:7ccf0e7e8a83 211 * change the SIM PIN when SIM PIN checking is ENABLED.
RobMeades 0:7ccf0e7e8a83 212 *
RobMeades 0:7ccf0e7e8a83 213 * @param new_pin New PIN to be used in string format, must be a const.
RobMeades 0:7ccf0e7e8a83 214 * @param immediate If true, change the SIM PIN now, else set a flag
RobMeades 0:7ccf0e7e8a83 215 * and make the change only when connect() is called.
RobMeades 0:7ccf0e7e8a83 216 * If this is true and init() has not been called previously,
RobMeades 0:7ccf0e7e8a83 217 * it will be called first.
RobMeades 0:7ccf0e7e8a83 218 * @param old_pin Old PIN, must be a const. If this is not provided, the SIM PIN
RobMeades 0:7ccf0e7e8a83 219 * must have previously been set by a call to set_sim_pin().
RobMeades 0:7ccf0e7e8a83 220 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 221 */
RobMeades 0:7ccf0e7e8a83 222 nsapi_error_t set_new_sim_pin(const char *new_pin, bool immediate = false,
RobMeades 0:7ccf0e7e8a83 223 const char *old_pin = NULL);
RobMeades 0:7ccf0e7e8a83 224
RobMeades 0:7ccf0e7e8a83 225 /** Check if the connection is currently established or not.
RobMeades 0:7ccf0e7e8a83 226 *
RobMeades 0:7ccf0e7e8a83 227 * @return True if connected to a data network, otherwise false.
RobMeades 0:7ccf0e7e8a83 228 */
RobMeades 0:7ccf0e7e8a83 229 virtual bool is_connected();
RobMeades 0:7ccf0e7e8a83 230
RobMeades 0:7ccf0e7e8a83 231 /** Get the local IP address
RobMeades 0:7ccf0e7e8a83 232 *
RobMeades 0:7ccf0e7e8a83 233 * @return Null-terminated representation of the local IP address
RobMeades 0:7ccf0e7e8a83 234 * or null if no IP address has been received.
RobMeades 0:7ccf0e7e8a83 235 */
RobMeades 0:7ccf0e7e8a83 236 virtual const char *get_ip_address();
RobMeades 0:7ccf0e7e8a83 237
RobMeades 0:7ccf0e7e8a83 238 /** Get the local network mask.
RobMeades 0:7ccf0e7e8a83 239 *
RobMeades 0:7ccf0e7e8a83 240 * @return Null-terminated representation of the local network mask
RobMeades 0:7ccf0e7e8a83 241 * or null if no network mask has been received.
RobMeades 0:7ccf0e7e8a83 242 */
RobMeades 0:7ccf0e7e8a83 243 virtual const char *get_netmask();
RobMeades 0:7ccf0e7e8a83 244
RobMeades 0:7ccf0e7e8a83 245 /** Get the local gateways.
RobMeades 0:7ccf0e7e8a83 246 *
RobMeades 0:7ccf0e7e8a83 247 * @return Null-terminated representation of the local gateway
RobMeades 0:7ccf0e7e8a83 248 * or null if no network mask has been received.
RobMeades 0:7ccf0e7e8a83 249 */
RobMeades 0:7ccf0e7e8a83 250 virtual const char *get_gateway();
RobMeades 0:7ccf0e7e8a83 251
RobMeades 0:7ccf0e7e8a83 252 /** Call back in case connection is lost.
RobMeades 0:7ccf0e7e8a83 253 *
RobMeades 0:7ccf0e7e8a83 254 * @param cb The function to call.
RobMeades 0:7ccf0e7e8a83 255 */
RobMeades 0:7ccf0e7e8a83 256 void connection_status_cb(Callback<void(nsapi_error_t)> cb);
fahim.alavi@u-blox.com 16:457d6bb1613d 257
fahim.alavi@u-blox.com 16:457d6bb1613d 258 /** Connect the on board IP stack of the modem.
fahim.alavi@u-blox.com 16:457d6bb1613d 259 *
fahim.alavi@u-blox.com 16:457d6bb1613d 260 * @return True if successful, otherwise false.
fahim.alavi@u-blox.com 16:457d6bb1613d 261 */
fahim.alavi@u-blox.com 16:457d6bb1613d 262 virtual bool connect_modem_stack();
RobMeades 0:7ccf0e7e8a83 263
fahim.alavi@u-blox.com 26:a16a65a4a06c 264 #ifdef TARGET_UBLOX_C030_R41XM
wajahat.abbas@u-blox.com 17:b43a3b85353f 265
wajahat.abbas@u-blox.com 17:b43a3b85353f 266 // /** Supported MNO profiles for SARA-R4.
wajahat.abbas@u-blox.com 17:b43a3b85353f 267 // */
wajahat.abbas@u-blox.com 17:b43a3b85353f 268 // typedef enum {
wajahat.abbas@u-blox.com 17:b43a3b85353f 269 // SW_DEFAULT = 0,
wajahat.abbas@u-blox.com 17:b43a3b85353f 270 // SIM_ICCID = 1,
wajahat.abbas@u-blox.com 17:b43a3b85353f 271 // ATT = 2,
wajahat.abbas@u-blox.com 17:b43a3b85353f 272 // VERIZON = 3,
wajahat.abbas@u-blox.com 17:b43a3b85353f 273 // TELSTRA = 4,
wajahat.abbas@u-blox.com 17:b43a3b85353f 274 // TMO = 5,
wajahat.abbas@u-blox.com 17:b43a3b85353f 275 // CT = 6,
wajahat.abbas@u-blox.com 17:b43a3b85353f 276 // } MNOProfile;
wajahat.abbas@u-blox.com 17:b43a3b85353f 277
wajahat.abbas@u-blox.com 17:b43a3b85353f 278 /** Enable or disable the 3GPP PSM. Application should reboot the module after enabling PSM in order to enter PSM state
wajahat.abbas@u-blox.com 17:b43a3b85353f 279 *
wajahat.abbas@u-blox.com 17:b43a3b85353f 280 * @param periodic_time requested periodic TAU in seconds.
wajahat.abbas@u-blox.com 17:b43a3b85353f 281 * @param active_time requested active time in seconds.
wajahat.abbas@u-blox.com 17:b43a3b85353f 282 * @return True if successful, otherwise false.
wajahat.abbas@u-blox.com 17:b43a3b85353f 283 */
wajahat.abbas@u-blox.com 17:b43a3b85353f 284 bool set_power_saving_mode(int periodic_time, int active_time, Callback<void()> func);
wajahat.abbas@u-blox.com 17:b43a3b85353f 285
wajahat.abbas@u-blox.com 17:b43a3b85353f 286 bool set_power_saving_mode(int periodic_time = 60, int active_time = 20);
wajahat.abbas@u-blox.com 17:b43a3b85353f 287
wajahat.abbas@u-blox.com 17:b43a3b85353f 288 /** Converts the given uint to binary string. Fills the given str starting from [0] with the number of bits defined by bit_cnt
wajahat.abbas@u-blox.com 17:b43a3b85353f 289 * For example uint_to_binary_string(9, str, 10) would fill str "0000001001"
wajahat.abbas@u-blox.com 17:b43a3b85353f 290 * For example uint_to_binary_string(9, str, 3) would fill str "001"
wajahat.abbas@u-blox.com 17:b43a3b85353f 291 *
wajahat.abbas@u-blox.com 17:b43a3b85353f 292 * @param num uint to converts to binary string
wajahat.abbas@u-blox.com 17:b43a3b85353f 293 * @param str buffer for converted binary string
wajahat.abbas@u-blox.com 17:b43a3b85353f 294 * @param str_size size of the str buffer
wajahat.abbas@u-blox.com 17:b43a3b85353f 295 * @param bit_cnt defines how many bits are filled to buffer started from lsb
wajahat.abbas@u-blox.com 17:b43a3b85353f 296 */
wajahat.abbas@u-blox.com 17:b43a3b85353f 297 void uint_to_binary_str(uint32_t num, char* str, int str_size, int bit_cnt);
wajahat.abbas@u-blox.com 17:b43a3b85353f 298
wajahat.abbas@u-blox.com 17:b43a3b85353f 299 /** Wake the modem up from PSM
wajahat.abbas@u-blox.com 17:b43a3b85353f 300 *
wajahat.abbas@u-blox.com 17:b43a3b85353f 301 * @return True if modem has successfully waken up, false if modem could not wake up
wajahat.abbas@u-blox.com 17:b43a3b85353f 302 */
wajahat.abbas@u-blox.com 17:b43a3b85353f 303 bool modem_psm_wake_up();
wajahat.abbas@u-blox.com 17:b43a3b85353f 304
wajahat.abbas@u-blox.com 17:b43a3b85353f 305 // /** Set a Mobile Network Operator profile
wajahat.abbas@u-blox.com 17:b43a3b85353f 306 // *
wajahat.abbas@u-blox.com 17:b43a3b85353f 307 // * @param profile MNO profile, see enum MNOProfile
wajahat.abbas@u-blox.com 17:b43a3b85353f 308 // * @return True if operation washas successful, False if there was an error
wajahat.abbas@u-blox.com 17:b43a3b85353f 309 // */
wajahat.abbas@u-blox.com 17:b43a3b85353f 310 // bool set_mno_profile(MNOProfile profile = SW_DEFAULT);
wajahat.abbas@u-blox.com 17:b43a3b85353f 311 #endif
RobMeades 0:7ccf0e7e8a83 312
fahim.alavi@u-blox.com 20:7b033423126c 313 /** Set the plmn. PLMN controls to what network device registers.
fahim.alavi@u-blox.com 20:7b033423126c 314 *
fahim.alavi@u-blox.com 20:7b033423126c 315 * @param plmn user to force what network to register.
fahim.alavi@u-blox.com 20:7b033423126c 316 */
fahim.alavi@u-blox.com 20:7b033423126c 317 virtual void set_plmn(const char *plmn);
fahim.alavi@u-blox.com 20:7b033423126c 318
RobMeades 0:7ccf0e7e8a83 319 protected:
RobMeades 0:7ccf0e7e8a83 320
RobMeades 0:7ccf0e7e8a83 321 /** Socket "unused" value.
RobMeades 0:7ccf0e7e8a83 322 */
RobMeades 0:7ccf0e7e8a83 323 #define SOCKET_UNUSED -1
RobMeades 0:7ccf0e7e8a83 324
RobMeades 0:7ccf0e7e8a83 325 /** Socket timeout value in milliseconds.
RobMeades 0:7ccf0e7e8a83 326 * Note: the sockets layer above will retry the
RobMeades 0:7ccf0e7e8a83 327 * call to the functions here when they return NSAPI_ERROR_WOULD_BLOCK
RobMeades 0:7ccf0e7e8a83 328 * and the user has set a larger timeout or full blocking.
RobMeades 0:7ccf0e7e8a83 329 */
RobMeades 0:7ccf0e7e8a83 330 #define SOCKET_TIMEOUT 1000
RobMeades 0:7ccf0e7e8a83 331
RobMeades 0:7ccf0e7e8a83 332 /** The maximum number of bytes in a packet that can be written
RobMeades 0:7ccf0e7e8a83 333 * to the AT interface in one go.
RobMeades 0:7ccf0e7e8a83 334 */
RobMeades 0:7ccf0e7e8a83 335 #define MAX_WRITE_SIZE 1024
RobMeades 0:7ccf0e7e8a83 336
RobMeades 0:7ccf0e7e8a83 337 /** The maximum number of bytes in a packet that can be read from
RobMeades 0:7ccf0e7e8a83 338 * from the AT interface in one go.
RobMeades 0:7ccf0e7e8a83 339 */
RobMeades 0:7ccf0e7e8a83 340 #define MAX_READ_SIZE 1024
RobMeades 0:7ccf0e7e8a83 341
RobMeades 0:7ccf0e7e8a83 342 /** Management structure for sockets.
RobMeades 0:7ccf0e7e8a83 343 */
RobMeades 0:7ccf0e7e8a83 344 typedef struct {
RobMeades 0:7ccf0e7e8a83 345 int modem_handle; //!< The modem's handle for the socket.
RobMeades 0:7ccf0e7e8a83 346 volatile nsapi_size_t pending; //!< The number of received bytes pending.
RobMeades 0:7ccf0e7e8a83 347 void (*callback)(void *); //!< A callback for events.
RobMeades 0:7ccf0e7e8a83 348 void *data; //!< A data pointer that must be passed to the callback.
RobMeades 0:7ccf0e7e8a83 349 } SockCtrl;
RobMeades 0:7ccf0e7e8a83 350
RobMeades 0:7ccf0e7e8a83 351 /** Sockets storage.
RobMeades 0:7ccf0e7e8a83 352 */
RobMeades 0:7ccf0e7e8a83 353 SockCtrl _sockets[7];
RobMeades 0:7ccf0e7e8a83 354
RobMeades 0:7ccf0e7e8a83 355 /** Storage for a single IP address.
RobMeades 0:7ccf0e7e8a83 356 */
RobMeades 0:7ccf0e7e8a83 357 char *_ip;
RobMeades 0:7ccf0e7e8a83 358
RobMeades 0:7ccf0e7e8a83 359 /** The APN to use.
RobMeades 0:7ccf0e7e8a83 360 */
RobMeades 0:7ccf0e7e8a83 361 const char *_apn;
RobMeades 0:7ccf0e7e8a83 362
RobMeades 0:7ccf0e7e8a83 363 /** The user name to use.
RobMeades 0:7ccf0e7e8a83 364 */
RobMeades 0:7ccf0e7e8a83 365 const char *_uname;
RobMeades 0:7ccf0e7e8a83 366
RobMeades 0:7ccf0e7e8a83 367 /** The password to use.
RobMeades 0:7ccf0e7e8a83 368 */
RobMeades 0:7ccf0e7e8a83 369 const char *_pwd;
RobMeades 0:7ccf0e7e8a83 370
RobMeades 0:7ccf0e7e8a83 371 /** The type of authentication to use.
RobMeades 0:7ccf0e7e8a83 372 */
RobMeades 0:7ccf0e7e8a83 373 nsapi_security_t _auth;
RobMeades 0:7ccf0e7e8a83 374
RobMeades 0:7ccf0e7e8a83 375 /** Get the next set of credentials from the database.
RobMeades 0:7ccf0e7e8a83 376 */
rob.meades@u-blox.com 7:3b2ca10cc23a 377 virtual void get_next_credentials(const char ** config);
RobMeades 0:7ccf0e7e8a83 378
RobMeades 0:7ccf0e7e8a83 379 /** Activate one of the on-board modem's connection profiles.
RobMeades 0:7ccf0e7e8a83 380 *
RobMeades 0:7ccf0e7e8a83 381 * @param apn The APN to use.
RobMeades 0:7ccf0e7e8a83 382 * @param username The user name to use.
RobMeades 0:7ccf0e7e8a83 383 * @param password The password to use.
RobMeades 0:7ccf0e7e8a83 384 * @param auth The authentication method to use
RobMeades 0:7ccf0e7e8a83 385 * (NSAPI_SECURITY_NONE, NSAPI_SECURITY_PAP,
RobMeades 0:7ccf0e7e8a83 386 * NSAPI_SECURITY_CHAP or NSAPI_SECURITY_UNKNOWN).
RobMeades 0:7ccf0e7e8a83 387 * @return True if successful, otherwise false.
RobMeades 0:7ccf0e7e8a83 388 */
RobMeades 0:7ccf0e7e8a83 389 virtual bool activate_profile(const char* apn, const char* username,
RobMeades 0:7ccf0e7e8a83 390 const char* password, nsapi_security_t auth);
RobMeades 0:7ccf0e7e8a83 391
RobMeades 0:7ccf0e7e8a83 392 /** Activate a profile using the existing external connection.
RobMeades 0:7ccf0e7e8a83 393 *
RobMeades 0:7ccf0e7e8a83 394 * @return true if successful, otherwise false.
RobMeades 0:7ccf0e7e8a83 395 */
RobMeades 0:7ccf0e7e8a83 396 virtual bool activate_profile_reuse_external(void);
RobMeades 0:7ccf0e7e8a83 397
RobMeades 0:7ccf0e7e8a83 398 /** Activate a profile based on connection ID.
RobMeades 0:7ccf0e7e8a83 399 *
RobMeades 0:7ccf0e7e8a83 400 * @param cid The connection ID.
RobMeades 0:7ccf0e7e8a83 401 * @param apn The APN to use.
RobMeades 0:7ccf0e7e8a83 402 * @param username The user name to use.
RobMeades 0:7ccf0e7e8a83 403 * @param password The password to use.
RobMeades 0:7ccf0e7e8a83 404 * @param auth The authentication method to use.
RobMeades 0:7ccf0e7e8a83 405 * @return True if successful, otherwise false.
RobMeades 0:7ccf0e7e8a83 406 */
RobMeades 0:7ccf0e7e8a83 407 virtual bool activate_profile_by_cid(int cid, const char* apn, const char* username,
RobMeades 0:7ccf0e7e8a83 408 const char* password, nsapi_security_t auth);
RobMeades 0:7ccf0e7e8a83 409
RobMeades 0:7ccf0e7e8a83 410 /** Disconnect the on board IP stack of the modem.
RobMeades 0:7ccf0e7e8a83 411 *
RobMeades 0:7ccf0e7e8a83 412 * @return True if successful, otherwise false.
RobMeades 0:7ccf0e7e8a83 413 */
RobMeades 0:7ccf0e7e8a83 414 virtual bool disconnect_modem_stack();
RobMeades 0:7ccf0e7e8a83 415
RobMeades 0:7ccf0e7e8a83 416 /** Provide access to the NetworkStack object
RobMeades 0:7ccf0e7e8a83 417 *
RobMeades 0:7ccf0e7e8a83 418 * @return The underlying NetworkStack object.
RobMeades 0:7ccf0e7e8a83 419 */
RobMeades 0:7ccf0e7e8a83 420 virtual NetworkStack *get_stack();
RobMeades 0:7ccf0e7e8a83 421
RobMeades 0:7ccf0e7e8a83 422 protected:
RobMeades 0:7ccf0e7e8a83 423
RobMeades 0:7ccf0e7e8a83 424 /** Open a socket.
RobMeades 0:7ccf0e7e8a83 425 *
RobMeades 0:7ccf0e7e8a83 426 * Creates a network socket and stores it in the specified handle.
RobMeades 0:7ccf0e7e8a83 427 * The handle must be passed to following calls on the socket.
RobMeades 0:7ccf0e7e8a83 428 *
RobMeades 0:7ccf0e7e8a83 429 * @param handle Destination for the handle to a newly created socket.
RobMeades 0:7ccf0e7e8a83 430 * @param proto Protocol of socket to open, NSAPI_TCP or NSAPI_UDP.
RobMeades 0:7ccf0e7e8a83 431 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 432 */
RobMeades 0:7ccf0e7e8a83 433 virtual nsapi_error_t socket_open(nsapi_socket_t *handle,
RobMeades 0:7ccf0e7e8a83 434 nsapi_protocol_t proto);
RobMeades 0:7ccf0e7e8a83 435
RobMeades 0:7ccf0e7e8a83 436 /** Close a socket.
RobMeades 0:7ccf0e7e8a83 437 *
RobMeades 0:7ccf0e7e8a83 438 * Closes any open connection and deallocates any memory associated
RobMeades 0:7ccf0e7e8a83 439 * with the socket.
RobMeades 0:7ccf0e7e8a83 440 *
RobMeades 0:7ccf0e7e8a83 441 * @param handle Socket handle.
RobMeades 0:7ccf0e7e8a83 442 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 443 */
RobMeades 0:7ccf0e7e8a83 444 virtual nsapi_error_t socket_close(nsapi_socket_t handle);
RobMeades 0:7ccf0e7e8a83 445
RobMeades 0:7ccf0e7e8a83 446 /** Bind a specific port to a socket.
RobMeades 0:7ccf0e7e8a83 447 *
RobMeades 0:7ccf0e7e8a83 448 * Binding a socket specifies port on which to receive
RobMeades 0:7ccf0e7e8a83 449 * data. The IP address is ignored. Note that binding
RobMeades 0:7ccf0e7e8a83 450 * a socket involves closing it and reopening and so the
RobMeades 0:7ccf0e7e8a83 451 * bind operation should be carried out before any others.
RobMeades 0:7ccf0e7e8a83 452 *
RobMeades 0:7ccf0e7e8a83 453 * @param handle Socket handle.
RobMeades 0:7ccf0e7e8a83 454 * @param address Local address to bind (of which only the port is used).
RobMeades 0:7ccf0e7e8a83 455 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 456 */
RobMeades 0:7ccf0e7e8a83 457 virtual nsapi_error_t socket_bind(nsapi_socket_t handle,
RobMeades 0:7ccf0e7e8a83 458 const SocketAddress &address);
RobMeades 0:7ccf0e7e8a83 459
RobMeades 0:7ccf0e7e8a83 460 /** Connects TCP socket to a remote host.
RobMeades 0:7ccf0e7e8a83 461 *
RobMeades 0:7ccf0e7e8a83 462 * Initiates a connection to a remote server specified by the
RobMeades 0:7ccf0e7e8a83 463 * indicated address.
RobMeades 0:7ccf0e7e8a83 464 *
RobMeades 0:7ccf0e7e8a83 465 * @param handle Socket handle.
RobMeades 0:7ccf0e7e8a83 466 * @param address The SocketAddress of the remote host.
RobMeades 0:7ccf0e7e8a83 467 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 468 */
RobMeades 0:7ccf0e7e8a83 469 virtual nsapi_error_t socket_connect(nsapi_socket_t handle,
RobMeades 0:7ccf0e7e8a83 470 const SocketAddress &address);
RobMeades 0:7ccf0e7e8a83 471
RobMeades 0:7ccf0e7e8a83 472 /** Send data over a TCP socket.
RobMeades 0:7ccf0e7e8a83 473 *
RobMeades 0:7ccf0e7e8a83 474 * The socket must be connected to a remote host. Returns the number of
RobMeades 0:7ccf0e7e8a83 475 * bytes sent from the buffer. This class sets no upper buffer limit on
RobMeades 0:7ccf0e7e8a83 476 * buffer size and the maximum packet size is not connected with the
RobMeades 0:7ccf0e7e8a83 477 * platform.buffered-serial-txbuf-size/platform.buffered-serial-rxbuf-size
RobMeades 0:7ccf0e7e8a83 478 * definitions.
RobMeades 0:7ccf0e7e8a83 479 *
RobMeades 0:7ccf0e7e8a83 480 * @param handle Socket handle.
RobMeades 0:7ccf0e7e8a83 481 * @param data Buffer of data to send to the host.
RobMeades 0:7ccf0e7e8a83 482 * @param size Size of the buffer in bytes.
RobMeades 0:7ccf0e7e8a83 483 * @return Number of sent bytes on success, negative error
RobMeades 0:7ccf0e7e8a83 484 * code on failure.
RobMeades 0:7ccf0e7e8a83 485 */
RobMeades 0:7ccf0e7e8a83 486 virtual nsapi_size_or_error_t socket_send(nsapi_socket_t handle,
RobMeades 0:7ccf0e7e8a83 487 const void *data, nsapi_size_t size);
RobMeades 0:7ccf0e7e8a83 488
RobMeades 0:7ccf0e7e8a83 489 /** Send a packet over a UDP socket.
RobMeades 0:7ccf0e7e8a83 490 *
RobMeades 0:7ccf0e7e8a83 491 * Sends data to the specified address. Returns the number of bytes
RobMeades 0:7ccf0e7e8a83 492 * sent from the buffer.
RobMeades 0:7ccf0e7e8a83 493 *
RobMeades 0:7ccf0e7e8a83 494 * PACKET SIZES: the maximum packet size that can be sent in a single
RobMeades 0:7ccf0e7e8a83 495 * UDP packet is limited by the configuration value
RobMeades 0:7ccf0e7e8a83 496 * platform.buffered-serial-txbuf-size (defaults to 256).
RobMeades 0:7ccf0e7e8a83 497 * The maximum UDP packet size is:
RobMeades 0:7ccf0e7e8a83 498 *
RobMeades 0:7ccf0e7e8a83 499 * platform.buffered-serial-txbuf-size - AT_PACKET_OVERHEAD
RobMeades 0:7ccf0e7e8a83 500 *
RobMeades 0:7ccf0e7e8a83 501 * ...with a limit of 1024 bytes (at the AT interface). So, to allow sending
RobMeades 0:7ccf0e7e8a83 502 * of a 1024 byte UDP packet, edit your mbed_app.json to add a target override
RobMeades 0:7ccf0e7e8a83 503 * setting platform.buffered-serial-txbuf-size to 1101. However, for
RobMeades 0:7ccf0e7e8a83 504 * UDP packets, 508 bytes is considered a more realistic size, taking into
RobMeades 0:7ccf0e7e8a83 505 * account fragmentation sizes over the public internet, which leads to a
RobMeades 0:7ccf0e7e8a83 506 * platform.buffered-serial-txbuf-size/platform.buffered-serial-rxbuf-size
RobMeades 0:7ccf0e7e8a83 507 * setting of 585.
RobMeades 0:7ccf0e7e8a83 508 *
RobMeades 0:7ccf0e7e8a83 509 * If size is larger than this limit, the data will be split across separate
RobMeades 0:7ccf0e7e8a83 510 * UDP packets.
RobMeades 0:7ccf0e7e8a83 511 *
RobMeades 0:7ccf0e7e8a83 512 * @param handle Socket handle.
RobMeades 0:7ccf0e7e8a83 513 * @param address The SocketAddress of the remote host.
RobMeades 0:7ccf0e7e8a83 514 * @param data Buffer of data to send to the host.
RobMeades 0:7ccf0e7e8a83 515 * @param size Size of the buffer in bytes.
RobMeades 0:7ccf0e7e8a83 516 * @return Number of sent bytes on success, negative error
RobMeades 0:7ccf0e7e8a83 517 * code on failure.
RobMeades 0:7ccf0e7e8a83 518 */
RobMeades 0:7ccf0e7e8a83 519 virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle,
RobMeades 0:7ccf0e7e8a83 520 const SocketAddress &address,
RobMeades 0:7ccf0e7e8a83 521 const void *data,
RobMeades 0:7ccf0e7e8a83 522 nsapi_size_t size);
RobMeades 0:7ccf0e7e8a83 523
RobMeades 0:7ccf0e7e8a83 524 /** Receive data over a TCP socket.
RobMeades 0:7ccf0e7e8a83 525 *
RobMeades 0:7ccf0e7e8a83 526 * The socket must be connected to a remote host. Returns the number of
RobMeades 0:7ccf0e7e8a83 527 * bytes received into the buffer. This class sets no upper limit on the
RobMeades 0:7ccf0e7e8a83 528 * buffer size and the maximum packet size is not connected with the
RobMeades 0:7ccf0e7e8a83 529 * platform.buffered-serial-txbuf-size/platform.buffered-serial-rxbuf-size
RobMeades 0:7ccf0e7e8a83 530 * definitions.
RobMeades 0:7ccf0e7e8a83 531 *
RobMeades 0:7ccf0e7e8a83 532 * @param handle Socket handle.
RobMeades 0:7ccf0e7e8a83 533 * @param data Destination buffer for data received from the host.
RobMeades 0:7ccf0e7e8a83 534 * @param size Size of the buffer in bytes.
RobMeades 0:7ccf0e7e8a83 535 * @return Number of received bytes on success, negative error
RobMeades 0:7ccf0e7e8a83 536 * code on failure.
RobMeades 0:7ccf0e7e8a83 537 */
RobMeades 0:7ccf0e7e8a83 538 virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t handle,
RobMeades 0:7ccf0e7e8a83 539 void *data, nsapi_size_t size);
RobMeades 0:7ccf0e7e8a83 540
RobMeades 0:7ccf0e7e8a83 541 /** Receive a packet over a UDP socket.
RobMeades 0:7ccf0e7e8a83 542 *
RobMeades 0:7ccf0e7e8a83 543 * Receives data and stores the source address in address if address
RobMeades 0:7ccf0e7e8a83 544 * is not NULL. Returns the number of bytes received into the buffer.
RobMeades 0:7ccf0e7e8a83 545 *
RobMeades 0:7ccf0e7e8a83 546 * PACKET SIZES: the maximum packet size that can be retrieved in a
RobMeades 0:7ccf0e7e8a83 547 * single call to this method is limited by the configuration value
RobMeades 0:7ccf0e7e8a83 548 * platform.buffered-serial-rxbuf-size (default 256). The maximum
RobMeades 0:7ccf0e7e8a83 549 * UDP packet size is:
RobMeades 0:7ccf0e7e8a83 550 *
RobMeades 0:7ccf0e7e8a83 551 * platform.buffered-serial-rxbuf-size - AT_PACKET_OVERHEAD
RobMeades 0:7ccf0e7e8a83 552 *
RobMeades 0:7ccf0e7e8a83 553 * ...with a limit of 1024 (at the AT interface). So to allow reception of a
RobMeades 0:7ccf0e7e8a83 554 * 1024 byte UDP packet in a single call, edit your mbed_app.json to add a
RobMeades 0:7ccf0e7e8a83 555 * target override setting platform.buffered-serial-rxbuf-size to 1101.
RobMeades 0:7ccf0e7e8a83 556 *
RobMeades 0:7ccf0e7e8a83 557 * If the received packet is larger than this limit, any remainder will
RobMeades 0:7ccf0e7e8a83 558 * be returned in subsequent calls to this method. Once a single UDP
RobMeades 0:7ccf0e7e8a83 559 * packet has been received, this method will return.
RobMeades 0:7ccf0e7e8a83 560 *
RobMeades 0:7ccf0e7e8a83 561 * @param handle Socket handle.
RobMeades 0:7ccf0e7e8a83 562 * @param address Destination for the source address or NULL.
RobMeades 0:7ccf0e7e8a83 563 * @param data Destination buffer for data received from the host.
RobMeades 0:7ccf0e7e8a83 564 * @param size Size of the buffer in bytes.
RobMeades 0:7ccf0e7e8a83 565 * @return Number of received bytes on success, negative error
RobMeades 0:7ccf0e7e8a83 566 * code on failure.
RobMeades 0:7ccf0e7e8a83 567 */
RobMeades 0:7ccf0e7e8a83 568 virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle,
RobMeades 0:7ccf0e7e8a83 569 SocketAddress *address,
RobMeades 0:7ccf0e7e8a83 570 void *data, nsapi_size_t size);
RobMeades 0:7ccf0e7e8a83 571
RobMeades 0:7ccf0e7e8a83 572 /** Register a callback on state change of the socket.
RobMeades 0:7ccf0e7e8a83 573 *
RobMeades 0:7ccf0e7e8a83 574 * The specified callback will be called on state changes such as when
RobMeades 0:7ccf0e7e8a83 575 * the socket can recv/send/accept successfully and on when an error
RobMeades 0:7ccf0e7e8a83 576 * occurs. The callback may also be called spuriously without reason.
RobMeades 0:7ccf0e7e8a83 577 *
RobMeades 0:7ccf0e7e8a83 578 * The callback may be called in an interrupt context and should not
RobMeades 0:7ccf0e7e8a83 579 * perform expensive operations such as recv/send calls.
RobMeades 0:7ccf0e7e8a83 580 *
RobMeades 0:7ccf0e7e8a83 581 * @param handle Socket handle.
RobMeades 0:7ccf0e7e8a83 582 * @param callback Function to call on state change.
RobMeades 0:7ccf0e7e8a83 583 * @param data Argument to pass to callback.
RobMeades 0:7ccf0e7e8a83 584 */
RobMeades 0:7ccf0e7e8a83 585 virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *),
RobMeades 0:7ccf0e7e8a83 586 void *data);
RobMeades 0:7ccf0e7e8a83 587
RobMeades 0:7ccf0e7e8a83 588 /** Listen for connections on a TCP socket.
RobMeades 0:7ccf0e7e8a83 589 *
RobMeades 0:7ccf0e7e8a83 590 * Marks the socket as a passive socket that can be used to accept
RobMeades 0:7ccf0e7e8a83 591 * incoming connections.
RobMeades 0:7ccf0e7e8a83 592 *
RobMeades 0:7ccf0e7e8a83 593 * @param handle Socket handle.
RobMeades 0:7ccf0e7e8a83 594 * @param backlog Number of pending connections that can be queued
RobMeades 0:7ccf0e7e8a83 595 * simultaneously, defaults to 1.
RobMeades 0:7ccf0e7e8a83 596 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 597 */
RobMeades 0:7ccf0e7e8a83 598 virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog);
RobMeades 0:7ccf0e7e8a83 599
RobMeades 0:7ccf0e7e8a83 600 /** Accepts a connection on a TCP socket.
RobMeades 0:7ccf0e7e8a83 601 *
RobMeades 0:7ccf0e7e8a83 602 * The server socket must be bound and set to listen for connections.
RobMeades 0:7ccf0e7e8a83 603 * On a new connection, creates a network socket and stores it in the
RobMeades 0:7ccf0e7e8a83 604 * specified handle. The handle must be passed to following calls on
RobMeades 0:7ccf0e7e8a83 605 * the socket.
RobMeades 0:7ccf0e7e8a83 606 *
RobMeades 0:7ccf0e7e8a83 607 * A stack may have a finite number of sockets, in this case
RobMeades 0:7ccf0e7e8a83 608 * NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
RobMeades 0:7ccf0e7e8a83 609 *
RobMeades 0:7ccf0e7e8a83 610 * This call is non-blocking. If accept would block,
RobMeades 0:7ccf0e7e8a83 611 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
RobMeades 0:7ccf0e7e8a83 612 *
RobMeades 0:7ccf0e7e8a83 613 * @param server Socket handle to server to accept from.
RobMeades 0:7ccf0e7e8a83 614 * @param handle Destination for a handle to the newly created socket.
RobMeades 0:7ccf0e7e8a83 615 * @param address Destination for the remote address or NULL.
RobMeades 0:7ccf0e7e8a83 616 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 617 */
RobMeades 0:7ccf0e7e8a83 618 virtual nsapi_error_t socket_accept(nsapi_socket_t server,
RobMeades 0:7ccf0e7e8a83 619 nsapi_socket_t *handle,
RobMeades 0:7ccf0e7e8a83 620 SocketAddress *address = 0);
RobMeades 0:7ccf0e7e8a83 621
RobMeades 0:7ccf0e7e8a83 622 /** Set stack-specific socket options.
RobMeades 0:7ccf0e7e8a83 623 *
RobMeades 0:7ccf0e7e8a83 624 * The setsockopt allow an application to pass stack-specific hints
RobMeades 0:7ccf0e7e8a83 625 * to the underlying stack. For unsupported options,
RobMeades 0:7ccf0e7e8a83 626 * NSAPI_ERROR_UNSUPPORTED is returned and the socket is unmodified.
RobMeades 0:7ccf0e7e8a83 627 *
RobMeades 0:7ccf0e7e8a83 628 * @param handle Socket handle.
RobMeades 0:7ccf0e7e8a83 629 * @param level Stack-specific protocol level.
RobMeades 0:7ccf0e7e8a83 630 * @param optname Stack-specific option identifier.
RobMeades 0:7ccf0e7e8a83 631 * @param optval Option value.
RobMeades 0:7ccf0e7e8a83 632 * @param optlen Length of the option value.
RobMeades 0:7ccf0e7e8a83 633 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 634 */
RobMeades 0:7ccf0e7e8a83 635 virtual nsapi_error_t setsockopt(nsapi_socket_t handle, int level,
RobMeades 0:7ccf0e7e8a83 636 int optname, const void *optval,
RobMeades 0:7ccf0e7e8a83 637 unsigned optlen);
RobMeades 0:7ccf0e7e8a83 638
RobMeades 0:7ccf0e7e8a83 639 /** Get stack-specific socket options.
RobMeades 0:7ccf0e7e8a83 640 *
RobMeades 0:7ccf0e7e8a83 641 * The getstackopt allow an application to retrieve stack-specific hints
RobMeades 0:7ccf0e7e8a83 642 * from the underlying stack. For unsupported options,
RobMeades 0:7ccf0e7e8a83 643 * NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified.
RobMeades 0:7ccf0e7e8a83 644 *
RobMeades 0:7ccf0e7e8a83 645 * @param handle Socket handle.
RobMeades 0:7ccf0e7e8a83 646 * @param level Stack-specific protocol level.
RobMeades 0:7ccf0e7e8a83 647 * @param optname Stack-specific option identifier.
RobMeades 0:7ccf0e7e8a83 648 * @param optval Destination for option value.
RobMeades 0:7ccf0e7e8a83 649 * @param optlen Length of the option value.
RobMeades 0:7ccf0e7e8a83 650 * @return 0 on success, negative error code on failure.
RobMeades 0:7ccf0e7e8a83 651 */
RobMeades 0:7ccf0e7e8a83 652 virtual nsapi_error_t getsockopt(nsapi_socket_t handle, int level,
RobMeades 0:7ccf0e7e8a83 653 int optname, void *optval,
RobMeades 0:7ccf0e7e8a83 654 unsigned *optlen);
RobMeades 0:7ccf0e7e8a83 655
RobMeades 0:7ccf0e7e8a83 656 private:
RobMeades 0:7ccf0e7e8a83 657
RobMeades 0:7ccf0e7e8a83 658 // u_ added to namespace us somewhat as this darned macro
RobMeades 0:7ccf0e7e8a83 659 // is defined by everyone and their dog
RobMeades 0:7ccf0e7e8a83 660 #define u_stringify(a) str(a)
RobMeades 0:7ccf0e7e8a83 661 #define str(a) #a
RobMeades 0:7ccf0e7e8a83 662
RobMeades 0:7ccf0e7e8a83 663 bool _sim_pin_check_change_pending;
RobMeades 0:7ccf0e7e8a83 664 bool _sim_pin_check_change_pending_enabled_value;
RobMeades 0:7ccf0e7e8a83 665 bool _sim_pin_change_pending;
RobMeades 0:7ccf0e7e8a83 666 const char *_sim_pin_change_pending_new_pin_value;
RobMeades 0:7ccf0e7e8a83 667 Thread event_thread;
RobMeades 14:e7dcf3388403 668 volatile bool _run_event_thread;
RobMeades 0:7ccf0e7e8a83 669 void handle_event();
RobMeades 0:7ccf0e7e8a83 670 SockCtrl * find_socket(int modem_handle = SOCKET_UNUSED);
RobMeades 0:7ccf0e7e8a83 671 void clear_socket(SockCtrl * socket);
RobMeades 0:7ccf0e7e8a83 672 bool check_socket(SockCtrl * socket);
RobMeades 0:7ccf0e7e8a83 673 int nsapi_security_to_modem_security(nsapi_security_t nsapi_security);
RobMeades 0:7ccf0e7e8a83 674 Callback<void(nsapi_error_t)> _connection_status_cb;
RobMeades 0:7ccf0e7e8a83 675 void UUSORD_URC();
RobMeades 0:7ccf0e7e8a83 676 void UUSORF_URC();
RobMeades 0:7ccf0e7e8a83 677 void UUSOCL_URC();
RobMeades 0:7ccf0e7e8a83 678 void UUPSDD_URC();
RobMeades 0:7ccf0e7e8a83 679 };
RobMeades 0:7ccf0e7e8a83 680
rob.meades@u-blox.com 1:bc228becc45d 681 #endif // _UBLOX_AT_CELLULAR_INTERFACE_
RobMeades 0:7ccf0e7e8a83 682