Driver_WiFi.h 42 KB

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