From owner-p4-projects@FreeBSD.ORG Mon Nov 8 06:50:42 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 859C216A4D0; Mon, 8 Nov 2004 06:50:42 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 60FC216A4CE for ; Mon, 8 Nov 2004 06:50:42 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3B0FE43D49 for ; Mon, 8 Nov 2004 06:50:42 +0000 (GMT) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id iA86og32085566 for ; Mon, 8 Nov 2004 06:50:42 GMT (envelope-from sam@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id iA86ofW2085563 for perforce@freebsd.org; Mon, 8 Nov 2004 06:50:41 GMT (envelope-from sam@freebsd.org) Date: Mon, 8 Nov 2004 06:50:41 GMT Message-Id: <200411080650.iA86ofW2085563@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to sam@freebsd.org using -f From: Sam Leffler To: Perforce Change Reviews Subject: PERFORCE change 64563 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Nov 2004 06:50:43 -0000 http://perforce.freebsd.org/chv.cgi?CH=64563 Change 64563 by sam@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 + +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"