drivers: wifi: esp_at: changes to scanning
If CONFIG_WIFI_ESP_AT_SCAN_MAC_ADDRESS: mac addr included in scanning results. if CONFIG_WIFI_ESP_AT_SCAN_PASSIVE: passive scanning is used instead of default active scanning. If CONFIG_WIFI_ESP_AT_SCAN_RESULT_RSSI_ORDERED: scanning response ordered by RSSI. Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
This commit is contained in:
parent
e913fda436
commit
f2859f9501
3 changed files with 64 additions and 4 deletions
|
@ -16,6 +16,21 @@ menuconfig WIFI_ESP_AT
|
|||
|
||||
if WIFI_ESP_AT
|
||||
|
||||
config WIFI_ESP_AT_SCAN_PASSIVE
|
||||
bool "Passive scan"
|
||||
help
|
||||
Use passive scanning.
|
||||
|
||||
config WIFI_ESP_AT_SCAN_MAC_ADDRESS
|
||||
bool "MAC address in scan response"
|
||||
help
|
||||
Get mac address in scan response.
|
||||
|
||||
config WIFI_ESP_AT_SCAN_RESULT_RSSI_ORDERED
|
||||
bool "Scan result ordering based on RSSI"
|
||||
help
|
||||
Order based on RSSI.
|
||||
|
||||
config WIFI_ESP_AT_RX_STACK_SIZE
|
||||
int "Stack size for the Espressif esp wifi driver RX thread"
|
||||
default 1024
|
||||
|
|
|
@ -253,6 +253,7 @@ MODEM_CMD_DEFINE(on_cmd_cipstamac)
|
|||
}
|
||||
|
||||
/* +CWLAP:(sec,ssid,rssi,channel) */
|
||||
/* with: CONFIG_WIFI_ESP_AT_SCAN_MAC_ADDRESS: +CWLAP:<ecn>,<ssid>,<rssi>,<mac>,<ch>*/
|
||||
MODEM_CMD_DEFINE(on_cmd_cwlap)
|
||||
{
|
||||
struct esp_data *dev = CONTAINER_OF(data, struct esp_data,
|
||||
|
@ -276,7 +277,18 @@ MODEM_CMD_DEFINE(on_cmd_cwlap)
|
|||
memcpy(res.ssid, argv[1], i);
|
||||
res.ssid_length = i;
|
||||
res.rssi = strtol(argv[2], NULL, 10);
|
||||
res.channel = strtol(argv[3], NULL, 10);
|
||||
|
||||
if (IS_ENABLED(CONFIG_WIFI_ESP_AT_SCAN_MAC_ADDRESS)) {
|
||||
argv[3] = str_unquote(argv[3]);
|
||||
res.mac_length = WIFI_MAC_ADDR_LEN;
|
||||
if (net_bytes_from_str(res.mac, sizeof(res.mac), argv[3]) < 0) {
|
||||
LOG_ERR("Invalid MAC address");
|
||||
res.mac_length = 0;
|
||||
}
|
||||
res.channel = (argc > 4) ? strtol(argv[4], NULL, 10) : -1;
|
||||
} else {
|
||||
res.channel = strtol(argv[3], NULL, 10);
|
||||
}
|
||||
|
||||
if (dev->scan_cb) {
|
||||
dev->scan_cb(dev->net_iface, 0, &res);
|
||||
|
@ -717,7 +729,11 @@ static void esp_mgmt_scan_work(struct k_work *work)
|
|||
struct esp_data *dev;
|
||||
int ret;
|
||||
static const struct modem_cmd cmds[] = {
|
||||
#if defined(CONFIG_WIFI_ESP_AT_SCAN_MAC_ADDRESS)
|
||||
MODEM_CMD("+CWLAP:", on_cmd_cwlap, 5U, ","),
|
||||
#else
|
||||
MODEM_CMD("+CWLAP:", on_cmd_cwlap, 4U, ","),
|
||||
#endif
|
||||
};
|
||||
|
||||
dev = CONTAINER_OF(work, struct esp_data, scan_work);
|
||||
|
@ -726,9 +742,13 @@ static void esp_mgmt_scan_work(struct k_work *work)
|
|||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
ret = esp_cmd_send(dev, cmds, ARRAY_SIZE(cmds), "AT+CWLAP",
|
||||
ret = esp_cmd_send(dev,
|
||||
cmds, ARRAY_SIZE(cmds),
|
||||
ESP_CMD_CWLAP,
|
||||
ESP_SCAN_TIMEOUT);
|
||||
esp_mode_flags_clear(dev, EDF_STA_LOCK);
|
||||
LOG_DBG("ESP Wi-Fi scan: cmd = %s", ESP_CMD_CWLAP);
|
||||
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Failed to scan: ret %d", ret);
|
||||
}
|
||||
|
@ -926,8 +946,11 @@ static void esp_init_work(struct k_work *work)
|
|||
#endif
|
||||
/* enable multiple socket support */
|
||||
SETUP_CMD_NOHANDLE("AT+CIPMUX=1"),
|
||||
/* only need ecn,ssid,rssi,channel */
|
||||
SETUP_CMD_NOHANDLE("AT+CWLAPOPT=0,23"),
|
||||
|
||||
SETUP_CMD_NOHANDLE(
|
||||
ESP_CMD_CWLAPOPT(ESP_CMD_CWLAPOPT_ORDERED, ESP_CMD_CWLAPOPT_MASK)),
|
||||
SETUP_CMD_NOHANDLE(ESP_CMD_CWLAP),
|
||||
|
||||
#if defined(CONFIG_WIFI_ESP_AT_VERSION_2_0)
|
||||
SETUP_CMD_NOHANDLE(ESP_CMD_CWMODE(STA)),
|
||||
SETUP_CMD_NOHANDLE("AT+CWAUTOCONN=0"),
|
||||
|
|
|
@ -131,6 +131,28 @@ extern "C" {
|
|||
#define ESP_CMD_SET_IP(ip, gateway, mask) "AT+"_CIPSTA"=\"" \
|
||||
ip "\",\"" gateway "\",\"" mask "\""
|
||||
|
||||
#if defined(CONFIG_WIFI_ESP_AT_SCAN_PASSIVE)
|
||||
#define ESP_CMD_CWLAP "AT+CWLAP=,,,1,,"
|
||||
#else
|
||||
#define ESP_CMD_CWLAP "AT+CWLAP"
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_WIFI_ESP_AT_SCAN_RESULT_RSSI_ORDERED)
|
||||
#define ESP_CMD_CWLAPOPT_ORDERED "1"
|
||||
#else
|
||||
#define ESP_CMD_CWLAPOPT_ORDERED "0"
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_WIFI_ESP_AT_SCAN_MAC_ADDRESS)
|
||||
/* We need ecn,ssid,rssi,mac,channel */
|
||||
#define ESP_CMD_CWLAPOPT_MASK "31"
|
||||
#else
|
||||
/* no mac: only need ecn,ssid,rssi,channel */
|
||||
#define ESP_CMD_CWLAPOPT_MASK "23"
|
||||
#endif
|
||||
|
||||
#define ESP_CMD_CWLAPOPT(sort, mask) "AT+CWLAPOPT=" sort "," mask
|
||||
|
||||
extern struct esp_data esp_driver_data;
|
||||
|
||||
enum esp_socket_flags {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue