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