xref: /freebsd/sys/net80211/ieee80211_ddb.c (revision b032f27c)
1 /*-
2  * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
28 
29 #include "opt_ddb.h"
30 #include "opt_wlan.h"
31 
32 #ifdef DDB
33 /*
34  * IEEE 802.11 DDB support
35  */
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 
40 #include <sys/socket.h>
41 
42 #include <net/if.h>
43 #include <net/if_dl.h>
44 #include <net/if_media.h>
45 #include <net/if_types.h>
46 #include <net/ethernet.h>
47 
48 #include <net80211/ieee80211_var.h>
49 
50 #include <ddb/ddb.h>
51 
52 #define	IEEE80211_MSG_BITS \
53 	"\20\3IOCTL\4WDS\5ACTION\6RATECTL\7ROAM\10INACT\11DOTH\12SUPERG" \
54 	"\13WME\14ACL\15WPA\16RADKEYS\17RADDUMP\20RADIUS\21DOT1X\22POWER" \
55 	"\23STATE\24OUTPUT\25SCAN\26AUTH\27ASSOC\30NODE\31ELEMID\32XRATE" \
56 	"\33INPUT\34CRYPTO\35DUPMPKTS\36DEBUG\3711N"
57 
58 #define	IEEE80211_F_BITS \
59 	"\20\1TURBOP\2COMP\3FF\4BURST\5PRIVACY\6PUREG\10SCAN\11ASCAN\12SIBSS" \
60 	"\13SHSLOT\14PMGTON\15DESBSSID\16WME\17BGSCAN\20SWRETRY\21TXPOW_FIXED" \
61 	"\22IBSSON\23SHPREAMBLE\24DATAPAD\25USEPROT\26USERBARKER\27CSAPENDING" \
62 	"\30WPA1\31WPA2\32DROPUNENC\33COUNTERM\34HIDESSID\35NOBRIDG\36PCF" \
63 	"\37DOTH\40DWDS"
64 
65 #define	IEEE80211_FEXT_BITS \
66 	"\20\1NONHT_PR\2INACT\3SCANWAIT\4BGSCAN\5WPS\6TSN\7SCANREQ\12NONEPR_PR"\
67 	"\13SWBMISS\14DFS\15DOTD\22WDSLEGACY\23PROBECHAN\24HT\25AMDPU_TX" \
68 	"\26AMPDU_TX\27AMSDU_TX\30AMSDU_RX\31USEHT40\32PUREN\33SHORTGI20" \
69 	"\34SHORTGI40\35HTCOMPAT"
70 
71 #define	IEEE80211_FVEN_BITS	"\20"
72 
73 #define	IEEE80211_C_BITS \
74 	"\20\7FF\10TURBOP\11IBSS\12PMGT" \
75 	"\13HOSTAP\14AHDEMO\15SWRETRY\16TXPMGT\17SHSLOT\20SHPREAMBLE" \
76 	"\21MONITOR\30WPA1\31WPA2\32BURST\33WME\34WDS\36BGSCAN" \
77 	"\37TXFRAG"
78 
79 #define	IEEE80211_C_CRYPTO_BITS \
80 	"\20\1WEP\2TKIP\3AES\4AES_CCM\5TKIPMIC\6CKIP\12PMGT"
81 
82 #define	IEEE80211_C_HTCAP_BITS \
83 	"\20\1LDPC\2CHWIDTH40\5GREENFIELD\6SHORTGI20\7SHORTGI40\10TXSTBC" \
84 	"\21AMPDU\22AMSDU\23HT"
85 
86 /* NB: policy bits not included */
87 #define	IEEE80211_CHAN_BITS \
88 	"\20\5TURBO\6CCK\7OFDM\0102GHZ\0115GHZ\12PASSIVE\13DYN\14GFSK" \
89 	"\15STURBO\16HALF\17QUARTER\20HT20\21HT40U\22HT40D\23DFS"
90 
91 #define	IEEE80211_NODE_BITS \
92 	"\20\1AUTH\2QOS\3ERP\5PWR_MGT\6AREF\7HT\10HTCOMPAT\11WPS\12TSN" \
93 	"\13AMPDU_RX\14AMPDU_TX"
94 
95 #define	IEEE80211_ERP_BITS \
96 	"\20\1NON_ERP_PRESENT\2USE_PROTECTION\3LONG_PREAMBLE"
97 
98 #define	IEEE80211_CAPINFO_BITS \
99 	"\20\1ESS\2IBSS\3CF_POLLABLE\4CF_POLLREQ\5PRIVACY\6SHORT_PREAMBLE" \
100 	"\7PBCC\10CHNL_AGILITY\11SPECTRUM_MGMT\13SHORT_SLOTTIME\14RSN" \
101 	"\16DSSOFDM"
102 
103 #define	IEEE80211_HTCAP_BITS \
104 	"\20\1LDPC\2CHWIDTH40\5GREENFIELD\6SHORTGI20\7SHORTGI40\10TXSTBC" \
105 	"\13DELBA\14AMSDU(7935)\15DSSSCCK40\16PSMP\1740INTOLERANT" \
106 	"\20LSIGTXOPPROT"
107 
108 #define	IEEE80211_AGGR_BITS \
109 	"\20\1IMMEDIATE\2XCHGPEND\3RUNNING\4SETUP\5NAK"
110 
111 static void _db_show_sta(const struct ieee80211_node *);
112 static void _db_show_vap(const struct ieee80211vap *, int);
113 static void _db_show_com(const struct ieee80211com *,
114 	int showvaps, int showsta, int showprocs);
115 
116 static void _db_show_channel(const char *tag, const struct ieee80211_channel *);
117 static void _db_show_ssid(const char *tag, int ix, int len, const uint8_t *);
118 static void _db_show_appie(const char *tag, const struct ieee80211_appie *);
119 static void _db_show_key(const char *tag, int ix, const struct ieee80211_key *);
120 static void _db_show_roamparams(const char *tag, const void *arg,
121 	const struct ieee80211_roamparam *rp);
122 static void _db_show_txparams(const char *tag, const void *arg,
123 	const struct ieee80211_txparam *tp);
124 static void _db_show_stats(const struct ieee80211_stats *);
125 
126 DB_SHOW_COMMAND(sta, db_show_sta)
127 {
128 	if (!have_addr) {
129 		db_printf("usage: show sta <addr>\n");
130 		return;
131 	}
132 	_db_show_sta((const struct ieee80211_node *) addr);
133 }
134 
135 DB_SHOW_COMMAND(vap, db_show_vap)
136 {
137 	int i, showprocs = 0;
138 
139 	if (!have_addr) {
140 		db_printf("usage: show vap <addr>\n");
141 		return;
142 	}
143 	for (i = 0; modif[i] != '\0'; i++)
144 		switch (modif[i]) {
145 		case 'a':
146 			showprocs = 1;
147 			break;
148 		case 'p':
149 			showprocs = 1;
150 			break;
151 		}
152 	_db_show_vap((const struct ieee80211vap *) addr, showprocs);
153 }
154 
155 DB_SHOW_COMMAND(com, db_show_com)
156 {
157 	const struct ieee80211com *ic;
158 	int i, showprocs = 0, showvaps = 0, showsta = 0;
159 
160 	if (!have_addr) {
161 		db_printf("usage: show com <addr>\n");
162 		return;
163 	}
164 	for (i = 0; modif[i] != '\0'; i++)
165 		switch (modif[i]) {
166 		case 'a':
167 			showsta = showvaps = showprocs = 1;
168 			break;
169 		case 's':
170 			showsta = 1;
171 			break;
172 		case 'v':
173 			showvaps = 1;
174 			break;
175 		case 'p':
176 			showprocs = 1;
177 			break;
178 		}
179 
180 	ic = (const struct ieee80211com *) addr;
181 	_db_show_com(ic, showvaps, showsta, showprocs);
182 }
183 
184 DB_SHOW_ALL_COMMAND(vaps, db_show_all_vaps)
185 {
186 	const struct ifnet *ifp;
187 	int i, showall = 0;
188 
189 	for (i = 0; modif[i] != '\0'; i++)
190 		switch (modif[i]) {
191 		case 'a':
192 			showall = 1;
193 			break;
194 		}
195 
196 	TAILQ_FOREACH(ifp, &ifnet, if_list)
197 		if (ifp->if_type == IFT_IEEE80211) {
198 			const struct ieee80211com *ic = ifp->if_l2com;
199 
200 			if (!showall) {
201 				const struct ieee80211vap *vap;
202 				db_printf("%s: com %p vaps:",
203 				    ifp->if_xname, ic);
204 				TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
205 					db_printf(" %s(%p)",
206 					    vap->iv_ifp->if_xname, vap);
207 				db_printf("\n");
208 			} else
209 				_db_show_com(ic, 1, 1, 1);
210 		}
211 }
212 
213 static void
214 _db_show_txampdu(const char *sep, int ix, const struct ieee80211_tx_ampdu *tap)
215 {
216 	db_printf("%stxampdu[%d]: %p flags %b ac %u\n",
217 		sep, ix, tap, tap->txa_flags, IEEE80211_AGGR_BITS, tap->txa_ac);
218 	db_printf("%s  token %u qbytes %d qframes %d seqstart %u start %u wnd %u\n",
219 		sep, tap->txa_token, tap->txa_qbytes, tap->txa_qframes,
220 		tap->txa_seqstart, tap->txa_start, tap->txa_wnd);
221 	db_printf("%s  attempts %d nextrequest %d\n",
222 		sep, tap->txa_attempts, tap->txa_nextrequest);
223 	/* XXX packet q + timer */
224 }
225 
226 static void
227 _db_show_rxampdu(const char *sep, int ix, const struct ieee80211_rx_ampdu *rap)
228 {
229 	db_printf("%srxampdu[%d]: %p flags 0x%x tid %u\n",
230 		sep, ix, rap, rap->rxa_flags, ix /*XXX */);
231 	db_printf("%s  qbytes %d qframes %d seqstart %u start %u wnd %u\n",
232 		sep, rap->rxa_qbytes, rap->rxa_qframes,
233 		rap->rxa_seqstart, rap->rxa_start, rap->rxa_wnd);
234 	db_printf("%s  age %d nframes %d\n",
235 		sep, rap->rxa_age, rap->rxa_nframes);
236 }
237 
238 static void
239 _db_show_sta(const struct ieee80211_node *ni)
240 {
241 	int i;
242 
243 	db_printf("0x%p: mac %s refcnt %d\n", ni,
244 		ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni));
245 	db_printf("\tvap %p wdsvap %p ic %p table %p\n",
246 		ni->ni_vap, ni->ni_wdsvap, ni->ni_ic, ni->ni_table);
247 	db_printf("\tflags=%b\n", ni->ni_flags, IEEE80211_NODE_BITS);
248 	db_printf("\tscangen %u authmode %u ath_flags 0x%x ath_defkeyix %u\n",
249 		ni->ni_scangen, ni->ni_authmode,
250 		ni->ni_ath_flags, ni->ni_ath_defkeyix);
251 	db_printf("\tassocid 0x%x txpower %u vlan %u\n",
252 		ni->ni_associd, ni->ni_txpower, ni->ni_vlan);
253 	db_printf("\tjointime %d (%lu secs) challenge %p\n",
254 		ni->ni_jointime, (unsigned long)(time_uptime - ni->ni_jointime),
255 		ni->ni_challenge);
256 	db_printf("\ties: data %p len %d\n", ni->ni_ies.data, ni->ni_ies.len);
257 	db_printf("\t[wpa_ie %p rsn_ie %p wme_ie %p ath_ie %p\n",
258 		ni->ni_ies.wpa_ie, ni->ni_ies.rsn_ie, ni->ni_ies.wme_ie,
259 		ni->ni_ies.ath_ie);
260 	db_printf("\t htcap_ie %p htinfo_ie %p]\n",
261 		ni->ni_ies.htcap_ie, ni->ni_ies.htinfo_ie);
262 	db_printf("\ttxseq %u rxseq %u fragno %u rxfragstamp %u\n",
263 		ni->ni_txseqs[IEEE80211_NONQOS_TID],
264 		ni->ni_rxseqs[IEEE80211_NONQOS_TID] >> IEEE80211_SEQ_SEQ_SHIFT,
265 		ni->ni_rxseqs[IEEE80211_NONQOS_TID] & IEEE80211_SEQ_FRAG_MASK,
266 		ni->ni_rxfragstamp);
267 	db_printf("\trxfrag[0] %p rxfrag[1] %p rxfrag[2] %p\n",
268 		ni->ni_rxfrag[0], ni->ni_rxfrag[1], ni->ni_rxfrag[2]);
269 	db_printf("\trstamp %u avgrssi 0x%x (rssi %d) noise %d\n",
270 		ni->ni_rstamp, ni->ni_avgrssi,
271 		IEEE80211_RSSI_GET(ni->ni_avgrssi), ni->ni_noise);
272 	db_printf("\tintval %u capinfo %b\n",
273 		ni->ni_intval, ni->ni_capinfo, IEEE80211_CAPINFO_BITS);
274 	db_printf("\tbssid %s", ether_sprintf(ni->ni_bssid));
275 	_db_show_ssid(" essid ", 0, ni->ni_esslen, ni->ni_essid);
276 	db_printf("\n");
277 	_db_show_channel("\tchannel", ni->ni_chan);
278 	db_printf("\n");
279 	db_printf("\terp %b dtim_period %u dtim_count %u\n",
280 		ni->ni_erp, IEEE80211_ERP_BITS,
281 		ni->ni_dtim_period, ni->ni_dtim_count);
282 
283 	db_printf("\thtcap %b htparam 0x%x htctlchan %u ht2ndchan %u\n",
284 		ni->ni_htcap, IEEE80211_HTCAP_BITS,
285 		ni->ni_htparam, ni->ni_htctlchan, ni->ni_ht2ndchan);
286 	db_printf("\thtopmode 0x%x htstbc 0x%x reqcw %u chw %u\n",
287 		ni->ni_htopmode, ni->ni_htstbc, ni->ni_reqcw, ni->ni_chw);
288 
289 	/* XXX ampdu state */
290 	for (i = 0; i < WME_NUM_AC; i++)
291 		if (ni->ni_tx_ampdu[i].txa_flags & IEEE80211_AGGR_SETUP)
292 			_db_show_txampdu("\t", i, &ni->ni_tx_ampdu[i]);
293 	for (i = 0; i < WME_NUM_TID; i++)
294 		if (ni->ni_rx_ampdu[i].rxa_nframes)
295 			_db_show_rxampdu("\t", i, &ni->ni_rx_ampdu[i]);
296 
297 	db_printf("\tinact %u inact_reload %u txrate %u\n",
298 		ni->ni_inact, ni->ni_inact_reload, ni->ni_txrate);
299 	/* XXX savedq */
300 	/* XXX wdsq */
301 }
302 
303 static void
304 _db_show_vap(const struct ieee80211vap *vap, int showprocs)
305 {
306 	const struct ieee80211com *ic = vap->iv_ic;
307 	int i;
308 
309 	db_printf("%p:", vap);
310 	db_printf(" bss %p", vap->iv_bss);
311 	db_printf(" myaddr %s", ether_sprintf(vap->iv_myaddr));
312 	db_printf("\n");
313 
314 	db_printf("\topmode %s", ieee80211_opmode_name[vap->iv_opmode]);
315 	db_printf(" state %s", ieee80211_state_name[vap->iv_state]);
316 	db_printf(" ifp %p", vap->iv_ifp);
317 	db_printf("\n");
318 
319 	db_printf("\tic %p", vap->iv_ic);
320 	db_printf(" media %p", &vap->iv_media);
321 	db_printf(" bpf_if %p", vap->iv_rawbpf);
322 	db_printf(" mgtsend %p", &vap->iv_mgtsend);
323 #if 0
324 	struct sysctllog	*iv_sysctl;	/* dynamic sysctl context */
325 #endif
326 	db_printf("\n");
327 	db_printf("\tdebug=%b\n", vap->iv_debug, IEEE80211_MSG_BITS);
328 
329 	db_printf("\tflags=%b\n", vap->iv_flags, IEEE80211_F_BITS);
330 	db_printf("\tflags_ext=%b\n", vap->iv_flags_ext, IEEE80211_FEXT_BITS);
331 	db_printf("\tflags_ven=%b\n", vap->iv_flags_ven, IEEE80211_FVEN_BITS);
332 	db_printf("\tcaps=%b\n", vap->iv_caps, IEEE80211_C_BITS);
333 	db_printf("\thtcaps=%b\n", vap->iv_htcaps, IEEE80211_C_HTCAP_BITS);
334 
335 	_db_show_stats(&vap->iv_stats);
336 
337 	db_printf("\tinact_init %d", vap->iv_inact_init);
338 	db_printf(" inact_auth %d", vap->iv_inact_auth);
339 	db_printf(" inact_run %d", vap->iv_inact_run);
340 	db_printf(" inact_probe %d", vap->iv_inact_probe);
341 	db_printf("\n");
342 
343 	db_printf("\tdes_nssid %d", vap->iv_des_nssid);
344 	if (vap->iv_des_nssid)
345 		_db_show_ssid(" des_ssid[%u] ", 0,
346 		    vap->iv_des_ssid[0].len, vap->iv_des_ssid[0].ssid);
347 	db_printf(" des_bssid %s", ether_sprintf(vap->iv_des_bssid));
348 	db_printf("\n");
349 	db_printf("\tdes_mode %d", vap->iv_des_mode);
350 	_db_show_channel(" des_chan", vap->iv_des_chan);
351 	db_printf("\n");
352 #if 0
353 	int			iv_nicknamelen;	/* XXX junk */
354 	uint8_t			iv_nickname[IEEE80211_NWID_LEN];
355 #endif
356 	db_printf("\tbgscanidle %u", vap->iv_bgscanidle);
357 	db_printf(" bgscanintvl %u", vap->iv_bgscanintvl);
358 	db_printf(" scanvalid %u", vap->iv_scanvalid);
359 	db_printf("\n");
360 	db_printf("\tscanreq_duration %u", vap->iv_scanreq_duration);
361 	db_printf(" scanreq_mindwell %u", vap->iv_scanreq_mindwell);
362 	db_printf(" scanreq_maxdwell %u", vap->iv_scanreq_maxdwell);
363 	db_printf("\n");
364 	db_printf(" scanreq_flags 0x%x", vap->iv_scanreq_flags);
365 	db_printf("\tscanreq_nssid %d", vap->iv_scanreq_nssid);
366 	for (i = 0; i < vap->iv_scanreq_nssid; i++)
367 		_db_show_ssid(" scanreq_ssid[%u]", i,
368 		    vap->iv_scanreq_ssid[i].len, vap->iv_scanreq_ssid[i].ssid);
369 	db_printf(" roaming %d", vap->iv_roaming);
370 	db_printf("\n");
371 	for (i = IEEE80211_MODE_11A; i < IEEE80211_MODE_MAX; i++)
372 		if (isset(ic->ic_modecaps, i)) {
373 			_db_show_roamparams("\troamparms[%s]",
374 			    ieee80211_phymode_name[i], &vap->iv_roamparms[i]);
375 			db_printf("\n");
376 		}
377 
378 	db_printf("\tbmissthreshold %u", vap->iv_bmissthreshold);
379 	db_printf(" bmiss_max %u", vap->iv_bmiss_count);
380 	db_printf(" bmiss_max %d", vap->iv_bmiss_max);
381 	db_printf("\n");
382 	db_printf("\tswbmiss_count %u", vap->iv_swbmiss_count);
383 	db_printf(" swbmiss_period %u", vap->iv_swbmiss_period);
384 	db_printf(" swbmiss %p", &vap->iv_swbmiss);
385 	db_printf("\n");
386 
387 	db_printf("\tampdu_rxmax %d", vap->iv_ampdu_rxmax);
388 	db_printf(" ampdu_density %d", vap->iv_ampdu_density);
389 	db_printf(" ampdu_limit %d", vap->iv_ampdu_limit);
390 	db_printf(" amsdu_limit %d", vap->iv_amsdu_limit);
391 	db_printf("\n");
392 
393 	db_printf("\tmax_aid %u", vap->iv_max_aid);
394 	db_printf(" aid_bitmap %p", vap->iv_aid_bitmap);
395 	db_printf("\n");
396 	db_printf("\tsta_assoc %u", vap->iv_sta_assoc);
397 	db_printf(" ps_sta %u", vap->iv_ps_sta);
398 	db_printf(" ps_pending %u", vap->iv_ps_pending);
399 	db_printf(" tim_len %u", vap->iv_tim_len);
400 	db_printf(" tim_bitmap %p", vap->iv_tim_bitmap);
401 	db_printf("\n");
402 	db_printf("\tdtim_period %u", vap->iv_dtim_period);
403 	db_printf(" dtim_count %u", vap->iv_dtim_count);
404 	db_printf(" set_tim %p", vap->iv_set_tim);
405 	db_printf(" csa_count %d", vap->iv_csa_count);
406 	db_printf("\n");
407 
408 	db_printf("\trtsthreshold %u", vap->iv_rtsthreshold);
409 	db_printf(" fragthreshold %u", vap->iv_fragthreshold);
410 	db_printf(" inact_timer %d", vap->iv_inact_timer);
411 	db_printf("\n");
412 	for (i = IEEE80211_MODE_11A; i < IEEE80211_MODE_MAX; i++)
413 		if (isset(ic->ic_modecaps, i)) {
414 			_db_show_txparams("\ttxparms[%s]",
415 			    ieee80211_phymode_name[i], &vap->iv_txparms[i]);
416 			db_printf("\n");
417 		}
418 
419 	/* application-specified IE's to attach to mgt frames */
420 	_db_show_appie("\tappie_beacon", vap->iv_appie_beacon);
421 	_db_show_appie("\tappie_probereq", vap->iv_appie_probereq);
422 	_db_show_appie("\tappie_proberesp", vap->iv_appie_proberesp);
423 	_db_show_appie("\tappie_assocreq", vap->iv_appie_assocreq);
424 	_db_show_appie("\tappie_asscoresp", vap->iv_appie_assocresp);
425 	_db_show_appie("\tappie_wpa", vap->iv_appie_wpa);
426 	if (vap->iv_wpa_ie != NULL || vap->iv_rsn_ie != NULL) {
427 		if (vap->iv_wpa_ie != NULL)
428 			db_printf("\twpa_ie %p", vap->iv_wpa_ie);
429 		if (vap->iv_rsn_ie != NULL)
430 			db_printf("\trsn_ie %p", vap->iv_rsn_ie);
431 		db_printf("\n");
432 	}
433 	db_printf("\tmax_keyix %u", vap->iv_max_keyix);
434 	db_printf(" def_txkey %d", vap->iv_def_txkey);
435 	db_printf("\n");
436 	for (i = 0; i < IEEE80211_WEP_NKID; i++)
437 		_db_show_key("\tnw_keys[%u]", i, &vap->iv_nw_keys[i]);
438 
439 	db_printf("\tauth %p", vap->iv_auth);
440 	db_printf(" ec %p", vap->iv_ec);
441 
442 	db_printf(" acl %p", vap->iv_acl);
443 	db_printf(" as %p", vap->iv_as);
444 	db_printf("\n");
445 
446 	if (showprocs) {
447 		db_printf("\tiv_key_alloc %p\n", vap->iv_key_alloc);
448 		db_printf("\tiv_key_delete %p\n", vap->iv_key_delete);
449 		db_printf("\tiv_key_set %p\n", vap->iv_key_set);
450 		db_printf("\tiv_key_update_begin %p\n", vap->iv_key_update_begin);
451 		db_printf("\tiv_key_update_end %p\n", vap->iv_key_update_end);
452 		db_printf("\tiv_opdetach %p\n", vap->iv_opdetach);
453 		db_printf("\tiv_input %p\n", vap->iv_input);
454 		db_printf("\tiv_recv_mgmt %p\n", vap->iv_recv_mgmt);
455 		db_printf("\tiv_deliver_data %p\n", vap->iv_deliver_data);
456 		db_printf("\tiv_bmiss %p\n", vap->iv_bmiss);
457 		db_printf("\tiv_reset %p\n", vap->iv_reset);
458 		db_printf("\tiv_update_beacon %p\n", vap->iv_update_beacon);
459 		db_printf("\tiv_newstate %p\n", vap->iv_newstate);
460 		db_printf("\tiv_output %p\n", vap->iv_output);
461 	}
462 }
463 
464 static void
465 _db_show_com(const struct ieee80211com *ic, int showvaps, int showsta, int showprocs)
466 {
467 	struct ieee80211vap *vap;
468 
469 	db_printf("%p:", ic);
470 	TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
471 		db_printf(" %s(%p)", vap->iv_ifp->if_xname, vap);
472 	db_printf("\n");
473 	db_printf("\tifp %p", ic->ic_ifp);
474 	db_printf(" comlock %p", &ic->ic_comlock);
475 	db_printf("\n");
476 	_db_show_stats(&ic->ic_stats);
477 	db_printf("\theadroom %d", ic->ic_headroom);
478 	db_printf(" phytype %d", ic->ic_phytype);
479 	db_printf(" opmode %s", ieee80211_opmode_name[ic->ic_opmode]);
480 	db_printf("\n");
481 	db_printf("\tmedia %p", &ic->ic_media);
482 	db_printf(" myaddr %s", ether_sprintf(ic->ic_myaddr));
483 	db_printf(" inact %p", &ic->ic_inact);
484 	db_printf("\n");
485 
486 	db_printf("\tflags=%b\n", ic->ic_flags, IEEE80211_F_BITS);
487 	db_printf("\tflags_ext=%b\n", ic->ic_flags_ext, IEEE80211_FEXT_BITS);
488 	db_printf("\tflags_ven=%b\n", ic->ic_flags_ven, IEEE80211_FVEN_BITS);
489 	db_printf("\tcaps=%b\n", ic->ic_caps, IEEE80211_C_BITS);
490 	db_printf("\tcryptocaps=%b\n",
491 	    ic->ic_cryptocaps, IEEE80211_C_CRYPTO_BITS);
492 	db_printf("\thtcaps=%b\n", ic->ic_htcaps, IEEE80211_HTCAP_BITS);
493 
494 #if 0
495 	uint8_t			ic_modecaps[2];	/* set of mode capabilities */
496 #endif
497 	db_printf("\tcurmode %u", ic->ic_curmode);
498 	db_printf(" promisc %u", ic->ic_promisc);
499 	db_printf(" allmulti %u", ic->ic_allmulti);
500 	db_printf(" nrunning %u", ic->ic_nrunning);
501 	db_printf("\n");
502 	db_printf("\tbintval %u", ic->ic_bintval);
503 	db_printf(" lintval %u", ic->ic_lintval);
504 	db_printf(" holdover %u", ic->ic_holdover);
505 	db_printf(" txpowlimit %u", ic->ic_txpowlimit);
506 	db_printf("\n");
507 #if 0
508 	struct ieee80211_rateset ic_sup_rates[IEEE80211_MODE_MAX];
509 #endif
510 	/*
511 	 * Channel state:
512 	 *
513 	 * ic_channels is the set of available channels for the device;
514 	 *    it is setup by the driver
515 	 * ic_nchans is the number of valid entries in ic_channels
516 	 * ic_chan_avail is a bit vector of these channels used to check
517 	 *    whether a channel is available w/o searching the channel table.
518 	 * ic_chan_active is a (potentially) constrained subset of
519 	 *    ic_chan_avail that reflects any mode setting or user-specified
520 	 *    limit on the set of channels to use/scan
521 	 * ic_curchan is the current channel the device is set to; it may
522 	 *    be different from ic_bsschan when we are off-channel scanning
523 	 *    or otherwise doing background work
524 	 * ic_bsschan is the channel selected for operation; it may
525 	 *    be undefined (IEEE80211_CHAN_ANYC)
526 	 * ic_prevchan is a cached ``previous channel'' used to optimize
527 	 *    lookups when switching back+forth between two channels
528 	 *    (e.g. for dynamic turbo)
529 	 */
530 	db_printf("\tnchans %d", ic->ic_nchans);
531 #if 0
532 	struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX+1];
533 	uint8_t			ic_chan_avail[IEEE80211_CHAN_BYTES];
534 	uint8_t			ic_chan_active[IEEE80211_CHAN_BYTES];
535 	uint8_t			ic_chan_scan[IEEE80211_CHAN_BYTES];
536 #endif
537 	db_printf("\n");
538 	_db_show_channel("\tcurchan", ic->ic_curchan);
539 	db_printf("\n");
540 	_db_show_channel("\tbsschan", ic->ic_bsschan);
541 	db_printf("\n");
542 	_db_show_channel("\tprevchan", ic->ic_prevchan);
543 	db_printf("\n");
544 	db_printf("\tregdomain %p", &ic->ic_regdomain);
545 	db_printf("\n");
546 
547 	_db_show_channel("\tcsa_newchan", ic->ic_csa_newchan);
548 	db_printf(" csa_count %d", ic->ic_csa_count);
549 	db_printf( "dfs %p", &ic->ic_dfs);
550 	db_printf("\n");
551 
552 	db_printf("\tscan %p", ic->ic_scan);
553 	db_printf(" lastdata %d", ic->ic_lastdata);
554 	db_printf(" lastscan %d", ic->ic_lastscan);
555 	db_printf("\n");
556 
557 	db_printf("\tmax_keyix %d", ic->ic_max_keyix);
558 	db_printf(" sta %p", &ic->ic_sta);
559 	db_printf(" wme %p", &ic->ic_wme);
560 	db_printf("\n");
561 
562 	db_printf("\tprotmode %d", ic->ic_protmode);
563 	db_printf(" nonerpsta %u", ic->ic_nonerpsta);
564 	db_printf(" longslotsta %u", ic->ic_longslotsta);
565 	db_printf(" lastnonerp %d", ic->ic_lastnonerp);
566 	db_printf("\n");
567 	db_printf("\tsta_assoc %u", ic->ic_sta_assoc);
568 	db_printf(" ht_sta_assoc %u", ic->ic_ht_sta_assoc);
569 	db_printf(" ht40_sta_assoc %u", ic->ic_ht40_sta_assoc);
570 	db_printf("\n");
571 	db_printf("\tcurhtprotmode 0x%x", ic->ic_curhtprotmode);
572 	db_printf(" htprotmode %d", ic->ic_htprotmode);
573 	db_printf(" lastnonht %d", ic->ic_lastnonht);
574 	db_printf("\n");
575 
576 	if (showprocs) {
577 		db_printf("\tic_vap_create %p\n", ic->ic_vap_create);
578 		db_printf("\tic_vap_delete %p\n", ic->ic_vap_delete);
579 #if 0
580 		/* operating mode attachment */
581 		ieee80211vap_attach	ic_vattach[IEEE80211_OPMODE_MAX];
582 #endif
583 		db_printf("\tic_newassoc %p\n", ic->ic_newassoc);
584 		db_printf("\tic_getradiocaps %p\n", ic->ic_getradiocaps);
585 		db_printf("\tic_setregdomain %p\n", ic->ic_setregdomain);
586 		db_printf("\tic_send_mgmt %p\n", ic->ic_send_mgmt);
587 		db_printf("\tic_raw_xmit %p\n", ic->ic_raw_xmit);
588 		db_printf("\tic_updateslot %p\n", ic->ic_updateslot);
589 		db_printf("\tic_update_mcast %p\n", ic->ic_update_mcast);
590 		db_printf("\tic_update_promisc %p\n", ic->ic_update_promisc);
591 		db_printf("\tic_node_alloc %p\n", ic->ic_node_alloc);
592 		db_printf("\tic_node_free %p\n", ic->ic_node_free);
593 		db_printf("\tic_node_cleanup %p\n", ic->ic_node_cleanup);
594 		db_printf("\tic_node_getrssi %p\n", ic->ic_node_getrssi);
595 		db_printf("\tic_node_getsignal %p\n", ic->ic_node_getsignal);
596 		db_printf("\tic_node_getmimoinfo %p\n", ic->ic_node_getmimoinfo);
597 		db_printf("\tic_scan_start %p\n", ic->ic_scan_start);
598 		db_printf("\tic_scan_end %p\n", ic->ic_scan_end);
599 		db_printf("\tic_set_channel %p\n", ic->ic_set_channel);
600 		db_printf("\tic_scan_curchan %p\n", ic->ic_scan_curchan);
601 		db_printf("\tic_scan_mindwell %p\n", ic->ic_scan_mindwell);
602 		db_printf("\tic_recv_action %p\n", ic->ic_recv_action);
603 		db_printf("\tic_send_action %p\n", ic->ic_send_action);
604 		db_printf("\tic_addba_request %p\n", ic->ic_addba_request);
605 		db_printf("\tic_addba_response %p\n", ic->ic_addba_response);
606 		db_printf("\tic_addba_stop %p\n", ic->ic_addba_stop);
607 	}
608 	if (showvaps && !TAILQ_EMPTY(&ic->ic_vaps)) {
609 		db_printf("\n");
610 		TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
611 			_db_show_vap(vap, showprocs);
612 	}
613 	if (showsta && !TAILQ_EMPTY(&ic->ic_sta.nt_node)) {
614 		const struct ieee80211_node_table *nt = &ic->ic_sta;
615 		const struct ieee80211_node *ni;
616 
617 		TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
618 			db_printf("\n");
619 			_db_show_sta(ni);
620 		}
621 	}
622 }
623 
624 static void
625 _db_show_channel(const char *tag, const struct ieee80211_channel *c)
626 {
627 	db_printf("%s ", tag);
628 	if (c == NULL)
629 		db_printf("<NULL>");
630 	else if (c == IEEE80211_CHAN_ANYC)
631 		db_printf("<ANY>");
632 	else
633 		db_printf("[%u (%u) flags=%b maxreg %u maxpow %u minpow %u state 0x%x extieee %u]",
634 		    c->ic_freq, c->ic_ieee,
635 		    c->ic_flags, IEEE80211_CHAN_BITS,
636 		    c->ic_maxregpower, c->ic_maxpower, c->ic_minpower,
637 		    c->ic_state, c->ic_extieee);
638 }
639 
640 static void
641 _db_show_ssid(const char *tag, int ix, int len, const uint8_t *ssid)
642 {
643 	const uint8_t *p;
644 	int i;
645 
646 	db_printf(tag, ix);
647 
648 	if (len > IEEE80211_NWID_LEN)
649 		len = IEEE80211_NWID_LEN;
650 	/* determine printable or not */
651 	for (i = 0, p = ssid; i < len; i++, p++) {
652 		if (*p < ' ' || *p > 0x7e)
653 			break;
654 	}
655 	if (i == len) {
656 		db_printf("\"");
657 		for (i = 0, p = ssid; i < len; i++, p++)
658 			db_printf("%c", *p);
659 		db_printf("\"");
660 	} else {
661 		db_printf("0x");
662 		for (i = 0, p = ssid; i < len; i++, p++)
663 			db_printf("%02x", *p);
664 	}
665 }
666 
667 static void
668 _db_show_appie(const char *tag, const struct ieee80211_appie *ie)
669 {
670 	const uint8_t *p;
671 	int i;
672 
673 	if (ie == NULL)
674 		return;
675 	db_printf("%s [0x", tag);
676 	for (i = 0, p = ie->ie_data; i < ie->ie_len; i++, p++)
677 		db_printf("%02x", *p);
678 	db_printf("]\n");
679 }
680 
681 static void
682 _db_show_key(const char *tag, int ix, const struct ieee80211_key *wk)
683 {
684 	static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
685 	const struct ieee80211_cipher *cip = wk->wk_cipher;
686 	int keylen = wk->wk_keylen;
687 
688 	if (wk->wk_keyix == IEEE80211_KEYIX_NONE)
689 		return;
690 	db_printf(tag, ix);
691 	switch (cip->ic_cipher) {
692 	case IEEE80211_CIPHER_WEP:
693 		/* compatibility */
694 		db_printf(" wepkey %u:%s", wk->wk_keyix+1,
695 		    keylen <= 5 ? "40-bit" :
696 		    keylen <= 13 ? "104-bit" : "128-bit");
697 		break;
698 	case IEEE80211_CIPHER_TKIP:
699 		if (keylen > 128/8)
700 			keylen -= 128/8;	/* ignore MIC for now */
701 		db_printf(" TKIP %u:%u-bit", wk->wk_keyix+1, 8*keylen);
702 		break;
703 	case IEEE80211_CIPHER_AES_OCB:
704 		db_printf(" AES-OCB %u:%u-bit", wk->wk_keyix+1, 8*keylen);
705 		break;
706 	case IEEE80211_CIPHER_AES_CCM:
707 		db_printf(" AES-CCM %u:%u-bit", wk->wk_keyix+1, 8*keylen);
708 		break;
709 	case IEEE80211_CIPHER_CKIP:
710 		db_printf(" CKIP %u:%u-bit", wk->wk_keyix+1, 8*keylen);
711 		break;
712 	case IEEE80211_CIPHER_NONE:
713 		db_printf(" NULL %u:%u-bit", wk->wk_keyix+1, 8*keylen);
714 		break;
715 	default:
716 		db_printf(" UNKNOWN (0x%x) %u:%u-bit",
717 			cip->ic_cipher, wk->wk_keyix+1, 8*keylen);
718 		break;
719 	}
720 	if (memcmp(wk->wk_key, zerodata, keylen) != 0) {
721 		int i;
722 
723 		db_printf(" <");
724 		for (i = 0; i < keylen; i++)
725 			db_printf("%02x", wk->wk_key[i]);
726 		db_printf(">");
727 		if (cip->ic_cipher != IEEE80211_CIPHER_WEP &&
728 		    wk->wk_keyrsc[IEEE80211_NONQOS_TID] != 0)
729 			db_printf(" rsc %ju", (uintmax_t)wk->wk_keyrsc[IEEE80211_NONQOS_TID]);
730 		if (cip->ic_cipher != IEEE80211_CIPHER_WEP &&
731 		    wk->wk_keytsc != 0)
732 			db_printf(" tsc %ju", (uintmax_t)wk->wk_keytsc);
733 		if (wk->wk_flags != 0) {
734 			const char *sep = " ";
735 
736 			if (wk->wk_flags & IEEE80211_KEY_XMIT)
737 				db_printf("%stx", sep), sep = "+";
738 			if (wk->wk_flags & IEEE80211_KEY_RECV)
739 				db_printf("%srx", sep), sep = "+";
740 			if (wk->wk_flags & IEEE80211_KEY_DEFAULT)
741 				db_printf("%sdef", sep), sep = "+";
742 		}
743 		db_printf("\n");
744 	}
745 }
746 
747 static void
748 printrate(const char *tag, int v)
749 {
750 	if (v == IEEE80211_FIXED_RATE_NONE)
751 		db_printf(" %s <none>", tag);
752 	else if (v == 11)
753 		db_printf(" %s 5.5", tag);
754 	else if (v & IEEE80211_RATE_MCS)
755 		db_printf(" %s MCS%d", tag, v &~ IEEE80211_RATE_MCS);
756 	else
757 		db_printf(" %s %d", tag, v/2);
758 }
759 
760 static void
761 _db_show_roamparams(const char *tag, const void *arg,
762     const struct ieee80211_roamparam *rp)
763 {
764 
765 	db_printf(tag, arg);
766 	if (rp->rssi & 1)
767 		db_printf(" rssi %u.5", rp->rssi/2);
768 	else
769 		db_printf(" rssi %u", rp->rssi/2);
770 	printrate("rate", rp->rate);
771 }
772 
773 static void
774 _db_show_txparams(const char *tag, const void *arg,
775     const struct ieee80211_txparam *tp)
776 {
777 
778 	db_printf(tag, arg);
779 	printrate("ucastrate", tp->ucastrate);
780 	printrate("mcastrate", tp->mcastrate);
781 	printrate("mgmtrate", tp->mgmtrate);
782 	db_printf(" maxretry %d", tp->maxretry);
783 }
784 
785 static void
786 _db_show_stats(const struct ieee80211_stats *is)
787 {
788 }
789 #endif /* DDB */
790