Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
This example is known to work great on the following platforms:
- WISE-1530 WiFi Module using DB-1505 carrier board and external SD card reader.
Example Functionality
This example showcases the following device functionality:
- On timer button increment, simulate Pelion LWM2M button resource change
Use this example with Mbed CLI
1. Import the application into your desktop:
mbed import https://os.mbed.com/teams/Advantech/code/pelion-example-common cd pelion-example-common
2. Download your developer certificate from pelion portal
3. Compile the program
mbed compile -t <toolchain> -m <TARGET_BOARD>
(supported toolchains : GCC_ARM / ARM / IAR)
4. Copy the binary file pelion-example-common.bin to your mbed device.
drivers/network/COMPONENT_WIFI_ISM43362/ISM43362Interface.h@0:43ff9e3bc244, 2019-03-12 (annotated)
- Committer:
- chuanga
- Date:
- Tue Mar 12 13:48:39 2019 +0800
- Revision:
- 0:43ff9e3bc244
copying sources from github repository
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| chuanga | 0:43ff9e3bc244 | 1 | /* ISM43362 implementation of NetworkInterfaceAPI |
| chuanga | 0:43ff9e3bc244 | 2 | * Copyright (c) STMicroelectronics 2017 |
| chuanga | 0:43ff9e3bc244 | 3 | * |
| chuanga | 0:43ff9e3bc244 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| chuanga | 0:43ff9e3bc244 | 5 | * you may not use this file except in compliance with the License. |
| chuanga | 0:43ff9e3bc244 | 6 | * You may obtain a copy of the License at |
| chuanga | 0:43ff9e3bc244 | 7 | * |
| chuanga | 0:43ff9e3bc244 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| chuanga | 0:43ff9e3bc244 | 9 | * |
| chuanga | 0:43ff9e3bc244 | 10 | * Unless required by applicable law or agreed to in writing, software |
| chuanga | 0:43ff9e3bc244 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| chuanga | 0:43ff9e3bc244 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| chuanga | 0:43ff9e3bc244 | 13 | * See the License for the specific language governing permissions and |
| chuanga | 0:43ff9e3bc244 | 14 | * limitations under the License. |
| chuanga | 0:43ff9e3bc244 | 15 | */ |
| chuanga | 0:43ff9e3bc244 | 16 | |
| chuanga | 0:43ff9e3bc244 | 17 | #ifndef ISM43362_INTERFACE_H |
| chuanga | 0:43ff9e3bc244 | 18 | #define ISM43362_INTERFACE_H |
| chuanga | 0:43ff9e3bc244 | 19 | |
| chuanga | 0:43ff9e3bc244 | 20 | #include "mbed.h" |
| chuanga | 0:43ff9e3bc244 | 21 | #include "ISM43362.h" |
| chuanga | 0:43ff9e3bc244 | 22 | |
| chuanga | 0:43ff9e3bc244 | 23 | |
| chuanga | 0:43ff9e3bc244 | 24 | #define ISM43362_SOCKET_COUNT 4 |
| chuanga | 0:43ff9e3bc244 | 25 | |
| chuanga | 0:43ff9e3bc244 | 26 | /** ISM43362Interface class |
| chuanga | 0:43ff9e3bc244 | 27 | * Implementation of the NetworkStack for the ISM43362 |
| chuanga | 0:43ff9e3bc244 | 28 | */ |
| chuanga | 0:43ff9e3bc244 | 29 | class ISM43362Interface : public NetworkStack, public WiFiInterface |
| chuanga | 0:43ff9e3bc244 | 30 | { |
| chuanga | 0:43ff9e3bc244 | 31 | public: |
| chuanga | 0:43ff9e3bc244 | 32 | /** ISM43362Interface lifetime |
| chuanga | 0:43ff9e3bc244 | 33 | * @param debug Enable debugging |
| chuanga | 0:43ff9e3bc244 | 34 | */ |
| chuanga | 0:43ff9e3bc244 | 35 | ISM43362Interface(bool debug = MBED_CONF_ISM43362_WIFI_DEBUG); |
| chuanga | 0:43ff9e3bc244 | 36 | |
| chuanga | 0:43ff9e3bc244 | 37 | /** Start the interface |
| chuanga | 0:43ff9e3bc244 | 38 | * |
| chuanga | 0:43ff9e3bc244 | 39 | * Attempts to connect to a WiFi network. Requires ssid and passphrase to be set. |
| chuanga | 0:43ff9e3bc244 | 40 | * If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned. |
| chuanga | 0:43ff9e3bc244 | 41 | * |
| chuanga | 0:43ff9e3bc244 | 42 | * @return 0 on success, negative error code on failure |
| chuanga | 0:43ff9e3bc244 | 43 | */ |
| chuanga | 0:43ff9e3bc244 | 44 | virtual nsapi_error_t connect(); |
| chuanga | 0:43ff9e3bc244 | 45 | |
| chuanga | 0:43ff9e3bc244 | 46 | /** Start the interface |
| chuanga | 0:43ff9e3bc244 | 47 | * |
| chuanga | 0:43ff9e3bc244 | 48 | * Attempts to connect to a WiFi network. |
| chuanga | 0:43ff9e3bc244 | 49 | * |
| chuanga | 0:43ff9e3bc244 | 50 | * @param ssid Name of the network to connect to |
| chuanga | 0:43ff9e3bc244 | 51 | * @param pass Security passphrase to connect to the network |
| chuanga | 0:43ff9e3bc244 | 52 | * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE) |
| chuanga | 0:43ff9e3bc244 | 53 | * @param channel This parameter is not supported, setting it to anything else than 0 will result in NSAPI_ERROR_UNSUPPORTED |
| chuanga | 0:43ff9e3bc244 | 54 | * @return 0 on success, or error code on failure |
| chuanga | 0:43ff9e3bc244 | 55 | */ |
| chuanga | 0:43ff9e3bc244 | 56 | virtual nsapi_error_t connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE, |
| chuanga | 0:43ff9e3bc244 | 57 | uint8_t channel = 0); |
| chuanga | 0:43ff9e3bc244 | 58 | |
| chuanga | 0:43ff9e3bc244 | 59 | /** Translates a hostname to an IP address with specific version |
| chuanga | 0:43ff9e3bc244 | 60 | * |
| chuanga | 0:43ff9e3bc244 | 61 | * The hostname may be either a domain name or an IP address. If the |
| chuanga | 0:43ff9e3bc244 | 62 | * hostname is an IP address, no network transactions will be performed. |
| chuanga | 0:43ff9e3bc244 | 63 | * |
| chuanga | 0:43ff9e3bc244 | 64 | * |
| chuanga | 0:43ff9e3bc244 | 65 | * @param host Hostname to resolve |
| chuanga | 0:43ff9e3bc244 | 66 | * @param address Destination for the host SocketAddress |
| chuanga | 0:43ff9e3bc244 | 67 | * @param version IP version of address to resolve, NSAPI_UNSPEC indicates |
| chuanga | 0:43ff9e3bc244 | 68 | * version is chosen by the stack (defaults to NSAPI_UNSPEC) |
| chuanga | 0:43ff9e3bc244 | 69 | * @return 0 on success, negative error code on failure |
| chuanga | 0:43ff9e3bc244 | 70 | */ |
| chuanga | 0:43ff9e3bc244 | 71 | virtual nsapi_error_t gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC); |
| chuanga | 0:43ff9e3bc244 | 72 | |
| chuanga | 0:43ff9e3bc244 | 73 | /** Set the WiFi network credentials |
| chuanga | 0:43ff9e3bc244 | 74 | * |
| chuanga | 0:43ff9e3bc244 | 75 | * @param ssid Name of the network to connect to |
| chuanga | 0:43ff9e3bc244 | 76 | * @param pass Security passphrase to connect to the network |
| chuanga | 0:43ff9e3bc244 | 77 | * @param security Type of encryption for connection |
| chuanga | 0:43ff9e3bc244 | 78 | * (defaults to NSAPI_SECURITY_NONE) |
| chuanga | 0:43ff9e3bc244 | 79 | * @return 0 on success, or error code on failure |
| chuanga | 0:43ff9e3bc244 | 80 | */ |
| chuanga | 0:43ff9e3bc244 | 81 | virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE); |
| chuanga | 0:43ff9e3bc244 | 82 | |
| chuanga | 0:43ff9e3bc244 | 83 | /** Set the WiFi network channel - NOT SUPPORTED |
| chuanga | 0:43ff9e3bc244 | 84 | * |
| chuanga | 0:43ff9e3bc244 | 85 | * This function is not supported and will return NSAPI_ERROR_UNSUPPORTED |
| chuanga | 0:43ff9e3bc244 | 86 | * |
| chuanga | 0:43ff9e3bc244 | 87 | * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0) |
| chuanga | 0:43ff9e3bc244 | 88 | * @return Not supported, returns NSAPI_ERROR_UNSUPPORTED |
| chuanga | 0:43ff9e3bc244 | 89 | */ |
| chuanga | 0:43ff9e3bc244 | 90 | virtual int set_channel(uint8_t channel); |
| chuanga | 0:43ff9e3bc244 | 91 | |
| chuanga | 0:43ff9e3bc244 | 92 | /** Stop the interface |
| chuanga | 0:43ff9e3bc244 | 93 | * @return 0 on success, negative on failure |
| chuanga | 0:43ff9e3bc244 | 94 | */ |
| chuanga | 0:43ff9e3bc244 | 95 | virtual nsapi_error_t disconnect(); |
| chuanga | 0:43ff9e3bc244 | 96 | |
| chuanga | 0:43ff9e3bc244 | 97 | /** Get the internally stored IP address |
| chuanga | 0:43ff9e3bc244 | 98 | * @return IP address of the interface or null if not yet connected |
| chuanga | 0:43ff9e3bc244 | 99 | */ |
| chuanga | 0:43ff9e3bc244 | 100 | virtual const char *get_ip_address(); |
| chuanga | 0:43ff9e3bc244 | 101 | |
| chuanga | 0:43ff9e3bc244 | 102 | /** Get the internally stored MAC address |
| chuanga | 0:43ff9e3bc244 | 103 | * @return MAC address of the interface |
| chuanga | 0:43ff9e3bc244 | 104 | */ |
| chuanga | 0:43ff9e3bc244 | 105 | virtual const char *get_mac_address(); |
| chuanga | 0:43ff9e3bc244 | 106 | |
| chuanga | 0:43ff9e3bc244 | 107 | /** Get the local gateway |
| chuanga | 0:43ff9e3bc244 | 108 | * |
| chuanga | 0:43ff9e3bc244 | 109 | * @return Null-terminated representation of the local gateway |
| chuanga | 0:43ff9e3bc244 | 110 | * or null if no network mask has been recieved |
| chuanga | 0:43ff9e3bc244 | 111 | */ |
| chuanga | 0:43ff9e3bc244 | 112 | virtual const char *get_gateway(); |
| chuanga | 0:43ff9e3bc244 | 113 | |
| chuanga | 0:43ff9e3bc244 | 114 | /** Get the local network mask |
| chuanga | 0:43ff9e3bc244 | 115 | * |
| chuanga | 0:43ff9e3bc244 | 116 | * @return Null-terminated representation of the local network mask |
| chuanga | 0:43ff9e3bc244 | 117 | * or null if no network mask has been recieved |
| chuanga | 0:43ff9e3bc244 | 118 | */ |
| chuanga | 0:43ff9e3bc244 | 119 | virtual const char *get_netmask(); |
| chuanga | 0:43ff9e3bc244 | 120 | |
| chuanga | 0:43ff9e3bc244 | 121 | /** Gets the current radio signal strength for active connection |
| chuanga | 0:43ff9e3bc244 | 122 | * |
| chuanga | 0:43ff9e3bc244 | 123 | * @return Connection strength in dBm (negative value) |
| chuanga | 0:43ff9e3bc244 | 124 | */ |
| chuanga | 0:43ff9e3bc244 | 125 | virtual int8_t get_rssi(); |
| chuanga | 0:43ff9e3bc244 | 126 | |
| chuanga | 0:43ff9e3bc244 | 127 | /** Scan for available networks |
| chuanga | 0:43ff9e3bc244 | 128 | * |
| chuanga | 0:43ff9e3bc244 | 129 | * This function will block. |
| chuanga | 0:43ff9e3bc244 | 130 | * |
| chuanga | 0:43ff9e3bc244 | 131 | * @param ap Pointer to allocated array to store discovered AP |
| chuanga | 0:43ff9e3bc244 | 132 | * @param count Size of allocated @a res array, or 0 to only count available AP |
| chuanga | 0:43ff9e3bc244 | 133 | * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error |
| chuanga | 0:43ff9e3bc244 | 134 | * see @a nsapi_error |
| chuanga | 0:43ff9e3bc244 | 135 | */ |
| chuanga | 0:43ff9e3bc244 | 136 | virtual int scan(WiFiAccessPoint *res, unsigned count); |
| chuanga | 0:43ff9e3bc244 | 137 | |
| chuanga | 0:43ff9e3bc244 | 138 | /** Translates a hostname to an IP address with specific version |
| chuanga | 0:43ff9e3bc244 | 139 | * |
| chuanga | 0:43ff9e3bc244 | 140 | * The hostname may be either a domain name or an IP address. If the |
| chuanga | 0:43ff9e3bc244 | 141 | * hostname is an IP address, no network transactions will be performed. |
| chuanga | 0:43ff9e3bc244 | 142 | * |
| chuanga | 0:43ff9e3bc244 | 143 | * If no stack-specific DNS resolution is provided, the hostname |
| chuanga | 0:43ff9e3bc244 | 144 | * will be resolve using a UDP socket on the stack. |
| chuanga | 0:43ff9e3bc244 | 145 | * |
| chuanga | 0:43ff9e3bc244 | 146 | * @param address Destination for the host SocketAddress |
| chuanga | 0:43ff9e3bc244 | 147 | * @param host Hostname to resolve |
| chuanga | 0:43ff9e3bc244 | 148 | * @param version IP version of address to resolve, NSAPI_UNSPEC indicates |
| chuanga | 0:43ff9e3bc244 | 149 | * version is chosen by the stack (defaults to NSAPI_UNSPEC) |
| chuanga | 0:43ff9e3bc244 | 150 | * @return 0 on success, negative error code on failure |
| chuanga | 0:43ff9e3bc244 | 151 | */ |
| chuanga | 0:43ff9e3bc244 | 152 | using NetworkInterface::gethostbyname; |
| chuanga | 0:43ff9e3bc244 | 153 | |
| chuanga | 0:43ff9e3bc244 | 154 | /** Add a domain name server to list of servers to query |
| chuanga | 0:43ff9e3bc244 | 155 | * |
| chuanga | 0:43ff9e3bc244 | 156 | * @param addr Destination for the host address |
| chuanga | 0:43ff9e3bc244 | 157 | * @return 0 on success, negative error code on failure |
| chuanga | 0:43ff9e3bc244 | 158 | */ |
| chuanga | 0:43ff9e3bc244 | 159 | using NetworkInterface::add_dns_server; |
| chuanga | 0:43ff9e3bc244 | 160 | |
| chuanga | 0:43ff9e3bc244 | 161 | /** Register callback for status reporting |
| chuanga | 0:43ff9e3bc244 | 162 | * |
| chuanga | 0:43ff9e3bc244 | 163 | * The specified status callback function will be called on status changes |
| chuanga | 0:43ff9e3bc244 | 164 | * on the network. The parameters on the callback are the event type and |
| chuanga | 0:43ff9e3bc244 | 165 | * event-type dependent reason parameter. |
| chuanga | 0:43ff9e3bc244 | 166 | * |
| chuanga | 0:43ff9e3bc244 | 167 | * @param status_cb The callback for status changes |
| chuanga | 0:43ff9e3bc244 | 168 | */ |
| chuanga | 0:43ff9e3bc244 | 169 | virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); |
| chuanga | 0:43ff9e3bc244 | 170 | |
| chuanga | 0:43ff9e3bc244 | 171 | /** Get the connection status |
| chuanga | 0:43ff9e3bc244 | 172 | * |
| chuanga | 0:43ff9e3bc244 | 173 | * @return The connection status according to ConnectionStatusType |
| chuanga | 0:43ff9e3bc244 | 174 | */ |
| chuanga | 0:43ff9e3bc244 | 175 | virtual nsapi_connection_status_t get_connection_status() const; |
| chuanga | 0:43ff9e3bc244 | 176 | |
| chuanga | 0:43ff9e3bc244 | 177 | protected: |
| chuanga | 0:43ff9e3bc244 | 178 | /** Open a socket |
| chuanga | 0:43ff9e3bc244 | 179 | * @param handle Handle in which to store new socket |
| chuanga | 0:43ff9e3bc244 | 180 | * @param proto Type of socket to open, NSAPI_TCP or NSAPI_UDP |
| chuanga | 0:43ff9e3bc244 | 181 | * @return 0 on success, negative on failure |
| chuanga | 0:43ff9e3bc244 | 182 | */ |
| chuanga | 0:43ff9e3bc244 | 183 | virtual int socket_open(void **handle, nsapi_protocol_t proto); |
| chuanga | 0:43ff9e3bc244 | 184 | |
| chuanga | 0:43ff9e3bc244 | 185 | /** Close the socket |
| chuanga | 0:43ff9e3bc244 | 186 | * @param handle Socket handle |
| chuanga | 0:43ff9e3bc244 | 187 | * @return 0 on success, negative on failure |
| chuanga | 0:43ff9e3bc244 | 188 | * @note On failure, any memory associated with the socket must still |
| chuanga | 0:43ff9e3bc244 | 189 | * be cleaned up |
| chuanga | 0:43ff9e3bc244 | 190 | */ |
| chuanga | 0:43ff9e3bc244 | 191 | virtual int socket_close(void *handle); |
| chuanga | 0:43ff9e3bc244 | 192 | |
| chuanga | 0:43ff9e3bc244 | 193 | /** Bind a server socket to a specific port |
| chuanga | 0:43ff9e3bc244 | 194 | * @param handle Socket handle |
| chuanga | 0:43ff9e3bc244 | 195 | * @param address Local address to listen for incoming connections on |
| chuanga | 0:43ff9e3bc244 | 196 | * @return 0 on success, negative on failure. |
| chuanga | 0:43ff9e3bc244 | 197 | */ |
| chuanga | 0:43ff9e3bc244 | 198 | virtual int socket_bind(void *handle, const SocketAddress &address); |
| chuanga | 0:43ff9e3bc244 | 199 | |
| chuanga | 0:43ff9e3bc244 | 200 | /** Start listening for incoming connections |
| chuanga | 0:43ff9e3bc244 | 201 | * @param handle Socket handle |
| chuanga | 0:43ff9e3bc244 | 202 | * @param backlog Number of pending connections that can be queued up at any |
| chuanga | 0:43ff9e3bc244 | 203 | * one time [Default: 1] |
| chuanga | 0:43ff9e3bc244 | 204 | * @return 0 on success, negative on failure |
| chuanga | 0:43ff9e3bc244 | 205 | */ |
| chuanga | 0:43ff9e3bc244 | 206 | virtual int socket_listen(void *handle, int backlog); |
| chuanga | 0:43ff9e3bc244 | 207 | |
| chuanga | 0:43ff9e3bc244 | 208 | /** Connects this TCP socket to the server |
| chuanga | 0:43ff9e3bc244 | 209 | * @param handle Socket handle |
| chuanga | 0:43ff9e3bc244 | 210 | * @param address SocketAddress to connect to |
| chuanga | 0:43ff9e3bc244 | 211 | * @return 0 on success, negative on failure |
| chuanga | 0:43ff9e3bc244 | 212 | */ |
| chuanga | 0:43ff9e3bc244 | 213 | virtual int socket_connect(void *handle, const SocketAddress &address); |
| chuanga | 0:43ff9e3bc244 | 214 | |
| chuanga | 0:43ff9e3bc244 | 215 | /** Accept a new connection. |
| chuanga | 0:43ff9e3bc244 | 216 | * @param handle Handle in which to store new socket |
| chuanga | 0:43ff9e3bc244 | 217 | * @param server Socket handle to server to accept from |
| chuanga | 0:43ff9e3bc244 | 218 | * @return 0 on success, negative on failure |
| chuanga | 0:43ff9e3bc244 | 219 | * @note This call is not-blocking, if this call would block, must |
| chuanga | 0:43ff9e3bc244 | 220 | * immediately return NSAPI_ERROR_WOULD_WAIT |
| chuanga | 0:43ff9e3bc244 | 221 | */ |
| chuanga | 0:43ff9e3bc244 | 222 | virtual int socket_accept(void *handle, void **socket, SocketAddress *address); |
| chuanga | 0:43ff9e3bc244 | 223 | |
| chuanga | 0:43ff9e3bc244 | 224 | /** Send data to the remote host |
| chuanga | 0:43ff9e3bc244 | 225 | * @param handle Socket handle |
| chuanga | 0:43ff9e3bc244 | 226 | * @param data The buffer to send to the host |
| chuanga | 0:43ff9e3bc244 | 227 | * @param size The length of the buffer to send |
| chuanga | 0:43ff9e3bc244 | 228 | * @return Number of written bytes on success, negative on failure |
| chuanga | 0:43ff9e3bc244 | 229 | * @note This call is not-blocking, if this call would block, must |
| chuanga | 0:43ff9e3bc244 | 230 | * immediately return NSAPI_ERROR_WOULD_WAIT |
| chuanga | 0:43ff9e3bc244 | 231 | */ |
| chuanga | 0:43ff9e3bc244 | 232 | virtual int socket_send(void *handle, const void *data, unsigned size); |
| chuanga | 0:43ff9e3bc244 | 233 | |
| chuanga | 0:43ff9e3bc244 | 234 | /** Receive data from the remote host |
| chuanga | 0:43ff9e3bc244 | 235 | * @param handle Socket handle |
| chuanga | 0:43ff9e3bc244 | 236 | * @param data The buffer in which to store the data received from the host |
| chuanga | 0:43ff9e3bc244 | 237 | * @param size The maximum length of the buffer |
| chuanga | 0:43ff9e3bc244 | 238 | * @return Number of received bytes on success, negative on failure |
| chuanga | 0:43ff9e3bc244 | 239 | * @note This call is not-blocking, if this call would block, must |
| chuanga | 0:43ff9e3bc244 | 240 | * immediately return NSAPI_ERROR_WOULD_WAIT |
| chuanga | 0:43ff9e3bc244 | 241 | */ |
| chuanga | 0:43ff9e3bc244 | 242 | virtual int socket_recv(void *handle, void *data, unsigned size); |
| chuanga | 0:43ff9e3bc244 | 243 | |
| chuanga | 0:43ff9e3bc244 | 244 | /** Send a packet to a remote endpoint |
| chuanga | 0:43ff9e3bc244 | 245 | * @param handle Socket handle |
| chuanga | 0:43ff9e3bc244 | 246 | * @param address The remote SocketAddress |
| chuanga | 0:43ff9e3bc244 | 247 | * @param data The packet to be sent |
| chuanga | 0:43ff9e3bc244 | 248 | * @param size The length of the packet to be sent |
| chuanga | 0:43ff9e3bc244 | 249 | * @return The number of written bytes on success, negative on failure |
| chuanga | 0:43ff9e3bc244 | 250 | * @note This call is not-blocking, if this call would block, must |
| chuanga | 0:43ff9e3bc244 | 251 | * immediately return NSAPI_ERROR_WOULD_WAIT |
| chuanga | 0:43ff9e3bc244 | 252 | */ |
| chuanga | 0:43ff9e3bc244 | 253 | virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size); |
| chuanga | 0:43ff9e3bc244 | 254 | |
| chuanga | 0:43ff9e3bc244 | 255 | /** Receive a packet from a remote endpoint |
| chuanga | 0:43ff9e3bc244 | 256 | * @param handle Socket handle |
| chuanga | 0:43ff9e3bc244 | 257 | * @param address Destination for the remote SocketAddress or null |
| chuanga | 0:43ff9e3bc244 | 258 | * @param buffer The buffer for storing the incoming packet data |
| chuanga | 0:43ff9e3bc244 | 259 | * If a packet is too long to fit in the supplied buffer, |
| chuanga | 0:43ff9e3bc244 | 260 | * excess bytes are discarded |
| chuanga | 0:43ff9e3bc244 | 261 | * @param size The length of the buffer |
| chuanga | 0:43ff9e3bc244 | 262 | * @return The number of received bytes on success, negative on failure |
| chuanga | 0:43ff9e3bc244 | 263 | * @note This call is not-blocking, if this call would block, must |
| chuanga | 0:43ff9e3bc244 | 264 | * immediately return NSAPI_ERROR_WOULD_WAIT |
| chuanga | 0:43ff9e3bc244 | 265 | */ |
| chuanga | 0:43ff9e3bc244 | 266 | virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size); |
| chuanga | 0:43ff9e3bc244 | 267 | |
| chuanga | 0:43ff9e3bc244 | 268 | /** Register a callback on state change of the socket |
| chuanga | 0:43ff9e3bc244 | 269 | * @param handle Socket handle |
| chuanga | 0:43ff9e3bc244 | 270 | * @param callback Function to call on state change |
| chuanga | 0:43ff9e3bc244 | 271 | * @param data Argument to pass to callback |
| chuanga | 0:43ff9e3bc244 | 272 | * @note Callback may be called in an interrupt context. |
| chuanga | 0:43ff9e3bc244 | 273 | */ |
| chuanga | 0:43ff9e3bc244 | 274 | virtual void socket_attach(void *handle, void (*callback)(void *), void *data); |
| chuanga | 0:43ff9e3bc244 | 275 | |
| chuanga | 0:43ff9e3bc244 | 276 | /** Provide access to the NetworkStack object |
| chuanga | 0:43ff9e3bc244 | 277 | * |
| chuanga | 0:43ff9e3bc244 | 278 | * @return The underlying NetworkStack object |
| chuanga | 0:43ff9e3bc244 | 279 | */ |
| chuanga | 0:43ff9e3bc244 | 280 | virtual NetworkStack *get_stack() |
| chuanga | 0:43ff9e3bc244 | 281 | { |
| chuanga | 0:43ff9e3bc244 | 282 | return this; |
| chuanga | 0:43ff9e3bc244 | 283 | } |
| chuanga | 0:43ff9e3bc244 | 284 | |
| chuanga | 0:43ff9e3bc244 | 285 | private: |
| chuanga | 0:43ff9e3bc244 | 286 | ISM43362 _ism; |
| chuanga | 0:43ff9e3bc244 | 287 | bool _ids[ISM43362_SOCKET_COUNT]; |
| chuanga | 0:43ff9e3bc244 | 288 | uint32_t _socket_obj[ISM43362_SOCKET_COUNT]; // store addresses of socket handles |
| chuanga | 0:43ff9e3bc244 | 289 | Mutex _mutex; |
| chuanga | 0:43ff9e3bc244 | 290 | Thread thread_read_socket; |
| chuanga | 0:43ff9e3bc244 | 291 | char ap_ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */ |
| chuanga | 0:43ff9e3bc244 | 292 | ism_security_t ap_sec; |
| chuanga | 0:43ff9e3bc244 | 293 | uint8_t ap_ch; |
| chuanga | 0:43ff9e3bc244 | 294 | char ap_pass[64]; /* The longest allowed passphrase */ |
| chuanga | 0:43ff9e3bc244 | 295 | nsapi_error_t _connect_status ; |
| chuanga | 0:43ff9e3bc244 | 296 | |
| chuanga | 0:43ff9e3bc244 | 297 | bool _ism_debug; |
| chuanga | 0:43ff9e3bc244 | 298 | uint32_t _FwVersion; |
| chuanga | 0:43ff9e3bc244 | 299 | |
| chuanga | 0:43ff9e3bc244 | 300 | void event(); |
| chuanga | 0:43ff9e3bc244 | 301 | struct { |
| chuanga | 0:43ff9e3bc244 | 302 | void (*callback)(void *); |
| chuanga | 0:43ff9e3bc244 | 303 | void *data; |
| chuanga | 0:43ff9e3bc244 | 304 | } _cbs[ISM43362_SOCKET_COUNT]; |
| chuanga | 0:43ff9e3bc244 | 305 | |
| chuanga | 0:43ff9e3bc244 | 306 | /** Function called by the socket read thread to check if data is available on the wifi module |
| chuanga | 0:43ff9e3bc244 | 307 | * |
| chuanga | 0:43ff9e3bc244 | 308 | */ |
| chuanga | 0:43ff9e3bc244 | 309 | virtual void socket_check_read(); |
| chuanga | 0:43ff9e3bc244 | 310 | int socket_send_nolock(void *handle, const void *data, unsigned size); |
| chuanga | 0:43ff9e3bc244 | 311 | int socket_connect_nolock(void *handle, const SocketAddress &addr); |
| chuanga | 0:43ff9e3bc244 | 312 | |
| chuanga | 0:43ff9e3bc244 | 313 | // Connection state reporting to application |
| chuanga | 0:43ff9e3bc244 | 314 | void update_conn_state_cb(); |
| chuanga | 0:43ff9e3bc244 | 315 | nsapi_connection_status_t _conn_stat; |
| chuanga | 0:43ff9e3bc244 | 316 | mbed::Callback<void(nsapi_event_t, intptr_t)> _conn_stat_cb; |
| chuanga | 0:43ff9e3bc244 | 317 | |
| chuanga | 0:43ff9e3bc244 | 318 | |
| chuanga | 0:43ff9e3bc244 | 319 | }; |
| chuanga | 0:43ff9e3bc244 | 320 | |
| chuanga | 0:43ff9e3bc244 | 321 | #endif |