Disconnect when same SSID selected (#1)
[dhcpcd-ui] / src / dhcpcd-gtk / wpa.c
index 929bb7db09735bd370e0db712582496c3d667595..371323ea93d6c8c037c8e443c870783c65f82884 100644 (file)
@@ -108,6 +108,7 @@ bool
 wpa_configure(DHCPCD_WPA *wpa, DHCPCD_WI_SCAN *scan)
 {
        DHCPCD_WI_SCAN s;
+       DHCPCD_IF *i;
        GtkWidget *label, *psk, *vbox, *hbox;
        const char *var;
        int result;
@@ -117,6 +118,14 @@ wpa_configure(DHCPCD_WPA *wpa, DHCPCD_WI_SCAN *scan)
        memcpy(&s, scan, sizeof(s));
        s.next = NULL;
 
+       i = dhcpcd_wpa_if(wpa);
+       if (i == NULL)
+               return false;
+
+       /* Disconnect if same interface selected */
+       if (dhcpcd_wi_associated(i, &s))
+               return dhcpcd_wpa_disconnect(wpa);
+
        if (!(s.flags & WSF_PSK))
                return wpa_conf(dhcpcd_wpa_configure(wpa, &s, NULL));