From 262bc09f1e82fd173ccda07db4e7e67c0d9a86ce Mon Sep 17 00:00:00 2001 From: lyon Date: Wed, 25 Jan 2023 00:25:18 +0800 Subject: [PATCH] test wifi sacn on linux --- examples/network/network_scan.py | 6 ++++++ package/PikaStdDevice/pika_hal.c | 21 ++++++++++++------- package/PikaStdDevice/pika_hal_table_rule.h | 4 +++- package/network/_network.pyi | 2 ++ package/network/_network_WLAN.c | 8 +++++++ port/linux/package/pikascript/_network.pyi | 2 ++ .../pikascript-lib/PikaStdDevice/pika_hal.c | 21 ++++++++++++------- .../PikaStdDevice/pika_hal_table_rule.h | 4 +++- .../pikascript-lib/network/_network_WLAN.c | 8 +++++++ test/python/network/network_scan.py | 6 ++++++ 10 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 examples/network/network_scan.py create mode 100644 test/python/network/network_scan.py diff --git a/examples/network/network_scan.py b/examples/network/network_scan.py new file mode 100644 index 000000000..d85746b5a --- /dev/null +++ b/examples/network/network_scan.py @@ -0,0 +1,6 @@ +import network + +wlan = network.WLAN(network.STA_IF) +wlan.active(True) +wlan.scan() +wlan.close() diff --git a/package/PikaStdDevice/pika_hal.c b/package/PikaStdDevice/pika_hal.c index 993981993..bddaef43d 100644 --- a/package/PikaStdDevice/pika_hal.c +++ b/package/PikaStdDevice/pika_hal.c @@ -118,10 +118,7 @@ static const int _pika_hal_cmd_arg_cnt[] = { (sizeof _pika_hal_cmd_arg_cnt / sizeof _pika_hal_cmd_arg_cnt[0]) static int _pika_hal_get_arg_cnt(PIKA_HAL_IOCTL_CMD cmd) { - if (cmd >= _PIKA_HAL_CMD_ARG_CNT_MAX) { - return -1; - } - return _pika_hal_cmd_arg_cnt[cmd]; + return _pika_hal_cmd_arg_cnt[PIKA_HAL_IOCTL_CONFIG]; } int _pika_hal_ioctl_merge_config(pika_dev* dev, void* config_in) { @@ -144,18 +141,26 @@ int pika_hal_ioctl(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, ...) { if (impl->ioctl == NULL) { return -1; } - void* config_in = NULL; + void* arg_in = NULL; if (cmd != 0) { va_list args; va_start(args, cmd); - config_in = va_arg(args, void*); - ret = _pika_hal_ioctl_merge_config(dev, config_in); + arg_in = va_arg(args, void*); + if (cmd_origin == PIKA_HAL_IOCTL_CONFIG) { + ret = _pika_hal_ioctl_merge_config(dev, arg_in); + } else { + ret = 0; + } va_end(args); if (0 != ret) { return ret; } } - ret = impl->ioctl(dev, cmd_origin, dev->ioctl_config); + if (cmd_origin == PIKA_HAL_IOCTL_CONFIG) { + ret = impl->ioctl(dev, cmd_origin, dev->ioctl_config); + } else { + ret = impl->ioctl(dev, cmd_origin, arg_in); + } if (ret == 0) { if (cmd_origin == PIKA_HAL_IOCTL_ENABLE) { dev->is_enabled = 1; diff --git a/package/PikaStdDevice/pika_hal_table_rule.h b/package/PikaStdDevice/pika_hal_table_rule.h index 4df9d6b9e..70a7cef51 100644 --- a/package/PikaStdDevice/pika_hal_table_rule.h +++ b/package/PikaStdDevice/pika_hal_table_rule.h @@ -86,7 +86,9 @@ int pika_hal_platform_##dev_name##_ioctl_enable(pika_dev* dev); \ int pika_hal_platform_##dev_name##_ioctl_disable(pika_dev* dev); \ int pika_hal_platform_##dev_name##_ioctl_config( \ - pika_dev* dev, pika_hal_##dev_name##_config* cfg); + pika_dev* dev, pika_hal_##dev_name##_config* cfg); \ + int pika_hal_platform_##dev_name##_ioctl_others( \ + pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, void* arg); #endif #if defined(PIKA_HAL_TABLE_DEV_CONFIG_SIZE) diff --git a/package/network/_network.pyi b/package/network/_network.pyi index 9ffbe9ca0..c3ca7b92d 100644 --- a/package/network/_network.pyi +++ b/package/network/_network.pyi @@ -37,5 +37,7 @@ class WLAN: def scan(self) -> list: ... + def close(self): ... + def __init__(): ... diff --git a/package/network/_network_WLAN.c b/package/network/_network_WLAN.c index 4e4725df5..ad740498d 100644 --- a/package/network/_network_WLAN.c +++ b/package/network/_network_WLAN.c @@ -209,3 +209,11 @@ PikaObj* _network_WLAN_scan(PikaObj* self) { pika_platform_free(result); return scan_list; } + +void _network_WLAN_close(PikaObj* self) { + pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi"); + if (hal_wifi == NULL) { + return; + } + pika_hal_close(hal_wifi); +} diff --git a/port/linux/package/pikascript/_network.pyi b/port/linux/package/pikascript/_network.pyi index 9ffbe9ca0..c3ca7b92d 100644 --- a/port/linux/package/pikascript/_network.pyi +++ b/port/linux/package/pikascript/_network.pyi @@ -37,5 +37,7 @@ class WLAN: def scan(self) -> list: ... + def close(self): ... + def __init__(): ... diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.c b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.c index 993981993..bddaef43d 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.c +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal.c @@ -118,10 +118,7 @@ static const int _pika_hal_cmd_arg_cnt[] = { (sizeof _pika_hal_cmd_arg_cnt / sizeof _pika_hal_cmd_arg_cnt[0]) static int _pika_hal_get_arg_cnt(PIKA_HAL_IOCTL_CMD cmd) { - if (cmd >= _PIKA_HAL_CMD_ARG_CNT_MAX) { - return -1; - } - return _pika_hal_cmd_arg_cnt[cmd]; + return _pika_hal_cmd_arg_cnt[PIKA_HAL_IOCTL_CONFIG]; } int _pika_hal_ioctl_merge_config(pika_dev* dev, void* config_in) { @@ -144,18 +141,26 @@ int pika_hal_ioctl(pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, ...) { if (impl->ioctl == NULL) { return -1; } - void* config_in = NULL; + void* arg_in = NULL; if (cmd != 0) { va_list args; va_start(args, cmd); - config_in = va_arg(args, void*); - ret = _pika_hal_ioctl_merge_config(dev, config_in); + arg_in = va_arg(args, void*); + if (cmd_origin == PIKA_HAL_IOCTL_CONFIG) { + ret = _pika_hal_ioctl_merge_config(dev, arg_in); + } else { + ret = 0; + } va_end(args); if (0 != ret) { return ret; } } - ret = impl->ioctl(dev, cmd_origin, dev->ioctl_config); + if (cmd_origin == PIKA_HAL_IOCTL_CONFIG) { + ret = impl->ioctl(dev, cmd_origin, dev->ioctl_config); + } else { + ret = impl->ioctl(dev, cmd_origin, arg_in); + } if (ret == 0) { if (cmd_origin == PIKA_HAL_IOCTL_ENABLE) { dev->is_enabled = 1; diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal_table_rule.h b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal_table_rule.h index 4df9d6b9e..70a7cef51 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal_table_rule.h +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/pika_hal_table_rule.h @@ -86,7 +86,9 @@ int pika_hal_platform_##dev_name##_ioctl_enable(pika_dev* dev); \ int pika_hal_platform_##dev_name##_ioctl_disable(pika_dev* dev); \ int pika_hal_platform_##dev_name##_ioctl_config( \ - pika_dev* dev, pika_hal_##dev_name##_config* cfg); + pika_dev* dev, pika_hal_##dev_name##_config* cfg); \ + int pika_hal_platform_##dev_name##_ioctl_others( \ + pika_dev* dev, PIKA_HAL_IOCTL_CMD cmd, void* arg); #endif #if defined(PIKA_HAL_TABLE_DEV_CONFIG_SIZE) diff --git a/port/linux/package/pikascript/pikascript-lib/network/_network_WLAN.c b/port/linux/package/pikascript/pikascript-lib/network/_network_WLAN.c index 4e4725df5..ad740498d 100644 --- a/port/linux/package/pikascript/pikascript-lib/network/_network_WLAN.c +++ b/port/linux/package/pikascript/pikascript-lib/network/_network_WLAN.c @@ -209,3 +209,11 @@ PikaObj* _network_WLAN_scan(PikaObj* self) { pika_platform_free(result); return scan_list; } + +void _network_WLAN_close(PikaObj* self) { + pika_dev* hal_wifi = obj_getPtr(self, "hal_wifi"); + if (hal_wifi == NULL) { + return; + } + pika_hal_close(hal_wifi); +} diff --git a/test/python/network/network_scan.py b/test/python/network/network_scan.py new file mode 100644 index 000000000..d85746b5a --- /dev/null +++ b/test/python/network/network_scan.py @@ -0,0 +1,6 @@ +import network + +wlan = network.WLAN(network.STA_IF) +wlan.active(True) +wlan.scan() +wlan.close()