From f03580e319f6398fc474a7d45db8c7deb1765845 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 21 Feb 2021 17:22:37 +0200 Subject: [PATCH] Restore permanent MAC address on the FLUSH command Clear previously used random MAC address on the FLUSH command if mac_addr setting has been disabled. Signed-off-by: Jouni Malinen --- wpa_supplicant/ctrl_iface.c | 2 ++ wpa_supplicant/wpa_supplicant.c | 30 +++++++++++++++++++----------- wpa_supplicant/wpa_supplicant_i.h | 1 + 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 2dce086f1..0d4c2bc8f 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -8572,6 +8572,8 @@ static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s) wpas_pasn_auth_stop(wpa_s); #endif /* CONFIG_PASN */ + if (wpa_s->mac_addr_changed && wpa_s->conf->mac_addr == 0) + wpas_restore_permanent_mac_addr(wpa_s); } diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index 8384cce75..e1497e1f5 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -2145,6 +2145,24 @@ static void wpa_s_clear_sae_rejected(struct wpa_supplicant *wpa_s) } +int wpas_restore_permanent_mac_addr(struct wpa_supplicant *wpa_s) +{ + if (wpa_drv_set_mac_addr(wpa_s, NULL) < 0) { + wpa_msg(wpa_s, MSG_INFO, + "Could not restore permanent MAC address"); + return -1; + } + wpa_s->mac_addr_changed = 0; + if (wpa_supplicant_update_mac_addr(wpa_s) < 0) { + wpa_msg(wpa_s, MSG_INFO, + "Could not update MAC address information"); + return -1; + } + wpa_msg(wpa_s, MSG_DEBUG, "Using permanent MAC address"); + return 0; +} + + static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit); /** @@ -2205,18 +2223,8 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s, return; wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); } else if (rand_style == 0 && wpa_s->mac_addr_changed) { - if (wpa_drv_set_mac_addr(wpa_s, NULL) < 0) { - wpa_msg(wpa_s, MSG_INFO, - "Could not restore permanent MAC address"); + if (wpas_restore_permanent_mac_addr(wpa_s) < 0) return; - } - wpa_s->mac_addr_changed = 0; - if (wpa_supplicant_update_mac_addr(wpa_s) < 0) { - wpa_msg(wpa_s, MSG_INFO, - "Could not update MAC address information"); - return; - } - wpa_msg(wpa_s, MSG_DEBUG, "Using permanent MAC address"); } wpa_s->last_ssid = ssid; diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index f192bf8a2..7d14b627d 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -1425,6 +1425,7 @@ int wpa_supplicant_update_bridge_ifname(struct wpa_supplicant *wpa_s, int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, struct wpa_ssid *ssid, u8 *wpa_ie, size_t *wpa_ie_len); +int wpas_restore_permanent_mac_addr(struct wpa_supplicant *wpa_s); void wpa_supplicant_associate(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, struct wpa_ssid *ssid);