2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
33 * athdebug [-i interface] flags
34 * (default interface is ath0).
36 #include <sys/types.h>
38 #include <sys/ioctl.h>
39 #include <sys/socket.h>
40 #include <sys/sysctl.h>
50 #define N(a) (sizeof(a)/sizeof(a[0]))
54 /* XXX TODO: include if_ath_debug.h */
56 ATH_DEBUG_XMIT = 0x00000001, /* basic xmit operation */
57 ATH_DEBUG_XMIT_DESC = 0x00000002, /* xmit descriptors */
58 ATH_DEBUG_RECV = 0x00000004, /* basic recv operation */
59 ATH_DEBUG_RECV_DESC = 0x00000008, /* recv descriptors */
60 ATH_DEBUG_RATE = 0x00000010, /* rate control */
61 ATH_DEBUG_RESET = 0x00000020, /* reset processing */
62 ATH_DEBUG_MODE = 0x00000040, /* mode init/setup */
63 ATH_DEBUG_BEACON = 0x00000080, /* beacon handling */
64 ATH_DEBUG_WATCHDOG = 0x00000100, /* watchdog timeout */
65 ATH_DEBUG_INTR = 0x00001000, /* ISR */
66 ATH_DEBUG_TX_PROC = 0x00002000, /* tx ISR proc */
67 ATH_DEBUG_RX_PROC = 0x00004000, /* rx ISR proc */
68 ATH_DEBUG_BEACON_PROC = 0x00008000, /* beacon ISR proc */
69 ATH_DEBUG_CALIBRATE = 0x00010000, /* periodic calibration */
70 ATH_DEBUG_KEYCACHE = 0x00020000, /* key cache management */
71 ATH_DEBUG_STATE = 0x00040000, /* 802.11 state transitions */
72 ATH_DEBUG_NODE = 0x00080000, /* node management */
73 ATH_DEBUG_LED = 0x00100000, /* led management */
74 ATH_DEBUG_FF = 0x00200000, /* fast frames */
75 ATH_DEBUG_DFS = 0x00400000, /* DFS processing */
76 ATH_DEBUG_TDMA = 0x00800000, /* TDMA processing */
77 ATH_DEBUG_TDMA_TIMER = 0x01000000, /* TDMA timer processing */
78 ATH_DEBUG_REGDOMAIN = 0x02000000, /* regulatory processing */
79 ATH_DEBUG_FATAL = 0x80000000, /* fatal errors */
80 ATH_DEBUG_ANY = 0xffffffff
87 { "xmit", ATH_DEBUG_XMIT },
88 { "xmit_desc", ATH_DEBUG_XMIT_DESC },
89 { "recv", ATH_DEBUG_RECV },
90 { "recv_desc", ATH_DEBUG_RECV_DESC },
91 { "rate", ATH_DEBUG_RATE },
92 { "reset", ATH_DEBUG_RESET },
93 { "mode", ATH_DEBUG_MODE },
94 { "beacon", ATH_DEBUG_BEACON },
95 { "watchdog", ATH_DEBUG_WATCHDOG },
96 { "intr", ATH_DEBUG_INTR },
97 { "xmit_proc", ATH_DEBUG_TX_PROC },
98 { "recv_proc", ATH_DEBUG_RX_PROC },
99 { "beacon_proc",ATH_DEBUG_BEACON_PROC },
100 { "calibrate", ATH_DEBUG_CALIBRATE },
101 { "keycache", ATH_DEBUG_KEYCACHE },
102 { "state", ATH_DEBUG_STATE },
103 { "node", ATH_DEBUG_NODE },
104 { "led", ATH_DEBUG_LED },
105 { "ff", ATH_DEBUG_FF },
106 { "dfs", ATH_DEBUG_DFS },
107 { "tdma", ATH_DEBUG_TDMA },
108 { "tdma_timer", ATH_DEBUG_TDMA_TIMER },
109 { "regdomain", ATH_DEBUG_REGDOMAIN },
110 { "fatal", ATH_DEBUG_FATAL },
114 getflag(const char *name, int len)
118 for (i = 0; i < N(flags); i++)
119 if (strncasecmp(flags[i].name, name, len) == 0)
125 getflagname(u_int flag)
129 for (i = 0; i < N(flags); i++)
130 if (flags[i].bit == flag)
131 return flags[i].name;
140 fprintf(stderr, "usage: %s [-i device] [flags]\n", progname);
141 fprintf(stderr, "where flags are:\n");
142 for (i = 0; i < N(flags); i++)
143 printf("%s\n", flags[i].name);
148 main(int argc, char *argv[])
154 uint64_t debug, ndebug;
158 ifname = getenv("ATH");
163 if (strcmp(argv[1], "-i") == 0) {
165 errx(1, "missing interface name for -i option");
167 if (strncmp(ifname, "ath", 3) != 0)
168 errx(2, "huh, this is for ath devices?");
169 argc -= 2, argv += 2;
170 } else if (strcmp(argv[1], "-?") == 0)
175 snprintf(oid, sizeof(oid), "dev.%s.debug", ifname);
177 snprintf(oid, sizeof(oid), "dev.ath.%s.debug", ifname+3);
179 debuglen = sizeof(debug);
180 if (sysctlbyname(oid, &debug, &debuglen, NULL, 0) < 0)
181 err(1, "sysctl-get(%s)", oid);
183 for (; argc > 1; argc--, argv++) {
191 } else if (*cp == '+') {
196 for (tp = cp; *tp != '\0' && *tp != '+' && *tp != '-';)
198 bit = getflag(cp, tp-cp);
206 bit = strtoul(cp, NULL, 0);
208 errx(1, "unknown flag %.*s",
213 } while (*(cp = tp) != '\0');
215 if (debug != ndebug) {
216 printf("%s: 0x%llx => ", oid, (long long) debug);
217 if (sysctlbyname(oid, NULL, NULL, &ndebug, sizeof(ndebug)) < 0)
218 err(1, "sysctl-set(%s)", oid);
219 printf("0x%llx", (long long) ndebug);
222 printf("%s: 0x%llx", oid, (long long) debug);
224 for (i = 0; i < N(flags); i++)
225 if (debug & flags[i].bit) {
226 printf("%s%s", sep, flags[i].name);
229 printf("%s\n", *sep != '<' ? ">" : "");