When connecting to a SSID, reload the configuration, save it and then
authorRoy Marples <roy@marples.name>
Mon, 1 Dec 2014 14:26:05 +0000 (14:26 +0000)
committerRoy Marples <roy@marples.name>
Mon, 1 Dec 2014 14:26:05 +0000 (14:26 +0000)
select it, so that we don't save the fact the others are disabled.
This allows us to force a connection to less preferred SSID.

src/dhcpcd-gtk/wpa.c
src/dhcpcd-qt/dhcpcd-wi.cpp
src/libdhcpcd/dhcpcd.h
src/libdhcpcd/wpa.c

index 8565fc32b17e8a02521d15e0a63ddb16c103509e..d8f633b9b9c9689cb4713ca0780c8af7bd64d219 100644 (file)
@@ -81,6 +81,9 @@ wpa_conf(DHCPCD_WPA *wpa, DHCPCD_WI_SCAN *scan, const char *psk)
        case DHCPCD_WPA_ERR_ENABLE:
                errt = _("Failed to enable the network.");
                break;
+       case DHCPCD_WPA_ERR_SELECT:
+               errt = _("Failed to select the network.");
+               break;
        case DHCPCD_WPA_ERR_ASSOC:
                errt = _("Failed to start association.");
                break;
index 3154595e74bafaed459a41c8255000cbba0e748e..4b58d4b954017b25d506775404d96edd2a119553 100644 (file)
@@ -256,6 +256,9 @@ void DhcpcdWi::connectSsid(DHCPCD_WI_SCAN *scan)
        case DHCPCD_WPA_ERR_ENABLE:
                errt = tr("Failed to enable the network.");
                break;
+       case DHCPCD_WPA_ERR_SELECT:
+               errt = tr("Failed to select the network.");
+               break;
        case DHCPCD_WPA_ERR_ASSOC:
                errt = tr("Failed to start association.");
                break;
index 335776c87bfed124e71f1856fcf83525b2a4a527..5e8207b7dc951c8225b938555a5375fbe583176b 100644 (file)
@@ -243,12 +243,14 @@ bool dhcpcd_wpa_command(DHCPCD_WPA *, const char *);
 bool dhcpcd_wpa_command_arg(DHCPCD_WPA *, const char *, const char *);
 
 bool dhcpcd_wpa_scan(DHCPCD_WPA *);
+bool dhcpcd_wpa_reconfigure(DHCPCD_WPA *);
 bool dhcpcd_wpa_reassociate(DHCPCD_WPA *);
 bool dhcpcd_wpa_disconnect(DHCPCD_WPA *);
 bool dhcpcd_wpa_config_write(DHCPCD_WPA *);
 int dhcpcd_wpa_network_find_new(DHCPCD_WPA *, const char *);
 bool dhcpcd_wpa_network_disable(DHCPCD_WPA *, int);
 bool dhcpcd_wpa_network_enable(DHCPCD_WPA *, int);
+bool dhcpcd_wpa_network_select(DHCPCD_WPA *, int);
 bool dhcpcd_wpa_network_remove(DHCPCD_WPA *, int);
 char * dhcpcd_wpa_network_get(DHCPCD_WPA *, int, const char *);
 bool dhcpcd_wpa_network_set(DHCPCD_WPA *, int, const char *, const char *);
@@ -259,7 +261,8 @@ bool dhcpcd_wpa_network_set(DHCPCD_WPA *, int, const char *, const char *);
 #define DHCPCD_WPA_ERR_SET_PSK -3
 #define DHCPCD_WPA_ERR_ENABLE  -4
 #define DHCPCD_WPA_ERR_WRITE   -5
-#define DHCPCD_WPA_ERR_ASSOC   -6
+#define DHCPCD_WPA_ERR_SELECT  -6
+#define DHCPCD_WPA_ERR_ASSOC   -7
 int dhcpcd_wpa_configure_psk(DHCPCD_WPA *w, DHCPCD_WI_SCAN *s, const char *p);
 
 char ** dhcpcd_config_blocks(DHCPCD_CONNECTION *, const char *);
index 4cd917d1e7fac283c6f5e3d26250ddb9666e271b..2146d4593a23362e5c3c105f177e01acef92162f 100644 (file)
@@ -576,6 +576,13 @@ dhcpcd_wi_scans(DHCPCD_IF *i)
 }
 
 bool
+dhcpcd_wpa_reconfigure(DHCPCD_WPA *wpa)
+{
+
+       return dhcpcd_wpa_command(wpa, "RECONFIGURE");
+}
+
+bool
 dhcpcd_wpa_reassociate(DHCPCD_WPA *wpa)
 {
 
@@ -623,6 +630,13 @@ dhcpcd_wpa_network_enable(DHCPCD_WPA *wpa, int id)
 }
 
 bool
+dhcpcd_wpa_network_select(DHCPCD_WPA *wpa, int id)
+{
+
+       return dhcpcd_wpa_network(wpa, "SELECT_NETWORK", id);
+}
+
+bool
 dhcpcd_wpa_network_remove(DHCPCD_WPA *wpa, int id)
 {
 
@@ -1013,7 +1027,7 @@ int
 dhcpcd_wpa_configure_psk(DHCPCD_WPA *wpa, DHCPCD_WI_SCAN *s, const char *psk)
 {
        const char *mgmt, *var;
-       int id;
+       int id, retval;
        char *npsk;
        size_t psk_len;
        bool r;
@@ -1021,6 +1035,11 @@ dhcpcd_wpa_configure_psk(DHCPCD_WPA *wpa, DHCPCD_WI_SCAN *s, const char *psk)
        assert(wpa);
        assert(s);
 
+       /* reload the configuration so that when we don't save
+        * the disabled networks to the config file. */
+       if (!dhcpcd_wpa_reconfigure(wpa))
+               return DHCPCD_WPA_ERR;
+
        id = dhcpcd_wpa_network_find_new(wpa, s->ssid);
        if (id == -1)
                return DHCPCD_WPA_ERR;
@@ -1063,9 +1082,15 @@ dhcpcd_wpa_configure_psk(DHCPCD_WPA *wpa, DHCPCD_WI_SCAN *s, const char *psk)
 
        if (!dhcpcd_wpa_network_enable(wpa, id))
                return DHCPCD_WPA_ERR_ENABLE;
+       if (dhcpcd_wpa_config_write(wpa))
+               retval = DHCPCD_WPA_SUCCESS;
+       else
+               retval = DHCPCD_WPA_ERR_WRITE;
+       /* Selecting a network disbales the others.
+        * This should not be saved. */
+       if (!dhcpcd_wpa_network_select(wpa, id))
+               return DHCPCD_WPA_ERR_SELECT;
        if (!dhcpcd_wpa_reassociate(wpa))
                return DHCPCD_WPA_ERR_ASSOC;
-       if (!dhcpcd_wpa_config_write(wpa))
-               return DHCPCD_WPA_ERR_WRITE;
-       return DHCPCD_WPA_SUCCESS;
+       return retval;
 }