MAXREFDES143#: DeepCover Embedded Security in IoT Authenticated Sensing & Notification
Dependencies: MaximInterface mbed
The MAXREFDES143# is an Internet of Things (IoT) embedded security reference design, built to protect an industrial sensing node by means of authentication and notification to a web server. The hardware includes a peripheral module representing a protected sensor node monitoring operating temperature and remaining life of a filter (simulated through ambient light sensing) and an mbed shield representing a controller node responsible for monitoring one or more sensor nodes. The design is hierarchical with each controller node communicating data from connected sensor nodes to a web server that maintains a centralized log and dispatches notifications as necessary. The mbed shield contains a Wi-Fi module, a DS2465 coprocessor with 1-Wire® master function, an LCD, LEDs, and pushbuttons. The protected sensor node contains a DS28E15 authenticator, a DS7505 temperature sensor, and a MAX44009 light sensor. The mbed shield communicates to a web server by the onboard Wi-Fi module and to the protected sensor node with I2C and 1-Wire. The MAXREFDES143# is equipped with a standard shield connector for immediate testing using an mbed board such as the MAX32600MBED#. The simplicity of this design enables rapid integration into any star-topology IoT network requiring the heightened security with low overhead provided by the SHA-256 symmetric-key algorithm.
More information about the MAXREFDES143# is available on the Maxim Integrated website.
esp8266-driver/ESP8266Interface.h@28:e5cdaf13d299, 2017-01-26 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Thu Jan 26 14:18:21 2017 -0600
- Revision:
- 28:e5cdaf13d299
Migrated the web interface to the mbed 5 networking stack to improve system compatibility.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| IanBenzMaxim | 28:e5cdaf13d299 | 1 | /* ESP8266 implementation of NetworkInterfaceAPI |
| IanBenzMaxim | 28:e5cdaf13d299 | 2 | * Copyright (c) 2015 ARM Limited |
| IanBenzMaxim | 28:e5cdaf13d299 | 3 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| IanBenzMaxim | 28:e5cdaf13d299 | 5 | * you may not use this file except in compliance with the License. |
| IanBenzMaxim | 28:e5cdaf13d299 | 6 | * You may obtain a copy of the License at |
| IanBenzMaxim | 28:e5cdaf13d299 | 7 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| IanBenzMaxim | 28:e5cdaf13d299 | 9 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 10 | * Unless required by applicable law or agreed to in writing, software |
| IanBenzMaxim | 28:e5cdaf13d299 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| IanBenzMaxim | 28:e5cdaf13d299 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| IanBenzMaxim | 28:e5cdaf13d299 | 13 | * See the License for the specific language governing permissions and |
| IanBenzMaxim | 28:e5cdaf13d299 | 14 | * limitations under the License. |
| IanBenzMaxim | 28:e5cdaf13d299 | 15 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 16 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 17 | #ifndef ESP8266_INTERFACE_H |
| IanBenzMaxim | 28:e5cdaf13d299 | 18 | #define ESP8266_INTERFACE_H |
| IanBenzMaxim | 28:e5cdaf13d299 | 19 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 20 | #include "mbed.h" |
| IanBenzMaxim | 28:e5cdaf13d299 | 21 | #include "ESP8266.h" |
| IanBenzMaxim | 28:e5cdaf13d299 | 22 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 23 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 24 | #define ESP8266_SOCKET_COUNT 5 |
| IanBenzMaxim | 28:e5cdaf13d299 | 25 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 26 | /** ESP8266Interface class |
| IanBenzMaxim | 28:e5cdaf13d299 | 27 | * Implementation of the NetworkStack for the ESP8266 |
| IanBenzMaxim | 28:e5cdaf13d299 | 28 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 29 | class ESP8266Interface : public NetworkStack, public WiFiInterface |
| IanBenzMaxim | 28:e5cdaf13d299 | 30 | { |
| IanBenzMaxim | 28:e5cdaf13d299 | 31 | public: |
| IanBenzMaxim | 28:e5cdaf13d299 | 32 | /** ESP8266Interface lifetime |
| IanBenzMaxim | 28:e5cdaf13d299 | 33 | * @param tx TX pin |
| IanBenzMaxim | 28:e5cdaf13d299 | 34 | * @param rx RX pin |
| IanBenzMaxim | 28:e5cdaf13d299 | 35 | * @param debug Enable debugging |
| IanBenzMaxim | 28:e5cdaf13d299 | 36 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 37 | ESP8266Interface(PinName tx, PinName rx, bool debug = false); |
| IanBenzMaxim | 28:e5cdaf13d299 | 38 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 39 | /** Start the interface |
| IanBenzMaxim | 28:e5cdaf13d299 | 40 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 41 | * Attempts to connect to a WiFi network. Requires ssid and passphrase to be set. |
| IanBenzMaxim | 28:e5cdaf13d299 | 42 | * If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned. |
| IanBenzMaxim | 28:e5cdaf13d299 | 43 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 44 | * @return 0 on success, negative error code on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 45 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 46 | virtual int connect(); |
| IanBenzMaxim | 28:e5cdaf13d299 | 47 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 48 | /** Start the interface |
| IanBenzMaxim | 28:e5cdaf13d299 | 49 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 50 | * Attempts to connect to a WiFi network. |
| IanBenzMaxim | 28:e5cdaf13d299 | 51 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 52 | * @param ssid Name of the network to connect to |
| IanBenzMaxim | 28:e5cdaf13d299 | 53 | * @param pass Security passphrase to connect to the network |
| IanBenzMaxim | 28:e5cdaf13d299 | 54 | * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE) |
| IanBenzMaxim | 28:e5cdaf13d299 | 55 | * @param channel This parameter is not supported, setting it to anything else than 0 will result in NSAPI_ERROR_UNSUPPORTED |
| IanBenzMaxim | 28:e5cdaf13d299 | 56 | * @return 0 on success, or error code on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 57 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 58 | virtual int connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE, |
| IanBenzMaxim | 28:e5cdaf13d299 | 59 | uint8_t channel = 0); |
| IanBenzMaxim | 28:e5cdaf13d299 | 60 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 61 | /** Set the WiFi network credentials |
| IanBenzMaxim | 28:e5cdaf13d299 | 62 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 63 | * @param ssid Name of the network to connect to |
| IanBenzMaxim | 28:e5cdaf13d299 | 64 | * @param pass Security passphrase to connect to the network |
| IanBenzMaxim | 28:e5cdaf13d299 | 65 | * @param security Type of encryption for connection |
| IanBenzMaxim | 28:e5cdaf13d299 | 66 | * (defaults to NSAPI_SECURITY_NONE) |
| IanBenzMaxim | 28:e5cdaf13d299 | 67 | * @return 0 on success, or error code on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 68 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 69 | virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE); |
| IanBenzMaxim | 28:e5cdaf13d299 | 70 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 71 | /** Set the WiFi network channel - NOT SUPPORTED |
| IanBenzMaxim | 28:e5cdaf13d299 | 72 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 73 | * This function is not supported and will return NSAPI_ERROR_UNSUPPORTED |
| IanBenzMaxim | 28:e5cdaf13d299 | 74 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 75 | * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0) |
| IanBenzMaxim | 28:e5cdaf13d299 | 76 | * @return Not supported, returns NSAPI_ERROR_UNSUPPORTED |
| IanBenzMaxim | 28:e5cdaf13d299 | 77 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 78 | virtual int set_channel(uint8_t channel); |
| IanBenzMaxim | 28:e5cdaf13d299 | 79 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 80 | /** Stop the interface |
| IanBenzMaxim | 28:e5cdaf13d299 | 81 | * @return 0 on success, negative on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 82 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 83 | virtual int disconnect(); |
| IanBenzMaxim | 28:e5cdaf13d299 | 84 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 85 | /** Get the internally stored IP address |
| IanBenzMaxim | 28:e5cdaf13d299 | 86 | * @return IP address of the interface or null if not yet connected |
| IanBenzMaxim | 28:e5cdaf13d299 | 87 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 88 | virtual const char *get_ip_address(); |
| IanBenzMaxim | 28:e5cdaf13d299 | 89 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 90 | /** Get the internally stored MAC address |
| IanBenzMaxim | 28:e5cdaf13d299 | 91 | * @return MAC address of the interface |
| IanBenzMaxim | 28:e5cdaf13d299 | 92 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 93 | virtual const char *get_mac_address(); |
| IanBenzMaxim | 28:e5cdaf13d299 | 94 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 95 | /** Get the local gateway |
| IanBenzMaxim | 28:e5cdaf13d299 | 96 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 97 | * @return Null-terminated representation of the local gateway |
| IanBenzMaxim | 28:e5cdaf13d299 | 98 | * or null if no network mask has been recieved |
| IanBenzMaxim | 28:e5cdaf13d299 | 99 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 100 | virtual const char *get_gateway(); |
| IanBenzMaxim | 28:e5cdaf13d299 | 101 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 102 | /** Get the local network mask |
| IanBenzMaxim | 28:e5cdaf13d299 | 103 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 104 | * @return Null-terminated representation of the local network mask |
| IanBenzMaxim | 28:e5cdaf13d299 | 105 | * or null if no network mask has been recieved |
| IanBenzMaxim | 28:e5cdaf13d299 | 106 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 107 | virtual const char *get_netmask(); |
| IanBenzMaxim | 28:e5cdaf13d299 | 108 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 109 | /** Gets the current radio signal strength for active connection |
| IanBenzMaxim | 28:e5cdaf13d299 | 110 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 111 | * @return Connection strength in dBm (negative value) |
| IanBenzMaxim | 28:e5cdaf13d299 | 112 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 113 | virtual int8_t get_rssi(); |
| IanBenzMaxim | 28:e5cdaf13d299 | 114 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 115 | /** Scan for available networks |
| IanBenzMaxim | 28:e5cdaf13d299 | 116 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 117 | * This function will block. |
| IanBenzMaxim | 28:e5cdaf13d299 | 118 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 119 | * @param ap Pointer to allocated array to store discovered AP |
| IanBenzMaxim | 28:e5cdaf13d299 | 120 | * @param count Size of allocated @a res array, or 0 to only count available AP |
| IanBenzMaxim | 28:e5cdaf13d299 | 121 | * @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0) |
| IanBenzMaxim | 28:e5cdaf13d299 | 122 | * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error |
| IanBenzMaxim | 28:e5cdaf13d299 | 123 | * see @a nsapi_error |
| IanBenzMaxim | 28:e5cdaf13d299 | 124 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 125 | virtual int scan(WiFiAccessPoint *res, unsigned count); |
| IanBenzMaxim | 28:e5cdaf13d299 | 126 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 127 | /** Translates a hostname to an IP address with specific version |
| IanBenzMaxim | 28:e5cdaf13d299 | 128 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 129 | * The hostname may be either a domain name or an IP address. If the |
| IanBenzMaxim | 28:e5cdaf13d299 | 130 | * hostname is an IP address, no network transactions will be performed. |
| IanBenzMaxim | 28:e5cdaf13d299 | 131 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 132 | * If no stack-specific DNS resolution is provided, the hostname |
| IanBenzMaxim | 28:e5cdaf13d299 | 133 | * will be resolve using a UDP socket on the stack. |
| IanBenzMaxim | 28:e5cdaf13d299 | 134 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 135 | * @param address Destination for the host SocketAddress |
| IanBenzMaxim | 28:e5cdaf13d299 | 136 | * @param host Hostname to resolve |
| IanBenzMaxim | 28:e5cdaf13d299 | 137 | * @param version IP version of address to resolve, NSAPI_UNSPEC indicates |
| IanBenzMaxim | 28:e5cdaf13d299 | 138 | * version is chosen by the stack (defaults to NSAPI_UNSPEC) |
| IanBenzMaxim | 28:e5cdaf13d299 | 139 | * @return 0 on success, negative error code on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 140 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 141 | using NetworkInterface::gethostbyname; |
| IanBenzMaxim | 28:e5cdaf13d299 | 142 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 143 | /** Add a domain name server to list of servers to query |
| IanBenzMaxim | 28:e5cdaf13d299 | 144 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 145 | * @param addr Destination for the host address |
| IanBenzMaxim | 28:e5cdaf13d299 | 146 | * @return 0 on success, negative error code on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 147 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 148 | using NetworkInterface::add_dns_server; |
| IanBenzMaxim | 28:e5cdaf13d299 | 149 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 150 | protected: |
| IanBenzMaxim | 28:e5cdaf13d299 | 151 | /** Open a socket |
| IanBenzMaxim | 28:e5cdaf13d299 | 152 | * @param handle Handle in which to store new socket |
| IanBenzMaxim | 28:e5cdaf13d299 | 153 | * @param proto Type of socket to open, NSAPI_TCP or NSAPI_UDP |
| IanBenzMaxim | 28:e5cdaf13d299 | 154 | * @return 0 on success, negative on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 155 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 156 | virtual int socket_open(void **handle, nsapi_protocol_t proto); |
| IanBenzMaxim | 28:e5cdaf13d299 | 157 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 158 | /** Close the socket |
| IanBenzMaxim | 28:e5cdaf13d299 | 159 | * @param handle Socket handle |
| IanBenzMaxim | 28:e5cdaf13d299 | 160 | * @return 0 on success, negative on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 161 | * @note On failure, any memory associated with the socket must still |
| IanBenzMaxim | 28:e5cdaf13d299 | 162 | * be cleaned up |
| IanBenzMaxim | 28:e5cdaf13d299 | 163 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 164 | virtual int socket_close(void *handle); |
| IanBenzMaxim | 28:e5cdaf13d299 | 165 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 166 | /** Bind a server socket to a specific port |
| IanBenzMaxim | 28:e5cdaf13d299 | 167 | * @param handle Socket handle |
| IanBenzMaxim | 28:e5cdaf13d299 | 168 | * @param address Local address to listen for incoming connections on |
| IanBenzMaxim | 28:e5cdaf13d299 | 169 | * @return 0 on success, negative on failure. |
| IanBenzMaxim | 28:e5cdaf13d299 | 170 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 171 | virtual int socket_bind(void *handle, const SocketAddress &address); |
| IanBenzMaxim | 28:e5cdaf13d299 | 172 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 173 | /** Start listening for incoming connections |
| IanBenzMaxim | 28:e5cdaf13d299 | 174 | * @param handle Socket handle |
| IanBenzMaxim | 28:e5cdaf13d299 | 175 | * @param backlog Number of pending connections that can be queued up at any |
| IanBenzMaxim | 28:e5cdaf13d299 | 176 | * one time [Default: 1] |
| IanBenzMaxim | 28:e5cdaf13d299 | 177 | * @return 0 on success, negative on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 178 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 179 | virtual int socket_listen(void *handle, int backlog); |
| IanBenzMaxim | 28:e5cdaf13d299 | 180 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 181 | /** Connects this TCP socket to the server |
| IanBenzMaxim | 28:e5cdaf13d299 | 182 | * @param handle Socket handle |
| IanBenzMaxim | 28:e5cdaf13d299 | 183 | * @param address SocketAddress to connect to |
| IanBenzMaxim | 28:e5cdaf13d299 | 184 | * @return 0 on success, negative on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 185 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 186 | virtual int socket_connect(void *handle, const SocketAddress &address); |
| IanBenzMaxim | 28:e5cdaf13d299 | 187 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 188 | /** Accept a new connection. |
| IanBenzMaxim | 28:e5cdaf13d299 | 189 | * @param handle Handle in which to store new socket |
| IanBenzMaxim | 28:e5cdaf13d299 | 190 | * @param server Socket handle to server to accept from |
| IanBenzMaxim | 28:e5cdaf13d299 | 191 | * @return 0 on success, negative on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 192 | * @note This call is not-blocking, if this call would block, must |
| IanBenzMaxim | 28:e5cdaf13d299 | 193 | * immediately return NSAPI_ERROR_WOULD_WAIT |
| IanBenzMaxim | 28:e5cdaf13d299 | 194 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 195 | virtual int socket_accept(void *handle, void **socket, SocketAddress *address); |
| IanBenzMaxim | 28:e5cdaf13d299 | 196 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 197 | /** Send data to the remote host |
| IanBenzMaxim | 28:e5cdaf13d299 | 198 | * @param handle Socket handle |
| IanBenzMaxim | 28:e5cdaf13d299 | 199 | * @param data The buffer to send to the host |
| IanBenzMaxim | 28:e5cdaf13d299 | 200 | * @param size The length of the buffer to send |
| IanBenzMaxim | 28:e5cdaf13d299 | 201 | * @return Number of written bytes on success, negative on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 202 | * @note This call is not-blocking, if this call would block, must |
| IanBenzMaxim | 28:e5cdaf13d299 | 203 | * immediately return NSAPI_ERROR_WOULD_WAIT |
| IanBenzMaxim | 28:e5cdaf13d299 | 204 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 205 | virtual int socket_send(void *handle, const void *data, unsigned size); |
| IanBenzMaxim | 28:e5cdaf13d299 | 206 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 207 | /** Receive data from the remote host |
| IanBenzMaxim | 28:e5cdaf13d299 | 208 | * @param handle Socket handle |
| IanBenzMaxim | 28:e5cdaf13d299 | 209 | * @param data The buffer in which to store the data received from the host |
| IanBenzMaxim | 28:e5cdaf13d299 | 210 | * @param size The maximum length of the buffer |
| IanBenzMaxim | 28:e5cdaf13d299 | 211 | * @return Number of received bytes on success, negative on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 212 | * @note This call is not-blocking, if this call would block, must |
| IanBenzMaxim | 28:e5cdaf13d299 | 213 | * immediately return NSAPI_ERROR_WOULD_WAIT |
| IanBenzMaxim | 28:e5cdaf13d299 | 214 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 215 | virtual int socket_recv(void *handle, void *data, unsigned size); |
| IanBenzMaxim | 28:e5cdaf13d299 | 216 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 217 | /** Send a packet to a remote endpoint |
| IanBenzMaxim | 28:e5cdaf13d299 | 218 | * @param handle Socket handle |
| IanBenzMaxim | 28:e5cdaf13d299 | 219 | * @param address The remote SocketAddress |
| IanBenzMaxim | 28:e5cdaf13d299 | 220 | * @param data The packet to be sent |
| IanBenzMaxim | 28:e5cdaf13d299 | 221 | * @param size The length of the packet to be sent |
| IanBenzMaxim | 28:e5cdaf13d299 | 222 | * @return The number of written bytes on success, negative on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 223 | * @note This call is not-blocking, if this call would block, must |
| IanBenzMaxim | 28:e5cdaf13d299 | 224 | * immediately return NSAPI_ERROR_WOULD_WAIT |
| IanBenzMaxim | 28:e5cdaf13d299 | 225 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 226 | virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size); |
| IanBenzMaxim | 28:e5cdaf13d299 | 227 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 228 | /** Receive a packet from a remote endpoint |
| IanBenzMaxim | 28:e5cdaf13d299 | 229 | * @param handle Socket handle |
| IanBenzMaxim | 28:e5cdaf13d299 | 230 | * @param address Destination for the remote SocketAddress or null |
| IanBenzMaxim | 28:e5cdaf13d299 | 231 | * @param buffer The buffer for storing the incoming packet data |
| IanBenzMaxim | 28:e5cdaf13d299 | 232 | * If a packet is too long to fit in the supplied buffer, |
| IanBenzMaxim | 28:e5cdaf13d299 | 233 | * excess bytes are discarded |
| IanBenzMaxim | 28:e5cdaf13d299 | 234 | * @param size The length of the buffer |
| IanBenzMaxim | 28:e5cdaf13d299 | 235 | * @return The number of received bytes on success, negative on failure |
| IanBenzMaxim | 28:e5cdaf13d299 | 236 | * @note This call is not-blocking, if this call would block, must |
| IanBenzMaxim | 28:e5cdaf13d299 | 237 | * immediately return NSAPI_ERROR_WOULD_WAIT |
| IanBenzMaxim | 28:e5cdaf13d299 | 238 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 239 | virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size); |
| IanBenzMaxim | 28:e5cdaf13d299 | 240 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 241 | /** Register a callback on state change of the socket |
| IanBenzMaxim | 28:e5cdaf13d299 | 242 | * @param handle Socket handle |
| IanBenzMaxim | 28:e5cdaf13d299 | 243 | * @param callback Function to call on state change |
| IanBenzMaxim | 28:e5cdaf13d299 | 244 | * @param data Argument to pass to callback |
| IanBenzMaxim | 28:e5cdaf13d299 | 245 | * @note Callback may be called in an interrupt context. |
| IanBenzMaxim | 28:e5cdaf13d299 | 246 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 247 | virtual void socket_attach(void *handle, void (*callback)(void *), void *data); |
| IanBenzMaxim | 28:e5cdaf13d299 | 248 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 249 | /** Provide access to the NetworkStack object |
| IanBenzMaxim | 28:e5cdaf13d299 | 250 | * |
| IanBenzMaxim | 28:e5cdaf13d299 | 251 | * @return The underlying NetworkStack object |
| IanBenzMaxim | 28:e5cdaf13d299 | 252 | */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 253 | virtual NetworkStack *get_stack() |
| IanBenzMaxim | 28:e5cdaf13d299 | 254 | { |
| IanBenzMaxim | 28:e5cdaf13d299 | 255 | return this; |
| IanBenzMaxim | 28:e5cdaf13d299 | 256 | } |
| IanBenzMaxim | 28:e5cdaf13d299 | 257 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 258 | private: |
| IanBenzMaxim | 28:e5cdaf13d299 | 259 | ESP8266 _esp; |
| IanBenzMaxim | 28:e5cdaf13d299 | 260 | bool _ids[ESP8266_SOCKET_COUNT]; |
| IanBenzMaxim | 28:e5cdaf13d299 | 261 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 262 | char ap_ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 263 | nsapi_security_t ap_sec; |
| IanBenzMaxim | 28:e5cdaf13d299 | 264 | uint8_t ap_ch; |
| IanBenzMaxim | 28:e5cdaf13d299 | 265 | char ap_pass[64]; /* The longest allowed passphrase */ |
| IanBenzMaxim | 28:e5cdaf13d299 | 266 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 267 | void event(); |
| IanBenzMaxim | 28:e5cdaf13d299 | 268 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 269 | struct { |
| IanBenzMaxim | 28:e5cdaf13d299 | 270 | void (*callback)(void *); |
| IanBenzMaxim | 28:e5cdaf13d299 | 271 | void *data; |
| IanBenzMaxim | 28:e5cdaf13d299 | 272 | } _cbs[ESP8266_SOCKET_COUNT]; |
| IanBenzMaxim | 28:e5cdaf13d299 | 273 | }; |
| IanBenzMaxim | 28:e5cdaf13d299 | 274 | |
| IanBenzMaxim | 28:e5cdaf13d299 | 275 | #endif |
MAXREFDES143#: DeepCover Embedded Security in IoT Authenticated Sensing & Notification