2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ctr.columbia.edu>. 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.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
32 * $FreeBSD: src/sys/dev/wi/if_wi.c,v 1.103.2.2 2002/08/02 07:11:34 imp Exp $
33 * $DragonFly: src/sys/dev/netif/wi/if_wi.c,v 1.14 2004/07/23 07:16:29 joerg Exp $
37 * Lucent WaveLAN/IEEE 802.11 PCMCIA driver for FreeBSD.
39 * Written by Bill Paul <wpaul@ctr.columbia.edu>
40 * Electrical Engineering Department
41 * Columbia University, New York City
45 * The WaveLAN/IEEE adapter is the second generation of the WaveLAN
46 * from Lucent. Unlike the older cards, the new ones are programmed
47 * entirely via a firmware-driven controller called the Hermes.
48 * Unfortunately, Lucent will not release the Hermes programming manual
49 * without an NDA (if at all). What they do release is an API library
50 * called the HCF (Hardware Control Functions) which is supposed to
51 * do the device-specific operations of a device driver for you. The
52 * publically available version of the HCF library (the 'HCF Light') is
53 * a) extremely gross, b) lacks certain features, particularly support
54 * for 802.11 frames, and c) is contaminated by the GNU Public License.
56 * This driver does not use the HCF or HCF Light at all. Instead, it
57 * programs the Hermes controller directly, using information gleaned
58 * from the HCF Light code and corresponding documentation.
60 * This driver supports the ISA, PCMCIA and PCI versions of the Lucent
61 * WaveLan cards (based on the Hermes chipset), as well as the newer
62 * Prism 2 chipsets with firmware from Intersil and Symbol.
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #if defined(__FreeBSD__) && __FreeBSD_version >= 500033
68 #include <sys/endian.h>
70 #include <sys/sockio.h>
73 #include <sys/kernel.h>
74 #include <sys/socket.h>
75 #include <sys/module.h>
77 #include <sys/random.h>
78 #include <sys/syslog.h>
79 #include <sys/sysctl.h>
81 #include <machine/bus.h>
82 #include <machine/resource.h>
83 #include <machine/clock.h>
87 #include <net/if_arp.h>
88 #include <net/ethernet.h>
89 #include <net/if_dl.h>
90 #include <net/if_media.h>
91 #include <net/if_types.h>
92 #include <net/if_ieee80211.h>
94 #include <netinet/in.h>
95 #include <netinet/in_systm.h>
96 #include <netinet/in_var.h>
97 #include <netinet/ip.h>
98 #include <netinet/if_ether.h>
102 #include "if_wavelan_ieee.h"
103 #include "wi_hostap.h"
104 #include "if_wivar.h"
105 #include "if_wireg.h"
107 static void wi_intr(void *);
108 static void wi_reset(struct wi_softc *);
109 static int wi_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
110 static void wi_init(void *);
111 static void wi_start(struct ifnet *);
112 static void wi_stop(struct wi_softc *);
113 static void wi_watchdog(struct ifnet *);
114 static void wi_rxeof(struct wi_softc *);
115 static void wi_txeof(struct wi_softc *, int);
116 static void wi_update_stats(struct wi_softc *);
117 static void wi_setmulti(struct wi_softc *);
119 static int wi_cmd(struct wi_softc *, int, int, int, int);
120 static int wi_read_record(struct wi_softc *, struct wi_ltv_gen *);
121 static int wi_write_record(struct wi_softc *, struct wi_ltv_gen *);
122 static int wi_read_data(struct wi_softc *, int, int, caddr_t, int);
123 static int wi_write_data(struct wi_softc *, int, int, caddr_t, int);
124 static int wi_seek(struct wi_softc *, int, int, int);
125 static int wi_alloc_nicmem(struct wi_softc *, int, int *);
126 static void wi_inquire(void *);
127 static void wi_setdef(struct wi_softc *, struct wi_req *);
131 void wi_cache_store(struct wi_softc *, struct mbuf *, unsigned short);
134 static int wi_get_cur_ssid(struct wi_softc *, char *, int *);
135 static void wi_get_id(struct wi_softc *);
136 static int wi_media_change(struct ifnet *);
137 static void wi_media_status(struct ifnet *, struct ifmediareq *);
139 static int wi_get_debug(struct wi_softc *, struct wi_req *);
140 static int wi_set_debug(struct wi_softc *, struct wi_req *);
142 DECLARE_DUMMY_MODULE(if_wi);
144 devclass_t wi_devclass;
146 struct wi_card_ident wi_card_ident[] = {
147 /* CARD_ID CARD_NAME FIRM_TYPE */
148 { WI_NIC_LUCENT_ID, WI_NIC_LUCENT_STR, WI_LUCENT },
149 { WI_NIC_SONY_ID, WI_NIC_SONY_STR, WI_LUCENT },
150 { WI_NIC_LUCENT_EMB_ID, WI_NIC_LUCENT_EMB_STR, WI_LUCENT },
151 { WI_NIC_EVB2_ID, WI_NIC_EVB2_STR, WI_INTERSIL },
152 { WI_NIC_HWB3763_ID, WI_NIC_HWB3763_STR, WI_INTERSIL },
153 { WI_NIC_HWB3163_ID, WI_NIC_HWB3163_STR, WI_INTERSIL },
154 { WI_NIC_HWB3163B_ID, WI_NIC_HWB3163B_STR, WI_INTERSIL },
155 { WI_NIC_EVB3_ID, WI_NIC_EVB3_STR, WI_INTERSIL },
156 { WI_NIC_HWB1153_ID, WI_NIC_HWB1153_STR, WI_INTERSIL },
157 { WI_NIC_P2_SST_ID, WI_NIC_P2_SST_STR, WI_INTERSIL },
158 { WI_NIC_EVB2_SST_ID, WI_NIC_EVB2_SST_STR, WI_INTERSIL },
159 { WI_NIC_3842_EVA_ID, WI_NIC_3842_EVA_STR, WI_INTERSIL },
160 { WI_NIC_3842_PCMCIA_AMD_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL },
161 { WI_NIC_3842_PCMCIA_SST_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL },
162 { WI_NIC_3842_PCMCIA_ATM_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL },
163 { WI_NIC_3842_MINI_AMD_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL },
164 { WI_NIC_3842_MINI_SST_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL },
165 { WI_NIC_3842_MINI_ATM_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL },
166 { WI_NIC_3842_PCI_AMD_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL },
167 { WI_NIC_3842_PCI_SST_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL },
168 { WI_NIC_3842_PCI_ATM_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL },
169 { WI_NIC_P3_PCMCIA_AMD_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL },
170 { WI_NIC_P3_PCMCIA_SST_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL },
171 { WI_NIC_P3_MINI_AMD_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL },
172 { WI_NIC_P3_MINI_SST_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL },
177 wi_generic_detach(dev)
184 sc = device_get_softc(dev);
186 ifp = &sc->arpcom.ac_if;
189 device_printf(dev, "already unloaded\n");
196 /* Delete all remaining media. */
197 ifmedia_removeall(&sc->ifmedia);
200 bus_teardown_intr(dev, sc->irq, sc->wi_intrhand);
205 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
206 mtx_destroy(&sc->wi_mtx);
213 wi_generic_attach(device_t dev)
216 struct wi_ltv_macaddr mac;
217 struct wi_ltv_gen gen;
222 /* XXX maybe we need the splimp stuff here XXX */
223 sc = device_get_softc(dev);
224 ifp = &sc->arpcom.ac_if;
226 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
227 wi_intr, sc, &sc->wi_intrhand);
230 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error);
235 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
236 mtx_init(&sc->wi_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
237 MTX_DEF | MTX_RECURSE);
245 * Read the station address.
246 * And do it twice. I've seen PRISM-based cards that return
247 * an error when trying to read it the first time, which causes
250 mac.wi_type = WI_RID_MAC_NODE;
252 wi_read_record(sc, (struct wi_ltv_gen *)&mac);
253 if ((error = wi_read_record(sc, (struct wi_ltv_gen *)&mac)) != 0) {
254 device_printf(dev, "mac read failed %d\n", error);
259 bcopy((char *)&mac.wi_mac_addr,
260 (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
265 if_initname(ifp, "wi", sc->wi_unit);
266 ifp->if_mtu = ETHERMTU;
267 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
268 ifp->if_ioctl = wi_ioctl;
269 ifp->if_start = wi_start;
270 ifp->if_watchdog = wi_watchdog;
271 ifp->if_init = wi_init;
272 ifp->if_baudrate = 10000000;
273 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
275 bzero(sc->wi_node_name, sizeof(sc->wi_node_name));
276 bcopy(WI_DEFAULT_NODENAME, sc->wi_node_name,
277 sizeof(WI_DEFAULT_NODENAME) - 1);
279 bzero(sc->wi_net_name, sizeof(sc->wi_net_name));
280 bcopy(WI_DEFAULT_NETNAME, sc->wi_net_name,
281 sizeof(WI_DEFAULT_NETNAME) - 1);
283 bzero(sc->wi_ibss_name, sizeof(sc->wi_ibss_name));
284 bcopy(WI_DEFAULT_IBSS, sc->wi_ibss_name,
285 sizeof(WI_DEFAULT_IBSS) - 1);
287 sc->wi_portnum = WI_DEFAULT_PORT;
288 sc->wi_ptype = WI_PORTTYPE_BSS;
289 sc->wi_ap_density = WI_DEFAULT_AP_DENSITY;
290 sc->wi_rts_thresh = WI_DEFAULT_RTS_THRESH;
291 sc->wi_tx_rate = WI_DEFAULT_TX_RATE;
292 sc->wi_max_data_len = WI_DEFAULT_DATALEN;
293 sc->wi_create_ibss = WI_DEFAULT_CREATE_IBSS;
294 sc->wi_pm_enabled = WI_DEFAULT_PM_ENABLED;
295 sc->wi_max_sleep = WI_DEFAULT_MAX_SLEEP;
296 sc->wi_roaming = WI_DEFAULT_ROAMING;
297 sc->wi_authtype = WI_DEFAULT_AUTHTYPE;
298 sc->wi_authmode = IEEE80211_AUTH_OPEN;
301 * Read the default channel from the NIC. This may vary
302 * depending on the country where the NIC was purchased, so
303 * we can't hard-code a default and expect it to work for
306 gen.wi_type = WI_RID_OWN_CHNL;
308 wi_read_record(sc, &gen);
309 sc->wi_channel = gen.wi_val;
312 * Set flags based on firmware version.
314 switch (sc->sc_firmware_type) {
316 sc->wi_flags |= WI_FLAGS_HAS_ROAMING;
317 if (sc->sc_sta_firmware_ver >= 60000)
318 sc->wi_flags |= WI_FLAGS_HAS_MOR;
319 if (sc->sc_sta_firmware_ver >= 60006) {
320 sc->wi_flags |= WI_FLAGS_HAS_IBSS;
321 sc->wi_flags |= WI_FLAGS_HAS_CREATE_IBSS;
323 sc->wi_ibss_port = htole16(1);
326 sc->wi_flags |= WI_FLAGS_HAS_ROAMING;
327 if (sc->sc_sta_firmware_ver >= 800) {
328 sc->wi_flags |= WI_FLAGS_HAS_IBSS;
329 sc->wi_flags |= WI_FLAGS_HAS_CREATE_IBSS;
332 * version 0.8.3 and newer are the only ones that are known
333 * to currently work. Earlier versions can be made to work,
334 * at least according to the Linux driver.
336 if (sc->sc_sta_firmware_ver >= 803)
337 sc->wi_flags |= WI_FLAGS_HAS_HOSTAP;
338 sc->wi_ibss_port = htole16(0);
341 sc->wi_flags |= WI_FLAGS_HAS_DIVERSITY;
342 if (sc->sc_sta_firmware_ver >= 20000)
343 sc->wi_flags |= WI_FLAGS_HAS_IBSS;
344 /* Older Symbol firmware does not support IBSS creation. */
345 if (sc->sc_sta_firmware_ver >= 25000)
346 sc->wi_flags |= WI_FLAGS_HAS_CREATE_IBSS;
347 sc->wi_ibss_port = htole16(4);
352 * Find out if we support WEP on this card.
354 gen.wi_type = WI_RID_WEP_AVAIL;
356 wi_read_record(sc, &gen);
357 sc->wi_has_wep = gen.wi_val;
360 device_printf(sc->dev, "wi_has_wep = %d\n", sc->wi_has_wep);
363 * Find supported rates.
365 gen.wi_type = WI_RID_DATA_RATES;
367 if (wi_read_record(sc, &gen))
368 sc->wi_supprates = WI_SUPPRATES_1M | WI_SUPPRATES_2M |
369 WI_SUPPRATES_5M | WI_SUPPRATES_11M;
371 sc->wi_supprates = gen.wi_val;
373 bzero((char *)&sc->wi_stats, sizeof(sc->wi_stats));
378 ifmedia_init(&sc->ifmedia, 0, wi_media_change, wi_media_status);
379 #define ADD(m, c) ifmedia_add(&sc->ifmedia, (m), (c), NULL)
380 if (sc->wi_supprates & WI_SUPPRATES_1M) {
381 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1, 0, 0), 0);
382 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
383 IFM_IEEE80211_ADHOC, 0), 0);
384 if (sc->wi_flags & WI_FLAGS_HAS_IBSS)
385 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
386 IFM_IEEE80211_IBSS, 0), 0);
387 if (sc->wi_flags & WI_FLAGS_HAS_CREATE_IBSS)
388 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
389 IFM_IEEE80211_IBSSMASTER, 0), 0);
390 if (sc->wi_flags & WI_FLAGS_HAS_HOSTAP)
391 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS1,
392 IFM_IEEE80211_HOSTAP, 0), 0);
394 if (sc->wi_supprates & WI_SUPPRATES_2M) {
395 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2, 0, 0), 0);
396 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
397 IFM_IEEE80211_ADHOC, 0), 0);
398 if (sc->wi_flags & WI_FLAGS_HAS_IBSS)
399 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
400 IFM_IEEE80211_IBSS, 0), 0);
401 if (sc->wi_flags & WI_FLAGS_HAS_CREATE_IBSS)
402 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
403 IFM_IEEE80211_IBSSMASTER, 0), 0);
404 if (sc->wi_flags & WI_FLAGS_HAS_HOSTAP)
405 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS2,
406 IFM_IEEE80211_HOSTAP, 0), 0);
408 if (sc->wi_supprates & WI_SUPPRATES_5M) {
409 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5, 0, 0), 0);
410 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
411 IFM_IEEE80211_ADHOC, 0), 0);
412 if (sc->wi_flags & WI_FLAGS_HAS_IBSS)
413 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
414 IFM_IEEE80211_IBSS, 0), 0);
415 if (sc->wi_flags & WI_FLAGS_HAS_CREATE_IBSS)
416 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
417 IFM_IEEE80211_IBSSMASTER, 0), 0);
418 if (sc->wi_flags & WI_FLAGS_HAS_HOSTAP)
419 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS5,
420 IFM_IEEE80211_HOSTAP, 0), 0);
422 if (sc->wi_supprates & WI_SUPPRATES_11M) {
423 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11, 0, 0), 0);
424 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
425 IFM_IEEE80211_ADHOC, 0), 0);
426 if (sc->wi_flags & WI_FLAGS_HAS_IBSS)
427 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
428 IFM_IEEE80211_IBSS, 0), 0);
429 if (sc->wi_flags & WI_FLAGS_HAS_CREATE_IBSS)
430 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
431 IFM_IEEE80211_IBSSMASTER, 0), 0);
432 if (sc->wi_flags & WI_FLAGS_HAS_HOSTAP)
433 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_IEEE80211_DS11,
434 IFM_IEEE80211_HOSTAP, 0), 0);
435 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_MANUAL, 0, 0), 0);
437 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, IFM_IEEE80211_ADHOC, 0), 0);
438 if (sc->wi_flags & WI_FLAGS_HAS_IBSS)
439 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, IFM_IEEE80211_IBSS,
441 if (sc->wi_flags & WI_FLAGS_HAS_CREATE_IBSS)
442 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
443 IFM_IEEE80211_IBSSMASTER, 0), 0);
444 if (sc->wi_flags & WI_FLAGS_HAS_HOSTAP)
445 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO,
446 IFM_IEEE80211_HOSTAP, 0), 0);
447 ADD(IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0), 0);
449 ifmedia_set(&sc->ifmedia, IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0));
452 * Call MI attach routine.
454 ether_ifattach(ifp, sc->arpcom.ac_enaddr);
455 callout_handle_init(&sc->wi_stat_ch);
465 struct wi_ltv_ver ver;
466 struct wi_card_ident *id;
468 /* getting chip identity */
469 memset(&ver, 0, sizeof(ver));
470 ver.wi_type = WI_RID_CARD_ID;
472 wi_read_record(sc, (struct wi_ltv_gen *)&ver);
473 device_printf(sc->dev, "using ");
474 sc->sc_firmware_type = WI_NOTYPE;
475 for (id = wi_card_ident; id->card_name != NULL; id++) {
476 if (le16toh(ver.wi_ver[0]) == id->card_id) {
477 printf("%s", id->card_name);
478 sc->sc_firmware_type = id->firm_type;
482 if (sc->sc_firmware_type == WI_NOTYPE) {
483 if (le16toh(ver.wi_ver[0]) & 0x8000) {
484 printf("Unknown PRISM2 chip");
485 sc->sc_firmware_type = WI_INTERSIL;
487 printf("Unknown Lucent chip");
488 sc->sc_firmware_type = WI_LUCENT;
492 if (sc->sc_firmware_type != WI_LUCENT) {
493 /* get primary firmware version */
494 memset(&ver, 0, sizeof(ver));
495 ver.wi_type = WI_RID_PRI_IDENTITY;
497 wi_read_record(sc, (struct wi_ltv_gen *)&ver);
498 ver.wi_ver[1] = le16toh(ver.wi_ver[1]);
499 ver.wi_ver[2] = le16toh(ver.wi_ver[2]);
500 ver.wi_ver[3] = le16toh(ver.wi_ver[3]);
501 sc->sc_pri_firmware_ver = ver.wi_ver[2] * 10000 +
502 ver.wi_ver[3] * 100 + ver.wi_ver[1];
505 /* get station firmware version */
506 memset(&ver, 0, sizeof(ver));
507 ver.wi_type = WI_RID_STA_IDENTITY;
509 wi_read_record(sc, (struct wi_ltv_gen *)&ver);
510 ver.wi_ver[1] = le16toh(ver.wi_ver[1]);
511 ver.wi_ver[2] = le16toh(ver.wi_ver[2]);
512 ver.wi_ver[3] = le16toh(ver.wi_ver[3]);
513 sc->sc_sta_firmware_ver = ver.wi_ver[2] * 10000 +
514 ver.wi_ver[3] * 100 + ver.wi_ver[1];
515 if (sc->sc_firmware_type == WI_INTERSIL &&
516 (sc->sc_sta_firmware_ver == 10102 ||
517 sc->sc_sta_firmware_ver == 20102)) {
518 struct wi_ltv_str sver;
521 memset(&sver, 0, sizeof(sver));
522 sver.wi_type = WI_RID_SYMBOL_IDENTITY;
524 /* value should be the format like "V2.00-11" */
525 if (wi_read_record(sc, (struct wi_ltv_gen *)&sver) == 0 &&
526 *(p = (char *)sver.wi_str) >= 'A' &&
527 p[2] == '.' && p[5] == '-' && p[8] == '\0') {
528 sc->sc_firmware_type = WI_SYMBOL;
529 sc->sc_sta_firmware_ver = (p[1] - '0') * 10000 +
530 (p[3] - '0') * 1000 + (p[4] - '0') * 100 +
531 (p[6] - '0') * 10 + (p[7] - '0');
535 device_printf(sc->dev, "%s Firmware: ",
536 sc->sc_firmware_type == WI_LUCENT ? "Lucent" :
537 (sc->sc_firmware_type == WI_SYMBOL ? "Symbol" : "Intersil"));
540 * The primary firmware is only valid on Prism based chipsets
541 * (INTERSIL or SYMBOL).
543 if (sc->sc_firmware_type != WI_LUCENT)
544 printf("Primary %u.%02u.%02u, ", sc->sc_pri_firmware_ver / 10000,
545 (sc->sc_pri_firmware_ver % 10000) / 100,
546 sc->sc_pri_firmware_ver % 100);
547 printf("Station %u.%02u.%02u\n",
548 sc->sc_sta_firmware_ver / 10000, (sc->sc_sta_firmware_ver % 10000) / 100,
549 sc->sc_sta_firmware_ver % 100);
558 struct ether_header *eh;
562 ifp = &sc->arpcom.ac_if;
564 id = CSR_READ_2(sc, WI_RX_FID);
567 * if we have the procframe flag set, disregard all this and just
568 * read the data from the device.
570 if (sc->wi_procframe || sc->wi_debug.wi_monitor) {
571 struct wi_frame *rx_frame;
574 /* first allocate mbuf for packet storage */
575 MGETHDR(m, MB_DONTWAIT, MT_DATA);
580 MCLGET(m, MB_DONTWAIT);
581 if (!(m->m_flags & M_EXT)) {
587 m->m_pkthdr.rcvif = ifp;
589 /* now read wi_frame first so we know how much data to read */
590 if (wi_read_data(sc, id, 0, mtod(m, caddr_t),
591 sizeof(struct wi_frame))) {
597 rx_frame = mtod(m, struct wi_frame *);
599 switch ((rx_frame->wi_status & WI_STAT_MAC_PORT) >> 8) {
601 switch (rx_frame->wi_frame_ctl & WI_FCTL_FTYPE) {
603 hdrlen = WI_DATA_HDRLEN;
604 datlen = rx_frame->wi_dat_len + WI_FCS_LEN;
607 hdrlen = WI_MGMT_HDRLEN;
608 datlen = rx_frame->wi_dat_len + WI_FCS_LEN;
612 * prism2 cards don't pass control packets
613 * down properly or consistently, so we'll only
614 * pass down the header.
616 hdrlen = WI_CTL_HDRLEN;
620 device_printf(sc->dev, "received packet of "
621 "unknown type on port 7\n");
628 hdrlen = WI_DATA_HDRLEN;
629 datlen = rx_frame->wi_dat_len + WI_FCS_LEN;
632 device_printf(sc->dev, "received packet on invalid "
633 "port (wi_status=0x%x)\n", rx_frame->wi_status);
639 if ((hdrlen + datlen + 2) > MCLBYTES) {
640 device_printf(sc->dev, "oversized packet received "
641 "(wi_dat_len=%d, wi_status=0x%x)\n",
642 datlen, rx_frame->wi_status);
648 if (wi_read_data(sc, id, hdrlen, mtod(m, caddr_t) + hdrlen,
655 m->m_pkthdr.len = m->m_len = hdrlen + datlen;
659 /* Handle BPF listeners. */
665 struct wi_frame rx_frame;
667 /* First read in the frame header */
668 if (wi_read_data(sc, id, 0, (caddr_t)&rx_frame,
674 if (rx_frame.wi_status & WI_STAT_ERRSTAT) {
679 MGETHDR(m, MB_DONTWAIT, MT_DATA);
684 MCLGET(m, MB_DONTWAIT);
685 if (!(m->m_flags & M_EXT)) {
691 eh = mtod(m, struct ether_header *);
692 m->m_pkthdr.rcvif = ifp;
694 if (rx_frame.wi_status == WI_STAT_MGMT &&
695 sc->wi_ptype == WI_PORTTYPE_AP) {
696 if ((WI_802_11_OFFSET_RAW + rx_frame.wi_dat_len + 2) >
698 device_printf(sc->dev, "oversized mgmt packet "
699 "received in hostap mode "
700 "(wi_dat_len=%d, wi_status=0x%x)\n",
701 rx_frame.wi_dat_len, rx_frame.wi_status);
707 /* Put the whole header in there. */
708 bcopy(&rx_frame, mtod(m, void *),
709 sizeof(struct wi_frame));
710 if (wi_read_data(sc, id, WI_802_11_OFFSET_RAW,
711 mtod(m, caddr_t) + WI_802_11_OFFSET_RAW,
712 rx_frame.wi_dat_len + 2)) {
717 m->m_pkthdr.len = m->m_len =
718 WI_802_11_OFFSET_RAW + rx_frame.wi_dat_len;
719 /* XXX: consider giving packet to bhp? */
720 wihap_mgmt_input(sc, &rx_frame, m);
724 if (rx_frame.wi_status == WI_STAT_1042 ||
725 rx_frame.wi_status == WI_STAT_TUNNEL ||
726 rx_frame.wi_status == WI_STAT_WMP_MSG) {
727 if((rx_frame.wi_dat_len + WI_SNAPHDR_LEN) > MCLBYTES) {
728 device_printf(sc->dev,
729 "oversized packet received "
730 "(wi_dat_len=%d, wi_status=0x%x)\n",
731 rx_frame.wi_dat_len, rx_frame.wi_status);
736 m->m_pkthdr.len = m->m_len =
737 rx_frame.wi_dat_len + WI_SNAPHDR_LEN;
740 bcopy((char *)&rx_frame.wi_addr1,
741 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
742 if (sc->wi_ptype == WI_PORTTYPE_ADHOC) {
743 bcopy((char *)&rx_frame.wi_addr2,
744 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
746 bcopy((char *)&rx_frame.wi_addr3,
747 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
750 bcopy((char *)&rx_frame.wi_dst_addr,
751 (char *)&eh->ether_dhost, ETHER_ADDR_LEN);
752 bcopy((char *)&rx_frame.wi_src_addr,
753 (char *)&eh->ether_shost, ETHER_ADDR_LEN);
756 bcopy((char *)&rx_frame.wi_type,
757 (char *)&eh->ether_type, ETHER_TYPE_LEN);
759 if (wi_read_data(sc, id, WI_802_11_OFFSET,
760 mtod(m, caddr_t) + sizeof(struct ether_header),
767 if((rx_frame.wi_dat_len +
768 sizeof(struct ether_header)) > MCLBYTES) {
769 device_printf(sc->dev,
770 "oversized packet received "
771 "(wi_dat_len=%d, wi_status=0x%x)\n",
772 rx_frame.wi_dat_len, rx_frame.wi_status);
777 m->m_pkthdr.len = m->m_len =
778 rx_frame.wi_dat_len + sizeof(struct ether_header);
780 if (wi_read_data(sc, id, WI_802_3_OFFSET,
781 mtod(m, caddr_t), m->m_len + 2)) {
790 if (sc->wi_ptype == WI_PORTTYPE_AP) {
792 * Give host AP code first crack at data
793 * packets. If it decides to handle it (or
794 * drop it), it will return a non-zero.
795 * Otherwise, it is destined for this host.
797 if (wihap_data_input(sc, &rx_frame, m))
800 /* Receive packet. */
802 wi_cache_store(sc, m, rx_frame.wi_q_info);
804 (*ifp->if_input)(ifp, m);
815 ifp = &sc->arpcom.ac_if;
818 ifp->if_flags &= ~IFF_OACTIVE;
820 if (status & WI_EV_TX_EXC)
837 ifp = &sc->arpcom.ac_if;
839 sc->wi_stat_ch = timeout(wi_inquire, sc, hz * 60);
841 /* Don't do this while we're transmitting */
842 if (ifp->if_flags & IFF_OACTIVE)
846 wi_cmd(sc, WI_CMD_INQUIRE, WI_INFO_COUNTERS, 0, 0);
856 struct wi_ltv_gen gen;
863 ifp = &sc->arpcom.ac_if;
865 id = CSR_READ_2(sc, WI_INFO_FID);
867 wi_read_data(sc, id, 0, (char *)&gen, 4);
870 * if we just got our scan results, copy it over into the scan buffer
871 * so we can return it to anyone that asks for it. (add a little
872 * compatibility with the prism2 scanning mechanism)
874 if (gen.wi_type == WI_INFO_SCAN_RESULTS)
876 sc->wi_scanbuf_len = gen.wi_len;
877 wi_read_data(sc, id, 4, (char *)sc->wi_scanbuf,
878 sc->wi_scanbuf_len * 2);
882 else if (gen.wi_type != WI_INFO_COUNTERS)
885 len = (gen.wi_len - 1 < sizeof(sc->wi_stats) / 4) ?
886 gen.wi_len - 1 : sizeof(sc->wi_stats) / 4;
887 ptr = (u_int32_t *)&sc->wi_stats;
889 for (i = 0; i < len - 1; i++) {
890 t = CSR_READ_2(sc, WI_DATA1);
891 #ifdef WI_HERMES_STATS_WAR
898 ifp->if_collisions = sc->wi_stats.wi_tx_single_retries +
899 sc->wi_stats.wi_tx_multi_retries +
900 sc->wi_stats.wi_tx_retry_limit;
909 struct wi_softc *sc = xsc;
916 ifp = &sc->arpcom.ac_if;
918 if (sc->wi_gone || !(ifp->if_flags & IFF_UP)) {
919 CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
920 CSR_WRITE_2(sc, WI_INT_EN, 0);
925 /* Disable interrupts. */
926 CSR_WRITE_2(sc, WI_INT_EN, 0);
928 status = CSR_READ_2(sc, WI_EVENT_STAT);
929 CSR_WRITE_2(sc, WI_EVENT_ACK, ~WI_INTRS);
931 if (status & WI_EV_RX) {
933 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
936 if (status & WI_EV_TX) {
937 wi_txeof(sc, status);
938 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_TX);
941 if (status & WI_EV_ALLOC) {
944 id = CSR_READ_2(sc, WI_ALLOC_FID);
945 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_ALLOC);
946 if (id == sc->wi_tx_data_id)
947 wi_txeof(sc, status);
950 if (status & WI_EV_INFO) {
952 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_INFO);
955 if (status & WI_EV_TX_EXC) {
956 wi_txeof(sc, status);
957 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_TX_EXC);
960 if (status & WI_EV_INFO_DROP) {
961 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_INFO_DROP);
964 /* Re-enable interrupts. */
965 CSR_WRITE_2(sc, WI_INT_EN, WI_INTRS);
967 if (ifp->if_snd.ifq_head != NULL) {
977 wi_cmd(sc, cmd, val0, val1, val2)
985 static volatile int count = 0;
988 panic("Hey partner, hold on there!");
991 /* wait for the busy bit to clear */
992 for (i = 500; i > 0; i--) { /* 5s */
993 if (!(CSR_READ_2(sc, WI_COMMAND) & WI_CMD_BUSY)) {
996 DELAY(10*1000); /* 10 m sec */
999 device_printf(sc->dev, "wi_cmd: busy bit won't clear.\n" );
1004 CSR_WRITE_2(sc, WI_PARAM0, val0);
1005 CSR_WRITE_2(sc, WI_PARAM1, val1);
1006 CSR_WRITE_2(sc, WI_PARAM2, val2);
1007 CSR_WRITE_2(sc, WI_COMMAND, cmd);
1009 for (i = 0; i < WI_TIMEOUT; i++) {
1011 * Wait for 'command complete' bit to be
1012 * set in the event status register.
1014 s = CSR_READ_2(sc, WI_EVENT_STAT);
1015 if (s & WI_EV_CMD) {
1016 /* Ack the event and read result code. */
1017 s = CSR_READ_2(sc, WI_STATUS);
1018 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_CMD);
1020 if ((s & WI_CMD_CODE_MASK) != (cmd & WI_CMD_CODE_MASK))
1023 if (s & WI_STAT_CMD_RESULT) {
1033 if (i == WI_TIMEOUT) {
1034 device_printf(sc->dev,
1035 "timeout in wi_cmd 0x%04x; event status 0x%04x\n", cmd, s);
1043 struct wi_softc *sc;
1045 #define WI_INIT_TRIES 3
1049 /* Symbol firmware cannot be initialized more than once */
1050 if (sc->sc_firmware_type == WI_SYMBOL && sc->sc_enabled)
1052 if (sc->sc_firmware_type == WI_SYMBOL)
1055 tries = WI_INIT_TRIES;
1057 for (i = 0; i < tries; i++) {
1058 if (wi_cmd(sc, WI_CMD_INI, 0, 0, 0) == 0)
1060 DELAY(WI_DELAY * 1000);
1065 device_printf(sc->dev, "init failed\n");
1069 CSR_WRITE_2(sc, WI_INT_EN, 0);
1070 CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
1072 /* Calibrate timer. */
1073 WI_SETVAL(WI_RID_TICK_TIME, 8);
1079 * Read an LTV record from the NIC.
1082 wi_read_record(sc, ltv)
1083 struct wi_softc *sc;
1084 struct wi_ltv_gen *ltv;
1088 struct wi_ltv_gen *oltv, p2ltv;
1091 if (sc->sc_firmware_type != WI_LUCENT) {
1092 switch (ltv->wi_type) {
1093 case WI_RID_ENCRYPTION:
1094 p2ltv.wi_type = WI_RID_P2_ENCRYPTION;
1098 case WI_RID_TX_CRYPT_KEY:
1099 p2ltv.wi_type = WI_RID_P2_TX_CRYPT_KEY;
1103 case WI_RID_ROAMING_MODE:
1104 if (sc->sc_firmware_type == WI_INTERSIL)
1109 case WI_RID_MICROWAVE_OVEN:
1116 /* Tell the NIC to enter record read mode. */
1117 if (wi_cmd(sc, WI_CMD_ACCESS|WI_ACCESS_READ, ltv->wi_type, 0, 0))
1120 /* Seek to the record. */
1121 if (wi_seek(sc, ltv->wi_type, 0, WI_BAP1))
1125 * Read the length and record type and make sure they
1126 * match what we expect (this verifies that we have enough
1127 * room to hold all of the returned data).
1129 len = CSR_READ_2(sc, WI_DATA1);
1130 if (len > ltv->wi_len)
1132 code = CSR_READ_2(sc, WI_DATA1);
1133 if (code != ltv->wi_type)
1137 ltv->wi_type = code;
1139 /* Now read the data. */
1141 for (i = 0; i < ltv->wi_len - 1; i++)
1142 ptr[i] = CSR_READ_2(sc, WI_DATA1);
1144 if (ltv->wi_type == WI_RID_PORTTYPE && sc->wi_ptype == WI_PORTTYPE_IBSS
1145 && ltv->wi_val == sc->wi_ibss_port) {
1147 * Convert vendor IBSS port type to WI_PORTTYPE_IBSS.
1148 * Since Lucent uses port type 1 for BSS *and* IBSS we
1149 * have to rely on wi_ptype to distinguish this for us.
1151 ltv->wi_val = htole16(WI_PORTTYPE_IBSS);
1152 } else if (sc->sc_firmware_type != WI_LUCENT) {
1153 switch (oltv->wi_type) {
1154 case WI_RID_TX_RATE:
1155 case WI_RID_CUR_TX_RATE:
1156 switch (ltv->wi_val) {
1157 case 1: oltv->wi_val = 1; break;
1158 case 2: oltv->wi_val = 2; break;
1159 case 3: oltv->wi_val = 6; break;
1160 case 4: oltv->wi_val = 5; break;
1161 case 7: oltv->wi_val = 7; break;
1162 case 8: oltv->wi_val = 11; break;
1163 case 15: oltv->wi_val = 3; break;
1164 default: oltv->wi_val = 0x100 + ltv->wi_val; break;
1167 case WI_RID_ENCRYPTION:
1169 if (ltv->wi_val & 0x01)
1174 case WI_RID_TX_CRYPT_KEY:
1176 oltv->wi_val = ltv->wi_val;
1178 case WI_RID_CNFAUTHMODE:
1180 if (le16toh(ltv->wi_val) & 0x01)
1181 oltv->wi_val = htole16(1);
1182 else if (le16toh(ltv->wi_val) & 0x02)
1183 oltv->wi_val = htole16(2);
1192 * Same as read, except we inject data instead of reading it.
1195 wi_write_record(sc, ltv)
1196 struct wi_softc *sc;
1197 struct wi_ltv_gen *ltv;
1201 struct wi_ltv_gen p2ltv;
1203 if (ltv->wi_type == WI_RID_PORTTYPE &&
1204 le16toh(ltv->wi_val) == WI_PORTTYPE_IBSS) {
1205 /* Convert WI_PORTTYPE_IBSS to vendor IBSS port type. */
1206 p2ltv.wi_type = WI_RID_PORTTYPE;
1208 p2ltv.wi_val = sc->wi_ibss_port;
1210 } else if (sc->sc_firmware_type != WI_LUCENT) {
1211 switch (ltv->wi_type) {
1212 case WI_RID_TX_RATE:
1213 p2ltv.wi_type = WI_RID_TX_RATE;
1215 switch (ltv->wi_val) {
1216 case 1: p2ltv.wi_val = 1; break;
1217 case 2: p2ltv.wi_val = 2; break;
1218 case 3: p2ltv.wi_val = 15; break;
1219 case 5: p2ltv.wi_val = 4; break;
1220 case 6: p2ltv.wi_val = 3; break;
1221 case 7: p2ltv.wi_val = 7; break;
1222 case 11: p2ltv.wi_val = 8; break;
1223 default: return EINVAL;
1227 case WI_RID_ENCRYPTION:
1228 p2ltv.wi_type = WI_RID_P2_ENCRYPTION;
1230 if (le16toh(ltv->wi_val)) {
1231 p2ltv.wi_val =htole16(PRIVACY_INVOKED |
1232 EXCLUDE_UNENCRYPTED);
1233 if (sc->wi_ptype == WI_PORTTYPE_AP)
1235 * Disable tx encryption...
1238 p2ltv.wi_val |= htole16(HOST_ENCRYPT);
1241 htole16(HOST_ENCRYPT | HOST_DECRYPT);
1244 case WI_RID_TX_CRYPT_KEY:
1245 p2ltv.wi_type = WI_RID_P2_TX_CRYPT_KEY;
1247 p2ltv.wi_val = ltv->wi_val;
1250 case WI_RID_DEFLT_CRYPT_KEYS:
1254 struct wi_ltv_str ws;
1255 struct wi_ltv_keys *wk =
1256 (struct wi_ltv_keys *)ltv;
1258 keylen = wk->wi_keys[sc->wi_tx_key].wi_keylen;
1260 for (i = 0; i < 4; i++) {
1261 bzero(&ws, sizeof(ws));
1262 ws.wi_len = (keylen > 5) ? 8 : 4;
1263 ws.wi_type = WI_RID_P2_CRYPT_KEY0 + i;
1265 &wk->wi_keys[i].wi_keydat, keylen);
1266 error = wi_write_record(sc,
1267 (struct wi_ltv_gen *)&ws);
1273 case WI_RID_CNFAUTHMODE:
1274 p2ltv.wi_type = WI_RID_CNFAUTHMODE;
1276 if (le16toh(ltv->wi_val) == 1)
1277 p2ltv.wi_val = htole16(0x01);
1278 else if (le16toh(ltv->wi_val) == 2)
1279 p2ltv.wi_val = htole16(0x02);
1282 case WI_RID_ROAMING_MODE:
1283 if (sc->sc_firmware_type == WI_INTERSIL)
1287 case WI_RID_MICROWAVE_OVEN:
1293 switch (ltv->wi_type) {
1294 case WI_RID_TX_RATE:
1295 switch (ltv->wi_val) {
1296 case 1: ltv->wi_val = 1; break; /* 1Mb/s fixed */
1297 case 2: ltv->wi_val = 2; break; /* 2Mb/s fixed */
1298 case 3: ltv->wi_val = 3; break; /* 11Mb/s auto */
1299 case 5: ltv->wi_val = 4; break; /* 5.5Mb/s fixed */
1300 case 6: ltv->wi_val = 6; break; /* 2Mb/s auto */
1301 case 7: ltv->wi_val = 7; break; /* 5.5Mb/s auto */
1302 case 11: ltv->wi_val = 5; break; /* 11Mb/s fixed */
1303 default: return EINVAL;
1308 if (wi_seek(sc, ltv->wi_type, 0, WI_BAP1))
1311 CSR_WRITE_2(sc, WI_DATA1, ltv->wi_len);
1312 CSR_WRITE_2(sc, WI_DATA1, ltv->wi_type);
1315 for (i = 0; i < ltv->wi_len - 1; i++)
1316 CSR_WRITE_2(sc, WI_DATA1, ptr[i]);
1318 if (wi_cmd(sc, WI_CMD_ACCESS|WI_ACCESS_WRITE, ltv->wi_type, 0, 0))
1325 wi_seek(sc, id, off, chan)
1326 struct wi_softc *sc;
1343 device_printf(sc->dev, "invalid data path: %x\n", chan);
1347 CSR_WRITE_2(sc, selreg, id);
1348 CSR_WRITE_2(sc, offreg, off);
1350 for (i = 0; i < WI_TIMEOUT; i++) {
1351 status = CSR_READ_2(sc, offreg);
1352 if (!(status & (WI_OFF_BUSY|WI_OFF_ERR)))
1357 if (i == WI_TIMEOUT) {
1358 device_printf(sc->dev, "timeout in wi_seek to %x/%x; last status %x\n",
1367 wi_read_data(sc, id, off, buf, len)
1368 struct wi_softc *sc;
1376 if (wi_seek(sc, id, off, WI_BAP1))
1379 ptr = (u_int16_t *)buf;
1380 for (i = 0; i < len / 2; i++)
1381 ptr[i] = CSR_READ_2(sc, WI_DATA1);
1387 * According to the comments in the HCF Light code, there is a bug in
1388 * the Hermes (or possibly in certain Hermes firmware revisions) where
1389 * the chip's internal autoincrement counter gets thrown off during
1390 * data writes: the autoincrement is missed, causing one data word to
1391 * be overwritten and subsequent words to be written to the wrong memory
1392 * locations. The end result is that we could end up transmitting bogus
1393 * frames without realizing it. The workaround for this is to write a
1394 * couple of extra guard words after the end of the transfer, then
1395 * attempt to read then back. If we fail to locate the guard words where
1396 * we expect them, we preform the transfer over again.
1399 wi_write_data(sc, id, off, buf, len)
1400 struct wi_softc *sc;
1407 #ifdef WI_HERMES_AUTOINC_WAR
1414 if (wi_seek(sc, id, off, WI_BAP0))
1417 ptr = (u_int16_t *)buf;
1418 for (i = 0; i < (len / 2); i++)
1419 CSR_WRITE_2(sc, WI_DATA0, ptr[i]);
1421 #ifdef WI_HERMES_AUTOINC_WAR
1422 CSR_WRITE_2(sc, WI_DATA0, 0x1234);
1423 CSR_WRITE_2(sc, WI_DATA0, 0x5678);
1425 if (wi_seek(sc, id, off + len, WI_BAP0))
1428 if (CSR_READ_2(sc, WI_DATA0) != 0x1234 ||
1429 CSR_READ_2(sc, WI_DATA0) != 0x5678) {
1432 device_printf(sc->dev, "wi_write_data device timeout\n");
1441 * Allocate a region of memory inside the NIC and zero
1445 wi_alloc_nicmem(sc, len, id)
1446 struct wi_softc *sc;
1452 if (wi_cmd(sc, WI_CMD_ALLOC_MEM, len, 0, 0)) {
1453 device_printf(sc->dev,
1454 "failed to allocate %d bytes on NIC\n", len);
1458 for (i = 0; i < WI_TIMEOUT; i++) {
1459 if (CSR_READ_2(sc, WI_EVENT_STAT) & WI_EV_ALLOC)
1464 if (i == WI_TIMEOUT) {
1465 device_printf(sc->dev, "time out allocating memory on card\n");
1469 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_ALLOC);
1470 *id = CSR_READ_2(sc, WI_ALLOC_FID);
1472 if (wi_seek(sc, *id, 0, WI_BAP0)) {
1473 device_printf(sc->dev, "seek failed while allocating memory on card\n");
1477 for (i = 0; i < len / 2; i++)
1478 CSR_WRITE_2(sc, WI_DATA0, 0);
1485 struct wi_softc *sc;
1489 struct ifmultiaddr *ifma;
1490 struct wi_ltv_mcast mcast;
1492 ifp = &sc->arpcom.ac_if;
1494 bzero((char *)&mcast, sizeof(mcast));
1496 mcast.wi_type = WI_RID_MCAST_LIST;
1497 mcast.wi_len = (3 * 16) + 1;
1499 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
1500 wi_write_record(sc, (struct wi_ltv_gen *)&mcast);
1504 #if defined(__DragonFly__) || __FreeBSD_version < 500000
1505 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1507 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1509 if (ifma->ifma_addr->sa_family != AF_LINK)
1512 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
1513 (char *)&mcast.wi_mcast[i], ETHER_ADDR_LEN);
1516 bzero((char *)&mcast, sizeof(mcast));
1521 mcast.wi_len = (i * 3) + 1;
1522 wi_write_record(sc, (struct wi_ltv_gen *)&mcast);
1529 struct wi_softc *sc;
1530 struct wi_req *wreq;
1532 struct sockaddr_dl *sdl;
1536 ifp = &sc->arpcom.ac_if;
1538 switch(wreq->wi_type) {
1539 case WI_RID_MAC_NODE:
1540 ifa = ifaddr_byindex(ifp->if_index);
1541 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
1542 bcopy((char *)&wreq->wi_val, (char *)&sc->arpcom.ac_enaddr,
1544 bcopy((char *)&wreq->wi_val, LLADDR(sdl), ETHER_ADDR_LEN);
1546 case WI_RID_PORTTYPE:
1547 sc->wi_ptype = le16toh(wreq->wi_val[0]);
1549 case WI_RID_TX_RATE:
1550 sc->wi_tx_rate = le16toh(wreq->wi_val[0]);
1552 case WI_RID_MAX_DATALEN:
1553 sc->wi_max_data_len = le16toh(wreq->wi_val[0]);
1555 case WI_RID_RTS_THRESH:
1556 sc->wi_rts_thresh = le16toh(wreq->wi_val[0]);
1558 case WI_RID_SYSTEM_SCALE:
1559 sc->wi_ap_density = le16toh(wreq->wi_val[0]);
1561 case WI_RID_CREATE_IBSS:
1562 sc->wi_create_ibss = le16toh(wreq->wi_val[0]);
1564 case WI_RID_OWN_CHNL:
1565 sc->wi_channel = le16toh(wreq->wi_val[0]);
1567 case WI_RID_NODENAME:
1568 bzero(sc->wi_node_name, sizeof(sc->wi_node_name));
1569 bcopy((char *)&wreq->wi_val[1], sc->wi_node_name, 30);
1571 case WI_RID_DESIRED_SSID:
1572 bzero(sc->wi_net_name, sizeof(sc->wi_net_name));
1573 bcopy((char *)&wreq->wi_val[1], sc->wi_net_name, 30);
1575 case WI_RID_OWN_SSID:
1576 bzero(sc->wi_ibss_name, sizeof(sc->wi_ibss_name));
1577 bcopy((char *)&wreq->wi_val[1], sc->wi_ibss_name, 30);
1579 case WI_RID_PM_ENABLED:
1580 sc->wi_pm_enabled = le16toh(wreq->wi_val[0]);
1582 case WI_RID_MICROWAVE_OVEN:
1583 sc->wi_mor_enabled = le16toh(wreq->wi_val[0]);
1585 case WI_RID_MAX_SLEEP:
1586 sc->wi_max_sleep = le16toh(wreq->wi_val[0]);
1588 case WI_RID_CNFAUTHMODE:
1589 sc->wi_authtype = le16toh(wreq->wi_val[0]);
1591 case WI_RID_ROAMING_MODE:
1592 sc->wi_roaming = le16toh(wreq->wi_val[0]);
1594 case WI_RID_ENCRYPTION:
1595 sc->wi_use_wep = le16toh(wreq->wi_val[0]);
1597 case WI_RID_TX_CRYPT_KEY:
1598 sc->wi_tx_key = le16toh(wreq->wi_val[0]);
1600 case WI_RID_DEFLT_CRYPT_KEYS:
1601 bcopy((char *)wreq, (char *)&sc->wi_keys,
1602 sizeof(struct wi_ltv_keys));
1608 /* Reinitialize WaveLAN. */
1615 wi_ioctl(ifp, command, data, cr)
1623 u_int8_t tmpkey[14];
1624 char tmpssid[IEEE80211_NWID_LEN];
1625 struct wi_softc *sc;
1628 struct ieee80211req *ireq;
1633 ifr = (struct ifreq *)data;
1634 ireq = (struct ieee80211req *)data;
1645 error = ether_ioctl(ifp, command, data);
1649 * Can't do promisc and hostap at the same time. If all that's
1650 * changing is the promisc flag, try to short-circuit a call to
1651 * wi_init() by just setting PROMISC in the hardware.
1653 if (ifp->if_flags & IFF_UP) {
1654 if (sc->wi_ptype != WI_PORTTYPE_AP &&
1655 ifp->if_flags & IFF_RUNNING) {
1656 if (ifp->if_flags & IFF_PROMISC &&
1657 !(sc->wi_if_flags & IFF_PROMISC)) {
1658 WI_SETVAL(WI_RID_PROMISC, 1);
1659 } else if (!(ifp->if_flags & IFF_PROMISC) &&
1660 sc->wi_if_flags & IFF_PROMISC) {
1661 WI_SETVAL(WI_RID_PROMISC, 0);
1669 if (ifp->if_flags & IFF_RUNNING) {
1673 sc->wi_if_flags = ifp->if_flags;
1678 error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, command);
1686 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
1689 if (wreq.wi_len > WI_MAX_DATALEN) {
1693 /* Don't show WEP keys to non-root users. */
1694 if (wreq.wi_type == WI_RID_DEFLT_CRYPT_KEYS &&
1695 suser_cred(cr, NULL_CRED_OKAY))
1697 if (wreq.wi_type == WI_RID_IFACE_STATS) {
1698 bcopy((char *)&sc->wi_stats, (char *)&wreq.wi_val,
1699 sizeof(sc->wi_stats));
1700 wreq.wi_len = (sizeof(sc->wi_stats) / 2) + 1;
1701 } else if (wreq.wi_type == WI_RID_DEFLT_CRYPT_KEYS) {
1702 bcopy((char *)&sc->wi_keys, (char *)&wreq,
1703 sizeof(struct wi_ltv_keys));
1706 else if (wreq.wi_type == WI_RID_ZERO_CACHE) {
1707 sc->wi_sigitems = sc->wi_nextitem = 0;
1708 } else if (wreq.wi_type == WI_RID_READ_CACHE) {
1709 char *pt = (char *)&wreq.wi_val;
1710 bcopy((char *)&sc->wi_sigitems,
1711 (char *)pt, sizeof(int));
1712 pt += (sizeof (int));
1713 wreq.wi_len = sizeof(int) / 2;
1714 bcopy((char *)&sc->wi_sigcache, (char *)pt,
1715 sizeof(struct wi_sigcache) * sc->wi_sigitems);
1716 wreq.wi_len += ((sizeof(struct wi_sigcache) *
1717 sc->wi_sigitems) / 2) + 1;
1720 else if (wreq.wi_type == WI_RID_PROCFRAME) {
1722 wreq.wi_val[0] = sc->wi_procframe;
1723 } else if (wreq.wi_type == WI_RID_PRISM2) {
1725 wreq.wi_val[0] = sc->sc_firmware_type != WI_LUCENT;
1726 } else if (wreq.wi_type == WI_RID_SCAN_RES &&
1727 sc->sc_firmware_type == WI_LUCENT) {
1728 memcpy((char *)wreq.wi_val, (char *)sc->wi_scanbuf,
1729 sc->wi_scanbuf_len * 2);
1730 wreq.wi_len = sc->wi_scanbuf_len;
1732 if (wi_read_record(sc, (struct wi_ltv_gen *)&wreq)) {
1737 error = copyout(&wreq, ifr->ifr_data, sizeof(wreq));
1740 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1742 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
1745 if (wreq.wi_len > WI_MAX_DATALEN) {
1749 if (wreq.wi_type == WI_RID_IFACE_STATS) {
1752 } else if (wreq.wi_type == WI_RID_MGMT_XMIT) {
1753 error = wi_mgmt_xmit(sc, (caddr_t)&wreq.wi_val,
1755 } else if (wreq.wi_type == WI_RID_PROCFRAME) {
1756 sc->wi_procframe = wreq.wi_val[0];
1758 * if we're getting a scan request from a wavelan card
1759 * (non-prism2), send out a cmd_inquire to the card to scan
1760 * results for the scan will be received through the info
1761 * interrupt handler. otherwise the scan request can be
1762 * directly handled by a prism2 card's rid interface.
1764 } else if (wreq.wi_type == WI_RID_SCAN_REQ &&
1765 sc->sc_firmware_type == WI_LUCENT) {
1766 wi_cmd(sc, WI_CMD_INQUIRE, WI_INFO_SCAN_RESULTS, 0, 0);
1768 error = wi_write_record(sc, (struct wi_ltv_gen *)&wreq);
1770 wi_setdef(sc, &wreq);
1773 case SIOCGPRISM2DEBUG:
1774 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
1777 if (!(ifp->if_flags & IFF_RUNNING) ||
1778 sc->sc_firmware_type == WI_LUCENT) {
1782 error = wi_get_debug(sc, &wreq);
1784 error = copyout(&wreq, ifr->ifr_data, sizeof(wreq));
1786 case SIOCSPRISM2DEBUG:
1787 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1789 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
1792 error = wi_set_debug(sc, &wreq);
1795 switch(ireq->i_type) {
1796 case IEEE80211_IOC_SSID:
1797 if(ireq->i_val == -1) {
1798 bzero(tmpssid, IEEE80211_NWID_LEN);
1799 error = wi_get_cur_ssid(sc, tmpssid, &len);
1802 error = copyout(tmpssid, ireq->i_data,
1803 IEEE80211_NWID_LEN);
1805 } else if (ireq->i_val == 0) {
1806 error = copyout(sc->wi_net_name,
1808 IEEE80211_NWID_LEN);
1809 ireq->i_len = IEEE80211_NWID_LEN;
1813 case IEEE80211_IOC_NUMSSIDS:
1816 case IEEE80211_IOC_WEP:
1817 if(!sc->wi_has_wep) {
1818 ireq->i_val = IEEE80211_WEP_NOSUP;
1820 if(sc->wi_use_wep) {
1822 IEEE80211_WEP_MIXED;
1829 case IEEE80211_IOC_WEPKEY:
1830 if(!sc->wi_has_wep ||
1831 ireq->i_val < 0 || ireq->i_val > 3) {
1835 len = sc->wi_keys.wi_keys[ireq->i_val].wi_keylen;
1836 if (suser_cred(cr, NULL_CRED_OKAY))
1837 bcopy(sc->wi_keys.wi_keys[ireq->i_val].wi_keydat,
1843 error = copyout(tmpkey, ireq->i_data, len);
1846 case IEEE80211_IOC_NUMWEPKEYS:
1852 case IEEE80211_IOC_WEPTXKEY:
1856 ireq->i_val = sc->wi_tx_key;
1858 case IEEE80211_IOC_AUTHMODE:
1859 ireq->i_val = sc->wi_authmode;
1861 case IEEE80211_IOC_STATIONNAME:
1862 error = copyout(sc->wi_node_name,
1863 ireq->i_data, IEEE80211_NWID_LEN);
1864 ireq->i_len = IEEE80211_NWID_LEN;
1866 case IEEE80211_IOC_CHANNEL:
1867 wreq.wi_type = WI_RID_CURRENT_CHAN;
1868 wreq.wi_len = WI_MAX_DATALEN;
1869 if (wi_read_record(sc, (struct wi_ltv_gen *)&wreq))
1872 ireq->i_val = wreq.wi_val[0];
1875 case IEEE80211_IOC_POWERSAVE:
1876 if(sc->wi_pm_enabled)
1877 ireq->i_val = IEEE80211_POWERSAVE_ON;
1879 ireq->i_val = IEEE80211_POWERSAVE_OFF;
1881 case IEEE80211_IOC_POWERSAVESLEEP:
1882 ireq->i_val = sc->wi_max_sleep;
1889 if ((error = suser_cred(cr, NULL_CRED_OKAY)))
1891 switch(ireq->i_type) {
1892 case IEEE80211_IOC_SSID:
1893 if (ireq->i_val != 0 ||
1894 ireq->i_len > IEEE80211_NWID_LEN) {
1898 /* We set both of them */
1899 bzero(sc->wi_net_name, IEEE80211_NWID_LEN);
1900 error = copyin(ireq->i_data,
1901 sc->wi_net_name, ireq->i_len);
1902 bcopy(sc->wi_net_name, sc->wi_ibss_name, IEEE80211_NWID_LEN);
1904 case IEEE80211_IOC_WEP:
1906 * These cards only support one mode so
1907 * we just turn wep on what ever is
1908 * passed in if it's not OFF.
1910 if (ireq->i_val == IEEE80211_WEP_OFF) {
1916 case IEEE80211_IOC_WEPKEY:
1917 if (ireq->i_val < 0 || ireq->i_val > 3 ||
1922 bzero(sc->wi_keys.wi_keys[ireq->i_val].wi_keydat, 13);
1923 error = copyin(ireq->i_data,
1924 sc->wi_keys.wi_keys[ireq->i_val].wi_keydat,
1928 sc->wi_keys.wi_keys[ireq->i_val].wi_keylen =
1931 case IEEE80211_IOC_WEPTXKEY:
1932 if (ireq->i_val < 0 || ireq->i_val > 3) {
1936 sc->wi_tx_key = ireq->i_val;
1938 case IEEE80211_IOC_AUTHMODE:
1939 sc->wi_authmode = ireq->i_val;
1941 case IEEE80211_IOC_STATIONNAME:
1942 if (ireq->i_len > 32) {
1946 bzero(sc->wi_node_name, 32);
1947 error = copyin(ireq->i_data,
1948 sc->wi_node_name, ireq->i_len);
1950 case IEEE80211_IOC_CHANNEL:
1952 * The actual range is 1-14, but if you
1953 * set it to 0 you get the default. So
1954 * we let that work too.
1956 if (ireq->i_val < 0 || ireq->i_val > 14) {
1960 sc->wi_channel = ireq->i_val;
1962 case IEEE80211_IOC_POWERSAVE:
1963 switch (ireq->i_val) {
1964 case IEEE80211_POWERSAVE_OFF:
1965 sc->wi_pm_enabled = 0;
1967 case IEEE80211_POWERSAVE_ON:
1968 sc->wi_pm_enabled = 1;
1975 case IEEE80211_IOC_POWERSAVESLEEP:
1976 if (ireq->i_val < 0) {
1980 sc->wi_max_sleep = ireq->i_val;
1987 /* Reinitialize WaveLAN. */
1991 case SIOCHOSTAP_ADD:
1992 case SIOCHOSTAP_DEL:
1993 case SIOCHOSTAP_GET:
1994 case SIOCHOSTAP_GETALL:
1995 case SIOCHOSTAP_GFLAGS:
1996 case SIOCHOSTAP_SFLAGS:
1997 /* Send all Host AP specific ioctl's to Host AP code. */
1998 error = wihap_ioctl(sc, command, data);
2014 struct wi_softc *sc = xsc;
2015 struct ifnet *ifp = &sc->arpcom.ac_if;
2016 struct wi_ltv_macaddr mac;
2027 if (ifp->if_flags & IFF_RUNNING)
2032 /* Program max data length. */
2033 WI_SETVAL(WI_RID_MAX_DATALEN, sc->wi_max_data_len);
2035 /* Set the port type. */
2036 WI_SETVAL(WI_RID_PORTTYPE, sc->wi_ptype);
2038 /* Enable/disable IBSS creation. */
2039 WI_SETVAL(WI_RID_CREATE_IBSS, sc->wi_create_ibss);
2041 /* Program the RTS/CTS threshold. */
2042 WI_SETVAL(WI_RID_RTS_THRESH, sc->wi_rts_thresh);
2044 /* Program the TX rate */
2045 WI_SETVAL(WI_RID_TX_RATE, sc->wi_tx_rate);
2047 /* Access point density */
2048 WI_SETVAL(WI_RID_SYSTEM_SCALE, sc->wi_ap_density);
2050 /* Power Management Enabled */
2051 WI_SETVAL(WI_RID_PM_ENABLED, sc->wi_pm_enabled);
2053 /* Power Managment Max Sleep */
2054 WI_SETVAL(WI_RID_MAX_SLEEP, sc->wi_max_sleep);
2057 WI_SETVAL(WI_RID_ROAMING_MODE, sc->wi_roaming);
2059 /* Specify the IBSS name */
2060 WI_SETSTR(WI_RID_OWN_SSID, sc->wi_ibss_name);
2062 /* Specify the network name */
2063 WI_SETSTR(WI_RID_DESIRED_SSID, sc->wi_net_name);
2065 /* Specify the frequency to use */
2066 WI_SETVAL(WI_RID_OWN_CHNL, sc->wi_channel);
2068 /* Program the nodename. */
2069 WI_SETSTR(WI_RID_NODENAME, sc->wi_node_name);
2071 /* Specify the authentication mode. */
2072 WI_SETVAL(WI_RID_CNFAUTHMODE, sc->wi_authmode);
2074 /* Set our MAC address. */
2076 mac.wi_type = WI_RID_MAC_NODE;
2077 bcopy((char *)&sc->arpcom.ac_enaddr,
2078 (char *)&mac.wi_mac_addr, ETHER_ADDR_LEN);
2079 wi_write_record(sc, (struct wi_ltv_gen *)&mac);
2082 * Initialize promisc mode.
2083 * Being in the Host-AP mode causes
2084 * great deal of pain if promisc mode is set.
2085 * Therefore we avoid confusing the firmware
2086 * and always reset promisc mode in Host-AP regime,
2087 * it shows us all the packets anyway.
2089 if (sc->wi_ptype != WI_PORTTYPE_AP && ifp->if_flags & IFF_PROMISC)
2090 WI_SETVAL(WI_RID_PROMISC, 1);
2092 WI_SETVAL(WI_RID_PROMISC, 0);
2094 /* Configure WEP. */
2095 if (sc->wi_has_wep) {
2096 WI_SETVAL(WI_RID_ENCRYPTION, sc->wi_use_wep);
2097 WI_SETVAL(WI_RID_TX_CRYPT_KEY, sc->wi_tx_key);
2098 sc->wi_keys.wi_len = (sizeof(struct wi_ltv_keys) / 2) + 1;
2099 sc->wi_keys.wi_type = WI_RID_DEFLT_CRYPT_KEYS;
2100 wi_write_record(sc, (struct wi_ltv_gen *)&sc->wi_keys);
2101 if (sc->sc_firmware_type != WI_LUCENT && sc->wi_use_wep) {
2103 * ONLY HWB3163 EVAL-CARD Firmware version
2104 * less than 0.8 variant2
2106 * If promiscuous mode disable, Prism2 chip
2107 * does not work with WEP.
2108 * It is under investigation for details.
2109 * (ichiro@netbsd.org)
2111 * And make sure that we don't need to do it
2112 * in hostap mode, since it interferes with
2113 * the above hostap workaround.
2115 if (sc->wi_ptype != WI_PORTTYPE_AP &&
2116 sc->sc_firmware_type == WI_INTERSIL &&
2117 sc->sc_sta_firmware_ver < 802 ) {
2118 /* firm ver < 0.8 variant 2 */
2119 WI_SETVAL(WI_RID_PROMISC, 1);
2121 WI_SETVAL(WI_RID_CNFAUTHMODE, sc->wi_authtype);
2125 /* Set multicast filter. */
2128 /* Enable desired port */
2129 wi_cmd(sc, WI_CMD_ENABLE | sc->wi_portnum, 0, 0, 0);
2131 if (wi_alloc_nicmem(sc, ETHER_MAX_LEN + sizeof(struct wi_frame) + 8, &id))
2132 device_printf(sc->dev, "tx buffer allocation failed\n");
2133 sc->wi_tx_data_id = id;
2135 if (wi_alloc_nicmem(sc, ETHER_MAX_LEN + sizeof(struct wi_frame) + 8, &id))
2136 device_printf(sc->dev, "mgmt. buffer allocation failed\n");
2137 sc->wi_tx_mgmt_id = id;
2139 /* enable interrupts */
2140 CSR_WRITE_2(sc, WI_INT_EN, WI_INTRS);
2144 ifp->if_flags |= IFF_RUNNING;
2145 ifp->if_flags &= ~IFF_OACTIVE;
2147 sc->wi_stat_ch = timeout(wi_inquire, sc, hz * 60);
2153 #define RC4STATE 256
2154 #define RC4KEYLEN 16
2155 #define RC4SWAP(x,y) \
2156 do { u_int8_t t = state[x]; state[x] = state[y]; state[y] = t; } while(0)
2159 wi_do_hostencrypt(struct wi_softc *sc, caddr_t buf, int len)
2161 u_int32_t i, crc, klen;
2162 u_int8_t state[RC4STATE], key[RC4KEYLEN];
2163 u_int8_t x, y, *dat;
2165 if (!sc->wi_icv_flag) {
2166 sc->wi_icv = arc4random();
2171 * Skip 'bad' IVs from Fluhrer/Mantin/Shamir:
2172 * (B, 255, N) with 3 <= B < 8
2174 if (sc->wi_icv >= 0x03ff00 &&
2175 (sc->wi_icv & 0xf8ff00) == 0x00ff00)
2176 sc->wi_icv += 0x000100;
2178 /* prepend 24bit IV to tx key, byte order does not matter */
2179 key[0] = sc->wi_icv >> 16;
2180 key[1] = sc->wi_icv >> 8;
2181 key[2] = sc->wi_icv;
2183 klen = sc->wi_keys.wi_keys[sc->wi_tx_key].wi_keylen +
2184 IEEE80211_WEP_IVLEN;
2185 klen = (klen >= RC4KEYLEN) ? RC4KEYLEN : RC4KEYLEN/2;
2186 bcopy((char *)&sc->wi_keys.wi_keys[sc->wi_tx_key].wi_keydat,
2187 (char *)key + IEEE80211_WEP_IVLEN, klen - IEEE80211_WEP_IVLEN);
2191 for (i = 0; i < RC4STATE; i++)
2193 for (i = 0; i < RC4STATE; i++) {
2194 y = (key[x] + state[i] + y) % RC4STATE;
2199 /* output: IV, tx keyid, rc4(data), rc4(crc32(data)) */
2204 dat[3] = sc->wi_tx_key << 6; /* pad and keyid */
2207 /* compute rc4 over data, crc32 over data */
2210 for (i = 0; i < len; i++) {
2211 x = (x + 1) % RC4STATE;
2212 y = (state[x] + y) % RC4STATE;
2214 crc = crc32_tab[(crc ^ dat[i]) & 0xff] ^ (crc >> 8);
2215 dat[i] ^= state[(state[x] + state[y]) % RC4STATE];
2220 /* append little-endian crc32 and encrypt */
2225 for (i = 0; i < IEEE80211_WEP_CRCLEN; i++) {
2226 x = (x + 1) % RC4STATE;
2227 y = (state[x] + y) % RC4STATE;
2229 dat[i] ^= state[(state[x] + state[y]) % RC4STATE];
2237 struct wi_softc *sc;
2239 struct wi_frame tx_frame;
2240 struct ether_header *eh;
2252 if (ifp->if_flags & IFF_OACTIVE) {
2258 IF_DEQUEUE(&ifp->if_snd, m0);
2264 bzero((char *)&tx_frame, sizeof(tx_frame));
2265 tx_frame.wi_frame_ctl = htole16(WI_FTYPE_DATA);
2266 id = sc->wi_tx_data_id;
2267 eh = mtod(m0, struct ether_header *);
2269 if (sc->wi_ptype == WI_PORTTYPE_AP) {
2270 if (!wihap_check_tx(&sc->wi_hostap_info,
2271 eh->ether_dhost, &tx_frame.wi_tx_rate)) {
2272 if (ifp->if_flags & IFF_DEBUG)
2273 printf("wi_start: dropping unassoc "
2274 "dst %6D\n", eh->ether_dhost, ":");
2280 * Use RFC1042 encoding for IP and ARP datagrams,
2281 * 802.3 for anything else.
2283 if (ntohs(eh->ether_type) > ETHER_MAX_LEN) {
2284 bcopy((char *)&eh->ether_dhost,
2285 (char *)&tx_frame.wi_addr1, ETHER_ADDR_LEN);
2286 if (sc->wi_ptype == WI_PORTTYPE_AP) {
2287 tx_frame.wi_tx_ctl = WI_ENC_TX_MGMT; /* XXX */
2288 tx_frame.wi_frame_ctl |= WI_FCTL_FROMDS;
2290 tx_frame.wi_frame_ctl |= WI_FCTL_WEP;
2291 bcopy((char *)&sc->arpcom.ac_enaddr,
2292 (char *)&tx_frame.wi_addr2, ETHER_ADDR_LEN);
2293 bcopy((char *)&eh->ether_shost,
2294 (char *)&tx_frame.wi_addr3, ETHER_ADDR_LEN);
2297 bcopy((char *)&eh->ether_shost,
2298 (char *)&tx_frame.wi_addr2, ETHER_ADDR_LEN);
2299 bcopy((char *)&eh->ether_dhost,
2300 (char *)&tx_frame.wi_dst_addr, ETHER_ADDR_LEN);
2301 bcopy((char *)&eh->ether_shost,
2302 (char *)&tx_frame.wi_src_addr, ETHER_ADDR_LEN);
2304 tx_frame.wi_dat_len = m0->m_pkthdr.len - WI_SNAPHDR_LEN;
2305 tx_frame.wi_dat[0] = htons(WI_SNAP_WORD0);
2306 tx_frame.wi_dat[1] = htons(WI_SNAP_WORD1);
2307 tx_frame.wi_len = htons(m0->m_pkthdr.len - WI_SNAPHDR_LEN);
2308 tx_frame.wi_type = eh->ether_type;
2310 if (sc->wi_ptype == WI_PORTTYPE_AP && sc->wi_use_wep) {
2311 /* Do host encryption. */
2312 bcopy(&tx_frame.wi_dat[0], &sc->wi_txbuf[4], 8);
2313 m_copydata(m0, sizeof(struct ether_header),
2314 m0->m_pkthdr.len - sizeof(struct ether_header),
2315 (caddr_t)&sc->wi_txbuf[12]);
2316 wi_do_hostencrypt(sc, &sc->wi_txbuf[0],
2317 tx_frame.wi_dat_len);
2318 tx_frame.wi_dat_len += IEEE80211_WEP_IVLEN +
2319 IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN;
2320 wi_write_data(sc, id, 0, (caddr_t)&tx_frame,
2321 sizeof(struct wi_frame));
2322 wi_write_data(sc, id, WI_802_11_OFFSET_RAW,
2323 (caddr_t)&sc->wi_txbuf, (m0->m_pkthdr.len -
2324 sizeof(struct ether_header)) + 18);
2326 m_copydata(m0, sizeof(struct ether_header),
2327 m0->m_pkthdr.len - sizeof(struct ether_header),
2328 (caddr_t)&sc->wi_txbuf);
2329 wi_write_data(sc, id, 0, (caddr_t)&tx_frame,
2330 sizeof(struct wi_frame));
2331 wi_write_data(sc, id, WI_802_11_OFFSET,
2332 (caddr_t)&sc->wi_txbuf, (m0->m_pkthdr.len -
2333 sizeof(struct ether_header)) + 2);
2336 tx_frame.wi_dat_len = m0->m_pkthdr.len;
2338 if (sc->wi_ptype == WI_PORTTYPE_AP && sc->wi_use_wep) {
2339 /* Do host encryption. */
2340 printf( "XXX: host encrypt not implemented for 802.3\n" );
2342 eh->ether_type = htons(m0->m_pkthdr.len -
2344 m_copydata(m0, 0, m0->m_pkthdr.len,
2345 (caddr_t)&sc->wi_txbuf);
2347 wi_write_data(sc, id, 0, (caddr_t)&tx_frame,
2348 sizeof(struct wi_frame));
2349 wi_write_data(sc, id, WI_802_3_OFFSET,
2350 (caddr_t)&sc->wi_txbuf, m0->m_pkthdr.len + 2);
2355 * If there's a BPF listner, bounce a copy of
2356 * this frame to him. Also, don't send this to the bpf sniffer
2357 * if we're in procframe or monitor sniffing mode.
2359 if (!(sc->wi_procframe || sc->wi_debug.wi_monitor) && ifp->if_bpf)
2364 if (wi_cmd(sc, WI_CMD_TX|WI_RECLAIM, id, 0, 0))
2365 device_printf(sc->dev, "xmit failed\n");
2367 ifp->if_flags |= IFF_OACTIVE;
2370 * Set a timeout in case the chip goes out to lunch.
2379 wi_mgmt_xmit(sc, data, len)
2380 struct wi_softc *sc;
2384 struct wi_frame tx_frame;
2386 struct wi_80211_hdr *hdr;
2392 hdr = (struct wi_80211_hdr *)data;
2393 dptr = data + sizeof(struct wi_80211_hdr);
2395 bzero((char *)&tx_frame, sizeof(tx_frame));
2396 id = sc->wi_tx_mgmt_id;
2398 bcopy((char *)hdr, (char *)&tx_frame.wi_frame_ctl,
2399 sizeof(struct wi_80211_hdr));
2401 tx_frame.wi_tx_ctl = WI_ENC_TX_MGMT;
2402 tx_frame.wi_dat_len = len - sizeof(struct wi_80211_hdr);
2403 tx_frame.wi_len = htons(tx_frame.wi_dat_len);
2405 wi_write_data(sc, id, 0, (caddr_t)&tx_frame, sizeof(struct wi_frame));
2406 wi_write_data(sc, id, WI_802_11_OFFSET_RAW, dptr,
2407 len - sizeof(struct wi_80211_hdr) + 2);
2409 if (wi_cmd(sc, WI_CMD_TX|WI_RECLAIM, id, 0, 0)) {
2410 device_printf(sc->dev, "xmit failed\n");
2419 struct wi_softc *sc;
2433 ifp = &sc->arpcom.ac_if;
2436 * If the card is gone and the memory port isn't mapped, we will
2437 * (hopefully) get 0xffff back from the status read, which is not
2438 * a valid status value.
2440 if (CSR_READ_2(sc, WI_STATUS) != 0xffff) {
2441 CSR_WRITE_2(sc, WI_INT_EN, 0);
2442 wi_cmd(sc, WI_CMD_DISABLE|sc->wi_portnum, 0, 0, 0);
2445 untimeout(wi_inquire, sc, sc->wi_stat_ch);
2447 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2457 struct wi_softc *sc;
2461 device_printf(sc->dev, "watchdog timeout\n");
2475 struct wi_softc *sc = device_get_softc(dev);
2477 if (sc->wi_bus_type != WI_BUS_PCI_NATIVE) {
2478 sc->iobase_rid = rid;
2479 sc->iobase = bus_alloc_resource(dev, SYS_RES_IOPORT,
2480 &sc->iobase_rid, 0, ~0, (1 << 6),
2481 rman_make_alignment_flags(1 << 6) | RF_ACTIVE);
2483 device_printf(dev, "No I/O space?!\n");
2487 sc->wi_io_addr = rman_get_start(sc->iobase);
2488 sc->wi_btag = rman_get_bustag(sc->iobase);
2489 sc->wi_bhandle = rman_get_bushandle(sc->iobase);
2492 sc->mem = bus_alloc_resource(dev, SYS_RES_MEMORY,
2493 &sc->mem_rid, 0, ~0, 1, RF_ACTIVE);
2496 device_printf(dev, "No Mem space on prism2.5?\n");
2500 sc->wi_btag = rman_get_bustag(sc->mem);
2501 sc->wi_bhandle = rman_get_bushandle(sc->mem);
2506 sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid,
2507 0, ~0, 1, RF_ACTIVE |
2508 ((sc->wi_bus_type == WI_BUS_PCCARD) ? 0 : RF_SHAREABLE));
2512 device_printf(dev, "No irq?!\n");
2517 sc->wi_unit = device_get_unit(dev);
2526 struct wi_softc *sc = device_get_softc(dev);
2528 if (sc->iobase != NULL) {
2529 bus_release_resource(dev, SYS_RES_IOPORT, sc->iobase_rid, sc->iobase);
2532 if (sc->irq != NULL) {
2533 bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq);
2536 if (sc->mem != NULL) {
2537 bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem);
2548 struct wi_softc *sc;
2550 sc = device_get_softc(dev);
2557 /* wavelan signal strength cache code.
2558 * store signal/noise/quality on per MAC src basis in
2559 * a small fixed cache. The cache wraps if > MAX slots
2560 * used. The cache may be zeroed out to start over.
2561 * Two simple filters exist to reduce computation:
2562 * 1. ip only (literally 0x800) which may be used
2563 * to ignore some packets. It defaults to ip only.
2564 * it could be used to focus on broadcast, non-IP 802.11 beacons.
2565 * 2. multicast/broadcast only. This may be used to
2566 * ignore unicast packets and only cache signal strength
2567 * for multicast/broadcast packets (beacons); e.g., Mobile-IP
2568 * beacons and not unicast traffic.
2570 * The cache stores (MAC src(index), IP src (major clue), signal,
2573 * No apologies for storing IP src here. It's easy and saves much
2574 * trouble elsewhere. The cache is assumed to be INET dependent,
2575 * although it need not be.
2578 #ifdef documentation
2580 int wi_sigitems; /* number of cached entries */
2581 struct wi_sigcache wi_sigcache[MAXWICACHE]; /* array of cache entries */
2582 int wi_nextitem; /* index/# of entries */
2587 /* control variables for cache filtering. Basic idea is
2588 * to reduce cost (e.g., to only Mobile-IP agent beacons
2589 * which are broadcast or multicast). Still you might
2590 * want to measure signal strength with unicast ping packets
2591 * on a pt. to pt. ant. setup.
2593 /* set true if you want to limit cache items to broadcast/mcast
2594 * only packets (not unicast). Useful for mobile-ip beacons which
2595 * are broadcast/multicast at network layer. Default is all packets
2596 * so ping/unicast will work say with pt. to pt. antennae setup.
2598 static int wi_cache_mcastonly = 0;
2599 SYSCTL_INT(_machdep, OID_AUTO, wi_cache_mcastonly, CTLFLAG_RW,
2600 &wi_cache_mcastonly, 0, "");
2602 /* set true if you want to limit cache items to IP packets only
2604 static int wi_cache_iponly = 1;
2605 SYSCTL_INT(_machdep, OID_AUTO, wi_cache_iponly, CTLFLAG_RW,
2606 &wi_cache_iponly, 0, "");
2609 * Original comments:
2611 * wi_cache_store, per rx packet store signal
2612 * strength in MAC (src) indexed cache.
2614 * follows linux driver in how signal strength is computed.
2615 * In ad hoc mode, we use the rx_quality field.
2616 * signal and noise are trimmed to fit in the range from 47..138.
2617 * rx_quality field MSB is signal strength.
2618 * rx_quality field LSB is noise.
2619 * "quality" is (signal - noise) as is log value.
2620 * note: quality CAN be negative.
2622 * In BSS mode, we use the RID for communication quality.
2623 * TBD: BSS mode is currently untested.
2627 * Actually, we use the rx_quality field all the time for both "ad-hoc"
2628 * and BSS modes. Why? Because reading an RID is really, really expensive:
2629 * there's a bunch of PIO operations that have to be done to read a record
2630 * from the NIC, and reading the comms quality RID each time a packet is
2631 * received can really hurt performance. We don't have to do this anyway:
2632 * the comms quality field only reflects the values in the rx_quality field
2633 * anyway. The comms quality RID is only meaningful in infrastructure mode,
2634 * but the values it contains are updated based on the rx_quality from
2635 * frames received from the access point.
2637 * Also, according to Lucent, the signal strength and noise level values
2638 * can be converted to dBms by subtracting 149, so I've modified the code
2639 * to do that instead of the scaling it did originally.
2642 wi_cache_store(struct wi_softc *sc, struct mbuf *m, unsigned short rx_quality)
2644 struct ether_header *eh = mtod(m, struct ether_header *);
2645 struct ip *ip = NULL;
2647 static int cache_slot = 0; /* use this cache entry */
2648 static int wrapindex = 0; /* next "free" cache entry */
2654 * 2. configurable filter to throw out unicast packets,
2655 * keep multicast only.
2658 if ((ntohs(eh->ether_type) == ETHERTYPE_IP))
2659 ip = (struct ip *)(mtod(m, uint8_t *) + ETHER_HDR_LEN);
2660 else if (wi_cache_iponly)
2664 * filter for broadcast/multicast only
2666 if (wi_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) {
2671 printf("wi%d: q value %x (MSB=0x%x, LSB=0x%x) \n", sc->wi_unit,
2672 rx_quality & 0xffff, rx_quality >> 8, rx_quality & 0xff);
2677 * do a linear search for a matching MAC address
2678 * in the cache table
2679 * . MAC address is 6 bytes,
2680 * . var w_nextitem holds total number of entries already cached
2682 for(i = 0; i < sc->wi_nextitem; i++) {
2683 if (! bcmp(eh->ether_shost , sc->wi_sigcache[i].macsrc, 6 )) {
2686 * so we already have this entry,
2694 * did we find a matching mac address?
2695 * if yes, then overwrite a previously existing cache entry
2697 if (i < sc->wi_nextitem ) {
2701 * else, have a new address entry,so
2702 * add this new entry,
2703 * if table full, then we need to replace LRU entry
2708 * check for space in cache table
2709 * note: wi_nextitem also holds number of entries
2710 * added in the cache table
2712 if ( sc->wi_nextitem < MAXWICACHE ) {
2713 cache_slot = sc->wi_nextitem;
2715 sc->wi_sigitems = sc->wi_nextitem;
2717 /* no space found, so simply wrap with wrap index
2718 * and "zap" the next entry
2721 if (wrapindex == MAXWICACHE) {
2724 cache_slot = wrapindex++;
2729 * invariant: cache_slot now points at some slot
2732 if (cache_slot < 0 || cache_slot >= MAXWICACHE) {
2733 log(LOG_ERR, "wi_cache_store, bad index: %d of "
2734 "[0..%d], gross cache error\n",
2735 cache_slot, MAXWICACHE);
2740 * store items in cache
2741 * .ip source address
2746 sc->wi_sigcache[cache_slot].ipsrc = ip->ip_src.s_addr;
2747 bcopy( eh->ether_shost, sc->wi_sigcache[cache_slot].macsrc, 6);
2749 sig = (rx_quality >> 8) & 0xFF;
2750 noise = rx_quality & 0xFF;
2751 sc->wi_sigcache[cache_slot].signal = sig - 149;
2752 sc->wi_sigcache[cache_slot].noise = noise - 149;
2753 sc->wi_sigcache[cache_slot].quality = sig - noise;
2760 wi_get_cur_ssid(sc, ssid, len)
2761 struct wi_softc *sc;
2768 wreq.wi_len = WI_MAX_DATALEN;
2769 switch (sc->wi_ptype) {
2770 case WI_PORTTYPE_AP:
2771 *len = IEEE80211_NWID_LEN;
2772 bcopy(sc->wi_net_name, ssid, IEEE80211_NWID_LEN);
2774 case WI_PORTTYPE_ADHOC:
2775 wreq.wi_type = WI_RID_CURRENT_SSID;
2776 error = wi_read_record(sc, (struct wi_ltv_gen *)&wreq);
2779 if (wreq.wi_val[0] > IEEE80211_NWID_LEN) {
2783 *len = wreq.wi_val[0];
2784 bcopy(&wreq.wi_val[1], ssid, IEEE80211_NWID_LEN);
2786 case WI_PORTTYPE_BSS:
2787 wreq.wi_type = WI_RID_COMMQUAL;
2788 error = wi_read_record(sc, (struct wi_ltv_gen *)&wreq);
2791 if (wreq.wi_val[0] != 0) /* associated */ {
2792 wreq.wi_type = WI_RID_CURRENT_SSID;
2793 wreq.wi_len = WI_MAX_DATALEN;
2794 error = wi_read_record(sc, (struct wi_ltv_gen *)&wreq);
2797 if (wreq.wi_val[0] > IEEE80211_NWID_LEN) {
2801 *len = wreq.wi_val[0];
2802 bcopy(&wreq.wi_val[1], ssid, IEEE80211_NWID_LEN);
2804 *len = IEEE80211_NWID_LEN;
2805 bcopy(sc->wi_net_name, ssid, IEEE80211_NWID_LEN);
2817 wi_media_change(ifp)
2820 struct wi_softc *sc = ifp->if_softc;
2821 int otype = sc->wi_ptype;
2822 int orate = sc->wi_tx_rate;
2823 int ocreate_ibss = sc->wi_create_ibss;
2825 if ((sc->ifmedia.ifm_cur->ifm_media & IFM_IEEE80211_HOSTAP) &&
2826 sc->sc_firmware_type != WI_INTERSIL)
2829 sc->wi_create_ibss = 0;
2831 switch (sc->ifmedia.ifm_cur->ifm_media & IFM_OMASK) {
2833 sc->wi_ptype = WI_PORTTYPE_BSS;
2835 case IFM_IEEE80211_ADHOC:
2836 sc->wi_ptype = WI_PORTTYPE_ADHOC;
2838 case IFM_IEEE80211_HOSTAP:
2839 sc->wi_ptype = WI_PORTTYPE_AP;
2841 case IFM_IEEE80211_IBSSMASTER:
2842 case IFM_IEEE80211_IBSSMASTER|IFM_IEEE80211_IBSS:
2843 if (!(sc->wi_flags & WI_FLAGS_HAS_CREATE_IBSS))
2845 sc->wi_create_ibss = 1;
2847 case IFM_IEEE80211_IBSS:
2848 sc->wi_ptype = WI_PORTTYPE_IBSS;
2851 /* Invalid combination. */
2855 switch (IFM_SUBTYPE(sc->ifmedia.ifm_cur->ifm_media)) {
2856 case IFM_IEEE80211_DS1:
2859 case IFM_IEEE80211_DS2:
2862 case IFM_IEEE80211_DS5:
2865 case IFM_IEEE80211_DS11:
2866 sc->wi_tx_rate = 11;
2873 if (ocreate_ibss != sc->wi_create_ibss || otype != sc->wi_ptype ||
2874 orate != sc->wi_tx_rate)
2881 wi_media_status(ifp, imr)
2883 struct ifmediareq *imr;
2886 struct wi_softc *sc = ifp->if_softc;
2888 if (sc->wi_tx_rate == 3) {
2889 imr->ifm_active = IFM_IEEE80211|IFM_AUTO;
2890 if (sc->wi_ptype == WI_PORTTYPE_ADHOC)
2891 imr->ifm_active |= IFM_IEEE80211_ADHOC;
2892 else if (sc->wi_ptype == WI_PORTTYPE_AP)
2893 imr->ifm_active |= IFM_IEEE80211_HOSTAP;
2894 else if (sc->wi_ptype == WI_PORTTYPE_IBSS) {
2895 if (sc->wi_create_ibss)
2896 imr->ifm_active |= IFM_IEEE80211_IBSSMASTER;
2898 imr->ifm_active |= IFM_IEEE80211_IBSS;
2900 wreq.wi_type = WI_RID_CUR_TX_RATE;
2901 wreq.wi_len = WI_MAX_DATALEN;
2902 if (wi_read_record(sc, (struct wi_ltv_gen *)&wreq) == 0) {
2903 switch(wreq.wi_val[0]) {
2905 imr->ifm_active |= IFM_IEEE80211_DS1;
2908 imr->ifm_active |= IFM_IEEE80211_DS2;
2911 imr->ifm_active |= IFM_IEEE80211_DS5;
2914 imr->ifm_active |= IFM_IEEE80211_DS11;
2919 imr->ifm_active = sc->ifmedia.ifm_cur->ifm_media;
2922 imr->ifm_status = IFM_AVALID;
2923 if (sc->wi_ptype == WI_PORTTYPE_ADHOC ||
2924 sc->wi_ptype == WI_PORTTYPE_IBSS)
2926 * XXX: It would be nice if we could give some actually
2927 * useful status like whether we joined another IBSS or
2928 * created one ourselves.
2930 imr->ifm_status |= IFM_ACTIVE;
2931 else if (sc->wi_ptype == WI_PORTTYPE_AP)
2932 imr->ifm_status |= IFM_ACTIVE;
2934 wreq.wi_type = WI_RID_COMMQUAL;
2935 wreq.wi_len = WI_MAX_DATALEN;
2936 if (wi_read_record(sc, (struct wi_ltv_gen *)&wreq) == 0 &&
2937 wreq.wi_val[0] != 0)
2938 imr->ifm_status |= IFM_ACTIVE;
2943 wi_get_debug(sc, wreq)
2944 struct wi_softc *sc;
2945 struct wi_req *wreq;
2951 switch (wreq->wi_type) {
2952 case WI_DEBUG_SLEEP:
2954 wreq->wi_val[0] = sc->wi_debug.wi_sleep;
2956 case WI_DEBUG_DELAYSUPP:
2958 wreq->wi_val[0] = sc->wi_debug.wi_delaysupp;
2960 case WI_DEBUG_TXSUPP:
2962 wreq->wi_val[0] = sc->wi_debug.wi_txsupp;
2964 case WI_DEBUG_MONITOR:
2966 wreq->wi_val[0] = sc->wi_debug.wi_monitor;
2968 case WI_DEBUG_LEDTEST:
2970 wreq->wi_val[0] = sc->wi_debug.wi_ledtest;
2971 wreq->wi_val[1] = sc->wi_debug.wi_ledtest_param0;
2972 wreq->wi_val[2] = sc->wi_debug.wi_ledtest_param1;
2974 case WI_DEBUG_CONTTX:
2976 wreq->wi_val[0] = sc->wi_debug.wi_conttx;
2977 wreq->wi_val[1] = sc->wi_debug.wi_conttx_param0;
2979 case WI_DEBUG_CONTRX:
2981 wreq->wi_val[0] = sc->wi_debug.wi_contrx;
2983 case WI_DEBUG_SIGSTATE:
2985 wreq->wi_val[0] = sc->wi_debug.wi_sigstate;
2986 wreq->wi_val[1] = sc->wi_debug.wi_sigstate_param0;
2988 case WI_DEBUG_CONFBITS:
2990 wreq->wi_val[0] = sc->wi_debug.wi_confbits;
2991 wreq->wi_val[1] = sc->wi_debug.wi_confbits_param0;
3002 wi_set_debug(sc, wreq)
3003 struct wi_softc *sc;
3004 struct wi_req *wreq;
3007 u_int16_t cmd, param0 = 0, param1 = 0;
3009 switch (wreq->wi_type) {
3010 case WI_DEBUG_RESET:
3012 case WI_DEBUG_CALENABLE:
3014 case WI_DEBUG_SLEEP:
3015 sc->wi_debug.wi_sleep = 1;
3018 sc->wi_debug.wi_sleep = 0;
3021 param0 = wreq->wi_val[0];
3023 case WI_DEBUG_DELAYSUPP:
3024 sc->wi_debug.wi_delaysupp = 1;
3026 case WI_DEBUG_TXSUPP:
3027 sc->wi_debug.wi_txsupp = 1;
3029 case WI_DEBUG_MONITOR:
3030 sc->wi_debug.wi_monitor = 1;
3032 case WI_DEBUG_LEDTEST:
3033 param0 = wreq->wi_val[0];
3034 param1 = wreq->wi_val[1];
3035 sc->wi_debug.wi_ledtest = 1;
3036 sc->wi_debug.wi_ledtest_param0 = param0;
3037 sc->wi_debug.wi_ledtest_param1 = param1;
3039 case WI_DEBUG_CONTTX:
3040 param0 = wreq->wi_val[0];
3041 sc->wi_debug.wi_conttx = 1;
3042 sc->wi_debug.wi_conttx_param0 = param0;
3044 case WI_DEBUG_STOPTEST:
3045 sc->wi_debug.wi_delaysupp = 0;
3046 sc->wi_debug.wi_txsupp = 0;
3047 sc->wi_debug.wi_monitor = 0;
3048 sc->wi_debug.wi_ledtest = 0;
3049 sc->wi_debug.wi_ledtest_param0 = 0;
3050 sc->wi_debug.wi_ledtest_param1 = 0;
3051 sc->wi_debug.wi_conttx = 0;
3052 sc->wi_debug.wi_conttx_param0 = 0;
3053 sc->wi_debug.wi_contrx = 0;
3054 sc->wi_debug.wi_sigstate = 0;
3055 sc->wi_debug.wi_sigstate_param0 = 0;
3057 case WI_DEBUG_CONTRX:
3058 sc->wi_debug.wi_contrx = 1;
3060 case WI_DEBUG_SIGSTATE:
3061 param0 = wreq->wi_val[0];
3062 sc->wi_debug.wi_sigstate = 1;
3063 sc->wi_debug.wi_sigstate_param0 = param0;
3065 case WI_DEBUG_CONFBITS:
3066 param0 = wreq->wi_val[0];
3067 param1 = wreq->wi_val[1];
3068 sc->wi_debug.wi_confbits = param0;
3069 sc->wi_debug.wi_confbits_param0 = param1;
3079 cmd = WI_CMD_DEBUG | (wreq->wi_type << 8);
3080 error = wi_cmd(sc, cmd, param0, param1, 0);