1/*-
2 * Copyright (c) 2007-2009 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#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#ifdef IEEE80211_SUPPORT_TDMA
52#include <net80211/ieee80211_tdma.h>
53#endif
54#ifdef IEEE80211_SUPPORT_MESH
55#include <net80211/ieee80211_mesh.h>
56#endif
57
58#include <ddb/ddb.h>
59#include <ddb/db_sym.h>
60
61#define DB_PRINTSYM(prefix, name, addr) do { \
62	db_printf("%s%-25s : ",  prefix, name); \
63	db_printsym((db_addr_t) addr, DB_STGY_ANY); \
64	db_printf("\n"); \
65} while (0)
66
67static void _db_show_sta(const struct ieee80211_node *);
68static void _db_show_vap(const struct ieee80211vap *, int, int);
69static void _db_show_com(const struct ieee80211com *,
70	int showvaps, int showsta, int showmesh, int showprocs);
71
72static void _db_show_all_vaps(void *, struct ieee80211com *);
73
74static void _db_show_node_table(const char *tag,
75	const struct ieee80211_node_table *);
76static void _db_show_channel(const char *tag, const struct ieee80211_channel *);
77static void _db_show_ssid(const char *tag, int ix, int len, const uint8_t *);
78static void _db_show_appie(const char *tag, const struct ieee80211_appie *);
79static void _db_show_key(const char *tag, int ix, const struct ieee80211_key *);
80static void _db_show_roamparams(const char *tag, const void *arg,
81	const struct ieee80211_roamparam *rp);
82static void _db_show_txparams(const char *tag, const void *arg,
83	const struct ieee80211_txparam *tp);
84static void _db_show_ageq(const char *tag, const struct ieee80211_ageq *q);
85static void _db_show_stats(const struct ieee80211_stats *);
86#ifdef IEEE80211_SUPPORT_MESH
87static void _db_show_mesh(const struct ieee80211_mesh_state *);
88#endif
89
90DB_SHOW_COMMAND(sta, db_show_sta)
91{
92	if (!have_addr) {
93		db_printf("usage: show sta <addr>\n");
94		return;
95	}
96	_db_show_sta((const struct ieee80211_node *) addr);
97}
98
99DB_SHOW_COMMAND(statab, db_show_statab)
100{
101	if (!have_addr) {
102		db_printf("usage: show statab <addr>\n");
103		return;
104	}
105	_db_show_node_table("", (const struct ieee80211_node_table *) addr);
106}
107
108DB_SHOW_COMMAND(vap, db_show_vap)
109{
110	int i, showmesh = 0, showprocs = 0;
111
112	if (!have_addr) {
113		db_printf("usage: show vap <addr>\n");
114		return;
115	}
116	for (i = 0; modif[i] != '\0'; i++)
117		switch (modif[i]) {
118		case 'a':
119			showprocs = 1;
120			showmesh = 1;
121			break;
122		case 'm':
123			showmesh = 1;
124			break;
125		case 'p':
126			showprocs = 1;
127			break;
128		}
129	_db_show_vap((const struct ieee80211vap *) addr, showmesh, showprocs);
130}
131
132DB_SHOW_COMMAND(com, db_show_com)
133{
134	const struct ieee80211com *ic;
135	int i, showprocs = 0, showvaps = 0, showsta = 0, showmesh = 0;
136
137	if (!have_addr) {
138		db_printf("usage: show com <addr>\n");
139		return;
140	}
141	for (i = 0; modif[i] != '\0'; i++)
142		switch (modif[i]) {
143		case 'a':
144			showsta = showmesh = showvaps = showprocs = 1;
145			break;
146		case 's':
147			showsta = 1;
148			break;
149		case 'm':
150			showmesh = 1;
151			break;
152		case 'v':
153			showvaps = 1;
154			break;
155		case 'p':
156			showprocs = 1;
157			break;
158		}
159
160	ic = (const struct ieee80211com *) addr;
161	_db_show_com(ic, showvaps, showsta, showmesh, showprocs);
162}
163
164DB_SHOW_ALL_COMMAND(vaps, db_show_all_vaps)
165{
166	int i, showall = 0;
167
168	for (i = 0; modif[i] != '\0'; i++)
169		switch (modif[i]) {
170		case 'a':
171			showall = 1;
172			break;
173		}
174
175	ieee80211_iterate_coms(_db_show_all_vaps, &showall);
176}
177
178#ifdef IEEE80211_SUPPORT_MESH
179DB_SHOW_ALL_COMMAND(mesh, db_show_mesh)
180{
181	const struct ieee80211_mesh_state *ms;
182
183	if (!have_addr) {
184		db_printf("usage: show mesh <addr>\n");
185		return;
186	}
187	ms = (const struct ieee80211_mesh_state *) addr;
188	_db_show_mesh(ms);
189}
190#endif /* IEEE80211_SUPPORT_MESH */
191
192static void
193_db_show_txampdu(const char *sep, int ix, const struct ieee80211_tx_ampdu *tap)
194{
195	db_printf("%stxampdu[%d]: %p flags %b %s\n",
196		sep, ix, tap, tap->txa_flags, IEEE80211_AGGR_BITS,
197		ieee80211_wme_acnames[TID_TO_WME_AC(tap->txa_tid)]);
198	db_printf("%s  token %u lastsample %d pkts %d avgpps %d qbytes %d qframes %d\n",
199		sep, tap->txa_token, tap->txa_lastsample, tap->txa_pkts,
200		tap->txa_avgpps, tap->txa_qbytes, tap->txa_qframes);
201	db_printf("%s  start %u seqpending %u wnd %u attempts %d nextrequest %d\n",
202		sep, tap->txa_start, tap->txa_seqpending, tap->txa_wnd,
203		tap->txa_attempts, tap->txa_nextrequest);
204	/* XXX timer */
205}
206
207static void
208_db_show_rxampdu(const char *sep, int ix, const struct ieee80211_rx_ampdu *rap)
209{
210	int i;
211
212	db_printf("%srxampdu[%d]: %p flags 0x%x tid %u\n",
213		sep, ix, rap, rap->rxa_flags, ix /*XXX */);
214	db_printf("%s  qbytes %d qframes %d seqstart %u start %u wnd %u\n",
215		sep, rap->rxa_qbytes, rap->rxa_qframes,
216		rap->rxa_seqstart, rap->rxa_start, rap->rxa_wnd);
217	db_printf("%s  age %d nframes %d\n", sep,
218		rap->rxa_age, rap->rxa_nframes);
219	for (i = 0; i < IEEE80211_AGGR_BAWMAX; i++)
220		if (rap->rxa_m[i] != NULL)
221			db_printf("%s  m[%2u:%4u] %p\n", sep, i,
222			    IEEE80211_SEQ_ADD(rap->rxa_start, i),
223			    rap->rxa_m[i]);
224}
225
226static void
227_db_show_sta(const struct ieee80211_node *ni)
228{
229	int i;
230
231	db_printf("0x%p: mac %s refcnt %d\n", ni,
232		ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni));
233	db_printf("\tvap %p wdsvap %p ic %p table %p\n",
234		ni->ni_vap, ni->ni_wdsvap, ni->ni_ic, ni->ni_table);
235	db_printf("\tflags=%b\n", ni->ni_flags, IEEE80211_NODE_BITS);
236	db_printf("\tauthmode %u ath_flags 0x%x ath_defkeyix %u\n",
237		ni->ni_authmode, ni->ni_ath_flags, ni->ni_ath_defkeyix);
238	db_printf("\tassocid 0x%x txpower %u vlan %u\n",
239		ni->ni_associd, ni->ni_txpower, ni->ni_vlan);
240	db_printf("\tjointime %d (%lu secs) challenge %p\n",
241		ni->ni_jointime, (unsigned long)(time_uptime - ni->ni_jointime),
242		ni->ni_challenge);
243	db_printf("\ties: data %p len %d\n", ni->ni_ies.data, ni->ni_ies.len);
244	db_printf("\t[wpa_ie %p rsn_ie %p wme_ie %p ath_ie %p\n",
245		ni->ni_ies.wpa_ie, ni->ni_ies.rsn_ie, ni->ni_ies.wme_ie,
246		ni->ni_ies.ath_ie);
247	db_printf("\t htcap_ie %p htinfo_ie %p]\n",
248		ni->ni_ies.htcap_ie, ni->ni_ies.htinfo_ie);
249	if (ni->ni_flags & IEEE80211_NODE_QOS) {
250		for (i = 0; i < WME_NUM_TID; i++) {
251			if (ni->ni_txseqs[i] || ni->ni_rxseqs[i])
252				db_printf("\t[%u] txseq %u rxseq %u fragno %u\n",
253				    i, ni->ni_txseqs[i],
254				    ni->ni_rxseqs[i] >> IEEE80211_SEQ_SEQ_SHIFT,
255				    ni->ni_rxseqs[i] & IEEE80211_SEQ_FRAG_MASK);
256		}
257	}
258	db_printf("\ttxseq %u rxseq %u fragno %u rxfragstamp %u\n",
259		ni->ni_txseqs[IEEE80211_NONQOS_TID],
260		ni->ni_rxseqs[IEEE80211_NONQOS_TID] >> IEEE80211_SEQ_SEQ_SHIFT,
261		ni->ni_rxseqs[IEEE80211_NONQOS_TID] & IEEE80211_SEQ_FRAG_MASK,
262		ni->ni_rxfragstamp);
263	db_printf("\trxfrag[0] %p rxfrag[1] %p rxfrag[2] %p\n",
264		ni->ni_rxfrag[0], ni->ni_rxfrag[1], ni->ni_rxfrag[2]);
265	_db_show_key("\tucastkey", 0, &ni->ni_ucastkey);
266	db_printf("\tavgrssi 0x%x (rssi %d) noise %d\n",
267		ni->ni_avgrssi, IEEE80211_RSSI_GET(ni->ni_avgrssi),
268		ni->ni_noise);
269	db_printf("\tintval %u capinfo %b\n",
270		ni->ni_intval, ni->ni_capinfo, IEEE80211_CAPINFO_BITS);
271	db_printf("\tbssid %s", ether_sprintf(ni->ni_bssid));
272	_db_show_ssid(" essid ", 0, ni->ni_esslen, ni->ni_essid);
273	db_printf("\n");
274	_db_show_channel("\tchannel", ni->ni_chan);
275	db_printf("\n");
276	db_printf("\terp %b dtim_period %u dtim_count %u\n",
277		ni->ni_erp, IEEE80211_ERP_BITS,
278		ni->ni_dtim_period, ni->ni_dtim_count);
279
280	db_printf("\thtcap %b htparam 0x%x htctlchan %u ht2ndchan %u\n",
281		ni->ni_htcap, IEEE80211_HTCAP_BITS,
282		ni->ni_htparam, ni->ni_htctlchan, ni->ni_ht2ndchan);
283	db_printf("\thtopmode 0x%x htstbc 0x%x chw %u\n",
284		ni->ni_htopmode, ni->ni_htstbc, ni->ni_chw);
285
286	/* XXX ampdu state */
287	for (i = 0; i < WME_NUM_TID; i++)
288		if (ni->ni_tx_ampdu[i].txa_flags & IEEE80211_AGGR_SETUP)
289			_db_show_txampdu("\t", i, &ni->ni_tx_ampdu[i]);
290	for (i = 0; i < WME_NUM_TID; i++)
291		if (ni->ni_rx_ampdu[i].rxa_flags)
292			_db_show_rxampdu("\t", i, &ni->ni_rx_ampdu[i]);
293
294	db_printf("\tinact %u inact_reload %u txrate %u\n",
295		ni->ni_inact, ni->ni_inact_reload, ni->ni_txrate);
296#ifdef IEEE80211_SUPPORT_MESH
297	_db_show_ssid("\tmeshid ", 0, ni->ni_meshidlen, ni->ni_meshid);
298	db_printf(" mlstate %b mllid 0x%x mlpid 0x%x mlrcnt %u mltval %u\n",
299	    ni->ni_mlstate, IEEE80211_MESH_MLSTATE_BITS,
300	    ni->ni_mllid, ni->ni_mlpid, ni->ni_mlrcnt, ni->ni_mltval);
301#endif
302}
303
304#ifdef IEEE80211_SUPPORT_TDMA
305static void
306_db_show_tdma(const char *sep, const struct ieee80211_tdma_state *ts, int showprocs)
307{
308	db_printf("%stdma %p:\n", sep, ts);
309	db_printf("%s  version %u slot %u bintval %u peer %p\n", sep,
310	    ts->tdma_version, ts->tdma_slot, ts->tdma_bintval, ts->tdma_peer);
311	db_printf("%s  slotlen %u slotcnt %u", sep,
312	    ts->tdma_slotlen, ts->tdma_slotcnt);
313	db_printf(" inuse 0x%x active 0x%x count %d\n",
314	    ts->tdma_inuse[0], ts->tdma_active[0], ts->tdma_count);
315	if (showprocs) {
316		DB_PRINTSYM(sep, "  tdma_newstate", ts->tdma_newstate);
317		DB_PRINTSYM(sep, "  tdma_recv_mgmt", ts->tdma_recv_mgmt);
318		DB_PRINTSYM(sep, "  tdma_opdetach", ts->tdma_opdetach);
319	}
320}
321#endif /* IEEE80211_SUPPORT_TDMA */
322
323static void
324_db_show_vap(const struct ieee80211vap *vap, int showmesh, int showprocs)
325{
326	const struct ieee80211com *ic = vap->iv_ic;
327	int i;
328
329	db_printf("%p:", vap);
330	db_printf(" bss %p", vap->iv_bss);
331	db_printf(" myaddr %s", ether_sprintf(vap->iv_myaddr));
332	db_printf("\n");
333
334	db_printf("\topmode %s", ieee80211_opmode_name[vap->iv_opmode]);
335#ifdef IEEE80211_SUPPORT_MESH
336	if (vap->iv_opmode == IEEE80211_M_MBSS)
337		db_printf("(%p)", vap->iv_mesh);
338#endif
339	db_printf(" state %s", ieee80211_state_name[vap->iv_state]);
340	db_printf(" ifp %p(%s)", vap->iv_ifp, vap->iv_ifp->if_xname);
341	db_printf("\n");
342
343	db_printf("\tic %p", vap->iv_ic);
344	db_printf(" media %p", &vap->iv_media);
345	db_printf(" bpf_if %p", vap->iv_rawbpf);
346	db_printf(" mgtsend %p", &vap->iv_mgtsend);
347#if 0
348	struct sysctllog	*iv_sysctl;	/* dynamic sysctl context */
349#endif
350	db_printf("\n");
351	db_printf("\tdebug=%b\n", vap->iv_debug, IEEE80211_MSG_BITS);
352
353	db_printf("\tflags=%b\n", vap->iv_flags, IEEE80211_F_BITS);
354	db_printf("\tflags_ext=%b\n", vap->iv_flags_ext, IEEE80211_FEXT_BITS);
355	db_printf("\tflags_ht=%b\n", vap->iv_flags_ht, IEEE80211_FHT_BITS);
356	db_printf("\tflags_ven=%b\n", vap->iv_flags_ven, IEEE80211_FVEN_BITS);
357	db_printf("\tcaps=%b\n", vap->iv_caps, IEEE80211_C_BITS);
358	db_printf("\thtcaps=%b\n", vap->iv_htcaps, IEEE80211_C_HTCAP_BITS);
359
360	_db_show_stats(&vap->iv_stats);
361
362	db_printf("\tinact_init %d", vap->iv_inact_init);
363	db_printf(" inact_auth %d", vap->iv_inact_auth);
364	db_printf(" inact_run %d", vap->iv_inact_run);
365	db_printf(" inact_probe %d", vap->iv_inact_probe);
366	db_printf("\n");
367
368	db_printf("\tdes_nssid %d", vap->iv_des_nssid);
369	if (vap->iv_des_nssid)
370		_db_show_ssid(" des_ssid[%u] ", 0,
371		    vap->iv_des_ssid[0].len, vap->iv_des_ssid[0].ssid);
372	db_printf(" des_bssid %s", ether_sprintf(vap->iv_des_bssid));
373	db_printf("\n");
374	db_printf("\tdes_mode %d", vap->iv_des_mode);
375	_db_show_channel(" des_chan", vap->iv_des_chan);
376	db_printf("\n");
377#if 0
378	int			iv_nicknamelen;	/* XXX junk */
379	uint8_t			iv_nickname[IEEE80211_NWID_LEN];
380#endif
381	db_printf("\tbgscanidle %u", vap->iv_bgscanidle);
382	db_printf(" bgscanintvl %u", vap->iv_bgscanintvl);
383	db_printf(" scanvalid %u", vap->iv_scanvalid);
384	db_printf("\n");
385	db_printf("\tscanreq_duration %u", vap->iv_scanreq_duration);
386	db_printf(" scanreq_mindwell %u", vap->iv_scanreq_mindwell);
387	db_printf(" scanreq_maxdwell %u", vap->iv_scanreq_maxdwell);
388	db_printf("\n");
389	db_printf("\tscanreq_flags 0x%x", vap->iv_scanreq_flags);
390	db_printf(" scanreq_nssid %d", vap->iv_scanreq_nssid);
391	for (i = 0; i < vap->iv_scanreq_nssid; i++)
392		_db_show_ssid(" scanreq_ssid[%u]", i,
393		    vap->iv_scanreq_ssid[i].len, vap->iv_scanreq_ssid[i].ssid);
394	db_printf(" roaming %d", vap->iv_roaming);
395	db_printf("\n");
396	for (i = IEEE80211_MODE_11A; i < IEEE80211_MODE_MAX; i++)
397		if (isset(ic->ic_modecaps, i)) {
398			_db_show_roamparams("\troamparms[%s]",
399			    ieee80211_phymode_name[i], &vap->iv_roamparms[i]);
400			db_printf("\n");
401		}
402
403	db_printf("\tbmissthreshold %u", vap->iv_bmissthreshold);
404	db_printf(" bmiss_max %u", vap->iv_bmiss_count);
405	db_printf(" bmiss_max %d", vap->iv_bmiss_max);
406	db_printf("\n");
407	db_printf("\tswbmiss_count %u", vap->iv_swbmiss_count);
408	db_printf(" swbmiss_period %u", vap->iv_swbmiss_period);
409	db_printf(" swbmiss %p", &vap->iv_swbmiss);
410	db_printf("\n");
411
412	db_printf("\tampdu_rxmax %d", vap->iv_ampdu_rxmax);
413	db_printf(" ampdu_density %d", vap->iv_ampdu_density);
414	db_printf(" ampdu_limit %d", vap->iv_ampdu_limit);
415	db_printf(" amsdu_limit %d", vap->iv_amsdu_limit);
416	db_printf("\n");
417
418	db_printf("\tmax_aid %u", vap->iv_max_aid);
419	db_printf(" aid_bitmap %p", vap->iv_aid_bitmap);
420	db_printf("\n");
421	db_printf("\tsta_assoc %u", vap->iv_sta_assoc);
422	db_printf(" ps_sta %u", vap->iv_ps_sta);
423	db_printf(" ps_pending %u", vap->iv_ps_pending);
424	db_printf(" tim_len %u", vap->iv_tim_len);
425	db_printf(" tim_bitmap %p", vap->iv_tim_bitmap);
426	db_printf("\n");
427	db_printf("\tdtim_period %u", vap->iv_dtim_period);
428	db_printf(" dtim_count %u", vap->iv_dtim_count);
429	db_printf(" set_tim %p", vap->iv_set_tim);
430	db_printf(" csa_count %d", vap->iv_csa_count);
431	db_printf("\n");
432
433	db_printf("\trtsthreshold %u", vap->iv_rtsthreshold);
434	db_printf(" fragthreshold %u", vap->iv_fragthreshold);
435	db_printf(" inact_timer %d", vap->iv_inact_timer);
436	db_printf("\n");
437	for (i = IEEE80211_MODE_11A; i < IEEE80211_MODE_MAX; i++)
438		if (isset(ic->ic_modecaps, i)) {
439			_db_show_txparams("\ttxparms[%s]",
440			    ieee80211_phymode_name[i], &vap->iv_txparms[i]);
441			db_printf("\n");
442		}
443
444	/* application-specified IE's to attach to mgt frames */
445	_db_show_appie("\tappie_beacon", vap->iv_appie_beacon);
446	_db_show_appie("\tappie_probereq", vap->iv_appie_probereq);
447	_db_show_appie("\tappie_proberesp", vap->iv_appie_proberesp);
448	_db_show_appie("\tappie_assocreq", vap->iv_appie_assocreq);
449	_db_show_appie("\tappie_asscoresp", vap->iv_appie_assocresp);
450	_db_show_appie("\tappie_wpa", vap->iv_appie_wpa);
451	if (vap->iv_wpa_ie != NULL || vap->iv_rsn_ie != NULL) {
452		if (vap->iv_wpa_ie != NULL)
453			db_printf("\twpa_ie %p", vap->iv_wpa_ie);
454		if (vap->iv_rsn_ie != NULL)
455			db_printf("\trsn_ie %p", vap->iv_rsn_ie);
456		db_printf("\n");
457	}
458	db_printf("\tmax_keyix %u", vap->iv_max_keyix);
459	db_printf(" def_txkey %d", vap->iv_def_txkey);
460	db_printf("\n");
461	for (i = 0; i < IEEE80211_WEP_NKID; i++)
462		_db_show_key("\tnw_keys[%u]", i, &vap->iv_nw_keys[i]);
463
464	db_printf("\tauth %p(%s)", vap->iv_auth, vap->iv_auth->ia_name);
465	db_printf(" ec %p", vap->iv_ec);
466
467	db_printf(" acl %p", vap->iv_acl);
468	db_printf(" as %p", vap->iv_as);
469	db_printf("\n");
470#ifdef IEEE80211_SUPPORT_MESH
471	if (showmesh && vap->iv_mesh != NULL)
472		_db_show_mesh(vap->iv_mesh);
473#endif
474#ifdef IEEE80211_SUPPORT_TDMA
475	if (vap->iv_tdma != NULL)
476		_db_show_tdma("\t", vap->iv_tdma, showprocs);
477#endif /* IEEE80211_SUPPORT_TDMA */
478	if (showprocs) {
479		DB_PRINTSYM("\t", "iv_key_alloc", vap->iv_key_alloc);
480		DB_PRINTSYM("\t", "iv_key_delete", vap->iv_key_delete);
481		DB_PRINTSYM("\t", "iv_key_set", vap->iv_key_set);
482		DB_PRINTSYM("\t", "iv_key_update_begin", vap->iv_key_update_begin);
483		DB_PRINTSYM("\t", "iv_key_update_end", vap->iv_key_update_end);
484		DB_PRINTSYM("\t", "iv_opdetach", vap->iv_opdetach);
485		DB_PRINTSYM("\t", "iv_input", vap->iv_input);
486		DB_PRINTSYM("\t", "iv_recv_mgmt", vap->iv_recv_mgmt);
487		DB_PRINTSYM("\t", "iv_deliver_data", vap->iv_deliver_data);
488		DB_PRINTSYM("\t", "iv_bmiss", vap->iv_bmiss);
489		DB_PRINTSYM("\t", "iv_reset", vap->iv_reset);
490		DB_PRINTSYM("\t", "iv_update_beacon", vap->iv_update_beacon);
491		DB_PRINTSYM("\t", "iv_newstate", vap->iv_newstate);
492		DB_PRINTSYM("\t", "iv_output", vap->iv_output);
493	}
494}
495
496static void
497_db_show_com(const struct ieee80211com *ic, int showvaps, int showsta,
498    int showmesh, int showprocs)
499{
500	struct ieee80211vap *vap;
501
502	db_printf("%p:", ic);
503	TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
504		db_printf(" %s(%p)", vap->iv_ifp->if_xname, vap);
505	db_printf("\n");
506	db_printf("\tsoftc %p", ic->ic_softc);
507	db_printf("\tname %s", ic->ic_name);
508	db_printf(" comlock %p", &ic->ic_comlock);
509	db_printf(" txlock %p", &ic->ic_txlock);
510	db_printf(" fflock %p", &ic->ic_fflock);
511	db_printf("\n");
512	db_printf("\theadroom %d", ic->ic_headroom);
513	db_printf(" phytype %d", ic->ic_phytype);
514	db_printf(" opmode %s", ieee80211_opmode_name[ic->ic_opmode]);
515	db_printf("\n");
516	db_printf(" inact %p", &ic->ic_inact);
517	db_printf("\n");
518
519	db_printf("\tflags=%b\n", ic->ic_flags, IEEE80211_F_BITS);
520	db_printf("\tflags_ext=%b\n", ic->ic_flags_ext, IEEE80211_FEXT_BITS);
521	db_printf("\tflags_ht=%b\n", ic->ic_flags_ht, IEEE80211_FHT_BITS);
522	db_printf("\tflags_ven=%b\n", ic->ic_flags_ven, IEEE80211_FVEN_BITS);
523	db_printf("\tcaps=%b\n", ic->ic_caps, IEEE80211_C_BITS);
524	db_printf("\tcryptocaps=%b\n",
525	    ic->ic_cryptocaps, IEEE80211_CRYPTO_BITS);
526	db_printf("\thtcaps=%b\n", ic->ic_htcaps, IEEE80211_HTCAP_BITS);
527
528#if 0
529	uint8_t			ic_modecaps[2];	/* set of mode capabilities */
530#endif
531	db_printf("\tcurmode %u", ic->ic_curmode);
532	db_printf(" promisc %u", ic->ic_promisc);
533	db_printf(" allmulti %u", ic->ic_allmulti);
534	db_printf(" nrunning %u", ic->ic_nrunning);
535	db_printf("\n");
536	db_printf("\tbintval %u", ic->ic_bintval);
537	db_printf(" lintval %u", ic->ic_lintval);
538	db_printf(" holdover %u", ic->ic_holdover);
539	db_printf(" txpowlimit %u", ic->ic_txpowlimit);
540	db_printf("\n");
541#if 0
542	struct ieee80211_rateset ic_sup_rates[IEEE80211_MODE_MAX];
543#endif
544	/*
545	 * Channel state:
546	 *
547	 * ic_channels is the set of available channels for the device;
548	 *    it is setup by the driver
549	 * ic_nchans is the number of valid entries in ic_channels
550	 * ic_chan_avail is a bit vector of these channels used to check
551	 *    whether a channel is available w/o searching the channel table.
552	 * ic_chan_active is a (potentially) constrained subset of
553	 *    ic_chan_avail that reflects any mode setting or user-specified
554	 *    limit on the set of channels to use/scan
555	 * ic_curchan is the current channel the device is set to; it may
556	 *    be different from ic_bsschan when we are off-channel scanning
557	 *    or otherwise doing background work
558	 * ic_bsschan is the channel selected for operation; it may
559	 *    be undefined (IEEE80211_CHAN_ANYC)
560	 * ic_prevchan is a cached ``previous channel'' used to optimize
561	 *    lookups when switching back+forth between two channels
562	 *    (e.g. for dynamic turbo)
563	 */
564	db_printf("\tnchans %d", ic->ic_nchans);
565#if 0
566	struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX];
567	uint8_t			ic_chan_avail[IEEE80211_CHAN_BYTES];
568	uint8_t			ic_chan_active[IEEE80211_CHAN_BYTES];
569	uint8_t			ic_chan_scan[IEEE80211_CHAN_BYTES];
570#endif
571	db_printf("\n");
572	_db_show_channel("\tcurchan", ic->ic_curchan);
573	db_printf("\n");
574	_db_show_channel("\tbsschan", ic->ic_bsschan);
575	db_printf("\n");
576	_db_show_channel("\tprevchan", ic->ic_prevchan);
577	db_printf("\n");
578	db_printf("\tregdomain %p", &ic->ic_regdomain);
579	db_printf("\n");
580
581	_db_show_channel("\tcsa_newchan", ic->ic_csa_newchan);
582	db_printf(" csa_count %d", ic->ic_csa_count);
583	db_printf( "dfs %p", &ic->ic_dfs);
584	db_printf("\n");
585
586	db_printf("\tscan %p", ic->ic_scan);
587	db_printf(" lastdata %d", ic->ic_lastdata);
588	db_printf(" lastscan %d", ic->ic_lastscan);
589	db_printf("\n");
590
591	db_printf("\tmax_keyix %d", ic->ic_max_keyix);
592	db_printf(" hash_key 0x%x", ic->ic_hash_key);
593	db_printf(" wme %p", &ic->ic_wme);
594	if (!showsta)
595		db_printf(" sta %p", &ic->ic_sta);
596	db_printf("\n");
597	db_printf("\tstageq@%p:\n", &ic->ic_stageq);
598	_db_show_ageq("\t", &ic->ic_stageq);
599	if (showsta)
600		_db_show_node_table("\t", &ic->ic_sta);
601
602	db_printf("\tprotmode %d", ic->ic_protmode);
603	db_printf(" nonerpsta %u", ic->ic_nonerpsta);
604	db_printf(" longslotsta %u", ic->ic_longslotsta);
605	db_printf(" lastnonerp %d", ic->ic_lastnonerp);
606	db_printf("\n");
607	db_printf("\tsta_assoc %u", ic->ic_sta_assoc);
608	db_printf(" ht_sta_assoc %u", ic->ic_ht_sta_assoc);
609	db_printf(" ht40_sta_assoc %u", ic->ic_ht40_sta_assoc);
610	db_printf("\n");
611	db_printf("\tcurhtprotmode 0x%x", ic->ic_curhtprotmode);
612	db_printf(" htprotmode %d", ic->ic_htprotmode);
613	db_printf(" lastnonht %d", ic->ic_lastnonht);
614	db_printf("\n");
615
616	db_printf("\tsuperg %p\n", ic->ic_superg);
617
618	db_printf("\tmontaps %d th %p txchan %p rh %p rxchan %p\n",
619	    ic->ic_montaps, ic->ic_th, ic->ic_txchan, ic->ic_rh, ic->ic_rxchan);
620
621	if (showprocs) {
622		DB_PRINTSYM("\t", "ic_vap_create", ic->ic_vap_create);
623		DB_PRINTSYM("\t", "ic_vap_delete", ic->ic_vap_delete);
624#if 0
625		/* operating mode attachment */
626		ieee80211vap_attach	ic_vattach[IEEE80211_OPMODE_MAX];
627#endif
628		DB_PRINTSYM("\t", "ic_newassoc", ic->ic_newassoc);
629		DB_PRINTSYM("\t", "ic_getradiocaps", ic->ic_getradiocaps);
630		DB_PRINTSYM("\t", "ic_setregdomain", ic->ic_setregdomain);
631		DB_PRINTSYM("\t", "ic_send_mgmt", ic->ic_send_mgmt);
632		DB_PRINTSYM("\t", "ic_raw_xmit", ic->ic_raw_xmit);
633		DB_PRINTSYM("\t", "ic_updateslot", ic->ic_updateslot);
634		DB_PRINTSYM("\t", "ic_update_mcast", ic->ic_update_mcast);
635		DB_PRINTSYM("\t", "ic_update_promisc", ic->ic_update_promisc);
636		DB_PRINTSYM("\t", "ic_node_alloc", ic->ic_node_alloc);
637		DB_PRINTSYM("\t", "ic_node_free", ic->ic_node_free);
638		DB_PRINTSYM("\t", "ic_node_cleanup", ic->ic_node_cleanup);
639		DB_PRINTSYM("\t", "ic_node_getrssi", ic->ic_node_getrssi);
640		DB_PRINTSYM("\t", "ic_node_getsignal", ic->ic_node_getsignal);
641		DB_PRINTSYM("\t", "ic_node_getmimoinfo", ic->ic_node_getmimoinfo);
642		DB_PRINTSYM("\t", "ic_scan_start", ic->ic_scan_start);
643		DB_PRINTSYM("\t", "ic_scan_end", ic->ic_scan_end);
644		DB_PRINTSYM("\t", "ic_set_channel", ic->ic_set_channel);
645		DB_PRINTSYM("\t", "ic_scan_curchan", ic->ic_scan_curchan);
646		DB_PRINTSYM("\t", "ic_scan_mindwell", ic->ic_scan_mindwell);
647		DB_PRINTSYM("\t", "ic_recv_action", ic->ic_recv_action);
648		DB_PRINTSYM("\t", "ic_send_action", ic->ic_send_action);
649		DB_PRINTSYM("\t", "ic_addba_request", ic->ic_addba_request);
650		DB_PRINTSYM("\t", "ic_addba_response", ic->ic_addba_response);
651		DB_PRINTSYM("\t", "ic_addba_stop", ic->ic_addba_stop);
652	}
653	if (showvaps && !TAILQ_EMPTY(&ic->ic_vaps)) {
654		db_printf("\n");
655		TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
656			_db_show_vap(vap, showmesh, showprocs);
657	}
658	if (showsta && !TAILQ_EMPTY(&ic->ic_sta.nt_node)) {
659		const struct ieee80211_node_table *nt = &ic->ic_sta;
660		const struct ieee80211_node *ni;
661
662		TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
663			db_printf("\n");
664			_db_show_sta(ni);
665		}
666	}
667}
668
669static void
670_db_show_all_vaps(void *arg, struct ieee80211com *ic)
671{
672	int showall = *(int *)arg;
673
674	if (!showall) {
675		const struct ieee80211vap *vap;
676		db_printf("%s: com %p vaps:", ic->ic_name, ic);
677		TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
678			db_printf(" %s(%p)", vap->iv_ifp->if_xname, vap);
679		db_printf("\n");
680	} else
681		_db_show_com(ic, 1, 1, 1, 1);
682}
683
684static void
685_db_show_node_table(const char *tag, const struct ieee80211_node_table *nt)
686{
687	int i;
688
689	db_printf("%s%s@%p:\n", tag, nt->nt_name, nt);
690	db_printf("%s nodelock %p", tag, &nt->nt_nodelock);
691	db_printf(" inact_init %d", nt->nt_inact_init);
692	db_printf("%s keyixmax %d keyixmap %p\n",
693	    tag, nt->nt_keyixmax, nt->nt_keyixmap);
694	for (i = 0; i < nt->nt_keyixmax; i++) {
695		const struct ieee80211_node *ni = nt->nt_keyixmap[i];
696		if (ni != NULL)
697			db_printf("%s [%3u] %p %s\n", tag, i, ni,
698			    ether_sprintf(ni->ni_macaddr));
699	}
700}
701
702static void
703_db_show_channel(const char *tag, const struct ieee80211_channel *c)
704{
705	db_printf("%s ", tag);
706	if (c == NULL)
707		db_printf("<NULL>");
708	else if (c == IEEE80211_CHAN_ANYC)
709		db_printf("<ANY>");
710	else
711		db_printf("[%u (%u) flags=%b maxreg %d maxpow %d minpow %d state 0x%x extieee %u]",
712		    c->ic_freq, c->ic_ieee,
713		    c->ic_flags, IEEE80211_CHAN_BITS,
714		    c->ic_maxregpower, c->ic_maxpower, c->ic_minpower,
715		    c->ic_state, c->ic_extieee);
716}
717
718static void
719_db_show_ssid(const char *tag, int ix, int len, const uint8_t *ssid)
720{
721	const uint8_t *p;
722	int i;
723
724	db_printf(tag, ix);
725
726	if (len > IEEE80211_NWID_LEN)
727		len = IEEE80211_NWID_LEN;
728	/* determine printable or not */
729	for (i = 0, p = ssid; i < len; i++, p++) {
730		if (*p < ' ' || *p > 0x7e)
731			break;
732	}
733	if (i == len) {
734		db_printf("\"");
735		for (i = 0, p = ssid; i < len; i++, p++)
736			db_printf("%c", *p);
737		db_printf("\"");
738	} else {
739		db_printf("0x");
740		for (i = 0, p = ssid; i < len; i++, p++)
741			db_printf("%02x", *p);
742	}
743}
744
745static void
746_db_show_appie(const char *tag, const struct ieee80211_appie *ie)
747{
748	const uint8_t *p;
749	int i;
750
751	if (ie == NULL)
752		return;
753	db_printf("%s [0x", tag);
754	for (i = 0, p = ie->ie_data; i < ie->ie_len; i++, p++)
755		db_printf("%02x", *p);
756	db_printf("]\n");
757}
758
759static void
760_db_show_key(const char *tag, int ix, const struct ieee80211_key *wk)
761{
762	static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
763	const struct ieee80211_cipher *cip = wk->wk_cipher;
764	int keylen = wk->wk_keylen;
765
766	db_printf(tag, ix);
767	switch (cip->ic_cipher) {
768	case IEEE80211_CIPHER_WEP:
769		/* compatibility */
770		db_printf(" wepkey %u:%s", wk->wk_keyix,
771		    keylen <= 5 ? "40-bit" :
772		    keylen <= 13 ? "104-bit" : "128-bit");
773		break;
774	case IEEE80211_CIPHER_TKIP:
775		if (keylen > 128/8)
776			keylen -= 128/8;	/* ignore MIC for now */
777		db_printf(" TKIP %u:%u-bit", wk->wk_keyix, 8*keylen);
778		break;
779	case IEEE80211_CIPHER_AES_OCB:
780		db_printf(" AES-OCB %u:%u-bit", wk->wk_keyix, 8*keylen);
781		break;
782	case IEEE80211_CIPHER_AES_CCM:
783		db_printf(" AES-CCM %u:%u-bit", wk->wk_keyix, 8*keylen);
784		break;
785	case IEEE80211_CIPHER_CKIP:
786		db_printf(" CKIP %u:%u-bit", wk->wk_keyix, 8*keylen);
787		break;
788	case IEEE80211_CIPHER_NONE:
789		db_printf(" NULL %u:%u-bit", wk->wk_keyix, 8*keylen);
790		break;
791	default:
792		db_printf(" UNKNOWN (0x%x) %u:%u-bit",
793			cip->ic_cipher, wk->wk_keyix, 8*keylen);
794		break;
795	}
796	if (wk->wk_rxkeyix != wk->wk_keyix)
797		db_printf(" rxkeyix %u", wk->wk_rxkeyix);
798	if (memcmp(wk->wk_key, zerodata, keylen) != 0) {
799		int i;
800
801		db_printf(" <");
802		for (i = 0; i < keylen; i++)
803			db_printf("%02x", wk->wk_key[i]);
804		db_printf(">");
805		if (cip->ic_cipher != IEEE80211_CIPHER_WEP &&
806		    wk->wk_keyrsc[IEEE80211_NONQOS_TID] != 0)
807			db_printf(" rsc %ju", (uintmax_t)wk->wk_keyrsc[IEEE80211_NONQOS_TID]);
808		if (cip->ic_cipher != IEEE80211_CIPHER_WEP &&
809		    wk->wk_keytsc != 0)
810			db_printf(" tsc %ju", (uintmax_t)wk->wk_keytsc);
811		db_printf(" flags=%b", wk->wk_flags, IEEE80211_KEY_BITS);
812	}
813	db_printf("\n");
814}
815
816static void
817printrate(const char *tag, int v)
818{
819	if (v == IEEE80211_FIXED_RATE_NONE)
820		db_printf(" %s <none>", tag);
821	else if (v == 11)
822		db_printf(" %s 5.5", tag);
823	else if (v & IEEE80211_RATE_MCS)
824		db_printf(" %s MCS%d", tag, v &~ IEEE80211_RATE_MCS);
825	else
826		db_printf(" %s %d", tag, v/2);
827}
828
829static void
830_db_show_roamparams(const char *tag, const void *arg,
831    const struct ieee80211_roamparam *rp)
832{
833
834	db_printf(tag, arg);
835	if (rp->rssi & 1)
836		db_printf(" rssi %u.5", rp->rssi/2);
837	else
838		db_printf(" rssi %u", rp->rssi/2);
839	printrate("rate", rp->rate);
840}
841
842static void
843_db_show_txparams(const char *tag, const void *arg,
844    const struct ieee80211_txparam *tp)
845{
846
847	db_printf(tag, arg);
848	printrate("ucastrate", tp->ucastrate);
849	printrate("mcastrate", tp->mcastrate);
850	printrate("mgmtrate", tp->mgmtrate);
851	db_printf(" maxretry %d", tp->maxretry);
852}
853
854static void
855_db_show_ageq(const char *tag, const struct ieee80211_ageq *q)
856{
857	const struct mbuf *m;
858
859	db_printf("%s lock %p len %d maxlen %d drops %d head %p tail %p\n",
860	    tag, &q->aq_lock, q->aq_len, q->aq_maxlen, q->aq_drops,
861	    q->aq_head, q->aq_tail);
862	for (m = q->aq_head; m != NULL; m = m->m_nextpkt)
863		db_printf("%s %p (len %d, %b)\n", tag, m, m->m_len,
864		    /* XXX could be either TX or RX but is mostly TX */
865		    m->m_flags, IEEE80211_MBUF_TX_FLAG_BITS);
866}
867
868static void
869_db_show_stats(const struct ieee80211_stats *is)
870{
871}
872
873#ifdef IEEE80211_SUPPORT_MESH
874static void
875_db_show_mesh(const struct ieee80211_mesh_state *ms)
876{
877	struct ieee80211_mesh_route *rt;
878	int i;
879
880	_db_show_ssid(" meshid ", 0, ms->ms_idlen, ms->ms_id);
881	db_printf("nextseq %u ttl %u flags 0x%x\n", ms->ms_seq,
882	    ms->ms_ttl, ms->ms_flags);
883	db_printf("routing table:\n");
884	i = 0;
885	TAILQ_FOREACH(rt, &ms->ms_routes, rt_next) {
886		db_printf("entry %d:\tdest: %6D nexthop: %6D metric: %u", i,
887		    rt->rt_dest, ":", rt->rt_nexthop, ":", rt->rt_metric);
888
889		db_printf("\tlifetime: %u lastseq: %u priv: %p\n",
890		    ieee80211_mesh_rt_update(rt, 0),
891		    rt->rt_lastmseq, rt->rt_priv);
892		i++;
893	}
894}
895#endif /* IEEE80211_SUPPORT_MESH */
896#endif /* DDB */
897