Disconnect when same SSID selected (#1) master
authorRoy Marples <roy@marples.name>
Thu, 18 Mar 2021 15:30:13 +0000 (15:30 +0000)
committerGitHub <noreply@github.com>
Thu, 18 Mar 2021 15:30:13 +0000 (15:30 +0000)
Modify gui functions so that when the entry of the currently
associated SSID is selected, the interface is disconnected.

Co-authored-by: Jorge Natz <jorgenatzdev@gmail.com>
src/dhcpcd-gtk/wpa.c
src/dhcpcd-qt/dhcpcd-wi.cpp

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));
 
index 617e5f6d4dfea09b15af126fe04c7496a043cb1f..4e4d86a8a5fbeaa2a11a77f28d95a4cd0376c802 100644 (file)
@@ -295,13 +295,23 @@ void DhcpcdWi::ping()
 void DhcpcdWi::connectSsid(DHCPCD_WI_SCAN *scan)
 {
        DHCPCD_WI_SCAN s;
+       DHCPCD_IF *i;
        int err;
 
        /* Take a copy of scan incase it's destroyed by a scan update */
        memcpy(&s, scan, sizeof(s));
        s.next = NULL;
 
-       if (s.flags & WSF_PSK) {
+       i = dhcpcd_wpa_if(wpa);
+       if (i == NULL)
+               err = DHCPCD_WPA_ERR;
+       else if (dhcpcd_wi_associated(i, &s)) {
+               /* Disconnect if same interface selected */
+               if (!dhcpcd_wpa_disconnect(wpa))
+                       err = DHCPCD_WPA_ERR_DISCONN;
+               else
+                       err = DHCPCD_WPA_SUCCESS;
+       } else if (s.flags & WSF_PSK) {
                bool ok;
                QString pwd;
 
@@ -322,11 +332,14 @@ void DhcpcdWi::connectSsid(DHCPCD_WI_SCAN *scan)
        switch (err) {
        case DHCPCD_WPA_SUCCESS:
                return;
+       case DHCPCD_WPA_ERR:
+               errt = tr("Failed.");
+               break;
        case DHCPCD_WPA_ERR_DISCONN:
                errt = tr("Failed to disconnect.");
                break;
        case DHCPCD_WPA_ERR_RECONF:
-               errt = tr("Faile to reconfigure.");
+               errt = tr("Failed to reconfigure.");
                break;
        case DHCPCD_WPA_ERR_SET:
                errt = tr("Failed to set key management.");