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