update RW009 driver: add softAP support.
This commit is contained in:
parent
4586e48c18
commit
92fac29f70
|
@ -126,6 +126,7 @@ static void resp_handler(struct rw009_wifi *wifi_device, struct rw009_resp *resp
|
|||
//dump
|
||||
if(1)
|
||||
{
|
||||
#ifdef WIFI_DEBUG_ON
|
||||
rw009_ap_info *ap_info = &resp->resp.ap_info;
|
||||
WIFI_DEBUG("SCAN SSID:%-32.32s\n", ap_info->ssid);
|
||||
WIFI_DEBUG("SCAN BSSID:%02X-%02X-%02X-%02X-%02X-%02X\n",
|
||||
|
@ -139,6 +140,7 @@ static void resp_handler(struct rw009_wifi *wifi_device, struct rw009_resp *resp
|
|||
WIFI_DEBUG("SCAN rate:%dMbps\n", ap_info->max_data_rate/1000);
|
||||
WIFI_DEBUG("SCAN channel:%d\n", ap_info->channel);
|
||||
WIFI_DEBUG("SCAN security:%08X\n\n", ap_info->security);
|
||||
#endif /* WIFI_DEBUG_ON */
|
||||
}
|
||||
|
||||
wifi_device->ap_scan_count++;
|
||||
|
@ -148,7 +150,6 @@ static void resp_handler(struct rw009_wifi *wifi_device, struct rw009_resp *resp
|
|||
return; /* wait for next ap */
|
||||
}
|
||||
break;
|
||||
|
||||
case RW009_CMD_JOIN:
|
||||
case RW009_CMD_EASY_JOIN:
|
||||
WIFI_DEBUG("resp_handler RW009_CMD_EASY_JOIN\n");
|
||||
|
@ -170,6 +171,7 @@ static void resp_handler(struct rw009_wifi *wifi_device, struct rw009_resp *resp
|
|||
//dupm
|
||||
if(1)
|
||||
{
|
||||
#ifdef WIFI_DEBUG_ON
|
||||
rw009_ap_info *ap_info = &resp->resp.ap_info;
|
||||
WIFI_DEBUG("JOIN SSID:%-32.32s\n", ap_info->ssid);
|
||||
WIFI_DEBUG("JOIN BSSID:%02X-%02X-%02X-%02X-%02X-%02X\n",
|
||||
|
@ -183,17 +185,34 @@ static void resp_handler(struct rw009_wifi *wifi_device, struct rw009_resp *resp
|
|||
WIFI_DEBUG("JOIN rate:%dMbps\n", ap_info->max_data_rate/1000);
|
||||
WIFI_DEBUG("JOIN channel:%d\n", ap_info->channel);
|
||||
WIFI_DEBUG("JOIN security:%08X\n\n", ap_info->security);
|
||||
#endif /* WIFI_DEBUG_ON */
|
||||
}
|
||||
break;
|
||||
|
||||
case RW009_CMD_RSSI:
|
||||
// TODO: client RSSI.
|
||||
{
|
||||
rw009_ap_info *ap_info = &resp->resp.ap_info;
|
||||
wifi_device->ap_info.rssi = ap_info->rssi;
|
||||
WIFI_DEBUG("current RSSI: %d\n", wifi_device->ap_info.rssi);
|
||||
}
|
||||
break;
|
||||
|
||||
case RW009_CMD_SOFTAP:
|
||||
{
|
||||
if( resp->result == 0 )
|
||||
{
|
||||
rw009_ap_info *ap_info = &resp->resp.ap_info;
|
||||
wifi_device->ap_info.rssi = ap_info->rssi;
|
||||
WIFI_DEBUG("current RSSI: %d\n", wifi_device->ap_info.rssi);
|
||||
;
|
||||
wifi_device->active = 1;
|
||||
eth_device_linkchange(&wifi_device->parent, RT_TRUE);
|
||||
}
|
||||
break;
|
||||
else
|
||||
{
|
||||
WIFI_DEBUG("RW009_CMD_EASY_JOIN result: %d\n", resp->result );
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
WIFI_DEBUG("resp_handler %d\n", resp->cmd);
|
||||
|
@ -258,6 +277,10 @@ static rt_err_t rw009_cmd(struct rw009_wifi *wifi_device, uint32_t cmd, void *ar
|
|||
{
|
||||
wifi_cmd->len = sizeof(rw009_cmd_rssi);
|
||||
}
|
||||
else if( cmd == RW009_CMD_SOFTAP )
|
||||
{
|
||||
wifi_cmd->len = sizeof(rw009_cmd_softap);
|
||||
}
|
||||
else
|
||||
{
|
||||
WIFI_DEBUG("unkown RW009 CMD %d\n", cmd);
|
||||
|
@ -603,7 +626,7 @@ static void spi_wifi_data_thread_entry(void *parameter)
|
|||
}
|
||||
}
|
||||
|
||||
rt_err_t rt_hw_wifi_init(const char *spi_device_name)
|
||||
rt_err_t rt_hw_wifi_init(const char *spi_device_name, wifi_mode_t mode)
|
||||
{
|
||||
/* align and struct size check. */
|
||||
RT_ASSERT( (SPI_MAX_DATA_LEN & 0x03) == 0);
|
||||
|
@ -689,10 +712,12 @@ rt_err_t rt_hw_wifi_init(const char *spi_device_name)
|
|||
|
||||
/* init: get mac address */
|
||||
{
|
||||
rw009_cmd_init init;
|
||||
init.mode = mode;
|
||||
WIFI_DEBUG("wifi_control RW009_CMD_INIT\n");
|
||||
rw009_wifi_control((rt_device_t)&rw009_wifi_device,
|
||||
RW009_CMD_INIT,
|
||||
(void *)1); // 0: firmware, 1: STA, 2:AP
|
||||
(void *)&init); // 0: firmware, 1: STA, 2:AP
|
||||
|
||||
}
|
||||
|
||||
|
@ -736,6 +761,28 @@ rt_err_t rw009_join(const char * SSID, const char * passwd)
|
|||
return result;
|
||||
}
|
||||
|
||||
rt_err_t rw009_softap(const char * SSID, const char * passwd,uint32_t security,uint32_t channel)
|
||||
{
|
||||
rt_err_t result;
|
||||
rt_device_t wifi_device;
|
||||
rw009_cmd_softap softap;
|
||||
|
||||
wifi_device = rt_device_find("w0");
|
||||
if(wifi_device == RT_NULL)
|
||||
return -RT_ENOSYS;
|
||||
|
||||
strncpy( softap.ssid, SSID, sizeof(softap.ssid) );
|
||||
strncpy( softap.passwd, passwd, sizeof(softap.passwd) );
|
||||
|
||||
softap.security = security;
|
||||
softap.channel = channel;
|
||||
result = rt_device_control(wifi_device,
|
||||
RW009_CMD_SOFTAP,
|
||||
(void *)&softap);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t rw009_rssi(void)
|
||||
{
|
||||
rt_err_t result;
|
||||
|
|
|
@ -83,6 +83,12 @@ struct spi_data_packet
|
|||
#define SSID_NAME_LENGTH_MAX (32)
|
||||
#define PASSWORD_LENGTH_MAX (64)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MODE_STATION=0,
|
||||
MODE_SOFTAP=1,
|
||||
} wifi_mode_t;
|
||||
|
||||
typedef struct _rw009_ap_info
|
||||
{
|
||||
char ssid[SSID_NAME_LENGTH_MAX];
|
||||
|
@ -122,6 +128,15 @@ typedef struct _rw009_cmd_rssi
|
|||
uint8_t bssid[8]; // 6byte + 2byte PAD.
|
||||
} rw009_cmd_rssi;
|
||||
|
||||
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;
|
||||
|
||||
typedef struct _rw009_resp_join
|
||||
{
|
||||
rw009_ap_info ap_info;
|
||||
|
@ -139,6 +154,7 @@ struct rw009_cmd
|
|||
rw009_cmd_easy_join easy_join;
|
||||
rw009_cmd_join join;
|
||||
rw009_cmd_rssi rssi;
|
||||
rw009_cmd_softap softap;
|
||||
} params;
|
||||
};
|
||||
|
||||
|
@ -162,6 +178,39 @@ struct rw009_resp
|
|||
#define RW009_CMD_JOIN 130
|
||||
#define RW009_CMD_EASY_JOIN 131
|
||||
#define RW009_CMD_RSSI 132
|
||||
#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;
|
||||
|
||||
/* porting */
|
||||
extern void spi_wifi_hw_init(void);
|
||||
|
@ -169,7 +218,9 @@ extern void spi_wifi_int_cmd(rt_bool_t cmd);
|
|||
extern rt_bool_t spi_wifi_is_busy(void);
|
||||
|
||||
/* export API. */
|
||||
extern rt_err_t rt_hw_wifi_init(const char *spi_device_name,wifi_mode_t mode);
|
||||
extern int32_t rw009_rssi(void);
|
||||
extern rt_err_t rw009_join(const char * SSID, const char * passwd);
|
||||
extern rt_err_t rw009_softap(const char * SSID, const char * passwd,uint32_t security,uint32_t channel);
|
||||
|
||||
#endif // SPI_WIFI_H_INCLUDED
|
||||
|
|
Loading…
Reference in New Issue