[PATCH] Skip PSK re-calculation when psk/ssid is not modified

Masashi Honma masashi.honma
Mon Oct 28 00:18:31 PDT 2013


Signed-hostap: Masashi Honma <masashi.honma at gmail.com>

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index d0c0a01..153611a 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -2332,9 +2332,11 @@ static int wpa_supplicant_ctrl_iface_remove_network(
 static int wpa_supplicant_ctrl_iface_set_network(
     struct wpa_supplicant *wpa_s, char *cmd)
 {
-    int id;
+    int id, update_psk = 0;
     struct wpa_ssid *ssid;
     char *name, *value;
+    u8 *old_ssid = NULL;
+    size_t old_ssid_len = 0;

     /* cmd: "<network id> <variable name> <value>" */
     name = os_strchr(cmd, ' ');
@@ -2360,12 +2362,44 @@ static int wpa_supplicant_ctrl_iface_set_network(
         return -1;
     }

+    if (os_strcmp(name, "psk") == 0 && value[0] == '"' && ssid->ssid_len) {
+        if (ssid->passphrase) {
+            if (os_strlen(ssid->passphrase) !=
+                os_strlen(value) - 2 ||
+                os_memcmp(ssid->passphrase, &value[1],
+                os_strlen(ssid->passphrase)) != 0)
+                update_psk = 1;
+        } else {
+            update_psk = 1;
+        }
+    }
+
+    if (os_strcmp(name, "ssid") == 0 && ssid->passphrase) {
+        if (ssid->ssid_len) {
+            old_ssid = os_malloc(ssid->ssid_len);
+            if (old_ssid == NULL)
+                return -1;
+            os_memcpy(old_ssid, ssid->ssid, ssid->ssid_len);
+            old_ssid_len = ssid->ssid_len;
+        } else {
+            update_psk = 1;
+        }
+    }
+
     if (wpa_config_set(ssid, name, value, 0) < 0) {
         wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
                "variable '%s'", name);
+        os_free(old_ssid);
         return -1;
     }

+    if (old_ssid) {
+        if (old_ssid_len != ssid->ssid_len ||
+            os_memcmp(old_ssid, ssid->ssid, ssid->ssid_len) != 0)
+            update_psk = 1;
+        os_free(old_ssid);
+    }
+
     if (os_strcmp(name, "bssid") != 0 &&
         os_strcmp(name, "priority") != 0)
         wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
@@ -2378,9 +2412,7 @@ static int wpa_supplicant_ctrl_iface_set_network(
         eapol_sm_invalidate_cached_session(wpa_s->eapol);
     }

-    if ((os_strcmp(name, "psk") == 0 &&
-         value[0] == '"' && ssid->ssid_len) ||
-        (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
+    if (update_psk)
         wpa_config_update_psk(ssid);
     else if (os_strcmp(name, "priority") == 0)
         wpa_config_update_prio_list(wpa_s->conf);


Regards,
Masashi Honma.



More information about the Hostap mailing list