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.
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>
52 #define N(a) (sizeof(a)/sizeof(a[0]))
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
}
88 getflag(const char *name
, int len
)
92 for (i
= 0; i
< N(flags
); i
++)
93 if (strncasecmp(flags
[i
].name
, name
, len
) == 0)
99 getflagname(u_int flag
)
103 for (i
= 0; i
< N(flags
); i
++)
104 if (flags
[i
].bit
== flag
)
105 return flags
[i
].name
;
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
);
122 main(int argc
, char *argv
[])
124 const char *ifname
= NULL
;
128 u_int32_t debug
, ndebug
;
129 size_t debuglen
, parentlen
;
130 char oid
[256], parent
[256];
134 if (strcmp(argv
[1], "-i") == 0) {
136 errx(1, "missing interface name for -i option");
138 argc
-= 2, argv
+= 2;
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)
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
);
159 for (; argc
> 1; argc
--, argv
++) {
167 } else if (*cp
== '+') {
172 for (tp
= cp
; *tp
!= '\0' && *tp
!= '+' && *tp
!= '-';)
174 bit
= getflag(cp
, tp
-cp
);
182 bit
= strtoul(cp
, NULL
, 0);
184 errx(1, "unknown flag %.*s",
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
);
198 printf("%s: 0x%x", oid
, debug
);
200 for (i
= 0; i
< N(flags
); i
++)
201 if (debug
& flags
[i
].bit
) {
202 printf("%s%s", sep
, flags
[i
].name
);
205 printf("%s\n", *sep
!= '<' ? ">" : "");