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