From owner-p4-projects@FreeBSD.ORG Sat Dec 4 02:30:23 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1C3BC16A4D1; Sat, 4 Dec 2004 02:30:23 +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 DA6A216A4CF for ; Sat, 4 Dec 2004 02:30:22 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9F41643D46 for ; Sat, 4 Dec 2004 02:30:22 +0000 (GMT) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id iB42UMUO017589 for ; Sat, 4 Dec 2004 02:30:22 GMT (envelope-from sam@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id iB42UMUu017577 for perforce@freebsd.org; Sat, 4 Dec 2004 02:30:22 GMT (envelope-from sam@freebsd.org) Date: Sat, 4 Dec 2004 02:30:22 GMT Message-Id: <200412040230.iB42UMUu017577@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 66381 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: Sat, 04 Dec 2004 02:30:23 -0000 http://perforce.freebsd.org/chv.cgi?CH=66381 Change 66381 by sam@sam_ebb on 2004/12/04 02:30:04 There are too many parameters for 802.11 devices so stop trying to use a fixed format and just bin-pack the output with special consideration for keys. Not 100% happy with this; it'll likely need tweaking. Affected files ... .. //depot/projects/wifi/sbin/ifconfig/ifieee80211.c#27 edit Differences ... ==== //depot/projects/wifi/sbin/ifconfig/ifieee80211.c#27 (text+ko) ==== @@ -1079,6 +1079,31 @@ return IEEE80211_M_STA; } +static const struct ieee80211_channel * +getchaninfo(int s, int chan) +{ + struct ieee80211req ireq; + static struct ieee80211req_chaninfo chans; + static struct ieee80211_channel undef; + const struct ieee80211_channel *c; + int i, freq; + + (void) memset(&ireq, 0, sizeof(ireq)); + (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); + ireq.i_type = IEEE80211_IOC_CHANINFO; + ireq.i_data = &chans; + ireq.i_len = sizeof(chans); + if (ioctl(s, SIOCG80211, &ireq) < 0) + errx(1, "unable to get channel information"); + freq = ieee80211_ieee2mhz(chan); + for (i = 0; i < chans.ic_nchans; i++) { + c = &chans.ic_chans[i]; + if (c->ic_freq == freq) + return c; + } + return &undef; +} + #if 0 static void printcipher(int s, struct ieee80211req *ireq, int keylenop) @@ -1115,42 +1140,73 @@ } #endif -static int +#define MAXCOL 78 +int col; +char spacer; + +#define LINE_BREAK() do { \ + if (spacer != '\t') { \ + printf("\n"); \ + spacer = '\t'; \ + } \ + col = 8; /* 8-col tab */ \ +} while (0) +#define LINE_CHECK(fmt, ...) do { \ + col += sizeof(fmt)-2; \ + if (col > MAXCOL) { \ + LINE_BREAK(); \ + col += sizeof(fmt)-2; \ + } \ + printf(fmt, __VA_ARGS__); \ + spacer = ' '; \ +} while (0) + +static void printkey(const struct ieee80211req_key *ik) { static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE]; int keylen = ik->ik_keylen; + int printcontents; + printcontents = + (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose); + if (printcontents) + LINE_BREAK(); switch (ik->ik_type) { case IEEE80211_CIPHER_WEP: /* compatibility */ - printf("wepkey %u:%s", ik->ik_keyix+1, + LINE_CHECK("%cwepkey %u:%s", spacer, ik->ik_keyix+1, keylen <= 5 ? "40-bit" : keylen <= 13 ? "104-bit" : "128-bit"); break; case IEEE80211_CIPHER_TKIP: if (keylen > 128/8) keylen -= 128/8; /* ignore MIC for now */ - printf("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen); + LINE_CHECK("%cTKIP %u:%u-bit", + spacer, ik->ik_keyix+1, 8*keylen); break; case IEEE80211_CIPHER_AES_OCB: - printf("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen); + LINE_CHECK("%cAES-OCB %u:%u-bit", + spacer, ik->ik_keyix+1, 8*keylen); break; case IEEE80211_CIPHER_AES_CCM: - printf("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen); + LINE_CHECK("%cAES-CCM %u:%u-bit", + spacer, ik->ik_keyix+1, 8*keylen); break; case IEEE80211_CIPHER_CKIP: - printf("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen); + LINE_CHECK("%cCKIP %u:%u-bit", + spacer, ik->ik_keyix+1, 8*keylen); break; case IEEE80211_CIPHER_NONE: - printf("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen); + LINE_CHECK("%cNULL %u:%u-bit", + spacer, ik->ik_keyix+1, 8*keylen); break; default: - printf("UNKNOWN (0x%x) %u:%u-bit", ik->ik_type, - ik->ik_keyix+1, 8*keylen); + LINE_CHECK("%cUNKNOWN (0x%x) %u:%u-bit", spacer, + ik->ik_type, ik->ik_keyix+1, 8*keylen); break; } - if (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose) { + if (printcontents) { int i; printf(" <"); @@ -1173,36 +1229,10 @@ if (ik->ik_flags & IEEE80211_KEY_DEFAULT) printf("%sdef", sep), sep = "+"; } - return 1; /* tell caller to do line break */ + LINE_BREAK(); } - return 0; } -static const struct ieee80211_channel * -getchaninfo(int s, int chan) -{ - struct ieee80211req ireq; - static struct ieee80211req_chaninfo chans; - static struct ieee80211_channel undef; - const struct ieee80211_channel *c; - int i, freq; - - (void) memset(&ireq, 0, sizeof(ireq)); - (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); - ireq.i_type = IEEE80211_IOC_CHANINFO; - ireq.i_data = &chans; - ireq.i_len = sizeof(chans); - if (ioctl(s, SIOCG80211, &ireq) < 0) - errx(1, "unable to get channel information"); - freq = ieee80211_ieee2mhz(chan); - for (i = 0; i < chans.ic_nchans; i++) { - c = &chans.ic_chans[i]; - if (c->ic_freq == freq) - return c; - } - return &undef; -} - static void ieee80211_status(int s, const struct rt_addrinfo *info __unused) { @@ -1212,7 +1242,6 @@ struct ieee80211req ireq; u_int8_t data[32]; const struct ieee80211_channel *c; - char spacer; (void) memset(&ireq, 0, sizeof(ireq)); (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); @@ -1259,33 +1288,29 @@ memcmp(ireq.i_data, zerobssid, sizeof(zerobssid)) != 0) printf(" bssid %s", ether_ntoa(ireq.i_data)); - printf("\n"); - ireq.i_type = IEEE80211_IOC_STATIONNAME; if (ioctl(s, SIOCG80211, &ireq) != -1) { - printf("\tstationname "); + printf("\n\tstationname "); print_string(data, ireq.i_len); - printf("\n"); } - spacer = '\t'; + spacer = ' '; /* force first break */ + LINE_BREAK(); ireq.i_type = IEEE80211_IOC_AUTHMODE; if (ioctl(s, SIOCG80211, &ireq) != -1) { - printf("%cauthmode ", spacer); - spacer = ' '; switch (ireq.i_val) { case IEEE80211_AUTH_NONE: - printf("NONE"); + LINE_CHECK("%cauthmode NONE", spacer); break; case IEEE80211_AUTH_OPEN: - printf("OPEN"); + LINE_CHECK("%cauthmode OPEN", spacer); break; case IEEE80211_AUTH_SHARED: - printf("SHARED"); + LINE_CHECK("%cauthmode SHARED", spacer); break; case IEEE80211_AUTH_8021X: - printf("802.1x"); + LINE_CHECK("%cauthmode 802.1x", spacer); break; case IEEE80211_AUTH_WPA: ireq.i_type = IEEE80211_IOC_WPA; @@ -1295,21 +1320,24 @@ wpa = 1; /* default to WPA1 */ switch (wpa) { case 2: - printf("WPA2/802.11i"); + LINE_CHECK("%cauthmode WPA2/802.11i", + spacer); break; case 3: - printf("WPA1+WPA2/802.11i"); + LINE_CHECK("%cauthmode WPA1+WPA2/802.11i", + spacer); break; default: - printf("WPA"); + LINE_CHECK("%cauthmode WPA", spacer); break; } break; case IEEE80211_AUTH_AUTO: - printf("AUTO"); + LINE_CHECK("%cauthmode AUTO", spacer); break; default: - printf("UNKNOWN (0x%x)", ireq.i_val); + LINE_CHECK("%cauthmode UNKNOWN (0x%x)", + spacer, ireq.i_val); break; } } @@ -1317,19 +1345,21 @@ ireq.i_type = IEEE80211_IOC_WEP; if (ioctl(s, SIOCG80211, &ireq) != -1 && ireq.i_val != IEEE80211_WEP_NOSUP) { - printf("%cprivacy ", spacer); + int firstkey; + switch (ireq.i_val) { case IEEE80211_WEP_OFF: - printf("OFF"); + LINE_CHECK("%cprivacy OFF", spacer); break; case IEEE80211_WEP_ON: - printf("ON"); + LINE_CHECK("%cprivacy ON", spacer); break; case IEEE80211_WEP_MIXED: - printf("MIXED"); + LINE_CHECK("%cprivacy MIXED", spacer); break; default: - printf("UNKNOWN (0x%x)", ireq.i_val); + LINE_CHECK("%cprivacy UNKNOWN (0x%x)", + spacer, ireq.i_val); break; } @@ -1344,9 +1374,9 @@ goto end; } if (ireq.i_val != -1) - printf(" deftxkey %d", ireq.i_val+1); + LINE_CHECK("%cdeftxkey %d", spacer, ireq.i_val+1); else if (verbose) - printf(" deftxkey UNDEF"); + LINE_CHECK("%cdeftxkey UNDEF", spacer); ireq.i_type = IEEE80211_IOC_NUMWEPKEYS; if (ioctl(s, SIOCG80211, &ireq) < 0) { @@ -1355,9 +1385,7 @@ } num = ireq.i_val; - printf("\n"); - spacer = '\t'; - + firstkey = 1; for (i = 0; i < num; i++) { struct ieee80211req_key ik; @@ -1370,187 +1398,151 @@ warn("WEP support, but can get keys!"); goto end; } - if (ik.ik_keylen == 0) - continue; - printf("%c", spacer); - if (printkey(&ik)) { - printf("\n"); - spacer = '\t'; - } else - spacer = ' '; + if (ik.ik_keylen != 0) { + if (verbose) + LINE_BREAK(); + printkey(&ik); + firstkey = 0; + } } } - if (spacer != '\t') - printf("\n"); - spacer = '\t'; - ireq.i_type = IEEE80211_IOC_POWERSAVE; if (ioctl(s, SIOCG80211, &ireq) != -1 && ireq.i_val != IEEE80211_POWERSAVE_NOSUP ) { if (ireq.i_val != IEEE80211_POWERSAVE_OFF || verbose) { - printf("%cpowersavemode", spacer); switch (ireq.i_val) { case IEEE80211_POWERSAVE_OFF: - printf(" OFF"); + LINE_CHECK("%cpowersavemode OFF", + spacer); break; case IEEE80211_POWERSAVE_CAM: - printf(" CAM"); + LINE_CHECK("%cpowersavemode CAM", + spacer); break; case IEEE80211_POWERSAVE_PSP: - printf(" PSP"); + LINE_CHECK("%cpowersavemode PSP", + spacer); break; case IEEE80211_POWERSAVE_PSP_CAM: - printf(" PSP-CAM"); + LINE_CHECK("%cpowersavemode PSP-CAM", + spacer); break; } ireq.i_type = IEEE80211_IOC_POWERSAVESLEEP; - if (ioctl(s, SIOCG80211, &ireq) != -1) { - printf(" powersavesleep %d", ireq.i_val); - } - spacer = ' '; + if (ioctl(s, SIOCG80211, &ireq) != -1) + LINE_CHECK("%cpowersavesleep %d", + spacer, ireq.i_val); } } ireq.i_type = IEEE80211_IOC_TXPOWMAX; - if (ioctl(s, SIOCG80211, &ireq) != -1) { - printf("%ctxpowmax %d", spacer, ireq.i_val); - spacer = ' '; - } + if (ioctl(s, SIOCG80211, &ireq) != -1) + LINE_CHECK("%ctxpowmax %d", spacer, ireq.i_val); if (verbose) { ireq.i_type = IEEE80211_IOC_TXPOWER; - if (ioctl(s, SIOCG80211, &ireq) != -1) { - printf("%ctxpower %d", spacer, ireq.i_val); - spacer = ' '; - } + if (ioctl(s, SIOCG80211, &ireq) != -1) + LINE_CHECK("%ctxpower %d", spacer, ireq.i_val); } - if (spacer != '\t') - printf("\n"); - spacer = '\t'; - ireq.i_type = IEEE80211_IOC_RTSTHRESHOLD; - if (ioctl(s, SIOCG80211, &ireq) != -1) { - printf("%crtsthreshold %d", spacer, ireq.i_val); - spacer = ' '; - } + if (ioctl(s, SIOCG80211, &ireq) != -1) + LINE_CHECK("%crtsthreshold %d", spacer, ireq.i_val); if (IEEE80211_IS_CHAN_G(c) || IEEE80211_IS_CHAN_PUREG(c) || verbose) { ireq.i_type = IEEE80211_IOC_PROTMODE; if (ioctl(s, SIOCG80211, &ireq) != -1) { - printf("%cprotmode ", spacer); switch (ireq.i_val) { case IEEE80211_PROTMODE_OFF: - printf("OFF"); + LINE_CHECK("%cprotmode OFF", spacer); break; case IEEE80211_PROTMODE_CTS: - printf("CTS"); + LINE_CHECK("%cprotmode CTS", spacer); break; case IEEE80211_PROTMODE_RTSCTS: - printf("RTSCTS"); + LINE_CHECK("%cprotmode RTSCTS", spacer); break; default: - printf("UNKNOWN (0x%x)", ireq.i_val); + LINE_CHECK("%cprotmode UNKNOWN (0x%x)", + spacer, ireq.i_val); break; } - spacer = ' '; } } ireq.i_type = IEEE80211_IOC_WME; if (ioctl(s, SIOCG80211, &ireq) != -1) { wme = ireq.i_val; - if (wme) { - printf("%cwme", spacer); - spacer = ' '; - } else if (verbose) { - printf("%c-wme", spacer); - spacer = ' '; - } + if (wme) + LINE_CHECK("%cwme", spacer); + else if (verbose) + LINE_CHECK("%c-wme", spacer); } else wme = 0; if (opmode == IEEE80211_M_HOSTAP) { ireq.i_type = IEEE80211_IOC_HIDESSID; if (ioctl(s, SIOCG80211, &ireq) != -1) { - if (ireq.i_val) { - printf("%cssid HIDE", spacer); - spacer = ' '; - } else if (verbose) { - printf("%cssid SHOW", spacer); - spacer = ' '; - } + if (ireq.i_val) + LINE_CHECK("%cssid HIDE", spacer); + else if (verbose) + LINE_CHECK("%cssid SHOW", spacer); } ireq.i_type = IEEE80211_IOC_APBRIDGE; if (ioctl(s, SIOCG80211, &ireq) != -1) { - if (!ireq.i_val) { - printf("%c-apbridge", spacer); - spacer = ' '; - } else if (verbose) { - printf("%capbridge", spacer); - spacer = ' '; - } + if (!ireq.i_val) + LINE_CHECK("%c-apbridge", spacer); + else if (verbose) + LINE_CHECK("%capbridge", spacer); } ireq.i_type = IEEE80211_IOC_DTIM_PERIOD; - if (ioctl(s, SIOCG80211, &ireq) != -1) { - printf("%cdtimperiod %u", spacer, ireq.i_val); - spacer = ' '; - } + if (ioctl(s, SIOCG80211, &ireq) != -1) + LINE_CHECK("%cdtimperiod %u", spacer, ireq.i_val); } else { ireq.i_type = IEEE80211_IOC_ROAMING; if (ioctl(s, SIOCG80211, &ireq) != -1) { if (ireq.i_val != IEEE80211_ROAMING_AUTO || verbose) { - printf("%croaming ", spacer); switch (ireq.i_val) { case IEEE80211_ROAMING_DEVICE: - printf("DEVICE"); + LINE_CHECK("%croaming DEVICE", spacer); break; case IEEE80211_ROAMING_AUTO: - printf("AUTO"); + LINE_CHECK("%croaming AUTO", spacer); break; case IEEE80211_ROAMING_MANUAL: - printf("MANUAL"); + LINE_CHECK("%croaming MANUAL", spacer); break; default: - printf("UNKNOWN (0x%x)", ireq.i_val); + LINE_CHECK("%croaming UNKNOWN (0x%x)", + spacer, ireq.i_val); break; } - spacer = ' '; } } } ireq.i_type = IEEE80211_IOC_BEACON_INTERVAL; if (ioctl(s, SIOCG80211, &ireq) != -1) { - if (ireq.i_val) { - printf("%cbintval %u", spacer, ireq.i_val); - spacer = ' '; - } else if (verbose) { - printf("%cbintval %u", spacer, ireq.i_val); - spacer = ' '; - } + if (ireq.i_val) + LINE_CHECK("%cbintval %u", spacer, ireq.i_val); + else if (verbose) + LINE_CHECK("%cbintval %u", spacer, ireq.i_val); } - if (spacer != '\t') - printf("\n"); - spacer = '\t'; - - if (wme && verbose) + if (wme && verbose) { + LINE_BREAK(); list_wme(s); + } if (wpa) { - spacer = '\t'; ireq.i_type = IEEE80211_IOC_COUNTERMEASURES; if (ioctl(s, SIOCG80211, &ireq) != -1) { - if (ireq.i_val) { - printf("%ccountermeasures", spacer); - spacer = ' '; - } else if (verbose) { - printf("%c-countermeasures", spacer); - spacer = ' '; - } + if (ireq.i_val) + LINE_CHECK("%ccountermeasures", spacer); + else if (verbose) + LINE_CHECK("%c-countermeasures", spacer); } #if 0 /* XXX not interesting with WPA done in user space */ @@ -1583,9 +1575,9 @@ if (ioctl(s, SIOCG80211, &ireq) != -1) { } #endif - if (spacer != '\t') - printf("\n"); + LINE_BREAK(); } + LINE_BREAK(); end: return;