3 * Michael Smith. 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.
14 * THIS SOFTWARE IS PROVIDED BY Michael Smith AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL Michael Smith OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 static const char rcsid[] =
35 * utility to read out and change various WAVELAN parameters.
36 * Currently supports NWID and IRQ values.
38 * The NWID is used by 2 or more wavelan controllers to determine
39 * if packets should be received or not. It is a filter that
40 * is roughly analogous to the "channel" setting with a garage
41 * door controller. Two companies side by side with wavelan devices
42 * that could actually hear each other can use different NWIDs
43 * and ignore packets. In truth however, the air space is shared,
44 * and the NWID is a virtual filter.
46 * In the current set of wavelan drivers, ioctls changed only
47 * the runtime radio modem registers which act in a manner analogous
48 * to an ethernet transceiver. The ioctls do not change the
49 * stored nvram PSA (or parameter storage area). At boot, the PSA
50 * values are stored in the radio modem. Thus when the
51 * system reboots it will restore the wavelan NWID to the value
52 * stored in the PSA. The NCR/ATT dos utilities must be used to
53 * change the initial NWID values in the PSA. The wlconfig utility
54 * may be used to set a different NWID at runtime; this is only
55 * permitted while the interface is up and running.
57 * By contrast, the IRQ value can only be changed while the
58 * Wavelan card is down and unconfigured, and it will remain
59 * disabled after an IRQ change until reboot.
63 #include <sys/param.h>
64 #include <sys/socket.h>
65 #include <sys/ioctl.h>
67 #include <machine/if_wl_wavelan.h>
70 #include <netinet/in.h>
71 #include <netinet/if_ether.h>
80 /* translate IRQ bit to number */
81 /* array for maping irq numbers to values for the irq parameter register */
82 static int irqvals[16] = {
83 0, 0, 0, 0x01, 0x02, 0x04, 0, 0x08, 0, 0, 0x10, 0x20, 0x40, 0, 0, 0x80
87 static int w_sigitems; /* count of valid items */
88 static struct w_sigcache wsc[MAXCACHEITEMS];
95 for(irq = 0; irq < 16; irq++)
96 if(irqvals[irq] == irqval)
101 char *compat_type[] = {
106 "PCCARD or 1/2 size AT, 915MHz or 2.4GHz"
110 "915MHz/see WaveModem",
121 ** Given a pointer to a PSA structure, print it out
124 print_psa(u_char *psa, int currnwid)
129 ** Work out what sort of board we have
131 if (psa[0] == 0x14) {
132 printf("Board type : Microchannel\n");
135 printf("Board type : PCCARD\n");
137 printf("Board type : ISA");
141 printf(" (DEC OEM)");
143 printf("Base address options : 0x300, 0x%02x0, 0x%02x0, 0x%02x0\n",
144 (int)psa[1], (int)psa[2], (int)psa[3]);
145 printf("Waitstates : %d\n",psa[7] & 0xf);
146 printf("Bus mode : %s\n",(psa[7] & 0x10) ? "EISA" : "ISA");
147 printf("IRQ : %d\n",wlirq(psa[8]));
150 printf("Default MAC address : %02x:%02x:%02x:%02x:%02x:%02x\n",
151 psa[0x10],psa[0x11],psa[0x12],psa[0x13],psa[0x14],psa[0x15]);
152 printf("Soft MAC address : %02x:%02x:%02x:%02x:%02x:%02x\n",
153 psa[0x16],psa[0x17],psa[0x18],psa[0x19],psa[0x1a],psa[0x1b]);
154 printf("Current MAC address : %s\n",(psa[0x1c] & 0x1) ? "Soft" : "Default");
155 printf("Adapter compatibility : ");
157 printf("%s\n",compat_type[psa[0x1d]]);
161 printf("Threshold preset : %d\n",psa[0x1e]);
162 printf("Call code required : %s\n",(psa[0x1f] & 0x1) ? "YES" : "NO");
164 printf("Call code : 0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
165 psa[0x30],psa[0x31],psa[0x32],psa[0x33],psa[0x34],psa[0x35],psa[0x36],psa[0x37]);
166 printf("Subband : %s\n",subband[psa[0x20] & 0xf]);
167 printf("Quality threshold : %d\n",psa[0x21]);
168 printf("Hardware version : %d (%s)\n",psa[0x22],psa[0x22] ? "Rel3" : "Rel1/Rel2");
169 printf("Network ID enable : %s\n",(psa[0x25] & 0x1) ? "YES" : "NO");
170 if (psa[0x25] & 0x1) {
171 nwid = (psa[0x23] << 8) + psa[0x24];
172 printf("NWID : 0x%04x\n",nwid);
173 if (nwid != currnwid) {
174 printf("Current NWID : 0x%04x\n",currnwid);
177 printf("Datalink security : %s\n",(psa[0x26] & 0x1) ? "YES" : "NO");
178 if (psa[0x26] & 0x1) {
179 printf("Encryption key : ");
180 if (psa[0x27] == 0) {
183 printf("0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
184 psa[0x27],psa[0x28],psa[0x29],psa[0x2a],psa[0x2b],psa[0x2c],psa[0x2d],psa[0x2e]);
187 printf("Databus width : %d (%s)\n",
188 (psa[0x2f] & 0x1) ? 16 : 8, (psa[0x2f] & 0x80) ? "fixed" : "variable");
189 printf("Configuration state : %sconfigured\n",(psa[0x38] & 0x1) ? "" : "un");
190 printf("CRC-16 : 0x%02x%02x\n",psa[0x3e],psa[0x3d]);
191 printf("CRC status : ");
209 fprintf(stderr,"usage: wlconfig ifname [param value ...]\n");
215 get_cache(int sd, struct ifreq *ifr)
217 /* get the cache count */
218 if (ioctl(sd, SIOCGWLCITEM, (caddr_t)ifr))
219 err(1, "SIOCGWLCITEM - get cache count");
220 w_sigitems = (int) ifr->ifr_data;
222 ifr->ifr_data = (caddr_t) &wsc;
224 if (ioctl(sd, SIOCGWLCACHE, (caddr_t)ifr))
225 err(1, "SIOCGWLCACHE - get cache count");
229 scale_value(int value, int max)
231 double dmax = (double) max;
234 return((value/dmax) * 100);
238 dump_cache(int rawFlag)
241 int signal, silence, quality;
244 printf("signal range 0..63: silence 0..63: quality 0..15\n");
246 printf("signal range 0..100: silence 0..100: quality 0..100\n");
248 /* after you read it, loop through structure,i.e. wsc
251 for(i = 0; i < w_sigitems; i++) {
252 printf("[%d:%d]>\n", i+1, w_sigitems);
253 printf("\tip: %d.%d.%d.%d,",((wsc[i].ipsrc >> 0) & 0xff),
254 ((wsc[i].ipsrc >> 8) & 0xff),
255 ((wsc[i].ipsrc >> 16) & 0xff),
256 ((wsc[i].ipsrc >> 24) & 0xff));
257 printf(" mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
258 wsc[i].macsrc[0]&0xff,
259 wsc[i].macsrc[1]&0xff,
260 wsc[i].macsrc[2]&0xff,
261 wsc[i].macsrc[3]&0xff,
262 wsc[i].macsrc[4]&0xff,
263 wsc[i].macsrc[5]&0xff);
265 signal = wsc[i].signal;
266 silence = wsc[i].silence;
267 quality = wsc[i].quality;
270 signal = scale_value(wsc[i].signal, 63);
271 silence = scale_value(wsc[i].silence, 63);
272 quality = scale_value(wsc[i].quality, 15);
274 printf("\tsignal: %d, silence: %d, quality: %d, ",
278 printf("snr: %d\n", signal - silence);
282 #define raw_cache() dump_cache(1)
283 #define scale_cache() dump_cache(0)
286 main(int argc, char *argv[])
292 char *cp, *param, *value;
293 struct ether_addr *ea;
297 if ((argc < 2) || (argc % 2))
301 sd = socket(AF_INET, SOCK_DGRAM, 0);
304 strncpy(ifr.ifr_name, argv[1], sizeof(ifr.ifr_name));
305 ifr.ifr_addr.sa_family = AF_INET;
308 ifr.ifr_data = (caddr_t)psabuf;
309 if (ioctl(sd, SIOCGWLPSA, (caddr_t)&ifr))
312 /* get the current NWID */
313 if (ioctl(sd, SIOCGWLCNWID, (caddr_t)&ifr))
315 currnwid = (int)ifr.ifr_data;
317 /* just dump and exit? */
319 print_psa(psabuf, currnwid);
323 /* loop reading arg pairs */
324 for (argind = 2; argind < argc; argind += 2) {
326 param = argv[argind];
327 value = argv[argind+1];
331 if (!strcasecmp(param,"currnwid")) { /* set current NWID */
332 val = strtol(value,&cp,0);
333 if ((val < 0) || (val > 0xffff) || (cp == value))
334 errx(1,"bad NWID '%s'",value);
336 ifr.ifr_data = (caddr_t)val;
337 if (ioctl(sd, SIOCSWLCNWID, (caddr_t)&ifr))
338 err(1,"set NWID (interface not up?)");
342 if (!strcasecmp(param,"irq")) {
343 val = strtol(value,&cp,0);
345 if ((val == 0) || (cp == value))
346 errx(1,"bad IRQ '%s'",value);
347 psabuf[WLPSA_IRQNO] = (u_char)val;
352 if (!strcasecmp(param,"mac")) {
353 if ((ea = ether_aton(value)) == NULL)
354 errx(1,"bad ethernet address '%s'",value);
355 for (i = 0; i < 6; i++)
356 psabuf[WLPSA_LOCALMAC + i] = ea->octet[i];
361 if (!strcasecmp(param,"macsel")) {
362 if (!strcasecmp(value,"local")) {
363 psabuf[WLPSA_MACSEL] |= 0x1;
367 if (!strcasecmp(value,"universal")) {
368 psabuf[WLPSA_MACSEL] &= ~0x1;
372 errx(1,"bad macsel value '%s'",value);
375 if (!strcasecmp(param,"nwid")) {
376 val = strtol(value,&cp,0);
377 if ((val < 0) || (val > 0xffff) || (cp == value))
378 errx(1,"bad NWID '%s'",value);
379 psabuf[WLPSA_NWID] = (val >> 8) & 0xff;
380 psabuf[WLPSA_NWID+1] = val & 0xff;
384 if (!strcasecmp(param,"cache")) {
388 if (!strcasecmp(value,"raw")) {
395 else if (!strcasecmp(value,"scale")) {
402 else if (!strcasecmp(value,"zero")) {
403 if (ioctl(sd, SIOCDWLCACHE, (caddr_t)&ifr))
407 errx(1,"unknown value '%s'", value);
409 errx(1,"unknown parameter '%s'",param);
412 ifr.ifr_data = (caddr_t)psabuf;
413 if (ioctl(sd, SIOCSWLPSA, (caddr_t)&ifr))