Fix registration issue in the devfs rc script.
[dragonfly.git] / tools / tools / wlandebug / wlandebug.c
bloba1dae3f54f49c0ff12900fa3ef51ae93fe276d80
1 /*-
2 * Copyright (c) 2002-2004 Sam Leffler, Errno Consulting
3 * All rights reserved.
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 * 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.
23 * NO WARRANTY
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.
36 * $FreeBSD: src/tools/tools/net80211/wlandebug/wlandebug.c,v 1.3 2007/01/12 05:36:17 sam Exp $
37 * $DragonFly: src/tools/tools/wlandebug/wlandebug.c,v 1.1 2007/03/04 13:15:48 sephe Exp $
41 * wlandebug -i interface [flags]
44 #include <sys/types.h>
45 #include <netproto/802_11/ieee80211_var.h>
47 #include <stdio.h>
48 #include <ctype.h>
49 #include <getopt.h>
50 #include <string.h>
52 #define N(a) (sizeof(a)/sizeof(a[0]))
54 const char *progname;
56 static struct {
57 const char *name;
58 u_int bit;
59 } flags[] = {
60 { "debug", IEEE80211_MSG_DEBUG },
61 { "dumppkts", IEEE80211_MSG_DUMPPKTS },
62 { "crypto", IEEE80211_MSG_CRYPTO },
63 { "input", IEEE80211_MSG_INPUT },
64 { "xrate", IEEE80211_MSG_XRATE },
65 { "elemid", IEEE80211_MSG_ELEMID },
66 { "node", IEEE80211_MSG_NODE },
67 { "assoc", IEEE80211_MSG_ASSOC },
68 { "auth", IEEE80211_MSG_AUTH },
69 { "scan", IEEE80211_MSG_SCAN },
70 { "output", IEEE80211_MSG_OUTPUT },
71 { "state", IEEE80211_MSG_STATE },
72 { "power", IEEE80211_MSG_POWER },
73 { "dot1x", IEEE80211_MSG_DOT1X },
74 { "dot1xsm", IEEE80211_MSG_DOT1XSM },
75 { "radius", IEEE80211_MSG_RADIUS },
76 { "raddump", IEEE80211_MSG_RADDUMP },
77 { "radkeys", IEEE80211_MSG_RADKEYS },
78 { "wpa", IEEE80211_MSG_WPA },
79 { "acl", IEEE80211_MSG_ACL },
80 { "wme", IEEE80211_MSG_WME },
81 { "superg", IEEE80211_MSG_SUPERG },
82 { "doth", IEEE80211_MSG_DOTH },
83 { "inact", IEEE80211_MSG_INACT },
84 { "roam", IEEE80211_MSG_ROAM }
87 static u_int
88 getflag(const char *name, int len)
90 int i;
92 for (i = 0; i < N(flags); i++)
93 if (strncasecmp(flags[i].name, name, len) == 0)
94 return flags[i].bit;
95 return 0;
98 static const char *
99 getflagname(u_int flag)
101 int i;
103 for (i = 0; i < N(flags); i++)
104 if (flags[i].bit == flag)
105 return flags[i].name;
106 return "???";
109 static void
110 usage(void)
112 int i;
114 fprintf(stderr, "usage: %s -i device [flags]\n", progname);
115 fprintf(stderr, "where flags are:\n");
116 for (i = 0; i < N(flags); i++)
117 printf("%s\n", flags[i].name);
118 exit(-1);
122 main(int argc, char *argv[])
124 const char *ifname = NULL;
125 const char *cp, *tp;
126 const char *sep;
127 int c, op, i, unit;
128 u_int32_t debug, ndebug;
129 size_t debuglen, parentlen;
130 char oid[256], parent[256];
132 progname = argv[0];
133 if (argc > 1) {
134 if (strcmp(argv[1], "-i") == 0) {
135 if (argc < 2)
136 errx(1, "missing interface name for -i option");
137 ifname = argv[2];
138 argc -= 2, argv += 2;
142 if (ifname == NULL)
143 usage();
145 for (unit = 0; unit < 10; unit++) {
146 snprintf(oid, sizeof(oid), "net.wlan.%d.%%parent", unit);
147 parentlen = sizeof(parent);
148 if (sysctlbyname(oid, parent, &parentlen, NULL, 0) >= 0 &&
149 strncmp(parent, ifname, parentlen) == 0)
150 break;
152 if (unit == 10)
153 errx(1, "%s: cannot locate wlan sysctl node.", ifname);
154 snprintf(oid, sizeof(oid), "net.wlan.%d.debug", unit);
155 debuglen = sizeof(debug);
156 if (sysctlbyname(oid, &debug, &debuglen, NULL, 0) < 0)
157 err(1, "sysctl-get(%s)", oid);
158 ndebug = debug;
159 for (; argc > 1; argc--, argv++) {
160 cp = argv[1];
161 do {
162 u_int bit;
164 if (*cp == '-') {
165 cp++;
166 op = -1;
167 } else if (*cp == '+') {
168 cp++;
169 op = 1;
170 } else
171 op = 0;
172 for (tp = cp; *tp != '\0' && *tp != '+' && *tp != '-';)
173 tp++;
174 bit = getflag(cp, tp-cp);
175 if (op < 0)
176 ndebug &= ~bit;
177 else if (op > 0)
178 ndebug |= bit;
179 else {
180 if (bit == 0) {
181 if (isdigit(*cp))
182 bit = strtoul(cp, NULL, 0);
183 else
184 errx(1, "unknown flag %.*s",
185 tp-cp, cp);
187 ndebug = bit;
189 } while (*(cp = tp) != '\0');
191 if (debug != ndebug) {
192 printf("%s: 0x%x => ", oid, debug);
193 if (sysctlbyname(oid, NULL, NULL, &ndebug, sizeof(ndebug)) < 0)
194 err(1, "sysctl-set(%s)", oid);
195 printf("0x%x", ndebug);
196 debug = ndebug;
197 } else
198 printf("%s: 0x%x", oid, debug);
199 sep = "<";
200 for (i = 0; i < N(flags); i++)
201 if (debug & flags[i].bit) {
202 printf("%s%s", sep, flags[i].name);
203 sep = ",";
205 printf("%s\n", *sep != '<' ? ">" : "");
206 return 0;