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

net: wifi: shell: only process scan events during requested scan #84546

Merged
merged 1 commit into from
Jan 29, 2025
Merged
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
54 changes: 38 additions & 16 deletions subsys/net/l2/wifi/wifi_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,24 @@ static const char server_key_test[] = {

#define WIFI_SHELL_MODULE "wifi"

#define WIFI_SHELL_MGMT_EVENTS_COMMON (NET_EVENT_WIFI_SCAN_DONE |\
#define WIFI_SHELL_MGMT_EVENTS ( \
NET_EVENT_WIFI_CONNECT_RESULT |\
NET_EVENT_WIFI_DISCONNECT_RESULT |\
NET_EVENT_WIFI_TWT |\
NET_EVENT_WIFI_RAW_SCAN_RESULT |\
NET_EVENT_WIFI_AP_ENABLE_RESULT |\
NET_EVENT_WIFI_AP_DISABLE_RESULT |\
NET_EVENT_WIFI_AP_STA_CONNECTED |\
NET_EVENT_WIFI_AP_STA_DISCONNECTED)

#ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY
#define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON)
#define WIFI_SHELL_SCAN_EVENTS ( \
NET_EVENT_WIFI_SCAN_DONE |\
NET_EVENT_WIFI_RAW_SCAN_RESULT)
#else
#define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON |\
NET_EVENT_WIFI_SCAN_RESULT)
#define WIFI_SHELL_SCAN_EVENTS ( \
NET_EVENT_WIFI_SCAN_RESULT |\
NET_EVENT_WIFI_SCAN_DONE |\
NET_EVENT_WIFI_RAW_SCAN_RESULT)
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY */

#define MAX_BANDS_STR_LEN 64
Expand All @@ -105,6 +108,7 @@ static struct {
} context;

static struct net_mgmt_event_callback wifi_shell_mgmt_cb;
static struct net_mgmt_event_callback wifi_shell_scan_cb;
static struct wifi_reg_chan_info chan_info[MAX_REG_CHAN_NUM];

static K_MUTEX_DEFINE(wifi_ap_sta_list_lock);
Expand Down Expand Up @@ -298,6 +302,8 @@ static void handle_wifi_scan_done(struct net_mgmt_event_callback *cb)
PR("Scan request done\n");
}

net_mgmt_del_event_callback(&wifi_shell_scan_cb);

context.scan_result = 0U;
}

Expand Down Expand Up @@ -517,12 +523,6 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb,
uint32_t mgmt_event, struct net_if *iface)
{
switch (mgmt_event) {
case NET_EVENT_WIFI_SCAN_RESULT:
handle_wifi_scan_result(cb);
break;
case NET_EVENT_WIFI_SCAN_DONE:
handle_wifi_scan_done(cb);
break;
case NET_EVENT_WIFI_CONNECT_RESULT:
handle_wifi_connect_result(cb);
break;
Expand All @@ -532,11 +532,6 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb,
case NET_EVENT_WIFI_TWT:
handle_wifi_twt_event(cb);
break;
#ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS
case NET_EVENT_WIFI_RAW_SCAN_RESULT:
handle_wifi_raw_scan_result(cb);
break;
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
case NET_EVENT_WIFI_AP_ENABLE_RESULT:
handle_wifi_ap_enable_result(cb);
break;
Expand All @@ -562,6 +557,26 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb,
}
}

static void wifi_mgmt_scan_event_handler(struct net_mgmt_event_callback *cb,
uint32_t mgmt_event, struct net_if *iface)
{
switch (mgmt_event) {
case NET_EVENT_WIFI_SCAN_RESULT:
handle_wifi_scan_result(cb);
break;
case NET_EVENT_WIFI_SCAN_DONE:
handle_wifi_scan_done(cb);
break;
#ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS
case NET_EVENT_WIFI_RAW_SCAN_RESULT:
handle_wifi_raw_scan_result(cb);
break;
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
default:
break;
}
}

static int __wifi_args_to_params(const struct shell *sh, size_t argc, char *argv[],
struct wifi_connect_req_params *params,
enum wifi_iface_mode iface_mode)
Expand Down Expand Up @@ -1112,6 +1127,8 @@ static int cmd_wifi_scan(const struct shell *sh, size_t argc, char *argv[])
}

if (do_scan) {
net_mgmt_add_event_callback(&wifi_shell_scan_cb);

if (net_mgmt(NET_REQUEST_WIFI_SCAN, iface, &params, sizeof(params))) {
PR_WARNING("Scan request failed\n");
return -ENOEXEC;
Expand Down Expand Up @@ -3851,6 +3868,11 @@ static int wifi_shell_init(void)

net_mgmt_add_event_callback(&wifi_shell_mgmt_cb);


net_mgmt_init_event_callback(&wifi_shell_scan_cb,
wifi_mgmt_scan_event_handler,
WIFI_SHELL_SCAN_EVENTS);

return 0;
}

Expand Down
Loading