2 * Copyright (c) 2002-2004 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.
15 * 3. Neither the names of the above-listed copyright holders nor the names
16 * of any contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * Alternatively, this software may be distributed under the terms of the
20 * GNU General Public License ("GPL") version 2 as published by the Free
21 * Software Foundation.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
28 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
29 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
32 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34 * THE POSSIBILITY OF SUCH DAMAGES.
40 * athdebug [-i interface] flags
41 * (default interface is ath0).
43 #include <sys/types.h>
45 #include <sys/ioctl.h>
46 #include <sys/socket.h>
52 #define N(a) (sizeof(a)/sizeof(a[0]))
57 ATH_DEBUG_XMIT = 0x00000001, /* basic xmit operation */
58 ATH_DEBUG_XMIT_DESC = 0x00000002, /* xmit descriptors */
59 ATH_DEBUG_RECV = 0x00000004, /* basic recv operation */
60 ATH_DEBUG_RECV_DESC = 0x00000008, /* recv descriptors */
61 ATH_DEBUG_RATE = 0x00000010, /* rate control */
62 ATH_DEBUG_RESET = 0x00000020, /* reset processing */
63 ATH_DEBUG_MODE = 0x00000040, /* mode init/setup */
64 ATH_DEBUG_BEACON = 0x00000080, /* beacon handling */
65 ATH_DEBUG_WATCHDOG = 0x00000100, /* watchdog timeout */
66 ATH_DEBUG_INTR = 0x00001000, /* ISR */
67 ATH_DEBUG_TX_PROC = 0x00002000, /* tx ISR proc */
68 ATH_DEBUG_RX_PROC = 0x00004000, /* rx ISR proc */
69 ATH_DEBUG_BEACON_PROC = 0x00008000, /* beacon ISR proc */
70 ATH_DEBUG_CALIBRATE = 0x00010000, /* periodic calibration */
71 ATH_DEBUG_KEYCACHE = 0x00020000, /* key cache management */
72 ATH_DEBUG_STATE = 0x00040000, /* 802.11 state transitions */
73 ATH_DEBUG_NODE = 0x00080000, /* node management */
74 ATH_DEBUG_LED = 0x00100000, /* led management */
75 ATH_DEBUG_FF = 0x00200000, /* fast frames */
76 ATH_DEBUG_DFS = 0x00400000, /* DFS processing */
77 ATH_DEBUG_FATAL = 0x80000000, /* fatal errors */
78 ATH_DEBUG_ANY = 0xffffffff
85 { "xmit", ATH_DEBUG_XMIT },
86 { "xmit_desc", ATH_DEBUG_XMIT_DESC },
87 { "recv", ATH_DEBUG_RECV },
88 { "recv_desc", ATH_DEBUG_RECV_DESC },
89 { "rate", ATH_DEBUG_RATE },
90 { "reset", ATH_DEBUG_RESET },
91 { "mode", ATH_DEBUG_MODE },
92 { "beacon", ATH_DEBUG_BEACON },
93 { "watchdog", ATH_DEBUG_WATCHDOG },
94 { "intr", ATH_DEBUG_INTR },
95 { "xmit_proc", ATH_DEBUG_TX_PROC },
96 { "recv_proc", ATH_DEBUG_RX_PROC },
97 { "beacon_proc",ATH_DEBUG_BEACON_PROC },
98 { "calibrate", ATH_DEBUG_CALIBRATE },
99 { "keycache", ATH_DEBUG_KEYCACHE },
100 { "state", ATH_DEBUG_STATE },
101 { "node", ATH_DEBUG_NODE },
102 { "led", ATH_DEBUG_LED },
103 { "ff", ATH_DEBUG_FF },
104 { "dfs", ATH_DEBUG_DFS },
105 { "fatal", ATH_DEBUG_FATAL },
109 getflag(const char *name, int len)
113 for (i = 0; i < N(flags); i++)
114 if (strncasecmp(flags[i].name, name, len) == 0)
120 getflagname(u_int flag)
124 for (i = 0; i < N(flags); i++)
125 if (flags[i].bit == flag)
126 return flags[i].name;
135 fprintf(stderr, "usage: %s [-i device] [flags]\n", progname);
136 fprintf(stderr, "where flags are:\n");
137 for (i = 0; i < N(flags); i++)
138 printf("%s\n", flags[i].name);
143 main(int argc, char *argv[])
145 const char *ifname = "ath0";
149 u_int32_t debug, ndebug;
155 if (strcmp(argv[1], "-i") == 0) {
157 errx(1, "missing interface name for -i option");
159 if (strncmp(ifname, "ath", 3) != 0)
160 errx(2, "huh, this is for ath devices?");
161 argc -= 2, argv += 2;
162 } else if (strcmp(argv[1], "-?") == 0)
167 snprintf(oid, sizeof(oid), "dev.%s.debug", ifname);
169 snprintf(oid, sizeof(oid), "dev.ath.%s.debug", ifname+3);
171 debuglen = sizeof(debug);
172 if (sysctlbyname(oid, &debug, &debuglen, NULL, 0) < 0)
173 err(1, "sysctl-get(%s)", oid);
175 for (; argc > 1; argc--, argv++) {
183 } else if (*cp == '+') {
188 for (tp = cp; *tp != '\0' && *tp != '+' && *tp != '-';)
190 bit = getflag(cp, tp-cp);
198 bit = strtoul(cp, NULL, 0);
200 errx(1, "unknown flag %.*s",
205 } while (*(cp = tp) != '\0');
207 if (debug != ndebug) {
208 printf("%s: 0x%x => ", oid, debug);
209 if (sysctlbyname(oid, NULL, NULL, &ndebug, sizeof(ndebug)) < 0)
210 err(1, "sysctl-set(%s)", oid);
211 printf("0x%x", ndebug);
214 printf("%s: 0x%x", oid, debug);
216 for (i = 0; i < N(flags); i++)
217 if (debug & flags[i].bit) {
218 printf("%s%s", sep, flags[i].name);
221 printf("%s\n", *sep != '<' ? ">" : "");