示例#1
0
static gboolean
dhcpcd_wpa_cb(_unused GIOChannel *gio, _unused GIOCondition c,
    gpointer data)
{
	DHCPCD_WPA *wpa;
	DHCPCD_IF *i;

	wpa = (DHCPCD_WPA *)data;
	if (dhcpcd_wpa_get_fd(wpa) == -1) {
		dhcpcd_unwatch(-1, wpa);

		/* If the interface hasn't left, try re-opening */
		i = dhcpcd_wpa_if(wpa);
		if (i == NULL ||
		    g_strcmp0(i->reason, "DEPARTED") == 0 ||
		    g_strcmp0(i->reason, "STOPPED") == 0)
			return TRUE;
		g_warning(_("dhcpcd WPA connection lost: %s"), i->ifname);
		g_timeout_add(DHCPCD_RETRYOPEN, dhcpcd_wpa_try_open, wpa);
		return FALSE;
	}

	dhcpcd_wpa_dispatch(wpa);
	return TRUE;
}
void DhcpcdQt::scanCallback(DHCPCD_WPA *wpa)
{
	DHCPCD_WI_SCAN *scans;
	int fd = dhcpcd_wpa_get_fd(wpa);
	DhcpcdWi *wi;

	wi = findWi(wpa);
	if (fd == -1) {
		qCritical("No fd for WPA");
		if (wi) {
			wis->removeOne(wi);
			wi->deleteLater();
		}
		return;
	}

	DHCPCD_IF *i = dhcpcd_wpa_if(wpa);
	if (i == NULL) {
		qCritical("No interface for WPA");
		if (wi) {
			wis->removeOne(wi);
			wi->deleteLater();
		}
		return;
	}

	qDebug("%s: Received scan results", i->ifname);
	scans = dhcpcd_wi_scans(i);
	if (wi == NULL) {
		wi = new DhcpcdWi(this, wpa);
		if (wi->open()) {
			wis->append(wi);
			wi->setScans(scans);
		} else
			wi->deleteLater();
	} else
		processScans(wi, scans);

	if (!aniTimer->isActive()) {
		DHCPCD_WI_SCAN *scan;
		const char *icon;

		scan = getStrongestSignal();
		if (scan)
			icon = DhcpcdQt::signalStrengthIcon(scan);
		else if (onLine)
			icon = "network-transmit-receive";
		else
			icon = "network-offline";

		setIcon("status", icon);
	}
}
示例#3
0
static void
dhcpcd_wpa_scan_cb(DHCPCD_WPA *wpa, _unused void *data)
{
	DHCPCD_IF *i;
	WI_SCAN *w;
	DHCPCD_WI_SCAN *scans, *s1, *s2;
	char *txt, *t;
	int lerrno, fd;
	const char *msg;

	/* This could be a new WPA so watch it */
	fd = dhcpcd_wpa_get_fd(wpa);
	if (fd == -1) {
		g_critical("No fd for WPA %p", wpa);
		dhcpcd_unwatch(-1, wpa);
		return;
	}
	dhcpcd_watch(fd, dhcpcd_wpa_cb, wpa);

	i = dhcpcd_wpa_if(wpa);
	if (i == NULL) {
		g_critical("No interface for WPA %p", wpa);
		return;
	}
	g_message(_("%s: Received scan results"), i->ifname);
	lerrno = errno;
	errno = 0;
	scans = dhcpcd_wi_scans(i);
	if (scans == NULL && errno)
		g_warning("%s: %s", i->ifname, strerror(errno));
	errno = lerrno;
	for (w = wi_scans; w; w = w->next)
		if (w->interface == i)
			break;
	if (w == NULL) {
		w = g_malloc(sizeof(*w));
		w->interface = i;
		w->next = wi_scans;
		wi_scans = w;
	} else {
		txt = NULL;
		msg = N_("New Access Point");
		for (s1 = scans; s1; s1 = s1->next) {
			for (s2 = w->scans; s2; s2 = s2->next)
				if (g_strcmp0(s1->ssid, s2->ssid) == 0)
					break;
			if (s2 == NULL) {
				if (txt == NULL)
					txt = g_strdup(s1->ssid);
				else {
					msg = N_("New Access Points");
					t = g_strconcat(txt, "\n",
					    s1->ssid, NULL);
					g_free(txt);
					txt = t;
				}
			}
		}
		if (txt) {
			notify(msg, txt, "network-wireless");
			g_free(txt);
		}
		menu_update_scans(w->interface, scans);
		dhcpcd_wi_scans_free(w->scans);
	}
	w->scans = scans;
}