dev_spi_wifi_rw009.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * COPYRIGHT (C) 2011-2023, Real-Thread Information Technology Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2014-07-31 aozima the first version
  9. * 2014-09-18 aozima update command & response.
  10. */
  11. #ifndef __DEV_SPI_WIFI_H_INCLUDED__
  12. #define __DEV_SPI_WIFI_H_INCLUDED__
  13. #include <stdint.h>
  14. // little-endian
  15. struct spi_cmd_request
  16. {
  17. uint32_t flag;
  18. uint32_t M2S_len; // master to slave data len.
  19. uint32_t magic1;
  20. uint32_t magic2;
  21. };
  22. #define CMD_MAGIC1 (0x67452301)
  23. #define CMD_MAGIC2 (0xEFCDAB89)
  24. #define CMD_FLAG_MRDY (0x01)
  25. // little-endian
  26. struct spi_response
  27. {
  28. uint32_t flag;
  29. uint32_t S2M_len; // slave to master data len.
  30. uint32_t magic1;
  31. uint32_t magic2;
  32. };
  33. #define RESP_FLAG_SRDY (0x01)
  34. #define RESP_MAGIC1 (0x98BADCFE)
  35. #define RESP_MAGIC2 (0x10325476)
  36. /* spi slave configure. */
  37. #define SPI_MAX_DATA_LEN 1520
  38. #define SPI_TX_POOL_SIZE 2
  39. #define SPI_RX_POOL_SIZE 2
  40. typedef enum
  41. {
  42. data_type_eth_data = 0,
  43. data_type_cmd,
  44. data_type_resp,
  45. data_type_status,
  46. }
  47. app_data_type_typedef;
  48. struct spi_data_packet
  49. {
  50. uint32_t data_len;
  51. uint32_t data_type;
  52. char buffer[SPI_MAX_DATA_LEN];
  53. };
  54. /********************************* RW009 **************************************/
  55. /* option */
  56. #define RW009_CMD_TIMEOUT (RT_TICK_PER_SECOND*3)
  57. #define SSID_NAME_LENGTH_MAX (32)
  58. #define PASSWORD_LENGTH_MAX (64)
  59. typedef enum
  60. {
  61. MODE_STATION=0,
  62. MODE_SOFTAP=1,
  63. } wifi_mode_t;
  64. typedef struct _rw009_ap_info
  65. {
  66. char ssid[SSID_NAME_LENGTH_MAX];
  67. uint8_t bssid[8]; // 6byte + 2byte PAD.
  68. int rssi; /* Receive Signal Strength Indication in dBm. */
  69. uint32_t max_data_rate; /* Maximum data rate in kilobits/s */
  70. uint32_t security; /* Security type */
  71. uint32_t channel; /* Radio channel that the AP beacon was received on */
  72. } rw009_ap_info;
  73. typedef struct _rw009_cmd_init
  74. {
  75. uint32_t mode;
  76. } rw009_cmd_init;
  77. typedef struct _rw009_resp_init
  78. {
  79. uint8_t mac[8]; // 6byte + 2byte PAD.
  80. uint8_t sn[24]; // serial.
  81. char version[16]; // firmware version.
  82. } rw009_resp_init;
  83. typedef struct _rw009_cmd_easy_join
  84. {
  85. char ssid[SSID_NAME_LENGTH_MAX];
  86. char passwd[PASSWORD_LENGTH_MAX];
  87. } rw009_cmd_easy_join;
  88. typedef struct _rw009_cmd_join
  89. {
  90. uint8_t bssid[8]; // 6byte + 2byte PAD.
  91. char passwd[PASSWORD_LENGTH_MAX];
  92. } rw009_cmd_join;
  93. typedef struct _rw009_cmd_rssi
  94. {
  95. uint8_t bssid[8]; // 6byte + 2byte PAD.
  96. } rw009_cmd_rssi;
  97. typedef struct _rw009_cmd_softap
  98. {
  99. char ssid[SSID_NAME_LENGTH_MAX];
  100. char passwd[PASSWORD_LENGTH_MAX];
  101. uint32_t security; /* Security type. */
  102. uint32_t channel; /* Radio channel that the AP beacon was received on */
  103. } rw009_cmd_softap;
  104. typedef struct _rw009_resp_join
  105. {
  106. rw009_ap_info ap_info;
  107. } rw009_resp_join;
  108. struct rw009_cmd
  109. {
  110. uint32_t cmd;
  111. uint32_t len;
  112. /** command body */
  113. union
  114. {
  115. rw009_cmd_init init;
  116. rw009_cmd_easy_join easy_join;
  117. rw009_cmd_join join;
  118. rw009_cmd_rssi rssi;
  119. rw009_cmd_softap softap;
  120. } params;
  121. };
  122. struct rw009_resp
  123. {
  124. uint32_t cmd;
  125. uint32_t len;
  126. int32_t result; // result for CMD.
  127. /** resp Body */
  128. union
  129. {
  130. rw009_resp_init init;
  131. rw009_ap_info ap_info;
  132. } resp;
  133. };
  134. #define RW009_CMD_INIT 128
  135. #define RW009_CMD_SCAN 129
  136. #define RW009_CMD_JOIN 130
  137. #define RW009_CMD_EASY_JOIN 131
  138. #define RW009_CMD_RSSI 132
  139. #define RW009_CMD_SOFTAP 133
  140. /** cond !ADDTHIS*/
  141. #define SHARED_ENABLED 0x00008000
  142. #define WPA_SECURITY 0x00200000
  143. #define WPA2_SECURITY 0x00400000
  144. #define WPS_ENABLED 0x10000000
  145. #define WEP_ENABLED 0x0001
  146. #define TKIP_ENABLED 0x0002
  147. #define AES_ENABLED 0x0004
  148. #define WSEC_SWFLAG 0x0008
  149. /** endcond */
  150. /**
  151. * Enumeration of Wi-Fi security modes
  152. */
  153. typedef enum
  154. {
  155. SECURITY_OPEN = 0, /**< Open security */
  156. SECURITY_WEP_PSK = WEP_ENABLED, /**< WEP Security with open authentication */
  157. SECURITY_WEP_SHARED = ( WEP_ENABLED | SHARED_ENABLED ), /**< WEP Security with shared authentication */
  158. SECURITY_WPA_TKIP_PSK = ( WPA_SECURITY | TKIP_ENABLED ), /**< WPA Security with TKIP */
  159. SECURITY_WPA_AES_PSK = ( WPA_SECURITY | AES_ENABLED ), /**< WPA Security with AES */
  160. SECURITY_WPA2_AES_PSK = ( WPA2_SECURITY | AES_ENABLED ), /**< WPA2 Security with AES */
  161. SECURITY_WPA2_TKIP_PSK = ( WPA2_SECURITY | TKIP_ENABLED ), /**< WPA2 Security with TKIP */
  162. SECURITY_WPA2_MIXED_PSK = ( WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED ), /**< WPA2 Security with AES & TKIP */
  163. SECURITY_WPS_OPEN = WPS_ENABLED, /**< WPS with open security */
  164. SECURITY_WPS_SECURE = (WPS_ENABLED | AES_ENABLED), /**< WPS with AES security */
  165. SECURITY_UNKNOWN = -1, /**< May be returned by scan function if security is unknown. Do not pass this to the join function! */
  166. SECURITY_FORCE_32_BIT = 0x7fffffff /**< Exists only to force wiced_security_t type to 32 bits */
  167. } security_t;
  168. /* porting */
  169. extern void spi_wifi_hw_init(void);
  170. extern void spi_wifi_int_cmd(rt_bool_t cmd);
  171. extern rt_bool_t spi_wifi_is_busy(void);
  172. /* export API. */
  173. extern rt_err_t rt_hw_wifi_init(const char *spi_device_name,wifi_mode_t mode);
  174. extern int32_t rw009_rssi(void);
  175. extern rt_err_t rw009_join(const char * SSID, const char * passwd);
  176. extern rt_err_t rw009_softap(const char * SSID, const char * passwd,uint32_t security,uint32_t channel);
  177. #endif // __DEV_SPI_WIFI_H_INCLUDED__