|
|
@@ -12,8 +12,7 @@
|
|
|
* 2019-02-25 zyh porting rw007 to wlan
|
|
|
*/
|
|
|
#include <rtthread.h>
|
|
|
-#include <rtdevice.h>
|
|
|
-
|
|
|
+#include <string.h>
|
|
|
|
|
|
#ifndef RW007_LOG_LEVEL
|
|
|
#define RW007_LOG_LEVEL DBG_LOG
|
|
|
@@ -34,7 +33,6 @@ static struct rt_event spi_wifi_data_event;
|
|
|
|
|
|
static rt_err_t spi_wifi_transfer(struct rw007_spi *dev)
|
|
|
{
|
|
|
- struct pbuf *p = RT_NULL;
|
|
|
struct spi_cmd_request cmd;
|
|
|
struct spi_response resp;
|
|
|
|
|
|
@@ -152,6 +150,10 @@ static rt_err_t spi_wifi_transfer(struct rw007_spi *dev)
|
|
|
{
|
|
|
rt_wlan_dev_report_data(wifi_ap.wlan, (void *)data_packet->buffer, data_packet->data_len);
|
|
|
}
|
|
|
+ else if (data_packet->data_type == data_type_promisc_data)
|
|
|
+ {
|
|
|
+ rt_wlan_dev_promisc_handler(wifi_sta.wlan, (void *)data_packet->buffer, data_packet->data_len);
|
|
|
+ }
|
|
|
else if(data_packet->data_type == data_type_cb)
|
|
|
{
|
|
|
struct rw00x_resp * resp = (struct rw00x_resp *)data_packet->buffer;
|
|
|
@@ -167,7 +169,15 @@ static rt_err_t spi_wifi_transfer(struct rw007_spi *dev)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- rt_wlan_dev_indicate_event_handle(wifi_sta.wlan, resp->cmd, RT_NULL);
|
|
|
+ if(resp->cmd == RT_WLAN_DEV_EVT_AP_START || resp->cmd == RT_WLAN_DEV_EVT_AP_STOP ||
|
|
|
+ resp->cmd == RT_WLAN_DEV_EVT_AP_ASSOCIATED || resp->cmd == RT_WLAN_DEV_EVT_AP_DISASSOCIATED)
|
|
|
+ {
|
|
|
+ rt_wlan_dev_indicate_event_handle(wifi_ap.wlan, (rt_wlan_dev_event_t)resp->cmd, RT_NULL);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rt_wlan_dev_indicate_event_handle(wifi_sta.wlan, (rt_wlan_dev_event_t)resp->cmd, RT_NULL);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
else if (data_packet->data_type == data_type_resp)
|
|
|
@@ -233,9 +243,9 @@ rt_inline struct rw007_wifi *wifi_get_dev_by_wlan(struct rt_wlan_device *wlan)
|
|
|
{
|
|
|
return &wifi_sta;
|
|
|
}
|
|
|
- if (wlan == RT_NULL)
|
|
|
+ if (wlan == wifi_ap.wlan)
|
|
|
{
|
|
|
- return RT_NULL;
|
|
|
+ return &wifi_ap;
|
|
|
}
|
|
|
return RT_NULL;
|
|
|
}
|
|
|
@@ -328,7 +338,13 @@ rt_err_t rw007_version_get(char version[16])
|
|
|
|
|
|
static rt_err_t wlan_init(struct rt_wlan_device *wlan)
|
|
|
{
|
|
|
- return spi_set_data(wlan, RW00x_CMD_INIT, RT_NULL, 0);
|
|
|
+ static int inited = 0;
|
|
|
+ if(!inited)
|
|
|
+ {
|
|
|
+ inited = 1;
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_INIT, RT_NULL, 0);
|
|
|
+ }
|
|
|
+ return RT_EOK;
|
|
|
}
|
|
|
|
|
|
static rt_err_t wlan_mode(struct rt_wlan_device *wlan, rt_wlan_mode_t mode)
|
|
|
@@ -353,6 +369,7 @@ static rt_err_t wlan_join(struct rt_wlan_device *wlan, struct rt_sta_info *sta_i
|
|
|
value.info.ssid = sta_info->ssid;
|
|
|
rt_memcpy(value.info.bssid, sta_info->bssid, 6);
|
|
|
strncpy(value.passwd, (const char *)&sta_info->key.val[0], sta_info->key.len);
|
|
|
+ value.passwd[sta_info->key.len] = '\0';
|
|
|
return spi_set_data(wlan, RW00x_CMD_JOIN, &value, sizeof(value));
|
|
|
}
|
|
|
|
|
|
@@ -367,6 +384,7 @@ static rt_err_t wlan_softap(struct rt_wlan_device *wlan, struct rt_ap_info *ap_i
|
|
|
value.info.rssi = 0;
|
|
|
value.info.ssid = ap_info->ssid;
|
|
|
strncpy(value.passwd, (const char *)&ap_info->key.val[0], ap_info->key.len);
|
|
|
+ value.passwd[ap_info->key.len] = '\0';
|
|
|
return spi_set_data(wlan, RW00x_CMD_SOFTAP, &value, sizeof(value));
|
|
|
}
|
|
|
|
|
|
@@ -449,13 +467,21 @@ static rt_country_code_t wlan_get_country(struct rt_wlan_device *wlan)
|
|
|
|
|
|
static rt_err_t wlan_set_mac(struct rt_wlan_device *wlan, rt_uint8_t mac[])
|
|
|
{
|
|
|
- return spi_set_data(wlan, RW00x_CMD_MAC_SET, mac, 6);
|
|
|
+ if(wlan == wifi_sta.wlan)
|
|
|
+ {
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_MAC_SET, mac, 6);
|
|
|
+ }
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_AP_MAC_SET, mac, 6);
|
|
|
}
|
|
|
|
|
|
static rt_err_t wlan_get_mac(struct rt_wlan_device *wlan, rt_uint8_t mac[])
|
|
|
{
|
|
|
rt_uint32_t size_of_data;
|
|
|
- return spi_get_data(wlan, RW00x_CMD_MAC_GET, mac, &size_of_data);
|
|
|
+ if(wlan == wifi_sta.wlan)
|
|
|
+ {
|
|
|
+ return spi_get_data(wlan, RW00x_CMD_MAC_GET, mac, &size_of_data);
|
|
|
+ }
|
|
|
+ return spi_get_data(wlan, RW00x_CMD_AP_MAC_GET, mac, &size_of_data);
|
|
|
}
|
|
|
|
|
|
static int wlan_send(struct rt_wlan_device *wlan, void *buff, int len)
|