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.9 2005/06/13 20:25:56 joerg 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>
57 #include <net/if_dl.h>
58 #include <net/ethernet.h>
59 #include <net/if_arp.h>
60 #include <net/if_media.h>
61 #include <netproto/802_11/ieee80211.h>
62 #include <netproto/802_11/ieee80211_ioctl.h>
64 #include <machine/cpu.h>
65 #include <machine/bus.h>
67 #include <dev/netif/awi/am79c930reg.h>
68 #include <dev/netif/awi/am79c930var.h>
70 #include <netproto/802_11/if_wavelan_ieee.h>
71 #include <dev/netif/awi/awireg.h>
72 #include <dev/netif/awi/awivar.h>
74 static int awi_cfgget (struct ifnet *ifp, u_long cmd, caddr_t data);
75 static int awi_cfgset (struct ifnet *ifp, u_long cmd, caddr_t data);
78 awi_wicfg(ifp, cmd, data)
84 struct thread *td = curthread;
88 error = awi_cfgget(ifp, cmd, data);
91 error = suser(td); /* note: EPERM if no proc */
94 error = awi_cfgset(ifp, cmd, data);
104 awi_cfgget(ifp, cmd, data)
109 int i, error, keylen;
111 struct awi_softc *sc = (struct awi_softc *)ifp->if_softc;
112 struct ifreq *ifr = (struct ifreq *)data;
113 struct wi_ltv_keys *keys;
117 struct wi_sigcache wsc;
120 struct thread *td = curthread;
122 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
125 switch (wreq.wi_type) {
126 case WI_RID_SERIALNO:
127 memcpy(wreq.wi_val, sc->sc_banner, AWI_BANNER_LEN);
128 wreq.wi_len = (AWI_BANNER_LEN + 1) / 2;
130 case WI_RID_NODENAME:
131 strcpy((char *)&wreq.wi_val[1], hostname);
132 wreq.wi_val[0] = strlen(hostname);
133 wreq.wi_len = (1 + wreq.wi_val[0] + 1) / 2;
135 case WI_RID_OWN_SSID:
137 wreq.wi_val[0] = p[1];
138 memcpy(&wreq.wi_val[1], p + 2, p[1]);
139 wreq.wi_len = (1 + wreq.wi_val[0] + 1) / 2;
141 case WI_RID_CURRENT_SSID:
142 if (ifp->if_flags & IFF_RUNNING) {
143 p = sc->sc_bss.essid;
144 wreq.wi_val[0] = p[1];
145 memcpy(&wreq.wi_val[1], p + 2, p[1]);
148 wreq.wi_val[1] = '\0';
150 wreq.wi_len = (1 + wreq.wi_val[0] + 1) / 2;
152 case WI_RID_DESIRED_SSID:
153 p = sc->sc_mib_mac.aDesired_ESS_ID;
154 wreq.wi_val[0] = p[1];
155 memcpy(&wreq.wi_val[1], p + 2, p[1]);
156 wreq.wi_len = (1 + wreq.wi_val[0] + 1) / 2;
158 case WI_RID_CURRENT_BSSID:
159 if (ifp->if_flags & IFF_RUNNING)
160 memcpy(wreq.wi_val, sc->sc_bss.bssid, ETHER_ADDR_LEN);
162 memset(wreq.wi_val, 0, ETHER_ADDR_LEN);
163 wreq.wi_len = ETHER_ADDR_LEN / 2;
165 case WI_RID_CHANNEL_LIST:
166 if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
167 wreq.wi_val[0] = sc->sc_scan_min;
168 wreq.wi_val[1] = sc->sc_scan_max;
172 for (i = sc->sc_scan_min; i <= sc->sc_scan_max; i++)
173 wreq.wi_val[0] |= 1 << (i - 1);
177 case WI_RID_OWN_CHNL:
178 wreq.wi_val[0] = sc->sc_ownch;
181 case WI_RID_CURRENT_CHAN:
182 if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH)
183 wreq.wi_val[0] = sc->sc_bss.pattern;
185 wreq.wi_val[0] = sc->sc_bss.chanset;
188 case WI_RID_COMMS_QUALITY:
189 wreq.wi_val[0] = 0; /* quality */
190 wreq.wi_val[1] = sc->sc_bss.rssi; /* signal */
191 wreq.wi_val[2] = 0; /* noise */
195 wreq.wi_val[0] = sc->sc_mib_mac.aPromiscuous_Enable;
198 case WI_RID_PORTTYPE:
199 if (sc->sc_mib_local.Network_Mode)
201 else if (!sc->sc_no_bssid)
207 case WI_RID_MAC_NODE:
208 memcpy(wreq.wi_val, sc->sc_mib_addr.aMAC_Address,
210 wreq.wi_len = ETHER_ADDR_LEN / 2;
213 case WI_RID_CUR_TX_RATE:
214 wreq.wi_val[0] = sc->sc_tx_rate / 10;
217 case WI_RID_RTS_THRESH:
218 wreq.wi_val[0] = LE_READ_2(&sc->sc_mib_mac.aRTS_Threshold);
221 case WI_RID_CREATE_IBSS:
222 wreq.wi_val[0] = sc->sc_start_bss;
225 case WI_RID_SYSTEM_SCALE:
226 wreq.wi_val[0] = 1; /* low density ... not supported */
229 case WI_RID_PM_ENABLED:
230 wreq.wi_val[0] = sc->sc_mib_local.Power_Saving_Mode_Dis ? 0 : 1;
233 case WI_RID_MAX_SLEEP:
234 wreq.wi_val[0] = 0; /* not implemented */
237 case WI_RID_WEP_AVAIL:
241 case WI_RID_ENCRYPTION:
242 wreq.wi_val[0] = awi_wep_getalgo(sc);
245 case WI_RID_TX_CRYPT_KEY:
246 wreq.wi_val[0] = sc->sc_wep_defkid;
249 case WI_RID_DEFLT_CRYPT_KEYS:
250 keys = (struct wi_ltv_keys *)&wreq;
251 /* do not show keys to non-root user */
252 error = suser(td); /* note: EPERM if no proc */
254 memset(keys, 0, sizeof(*keys));
258 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
259 k = &keys->wi_keys[i];
260 keylen = sizeof(k->wi_keydat);
261 error = awi_wep_getkey(sc, i, k->wi_keydat, &keylen);
264 k->wi_keylen = keylen;
266 wreq.wi_len = sizeof(*keys) / 2;
268 case WI_RID_MAX_DATALEN:
269 wreq.wi_val[0] = LE_READ_2(&sc->sc_mib_mac.aMax_Frame_Length);
272 case WI_RID_IFACE_STATS:
273 /* not implemented yet */
277 case WI_RID_READ_CACHE:
278 for (bp = TAILQ_FIRST(&sc->sc_scan), i = 0;
279 bp != NULL && i < MAXWICACHE;
280 bp = TAILQ_NEXT(bp, list), i++) {
281 memcpy(wsc.macsrc, bp->esrc, ETHER_ADDR_LEN);
283 memcpy(&wsc.ipsrc, bp->bssid, sizeof(wsc.ipsrc));
284 wsc.signal = bp->rssi;
287 memcpy((caddr_t)wreq.wi_val + sizeof(wsc) * i,
290 wreq.wi_len = sizeof(wsc) * i / 2;
299 error = copyout(&wreq, ifr->ifr_data, sizeof(wreq));
305 awi_cfgset(ifp, cmd, data)
310 int i, error, rate, oregion;
312 struct awi_softc *sc = (struct awi_softc *)ifp->if_softc;
313 struct ifreq *ifr = (struct ifreq *)data;
314 struct wi_ltv_keys *keys;
318 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
321 if (wreq.wi_len-- < 1)
323 switch (wreq.wi_type) {
324 case WI_RID_SERIALNO:
325 case WI_RID_NODENAME:
328 case WI_RID_OWN_SSID:
329 if (wreq.wi_len < (1 + wreq.wi_val[0] + 1) / 2) {
333 if (wreq.wi_val[0] > IEEE80211_NWID_LEN) {
337 memset(sc->sc_ownssid, 0, AWI_ESS_ID_SIZE);
338 sc->sc_ownssid[0] = IEEE80211_ELEMID_SSID;
339 sc->sc_ownssid[1] = wreq.wi_val[0];
340 memcpy(&sc->sc_ownssid[2], &wreq.wi_val[1], wreq.wi_val[0]);
341 if (!sc->sc_mib_local.Network_Mode &&
342 !sc->sc_no_bssid && sc->sc_start_bss)
345 case WI_RID_CURRENT_SSID:
348 case WI_RID_DESIRED_SSID:
349 if (wreq.wi_len < (1 + wreq.wi_val[0] + 1) / 2) {
353 if (wreq.wi_val[0] > IEEE80211_NWID_LEN) {
357 memset(sc->sc_mib_mac.aDesired_ESS_ID, 0, AWI_ESS_ID_SIZE);
358 sc->sc_mib_mac.aDesired_ESS_ID[0] = IEEE80211_ELEMID_SSID;
359 sc->sc_mib_mac.aDesired_ESS_ID[1] = wreq.wi_val[0];
360 memcpy(&sc->sc_mib_mac.aDesired_ESS_ID[2], &wreq.wi_val[1],
362 if (sc->sc_mib_local.Network_Mode || !sc->sc_no_bssid)
365 case WI_RID_CURRENT_BSSID:
368 case WI_RID_CHANNEL_LIST:
369 if (wreq.wi_len != 1) {
373 oregion = sc->sc_mib_phy.aCurrent_Reg_Domain;
374 if (wreq.wi_val[0] == oregion)
376 sc->sc_mib_phy.aCurrent_Reg_Domain = wreq.wi_val[0];
377 error = awi_init_region(sc);
379 sc->sc_mib_phy.aCurrent_Reg_Domain = oregion;
384 case WI_RID_OWN_CHNL:
385 if (wreq.wi_len != 1) {
389 if (wreq.wi_val[0] < sc->sc_scan_min ||
390 wreq.wi_val[0] > sc->sc_scan_max) {
394 sc->sc_ownch = wreq.wi_val[0];
395 if (!sc->sc_mib_local.Network_Mode)
398 case WI_RID_CURRENT_CHAN:
401 case WI_RID_COMMS_QUALITY:
405 if (wreq.wi_len != 1) {
409 if (ifp->if_flags & IFF_PROMISC) {
410 if (wreq.wi_val[0] == 0) {
411 ifp->if_flags &= ~IFF_PROMISC;
415 if (wreq.wi_val[0] != 0) {
416 ifp->if_flags |= IFF_PROMISC;
421 case WI_RID_PORTTYPE:
422 if (wreq.wi_len != 1) {
426 switch (wreq.wi_val[0]) {
428 sc->sc_mib_local.Network_Mode = 1;
433 sc->sc_mib_local.Network_Mode = 0;
438 if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
442 sc->sc_mib_local.Network_Mode = 0;
451 case WI_RID_MAC_NODE:
452 /* XXX: should be implemented? */
456 if (wreq.wi_len != 1) {
460 phy_rates = sc->sc_mib_phy.aSuprt_Data_Rates;
461 switch (wreq.wi_val[0]) {
466 rate = wreq.wi_val[0] * 10;
474 phy_rates = sc->sc_mib_phy.aSuprt_Data_Rates;
475 rate = AWI_RATE_1MBIT;
476 for (i = 0; i < phy_rates[1]; i++) {
477 if (AWI_80211_RATE(phy_rates[2 + i]) > rate)
478 rate = AWI_80211_RATE(phy_rates[2 + i]);
488 for (i = 0; i < phy_rates[1]; i++) {
489 if (rate == AWI_80211_RATE(phy_rates[2 + i]))
492 if (i == phy_rates[1]) {
496 sc->sc_tx_rate = rate;
498 case WI_RID_CUR_TX_RATE:
501 case WI_RID_RTS_THRESH:
502 if (wreq.wi_len != 1) {
506 LE_WRITE_2(&sc->sc_mib_mac.aRTS_Threshold, wreq.wi_val[0]);
509 case WI_RID_CREATE_IBSS:
510 if (wreq.wi_len != 1) {
514 sc->sc_start_bss = wreq.wi_val[0] ? 1 : 0;
517 case WI_RID_SYSTEM_SCALE:
518 if (wreq.wi_len != 1) {
522 if (wreq.wi_val[0] != 1)
523 error = EINVAL; /* not supported */
525 case WI_RID_PM_ENABLED:
526 if (wreq.wi_len != 1) {
530 if (wreq.wi_val[0] != 0)
531 error = EINVAL; /* not implemented */
533 case WI_RID_MAX_SLEEP:
534 error = EINVAL; /* not implemented */
536 case WI_RID_WEP_AVAIL:
539 case WI_RID_ENCRYPTION:
540 if (wreq.wi_len != 1) {
544 error = awi_wep_setalgo(sc, wreq.wi_val[0]);
549 case WI_RID_TX_CRYPT_KEY:
550 if (wreq.wi_len != 1) {
554 if (wreq.wi_val[0] >= IEEE80211_WEP_NKID) {
558 sc->sc_wep_defkid = wreq.wi_val[1];
560 case WI_RID_DEFLT_CRYPT_KEYS:
561 if (wreq.wi_len != sizeof(*keys) / 2) {
565 keys = (struct wi_ltv_keys *)&wreq;
566 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
567 k = &keys->wi_keys[i];
568 error = awi_wep_setkey(sc, i, k->wi_keydat,
574 case WI_RID_MAX_DATALEN:
575 if (wreq.wi_len != 1) {
579 if (wreq.wi_val[0] < 350 || wreq.wi_val[0] > 2304) {
583 LE_WRITE_2(&sc->sc_mib_mac.aMax_Frame_Length, wreq.wi_val[0]);
585 case WI_RID_IFACE_STATS:
592 if (error == ENETRESET) {
593 if (sc->sc_enabled) {
595 error = awi_init(sc);