2014-07-31 14:42:37 +08:00
|
|
|
/*
|
2023-04-18 10:26:23 +08:00
|
|
|
* COPYRIGHT (C) 2011-2023, Real-Thread Information Technology Ltd
|
2021-03-08 18:19:04 +08:00
|
|
|
*
|
2018-10-14 19:37:18 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2014-07-31 14:42:37 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2014-07-31 aozima the first version
|
2014-09-24 12:08:01 +08:00
|
|
|
* 2014-09-18 aozima update command & response.
|
2014-07-31 14:42:37 +08:00
|
|
|
*/
|
|
|
|
|
2024-09-14 05:40:40 +08:00
|
|
|
#ifndef __DEV_SPI_WIFI_H_INCLUDED__
|
|
|
|
#define __DEV_SPI_WIFI_H_INCLUDED__
|
2014-07-31 14:42:37 +08:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
// little-endian
|
2014-09-24 12:08:01 +08:00
|
|
|
struct spi_cmd_request
|
2014-07-31 14:42:37 +08:00
|
|
|
{
|
|
|
|
uint32_t flag;
|
|
|
|
uint32_t M2S_len; // master to slave data len.
|
|
|
|
uint32_t magic1;
|
|
|
|
uint32_t magic2;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CMD_MAGIC1 (0x67452301)
|
|
|
|
#define CMD_MAGIC2 (0xEFCDAB89)
|
|
|
|
|
|
|
|
#define CMD_FLAG_MRDY (0x01)
|
|
|
|
|
|
|
|
// little-endian
|
2014-09-24 12:08:01 +08:00
|
|
|
struct spi_response
|
2014-07-31 14:42:37 +08:00
|
|
|
{
|
|
|
|
uint32_t flag;
|
|
|
|
uint32_t S2M_len; // slave to master data len.
|
|
|
|
uint32_t magic1;
|
|
|
|
uint32_t magic2;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define RESP_FLAG_SRDY (0x01)
|
|
|
|
#define RESP_MAGIC1 (0x98BADCFE)
|
|
|
|
#define RESP_MAGIC2 (0x10325476)
|
|
|
|
|
|
|
|
/* spi slave configure. */
|
2014-09-24 12:08:01 +08:00
|
|
|
#define SPI_MAX_DATA_LEN 1520
|
2014-07-31 14:42:37 +08:00
|
|
|
#define SPI_TX_POOL_SIZE 2
|
2014-09-08 16:59:52 +08:00
|
|
|
#define SPI_RX_POOL_SIZE 2
|
2014-07-31 14:42:37 +08:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
data_type_eth_data = 0,
|
|
|
|
data_type_cmd,
|
|
|
|
data_type_resp,
|
2014-09-24 12:08:01 +08:00
|
|
|
data_type_status,
|
2014-07-31 14:42:37 +08:00
|
|
|
}
|
|
|
|
app_data_type_typedef;
|
|
|
|
|
|
|
|
struct spi_data_packet
|
|
|
|
{
|
|
|
|
uint32_t data_len;
|
|
|
|
uint32_t data_type;
|
2014-09-24 12:08:01 +08:00
|
|
|
char buffer[SPI_MAX_DATA_LEN];
|
2014-07-31 14:42:37 +08:00
|
|
|
};
|
|
|
|
|
2014-09-24 12:08:01 +08:00
|
|
|
/********************************* RW009 **************************************/
|
2014-09-08 16:59:52 +08:00
|
|
|
|
2014-09-24 12:08:01 +08:00
|
|
|
/* option */
|
|
|
|
#define RW009_CMD_TIMEOUT (RT_TICK_PER_SECOND*3)
|
|
|
|
#define SSID_NAME_LENGTH_MAX (32)
|
|
|
|
#define PASSWORD_LENGTH_MAX (64)
|
2014-09-08 16:59:52 +08:00
|
|
|
|
2014-11-15 16:11:24 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
MODE_STATION=0,
|
|
|
|
MODE_SOFTAP=1,
|
|
|
|
} wifi_mode_t;
|
|
|
|
|
2014-09-24 12:08:01 +08:00
|
|
|
typedef struct _rw009_ap_info
|
|
|
|
{
|
|
|
|
char ssid[SSID_NAME_LENGTH_MAX];
|
|
|
|
uint8_t bssid[8]; // 6byte + 2byte PAD.
|
|
|
|
int rssi; /* Receive Signal Strength Indication in dBm. */
|
|
|
|
uint32_t max_data_rate; /* Maximum data rate in kilobits/s */
|
|
|
|
uint32_t security; /* Security type */
|
|
|
|
uint32_t channel; /* Radio channel that the AP beacon was received on */
|
|
|
|
} rw009_ap_info;
|
|
|
|
|
|
|
|
typedef struct _rw009_cmd_init
|
|
|
|
{
|
|
|
|
uint32_t mode;
|
|
|
|
} rw009_cmd_init;
|
|
|
|
|
|
|
|
typedef struct _rw009_resp_init
|
|
|
|
{
|
|
|
|
uint8_t mac[8]; // 6byte + 2byte PAD.
|
|
|
|
uint8_t sn[24]; // serial.
|
|
|
|
char version[16]; // firmware version.
|
|
|
|
} rw009_resp_init;
|
|
|
|
|
|
|
|
typedef struct _rw009_cmd_easy_join
|
|
|
|
{
|
|
|
|
char ssid[SSID_NAME_LENGTH_MAX];
|
|
|
|
char passwd[PASSWORD_LENGTH_MAX];
|
|
|
|
} rw009_cmd_easy_join;
|
|
|
|
|
|
|
|
typedef struct _rw009_cmd_join
|
|
|
|
{
|
|
|
|
uint8_t bssid[8]; // 6byte + 2byte PAD.
|
|
|
|
char passwd[PASSWORD_LENGTH_MAX];
|
|
|
|
} rw009_cmd_join;
|
2014-09-08 16:59:52 +08:00
|
|
|
|
2014-09-24 12:08:01 +08:00
|
|
|
typedef struct _rw009_cmd_rssi
|
|
|
|
{
|
|
|
|
uint8_t bssid[8]; // 6byte + 2byte PAD.
|
|
|
|
} rw009_cmd_rssi;
|
|
|
|
|
2014-11-15 16:11:24 +08:00
|
|
|
typedef struct _rw009_cmd_softap
|
|
|
|
{
|
|
|
|
char ssid[SSID_NAME_LENGTH_MAX];
|
|
|
|
char passwd[PASSWORD_LENGTH_MAX];
|
|
|
|
|
|
|
|
uint32_t security; /* Security type. */
|
|
|
|
uint32_t channel; /* Radio channel that the AP beacon was received on */
|
|
|
|
} rw009_cmd_softap;
|
|
|
|
|
2014-09-24 12:08:01 +08:00
|
|
|
typedef struct _rw009_resp_join
|
|
|
|
{
|
|
|
|
rw009_ap_info ap_info;
|
|
|
|
} rw009_resp_join;
|
|
|
|
|
|
|
|
struct rw009_cmd
|
2014-07-31 14:42:37 +08:00
|
|
|
{
|
|
|
|
uint32_t cmd;
|
2014-09-24 12:08:01 +08:00
|
|
|
uint32_t len;
|
|
|
|
|
|
|
|
/** command body */
|
|
|
|
union
|
|
|
|
{
|
|
|
|
rw009_cmd_init init;
|
|
|
|
rw009_cmd_easy_join easy_join;
|
|
|
|
rw009_cmd_join join;
|
|
|
|
rw009_cmd_rssi rssi;
|
2014-11-15 16:11:24 +08:00
|
|
|
rw009_cmd_softap softap;
|
2014-09-24 12:08:01 +08:00
|
|
|
} params;
|
2014-07-31 14:42:37 +08:00
|
|
|
};
|
|
|
|
|
2014-09-24 12:08:01 +08:00
|
|
|
struct rw009_resp
|
2014-07-31 14:42:37 +08:00
|
|
|
{
|
|
|
|
uint32_t cmd;
|
2014-09-24 12:08:01 +08:00
|
|
|
uint32_t len;
|
|
|
|
|
|
|
|
int32_t result; // result for CMD.
|
|
|
|
|
|
|
|
/** resp Body */
|
|
|
|
union
|
|
|
|
{
|
|
|
|
rw009_resp_init init;
|
|
|
|
rw009_ap_info ap_info;
|
|
|
|
} resp;
|
2014-07-31 14:42:37 +08:00
|
|
|
};
|
|
|
|
|
2014-09-24 12:08:01 +08:00
|
|
|
#define RW009_CMD_INIT 128
|
|
|
|
#define RW009_CMD_SCAN 129
|
|
|
|
#define RW009_CMD_JOIN 130
|
|
|
|
#define RW009_CMD_EASY_JOIN 131
|
|
|
|
#define RW009_CMD_RSSI 132
|
2014-11-15 16:11:24 +08:00
|
|
|
#define RW009_CMD_SOFTAP 133
|
|
|
|
|
|
|
|
/** cond !ADDTHIS*/
|
|
|
|
#define SHARED_ENABLED 0x00008000
|
|
|
|
#define WPA_SECURITY 0x00200000
|
|
|
|
#define WPA2_SECURITY 0x00400000
|
|
|
|
#define WPS_ENABLED 0x10000000
|
|
|
|
#define WEP_ENABLED 0x0001
|
|
|
|
#define TKIP_ENABLED 0x0002
|
|
|
|
#define AES_ENABLED 0x0004
|
|
|
|
#define WSEC_SWFLAG 0x0008
|
|
|
|
/** endcond */
|
|
|
|
/**
|
|
|
|
* Enumeration of Wi-Fi security modes
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
SECURITY_OPEN = 0, /**< Open security */
|
|
|
|
SECURITY_WEP_PSK = WEP_ENABLED, /**< WEP Security with open authentication */
|
|
|
|
SECURITY_WEP_SHARED = ( WEP_ENABLED | SHARED_ENABLED ), /**< WEP Security with shared authentication */
|
|
|
|
SECURITY_WPA_TKIP_PSK = ( WPA_SECURITY | TKIP_ENABLED ), /**< WPA Security with TKIP */
|
|
|
|
SECURITY_WPA_AES_PSK = ( WPA_SECURITY | AES_ENABLED ), /**< WPA Security with AES */
|
|
|
|
SECURITY_WPA2_AES_PSK = ( WPA2_SECURITY | AES_ENABLED ), /**< WPA2 Security with AES */
|
|
|
|
SECURITY_WPA2_TKIP_PSK = ( WPA2_SECURITY | TKIP_ENABLED ), /**< WPA2 Security with TKIP */
|
|
|
|
SECURITY_WPA2_MIXED_PSK = ( WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED ), /**< WPA2 Security with AES & TKIP */
|
|
|
|
|
|
|
|
SECURITY_WPS_OPEN = WPS_ENABLED, /**< WPS with open security */
|
|
|
|
SECURITY_WPS_SECURE = (WPS_ENABLED | AES_ENABLED), /**< WPS with AES security */
|
|
|
|
|
|
|
|
SECURITY_UNKNOWN = -1, /**< May be returned by scan function if security is unknown. Do not pass this to the join function! */
|
|
|
|
|
|
|
|
SECURITY_FORCE_32_BIT = 0x7fffffff /**< Exists only to force wiced_security_t type to 32 bits */
|
|
|
|
} security_t;
|
2014-07-31 14:42:37 +08:00
|
|
|
|
|
|
|
/* porting */
|
|
|
|
extern void spi_wifi_hw_init(void);
|
|
|
|
extern void spi_wifi_int_cmd(rt_bool_t cmd);
|
|
|
|
extern rt_bool_t spi_wifi_is_busy(void);
|
|
|
|
|
2014-09-24 12:08:01 +08:00
|
|
|
/* export API. */
|
2014-11-15 16:11:24 +08:00
|
|
|
extern rt_err_t rt_hw_wifi_init(const char *spi_device_name,wifi_mode_t mode);
|
2014-09-24 12:08:01 +08:00
|
|
|
extern int32_t rw009_rssi(void);
|
|
|
|
extern rt_err_t rw009_join(const char * SSID, const char * passwd);
|
2014-11-15 16:11:24 +08:00
|
|
|
extern rt_err_t rw009_softap(const char * SSID, const char * passwd,uint32_t security,uint32_t channel);
|
2014-07-31 14:42:37 +08:00
|
|
|
|
2024-09-14 05:40:40 +08:00
|
|
|
#endif // __DEV_SPI_WIFI_H_INCLUDED__
|