not needd for dhcpcd-online.
dhcpcd_version(con));
refresh = true;
} else
- refresh = false;
+ refresh = g_strcmp0(last, "opened") ? false : true;
update_online(con, refresh);
}
con = (DHCPCD_CONNECTION *)data;
fd = dhcpcd_open(con);
if (fd == -1) {
- if (errno != last_error)
+ if (errno != last_error) {
g_critical("dhcpcd_open: %s", strerror(errno));
- last_error = errno;
+ last_error = errno;
+ }
return TRUE;
}
return TRUE;
}
+ /* Start listening to WPA events */
+ dhcpcd_wpa_start(con);
+
return FALSE;
}
} else {
bool refresh;
- if ((lastStatus == NULL || strcmp(lastStatus, "down") == 0)) {
+ if (lastStatus == NULL || strcmp(lastStatus, "down") == 0) {
qDebug("Connected to dhcpcd-%s", dhcpcd_version(con));
refresh = true;
} else
- refresh = false;
+ refresh = strcmp(lastStatus, "opened") ? false : true;
+ printf ("refresh %d\n", refresh);
updateOnline(refresh);
+ printf ("updated\n");
}
free(lastStatus);
return;
}
+ /* Start listening to WPA events */
+ dhcpcd_wpa_start(con);
+
if (retryOpenTimer) {
delete retryOpenTimer;
retryOpenTimer = NULL;
const char *status;
assert(con);
- if (con->command_fd == -1 || con->listen_fd == -1)
+ if (con->command_fd == -1)
return "down";
+ if (con->listen_fd == -1)
+ return "opened";
+
+ if (con->interfaces == NULL)
+ return "initialised";
+
status = "disconnected";
for (i = con->interfaces; i; i = i->next) {
if (i->up) {
DHCPCD_IF *i;
assert(con);
- if (con->listen_fd != -1) {
- if (!con->open) {
- errno = EISCONN;
- return -1;
- }
- return con->listen_fd;
+ if (con->open) {
+ if (con->listen_fd != -1)
+ return con->listen_fd;
+ errno = EISCONN;
+ return -1;
}
/* We need to block the command fd */
con->command_fd = dhcpcd_connect(0);
if (dhcpcd_command(con, "--getconfigfile", &con->cffile) <= 0)
goto err_exit;
+ con->open = true;
+ update_status(con, NULL);
+
con->listen_fd = dhcpcd_connect(SOCK_NONBLOCK);
if (con->listen_fd == -1)
goto err_exit;
- dhcpcd_command_fd(con, con->listen_fd, "--listen", NULL);
+ dhcpcd_command_fd(con, con->listen_fd, "--listen", NULL);
dhcpcd_command_fd(con, con->command_fd, "--getinterfaces", NULL);
bytes = read(con->command_fd, cmd, sizeof(nifs));
if (bytes != sizeof(nifs))
goto err_exit;
-
memcpy(&nifs, cmd, sizeof(nifs));
/* We don't dispatch each interface here as that
* causes too much notification spam when the GUI starts */
- for (n = 0; n < nifs; n++) {
+ for (n = 0; n < nifs; n++)
i = dhcpcd_read_if(con, con->command_fd);
- if (i)
- dhcpcd_wpa_if_event(i);
- }
+
update_status(con, NULL);
- con->open = true;
+
return con->listen_fd;
err_exit:
void *if_context;
void (*status_cb)(struct dhcpcd_connection *, const char *, void *);
void *status_context;
+ bool wpa_started;
void (*wi_scanresults_cb)(DHCPCD_WPA *, void *);
void *wi_scanresults_context;
void (*wpa_status_cb)(DHCPCD_WPA *, const char *, void *);
#define dhcpcd_rebind(c, i) dhcpcd_command_arg((c), "-n", (i), NULL)
#define dhcpcd_release(c, i) dhcpcd_command_arg((c), "-k", (i), NULL)
+void dhcpcd_wpa_start(DHCPCD_CONNECTION *);
DHCPCD_WPA *dhcpcd_wpa_find(DHCPCD_CONNECTION *, const char *);
DHCPCD_WPA *dhcpcd_wpa_new(DHCPCD_CONNECTION *, const char *);
DHCPCD_CONNECTION *dhcpcd_wpa_connection(DHCPCD_WPA *);
wpa = dhcpcd_wpa_find(i->con, i->ifname);
if (wpa)
dhcpcd_wpa_close(wpa);
- } else if (i->up) {
+ } else if (i->up && i->con->wpa_started) {
wpa = dhcpcd_wpa_new(i->con, i->ifname);
if (wpa && wpa->listen_fd == -1)
dhcpcd_wpa_open(wpa);
}
}
}
+
+void
+dhcpcd_wpa_start(DHCPCD_CONNECTION *con)
+{
+ DHCPCD_IF *i;
+
+ assert(con);
+ con->wpa_started = true;
+
+ for (i = con->interfaces; i; i = i->next)
+ dhcpcd_wpa_if_event(i);
+}