mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-06 22:34:34 +08:00
Merge pull request #1506 from enkiller/dev
[components][drivers]wlan驱动框架更新
This commit is contained in:
commit
97ca1bf1af
@ -2,7 +2,7 @@
|
|||||||
* File : wlan_cmd.c
|
* File : wlan_cmd.c
|
||||||
* Wi-Fi common commands
|
* Wi-Fi common commands
|
||||||
* This file is part of RT-Thread RTOS
|
* This file is part of RT-Thread RTOS
|
||||||
* COPYRIGHT (C) 2006 - 2016, RT-Thread Development Team
|
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -40,6 +40,13 @@ static char wifi_ssid[32] = {0};
|
|||||||
static char wifi_key[32] = {0};
|
static char wifi_key[32] = {0};
|
||||||
static int network_mode = WIFI_STATION;
|
static int network_mode = WIFI_STATION;
|
||||||
|
|
||||||
|
#define WLAN_DEBUG 1
|
||||||
|
#if WLAN_DEBUG
|
||||||
|
#define WLAN_DBG(...) rt_kprintf("[WLAN]"),rt_kprintf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define WLAN_DBG(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef WIFI_SETTING_FN
|
#ifndef WIFI_SETTING_FN
|
||||||
#define WIFI_SETTING_FN "/appfs/setting.json"
|
#define WIFI_SETTING_FN "/appfs/setting.json"
|
||||||
#endif
|
#endif
|
||||||
@ -397,6 +404,7 @@ int wifi(int argc, char** argv)
|
|||||||
/* TODO: use easy-join to replace */
|
/* TODO: use easy-join to replace */
|
||||||
rt_wlan_info_init(&info, WIFI_STATION, SECURITY_WPA2_MIXED_PSK, argv[3]);
|
rt_wlan_info_init(&info, WIFI_STATION, SECURITY_WPA2_MIXED_PSK, argv[3]);
|
||||||
rt_wlan_connect(wlan, &info, argv[4]);
|
rt_wlan_connect(wlan, &info, argv[4]);
|
||||||
|
rt_wlan_info_deinit(&info);
|
||||||
}
|
}
|
||||||
else if (strcmp(argv[2], "up") == 0)
|
else if (strcmp(argv[2], "up") == 0)
|
||||||
{
|
{
|
||||||
@ -406,36 +414,28 @@ int wifi(int argc, char** argv)
|
|||||||
else if (strcmp(argv[2], "down") == 0)
|
else if (strcmp(argv[2], "down") == 0)
|
||||||
{
|
{
|
||||||
rt_wlan_disconnect(wlan);
|
rt_wlan_disconnect(wlan);
|
||||||
|
rt_wlan_info_deinit(&info);
|
||||||
}
|
}
|
||||||
else if (strcmp(argv[2], "scan") == 0)
|
else if (strcmp(argv[2], "scan") == 0)
|
||||||
{
|
{
|
||||||
struct rt_wlan_info *infos;
|
struct rt_wlan_scan_result *scan_result = RT_NULL;
|
||||||
|
|
||||||
infos = (struct rt_wlan_info*)rt_malloc(sizeof(struct rt_wlan_info) * 12);
|
rt_wlan_scan(wlan, &scan_result);
|
||||||
if (infos)
|
if (scan_result)
|
||||||
{
|
{
|
||||||
int index, num;
|
int index, num;
|
||||||
|
|
||||||
memset(infos, 0x0, sizeof(struct rt_wlan_info) * 12);
|
num = scan_result->ap_num;
|
||||||
num = rt_wlan_scan(wlan, infos, 12);
|
rt_kprintf("----Wi-Fi APInformation----\n");
|
||||||
|
|
||||||
for (index = 0; index < num; index ++)
|
for (index = 0; index < num; index ++)
|
||||||
{
|
{
|
||||||
rt_kprintf("----Wi-Fi AP[%d] Information----\n", index);
|
rt_kprintf("SSID:%-.32s, ", scan_result->ap_table[index].ssid);
|
||||||
rt_kprintf("SSID: %-.32s\n", infos[index].ssid);
|
rt_kprintf("rssi:%d, ", scan_result->ap_table[index].rssi);
|
||||||
rt_kprintf("rssi: %d\n", infos[index].rssi);
|
rt_kprintf("chn:%d, ", scan_result->ap_table[index].channel);
|
||||||
rt_kprintf(" chn: %d\n", infos[index].channel);
|
rt_kprintf("rate:%d\n", scan_result->ap_table[index].datarate);
|
||||||
rt_kprintf("rate: %d\n", infos[index].datarate);
|
|
||||||
rt_kprintf("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* de-initialize info */
|
|
||||||
for (index = 0; index < num; index ++)
|
|
||||||
{
|
|
||||||
rt_wlan_info_deinit(&infos[index]);
|
|
||||||
}
|
|
||||||
rt_free(infos);
|
|
||||||
}
|
}
|
||||||
|
rt_wlan_release_scan_result(&scan_result);
|
||||||
}
|
}
|
||||||
else if (strcmp(argv[2], "rssi") == 0)
|
else if (strcmp(argv[2], "rssi") == 0)
|
||||||
{
|
{
|
||||||
|
@ -1,3 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* File : wlan_cmd.h
|
||||||
|
* Wi-Fi common commands
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2018-06-05 RT-Thread first version
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef WLAN_CMD_H__
|
#ifndef WLAN_CMD_H__
|
||||||
#define WLAN_CMD_H__
|
#define WLAN_CMD_H__
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* RT-Thread Wi-Fi Device
|
* RT-Thread Wi-Fi Device
|
||||||
*
|
*
|
||||||
* COPYRIGHT (C) 2014 - 2015, Shanghai Real-Thread Technology Co., Ltd
|
* COPYRIGHT (C) 2014 - 2018, Shanghai Real-Thread Technology Co., Ltd
|
||||||
*
|
*
|
||||||
* This file is part of RT-Thread (http://www.rt-thread.org)
|
* This file is part of RT-Thread (http://www.rt-thread.org)
|
||||||
*
|
*
|
||||||
@ -29,8 +29,6 @@
|
|||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <rtdevice.h>
|
#include <rtdevice.h>
|
||||||
|
|
||||||
#include <lwip/netifapi.h>
|
|
||||||
|
|
||||||
#include "wlan_dev.h"
|
#include "wlan_dev.h"
|
||||||
#include "wlan_cmd.h"
|
#include "wlan_cmd.h"
|
||||||
|
|
||||||
@ -71,6 +69,20 @@ int rt_wlan_init(struct rt_wlan_device* device, rt_wlan_mode_t mode)
|
|||||||
|
|
||||||
if (device == RT_NULL) return 0;
|
if (device == RT_NULL) return 0;
|
||||||
|
|
||||||
|
if (device->info == RT_NULL)
|
||||||
|
{
|
||||||
|
struct rt_wlan_info *info;
|
||||||
|
char *ssid;
|
||||||
|
|
||||||
|
info = rt_malloc(sizeof(struct rt_wlan_info));
|
||||||
|
if (info)
|
||||||
|
{
|
||||||
|
ssid = rt_malloc(SSID_LENGTH_MAX_SIZE);
|
||||||
|
info->ssid = ssid;
|
||||||
|
}
|
||||||
|
device->info = info;
|
||||||
|
}
|
||||||
|
|
||||||
result = rt_device_control(RT_DEVICE(device), WIFI_INIT, (void *)&mode);
|
result = rt_device_control(RT_DEVICE(device), WIFI_INIT, (void *)&mode);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -87,23 +99,9 @@ int rt_wlan_connect(struct rt_wlan_device* device, struct rt_wlan_info* info, ch
|
|||||||
rt_wlan_set_info(device, info);
|
rt_wlan_set_info(device, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = rt_device_control(RT_DEVICE(device), WIFI_EASYJOIN, (void*)password);
|
|
||||||
if (result == RT_EOK)
|
|
||||||
{
|
|
||||||
struct netif *netif = device->parent.netif;
|
|
||||||
|
|
||||||
netifapi_netif_set_up(netif);
|
|
||||||
eth_device_linkchange(&(device->parent), RT_TRUE);
|
|
||||||
|
|
||||||
#ifdef RT_LWIP_DHCP
|
|
||||||
/* set DHCP flags */
|
|
||||||
// netif->flags |= NETIF_FLAG_DHCP;
|
|
||||||
/* start DHCP */
|
|
||||||
dhcp_start(netif);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rt_strncpy((char *)device->key, (char *)password, sizeof(device->key) - 1);
|
rt_strncpy((char *)device->key, (char *)password, sizeof(device->key) - 1);
|
||||||
}
|
|
||||||
|
result = rt_device_control(RT_DEVICE(device), WIFI_EASYJOIN, (void *)password);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -119,16 +117,9 @@ int rt_wlan_softap(struct rt_wlan_device* device, struct rt_wlan_info* info, cha
|
|||||||
rt_wlan_set_info(device, info);
|
rt_wlan_set_info(device, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = rt_device_control(RT_DEVICE(device), WIFI_SOFTAP, (void*)password);
|
|
||||||
if (result == RT_EOK)
|
|
||||||
{
|
|
||||||
rt_strncpy((char *)device->key, (char *)password, sizeof(device->key) - 1);
|
rt_strncpy((char *)device->key, (char *)password, sizeof(device->key) - 1);
|
||||||
|
|
||||||
netifapi_netif_set_up(device->parent.netif);
|
result = rt_device_control(RT_DEVICE(device), WIFI_SOFTAP, (void *)password);
|
||||||
eth_device_linkchange(&(device->parent), RT_TRUE);
|
|
||||||
|
|
||||||
wifi_softap_setup_netif(device->parent.netif);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -141,26 +132,23 @@ int rt_wlan_disconnect(struct rt_wlan_device* device)
|
|||||||
|
|
||||||
/* save event handler */
|
/* save event handler */
|
||||||
result = rt_device_control(RT_DEVICE(device), WIFI_DISCONNECT, RT_NULL);
|
result = rt_device_control(RT_DEVICE(device), WIFI_DISCONNECT, RT_NULL);
|
||||||
if (result == RT_EOK)
|
|
||||||
{
|
|
||||||
netifapi_netif_set_down(device->parent.netif);
|
|
||||||
eth_device_linkchange(&(device->parent), RT_FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rt_wlan_set_info(struct rt_wlan_device *device, struct rt_wlan_info *info)
|
int rt_wlan_set_info(struct rt_wlan_device *device, struct rt_wlan_info *info)
|
||||||
{
|
{
|
||||||
if (device->info == info) return RT_EOK; /* same info */
|
if (device == RT_NULL) return -RT_EIO;
|
||||||
|
if (device->info == RT_NULL) return -RT_EIO;
|
||||||
|
|
||||||
if (device->info != RT_NULL)
|
device->info->mode = info->mode;
|
||||||
{
|
device->info->security = info->security;
|
||||||
rt_wlan_info_deinit(device->info);
|
memset(device->info->ssid, 0, SSID_LENGTH_MAX_SIZE);
|
||||||
rt_free(device->info);
|
memcpy(device->info->ssid, info->ssid, strlen(info->ssid));
|
||||||
}
|
memcpy(device->info->bssid, info->bssid, 6);
|
||||||
|
device->info->datarate = info->datarate;
|
||||||
device->info = info;
|
device->info->channel = info->channel;
|
||||||
|
device->info->rssi = info->rssi;
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
@ -177,21 +165,13 @@ struct rt_wlan_info *rt_wlan_get_info(struct rt_wlan_device* device)
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rt_wlan_scan(struct rt_wlan_device* device, struct rt_wlan_info *infos, int item_sz)
|
int rt_wlan_scan(struct rt_wlan_device *device, struct rt_wlan_scan_result **scan_result)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
struct rt_wlan_info_request request;
|
|
||||||
|
|
||||||
if (device == RT_NULL) return 0;
|
result = rt_device_control(RT_DEVICE(device), WIFI_SCAN, scan_result);
|
||||||
|
|
||||||
request.req_number = item_sz;
|
return result;
|
||||||
request.rsp_number = 0;
|
|
||||||
request.infos = infos;
|
|
||||||
|
|
||||||
result = rt_device_control(RT_DEVICE(device), WIFI_SCAN, (void*)&request);
|
|
||||||
result = result; /* skip warning */
|
|
||||||
|
|
||||||
return request.rsp_number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int rt_wlan_get_rssi(struct rt_wlan_device *device)
|
int rt_wlan_get_rssi(struct rt_wlan_device *device)
|
||||||
@ -234,13 +214,104 @@ int rt_wlan_enter_powersave(struct rt_wlan_device* device, int level)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rt_wlan_set_event_callback(struct rt_wlan_device* device, rt_wlan_event_handler handler,
|
int rt_wlan_register_event_handler(struct rt_wlan_device *device, rt_wlan_event_t event,
|
||||||
void *user_data)
|
rt_wlan_event_handler handler)
|
||||||
{
|
{
|
||||||
if (device == RT_NULL) return ;
|
if (device == RT_NULL) return -RT_EIO;
|
||||||
|
if (event >= WIFI_EVT_MAX) return -RT_EINVAL;
|
||||||
|
|
||||||
device->handler = handler;
|
device->handler[event] = handler;
|
||||||
device->user_data = user_data;
|
|
||||||
|
|
||||||
return ;
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rt_wlan_unregister_event_handler(struct rt_wlan_device *device, rt_wlan_event_t event)
|
||||||
|
{
|
||||||
|
if (device == RT_NULL) return -RT_EIO;
|
||||||
|
if (event >= WIFI_EVT_MAX) return -RT_EINVAL;
|
||||||
|
|
||||||
|
device->handler[event] = RT_NULL;
|
||||||
|
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rt_wlan_indicate_event_handle(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||||
|
{
|
||||||
|
if (device == RT_NULL) return -RT_EIO;
|
||||||
|
if (event >= WIFI_EVT_MAX) return -RT_EINVAL;
|
||||||
|
|
||||||
|
if (device->handler[event] != RT_NULL)
|
||||||
|
device->handler[event](device, event, user_data);
|
||||||
|
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rt_wlan_cfg_monitor(struct rt_wlan_device *device, rt_wlan_monitor_opition_t opition)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
if (device == RT_NULL) return -RT_EIO;
|
||||||
|
|
||||||
|
result = rt_device_control(RT_DEVICE(device), WIFI_CFG_MONITOR, (void *)&opition);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rt_wlan_set_monitor_callback(struct rt_wlan_device *device, rt_wlan_monitor_callback_t callback)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
if (device == RT_NULL) return -RT_EIO;
|
||||||
|
|
||||||
|
result = rt_device_control(RT_DEVICE(device), WIFI_SET_MONITOR_CALLBACK, (void *)callback);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rt_wlan_set_channel(struct rt_wlan_device *device, int channel)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
if (device == RT_NULL) return -RT_EIO;
|
||||||
|
|
||||||
|
result = rt_device_control(RT_DEVICE(device), WIFI_SET_CHANNEL, (void *)&channel);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rt_wlan_get_channel(struct rt_wlan_device *device)
|
||||||
|
{
|
||||||
|
int channel = 0;
|
||||||
|
|
||||||
|
if (device == RT_NULL) return -RT_EIO;
|
||||||
|
|
||||||
|
rt_device_control(RT_DEVICE(device), WIFI_GET_CHANNEL, &channel);
|
||||||
|
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rt_wlan_release_scan_result(struct rt_wlan_scan_result **scan_result)
|
||||||
|
{
|
||||||
|
int i, ap_num;
|
||||||
|
struct rt_wlan_scan_result *_scan_result;
|
||||||
|
|
||||||
|
if (*scan_result != RT_NULL)
|
||||||
|
{
|
||||||
|
_scan_result = *scan_result;
|
||||||
|
ap_num = _scan_result->ap_num;
|
||||||
|
for (i = 0; i < ap_num; i++)
|
||||||
|
{
|
||||||
|
if (_scan_result->ap_table[i].ssid != RT_NULL)
|
||||||
|
{
|
||||||
|
rt_free(_scan_result->ap_table[i].ssid);
|
||||||
|
_scan_result->ap_table[i].ssid = RT_NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_scan_result->ap_num = 0;
|
||||||
|
rt_free(_scan_result->ap_table);
|
||||||
|
_scan_result->ap_table = RT_NULL;
|
||||||
|
}
|
||||||
|
rt_free(*scan_result);
|
||||||
|
*scan_result = RT_NULL;
|
||||||
|
scan_result = RT_NULL;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* RT-Thread Wi-Fi Device
|
* RT-Thread Wi-Fi Device
|
||||||
*
|
*
|
||||||
* COPYRIGHT (C) 2014 - 2015, Shanghai Real-Thread Technology Co., Ltd
|
* COPYRIGHT (C) 2014 - 2018, Shanghai Real-Thread Technology Co., Ltd
|
||||||
*
|
*
|
||||||
* This file is part of RT-Thread (http://www.rt-thread.org)
|
* This file is part of RT-Thread (http://www.rt-thread.org)
|
||||||
*
|
*
|
||||||
@ -25,6 +25,7 @@
|
|||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2014-09-11 Bernard the first verion
|
* 2014-09-11 Bernard the first verion
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef WIFI_DEVICE_H__
|
#ifndef WIFI_DEVICE_H__
|
||||||
#define WIFI_DEVICE_H__
|
#define WIFI_DEVICE_H__
|
||||||
|
|
||||||
@ -33,6 +34,7 @@
|
|||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
WIFI_NONE,
|
||||||
WIFI_STATION,
|
WIFI_STATION,
|
||||||
WIFI_AP,
|
WIFI_AP,
|
||||||
} rt_wlan_mode_t;
|
} rt_wlan_mode_t;
|
||||||
@ -47,6 +49,10 @@ typedef enum
|
|||||||
WIFI_DISCONNECT,
|
WIFI_DISCONNECT,
|
||||||
WIFI_GET_RSSI, /* get sensitivity (dBm) */
|
WIFI_GET_RSSI, /* get sensitivity (dBm) */
|
||||||
WIFI_ENTER_POWERSAVE,
|
WIFI_ENTER_POWERSAVE,
|
||||||
|
WIFI_CFG_MONITOR, /* start/stop minitor */
|
||||||
|
WIFI_SET_CHANNEL,
|
||||||
|
WIFI_GET_CHANNEL,
|
||||||
|
WIFI_SET_MONITOR_CALLBACK,
|
||||||
} rt_wlan_cmd_t;
|
} rt_wlan_cmd_t;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
@ -56,6 +62,12 @@ typedef enum
|
|||||||
WIFI_PWR_NORMAL
|
WIFI_PWR_NORMAL
|
||||||
} rt_wlan_powersave_t;
|
} rt_wlan_powersave_t;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
WIFI_MONITOR_START,
|
||||||
|
WIFI_MONITOR_STOP
|
||||||
|
} rt_wlan_monitor_opition_t;
|
||||||
|
|
||||||
#define SHARED_ENABLED 0x00008000
|
#define SHARED_ENABLED 0x00008000
|
||||||
#define WPA_SECURITY 0x00200000
|
#define WPA_SECURITY 0x00200000
|
||||||
#define WPA2_SECURITY 0x00400000
|
#define WPA2_SECURITY 0x00400000
|
||||||
@ -66,7 +78,7 @@ typedef enum
|
|||||||
#define WSEC_SWFLAG 0x0008
|
#define WSEC_SWFLAG 0x0008
|
||||||
|
|
||||||
#define KEY_ARRAY_SIZE 32
|
#define KEY_ARRAY_SIZE 32
|
||||||
|
#define SSID_LENGTH_MAX_SIZE 32 + 1
|
||||||
/**
|
/**
|
||||||
* Enumeration of Wi-Fi security modes
|
* Enumeration of Wi-Fi security modes
|
||||||
*/
|
*/
|
||||||
@ -88,8 +100,17 @@ typedef enum
|
|||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
WIFI_EVT_INIT_DONE = 0,
|
||||||
WIFI_EVT_LINK_DOWN,
|
WIFI_EVT_LINK_DOWN,
|
||||||
WIFI_EVT_LINK_UP,
|
WIFI_EVT_LINK_UP,
|
||||||
|
WIFI_EVT_CONNECT,
|
||||||
|
WIFI_EVT_DISCONNECT,
|
||||||
|
WIFI_EVT_AP_START,
|
||||||
|
WIFI_EVT_AP_STOP,
|
||||||
|
WIFI_EVENT_STA_ASSOC,
|
||||||
|
WIFI_EVENT_STA_DISASSOC,
|
||||||
|
WIFI_EVT_SCAN_DONE,
|
||||||
|
WIFI_EVT_MAX,
|
||||||
} rt_wlan_event_t;
|
} rt_wlan_event_t;
|
||||||
|
|
||||||
/* wifi network information */
|
/* wifi network information */
|
||||||
@ -117,9 +138,15 @@ struct rt_wlan_info_request
|
|||||||
struct rt_wlan_info *infos;/* the array of information to save response */
|
struct rt_wlan_info *infos;/* the array of information to save response */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct rt_wlan_scan_result
|
||||||
|
{
|
||||||
|
char ap_num;
|
||||||
|
struct rt_wlan_info *ap_table;
|
||||||
|
} rt_wlan_scan_result_t;
|
||||||
|
|
||||||
struct rt_wlan_device;
|
struct rt_wlan_device;
|
||||||
typedef void (*rt_wlan_event_handler)(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data);
|
typedef void (*rt_wlan_event_handler)(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data);
|
||||||
|
typedef void (*rt_wlan_monitor_callback_t)(uint8_t *data, int len, void *user_data);
|
||||||
struct rt_wlan_device
|
struct rt_wlan_device
|
||||||
{
|
{
|
||||||
struct eth_device parent;
|
struct eth_device parent;
|
||||||
@ -127,7 +154,7 @@ struct rt_wlan_device
|
|||||||
struct rt_wlan_info *info;
|
struct rt_wlan_info *info;
|
||||||
char key[KEY_ARRAY_SIZE + 1];
|
char key[KEY_ARRAY_SIZE + 1];
|
||||||
|
|
||||||
rt_wlan_event_handler handler;
|
rt_wlan_event_handler handler[WIFI_EVT_MAX];
|
||||||
void *user_data;
|
void *user_data;
|
||||||
int interface;
|
int interface;
|
||||||
};
|
};
|
||||||
@ -157,7 +184,7 @@ int rt_wlan_set_info(struct rt_wlan_device* device, struct rt_wlan_info* info);
|
|||||||
struct rt_wlan_info *rt_wlan_get_info(struct rt_wlan_device *device);
|
struct rt_wlan_info *rt_wlan_get_info(struct rt_wlan_device *device);
|
||||||
|
|
||||||
/* get the AP result which were scaned in station */
|
/* get the AP result which were scaned in station */
|
||||||
int rt_wlan_scan(struct rt_wlan_device* device, struct rt_wlan_info *infos, int item_sz);
|
int rt_wlan_scan(struct rt_wlan_device *device, struct rt_wlan_scan_result **scan_result);
|
||||||
|
|
||||||
/* get rssi */
|
/* get rssi */
|
||||||
int rt_wlan_get_rssi(struct rt_wlan_device *device);
|
int rt_wlan_get_rssi(struct rt_wlan_device *device);
|
||||||
@ -168,8 +195,26 @@ int rt_wlan_set_mac(struct rt_wlan_device* device,rt_uint8_t hwaddr[6]);
|
|||||||
/* enter power save level */
|
/* enter power save level */
|
||||||
int rt_wlan_enter_powersave(struct rt_wlan_device *device, int level);
|
int rt_wlan_enter_powersave(struct rt_wlan_device *device, int level);
|
||||||
|
|
||||||
void rt_wlan_set_event_callback(struct rt_wlan_device* device, rt_wlan_event_handler handler,
|
/* register the event handler */
|
||||||
|
int rt_wlan_register_event_handler(struct rt_wlan_device *device, rt_wlan_event_t event,
|
||||||
|
rt_wlan_event_handler handler);
|
||||||
|
|
||||||
|
/* un-register the event handler */
|
||||||
|
int rt_wlan_unregister_event_handler(struct rt_wlan_device *device, rt_wlan_event_t event);
|
||||||
|
|
||||||
|
/* wlan driver indicate event to upper layer through wifi_indication. */
|
||||||
|
int rt_wlan_indicate_event_handle(struct rt_wlan_device *device, rt_wlan_event_t event,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
#endif
|
/* start or stop monitor */
|
||||||
|
int rt_wlan_cfg_monitor(struct rt_wlan_device *device, rt_wlan_monitor_opition_t opition);
|
||||||
|
|
||||||
|
/* set callback function for monitor mode*/
|
||||||
|
int rt_wlan_set_monitor_callback(struct rt_wlan_device *device, rt_wlan_monitor_callback_t callback);
|
||||||
|
|
||||||
|
/* Set the monitor channel */
|
||||||
|
int rt_wlan_set_channel(struct rt_wlan_device *device, int channel);
|
||||||
|
|
||||||
|
void rt_wlan_release_scan_result(struct rt_wlan_scan_result **scan_result);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
142
components/drivers/wlan/wlan_mgnt.c
Normal file
142
components/drivers/wlan/wlan_mgnt.c
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* RT-Thread Wi-Fi Device
|
||||||
|
*
|
||||||
|
* COPYRIGHT (C) 2014 - 2018, Shanghai Real-Thread Technology Co., Ltd
|
||||||
|
*
|
||||||
|
* This file is part of RT-Thread (http://www.rt-thread.org)
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2018-02-27 EvalZero the first verion
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <rtdevice.h>
|
||||||
|
|
||||||
|
#include <lwip/netifapi.h>
|
||||||
|
|
||||||
|
#include "wlan_dev.h"
|
||||||
|
#include "wlan_cmd.h"
|
||||||
|
|
||||||
|
#define WLAN_MGNT_DEBUG 1
|
||||||
|
|
||||||
|
#if WLAN_MGNT_DEBUG
|
||||||
|
#define WLAN_MGNT_DBG(...) rt_kprintf("[WLAN_MGNT]"),rt_kprintf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define WLAN_MGNT_DBG(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WIFI_DEVICE_STA_NAME
|
||||||
|
#define WIFI_DEVICE_STA_NAME "w0"
|
||||||
|
#endif
|
||||||
|
#ifndef WIFI_DEVICE_AP_NAME
|
||||||
|
#define WIFI_DEVICE_AP_NAME "ap"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void wlan_mgnt_init_done_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||||
|
{
|
||||||
|
WLAN_MGNT_DBG("wlan init done event callback \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wlan_mgnt_link_up_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||||
|
{
|
||||||
|
WLAN_MGNT_DBG("wlan link up event callback \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wlan_mgnt_link_down_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||||
|
{
|
||||||
|
WLAN_MGNT_DBG("wlan link down event callback \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wlan_mgnt_sta_connect_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||||
|
{
|
||||||
|
WLAN_MGNT_DBG("wlan sta connect event callback \n");
|
||||||
|
struct netif *netif = device->parent.netif;
|
||||||
|
|
||||||
|
netifapi_netif_set_up(netif);
|
||||||
|
netifapi_netif_set_link_up(netif);
|
||||||
|
#ifdef RT_LWIP_DHCP
|
||||||
|
/* start DHCP */
|
||||||
|
dhcp_start(netif);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wlan_mgnt_sta_disconnect_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||||
|
{
|
||||||
|
WLAN_MGNT_DBG("wlan sta disconnect event callback \n");
|
||||||
|
netifapi_netif_set_down(device->parent.netif);
|
||||||
|
netifapi_netif_set_link_down(device->parent.netif);
|
||||||
|
rt_memset(&device->parent.netif->ip_addr, 0, sizeof(ip_addr_t));
|
||||||
|
rt_memset(&device->parent.netif->netmask, 0, sizeof(ip_addr_t));
|
||||||
|
rt_memset(&device->parent.netif->gw, 0, sizeof(ip_addr_t));
|
||||||
|
#ifdef RT_LWIP_DHCP
|
||||||
|
dhcp_stop(device->parent.netif);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wlan_mgnt_ap_start_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||||
|
{
|
||||||
|
WLAN_MGNT_DBG("wlan ap start event callback \n");
|
||||||
|
netifapi_netif_set_up(device->parent.netif);
|
||||||
|
netifapi_netif_set_link_up(device->parent.netif);
|
||||||
|
|
||||||
|
wifi_softap_setup_netif(device->parent.netif);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void wlan_mgnt_ap_stop_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||||
|
{
|
||||||
|
WLAN_MGNT_DBG("wlan ap stop event callback \n");
|
||||||
|
|
||||||
|
netifapi_netif_set_down(device->parent.netif);
|
||||||
|
netifapi_netif_set_link_down(device->parent.netif);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wlan_mgnt_ap_associate_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||||
|
{
|
||||||
|
WLAN_MGNT_DBG("wlan ap associate event callback \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wlan_mgnt_ap_disassociate_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||||
|
{
|
||||||
|
WLAN_MGNT_DBG("wlan ap disassociate event callback \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wlan_mgnt_scan_done_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||||
|
{
|
||||||
|
WLAN_MGNT_DBG("wlan scan done event callback \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int rt_wlan_mgnt_attach(struct rt_wlan_device *device, void *user_data)
|
||||||
|
{
|
||||||
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
|
||||||
|
rt_wlan_register_event_handler(device, WIFI_EVT_INIT_DONE, wlan_mgnt_init_done_event);
|
||||||
|
rt_wlan_register_event_handler(device, WIFI_EVT_LINK_DOWN, wlan_mgnt_link_up_event);
|
||||||
|
rt_wlan_register_event_handler(device, WIFI_EVT_LINK_UP, wlan_mgnt_link_down_event);
|
||||||
|
rt_wlan_register_event_handler(device, WIFI_EVT_CONNECT, wlan_mgnt_sta_connect_event);
|
||||||
|
rt_wlan_register_event_handler(device, WIFI_EVT_DISCONNECT, wlan_mgnt_sta_disconnect_event);
|
||||||
|
rt_wlan_register_event_handler(device, WIFI_EVT_AP_START, wlan_mgnt_ap_start_event);
|
||||||
|
rt_wlan_register_event_handler(device, WIFI_EVT_AP_STOP, wlan_mgnt_ap_stop_event);
|
||||||
|
rt_wlan_register_event_handler(device, WIFI_EVENT_STA_ASSOC, wlan_mgnt_ap_associate_event);
|
||||||
|
rt_wlan_register_event_handler(device, WIFI_EVENT_STA_DISASSOC, wlan_mgnt_ap_disassociate_event);
|
||||||
|
rt_wlan_register_event_handler(device, WIFI_EVT_SCAN_DONE, wlan_mgnt_scan_done_event);
|
||||||
|
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
34
components/drivers/wlan/wlan_mgnt.h
Normal file
34
components/drivers/wlan/wlan_mgnt.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* RT-Thread Wi-Fi Device
|
||||||
|
*
|
||||||
|
* COPYRIGHT (C) 2014 - 2018, Shanghai Real-Thread Technology Co., Ltd
|
||||||
|
*
|
||||||
|
* This file is part of RT-Thread (http://www.rt-thread.org)
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2018-02-27 EvalZero the first verion
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __WLAN_MGNT_H__
|
||||||
|
#define __WLAN_MGNT_H__
|
||||||
|
|
||||||
|
int rt_wlan_mgnt_attach(struct rt_wlan_device *device, void *user_data);
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user