Driver_WiFi.h 42 KB

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