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