Skip to content

Commit a8e4909

Browse files
rsmarplesJorge Natz
andauthored
Disconnect when same SSID selected (#1)
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>
1 parent a8dd045 commit a8e4909

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/dhcpcd-gtk/wpa.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ bool
108108
wpa_configure(DHCPCD_WPA *wpa, DHCPCD_WI_SCAN *scan)
109109
{
110110
DHCPCD_WI_SCAN s;
111+
DHCPCD_IF *i;
111112
GtkWidget *label, *psk, *vbox, *hbox;
112113
const char *var;
113114
int result;
@@ -117,6 +118,14 @@ wpa_configure(DHCPCD_WPA *wpa, DHCPCD_WI_SCAN *scan)
117118
memcpy(&s, scan, sizeof(s));
118119
s.next = NULL;
119120

121+
i = dhcpcd_wpa_if(wpa);
122+
if (i == NULL)
123+
return false;
124+
125+
/* Disconnect if same interface selected */
126+
if (dhcpcd_wi_associated(i, &s))
127+
return dhcpcd_wpa_disconnect(wpa);
128+
120129
if (!(s.flags & WSF_PSK))
121130
return wpa_conf(dhcpcd_wpa_configure(wpa, &s, NULL));
122131

src/dhcpcd-qt/dhcpcd-wi.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,23 @@ void DhcpcdWi::ping()
295295
void DhcpcdWi::connectSsid(DHCPCD_WI_SCAN *scan)
296296
{
297297
DHCPCD_WI_SCAN s;
298+
DHCPCD_IF *i;
298299
int err;
299300

300301
/* Take a copy of scan incase it's destroyed by a scan update */
301302
memcpy(&s, scan, sizeof(s));
302303
s.next = NULL;
303304

304-
if (s.flags & WSF_PSK) {
305+
i = dhcpcd_wpa_if(wpa);
306+
if (i == NULL)
307+
err = DHCPCD_WPA_ERR;
308+
else if (dhcpcd_wi_associated(i, &s)) {
309+
/* Disconnect if same interface selected */
310+
if (!dhcpcd_wpa_disconnect(wpa))
311+
err = DHCPCD_WPA_ERR_DISCONN;
312+
else
313+
err = DHCPCD_WPA_SUCCESS;
314+
} else if (s.flags & WSF_PSK) {
305315
bool ok;
306316
QString pwd;
307317

@@ -322,11 +332,14 @@ void DhcpcdWi::connectSsid(DHCPCD_WI_SCAN *scan)
322332
switch (err) {
323333
case DHCPCD_WPA_SUCCESS:
324334
return;
335+
case DHCPCD_WPA_ERR:
336+
errt = tr("Failed.");
337+
break;
325338
case DHCPCD_WPA_ERR_DISCONN:
326339
errt = tr("Failed to disconnect.");
327340
break;
328341
case DHCPCD_WPA_ERR_RECONF:
329-
errt = tr("Faile to reconfigure.");
342+
errt = tr("Failed to reconfigure.");
330343
break;
331344
case DHCPCD_WPA_ERR_SET:
332345
errt = tr("Failed to set key management.");

0 commit comments

Comments
 (0)