diff options
| author | Bernard Xiong <[email protected]> | 2019-07-27 14:51:10 +0800 |
|---|---|---|
| committer | Bernard Xiong <[email protected]> | 2019-07-27 14:51:10 +0800 |
| commit | 384f3909711e831ee6dfe9fce4de337e07b35319 (patch) | |
| tree | 8616205b271393523c775bc653077769027c6882 /components | |
| parent | 5e88ea520560126d03afa3b485633434f90badbf (diff) | |
| parent | 5180262010f5ed76f757125a75d54d37c289d022 (diff) | |
Merge remote-tracking branch 'github/master'
Diffstat (limited to 'components')
24 files changed, 644 insertions, 234 deletions
diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index d4f9f5c506..4aceee3b4e 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -254,9 +254,8 @@ config RT_USING_TOUCH bool "Using Touch device drivers" default n -menu "Using Hardware Crypto drivers" - config RT_USING_HWCRYPTO - bool "Using Hardware Crypto" +menuconfig RT_USING_HWCRYPTO + bool "Using Hardware Crypto drivers" default n if RT_USING_HWCRYPTO @@ -420,69 +419,126 @@ menu "Using Hardware Crypto drivers" default n endif endif -endmenu -menu "Using WiFi" - config RT_USING_WIFI - bool "Using Wi-Fi framework" - default n +menuconfig RT_USING_WIFI + bool "Using Wi-Fi framework" + default n if RT_USING_WIFI config RT_WLAN_DEVICE_STA_NAME - string "The WiFi device name for station" + string "The device name for station" default "wlan0" config RT_WLAN_DEVICE_AP_NAME - string "The WiFi device name for ap" + string "The device name for ap" default "wlan1" - config RT_WLAN_DEFAULT_PROT - string "Default transport protocol" - default "lwip" - - config RT_WLAN_SCAN_WAIT_MS - int "Set scan timeout time(ms)" - default 10000 - - config RT_WLAN_CONNECT_WAIT_MS - int "Set connect timeout time(ms)" - default 10000 - config RT_WLAN_SSID_MAX_LENGTH - int "SSID name maximum length" + int "SSID maximum length" default 32 config RT_WLAN_PASSWORD_MAX_LENGTH - int "Maximum password length" + int "Password maximum length" default 32 - config RT_WLAN_SCAN_SORT - bool "Automatic sorting of scan results" + config RT_WLAN_DEV_EVENT_NUM + int "Driver events maxcount" + default 2 + + config RT_WLAN_MANAGE_ENABLE + bool "Connection management Enable" default y - config RT_WLAN_CFG_INFO_MAX - int "Maximum number of WiFi information automatically saved" - default 3 + if RT_WLAN_MANAGE_ENABLE + config RT_WLAN_SCAN_WAIT_MS + int "Set scan timeout time(ms)" + default 10000 - config RT_WLAN_WORKQUEUE_THREAD_NAME - string "WiFi work queue thread name" - default "wlan_job" + config RT_WLAN_CONNECT_WAIT_MS + int "Set connect timeout time(ms)" + default 10000 - config RT_WLAN_WORKQUEUE_THREAD_SIZE - int "wifi work queue thread size" - default 2048 + config RT_WLAN_SCAN_SORT + bool "Automatic sorting of scan results" + default y - config RT_WLAN_WORKQUEUE_THREAD_PRIO - int "WiFi work queue thread priority" - default 22 + config RT_WLAN_MSH_CMD_ENABLE + bool "MSH command Enable" + default y - config RT_WLAN_DEV_EVENT_NUM - int "Maximum number of driver events" - default 2 + config RT_WLAN_AUTO_CONNECT_ENABLE + bool "Auto connect Enable" + select RT_WLAN_CFG_ENABLE + select RT_WLAN_WORK_THREAD_ENABLE + default y - config RT_WLAN_PROT_LWIP_PBUF_FORCE - bool "Forced use of PBUF transmission" - default n + if RT_WLAN_AUTO_CONNECT_ENABLE + config AUTO_CONNECTION_PERIOD_MS + int "Auto connect period(ms)" + default 2000 + endif + endif + + config RT_WLAN_CFG_ENABLE + bool "WiFi information automatically saved Enable" + default y + + if RT_WLAN_CFG_ENABLE + config RT_WLAN_CFG_INFO_MAX + int "Maximum number of WiFi information automatically saved" + default 3 + endif + + config RT_WLAN_PROT_ENABLE + bool "Transport protocol manage Enable" + default y + + if RT_WLAN_PROT_ENABLE + config RT_WLAN_PROT_NAME_LEN + int "Transport protocol name length" + default 8 + + config RT_WLAN_PROT_MAX + int "Transport protocol maxcount" + default 2 + + config RT_WLAN_DEFAULT_PROT + string "Default transport protocol" + default "lwip" + + config RT_WLAN_PROT_LWIP_ENABLE + bool "LWIP transport protocol Enable" + select RT_USING_LWIP + default y + + if RT_WLAN_PROT_LWIP_ENABLE + config RT_WLAN_PROT_LWIP_NAME + string "LWIP transport protocol name" + default "lwip" + + config RT_WLAN_PROT_LWIP_PBUF_FORCE + bool "Forced use of PBUF transmission" + default n + endif + endif + + config RT_WLAN_WORK_THREAD_ENABLE + bool "WLAN work queue thread Enable" + default y + + if RT_WLAN_WORK_THREAD_ENABLE + config RT_WLAN_WORKQUEUE_THREAD_NAME + string "WLAN work queue thread name" + default "wlan" + + config RT_WLAN_WORKQUEUE_THREAD_SIZE + int "WLAN work queue thread size" + default 2048 + + config RT_WLAN_WORKQUEUE_THREAD_PRIO + int "WLAN work queue thread priority" + default 15 + endif menuconfig RT_WLAN_DEBUG bool "Enable WLAN Debugging Options" @@ -514,7 +570,6 @@ menu "Using WiFi" default n endif endif -endmenu menu "Using USB" config RT_USING_USB_HOST diff --git a/components/drivers/hwcrypto/hw_bignum.c b/components/drivers/hwcrypto/hw_bignum.c index cfc57f8273..88813566b1 100644 --- a/components/drivers/hwcrypto/hw_bignum.c +++ b/components/drivers/hwcrypto/hw_bignum.c @@ -22,7 +22,7 @@ rt_inline rt_err_t hwcrypto_bignum_dev_is_init(void) { return RT_EOK; } - dev = rt_hwcrypto_dev_dufault(); + dev = rt_hwcrypto_dev_default(); if (dev == RT_NULL) { return -RT_ERROR; diff --git a/components/drivers/hwcrypto/hw_rng.c b/components/drivers/hwcrypto/hw_rng.c index f64bdf8831..13a17cc6be 100644 --- a/components/drivers/hwcrypto/hw_rng.c +++ b/components/drivers/hwcrypto/hw_rng.c @@ -103,8 +103,8 @@ rt_uint32_t rt_hwcrypto_rng_update(void) /* Default device does not exist ? */ if (ctx_default == RT_NULL) { - /* try create Context from dufault device */ - rt_hwcrypto_rng_default(rt_hwcrypto_dev_dufault()); + /* try create Context from default device */ + rt_hwcrypto_rng_default(rt_hwcrypto_dev_default()); } return rt_hwcrypto_rng_update_ctx(ctx_default); } diff --git a/components/drivers/hwcrypto/hwcrypto.c b/components/drivers/hwcrypto/hwcrypto.c index 3dc5649cd6..bbe1ff63fb 100644 --- a/components/drivers/hwcrypto/hwcrypto.c +++ b/components/drivers/hwcrypto/hwcrypto.c @@ -171,7 +171,7 @@ rt_err_t rt_hwcrypto_ctx_cpy(struct rt_hwcrypto_ctx *des, const struct rt_hwcryp * @return Hardware crypto device * */ -struct rt_hwcrypto_device *rt_hwcrypto_dev_dufault(void) +struct rt_hwcrypto_device *rt_hwcrypto_dev_default(void) { static struct rt_hwcrypto_device *hwcrypto_dev; diff --git a/components/drivers/hwcrypto/hwcrypto.h b/components/drivers/hwcrypto/hwcrypto.h index 944fb03c14..a428f4437d 100644 --- a/components/drivers/hwcrypto/hwcrypto.h +++ b/components/drivers/hwcrypto/hwcrypto.h @@ -175,7 +175,7 @@ rt_err_t rt_hwcrypto_register(struct rt_hwcrypto_device *device, const char *nam * @return Hardware crypto device * */ -struct rt_hwcrypto_device *rt_hwcrypto_dev_dufault(void); +struct rt_hwcrypto_device *rt_hwcrypto_dev_default(void); /** * @brief Get the unique ID of the device diff --git a/components/drivers/sdio/mmc.c b/components/drivers/sdio/mmc.c index 5c7ddcb258..7b1f7ee193 100644 --- a/components/drivers/sdio/mmc.c +++ b/components/drivers/sdio/mmc.c @@ -4,8 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 * * Change Logs: - * Date Author Notes - * 2015-06-15 hichard first version + * Date Author Notes + * 2015-06-15 hichard first version */ #include <drivers/mmcsd_core.h> @@ -182,6 +182,8 @@ static int mmc_get_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t **new_ext_csd) */ static int mmc_parse_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) { + rt_uint64_t card_capacity = 0; + if(card == RT_NULL || ext_csd == RT_NULL) { LOG_E("emmc parse ext csd fail, invaild args"); @@ -191,9 +193,10 @@ static int mmc_parse_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) card->flags |= CARD_FLAG_HIGHSPEED; card->hs_max_data_rate = 200000000; - card->card_capacity = *((rt_uint32_t *)&ext_csd[EXT_CSD_SEC_CNT]); - card->card_capacity *= card->card_blksize; - card->card_capacity >>= 10; /* unit:KB */ + card_capacity = *((rt_uint32_t *)&ext_csd[EXT_CSD_SEC_CNT]); + card_capacity *= card->card_blksize; + card_capacity >>= 10; /* unit:KB */ + card->card_capacity = card_capacity; LOG_I("emmc card capacity %d KB.", card->card_capacity); return 0; diff --git a/components/drivers/sensors/sensor.h b/components/drivers/sensors/sensor.h index a9b6684457..9c6e5ecc55 100755 --- a/components/drivers/sensors/sensor.h +++ b/components/drivers/sensors/sensor.h @@ -55,6 +55,7 @@ extern "C" { #define RT_SENSOR_VENDOR_SEMTECH (4) /* Semtech */ #define RT_SENSOR_VENDOR_GOERTEK (5) /* Goertek */ #define RT_SENSOR_VENDOR_MIRAMEMS (6) /* MiraMEMS */ +#define RT_SENSOR_VENDOR_DALLAS (7) /* Dallas */ /* Sensor unit types */ diff --git a/components/drivers/sensors/sensor_cmd.c b/components/drivers/sensors/sensor_cmd.c index ea9e56a3d3..dd1aa1ef95 100755 --- a/components/drivers/sensors/sensor_cmd.c +++ b/components/drivers/sensors/sensor_cmd.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 * * Change Logs: - * Date Author Notes - * 2019-01-31 flybreak first version + * Date Author Notes + * 2019-01-31 flybreak first version + * 2019-07-16 WillianChan Increase the output of sensor information */ #include "sensor.h" @@ -268,13 +269,88 @@ static void sensor(int argc, char **argv) else if (!strcmp(argv[1], "info")) { struct rt_sensor_info info; + if (dev == RT_NULL) + { + LOG_W("Please probe sensor device first!"); + return ; + } rt_device_control(dev, RT_SENSOR_CTRL_GET_INFO, &info); - rt_kprintf("vendor :%d\n", info.vendor); - rt_kprintf("model :%s\n", info.model); - rt_kprintf("unit :%d\n", info.unit); + switch (info.vendor) + { + case RT_SENSOR_VENDOR_UNKNOWN: + rt_kprintf("vendor :unknown vendor\n"); + break; + case RT_SENSOR_VENDOR_STM: + rt_kprintf("vendor :STMicroelectronics\n"); + break; + case RT_SENSOR_VENDOR_BOSCH: + rt_kprintf("vendor :Bosch\n"); + break; + case RT_SENSOR_VENDOR_INVENSENSE: + rt_kprintf("vendor :Invensense\n"); + break; + case RT_SENSOR_VENDOR_SEMTECH: + rt_kprintf("vendor :Semtech\n"); + break; + case RT_SENSOR_VENDOR_GOERTEK: + rt_kprintf("vendor :Goertek\n"); + break; + case RT_SENSOR_VENDOR_MIRAMEMS: + rt_kprintf("vendor :MiraMEMS\n"); + break; + case RT_SENSOR_VENDOR_DALLAS: + rt_kprintf("vendor :Dallas\n"); + break; + } + rt_kprintf("model :%s\n", info.model); + switch (info.unit) + { + case RT_SENSOR_UNIT_NONE: + rt_kprintf("unit :none\n"); + break; + case RT_SENSOR_UNIT_MG: + rt_kprintf("unit :mG\n"); + break; + case RT_SENSOR_UNIT_MDPS: + rt_kprintf("unit :mdps\n"); + break; + case RT_SENSOR_UNIT_MGAUSS: + rt_kprintf("unit :mGauss\n"); + break; + case RT_SENSOR_UNIT_LUX: + rt_kprintf("unit :lux\n"); + break; + case RT_SENSOR_UNIT_CM: + rt_kprintf("unit :cm\n"); + break; + case RT_SENSOR_UNIT_PA: + rt_kprintf("unit :pa\n"); + break; + case RT_SENSOR_UNIT_PERMILLAGE: + rt_kprintf("unit :permillage\n"); + break; + case RT_SENSOR_UNIT_DCELSIUS: + rt_kprintf("unit :Celsius\n"); + break; + case RT_SENSOR_UNIT_HZ: + rt_kprintf("unit :HZ\n"); + break; + case RT_SENSOR_UNIT_ONE: + rt_kprintf("unit :1\n"); + break; + case RT_SENSOR_UNIT_BPM: + rt_kprintf("unit :bpm\n"); + break; + case RT_SENSOR_UNIT_MM: + rt_kprintf("unit :mm\n"); + break; + case RT_SENSOR_UNIT_MN: + rt_kprintf("unit :mN\n"); + break; + } rt_kprintf("range_max :%d\n", info.range_max); rt_kprintf("range_min :%d\n", info.range_min); - rt_kprintf("period_min:%d\n", info.period_min); + rt_kprintf("period_min:%dms\n", info.period_min); rt_kprintf("fifo_max :%d\n", info.fifo_max); } else if (!strcmp(argv[1], "read")) diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index 04034e8c44..e1d606557b 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -428,12 +428,10 @@ static void rt_dma_recv_update_put_index(struct rt_serial_device *serial, rt_siz } } - if(rx_fifo->is_full == RT_TRUE) + if(rx_fifo->is_full == RT_TRUE) { - rx_fifo->get_index = rx_fifo->put_index; - } - - if (rx_fifo->get_index >= serial->config.bufsz) rx_fifo->get_index = 0; + rx_fifo->get_index = rx_fifo->put_index; + } } /* diff --git a/components/drivers/usb/usbdevice/class/hid.c b/components/drivers/usb/usbdevice/class/hid.c index aea6d802d1..a9b2e62d70 100644 --- a/components/drivers/usb/usbdevice/class/hid.c +++ b/components/drivers/usb/usbdevice/class/hid.c @@ -372,7 +372,7 @@ const static char* _ustring[] = "Interface", }; -static void dump_data(uint8_t *data, rt_size_t size) +static void dump_data(rt_uint8_t *data, rt_size_t size) { rt_size_t i; for (i = 0; i < size; i++) diff --git a/components/drivers/wlan/SConscript b/components/drivers/wlan/SConscript index 271ca66a80..f2a6bbdc82 100644 --- a/components/drivers/wlan/SConscript +++ b/components/drivers/wlan/SConscript @@ -1,8 +1,30 @@ from building import * cwd = GetCurrentDir() -src = Glob('*.c') CPPPATH = [cwd] + +src = Split(''' + wlan_dev.c + ''') + +if GetDepend(['RT_WLAN_MANAGE_ENABLE']): + src += ['wlan_mgnt.c'] + +if GetDepend(['RT_WLAN_MSH_CMD_ENABLE']): + src += ['wlan_cmd.c'] + +if GetDepend(['RT_WLAN_PROT_ENABLE']): + src += ['wlan_prot.c'] + +if GetDepend(['RT_WLAN_PROT_LWIP_ENABLE']): + src += ['wlan_lwip.c'] + +if GetDepend(['RT_WLAN_CFG_ENABLE']): + src += ['wlan_cfg.c'] + +if GetDepend(['RT_WLAN_WORK_THREAD_ENABLE']): + src += ['wlan_workqueue.c'] + group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_WIFI'], CPPPATH = CPPPATH) Return('group') diff --git a/components/drivers/wlan/wlan_cfg.c b/components/drivers/wlan/wlan_cfg.c index 126cee40f5..7fa9ecb2da 100644 --- a/components/drivers/wlan/wlan_cfg.c +++ b/components/drivers/wlan/wlan_cfg.c @@ -19,6 +19,8 @@ #endif /* RT_WLAN_CFG_DEBUG */ #include <rtdbg.h> +#ifdef RT_WLAN_CFG_ENABLE + #define WLAN_CFG_LOCK() (rt_mutex_take(&cfg_mutex, RT_WAITING_FOREVER)) #define WLAN_CFG_UNLOCK() (rt_mutex_release(&cfg_mutex)) @@ -462,3 +464,5 @@ void rt_wlan_cfg_dump(void) rt_kprintf("%3d \n", info->channel); } } + +#endif diff --git a/components/drivers/wlan/wlan_cmd.c b/components/drivers/wlan/wlan_cmd.c index b962b63947..fead6a8bf2 100644 --- a/components/drivers/wlan/wlan_cmd.c +++ b/components/drivers/wlan/wlan_cmd.c @@ -13,6 +13,8 @@ #include <wlan_cfg.h> #include <wlan_prot.h> +#if defined(RT_WLAN_MANAGE_ENABLE) && defined(RT_WLAN_MSH_CMD_ENABLE) + struct wifi_cmd_des { const char *cmd; @@ -75,7 +77,7 @@ static int wifi_help(int argc, char *argv[]) { rt_kprintf("wifi\n"); rt_kprintf("wifi help\n"); - rt_kprintf("wifi scan\n"); + rt_kprintf("wifi scan [SSID]\n"); rt_kprintf("wifi join [SSID] [PASSWORD]\n"); rt_kprintf("wifi ap SSID [PASSWORD]\n"); rt_kprintf("wifi disc\n"); @@ -143,12 +145,23 @@ static int wifi_status(int argc, char *argv[]) static int wifi_scan(int argc, char *argv[]) { struct rt_wlan_scan_result *scan_result = RT_NULL; + struct rt_wlan_info *info = RT_NULL; + struct rt_wlan_info filter; - if (argc > 2) + if (argc > 3) return -1; + if (argc == 3) + { + INVALID_INFO(&filter); + SSID_SET(&filter, argv[2]); + info = &filter; + } + + /* clean scan result */ + rt_wlan_scan_result_clean(); /* scan ap info */ - scan_result = rt_wlan_scan_sync(); + scan_result = rt_wlan_scan_with_info(info); if (scan_result) { int index, num; @@ -224,8 +237,10 @@ static int wifi_join(int argc, char *argv[]) const char *key = RT_NULL; struct rt_wlan_cfg_info cfg_info; + rt_memset(&cfg_info, 0, sizeof(cfg_info)); if (argc == 2) { +#ifdef RT_WLAN_CFG_ENABLE /* get info to connect */ if (rt_wlan_cfg_read_index(&cfg_info, 0) == 1) { @@ -234,8 +249,9 @@ static int wifi_join(int argc, char *argv[]) key = (char *)(&cfg_info.key.val[0]); } else +#endif { - rt_kprintf("not find info\n"); + rt_kprintf("not find connect info\n"); } } else if (argc == 3) @@ -387,8 +403,9 @@ static int wifi_debug_save_cfg(int argc, char *argv[]) rt_memcpy(&cfg_info.key.val[0], password, len); cfg_info.key.len = len; } - +#ifdef RT_WLAN_CFG_ENABLE rt_wlan_cfg_save(&cfg_info); +#endif return 0; } @@ -396,7 +413,9 @@ static int wifi_debug_dump_cfg(int argc, char *argv[]) { if (argc == 1) { +#ifdef RT_WLAN_CFG_ENABLE rt_wlan_cfg_dump(); +#endif } else { @@ -409,8 +428,10 @@ static int wifi_debug_clear_cfg(int argc, char *argv[]) { if (argc == 1) { +#ifdef RT_WLAN_CFG_ENABLE rt_wlan_cfg_delete_all(); rt_wlan_cfg_cache_save(); +#endif } else { @@ -447,6 +468,10 @@ static int wifi_debug_set_mode(int argc, char *argv[]) { mode = RT_WLAN_AP; } + else if (rt_strcmp("none", argv[1]) == 0) + { + mode = RT_WLAN_NONE; + } else return -1; @@ -564,3 +589,5 @@ static int wifi_msh(int argc, char *argv[]) #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) FINSH_FUNCTION_EXPORT_ALIAS(wifi_msh, __cmd_wifi, wifi command.); #endif + +#endif diff --git a/components/drivers/wlan/wlan_dev.c b/components/drivers/wlan/wlan_dev.c index 82fa4e73e7..2490c2c456 100644 --- a/components/drivers/wlan/wlan_dev.c +++ b/components/drivers/wlan/wlan_dev.c @@ -21,6 +21,8 @@ #endif /* RT_WLAN_DEV_DEBUG */ #include <rtdbg.h> +#if defined(RT_USING_WIFI) || defined(RT_USING_WLAN) + #ifndef RT_DEVICE #define RT_DEVICE(__device) ((rt_device_t)__device) #endif @@ -56,6 +58,17 @@ rt_err_t rt_wlan_dev_init(struct rt_wlan_device *device, rt_wlan_mode_t mode) return -RT_ERROR; } + if (mode == RT_WLAN_AP && device->flags & RT_WLAN_FLAG_STA_ONLY) + { + LOG_E("F:%s L:%d This wlan device can only be set to sta mode!", __FUNCTION__, __LINE__); + return -RT_ERROR; + } + else if (mode == RT_WLAN_STATION && device->flags & RT_WLAN_FLAG_AP_ONLY) + { + LOG_E("F:%s L:%d This wlan device can only be set to ap mode!", __FUNCTION__, __LINE__); + return -RT_ERROR; + } + result = rt_device_init(RT_DEVICE(device)); if (result != RT_EOK) { @@ -522,8 +535,16 @@ rt_err_t rt_wlan_dev_scan(struct rt_wlan_device *device, struct rt_wlan_info *in } rt_memcpy(&scan_info.ssid, &info->ssid, sizeof(rt_wlan_ssid_t)); rt_memcpy(scan_info.bssid, info->bssid, RT_WLAN_BSSID_MAX_LENGTH); - scan_info.channel_min = -1; - scan_info.channel_max = -1; + if (info->channel > 0) + { + scan_info.channel_min = info->channel; + scan_info.channel_max = info->channel; + } + else + { + scan_info.channel_min = -1; + scan_info.channel_max = -1; + } p_scan_info = &scan_info; } result = rt_device_control(RT_DEVICE(device), RT_WLAN_CMD_SCAN, p_scan_info); @@ -545,7 +566,11 @@ 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) { +#ifdef RT_WLAN_PROT_ENABLE return rt_wlan_dev_transfer_prot(device, buff, len); +#else + return -RT_ERROR; +#endif } static rt_err_t _rt_wlan_dev_init(rt_device_t dev) @@ -768,14 +793,15 @@ rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name, con { rt_err_t err = RT_EOK; - if ((wlan == RT_NULL) || (name == RT_NULL) || (ops == RT_NULL)) + if ((wlan == RT_NULL) || (name == RT_NULL) || (ops == RT_NULL) || + (flag & RT_WLAN_FLAG_STA_ONLY && flag & RT_WLAN_FLAG_AP_ONLY)) { LOG_E("F:%s L:%d parameter Wrongful", __FUNCTION__, __LINE__); return RT_NULL; } rt_memset(wlan, 0, sizeof(struct rt_wlan_device)); - + #ifdef RT_USING_DEVICE_OPS wlan->device.ops = &wlan_ops; #else @@ -801,3 +827,5 @@ rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name, con return err; } + +#endif diff --git a/components/drivers/wlan/wlan_dev.h b/components/drivers/wlan/wlan_dev.h index a9300be9d7..96b22bc456 100644 --- a/components/drivers/wlan/wlan_dev.h +++ b/components/drivers/wlan/wlan_dev.h @@ -381,6 +381,11 @@ typedef struct rt_wlan_key rt_wlan_key_t; (_info)->channel = -1; \ } while(0) +#define SSID_SET(_info, _ssid) do { \ + rt_strncpy((char *)(_info)->ssid.val, (_ssid), RT_WLAN_SSID_MAX_LENGTH); \ + (_info)->ssid.len = rt_strlen((char *)(_info)->ssid.val); \ + } while(0) + struct rt_wlan_info { /* security type */ @@ -442,6 +447,7 @@ struct rt_wlan_device rt_wlan_pormisc_callback_t pormisc_callback; const struct rt_wlan_dev_ops *ops; rt_uint32_t flags; + struct netdev *netdev; void *prot; void *user_data; }; diff --git a/components/drivers/wlan/wlan_lwip.c b/components/drivers/wlan/wlan_lwip.c index 84b448c68f..797dd823fb 100644 --- a/components/drivers/wlan/wlan_lwip.c +++ b/components/drivers/wlan/wlan_lwip.c @@ -14,12 +14,17 @@ #include <wlan_prot.h> #include <wlan_workqueue.h> +#if defined(RT_WLAN_PROT_ENABLE) && defined(RT_WLAN_PROT_LWIP_ENABLE) + #ifdef RT_USING_LWIP #include <netif/ethernetif.h> #include <lwip/netifapi.h> #ifdef LWIP_USING_DHCPD #include <dhcp_server.h> #endif +#ifdef RT_USING_NETDEV +#include <netdev.h> +#endif #define DBG_TAG "WLAN.lwip" #ifdef RT_WLAN_LWIP_DEBUG @@ -33,6 +38,10 @@ #define IPADDR_STRLEN_MAX (32) #endif +#ifndef RT_WLAN_PROT_LWIP_NAME +#define RT_WLAN_PROT_LWIP_NAME ("lwip") +#endif + struct lwip_prot_des { struct rt_wlan_prot prot; @@ -47,12 +56,16 @@ static void netif_is_ready(struct rt_work *work, void *parameter) ip_addr_t ip_addr_zero = { 0 }; struct rt_wlan_device *wlan = parameter; struct lwip_prot_des *lwip_prot = (struct lwip_prot_des *)wlan->prot; - struct eth_device *eth_dev = &lwip_prot->eth; + struct eth_device *eth_dev; rt_base_t level; struct rt_wlan_buff buff; rt_uint32_t ip_addr[4]; char str[IPADDR_STRLEN_MAX]; + if (lwip_prot == RT_NULL) + return; + + eth_dev = &lwip_prot->eth; rt_timer_stop(&lwip_prot->timer); if (ip_addr_cmp(&(eth_dev->netif->ip_addr), &ip_addr_zero) != 0) { @@ -100,18 +113,26 @@ static void netif_is_ready(struct rt_work *work, void *parameter) LOG_I("Got IP address : %s", str); exit: level = rt_hw_interrupt_disable(); - rt_memset(work, 0, sizeof(struct rt_work)); + if (work) + { + rt_memset(work, 0, sizeof(struct rt_work)); + } rt_hw_interrupt_enable(level); } static void timer_callback(void *parameter) { +#ifdef RT_WLAN_WORK_THREAD_ENABLE struct rt_workqueue *workqueue; struct rt_wlan_device *wlan = parameter; struct lwip_prot_des *lwip_prot = (struct lwip_prot_des *)wlan->prot; - struct rt_work *work = &lwip_prot->work; + struct rt_work *work; rt_base_t level; + if (lwip_prot == RT_NULL) + return; + + work = &lwip_prot->work; workqueue = rt_wlan_get_workqueue(); if (workqueue != RT_NULL) { @@ -125,13 +146,22 @@ static void timer_callback(void *parameter) rt_hw_interrupt_enable(level); } } +#else + netif_is_ready(RT_NULL, parameter); +#endif + } static void netif_set_connected(void *parameter) { struct rt_wlan_device *wlan = parameter; struct lwip_prot_des *lwip_prot = wlan->prot; - struct eth_device *eth_dev = &lwip_prot->eth; + struct eth_device *eth_dev; + + if (lwip_prot == RT_NULL) + return; + + eth_dev = &lwip_prot->eth; if (lwip_prot->connected_flag) { @@ -192,6 +222,9 @@ static void rt_wlan_lwip_event_handle(struct rt_wlan_prot *port, struct rt_wlan_ struct lwip_prot_des *lwip_prot = (struct lwip_prot_des *)wlan->prot; rt_bool_t flag_old; + if (lwip_prot == RT_NULL) + return; + flag_old = lwip_prot->connected_flag; switch (event) @@ -238,8 +271,11 @@ static void rt_wlan_lwip_event_handle(struct rt_wlan_prot *port, struct rt_wlan_ } if (flag_old != lwip_prot->connected_flag) { +#ifdef RT_WLAN_WORK_THREAD_ENABLE rt_wlan_workqueue_dowork(netif_set_connected, wlan); - // netif_set_connected(wlan); +#else + netif_set_connected(wlan); +#endif } } @@ -452,15 +488,14 @@ static struct rt_wlan_prot *rt_wlan_lwip_protocol_register(struct rt_wlan_prot * return RT_NULL; } rt_memcpy(&lwip_prot->prot, prot, sizeof(struct rt_wlan_prot)); - if (wlan->mode == RT_WLAN_STATION) - { - rt_sprintf(timer_name, "timer_%s", eth_name); - rt_timer_init(&lwip_prot->timer, timer_name, timer_callback, wlan, rt_tick_from_millisecond(1000), - RT_TIMER_FLAG_SOFT_TIMER | RT_TIMER_FLAG_ONE_SHOT); - } + rt_sprintf(timer_name, "timer_%s", eth_name); + rt_timer_init(&lwip_prot->timer, timer_name, timer_callback, wlan, rt_tick_from_millisecond(1000), + RT_TIMER_FLAG_SOFT_TIMER | RT_TIMER_FLAG_ONE_SHOT); netif_set_up(eth->netif); LOG_I("eth device init ok name:%s", eth_name); - +#ifdef RT_USING_NETDEV + wlan->netdev = netdev_get_by_name(eth_name); +#endif return &lwip_prot->prot; } @@ -483,7 +518,7 @@ int rt_wlan_lwip_init(void) rt_wlan_prot_event_t event; rt_memset(&prot, 0, sizeof(prot)); - rt_strncpy(&prot.name[0], RT_WLAN_PROT_LWIP, RT_WLAN_PROT_NAME_LEN); + rt_strncpy(&prot.name[0], RT_WLAN_PROT_LWIP_NAME, RT_WLAN_PROT_NAME_LEN); prot.ops = &ops; if (rt_wlan_prot_regisetr(&prot) != RT_EOK) @@ -502,3 +537,4 @@ int rt_wlan_lwip_init(void) INIT_PREV_EXPORT(rt_wlan_lwip_init); #endif +#endif diff --git a/components/drivers/wlan/wlan_mgnt.c b/components/drivers/wlan/wlan_mgnt.c index 91a77e43d0..e0ee67e06c 100644 --- a/components/drivers/wlan/wlan_mgnt.c +++ b/components/drivers/wlan/wlan_mgnt.c @@ -24,6 +24,8 @@ #endif /* RT_WLAN_MGNT_DEBUG */ #include <rtdbg.h> +#ifdef RT_WLAN_MANAGE_ENABLE + #ifndef RT_WLAN_DEVICE #define RT_WLAN_DEVICE(__device) ((struct rt_wlan_device *)__device) #endif @@ -48,13 +50,16 @@ #define COMPLETE_LOCK() (rt_mutex_take(&complete_mutex, RT_WAITING_FOREVER)) #define COMPLETE_UNLOCK() (rt_mutex_release(&complete_mutex)) +#ifdef RT_WLAN_AUTO_CONNECT_ENABLE #define TIME_STOP() (rt_timer_stop(&reconnect_time)) #define TIME_START() (rt_timer_start(&reconnect_time)) - -#define DISCONNECT_RESPONSE_TICK (2000) +#else +#define TIME_STOP() +#define TIME_START() +#endif #if RT_WLAN_EBOX_NUM < 1 -#error "event box num Too little" +#error "event box num Too few" #endif struct rt_wlan_mgnt_des @@ -113,8 +118,11 @@ 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 struct rt_wlan_info *scan_filter; +#ifdef RT_WLAN_AUTO_CONNECT_ENABLE static struct rt_timer reconnect_time; +#endif rt_inline int _sta_is_null(void) { @@ -145,9 +153,97 @@ rt_inline rt_bool_t _is_do_connect(void) return RT_TRUE; } -static void rt_wlan_mgnt_work(void *parameter); +#ifdef RT_WLAN_WORK_THREAD_ENABLE + +static rt_bool_t rt_wlan_info_isequ(struct rt_wlan_info *info1, struct rt_wlan_info *info2) +{ + rt_bool_t is_equ = 1; + rt_uint8_t bssid_zero[RT_WLAN_BSSID_MAX_LENGTH] = { 0 }; + + if (is_equ && (info1->security != SECURITY_UNKNOWN) && (info2->security != SECURITY_UNKNOWN)) + { + is_equ &= info2->security == info1->security; + } + if (is_equ && ((info1->ssid.len > 0) && (info2->ssid.len > 0))) + { + is_equ &= info1->ssid.len == info2->ssid.len; + is_equ &= rt_memcmp(&info2->ssid.val[0], &info1->ssid.val[0], info1->ssid.len) == 0; + } + if (is_equ && (rt_memcmp(&info1->bssid[0], bssid_zero, RT_WLAN_BSSID_MAX_LENGTH)) && + (rt_memcmp(&info2->bssid[0], bssid_zero, RT_WLAN_BSSID_MAX_LENGTH))) + { + is_equ &= rt_memcmp(&info1->bssid[0], &info2->bssid[0], RT_WLAN_BSSID_MAX_LENGTH) == 0; + } + if (is_equ && info1->datarate && info2->datarate) + { + is_equ &= info1->datarate == info2->datarate; + } + if (is_equ && (info1->channel >= 0) && (info2->channel >= 0)) + { + is_equ &= info1->channel == info2->channel; + } + if (is_equ && (info1->rssi < 0) && (info2->rssi < 0)) + { + is_equ &= info1->rssi == info2->rssi; + } + return is_equ; +} + +static void rt_wlan_mgnt_work(void *parameter) +{ + struct rt_wlan_msg *msg = parameter; + void *user_parameter; + rt_wlan_event_handler handler = RT_NULL; + struct rt_wlan_buff user_buff = { 0 }; + rt_base_t level; + + /* Get user callback */ + if (msg->event < RT_WLAN_EVT_MAX) + { + level = rt_hw_interrupt_disable(); + handler = event_tab[msg->event].handler; + user_parameter = event_tab[msg->event].parameter; + rt_hw_interrupt_enable(level); + } + + /* run user callback fun */ + if (handler) + { + user_buff.data = msg->buff; + user_buff.len = msg->len; + RT_WLAN_LOG_D("wlan work thread run user callback, event:%d", msg->event); + handler(msg->event, &user_buff, user_parameter); + } + + switch (msg->event) + { + case RT_WLAN_EVT_STA_CONNECTED: + { + struct rt_wlan_cfg_info cfg_info; + + rt_memset(&cfg_info, 0, sizeof(cfg_info)); + /* save config */ + if (rt_wlan_is_connected() == RT_TRUE) + { + rt_enter_critical(); + cfg_info.info = _sta_mgnt.info; + cfg_info.key = _sta_mgnt.key; + rt_exit_critical(); + RT_WLAN_LOG_D("run save config! ssid:%s len%d", _sta_mgnt.info.ssid.val, _sta_mgnt.info.ssid.len); +#ifdef RT_WLAN_CFG_ENABLE + rt_wlan_cfg_save(&cfg_info); +#endif + } + break; + } + default : + break; + } + + rt_free(msg); +} -static rt_err_t rt_wlan_send_msg(rt_wlan_dev_event_t event, void *buff, int len) +static rt_err_t rt_wlan_send_to_thread(rt_wlan_event_t event, void *buff, int len) { struct rt_wlan_msg *msg; @@ -177,14 +273,16 @@ static rt_err_t rt_wlan_send_msg(rt_wlan_dev_event_t event, void *buff, int len) } return RT_EOK; } +#endif static rt_err_t rt_wlan_scan_result_cache(struct rt_wlan_info *info, int timeout) { struct rt_wlan_info *ptable; rt_err_t err = RT_EOK; int i, insert = -1; + rt_base_t level; - if (_sta_is_null() || (info == RT_NULL)) return RT_EOK; + if (_sta_is_null() || (info == RT_NULL) || (info->ssid.len == 0)) return RT_EOK; RT_WLAN_LOG_D("ssid:%s len:%d mac:%02x:%02x:%02x:%02x:%02x:%02x", info->ssid.val, info->ssid.len, info->bssid[0], info->bssid[1], info->bssid[2], info->bssid[3], info->bssid[4], info->bssid[5]); @@ -193,6 +291,23 @@ static rt_err_t rt_wlan_scan_result_cache(struct rt_wlan_info *info, int timeout if (err != RT_EOK) return err; + /* scanning result filtering */ + level = rt_hw_interrupt_disable(); + if (scan_filter) + { + struct rt_wlan_info _tmp_info = *scan_filter; + rt_hw_interrupt_enable(level); + if (rt_wlan_info_isequ(&_tmp_info, info) != RT_TRUE) + { + rt_mutex_release(&scan_result_mutex); + return RT_EOK; + } + } + else + { + rt_hw_interrupt_enable(level); + } + /* de-duplicatio */ for (i = 0; i < scan_result.num; i++) { @@ -381,7 +496,7 @@ static rt_err_t rt_wlan_sta_info_del_all(int timeout) sta_info.node = RT_NULL; return err; } - +#ifdef RT_WLAN_AUTO_CONNECT_ENABLE static void rt_wlan_auto_connect_run(struct rt_work *work, void *parameter) { static rt_uint32_t id = 0; @@ -413,12 +528,12 @@ static void rt_wlan_auto_connect_run(struct rt_work *work, void *parameter) if (id >= rt_wlan_cfg_get_num()) id = 0; - if ((cfg_info.key.len > 0) && (cfg_info.key.len < RT_WLAN_PASSWORD_MAX_LENGTH)) + if ((cfg_info.key.len > 0) && (cfg_info.key.len <= RT_WLAN_PASSWORD_MAX_LENGTH)) { cfg_info.key.val[cfg_info.key.len] = '\0'; password = (char *)(&cfg_info.key.val[0]); } - rt_wlan_connect_adv(&cfg_info.info, password); + rt_wlan_connect((char *)cfg_info.info.ssid.val, password); exit: rt_mutex_release(&mgnt_mutex); level = rt_hw_interrupt_disable(); @@ -449,41 +564,10 @@ static void rt_wlan_cyclic_check(void *parameter) } } } - -static void rt_wlan_mgnt_work(void *parameter) -{ - struct rt_wlan_msg *msg = parameter; - - switch (msg->event) - { - case RT_WLAN_DEV_EVT_CONNECT: - { - struct rt_wlan_cfg_info cfg_info; - - /* save config */ - if (rt_wlan_is_connected() == RT_TRUE) - { - rt_enter_critical(); - cfg_info.info = _sta_mgnt.info; - cfg_info.key = _sta_mgnt.key; - rt_exit_critical(); - RT_WLAN_LOG_D("run save config! ssid:%s len%d", _sta_mgnt.info.ssid.val, _sta_mgnt.info.ssid.len); - rt_wlan_cfg_save(&cfg_info); - } - break; - } - default : - break; - } - - rt_free(msg); -} +#endif static void rt_wlan_event_dispatch(struct rt_wlan_device *device, rt_wlan_dev_event_t event, struct rt_wlan_buff *buff, void *parameter) { - rt_base_t level; - void *user_parameter; - rt_wlan_event_handler handler = RT_NULL; rt_err_t err = RT_NULL; rt_wlan_event_t user_event = RT_WLAN_EVT_MAX; int i; @@ -503,7 +587,6 @@ static void rt_wlan_event_dispatch(struct rt_wlan_device *device, rt_wlan_dev_ev _sta_mgnt.state &= ~RT_WLAN_STATE_CONNECTING; user_event = RT_WLAN_EVT_STA_CONNECTED; TIME_STOP(); - rt_wlan_send_msg(event, RT_NULL, 0); user_buff.data = &_sta_mgnt.info; user_buff.len = sizeof(struct rt_wlan_info); RT_WLAN_LOG_I("wifi connect success ssid:%s", &_sta_mgnt.info.ssid.val[0]); @@ -518,7 +601,10 @@ static void rt_wlan_event_dispatch(struct rt_wlan_device *device, rt_wlan_dev_ev user_event = RT_WLAN_EVT_STA_CONNECTED_FAIL; user_buff.data = &_sta_mgnt.info; user_buff.len = sizeof(struct rt_wlan_info); - TIME_START(); + if (rt_wlan_get_autoreconnect_mode()) + { + TIME_START(); + } break; } case RT_WLAN_DEV_EVT_DISCONNECT: @@ -529,7 +615,10 @@ static void rt_wlan_event_dispatch(struct rt_wlan_device *device, rt_wlan_dev_ev user_event = RT_WLAN_EVT_STA_DISCONNECTED; user_buff.data = &_sta_mgnt.info; user_buff.len = sizeof(struct rt_wlan_info); - TIME_START(); + if (rt_wlan_get_autoreconnect_mode()) + { + TIME_START(); + } break; } case RT_WLAN_DEV_EVT_AP_START: @@ -622,20 +711,30 @@ 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) +#ifdef RT_WLAN_WORK_THREAD_ENABLE + rt_wlan_send_to_thread(user_event, RT_NULL, 0); +#else { - level = rt_hw_interrupt_disable(); - handler = event_tab[user_event].handler; - user_parameter = event_tab[user_event].parameter; - rt_hw_interrupt_enable(level); - } + void *user_parameter; + rt_wlan_event_handler handler = RT_NULL; + rt_base_t level; + /* Get user callback */ + if (user_event < RT_WLAN_EVT_MAX) + { + level = rt_hw_interrupt_disable(); + handler = event_tab[user_event].handler; + user_parameter = event_tab[user_event].parameter; + rt_hw_interrupt_enable(level); + } - /* run user callback fun */ - if (handler) - { - handler(user_event, &user_buff, user_parameter); + /* run user callback fun */ + if (handler) + { + RT_WLAN_LOG_D("unknown thread run user callback, event:%d", user_event); + handler(user_event, &user_buff, user_parameter); + } } +#endif } static struct rt_wlan_complete_des *rt_wlan_complete_create(const char *name) @@ -820,14 +919,30 @@ rt_err_t rt_wlan_set_mode(const char *dev_name, rt_wlan_mode_t mode) /* update dev event handle */ if (up_event_flag == 1) { - rt_wlan_dev_event_t event; - for (event = RT_WLAN_DEV_EVT_INIT_DONE; event < RT_WLAN_DEV_EVT_MAX; event++) + if (handler) { - if (handler) + if (mode == RT_WLAN_STATION) + { + rt_wlan_dev_register_event_handler(RT_WLAN_DEVICE(device), RT_WLAN_DEV_EVT_CONNECT, handler, RT_NULL); + rt_wlan_dev_register_event_handler(RT_WLAN_DEVICE(device), RT_WLAN_DEV_EVT_CONNECT_FAIL, handler, RT_NULL); + rt_wlan_dev_register_event_handler(RT_WLAN_DEVICE(device), RT_WLAN_DEV_EVT_DISCONNECT, handler, RT_NULL); + rt_wlan_dev_register_event_handler(RT_WLAN_DEVICE(device), RT_WLAN_DEV_EVT_SCAN_REPORT, handler, RT_NULL); + rt_wlan_dev_register_event_handler(RT_WLAN_DEVICE(device), RT_WLAN_DEV_EVT_SCAN_DONE, handler, RT_NULL); + } + else if (mode == RT_WLAN_AP) { - rt_wlan_dev_register_event_handler(RT_WLAN_DEVICE(device), event, handler, RT_NULL); + rt_wlan_dev_register_event_handler(RT_WLAN_DEVICE(device), RT_WLAN_DEV_EVT_AP_START, handler, RT_NULL); + rt_wlan_dev_register_event_handler(RT_WLAN_DEVICE(device), RT_WLAN_DEV_EVT_AP_STOP, handler, RT_NULL); + rt_wlan_dev_register_event_handler(RT_WLAN_DEVICE(device), RT_WLAN_DEV_EVT_AP_ASSOCIATED, handler, RT_NULL); + rt_wlan_dev_register_event_handler(RT_WLAN_DEVICE(device), RT_WLAN_DEV_EVT_AP_DISASSOCIATED, handler, RT_NULL); + rt_wlan_dev_register_event_handler(RT_WLAN_DEVICE(device), RT_WLAN_DEV_EVT_AP_ASSOCIATE_FAILED, handler, RT_NULL); } - else + } + else + { + rt_wlan_dev_event_t event; + handler = rt_wlan_event_dispatch; + for (event = RT_WLAN_DEV_EVT_INIT_DONE; event < RT_WLAN_DEV_EVT_MAX; event++) { rt_wlan_dev_unregister_event_handler(RT_WLAN_DEVICE(device), event, handler); } @@ -836,8 +951,11 @@ rt_err_t rt_wlan_set_mode(const char *dev_name, rt_wlan_mode_t mode) MGNT_UNLOCK(); /* Mount protocol */ -#ifdef RT_WLAN_DEFAULT_PROT - rt_wlan_prot_attach(dev_name, RT_WLAN_DEFAULT_PROT); +#if defined(RT_WLAN_PROT_ENABLE) && defined(RT_WLAN_DEFAULT_PROT) + if (err == RT_EOK) + { + rt_wlan_prot_attach(dev_name, RT_WLAN_DEFAULT_PROT); + } #endif return err; } @@ -932,6 +1050,7 @@ rt_err_t rt_wlan_connect(const char *ssid, const char *password) struct rt_wlan_info info; struct rt_wlan_complete_des *complete; rt_uint32_t set = 0, recved = 0; + rt_uint32_t scan_retry = RT_WLAN_SCAN_RETRY_CNT; /* sta dev Can't be NULL */ if (_sta_is_null()) @@ -960,12 +1079,11 @@ rt_err_t rt_wlan_connect(const char *ssid, const char *password) /* get info from cache */ INVALID_INFO(&info); MGNT_LOCK(); - if (rt_wlan_find_best_by_cache(ssid, &info) != RT_TRUE) + while (scan_retry-- && rt_wlan_find_best_by_cache(ssid, &info) != RT_TRUE) { rt_wlan_scan_sync(); - rt_wlan_find_best_by_cache(ssid, &info); - rt_wlan_scan_result_clean(); } + rt_wlan_scan_result_clean(); if (info.ssid.len <= 0) { @@ -1216,10 +1334,13 @@ rt_err_t rt_wlan_get_info(struct rt_wlan_info *info) } RT_WLAN_LOG_D("%s is run", __FUNCTION__); - rt_enter_critical(); - *info = _sta_mgnt.info; - rt_exit_critical(); - return RT_EOK; + if (rt_wlan_is_connected() == RT_TRUE) + { + *info = _sta_mgnt.info; + info->rssi = rt_wlan_get_rssi(); + return RT_EOK; + } + return -RT_ERROR; } int rt_wlan_get_rssi(void) @@ -1268,6 +1389,7 @@ rt_err_t rt_wlan_start_ap(const char *ssid, const char *password) rt_memcpy(&info.ssid.val, ssid, ssid_len); info.ssid.len = ssid_len; info.channel = 6; + info.band = RT_802_11_BAND_2_4GHZ; /* Initializing events that need to wait */ MGNT_LOCK(); @@ -1427,8 +1549,12 @@ rt_err_t rt_wlan_ap_get_info(struct rt_wlan_info *info) } RT_WLAN_LOG_D("%s is run", __FUNCTION__); - *info = _ap_mgnt.info; - return RT_EOK; + if (rt_wlan_ap_is_active() == RT_TRUE) + { + *info = _ap_mgnt.info; + return RT_EOK; + } + return -RT_ERROR; } /* get sta number */ @@ -1555,27 +1681,35 @@ rt_country_code_t rt_wlan_ap_get_country(void) void rt_wlan_config_autoreconnect(rt_bool_t enable) { +#ifdef RT_WLAN_AUTO_CONNECT_ENABLE RT_WLAN_LOG_D("%s is run enable:%d", __FUNCTION__, enable); MGNT_LOCK(); if (enable) { + TIME_START(); _sta_mgnt.flags |= RT_WLAN_STATE_AUTOEN; } else { + TIME_STOP(); _sta_mgnt.flags &= ~RT_WLAN_STATE_AUTOEN; } MGNT_UNLOCK(); +#endif } rt_bool_t rt_wlan_get_autoreconnect_mode(void) { +#ifdef RT_WLAN_AUTO_CONNECT_ENABLE rt_bool_t enable = 0; enable = _sta_mgnt.flags & RT_WLAN_STATE_AUTOEN ? 1 : 0; RT_WLAN_LOG_D("%s is run enable:%d", __FUNCTION__, enable); return enable; +#else + return RT_FALSE; +#endif } /* Call the underlying scan function, which is asynchronous. @@ -1612,6 +1746,9 @@ struct rt_wlan_scan_result *rt_wlan_scan_with_info(struct rt_wlan_info *info) rt_err_t err = RT_EOK; struct rt_wlan_complete_des *complete; rt_uint32_t set = 0, recved = 0; + static struct rt_wlan_info scan_filter_info; + rt_base_t level; + struct rt_wlan_scan_result *result; if (_sta_is_null()) { @@ -1633,14 +1770,23 @@ struct rt_wlan_scan_result *rt_wlan_scan_with_info(struct rt_wlan_info *info) return &scan_result; } + /* add scan info filter */ + if (info) + { + scan_filter_info = *info; + level = rt_hw_interrupt_disable(); + scan_filter = &scan_filter_info; + rt_hw_interrupt_enable(level); + } + /* run scan */ err = rt_wlan_dev_scan(STA_DEVICE(), info); if (err != RT_EOK) { rt_wlan_complete_delete(complete); RT_WLAN_LOG_E("scan sync fail"); - MGNT_UNLOCK(); - return RT_NULL; + result = RT_NULL; + goto scan_exit; } /* Initializing events that need to wait */ @@ -1653,12 +1799,17 @@ struct rt_wlan_scan_result *rt_wlan_scan_with_info(struct rt_wlan_info *info) if (!(recved & set)) { RT_WLAN_LOG_E("scan wait timeout!"); - MGNT_UNLOCK(); - return &scan_result; + result = &scan_result; + goto scan_exit; } +scan_exit: MGNT_UNLOCK(); - return &scan_result; + level = rt_hw_interrupt_disable(); + scan_filter = RT_NULL; + rt_hw_interrupt_enable(level); + result = &scan_result; + return result; } int rt_wlan_scan_get_info_num(void) @@ -1709,8 +1860,7 @@ int rt_wlan_scan_find_cache(struct rt_wlan_info *info, struct rt_wlan_info *out_ { int i = 0, count = 0; struct rt_wlan_info *scan_info; - rt_bool_t is_equ = 1; - rt_uint8_t bssid_zero[RT_WLAN_BSSID_MAX_LENGTH] = { 0 }; + rt_bool_t is_equ; if ((out_info == RT_NULL) || (info == RT_NULL) || (num <= 0)) { @@ -1721,31 +1871,7 @@ int rt_wlan_scan_find_cache(struct rt_wlan_info *info, struct rt_wlan_info *out_ for (i = 0; (i < scan_result.num) && (count < num); i++) { scan_info = &scan_result.info[i]; - - if (is_equ && (info->security != SECURITY_UNKNOWN)) - { - is_equ &= info->security == scan_info->security; - } - if (is_equ && ((info->ssid.len > 0) && (info->ssid.len == scan_info->ssid.len))) - { - is_equ &= rt_memcmp(&info->ssid.val[0], &scan_info->ssid.val[0], scan_info->ssid.len) == 0; - } - if (is_equ && (rt_memcmp(&info->bssid[0], bssid_zero, RT_WLAN_BSSID_MAX_LENGTH))) - { - is_equ &= rt_memcmp(&info->bssid[0], &scan_info->bssid[0], RT_WLAN_BSSID_MAX_LENGTH) == 0; - } - if (is_equ && info->datarate) - { - is_equ &= info->datarate == scan_info->datarate; - } - if (is_equ && (info->channel >= 0)) - { - is_equ &= info->channel == scan_info->channel; - } - if (is_equ && (info->rssi < 0)) - { - is_equ &= info->rssi == scan_info->rssi; - } + is_equ = rt_wlan_info_isequ(scan_info, info); /* Determine whether to find */ if (is_equ) { @@ -1840,8 +1966,6 @@ void rt_wlan_mgnt_unlock(void) int rt_wlan_prot_ready_event(struct rt_wlan_device *wlan, struct rt_wlan_buff *buff) { rt_base_t level; - void *user_parameter; - rt_wlan_event_handler handler = RT_NULL; if ((wlan == RT_NULL) || (_sta_mgnt.device != wlan) || (!(_sta_mgnt.state & RT_WLAN_STATE_CONNECT))) @@ -1854,13 +1978,24 @@ int rt_wlan_prot_ready_event(struct rt_wlan_device *wlan, struct rt_wlan_buff *b } level = rt_hw_interrupt_disable(); _sta_mgnt.state |= RT_WLAN_STATE_READY; - handler = event_tab[RT_WLAN_EVT_READY].handler; - user_parameter = event_tab[RT_WLAN_EVT_READY].parameter; rt_hw_interrupt_enable(level); - if (handler) +#ifdef RT_WLAN_WORK_THREAD_ENABLE + rt_wlan_send_to_thread(RT_WLAN_EVT_READY, buff->data, buff->len); +#else { - handler(RT_WLAN_EVT_READY, buff, user_parameter); + void *user_parameter; + rt_wlan_event_handler handler = RT_NULL; + + level = rt_hw_interrupt_disable(); + handler = event_tab[RT_WLAN_EVT_READY].handler; + user_parameter = event_tab[RT_WLAN_EVT_READY].parameter; + rt_hw_interrupt_enable(level); + if (handler) + { + handler(RT_WLAN_EVT_READY, buff, user_parameter); + } } +#endif return 0; } @@ -1879,10 +2014,15 @@ int rt_wlan_init(void) rt_mutex_init(&scan_result_mutex, "scan", RT_IPC_FLAG_FIFO); rt_mutex_init(&sta_info_mutex, "sta", RT_IPC_FLAG_FIFO); 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); +#ifdef RT_WLAN_AUTO_CONNECT_ENABLE + rt_timer_init(&reconnect_time, "wifi_tim", rt_wlan_cyclic_check, RT_NULL, + rt_tick_from_millisecond(AUTO_CONNECTION_PERIOD_MS), + RT_TIMER_FLAG_PERIODIC | RT_TIMER_FLAG_SOFT_TIMER); +#endif _init_flag = 1; } return 0; } INIT_PREV_EXPORT(rt_wlan_init); + +#endif diff --git a/components/drivers/wlan/wlan_mgnt.h b/components/drivers/wlan/wlan_mgnt.h index f4d9e0cff9..df0827bb7b 100644 --- a/components/drivers/wlan/wlan_mgnt.h +++ b/components/drivers/wlan/wlan_mgnt.h @@ -37,6 +37,14 @@ extern "C" { #define RT_WLAN_EBOX_NUM (10) #endif +#ifndef RT_WLAN_SCAN_RETRY_CNT +#define RT_WLAN_SCAN_RETRY_CNT (3) +#endif + +#ifndef AUTO_CONNECTION_PERIOD_MS +#define AUTO_CONNECTION_PERIOD_MS (2000) +#endif + /*state fot station*/ #define RT_WLAN_STATE_CONNECT (1UL << 0) #define RT_WLAN_STATE_CONNECTING (1UL << 1) diff --git a/components/drivers/wlan/wlan_prot.c b/components/drivers/wlan/wlan_prot.c index 0402962e01..b1a1b5de99 100644 --- a/components/drivers/wlan/wlan_prot.c +++ b/components/drivers/wlan/wlan_prot.c @@ -21,6 +21,8 @@ #endif /* RT_WLAN_PROT_DEBUG */ #include <rtdbg.h> +#ifdef RT_WLAN_PROT_ENABLE + #if RT_WLAN_PROT_NAME_LEN < 4 #error "The name is too short" #endif @@ -160,7 +162,7 @@ rt_err_t rt_wlan_prot_attach_dev(struct rt_wlan_device *wlan, const char *prot_n { int i = 0; struct rt_wlan_prot *prot = wlan->prot; - rt_wlan_dev_event_t event; + rt_wlan_dev_event_handler handler = rt_wlan_prot_event_handle; if (wlan == RT_NULL) { @@ -180,7 +182,7 @@ rt_err_t rt_wlan_prot_attach_dev(struct rt_wlan_device *wlan, const char *prot_n rt_wlan_prot_detach_dev(wlan); #ifdef RT_WLAN_PROT_LWIP_PBUF_FORCE - if (rt_strcmp(RT_WLAN_PROT_LWIP, prot_name) != 0) + if (rt_strcmp(RT_WLAN_PROT_LWIP_NAME, prot_name) != 0) { return -RT_ERROR; } @@ -202,13 +204,12 @@ rt_err_t rt_wlan_prot_attach_dev(struct rt_wlan_device *wlan, const char *prot_n return -RT_ERROR; } - for (event = RT_WLAN_DEV_EVT_INIT_DONE; event < RT_WLAN_DEV_EVT_MAX; event ++) - { - if (rt_wlan_dev_register_event_handler(wlan, event, rt_wlan_prot_event_handle, RT_NULL) != RT_EOK) - { - LOG_E("prot register event filed:%d", event); - } - } + rt_wlan_dev_register_event_handler(wlan, RT_WLAN_DEV_EVT_CONNECT, handler, RT_NULL); + rt_wlan_dev_register_event_handler(wlan, RT_WLAN_DEV_EVT_DISCONNECT, handler, RT_NULL); + rt_wlan_dev_register_event_handler(wlan, RT_WLAN_DEV_EVT_AP_START, handler, RT_NULL); + rt_wlan_dev_register_event_handler(wlan, RT_WLAN_DEV_EVT_AP_STOP, handler, RT_NULL); + rt_wlan_dev_register_event_handler(wlan, RT_WLAN_DEV_EVT_AP_ASSOCIATED, handler, RT_NULL); + rt_wlan_dev_register_event_handler(wlan, RT_WLAN_DEV_EVT_AP_DISASSOCIATED, handler, RT_NULL); return RT_EOK; } @@ -360,3 +361,4 @@ void rt_wlan_prot_dump(void) } } } +#endif diff --git a/components/drivers/wlan/wlan_prot.h b/components/drivers/wlan/wlan_prot.h index 34c5bae7fd..2df979270f 100644 --- a/components/drivers/wlan/wlan_prot.h +++ b/components/drivers/wlan/wlan_prot.h @@ -25,8 +25,6 @@ extern "C" { #define RT_LWAN_ID_PREFIX (0x5054) -#define RT_WLAN_PROT_LWIP ("lwip") - typedef enum { RT_WLAN_PROT_EVT_INIT_DONE = 0, diff --git a/components/drivers/wlan/wlan_workqueue.c b/components/drivers/wlan/wlan_workqueue.c index ec21243d60..4cd98346d2 100644 --- a/components/drivers/wlan/wlan_workqueue.c +++ b/components/drivers/wlan/wlan_workqueue.c @@ -17,6 +17,8 @@ #define DBG_LVL DBG_INFO #include <rtdbg.h> +#ifdef RT_WLAN_WORK_THREAD_ENABLE + struct rt_wlan_work { struct rt_work work; @@ -95,3 +97,5 @@ int rt_wlan_workqueue_init(void) return 0; } INIT_PREV_EXPORT(rt_wlan_workqueue_init); + +#endif diff --git a/components/finsh/finsh_vm.c b/components/finsh/finsh_vm.c index fcd58494a9..7c56407084 100644 --- a/components/finsh/finsh_vm.c +++ b/components/finsh/finsh_vm.c @@ -78,28 +78,6 @@ void finsh_syscall_append(const char* name, syscall_func func) } #endif -#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) -struct finsh_syscall* finsh_syscall_next(struct finsh_syscall* call) -{ - unsigned int *ptr; - ptr = (unsigned int*) (call + 1); - while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) _syscall_table_end)) - ptr ++; - - return (struct finsh_syscall*)ptr; -} - -struct finsh_sysvar* finsh_sysvar_next(struct finsh_sysvar* call) -{ - unsigned int *ptr; - ptr = (unsigned int*) (call + 1); - while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) _sysvar_table_end)) - ptr ++; - - return (struct finsh_sysvar*)ptr; -} -#endif - struct finsh_syscall* finsh_syscall_lookup(const char* name) { struct finsh_syscall* index; diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 1505e071c5..76ac726597 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -44,6 +44,28 @@ struct finsh_shell _shell; struct finsh_shell *shell; static char *finsh_prompt_custom = RT_NULL; +#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) +struct finsh_syscall* finsh_syscall_next(struct finsh_syscall* call) +{ + unsigned int *ptr; + ptr = (unsigned int*) (call + 1); + while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) _syscall_table_end)) + ptr ++; + + return (struct finsh_syscall*)ptr; +} + +struct finsh_sysvar* finsh_sysvar_next(struct finsh_sysvar* call) +{ + unsigned int *ptr; + ptr = (unsigned int*) (call + 1); + while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) _sysvar_table_end)) + ptr ++; + + return (struct finsh_sysvar*)ptr; +} +#endif /* defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) */ + #ifdef RT_USING_HEAP int finsh_set_prompt(const char * prompt) { diff --git a/components/net/sal_socket/impl/af_inet_lwip.c b/components/net/sal_socket/impl/af_inet_lwip.c index e53aa845cc..56df735ab9 100644 --- a/components/net/sal_socket/impl/af_inet_lwip.c +++ b/components/net/sal_socket/impl/af_inet_lwip.c @@ -273,6 +273,8 @@ static int inet_poll(struct dfs_fd *file, struct rt_pollreq *req) if (sock->errevent) { mask |= POLLERR; + /* clean error event */ + sock->errevent = 0; } rt_hw_interrupt_enable(level); } |
