2 * Copyright (c) 1999, 2000
3 * Dr. Duncan McLennan Barclay, dmlb@ragnet.demon.co.uk. All Rights Reserved.
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 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY DUNCAN BARCLAY AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL DUNCAN BARCLAY OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/socket.h>
39 #include <sys/ioctl.h>
40 #include <sys/socket.h>
43 #include <net/ethernet.h>
44 #include <net80211/ieee80211.h>
45 #include <net80211/ieee80211_ioctl.h>
47 #include <dev/ray/if_rayreg.h>
48 #include <dev/ray/if_raymib.h>
57 static char * ray_printhex (u_int8_t *d, char *s, int len);
58 static void ray_getval (char *iface, struct ray_param_req *rreq);
59 static void ray_getstats (char *iface, struct ray_stats_req *sreq);
60 static int ray_version (char *iface);
61 static void ray_dumpstats (char *iface);
62 static void ray_dumpinfo (char *iface);
63 static void ray_setstr (char *iface, u_int8_t mib, char *s);
64 static void ray_setword (char *iface, u_int8_t mib, u_int16_t v);
65 static void ray_setval (char *iface, struct ray_param_req *rreq);
66 static void usage (char *p);
68 static char *mib_strings[] = RAY_MIB_STRINGS;
69 static char *mib_help_strings[] = RAY_MIB_HELP_STRINGS;
70 static int mib_info[RAY_MIB_MAX+1][3] = RAY_MIB_INFO;
73 ray_printhex(u_int8_t *d, char *s, int len)
75 static char buf[3*256];
79 if (2 * len + strlen(s) * (len - 1) > sizeof(buf) - 1)
80 errx(1, "byte string too long");
82 sprintf(buf, "%02x", *d);
83 for (p = buf + 2, i = 1; i < len; i++)
84 p += sprintf(p, "%s%02x", s, *(d+i));
90 ray_getval(char *iface, struct ray_param_req *rreq)
95 bzero((char *)&ifr, sizeof(ifr));
97 strlcpy(ifr.ifr_name, iface, IFNAMSIZ);
98 ifr.ifr_data = (caddr_t)rreq;
100 s = socket(AF_INET, SOCK_DGRAM, 0);
105 if (ioctl(s, SIOCGRAYPARAM, &ifr) == -1)
106 warn("SIOCGRAYPARAM failed with failcode 0x%02x",
113 ray_getsiglev(char *iface, struct ray_siglev *siglev)
118 bzero((char *)&ifr, sizeof(ifr));
120 strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
121 ifr.ifr_data = (caddr_t)siglev;
123 s = socket(AF_INET, SOCK_DGRAM, 0);
128 if (ioctl(s, SIOCGRAYSIGLEV, &ifr) == -1)
129 err(1, "SIOCGRAYSIGLEV failed");
135 ray_getstats(char *iface, struct ray_stats_req *sreq)
140 bzero((char *)&ifr, sizeof(ifr));
142 strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
143 ifr.ifr_data = (caddr_t)sreq;
145 s = socket(AF_INET, SOCK_DGRAM, 0);
150 if (ioctl(s, SIOCGRAYSTATS, &ifr) == -1)
151 err(1, "SIOCGRAYSTATS failed");
157 ray_version(char *iface)
159 struct ray_param_req rreq;
162 errx(1, "must specify interface name");
164 bzero((char *)&rreq, sizeof(rreq));
165 rreq.r_paramid = RAY_MIB_VERSION;
166 ray_getval(iface, &rreq);
167 return(*rreq.r_data);
171 ray_dumpinfo(char *iface)
173 struct ray_param_req rreq;
174 u_int8_t mib, version;
177 errx(1, "must specify interface name");
179 bzero((char *)&rreq, sizeof(rreq));
181 version = ray_version(iface);
182 printf("%-26s\t", mib_strings[RAY_MIB_VERSION]);
183 printf("%d\n", 3+version);
185 for (mib = RAY_MIB_NET_TYPE; mib <= RAY_MIB_MAX; mib++) {
187 if ((mib_info[mib][0] & version) == 0)
189 if (mib == RAY_MIB_VERSION)
192 rreq.r_paramid = mib;
193 ray_getval(iface, &rreq);
194 printf("%-26s\t", mib_strings[mib]);
195 switch (rreq.r_len) {
198 printf("0x%02x%02x", *rreq.r_data, *(rreq.r_data+1));
203 ray_printhex(rreq.r_data, ":", rreq.r_len));
206 case IEEE80211_NWID_LEN:
207 printf("%-32s", (char *)rreq.r_data);
213 printf("0x%02x", *rreq.r_data);
216 printf("\t%s\n", mib_help_strings[mib]);
221 ray_dumpsiglev(char *iface)
223 struct ray_siglev siglevs[RAY_NSIGLEVRECS];
227 errx(1, "must specify interface name");
229 bzero((char *)siglevs, sizeof(siglevs));
231 ray_getsiglev(iface, siglevs);
233 for (i = 0; i < RAY_NSIGLEVRECS; i++) {
234 printf("Slot %d: %s", i,
235 ray_printhex(siglevs[i].rsl_host, ":", ETHER_ADDR_LEN));
237 ray_printhex(siglevs[i].rsl_siglevs, ",", RAY_NSIGLEV));
239 ray_printhex(siglevs[i].rsl_antennas, "", RAY_NANTENNA));
245 ray_dumpstats(char *iface)
247 struct ray_stats_req sreq;
250 errx(1, "must specify interface name");
252 bzero((char *)&sreq, sizeof(sreq));
254 ray_getstats(iface, &sreq);
256 printf("Receiver overflows %lu\n",
257 (unsigned long int)sreq.rxoverflow);
258 printf("Receiver checksum errors %lu\n",
259 (unsigned long int)sreq.rxcksum);
260 printf("Header checksum errors %lu\n",
261 (unsigned long int)sreq.rxhcksum);
262 printf("Clear channel noise level %u\n", sreq.rxnoise);
266 ray_setval(char *iface, struct ray_param_req *rreq)
271 bzero((char *)&ifr, sizeof(ifr));
273 strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
274 ifr.ifr_data = (caddr_t)rreq;
276 s = socket(AF_INET, SOCK_DGRAM, 0);
281 if (ioctl(s, SIOCSRAYPARAM, &ifr) == -1) {
282 err(1, "SIOCSRAYPARAM failed with failcode 0x%02x",
290 ray_setword(char *iface, u_int8_t mib, u_int16_t v)
292 struct ray_param_req rreq;
295 errx(1, "must specify interface name");
297 bzero((char *)&rreq, sizeof(rreq));
299 rreq.r_paramid = mib;
300 rreq.r_len = RAY_MIB_SIZE(mib_info, mib, ray_version(iface));
301 switch (rreq.r_len) {
304 *rreq.r_data = (u_int8_t)(v & 0xff);
308 *rreq.r_data = (u_int8_t)((v & 0xff00) >> 8);
309 *(rreq.r_data+1) = (u_int8_t)(v & 0xff);
316 ray_setval(iface, &rreq);
320 ray_setstr(char *iface, u_int8_t mib, char *s)
322 struct ray_param_req rreq;
325 errx(1, "must specify interface name");
327 errx(1, "must specify string");
328 if (strlen(s) > RAY_MIB_SIZE(mib_info, mib, ray_version(iface)))
329 errx(1, "string too long");
331 bzero((char *)&rreq, sizeof(rreq));
333 rreq.r_paramid = mib;
334 rreq.r_len = RAY_MIB_SIZE(mib_info, mib, ray_version(iface));
335 bcopy(s, (char *)rreq.r_data, strlen(s));
337 ray_setval(iface, &rreq);
343 fprintf(stderr, "usage: %s -i iface\n", p);
344 fprintf(stderr, "\t%s -i iface -o\n", p);
345 fprintf(stderr, "\t%s -i iface -t tx rate\n", p);
346 fprintf(stderr, "\t%s -i iface -n network name\n", p);
347 fprintf(stderr, "\t%s -i iface -p port type\n", p);
348 fprintf(stderr, "\t%s -i iface -m mac address\n", p);
349 fprintf(stderr, "\t%s -i iface -d max data length\n", p);
350 fprintf(stderr, "\t%s -i iface -r RTS threshold\n", p);
351 fprintf(stderr, "\t%s -i iface -f hopset\n", p);
352 fprintf(stderr, "\t%s -i iface -P 0|1\n", p);
353 fprintf(stderr, "\t%s -i iface -S max sleep duration\n", p);
354 fprintf(stderr, "\t%s -i iface -C print signal cache\n", p);
360 main(int argc, char *argv[])
369 /* Get the interface name */
371 ch = getopt(argc, argv, "i:");
375 if (argc > 1 && *argv[1] != '-') {
386 while ((ch = getopt(argc, argv, "hoCi:d:f:n:p:r:t:W:")) != -1) {
396 (val != -1)) || (val > RAY_MIB_FRAG_THRESH_MAXIMUM))
400 ray_setword(iface, RAY_MIB_FRAG_THRESH, val);
406 if ((val < RAY_MIB_COUNTRY_CODE_MIMIMUM) ||
407 (val > RAY_MIB_COUNTRY_CODE_MAXIMUM))
409 ray_setword(iface, RAY_MIB_COUNTRY_CODE, val);
414 ray_setstr(iface, RAY_MIB_SSID, optarg);
419 ray_dumpstats(iface);
425 if ((val < 0) || (val > 1))
427 ray_setword(iface, RAY_MIB_NET_TYPE, val);
434 if ((val < -1) || (val > RAY_MIB_RTS_THRESH_MAXIMUM))
438 ray_setword(iface, RAY_MIB_RTS_THRESH, val);
444 if ((val < RAY_MIB_BASIC_RATE_SET_MINIMUM) ||
445 (val > RAY_MIB_BASIC_RATE_SET_MAXIMUM))
447 ray_setword(iface, RAY_MIB_BASIC_RATE_SET, val);
452 ray_dumpsiglev(iface);
458 char *stringp, **ap, *av[5];
463 *ap = strsep(&stringp, ":");
467 *ap = strsep(&stringp, ":");
469 sscanf(av[1], "%x", &val);
470 printf("mib %d, val 0x%02x\n", mib, val);
471 ray_setword(iface, mib, val);