1 /* $NetBSD: wi.c,v 1.109 2003/01/09 08:52:19 dyoung Exp $ */
4 * Copyright (c) 1997, 1998, 1999
5 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Bill Paul.
18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
36 * Lucent WaveLAN/IEEE 802.11 PCMCIA driver.
38 * Original FreeBSD driver written by Bill Paul <wpaul@ctr.columbia.edu>
39 * Electrical Engineering Department
40 * Columbia University, New York City
44 * The WaveLAN/IEEE adapter is the second generation of the WaveLAN
45 * from Lucent. Unlike the older cards, the new ones are programmed
46 * entirely via a firmware-driven controller called the Hermes.
47 * Unfortunately, Lucent will not release the Hermes programming manual
48 * without an NDA (if at all). What they do release is an API library
49 * called the HCF (Hardware Control Functions) which is supposed to
50 * do the device-specific operations of a device driver for you. The
51 * publically available version of the HCF library (the 'HCF Light') is
52 * a) extremely gross, b) lacks certain features, particularly support
53 * for 802.11 frames, and c) is contaminated by the GNU Public License.
55 * This driver does not use the HCF or HCF Light at all. Instead, it
56 * programs the Hermes controller directly, using information gleaned
57 * from the HCF Light code and corresponding documentation.
59 * This driver supports the ISA, PCMCIA and PCI versions of the Lucent
60 * WaveLan cards (based on the Hermes chipset), as well as the newer
61 * Prism 2 chipsets with firmware from Intersil and Symbol.
64 #include <sys/cdefs.h>
65 __FBSDID("$FreeBSD$");
67 #define WI_HERMES_AUTOINC_WAR /* Work around data write autoinc bug. */
68 #define WI_HERMES_STATS_WAR /* Work around stats counter bug. */
72 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <sys/endian.h>
75 #include <sys/sockio.h>
79 #include <sys/kernel.h>
80 #include <sys/socket.h>
81 #include <sys/module.h>
83 #include <sys/random.h>
84 #include <sys/syslog.h>
85 #include <sys/sysctl.h>
87 #include <machine/bus.h>
88 #include <machine/resource.h>
89 #include <machine/atomic.h>
93 #include <net/if_arp.h>
94 #include <net/ethernet.h>
95 #include <net/if_dl.h>
96 #include <net/if_media.h>
97 #include <net/if_types.h>
99 #include <net80211/ieee80211_var.h>
100 #include <net80211/ieee80211_ioctl.h>
101 #include <net80211/ieee80211_radiotap.h>
103 #include <netinet/in.h>
104 #include <netinet/in_systm.h>
105 #include <netinet/in_var.h>
106 #include <netinet/ip.h>
107 #include <netinet/if_ether.h>
111 #include <dev/wi/if_wavelan_ieee.h>
112 #include <dev/wi/if_wireg.h>
113 #include <dev/wi/if_wivar.h>
115 static void wi_start_locked(struct ifnet *);
116 static void wi_start(struct ifnet *);
117 static int wi_start_tx(struct ifnet *ifp, struct wi_frame *frmhdr,
119 static int wi_raw_xmit(struct ieee80211_node *, struct mbuf *,
120 const struct ieee80211_bpf_params *);
121 static int wi_reset(struct ifnet *);
122 static void wi_watchdog(void *);
123 static int wi_ioctl(struct ifnet *, u_long, caddr_t);
124 static int wi_media_change(struct ifnet *);
125 static void wi_media_status(struct ifnet *, struct ifmediareq *);
127 static void wi_rx_intr(struct wi_softc *);
128 static void wi_tx_intr(struct wi_softc *);
129 static void wi_tx_ex_intr(struct wi_softc *);
130 static void wi_info_intr(struct wi_softc *);
132 static int wi_key_alloc(struct ieee80211com *, const struct ieee80211_key *,
133 ieee80211_keyix *, ieee80211_keyix *);
136 static int wi_get_cfg(struct ifnet *, u_long, caddr_t);
137 static int wi_set_cfg(struct ifnet *, u_long, caddr_t);
139 static int wi_write_txrate(struct wi_softc *);
140 static int wi_write_wep(struct wi_softc *);
141 static int wi_write_multi(struct wi_softc *);
142 static int wi_alloc_fid(struct wi_softc *, int, int *);
143 static void wi_read_nicid(struct wi_softc *);
144 static int wi_write_ssid(struct wi_softc *, int, u_int8_t *, int);
146 static int wi_cmd(struct wi_softc *, int, int, int, int);
147 static int wi_seek_bap(struct wi_softc *, int, int);
148 static int wi_read_bap(struct wi_softc *, int, int, void *, int);
149 static int wi_write_bap(struct wi_softc *, int, int, void *, int);
150 static int wi_mwrite_bap(struct wi_softc *, int, int, struct mbuf *, int);
151 static int wi_read_rid(struct wi_softc *, int, void *, int *);
152 static int wi_write_rid(struct wi_softc *, int, void *, int);
154 static int wi_newstate(struct ieee80211com *, enum ieee80211_state, int);
156 static int wi_scan_ap(struct wi_softc *, u_int16_t, u_int16_t);
157 static void wi_scan_result(struct wi_softc *, int, int);
159 static void wi_dump_pkt(struct wi_frame *, struct ieee80211_node *, int rssi);
162 static int wi_get_debug(struct wi_softc *, struct wi_req *);
163 static int wi_set_debug(struct wi_softc *, struct wi_req *);
166 /* support to download firmware for symbol CF card */
167 static int wi_symbol_write_firm(struct wi_softc *, const void *, int,
169 static int wi_symbol_set_hcr(struct wi_softc *, int);
171 static void wi_scan_start(struct ieee80211com *);
172 static void wi_scan_curchan(struct ieee80211com *, unsigned long);
173 static void wi_scan_mindwell(struct ieee80211com *);
174 static void wi_scan_end(struct ieee80211com *);
175 static void wi_set_channel(struct ieee80211com *);
176 static void wi_update_slot(struct ifnet *);
177 static struct ieee80211_node *wi_node_alloc(struct ieee80211_node_table *);
178 static int wi_ioctl_get(struct ifnet *ifp, u_long command, caddr_t data);
179 static int wi_ioctl_set(struct ifnet *ifp, u_long command, caddr_t data);
182 wi_write_val(struct wi_softc *sc, int rid, u_int16_t val)
186 return wi_write_rid(sc, rid, &val, sizeof(val));
189 SYSCTL_NODE(_hw, OID_AUTO, wi, CTLFLAG_RD, 0, "Wireless driver parameters");
191 static struct timeval lasttxerror; /* time of last tx error msg */
192 static int curtxeps; /* current tx error msgs/sec */
193 static int wi_txerate = 0; /* tx error rate: max msgs/sec */
194 SYSCTL_INT(_hw_wi, OID_AUTO, txerate, CTLFLAG_RW, &wi_txerate,
195 0, "max tx error msgs/sec; 0 to disable msgs");
199 static int wi_debug = 0;
200 SYSCTL_INT(_hw_wi, OID_AUTO, debug, CTLFLAG_RW, &wi_debug,
201 0, "control debugging printfs");
203 #define DPRINTF(X) if (wi_debug) printf X
204 #define DPRINTF2(X) if (wi_debug > 1) printf X
205 #define IFF_DUMPPKTS(_ifp) \
206 (((_ifp)->if_flags & (IFF_DEBUG|IFF_LINK2)) == (IFF_DEBUG|IFF_LINK2))
210 #define IFF_DUMPPKTS(_ifp) 0
213 #define WI_INTRS (WI_EV_RX | WI_EV_ALLOC | WI_EV_INFO)
215 struct wi_card_ident wi_card_ident[] = {
216 /* CARD_ID CARD_NAME FIRM_TYPE */
217 { WI_NIC_LUCENT_ID, WI_NIC_LUCENT_STR, WI_LUCENT },
218 { WI_NIC_SONY_ID, WI_NIC_SONY_STR, WI_LUCENT },
219 { WI_NIC_LUCENT_EMB_ID, WI_NIC_LUCENT_EMB_STR, WI_LUCENT },
220 { WI_NIC_EVB2_ID, WI_NIC_EVB2_STR, WI_INTERSIL },
221 { WI_NIC_HWB3763_ID, WI_NIC_HWB3763_STR, WI_INTERSIL },
222 { WI_NIC_HWB3163_ID, WI_NIC_HWB3163_STR, WI_INTERSIL },
223 { WI_NIC_HWB3163B_ID, WI_NIC_HWB3163B_STR, WI_INTERSIL },
224 { WI_NIC_EVB3_ID, WI_NIC_EVB3_STR, WI_INTERSIL },
225 { WI_NIC_HWB1153_ID, WI_NIC_HWB1153_STR, WI_INTERSIL },
226 { WI_NIC_P2_SST_ID, WI_NIC_P2_SST_STR, WI_INTERSIL },
227 { WI_NIC_EVB2_SST_ID, WI_NIC_EVB2_SST_STR, WI_INTERSIL },
228 { WI_NIC_3842_EVA_ID, WI_NIC_3842_EVA_STR, WI_INTERSIL },
229 { WI_NIC_3842_PCMCIA_AMD_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL },
230 { WI_NIC_3842_PCMCIA_SST_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL },
231 { WI_NIC_3842_PCMCIA_ATL_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL },
232 { WI_NIC_3842_PCMCIA_ATS_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL },
233 { WI_NIC_3842_MINI_AMD_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL },
234 { WI_NIC_3842_MINI_SST_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL },
235 { WI_NIC_3842_MINI_ATL_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL },
236 { WI_NIC_3842_MINI_ATS_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL },
237 { WI_NIC_3842_PCI_AMD_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL },
238 { WI_NIC_3842_PCI_SST_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL },
239 { WI_NIC_3842_PCI_ATS_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL },
240 { WI_NIC_3842_PCI_ATL_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL },
241 { WI_NIC_P3_PCMCIA_AMD_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL },
242 { WI_NIC_P3_PCMCIA_SST_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL },
243 { WI_NIC_P3_PCMCIA_ATL_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL },
244 { WI_NIC_P3_PCMCIA_ATS_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL },
245 { WI_NIC_P3_MINI_AMD_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL },
246 { WI_NIC_P3_MINI_SST_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL },
247 { WI_NIC_P3_MINI_ATL_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL },
248 { WI_NIC_P3_MINI_ATS_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL },
252 devclass_t wi_devclass;
255 wi_attach(device_t dev)
257 struct wi_softc *sc = device_get_softc(dev);
258 struct ieee80211com *ic = &sc->sc_ic;
260 int i, nrates, buflen;
262 u_int8_t ratebuf[2 + IEEE80211_RATE_SIZE];
263 struct ieee80211_rateset *rs;
264 static const u_int8_t empty_macaddr[IEEE80211_ADDR_LEN] = {
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
269 ifp = sc->sc_ifp = if_alloc(IFT_ETHER);
271 device_printf(dev, "can not if_alloc\n");
278 * NB: no locking is needed here; don't put it here
279 * unless you can prove it!
281 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE,
282 NULL, wi_intr, sc, &sc->wi_intrhand);
285 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error);
290 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
291 MTX_DEF | MTX_RECURSE);
292 callout_init_mtx(&sc->sc_watchdog, &sc->sc_mtx, 0);
294 sc->sc_firmware_type = WI_NOTYPE;
295 sc->wi_cmd_count = 500;
297 if (wi_reset(ifp) != 0)
298 return ENXIO; /* XXX */
301 * Read the station address.
302 * And do it twice. I've seen PRISM-based cards that return
303 * an error when trying to read it the first time, which causes
306 buflen = IEEE80211_ADDR_LEN;
307 error = wi_read_rid(sc, WI_RID_MAC_NODE, ic->ic_myaddr, &buflen);
309 buflen = IEEE80211_ADDR_LEN;
310 error = wi_read_rid(sc, WI_RID_MAC_NODE, ic->ic_myaddr, &buflen);
312 if (error || IEEE80211_ADDR_EQ(ic->ic_myaddr, empty_macaddr)) {
314 device_printf(dev, "mac read failed %d\n", error);
316 device_printf(dev, "mac read failed (all zeros)\n");
323 /* Read NIC identification */
326 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
327 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
328 ifp->if_ioctl = wi_ioctl;
329 ifp->if_start = wi_start;
330 ifp->if_init = wi_init;
331 IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
332 ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN;
333 IFQ_SET_READY(&ifp->if_snd);
336 ic->ic_phytype = IEEE80211_T_DS;
337 ic->ic_opmode = IEEE80211_M_STA;
338 ic->ic_state = IEEE80211_S_INIT;
339 ic->ic_caps = IEEE80211_C_PMGT
340 | IEEE80211_C_WEP /* everyone supports WEP */
342 ic->ic_max_aid = WI_MAX_AID;
345 * Query the card for available channels and setup the
346 * channel table. We assume these are all 11b channels.
348 buflen = sizeof(val);
349 if (wi_read_rid(sc, WI_RID_CHANNEL_LIST, &val, &buflen) != 0)
350 val = htole16(0x1fff); /* assume 1-11 */
351 KASSERT(val != 0, ("wi_attach: no available channels listed!"));
353 val <<= 1; /* shift for base 1 indices */
354 for (i = 1; i < 16; i++) {
355 struct ieee80211_channel *c;
357 if (!isset((u_int8_t*)&val, i))
359 c = &ic->ic_channels[ic->ic_nchans++];
360 c->ic_freq = ieee80211_ieee2mhz(i, IEEE80211_CHAN_B);
361 c->ic_flags = IEEE80211_CHAN_B;
366 * Read the default channel from the NIC. This may vary
367 * depending on the country where the NIC was purchased, so
368 * we can't hard-code a default and expect it to work for
371 * If no channel is specified, let the 802.11 code select.
373 buflen = sizeof(val);
374 if (wi_read_rid(sc, WI_RID_OWN_CHNL, &val, &buflen) == 0) {
376 ic->ic_bsschan = ieee80211_find_channel(ic,
377 ieee80211_ieee2mhz(val, IEEE80211_CHAN_B),
379 if (ic->ic_bsschan == NULL)
380 ic->ic_bsschan = &ic->ic_channels[0];
383 "WI_RID_OWN_CHNL failed, using first channel!\n");
384 ic->ic_bsschan = &ic->ic_channels[0];
388 * Set flags based on firmware version.
390 switch (sc->sc_firmware_type) {
393 sc->sc_flags |= WI_FLAGS_HAS_SYSSCALE;
394 #ifdef WI_HERMES_AUTOINC_WAR
395 /* XXX: not confirmed, but never seen for recent firmware */
396 if (sc->sc_sta_firmware_ver < 40000) {
397 sc->sc_flags |= WI_FLAGS_BUG_AUTOINC;
400 if (sc->sc_sta_firmware_ver >= 60000)
401 sc->sc_flags |= WI_FLAGS_HAS_MOR;
402 if (sc->sc_sta_firmware_ver >= 60006) {
403 ic->ic_caps |= IEEE80211_C_IBSS;
404 ic->ic_caps |= IEEE80211_C_MONITOR;
406 sc->sc_ibss_port = htole16(1);
408 sc->sc_min_rssi = WI_LUCENT_MIN_RSSI;
409 sc->sc_max_rssi = WI_LUCENT_MAX_RSSI;
410 sc->sc_dbm_offset = WI_LUCENT_DBM_OFFSET;
414 sc->sc_ntxbuf = WI_NTXBUF;
415 sc->sc_flags |= WI_FLAGS_HAS_FRAGTHR;
416 sc->sc_flags |= WI_FLAGS_HAS_ROAMING;
417 sc->sc_flags |= WI_FLAGS_HAS_SYSSCALE;
419 * Old firmware are slow, so give peace a chance.
421 if (sc->sc_sta_firmware_ver < 10000)
422 sc->wi_cmd_count = 5000;
423 if (sc->sc_sta_firmware_ver > 10101)
424 sc->sc_flags |= WI_FLAGS_HAS_DBMADJUST;
425 if (sc->sc_sta_firmware_ver >= 800) {
426 ic->ic_caps |= IEEE80211_C_IBSS;
427 ic->ic_caps |= IEEE80211_C_MONITOR;
430 * version 0.8.3 and newer are the only ones that are known
431 * to currently work. Earlier versions can be made to work,
432 * at least according to the Linux driver.
434 if (sc->sc_sta_firmware_ver >= 803)
435 ic->ic_caps |= IEEE80211_C_HOSTAP;
436 sc->sc_ibss_port = htole16(0);
438 sc->sc_min_rssi = WI_PRISM_MIN_RSSI;
439 sc->sc_max_rssi = WI_PRISM_MAX_RSSI;
440 sc->sc_dbm_offset = WI_PRISM_DBM_OFFSET;
445 sc->sc_flags |= WI_FLAGS_HAS_DIVERSITY;
446 if (sc->sc_sta_firmware_ver >= 25000)
447 ic->ic_caps |= IEEE80211_C_IBSS;
448 sc->sc_ibss_port = htole16(4);
450 sc->sc_min_rssi = WI_PRISM_MIN_RSSI;
451 sc->sc_max_rssi = WI_PRISM_MAX_RSSI;
452 sc->sc_dbm_offset = WI_PRISM_DBM_OFFSET;
457 * Find out if we support WEP on this card.
459 buflen = sizeof(val);
460 if (wi_read_rid(sc, WI_RID_WEP_AVAIL, &val, &buflen) == 0 &&
462 ic->ic_caps |= IEEE80211_C_WEP;
464 /* Find supported rates. */
465 buflen = sizeof(ratebuf);
466 rs = &ic->ic_sup_rates[IEEE80211_MODE_11B];
467 if (wi_read_rid(sc, WI_RID_DATA_RATES, ratebuf, &buflen) == 0) {
468 nrates = le16toh(*(u_int16_t *)ratebuf);
469 if (nrates > IEEE80211_RATE_MAXSIZE)
470 nrates = IEEE80211_RATE_MAXSIZE;
472 for (i = 0; i < nrates; i++)
474 rs->rs_rates[rs->rs_nrates++] = ratebuf[2+i];
476 /* XXX fallback on error? */
479 buflen = sizeof(val);
480 if ((sc->sc_flags & WI_FLAGS_HAS_DBMADJUST) &&
481 wi_read_rid(sc, WI_RID_DBM_ADJUST, &val, &buflen) == 0) {
482 sc->sc_dbm_offset = le16toh(val);
485 sc->sc_max_datalen = 2304;
486 sc->sc_system_scale = 1;
487 sc->sc_cnfauthmode = IEEE80211_AUTH_OPEN;
488 sc->sc_roaming_mode = 1;
489 sc->wi_channel = IEEE80211_CHAN_ANYC;
490 sc->sc_portnum = WI_DEFAULT_PORT;
491 sc->sc_authtype = WI_DEFAULT_AUTHTYPE;
493 bzero(sc->sc_nodename, sizeof(sc->sc_nodename));
494 sc->sc_nodelen = sizeof(WI_DEFAULT_NODENAME) - 1;
495 bcopy(WI_DEFAULT_NODENAME, sc->sc_nodename, sc->sc_nodelen);
497 bzero(sc->sc_net_name, sizeof(sc->sc_net_name));
498 bcopy(WI_DEFAULT_NETNAME, sc->sc_net_name,
499 sizeof(WI_DEFAULT_NETNAME) - 1);
502 * Call MI attach routine.
504 ieee80211_ifattach(ic);
505 /* override state transition method */
506 sc->sc_newstate = ic->ic_newstate;
507 sc->sc_key_alloc = ic->ic_crypto.cs_key_alloc;
508 ic->ic_crypto.cs_key_alloc = wi_key_alloc;
509 ic->ic_newstate = wi_newstate;
510 ic->ic_raw_xmit = wi_raw_xmit;
512 ic->ic_scan_start = wi_scan_start;
513 ic->ic_scan_curchan = wi_scan_curchan;
514 ic->ic_scan_mindwell = wi_scan_mindwell;
515 ic->ic_scan_end = wi_scan_end;
516 ic->ic_set_channel = wi_set_channel;
517 ic->ic_node_alloc = wi_node_alloc;
518 ic->ic_updateslot = wi_update_slot;
519 ic->ic_reset = wi_reset;
521 ieee80211_media_init(ic, wi_media_change, wi_media_status);
524 bpfattach2(ifp, DLT_IEEE802_11_RADIO,
525 sizeof(struct ieee80211_frame) + sizeof(sc->sc_tx_th),
528 * Initialize constant fields.
529 * XXX make header lengths a multiple of 32-bits so subsequent
530 * headers are properly aligned; this is a kludge to keep
531 * certain applications happy.
533 * NB: the channel is setup each time we transition to the
534 * RUN state to avoid filling it in for each frame.
536 sc->sc_tx_th_len = roundup(sizeof(sc->sc_tx_th), sizeof(u_int32_t));
537 sc->sc_tx_th.wt_ihdr.it_len = htole16(sc->sc_tx_th_len);
538 sc->sc_tx_th.wt_ihdr.it_present = htole32(WI_TX_RADIOTAP_PRESENT);
540 sc->sc_rx_th_len = roundup(sizeof(sc->sc_rx_th), sizeof(u_int32_t));
541 sc->sc_rx_th.wr_ihdr.it_len = htole16(sc->sc_rx_th_len);
542 sc->sc_rx_th.wr_ihdr.it_present = htole32(WI_RX_RADIOTAP_PRESENT);
546 ieee80211_announce(ic);
552 wi_detach(device_t dev)
554 struct wi_softc *sc = device_get_softc(dev);
555 struct ifnet *ifp = sc->sc_ifp;
559 /* check if device was removed */
560 sc->wi_gone |= !bus_child_present(dev);
568 ieee80211_ifdetach(&sc->sc_ic);
569 bus_teardown_intr(dev, sc->irq, sc->wi_intrhand);
572 mtx_destroy(&sc->sc_mtx);
578 wi_activate(struct device *self, enum devact act)
580 struct wi_softc *sc = (struct wi_softc *)self;
589 case DVACT_DEACTIVATE:
590 if_deactivate(sc->sc_ifp);
598 wi_power(struct wi_softc *sc, int why)
600 struct ifnet *ifp = sc->sc_ifp;
610 if (ifp->if_flags & IFF_UP) {
615 case PWR_SOFTSUSPEND:
616 case PWR_SOFTSTANDBY:
622 #endif /* __NetBSD__ */
625 wi_shutdown(device_t dev)
627 struct wi_softc *sc = device_get_softc(dev);
629 wi_stop(sc->sc_ifp, 1);
635 struct wi_softc *sc = arg;
636 struct ifnet *ifp = sc->sc_ifp;
641 if (sc->wi_gone || !sc->sc_enabled || (ifp->if_flags & IFF_UP) == 0) {
642 CSR_WRITE_2(sc, WI_INT_EN, 0);
643 CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
648 /* Disable interrupts. */
649 CSR_WRITE_2(sc, WI_INT_EN, 0);
651 status = CSR_READ_2(sc, WI_EVENT_STAT);
652 if (status & WI_EV_RX)
654 if (status & WI_EV_ALLOC)
656 if (status & WI_EV_TX_EXC)
658 if (status & WI_EV_INFO)
660 if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0 &&
661 (sc->sc_flags & WI_FLAGS_OUTRANGE) == 0 &&
662 !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
663 wi_start_locked(ifp);
665 /* Re-enable interrupts. */
666 CSR_WRITE_2(sc, WI_INT_EN, WI_INTRS);
676 struct wi_softc *sc = arg;
677 struct ifnet *ifp = sc->sc_ifp;
678 struct ieee80211com *ic = &sc->sc_ic;
679 struct wi_joinreq join;
680 struct ieee80211_channel *chan;
682 int error = 0, wasenabled;
689 if ((wasenabled = sc->sc_enabled))
695 /* common 802.11 configuration */
696 ic->ic_flags &= ~IEEE80211_F_IBSSON;
697 sc->sc_flags &= ~WI_FLAGS_OUTRANGE;
698 switch (ic->ic_opmode) {
699 case IEEE80211_M_STA:
700 wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_BSS);
702 case IEEE80211_M_IBSS:
703 wi_write_val(sc, WI_RID_PORTTYPE, sc->sc_ibss_port);
704 ic->ic_flags |= IEEE80211_F_IBSSON;
706 case IEEE80211_M_AHDEMO:
707 wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_ADHOC);
709 case IEEE80211_M_HOSTAP:
711 * For PRISM cards, override the empty SSID, because in
712 * HostAP mode the controller will lock up otherwise.
714 if (sc->sc_firmware_type == WI_INTERSIL &&
715 ic->ic_des_ssid[0].len == 0) {
716 ic->ic_des_ssid[0].ssid[0] = ' ';
717 ic->ic_des_ssid[0].len = 1;
719 wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_HOSTAP);
721 case IEEE80211_M_MONITOR:
722 switch (sc->sc_firmware_type) {
724 wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_ADHOC);
728 wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_APSILENT);
732 wi_cmd(sc, WI_CMD_DEBUG | (WI_TEST_MONITOR << 8), 0, 0, 0);
734 case IEEE80211_M_WDS:
739 /* Intersil interprets this RID as joining ESS even in IBSS mode */
740 if (sc->sc_firmware_type == WI_LUCENT &&
741 (ic->ic_flags & IEEE80211_F_IBSSON) && ic->ic_des_ssid[0].len > 0)
742 wi_write_val(sc, WI_RID_CREATE_IBSS, 1);
744 wi_write_val(sc, WI_RID_CREATE_IBSS, 0);
745 wi_write_val(sc, WI_RID_MAX_SLEEP, ic->ic_lintval);
746 wi_write_ssid(sc, WI_RID_DESIRED_SSID, ic->ic_des_ssid[0].ssid,
747 ic->ic_des_ssid[0].len);
748 wi_write_val(sc, WI_RID_OWN_CHNL,
749 ieee80211_chan2ieee(ic, ic->ic_bsschan));
750 wi_write_ssid(sc, WI_RID_OWN_SSID, ic->ic_des_ssid[0].ssid,
751 ic->ic_des_ssid[0].len);
753 IEEE80211_ADDR_COPY(ic->ic_myaddr, IF_LLADDR(ifp));
754 wi_write_rid(sc, WI_RID_MAC_NODE, ic->ic_myaddr, IEEE80211_ADDR_LEN);
756 if (ic->ic_caps & IEEE80211_C_PMGT)
757 wi_write_val(sc, WI_RID_PM_ENABLED,
758 (ic->ic_flags & IEEE80211_F_PMGTON) ? 1 : 0);
760 /* not yet common 802.11 configuration */
761 wi_write_val(sc, WI_RID_MAX_DATALEN, sc->sc_max_datalen);
762 wi_write_val(sc, WI_RID_RTS_THRESH, ic->ic_rtsthreshold);
763 if (sc->sc_flags & WI_FLAGS_HAS_FRAGTHR)
764 wi_write_val(sc, WI_RID_FRAG_THRESH, ic->ic_fragthreshold);
766 /* driver specific 802.11 configuration */
767 if (sc->sc_flags & WI_FLAGS_HAS_SYSSCALE)
768 wi_write_val(sc, WI_RID_SYSTEM_SCALE, sc->sc_system_scale);
769 if (sc->sc_flags & WI_FLAGS_HAS_ROAMING)
770 wi_write_val(sc, WI_RID_ROAMING_MODE, sc->sc_roaming_mode);
771 if (sc->sc_flags & WI_FLAGS_HAS_MOR)
772 wi_write_val(sc, WI_RID_MICROWAVE_OVEN, sc->sc_microwave_oven);
774 wi_write_ssid(sc, WI_RID_NODENAME, sc->sc_nodename, sc->sc_nodelen);
775 wi_write_val(sc, WI_RID_ALT_RETRY_CNT, 0); /* for IEEE80211_BPF_NOACK */
777 if (ic->ic_opmode == IEEE80211_M_HOSTAP &&
778 sc->sc_firmware_type == WI_INTERSIL) {
779 wi_write_val(sc, WI_RID_OWN_BEACON_INT, ic->ic_bintval);
780 wi_write_val(sc, WI_RID_BASIC_RATE, 0x03); /* 1, 2 */
781 wi_write_val(sc, WI_RID_SUPPORT_RATE, 0x0f); /* 1, 2, 5.5, 11 */
782 wi_write_val(sc, WI_RID_DTIM_PERIOD, ic->ic_dtim_period);
786 * Initialize promisc mode.
787 * Being in the Host-AP mode causes a great
788 * deal of pain if primisc mode is set.
789 * Therefore we avoid confusing the firmware
790 * and always reset promisc mode in Host-AP
791 * mode. Host-AP sees all the packets anyway.
793 if (ic->ic_opmode != IEEE80211_M_HOSTAP &&
794 (ifp->if_flags & IFF_PROMISC) != 0) {
795 wi_write_val(sc, WI_RID_PROMISC, 1);
797 wi_write_val(sc, WI_RID_PROMISC, 0);
801 if (ic->ic_caps & IEEE80211_C_WEP) {
802 sc->sc_cnfauthmode = ic->ic_bss->ni_authmode;
805 sc->sc_encryption = 0;
807 /* Set multicast filter. */
810 /* Allocate fids for the card */
811 if (sc->sc_firmware_type != WI_SYMBOL || !wasenabled) {
812 sc->sc_buflen = IEEE80211_MAX_LEN + sizeof(struct wi_frame);
813 if (sc->sc_firmware_type == WI_SYMBOL)
814 sc->sc_buflen = 1585; /* XXX */
815 for (i = 0; i < sc->sc_ntxbuf; i++) {
816 error = wi_alloc_fid(sc, sc->sc_buflen,
817 &sc->sc_txd[i].d_fid);
819 device_printf(sc->sc_dev,
820 "tx buffer allocation failed (error %u)\n",
824 sc->sc_txd[i].d_len = 0;
827 sc->sc_txcur = sc->sc_txnext = 0;
829 /* Enable desired port */
830 wi_cmd(sc, WI_CMD_ENABLE | sc->sc_portnum, 0, 0, 0);
833 ifp->if_drv_flags |= IFF_DRV_RUNNING;
834 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
835 if (ic->ic_opmode == IEEE80211_M_AHDEMO ||
836 ic->ic_opmode == IEEE80211_M_IBSS ||
837 ic->ic_opmode == IEEE80211_M_MONITOR ||
838 ic->ic_opmode == IEEE80211_M_HOSTAP) {
839 chan = (sc->wi_channel == IEEE80211_CHAN_ANYC) ?
840 ic->ic_curchan : sc->wi_channel;
841 ieee80211_create_ibss(ic, chan);
843 /* Enable interrupts */
844 CSR_WRITE_2(sc, WI_INT_EN, WI_INTRS);
847 ic->ic_opmode == IEEE80211_M_HOSTAP &&
848 sc->sc_firmware_type == WI_INTERSIL) {
849 /* XXX: some card need to be re-enabled for hostap */
850 wi_cmd(sc, WI_CMD_DISABLE | WI_PORT0, 0, 0, 0);
851 wi_cmd(sc, WI_CMD_ENABLE | WI_PORT0, 0, 0, 0);
854 if (ic->ic_opmode == IEEE80211_M_STA &&
855 ((ic->ic_flags & IEEE80211_F_DESBSSID) ||
856 ic->ic_des_chan != IEEE80211_CHAN_ANYC)) {
857 memset(&join, 0, sizeof(join));
858 if (ic->ic_flags & IEEE80211_F_DESBSSID)
859 IEEE80211_ADDR_COPY(&join.wi_bssid, ic->ic_des_bssid);
860 if (ic->ic_des_chan != IEEE80211_CHAN_ANYC)
861 join.wi_chan = htole16(
862 ieee80211_chan2ieee(ic, ic->ic_des_chan));
863 /* Lucent firmware does not support the JOIN RID. */
864 if (sc->sc_firmware_type != WI_LUCENT)
865 wi_write_rid(sc, WI_RID_JOIN_REQ, &join, sizeof(join));
868 callout_reset(&sc->sc_watchdog, hz, wi_watchdog, sc);
874 if_printf(ifp, "interface not running\n");
878 DPRINTF(("wi_init: return %d\n", error));
883 wi_stop(struct ifnet *ifp, int disable)
885 struct wi_softc *sc = ifp->if_softc;
886 struct ieee80211com *ic = &sc->sc_ic;
888 ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
892 if (sc->sc_enabled && !sc->wi_gone) {
893 CSR_WRITE_2(sc, WI_INT_EN, 0);
894 wi_cmd(sc, WI_CMD_DISABLE | sc->sc_portnum, 0, 0, 0);
898 (*sc->sc_disable)(sc);
902 } else if (sc->wi_gone && disable) /* gone --> not enabled */
905 callout_stop(&sc->sc_watchdog); /* XXX drain */
907 sc->sc_scan_timer = 0;
908 sc->sc_false_syns = 0;
910 ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE | IFF_DRV_RUNNING);
916 wi_start_locked(struct ifnet *ifp)
918 struct wi_softc *sc = ifp->if_softc;
919 struct ieee80211com *ic = &sc->sc_ic;
920 struct ieee80211_node *ni;
921 struct ieee80211_frame *wh;
922 struct ether_header *eh;
924 struct wi_frame frmhdr;
931 if (sc->sc_flags & WI_FLAGS_OUTRANGE)
934 memset(&frmhdr, 0, sizeof(frmhdr));
937 IF_POLL(&ic->ic_mgtq, m0);
939 if (sc->sc_txd[cur].d_len != 0) {
940 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
943 IF_DEQUEUE(&ic->ic_mgtq, m0);
945 * Hack! The referenced node pointer is in the
946 * rcvif field of the packet header. This is
947 * placed there by ieee80211_mgmt_output because
948 * we need to hold the reference with the frame
949 * and there's no other way (other than packet
950 * tags which we consider too expensive to use)
953 ni = (struct ieee80211_node *) m0->m_pkthdr.rcvif;
954 m0->m_pkthdr.rcvif = NULL;
956 m_copydata(m0, 4, ETHER_ADDR_LEN * 2,
957 (caddr_t)&frmhdr.wi_ehdr);
958 frmhdr.wi_ehdr.ether_type = 0;
959 wh = mtod(m0, struct ieee80211_frame *);
961 if (ic->ic_state != IEEE80211_S_RUN)
963 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
966 if (sc->sc_txd[cur].d_len != 0) {
967 IFQ_DRV_PREPEND(&ifp->if_snd, m0);
968 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
971 if (m0->m_len < sizeof(struct ether_header) &&
972 (m0 = m_pullup(m0, sizeof(struct ether_header))) == NULL) {
976 eh = mtod(m0, struct ether_header *);
977 ni = ieee80211_find_txnode(ic, eh->ether_dhost);
983 m_copydata(m0, 0, ETHER_HDR_LEN,
984 (caddr_t)&frmhdr.wi_ehdr);
989 m0 = ieee80211_encap(ic, m0, ni);
992 ieee80211_free_node(ni);
995 wh = mtod(m0, struct ieee80211_frame *);
998 if (bpf_peers_present(ic->ic_rawbpf))
999 bpf_mtap(ic->ic_rawbpf, m0);
1001 frmhdr.wi_tx_ctl = htole16(WI_ENC_TX_802_11|WI_TXCNTL_TX_EX);
1002 /* XXX check key for SWCRYPT instead of using operating mode */
1003 if ((wh->i_fc[1] & IEEE80211_FC1_WEP) &&
1004 (sc->sc_encryption & HOST_ENCRYPT)) {
1005 struct ieee80211_key *k;
1007 k = ieee80211_crypto_encap(ic, ni, m0);
1009 ieee80211_free_node(ni);
1013 frmhdr.wi_tx_ctl |= htole16(WI_TXCNTL_NOCRYPT);
1016 if (bpf_peers_present(sc->sc_drvbpf)) {
1017 sc->sc_tx_th.wt_rate =
1018 ni->ni_rates.rs_rates[ni->ni_txrate];
1019 bpf_mtap2(sc->sc_drvbpf,
1020 &sc->sc_tx_th, sc->sc_tx_th_len, m0);
1023 m_copydata(m0, 0, sizeof(struct ieee80211_frame),
1024 (caddr_t)&frmhdr.wi_whdr);
1025 m_adj(m0, sizeof(struct ieee80211_frame));
1026 frmhdr.wi_dat_len = htole16(m0->m_pkthdr.len);
1027 if (IFF_DUMPPKTS(ifp))
1028 wi_dump_pkt(&frmhdr, NULL, -1);
1029 ieee80211_free_node(ni);
1030 if (wi_start_tx(ifp, &frmhdr, m0))
1032 sc->sc_txnext = cur = (cur + 1) % sc->sc_ntxbuf;
1037 wi_start(struct ifnet *ifp)
1039 struct wi_softc *sc = ifp->if_softc;
1042 wi_start_locked(ifp);
1047 wi_start_tx(struct ifnet *ifp, struct wi_frame *frmhdr, struct mbuf *m0)
1049 struct wi_softc *sc = ifp->if_softc;
1050 int cur = sc->sc_txnext;
1051 int fid, off, error;
1053 fid = sc->sc_txd[cur].d_fid;
1054 off = sizeof(*frmhdr);
1055 error = wi_write_bap(sc, fid, 0, frmhdr, sizeof(*frmhdr)) != 0
1056 || wi_mwrite_bap(sc, fid, off, m0, m0->m_pkthdr.len) != 0;
1062 sc->sc_txd[cur].d_len = off;
1063 if (sc->sc_txcur == cur) {
1064 if (wi_cmd(sc, WI_CMD_TX | WI_RECLAIM, fid, 0, 0)) {
1065 if_printf(ifp, "xmit failed\n");
1066 sc->sc_txd[cur].d_len = 0;
1069 sc->sc_tx_timer = 5;
1075 wi_raw_xmit(struct ieee80211_node *ni, struct mbuf *m0,
1076 const struct ieee80211_bpf_params *params)
1078 struct ieee80211com *ic = ni->ni_ic;
1079 struct ifnet *ifp = ic->ic_ifp;
1080 struct wi_softc *sc = ifp->if_softc;
1081 struct ieee80211_frame *wh;
1082 struct wi_frame frmhdr;
1092 if (sc->sc_flags & WI_FLAGS_OUTRANGE) {
1097 memset(&frmhdr, 0, sizeof(frmhdr));
1098 cur = sc->sc_txnext;
1099 if (sc->sc_txd[cur].d_len != 0) {
1100 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
1104 m0->m_pkthdr.rcvif = NULL;
1106 m_copydata(m0, 4, ETHER_ADDR_LEN * 2,
1107 (caddr_t)&frmhdr.wi_ehdr);
1108 frmhdr.wi_ehdr.ether_type = 0;
1109 wh = mtod(m0, struct ieee80211_frame *);
1112 if (bpf_peers_present(ic->ic_rawbpf))
1113 bpf_mtap(ic->ic_rawbpf, m0);
1115 frmhdr.wi_tx_ctl = htole16(WI_ENC_TX_802_11|WI_TXCNTL_TX_EX);
1116 if (params && (params->ibp_flags & IEEE80211_BPF_NOACK))
1117 frmhdr.wi_tx_ctl |= htole16(WI_TXCNTL_ALTRTRY);
1118 /* XXX check key for SWCRYPT instead of using operating mode */
1119 if ((wh->i_fc[1] & IEEE80211_FC1_WEP) &&
1120 (sc->sc_encryption & HOST_ENCRYPT)) {
1122 (params && (params->ibp_flags & IEEE80211_BPF_CRYPTO))) {
1123 struct ieee80211_key *k;
1125 k = ieee80211_crypto_encap(ic, ni, m0);
1130 frmhdr.wi_tx_ctl |= htole16(WI_TXCNTL_NOCRYPT);
1134 if (bpf_peers_present(sc->sc_drvbpf)) {
1135 sc->sc_tx_th.wt_rate =
1136 ni->ni_rates.rs_rates[ni->ni_txrate];
1137 bpf_mtap2(sc->sc_drvbpf,
1138 &sc->sc_tx_th, sc->sc_tx_th_len, m0);
1141 m_copydata(m0, 0, sizeof(struct ieee80211_frame),
1142 (caddr_t)&frmhdr.wi_whdr);
1143 m_adj(m0, sizeof(struct ieee80211_frame));
1144 frmhdr.wi_dat_len = htole16(m0->m_pkthdr.len);
1145 if (IFF_DUMPPKTS(ifp))
1146 wi_dump_pkt(&frmhdr, NULL, -1);
1147 if (wi_start_tx(ifp, &frmhdr, m0) < 0) {
1154 sc->sc_txnext = cur = (cur + 1) % sc->sc_ntxbuf;
1160 ieee80211_free_node(ni);
1165 wi_reset(struct ifnet *ifp)
1167 struct wi_softc *sc = ifp->if_softc;
1168 #define WI_INIT_TRIES 3
1173 /* Symbol firmware cannot be initialized more than once */
1174 if (sc->sc_firmware_type == WI_SYMBOL && sc->sc_reset)
1176 if (sc->sc_firmware_type == WI_SYMBOL)
1179 tries = WI_INIT_TRIES;
1181 for (i = 0; i < tries; i++) {
1182 if ((error = wi_cmd(sc, WI_CMD_INI, 0, 0, 0)) == 0)
1184 DELAY(WI_DELAY * 1000);
1189 if_printf(ifp, "init failed\n");
1193 CSR_WRITE_2(sc, WI_INT_EN, 0);
1194 CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);
1196 /* Calibrate timer. */
1197 wi_write_val(sc, WI_RID_TICK_TIME, 8);
1200 #undef WI_INIT_TRIES
1204 wi_watchdog(void *arg)
1206 struct wi_softc *sc = arg;
1207 struct ifnet *ifp = sc->sc_ifp;
1209 if (!sc->sc_enabled)
1212 if (sc->sc_tx_timer) {
1213 if (--sc->sc_tx_timer == 0) {
1214 if_printf(ifp, "device timeout\n");
1216 wi_init(ifp->if_softc);
1221 if (sc->sc_scan_timer) {
1222 if (--sc->sc_scan_timer <= WI_SCAN_WAIT - WI_SCAN_INQWAIT &&
1223 sc->sc_firmware_type == WI_INTERSIL) {
1224 DPRINTF(("wi_watchdog: inquire scan\n"));
1225 wi_cmd(sc, WI_CMD_INQUIRE, WI_INFO_SCAN_RESULTS, 0, 0);
1229 /* TODO: rate control */
1231 callout_reset(&sc->sc_watchdog, hz, wi_watchdog, sc);
1235 wi_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
1237 struct wi_softc *sc = ifp->if_softc;
1238 struct ieee80211com *ic = &sc->sc_ic;
1240 struct thread *td = curthread;
1242 struct ifreq *ifr = (struct ifreq *)data;
1252 * Can't do promisc and hostap at the same time. If all that's
1253 * changing is the promisc flag, try to short-circuit a call to
1254 * wi_init() by just setting PROMISC in the hardware.
1257 if (ifp->if_flags & IFF_UP) {
1258 if (ic->ic_opmode != IEEE80211_M_HOSTAP &&
1259 ifp->if_drv_flags & IFF_DRV_RUNNING) {
1260 if (ifp->if_flags & IFF_PROMISC &&
1261 !(sc->sc_if_flags & IFF_PROMISC)) {
1262 wi_write_val(sc, WI_RID_PROMISC, 1);
1263 } else if (!(ifp->if_flags & IFF_PROMISC) &&
1264 sc->sc_if_flags & IFF_PROMISC) {
1265 wi_write_val(sc, WI_RID_PROMISC, 0);
1273 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1278 sc->sc_if_flags = ifp->if_flags;
1285 error = wi_write_multi(sc);
1289 case SIOCGIFGENERIC:
1291 error = wi_get_cfg(ifp, cmd, data);
1294 case SIOCSIFGENERIC:
1295 error = priv_check(td, PRIV_DRIVER);
1297 error = wi_set_cfg(ifp, cmd, data);
1299 case SIOCGPRISM2DEBUG:
1300 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
1303 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING) ||
1304 sc->sc_firmware_type == WI_LUCENT) {
1308 error = wi_get_debug(sc, &wreq);
1310 error = copyout(&wreq, ifr->ifr_data, sizeof(wreq));
1312 case SIOCSPRISM2DEBUG:
1313 if ((error = priv_check(td, PRIV_DRIVER)))
1315 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
1319 error = wi_set_debug(sc, &wreq);
1324 error = wi_ioctl_get(ifp, cmd, data);
1327 error = priv_check(td, PRIV_NET80211_MANAGE);
1330 error = wi_ioctl_set(ifp, cmd, data);
1335 error = ieee80211_ioctl(ic, cmd, data);
1337 if (error == ENETRESET) {
1339 wi_init(sc); /* XXX no error return */
1349 wi_ioctl_get(struct ifnet *ifp, u_long cmd, caddr_t data)
1352 struct wi_softc *sc;
1353 struct ieee80211req *ireq;
1354 struct ieee80211com *ic;
1359 ireq = (struct ieee80211req *) data;
1361 switch (ireq->i_type) {
1362 case IEEE80211_IOC_STATIONNAME:
1363 ireq->i_len = sc->sc_nodelen + 1;
1364 error = copyout(sc->sc_nodename, ireq->i_data,
1368 error = ieee80211_ioctl(ic, cmd, data);
1370 if (error == ENETRESET) {
1372 wi_init(sc); /* XXX no error return */
1384 wi_ioctl_set(struct ifnet *ifp, u_long cmd, caddr_t data)
1387 struct wi_softc *sc;
1388 struct ieee80211req *ireq;
1389 u_int8_t nodename[IEEE80211_NWID_LEN];
1392 ireq = (struct ieee80211req *) data;
1393 switch (ireq->i_type) {
1394 case IEEE80211_IOC_STATIONNAME:
1395 if (ireq->i_val != 0 ||
1396 ireq->i_len > IEEE80211_NWID_LEN) {
1400 memset(nodename, 0, IEEE80211_NWID_LEN);
1401 error = copyin(ireq->i_data, nodename, ireq->i_len);
1405 if (sc->sc_enabled) {
1406 error = wi_write_ssid(sc, WI_RID_NODENAME,
1407 nodename, ireq->i_len);
1410 memcpy(sc->sc_nodename, nodename,
1411 IEEE80211_NWID_LEN);
1412 sc->sc_nodelen = ireq->i_len;
1418 error = ieee80211_ioctl(&sc->sc_ic, cmd, data);
1420 if (error == ENETRESET) {
1422 wi_init(sc); /* XXX no error return */
1432 static struct ieee80211_node *
1433 wi_node_alloc(struct ieee80211_node_table *nt)
1437 rn = malloc(sizeof (struct wi_node), M_80211_NODE,
1440 return (rn != NULL) ? &rn->ni : NULL;
1444 wi_media_change(struct ifnet *ifp)
1446 struct wi_softc *sc = ifp->if_softc;
1449 error = ieee80211_media_change(ifp);
1450 if (error == ENETRESET) {
1452 wi_init(sc); /* XXX no error return */
1459 wi_media_status(struct ifnet *ifp, struct ifmediareq *imr)
1461 struct wi_softc *sc = ifp->if_softc;
1462 struct ieee80211com *ic = &sc->sc_ic;
1466 if (sc->wi_gone) { /* hardware gone (e.g. ejected) */
1467 imr->ifm_active = IFM_IEEE80211 | IFM_NONE;
1468 imr->ifm_status = 0;
1472 imr->ifm_status = IFM_AVALID;
1473 imr->ifm_active = IFM_IEEE80211;
1474 if (!sc->sc_enabled) { /* port !enabled, have no status */
1475 imr->ifm_active |= IFM_NONE;
1476 imr->ifm_status = IFM_AVALID;
1479 if (ic->ic_state == IEEE80211_S_RUN &&
1480 (sc->sc_flags & WI_FLAGS_OUTRANGE) == 0)
1481 imr->ifm_status |= IFM_ACTIVE;
1483 if (wi_read_rid(sc, WI_RID_CUR_TX_RATE, &val, &len) == 0 &&
1484 len == sizeof(val)) {
1485 /* convert to 802.11 rate */
1488 if (sc->sc_firmware_type == WI_LUCENT) {
1490 rate = 11; /* 5.5Mbps */
1493 rate = 11; /* 5.5Mbps */
1494 else if (rate == 8*2)
1495 rate = 22; /* 11Mbps */
1499 imr->ifm_active |= ieee80211_rate2media(ic, rate, IEEE80211_MODE_11B);
1500 switch (ic->ic_opmode) {
1501 case IEEE80211_M_STA:
1503 case IEEE80211_M_IBSS:
1504 imr->ifm_active |= IFM_IEEE80211_ADHOC;
1506 case IEEE80211_M_AHDEMO:
1507 imr->ifm_active |= IFM_IEEE80211_ADHOC | IFM_FLAG0;
1509 case IEEE80211_M_HOSTAP:
1510 imr->ifm_active |= IFM_IEEE80211_HOSTAP;
1512 case IEEE80211_M_MONITOR:
1513 imr->ifm_active |= IFM_IEEE80211_MONITOR;
1515 case IEEE80211_M_WDS:
1522 wi_sync_bssid(struct wi_softc *sc, u_int8_t new_bssid[IEEE80211_ADDR_LEN])
1524 struct ieee80211com *ic = &sc->sc_ic;
1525 struct ieee80211_node *ni = ic->ic_bss;
1526 struct ifnet *ifp = sc->sc_ifp;
1528 if (IEEE80211_ADDR_EQ(new_bssid, ni->ni_bssid))
1531 DPRINTF(("wi_sync_bssid: bssid %s -> ", ether_sprintf(ni->ni_bssid)));
1532 DPRINTF(("%s ?\n", ether_sprintf(new_bssid)));
1534 /* In promiscuous mode, the BSSID field is not a reliable
1535 * indicator of the firmware's BSSID. Damp spurious
1536 * change-of-BSSID indications.
1538 if ((ifp->if_flags & IFF_PROMISC) != 0 &&
1539 !ppsratecheck(&sc->sc_last_syn, &sc->sc_false_syns,
1543 sc->sc_false_syns = MAX(0, sc->sc_false_syns - 1);
1546 * XXX hack; we should create a new node with the new bssid
1547 * and replace the existing ic_bss with it but since we don't
1548 * process management frames to collect state we cheat by
1549 * reusing the existing node as we know wi_newstate will be
1550 * called and it will overwrite the node state.
1552 ieee80211_sta_join(ic, ieee80211_ref_node(ni));
1557 wi_rx_monitor(struct wi_softc *sc, int fid)
1559 struct ifnet *ifp = sc->sc_ifp;
1560 struct wi_frame *rx_frame;
1564 /* first allocate mbuf for packet storage */
1565 m = m_getcl(M_DONTWAIT, MT_DATA, 0);
1571 m->m_pkthdr.rcvif = ifp;
1573 /* now read wi_frame first so we know how much data to read */
1574 if (wi_read_bap(sc, fid, 0, mtod(m, caddr_t), sizeof(*rx_frame))) {
1579 rx_frame = mtod(m, struct wi_frame *);
1581 switch ((rx_frame->wi_status & WI_STAT_MAC_PORT) >> 8) {
1583 switch (rx_frame->wi_whdr.i_fc[0] & IEEE80211_FC0_TYPE_MASK) {
1584 case IEEE80211_FC0_TYPE_DATA:
1585 hdrlen = WI_DATA_HDRLEN;
1586 datlen = rx_frame->wi_dat_len + WI_FCS_LEN;
1588 case IEEE80211_FC0_TYPE_MGT:
1589 hdrlen = WI_MGMT_HDRLEN;
1590 datlen = rx_frame->wi_dat_len + WI_FCS_LEN;
1592 case IEEE80211_FC0_TYPE_CTL:
1594 * prism2 cards don't pass control packets
1595 * down properly or consistently, so we'll only
1596 * pass down the header.
1598 hdrlen = WI_CTL_HDRLEN;
1602 if_printf(ifp, "received packet of unknown type "
1609 hdrlen = WI_DATA_HDRLEN;
1610 datlen = rx_frame->wi_dat_len + WI_FCS_LEN;
1613 if_printf(ifp, "received packet on invalid "
1614 "port (wi_status=0x%x)\n", rx_frame->wi_status);
1619 if (hdrlen + datlen + 2 > MCLBYTES) {
1620 if_printf(ifp, "oversized packet received "
1621 "(wi_dat_len=%d, wi_status=0x%x)\n",
1622 datlen, rx_frame->wi_status);
1627 if (wi_read_bap(sc, fid, hdrlen, mtod(m, caddr_t) + hdrlen,
1629 m->m_pkthdr.len = m->m_len = hdrlen + datlen;
1631 BPF_MTAP(ifp, m); /* Handle BPF listeners. */
1639 wi_rx_intr(struct wi_softc *sc)
1641 struct ieee80211com *ic = &sc->sc_ic;
1642 struct ifnet *ifp = sc->sc_ifp;
1643 struct wi_frame frmhdr;
1645 struct ieee80211_frame *wh;
1646 struct ieee80211_node *ni;
1647 int fid, len, off, rssi;
1652 fid = CSR_READ_2(sc, WI_RX_FID);
1654 if (sc->wi_debug.wi_monitor) {
1656 * If we are in monitor mode just
1657 * read the data from the device.
1659 wi_rx_monitor(sc, fid);
1660 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
1664 /* First read in the frame header */
1665 if (wi_read_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr))) {
1666 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
1668 DPRINTF(("wi_rx_intr: read fid %x failed\n", fid));
1672 if (IFF_DUMPPKTS(ifp))
1673 wi_dump_pkt(&frmhdr, NULL, frmhdr.wi_rx_signal);
1676 * Drop undecryptable or packets with receive errors here
1678 status = le16toh(frmhdr.wi_status);
1679 if (status & WI_STAT_ERRSTAT) {
1680 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
1682 DPRINTF(("wi_rx_intr: fid %x error status %x\n", fid, status));
1685 rssi = frmhdr.wi_rx_signal;
1686 rstamp = (le16toh(frmhdr.wi_rx_tstamp0) << 16) |
1687 le16toh(frmhdr.wi_rx_tstamp1);
1689 len = le16toh(frmhdr.wi_dat_len);
1690 off = ALIGN(sizeof(struct ieee80211_frame));
1693 * Sometimes the PRISM2.x returns bogusly large frames. Except
1694 * in monitor mode, just throw them away.
1696 if (off + len > MCLBYTES) {
1697 if (ic->ic_opmode != IEEE80211_M_MONITOR) {
1698 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
1700 DPRINTF(("wi_rx_intr: oversized packet\n"));
1706 MGETHDR(m, M_DONTWAIT, MT_DATA);
1708 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
1710 DPRINTF(("wi_rx_intr: MGET failed\n"));
1713 if (off + len > MHLEN) {
1714 MCLGET(m, M_DONTWAIT);
1715 if ((m->m_flags & M_EXT) == 0) {
1716 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
1719 DPRINTF(("wi_rx_intr: MCLGET failed\n"));
1724 m->m_data += off - sizeof(struct ieee80211_frame);
1725 memcpy(m->m_data, &frmhdr.wi_whdr, sizeof(struct ieee80211_frame));
1726 wi_read_bap(sc, fid, sizeof(frmhdr),
1727 m->m_data + sizeof(struct ieee80211_frame), len);
1728 m->m_pkthdr.len = m->m_len = sizeof(struct ieee80211_frame) + len;
1729 m->m_pkthdr.rcvif = ifp;
1731 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
1734 if (bpf_peers_present(sc->sc_drvbpf)) {
1735 /* XXX replace divide by table */
1736 sc->sc_rx_th.wr_rate = frmhdr.wi_rx_rate / 5;
1737 sc->sc_rx_th.wr_antsignal = frmhdr.wi_rx_signal;
1738 sc->sc_rx_th.wr_antnoise = frmhdr.wi_rx_silence;
1739 sc->sc_rx_th.wr_flags = 0;
1740 if (frmhdr.wi_status & WI_STAT_PCF)
1741 sc->sc_rx_th.wr_flags |= IEEE80211_RADIOTAP_F_CFP;
1742 /* XXX IEEE80211_RADIOTAP_F_WEP */
1743 bpf_mtap2(sc->sc_drvbpf,
1744 &sc->sc_rx_th, sc->sc_rx_th_len, m);
1747 wh = mtod(m, struct ieee80211_frame *);
1748 if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
1750 * WEP is decrypted by hardware and the IV
1751 * is stripped. Clear WEP bit so we don't
1752 * try to process it in ieee80211_input.
1753 * XXX fix for TKIP, et. al.
1755 wh->i_fc[1] &= ~IEEE80211_FC1_WEP;
1758 /* synchronize driver's BSSID with firmware's BSSID */
1759 dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
1760 if (ic->ic_opmode == IEEE80211_M_IBSS && dir == IEEE80211_FC1_DIR_NODS)
1761 wi_sync_bssid(sc, wh->i_addr3);
1765 * Locate the node for sender, track state, and
1766 * then pass this node (referenced) up to the 802.11
1767 * layer for its use.
1769 ni = ieee80211_find_rxnode(ic, (struct ieee80211_frame_min *) wh);
1771 * Send frame up for processing.
1773 ieee80211_input(ic, m, ni, rssi, -95/*XXXXwi_rx_silence?*/, rstamp);
1775 * The frame may have caused the node to be marked for
1776 * reclamation (e.g. in response to a DEAUTH message)
1777 * so use free_node here instead of unref_node.
1779 ieee80211_free_node(ni);
1785 wi_tx_ex_intr(struct wi_softc *sc)
1787 struct ifnet *ifp = sc->sc_ifp;
1788 struct wi_frame frmhdr;
1791 fid = CSR_READ_2(sc, WI_TX_CMP_FID);
1792 /* Read in the frame header */
1793 if (wi_read_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr)) == 0) {
1794 u_int16_t status = le16toh(frmhdr.wi_status);
1797 * Spontaneous station disconnects appear as xmit
1798 * errors. Don't announce them and/or count them
1799 * as an output error.
1801 if ((status & WI_TXSTAT_DISCONNECT) == 0) {
1802 if (ppsratecheck(&lasttxerror, &curtxeps, wi_txerate)) {
1803 if_printf(ifp, "tx failed");
1804 if (status & WI_TXSTAT_RET_ERR)
1805 printf(", retry limit exceeded");
1806 if (status & WI_TXSTAT_AGED_ERR)
1807 printf(", max transmit lifetime exceeded");
1808 if (status & WI_TXSTAT_DISCONNECT)
1809 printf(", port disconnected");
1810 if (status & WI_TXSTAT_FORM_ERR)
1811 printf(", invalid format (data len %u src %6D)",
1812 le16toh(frmhdr.wi_dat_len),
1813 frmhdr.wi_ehdr.ether_shost, ":");
1815 printf(", status=0x%x", status);
1820 DPRINTF(("port disconnected\n"));
1821 ifp->if_collisions++; /* XXX */
1824 DPRINTF(("wi_tx_ex_intr: read fid %x failed\n", fid));
1825 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_TX_EXC);
1829 wi_tx_intr(struct wi_softc *sc)
1831 struct ifnet *ifp = sc->sc_ifp;
1837 fid = CSR_READ_2(sc, WI_ALLOC_FID);
1838 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_ALLOC);
1841 if (sc->sc_txd[cur].d_fid != fid) {
1842 if_printf(ifp, "bad alloc %x != %x, cur %d nxt %d\n",
1843 fid, sc->sc_txd[cur].d_fid, cur, sc->sc_txnext);
1846 sc->sc_tx_timer = 0;
1847 sc->sc_txd[cur].d_len = 0;
1848 sc->sc_txcur = cur = (cur + 1) % sc->sc_ntxbuf;
1849 if (sc->sc_txd[cur].d_len == 0)
1850 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1852 if (wi_cmd(sc, WI_CMD_TX | WI_RECLAIM, sc->sc_txd[cur].d_fid,
1854 if_printf(ifp, "xmit failed\n");
1855 sc->sc_txd[cur].d_len = 0;
1857 sc->sc_tx_timer = 5;
1863 wi_info_intr(struct wi_softc *sc)
1865 struct ieee80211com *ic = &sc->sc_ic;
1866 struct ifnet *ifp = sc->sc_ifp;
1867 int i, fid, len, off;
1872 fid = CSR_READ_2(sc, WI_INFO_FID);
1873 wi_read_bap(sc, fid, 0, ltbuf, sizeof(ltbuf));
1875 switch (le16toh(ltbuf[1])) {
1877 case WI_INFO_LINK_STAT:
1878 wi_read_bap(sc, fid, sizeof(ltbuf), &stat, sizeof(stat));
1879 DPRINTF(("wi_info_intr: LINK_STAT 0x%x\n", le16toh(stat)));
1880 switch (le16toh(stat)) {
1881 case WI_INFO_LINK_STAT_CONNECTED:
1882 sc->sc_flags &= ~WI_FLAGS_OUTRANGE;
1883 if (ic->ic_state == IEEE80211_S_RUN &&
1884 ic->ic_opmode != IEEE80211_M_IBSS)
1887 case WI_INFO_LINK_STAT_AP_CHG:
1888 ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
1890 case WI_INFO_LINK_STAT_AP_INR:
1891 sc->sc_flags &= ~WI_FLAGS_OUTRANGE;
1893 case WI_INFO_LINK_STAT_AP_OOR:
1894 if (sc->sc_firmware_type == WI_SYMBOL &&
1895 sc->sc_scan_timer > 0) {
1896 if (wi_cmd(sc, WI_CMD_INQUIRE,
1897 WI_INFO_HOST_SCAN_RESULTS, 0, 0) != 0)
1898 sc->sc_scan_timer = 0;
1901 if (ic->ic_opmode == IEEE80211_M_STA)
1902 sc->sc_flags |= WI_FLAGS_OUTRANGE;
1904 case WI_INFO_LINK_STAT_DISCONNECTED:
1905 case WI_INFO_LINK_STAT_ASSOC_FAILED:
1906 if (ic->ic_opmode == IEEE80211_M_STA)
1907 ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
1912 case WI_INFO_COUNTERS:
1913 /* some card versions have a larger stats structure */
1914 len = min(le16toh(ltbuf[0]) - 1, sizeof(sc->sc_stats) / 4);
1915 ptr = (u_int32_t *)&sc->sc_stats;
1916 off = sizeof(ltbuf);
1917 for (i = 0; i < len; i++, off += 2, ptr++) {
1918 wi_read_bap(sc, fid, off, &stat, sizeof(stat));
1919 #ifdef WI_HERMES_STATS_WAR
1925 ifp->if_collisions = sc->sc_stats.wi_tx_single_retries +
1926 sc->sc_stats.wi_tx_multi_retries +
1927 sc->sc_stats.wi_tx_retry_limit;
1930 case WI_INFO_SCAN_RESULTS:
1931 case WI_INFO_HOST_SCAN_RESULTS:
1932 wi_scan_result(sc, fid, le16toh(ltbuf[0]));
1933 ieee80211_scan_done(ic);
1937 DPRINTF(("wi_info_intr: got fid %x type %x len %d\n", fid,
1938 le16toh(ltbuf[1]), le16toh(ltbuf[0])));
1941 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_INFO);
1945 wi_write_multi(struct wi_softc *sc)
1947 struct ifnet *ifp = sc->sc_ifp;
1949 struct ifmultiaddr *ifma;
1950 struct wi_mcast mlist;
1952 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
1954 memset(&mlist, 0, sizeof(mlist));
1955 return wi_write_rid(sc, WI_RID_MCAST_LIST, &mlist,
1961 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1962 if (ifma->ifma_addr->sa_family != AF_LINK)
1966 IEEE80211_ADDR_COPY(&mlist.wi_mcast[n],
1967 (LLADDR((struct sockaddr_dl *)ifma->ifma_addr)));
1970 IF_ADDR_UNLOCK(ifp);
1971 return wi_write_rid(sc, WI_RID_MCAST_LIST, &mlist,
1972 IEEE80211_ADDR_LEN * n);
1976 wi_read_nicid(struct wi_softc *sc)
1978 struct wi_card_ident *id;
1983 /* getting chip identity */
1984 memset(ver, 0, sizeof(ver));
1986 wi_read_rid(sc, WI_RID_CARD_ID, ver, &len);
1987 device_printf(sc->sc_dev, "using ");
1989 sc->sc_firmware_type = WI_NOTYPE;
1990 for (id = wi_card_ident; id->card_name != NULL; id++) {
1991 if (le16toh(ver[0]) == id->card_id) {
1992 printf("%s", id->card_name);
1993 sc->sc_firmware_type = id->firm_type;
1997 if (sc->sc_firmware_type == WI_NOTYPE) {
1998 if (le16toh(ver[0]) & 0x8000) {
1999 printf("Unknown PRISM2 chip");
2000 sc->sc_firmware_type = WI_INTERSIL;
2002 printf("Unknown Lucent chip");
2003 sc->sc_firmware_type = WI_LUCENT;
2007 /* get primary firmware version (Only Prism chips) */
2008 if (sc->sc_firmware_type != WI_LUCENT) {
2009 memset(ver, 0, sizeof(ver));
2011 wi_read_rid(sc, WI_RID_PRI_IDENTITY, ver, &len);
2012 sc->sc_pri_firmware_ver = le16toh(ver[2]) * 10000 +
2013 le16toh(ver[3]) * 100 + le16toh(ver[1]);
2016 /* get station firmware version */
2017 memset(ver, 0, sizeof(ver));
2019 wi_read_rid(sc, WI_RID_STA_IDENTITY, ver, &len);
2020 sc->sc_sta_firmware_ver = le16toh(ver[2]) * 10000 +
2021 le16toh(ver[3]) * 100 + le16toh(ver[1]);
2022 if (sc->sc_firmware_type == WI_INTERSIL &&
2023 (sc->sc_sta_firmware_ver == 10102 ||
2024 sc->sc_sta_firmware_ver == 20102)) {
2026 memset(ident, 0, sizeof(ident));
2027 len = sizeof(ident);
2028 /* value should be the format like "V2.00-11" */
2029 if (wi_read_rid(sc, WI_RID_SYMBOL_IDENTITY, ident, &len) == 0 &&
2030 *(p = (char *)ident) >= 'A' &&
2031 p[2] == '.' && p[5] == '-' && p[8] == '\0') {
2032 sc->sc_firmware_type = WI_SYMBOL;
2033 sc->sc_sta_firmware_ver = (p[1] - '0') * 10000 +
2034 (p[3] - '0') * 1000 + (p[4] - '0') * 100 +
2035 (p[6] - '0') * 10 + (p[7] - '0');
2039 device_printf(sc->sc_dev, "%s Firmware: ",
2040 sc->sc_firmware_type == WI_LUCENT ? "Lucent" :
2041 (sc->sc_firmware_type == WI_SYMBOL ? "Symbol" : "Intersil"));
2042 if (sc->sc_firmware_type != WI_LUCENT) /* XXX */
2043 printf("Primary (%u.%u.%u), ",
2044 sc->sc_pri_firmware_ver / 10000,
2045 (sc->sc_pri_firmware_ver % 10000) / 100,
2046 sc->sc_pri_firmware_ver % 100);
2047 printf("Station (%u.%u.%u)\n",
2048 sc->sc_sta_firmware_ver / 10000,
2049 (sc->sc_sta_firmware_ver % 10000) / 100,
2050 sc->sc_sta_firmware_ver % 100);
2054 wi_write_ssid(struct wi_softc *sc, int rid, u_int8_t *buf, int buflen)
2056 struct wi_ssid ssid;
2058 if (buflen > IEEE80211_NWID_LEN)
2060 memset(&ssid, 0, sizeof(ssid));
2061 ssid.wi_len = htole16(buflen);
2062 memcpy(ssid.wi_ssid, buf, buflen);
2063 return wi_write_rid(sc, rid, &ssid, sizeof(ssid));
2068 wi_get_cfg(struct ifnet *ifp, u_long cmd, caddr_t data)
2070 struct wi_softc *sc = ifp->if_softc;
2071 struct ieee80211com *ic = &sc->sc_ic;
2072 struct ifreq *ifr = (struct ifreq *)data;
2074 struct wi_scan_res *res;
2076 int len, n, error, mif, val, off, i;
2078 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
2081 len = (wreq.wi_len - 1) * 2;
2082 if (len < sizeof(u_int16_t))
2084 if (len > sizeof(wreq.wi_val))
2085 len = sizeof(wreq.wi_val);
2087 switch (wreq.wi_type) {
2089 case WI_RID_IFACE_STATS:
2090 memcpy(wreq.wi_val, &sc->sc_stats, sizeof(sc->sc_stats));
2091 if (len < sizeof(sc->sc_stats))
2094 len = sizeof(sc->sc_stats);
2097 case WI_RID_ENCRYPTION:
2098 case WI_RID_TX_CRYPT_KEY:
2099 case WI_RID_DEFLT_CRYPT_KEYS:
2100 case WI_RID_TX_RATE:
2101 return ieee80211_ioctl(ic, cmd, data);
2103 case WI_RID_MICROWAVE_OVEN:
2104 if (sc->sc_enabled && (sc->sc_flags & WI_FLAGS_HAS_MOR)) {
2105 error = wi_read_rid(sc, wreq.wi_type, wreq.wi_val,
2109 wreq.wi_val[0] = htole16(sc->sc_microwave_oven);
2110 len = sizeof(u_int16_t);
2113 case WI_RID_DBM_ADJUST:
2114 if (sc->sc_enabled && (sc->sc_flags & WI_FLAGS_HAS_DBMADJUST)) {
2115 error = wi_read_rid(sc, wreq.wi_type, wreq.wi_val,
2119 wreq.wi_val[0] = htole16(sc->sc_dbm_offset);
2120 len = sizeof(u_int16_t);
2123 case WI_RID_ROAMING_MODE:
2124 if (sc->sc_enabled && (sc->sc_flags & WI_FLAGS_HAS_ROAMING)) {
2125 error = wi_read_rid(sc, wreq.wi_type, wreq.wi_val,
2129 wreq.wi_val[0] = htole16(sc->sc_roaming_mode);
2130 len = sizeof(u_int16_t);
2133 case WI_RID_SYSTEM_SCALE:
2134 if (sc->sc_enabled && (sc->sc_flags & WI_FLAGS_HAS_SYSSCALE)) {
2135 error = wi_read_rid(sc, wreq.wi_type, wreq.wi_val,
2139 wreq.wi_val[0] = htole16(sc->sc_system_scale);
2140 len = sizeof(u_int16_t);
2143 case WI_RID_FRAG_THRESH:
2144 if (sc->sc_enabled && (sc->sc_flags & WI_FLAGS_HAS_FRAGTHR)) {
2145 error = wi_read_rid(sc, wreq.wi_type, wreq.wi_val,
2149 wreq.wi_val[0] = htole16(ic->ic_fragthreshold);
2150 len = sizeof(u_int16_t);
2153 case WI_RID_READ_APS:
2154 if (ic->ic_opmode == IEEE80211_M_HOSTAP)
2155 return ieee80211_ioctl(ic, cmd, data);
2156 if (sc->sc_scan_timer > 0) {
2157 error = EINPROGRESS;
2161 if (len < sizeof(n)) {
2165 if (len < sizeof(n) + sizeof(struct wi_apinfo) * n)
2166 n = (len - sizeof(n)) / sizeof(struct wi_apinfo);
2167 len = sizeof(n) + sizeof(struct wi_apinfo) * n;
2168 memcpy(wreq.wi_val, &n, sizeof(n));
2169 memcpy((caddr_t)wreq.wi_val + sizeof(n), sc->sc_aps,
2170 sizeof(struct wi_apinfo) * n);
2174 wreq.wi_val[0] = sc->sc_firmware_type != WI_LUCENT;
2175 len = sizeof(u_int16_t);
2179 mif = wreq.wi_val[0];
2180 error = wi_cmd(sc, WI_CMD_READMIF, mif, 0, 0);
2181 val = CSR_READ_2(sc, WI_RESP0);
2182 wreq.wi_val[0] = val;
2183 len = sizeof(u_int16_t);
2186 case WI_RID_ZERO_CACHE:
2187 case WI_RID_PROCFRAME: /* ignore for compatibility */
2191 case WI_RID_READ_CACHE:
2192 return ieee80211_ioctl(ic, cmd, data);
2194 case WI_RID_SCAN_RES: /* compatibility interface */
2195 if (ic->ic_opmode == IEEE80211_M_HOSTAP)
2196 return ieee80211_ioctl(ic, cmd, data);
2197 if (sc->sc_scan_timer > 0) {
2198 error = EINPROGRESS;
2202 if (sc->sc_firmware_type == WI_LUCENT) {
2204 reslen = WI_WAVELAN_RES_SIZE;
2206 off = sizeof(struct wi_scan_p2_hdr);
2207 reslen = WI_PRISM2_RES_SIZE;
2209 if (len < off + reslen * n)
2210 n = (len - off) / reslen;
2211 len = off + reslen * n;
2213 struct wi_scan_p2_hdr *p2 = (struct wi_scan_p2_hdr *)wreq.wi_val;
2215 * Prepend Prism-specific header.
2217 if (len < sizeof(struct wi_scan_p2_hdr)) {
2221 p2 = (struct wi_scan_p2_hdr *)wreq.wi_val;
2223 p2->wi_reason = n; /* XXX */
2225 for (i = 0; i < n; i++, off += reslen) {
2226 const struct wi_apinfo *ap = &sc->sc_aps[i];
2228 res = (struct wi_scan_res *)((char *)wreq.wi_val + off);
2229 res->wi_chan = ap->channel;
2230 res->wi_noise = ap->noise;
2231 res->wi_signal = ap->signal;
2232 IEEE80211_ADDR_COPY(res->wi_bssid, ap->bssid);
2233 res->wi_interval = ap->interval;
2234 res->wi_capinfo = ap->capinfo;
2235 res->wi_ssid_len = ap->namelen;
2236 memcpy(res->wi_ssid, ap->name,
2237 IEEE80211_NWID_LEN);
2238 if (sc->sc_firmware_type != WI_LUCENT) {
2239 /* XXX not saved from Prism cards */
2240 memset(res->wi_srates, 0,
2241 sizeof(res->wi_srates));
2242 res->wi_rate = ap->rate;
2249 if (sc->sc_enabled) {
2250 error = wi_read_rid(sc, wreq.wi_type, wreq.wi_val,
2254 switch (wreq.wi_type) {
2255 case WI_RID_MAX_DATALEN:
2256 wreq.wi_val[0] = htole16(sc->sc_max_datalen);
2257 len = sizeof(u_int16_t);
2259 case WI_RID_RTS_THRESH:
2260 wreq.wi_val[0] = htole16(ic->ic_rtsthreshold);
2261 len = sizeof(u_int16_t);
2263 case WI_RID_CNFAUTHMODE:
2264 wreq.wi_val[0] = htole16(sc->sc_cnfauthmode);
2265 len = sizeof(u_int16_t);
2267 case WI_RID_NODENAME:
2268 if (len < sc->sc_nodelen + sizeof(u_int16_t)) {
2272 len = sc->sc_nodelen + sizeof(u_int16_t);
2273 wreq.wi_val[0] = htole16((sc->sc_nodelen + 1) / 2);
2274 memcpy(&wreq.wi_val[1], sc->sc_nodename,
2278 return ieee80211_ioctl(ic, cmd, data);
2284 wreq.wi_len = (len + 1) / 2 + 1;
2285 return copyout(&wreq, ifr->ifr_data, (wreq.wi_len + 1) * 2);
2289 wi_set_cfg(struct ifnet *ifp, u_long cmd, caddr_t data)
2291 struct wi_softc *sc = ifp->if_softc;
2292 struct ieee80211com *ic = &sc->sc_ic;
2293 struct ifreq *ifr = (struct ifreq *)data;
2296 int i, len, error, mif, val;
2297 struct ieee80211_rateset *rs;
2299 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
2302 len = wreq.wi_len ? (wreq.wi_len - 1) * 2 : 0;
2303 switch (wreq.wi_type) {
2304 case WI_RID_DBM_ADJUST:
2307 case WI_RID_NODENAME:
2308 if (le16toh(wreq.wi_val[0]) * 2 > len ||
2309 le16toh(wreq.wi_val[0]) > sizeof(sc->sc_nodename)) {
2315 error = wi_write_rid(sc, wreq.wi_type, wreq.wi_val,
2318 sc->sc_nodelen = le16toh(wreq.wi_val[0]) * 2;
2319 memcpy(sc->sc_nodename, &wreq.wi_val[1],
2325 case WI_RID_MICROWAVE_OVEN:
2326 case WI_RID_ROAMING_MODE:
2327 case WI_RID_SYSTEM_SCALE:
2328 case WI_RID_FRAG_THRESH:
2329 /* XXX unlocked reads */
2330 if (wreq.wi_type == WI_RID_MICROWAVE_OVEN &&
2331 (sc->sc_flags & WI_FLAGS_HAS_MOR) == 0)
2333 if (wreq.wi_type == WI_RID_ROAMING_MODE &&
2334 (sc->sc_flags & WI_FLAGS_HAS_ROAMING) == 0)
2336 if (wreq.wi_type == WI_RID_SYSTEM_SCALE &&
2337 (sc->sc_flags & WI_FLAGS_HAS_SYSSCALE) == 0)
2339 if (wreq.wi_type == WI_RID_FRAG_THRESH &&
2340 (sc->sc_flags & WI_FLAGS_HAS_FRAGTHR) == 0)
2343 case WI_RID_RTS_THRESH:
2344 case WI_RID_CNFAUTHMODE:
2345 case WI_RID_MAX_DATALEN:
2347 if (sc->sc_enabled) {
2348 error = wi_write_rid(sc, wreq.wi_type, wreq.wi_val,
2355 switch (wreq.wi_type) {
2356 case WI_RID_FRAG_THRESH:
2357 ic->ic_fragthreshold = le16toh(wreq.wi_val[0]);
2359 case WI_RID_RTS_THRESH:
2360 ic->ic_rtsthreshold = le16toh(wreq.wi_val[0]);
2362 case WI_RID_MICROWAVE_OVEN:
2363 sc->sc_microwave_oven = le16toh(wreq.wi_val[0]);
2365 case WI_RID_ROAMING_MODE:
2366 sc->sc_roaming_mode = le16toh(wreq.wi_val[0]);
2368 case WI_RID_SYSTEM_SCALE:
2369 sc->sc_system_scale = le16toh(wreq.wi_val[0]);
2371 case WI_RID_CNFAUTHMODE:
2372 sc->sc_cnfauthmode = le16toh(wreq.wi_val[0]);
2374 case WI_RID_MAX_DATALEN:
2375 sc->sc_max_datalen = le16toh(wreq.wi_val[0]);
2381 case WI_RID_TX_RATE:
2383 switch (le16toh(wreq.wi_val[0])) {
2385 ic->ic_fixed_rate = IEEE80211_FIXED_RATE_NONE;
2388 rs = &ic->ic_sup_rates[IEEE80211_MODE_11B];
2389 for (i = 0; i < rs->rs_nrates; i++) {
2390 if ((rs->rs_rates[i] & IEEE80211_RATE_VAL)
2391 / 2 == le16toh(wreq.wi_val[0]))
2394 if (i == rs->rs_nrates) {
2398 ic->ic_fixed_rate = rs->rs_rates[i] & IEEE80211_RATE_VAL;
2401 error = wi_write_txrate(sc);
2405 case WI_RID_SCAN_APS:
2407 if (sc->sc_enabled && ic->ic_opmode != IEEE80211_M_HOSTAP)
2408 error = wi_scan_ap(sc, 0x3fff, 0x000f);
2412 case WI_RID_SCAN_REQ: /* compatibility interface */
2414 if (sc->sc_enabled && ic->ic_opmode != IEEE80211_M_HOSTAP)
2415 error = wi_scan_ap(sc, wreq.wi_val[0], wreq.wi_val[1]);
2419 case WI_RID_MGMT_XMIT:
2421 if (!sc->sc_enabled)
2423 else if (ic->ic_mgtq.ifq_len > 5)
2426 /* NB: m_devget uses M_DONTWAIT so can hold the lock */
2427 /* XXX wi_len looks in u_int8_t, not in u_int16_t */
2428 m = m_devget((char *)&wreq.wi_val, wreq.wi_len, 0,
2431 IF_ENQUEUE(&ic->ic_mgtq, m);
2439 mif = wreq.wi_val[0];
2440 val = wreq.wi_val[1];
2442 error = wi_cmd(sc, WI_CMD_WRITEMIF, mif, val, 0);
2446 case WI_RID_PROCFRAME: /* ignore for compatibility */
2449 case WI_RID_OWN_SSID:
2450 if (le16toh(wreq.wi_val[0]) * 2 > len ||
2451 le16toh(wreq.wi_val[0]) > IEEE80211_NWID_LEN) {
2456 memset(ic->ic_des_ssid[0].ssid, 0, IEEE80211_NWID_LEN);
2457 ic->ic_des_ssid[0].len = le16toh(wreq.wi_val[0]) * 2;
2458 memcpy(ic->ic_des_ssid[0].ssid, &wreq.wi_val[1],
2459 ic->ic_des_ssid[0].len);
2461 wi_init(sc); /* XXX no error return */
2468 error = wi_write_rid(sc, wreq.wi_type, wreq.wi_val,
2471 /* XXX ieee80211_ioctl does a copyin */
2472 error = ieee80211_ioctl(ic, cmd, data);
2473 if (error == ENETRESET) {
2487 wi_write_txrate(struct wi_softc *sc)
2489 struct ieee80211com *ic = &sc->sc_ic;
2493 if (ic->ic_fixed_rate == IEEE80211_FIXED_RATE_NONE)
2494 rate = 0; /* auto */
2496 rate = ic->ic_fixed_rate / 2;
2498 /* rate: 0, 1, 2, 5, 11 */
2500 switch (sc->sc_firmware_type) {
2503 case 0: /* auto == 11mbps auto */
2506 /* case 1, 2 map to 1, 2*/
2507 case 5: /* 5.5Mbps -> 4 */
2510 case 11: /* 11mbps -> 5 */
2518 /* Choose a bit according to this table.
2521 * ----+-------------------
2527 for (i = 8; i > 0; i >>= 1) {
2532 rate = 0xf; /* auto */
2537 return wi_write_val(sc, WI_RID_TX_RATE, rate);
2541 wi_key_alloc(struct ieee80211com *ic, const struct ieee80211_key *k,
2542 ieee80211_keyix *keyix, ieee80211_keyix *rxkeyix)
2544 struct wi_softc *sc = ic->ic_ifp->if_softc;
2547 * When doing host encryption of outbound frames fail requests
2548 * for keys that are not marked w/ the SWCRYPT flag so the
2549 * net80211 layer falls back to s/w crypto. Note that we also
2550 * fixup existing keys below to handle mode changes.
2552 if ((sc->sc_encryption & HOST_ENCRYPT) &&
2553 (k->wk_flags & IEEE80211_KEY_SWCRYPT) == 0)
2555 return sc->sc_key_alloc(ic, k, keyix, rxkeyix);
2559 wi_write_wep(struct wi_softc *sc)
2561 struct ieee80211com *ic = &sc->sc_ic;
2565 struct wi_key wkey[IEEE80211_WEP_NKID];
2567 switch (sc->sc_firmware_type) {
2569 val = (ic->ic_flags & IEEE80211_F_PRIVACY) ? 1 : 0;
2570 error = wi_write_val(sc, WI_RID_ENCRYPTION, val);
2573 if ((ic->ic_flags & IEEE80211_F_PRIVACY) == 0)
2575 error = wi_write_val(sc, WI_RID_TX_CRYPT_KEY, ic->ic_def_txkey);
2578 memset(wkey, 0, sizeof(wkey));
2579 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
2580 keylen = ic->ic_nw_keys[i].wk_keylen;
2581 wkey[i].wi_keylen = htole16(keylen);
2582 memcpy(wkey[i].wi_keydat, ic->ic_nw_keys[i].wk_key,
2585 error = wi_write_rid(sc, WI_RID_DEFLT_CRYPT_KEYS,
2586 wkey, sizeof(wkey));
2587 sc->sc_encryption = 0;
2592 if (ic->ic_flags & IEEE80211_F_PRIVACY) {
2594 * ONLY HWB3163 EVAL-CARD Firmware version
2595 * less than 0.8 variant2
2597 * If promiscuous mode disable, Prism2 chip
2598 * does not work with WEP .
2599 * It is under investigation for details.
2600 * (ichiro@netbsd.org)
2602 if (sc->sc_firmware_type == WI_INTERSIL &&
2603 sc->sc_sta_firmware_ver < 802 ) {
2604 /* firm ver < 0.8 variant 2 */
2605 wi_write_val(sc, WI_RID_PROMISC, 1);
2607 wi_write_val(sc, WI_RID_CNFAUTHMODE,
2608 sc->sc_cnfauthmode);
2609 /* XXX should honor IEEE80211_F_DROPUNENC */
2610 val = PRIVACY_INVOKED | EXCLUDE_UNENCRYPTED;
2612 * Encryption firmware has a bug for HostAP mode.
2614 if (sc->sc_firmware_type == WI_INTERSIL &&
2615 ic->ic_opmode == IEEE80211_M_HOSTAP)
2616 val |= HOST_ENCRYPT;
2618 wi_write_val(sc, WI_RID_CNFAUTHMODE,
2619 IEEE80211_AUTH_OPEN);
2620 val = HOST_ENCRYPT | HOST_DECRYPT;
2622 error = wi_write_val(sc, WI_RID_P2_ENCRYPTION, val);
2625 sc->sc_encryption = val;
2626 if ((val & PRIVACY_INVOKED) == 0)
2628 error = wi_write_val(sc, WI_RID_P2_TX_CRYPT_KEY,
2632 if (val & HOST_DECRYPT)
2635 * It seems that the firmware accept 104bit key only if
2636 * all the keys have 104bit length. We get the length of
2637 * the transmit key and use it for all other keys.
2638 * Perhaps we should use software WEP for such situation.
2640 if (ic->ic_def_txkey != IEEE80211_KEYIX_NONE)
2641 keylen = ic->ic_nw_keys[ic->ic_def_txkey].wk_keylen;
2642 else /* XXX should not hapen */
2643 keylen = IEEE80211_WEP_KEYLEN;
2644 if (keylen > IEEE80211_WEP_KEYLEN)
2645 keylen = 13; /* 104bit keys */
2647 keylen = IEEE80211_WEP_KEYLEN;
2648 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
2649 error = wi_write_rid(sc, WI_RID_P2_CRYPT_KEY0 + i,
2650 ic->ic_nw_keys[i].wk_key, keylen);
2657 * XXX horrible hack; insure pre-existing keys are
2658 * setup properly to do s/w crypto.
2660 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
2661 struct ieee80211_key *k = &ic->ic_nw_keys[i];
2662 if (k->wk_flags & IEEE80211_KEY_XMIT) {
2663 if (sc->sc_encryption & HOST_ENCRYPT)
2664 k->wk_flags |= IEEE80211_KEY_SWCRYPT;
2666 k->wk_flags &= ~IEEE80211_KEY_SWCRYPT;
2673 wi_cmd(struct wi_softc *sc, int cmd, int val0, int val1, int val2)
2680 /* wait for the busy bit to clear */
2681 for (i = sc->wi_cmd_count; i > 0; i--) { /* 500ms */
2682 if (!(CSR_READ_2(sc, WI_COMMAND) & WI_CMD_BUSY))
2684 DELAY(1*1000); /* 1ms */
2687 device_printf(sc->sc_dev, "wi_cmd: busy bit won't clear.\n" );
2692 CSR_WRITE_2(sc, WI_PARAM0, val0);
2693 CSR_WRITE_2(sc, WI_PARAM1, val1);
2694 CSR_WRITE_2(sc, WI_PARAM2, val2);
2695 CSR_WRITE_2(sc, WI_COMMAND, cmd);
2697 if (cmd == WI_CMD_INI) {
2698 /* XXX: should sleep here. */
2699 DELAY(100*1000); /* 100ms delay for init */
2701 for (i = 0; i < WI_TIMEOUT; i++) {
2703 * Wait for 'command complete' bit to be
2704 * set in the event status register.
2706 s = CSR_READ_2(sc, WI_EVENT_STAT);
2707 if (s & WI_EV_CMD) {
2708 /* Ack the event and read result code. */
2709 s = CSR_READ_2(sc, WI_STATUS);
2710 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_CMD);
2711 if (s & WI_STAT_CMD_RESULT) {
2719 if (i == WI_TIMEOUT) {
2720 device_printf(sc->sc_dev,
2721 "timeout in wi_cmd 0x%04x; event status 0x%04x\n", cmd, s);
2730 wi_seek_bap(struct wi_softc *sc, int id, int off)
2734 CSR_WRITE_2(sc, WI_SEL0, id);
2735 CSR_WRITE_2(sc, WI_OFF0, off);
2737 for (i = 0; ; i++) {
2738 status = CSR_READ_2(sc, WI_OFF0);
2739 if ((status & WI_OFF_BUSY) == 0)
2741 if (i == WI_TIMEOUT) {
2742 device_printf(sc->sc_dev, "timeout in wi_seek to %x/%x\n",
2744 sc->sc_bap_off = WI_OFF_ERR; /* invalidate */
2745 if (status == 0xffff)
2751 if (status & WI_OFF_ERR) {
2752 device_printf(sc->sc_dev, "failed in wi_seek to %x/%x\n", id, off);
2753 sc->sc_bap_off = WI_OFF_ERR; /* invalidate */
2757 sc->sc_bap_off = off;
2762 wi_read_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen)
2769 if (id != sc->sc_bap_id || off != sc->sc_bap_off) {
2770 if ((error = wi_seek_bap(sc, id, off)) != 0)
2773 cnt = (buflen + 1) / 2;
2774 ptr = (u_int16_t *)buf;
2775 for (i = 0; i < cnt; i++)
2776 *ptr++ = CSR_READ_2(sc, WI_DATA0);
2777 sc->sc_bap_off += cnt * 2;
2782 wi_write_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen)
2790 #ifdef WI_HERMES_AUTOINC_WAR
2793 if (id != sc->sc_bap_id || off != sc->sc_bap_off) {
2794 if ((error = wi_seek_bap(sc, id, off)) != 0)
2797 cnt = (buflen + 1) / 2;
2798 ptr = (u_int16_t *)buf;
2799 for (i = 0; i < cnt; i++)
2800 CSR_WRITE_2(sc, WI_DATA0, ptr[i]);
2801 sc->sc_bap_off += cnt * 2;
2803 #ifdef WI_HERMES_AUTOINC_WAR
2805 * According to the comments in the HCF Light code, there is a bug
2806 * in the Hermes (or possibly in certain Hermes firmware revisions)
2807 * where the chip's internal autoincrement counter gets thrown off
2808 * during data writes: the autoincrement is missed, causing one
2809 * data word to be overwritten and subsequent words to be written to
2810 * the wrong memory locations. The end result is that we could end
2811 * up transmitting bogus frames without realizing it. The workaround
2812 * for this is to write a couple of extra guard words after the end
2813 * of the transfer, then attempt to read then back. If we fail to
2814 * locate the guard words where we expect them, we preform the
2815 * transfer over again.
2817 if ((sc->sc_flags & WI_FLAGS_BUG_AUTOINC) && (id & 0xf000) == 0) {
2818 CSR_WRITE_2(sc, WI_DATA0, 0x1234);
2819 CSR_WRITE_2(sc, WI_DATA0, 0x5678);
2820 wi_seek_bap(sc, id, sc->sc_bap_off);
2821 sc->sc_bap_off = WI_OFF_ERR; /* invalidate */
2822 if (CSR_READ_2(sc, WI_DATA0) != 0x1234 ||
2823 CSR_READ_2(sc, WI_DATA0) != 0x5678) {
2824 device_printf(sc->sc_dev,
2825 "detect auto increment bug, try again\n");
2834 wi_mwrite_bap(struct wi_softc *sc, int id, int off, struct mbuf *m0, int totlen)
2839 for (m = m0; m != NULL && totlen > 0; m = m->m_next) {
2843 len = min(m->m_len, totlen);
2845 if (((u_long)m->m_data) % 2 != 0 || len % 2 != 0) {
2846 m_copydata(m, 0, totlen, (caddr_t)&sc->sc_txbuf);
2847 return wi_write_bap(sc, id, off, (caddr_t)&sc->sc_txbuf,
2851 if ((error = wi_write_bap(sc, id, off, m->m_data, len)) != 0)
2861 wi_alloc_fid(struct wi_softc *sc, int len, int *idp)
2865 if (wi_cmd(sc, WI_CMD_ALLOC_MEM, len, 0, 0)) {
2866 device_printf(sc->sc_dev, "failed to allocate %d bytes on NIC\n",
2871 for (i = 0; i < WI_TIMEOUT; i++) {
2872 if (CSR_READ_2(sc, WI_EVENT_STAT) & WI_EV_ALLOC)
2876 if (i == WI_TIMEOUT) {
2877 device_printf(sc->sc_dev, "timeout in alloc\n");
2880 *idp = CSR_READ_2(sc, WI_ALLOC_FID);
2881 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_ALLOC);
2886 wi_read_rid(struct wi_softc *sc, int rid, void *buf, int *buflenp)
2891 /* Tell the NIC to enter record read mode. */
2892 error = wi_cmd(sc, WI_CMD_ACCESS | WI_ACCESS_READ, rid, 0, 0);
2896 error = wi_read_bap(sc, rid, 0, ltbuf, sizeof(ltbuf));
2900 if (le16toh(ltbuf[1]) != rid) {
2901 device_printf(sc->sc_dev, "record read mismatch, rid=%x, got=%x\n",
2902 rid, le16toh(ltbuf[1]));
2905 len = (le16toh(ltbuf[0]) - 1) * 2; /* already got rid */
2906 if (*buflenp < len) {
2907 device_printf(sc->sc_dev, "record buffer is too small, "
2908 "rid=%x, size=%d, len=%d\n",
2909 rid, *buflenp, len);
2913 return wi_read_bap(sc, rid, sizeof(ltbuf), buf, len);
2917 wi_write_rid(struct wi_softc *sc, int rid, void *buf, int buflen)
2922 ltbuf[0] = htole16((buflen + 1) / 2 + 1); /* includes rid */
2923 ltbuf[1] = htole16(rid);
2925 error = wi_write_bap(sc, rid, 0, ltbuf, sizeof(ltbuf));
2928 error = wi_write_bap(sc, rid, sizeof(ltbuf), buf, buflen);
2932 return wi_cmd(sc, WI_CMD_ACCESS | WI_ACCESS_WRITE, rid, 0, 0);
2936 wi_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg)
2938 struct ifnet *ifp = ic->ic_ifp;
2939 struct wi_softc *sc = ifp->if_softc;
2940 struct ieee80211_node *ni;
2943 struct wi_ssid ssid;
2944 u_int8_t old_bssid[IEEE80211_ADDR_LEN];
2946 DPRINTF(("%s: %s -> %s\n", __func__,
2947 ieee80211_state_name[ic->ic_state],
2948 ieee80211_state_name[nstate]));
2951 * Internal to the driver the INIT and RUN states are used
2952 * so bypass the net80211 state machine for other states.
2953 * Beware however that this requires use to net80211 state
2954 * management that otherwise would be handled for us.
2957 case IEEE80211_S_INIT:
2958 sc->sc_flags &= ~WI_FLAGS_OUTRANGE;
2959 return (*sc->sc_newstate)(ic, nstate, arg);
2961 case IEEE80211_S_SCAN:
2962 return (*sc->sc_newstate)(ic, nstate, arg);
2964 case IEEE80211_S_AUTH:
2965 case IEEE80211_S_ASSOC:
2966 ic->ic_state = nstate; /* NB: skip normal ieee80211 handling */
2969 case IEEE80211_S_RUN:
2971 sc->sc_flags &= ~WI_FLAGS_OUTRANGE;
2972 buflen = IEEE80211_ADDR_LEN;
2973 IEEE80211_ADDR_COPY(old_bssid, ni->ni_bssid);
2974 wi_read_rid(sc, WI_RID_CURRENT_BSSID, ni->ni_bssid, &buflen);
2975 IEEE80211_ADDR_COPY(ni->ni_macaddr, ni->ni_bssid);
2976 buflen = sizeof(val);
2977 wi_read_rid(sc, WI_RID_CURRENT_CHAN, &val, &buflen);
2978 ni->ni_chan = ieee80211_find_channel(ic,
2979 ieee80211_ieee2mhz(val, IEEE80211_CHAN_B),
2981 if (ni->ni_chan == NULL)
2982 ni->ni_chan = &ic->ic_channels[0];
2983 ic->ic_curchan = ic->ic_bsschan = ni->ni_chan;
2985 sc->sc_tx_th.wt_chan_freq = sc->sc_rx_th.wr_chan_freq =
2986 htole16(ni->ni_chan->ic_freq);
2987 sc->sc_tx_th.wt_chan_flags = sc->sc_rx_th.wr_chan_flags =
2988 htole16(ni->ni_chan->ic_flags);
2991 * XXX hack; unceremoniously clear
2992 * IEEE80211_F_DROPUNENC when operating with
2993 * wep enabled so we don't drop unencoded frames
2994 * at the 802.11 layer. This is necessary because
2995 * we must strip the WEP bit from the 802.11 header
2996 * before passing frames to ieee80211_input because
2997 * the card has already stripped the WEP crypto
2998 * header from the packet.
3000 if (ic->ic_flags & IEEE80211_F_PRIVACY)
3001 ic->ic_flags &= ~IEEE80211_F_DROPUNENC;
3002 if (ic->ic_opmode != IEEE80211_M_HOSTAP) {
3003 /* XXX check return value */
3004 buflen = sizeof(ssid);
3005 wi_read_rid(sc, WI_RID_CURRENT_SSID, &ssid, &buflen);
3006 ni->ni_esslen = le16toh(ssid.wi_len);
3007 if (ni->ni_esslen > IEEE80211_NWID_LEN)
3008 ni->ni_esslen = IEEE80211_NWID_LEN; /*XXX*/
3009 memcpy(ni->ni_essid, ssid.wi_ssid, ni->ni_esslen);
3011 return (*sc->sc_newstate)(ic, nstate, arg);
3019 wi_scan_ap(struct wi_softc *sc, u_int16_t chanmask, u_int16_t txrate)
3024 if (!sc->sc_enabled)
3026 switch (sc->sc_firmware_type) {
3028 (void)wi_cmd(sc, WI_CMD_INQUIRE, WI_INFO_SCAN_RESULTS, 0, 0);
3031 val[0] = htole16(chanmask); /* channel */
3032 val[1] = htole16(txrate); /* tx rate */
3033 error = wi_write_rid(sc, WI_RID_SCAN_REQ, val, sizeof(val));
3037 * XXX only supported on 3.x ?
3039 val[0] = BSCAN_BCAST | BSCAN_ONETIME;
3040 error = wi_write_rid(sc, WI_RID_BCAST_SCAN_REQ,
3041 val, sizeof(val[0]));
3045 sc->sc_scan_timer = WI_SCAN_WAIT;
3046 DPRINTF(("wi_scan_ap: start scanning, "
3047 "chamask 0x%x txrate 0x%x\n", chanmask, txrate));
3053 wi_scan_result(struct wi_softc *sc, int fid, int cnt)
3055 #define N(a) (sizeof (a) / sizeof (a[0]))
3056 int i, naps, off, szbuf;
3057 struct wi_scan_header ws_hdr; /* Prism2 header */
3058 struct wi_scan_data_p2 ws_dat; /* Prism2 scantable*/
3059 struct wi_apinfo *ap;
3060 struct ieee80211_scanparams sp;
3061 struct ieee80211_frame wh;
3063 struct ieee80211com *ic;
3064 uint8_t ssid[2+IEEE80211_NWID_LEN];
3068 memset(&sp, 0, sizeof(sp));
3070 off = sizeof(u_int16_t) * 2;
3071 memset(&ws_hdr, 0, sizeof(ws_hdr));
3072 switch (sc->sc_firmware_type) {
3074 wi_read_bap(sc, fid, off, &ws_hdr, sizeof(ws_hdr));
3075 off += sizeof(ws_hdr);
3076 szbuf = sizeof(struct wi_scan_data_p2);
3079 szbuf = sizeof(struct wi_scan_data_p2) + 6;
3082 szbuf = sizeof(struct wi_scan_data);
3085 device_printf(sc->sc_dev,
3086 "wi_scan_result: unknown firmware type %u\n",
3087 sc->sc_firmware_type);
3091 naps = (cnt * 2 + 2 - off) / szbuf;
3092 if (naps > N(sc->sc_aps))
3093 naps = N(sc->sc_aps);
3097 memset(&ws_dat, 0, sizeof(ws_dat));
3099 for (i = 0; i < naps; i++, ap++) {
3100 uint8_t rates[2 + IEEE80211_RATE_MAXSIZE];
3102 wi_read_bap(sc, fid, off, &ws_dat,
3103 (sizeof(ws_dat) < szbuf ? sizeof(ws_dat) : szbuf));
3104 DPRINTF2(("wi_scan_result: #%d: off %d bssid %s\n", i, off,
3105 ether_sprintf(ws_dat.wi_bssid)));
3108 ap->scanreason = le16toh(ws_hdr.wi_reason);
3109 memcpy(ap->bssid, ws_dat.wi_bssid, sizeof(ap->bssid));
3111 bssid = (uint16_t *)&ap->bssid;
3112 if (bssid[0] == 0 && bssid[1] == 0 && bssid[2] == 0)
3115 memcpy(wh.i_addr2, ws_dat.wi_bssid, sizeof(ap->bssid));
3116 memcpy(wh.i_addr3, ws_dat.wi_bssid, sizeof(ap->bssid));
3117 ap->channel = le16toh(ws_dat.wi_chid);
3118 ap->signal = le16toh(ws_dat.wi_signal);
3119 ap->noise = le16toh(ws_dat.wi_noise);
3120 ap->quality = ap->signal - ap->noise;
3121 sp.capinfo = ap->capinfo = le16toh(ws_dat.wi_capinfo);
3122 sp.bintval = ap->interval = le16toh(ws_dat.wi_interval);
3123 ap->rate = le16toh(ws_dat.wi_rate);
3125 rates[2] = (uint8_t)ap->rate / 5;
3126 ap->namelen = le16toh(ws_dat.wi_namelen);
3127 if (ap->namelen > sizeof(ap->name))
3128 ap->namelen = sizeof(ap->name);
3129 memcpy(ap->name, ws_dat.wi_name, ap->namelen);
3130 sp.ssid = (uint8_t *)&ssid[0];
3131 memcpy(sp.ssid + 2, ap->name, ap->namelen);
3132 sp.ssid[1] = ap->namelen;
3133 sp.bchan = ap->channel;
3134 sp.curchan = ieee80211_find_channel(ic,
3135 ieee80211_ieee2mhz(ap->channel, IEEE80211_CHAN_B),
3137 if (sp.curchan == NULL)
3138 sp.curchan = &ic->ic_channels[0];
3139 sp.rates = &rates[0];
3140 sp.tstamp = (uint8_t *)&rstamp;
3141 DPRINTF(("calling add_scan, bssid %s chan %d signal %d\n",
3142 ether_sprintf(ws_dat.wi_bssid), ap->channel, ap->signal));
3143 ieee80211_add_scan(ic, &sp, &wh, 0, ap->signal, ap->noise, rstamp);
3147 sc->sc_scan_timer = 0;
3148 DPRINTF(("wi_scan_result: scan complete: ap %d\n", naps));
3153 wi_dump_pkt(struct wi_frame *wh, struct ieee80211_node *ni, int rssi)
3156 ieee80211_dump_pkt(ni->ni_ic,
3157 (u_int8_t *) &wh->wi_whdr, sizeof(wh->wi_whdr),
3158 ni->ni_rates.rs_rates[ni->ni_txrate] & IEEE80211_RATE_VAL,
3160 printf(" status 0x%x rx_tstamp1 %u rx_tstamp0 0x%u rx_silence %u\n",
3161 le16toh(wh->wi_status), le16toh(wh->wi_rx_tstamp1),
3162 le16toh(wh->wi_rx_tstamp0), wh->wi_rx_silence);
3163 printf(" rx_signal %u rx_rate %u rx_flow %u\n",
3164 wh->wi_rx_signal, wh->wi_rx_rate, wh->wi_rx_flow);
3165 printf(" tx_rtry %u tx_rate %u tx_ctl 0x%x dat_len %u\n",
3166 wh->wi_tx_rtry, wh->wi_tx_rate,
3167 le16toh(wh->wi_tx_ctl), le16toh(wh->wi_dat_len));
3168 printf(" ehdr dst %6D src %6D type 0x%x\n",
3169 wh->wi_ehdr.ether_dhost, ":", wh->wi_ehdr.ether_shost, ":",
3170 wh->wi_ehdr.ether_type);
3174 wi_alloc(device_t dev, int rid)
3176 struct wi_softc *sc = device_get_softc(dev);
3178 if (sc->wi_bus_type != WI_BUS_PCI_NATIVE) {
3179 sc->iobase_rid = rid;
3180 sc->iobase = bus_alloc_resource(dev, SYS_RES_IOPORT,
3181 &sc->iobase_rid, 0, ~0, (1 << 6),
3182 rman_make_alignment_flags(1 << 6) | RF_ACTIVE);
3184 device_printf(dev, "No I/O space?!\n");
3188 sc->wi_io_addr = rman_get_start(sc->iobase);
3189 sc->wi_btag = rman_get_bustag(sc->iobase);
3190 sc->wi_bhandle = rman_get_bushandle(sc->iobase);
3193 sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
3194 &sc->mem_rid, RF_ACTIVE);
3197 device_printf(dev, "No Mem space on prism2.5?\n");
3201 sc->wi_btag = rman_get_bustag(sc->mem);
3202 sc->wi_bhandle = rman_get_bushandle(sc->mem);
3207 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
3209 ((sc->wi_bus_type == WI_BUS_PCCARD) ? 0 : RF_SHAREABLE));
3213 device_printf(dev, "No irq?!\n");
3218 sc->sc_unit = device_get_unit(dev);
3224 wi_free(device_t dev)
3226 struct wi_softc *sc = device_get_softc(dev);
3228 if (sc->iobase != NULL) {
3229 bus_release_resource(dev, SYS_RES_IOPORT, sc->iobase_rid, sc->iobase);
3232 if (sc->irq != NULL) {
3233 bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq);
3236 if (sc->mem != NULL) {
3237 bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem);
3246 wi_get_debug(struct wi_softc *sc, struct wi_req *wreq)
3252 switch (wreq->wi_type) {
3253 case WI_DEBUG_SLEEP:
3255 wreq->wi_val[0] = sc->wi_debug.wi_sleep;
3257 case WI_DEBUG_DELAYSUPP:
3259 wreq->wi_val[0] = sc->wi_debug.wi_delaysupp;
3261 case WI_DEBUG_TXSUPP:
3263 wreq->wi_val[0] = sc->wi_debug.wi_txsupp;
3265 case WI_DEBUG_MONITOR:
3267 wreq->wi_val[0] = sc->wi_debug.wi_monitor;
3269 case WI_DEBUG_LEDTEST:
3271 wreq->wi_val[0] = sc->wi_debug.wi_ledtest;
3272 wreq->wi_val[1] = sc->wi_debug.wi_ledtest_param0;
3273 wreq->wi_val[2] = sc->wi_debug.wi_ledtest_param1;
3275 case WI_DEBUG_CONTTX:
3277 wreq->wi_val[0] = sc->wi_debug.wi_conttx;
3278 wreq->wi_val[1] = sc->wi_debug.wi_conttx_param0;
3280 case WI_DEBUG_CONTRX:
3282 wreq->wi_val[0] = sc->wi_debug.wi_contrx;
3284 case WI_DEBUG_SIGSTATE:
3286 wreq->wi_val[0] = sc->wi_debug.wi_sigstate;
3287 wreq->wi_val[1] = sc->wi_debug.wi_sigstate_param0;
3289 case WI_DEBUG_CONFBITS:
3291 wreq->wi_val[0] = sc->wi_debug.wi_confbits;
3292 wreq->wi_val[1] = sc->wi_debug.wi_confbits_param0;
3303 wi_set_debug(struct wi_softc *sc, struct wi_req *wreq)
3306 u_int16_t cmd, param0 = 0, param1 = 0;
3308 switch (wreq->wi_type) {
3309 case WI_DEBUG_RESET:
3311 case WI_DEBUG_CALENABLE:
3313 case WI_DEBUG_SLEEP:
3314 sc->wi_debug.wi_sleep = 1;
3317 sc->wi_debug.wi_sleep = 0;
3320 param0 = wreq->wi_val[0];
3322 case WI_DEBUG_DELAYSUPP:
3323 sc->wi_debug.wi_delaysupp = 1;
3325 case WI_DEBUG_TXSUPP:
3326 sc->wi_debug.wi_txsupp = 1;
3328 case WI_DEBUG_MONITOR:
3329 sc->wi_debug.wi_monitor = 1;
3331 case WI_DEBUG_LEDTEST:
3332 param0 = wreq->wi_val[0];
3333 param1 = wreq->wi_val[1];
3334 sc->wi_debug.wi_ledtest = 1;
3335 sc->wi_debug.wi_ledtest_param0 = param0;
3336 sc->wi_debug.wi_ledtest_param1 = param1;
3338 case WI_DEBUG_CONTTX:
3339 param0 = wreq->wi_val[0];
3340 sc->wi_debug.wi_conttx = 1;
3341 sc->wi_debug.wi_conttx_param0 = param0;
3343 case WI_DEBUG_STOPTEST:
3344 sc->wi_debug.wi_delaysupp = 0;
3345 sc->wi_debug.wi_txsupp = 0;
3346 sc->wi_debug.wi_monitor = 0;
3347 sc->wi_debug.wi_ledtest = 0;
3348 sc->wi_debug.wi_ledtest_param0 = 0;
3349 sc->wi_debug.wi_ledtest_param1 = 0;
3350 sc->wi_debug.wi_conttx = 0;
3351 sc->wi_debug.wi_conttx_param0 = 0;
3352 sc->wi_debug.wi_contrx = 0;
3353 sc->wi_debug.wi_sigstate = 0;
3354 sc->wi_debug.wi_sigstate_param0 = 0;
3356 case WI_DEBUG_CONTRX:
3357 sc->wi_debug.wi_contrx = 1;
3359 case WI_DEBUG_SIGSTATE:
3360 param0 = wreq->wi_val[0];
3361 sc->wi_debug.wi_sigstate = 1;
3362 sc->wi_debug.wi_sigstate_param0 = param0;
3364 case WI_DEBUG_CONFBITS:
3365 param0 = wreq->wi_val[0];
3366 param1 = wreq->wi_val[1];
3367 sc->wi_debug.wi_confbits = param0;
3368 sc->wi_debug.wi_confbits_param0 = param1;
3378 cmd = WI_CMD_DEBUG | (wreq->wi_type << 8);
3379 error = wi_cmd(sc, cmd, param0, param1, 0);
3386 * Special routines to download firmware for Symbol CF card.
3387 * XXX: This should be modified generic into any PRISM-2 based card.
3390 #define WI_SBCF_PDIADDR 0x3100
3392 /* unaligned load little endian */
3393 #define GETLE32(p) ((p)[0] | ((p)[1]<<8) | ((p)[2]<<16) | ((p)[3]<<24))
3394 #define GETLE16(p) ((p)[0] | ((p)[1]<<8))
3397 wi_symbol_load_firm(struct wi_softc *sc, const void *primsym, int primlen,
3398 const void *secsym, int seclen)
3403 /* load primary code and run it */
3404 wi_symbol_set_hcr(sc, WI_HCR_EEHOLD);
3405 if (wi_symbol_write_firm(sc, primsym, primlen, NULL, 0))
3407 wi_symbol_set_hcr(sc, WI_HCR_RUN);
3408 for (i = 0; ; i++) {
3411 tsleep(sc, PWAIT, "wiinit", 1);
3412 if (CSR_READ_2(sc, WI_CNTL) == WI_CNTL_AUX_ENA_STAT)
3414 /* write the magic key value to unlock aux port */
3415 CSR_WRITE_2(sc, WI_PARAM0, WI_AUX_KEY0);
3416 CSR_WRITE_2(sc, WI_PARAM1, WI_AUX_KEY1);
3417 CSR_WRITE_2(sc, WI_PARAM2, WI_AUX_KEY2);
3418 CSR_WRITE_2(sc, WI_CNTL, WI_CNTL_AUX_ENA_CNTL);
3421 /* issue read EEPROM command: XXX copied from wi_cmd() */
3422 CSR_WRITE_2(sc, WI_PARAM0, 0);
3423 CSR_WRITE_2(sc, WI_PARAM1, 0);
3424 CSR_WRITE_2(sc, WI_PARAM2, 0);
3425 CSR_WRITE_2(sc, WI_COMMAND, WI_CMD_READEE);
3426 for (i = 0; i < WI_TIMEOUT; i++) {
3427 if (CSR_READ_2(sc, WI_EVENT_STAT) & WI_EV_CMD)
3431 CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_CMD);
3433 CSR_WRITE_2(sc, WI_AUX_PAGE, WI_SBCF_PDIADDR / WI_AUX_PGSZ);
3434 CSR_WRITE_2(sc, WI_AUX_OFFSET, WI_SBCF_PDIADDR % WI_AUX_PGSZ);
3435 CSR_READ_MULTI_STREAM_2(sc, WI_AUX_DATA,
3436 (uint16_t *)ebuf, sizeof(ebuf) / 2);
3437 if (GETLE16(ebuf) > sizeof(ebuf))
3439 if (wi_symbol_write_firm(sc, secsym, seclen, ebuf + 4, GETLE16(ebuf)))
3445 wi_symbol_write_firm(struct wi_softc *sc, const void *buf, int buflen,
3446 const void *ebuf, int ebuflen)
3448 const uint8_t *p, *ep, *q, *eq;
3450 uint32_t addr, id, eid;
3451 int i, len, elen, nblk, pdrlen;
3454 * Parse the header of the firmware image.
3458 while (p < ep && *p++ != ' '); /* FILE: */
3459 while (p < ep && *p++ != ' '); /* filename */
3460 while (p < ep && *p++ != ' '); /* type of the firmware */
3461 nblk = strtoul(p, &tp, 10);
3463 pdrlen = strtoul(p + 1, &tp, 10);
3465 while (p < ep && *p++ != 0x1a); /* skip rest of header */
3468 * Block records: address[4], length[2], data[length];
3470 for (i = 0; i < nblk; i++) {
3471 addr = GETLE32(p); p += 4;
3472 len = GETLE16(p); p += 2;
3473 CSR_WRITE_2(sc, WI_AUX_PAGE, addr / WI_AUX_PGSZ);
3474 CSR_WRITE_2(sc, WI_AUX_OFFSET, addr % WI_AUX_PGSZ);
3475 CSR_WRITE_MULTI_STREAM_2(sc, WI_AUX_DATA,
3476 (const uint16_t *)p, len / 2);
3481 * PDR: id[4], address[4], length[4];
3483 for (i = 0; i < pdrlen; ) {
3484 id = GETLE32(p); p += 4; i += 4;
3485 addr = GETLE32(p); p += 4; i += 4;
3486 len = GETLE32(p); p += 4; i += 4;
3487 /* replace PDR entry with the values from EEPROM, if any */
3488 for (q = ebuf, eq = q + ebuflen; q < eq; q += elen * 2) {
3489 elen = GETLE16(q); q += 2;
3490 eid = GETLE16(q); q += 2;
3491 elen--; /* elen includes eid */
3496 CSR_WRITE_2(sc, WI_AUX_PAGE, addr / WI_AUX_PGSZ);
3497 CSR_WRITE_2(sc, WI_AUX_OFFSET, addr % WI_AUX_PGSZ);
3498 CSR_WRITE_MULTI_STREAM_2(sc, WI_AUX_DATA,
3499 (const uint16_t *)q, len / 2);
3507 wi_symbol_set_hcr(struct wi_softc *sc, int mode)
3511 CSR_WRITE_2(sc, WI_COR, WI_COR_RESET);
3512 tsleep(sc, PWAIT, "wiinit", 1);
3513 hcr = CSR_READ_2(sc, WI_HCR);
3514 hcr = (hcr & WI_HCR_4WIRE) | (mode & ~WI_HCR_4WIRE);
3515 CSR_WRITE_2(sc, WI_HCR, hcr);
3516 tsleep(sc, PWAIT, "wiinit", 1);
3517 CSR_WRITE_2(sc, WI_COR, WI_COR_IOMODE);
3518 tsleep(sc, PWAIT, "wiinit", 1);
3523 * This function can be called by ieee80211_set_shortslottime(). Refer to
3524 * IEEE Std 802.11-1999 pp. 85 to know how these values are computed.
3527 wi_update_slot(struct ifnet *ifp)
3529 DPRINTF(("wi update slot unimplemented\n"));
3533 wi_set_channel(struct ieee80211com *ic)
3535 struct ifnet *ifp = ic->ic_ifp;
3536 struct wi_softc *sc = ifp->if_softc;
3539 if (sc->sc_enabled && !(sc->sc_flags & WI_FLAGS_SCANNING)) {
3540 DPRINTF(("wi_set_channel: %d (%dMHz)\n",
3541 ieee80211_chan2ieee(ic, ic->ic_curchan),
3542 ic->ic_curchan->ic_freq));
3544 sc->wi_channel = ic->ic_curchan;
3545 wi_write_val(sc, WI_RID_OWN_CHNL,
3546 ieee80211_chan2ieee(ic, ic->ic_curchan));
3548 if (ic->ic_opmode == IEEE80211_M_HOSTAP &&
3549 sc->sc_firmware_type == WI_INTERSIL) {
3550 /* XXX: some cards need to be re-enabled */
3551 wi_cmd(sc, WI_CMD_DISABLE | WI_PORT0, 0, 0, 0);
3552 wi_cmd(sc, WI_CMD_ENABLE | WI_PORT0, 0, 0, 0);
3559 wi_scan_start(struct ieee80211com *ic)
3561 struct ifnet *ifp = ic->ic_ifp;
3562 struct wi_softc *sc = ifp->if_softc;
3565 sc->sc_flags |= WI_FLAGS_SCANNING;
3566 wi_scan_ap(sc, 0x3fff, 0x000f);
3572 wi_scan_curchan(struct ieee80211com *ic, unsigned long maxdwell)
3574 /* The firmware is not capable of scanning a single channel */
3578 wi_scan_mindwell(struct ieee80211com *ic)
3580 /* NB: don't try to abort scan; wait for firmware to finish */
3584 wi_scan_end(struct ieee80211com *ic)
3586 struct ifnet *ifp = ic->ic_ifp;
3587 struct wi_softc *sc = ifp->if_softc;
3590 sc->sc_flags &= ~WI_FLAGS_SCANNING;