ieee80211.c revision 1.3 1 1.3 dyoung /* $NetBSD: ieee80211.c,v 1.3 2005/09/15 23:35:15 dyoung Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 1983, 1993
5 1.1 thorpej * The Regents of the University of California. All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1 thorpej * modification, are permitted provided that the following conditions
9 1.1 thorpej * are met:
10 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1 thorpej * documentation and/or other materials provided with the distribution.
15 1.1 thorpej * 3. Neither the name of the University nor the names of its contributors
16 1.1 thorpej * may be used to endorse or promote products derived from this software
17 1.1 thorpej * without specific prior written permission.
18 1.1 thorpej *
19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 thorpej * SUCH DAMAGE.
30 1.1 thorpej */
31 1.1 thorpej
32 1.1 thorpej #include <sys/cdefs.h>
33 1.1 thorpej #ifndef lint
34 1.3 dyoung __RCSID("$NetBSD: ieee80211.c,v 1.3 2005/09/15 23:35:15 dyoung Exp $");
35 1.1 thorpej #endif /* not lint */
36 1.1 thorpej
37 1.1 thorpej #include <sys/param.h>
38 1.1 thorpej #include <sys/ioctl.h>
39 1.1 thorpej #include <sys/socket.h>
40 1.1 thorpej
41 1.1 thorpej #include <net/if.h>
42 1.1 thorpej #include <net/if_ether.h>
43 1.1 thorpej #include <net80211/ieee80211.h>
44 1.1 thorpej #include <net80211/ieee80211_ioctl.h>
45 1.1 thorpej
46 1.1 thorpej #include <ctype.h>
47 1.1 thorpej #include <err.h>
48 1.1 thorpej #include <netdb.h>
49 1.1 thorpej #include <string.h>
50 1.1 thorpej #include <stdlib.h>
51 1.1 thorpej #include <stdio.h>
52 1.1 thorpej
53 1.1 thorpej #include "extern.h"
54 1.1 thorpej #include "ieee80211.h"
55 1.1 thorpej
56 1.1 thorpej void
57 1.1 thorpej setifnwid(const char *val, int d)
58 1.1 thorpej {
59 1.1 thorpej struct ieee80211_nwid nwid;
60 1.1 thorpej int len;
61 1.1 thorpej
62 1.1 thorpej len = sizeof(nwid.i_nwid);
63 1.1 thorpej if (get_string(val, NULL, nwid.i_nwid, &len) == NULL)
64 1.1 thorpej return;
65 1.1 thorpej nwid.i_len = len;
66 1.1 thorpej (void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
67 1.1 thorpej ifr.ifr_data = (void *)&nwid;
68 1.1 thorpej if (ioctl(s, SIOCS80211NWID, &ifr) == -1)
69 1.1 thorpej warn("SIOCS80211NWID");
70 1.1 thorpej }
71 1.1 thorpej
72 1.1 thorpej void
73 1.1 thorpej setifbssid(const char *val, int d)
74 1.1 thorpej {
75 1.1 thorpej struct ieee80211_bssid bssid;
76 1.1 thorpej struct ether_addr *ea;
77 1.1 thorpej
78 1.1 thorpej if (d != 0) {
79 1.1 thorpej /* no BSSID is especially desired */
80 1.1 thorpej memset(&bssid.i_bssid, 0, sizeof(bssid.i_bssid));
81 1.1 thorpej } else {
82 1.1 thorpej ea = ether_aton(val);
83 1.1 thorpej if (ea == NULL) {
84 1.1 thorpej warnx("malformed BSSID: %s", val);
85 1.1 thorpej return;
86 1.1 thorpej }
87 1.1 thorpej memcpy(&bssid.i_bssid, ea->ether_addr_octet,
88 1.1 thorpej sizeof(bssid.i_bssid));
89 1.1 thorpej }
90 1.1 thorpej (void)strncpy(bssid.i_name, name, sizeof(bssid.i_name));
91 1.1 thorpej if (ioctl(s, SIOCS80211BSSID, &bssid) == -1)
92 1.1 thorpej warn("SIOCS80211BSSID");
93 1.1 thorpej }
94 1.1 thorpej
95 1.1 thorpej void
96 1.1 thorpej setifchan(const char *val, int d)
97 1.1 thorpej {
98 1.1 thorpej struct ieee80211chanreq channel;
99 1.1 thorpej int chan;
100 1.1 thorpej
101 1.1 thorpej if (d != 0)
102 1.1 thorpej chan = IEEE80211_CHAN_ANY;
103 1.1 thorpej else {
104 1.1 thorpej chan = atoi(val);
105 1.1 thorpej if (chan < 0 || chan > 0xffff) {
106 1.1 thorpej warnx("invalid channel: %s", val);
107 1.1 thorpej return;
108 1.1 thorpej }
109 1.1 thorpej }
110 1.1 thorpej
111 1.1 thorpej (void)strncpy(channel.i_name, name, sizeof(channel.i_name));
112 1.1 thorpej channel.i_channel = (u_int16_t) chan;
113 1.1 thorpej if (ioctl(s, SIOCS80211CHANNEL, &channel) == -1)
114 1.1 thorpej warn("SIOCS80211CHANNEL");
115 1.1 thorpej }
116 1.1 thorpej
117 1.1 thorpej void
118 1.1 thorpej setifnwkey(const char *val, int d)
119 1.1 thorpej {
120 1.1 thorpej struct ieee80211_nwkey nwkey;
121 1.1 thorpej int i;
122 1.1 thorpej u_int8_t keybuf[IEEE80211_WEP_NKID][16];
123 1.1 thorpej
124 1.1 thorpej nwkey.i_wepon = IEEE80211_NWKEY_WEP;
125 1.1 thorpej nwkey.i_defkid = 1;
126 1.1 thorpej for (i = 0; i < IEEE80211_WEP_NKID; i++) {
127 1.1 thorpej nwkey.i_key[i].i_keylen = sizeof(keybuf[i]);
128 1.1 thorpej nwkey.i_key[i].i_keydat = keybuf[i];
129 1.1 thorpej }
130 1.1 thorpej if (d != 0) {
131 1.1 thorpej /* disable WEP encryption */
132 1.1 thorpej nwkey.i_wepon = 0;
133 1.1 thorpej i = 0;
134 1.1 thorpej } else if (strcasecmp("persist", val) == 0) {
135 1.1 thorpej /* use all values from persistent memory */
136 1.1 thorpej nwkey.i_wepon |= IEEE80211_NWKEY_PERSIST;
137 1.1 thorpej nwkey.i_defkid = 0;
138 1.1 thorpej for (i = 0; i < IEEE80211_WEP_NKID; i++)
139 1.1 thorpej nwkey.i_key[i].i_keylen = -1;
140 1.1 thorpej } else if (strncasecmp("persist:", val, 8) == 0) {
141 1.1 thorpej val += 8;
142 1.1 thorpej /* program keys in persistent memory */
143 1.1 thorpej nwkey.i_wepon |= IEEE80211_NWKEY_PERSIST;
144 1.1 thorpej goto set_nwkey;
145 1.1 thorpej } else {
146 1.1 thorpej set_nwkey:
147 1.1 thorpej if (isdigit((unsigned char)val[0]) && val[1] == ':') {
148 1.1 thorpej /* specifying a full set of four keys */
149 1.1 thorpej nwkey.i_defkid = val[0] - '0';
150 1.1 thorpej val += 2;
151 1.1 thorpej for (i = 0; i < IEEE80211_WEP_NKID; i++) {
152 1.1 thorpej val = get_string(val, ",", keybuf[i],
153 1.1 thorpej &nwkey.i_key[i].i_keylen);
154 1.1 thorpej if (val == NULL)
155 1.1 thorpej return;
156 1.1 thorpej }
157 1.1 thorpej if (*val != '\0') {
158 1.1 thorpej warnx("SIOCS80211NWKEY: too many keys.");
159 1.1 thorpej return;
160 1.1 thorpej }
161 1.1 thorpej } else {
162 1.1 thorpej val = get_string(val, NULL, keybuf[0],
163 1.1 thorpej &nwkey.i_key[0].i_keylen);
164 1.1 thorpej if (val == NULL)
165 1.1 thorpej return;
166 1.1 thorpej i = 1;
167 1.1 thorpej }
168 1.1 thorpej }
169 1.1 thorpej for (; i < IEEE80211_WEP_NKID; i++)
170 1.1 thorpej nwkey.i_key[i].i_keylen = 0;
171 1.1 thorpej (void)strncpy(nwkey.i_name, name, sizeof(nwkey.i_name));
172 1.1 thorpej if (ioctl(s, SIOCS80211NWKEY, &nwkey) == -1)
173 1.1 thorpej warn("SIOCS80211NWKEY");
174 1.1 thorpej }
175 1.1 thorpej
176 1.1 thorpej void
177 1.1 thorpej setifpowersave(const char *val, int d)
178 1.1 thorpej {
179 1.1 thorpej struct ieee80211_power power;
180 1.1 thorpej
181 1.1 thorpej (void)strncpy(power.i_name, name, sizeof(power.i_name));
182 1.1 thorpej if (ioctl(s, SIOCG80211POWER, &power) == -1) {
183 1.1 thorpej warn("SIOCG80211POWER");
184 1.1 thorpej return;
185 1.1 thorpej }
186 1.1 thorpej
187 1.1 thorpej power.i_enabled = d;
188 1.1 thorpej if (ioctl(s, SIOCS80211POWER, &power) == -1)
189 1.1 thorpej warn("SIOCS80211POWER");
190 1.1 thorpej }
191 1.1 thorpej
192 1.1 thorpej void
193 1.1 thorpej setifpowersavesleep(const char *val, int d)
194 1.1 thorpej {
195 1.1 thorpej struct ieee80211_power power;
196 1.1 thorpej
197 1.1 thorpej (void)strncpy(power.i_name, name, sizeof(power.i_name));
198 1.1 thorpej if (ioctl(s, SIOCG80211POWER, &power) == -1) {
199 1.1 thorpej warn("SIOCG80211POWER");
200 1.1 thorpej return;
201 1.1 thorpej }
202 1.1 thorpej
203 1.1 thorpej power.i_maxsleep = atoi(val);
204 1.1 thorpej if (ioctl(s, SIOCS80211POWER, &power) == -1)
205 1.1 thorpej warn("SIOCS80211POWER");
206 1.1 thorpej }
207 1.1 thorpej
208 1.1 thorpej void
209 1.1 thorpej ieee80211_statistics(void)
210 1.1 thorpej {
211 1.1 thorpej struct ieee80211_stats stats;
212 1.1 thorpej
213 1.1 thorpej memset(&ifr, 0, sizeof(ifr));
214 1.3 dyoung ifr.ifr_buflen = sizeof(stats);
215 1.3 dyoung ifr.ifr_buf = (caddr_t)&stats;
216 1.1 thorpej (void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
217 1.1 thorpej if (ioctl(s, (zflag) ? SIOCG80211ZSTATS : SIOCG80211STATS,
218 1.1 thorpej (caddr_t)&ifr) == -1)
219 1.1 thorpej return;
220 1.2 dyoung #define STAT_PRINT(_member, _desc) \
221 1.2 dyoung printf("\t" _desc ": %" PRIu32 "\n", stats._member)
222 1.1 thorpej
223 1.2 dyoung STAT_PRINT(is_rx_badversion, "rx frame with bad version");
224 1.2 dyoung STAT_PRINT(is_rx_tooshort, "rx frame too short");
225 1.2 dyoung STAT_PRINT(is_rx_wrongbss, "rx from wrong bssid");
226 1.2 dyoung STAT_PRINT(is_rx_dup, "rx discard 'cuz dup");
227 1.2 dyoung STAT_PRINT(is_rx_wrongdir, "rx w/ wrong direction");
228 1.2 dyoung STAT_PRINT(is_rx_mcastecho, "rx discard 'cuz mcast echo");
229 1.2 dyoung STAT_PRINT(is_rx_notassoc, "rx discard 'cuz sta !assoc");
230 1.2 dyoung STAT_PRINT(is_rx_noprivacy, "rx w/ wep but privacy off");
231 1.2 dyoung STAT_PRINT(is_rx_unencrypted, "rx w/o wep and privacy on");
232 1.2 dyoung STAT_PRINT(is_rx_wepfail, "rx wep processing failed");
233 1.2 dyoung STAT_PRINT(is_rx_decap, "rx decapsulation failed");
234 1.2 dyoung STAT_PRINT(is_rx_mgtdiscard, "rx discard mgt frames");
235 1.2 dyoung STAT_PRINT(is_rx_ctl, "rx discard ctrl frames");
236 1.2 dyoung STAT_PRINT(is_rx_beacon, "rx beacon frames");
237 1.2 dyoung STAT_PRINT(is_rx_rstoobig, "rx rate set truncated");
238 1.2 dyoung STAT_PRINT(is_rx_elem_missing, "rx required element missin");
239 1.2 dyoung STAT_PRINT(is_rx_elem_toobig, "rx element too big");
240 1.2 dyoung STAT_PRINT(is_rx_elem_toosmall, "rx element too small");
241 1.2 dyoung STAT_PRINT(is_rx_elem_unknown, "rx element unknown");
242 1.2 dyoung STAT_PRINT(is_rx_badchan, "rx frame w/ invalid chan");
243 1.2 dyoung STAT_PRINT(is_rx_chanmismatch, "rx frame chan mismatch");
244 1.2 dyoung STAT_PRINT(is_rx_nodealloc, "rx frame dropped");
245 1.2 dyoung STAT_PRINT(is_rx_ssidmismatch, "rx frame ssid mismatch ");
246 1.2 dyoung STAT_PRINT(is_rx_auth_unsupported, "rx w/ unsupported auth alg");
247 1.2 dyoung STAT_PRINT(is_rx_auth_fail, "rx sta auth failure");
248 1.2 dyoung STAT_PRINT(is_rx_auth_countermeasures, "rx auth discard 'cuz CM");
249 1.2 dyoung STAT_PRINT(is_rx_assoc_bss, "rx assoc from wrong bssid");
250 1.2 dyoung STAT_PRINT(is_rx_assoc_notauth, "rx assoc w/o auth");
251 1.2 dyoung STAT_PRINT(is_rx_assoc_capmismatch, "rx assoc w/ cap mismatch");
252 1.2 dyoung STAT_PRINT(is_rx_assoc_norate, "rx assoc w/ no rate match");
253 1.2 dyoung STAT_PRINT(is_rx_assoc_badwpaie, "rx assoc w/ bad WPA IE");
254 1.2 dyoung STAT_PRINT(is_rx_deauth, "rx deauthentication");
255 1.2 dyoung STAT_PRINT(is_rx_disassoc, "rx disassociation");
256 1.2 dyoung STAT_PRINT(is_rx_badsubtype, "rx frame w/ unknown subtyp");
257 1.2 dyoung STAT_PRINT(is_rx_nobuf, "rx failed for lack of buf");
258 1.2 dyoung STAT_PRINT(is_rx_decryptcrc, "rx decrypt failed on crc");
259 1.2 dyoung STAT_PRINT(is_rx_ahdemo_mgt, "rx discard ahdemo mgt fram");
260 1.2 dyoung STAT_PRINT(is_rx_bad_auth, "rx bad auth request");
261 1.2 dyoung STAT_PRINT(is_rx_unauth, "rx on unauthorized port");
262 1.2 dyoung STAT_PRINT(is_rx_badkeyid, "rx w/ incorrect keyid");
263 1.2 dyoung STAT_PRINT(is_rx_ccmpreplay, "rx seq# violation (CCMP)");
264 1.2 dyoung STAT_PRINT(is_rx_ccmpformat, "rx format bad (CCMP)");
265 1.2 dyoung STAT_PRINT(is_rx_ccmpmic, "rx MIC check failed (CCMP)");
266 1.2 dyoung STAT_PRINT(is_rx_tkipreplay, "rx seq# violation (TKIP)");
267 1.2 dyoung STAT_PRINT(is_rx_tkipformat, "rx format bad (TKIP)");
268 1.2 dyoung STAT_PRINT(is_rx_tkipmic, "rx MIC check failed (TKIP)");
269 1.2 dyoung STAT_PRINT(is_rx_tkipicv, "rx ICV check failed (TKIP)");
270 1.2 dyoung STAT_PRINT(is_rx_badcipher, "rx failed 'cuz key type");
271 1.2 dyoung STAT_PRINT(is_rx_nocipherctx, "rx failed 'cuz key !setup");
272 1.2 dyoung STAT_PRINT(is_rx_acl, "rx discard 'cuz acl policy");
273 1.2 dyoung
274 1.2 dyoung STAT_PRINT(is_tx_nobuf, "tx failed for lack of buf");
275 1.2 dyoung STAT_PRINT(is_tx_nonode, "tx failed for no node");
276 1.2 dyoung STAT_PRINT(is_tx_unknownmgt, "tx of unknown mgt frame");
277 1.2 dyoung STAT_PRINT(is_tx_badcipher, "tx failed 'cuz key type");
278 1.2 dyoung STAT_PRINT(is_tx_nodefkey, "tx failed 'cuz no defkey");
279 1.2 dyoung STAT_PRINT(is_tx_noheadroom, "tx failed 'cuz no space");
280 1.2 dyoung
281 1.2 dyoung STAT_PRINT(is_scan_active, "active scans started");
282 1.2 dyoung STAT_PRINT(is_scan_passive, "passive scans started");
283 1.2 dyoung STAT_PRINT(is_node_timeout, "nodes timed out inactivity");
284 1.2 dyoung STAT_PRINT(is_crypto_nomem, "no memory for crypto ctx");
285 1.2 dyoung STAT_PRINT(is_crypto_tkip, "tkip crypto done in s/w");
286 1.2 dyoung STAT_PRINT(is_crypto_tkipenmic, "tkip en-MIC done in s/w");
287 1.2 dyoung STAT_PRINT(is_crypto_tkipdemic, "tkip de-MIC done in s/w");
288 1.2 dyoung STAT_PRINT(is_crypto_tkipcm, "tkip counter measures");
289 1.2 dyoung STAT_PRINT(is_crypto_ccmp, "ccmp crypto done in s/w");
290 1.2 dyoung STAT_PRINT(is_crypto_wep, "wep crypto done in s/w");
291 1.2 dyoung STAT_PRINT(is_crypto_setkey_cipher, "cipher rejected key");
292 1.2 dyoung STAT_PRINT(is_crypto_setkey_nokey, "no key index for setkey");
293 1.2 dyoung STAT_PRINT(is_crypto_delkey, "driver key delete failed");
294 1.2 dyoung STAT_PRINT(is_crypto_badcipher, "unknown cipher");
295 1.2 dyoung STAT_PRINT(is_crypto_nocipher, "cipher not available");
296 1.2 dyoung STAT_PRINT(is_crypto_attachfail, "cipher attach failed");
297 1.2 dyoung STAT_PRINT(is_crypto_swfallback, "cipher fallback to s/w");
298 1.2 dyoung STAT_PRINT(is_crypto_keyfail, "driver key alloc failed");
299 1.2 dyoung STAT_PRINT(is_crypto_enmicfail, "en-MIC failed");
300 1.2 dyoung STAT_PRINT(is_ibss_capmismatch, "merge failed-cap mismatch");
301 1.2 dyoung STAT_PRINT(is_ibss_norate, "merge failed-rate mismatch");
302 1.2 dyoung STAT_PRINT(is_ps_unassoc, "ps-poll for unassoc. sta");
303 1.2 dyoung STAT_PRINT(is_ps_badaid, "ps-poll w/ incorrect aid");
304 1.2 dyoung STAT_PRINT(is_ps_qempty, "ps-poll w/ nothing to send");
305 1.1 thorpej }
306 1.1 thorpej
307 1.1 thorpej void
308 1.1 thorpej ieee80211_status(void)
309 1.1 thorpej {
310 1.1 thorpej int i, nwkey_verbose;
311 1.1 thorpej struct ieee80211_nwid nwid;
312 1.1 thorpej struct ieee80211_nwkey nwkey;
313 1.1 thorpej struct ieee80211_power power;
314 1.1 thorpej u_int8_t keybuf[IEEE80211_WEP_NKID][16];
315 1.1 thorpej struct ieee80211_bssid bssid;
316 1.1 thorpej struct ieee80211chanreq channel;
317 1.1 thorpej struct ether_addr ea;
318 1.1 thorpej static const u_int8_t zero_macaddr[IEEE80211_ADDR_LEN];
319 1.1 thorpej
320 1.1 thorpej memset(&ifr, 0, sizeof(ifr));
321 1.1 thorpej ifr.ifr_data = (void *)&nwid;
322 1.1 thorpej (void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
323 1.1 thorpej if (ioctl(s, SIOCG80211NWID, &ifr) == -1)
324 1.1 thorpej return;
325 1.1 thorpej if (nwid.i_len > IEEE80211_NWID_LEN) {
326 1.1 thorpej warnx("SIOCG80211NWID: wrong length of nwid (%d)", nwid.i_len);
327 1.1 thorpej return;
328 1.1 thorpej }
329 1.1 thorpej printf("\tssid ");
330 1.1 thorpej print_string(nwid.i_nwid, nwid.i_len);
331 1.1 thorpej memset(&nwkey, 0, sizeof(nwkey));
332 1.1 thorpej (void)strncpy(nwkey.i_name, name, sizeof(nwkey.i_name));
333 1.1 thorpej /* show nwkey only when WEP is enabled */
334 1.1 thorpej if (ioctl(s, SIOCG80211NWKEY, &nwkey) == -1 ||
335 1.1 thorpej nwkey.i_wepon == 0) {
336 1.1 thorpej printf("\n");
337 1.1 thorpej goto skip_wep;
338 1.1 thorpej }
339 1.1 thorpej
340 1.1 thorpej printf(" nwkey ");
341 1.1 thorpej /* try to retrieve WEP keys */
342 1.1 thorpej for (i = 0; i < IEEE80211_WEP_NKID; i++) {
343 1.1 thorpej nwkey.i_key[i].i_keydat = keybuf[i];
344 1.1 thorpej nwkey.i_key[i].i_keylen = sizeof(keybuf[i]);
345 1.1 thorpej }
346 1.1 thorpej if (ioctl(s, SIOCG80211NWKEY, &nwkey) == -1) {
347 1.1 thorpej printf("*****");
348 1.1 thorpej } else {
349 1.1 thorpej nwkey_verbose = 0;
350 1.1 thorpej /* check to see non default key or multiple keys defined */
351 1.1 thorpej if (nwkey.i_defkid != 1) {
352 1.1 thorpej nwkey_verbose = 1;
353 1.1 thorpej } else {
354 1.1 thorpej for (i = 1; i < IEEE80211_WEP_NKID; i++) {
355 1.1 thorpej if (nwkey.i_key[i].i_keylen != 0) {
356 1.1 thorpej nwkey_verbose = 1;
357 1.1 thorpej break;
358 1.1 thorpej }
359 1.1 thorpej }
360 1.1 thorpej }
361 1.1 thorpej /* check extra ambiguity with keywords */
362 1.1 thorpej if (!nwkey_verbose) {
363 1.1 thorpej if (nwkey.i_key[0].i_keylen >= 2 &&
364 1.1 thorpej isdigit(nwkey.i_key[0].i_keydat[0]) &&
365 1.1 thorpej nwkey.i_key[0].i_keydat[1] == ':')
366 1.1 thorpej nwkey_verbose = 1;
367 1.1 thorpej else if (nwkey.i_key[0].i_keylen >= 7 &&
368 1.1 thorpej strncasecmp("persist", nwkey.i_key[0].i_keydat, 7)
369 1.1 thorpej == 0)
370 1.1 thorpej nwkey_verbose = 1;
371 1.1 thorpej }
372 1.1 thorpej if (nwkey_verbose)
373 1.1 thorpej printf("%d:", nwkey.i_defkid);
374 1.1 thorpej for (i = 0; i < IEEE80211_WEP_NKID; i++) {
375 1.1 thorpej if (i > 0)
376 1.1 thorpej printf(",");
377 1.1 thorpej if (nwkey.i_key[i].i_keylen < 0)
378 1.1 thorpej printf("persist");
379 1.1 thorpej else
380 1.1 thorpej print_string(nwkey.i_key[i].i_keydat,
381 1.1 thorpej nwkey.i_key[i].i_keylen);
382 1.1 thorpej if (!nwkey_verbose)
383 1.1 thorpej break;
384 1.1 thorpej }
385 1.1 thorpej }
386 1.1 thorpej printf("\n");
387 1.1 thorpej
388 1.1 thorpej skip_wep:
389 1.1 thorpej (void)strncpy(power.i_name, name, sizeof(power.i_name));
390 1.1 thorpej if (ioctl(s, SIOCG80211POWER, &power) == -1)
391 1.1 thorpej goto skip_power;
392 1.1 thorpej printf("\tpowersave ");
393 1.1 thorpej if (power.i_enabled)
394 1.1 thorpej printf("on (%dms sleep)", power.i_maxsleep);
395 1.1 thorpej else
396 1.1 thorpej printf("off");
397 1.1 thorpej printf("\n");
398 1.1 thorpej
399 1.1 thorpej skip_power:
400 1.1 thorpej (void)strncpy(bssid.i_name, name, sizeof(bssid.i_name));
401 1.1 thorpej if (ioctl(s, SIOCG80211BSSID, &bssid) == -1)
402 1.1 thorpej return;
403 1.1 thorpej (void)strncpy(channel.i_name, name, sizeof(channel.i_name));
404 1.1 thorpej if (ioctl(s, SIOCG80211CHANNEL, &channel) == -1)
405 1.1 thorpej return;
406 1.1 thorpej if (memcmp(bssid.i_bssid, zero_macaddr, IEEE80211_ADDR_LEN) == 0) {
407 1.1 thorpej if (channel.i_channel != (u_int16_t)-1)
408 1.1 thorpej printf("\tchan %d\n", channel.i_channel);
409 1.1 thorpej } else {
410 1.1 thorpej memcpy(ea.ether_addr_octet, bssid.i_bssid,
411 1.1 thorpej sizeof(ea.ether_addr_octet));
412 1.1 thorpej printf("\tbssid %s", ether_ntoa(&ea));
413 1.1 thorpej if (channel.i_channel != IEEE80211_CHAN_ANY)
414 1.1 thorpej printf(" chan %d", channel.i_channel);
415 1.1 thorpej printf("\n");
416 1.1 thorpej }
417 1.1 thorpej }
418