1 /* $NetBSD: awi_wicfg.c,v 1.3 2000/07/06 17:22:25 onoe Exp $ */
5 * Copyright (c) 2000 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
41 * WaveLAN compatible configuration support routines for the awi driver.
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #include <sys/socket.h>
51 #include <sys/errno.h>
52 #include <sys/sockio.h>
53 #if defined(__FreeBSD__) && __FreeBSD_version >= 400000
56 #include <sys/device.h>
60 #include <net/if_dl.h>
62 #include <net/ethernet.h>
63 #include <net/if_arp.h>
65 #include <net/if_ether.h>
67 #include <net/if_media.h>
68 #include <net/if_ieee80211.h>
70 #include <machine/cpu.h>
71 #include <machine/bus.h>
74 #include <dev/ic/am79c930reg.h>
75 #include <dev/ic/am79c930var.h>
76 #include <dev/ic/awireg.h>
77 #include <dev/ic/awivar.h>
79 #include <dev/pcmcia/if_wi_ieee.h> /* XXX */
82 #include <dev/awi/am79c930reg.h>
83 #include <dev/awi/am79c930var.h>
85 #undef _KERNEL /* XXX */
86 #include <dev/wi/if_wavelan_ieee.h> /* XXX */
87 #define _KERNEL /* XXX */
88 #include <dev/awi/awireg.h>
89 #include <dev/awi/awivar.h>
92 static int awi_cfgget(struct ifnet *ifp, u_long cmd, caddr_t data);
93 static int awi_cfgset(struct ifnet *ifp, u_long cmd, caddr_t data);
96 awi_wicfg(ifp, cmd, data)
105 error = awi_cfgget(ifp, cmd, data);
109 #if __FreeBSD_version < 500028
110 error = suser(curproc);
112 error = suser(curthread);
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 #if __FreeBSD_version < 500028
278 error = suser(curproc);
280 error = suser(curthread);
283 error = suser(curproc->p_ucred, &curproc->p_acflag);
286 memset(keys, 0, sizeof(*keys));
290 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
291 k = &keys->wi_keys[i];
292 keylen = sizeof(k->wi_keydat);
293 error = awi_wep_getkey(sc, i, k->wi_keydat, &keylen);
296 k->wi_keylen = keylen;
298 wreq.wi_len = sizeof(*keys) / 2;
300 case WI_RID_MAX_DATALEN:
301 wreq.wi_val[0] = LE_READ_2(&sc->sc_mib_mac.aMax_Frame_Length);
304 case WI_RID_IFACE_STATS:
305 /* not implemented yet */
309 case WI_RID_READ_CACHE:
310 for (bp = TAILQ_FIRST(&sc->sc_scan), i = 0;
311 bp != NULL && i < MAXWICACHE;
312 bp = TAILQ_NEXT(bp, list), i++) {
313 memcpy(wsc.macsrc, bp->esrc, ETHER_ADDR_LEN);
315 memcpy(&wsc.ipsrc, bp->bssid, sizeof(wsc.ipsrc));
316 wsc.signal = bp->rssi;
319 memcpy((caddr_t)wreq.wi_val + sizeof(wsc) * i,
322 wreq.wi_len = sizeof(wsc) * i / 2;
331 error = copyout(&wreq, ifr->ifr_data, sizeof(wreq));
337 awi_cfgset(ifp, cmd, data)
342 int i, error, rate, oregion;
344 struct awi_softc *sc = (struct awi_softc *)ifp->if_softc;
345 struct ifreq *ifr = (struct ifreq *)data;
346 struct wi_ltv_keys *keys;
350 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
353 if (wreq.wi_len-- < 1)
355 switch (wreq.wi_type) {
356 case WI_RID_SERIALNO:
357 case WI_RID_NODENAME:
360 case WI_RID_OWN_SSID:
361 if (wreq.wi_len < (1 + wreq.wi_val[0] + 1) / 2) {
365 if (wreq.wi_val[0] > IEEE80211_NWID_LEN) {
369 memset(sc->sc_ownssid, 0, AWI_ESS_ID_SIZE);
370 sc->sc_ownssid[0] = IEEE80211_ELEMID_SSID;
371 sc->sc_ownssid[1] = wreq.wi_val[0];
372 memcpy(&sc->sc_ownssid[2], &wreq.wi_val[1], wreq.wi_val[0]);
373 if (!sc->sc_mib_local.Network_Mode &&
374 !sc->sc_no_bssid && sc->sc_start_bss)
377 case WI_RID_CURRENT_SSID:
380 case WI_RID_DESIRED_SSID:
381 if (wreq.wi_len < (1 + wreq.wi_val[0] + 1) / 2) {
385 if (wreq.wi_val[0] > IEEE80211_NWID_LEN) {
389 memset(sc->sc_mib_mac.aDesired_ESS_ID, 0, AWI_ESS_ID_SIZE);
390 sc->sc_mib_mac.aDesired_ESS_ID[0] = IEEE80211_ELEMID_SSID;
391 sc->sc_mib_mac.aDesired_ESS_ID[1] = wreq.wi_val[0];
392 memcpy(&sc->sc_mib_mac.aDesired_ESS_ID[2], &wreq.wi_val[1],
394 if (sc->sc_mib_local.Network_Mode || !sc->sc_no_bssid)
397 case WI_RID_CURRENT_BSSID:
400 case WI_RID_CHANNEL_LIST:
401 if (wreq.wi_len != 1) {
405 oregion = sc->sc_mib_phy.aCurrent_Reg_Domain;
406 if (wreq.wi_val[0] == oregion)
408 sc->sc_mib_phy.aCurrent_Reg_Domain = wreq.wi_val[0];
409 error = awi_init_region(sc);
411 sc->sc_mib_phy.aCurrent_Reg_Domain = oregion;
416 case WI_RID_OWN_CHNL:
417 if (wreq.wi_len != 1) {
421 if (wreq.wi_val[0] < sc->sc_scan_min ||
422 wreq.wi_val[0] > sc->sc_scan_max) {
426 sc->sc_ownch = wreq.wi_val[0];
427 if (!sc->sc_mib_local.Network_Mode)
430 case WI_RID_CURRENT_CHAN:
433 case WI_RID_COMMS_QUALITY:
437 if (wreq.wi_len != 1) {
441 if (ifp->if_flags & IFF_PROMISC) {
442 if (wreq.wi_val[0] == 0) {
443 ifp->if_flags &= ~IFF_PROMISC;
447 if (wreq.wi_val[0] != 0) {
448 ifp->if_flags |= IFF_PROMISC;
453 case WI_RID_PORTTYPE:
454 if (wreq.wi_len != 1) {
458 switch (wreq.wi_val[0]) {
460 sc->sc_mib_local.Network_Mode = 1;
465 sc->sc_mib_local.Network_Mode = 0;
470 if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
474 sc->sc_mib_local.Network_Mode = 0;
483 case WI_RID_MAC_NODE:
484 /* XXX: should be implemented? */
488 if (wreq.wi_len != 1) {
492 phy_rates = sc->sc_mib_phy.aSuprt_Data_Rates;
493 switch (wreq.wi_val[0]) {
498 rate = wreq.wi_val[0] * 10;
506 phy_rates = sc->sc_mib_phy.aSuprt_Data_Rates;
507 rate = AWI_RATE_1MBIT;
508 for (i = 0; i < phy_rates[1]; i++) {
509 if (AWI_80211_RATE(phy_rates[2 + i]) > rate)
510 rate = AWI_80211_RATE(phy_rates[2 + i]);
520 for (i = 0; i < phy_rates[1]; i++) {
521 if (rate == AWI_80211_RATE(phy_rates[2 + i]))
524 if (i == phy_rates[1]) {
528 sc->sc_tx_rate = rate;
530 case WI_RID_CUR_TX_RATE:
533 case WI_RID_RTS_THRESH:
534 if (wreq.wi_len != 1) {
538 LE_WRITE_2(&sc->sc_mib_mac.aRTS_Threshold, wreq.wi_val[0]);
541 case WI_RID_CREATE_IBSS:
542 if (wreq.wi_len != 1) {
546 sc->sc_start_bss = wreq.wi_val[0] ? 1 : 0;
549 case WI_RID_SYSTEM_SCALE:
550 if (wreq.wi_len != 1) {
554 if (wreq.wi_val[0] != 1)
555 error = EINVAL; /* not supported */
557 case WI_RID_PM_ENABLED:
558 if (wreq.wi_len != 1) {
562 if (wreq.wi_val[0] != 0)
563 error = EINVAL; /* not implemented */
565 case WI_RID_MAX_SLEEP:
566 error = EINVAL; /* not implemented */
568 case WI_RID_WEP_AVAIL:
571 case WI_RID_ENCRYPTION:
572 if (wreq.wi_len != 1) {
576 error = awi_wep_setalgo(sc, wreq.wi_val[0]);
581 case WI_RID_TX_CRYPT_KEY:
582 if (wreq.wi_len != 1) {
586 if (wreq.wi_val[0] >= IEEE80211_WEP_NKID) {
590 sc->sc_wep_defkid = wreq.wi_val[1];
592 case WI_RID_DEFLT_CRYPT_KEYS:
593 if (wreq.wi_len != sizeof(*keys) / 2) {
597 keys = (struct wi_ltv_keys *)&wreq;
598 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
599 k = &keys->wi_keys[i];
600 error = awi_wep_setkey(sc, i, k->wi_keydat,
606 case WI_RID_MAX_DATALEN:
607 if (wreq.wi_len != 1) {
611 if (wreq.wi_val[0] < 350 || wreq.wi_val[0] > 2304) {
615 LE_WRITE_2(&sc->sc_mib_mac.aMax_Frame_Length, wreq.wi_val[0]);
617 case WI_RID_IFACE_STATS:
624 if (error == ENETRESET) {
625 if (sc->sc_enabled) {
627 error = awi_init(sc);