From: Ilan Peer Date: Thu, 23 Oct 2025 10:45:31 +0000 (+0300) Subject: USD: Improve concurrency with other interfaces X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc917a8c081387c80ea994bb19e60d8449218357;p=thirdparty%2Fhostap.git USD: Improve concurrency with other interfaces Notify USD logic about interface state changes so it could configure the USD (and NAN DE) operation to take into consideration the concurrency with other interfaces sharing the same radio. In particular: - Consider P2P state to allow P2P2 handshakes to complete during USD channel dwells. - When a peer is locally authorized for connection, consider this as an indication that USD dwell time should be longer to allow the complete pairing, etc. Signed-off-by: Ilan Peer --- diff --git a/wpa_supplicant/nan_usd.c b/wpa_supplicant/nan_usd.c index 30e901207..ed7929206 100644 --- a/wpa_supplicant/nan_usd.c +++ b/wpa_supplicant/nan_usd.c @@ -663,3 +663,52 @@ int * wpas_nan_usd_all_freqs(struct wpa_supplicant *wpa_s) return freqs; } + + +void wpas_nan_usd_state_change_notif(struct wpa_supplicant *wpa_s) +{ + struct wpa_supplicant *ifs; + unsigned int n_active = 0; + struct nan_de_cfg cfg; + + if (!wpa_s->radio) + return; + + os_memset(&cfg, 0, sizeof(cfg)); + + dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, + radio_list) { + if (ifs->wpa_state >= WPA_AUTHENTICATING) + n_active++; + } + + wpa_printf(MSG_DEBUG, + "NAN: state change notif: n_active=%u, p2p_in_progress=%u", + n_active, wpas_p2p_in_progress(wpa_s)); + + if (n_active) { + cfg.n_max = 3; + + if (!wpas_p2p_in_progress(wpa_s)) { + /* Limit the USD operation on channel to 100 - 300 TUs + * to allow more time for other interfaces. + */ + cfg.n_min = 1; + } else { + /* Limit the USD operation on channel to 200 - 300 TUs + * to allow P2P operation to complete. + */ + cfg.n_min = 2; + } + + /* Each 500 ms suspend USD operation for 300 ms */ + cfg.cycle = 500; + cfg.suspend = 300; + } + + dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, + radio_list) { + if (ifs->nan_de) + nan_de_config(ifs->nan_de, &cfg); + } +} diff --git a/wpa_supplicant/nan_usd.h b/wpa_supplicant/nan_usd.h index dd7040964..394a09c46 100644 --- a/wpa_supplicant/nan_usd.h +++ b/wpa_supplicant/nan_usd.h @@ -49,5 +49,6 @@ void wpas_nan_usd_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s, unsigned int freq); void wpas_nan_usd_tx_wait_expire(struct wpa_supplicant *wpa_s); int * wpas_nan_usd_all_freqs(struct wpa_supplicant *wpa_s); +void wpas_nan_usd_state_change_notif(struct wpa_supplicant *wpa_s); #endif /* NAN_USD_H */ diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 05dd8bfa3..875a1676e 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -40,6 +40,7 @@ #include "wps_supplicant.h" #include "p2p_supplicant.h" #include "wifi_display.h" +#include "nan_usd.h" /* @@ -2899,6 +2900,12 @@ static void wpas_set_go_security_config(void *ctx, struct wpa_supplicant *tmp, *ifs = NULL; struct hostapd_data *hapd; + wpa_printf(MSG_DEBUG, "P2P: GO security config callback"); + +#ifdef CONFIG_NAN_USD + wpas_nan_usd_state_change_notif(wpa_s); +#endif /* CONFIG_NAN_USD */ + if (!params->p2p2) return; @@ -2954,6 +2961,10 @@ static void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res) } #endif /* CONFIG_PASN */ +#ifdef CONFIG_NAN_USD + wpas_nan_usd_state_change_notif(wpa_s); +#endif /* CONFIG_NAN_USD */ + if (res->status) { wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_FAILURE "status=%d", @@ -6168,15 +6179,24 @@ static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, unsigned int pref_freq, u16 bootstrap, const char *password) { + int ret; + if (persistent_group && wpa_s->conf->persistent_reconnect) persistent_group = 2; - return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method, - go_intent, own_interface_addr, force_freq, - persistent_group, ssid ? ssid->ssid : NULL, - ssid ? ssid->ssid_len : 0, pref_freq, - wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : - 0, bootstrap, password); + ret = p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method, + go_intent, own_interface_addr, force_freq, + persistent_group, ssid ? ssid->ssid : NULL, + ssid ? ssid->ssid_len : 0, pref_freq, + wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : + 0, bootstrap, password); + if (!ret) { + wpa_printf(MSG_DEBUG, "P2P: Peer authorized"); +#ifdef CONFIG_NAN_USD + wpas_nan_usd_state_change_notif(wpa_s); +#endif /* CONFIG_NAN_USD */ + } + return ret; } diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index aa620ef4e..500ee97a4 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -1323,6 +1323,10 @@ void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, if (update_fils_connect_params) wpas_update_fils_connect_params(wpa_s); #endif /* CONFIG_FILS && IEEE8021X_EAPOL */ + +#ifdef CONFIG_NAN_USD + wpas_nan_usd_state_change_notif(wpa_s); +#endif /* CONFIG_NAN_USD */ }