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