1 /* $NetBSD: awi_wicfg.c,v 1.3 2000/07/06 17:22:25 onoe Exp $ */
2 /* $FreeBSD: src/sys/dev/awi/awi_wicfg.c,v 1.3.2.2 2002/06/18 08:06:15 jhay Exp $ */
3 /* $DragonFly: src/sys/dev/netif/awi/Attic/awi_wicfg.c,v 1.2 2003/06/17 04:28:22 dillon Exp $ */
6 * Copyright (c) 2000 The NetBSD Foundation, Inc.
9 * This code is derived from software contributed to The NetBSD Foundation
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
42 * WaveLAN compatible configuration support routines for the awi driver.
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
49 #include <sys/malloc.h>
51 #include <sys/socket.h>
52 #include <sys/errno.h>
53 #include <sys/sockio.h>
54 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
57 #include <sys/device.h>
61 #include <net/if_dl.h>
63 #include <net/ethernet.h>
64 #include <net/if_arp.h>
66 #include <net/if_ether.h>
68 #include <net/if_media.h>
69 #include <net/if_ieee80211.h>
71 #include <machine/cpu.h>
72 #include <machine/bus.h>
74 #include <machine/clock.h>
78 #include <dev/ic/am79c930reg.h>
79 #include <dev/ic/am79c930var.h>
80 #include <dev/ic/awireg.h>
81 #include <dev/ic/awivar.h>
83 #include <dev/pcmcia/if_wi_ieee.h> /* XXX */
86 #include <dev/awi/am79c930reg.h>
87 #include <dev/awi/am79c930var.h>
89 #undef _KERNEL /* XXX */
90 #include <dev/wi/if_wavelan_ieee.h> /* XXX */
91 #define _KERNEL /* XXX */
92 #include <dev/awi/awireg.h>
93 #include <dev/awi/awivar.h>
96 static int awi_cfgget __P((struct ifnet *ifp, u_long cmd, caddr_t data));
97 static int awi_cfgset __P((struct ifnet *ifp, u_long cmd, caddr_t data));
100 awi_wicfg(ifp, cmd, data)
109 error = awi_cfgget(ifp, cmd, data);
113 error = suser(curproc);
115 error = suser(curproc->p_ucred, &curproc->p_acflag);
119 error = awi_cfgset(ifp, cmd, data);
129 awi_cfgget(ifp, cmd, data)
134 int i, error, keylen;
136 struct awi_softc *sc = (struct awi_softc *)ifp->if_softc;
137 struct ifreq *ifr = (struct ifreq *)data;
138 struct wi_ltv_keys *keys;
142 struct wi_sigcache wsc;
146 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
149 switch (wreq.wi_type) {
150 case WI_RID_SERIALNO:
151 memcpy(wreq.wi_val, sc->sc_banner, AWI_BANNER_LEN);
152 wreq.wi_len = (AWI_BANNER_LEN + 1) / 2;
154 case WI_RID_NODENAME:
155 strcpy((char *)&wreq.wi_val[1], hostname);
156 wreq.wi_val[0] = strlen(hostname);
157 wreq.wi_len = (1 + wreq.wi_val[0] + 1) / 2;
159 case WI_RID_OWN_SSID:
161 wreq.wi_val[0] = p[1];
162 memcpy(&wreq.wi_val[1], p + 2, p[1]);
163 wreq.wi_len = (1 + wreq.wi_val[0] + 1) / 2;
165 case WI_RID_CURRENT_SSID:
166 if (ifp->if_flags & IFF_RUNNING) {
167 p = sc->sc_bss.essid;
168 wreq.wi_val[0] = p[1];
169 memcpy(&wreq.wi_val[1], p + 2, p[1]);
172 wreq.wi_val[1] = '\0';
174 wreq.wi_len = (1 + wreq.wi_val[0] + 1) / 2;
176 case WI_RID_DESIRED_SSID:
177 p = sc->sc_mib_mac.aDesired_ESS_ID;
178 wreq.wi_val[0] = p[1];
179 memcpy(&wreq.wi_val[1], p + 2, p[1]);
180 wreq.wi_len = (1 + wreq.wi_val[0] + 1) / 2;
182 case WI_RID_CURRENT_BSSID:
183 if (ifp->if_flags & IFF_RUNNING)
184 memcpy(wreq.wi_val, sc->sc_bss.bssid, ETHER_ADDR_LEN);
186 memset(wreq.wi_val, 0, ETHER_ADDR_LEN);
187 wreq.wi_len = ETHER_ADDR_LEN / 2;
189 case WI_RID_CHANNEL_LIST:
190 if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
191 wreq.wi_val[0] = sc->sc_scan_min;
192 wreq.wi_val[1] = sc->sc_scan_max;
196 for (i = sc->sc_scan_min; i <= sc->sc_scan_max; i++)
197 wreq.wi_val[0] |= 1 << (i - 1);
201 case WI_RID_OWN_CHNL:
202 wreq.wi_val[0] = sc->sc_ownch;
205 case WI_RID_CURRENT_CHAN:
206 if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH)
207 wreq.wi_val[0] = sc->sc_bss.pattern;
209 wreq.wi_val[0] = sc->sc_bss.chanset;
212 case WI_RID_COMMS_QUALITY:
213 wreq.wi_val[0] = 0; /* quality */
214 wreq.wi_val[1] = sc->sc_bss.rssi; /* signal */
215 wreq.wi_val[2] = 0; /* noise */
219 wreq.wi_val[0] = sc->sc_mib_mac.aPromiscuous_Enable;
222 case WI_RID_PORTTYPE:
223 if (sc->sc_mib_local.Network_Mode)
225 else if (!sc->sc_no_bssid)
231 case WI_RID_MAC_NODE:
232 memcpy(wreq.wi_val, sc->sc_mib_addr.aMAC_Address,
234 wreq.wi_len = ETHER_ADDR_LEN / 2;
237 case WI_RID_CUR_TX_RATE:
238 wreq.wi_val[0] = sc->sc_tx_rate / 10;
241 case WI_RID_RTS_THRESH:
242 wreq.wi_val[0] = LE_READ_2(&sc->sc_mib_mac.aRTS_Threshold);
245 case WI_RID_CREATE_IBSS:
246 wreq.wi_val[0] = sc->sc_start_bss;
249 case WI_RID_SYSTEM_SCALE:
250 wreq.wi_val[0] = 1; /* low density ... not supported */
253 case WI_RID_PM_ENABLED:
254 wreq.wi_val[0] = sc->sc_mib_local.Power_Saving_Mode_Dis ? 0 : 1;
257 case WI_RID_MAX_SLEEP:
258 wreq.wi_val[0] = 0; /* not implemented */
261 case WI_RID_WEP_AVAIL:
265 case WI_RID_ENCRYPTION:
266 wreq.wi_val[0] = awi_wep_getalgo(sc);
269 case WI_RID_TX_CRYPT_KEY:
270 wreq.wi_val[0] = sc->sc_wep_defkid;
273 case WI_RID_DEFLT_CRYPT_KEYS:
274 keys = (struct wi_ltv_keys *)&wreq;
275 /* do not show keys to non-root user */
277 error = suser(curproc);
279 error = suser(curproc->p_ucred, &curproc->p_acflag);
282 memset(keys, 0, sizeof(*keys));
286 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
287 k = &keys->wi_keys[i];
288 keylen = sizeof(k->wi_keydat);
289 error = awi_wep_getkey(sc, i, k->wi_keydat, &keylen);
292 k->wi_keylen = keylen;
294 wreq.wi_len = sizeof(*keys) / 2;
296 case WI_RID_MAX_DATALEN:
297 wreq.wi_val[0] = LE_READ_2(&sc->sc_mib_mac.aMax_Frame_Length);
300 case WI_RID_IFACE_STATS:
301 /* not implemented yet */
305 case WI_RID_READ_CACHE:
306 for (bp = TAILQ_FIRST(&sc->sc_scan), i = 0;
307 bp != NULL && i < MAXWICACHE;
308 bp = TAILQ_NEXT(bp, list), i++) {
309 memcpy(wsc.macsrc, bp->esrc, ETHER_ADDR_LEN);
311 memcpy(&wsc.ipsrc, bp->bssid, sizeof(wsc.ipsrc));
312 wsc.signal = bp->rssi;
315 memcpy((caddr_t)wreq.wi_val + sizeof(wsc) * i,
318 wreq.wi_len = sizeof(wsc) * i / 2;
327 error = copyout(&wreq, ifr->ifr_data, sizeof(wreq));
333 awi_cfgset(ifp, cmd, data)
338 int i, error, rate, oregion;
340 struct awi_softc *sc = (struct awi_softc *)ifp->if_softc;
341 struct ifreq *ifr = (struct ifreq *)data;
342 struct wi_ltv_keys *keys;
346 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
349 if (wreq.wi_len-- < 1)
351 switch (wreq.wi_type) {
352 case WI_RID_SERIALNO:
353 case WI_RID_NODENAME:
356 case WI_RID_OWN_SSID:
357 if (wreq.wi_len < (1 + wreq.wi_val[0] + 1) / 2) {
361 if (wreq.wi_val[0] > IEEE80211_NWID_LEN) {
365 memset(sc->sc_ownssid, 0, AWI_ESS_ID_SIZE);
366 sc->sc_ownssid[0] = IEEE80211_ELEMID_SSID;
367 sc->sc_ownssid[1] = wreq.wi_val[0];
368 memcpy(&sc->sc_ownssid[2], &wreq.wi_val[1], wreq.wi_val[0]);
369 if (!sc->sc_mib_local.Network_Mode &&
370 !sc->sc_no_bssid && sc->sc_start_bss)
373 case WI_RID_CURRENT_SSID:
376 case WI_RID_DESIRED_SSID:
377 if (wreq.wi_len < (1 + wreq.wi_val[0] + 1) / 2) {
381 if (wreq.wi_val[0] > IEEE80211_NWID_LEN) {
385 memset(sc->sc_mib_mac.aDesired_ESS_ID, 0, AWI_ESS_ID_SIZE);
386 sc->sc_mib_mac.aDesired_ESS_ID[0] = IEEE80211_ELEMID_SSID;
387 sc->sc_mib_mac.aDesired_ESS_ID[1] = wreq.wi_val[0];
388 memcpy(&sc->sc_mib_mac.aDesired_ESS_ID[2], &wreq.wi_val[1],
390 if (sc->sc_mib_local.Network_Mode || !sc->sc_no_bssid)
393 case WI_RID_CURRENT_BSSID:
396 case WI_RID_CHANNEL_LIST:
397 if (wreq.wi_len != 1) {
401 oregion = sc->sc_mib_phy.aCurrent_Reg_Domain;
402 if (wreq.wi_val[0] == oregion)
404 sc->sc_mib_phy.aCurrent_Reg_Domain = wreq.wi_val[0];
405 error = awi_init_region(sc);
407 sc->sc_mib_phy.aCurrent_Reg_Domain = oregion;
412 case WI_RID_OWN_CHNL:
413 if (wreq.wi_len != 1) {
417 if (wreq.wi_val[0] < sc->sc_scan_min ||
418 wreq.wi_val[0] > sc->sc_scan_max) {
422 sc->sc_ownch = wreq.wi_val[0];
423 if (!sc->sc_mib_local.Network_Mode)
426 case WI_RID_CURRENT_CHAN:
429 case WI_RID_COMMS_QUALITY:
433 if (wreq.wi_len != 1) {
437 if (ifp->if_flags & IFF_PROMISC) {
438 if (wreq.wi_val[0] == 0) {
439 ifp->if_flags &= ~IFF_PROMISC;
443 if (wreq.wi_val[0] != 0) {
444 ifp->if_flags |= IFF_PROMISC;
449 case WI_RID_PORTTYPE:
450 if (wreq.wi_len != 1) {
454 switch (wreq.wi_val[0]) {
456 sc->sc_mib_local.Network_Mode = 1;
461 sc->sc_mib_local.Network_Mode = 0;
466 if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
470 sc->sc_mib_local.Network_Mode = 0;
479 case WI_RID_MAC_NODE:
480 /* XXX: should be implemented? */
484 if (wreq.wi_len != 1) {
488 phy_rates = sc->sc_mib_phy.aSuprt_Data_Rates;
489 switch (wreq.wi_val[0]) {
494 rate = wreq.wi_val[0] * 10;
502 phy_rates = sc->sc_mib_phy.aSuprt_Data_Rates;
503 rate = AWI_RATE_1MBIT;
504 for (i = 0; i < phy_rates[1]; i++) {
505 if (AWI_80211_RATE(phy_rates[2 + i]) > rate)
506 rate = AWI_80211_RATE(phy_rates[2 + i]);
516 for (i = 0; i < phy_rates[1]; i++) {
517 if (rate == AWI_80211_RATE(phy_rates[2 + i]))
520 if (i == phy_rates[1]) {
524 sc->sc_tx_rate = rate;
526 case WI_RID_CUR_TX_RATE:
529 case WI_RID_RTS_THRESH:
530 if (wreq.wi_len != 1) {
534 LE_WRITE_2(&sc->sc_mib_mac.aRTS_Threshold, wreq.wi_val[0]);
537 case WI_RID_CREATE_IBSS:
538 if (wreq.wi_len != 1) {
542 sc->sc_start_bss = wreq.wi_val[0] ? 1 : 0;
545 case WI_RID_SYSTEM_SCALE:
546 if (wreq.wi_len != 1) {
550 if (wreq.wi_val[0] != 1)
551 error = EINVAL; /* not supported */
553 case WI_RID_PM_ENABLED:
554 if (wreq.wi_len != 1) {
558 if (wreq.wi_val[0] != 0)
559 error = EINVAL; /* not implemented */
561 case WI_RID_MAX_SLEEP:
562 error = EINVAL; /* not implemented */
564 case WI_RID_WEP_AVAIL:
567 case WI_RID_ENCRYPTION:
568 if (wreq.wi_len != 1) {
572 error = awi_wep_setalgo(sc, wreq.wi_val[0]);
577 case WI_RID_TX_CRYPT_KEY:
578 if (wreq.wi_len != 1) {
582 if (wreq.wi_val[0] >= IEEE80211_WEP_NKID) {
586 sc->sc_wep_defkid = wreq.wi_val[1];
588 case WI_RID_DEFLT_CRYPT_KEYS:
589 if (wreq.wi_len != sizeof(*keys) / 2) {
593 keys = (struct wi_ltv_keys *)&wreq;
594 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
595 k = &keys->wi_keys[i];
596 error = awi_wep_setkey(sc, i, k->wi_keydat,
602 case WI_RID_MAX_DATALEN:
603 if (wreq.wi_len != 1) {
607 if (wreq.wi_val[0] < 350 || wreq.wi_val[0] > 2304) {
611 LE_WRITE_2(&sc->sc_mib_mac.aMax_Frame_Length, wreq.wi_val[0]);
613 case WI_RID_IFACE_STATS:
620 if (error == ENETRESET) {
621 if (sc->sc_enabled) {
623 error = awi_init(sc);