diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index c0e4f3e87a..7f216f1df4 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -205,11 +205,11 @@ menu "Using WiFi" if RT_USING_WIFI config RT_WLAN_DEVICE_STA_NAME - string "the WiFi device name for station" + string "The WiFi device name for station" default "wlan0" config RT_WLAN_DEVICE_AP_NAME - string "the WiFi device name for ap" + string "The WiFi device name for ap" default "wlan1" config RT_WLAN_DEFAULT_PROT @@ -217,11 +217,11 @@ menu "Using WiFi" default "lwip" config RT_WLAN_SCAN_WAIT_MS - int "Scan timeout time" + int "Set scan timeout time(ms)" default 10000; config RT_WLAN_CONNECT_WAIT_MS - int "connect timeout time" + int "Set connect timeout time(ms)" default 10000; config RT_WLAN_SSID_MAX_LENGTH @@ -259,6 +259,36 @@ menu "Using WiFi" config RT_WLAN_PROT_LWIP_PBUF_FORCE bool "Forced use of PBUF transmission" default n + + menuconfig RT_WLAN_DEBUG + bool "Enable WLAN Debugging Options" + default n + + if RT_WLAN_DEBUG + config RT_WLAN_CMD_DEBUG + bool "Enable Debugging of wlan_cmd.c" + default n + + config RT_WLAN_MGNT_DEBUG + bool "Enable Debugging of wlan_mgnt.c" + default n + + config RT_WLAN_DEV_DEBUG + bool "Enable Debugging of wlan_dev.c" + default n + + config RT_WLAN_PROT_DEBUG + bool "Enable Debugging of wlan_prot.c" + default n + + config RT_WLAN_CFG_DEBUG + bool "Enable Debugging of wlan_cfg.c" + default n + + config RT_WLAN_LWIP_DEBUG + bool "Enable Debugging of wlan_lwip.c" + default n + endif endif endmenu diff --git a/components/drivers/wlan/wlan_cfg.c b/components/drivers/wlan/wlan_cfg.c index b0cc88be08..27da9bc24e 100644 --- a/components/drivers/wlan/wlan_cfg.c +++ b/components/drivers/wlan/wlan_cfg.c @@ -12,11 +12,22 @@ #include #define DBG_ENABLE +#ifdef RT_WLAN_CFG_DEBUG +#define DBG_LEVEL DBG_LOG +#else #define DBG_LEVEL DBG_INFO +#endif #define DBG_SECTION_NAME "WLAN.cfg" #define DBG_COLOR #include +#define WLAN_CFG_LOCK() (rt_mutex_take(&cfg_mutex, RT_WAITING_FOREVER)) +#define WLAN_CFG_UNLOCK() (rt_mutex_release(&cfg_mutex)) + +#if RT_WLAN_CFG_INFO_MAX < 1 +#error "The minimum configuration is 1" +#endif + struct cfg_save_info_head { rt_uint32_t magic; @@ -31,9 +42,6 @@ struct rt_wlan_cfg_des struct rt_wlan_cfg_info *cfg_info; }; -#define WLAN_CFG_LOCK() (rt_mutex_take(&cfg_mutex, RT_WAITING_FOREVER)) -#define WLAN_CFG_UNLOCK() (rt_mutex_release(&cfg_mutex)) - static struct rt_wlan_cfg_des *cfg_cache; static const struct rt_wlan_cfg_ops *cfg_ops; static struct rt_mutex cfg_mutex; @@ -230,7 +238,7 @@ int rt_wlan_cfg_read(struct rt_wlan_cfg_info *cfg_info, int num) { rt_wlan_cfg_init(); - if (num <= 0) + if ((cfg_info == RT_NULL) || (num <= 0)) return 0; /* copy data */ WLAN_CFG_LOCK(); @@ -308,7 +316,7 @@ int rt_wlan_cfg_read_index(struct rt_wlan_cfg_info *cfg_info, int index) { rt_wlan_cfg_init(); - if (index < 0) + if ((cfg_info == RT_NULL) || (index < 0)) return 0; WLAN_CFG_LOCK(); diff --git a/components/drivers/wlan/wlan_cfg.h b/components/drivers/wlan/wlan_cfg.h index 4527043c39..3fae3f3e98 100644 --- a/components/drivers/wlan/wlan_cfg.h +++ b/components/drivers/wlan/wlan_cfg.h @@ -21,10 +21,6 @@ extern "C" { #define RT_WLAN_CFG_INFO_MAX (3) /* min is 1 */ #endif -#if RT_WLAN_CFG_INFO_MAX < 1 -#error "The minimum configuration is 1" -#endif - #define RT_WLAN_CFG_MAGIC (0x426f6d62) struct rt_wlan_cfg_info diff --git a/components/drivers/wlan/wlan_cmd.c b/components/drivers/wlan/wlan_cmd.c index e316a2c452..b962b63947 100644 --- a/components/drivers/wlan/wlan_cmd.c +++ b/components/drivers/wlan/wlan_cmd.c @@ -24,12 +24,13 @@ static int wifi_scan(int argc, char *argv[]); static int wifi_status(int argc, char *argv[]); static int wifi_join(int argc, char *argv[]); static int wifi_ap(int argc, char *argv[]); -static int list_sta(int argc, char *argv[]); +static int wifi_list_sta(int argc, char *argv[]); static int wifi_disconnect(int argc, char *argv[]); static int wifi_ap_stop(int argc, char *argv[]); -static int wifi_debug(int argc, char *argv[]); +#ifdef RT_WLAN_CMD_DEBUG /* just for debug */ +static int wifi_debug(int argc, char *argv[]); static int wifi_debug_save_cfg(int argc, char *argv[]); static int wifi_debug_dump_cfg(int argc, char *argv[]); static int wifi_debug_clear_cfg(int argc, char *argv[]); @@ -37,6 +38,7 @@ static int wifi_debug_dump_prot(int argc, char *argv[]); static int wifi_debug_set_mode(int argc, char *argv[]); static int wifi_debug_set_prot(int argc, char *argv[]); static int wifi_debug_set_autoconnect(int argc, char *argv[]); +#endif /* cmd table */ static const struct wifi_cmd_des cmd_tab[] = @@ -46,13 +48,16 @@ static const struct wifi_cmd_des cmd_tab[] = {"status", wifi_status}, {"join", wifi_join}, {"ap", wifi_ap}, - {"list_sta", list_sta}, + {"list_sta", wifi_list_sta}, {"disc", wifi_disconnect}, {"ap_stop", wifi_ap_stop}, {"smartconfig", RT_NULL}, +#ifdef RT_WLAN_CMD_DEBUG {"-d", wifi_debug}, +#endif }; +#ifdef RT_WLAN_CMD_DEBUG /* debug cmd table */ static const struct wifi_cmd_des debug_tab[] = { @@ -64,6 +69,7 @@ static const struct wifi_cmd_des debug_tab[] = {"prot", wifi_debug_set_prot}, {"auto", wifi_debug_set_autoconnect}, }; +#endif static int wifi_help(int argc, char *argv[]) { @@ -76,7 +82,9 @@ static int wifi_help(int argc, char *argv[]) rt_kprintf("wifi ap_stop\n"); rt_kprintf("wifi status\n"); rt_kprintf("wifi smartconfig\n"); +#ifdef RT_WLAN_CMD_DEBUG rt_kprintf("wifi -d debug command\n"); +#endif return 0; } @@ -272,7 +280,7 @@ static int wifi_ap(int argc, char *argv[]) return 0; } -static int list_sta(int argc, char *argv[]) +static int wifi_list_sta(int argc, char *argv[]) { struct rt_wlan_info *sta_info; int num, i; @@ -320,6 +328,7 @@ static int wifi_ap_stop(int argc, char *argv[]) return 0; } +#ifdef RT_WLAN_CMD_DEBUG /* just for debug */ static int wifi_debug_help(int argc, char *argv[]) { @@ -509,6 +518,7 @@ static int wifi_debug(int argc, char *argv[]) } return 0; } +#endif static int wifi_msh(int argc, char *argv[]) { @@ -551,4 +561,6 @@ static int wifi_msh(int argc, char *argv[]) return 0; } +#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) FINSH_FUNCTION_EXPORT_ALIAS(wifi_msh, __cmd_wifi, wifi command.); +#endif diff --git a/components/drivers/wlan/wlan_dev.c b/components/drivers/wlan/wlan_dev.c index 6892aed6d3..a5707d55f0 100644 --- a/components/drivers/wlan/wlan_dev.c +++ b/components/drivers/wlan/wlan_dev.c @@ -14,7 +14,11 @@ #include #define DBG_ENABLE +#ifdef RT_WLAN_DEV_DEBUG +#define DBG_LEVEL DBG_LOG +#else #define DBG_LEVEL DBG_INFO +#endif #define DBG_SECTION_NAME "WLAN.dev" #define DBG_COLOR #include @@ -26,6 +30,22 @@ #define WLAN_DEV_LOCK(_wlan) (rt_mutex_take(&(_wlan)->lock, RT_WAITING_FOREVER)) #define WLAN_DEV_UNLOCK(_wlan) (rt_mutex_release(&(_wlan)->lock)) +#if RT_WLAN_SSID_MAX_LENGTH < 1 +#error "SSID length is too short" +#endif + +#if RT_WLAN_BSSID_MAX_LENGTH < 1 +#error "BSSID length is too short" +#endif + +#if RT_WLAN_PASSWORD_MAX_LENGTH < 1 +#error "password length is too short" +#endif + +#if RT_WLAN_DEV_EVENT_NUM < 2 +#error "dev num Too little" +#endif + rt_err_t rt_wlan_dev_init(struct rt_wlan_device *device, rt_wlan_mode_t mode) { rt_err_t result = RT_EOK; @@ -137,7 +157,7 @@ rt_err_t rt_wlan_dev_ap_start(struct rt_wlan_device *device, struct rt_wlan_info rt_err_t rt_wlan_dev_ap_stop(struct rt_wlan_device *device) { - rt_err_t result = 0; + rt_err_t result = RT_EOK; if (device == RT_NULL) { @@ -150,7 +170,7 @@ rt_err_t rt_wlan_dev_ap_stop(struct rt_wlan_device *device) rt_err_t rt_wlan_dev_ap_deauth(struct rt_wlan_device *device, rt_uint8_t mac[6]) { - rt_err_t result = 0; + rt_err_t result = RT_EOK; if (device == RT_NULL) { @@ -176,7 +196,7 @@ int rt_wlan_dev_get_rssi(struct rt_wlan_device *device) rt_err_t rt_wlan_dev_get_mac(struct rt_wlan_device *device, rt_uint8_t mac[6]) { - rt_err_t result = 0; + rt_err_t result = RT_EOK; if (device == RT_NULL) { @@ -200,32 +220,31 @@ rt_err_t rt_wlan_dev_set_mac(struct rt_wlan_device *device, rt_uint8_t mac[6]) return result; } -rt_err_t rt_wlan_dev_enable_powersave(struct rt_wlan_device *device) +rt_err_t rt_wlan_dev_set_powersave(struct rt_wlan_device *device, int level) { rt_err_t result = RT_EOK; - int enable = 1; if (device == RT_NULL) { return -RT_EIO; } - result = rt_device_control(RT_DEVICE(device), RT_WLAN_CMD_POWERSAVE, &enable); + result = rt_device_control(RT_DEVICE(device), RT_WLAN_CMD_SET_POWERSAVE, &level); return result; } -rt_err_t rt_wlan_dev_disable_powersave(struct rt_wlan_device *device) +int rt_wlan_dev_get_powersave(struct rt_wlan_device *device) { - rt_err_t result = RT_EOK; - int enable = 0; + int level = 0; if (device == RT_NULL) { - return -RT_EIO; + return -1; } - result = rt_device_control(RT_DEVICE(device), RT_WLAN_CMD_POWERSAVE, &enable); - return result; + rt_device_control(RT_DEVICE(device), RT_WLAN_CMD_GET_POWERSAVE, &level); + + return level; } rt_err_t rt_wlan_dev_register_event_handler(struct rt_wlan_device *device, rt_wlan_dev_event_t event, rt_wlan_dev_event_handler handler, void *parameter) @@ -279,7 +298,7 @@ rt_err_t rt_wlan_dev_unregister_event_handler(struct rt_wlan_device *device, rt_ if (device->handler_table[event][i].handler == handler) { rt_memset(&device->handler_table[event][i], 0, sizeof(struct rt_wlan_dev_event_desc)); - rt_exit_critical(); + rt_hw_interrupt_enable(level); return RT_EOK; } } @@ -323,7 +342,7 @@ void rt_wlan_dev_indicate_event_handle(struct rt_wlan_device *device, rt_wlan_de } } -rt_err_t rt_wlan_dev_enter_pormisc(struct rt_wlan_device *device) +rt_err_t rt_wlan_dev_enter_promisc(struct rt_wlan_device *device) { rt_err_t result = RT_EOK; int enable = 1; @@ -337,7 +356,7 @@ rt_err_t rt_wlan_dev_enter_pormisc(struct rt_wlan_device *device) return result; } -rt_err_t rt_wlan_dev_exit_pormisc(struct rt_wlan_device *device) +rt_err_t rt_wlan_dev_exit_promisc(struct rt_wlan_device *device) { rt_err_t result = RT_EOK; int enable = 0; @@ -351,7 +370,7 @@ rt_err_t rt_wlan_dev_exit_pormisc(struct rt_wlan_device *device) return result; } -rt_err_t rt_wlan_dev_set_pormisc_callback(struct rt_wlan_device *device, rt_wlan_pormisc_callback_t callback) +rt_err_t rt_wlan_dev_set_promisc_callback(struct rt_wlan_device *device, rt_wlan_pormisc_callback_t callback) { if (device == RT_NULL) { @@ -362,7 +381,7 @@ rt_err_t rt_wlan_dev_set_pormisc_callback(struct rt_wlan_device *device, rt_wlan return RT_EOK; } -void rt_wlan_dev_pormisc_handler(struct rt_wlan_device *device, void *data, int len) +void rt_wlan_dev_promisc_handler(struct rt_wlan_device *device, void *data, int len) { rt_wlan_pormisc_callback_t callback; @@ -616,13 +635,22 @@ static rt_err_t _rt_wlan_dev_control(rt_device_t dev, int cmd, void *args) *rssi = wlan->ops->wlan_get_rssi(wlan); break; } - case RT_WLAN_CMD_POWERSAVE: + case RT_WLAN_CMD_SET_POWERSAVE: { - rt_bool_t enable = *((rt_bool_t *)args); + int level = *((int *)args); - LOG_D("%s %d cmd[%d]:%s run......", __FUNCTION__, __LINE__, RT_WLAN_CMD_POWERSAVE, "RT_WLAN_CMD_POWERSAVE"); - if (wlan->ops->wlan_powersave) - wlan->ops->wlan_powersave(wlan, enable); + LOG_D("%s %d cmd[%d]:%s run......", __FUNCTION__, __LINE__, RT_WLAN_CMD_POWERSAVE, "RT_WLAN_CMD_SET_POWERSAVE"); + if (wlan->ops->wlan_set_powersave) + wlan->ops->wlan_set_powersave(wlan, level); + break; + } + case RT_WLAN_CMD_GET_POWERSAVE: + { + int *level = args; + + LOG_D("%s %d cmd[%d]:%s run......", __FUNCTION__, __LINE__, RT_WLAN_CMD_POWERSAVE, "RT_WLAN_CMD_GET_POWERSAVE"); + if (wlan->ops->wlan_get_powersave) + *level = wlan->ops->wlan_get_powersave(wlan); break; } case RT_WLAN_CMD_CFG_PROMISC: diff --git a/components/drivers/wlan/wlan_dev.h b/components/drivers/wlan/wlan_dev.h index c382df8867..f46f3c001f 100644 --- a/components/drivers/wlan/wlan_dev.h +++ b/components/drivers/wlan/wlan_dev.h @@ -34,7 +34,8 @@ typedef enum RT_WLAN_CMD_AP_DEAUTH, RT_WLAN_CMD_SCAN_STOP, RT_WLAN_CMD_GET_RSSI, /* get sensitivity (dBm) */ - RT_WLAN_CMD_POWERSAVE, + RT_WLAN_CMD_SET_POWERSAVE, + RT_WLAN_CMD_GET_POWERSAVE, RT_WLAN_CMD_CFG_PROMISC, /* start/stop minitor */ RT_WLAN_CMD_CFG_FILTER, RT_WLAN_CMD_SET_CHANNEL, @@ -89,22 +90,6 @@ typedef enum #define RT_WLAN_DEV_EVENT_NUM (2) /* EVENT GROUP MAX NUM */ #endif -#if RT_WLAN_SSID_MAX_LENGTH < 1 -#error "SSID length is too short" -#endif - -#if RT_WLAN_BSSID_MAX_LENGTH < 1 -#error "BSSID length is too short" -#endif - -#if RT_WLAN_PASSWORD_MAX_LENGTH < 1 -#error "password length is too short" -#endif - -#if RT_WLAN_DEV_EVENT_NUM < 2 -#error "dev num Too little" -#endif - /** * Enumeration of Wi-Fi security modes */ @@ -499,7 +484,8 @@ struct rt_wlan_dev_ops rt_err_t (*wlan_ap_deauth)(struct rt_wlan_device *wlan, rt_uint8_t mac[]); rt_err_t (*wlan_scan_stop)(struct rt_wlan_device *wlan); int (*wlan_get_rssi)(struct rt_wlan_device *wlan); - rt_err_t (*wlan_powersave)(struct rt_wlan_device *wlan, rt_bool_t enable); + rt_err_t (*wlan_set_powersave)(struct rt_wlan_device *wlan, int level); + int (*wlan_get_powersave)(struct rt_wlan_device *wlan); rt_err_t (*wlan_cfg_promisc)(struct rt_wlan_device *wlan, rt_bool_t start); rt_err_t (*wlan_cfg_filter)(struct rt_wlan_device *wlan, struct rt_wlan_filter *filter); rt_err_t (*wlan_set_channel)(struct rt_wlan_device *wlan, int channel); @@ -512,60 +498,84 @@ struct rt_wlan_dev_ops int (*wlan_send)(struct rt_wlan_device *wlan, void *buff, int len); }; +/* + * wlan device init + */ rt_err_t rt_wlan_dev_init(struct rt_wlan_device *device, rt_wlan_mode_t mode); +/* + * wlan device station interface + */ rt_err_t rt_wlan_dev_connect(struct rt_wlan_device *device, struct rt_wlan_info *info, const char *password, int password_len); - rt_err_t rt_wlan_dev_disconnect(struct rt_wlan_device *device); - -rt_err_t rt_wlan_dev_ap_start(struct rt_wlan_device *device, struct rt_wlan_info *info, const char *password, int password_len); - -rt_err_t rt_wlan_dev_ap_stop(struct rt_wlan_device *device); - -rt_err_t rt_wlan_dev_ap_deauth(struct rt_wlan_device *device, rt_uint8_t mac[6]); - int rt_wlan_dev_get_rssi(struct rt_wlan_device *device); -rt_err_t rt_wlan_dev_get_mac(struct rt_wlan_device *device, rt_uint8_t mac[6]); - -rt_err_t rt_wlan_dev_set_mac(struct rt_wlan_device *device, rt_uint8_t mac[6]); - -rt_err_t rt_wlan_dev_enable_powersave(struct rt_wlan_device *device); - -rt_err_t rt_wlan_dev_disable_powersave(struct rt_wlan_device *device); - -rt_err_t rt_wlan_dev_register_event_handler(struct rt_wlan_device *device, rt_wlan_dev_event_t event, rt_wlan_dev_event_handler handler, void *parameter); - -rt_err_t rt_wlan_dev_unregister_event_handler(struct rt_wlan_device *device, rt_wlan_dev_event_t event, rt_wlan_dev_event_handler handler); - -void rt_wlan_dev_indicate_event_handle(struct rt_wlan_device *device, rt_wlan_dev_event_t event, struct rt_wlan_buff *buff); - -rt_err_t rt_wlan_dev_enter_pormisc(struct rt_wlan_device *device); - -rt_err_t rt_wlan_dev_exit_pormisc(struct rt_wlan_device *device); - -rt_err_t rt_wlan_dev_set_pormisc_callback(struct rt_wlan_device *device, rt_wlan_pormisc_callback_t callback); - -void rt_wlan_dev_pormisc_handler(struct rt_wlan_device *device, void *data, int len); - -rt_err_t rt_wlan_dev_cfg_filter(struct rt_wlan_device *device, struct rt_wlan_filter *filter); - -rt_err_t rt_wlan_dev_set_channel(struct rt_wlan_device *device, int channel); - -rt_err_t rt_wlan_dev_get_channel(struct rt_wlan_device *device); - -rt_err_t rt_wlan_dev_set_country(struct rt_wlan_device *device, rt_country_code_t country_code); - -rt_country_code_t rt_wlan_dev_get_country(struct rt_wlan_device *device); +/* + * wlan device ap interface + */ +rt_err_t rt_wlan_dev_ap_start(struct rt_wlan_device *device, struct rt_wlan_info *info, const char *password, int password_len); +rt_err_t rt_wlan_dev_ap_stop(struct rt_wlan_device *device); +rt_err_t rt_wlan_dev_ap_deauth(struct rt_wlan_device *device, rt_uint8_t mac[6]); +/* + * wlan device scan interface + */ rt_err_t rt_wlan_dev_scan(struct rt_wlan_device *device, struct rt_wlan_info *info); - rt_err_t rt_wlan_dev_scan_stop(struct rt_wlan_device *device); -rt_err_t rt_wlan_dev_report_data(struct rt_wlan_device *device, void *buff, int len); +/* + * wlan device mac interface + */ +rt_err_t rt_wlan_dev_get_mac(struct rt_wlan_device *device, rt_uint8_t mac[6]); +rt_err_t rt_wlan_dev_set_mac(struct rt_wlan_device *device, rt_uint8_t mac[6]); +/* + * wlan device powersave interface + */ +rt_err_t rt_wlan_dev_set_powersave(struct rt_wlan_device *device, int level); +int rt_wlan_dev_get_powersave(struct rt_wlan_device *device); + +/* + * wlan device event interface + */ +rt_err_t rt_wlan_dev_register_event_handler(struct rt_wlan_device *device, rt_wlan_dev_event_t event, rt_wlan_dev_event_handler handler, void *parameter); +rt_err_t rt_wlan_dev_unregister_event_handler(struct rt_wlan_device *device, rt_wlan_dev_event_t event, rt_wlan_dev_event_handler handler); +void rt_wlan_dev_indicate_event_handle(struct rt_wlan_device *device, rt_wlan_dev_event_t event, struct rt_wlan_buff *buff); + +/* + * wlan device promisc interface + */ +rt_err_t rt_wlan_dev_enter_promisc(struct rt_wlan_device *device); +rt_err_t rt_wlan_dev_exit_promisc(struct rt_wlan_device *device); +rt_err_t rt_wlan_dev_set_promisc_callback(struct rt_wlan_device *device, rt_wlan_pormisc_callback_t callback); +void rt_wlan_dev_promisc_handler(struct rt_wlan_device *device, void *data, int len); + +/* + * wlan device filter interface + */ +rt_err_t rt_wlan_dev_cfg_filter(struct rt_wlan_device *device, struct rt_wlan_filter *filter); + +/* + * wlan device channel interface + */ +rt_err_t rt_wlan_dev_set_channel(struct rt_wlan_device *device, int channel); +rt_err_t rt_wlan_dev_get_channel(struct rt_wlan_device *device); + +/* + * wlan device country interface + */ +rt_err_t rt_wlan_dev_set_country(struct rt_wlan_device *device, rt_country_code_t country_code); +rt_country_code_t rt_wlan_dev_get_country(struct rt_wlan_device *device); + +/* + * wlan device datat transfer interface + */ +rt_err_t rt_wlan_dev_report_data(struct rt_wlan_device *device, void *buff, int len); // void rt_wlan_dev_data_ready(struct rt_wlan_device *device, int len); +/* + * wlan device register interface + */ struct rt_wlan_device *rt_wlan_dev_register(const char *name, const struct rt_wlan_dev_ops *ops, rt_uint32_t flag, void *user_data); #ifdef __cplusplus diff --git a/components/drivers/wlan/wlan_lwip.c b/components/drivers/wlan/wlan_lwip.c index c9f1f875a0..73c2eebafe 100644 --- a/components/drivers/wlan/wlan_lwip.c +++ b/components/drivers/wlan/wlan_lwip.c @@ -13,6 +13,7 @@ #include #include #include + #ifdef RT_USING_LWIP #include #include @@ -21,7 +22,11 @@ #endif #define DBG_ENABLE +#ifdef RT_WLAN_LWIP_DEBUG +#define DBG_LEVEL DBG_LOG +#else #define DBG_LEVEL DBG_INFO +#endif #define DBG_SECTION_NAME "WLAN.lwip" #define DBG_COLOR #include diff --git a/components/drivers/wlan/wlan_mgnt.c b/components/drivers/wlan/wlan_mgnt.c index 4474f25050..c8f190239c 100644 --- a/components/drivers/wlan/wlan_mgnt.c +++ b/components/drivers/wlan/wlan_mgnt.c @@ -17,7 +17,11 @@ #include #define DBG_ENABLE +#ifdef RT_WLAN_MGNT_DEBUG +#define DBG_LEVEL DBG_LOG +#else #define DBG_LEVEL DBG_INFO +#endif #define DBG_SECTION_NAME "WLAN.mgnt" #define DBG_COLOR #include @@ -51,6 +55,10 @@ #define DISCONNECT_RESPONSE_TICK (2000) +#if RT_WLAN_EBOX_NUM < 1 +#error "event box num Too little" +#endif + struct rt_wlan_mgnt_des { struct rt_wlan_device *device; @@ -108,8 +116,6 @@ static struct rt_wlan_event_desc event_tab[RT_WLAN_EVT_MAX]; static struct rt_wlan_complete_des *complete_tab[5]; static struct rt_mutex complete_mutex; -static rt_mailbox_t event_box; - static struct rt_timer reconnect_time; rt_inline int _sta_is_null(void) @@ -153,7 +159,7 @@ static rt_err_t rt_wlan_send_msg(rt_wlan_dev_event_t event, void *buff, int len) msg = rt_malloc(sizeof(struct rt_wlan_msg) + len); if (msg == RT_NULL) { - RT_WLAN_LOG_E("No memory"); + RT_WLAN_LOG_E("wlan mgnt send msg err! No memory"); return -RT_ENOMEM; } rt_memset(msg, 0, sizeof(struct rt_wlan_msg) + len); @@ -352,12 +358,12 @@ static rt_err_t rt_wlan_sta_info_del(struct rt_wlan_info *info, int timeout) return err; } -static rt_err_t rt_wlan_sta_info_del_all(void) +static rt_err_t rt_wlan_sta_info_del_all(int timeout) { struct rt_wlan_sta_list *sta_list, *sta_next; rt_err_t err = RT_EOK; - err = rt_mutex_take(&sta_info_mutex, rt_tick_from_millisecond(200)); + err = rt_mutex_take(&sta_info_mutex, rt_tick_from_millisecond(timeout)); if (err == RT_EOK) { /* traversing the list */ @@ -370,7 +376,9 @@ static rt_err_t rt_wlan_sta_info_del_all(void) rt_mutex_release(&sta_info_mutex); } if (sta_info.num != 0) - rt_kprintf("zha guo zha guo zha guo\n"); + { + RT_WLAN_LOG_W("\n\n!!!Program runing exception!!!\n\n"); + } sta_info.num = 0; sta_info.node = RT_NULL; return err; @@ -414,7 +422,7 @@ static void rt_wlan_auto_connect_run(struct rt_work *work, void *parameter) } rt_wlan_connect_adv(&cfg_info.info, password); exit: - MGNT_UNLOCK(); + rt_mutex_release(&mgnt_mutex); level = rt_hw_interrupt_disable(); rt_memset(work, 0, sizeof(struct rt_work)); rt_hw_interrupt_enable(level); @@ -466,24 +474,6 @@ static void rt_wlan_mgnt_work(void *parameter) } break; } - case RT_WLAN_DEV_EVT_AP_ASSOCIATED: - { - /* save sta info */ - if (msg->len > 0) - { - rt_wlan_sta_info_add(msg->buff, RT_WAITING_FOREVER); - } - break; - } - case RT_WLAN_DEV_EVT_AP_DISASSOCIATED: - { - /* delete sta info */ - if (msg->len > 0) - { - rt_wlan_sta_info_del(msg->buff, RT_WAITING_FOREVER); - } - break; - } default : break; } @@ -558,11 +548,10 @@ static void rt_wlan_event_dispatch(struct rt_wlan_device *device, rt_wlan_dev_ev RT_WLAN_LOG_D("event: AP_STOP"); _ap_mgnt.state &= ~RT_WLAN_STATE_ACTIVE; user_event = RT_WLAN_EVT_AP_STOP; - err = rt_wlan_sta_info_del_all(); + err = rt_wlan_sta_info_del_all(RT_WAITING_FOREVER); if (err != RT_NULL) { RT_WLAN_LOG_W("AP_STOP event handle fail"); - rt_wlan_send_msg(event, RT_NULL, 0); } user_buff.data = &_ap_mgnt.info; user_buff.len = sizeof(struct rt_wlan_info); @@ -574,11 +563,10 @@ static void rt_wlan_event_dispatch(struct rt_wlan_device *device, rt_wlan_dev_ev user_event = RT_WLAN_EVT_AP_ASSOCIATED; if (user_buff.len != sizeof(struct rt_wlan_info)) break; - err = rt_wlan_sta_info_add(user_buff.data, 200); + err = rt_wlan_sta_info_add(user_buff.data, RT_WAITING_FOREVER); if (err != RT_EOK) { RT_WLAN_LOG_W("AP_ASSOCIATED event handle fail"); - rt_wlan_send_msg(event, user_buff.data, sizeof(struct rt_wlan_info)); } break; } @@ -588,11 +576,10 @@ static void rt_wlan_event_dispatch(struct rt_wlan_device *device, rt_wlan_dev_ev user_event = RT_WLAN_EVT_AP_DISASSOCIATED; if (user_buff.len != sizeof(struct rt_wlan_info)) break; - err = rt_wlan_sta_info_del(user_buff.data, 200); + err = rt_wlan_sta_info_del(user_buff.data, RT_WAITING_FOREVER); if (err != RT_EOK) { RT_WLAN_LOG_W("AP_DISASSOCIATED event handle fail"); - rt_wlan_send_msg(event, user_buff.data, sizeof(struct rt_wlan_info)); } break; } @@ -637,7 +624,7 @@ static void rt_wlan_event_dispatch(struct rt_wlan_device *device, rt_wlan_dev_ev } } COMPLETE_UNLOCK(); - /* 取出用户回调 */ + /* Get user callback */ if (user_event < RT_WLAN_EVT_MAX) { level = rt_hw_interrupt_disable(); @@ -1147,28 +1134,28 @@ rt_err_t rt_wlan_disconnect(void) return err; } -int rt_wlan_is_connected(void) +rt_bool_t rt_wlan_is_connected(void) { - int _connect = 0; + rt_bool_t _connect; if (_sta_is_null()) { - return 0; + return RT_FALSE; } - _connect = _sta_mgnt.state & RT_WLAN_STATE_CONNECT ? 1 : 0; + _connect = _sta_mgnt.state & RT_WLAN_STATE_CONNECT ? RT_TRUE : RT_FALSE; RT_WLAN_LOG_D("%s is run : %s", __FUNCTION__, _connect ? "connect" : "disconnect"); return _connect; } -int rt_wlan_is_ready(void) +rt_bool_t rt_wlan_is_ready(void) { - int _ready = 0; + rt_bool_t _ready; if (_sta_is_null()) { - return 0; + return RT_FALSE; } - _ready = _sta_mgnt.state & RT_WLAN_STATE_READY ? 1 : 0; + _ready = _sta_mgnt.state & RT_WLAN_STATE_READY ? RT_TRUE : RT_FALSE; RT_WLAN_LOG_D("%s is run : %s", __FUNCTION__, _ready ? "ready" : "not ready"); return _ready; } @@ -1392,7 +1379,6 @@ rt_err_t rt_wlan_ap_stop(void) } RT_WLAN_LOG_D("%s is run", __FUNCTION__); - /* 调用dev层接口 */ MGNT_LOCK(); /* create event wait complete */ complete = rt_wlan_complete_create("stop_ap"); @@ -1435,12 +1421,11 @@ rt_err_t rt_wlan_ap_get_info(struct rt_wlan_info *info) } RT_WLAN_LOG_D("%s is run", __FUNCTION__); - /* 返回暂存的ap info */ *info = _ap_mgnt.info; return RT_EOK; } -/* 获得sta连接数量 */ +/* get sta number */ int rt_wlan_ap_get_sta_num(void) { int sta_num = 0; @@ -1452,14 +1437,14 @@ int rt_wlan_ap_get_sta_num(void) return sta_num; } -/* 获得sta信息 */ +/* get sta info */ int rt_wlan_ap_get_sta_info(struct rt_wlan_info *info, int num) { int sta_num = 0, i = 0; struct rt_wlan_sta_list *sta_list; STAINFO_LOCK(); - /* 找出 num 与 sta_info.num 中较小的那个 */ + /* sta_num = min(sta_info.num, num) */ sta_num = sta_info.num > num ? num : sta_info.num; for (sta_list = sta_info.node; sta_list != RT_NULL && i < sta_num; sta_list = sta_list->next) { @@ -1471,7 +1456,7 @@ int rt_wlan_ap_get_sta_info(struct rt_wlan_info *info, int num) return i; } -/* 踢掉某个sta */ +/* deauth sta */ rt_err_t rt_wlan_ap_deauth_sta(rt_uint8_t *mac) { rt_err_t err = RT_EOK; @@ -1500,7 +1485,7 @@ rt_err_t rt_wlan_ap_deauth_sta(rt_uint8_t *mac) } STAINFO_LOCK(); - /* 重缓存中查询有没有这个sta */ + /* Search for MAC address from sta list */ for (sta_list = sta_info.node; sta_list != RT_NULL; sta_list = sta_list->next) { if (rt_memcmp(&sta_list->info.bssid[0], &mac[0], RT_WLAN_BSSID_MAX_LENGTH) == 0) @@ -1511,7 +1496,7 @@ rt_err_t rt_wlan_ap_deauth_sta(rt_uint8_t *mac) } STAINFO_UNLOCK(); - /* 没有找个这个sta,退出 */ + /* No MAC address was found. return */ if (find_flag != RT_TRUE) { RT_WLAN_LOG_E("Not find mac addr"); @@ -1519,7 +1504,7 @@ rt_err_t rt_wlan_ap_deauth_sta(rt_uint8_t *mac) return -RT_ERROR; } - /* 调用dev层接口,提到sta */ + /* Kill STA */ err = rt_wlan_dev_ap_deauth(AP_DEVICE(), mac); if (err != RT_NULL) { @@ -1767,7 +1752,7 @@ int rt_wlan_scan_find_cache(struct rt_wlan_info *info, struct rt_wlan_info *out_ return count; } -rt_err_t rt_wlan_enable_powersave(void) +rt_err_t rt_wlan_set_powersave(int level) { rt_err_t err = RT_EOK; @@ -1777,24 +1762,24 @@ rt_err_t rt_wlan_enable_powersave(void) } RT_WLAN_LOG_D("%s is run", __FUNCTION__); MGNT_LOCK(); - err = rt_wlan_dev_enable_powersave(STA_DEVICE()); + err = rt_wlan_dev_set_powersave(STA_DEVICE(), level); MGNT_UNLOCK(); return err; } -rt_err_t rt_wlan_disable_powersave(void) +int rt_wlan_get_powersave(void) { - rt_err_t err = RT_EOK; + int level; if (_sta_is_null()) { - return -RT_EIO; + return -1; } RT_WLAN_LOG_D("%s is run", __FUNCTION__); MGNT_LOCK(); - err = rt_wlan_dev_disable_powersave(STA_DEVICE()); + level = rt_wlan_dev_get_powersave(STA_DEVICE()); MGNT_UNLOCK(); - return err; + return level; } rt_err_t rt_wlan_register_event_handler(rt_wlan_event_t event, rt_wlan_event_handler handler, void *parameter) @@ -1890,10 +1875,6 @@ int rt_wlan_init(void) rt_mutex_init(&complete_mutex, "complete", RT_IPC_FLAG_FIFO); rt_timer_init(&reconnect_time, "wifi_tim", rt_wlan_cyclic_check, RT_NULL, DISCONNECT_RESPONSE_TICK, RT_TIMER_FLAG_PERIODIC | RT_TIMER_FLAG_SOFT_TIMER); rt_timer_start(&reconnect_time); - /* create event */ - event_box = rt_mb_create("wlan", RT_WLAN_EBOX_NUM, RT_IPC_FLAG_FIFO); - if (event_box == RT_NULL) - RT_ASSERT(event_box != RT_NULL); _init_flag = 1; } return 0; diff --git a/components/drivers/wlan/wlan_mgnt.h b/components/drivers/wlan/wlan_mgnt.h index 62e1dbde4a..d11d9ee347 100644 --- a/components/drivers/wlan/wlan_mgnt.h +++ b/components/drivers/wlan/wlan_mgnt.h @@ -37,21 +37,17 @@ extern "C" { #define RT_WLAN_EBOX_NUM (10) #endif -#if RT_WLAN_EBOX_NUM < 1 -#error "event box num Too little" -#endif - /*state fot station*/ -#define RT_WLAN_STATE_CONNECT (0x1 << 0) -#define RT_WLAN_STATE_CONNECTING (0x1 << 1) -#define RT_WLAN_STATE_READY (0x1 << 2) -#define RT_WLAN_STATE_POWERSAVE (0x1 << 3) +#define RT_WLAN_STATE_CONNECT (1UL << 0) +#define RT_WLAN_STATE_CONNECTING (1UL << 1) +#define RT_WLAN_STATE_READY (1UL << 2) +#define RT_WLAN_STATE_POWERSAVE (1UL << 3) /*flags fot station*/ -#define RT_WLAN_STATE_AUTOEN (0x1 << 0) +#define RT_WLAN_STATE_AUTOEN (1UL << 0) /*state fot ap*/ -#define RT_WLAN_STATE_ACTIVE (0x1 << 0) +#define RT_WLAN_STATE_ACTIVE (1UL << 0) typedef enum { @@ -89,8 +85,8 @@ rt_wlan_mode_t rt_wlan_get_mode(const char *dev_name); rt_err_t rt_wlan_connect(const char *ssid, const char *password); rt_err_t rt_wlan_connect_adv(struct rt_wlan_info *info, const char *password); rt_err_t rt_wlan_disconnect(void); -int rt_wlan_is_connected(void); -int rt_wlan_is_ready(void); +rt_bool_t rt_wlan_is_connected(void); +rt_bool_t rt_wlan_is_ready(void); rt_err_t rt_wlan_set_mac(rt_uint8_t *mac); rt_err_t rt_wlan_get_mac(rt_uint8_t *mac); rt_err_t rt_wlan_get_info(struct rt_wlan_info *info); @@ -132,8 +128,8 @@ rt_bool_t rt_wlan_get_autoreconnect_mode(void); /* * wifi power management interface */ -rt_err_t rt_wlan_enable_powersave(void); -rt_err_t rt_wlan_disable_powersave(void); +rt_err_t rt_wlan_set_powersave(int level); +int rt_wlan_get_powersave(void); /* * wifi event management interface diff --git a/components/drivers/wlan/wlan_prot.c b/components/drivers/wlan/wlan_prot.c index 011df270ad..ec5e419bc4 100644 --- a/components/drivers/wlan/wlan_prot.c +++ b/components/drivers/wlan/wlan_prot.c @@ -14,11 +14,19 @@ #include #define DBG_ENABLE +#ifdef RT_WLAN_PROT_DEBUG +#define DBG_LEVEL DBG_LOG +#else #define DBG_LEVEL DBG_INFO +#endif #define DBG_SECTION_NAME "WLAN.prot" #define DBG_COLOR #include +#if RT_WLAN_PROT_NAME_LEN < 4 +#error "The name is too short" +#endif + struct rt_wlan_prot_event_des { rt_wlan_prot_event_handler handler; diff --git a/components/drivers/wlan/wlan_prot.h b/components/drivers/wlan/wlan_prot.h index 13610e754b..34c5bae7fd 100644 --- a/components/drivers/wlan/wlan_prot.h +++ b/components/drivers/wlan/wlan_prot.h @@ -25,10 +25,6 @@ extern "C" { #define RT_LWAN_ID_PREFIX (0x5054) -#if RT_WLAN_PROT_NAME_LEN < 4 -#error "The name is too short" -#endif - #define RT_WLAN_PROT_LWIP ("lwip") typedef enum