While trying to port rsu(4) from OpenBSD, I was wondering why ifconfig
list scan does not work at all with my card, and I finally realized that
ifconfig list scan just fails with a silly error message when the card
is not up ("ifconfig: SIOCS80211: Invalid argument") (see
http://nxr.netbsd.org/xref/src/sys/net80211/ieee80211_ioctl.c#ieee80211_setupscan
for code reference).
So I propose that 'ifconfig list scan' automatically up the card if it
is down. See the attached patch. Any objection ?
At minima, we must return a more useful error message to the caller.
diff --git a/sbin/ifconfig/ieee80211.c b/sbin/ifconfig/ieee80211.c
index 1e49c57..da2566e 100644
--- a/sbin/ifconfig/ieee80211.c
+++ b/sbin/ifconfig/ieee80211.c
@@ -463,8 +463,33 @@ setifpowersavesleep(prop_dictionary_t env,
prop_dictionary_t oenv)
static int
scan_exec(prop_dictionary_t env, prop_dictionary_t oenv)
{
+ struct ifreq ifr;
+ bool must_up_card;
+
+ if (direct_ioctl(env, SIOCGIFFLAGS, &ifr) == -1) {
+ perror("ioctl(SIOCGIFFLAGS");
+ return -1;
+ }
+
+ must_up_card = (ifr.ifr_flags & IFF_UP) == 0;
+ if (must_up_card) {
+ ifr.ifr_flags |= IFF_UP;
+ if (direct_ioctl(env, SIOCSIFFLAGS, &ifr) == -1) {
+ perror("ioctl(SIOCSIFFLAGS");
+ return -1;
+ }
+ }
+
scan_and_wait(env);
list_scan(env);
+
+ if (must_up_card) {
+ ifr.ifr_flags &= ~IFF_UP;
+ if (direct_ioctl(env, SIOCSIFFLAGS, &ifr) == -1) {
+ perror("ioctl(SIOCSIFFLAGS");
+ return -1;
+ }
+ }
return 0;
}
Attachment:
pgp6T4lJBJmVh.pgp
Description: PGP signature