spi_wifi_rw009.h 6.8 KB

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