PERFORCE change 64563 for review

Sam Leffler sam at FreeBSD.org
Sun Nov 7 22:50:43 PST 2004


http://perforce.freebsd.org/chv.cgi?CH=64563

Change 64563 by sam at sam_ebb on 2004/11/08 06:49:47

	use the routing socket to wait for a scan to complete

Affected files ...

.. //depot/projects/wifi/sbin/ifconfig/ifieee80211.c#5 edit

Differences ...

==== //depot/projects/wifi/sbin/ifconfig/ifieee80211.c#5 (text+ko) ====

@@ -546,6 +546,43 @@
 	}
 }
 
+#include <net80211/ieee80211_freebsd.h>
+
+static void
+scan_and_wait(int s)
+{
+	struct ieee80211req ireq;
+	int sroute;
+
+	sroute = socket(PF_ROUTE, SOCK_RAW, 0);
+	if (sroute < 0) {
+		perror("socket(PF_ROUTE,SOCK_RAW)");
+		return;
+	}
+	(void) memset(&ireq, 0, sizeof(ireq));
+	(void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
+	ireq.i_type = IEEE80211_IOC_SCAN_REQ;
+	/* NB: only root can trigger a scan so ignore errors */
+	if (ioctl(s, SIOCS80211, &ireq) >= 0) {
+		char buf[2048];
+		struct if_announcemsghdr *ifan;
+		struct rt_msghdr *rtm;
+
+		do {
+			if (read(sroute, buf, sizeof(buf)) < 0) {
+				perror("read(PF_ROUTE)");
+				break;
+			}
+			rtm = (struct rt_msghdr *) buf;
+			if (rtm->rtm_version != RTM_VERSION)
+				break;
+			ifan = (struct if_announcemsghdr *) rtm;
+		} while (rtm->rtm_type != RTM_IEEE80211 ||
+		    ifan->ifan_what != RTM_IEEE80211_SCAN);
+	}
+	close(sroute);
+}
+
 static void
 set80211scan(const char *val, int d, int s, const struct afswtch *rafp)
 {
@@ -554,20 +591,15 @@
 	uint8_t *cp;
 	int len;
 
+	scan_and_wait(s);
+
 	(void) memset(&ireq, 0, sizeof(ireq));
 	(void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
-	ireq.i_type = IEEE80211_IOC_SCAN_REQ;
-	/* NB: only root can trigger a scan so ignore errors */
-	(void) ioctl(s, SIOCS80211, &ireq);
-
 	ireq.i_type = IEEE80211_IOC_SCAN_RESULTS;
 	ireq.i_data = buf;
 	ireq.i_len = sizeof(buf);
-	while (ioctl(s, SIOCG80211, &ireq) < 0) {
-		if (errno != EINPROGRESS)
-			errx(1, "unable to get scan results");
-		sleep(1);
-	}
+	if (ioctl(s, SIOCG80211, &ireq) < 0)
+		errx(1, "unable to get scan results");
 	len = ireq.i_len;
 	if (len >= sizeof(struct ieee80211req_scan_result))
 		printf("%-14.14s  %-17.17s  %4s %4s  %-5s %3s %4s\n"


More information about the p4-projects mailing list