Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wi-Fi shell improvs #1429

Merged
merged 15 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions include/zephyr/net/wifi_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ extern "C" {
#define WIFI_MGMT_SCAN_SSID_FILT_MAX 0
#endif /* CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX */

#ifdef CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL
#define WIFI_MGMT_SCAN_CHAN_MAX_MANUAL CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL
#else
#define WIFI_MGMT_SCAN_CHAN_MAX_MANUAL 1
#endif /* CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL */

#define WIFI_MGMT_BAND_STR_SIZE_MAX 8

/** Wi-Fi management commands */
Expand Down Expand Up @@ -203,6 +209,16 @@ enum net_event_wifi_cmd {
#define NET_EVENT_WIFI_DISCONNECT_COMPLETE \
(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE)

/**
* @brief Wi-Fi structure to uniquely identify a band-channel pair
*/
struct wifi_band_channel {
/** Frequency band */
uint8_t band;
/** Channel */
uint8_t channel;
};

/**
* @brief Wi-Fi scan parameters structure.
* Used to specify parameters which can control how the Wi-Fi scan
Expand All @@ -229,7 +245,7 @@ struct wifi_scan_params {
uint16_t dwell_time_passive;
/** Array of SSID strings to scan.
*/
char ssids[WIFI_MGMT_SCAN_SSID_FILT_MAX][WIFI_SSID_MAX_LEN + 1];
const char *ssids[WIFI_MGMT_SCAN_SSID_FILT_MAX];
/** Specifies the maximum number of scan results to return. These results would be the
* BSSIDS with the best RSSI values, in all the scanned channels. This should only be
* used to limit the number of returned scan results, and cannot be counted upon to limit
Expand All @@ -242,17 +258,17 @@ struct wifi_scan_params {
* band.
* E.g. to scan channel 6 and 11 on the 2.4 GHz band, channel 36 on the 5 GHz band:
* @code{.c}
* chan[WIFI_FREQ_BAND_2_4_GHZ][0] = 6;
* chan[WIFI_FREQ_BAND_2_4_GHZ][1] = 11;
* chan[WIFI_FREQ_BAND_5_GHZ][0] = 36;
* chan[0] = {WIFI_FREQ_BAND_2_4_GHZ, 6};
* chan[1] = {WIFI_FREQ_BAND_2_4_GHZ, 11};
* chan[2] = {WIFI_FREQ_BAND_5_GHZ, 36};
* @endcode
*
* This list specifies the channels to be __considered for scan__. The underlying
* Wi-Fi chip can silently omit some channels due to various reasons such as channels
* not conforming to regulatory restrictions etc. The invoker of the API should
* ensure that the channels specified follow regulatory rules.
*/
uint16_t chan[WIFI_FREQ_BAND_MAX + 1][WIFI_CHANNEL_MAX];
struct wifi_band_channel band_chan[WIFI_MGMT_SCAN_CHAN_MAX_MANUAL];
};

/** Wi-Fi scan result, each result is provided to the net_mgmt_event_callback
Expand Down
10 changes: 7 additions & 3 deletions include/zephyr/net/wifi_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ int wifi_utils_parse_scan_bands(char *scan_bands_str, uint8_t *band_map);
* as a comma separated string and convert it to an array.
*
* @param scan_ssids_str List of SSIDs expressed as a comma separated list.
* @param ssids Pointer to an array where the parsed SSIDs are to be stored.
* @param ssids Pointer to an array where the SSIDs pointers are to be stored.
* @param num_ssids Maximum number of SSIDs that can be stored.
*
* @retval 0 on success.
* @retval -errno value in case of failure.
*/
int wifi_utils_parse_scan_ssids(char *scan_ssids_str,
char ssids[][WIFI_SSID_MAX_LEN + 1]);
const char *ssids[],
uint8_t num_ssids);


/**
Expand All @@ -95,12 +97,14 @@ int wifi_utils_parse_scan_ssids(char *scan_ssids_str,
*
* @param scan_chan_str List of channels expressed in the format described above.
* @param chan Pointer to an array where the parsed channels are to be stored.
* @param max_channels Maximum number of channels to store
*
* @retval 0 on success.
* @retval -errno value in case of failure.
*/
int wifi_utils_parse_scan_chan(char *scan_chan_str,
uint16_t chan[][WIFI_CHANNEL_MAX]);
struct wifi_band_channel *chan,
uint8_t max_channels);

/**
* @}
Expand Down
74 changes: 12 additions & 62 deletions subsys/net/l2/wifi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,13 @@ config WIFI_MGMT_TWT_CHECK_IP
interface has a valid IP address might be desirable in most scenarios.

config WIFI_MGMT_FORCED_PASSIVE_SCAN
bool "Force Passive scan"
bool "Force passive Wi-Fi scanning"
help
Force passive scan (typically used to reduce power consumption),
the scan type is always sent as passive.
This doesn't guarantee that passive scan will be used, it depends
on the underlying chip implementation to support and honour scan type.

config WIFI_MGMT_SCAN_BANDS
string "Frequency bands to scan"
default ""
help
Specifies the frequency bands to scan, as follows:
2 - 2.4 GHz
5 - 5 GHz
6 - 6 GHz
"" - All bands allowed by the regulatory domain.
Multiple bands can be specified as comma separated band values.
Only regulatory domain permitted values are allowed.

config WIFI_MGMT_SCAN_DWELL_TIME_ACTIVE
int "Active scan dwell time"
default 50
range 5 1000
help
Active scan dwell time (in ms) per channel.

config WIFI_MGMT_SCAN_DWELL_TIME_PASSIVE
int "Passive scan dwell time"
default 130
range 10 1000
help
Passive scan dwell time (in ms) per channel.
Always request a passive scan, regardless of the user supplied parameters.
This is typically used when the underlying hardware is not certified for
RF transmissions. This doesn't guarantee that passive scan will be used,
it depends on the underlying chip implementation to support and honour
scan type.

config WIFI_MGMT_SCAN_SSID_FILT_MAX
int "Maximum number of SSIDs that can be specified for SSID filtering"
Expand All @@ -81,38 +56,13 @@ config WIFI_MGMT_SCAN_SSID_FILT_MAX
Maximum number of SSIDs that can be specified for SSID filtering.
This can be set based on the underlying chipsets limitations.

config WIFI_MGMT_SCAN_SSID_FILT
string "Scan for specific SSIDs"
default ""
help
String of comma separated SSID values to scan for. The number of SSID’s
that can be specified depends on WIFI_MGMT_SCAN_MAX_SSIDS.
Use "" to disable SSID filtering.

config WIFI_MGMT_SCAN_MAX_BSS_CNT
int "Maximum number of scan results to return."
default 0
range 0 65535
help
Maximum number of scan results to return. 0 represents unlimited number of BSSes.

config WIFI_MGMT_SCAN_CHAN
string "Scan on specific channels"
default ""
config WIFI_MGMT_SCAN_CHAN_MAX_MANUAL
int "Maximum number of channels that can be manually specified"
range 1 110
default 3
help
Formatted string which specifies channels to be scanned. The channel string has to be formatted
using the colon (:), comma(,), hyphen (-) and space ( ) delimiters as follows:
- A colon identifies the value preceding it as a band. A band value
(2: 2.4 GHz, 5: 5 GHz 6: 6 GHz) has to precede the channels in that band (e.g. 2: etc)
- Hyphens are used to identify channel ranges (e.g. 2-7, 32-48 etc)
- Commas are used to separate channel values within a band. Channels can be specified
as individual values (2,6,48 etc) or channel ranges using hyphens (1-14, 32-48 etc)
- Spaces are used to specify multiple band-channel sets (e.g. 2:1,2 5:36,40 etc)
- No spaces should be used anywhere else, i.e. before/after commas,
before/after hyphens.
An example channel specification specifying channels in the 2.4 GHz and 5 GHz bands is
as below:
2:1,5,7,9-11_5:36-48,100,163-167
There are approximately 100 channels allocated across the three supported bands.
The default of 3 allows the 3 most common channels (2.4GHz: 1, 6, 11) to be specified.

config WIFI_NM
bool "Wi-Fi Network manager support"
Expand Down
56 changes: 5 additions & 51 deletions subsys/net/l2/wifi/wifi_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ LOG_MODULE_REGISTER(net_wifi_mgmt, CONFIG_NET_L2_WIFI_MGMT_LOG_LEVEL);
#include <zephyr/net/net_core.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/wifi_mgmt.h>
#include <zephyr/net/wifi_utils.h>
#ifdef CONFIG_WIFI_NM
#include <zephyr/net/wifi_nm.h>
#endif /* CONFIG_WIFI_NM */
Expand Down Expand Up @@ -323,64 +322,19 @@ static int wifi_scan(uint32_t mgmt_request, struct net_if *iface,
const struct device *dev = net_if_get_device(iface);
struct wifi_scan_params *params = data;
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
bool chan_specified = false;
uint8_t i = 0;

if (wifi_mgmt_api == NULL || wifi_mgmt_api->scan == NULL) {
return -ENOTSUP;
}

if (data && (len == sizeof(*params))) {
#ifdef CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN
params->scan_type = WIFI_SCAN_TYPE_PASSIVE;
#endif /* CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN */

if (!params->bands) {
if (wifi_utils_parse_scan_bands(CONFIG_WIFI_MGMT_SCAN_BANDS,
&params->bands)) {
NET_ERR("Incorrect value(s) in CONFIG_WIFI_MGMT_SCAN_BANDS: %s",
CONFIG_WIFI_MGMT_SCAN_BANDS);
return -EINVAL;
}
}

if (!params->dwell_time_active) {
params->dwell_time_active = CONFIG_WIFI_MGMT_SCAN_DWELL_TIME_ACTIVE;
}

if (!params->dwell_time_passive) {
params->dwell_time_passive = CONFIG_WIFI_MGMT_SCAN_DWELL_TIME_PASSIVE;
}
struct wifi_scan_params default_params = {0};

if (!strlen(params->ssids[0])) {
if (wifi_utils_parse_scan_ssids(CONFIG_WIFI_MGMT_SCAN_SSID_FILT,
params->ssids)) {
NET_ERR("Incorrect value(s) in CONFIG_WIFI_MGMT_SCAN_SSID_FILT: %s",
CONFIG_WIFI_MGMT_SCAN_SSID_FILT);
return -EINVAL;
}
}

if (!params->max_bss_cnt) {
params->max_bss_cnt = CONFIG_WIFI_MGMT_SCAN_MAX_BSS_CNT;
}

for (i = 0; i <= WIFI_FREQ_BAND_MAX; i++) {
if (params->chan[i][0]) {
chan_specified = true;
break;
}
}

if ((!chan_specified) && strlen(CONFIG_WIFI_MGMT_SCAN_CHAN)) {
if (wifi_utils_parse_scan_chan(CONFIG_WIFI_MGMT_SCAN_CHAN,
params->chan)) {
NET_ERR("Incorrect value(s) in CONFIG_WIFI_MGMT_SCAN_CHAN: %s",
CONFIG_WIFI_MGMT_SCAN_CHAN);
return -EINVAL;
}
}
if (params == NULL) {
params = &default_params;
}
params->scan_type = WIFI_SCAN_TYPE_PASSIVE;
#endif /* CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN */

return wifi_mgmt_api->scan(dev, params, scan_result_cb);
}
Expand Down
Loading