xref: /freebsd/sys/net80211/ieee80211_ddb.c (revision 713db49d)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2007-2009 Sam Leffler, Errno Consulting
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <sys/cdefs.h>
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 #include <sys/malloc.h>
40 #include <sys/socket.h>
41 
42 #include <net/if.h>
43 #include <net/if_var.h>
44 #include <net/if_dl.h>
45 #include <net/if_media.h>
46 #include <net/if_types.h>
47 #include <net/ethernet.h>
48 #include <net/vnet.h>
49 
50 #include <net80211/ieee80211_var.h>
51 #include <net80211/ieee80211_ratectl.h>
52 #ifdef IEEE80211_SUPPORT_TDMA
53 #include <net80211/ieee80211_tdma.h>
54 #endif
55 #ifdef IEEE80211_SUPPORT_MESH
56 #include <net80211/ieee80211_mesh.h>
57 #endif
58 
59 #include <ddb/ddb.h>
60 #include <ddb/db_sym.h>
61 
62 #define DB_PRINTSYM(prefix, name, addr) do { \
63 	db_printf("%s%-25s : ",  prefix, name); \
64 	db_printsym((db_addr_t) addr, DB_STGY_ANY); \
65 	db_printf("\n"); \
66 } while (0)
67 
68 static void _db_show_sta(const struct ieee80211_node *);
69 static void _db_show_vap(const struct ieee80211vap *, int, int);
70 static void _db_show_com(const struct ieee80211com *,
71 	int showvaps, int showsta, int showmesh, int showprocs, int);
72 
73 static void _db_show_all_vaps(void *, struct ieee80211com *);
74 
75 static void _db_show_node_table(const char *tag,
76 	const struct ieee80211_node_table *);
77 static void _db_show_channel(const char *tag, const struct ieee80211_channel *);
78 static void _db_show_ssid(const char *tag, int ix, int len, const uint8_t *);
79 static void _db_show_appie(const char *tag, const struct ieee80211_appie *);
80 static void _db_show_key(const char *tag, int ix, const struct ieee80211_key *);
81 static void _db_show_roamparams(const char *tag, const void *arg,
82 	const struct ieee80211_roamparam *rp);
83 static void _db_show_txparams(const char *tag, const void *arg,
84 	const struct ieee80211_txparam *tp);
85 static void _db_show_ageq(const char *tag, const struct ieee80211_ageq *q);
86 static void _db_show_stats(const struct ieee80211_stats *);
87 #ifdef IEEE80211_SUPPORT_MESH
88 static void _db_show_mesh(const struct ieee80211_mesh_state *);
89 #endif
90 
DB_SHOW_COMMAND(sta,db_show_sta)91 DB_SHOW_COMMAND(sta, db_show_sta)
92 {
93 	if (!have_addr) {
94 		db_printf("usage: show sta <addr>\n");
95 		return;
96 	}
97 	_db_show_sta((const struct ieee80211_node *) addr);
98 }
99 
DB_SHOW_COMMAND(statab,db_show_statab)100 DB_SHOW_COMMAND(statab, db_show_statab)
101 {
102 	if (!have_addr) {
103 		db_printf("usage: show statab <addr>\n");
104 		return;
105 	}
106 	_db_show_node_table("", (const struct ieee80211_node_table *) addr);
107 }
108 
DB_SHOW_COMMAND(vap,db_show_vap)109 DB_SHOW_COMMAND(vap, db_show_vap)
110 {
111 	int i, showmesh = 0, showprocs = 0;
112 
113 	if (!have_addr) {
114 		db_printf("usage: show vap <addr>\n");
115 		return;
116 	}
117 	for (i = 0; modif[i] != '\0'; i++)
118 		switch (modif[i]) {
119 		case 'a':
120 			showprocs = 1;
121 			showmesh = 1;
122 			break;
123 		case 'm':
124 			showmesh = 1;
125 			break;
126 		case 'p':
127 			showprocs = 1;
128 			break;
129 		}
130 	_db_show_vap((const struct ieee80211vap *) addr, showmesh, showprocs);
131 }
132 
DB_SHOW_COMMAND(com,db_show_com)133 DB_SHOW_COMMAND(com, db_show_com)
134 {
135 	const struct ieee80211com *ic;
136 	int i, showprocs = 0, showvaps = 0, showsta = 0, showmesh = 0, showscan = 0;
137 
138 	if (!have_addr) {
139 		db_printf("usage: show com <addr>\n");
140 		return;
141 	}
142 	for (i = 0; modif[i] != '\0'; i++)
143 		switch (modif[i]) {
144 		case 'a':
145 			showsta = showmesh = showvaps = showprocs = showscan = 1;
146 			break;
147 		case 'S':
148 			showscan = 1;
149 			break;
150 		case 's':
151 			showsta = 1;
152 			break;
153 		case 'm':
154 			showmesh = 1;
155 			break;
156 		case 'v':
157 			showvaps = 1;
158 			break;
159 		case 'p':
160 			showprocs = 1;
161 			break;
162 		}
163 
164 	ic = (const struct ieee80211com *) addr;
165 	_db_show_com(ic, showvaps, showsta, showmesh, showprocs, showscan);
166 }
167 
DB_SHOW_ALL_COMMAND(vaps,db_show_all_vaps)168 DB_SHOW_ALL_COMMAND(vaps, db_show_all_vaps)
169 {
170 	int i, showall = 0;
171 
172 	for (i = 0; modif[i] != '\0'; i++)
173 		switch (modif[i]) {
174 		case 'a':
175 			showall = 1;
176 			break;
177 		}
178 
179 	ieee80211_iterate_coms(_db_show_all_vaps, &showall);
180 }
181 
182 #ifdef IEEE80211_SUPPORT_MESH
DB_SHOW_ALL_COMMAND(mesh,db_show_mesh)183 DB_SHOW_ALL_COMMAND(mesh, db_show_mesh)
184 {
185 	const struct ieee80211_mesh_state *ms;
186 
187 	if (!have_addr) {
188 		db_printf("usage: show mesh <addr>\n");
189 		return;
190 	}
191 	ms = (const struct ieee80211_mesh_state *) addr;
192 	_db_show_mesh(ms);
193 }
194 #endif /* IEEE80211_SUPPORT_MESH */
195 
196 static void
_db_show_txampdu(const char * sep,int ix,const struct ieee80211_tx_ampdu * tap)197 _db_show_txampdu(const char *sep, int ix, const struct ieee80211_tx_ampdu *tap)
198 {
199 	db_printf("%stxampdu[%d]: %p flags %b %s\n",
200 		sep, ix, tap, tap->txa_flags, IEEE80211_AGGR_BITS,
201 		ieee80211_wme_acnames[TID_TO_WME_AC(tap->txa_tid)]);
202 	db_printf("%s  token %u lastsample %d pkts %d avgpps %d qbytes %d qframes %d\n",
203 		sep, tap->txa_token, tap->txa_lastsample, tap->txa_pkts,
204 		tap->txa_avgpps, tap->txa_qbytes, tap->txa_qframes);
205 	db_printf("%s  start %u seqpending %u wnd %u attempts %d nextrequest %d\n",
206 		sep, tap->txa_start, tap->txa_seqpending, tap->txa_wnd,
207 		tap->txa_attempts, tap->txa_nextrequest);
208 	/* XXX timer */
209 }
210 
211 static void
_db_show_rxampdu(const char * sep,int ix,const struct ieee80211_rx_ampdu * rap)212 _db_show_rxampdu(const char *sep, int ix, const struct ieee80211_rx_ampdu *rap)
213 {
214 	struct mbuf *m;
215 	int i;
216 
217 	db_printf("%srxampdu[%d]: %p flags 0x%x tid %u\n",
218 		sep, ix, rap, rap->rxa_flags, ix /*XXX */);
219 	db_printf("%s  qbytes %d qframes %d seqstart %u start %u wnd %u\n",
220 		sep, rap->rxa_qbytes, rap->rxa_qframes,
221 		rap->rxa_seqstart, rap->rxa_start, rap->rxa_wnd);
222 	db_printf("%s  age %d nframes %d\n", sep,
223 		rap->rxa_age, rap->rxa_nframes);
224 	for (i = 0; i < IEEE80211_AGGR_BAWMAX; i++)
225 		if (!mbufq_empty(&rap->rxa_mq[i])) {
226 			db_printf("%s  m[%2u:%4u] ", sep, i,
227 			    IEEE80211_SEQ_ADD(rap->rxa_start, i));
228 			STAILQ_FOREACH(m, &rap->rxa_mq[i].mq_head,
229 			    m_stailqpkt) {
230 				db_printf(" %p", m);
231 			}
232 			db_printf("\n");
233 		}
234 }
235 
236 static void
_db_show_sta(const struct ieee80211_node * ni)237 _db_show_sta(const struct ieee80211_node *ni)
238 {
239 	int i;
240 
241 	db_printf("STA: %p: mac %s refcnt %d\n", ni,
242 		ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni));
243 	db_printf("\tvap %p wdsvap %p ic %p table %p\n",
244 		ni->ni_vap, ni->ni_wdsvap, ni->ni_ic, ni->ni_table);
245 	db_printf("\tflags=%b\n", ni->ni_flags, IEEE80211_NODE_BITS);
246 	db_printf("\tauthmode %u ath_flags 0x%x ath_defkeyix %u\n",
247 		ni->ni_authmode, ni->ni_ath_flags, ni->ni_ath_defkeyix);
248 	db_printf("\tassocid 0x%x txpower %u vlan %u\n",
249 		ni->ni_associd, ni->ni_txpower, ni->ni_vlan);
250 	db_printf("\tjointime %d (%lu secs) challenge %p\n",
251 		ni->ni_jointime, (unsigned long)(time_uptime - ni->ni_jointime),
252 		ni->ni_challenge);
253 	db_printf("\ties: data %p len %d\n", ni->ni_ies.data, ni->ni_ies.len);
254 	db_printf("\t[wpa_ie %p rsn_ie %p wme_ie %p ath_ie %p\n",
255 		ni->ni_ies.wpa_ie, ni->ni_ies.rsn_ie, ni->ni_ies.wme_ie,
256 		ni->ni_ies.ath_ie);
257 	db_printf("\t htcap_ie %p htinfo_ie %p]\n",
258 		ni->ni_ies.htcap_ie, ni->ni_ies.htinfo_ie);
259 	db_printf("\t vhtcap_ie %p vhtopmode_ie %p vhtpwrenv_ie %p]\n",
260 		ni->ni_ies.vhtcap_ie, ni->ni_ies.vhtopmode_ie,
261 		ni->ni_ies.vhtpwrenv_ie);
262 	if (ni->ni_flags & IEEE80211_NODE_QOS) {
263 		for (i = 0; i < WME_NUM_TID; i++) {
264 			if (ni->ni_txseqs[i] || ni->ni_rxseqs[i])
265 				db_printf("\t[%u] txseq %u rxseq %u fragno %u\n",
266 				    i, ni->ni_txseqs[i],
267 				    ni->ni_rxseqs[i] >> IEEE80211_SEQ_SEQ_SHIFT,
268 				    ni->ni_rxseqs[i] & IEEE80211_SEQ_FRAG_MASK);
269 		}
270 	}
271 
272 	db_printf("\ttxseq %u rxseq %u fragno %u rxfragstamp %u\n",
273 		ni->ni_txseqs[IEEE80211_NONQOS_TID],
274 		ni->ni_rxseqs[IEEE80211_NONQOS_TID] >> IEEE80211_SEQ_SEQ_SHIFT,
275 		ni->ni_rxseqs[IEEE80211_NONQOS_TID] & IEEE80211_SEQ_FRAG_MASK,
276 		ni->ni_rxfragstamp);
277 	db_printf("\trxfrag[0] %p rxfrag[1] %p rxfrag[2] %p\n",
278 		ni->ni_rxfrag[0], ni->ni_rxfrag[1], ni->ni_rxfrag[2]);
279 	_db_show_key("\tucastkey", 0, &ni->ni_ucastkey);
280 	db_printf("\tavgrssi 0x%x (rssi %d) noise %d\n",
281 		ni->ni_avgrssi, IEEE80211_RSSI_GET(ni->ni_avgrssi),
282 		ni->ni_noise);
283 	db_printf("\tintval %u capinfo %b\n",
284 		ni->ni_intval, ni->ni_capinfo, IEEE80211_CAPINFO_BITS);
285 	db_printf("\tbssid %s", ether_sprintf(ni->ni_bssid));
286 	_db_show_ssid(" essid ", 0, ni->ni_esslen, ni->ni_essid);
287 	db_printf("\n");
288 	_db_show_channel("\tchannel", ni->ni_chan);
289 	db_printf("\n");
290 	db_printf("\terp %b dtim_period %u dtim_count %u\n",
291 		ni->ni_erp, IEEE80211_ERP_BITS,
292 		ni->ni_dtim_period, ni->ni_dtim_count);
293 
294 	db_printf("\thtcap %b htparam 0x%x htctlchan %u ht2ndchan %u\n",
295 		ni->ni_htcap, IEEE80211_HTCAP_BITS,
296 		ni->ni_htparam, ni->ni_htctlchan, ni->ni_ht2ndchan);
297 	db_printf("\thtopmode 0x%x htstbc 0x%x chw %u\n",
298 		ni->ni_htopmode, ni->ni_htstbc, ni->ni_chw);
299 
300 	/* XXX ampdu state */
301 	for (i = 0; i < WME_NUM_TID; i++)
302 		if (ni->ni_tx_ampdu[i].txa_flags & IEEE80211_AGGR_SETUP)
303 			_db_show_txampdu("\t", i, &ni->ni_tx_ampdu[i]);
304 	for (i = 0; i < WME_NUM_TID; i++)
305 		if (ni->ni_rx_ampdu[i].rxa_flags)
306 			_db_show_rxampdu("\t", i, &ni->ni_rx_ampdu[i]);
307 
308 	db_printf("\tinact %u inact_reload %u txrate %u\n",
309 		ni->ni_inact, ni->ni_inact_reload, ni->ni_txrate);
310 #ifdef IEEE80211_SUPPORT_MESH
311 	_db_show_ssid("\tmeshid ", 0, ni->ni_meshidlen, ni->ni_meshid);
312 	db_printf(" mlstate %b mllid 0x%x mlpid 0x%x mlrcnt %u mltval %u\n",
313 	    ni->ni_mlstate, IEEE80211_MESH_MLSTATE_BITS,
314 	    ni->ni_mllid, ni->ni_mlpid, ni->ni_mlrcnt, ni->ni_mltval);
315 #endif
316 
317 	/* VHT state */
318 	db_printf("\tvhtcap %b vht_basicmcs %#06x vht_pad2 %#06x\n",
319 	    ni->ni_vhtcap, IEEE80211_VHTCAP_BITS,
320 	    ni->ni_vht_basicmcs, ni->ni_vht_pad2);
321 	db_printf("\tvht_mcsinfo: { rx_mcs_map %#06x rx_highest %#06x "
322 	    "tx_mcs_map %#06x tx_highest %#06x }\n",
323 	    ni->ni_vht_mcsinfo.rx_mcs_map, ni->ni_vht_mcsinfo.rx_highest,
324 	    ni->ni_vht_mcsinfo.tx_mcs_map, ni->ni_vht_mcsinfo.tx_highest);
325 	db_printf("\tvht_chan1/chan2 %u/%u vht_chanwidth %#04x\n",
326 	    ni->ni_vht_chan1, ni->ni_vht_chan2, ni->ni_vht_chanwidth);
327 	db_printf("\tvht_pad1 %#04x vht_spare { %#x %#x %#x %#x %#x %#x %#x %#x }\n",
328 	    ni->ni_vht_pad1, ni->ni_vht_spare[0], ni->ni_vht_spare[1],
329 	    ni->ni_vht_spare[2], ni->ni_vht_spare[3], ni->ni_vht_spare[4],
330 	    ni->ni_vht_spare[5], ni->ni_vht_spare[6], ni->ni_vht_spare[7]);
331 
332 	db_printf("\tni_tx_superg[] = {");
333 	for (i = 0; i < WME_NUM_TID; i++)
334 		db_printf(" %p%s", ni->ni_tx_superg[i], (i == 0) ? "" : ",");
335 	db_printf(" }\n");
336 
337 	db_printf("\tni_rctls = %p", ni->ni_rctls);
338 	db_printf("\tni_drv_data = %p", ni->ni_drv_data);
339 	db_printf("\n");
340 
341 	db_printf("\tni_spare[3] = { %#jx %#jx %#jx }",
342 	    ni->ni_spare[0], ni->ni_spare[1], ni->ni_spare[2]);
343 	db_printf("\n");
344 
345 #ifdef __notyet__
346 	struct ieee80211_psq	ni_psq;		/* power save queue */
347 	struct ieee80211_nodestats ni_stats;	/* per-node statistics */
348 
349 	/* quiet time IE state for the given node */
350 	uint32_t		ni_quiet_ie_set;	/* Quiet time IE was seen */
351 	struct			ieee80211_quiet_ie ni_quiet_ie;	/* last seen quiet IE */
352 
353 	/* U-APSD */
354 	uint8_t			ni_uapsd;	/* U-APSD per-node flags matching WMM STA QoS Info field */
355 #endif
356 }
357 
358 #ifdef IEEE80211_SUPPORT_TDMA
359 static void
_db_show_tdma(const char * sep,const struct ieee80211_tdma_state * ts,int showprocs)360 _db_show_tdma(const char *sep, const struct ieee80211_tdma_state *ts, int showprocs)
361 {
362 	db_printf("%stdma %p:\n", sep, ts);
363 	db_printf("%s  version %u slot %u bintval %u peer %p\n", sep,
364 	    ts->tdma_version, ts->tdma_slot, ts->tdma_bintval, ts->tdma_peer);
365 	db_printf("%s  slotlen %u slotcnt %u", sep,
366 	    ts->tdma_slotlen, ts->tdma_slotcnt);
367 	db_printf(" inuse 0x%x active 0x%x count %d\n",
368 	    ts->tdma_inuse[0], ts->tdma_active[0], ts->tdma_count);
369 	if (showprocs) {
370 		DB_PRINTSYM(sep, "  tdma_newstate", ts->tdma_newstate);
371 		DB_PRINTSYM(sep, "  tdma_recv_mgmt", ts->tdma_recv_mgmt);
372 		DB_PRINTSYM(sep, "  tdma_opdetach", ts->tdma_opdetach);
373 	}
374 }
375 #endif /* IEEE80211_SUPPORT_TDMA */
376 
377 static void
_db_show_scan(const struct ieee80211_scan_state * ss,int showprocs)378 _db_show_scan(const struct ieee80211_scan_state *ss, int showprocs)
379 {
380 	int i;
381 	const struct ieee80211_scanner *ss_ops;
382 
383 	db_printf("SCAN %p:", ss);
384 	db_printf(" vap %p ic %p", ss->ss_vap, ss->ss_ic);
385 	db_printf("\n");
386 
387 	db_printf("\tss_ops %p (%s) ss_priv %p",
388 	    ss->ss_ops, ss->ss_ops->scan_name, ss->ss_priv);
389 	db_printf("\n");
390 	if (showprocs) {
391 		ss_ops = ss->ss_ops;
392 		DB_PRINTSYM("\t", "scan_attach", ss_ops->scan_attach);
393 		DB_PRINTSYM("\t", "scan_detach", ss_ops->scan_detach);
394 		DB_PRINTSYM("\t", "scan_start", ss_ops->scan_start);
395 		DB_PRINTSYM("\t", "scan_restart", ss_ops->scan_restart);
396 		DB_PRINTSYM("\t", "scan_cancel", ss_ops->scan_cancel);
397 		DB_PRINTSYM("\t", "scan_end", ss_ops->scan_end);
398 		DB_PRINTSYM("\t", "scan_flush", ss_ops->scan_flush);
399 		DB_PRINTSYM("\t", "scan_pickchan", ss_ops->scan_pickchan);
400 		DB_PRINTSYM("\t", "scan_add", ss_ops->scan_add);
401 		DB_PRINTSYM("\t", "scan_age", ss_ops->scan_age);
402 		DB_PRINTSYM("\t", "scan_assoc_fail", ss_ops->scan_assoc_fail);
403 		DB_PRINTSYM("\t", "scan_assoc_success", ss_ops->scan_assoc_success);
404 		DB_PRINTSYM("\t", "scan_iterate", ss_ops->scan_iterate);
405 		DB_PRINTSYM("\t", "scan_spare0", ss_ops->scan_spare0);
406 		DB_PRINTSYM("\t", "scan_spare1", ss_ops->scan_spare1);
407 		DB_PRINTSYM("\t", "scan_spare2", ss_ops->scan_spare2);
408 		DB_PRINTSYM("\t", "scan_spare3", ss_ops->scan_spare3);
409 	}
410 
411 	db_printf("\tss_flags %b", ss->ss_flags, IEEE80211_SS_FLAGS_BITS);
412 	db_printf("\n");
413 
414 	db_printf("\tss_nssid %u", ss->ss_nssid);
415 	for (i = 0; i < ss->ss_nssid && i < IEEE80211_SCAN_MAX_SSID; i++)
416 		_db_show_ssid(" ss_nssid[%d]", i,
417 		    ss->ss_ssid[i].len, ss->ss_ssid[i].ssid);
418 	db_printf("\n");
419 
420 	db_printf("\tss_chans:\n");
421 	for (i = 0; i < ss->ss_last && i < IEEE80211_SCAN_MAX; i++) {
422 		db_printf("\t%-3d", i);
423 		_db_show_channel(" ", ss->ss_chans[i]);
424 		db_printf("\n");
425 	}
426 
427 	db_printf("\tss_next %u ss_last %u ss_mindwell %lu ss_maxdwell %lu",
428 	    ss->ss_next, ss->ss_last, ss->ss_mindwell, ss->ss_maxdwell);
429 	db_printf("\n");
430 }
431 
432 static void
_db_show_rate(const struct ieee80211_ratectl * rate,const void * rs,const int showprocs)433 _db_show_rate(const struct ieee80211_ratectl *rate, const void *rs,
434     const int showprocs)
435 {
436 
437 	db_printf("\tiv_rate %p", rate);
438 	db_printf(" iv_rs %p", rs);
439 	db_printf("\n");
440 	if (showprocs) {
441 		db_printf("\t  ir_name %s", rate->ir_name);
442 		db_printf("\n");
443 		DB_PRINTSYM("\t  ", "ir_attach", rate->ir_attach);
444 		DB_PRINTSYM("\t  ", "ir_detach", rate->ir_detach);
445 		DB_PRINTSYM("\t  ", "ir_init", rate->ir_init);
446 		DB_PRINTSYM("\t  ", "ir_deinit", rate->ir_deinit);
447 		DB_PRINTSYM("\t  ", "ir_node_init", rate->ir_node_init);
448 		DB_PRINTSYM("\t  ", "ir_node_deinit", rate->ir_node_deinit);
449 		DB_PRINTSYM("\t  ", "ir_rate", rate->ir_rate);
450 		DB_PRINTSYM("\t  ", "ir_tx_complete", rate->ir_tx_complete);
451 		DB_PRINTSYM("\t  ", "ir_tx_update", rate->ir_tx_update);
452 		DB_PRINTSYM("\t  ", "ir_setinterval", rate->ir_setinterval);
453 		DB_PRINTSYM("\t  ", "ir_node_stats", rate->ir_node_stats);
454 	}
455 }
456 
457 static void
_db_show_vap(const struct ieee80211vap * vap,int showmesh,int showprocs)458 _db_show_vap(const struct ieee80211vap *vap, int showmesh, int showprocs)
459 {
460 	const struct ieee80211com *ic = vap->iv_ic;
461 	int i;
462 
463 	db_printf("VAP %p:", vap);
464 	db_printf(" bss %p", vap->iv_bss);
465 	db_printf(" myaddr %s", ether_sprintf(vap->iv_myaddr));
466 	db_printf("\n");
467 
468 	db_printf("\topmode %s", ieee80211_opmode_name[vap->iv_opmode]);
469 #ifdef IEEE80211_SUPPORT_MESH
470 	if (vap->iv_opmode == IEEE80211_M_MBSS)
471 		db_printf("(%p)", vap->iv_mesh);
472 #endif
473 	db_printf(" state %#x %s", vap->iv_state,
474 	    ieee80211_state_name[vap->iv_state]);
475 	db_printf(" ifp %p(%s)", vap->iv_ifp, if_name(vap->iv_ifp));
476 	db_printf("\n");
477 
478 	db_printf("\tic %p", vap->iv_ic);
479 	db_printf(" media %p", &vap->iv_media);
480 	db_printf(" bpf_if %p", vap->iv_rawbpf);
481 	db_printf(" mgtsend %p", &vap->iv_mgtsend);
482 #if 0
483 	struct sysctllog	*iv_sysctl;	/* dynamic sysctl context */
484 #endif
485 	db_printf("\n");
486 
487 	db_printf("\tiv_nstate %#x %s iv_nstate_b %d iv_nstate_n %d\n",
488 	    vap->iv_nstate, ieee80211_state_name[vap->iv_nstate], /* historic */
489 	    vap->iv_nstate_b, vap->iv_nstate_n);
490 	for (i = 0; i < NET80211_IV_NSTATE_NUM; i++) {
491 		db_printf("\t [%d] iv_nstates %#x %s _task %p _args %d\n", i,
492 		    vap->iv_nstates[i], ieee80211_state_name[vap->iv_nstates[i]],
493 		    &vap->iv_nstate_task[i], vap->iv_nstate_args[i]);
494 	}
495 
496 	db_printf("\tdebug=%b\n", vap->iv_debug, IEEE80211_MSG_BITS);
497 
498 	db_printf("\tflags=%b\n", vap->iv_flags, IEEE80211_F_BITS);
499 	db_printf("\tflags_ext=%b\n", vap->iv_flags_ext, IEEE80211_FEXT_BITS);
500 	db_printf("\tflags_ht=%b\n", vap->iv_flags_ht, IEEE80211_FHT_BITS);
501 	db_printf("\tflags_ven=%b\n", vap->iv_flags_ven, IEEE80211_FVEN_BITS);
502 	db_printf("\tcaps=%b\n", vap->iv_caps, IEEE80211_C_BITS);
503 	db_printf("\thtcaps=%b\n", vap->iv_htcaps, IEEE80211_C_HTCAP_BITS);
504 	db_printf("\tvhtcap=%b\n", vap->iv_vht_cap.vht_cap_info, IEEE80211_VHTCAP_BITS);
505 
506 	_db_show_stats(&vap->iv_stats);
507 
508 	db_printf("\tinact_init %d", vap->iv_inact_init);
509 	db_printf(" inact_auth %d", vap->iv_inact_auth);
510 	db_printf(" inact_run %d", vap->iv_inact_run);
511 	db_printf(" inact_probe %d", vap->iv_inact_probe);
512 	db_printf("\n");
513 
514 	db_printf("\tdes_nssid %d", vap->iv_des_nssid);
515 	if (vap->iv_des_nssid)
516 		_db_show_ssid(" des_ssid[%u] ", 0,
517 		    vap->iv_des_ssid[0].len, vap->iv_des_ssid[0].ssid);
518 	db_printf(" des_bssid %s", ether_sprintf(vap->iv_des_bssid));
519 	db_printf("\n");
520 	db_printf("\tdes_mode %d", vap->iv_des_mode);
521 	_db_show_channel(" des_chan", vap->iv_des_chan);
522 	db_printf("\n");
523 #if 0
524 	int			iv_nicknamelen;	/* XXX junk */
525 	uint8_t			iv_nickname[IEEE80211_NWID_LEN];
526 #endif
527 	db_printf("\tbgscanidle %u", vap->iv_bgscanidle);
528 	db_printf(" bgscanintvl %u", vap->iv_bgscanintvl);
529 	db_printf(" scanvalid %u", vap->iv_scanvalid);
530 	db_printf("\n");
531 	db_printf("\tscanreq_duration %u", vap->iv_scanreq_duration);
532 	db_printf(" scanreq_mindwell %u", vap->iv_scanreq_mindwell);
533 	db_printf(" scanreq_maxdwell %u", vap->iv_scanreq_maxdwell);
534 	db_printf("\n");
535 	db_printf("\tscanreq_flags 0x%x", vap->iv_scanreq_flags);
536 	db_printf(" scanreq_nssid %d", vap->iv_scanreq_nssid);
537 	for (i = 0; i < vap->iv_scanreq_nssid; i++)
538 		_db_show_ssid(" scanreq_ssid[%u]", i,
539 		    vap->iv_scanreq_ssid[i].len, vap->iv_scanreq_ssid[i].ssid);
540 	db_printf(" roaming %d", vap->iv_roaming);
541 	db_printf("\n");
542 	for (i = IEEE80211_MODE_11A; i < IEEE80211_MODE_MAX; i++)
543 		if (isset(ic->ic_modecaps, i)) {
544 			_db_show_roamparams("\troamparms[%s]",
545 			    ieee80211_phymode_name[i], &vap->iv_roamparms[i]);
546 			db_printf("\n");
547 		}
548 
549 	db_printf("\tbmissthreshold %u", vap->iv_bmissthreshold);
550 	db_printf(" bmiss_max %u", vap->iv_bmiss_count);
551 	db_printf(" bmiss_max %d", vap->iv_bmiss_max);
552 	db_printf("\n");
553 	db_printf("\tswbmiss_count %u", vap->iv_swbmiss_count);
554 	db_printf(" swbmiss_period %u", vap->iv_swbmiss_period);
555 	db_printf(" swbmiss %p", &vap->iv_swbmiss);
556 	db_printf("\n");
557 
558 	db_printf("\tampdu_rxmax %d", vap->iv_ampdu_rxmax);
559 	db_printf(" ampdu_density %d", vap->iv_ampdu_density);
560 	db_printf(" ampdu_limit %d", vap->iv_ampdu_limit);
561 	db_printf(" amsdu_limit %d", vap->iv_amsdu_limit);
562 	db_printf("\n");
563 
564 	db_printf("\tmax_aid %u", vap->iv_max_aid);
565 	db_printf(" aid_bitmap %p", vap->iv_aid_bitmap);
566 	db_printf("\n");
567 	db_printf("\tsta_assoc %u", vap->iv_sta_assoc);
568 	db_printf(" ps_sta %u", vap->iv_ps_sta);
569 	db_printf(" ps_pending %u", vap->iv_ps_pending);
570 	db_printf(" tim_len %u", vap->iv_tim_len);
571 	db_printf(" tim_bitmap %p", vap->iv_tim_bitmap);
572 	db_printf("\n");
573 	db_printf("\tdtim_period %u", vap->iv_dtim_period);
574 	db_printf(" dtim_count %u", vap->iv_dtim_count);
575 	db_printf(" set_tim %p", vap->iv_set_tim);
576 	db_printf(" csa_count %d", vap->iv_csa_count);
577 	db_printf("\n");
578 
579 	db_printf("\trtsthreshold %u", vap->iv_rtsthreshold);
580 	db_printf(" fragthreshold %u", vap->iv_fragthreshold);
581 	db_printf(" inact_timer %d", vap->iv_inact_timer);
582 	db_printf("\n");
583 	for (i = IEEE80211_MODE_11A; i < IEEE80211_MODE_MAX; i++)
584 		if (isset(ic->ic_modecaps, i)) {
585 			_db_show_txparams("\ttxparms[%s]",
586 			    ieee80211_phymode_name[i], &vap->iv_txparms[i]);
587 			db_printf("\n");
588 		}
589 
590 	/* application-specified IE's to attach to mgt frames */
591 	_db_show_appie("\tappie_beacon", vap->iv_appie_beacon);
592 	_db_show_appie("\tappie_probereq", vap->iv_appie_probereq);
593 	_db_show_appie("\tappie_proberesp", vap->iv_appie_proberesp);
594 	_db_show_appie("\tappie_assocreq", vap->iv_appie_assocreq);
595 	_db_show_appie("\tappie_asscoresp", vap->iv_appie_assocresp);
596 	_db_show_appie("\tappie_wpa", vap->iv_appie_wpa);
597 	if (vap->iv_wpa_ie != NULL || vap->iv_rsn_ie != NULL) {
598 		if (vap->iv_wpa_ie != NULL)
599 			db_printf("\twpa_ie %p", vap->iv_wpa_ie);
600 		if (vap->iv_rsn_ie != NULL)
601 			db_printf("\trsn_ie %p", vap->iv_rsn_ie);
602 		db_printf("\n");
603 	}
604 	db_printf("\tmax_keyix %u", vap->iv_max_keyix);
605 	db_printf(" def_txkey %d", vap->iv_def_txkey);
606 	db_printf("\n");
607 	for (i = 0; i < IEEE80211_WEP_NKID; i++)
608 		_db_show_key("\tnw_keys[%u]", i, &vap->iv_nw_keys[i]);
609 
610 	db_printf("\tauth %p(%s)", vap->iv_auth, vap->iv_auth->ia_name);
611 	db_printf(" ec %p", vap->iv_ec);
612 
613 	db_printf(" acl %p", vap->iv_acl);
614 	db_printf(" as %p", vap->iv_as);
615 	db_printf("\n");
616 #ifdef IEEE80211_SUPPORT_MESH
617 	if (showmesh && vap->iv_mesh != NULL)
618 		_db_show_mesh(vap->iv_mesh);
619 #endif
620 #ifdef IEEE80211_SUPPORT_TDMA
621 	if (vap->iv_tdma != NULL)
622 		_db_show_tdma("\t", vap->iv_tdma, showprocs);
623 #endif /* IEEE80211_SUPPORT_TDMA */
624 
625 	db_printf("\tsta_assoc %u", vap->iv_sta_assoc);
626 	db_printf(" ht_sta_assoc %u", vap->iv_ht_sta_assoc);
627 	db_printf(" ht40_sta_assoc %u", vap->iv_ht40_sta_assoc);
628 	db_printf("\n");
629 	db_printf("\tnonerpsta %u", vap->iv_nonerpsta);
630 	db_printf(" longslotsta %u", vap->iv_longslotsta);
631 	db_printf(" lastnonerp %d", vap->iv_lastnonerp);
632 	db_printf(" lastnonht %d", vap->iv_lastnonht);
633 	db_printf("\n");
634 	if (vap->iv_rate != NULL)
635 		_db_show_rate(vap->iv_rate, vap->iv_rs, showprocs);
636 
637 	if (showprocs) {
638 		DB_PRINTSYM("\t", "iv_key_alloc", vap->iv_key_alloc);
639 		DB_PRINTSYM("\t", "iv_key_delete", vap->iv_key_delete);
640 		DB_PRINTSYM("\t", "iv_key_set", vap->iv_key_set);
641 		DB_PRINTSYM("\t", "iv_key_update_begin", vap->iv_key_update_begin);
642 		DB_PRINTSYM("\t", "iv_key_update_end", vap->iv_key_update_end);
643 		DB_PRINTSYM("\t", "iv_opdetach", vap->iv_opdetach);
644 		DB_PRINTSYM("\t", "iv_input", vap->iv_input);
645 		DB_PRINTSYM("\t", "iv_recv_mgmt", vap->iv_recv_mgmt);
646 		DB_PRINTSYM("\t", "iv_deliver_data", vap->iv_deliver_data);
647 		DB_PRINTSYM("\t", "iv_bmiss", vap->iv_bmiss);
648 		DB_PRINTSYM("\t", "iv_reset", vap->iv_reset);
649 		DB_PRINTSYM("\t", "iv_update_beacon", vap->iv_update_beacon);
650 		DB_PRINTSYM("\t", "iv_newstate", vap->iv_newstate);
651 		DB_PRINTSYM("\t", "iv_output", vap->iv_output);
652 	}
653 }
654 
655 static void
_db_show_com(const struct ieee80211com * ic,int showvaps,int showsta,int showmesh,int showprocs,int showscan)656 _db_show_com(const struct ieee80211com *ic, int showvaps, int showsta,
657     int showmesh, int showprocs, int showscan)
658 {
659 	struct ieee80211vap *vap;
660 
661 	db_printf("COM: %p:", ic);
662 	TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
663 		db_printf(" %s(%p)", if_name(vap->iv_ifp), vap);
664 	db_printf("\n");
665 	db_printf("\tsoftc %p", ic->ic_softc);
666 	db_printf("\tname %s", ic->ic_name);
667 	db_printf(" comlock %p", &ic->ic_comlock);
668 	db_printf(" txlock %p", &ic->ic_txlock);
669 	db_printf(" fflock %p", &ic->ic_fflock);
670 	db_printf("\n");
671 	db_printf("\theadroom %d", ic->ic_headroom);
672 	db_printf(" phytype %d", ic->ic_phytype);
673 	db_printf(" opmode %s", ieee80211_opmode_name[ic->ic_opmode]);
674 	db_printf("\n");
675 	db_printf("\tinact %p", &ic->ic_inact);
676 	db_printf("\n");
677 
678 	db_printf("\tflags=%b\n", ic->ic_flags, IEEE80211_F_BITS);
679 	db_printf("\tflags_ext=%b\n", ic->ic_flags_ext, IEEE80211_FEXT_BITS);
680 	db_printf("\tflags_ht=%b\n", ic->ic_flags_ht, IEEE80211_FHT_BITS);
681 	db_printf("\tflags_ven=%b\n", ic->ic_flags_ven, IEEE80211_FVEN_BITS);
682 	db_printf("\tcaps=%b\n", ic->ic_caps, IEEE80211_C_BITS);
683 	db_printf("\tcryptocaps=%b\n",
684 	    ic->ic_cryptocaps, IEEE80211_CRYPTO_BITS);
685 	db_printf("\thtcaps=%b\n", ic->ic_htcaps, IEEE80211_HTCAP_BITS);
686 	db_printf("\tvhtcaps=%b\n", ic->ic_vht_cap.vht_cap_info, IEEE80211_VHTCAP_BITS);
687 
688 #if 0
689 	uint8_t			ic_modecaps[2];	/* set of mode capabilities */
690 #endif
691 	db_printf("\tcurmode %u", ic->ic_curmode);
692 	db_printf(" promisc %u", ic->ic_promisc);
693 	db_printf(" allmulti %u", ic->ic_allmulti);
694 	db_printf(" nrunning %u", ic->ic_nrunning);
695 	db_printf("\n");
696 	db_printf("\tbintval %u", ic->ic_bintval);
697 	db_printf(" lintval %u", ic->ic_lintval);
698 	db_printf(" holdover %u", ic->ic_holdover);
699 	db_printf(" txpowlimit %u", ic->ic_txpowlimit);
700 	db_printf("\n");
701 #if 0
702 	struct ieee80211_rateset ic_sup_rates[IEEE80211_MODE_MAX];
703 #endif
704 	/*
705 	 * Channel state:
706 	 *
707 	 * ic_channels is the set of available channels for the device;
708 	 *    it is setup by the driver
709 	 * ic_nchans is the number of valid entries in ic_channels
710 	 * ic_chan_avail is a bit vector of these channels used to check
711 	 *    whether a channel is available w/o searching the channel table.
712 	 * ic_chan_active is a (potentially) constrained subset of
713 	 *    ic_chan_avail that reflects any mode setting or user-specified
714 	 *    limit on the set of channels to use/scan
715 	 * ic_curchan is the current channel the device is set to; it may
716 	 *    be different from ic_bsschan when we are off-channel scanning
717 	 *    or otherwise doing background work
718 	 * ic_bsschan is the channel selected for operation; it may
719 	 *    be undefined (IEEE80211_CHAN_ANYC)
720 	 * ic_prevchan is a cached ``previous channel'' used to optimize
721 	 *    lookups when switching back+forth between two channels
722 	 *    (e.g. for dynamic turbo)
723 	 */
724 	db_printf("\tnchans %d", ic->ic_nchans);
725 #if 0
726 	struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX];
727 	uint8_t			ic_chan_avail[IEEE80211_CHAN_BYTES];
728 	uint8_t			ic_chan_active[IEEE80211_CHAN_BYTES];
729 	uint8_t			ic_chan_scan[IEEE80211_CHAN_BYTES];
730 #endif
731 	db_printf("\n");
732 	_db_show_channel("\tcurchan", ic->ic_curchan);
733 	db_printf("\n");
734 	_db_show_channel("\tbsschan", ic->ic_bsschan);
735 	db_printf("\n");
736 	_db_show_channel("\tprevchan", ic->ic_prevchan);
737 	db_printf("\n");
738 	db_printf("\tregdomain %p", &ic->ic_regdomain);
739 	db_printf("\n");
740 
741 	_db_show_channel("\tcsa_newchan", ic->ic_csa_newchan);
742 	db_printf(" csa_count %d", ic->ic_csa_count);
743 	db_printf( "dfs %p", &ic->ic_dfs);
744 	db_printf("\n");
745 
746 	db_printf("\tscan %p", ic->ic_scan);
747 	db_printf(" lastdata %d", ic->ic_lastdata);
748 	db_printf(" lastscan %d", ic->ic_lastscan);
749 	db_printf("\n");
750 
751 	db_printf("\tmax_keyix %d", ic->ic_max_keyix);
752 	db_printf(" hash_key 0x%x", ic->ic_hash_key);
753 	db_printf(" wme %p", &ic->ic_wme);
754 	if (!showsta)
755 		db_printf(" sta %p", &ic->ic_sta);
756 	db_printf("\n");
757 	db_printf("\tstageq@%p:\n", &ic->ic_stageq);
758 	_db_show_ageq("\t", &ic->ic_stageq);
759 	if (showsta)
760 		_db_show_node_table("\t", &ic->ic_sta);
761 
762 	db_printf("\tprotmode %d", ic->ic_protmode);
763 	db_printf("\tcurhtprotmode 0x%x", ic->ic_curhtprotmode);
764 	db_printf(" htprotmode %d", ic->ic_htprotmode);
765 	db_printf("\n");
766 
767 	db_printf("\tsuperg %p\n", ic->ic_superg);
768 
769 	db_printf("\tmontaps %d th %p txchan %p rh %p rxchan %p\n",
770 	    ic->ic_montaps, ic->ic_th, ic->ic_txchan, ic->ic_rh, ic->ic_rxchan);
771 
772 	if (showprocs) {
773 		DB_PRINTSYM("\t", "ic_vap_create", ic->ic_vap_create);
774 		DB_PRINTSYM("\t", "ic_vap_delete", ic->ic_vap_delete);
775 #if 0
776 		/* operating mode attachment */
777 		ieee80211vap_attach	ic_vattach[IEEE80211_OPMODE_MAX];
778 #endif
779 		DB_PRINTSYM("\t", "ic_newassoc", ic->ic_newassoc);
780 		DB_PRINTSYM("\t", "ic_getradiocaps", ic->ic_getradiocaps);
781 		DB_PRINTSYM("\t", "ic_setregdomain", ic->ic_setregdomain);
782 		DB_PRINTSYM("\t", "ic_send_mgmt", ic->ic_send_mgmt);
783 		DB_PRINTSYM("\t", "ic_raw_xmit", ic->ic_raw_xmit);
784 		DB_PRINTSYM("\t", "ic_updateslot", ic->ic_updateslot);
785 		DB_PRINTSYM("\t", "ic_update_mcast", ic->ic_update_mcast);
786 		DB_PRINTSYM("\t", "ic_update_promisc", ic->ic_update_promisc);
787 		DB_PRINTSYM("\t", "ic_node_alloc", ic->ic_node_alloc);
788 		DB_PRINTSYM("\t", "ic_node_free", ic->ic_node_free);
789 		DB_PRINTSYM("\t", "ic_node_cleanup", ic->ic_node_cleanup);
790 		DB_PRINTSYM("\t", "ic_node_getrssi", ic->ic_node_getrssi);
791 		DB_PRINTSYM("\t", "ic_node_getsignal", ic->ic_node_getsignal);
792 		DB_PRINTSYM("\t", "ic_node_getmimoinfo", ic->ic_node_getmimoinfo);
793 		DB_PRINTSYM("\t", "ic_scan_start", ic->ic_scan_start);
794 		DB_PRINTSYM("\t", "ic_scan_end", ic->ic_scan_end);
795 		DB_PRINTSYM("\t", "ic_set_channel", ic->ic_set_channel);
796 		DB_PRINTSYM("\t", "ic_scan_curchan", ic->ic_scan_curchan);
797 		DB_PRINTSYM("\t", "ic_scan_mindwell", ic->ic_scan_mindwell);
798 		DB_PRINTSYM("\t", "ic_recv_action", ic->ic_recv_action);
799 		DB_PRINTSYM("\t", "ic_send_action", ic->ic_send_action);
800 		DB_PRINTSYM("\t", "ic_addba_request", ic->ic_addba_request);
801 		DB_PRINTSYM("\t", "ic_addba_response", ic->ic_addba_response);
802 		DB_PRINTSYM("\t", "ic_addba_stop", ic->ic_addba_stop);
803 	}
804 	if (showscan) {
805 		db_printf("\n");
806 		_db_show_scan(ic->ic_scan, showprocs);
807 	}
808 	if (showvaps && !TAILQ_EMPTY(&ic->ic_vaps)) {
809 		db_printf("\n");
810 		TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
811 			_db_show_vap(vap, showmesh, showprocs);
812 	}
813 	if (showsta && !TAILQ_EMPTY(&ic->ic_sta.nt_node)) {
814 		const struct ieee80211_node_table *nt = &ic->ic_sta;
815 		const struct ieee80211_node *ni;
816 
817 		TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
818 			db_printf("\n");
819 			_db_show_sta(ni);
820 		}
821 	}
822 }
823 
824 static void
_db_show_all_vaps(void * arg,struct ieee80211com * ic)825 _db_show_all_vaps(void *arg, struct ieee80211com *ic)
826 {
827 	int showall = *(int *)arg;
828 
829 	if (!showall) {
830 		const struct ieee80211vap *vap;
831 		db_printf("%s: com %p vaps:", ic->ic_name, ic);
832 		TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
833 			db_printf(" %s(%p)", if_name(vap->iv_ifp), vap);
834 		db_printf("\n");
835 	} else
836 		_db_show_com(ic, 1, 1, 1, 1, 1);
837 }
838 
839 static void
_db_show_node_table(const char * tag,const struct ieee80211_node_table * nt)840 _db_show_node_table(const char *tag, const struct ieee80211_node_table *nt)
841 {
842 	int i;
843 
844 	db_printf("%s%s@%p:\n", tag, nt->nt_name, nt);
845 	db_printf("%s nodelock %p", tag, &nt->nt_nodelock);
846 	db_printf(" inact_init %d", nt->nt_inact_init);
847 	db_printf("%s keyixmax %d keyixmap %p\n",
848 	    tag, nt->nt_keyixmax, nt->nt_keyixmap);
849 	for (i = 0; i < nt->nt_keyixmax; i++) {
850 		const struct ieee80211_node *ni = nt->nt_keyixmap[i];
851 		if (ni != NULL)
852 			db_printf("%s [%3u] %p %s\n", tag, i, ni,
853 			    ether_sprintf(ni->ni_macaddr));
854 	}
855 }
856 
857 static void
_db_show_channel(const char * tag,const struct ieee80211_channel * c)858 _db_show_channel(const char *tag, const struct ieee80211_channel *c)
859 {
860 	db_printf("%s ", tag);
861 	if (c == NULL)
862 		db_printf("<NULL>");
863 	else if (c == IEEE80211_CHAN_ANYC)
864 		db_printf("<ANY>");
865 	else
866 		db_printf("[%u (%u) flags=%b maxreg %d maxpow %d minpow %d state 0x%x extieee %u]",
867 		    c->ic_freq, c->ic_ieee,
868 		    c->ic_flags, IEEE80211_CHAN_BITS,
869 		    c->ic_maxregpower, c->ic_maxpower, c->ic_minpower,
870 		    c->ic_state, c->ic_extieee);
871 }
872 
873 static void
_db_show_ssid(const char * tag,int ix,int len,const uint8_t * ssid)874 _db_show_ssid(const char *tag, int ix, int len, const uint8_t *ssid)
875 {
876 	const uint8_t *p;
877 	int i;
878 
879 	db_printf(tag, ix);
880 
881 	if (len > IEEE80211_NWID_LEN)
882 		len = IEEE80211_NWID_LEN;
883 	/* determine printable or not */
884 	for (i = 0, p = ssid; i < len; i++, p++) {
885 		if (*p < ' ' || *p > 0x7e)
886 			break;
887 	}
888 	if (i == len) {
889 		db_printf("\"");
890 		for (i = 0, p = ssid; i < len; i++, p++)
891 			db_printf("%c", *p);
892 		db_printf("\"");
893 	} else {
894 		db_printf("0x");
895 		for (i = 0, p = ssid; i < len; i++, p++)
896 			db_printf("%02x", *p);
897 	}
898 }
899 
900 static void
_db_show_appie(const char * tag,const struct ieee80211_appie * ie)901 _db_show_appie(const char *tag, const struct ieee80211_appie *ie)
902 {
903 	const uint8_t *p;
904 	int i;
905 
906 	if (ie == NULL)
907 		return;
908 	db_printf("%s [0x", tag);
909 	for (i = 0, p = ie->ie_data; i < ie->ie_len; i++, p++)
910 		db_printf("%02x", *p);
911 	db_printf("]\n");
912 }
913 
914 static void
_db_show_key(const char * tag,int ix,const struct ieee80211_key * wk)915 _db_show_key(const char *tag, int ix, const struct ieee80211_key *wk)
916 {
917 	static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
918 	const struct ieee80211_cipher *cip = wk->wk_cipher;
919 	int keylen = wk->wk_keylen;
920 
921 	db_printf(tag, ix);
922 	switch (cip->ic_cipher) {
923 	case IEEE80211_CIPHER_WEP:
924 		/* compatibility */
925 		db_printf(" wepkey %u:%s", wk->wk_keyix,
926 		    keylen <= 5 ? "40-bit" :
927 		    keylen <= 13 ? "104-bit" : "128-bit");
928 		break;
929 	case IEEE80211_CIPHER_TKIP:
930 		if (keylen > 128/8)
931 			keylen -= 128/8;	/* ignore MIC for now */
932 		db_printf(" TKIP %u:%u-bit", wk->wk_keyix, 8*keylen);
933 		break;
934 	case IEEE80211_CIPHER_AES_OCB:
935 		db_printf(" AES-OCB %u:%u-bit", wk->wk_keyix, 8*keylen);
936 		break;
937 	case IEEE80211_CIPHER_AES_CCM:
938 		db_printf(" AES-CCM %u:%u-bit", wk->wk_keyix, 8*keylen);
939 		break;
940 	case IEEE80211_CIPHER_CKIP:
941 		db_printf(" CKIP %u:%u-bit", wk->wk_keyix, 8*keylen);
942 		break;
943 	case IEEE80211_CIPHER_NONE:
944 		db_printf(" NULL %u:%u-bit", wk->wk_keyix, 8*keylen);
945 		break;
946 	default:
947 		db_printf(" UNKNOWN (0x%x) %u:%u-bit",
948 			cip->ic_cipher, wk->wk_keyix, 8*keylen);
949 		break;
950 	}
951 	if (wk->wk_rxkeyix != wk->wk_keyix)
952 		db_printf(" rxkeyix %u", wk->wk_rxkeyix);
953 	if (memcmp(wk->wk_key, zerodata, keylen) != 0) {
954 		int i;
955 
956 		db_printf(" <");
957 		for (i = 0; i < keylen; i++)
958 			db_printf("%02x", wk->wk_key[i]);
959 		db_printf(">");
960 		if (cip->ic_cipher != IEEE80211_CIPHER_WEP &&
961 		    wk->wk_keyrsc[IEEE80211_NONQOS_TID] != 0)
962 			db_printf(" rsc %ju", (uintmax_t)wk->wk_keyrsc[IEEE80211_NONQOS_TID]);
963 		if (cip->ic_cipher != IEEE80211_CIPHER_WEP &&
964 		    wk->wk_keytsc != 0)
965 			db_printf(" tsc %ju", (uintmax_t)wk->wk_keytsc);
966 		db_printf(" flags=%b", wk->wk_flags, IEEE80211_KEY_BITS);
967 	}
968 	db_printf("\n");
969 }
970 
971 static void
printrate(const char * tag,int v)972 printrate(const char *tag, int v)
973 {
974 	if (v == IEEE80211_FIXED_RATE_NONE)
975 		db_printf(" %s <none>", tag);
976 	else if (v == 11)
977 		db_printf(" %s 5.5", tag);
978 	else if (v & IEEE80211_RATE_MCS)
979 		db_printf(" %s MCS%d", tag, v &~ IEEE80211_RATE_MCS);
980 	else
981 		db_printf(" %s %d", tag, v/2);
982 }
983 
984 static void
_db_show_roamparams(const char * tag,const void * arg,const struct ieee80211_roamparam * rp)985 _db_show_roamparams(const char *tag, const void *arg,
986     const struct ieee80211_roamparam *rp)
987 {
988 
989 	db_printf(tag, arg);
990 	if (rp->rssi & 1)
991 		db_printf(" rssi %u.5", rp->rssi/2);
992 	else
993 		db_printf(" rssi %u", rp->rssi/2);
994 	printrate("rate", rp->rate);
995 }
996 
997 static void
_db_show_txparams(const char * tag,const void * arg,const struct ieee80211_txparam * tp)998 _db_show_txparams(const char *tag, const void *arg,
999     const struct ieee80211_txparam *tp)
1000 {
1001 
1002 	db_printf(tag, arg);
1003 	printrate("ucastrate", tp->ucastrate);
1004 	printrate("mcastrate", tp->mcastrate);
1005 	printrate("mgmtrate", tp->mgmtrate);
1006 	db_printf(" maxretry %d", tp->maxretry);
1007 }
1008 
1009 static void
_db_show_ageq(const char * tag,const struct ieee80211_ageq * q)1010 _db_show_ageq(const char *tag, const struct ieee80211_ageq *q)
1011 {
1012 	const struct mbuf *m;
1013 
1014 	db_printf("%s lock %p len %d maxlen %d drops %d head %p tail %p\n",
1015 	    tag, &q->aq_lock, q->aq_len, q->aq_maxlen, q->aq_drops,
1016 	    q->aq_head, q->aq_tail);
1017 	for (m = q->aq_head; m != NULL; m = m->m_nextpkt)
1018 		db_printf("%s %p (len %d, %b)\n", tag, m, m->m_len,
1019 		    /* XXX could be either TX or RX but is mostly TX */
1020 		    m->m_flags, IEEE80211_MBUF_TX_FLAG_BITS);
1021 }
1022 
1023 static void
_db_show_stats(const struct ieee80211_stats * is)1024 _db_show_stats(const struct ieee80211_stats *is)
1025 {
1026 }
1027 
1028 #ifdef IEEE80211_SUPPORT_MESH
1029 static void
_db_show_mesh(const struct ieee80211_mesh_state * ms)1030 _db_show_mesh(const struct ieee80211_mesh_state *ms)
1031 {
1032 	struct ieee80211_mesh_route *rt;
1033 	int i;
1034 
1035 	_db_show_ssid(" meshid ", 0, ms->ms_idlen, ms->ms_id);
1036 	db_printf("nextseq %u ttl %u flags 0x%x\n", ms->ms_seq,
1037 	    ms->ms_ttl, ms->ms_flags);
1038 	db_printf("routing table:\n");
1039 	i = 0;
1040 	TAILQ_FOREACH(rt, &ms->ms_routes, rt_next) {
1041 		db_printf("entry %d:\tdest: %6D nexthop: %6D metric: %u", i,
1042 		    rt->rt_dest, ":", rt->rt_nexthop, ":", rt->rt_metric);
1043 
1044 		db_printf("\tlifetime: %u lastseq: %u priv: %p\n",
1045 		    ieee80211_mesh_rt_update(rt, 0),
1046 		    rt->rt_lastmseq, rt->rt_priv);
1047 		i++;
1048 	}
1049 }
1050 #endif /* IEEE80211_SUPPORT_MESH */
1051 #endif /* DDB */
1052