|
|
@@ -9,15 +9,11 @@
|
|
|
* 2014-09-18 aozima update command & response.
|
|
|
* 2017-07-28 armink fix auto reconnect feature
|
|
|
* 2018-12-24 zyh porting rw007 from rw009
|
|
|
+ * 2019-02-25 zyh porting rw007 to wlan
|
|
|
*/
|
|
|
-
|
|
|
-#include <drivers/spi.h>
|
|
|
#include <rtthread.h>
|
|
|
+#include <rtdevice.h>
|
|
|
|
|
|
-#include "lwipopts.h"
|
|
|
-#include <lwip/icmp.h>
|
|
|
-#include <netif/etharp.h>
|
|
|
-#include <netif/ethernetif.h>
|
|
|
|
|
|
#ifndef RW007_LOG_LEVEL
|
|
|
#define RW007_LOG_LEVEL DBG_LOG
|
|
|
@@ -29,246 +25,14 @@
|
|
|
#define DBG_COLOR
|
|
|
#include <rtdbg.h>
|
|
|
|
|
|
-/********************************* RW007 **************************************/
|
|
|
+
|
|
|
#include "spi_wifi_rw007.h"
|
|
|
|
|
|
-static struct rw007_wifi rw007_wifi_device;
|
|
|
+static struct rw007_spi rw007_spi;
|
|
|
+static struct rw007_wifi wifi_sta, wifi_ap;
|
|
|
static struct rt_event spi_wifi_data_event;
|
|
|
|
|
|
-static void resp_handler(struct rw007_wifi *wifi_device, struct rw007_resp *resp)
|
|
|
-{
|
|
|
- struct rw007_resp *resp_return = RT_NULL;
|
|
|
-
|
|
|
- switch (resp->cmd)
|
|
|
- {
|
|
|
- case RW007_CMD_INIT:
|
|
|
- rt_kprintf("[RW007] rw007 init done\n");
|
|
|
- resp_return = (struct rw007_resp *)rt_malloc(member_offset(struct rw007_resp, resp) + sizeof(rw007_resp_init)); //TODO:
|
|
|
- if (resp_return == RT_NULL)
|
|
|
- break;
|
|
|
- memcpy(resp_return, resp, member_offset(struct rw007_resp, resp) + sizeof(rw007_resp_init));
|
|
|
-
|
|
|
- rt_kprintf("[RW007] sn:%-*.*s\n", sizeof(resp->resp.init.sn), sizeof(resp->resp.init.sn), resp->resp.init.sn);
|
|
|
- rt_kprintf("[RW007] version:%-*.*s\n", sizeof(resp->resp.init.version), sizeof(resp->resp.init.version), resp->resp.init.version);
|
|
|
-
|
|
|
- rt_memcpy(wifi_device->dev_addr, resp->resp.init.mac, 6);
|
|
|
- break;
|
|
|
-
|
|
|
- case RW007_CMD_SCAN:
|
|
|
- if (resp->len == sizeof(rw007_ap_info))
|
|
|
- {
|
|
|
- rw007_ap_info *ap_scan = rt_realloc(wifi_device->ap_scan, sizeof(rw007_ap_info) * (wifi_device->ap_scan_count + 1));
|
|
|
- if (ap_scan != RT_NULL)
|
|
|
- {
|
|
|
- memcpy(&ap_scan[wifi_device->ap_scan_count], &resp->resp.ap_info, sizeof(rw007_ap_info));
|
|
|
-
|
|
|
-#if defined(DBG_ENABLE)
|
|
|
- {
|
|
|
- rw007_ap_info *ap_info = &resp->resp.ap_info;
|
|
|
-
|
|
|
- LOG_D("SCAN SSID:%-32.32s", ap_info->ssid);
|
|
|
- LOG_D("SCAN BSSID:%02X-%02X-%02X-%02X-%02X-%02X",
|
|
|
- ap_info->bssid[0],
|
|
|
- ap_info->bssid[1],
|
|
|
- ap_info->bssid[2],
|
|
|
- ap_info->bssid[3],
|
|
|
- ap_info->bssid[4],
|
|
|
- ap_info->bssid[5]);
|
|
|
- LOG_D("SCAN rssi:%ddBm", ap_info->rssi);
|
|
|
- LOG_D("SCAN rate:%dMbps", ap_info->max_data_rate / 1000);
|
|
|
- LOG_D("SCAN channel:%d", ap_info->channel);
|
|
|
- LOG_D("SCAN security:%08X", ap_info->security);
|
|
|
- }
|
|
|
-#endif
|
|
|
- wifi_device->ap_scan_count++;
|
|
|
- wifi_device->ap_scan = ap_scan;
|
|
|
- }
|
|
|
-
|
|
|
- return; /* wait for next ap */
|
|
|
- }
|
|
|
- break;
|
|
|
- case RW007_CMD_JOIN:
|
|
|
- case RW007_CMD_EASY_JOIN:
|
|
|
- LOG_D("resp_handler RW007_CMD_EASY_JOIN");
|
|
|
- resp_return = (struct rw007_resp *)rt_malloc(member_offset(struct rw007_resp, resp) + sizeof(rw007_resp_join)); //TODO:
|
|
|
- if (resp_return == RT_NULL)
|
|
|
- break;
|
|
|
- memcpy(resp_return, resp, member_offset(struct rw007_resp, resp) + sizeof(rw007_resp_join));
|
|
|
-
|
|
|
- if (resp->result == 0)
|
|
|
- {
|
|
|
- memcpy(&wifi_device->ap_info, &resp_return->resp.ap_info, sizeof(rw007_resp_join));
|
|
|
- wifi_device->active = 1;
|
|
|
- eth_device_linkchange(&wifi_device->parent, RT_TRUE);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- wifi_device->active = 1;
|
|
|
- eth_device_linkchange(&wifi_device->parent, RT_FALSE);
|
|
|
- LOG_I("RW007_CMD_EASY_JOIN result: %d", resp->result);
|
|
|
- }
|
|
|
- {
|
|
|
- rw007_ap_info *ap_info = &resp->resp.ap_info;
|
|
|
- wifi_device->ap_info = *ap_info;
|
|
|
-#if defined(DBG_ENABLE)
|
|
|
-
|
|
|
-
|
|
|
- if(ap_info->channel == 0)
|
|
|
- {
|
|
|
- rt_kprintf("[RW007] WIFI Connect failed!\n");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- rt_kprintf("[RW007] WIFI Connected!\n");
|
|
|
- LOG_D("JOIN SSID:%-32.32s", ap_info->ssid);
|
|
|
- LOG_D("JOIN BSSID:%02X-%02X-%02X-%02X-%02X-%02X",
|
|
|
- ap_info->bssid[0],
|
|
|
- ap_info->bssid[1],
|
|
|
- ap_info->bssid[2],
|
|
|
- ap_info->bssid[3],
|
|
|
- ap_info->bssid[4],
|
|
|
- ap_info->bssid[5]);
|
|
|
- LOG_D("JOIN rssi:%ddBm", ap_info->rssi);
|
|
|
- LOG_D("JOIN rate:%dMbps", ap_info->max_data_rate / 1000);
|
|
|
- LOG_D("JOIN channel:%d", ap_info->channel);
|
|
|
- LOG_D("JOIN security:%08X", ap_info->security);
|
|
|
-
|
|
|
- }
|
|
|
-#endif
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case RW007_CMD_RSSI:
|
|
|
- {
|
|
|
- wifi_device->ap_info.rssi = *((int *)&resp->resp);
|
|
|
- rt_kprintf("[RW007] current RSSI: %ddBm\n", wifi_device->ap_info.rssi);
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case RW007_CMD_SOFTAP:
|
|
|
- {
|
|
|
- if (resp->result == 0)
|
|
|
- {
|
|
|
- wifi_device->active = 1;
|
|
|
- eth_device_linkchange(&wifi_device->parent, RT_TRUE);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LOG_I("RW007_CMD_EASY_JOIN result: %d", resp->result);
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- LOG_W("unknow resp_handler %d", resp->cmd);
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if (resp->cmd == wifi_device->last_cmd)
|
|
|
- {
|
|
|
- rt_mb_send(&wifi_device->rw007_cmd_mb, (rt_uint32_t)resp_return);
|
|
|
- return;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- rt_free(resp_return);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static rt_err_t rw007_cmd(struct rw007_wifi *wifi_device, uint32_t cmd, void *args)
|
|
|
-{
|
|
|
- rt_err_t result = RT_EOK;
|
|
|
- rt_int32_t timeout = RW007_CMD_TIMEOUT;
|
|
|
-
|
|
|
- struct spi_data_packet *data_packet;
|
|
|
- struct rw007_cmd *wifi_cmd = RT_NULL;
|
|
|
- struct rw007_resp *resp = RT_NULL;
|
|
|
-
|
|
|
- wifi_device->last_cmd = cmd;
|
|
|
-
|
|
|
- data_packet = (struct spi_data_packet *)rt_mp_alloc(&wifi_device->spi_tx_mp, RT_WAITING_FOREVER);
|
|
|
- wifi_cmd = (struct rw007_cmd *)data_packet->buffer;
|
|
|
-
|
|
|
- wifi_cmd->cmd = cmd;
|
|
|
- wifi_cmd->len = 0;
|
|
|
-
|
|
|
- if (cmd == RW007_CMD_INIT)
|
|
|
- {
|
|
|
- wifi_cmd->len = sizeof(rw007_cmd_init);
|
|
|
- }
|
|
|
- else if (cmd == RW007_CMD_SCAN)
|
|
|
- {
|
|
|
- wifi_cmd->len = 0;
|
|
|
- timeout += RT_TICK_PER_SECOND * 10;
|
|
|
-
|
|
|
- if (wifi_device->ap_scan)
|
|
|
- {
|
|
|
- rt_free(wifi_device->ap_scan);
|
|
|
- wifi_device->ap_scan = RT_NULL;
|
|
|
- wifi_device->ap_scan_count = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- else if (cmd == RW007_CMD_JOIN)
|
|
|
- {
|
|
|
- wifi_cmd->len = sizeof(rw007_cmd_join);
|
|
|
- }
|
|
|
- else if (cmd == RW007_CMD_EASY_JOIN)
|
|
|
- {
|
|
|
- wifi_cmd->len = sizeof(rw007_cmd_easy_join);
|
|
|
- timeout += RT_TICK_PER_SECOND * 5;
|
|
|
- }
|
|
|
- else if (cmd == RW007_CMD_RSSI)
|
|
|
- {
|
|
|
- wifi_cmd->len = sizeof(rw007_cmd_rssi);
|
|
|
- }
|
|
|
- else if (cmd == RW007_CMD_SOFTAP)
|
|
|
- {
|
|
|
- wifi_cmd->len = sizeof(rw007_cmd_softap);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LOG_E("unkown RW007 CMD %d", cmd);
|
|
|
- result = -RT_ENOSYS;
|
|
|
- rt_mp_free(data_packet);
|
|
|
- data_packet = RT_NULL;
|
|
|
- }
|
|
|
-
|
|
|
- if (data_packet == RT_NULL)
|
|
|
- {
|
|
|
- goto _exit;
|
|
|
- }
|
|
|
-
|
|
|
- if (wifi_cmd->len)
|
|
|
- memcpy(&wifi_cmd->params, args, wifi_cmd->len);
|
|
|
-
|
|
|
- data_packet->data_type = data_type_cmd;
|
|
|
- data_packet->data_len = member_offset(struct rw007_cmd, params) + wifi_cmd->len;
|
|
|
-
|
|
|
- rt_mb_send(&wifi_device->spi_tx_mb, (rt_uint32_t)data_packet);
|
|
|
- rt_event_send(&spi_wifi_data_event, 1);
|
|
|
-
|
|
|
- result = rt_mb_recv(&wifi_device->rw007_cmd_mb,
|
|
|
- (rt_ubase_t *)&resp,
|
|
|
- timeout);
|
|
|
-
|
|
|
- if (result != RT_EOK)
|
|
|
- {
|
|
|
- LOG_E("CMD %d error, result %d", cmd, result);
|
|
|
- }
|
|
|
-
|
|
|
- if (resp != RT_NULL)
|
|
|
- result = resp->result;
|
|
|
-
|
|
|
-_exit:
|
|
|
- wifi_device->last_cmd = 0;
|
|
|
- if (resp)
|
|
|
- {
|
|
|
- rt_free(resp);
|
|
|
- }
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-static rt_err_t spi_wifi_transfer(struct rw007_wifi *dev)
|
|
|
+static rt_err_t spi_wifi_transfer(struct rw007_spi *dev)
|
|
|
{
|
|
|
struct pbuf *p = RT_NULL;
|
|
|
struct spi_cmd_request cmd;
|
|
|
@@ -276,9 +40,7 @@ static rt_err_t spi_wifi_transfer(struct rw007_wifi *dev)
|
|
|
|
|
|
rt_err_t result;
|
|
|
const struct spi_data_packet *data_packet = RT_NULL;
|
|
|
-
|
|
|
- struct rw007_wifi *wifi_device = (struct rw007_wifi *)dev;
|
|
|
- struct rt_spi_device *rt_spi_device = wifi_device->rt_spi_device;
|
|
|
+ struct rt_spi_device *rt_spi_device = dev->spi_device;
|
|
|
|
|
|
/* Disable INT Pin interrupt */
|
|
|
spi_wifi_int_cmd(0);
|
|
|
@@ -299,7 +61,7 @@ static rt_err_t spi_wifi_transfer(struct rw007_wifi *dev)
|
|
|
cmd.flag |= CMD_FLAG_MRDY;
|
|
|
|
|
|
/* Try get data to send to rw007 */
|
|
|
- result = rt_mb_recv(&wifi_device->spi_tx_mb,
|
|
|
+ result = rt_mb_recv(&dev->spi_tx_mb,
|
|
|
(rt_ubase_t *)&data_packet,
|
|
|
0);
|
|
|
/* Set length for master to slave when data ready*/
|
|
|
@@ -360,7 +122,7 @@ static rt_err_t spi_wifi_transfer(struct rw007_wifi *dev)
|
|
|
_bad_resp_magic:
|
|
|
/* Setup message */
|
|
|
message.send_buf = data_packet;
|
|
|
- message.recv_buf = wifi_device->spi_hw_rx_buffer;
|
|
|
+ message.recv_buf = dev->spi_hw_rx_buffer;
|
|
|
message.length = RT_ALIGN(max_data_len, 4);/* align clk to word */
|
|
|
message.cs_take = 0;
|
|
|
message.cs_release = 1;
|
|
|
@@ -381,22 +143,50 @@ static rt_err_t spi_wifi_transfer(struct rw007_wifi *dev)
|
|
|
/* Parse recevied data */
|
|
|
if ((resp.S2M_len) && (resp.S2M_len <= MAX_SPI_PACKET_SIZE))
|
|
|
{
|
|
|
- data_packet = (struct spi_data_packet *)wifi_device->spi_hw_rx_buffer;
|
|
|
- if (data_packet->data_type == data_type_eth_data)
|
|
|
+ data_packet = (struct spi_data_packet *)dev->spi_hw_rx_buffer;
|
|
|
+ if (data_packet->data_type == data_type_sta_eth_data)
|
|
|
{
|
|
|
-
|
|
|
- if (wifi_device->active)
|
|
|
+ rt_wlan_dev_report_data(wifi_sta.wlan, (void *)data_packet->buffer, data_packet->data_len);
|
|
|
+ }
|
|
|
+ else if (data_packet->data_type == data_type_ap_eth_data)
|
|
|
+ {
|
|
|
+ rt_wlan_dev_report_data(wifi_ap.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;
|
|
|
+ if(resp->cmd == RT_WLAN_DEV_EVT_SCAN_REPORT)
|
|
|
{
|
|
|
- p = pbuf_alloc(PBUF_LINK, data_packet->data_len, PBUF_RAM);
|
|
|
- pbuf_take(p, (rt_uint8_t *)data_packet->buffer, data_packet->data_len);
|
|
|
+ struct rt_wlan_buff buff;
|
|
|
+ struct rt_wlan_info * wlan_info;
|
|
|
+ wlan_info = (struct rt_wlan_info *)&resp->value;
|
|
|
+ buff.data = wlan_info;
|
|
|
+ buff.len = sizeof(struct rt_wlan_info);
|
|
|
|
|
|
- rt_mb_send(&wifi_device->eth_rx_mb, (rt_uint32_t)p);
|
|
|
- eth_device_ready((struct eth_device *)dev);
|
|
|
+ rt_wlan_dev_indicate_event_handle(wifi_sta.wlan, RT_WLAN_DEV_EVT_SCAN_REPORT, &buff);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rt_wlan_dev_indicate_event_handle(wifi_sta.wlan, resp->cmd, RT_NULL);
|
|
|
}
|
|
|
}
|
|
|
else if (data_packet->data_type == data_type_resp)
|
|
|
{
|
|
|
- resp_handler(dev, (struct rw007_resp *)data_packet->buffer);
|
|
|
+ struct rw00x_resp * resp = (struct rw00x_resp *)data_packet->buffer;
|
|
|
+ if(resp->cmd < RW00x_CMD_MAX_NUM)
|
|
|
+ {
|
|
|
+ if(dev->resp[resp->cmd])
|
|
|
+ {
|
|
|
+ rt_free(dev->resp[resp->cmd]);
|
|
|
+ }
|
|
|
+
|
|
|
+ dev->resp[resp->cmd] = rt_malloc(MAX_SPI_PACKET_SIZE);
|
|
|
+ if(dev->resp[resp->cmd])
|
|
|
+ {
|
|
|
+ rt_memcpy(dev->resp[resp->cmd], resp, MAX_SPI_PACKET_SIZE);
|
|
|
+ rt_event_send(dev->rw007_cmd_event, RW00x_CMD_RESP_EVENT(resp->cmd));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -411,206 +201,378 @@ static rt_err_t spi_wifi_transfer(struct rw007_wifi *dev)
|
|
|
return RT_EOK;
|
|
|
}
|
|
|
|
|
|
-/********************************* RT-Thread Ethernet interface begin **************************************/
|
|
|
-static rt_err_t rw007_wifi_init(rt_device_t dev)
|
|
|
+static void spi_wifi_data_thread_entry(void *parameter)
|
|
|
{
|
|
|
- return RT_EOK;
|
|
|
-}
|
|
|
+ rt_uint32_t e;
|
|
|
+ rt_err_t result;
|
|
|
|
|
|
-static rt_err_t rw007_wifi_open(rt_device_t dev, rt_uint16_t oflag)
|
|
|
-{
|
|
|
- return RT_EOK;
|
|
|
-}
|
|
|
+ while (1)
|
|
|
+ {
|
|
|
+ /* receive first event */
|
|
|
+ if (rt_event_recv(&spi_wifi_data_event,
|
|
|
+ 1,
|
|
|
+ RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR,
|
|
|
+ RT_WAITING_FOREVER,
|
|
|
+ &e) != RT_EOK)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
-static rt_err_t rw007_wifi_close(rt_device_t dev)
|
|
|
-{
|
|
|
- return RT_EOK;
|
|
|
+ result = spi_wifi_transfer(&rw007_spi);
|
|
|
+
|
|
|
+ if (result == RT_EOK)
|
|
|
+ {
|
|
|
+ rt_event_send(&spi_wifi_data_event, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-static rt_size_t rw007_wifi_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
|
|
|
+rt_inline struct rw007_wifi *wifi_get_dev_by_wlan(struct rt_wlan_device *wlan)
|
|
|
{
|
|
|
- rt_set_errno(-RT_ENOSYS);
|
|
|
- return 0;
|
|
|
+ if (wlan == wifi_sta.wlan)
|
|
|
+ {
|
|
|
+ return &wifi_sta;
|
|
|
+ }
|
|
|
+ if (wlan == RT_NULL)
|
|
|
+ {
|
|
|
+ return RT_NULL;
|
|
|
+ }
|
|
|
+ return RT_NULL;
|
|
|
}
|
|
|
|
|
|
-static rt_size_t rw007_wifi_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
|
|
|
+rt_inline void spi_send_cmd(struct rw007_spi * hspi, RW00x_CMD COMMAND, void * buffer, rt_uint32_t len)
|
|
|
{
|
|
|
- rt_set_errno(-RT_ENOSYS);
|
|
|
- return 0;
|
|
|
+ struct spi_data_packet * data_packet;
|
|
|
+ struct rw00x_cmd * cmd;
|
|
|
+
|
|
|
+ data_packet = rt_mp_alloc(&hspi->spi_tx_mp, RT_WAITING_FOREVER);
|
|
|
+ data_packet->data_type = data_type_cmd;
|
|
|
+
|
|
|
+ cmd = (struct rw00x_cmd *)data_packet->buffer;
|
|
|
+ cmd->cmd = COMMAND;
|
|
|
+ cmd->len = len;
|
|
|
+ if(cmd->len)
|
|
|
+ {
|
|
|
+ rt_memcpy(&cmd->value, buffer, cmd->len);
|
|
|
+ }
|
|
|
+
|
|
|
+ data_packet->data_len = member_offset(struct rw00x_cmd, value) + cmd->len;
|
|
|
+
|
|
|
+ rt_mb_send(&hspi->spi_tx_mb, (rt_uint32_t)data_packet);
|
|
|
+ rt_event_send(&spi_wifi_data_event, 1);
|
|
|
}
|
|
|
|
|
|
-static rt_err_t rw007_wifi_control(rt_device_t dev, int cmd, void *args)
|
|
|
+rt_inline rt_err_t spi_set_data(struct rt_wlan_device *wlan, RW00x_CMD COMMAND, void * buffer, rt_uint32_t len)
|
|
|
{
|
|
|
- struct rw007_wifi *wifi_device = (struct rw007_wifi *)dev;
|
|
|
+ struct rw007_spi * hspi = wifi_get_dev_by_wlan(wlan)->hspi;
|
|
|
+ rt_uint32_t result_event;
|
|
|
rt_err_t result = RT_EOK;
|
|
|
-
|
|
|
- if (cmd == NIOCTL_GADDR)
|
|
|
+ spi_send_cmd(hspi, COMMAND, buffer, len);
|
|
|
+ if(rt_event_recv(hspi->rw007_cmd_event,
|
|
|
+ RW00x_CMD_RESP_EVENT(COMMAND),
|
|
|
+ RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR,
|
|
|
+ rt_tick_from_millisecond(10000),
|
|
|
+ &result_event) != RT_EOK)
|
|
|
{
|
|
|
- memcpy(args, wifi_device->dev_addr, 6);
|
|
|
+ return -RT_ETIMEOUT;
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ if(hspi->resp[COMMAND])
|
|
|
{
|
|
|
- result = rw007_cmd(wifi_device, cmd, args);
|
|
|
+ result = hspi->resp[COMMAND]->result;
|
|
|
+ rt_free(hspi->resp[COMMAND]);
|
|
|
+ hspi->resp[COMMAND] = RT_NULL;
|
|
|
+ return result;
|
|
|
}
|
|
|
-
|
|
|
- return result;
|
|
|
+ return RT_EOK;
|
|
|
}
|
|
|
|
|
|
-/* transmit packet. */
|
|
|
-rt_err_t rw007_wifi_tx(rt_device_t dev, struct pbuf *p)
|
|
|
+rt_inline rt_err_t spi_get_data(struct rt_wlan_device *wlan, RW00x_CMD COMMAND, void * buffer, rt_uint32_t *len)
|
|
|
{
|
|
|
+ struct rw007_spi * hspi = wifi_get_dev_by_wlan(wlan)->hspi;
|
|
|
+ rt_uint32_t result_event;
|
|
|
rt_err_t result = RT_EOK;
|
|
|
- struct spi_data_packet *data_packet;
|
|
|
- struct rw007_wifi *wifi_device = (struct rw007_wifi *)dev;
|
|
|
-
|
|
|
- if (!wifi_device->active)
|
|
|
+ spi_send_cmd(hspi, COMMAND, RT_NULL, 0);
|
|
|
+ if(rt_event_recv(hspi->rw007_cmd_event,
|
|
|
+ RW00x_CMD_RESP_EVENT(COMMAND),
|
|
|
+ RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR,
|
|
|
+ rt_tick_from_millisecond(10000),
|
|
|
+ &result_event) != RT_EOK)
|
|
|
{
|
|
|
- return RT_EOK;
|
|
|
+ return -RT_ETIMEOUT;
|
|
|
}
|
|
|
|
|
|
- /* get free tx buffer */
|
|
|
- data_packet = (struct spi_data_packet *)rt_mp_alloc(&wifi_device->spi_tx_mp, RT_WAITING_FOREVER);
|
|
|
- if (data_packet != RT_NULL)
|
|
|
+ if(hspi->resp[COMMAND])
|
|
|
{
|
|
|
- data_packet->data_type = data_type_eth_data;
|
|
|
- data_packet->data_len = p->tot_len;
|
|
|
+ *len = hspi->resp[COMMAND]->len;
|
|
|
+ rt_memcpy(buffer, &hspi->resp[COMMAND]->value, hspi->resp[COMMAND]->len);
|
|
|
+ result = hspi->resp[COMMAND]->result;
|
|
|
+ rt_free(hspi->resp[COMMAND]);
|
|
|
+ hspi->resp[COMMAND] = RT_NULL;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return RT_EOK;
|
|
|
+}
|
|
|
|
|
|
- pbuf_copy_partial(p, data_packet->buffer, data_packet->data_len, 0);
|
|
|
+rt_err_t rw007_sn_get(char sn[24])
|
|
|
+{
|
|
|
+ rt_uint32_t size_of_data;
|
|
|
+ return spi_get_data(wifi_sta.wlan, RW00x_CMD_GET_SN, sn, &size_of_data);
|
|
|
+}
|
|
|
|
|
|
- rt_mb_send(&wifi_device->spi_tx_mb, (rt_uint32_t)data_packet);
|
|
|
- rt_event_send(&spi_wifi_data_event, 1);
|
|
|
- }
|
|
|
- else
|
|
|
- return -RT_ERROR;
|
|
|
+rt_err_t rw007_version_get(char version[16])
|
|
|
+{
|
|
|
+ rt_uint32_t size_of_data;
|
|
|
+ return spi_get_data(wifi_sta.wlan, RW00x_CMD_GET_VSR, version, &size_of_data);
|
|
|
+}
|
|
|
|
|
|
- /* Return SUCCESS */
|
|
|
- return result;
|
|
|
+static rt_err_t wlan_init(struct rt_wlan_device *wlan)
|
|
|
+{
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_INIT, RT_NULL, 0);
|
|
|
}
|
|
|
|
|
|
-/* reception packet. */
|
|
|
-struct pbuf *rw007_wifi_rx(rt_device_t dev)
|
|
|
+static rt_err_t wlan_mode(struct rt_wlan_device *wlan, rt_wlan_mode_t mode)
|
|
|
{
|
|
|
- struct pbuf *p = RT_NULL;
|
|
|
- struct rw007_wifi *wifi_device = (struct rw007_wifi *)dev;
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_SET_MODE, &mode, sizeof(mode));
|
|
|
+}
|
|
|
|
|
|
- if (rt_mb_recv(&wifi_device->eth_rx_mb, (rt_ubase_t *)&p, 0) != RT_EOK)
|
|
|
- {
|
|
|
- return RT_NULL;
|
|
|
- }
|
|
|
+static rt_err_t wlan_scan(struct rt_wlan_device *wlan, struct rt_scan_info *scan_info)
|
|
|
+{
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_SCAN, RT_NULL, 0);
|
|
|
+}
|
|
|
|
|
|
- return p;
|
|
|
+static rt_err_t wlan_join(struct rt_wlan_device *wlan, struct rt_sta_info *sta_info)
|
|
|
+{
|
|
|
+ struct rw00x_ap_info_value value;
|
|
|
+ value.info.security = sta_info->security;
|
|
|
+ value.info.band = RT_802_11_BAND_2_4GHZ;
|
|
|
+ value.info.datarate = 0;
|
|
|
+ value.info.channel = sta_info->channel;
|
|
|
+ value.info.hidden = 0;
|
|
|
+ value.info.rssi = 0;
|
|
|
+ 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);
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_JOIN, &value, sizeof(value));
|
|
|
}
|
|
|
-/********************************* RT-Thread Ethernet interface end **************************************/
|
|
|
|
|
|
-static void spi_wifi_data_thread_entry(void *parameter)
|
|
|
+static rt_err_t wlan_softap(struct rt_wlan_device *wlan, struct rt_ap_info *ap_info)
|
|
|
{
|
|
|
- rt_uint32_t e;
|
|
|
- rt_err_t result;
|
|
|
+ struct rw00x_ap_info_value value;
|
|
|
+ value.info.security = ap_info->security;
|
|
|
+ value.info.band = RT_802_11_BAND_2_4GHZ;
|
|
|
+ value.info.datarate = 0;
|
|
|
+ value.info.channel = ap_info->channel;
|
|
|
+ value.info.hidden = ap_info->hidden;
|
|
|
+ value.info.rssi = 0;
|
|
|
+ value.info.ssid = ap_info->ssid;
|
|
|
+ strncpy(value.passwd, (const char *)&ap_info->key.val[0], ap_info->key.len);
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_SOFTAP, &value, sizeof(value));
|
|
|
+}
|
|
|
|
|
|
- while (1)
|
|
|
+static rt_err_t wlan_disconnect(struct rt_wlan_device *wlan)
|
|
|
+{
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_DISCONNECT, RT_NULL, 0);
|
|
|
+}
|
|
|
+
|
|
|
+static rt_err_t wlan_ap_stop(struct rt_wlan_device *wlan)
|
|
|
+{
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_AP_STOP, RT_NULL, 0);
|
|
|
+}
|
|
|
+
|
|
|
+static rt_err_t wlan_ap_deauth(struct rt_wlan_device *wlan, rt_uint8_t mac[])
|
|
|
+{
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_AP_DEAUTH, mac, 6);
|
|
|
+}
|
|
|
+
|
|
|
+static rt_err_t wlan_scan_stop(struct rt_wlan_device *wlan)
|
|
|
+{
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_SCAN_STOP, RT_NULL, 0);
|
|
|
+}
|
|
|
+
|
|
|
+static int wlan_get_rssi(struct rt_wlan_device *wlan)
|
|
|
+{
|
|
|
+ int rssi = -1;
|
|
|
+ rt_uint32_t size_of_data;
|
|
|
+ spi_get_data(wlan, RW00x_CMD_GET_RSSI, &rssi, &size_of_data);
|
|
|
+ return rssi;
|
|
|
+}
|
|
|
+
|
|
|
+static rt_err_t wlan_set_powersave(struct rt_wlan_device *wlan, int level)
|
|
|
+{
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_SET_PWR_SAVE, &level, sizeof(level));
|
|
|
+}
|
|
|
+
|
|
|
+static int wlan_get_powersave(struct rt_wlan_device *wlan)
|
|
|
+{
|
|
|
+ int level = -1;
|
|
|
+ rt_uint32_t size_of_data;
|
|
|
+ spi_get_data(wlan, RW00x_CMD_GET_PWR_SAVE, &level, &size_of_data);
|
|
|
+ return level;
|
|
|
+}
|
|
|
+
|
|
|
+static rt_err_t wlan_cfg_promisc(struct rt_wlan_device *wlan, rt_bool_t start)
|
|
|
+{
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_CFG_PROMISC, &start, sizeof(start));
|
|
|
+}
|
|
|
+
|
|
|
+static rt_err_t wlan_cfg_filter(struct rt_wlan_device *wlan, struct rt_wlan_filter *filter)
|
|
|
+{
|
|
|
+ return -RT_ENOSYS;
|
|
|
+}
|
|
|
+
|
|
|
+static rt_err_t wlan_set_channel(struct rt_wlan_device *wlan, int channel)
|
|
|
+{
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_SET_CHANNEL, &channel, sizeof(channel));
|
|
|
+}
|
|
|
+
|
|
|
+static int wlan_get_channel(struct rt_wlan_device *wlan)
|
|
|
+{
|
|
|
+ int channel = -1;
|
|
|
+ rt_uint32_t size_of_data;
|
|
|
+ spi_get_data(wlan, RW00x_CMD_GET_CHANNEL, &channel, &size_of_data);
|
|
|
+ return channel;
|
|
|
+}
|
|
|
+
|
|
|
+static rt_err_t wlan_set_country(struct rt_wlan_device *wlan, rt_country_code_t country_code)
|
|
|
+{
|
|
|
+ return spi_set_data(wlan, RW00x_CMD_SET_COUNTRY, &country_code, sizeof(country_code));
|
|
|
+}
|
|
|
+
|
|
|
+static rt_country_code_t wlan_get_country(struct rt_wlan_device *wlan)
|
|
|
+{
|
|
|
+ rt_country_code_t code;
|
|
|
+ rt_uint32_t size_of_data;
|
|
|
+ spi_get_data(wlan, RW00x_CMD_GET_COUNTRY, &code, &size_of_data);
|
|
|
+ return code;
|
|
|
+}
|
|
|
+
|
|
|
+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);
|
|
|
+}
|
|
|
+
|
|
|
+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);
|
|
|
+}
|
|
|
+
|
|
|
+static int wlan_send(struct rt_wlan_device *wlan, void *buff, int len)
|
|
|
+{
|
|
|
+ struct rw007_spi * hspi = wifi_get_dev_by_wlan(wlan)->hspi;
|
|
|
+ struct spi_data_packet * data_packet;
|
|
|
+
|
|
|
+ if(wlan == RT_NULL)
|
|
|
{
|
|
|
- /* receive first event */
|
|
|
- if (rt_event_recv(&spi_wifi_data_event,
|
|
|
- 1,
|
|
|
- RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR,
|
|
|
- RT_WAITING_FOREVER,
|
|
|
- &e) != RT_EOK)
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
|
|
|
- result = spi_wifi_transfer(&rw007_wifi_device);
|
|
|
+ data_packet = rt_mp_alloc(&hspi->spi_tx_mp, RT_WAITING_FOREVER);
|
|
|
|
|
|
- if (result == RT_EOK)
|
|
|
- {
|
|
|
- rt_event_send(&spi_wifi_data_event, 1);
|
|
|
- }
|
|
|
+ if (wlan == wifi_sta.wlan)
|
|
|
+ {
|
|
|
+ data_packet->data_type = data_type_sta_eth_data;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ data_packet->data_type = data_type_ap_eth_data;
|
|
|
}
|
|
|
+
|
|
|
+ data_packet->data_len = len;
|
|
|
+
|
|
|
+ rt_memcpy(data_packet->buffer, buff, len);
|
|
|
+
|
|
|
+ rt_mb_send(&hspi->spi_tx_mb, (rt_uint32_t)data_packet);
|
|
|
+ rt_event_send(&spi_wifi_data_event, 1);
|
|
|
+ return len;
|
|
|
}
|
|
|
|
|
|
-#ifdef RT_USING_DEVICE_OPS
|
|
|
-const static struct rt_device_ops rw007_ops =
|
|
|
- {
|
|
|
- rw007_wifi_init,
|
|
|
- rw007_wifi_open,
|
|
|
- rw007_wifi_close,
|
|
|
- rw007_wifi_read,
|
|
|
- rw007_wifi_write,
|
|
|
- rw007_wifi_control};
|
|
|
-#endif
|
|
|
|
|
|
-rt_err_t rt_hw_wifi_init(const char *spi_device_name, wifi_mode_t mode)
|
|
|
+
|
|
|
+const static struct rt_wlan_dev_ops ops =
|
|
|
+{
|
|
|
+ .wlan_init = wlan_init,
|
|
|
+ .wlan_mode = wlan_mode,
|
|
|
+ .wlan_scan = wlan_scan,
|
|
|
+ .wlan_join = wlan_join,
|
|
|
+ .wlan_softap = wlan_softap,
|
|
|
+ .wlan_disconnect = wlan_disconnect,
|
|
|
+ .wlan_ap_stop = wlan_ap_stop,
|
|
|
+ .wlan_ap_deauth = wlan_ap_deauth,
|
|
|
+ .wlan_scan_stop = wlan_scan_stop,
|
|
|
+ .wlan_get_rssi = wlan_get_rssi,
|
|
|
+ .wlan_set_powersave = wlan_set_powersave,
|
|
|
+ .wlan_get_powersave = wlan_get_powersave,
|
|
|
+ .wlan_cfg_promisc = wlan_cfg_promisc,
|
|
|
+ .wlan_cfg_filter = wlan_cfg_filter,
|
|
|
+ .wlan_set_channel = wlan_set_channel,
|
|
|
+ .wlan_get_channel = wlan_get_channel,
|
|
|
+ .wlan_set_country = wlan_set_country,
|
|
|
+ .wlan_get_country = wlan_get_country,
|
|
|
+ .wlan_set_mac = wlan_set_mac,
|
|
|
+ .wlan_get_mac = wlan_get_mac,
|
|
|
+ .wlan_recv = RT_NULL,
|
|
|
+ .wlan_send = wlan_send,
|
|
|
+};
|
|
|
+
|
|
|
+rt_err_t rt_hw_wifi_init(const char *spi_device_name)
|
|
|
{
|
|
|
+ static struct rt_wlan_device wlan_sta, wlan_ap;
|
|
|
+ rt_err_t ret;
|
|
|
+ wifi_sta.wlan = &wlan_sta;
|
|
|
+ wifi_sta.hspi = &rw007_spi;
|
|
|
+ wifi_ap.wlan = &wlan_ap;
|
|
|
+ wifi_ap.hspi = &rw007_spi;
|
|
|
/* align and struct size check. */
|
|
|
RT_ASSERT((SPI_MAX_DATA_LEN & 0x03) == 0);
|
|
|
- RT_ASSERT(sizeof(struct rw007_resp) <= SPI_MAX_DATA_LEN);
|
|
|
|
|
|
- memset(&rw007_wifi_device, 0, sizeof(struct rw007_wifi));
|
|
|
+ memset(&rw007_spi, 0, sizeof(struct rw007_spi));
|
|
|
|
|
|
- rw007_wifi_device.rt_spi_device = (struct rt_spi_device *)rt_device_find(spi_device_name);
|
|
|
+ rw007_spi.spi_device = (struct rt_spi_device *)rt_device_find(spi_device_name);
|
|
|
|
|
|
- if (rw007_wifi_device.rt_spi_device == RT_NULL)
|
|
|
+ if (rw007_spi.spi_device == RT_NULL)
|
|
|
{
|
|
|
LOG_E("spi device %s not found!\r", spi_device_name);
|
|
|
return -RT_ENOSYS;
|
|
|
}
|
|
|
|
|
|
+ spi_wifi_hw_init();
|
|
|
+
|
|
|
/* config spi */
|
|
|
{
|
|
|
struct rt_spi_configuration cfg;
|
|
|
cfg.data_width = 8;
|
|
|
cfg.mode = RT_SPI_MODE_0 | RT_SPI_MSB; /* SPI Compatible: Mode 0. */
|
|
|
- cfg.max_hz = 30 * 1000000; /* max 30M */
|
|
|
- rt_spi_configure(rw007_wifi_device.rt_spi_device, &cfg);
|
|
|
+ cfg.max_hz = 30 * 1000000; /* 15M 007 max 30M */
|
|
|
+ rt_spi_configure(rw007_spi.spi_device, &cfg);
|
|
|
}
|
|
|
|
|
|
-#ifdef RT_USING_DEVICE_OPS
|
|
|
- rw007_wifi_device.parent.parent.ops = &rw007_ops;
|
|
|
-#else
|
|
|
- rw007_wifi_device.parent.parent.init = rw007_wifi_init;
|
|
|
- rw007_wifi_device.parent.parent.open = rw007_wifi_open;
|
|
|
- rw007_wifi_device.parent.parent.close = rw007_wifi_close;
|
|
|
- rw007_wifi_device.parent.parent.read = rw007_wifi_read;
|
|
|
- rw007_wifi_device.parent.parent.write = rw007_wifi_write;
|
|
|
- rw007_wifi_device.parent.parent.control = rw007_wifi_control;
|
|
|
-#endif
|
|
|
- rw007_wifi_device.parent.parent.user_data = RT_NULL;
|
|
|
-
|
|
|
- rw007_wifi_device.parent.eth_rx = rw007_wifi_rx;
|
|
|
- rw007_wifi_device.parent.eth_tx = rw007_wifi_tx;
|
|
|
-
|
|
|
- rt_mp_init(&rw007_wifi_device.spi_tx_mp,
|
|
|
+ rt_mp_init(&rw007_spi.spi_tx_mp,
|
|
|
"spi_tx",
|
|
|
- &rw007_wifi_device.spi_tx_mempool[0],
|
|
|
- sizeof(rw007_wifi_device.spi_tx_mempool),
|
|
|
+ &rw007_spi.spi_tx_mempool[0],
|
|
|
+ sizeof(rw007_spi.spi_tx_mempool),
|
|
|
sizeof(struct spi_data_packet));
|
|
|
|
|
|
- rt_mp_init(&rw007_wifi_device.spi_rx_mp,
|
|
|
- "spi_rx",
|
|
|
- &rw007_wifi_device.spi_rx_mempool[0],
|
|
|
- sizeof(rw007_wifi_device.spi_rx_mempool),
|
|
|
- sizeof(struct spi_data_packet));
|
|
|
-
|
|
|
- rt_mb_init(&rw007_wifi_device.spi_tx_mb,
|
|
|
+ rt_mb_init(&rw007_spi.spi_tx_mb,
|
|
|
"spi_tx",
|
|
|
- &rw007_wifi_device.spi_tx_mb_pool[0],
|
|
|
+ &rw007_spi.spi_tx_mb_pool[0],
|
|
|
SPI_TX_POOL_SIZE,
|
|
|
RT_IPC_FLAG_PRIO);
|
|
|
-
|
|
|
- rt_mb_init(&rw007_wifi_device.eth_rx_mb,
|
|
|
- "eth_rx",
|
|
|
- &rw007_wifi_device.eth_rx_mb_pool[0],
|
|
|
- SPI_TX_POOL_SIZE,
|
|
|
- RT_IPC_FLAG_PRIO);
|
|
|
-
|
|
|
- rt_mb_init(&rw007_wifi_device.rw007_cmd_mb,
|
|
|
- "wifi_cmd",
|
|
|
- &rw007_wifi_device.rw007_cmd_mb_pool[0],
|
|
|
- sizeof(rw007_wifi_device.rw007_cmd_mb_pool) / 4,
|
|
|
- RT_IPC_FLAG_PRIO);
|
|
|
rt_event_init(&spi_wifi_data_event, "wifi", RT_IPC_FLAG_FIFO);
|
|
|
|
|
|
- spi_wifi_hw_init();
|
|
|
+ rw007_spi.rw007_cmd_event = rt_event_create("wifi_cmd", RT_IPC_FLAG_FIFO);
|
|
|
+
|
|
|
+ ret = rt_wlan_dev_register(&wlan_ap, RT_WLAN_DEVICE_AP_NAME, &ops, 0, &wifi_ap);
|
|
|
+ if (ret != RT_EOK)
|
|
|
+ {
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ ret = rt_wlan_dev_register(&wlan_sta, RT_WLAN_DEVICE_STA_NAME, &ops, 0, &wifi_sta);
|
|
|
+ if (ret != RT_EOK)
|
|
|
+ {
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
{
|
|
|
rt_thread_t tid;
|
|
|
@@ -625,21 +587,7 @@ rt_err_t rt_hw_wifi_init(const char *spi_device_name, wifi_mode_t mode)
|
|
|
if (tid != RT_NULL)
|
|
|
rt_thread_startup(tid);
|
|
|
}
|
|
|
-
|
|
|
- /* init: get mac address */
|
|
|
- {
|
|
|
- rw007_cmd_init init;
|
|
|
- init.mode = mode;
|
|
|
- LOG_D("wifi_control init");
|
|
|
- rw007_wifi_control((rt_device_t)&rw007_wifi_device,
|
|
|
- RW007_CMD_INIT,
|
|
|
- (void *)&init); // 0: firmware, 1: STA, 2:AP
|
|
|
- }
|
|
|
-
|
|
|
- /* register eth device */
|
|
|
- eth_device_init(&(rw007_wifi_device.parent), "w0");
|
|
|
- eth_device_linkchange(&rw007_wifi_device.parent, RT_FALSE);
|
|
|
-
|
|
|
+ rt_event_send(&spi_wifi_data_event, 1);
|
|
|
return RT_EOK;
|
|
|
}
|
|
|
|
|
|
@@ -654,127 +602,4 @@ void spi_wifi_isr(int vector)
|
|
|
rt_interrupt_leave();
|
|
|
}
|
|
|
|
|
|
-/********************************* RW007 tools **************************************/
|
|
|
-rt_err_t rw007_join(const char *SSID, const char *passwd)
|
|
|
-{
|
|
|
- rt_err_t result;
|
|
|
- rt_device_t wifi_device;
|
|
|
- rw007_cmd_easy_join easy_join;
|
|
|
-
|
|
|
- wifi_device = rt_device_find("w0");
|
|
|
- if (wifi_device == RT_NULL)
|
|
|
- return -RT_ENOSYS;
|
|
|
-
|
|
|
- strncpy(easy_join.ssid, SSID, sizeof(easy_join.ssid));
|
|
|
- strncpy(easy_join.passwd, passwd, sizeof(easy_join.passwd));
|
|
|
-
|
|
|
- result = rt_device_control(wifi_device,
|
|
|
- RW007_CMD_EASY_JOIN,
|
|
|
- (void *)&easy_join);
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-rt_err_t rw007_softap(const char *SSID, const char *passwd, uint32_t security, uint32_t channel)
|
|
|
-{
|
|
|
- rt_err_t result;
|
|
|
- rt_device_t wifi_device;
|
|
|
- rw007_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,
|
|
|
- RW007_CMD_SOFTAP,
|
|
|
- (void *)&softap);
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-int32_t rw007_rssi(void)
|
|
|
-{
|
|
|
- rt_err_t result;
|
|
|
- struct rw007_wifi *wifi_device;
|
|
|
- rw007_cmd_rssi rssi_cmd;
|
|
|
-
|
|
|
- wifi_device = (struct rw007_wifi *)rt_device_find("w0");
|
|
|
-
|
|
|
- if (wifi_device == RT_NULL)
|
|
|
- return 0;
|
|
|
-
|
|
|
- if (wifi_device->active == 0)
|
|
|
- return 0;
|
|
|
-
|
|
|
- rt_memcpy(rssi_cmd.bssid, wifi_device->dev_addr, 6);
|
|
|
-
|
|
|
- // SCAN
|
|
|
- result = rt_device_control((rt_device_t)wifi_device,
|
|
|
- RW007_CMD_RSSI,
|
|
|
- &rssi_cmd);
|
|
|
-
|
|
|
- if (result == RT_EOK)
|
|
|
- {
|
|
|
- rt_kprintf("rssi: %d\n", wifi_device->ap_info.rssi);
|
|
|
- return wifi_device->ap_info.rssi;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- rt_kprintf("rssi: error\n");
|
|
|
- }
|
|
|
-
|
|
|
- return (-1);
|
|
|
-}
|
|
|
-
|
|
|
-#ifdef RT_USING_FINSH
|
|
|
-#include <finsh.h>
|
|
|
-
|
|
|
-static rt_err_t rw007_scan(void)
|
|
|
-{
|
|
|
- rt_err_t result;
|
|
|
- struct rw007_wifi *wifi_device;
|
|
|
-
|
|
|
- wifi_device = (struct rw007_wifi *)rt_device_find("w0");
|
|
|
-
|
|
|
- rt_kprintf("being scan \n");
|
|
|
- result = rt_device_control((rt_device_t)wifi_device,
|
|
|
- RW007_CMD_SCAN,
|
|
|
- RT_NULL);
|
|
|
-
|
|
|
- rt_kprintf("scan result:%d", result);
|
|
|
-
|
|
|
- if (result == RT_EOK)
|
|
|
- {
|
|
|
- uint32_t i;
|
|
|
- rw007_ap_info *ap_info;
|
|
|
-
|
|
|
- for (i = 0; i < wifi_device->ap_scan_count; i++)
|
|
|
- {
|
|
|
- ap_info = &wifi_device->ap_scan[i];
|
|
|
- rt_kprintf("AP #%02d SSID: %-32.32s\n", i, ap_info->ssid);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-static int wifi_join(int argc, char *args[])
|
|
|
-{
|
|
|
- if (argc != 3)
|
|
|
- return -1;
|
|
|
- return rw007_join(args[1], args[2]);
|
|
|
-}
|
|
|
-
|
|
|
-FINSH_FUNCTION_EXPORT(rw007_scan, SACN and list AP.);
|
|
|
-FINSH_FUNCTION_EXPORT(rw007_join, RW007 join to AP.);
|
|
|
-FINSH_FUNCTION_EXPORT(rw007_rssi, get RW007 current AP rssi.);
|
|
|
-
|
|
|
-MSH_CMD_EXPORT(wifi_join, wifi_join);
|
|
|
-MSH_CMD_EXPORT(rw007_rssi, rw007_rssi);
|
|
|
-MSH_CMD_EXPORT(rw007_scan, rw007_scan);
|
|
|
-#endif
|