]> begriffs open source - cmsis/blob - CMSIS/Driver/Include/Driver_WiFi.h
Updated WiFi Driver API 1.0.0-beta
[cmsis] / CMSIS / Driver / Include / Driver_WiFi.h
1 /*
2  * Copyright (c) 2019 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * $Date:        31. May 2019
19  * $Revision:    V1.0 (beta)
20  *
21  * Project:      WiFi (Wireless Fidelity Interface) Driver definitions
22  */
23
24 /* History:
25  *  Version 1.0 (beta)
26  *    Initial beta version
27  */
28
29 #ifndef DRIVER_WIFI_H_
30 #define DRIVER_WIFI_H_
31
32 #ifdef  __cplusplus
33 extern "C"
34 {
35 #endif
36
37 #include "Driver_Common.h"
38
39 #define ARM_WIFI_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,0)  /* API version */
40
41 #define _ARM_Driver_WiFi_(n)      Driver_WiFi##n
42 #define  ARM_Driver_WiFi_(n) _ARM_Driver_WiFi_(n)
43
44
45 /****** WiFi SetOption/GetOption Function Option Codes *****/
46 #define ARM_WIFI_BSSID                      1U          ///< Station/AP Set/Get BSSID of AP to connect or of AP;        data = &bssid,    len =  6, uint8_t[6]
47 #define ARM_WIFI_TX_POWER                   2U          ///< Station/AP Set/Get transmit power;                         data = &power,    len =  4, uint32_t: 0 .. 20 [dBm]
48 #define ARM_WIFI_LP_TIMER                   3U          ///< Station    Set/Get low-power deep-sleep time;              data = &time,     len =  4, uint32_t [seconds]: 0 = disable (default)
49 #define ARM_WIFI_DTIM                       4U          ///< Station/AP Set/Get DTIM interval;                          data = &dtim,     len =  4, uint32_t [beacons]
50 #define ARM_WIFI_BEACON                     5U          ///<         AP Set/Get beacon interval;                        data = &interval, len =  4, uint32_t [ms]
51 #define ARM_WIFI_MAC                        6U          ///< Station/AP Set/Get MAC;                                    data = &mac,      len =  6, uint8_t[6]
52 #define ARM_WIFI_IP                         7U          ///< Station/AP Set/Get IPv4 static/assigned address;           data = &ip,       len =  4, uint8_t[4]
53 #define ARM_WIFI_IP_SUBNET_MASK             8U          ///< Station/AP Set/Get IPv4 subnet mask;                       data = &mask,     len =  4, uint8_t[4]
54 #define ARM_WIFI_IP_GATEWAY                 9U          ///< Station/AP Set/Get IPv4 gateway address;                   data = &ip,       len =  4, uint8_t[4]
55 #define ARM_WIFI_IP_DNS1                    10U         ///< Station/AP Set/Get IPv4 primary   DNS address;             data = &ip,       len =  4, uint8_t[4]
56 #define ARM_WIFI_IP_DNS2                    11U         ///< Station/AP Set/Get IPv4 secondary DNS address;             data = &ip,       len =  4, uint8_t[4]
57 #define ARM_WIFI_IP_DHCP                    12U         ///< Station/AP Set/Get IPv4 DHCP client/server enable/disable; data = &dhcp,     len =  4, uint32_t: 0 = disable, non-zero = enable (default)
58 #define ARM_WIFI_IP_DHCP_POOL_BEGIN         13U         ///<         AP Set/Get IPv4 DHCP pool begin address;           data = &ip,       len =  4, uint8_t[4]
59 #define ARM_WIFI_IP_DHCP_POOL_END           14U         ///<         AP Set/Get IPv4 DHCP pool end address;             data = &ip,       len =  4, uint8_t[4]
60 #define ARM_WIFI_IP_DHCP_LEASE_TIME         15U         ///<         AP Set/Get IPv4 DHCP lease time;                   data = &time,     len =  4, uint32_t [seconds]
61 #define ARM_WIFI_IP6_GLOBAL                 16U         ///< Station/AP Set/Get IPv6 global address;                    data = &ip6,      len = 16, uint8_t[16]
62 #define ARM_WIFI_IP6_LINK_LOCAL             17U         ///< Station/AP Set/Get IPv6 link local address;                data = &ip6,      len = 16, uint8_t[16]
63 #define ARM_WIFI_IP6_SUBNET_PREFIX_LEN      18U         ///< Station/AP Set/Get IPv6 subnet prefix length;              data = &len,      len =  4, uint32_t: 1 .. 127
64 #define ARM_WIFI_IP6_GATEWAY                19U         ///< Station/AP Set/Get IPv6 gateway address;                   data = &ip6,      len = 16, uint8_t[16]
65 #define ARM_WIFI_IP6_DNS1                   20U         ///< Station/AP Set/Get IPv6 primary   DNS address;             data = &ip6,      len = 16, uint8_t[16]
66 #define ARM_WIFI_IP6_DNS2                   21U         ///< Station/AP Set/Get IPv6 secondary DNS address;             data = &ip6,      len = 16, uint8_t[16]
67 #define ARM_WIFI_IP6_DHCP_MODE              22U         ///< Station/AP Set/Get IPv6 DHCPv6 client mode;                data = &mode,     len =  4, uint32_t: ARM_WIFI_IP6_DHCP_xxx (default Off)
68
69 /****** WiFi Security Type *****/
70 #define ARM_WIFI_SECURITY_OPEN              0U          ///< Open
71 #define ARM_WIFI_SECURITY_WEP               1U          ///< Wired Equivalent Privacy (WEP) with Pre-Sheared Key (PSK)
72 #define ARM_WIFI_SECURITY_WPA               2U          ///< WiFi Protected Access (WPA) with PSK
73 #define ARM_WIFI_SECURITY_WPA2              3U          ///< WiFi Protected Access II (WPA2) with PSK
74 #define ARM_WIFI_SECURITY_UNKNOWN           255U        ///< Unknown
75
76 /****** WiFi Protected Setup (WPS) Method *****/
77 #define ARM_WIFI_WPS_METHOD_NONE            0U          ///< Not used
78 #define ARM_WIFI_WPS_METHOD_PBC             1U          ///< Push Button Configuration
79 #define ARM_WIFI_WPS_METHOD_PIN             2U          ///< PIN
80
81 /****** WiFi IPv6 Dynamic Host Configuration Protocol (DHCP) Mode *****/
82 #define ARM_WIFI_IP6_DHCP_OFF               0U          ///< Static Host Configuration (default)
83 #define ARM_WIFI_IP6_DHCP_STATELESS         1U          ///< Dynamic Host Configuration stateless DHCPv6
84 #define ARM_WIFI_IP6_DHCP_STATEFULL         2U          ///< Dynamic Host Configuration statefull DHCPv6
85
86 /****** WiFi Event *****/
87 #define ARM_WIFI_EVENT_AP_CONNECT          (1UL << 0)   ///< Access Point: Station has connected;           arg = &mac, mac (uint8_t[6])
88 #define ARM_WIFI_EVENT_AP_DISCONNECT       (1UL << 1)   ///< Access Point: Station has disconnected;        arg = &mac, mac (uint8_t[6])
89 #define ARM_WIFI_EVENT_ETH_RX_FRAME        (1UL << 4)   ///< Ethernet Frame Received (in bypass mode only); arg = interface (0 = Station, 1 = Access Point)
90
91
92 /**
93 \brief WiFi Configuration
94 */
95 typedef struct {
96   const char   *ssid;                                   ///< Pointer to Service Set Identifier (SSID) null-terminated string
97   const char   *pass;                                   ///< Pointer to Password null-terminated string
98         uint8_t security;                               ///< Security type (ARM_WIFI_SECURITY_xxx)
99         uint8_t ch;                                     ///< WiFi Channel (0 = auto, otherwise = exact channel)
100         uint8_t reserved;                               ///< Reserved
101         uint8_t wps_method;                             ///< WiFi Protected Setup (WPS) method (ARM_WIFI_WPS_METHOD_xxx)
102   const char   *wps_pin;                                ///< Pointer to WiFi Protected Setup (WPS) PIN null-terminated string
103 } ARM_WIFI_CONFIG_t;
104
105 /**
106 \brief WiFi Scan Information
107 */
108 typedef struct {
109   char    ssid[32+1];                                   ///< Service Set Identifier (SSID) null-terminated string
110   uint8_t bssid[6];                                     ///< Basic Service Set Identifier (BSSID)
111   uint8_t security;                                     ///< Security type (ARM_WIFI_SECURITY_xxx)
112   uint8_t ch;                                           ///< WiFi Channel
113   uint8_t rssi;                                         ///< Received Signal Strength Indicator
114 } ARM_WIFI_SCAN_INFO_t;
115
116 /**
117 \brief WiFi Network Information
118 */
119 typedef struct {
120   char    ssid[32+1];                                   ///< Service Set Identifier (SSID) null-terminated string
121   char    pass[64+1];                                   ///< Password null-terminated string
122   uint8_t security;                                     ///< Security type (ARM_WIFI_SECURITY_xxx)
123   uint8_t ch;                                           ///< WiFi Channel
124   uint8_t rssi;                                         ///< Received Signal Strength Indicator
125 } ARM_WIFI_NET_INFO_t;
126
127 /****** Socket Address Family definitions *****/
128 #define ARM_SOCKET_AF_INET                  1           ///< IPv4
129 #define ARM_SOCKET_AF_INET6                 2           ///< IPv6
130
131 /****** Socket Type definitions *****/
132 #define ARM_SOCKET_SOCK_STREAM              1           ///< Stream socket
133 #define ARM_SOCKET_SOCK_DGRAM               2           ///< Datagram socket
134
135 /****** Socket Protocol definitions *****/
136 #define ARM_SOCKET_IPPROTO_TCP              1           ///< TCP
137 #define ARM_SOCKET_IPPROTO_UDP              2           ///< UDP
138
139 /****** Socket Option definitions *****/
140 #define ARM_SOCKET_IO_FIONBIO               1           ///< Non-blocking I/O (Set only, default = 0); opt_val = &nbio, opt_len = sizeof(nbio), nbio (integer): 0=blocking, non-blocking otherwise
141 #define ARM_SOCKET_SO_RCVTIMEO              2           ///< Receive timeout in ms (default = 0); opt_val = &timeout, opt_len = sizeof(timeout)
142 #define ARM_SOCKET_SO_SNDTIMEO              3           ///< Send timeout in ms (default = 0); opt_val = &timeout, opt_len = sizeof(timeout)
143 #define ARM_SOCKET_SO_KEEPALIVE             4           ///< Keep-alive messages (default = 0); opt_val = &keepalive, opt_len = sizeof(keepalive), keepalive (integer): 0=disabled, enabled otherwise
144 #define ARM_SOCKET_SO_TYPE                  5           ///< Socket Type (Get only); opt_val = &socket_type, opt_len = sizeof(socket_type), socket_type (integer): ARM_SOCKET_SOCK_xxx
145
146 /****** Socket Function return codes *****/
147 #define ARM_SOCKET_ERROR                   (-1)         ///< Unspecified error
148 #define ARM_SOCKET_ESOCK                   (-2)         ///< Invalid socket
149 #define ARM_SOCKET_EINVAL                  (-3)         ///< Invalid argument
150 #define ARM_SOCKET_ENOTSUP                 (-4)         ///< Operation not supported
151 #define ARM_SOCKET_ENOMEM                  (-5)         ///< Not enough memory
152 #define ARM_SOCKET_EAGAIN                  (-6)         ///< Operation would block or timed out
153 #define ARM_SOCKET_EINPROGRESS             (-7)         ///< Operation in progress
154 #define ARM_SOCKET_ETIMEDOUT               (-8)         ///< Operation timed out
155 #define ARM_SOCKET_EISCONN                 (-9)         ///< Socket is connected
156 #define ARM_SOCKET_ENOTCONN                (-10)        ///< Socket is not connected
157 #define ARM_SOCKET_ECONNREFUSED            (-11)        ///< Connection rejected by the peer
158 #define ARM_SOCKET_ECONNRESET              (-12)        ///< Connection reset by the peer
159 #define ARM_SOCKET_ECONNABORTED            (-13)        ///< Connection aborted locally
160 #define ARM_SOCKET_EALREADY                (-14)        ///< Connection already in progress
161 #define ARM_SOCKET_EADDRINUSE              (-15)        ///< Address in use
162 #define ARM_SOCKET_EHOSTNOTFOUND           (-16)        ///< Host not found
163
164
165 // Function documentation
166 /**
167   \fn            ARM_DRIVER_VERSION ARM_WIFI_GetVersion (void)
168   \brief         Get driver version.
169   \return        \ref ARM_DRIVER_VERSION
170 */
171 /**
172   \fn            ARM_WIFI_CAPABILITIES ARM_WIFI_GetCapabilities (void)
173   \brief         Get driver capabilities.
174   \return        \ref ARM_WIFI_CAPABILITIES
175 */
176 /**
177   \fn            int32_t ARM_WIFI_Initialize (ARM_WIFI_SignalEvent_t cb_event)
178   \brief         Initialize WiFi Module.
179   \param[in]     cb_event Pointer to \ref ARM_WIFI_SignalEvent_t
180   \return        execution status
181                    - \ref ARM_DRIVER_OK                : Operation successful
182                    - \ref ARM_DRIVER_ERROR             : Operation failed
183 */
184 /**
185   \fn            int32_t ARM_WIFI_Uninitialize (void)
186   \brief         De-initialize WiFi Module.
187   \return        execution status
188                    - \ref ARM_DRIVER_OK                : Operation successful
189                    - \ref ARM_DRIVER_ERROR             : Operation failed
190 */
191 /**
192   \fn            int32_t ARM_WIFI_PowerControl (ARM_POWER_STATE state)
193   \brief         Control WiFi Module Power.
194   \param[in]     state     Power state
195                    - \ref ARM_POWER_OFF                : Power off: no operation possible
196                    - \ref ARM_POWER_LOW                : Low-power mode: sleep or deep-sleep depending on \ref ARM_WIFI_LP_TIMER option set
197                    - \ref ARM_POWER_FULL               : Power on: full operation at maximum performance
198   \return        execution status
199                    - \ref ARM_DRIVER_OK                : Operation successful
200                    - \ref ARM_DRIVER_ERROR             : Operation failed
201                    - \ref ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported
202                    - \ref ARM_DRIVER_ERROR_PARAMETER   : Parameter error (invalid state)
203 */
204 /**
205   \fn            int32_t ARM_WIFI_GetModuleInfo (char *module_info, uint32_t max_len)
206   \brief         Get Module information.
207   \param[out]    module_info Pointer to character buffer were info string will be returned
208   \param[in]     max_len     Maximum length of string to return (including null terminator)
209   \return        execution status
210                    - \ref ARM_DRIVER_OK                : Operation successful
211                    - \ref ARM_DRIVER_ERROR             : Operation failed
212                    - \ref ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported
213                    - \ref ARM_DRIVER_ERROR_PARAMETER   : Parameter error (NULL module_info pointer or max_len equals to 0)
214 */
215 /**
216   \fn            int32_t ARM_WIFI_SetOption (uint32_t interface, uint32_t option, const void *data, uint32_t len)
217   \brief         Set WiFi Module Options.
218   \param[in]     interface Interface (0 = Station, 1 = Access Point)
219   \param[in]     option    Option to set
220   \param[in]     data      Pointer to data relevant to selected option
221   \param[in]     len       Length of data (in bytes)
222   \return        execution status
223                    - \ref ARM_DRIVER_OK                : Operation successful
224                    - \ref ARM_DRIVER_ERROR             : Operation failed
225                    - \ref ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported
226                    - \ref ARM_DRIVER_ERROR_PARAMETER   : Parameter error (invalid interface, NULL data pointer or len less than option specifies)
227 */
228 /**
229   \fn            int32_t ARM_WIFI_GetOption (uint32_t interface, uint32_t option, void *data, uint32_t *len)
230   \brief         Get WiFi Module Options.
231   \param[in]     interface Interface (0 = Station, 1 = Access Point)
232   \param[in]     option    Option to get
233   \param[out]    data      Pointer to memory where data for selected option will be returned
234   \param[in,out] len       Pointer to length of data (input/output)
235                    - input: maximum length of data that can be returned (in bytes)
236                    - output: length of returned data (in bytes)
237   \return        execution status
238                    - \ref ARM_DRIVER_OK                : Operation successful
239                    - \ref ARM_DRIVER_ERROR             : Operation failed
240                    - \ref ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported
241                    - \ref ARM_DRIVER_ERROR_PARAMETER   : Parameter error (invalid interface, NULL data or len pointer, or *len less than option specifies)
242 */
243 /**
244   \fn            int32_t ARM_WIFI_Scan (ARM_WIFI_SCAN_INFO_t scan_info[], uint32_t max_num)
245   \brief         Scan for available networks in range.
246   \param[out]    scan_info Pointer to array of ARM_WIFI_SCAN_INFO_t structures where available Scan Information will be returned
247   \param[in]     max_num   Maximum number of Network Information structures to return
248   \return        number of ARM_WIFI_SCAN_INFO_t structures returned or error code
249                    - value >= 0                        : Number of ARM_WIFI_SCAN_INFO_t structures returned
250                    - \ref ARM_DRIVER_ERROR             : Operation failed
251                    - \ref ARM_DRIVER_ERROR_PARAMETER   : Parameter error (NULL scan_info pointer or max_num equal to 0)
252 */
253 /**
254   \fn            int32_t ARM_WIFI_Activate (uint32_t interface, ARM_WIFI_CONFIG_t *config)
255   \brief         Activate interface (Connect to a wireless network or activate an access point).
256   \param[in]     interface Interface (0 = Station, 1 = Access Point)
257   \param[in]     config    Pointer to ARM_WIFI_CONFIG_t structure where Configuration parameters are located
258   \return        execution status
259                    - \ref ARM_DRIVER_OK                : Operation successful
260                    - \ref ARM_DRIVER_ERROR             : Operation failed
261                    - \ref ARM_DRIVER_ERROR_TIMEOUT     : Timeout occurred
262                    - \ref ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported (security type, channel autodetect or WPS not supported)
263                    - \ref ARM_DRIVER_ERROR_PARAMETER   : Parameter error (invalid interface, NULL config pointer or invalid configuration)
264 */
265 /**
266   \fn            int32_t ARM_WIFI_Deactivate (uint32_t interface)
267   \brief         Deactivate interface (Disconnect from a wireless network or deactivate an access point).
268   \param[in]     interface Interface (0 = Station, 1 = Access Point)
269   \return        execution status
270                    - \ref ARM_DRIVER_OK                : Operation successful
271                    - \ref ARM_DRIVER_ERROR             : Operation failed
272                    - \ref ARM_DRIVER_ERROR_PARAMETER   : Parameter error (invalid interface)
273 */
274 /**
275   \fn            uint32_t ARM_WIFI_IsConnected (void)
276   \brief         Get station connection status.
277   \return        station connection status
278                    - value != 0: Station connected
279                    - value = 0: Station not connected
280 */
281 /**
282   \fn            int32_t ARM_WIFI_GetNetInfo (ARM_WIFI_NET_INFO_t *net_info)
283   \brief         Get station Network Information.
284   \param[out]    net_info  Pointer to ARM_WIFI_NET_INFO_t structure where station Network Information will be returned
285   \return        execution status
286                    - \ref ARM_DRIVER_OK                : Operation successful
287                    - \ref ARM_DRIVER_ERROR             : Operation failed (station not connected)
288                    - \ref ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported
289                    - \ref ARM_DRIVER_ERROR_PARAMETER   : Parameter error (invalid interface or NULL net_info pointer)
290 */
291 /**
292   \fn            int32_t ARM_WIFI_BypassControl (uint32_t interface, uint32_t mode)
293   \brief         Enable or disable bypass (pass-through) mode. Transmit and receive Ethernet frames (IP layer bypassed and WiFi/Ethernet translation).
294   \param[in]     interface Interface (0 = Station, 1 = Access Point)
295   \param[in]     mode
296                    - value = 1: all packets bypass internal IP stack
297                    - value = 0: all packets processed by internal IP stack
298   \return        execution status
299                    - \ref ARM_DRIVER_OK                : Operation successful
300                    - \ref ARM_DRIVER_ERROR             : Operation failed
301                    - \ref ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported
302                    - \ref ARM_DRIVER_ERROR_PARAMETER   : Parameter error (invalid interface or mode)
303 */
304 /**
305   \fn            int32_t ARM_WIFI_EthSendFrame (uint32_t interface, const uint8_t *frame, uint32_t len)
306   \brief         Send Ethernet frame (in bypass mode only).
307   \param[in]     interface Interface (0 = Station, 1 = Access Point)
308   \param[in]     frame    Pointer to frame buffer with data to send
309   \param[in]     len      Frame buffer length in bytes
310   \return        execution status
311                    - \ref ARM_DRIVER_OK                : Operation successful
312                    - \ref ARM_DRIVER_ERROR             : Operation failed
313                    - \ref ARM_DRIVER_ERROR_BUSY        : Driver is busy
314                    - \ref ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported
315                    - \ref ARM_DRIVER_ERROR_PARAMETER   : Parameter error (invalid interface or NULL frame pointer)
316 */
317 /**
318   \fn            int32_t ARM_WIFI_EthReadFrame (uint32_t interface, uint8_t *frame, uint32_t len)
319   \brief         Read data of received Ethernet frame (in bypass mode only).
320   \param[in]     interface Interface (0 = Station, 1 = Access Point)
321   \param[in]     frame    Pointer to frame buffer for data to read into
322   \param[in]     len      Frame buffer length in bytes
323   \return        number of data bytes read or error code
324                    - value >= 0                        : Number of data bytes read
325                    - \ref ARM_DRIVER_ERROR             : Operation failed
326                    - \ref ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported
327                    - \ref ARM_DRIVER_ERROR_PARAMETER   : Parameter error (invalid interface or NULL frame pointer)
328 */
329 /**
330   \fn            uint32_t ARM_WIFI_EthGetRxFrameSize (uint32_t interface)
331   \brief         Get size of received Ethernet frame (in bypass mode only).
332   \param[in]     interface Interface (0 = Station, 1 = Access Point)
333   \return        number of bytes in received frame
334 */
335 /**
336   \fn            int32_t ARM_WIFI_SocketCreate (int32_t af, int32_t type, int32_t protocol)
337   \brief         Create a communication socket.
338   \param[in]     af       Address family
339   \param[in]     type     Socket type
340   \param[in]     protocol Socket protocol
341   \return        status information
342                    - Socket identification number (>=0)
343                    - \ref ARM_SOCKET_EINVAL            : Invalid argument
344                    - \ref ARM_SOCKET_ENOTSUP           : Operation not supported
345                    - \ref ARM_SOCKET_ENOMEM            : Not enough memory
346                    - \ref ARM_SOCKET_ERROR             : Unspecified error
347 */
348 /**
349   \fn            int32_t ARM_WIFI_SocketBind (int32_t socket, const uint8_t *ip, uint32_t ip_len, uint16_t port)
350   \brief         Assign a local address to a socket.
351   \param[in]     socket   Socket identification number
352   \param[in]     ip       Pointer to local IP address
353   \param[in]     ip_len   Length of 'ip' address in bytes
354   \param[in]     port     Local port number
355   \return        status information
356                    - 0                                 : Operation successful
357                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
358                    - \ref ARM_SOCKET_EINVAL            : Invalid argument (address or socket already bound)
359                    - \ref ARM_SOCKET_EADDRINUSE        : Address already in use
360                    - \ref ARM_SOCKET_ERROR             : Unspecified error
361 */
362 /**
363   \fn            int32_t ARM_WIFI_SocketListen (int32_t socket, int32_t backlog)
364   \brief         Listen for socket connections.
365   \param[in]     socket   Socket identification number
366   \param[in]     backlog  Number of connection requests that can be queued
367   \return        status information
368                    - 0                                 : Operation successful
369                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
370                    - \ref ARM_SOCKET_EINVAL            : Invalid argument (socket not bound)
371                    - \ref ARM_SOCKET_ENOTSUP           : Operation not supported
372                    - \ref ARM_SOCKET_EISCONN           : Socket is already connected
373                    - \ref ARM_SOCKET_ERROR             : Unspecified error
374 */
375 /**
376   \fn            int32_t ARM_WIFI_SocketAccept (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
377   \brief         Accept a new connection on a socket.
378   \param[in]     socket   Socket identification number
379   \param[out]    ip       Pointer to buffer where address of connecting socket shall be returned (NULL for none)
380   \param[in,out] ip_len   Pointer to length of 'ip' (or NULL if 'ip' is NULL)
381                    - length of supplied 'ip' on input
382                    - length of stored 'ip' on output
383   \param[out]    port     Pointer to buffer where port of connecting socket shall be returned (NULL for none)
384   \return        status information
385                    - socket identification number of accepted socket (>=0)
386                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
387                    - \ref ARM_SOCKET_EINVAL            : Invalid argument (socket not in listen mode)
388                    - \ref ARM_SOCKET_ENOTSUP           : Operation not supported (socket type does not support accepting connections)
389                    - \ref ARM_SOCKET_ECONNRESET        : Connection reset by the peer
390                    - \ref ARM_SOCKET_ECONNABORTED      : Connection aborted locally
391                    - \ref ARM_SOCKET_EAGAIN            : Operation would block or timed out (may be called again)
392                    - \ref ARM_SOCKET_ERROR             : Unspecified error
393 */
394 /**
395   \fn            int32_t ARM_WIFI_SocketConnect (int32_t socket, const uint8_t *ip, uint32_t ip_len, uint16_t port)
396   \brief         Connect a socket to a remote host.
397   \param[in]     socket   Socket identification number
398   \param[in]     ip       Pointer to remote IP address
399   \param[in]     ip_len   Length of 'ip' address in bytes
400   \param[in]     port     Remote port number
401   \return        status information
402                    - 0                                 : Operation successful
403                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
404                    - \ref ARM_SOCKET_EINVAL            : Invalid argument
405                    - \ref ARM_SOCKET_EALREADY          : Connection already in progress
406                    - \ref ARM_SOCKET_EINPROGRESS       : Operation in progress
407                    - \ref ARM_SOCKET_EISCONN           : Socket is connected
408                    - \ref ARM_SOCKET_ECONNREFUSED      : Connection rejected by the peer
409                    - \ref ARM_SOCKET_ECONNABORTED      : Connection aborted locally
410                    - \ref ARM_SOCKET_EADDRINUSE        : Address already in use
411                    - \ref ARM_SOCKET_ETIMEDOUT         : Operation timed out
412                    - \ref ARM_SOCKET_ERROR             : Unspecified error
413 */
414 /**
415   \fn            int32_t ARM_WIFI_SocketRecv (int32_t socket, void *buf, uint32_t len)
416   \brief         Receive data on a connected socket.
417   \param[in]     socket   Socket identification number
418   \param[out]    buf      Pointer to buffer where data should be stored
419   \param[in]     len      Length of buffer (in bytes)
420   \return        status information
421                    - number of bytes received (>0)
422                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
423                    - \ref ARM_SOCKET_EINVAL            : Invalid argument (pointer to buffer or length)
424                    - \ref ARM_SOCKET_ENOTCONN          : Socket is not connected
425                    - \ref ARM_SOCKET_ECONNRESET        : Connection reset by the peer
426                    - \ref ARM_SOCKET_ECONNABORTED      : Connection aborted locally
427                    - \ref ARM_SOCKET_EAGAIN            : Operation would block or timed out (may be called again)
428                    - \ref ARM_SOCKET_ERROR             : Unspecified error
429 */
430 /**
431   \fn            int32_t ARM_WIFI_SocketRecvFrom (int32_t socket, void *buf, uint32_t len, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
432   \brief         Receive data on a socket.
433   \param[in]     socket   Socket identification number
434   \param[out]    buf      Pointer to buffer where data should be stored
435   \param[in]     len      Length of buffer (in bytes)
436   \param[out]    ip       Pointer to buffer where remote source address shall be returned (NULL for none)
437   \param[in,out] ip_len   Pointer to length of 'ip' (or NULL if 'ip' is NULL)
438                    - length of supplied 'ip' on input
439                    - length of stored 'ip' on output
440   \param[out]    port     Pointer to buffer where remote source port shall be returned (NULL for none)
441   \return        status information
442                    - number of bytes received (>0)
443                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
444                    - \ref ARM_SOCKET_EINVAL            : Invalid argument (pointer to buffer or length)
445                    - \ref ARM_SOCKET_ENOTCONN          : Socket is not connected
446                    - \ref ARM_SOCKET_ECONNRESET        : Connection reset by the peer
447                    - \ref ARM_SOCKET_ECONNABORTED      : Connection aborted locally
448                    - \ref ARM_SOCKET_EAGAIN            : Operation would block or timed out (may be called again)
449                    - \ref ARM_SOCKET_ERROR             : Unspecified error
450 */
451 /**
452   \fn            int32_t ARM_WIFI_SocketSend (int32_t socket, const void *buf, uint32_t len)
453   \brief         Send data on a connected socket.
454   \param[in]     socket   Socket identification number
455   \param[in]     buf      Pointer to buffer containing data to send
456   \param[in]     len      Length of data (in bytes)
457   \return        status information
458                    - number of bytes sent (>0)
459                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
460                    - \ref ARM_SOCKET_EINVAL            : Invalid argument (pointer to buffer or length)
461                    - \ref ARM_SOCKET_ENOTCONN          : Socket is not connected
462                    - \ref ARM_SOCKET_ECONNRESET        : Connection reset by the peer
463                    - \ref ARM_SOCKET_ECONNABORTED      : Connection aborted locally
464                    - \ref ARM_SOCKET_EAGAIN            : Operation would block or timed out (may be called again)
465                    - \ref ARM_SOCKET_ERROR             : Unspecified error
466 */
467 /**
468   \fn            int32_t ARM_WIFI_SocketSendTo (int32_t socket, const void *buf, uint32_t len, const uint8_t *ip, uint32_t ip_len, uint16_t port)
469   \brief         Send data on a socket.
470   \param[in]     socket   Socket identification number
471   \param[in]     buf      Pointer to buffer containing data to send
472   \param[in]     len      Length of data (in bytes)
473   \param[in]     ip       Pointer to remote destination IP address
474   \param[in]     ip_len   Length of 'ip' address in bytes
475   \param[in]     port     Remote destination port number
476   \return        status information
477                    - number of bytes sent (>0)
478                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
479                    - \ref ARM_SOCKET_EINVAL            : Invalid argument (pointer to buffer or length)
480                    - \ref ARM_SOCKET_ENOTCONN          : Socket is not connected
481                    - \ref ARM_SOCKET_ECONNRESET        : Connection reset by the peer
482                    - \ref ARM_SOCKET_ECONNABORTED      : Connection aborted locally
483                    - \ref ARM_SOCKET_EAGAIN            : Operation would block or timed out (may be called again)
484                    - \ref ARM_SOCKET_ERROR             : Unspecified error
485 */
486 /**
487   \fn            int32_t ARM_WIFI_SocketGetSockName (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
488   \brief         Retrieve local IP address and port of a socket.
489   \param[in]     socket   Socket identification number
490   \param[out]    ip       Pointer to buffer where local address shall be returned (NULL for none)
491   \param[in,out] ip_len   Pointer to length of 'ip' (or NULL if 'ip' is NULL)
492                    - length of supplied 'ip' on input
493                    - length of stored 'ip' on output
494   \param[out]    port     Pointer to buffer where local port shall be returned (NULL for none)
495   \return        status information
496                    - 0                                 : Operation successful
497                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
498                    - \ref ARM_SOCKET_EINVAL            : Invalid argument (pointer to buffer or length)
499                    - \ref ARM_SOCKET_ERROR             : Unspecified error
500 */
501 /**
502   \fn            int32_t ARM_WIFI_SocketGetPeerName (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)
503   \brief         Retrieve remote IP address and port of a socket
504   \param[in]     socket   Socket identification number
505   \param[out]    ip       Pointer to buffer where remote address shall be returned (NULL for none)
506   \param[in,out] ip_len   Pointer to length of 'ip' (or NULL if 'ip' is NULL)
507                    - length of supplied 'ip' on input
508                    - length of stored 'ip' on output
509   \param[out]    port     Pointer to buffer where remote port shall be returned (NULL for none)
510   \return        status information
511                    - 0                                 : Operation successful
512                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
513                    - \ref ARM_SOCKET_EINVAL            : Invalid argument (pointer to buffer or length)
514                    - \ref ARM_SOCKET_ENOTCONN          : Socket is not connected
515                    - \ref ARM_SOCKET_ERROR             : Unspecified error
516 */
517 /**
518   \fn            int32_t ARM_WIFI_SocketGetOpt (int32_t socket, int32_t opt_id, void *opt_val, uint32_t *opt_len)
519   \brief         Get socket option.
520   \param[in]     socket   Socket identification number
521   \param[in]     opt_id   Option identifier
522   \param[out]    opt_val  Pointer to the buffer that will receive the option value
523   \param[in,out] opt_len  Pointer to length of the option value
524                    - length of buffer on input
525                    - length of data on output
526   \return        status information
527                    - 0                                 : Operation successful
528                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
529                    - \ref ARM_SOCKET_EINVAL            : Invalid argument
530                    - \ref ARM_SOCKET_ENOTSUP           : Operation not supported
531                    - \ref ARM_SOCKET_ERROR             : Unspecified error
532 */
533 /**
534   \fn            int32_t ARM_WIFI_SocketSetOpt (int32_t socket, int32_t opt_id, const void *opt_val, uint32_t opt_len)
535   \brief         Set socket option.
536   \param[in]     socket   Socket identification number
537   \param[in]     opt_id   Option identifier
538   \param[in]     opt_val  Pointer to the option value
539   \param[in]     opt_len  Length of the option value in bytes
540   \return        status information
541                    - 0                                 : Operation successful
542                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
543                    - \ref ARM_SOCKET_EINVAL            : Invalid argument
544                    - \ref ARM_SOCKET_ENOTSUP           : Operation not supported
545                    - \ref ARM_SOCKET_ERROR             : Unspecified error
546 */
547 /**
548   \fn            int32_t ARM_WIFI_SocketClose (int32_t socket)
549   \brief         Close and release a socket.
550   \param[in]     socket   Socket identification number
551   \return        status information
552                    - 0                                 : Operation successful
553                    - \ref ARM_SOCKET_ESOCK             : Invalid socket
554                    - \ref ARM_SOCKET_EAGAIN            : Operation would block (may be called again)
555                    - \ref ARM_SOCKET_ERROR             : Unspecified error
556 */
557 /**
558   \fn            int32_t ARM_WIFI_SocketGetHostByName (const char *name, int32_t af, uint8_t *ip, uint32_t *ip_len)
559   \brief         Retrieve host IP address from host name.
560   \param[in]     name     Host name
561   \param[in]     af       Address family
562   \param[out]    ip       Pointer to buffer where resolved IP address shall be returned
563   \param[in,out] ip_len   Pointer to length of 'ip'
564                    - length of supplied 'ip' on input
565                    - length of stored 'ip' on output
566   \return        status information
567                    - 0                                 : Operation successful
568                    - \ref ARM_SOCKET_EINVAL            : Invalid argument
569                    - \ref ARM_SOCKET_ENOTSUP           : Operation not supported
570                    - \ref ARM_SOCKET_ETIMEDOUT         : Operation timed out
571                    - \ref ARM_SOCKET_EHOSTNOTFOUND     : Host not found
572                    - \ref ARM_SOCKET_ERROR             : Unspecified error
573 */
574 /**
575   \fn            int32_t ARM_WIFI_Ping (const uint8_t *ip, uint32_t ip_len)
576   \brief         Probe remote host with Ping command.
577   \param[in]     ip       Pointer to remote host IP address
578   \param[in]     ip_len   Length of 'ip' address in bytes
579   \return        execution status
580                    - \ref ARM_DRIVER_OK                : Operation successful
581                    - \ref ARM_DRIVER_ERROR             : Operation failed
582                    - \ref ARM_DRIVER_ERROR_TIMEOUT     : Timeout occurred
583                    - \ref ARM_DRIVER_ERROR_UNSUPPORTED : Operation not supported
584                    - \ref ARM_DRIVER_ERROR_PARAMETER   : Parameter error (NULL ip pointer or ip_len different than 4 or 16)
585 */
586 /**
587   \fn            void ARM_WIFI_SignalEvent (uint32_t event, void *arg)
588   \brief         Signal WiFi Events.
589   \param[in]     event    \ref wifi_event notification mask
590   \param[in]     arg      Pointer to argument of signaled event
591   \return        none
592 */
593
594 typedef void (*ARM_WIFI_SignalEvent_t) (uint32_t event, void *arg); ///< Pointer to \ref ARM_WIFI_SignalEvent : Signal WiFi Event.
595
596
597 /**
598 \brief WiFi Driver Capabilities.
599 */
600 typedef struct {
601   uint32_t station               : 1;   ///< Station
602   uint32_t ap                    : 1;   ///< Access Point
603   uint32_t station_ap            : 1;   ///< Concurrent Station and Access Point
604   uint32_t wps_station           : 1;   ///< WiFi Protected Setup (WPS) for Station
605   uint32_t wps_ap                : 1;   ///< WiFi Protected Setup (WPS) for Access Point
606   uint32_t event_ap_connect      : 1;   ///< Access Point: event generated on Station connect
607   uint32_t event_ap_disconnect   : 1;   ///< Access Point: event generated on Station disconnect
608   uint32_t event_eth_rx_frame    : 1;   ///< Event generated on Ethernet frame reception in bypass mode
609   uint32_t bypass_mode           : 1;   ///< Bypass or pass-through mode (Ethernet interface)
610   uint32_t ip                    : 1;   ///< IP (UDP/TCP) (Socket interface)
611   uint32_t ip6                   : 1;   ///< IPv6 (Socket interface)
612   uint32_t ping                  : 1;   ///< Ping (ICMP)
613   uint32_t reserved              : 20;  ///< Reserved (must be zero)
614 } ARM_WIFI_CAPABILITIES;
615
616 /**
617 \brief Access structure of the WiFi Driver.
618 */
619 typedef struct {
620   ARM_DRIVER_VERSION    (*GetVersion)                  (void);
621   ARM_WIFI_CAPABILITIES (*GetCapabilities)             (void);
622   int32_t               (*Initialize)                  (ARM_WIFI_SignalEvent_t cb_event);
623   int32_t               (*Uninitialize)                (void);
624   int32_t               (*PowerControl)                (ARM_POWER_STATE state);
625   int32_t               (*GetModuleInfo)               (char *module_info, uint32_t max_len);
626   int32_t               (*SetOption)                   (uint32_t interface, uint32_t option, const void *data, uint32_t  len);
627   int32_t               (*GetOption)                   (uint32_t interface, uint32_t option,       void *data, uint32_t *len);
628   int32_t               (*Scan)                        (ARM_WIFI_SCAN_INFO_t scan_info[], uint32_t max_num);
629   int32_t               (*Activate)                    (uint32_t interface, const ARM_WIFI_CONFIG_t *config);
630   int32_t               (*Deactivate)                  (uint32_t interface);
631   uint32_t              (*IsConnected)                 (void);
632   int32_t               (*GetNetInfo)                  (ARM_WIFI_NET_INFO_t *net_info);
633   int32_t               (*BypassControl)               (uint32_t interface, uint32_t mode);
634   int32_t               (*EthSendFrame)                (uint32_t interface, const uint8_t *frame, uint32_t len);
635   int32_t               (*EthReadFrame)                (uint32_t interface,       uint8_t *frame, uint32_t len);
636   uint32_t              (*EthGetRxFrameSize)           (uint32_t interface);
637   int32_t               (*SocketCreate)                (int32_t af, int32_t type, int32_t protocol);
638   int32_t               (*SocketBind)                  (int32_t socket, const uint8_t *ip, uint32_t  ip_len, uint16_t  port);
639   int32_t               (*SocketListen)                (int32_t socket, int32_t backlog);
640   int32_t               (*SocketAccept)                (int32_t socket,       uint8_t *ip, uint32_t *ip_len, uint16_t *port);
641   int32_t               (*SocketConnect)               (int32_t socket, const uint8_t *ip, uint32_t  ip_len, uint16_t  port);
642   int32_t               (*SocketRecv)                  (int32_t socket, void *buf, uint32_t len);
643   int32_t               (*SocketRecvFrom)              (int32_t socket, void *buf, uint32_t len, uint8_t *ip, uint32_t *ip_len, uint16_t *port);
644   int32_t               (*SocketSend)                  (int32_t socket, const void *buf, uint32_t len);
645   int32_t               (*SocketSendTo)                (int32_t socket, const void *buf, uint32_t len, const uint8_t *ip, uint32_t ip_len, uint16_t port);
646   int32_t               (*SocketGetSockName)           (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port);
647   int32_t               (*SocketGetPeerName)           (int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port);
648   int32_t               (*SocketGetOpt)                (int32_t socket, int32_t opt_id,       void *opt_val, uint32_t *opt_len);
649   int32_t               (*SocketSetOpt)                (int32_t socket, int32_t opt_id, const void *opt_val, uint32_t  opt_len);
650   int32_t               (*SocketClose)                 (int32_t socket);
651   int32_t               (*SocketGetHostByName)         (const char *name, int32_t af, uint8_t *ip, uint32_t *ip_len);
652   int32_t               (*Ping)                        (const uint8_t *ip, uint32_t ip_len);
653 } const ARM_DRIVER_WIFI;
654
655 #ifdef  __cplusplus
656 }
657 #endif
658
659 #endif /* DRIVER_WIFI_H_ */