xref: /freebsd/sys/net80211/DEBUG.md (revision 490c53e9353feb129fe0acb8d9ba8fa52db24e2c)
1*490c53e9SAdrian Chadd# Debugging in net80211
2*490c53e9SAdrian Chadd
3*490c53e9SAdrian ChaddThis document describes how debugging is implemented in net80211.
4*490c53e9SAdrian Chadd
5*490c53e9SAdrian Chadd## Overview
6*490c53e9SAdrian Chadd
7*490c53e9SAdrian Chaddnet80211 has run-time configurable debugging available. It is configured
8*490c53e9SAdrian Chaddper-VAP.  It is implemented as a bitmask which can be controlled via a
9*490c53e9SAdrian Chaddsysctl at runtime.
10*490c53e9SAdrian Chadd
11*490c53e9SAdrian ChaddDebugging is compiled in when IEEE80211_DEBUG is defined.
12*490c53e9SAdrian Chadd
13*490c53e9SAdrian ChaddThere is currently no global debugging API available; top-level net80211
14*490c53e9SAdrian Chaddcode is typically using printf() or some wrapper around it (eg
15*490c53e9SAdrian Chaddnet80211_printf).
16*490c53e9SAdrian Chadd
17*490c53e9SAdrian ChaddThe debug API is defined in (ieee80211_var.h).  This includes the
18*490c53e9SAdrian Chadddebug field definitions and exported debugging API.  The actual implementation
19*490c53e9SAdrian Chaddof the debugging routines is currently in (ieee80211_input.c) - see
20*490c53e9SAdrian Chadd(ieee80211_note) for an example.
21*490c53e9SAdrian Chadd
22*490c53e9SAdrian ChaddThe bitmap of available debugging sections is in (ieee80211_var.h), prefixed
23*490c53e9SAdrian Chaddwith IEEE80211_MSG .  See (IEEE80211_MSG_DEBUG) for an example.
24*490c53e9SAdrian Chadd
25*490c53e9SAdrian Chadd## Usage
26*490c53e9SAdrian Chadd
27*490c53e9SAdrian ChaddCalls to the debugging APIs should not include a terminating '\n' character.
28*490c53e9SAdrian ChaddThis will be added by the debug call.
29*490c53e9SAdrian Chadd
30*490c53e9SAdrian ChaddThe simplest example is a call to IEEE80211_DPRINTF().  This takes a vap
31*490c53e9SAdrian Chaddpointer, which debug option to log to, then the format string and optional
32*490c53e9SAdrian Chaddarguments.  For example:
33*490c53e9SAdrian Chadd
34*490c53e9SAdrian Chadd```
35*490c53e9SAdrian ChaddIEEE80211_DPRINTF(vap, IEEE80211_MSG_11N, "%s: called!", __func__);
36*490c53e9SAdrian Chadd```
37*490c53e9SAdrian Chadd
38*490c53e9SAdrian ChaddThe debug flags can be combined together using bitwise OR so they are
39*490c53e9SAdrian Chaddemitted if one or more debug options are set, for example:
40*490c53e9SAdrian Chadd
41*490c53e9SAdrian Chadd```
42*490c53e9SAdrian ChaddIEEE80211_DPRINTF(vap, IEEE80211_MSG_11N | IEEE80211_MSG_ASSOC,
43*490c53e9SAdrian Chadd    "%s: called!", __func__);
44*490c53e9SAdrian Chadd```
45*490c53e9SAdrian Chadd
46*490c53e9SAdrian ChaddThere are a number of different debugging calls that are designed to be
47*490c53e9SAdrian Chaddused in different contexts.  Although they all currently end up printing
48*490c53e9SAdrian Chaddto the same debug output, keeping them separate allows for future
49*490c53e9SAdrian Chaddbehavioural changes whilst minimising rototilling the whole codebase (eg
50*490c53e9SAdrian Chaddallowing non-DPRINTF to turn into event tracing.)
51*490c53e9SAdrian Chadd
52*490c53e9SAdrian Chadd * Straight up debugging should be done through IEEE80211_DPRINTF() .
53*490c53e9SAdrian Chadd * Debugging that's related to a specific ieee80211_node (eg a state
54*490c53e9SAdrian Chadd   change for a specific node) should be done via a call to IEEE80211_NOTE() .
55*490c53e9SAdrian Chadd * Debugging that's related to a specific ethernet MAC address (eg
56*490c53e9SAdrian Chadd   scan results) should be done via a call to IEEE80211_NOTE_MAC() .
57*490c53e9SAdrian Chadd * Debugging that should include a frame header should be done via
58*490c53e9SAdrian Chadd   a call to IEEE80211_NOTE_FRAME().  Note this takes a (struct ieee80211_frame \*)
59*490c53e9SAdrian Chadd   pointer.
60*490c53e9SAdrian Chadd * Debugging involving discarding frames (eg invalid frames) should be
61*490c53e9SAdrian Chadd   done via a call to IEEE80211_DISCARD() .
62*490c53e9SAdrian Chadd * Debugging involving discarding frames due to an invalid / bad IE should
63*490c53e9SAdrian Chadd   be done via a call to IEEE80211_DISCARD_IE().
64*490c53e9SAdrian Chadd * Debugging involving discarding frames due to a MAC address (eg ACL failure)
65*490c53e9SAdrian Chadd   should be done via a call to IEEE80211_DISCARD_MAC().
66*490c53e9SAdrian Chadd
67*490c53e9SAdrian Chadd## Usage Notes
68*490c53e9SAdrian Chadd
69*490c53e9SAdrian Chadd * It is required that the debugging be compiled in/out purely by defining or not
70*490c53e9SAdrian Chadd   defining IEEE80211_DEBUG.  This can often trip up unused variable warnings
71*490c53e9SAdrian Chadd   when debugging is disabled, so just double-check both configurations.
72*490c53e9SAdrian Chadd
73*490c53e9SAdrian Chadd * It is important to ensure calls to the debugging (and any other logging API)
74*490c53e9SAdrian Chadd   do not change any state/variables.  For example, do not call a function that
75*490c53e9SAdrian Chadd   updates some counter or some state variable inside a call to IEEE80211_DPRINTF().
76*490c53e9SAdrian Chadd   It won't be called at best and it will just be compiled out entirely at worst.
77*490c53e9SAdrian Chadd
78*490c53e9SAdrian Chadd## Configuration
79*490c53e9SAdrian Chadd
80*490c53e9SAdrian Chadd * The 'vap->iv_debug' field is controlled by the OS specific module.
81*490c53e9SAdrian Chadd * In FreeBSD (ieee80211_freebsd.c) it is assigned a sysctl (net.wlan.X.debug)
82*490c53e9SAdrian Chadd   during (ieee80211_sysctl_vattach).
83*490c53e9SAdrian Chadd * FreeBSD ships the wlandebug(8) tool to query and set this at runtime.
84*490c53e9SAdrian Chadd
85*490c53e9SAdrian Chadd## Implementation Details
86*490c53e9SAdrian Chadd
87*490c53e9SAdrian Chadd* The debug API goes out of its way to do the debug flag check before evaluating
88*490c53e9SAdrian Chadd  function parameters and potentially assembling the logging output. See
89*490c53e9SAdrian Chadd  (IEEE80211_DPRINTF) for an example.
90*490c53e9SAdrian Chadd
91*490c53e9SAdrian Chadd## Future work
92*490c53e9SAdrian Chadd
93*490c53e9SAdrian Chadd * Top-level net80211 debugging APIs and control would be nice (for things
94*490c53e9SAdrian Chadd   that are not specific to a VAP.)
95*490c53e9SAdrian Chadd * Drivers end up having to implement their own debugging API; it may be nice
96*490c53e9SAdrian Chadd   to provide drivers a net80211 API to do their own driver specific logging.
97*490c53e9SAdrian Chadd * The debug macros should likely be refactored out to a new header file,
98*490c53e9SAdrian Chadd   separate from ieee80211_var.h, so they can be more easily referenced.
99*490c53e9SAdrian Chadd * The debug fields should likely be refactored out into a new separate header
100*490c53e9SAdrian Chadd   file that is designed to be consumed both by the kernel and by userland
101*490c53e9SAdrian Chadd   utilities wishing to query/set the debug bitmask.
102