wlconfig.c revision 26005
1/*
2 * Copyright (C) 1996
3 *      Michael Smith.  All rights reserved.
4 *
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 * 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 *
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
24 * SUCH DAMAGE.
25 *
26 * $Id$
27 *
28 */
29/*
30 * wlconfig.c
31 *
32 * utility to read out and change various WAVELAN parameters.
33 * Currently supports NWID and IRQ values.
34 *
35 * The NWID is used by 2 or more wavelan controllers to determine
36 * if packets should be received or not.  It is a filter that
37 * is roughly analogous to the "channel" setting with a garage
38 * door controller.  Two companies side by side with wavelan devices
39 * that could actually hear each other can use different NWIDs
40 * and ignore packets.  In truth however, the air space is shared,
41 * and the NWID is a virtual filter.
42 *
43 * In the current set of wavelan drivers, ioctls changed only
44 * the runtime radio modem registers which act in a manner analogous
45 * to an ethernet transceiver.  The ioctls do not change the
46 * stored nvram PSA (or parameter storage area).  At boot, the PSA
47 * values are stored in the radio modem.   Thus when the
48 * system reboots it will restore the wavelan NWID to the value
49 * stored in the PSA.  The NCR/ATT dos utilities must be used to
50 * change the initial NWID values in the PSA.  The wlconfig utility
51 * may be used to set a different NWID at runtime; this is only
52 * permitted while the interface is up and running.
53 *
54 * By contrast, the IRQ value can only be changed while the
55 * Wavelan card is down and unconfigured, and it will remain
56 * disabled after an IRQ change until reboot.
57 *
58 */
59
60#include <sys/param.h>
61#include <sys/socket.h>
62#include <sys/ioctl.h>
63#include <machine/if_wl_wavelan.h>
64
65#include <net/if.h>
66#include <netinet/in.h>
67#include <netinet/if_ether.h>
68extern struct ether_addr *ether_aton(char *a);
69
70#include <err.h>
71#include <stdio.h>
72#include <stdlib.h>
73#include <string.h>
74#include <unistd.h>
75#include <limits.h>
76
77/* translate IRQ bit to number */
78/* array for maping irq numbers to values for the irq parameter register */
79static int irqvals[16] = {
80    0, 0, 0, 0x01, 0x02, 0x04, 0, 0x08, 0, 0, 0x10, 0x20, 0x40, 0, 0, 0x80
81};
82
83int
84wlirq(int irqval)
85{
86    int irq;
87
88    for(irq = 0; irq < 16; irq++)
89	if(irqvals[irq] == irqval)
90	    return(irq);
91    return 0;
92}
93
94char *compat_type[] = {
95    "PC-AT 915MHz",
96    "PC-MC 915MHz",
97    "PC-AT 2.4GHz",
98    "PC-MC 2.4GHz",
99    "PCCARD or 1/2 size AT, 915MHz or 2.4GHz"
100};
101
102char *subband[] = {
103    "915MHz/see WaveModem",
104    "2425MHz",
105    "2460MHz",
106    "2484MHz",
107    "2430.5MHz"
108};
109
110
111/*
112** print_psa
113**
114** Given a pointer to a PSA structure, print it out
115*/
116void
117print_psa(u_char *psa, int currnwid)
118{
119    int		nwid;
120
121    /*
122    ** Work out what sort of board we have
123    */
124    if (psa[0] == 0x14) {
125	printf("Board type            : Microchannel\n");
126    } else {
127	if (psa[1] == 0) {
128	    printf("Board type            : PCCARD\n");
129	} else {
130	    printf("Board type            : ISA");
131	    if ((psa[4] == 0) &&
132		(psa[5] == 0) &&
133		(psa[6] == 0))
134		printf(" (DEC OEM)");
135	    printf("\n");
136	    printf("Base address options  : 0x300, 0x%02x0, 0x%02x0, 0x%02x0\n",
137		   (int)psa[1], (int)psa[2], (int)psa[3]);
138	    printf("Waitstates            : %d\n",psa[7] & 0xf);
139	    printf("Bus mode              : %s\n",(psa[7] & 0x10) ? "EISA" : "ISA");
140	    printf("IRQ                   : %d\n",wlirq(psa[8]));
141	}
142    }
143    printf("Default MAC address   : %02x:%02x:%02x:%02x:%02x:%02x\n",
144	   psa[0x10],psa[0x11],psa[0x12],psa[0x13],psa[0x14],psa[0x15]);
145    printf("Soft MAC address      : %02x:%02x:%02x:%02x:%02x:%02x\n",
146	   psa[0x16],psa[0x17],psa[0x18],psa[0x19],psa[0x1a],psa[0x1b]);
147    printf("Current MAC address   : %s\n",(psa[0x1c] & 0x1) ? "Soft" : "Default");
148    printf("Adapter compatability : ");
149    if (psa[0x1d] < 5) {
150	printf("%s\n",compat_type[psa[0x1d]]);
151    } else {
152	printf("unknown\n");
153    }
154    printf("Threshold preset      : %d\n",psa[0x1e]);
155    printf("Call code required    : %s\n",(psa[0x1f] & 0x1) ? "YES" : "NO");
156    if (psa[0x1f] & 0x1)
157	printf("Call code             : 0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
158	       psa[0x30],psa[0x31],psa[0x32],psa[0x33],psa[0x34],psa[0x35],psa[0x36],psa[0x37]);
159    printf("Subband               : %s\n",subband[psa[0x20] & 0xf]);
160    printf("Quality threshold     : %d\n",psa[0x21]);
161    printf("Hardware version      : %d (%s)\n",psa[0x22],psa[0x22] ? "Rel3" : "Rel1/Rel2");
162    printf("Network ID enable     : %s\n",(psa[0x25] & 0x1) ? "YES" : "NO");
163    if (psa[0x25] & 0x1) {
164	nwid = (psa[0x23] << 8) + psa[0x24];
165	printf("NWID                  : 0x%04x\n",nwid);
166	if (nwid != currnwid) {
167	    printf("Current NWID          : 0x%04x\n",currnwid);
168	}
169    }
170    printf("Datalink security     : %s\n",(psa[0x26] & 0x1) ? "YES" : "NO");
171    if (psa[0x26] & 0x1) {
172	printf("Encryption key        : ");
173	if (psa[0x27] == 0) {
174	    printf("DENIED\n");
175	} else {
176	    printf("0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
177		   psa[0x27],psa[0x28],psa[0x29],psa[0x2a],psa[0x2b],psa[0x2c],psa[0x2d],psa[0x2e]);
178	}
179    }
180    printf("Databus width         : %d (%s)\n",
181	   (psa[0x2f] & 0x1) ? 16 : 8, (psa[0x2f] & 0x80) ? "fixed" : "variable");
182    printf("Configuration state   : %sconfigured\n",(psa[0x38] & 0x1) ? "" : "un");
183    printf("CRC-16                : 0x%02x%02x\n",psa[0x3e],psa[0x3d]);
184    printf("CRC status            : ");
185    switch(psa[0x3f]) {
186    case 0xaa:
187	printf("OK\n");
188	break;
189    case 0x55:
190	printf("BAD\n");
191	break;
192    default:
193	printf("Error\n");
194	break;
195    }
196}
197
198
199void
200syntax(char *pname)
201{
202    fprintf(stderr,"Usage: %s <ifname> [<param> <value> ...]\n",pname);
203    fprintf(stderr,"    <ifname>    Wavelan interface name.\n");
204    fprintf(stderr,"    <param>     Parameter name (see below)\n");
205    fprintf(stderr,"    <value>     New value for parameter.\n");
206    fprintf(stderr," Parameter name:        Value:\n");
207    fprintf(stderr,"     irq		3,4,5,6,10,11,12,15\n");
208    fprintf(stderr,"     mac		soft ethernet address\n");
209    fprintf(stderr,"     macsel		soft or default\n");
210    fprintf(stderr,"     nwid		default NWID (0x0-0xffff)\n");
211    fprintf(stderr,"     currnwid       current NWID (0x0-0xffff) or 'get'\n");
212    exit(1);
213}
214
215void
216main(int argc, char *argv[])
217{
218    int 		sd;
219    struct ifreq	ifr;
220    u_char		psabuf[0x40];
221    int			val, argind, i;
222    char		*cp, *param, *value;
223    struct ether_addr	*ea;
224    int			work = 0;
225    int			currnwid;
226
227    if ((argc < 2) || (argc % 2))
228	syntax(argv[0]);
229
230    /* get a socket */
231    sd = socket(AF_INET, SOCK_DGRAM, 0);
232    if (sd < 0)
233	err(1,"socket");
234    strncpy(ifr.ifr_name, argv[1], sizeof(ifr.ifr_name));
235    ifr.ifr_addr.sa_family = AF_INET;
236
237    /* get the PSA */
238    ifr.ifr_data = (caddr_t)psabuf;
239    if (ioctl(sd, SIOCGWLPSA, (caddr_t)&ifr))
240	err(1,"Get PSA");
241
242    /* get the current NWID */
243    if (ioctl(sd, SIOCGWLCNWID, (caddr_t)&ifr))
244	err(1,"Get NWID");
245    currnwid = (int)ifr.ifr_data;
246
247    /* just dump and exit? */
248    if (argc == 2) {
249	print_psa(psabuf, currnwid);
250	exit(0);
251    }
252
253    /* loop reading arg pairs */
254    for (argind = 2; argind < argc; argind += 2) {
255
256	param = argv[argind];
257	value = argv[argind+1];
258
259	/* What to do? */
260
261	if (!strcasecmp(param,"currnwid")) {		/* set current NWID */
262	    val = strtol(value,&cp,0);
263	    if ((val < 0) || (val > 0xffff) || (cp == value))
264		errx(1,"Bad NWID '%s'",value);
265
266	    ifr.ifr_data = (caddr_t)val;
267	    if (ioctl(sd, SIOCSWLCNWID, (caddr_t)&ifr))
268		err(1,"Set NWID (interface not up?)");
269	    continue ;
270	}
271
272	if (!strcasecmp(param,"irq")) {
273	    val = strtol(value,&cp,0);
274	    val = irqvals[val];
275	    if ((val == 0) || (cp == value))
276		errx(1,"Bad IRQ '%s'",value);
277	    psabuf[WLPSA_IRQNO] = (u_char)val;
278	    work = 1;
279	    continue;
280	}
281
282	if (!strcasecmp(param,"mac")) {
283	    if ((ea = ether_aton(value)) == NULL)
284		errx(1,"Bad ethernet address '%s'",value);
285	    for (i = 0; i < 6; i++)
286		psabuf[WLPSA_LOCALMAC + i] = ea->octet[i];
287	    work = 1;
288	    continue;
289	}
290
291	if (!strcasecmp(param,"macsel")) {
292	    if (!strcasecmp(value,"local")) {
293		psabuf[WLPSA_MACSEL] |= 0x1;
294		work = 1;
295		continue;
296	    }
297	    if (!strcasecmp(value,"universal")) {
298		psabuf[WLPSA_MACSEL] &= ~0x1;
299		work = 1;
300		continue;
301	    }
302	    errx(1,"Bad macsel value '%s'",value);
303	}
304
305	if (!strcasecmp(param,"nwid")) {
306	    val = strtol(value,&cp,0);
307	    if ((val < 0) || (val > 0xffff) || (cp == value))
308		errx(1,"Bad NWID '%s'",value);
309	    psabuf[WLPSA_NWID] = (val >> 8) & 0xff;
310	    psabuf[WLPSA_NWID+1] = val & 0xff;
311	    work = 1;
312	    continue;
313	}
314	errx(1,"Unknown parameter '%s'",param);
315    }
316    if (work) {
317	ifr.ifr_data = (caddr_t)psabuf;
318	if (ioctl(sd, SIOCSWLPSA, (caddr_t)&ifr))
319	    err(1,"Set PSA");
320    }
321}
322
323
324
325
326