Driver_WiFi.h 41 KB

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