Index: head/sys/dev/ath/if_ath.c =================================================================== --- head/sys/dev/ath/if_ath.c (revision 117811) +++ head/sys/dev/ath/if_ath.c (revision 117812) @@ -1,2565 +1,2565 @@ /*- * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any * redistribution must be conditioned upon including a substantially * similar Disclaimer requirement for further binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGES. */ #include __FBSDID("$FreeBSD$"); /* * Driver for the Atheros Wireless LAN controller. * * This software is derived from work of Atsushi Onoe; his contribution * is greatly appreciated. */ #include "opt_inet.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef INET #include #include #endif #define AR_DEBUG #include #include /* unalligned little endian access */ #define LE_READ_2(p) \ ((u_int16_t) \ ((((u_int8_t *)(p))[0] ) | (((u_int8_t *)(p))[1] << 8))) #define LE_READ_4(p) \ ((u_int32_t) \ ((((u_int8_t *)(p))[0] ) | (((u_int8_t *)(p))[1] << 8) | \ (((u_int8_t *)(p))[2] << 16) | (((u_int8_t *)(p))[3] << 24))) static void ath_init(void *); static void ath_stop(struct ifnet *); static void ath_start(struct ifnet *); static void ath_reset(struct ath_softc *); static int ath_media_change(struct ifnet *); static void ath_watchdog(struct ifnet *); static int ath_ioctl(struct ifnet *, u_long, caddr_t); static void ath_fatal_proc(void *, int); static void ath_rxorn_proc(void *, int); static void ath_bmiss_proc(void *, int); static void ath_initkeytable(struct ath_softc *); static void ath_mode_init(struct ath_softc *); static int ath_beacon_alloc(struct ath_softc *, struct ieee80211_node *); static void ath_beacon_proc(void *, int); static void ath_beacon_free(struct ath_softc *); static void ath_beacon_config(struct ath_softc *); static int ath_desc_alloc(struct ath_softc *); static void ath_desc_free(struct ath_softc *); static struct ieee80211_node *ath_node_alloc(struct ieee80211com *); static void ath_node_free(struct ieee80211com *, struct ieee80211_node *); static void ath_node_copy(struct ieee80211com *, struct ieee80211_node *, const struct ieee80211_node *); static int ath_rxbuf_init(struct ath_softc *, struct ath_buf *); static void ath_rx_proc(void *, int); static int ath_tx_start(struct ath_softc *, struct ieee80211_node *, struct ath_buf *, struct mbuf *); static void ath_tx_proc(void *, int); static int ath_chan_set(struct ath_softc *, struct ieee80211_channel *); static void ath_draintxq(struct ath_softc *); static void ath_stoprecv(struct ath_softc *); static int ath_startrecv(struct ath_softc *); static void ath_next_scan(void *); static void ath_calibrate(void *); -static int ath_newstate(void *, enum ieee80211_state); +static int ath_newstate(struct ieee80211com *, enum ieee80211_state, int); static void ath_newassoc(struct ieee80211com *, struct ieee80211_node *, int); static int ath_getchannels(struct ath_softc *, u_int cc, HAL_BOOL outdoor); static int ath_rate_setup(struct ath_softc *sc, u_int mode); static void ath_setcurmode(struct ath_softc *, enum ieee80211_phymode); static void ath_rate_ctl_reset(struct ath_softc *, enum ieee80211_state); static void ath_rate_ctl(void *, struct ieee80211_node *); SYSCTL_DECL(_hw_ath); /* XXX validate sysctl values */ static int ath_dwelltime = 200; /* 5 channels/second */ SYSCTL_INT(_hw_ath, OID_AUTO, dwell, CTLFLAG_RW, &ath_dwelltime, 0, "channel dwell time (ms) for AP/station scanning"); static int ath_calinterval = 30; /* calibrate every 30 secs */ SYSCTL_INT(_hw_ath, OID_AUTO, calibrate, CTLFLAG_RW, &ath_calinterval, 0, "chip calibration interval (secs)"); static int ath_outdoor = AH_TRUE; /* outdoor operation */ SYSCTL_INT(_hw_ath, OID_AUTO, outdoor, CTLFLAG_RD, &ath_outdoor, 0, "enable/disable outdoor operation"); static int ath_countrycode = CTRY_DEFAULT; /* country code */ SYSCTL_INT(_hw_ath, OID_AUTO, countrycode, CTLFLAG_RD, &ath_countrycode, 0, "country code"); static int ath_regdomain = 0; /* regulatory domain */ SYSCTL_INT(_hw_ath, OID_AUTO, regdomain, CTLFLAG_RD, &ath_regdomain, 0, "regulatory domain"); static int ath_bmisshack = 1; SYSCTL_INT(_hw_ath, OID_AUTO, bmisshack, CTLFLAG_RW, &ath_bmisshack, 0, "enable/disable hack to discard bmiss interrupts"); #ifdef AR_DEBUG int ath_debug = 0; SYSCTL_INT(_hw_ath, OID_AUTO, debug, CTLFLAG_RW, &ath_debug, 0, "control debugging printfs"); #define IFF_DUMPPKTS(_ifp) \ (ath_debug || \ ((_ifp)->if_flags & (IFF_DEBUG|IFF_LINK2)) == (IFF_DEBUG|IFF_LINK2)) static void ath_printrxbuf(struct ath_buf *bf, int); static void ath_printtxbuf(struct ath_buf *bf, int); #define DPRINTF(X) if (ath_debug) printf X #define DPRINTF2(X) if (ath_debug > 1) printf X #else #define IFF_DUMPPKTS(_ifp) \ (((_ifp)->if_flags & (IFF_DEBUG|IFF_LINK2)) == (IFF_DEBUG|IFF_LINK2)) #define DPRINTF(X) #define DPRINTF2(X) #endif int ath_attach(u_int16_t devid, struct ath_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; struct ath_hal *ah; HAL_STATUS status; int error = 0; DPRINTF(("ath_attach: devid 0x%x\n", devid)); /* set these up early for if_printf use */ ifp->if_unit = device_get_unit(sc->sc_dev); ifp->if_name = "ath"; ah = ath_hal_attach(devid, sc, sc->sc_st, sc->sc_sh, &status); if (ah == NULL) { if_printf(ifp, "unable to attach hardware; HAL status %u\n", status); error = ENXIO; goto bad; } sc->sc_ah = ah; /* * Collect the channel list using the default country * code and including outdoor channels. The 802.11 layer * is resposible for filtering this list based on settings * like the phy mode. */ error = ath_getchannels(sc, ath_countrycode, ath_outdoor); if (error != 0) goto bad; /* * Copy these back; they are set as a side effect * of constructing the channel list. */ ath_regdomain = ath_hal_getregdomain(ah); ath_countrycode = ath_hal_getcountrycode(ah); /* * Setup rate tables for all potential media types. */ ath_rate_setup(sc, IEEE80211_MODE_11A); ath_rate_setup(sc, IEEE80211_MODE_11B); ath_rate_setup(sc, IEEE80211_MODE_11G); ath_rate_setup(sc, IEEE80211_MODE_TURBO); error = ath_desc_alloc(sc); if (error != 0) { if_printf(ifp, "failed to allocate descriptors: %d\n", error); goto bad; } callout_init(&sc->sc_scan_ch, 0); callout_init(&sc->sc_cal_ch, 0); mtx_init(&sc->sc_txbuflock, device_get_nameunit(sc->sc_dev), "xmit buf q", MTX_DEF); mtx_init(&sc->sc_txqlock, device_get_nameunit(sc->sc_dev), "xmit q", MTX_DEF); TASK_INIT(&sc->sc_txtask, 0, ath_tx_proc, sc); TASK_INIT(&sc->sc_rxtask, 0, ath_rx_proc, sc); TASK_INIT(&sc->sc_swbatask, 0, ath_beacon_proc, sc); TASK_INIT(&sc->sc_rxorntask, 0, ath_rxorn_proc, sc); TASK_INIT(&sc->sc_fataltask, 0, ath_fatal_proc, sc); TASK_INIT(&sc->sc_bmisstask, 0, ath_bmiss_proc, sc); /* * For now just pre-allocate one data queue and one * beacon queue. Note that the HAL handles resetting * them at the needed time. Eventually we'll want to * allocate more tx queues for splitting management * frames and for QOS support. */ sc->sc_txhalq = ath_hal_setuptxqueue(ah, HAL_TX_QUEUE_DATA, AH_TRUE /* enable interrupts */ ); if (sc->sc_txhalq == (u_int) -1) { if_printf(ifp, "unable to setup a data xmit queue!\n"); goto bad; } sc->sc_bhalq = ath_hal_setuptxqueue(ah, HAL_TX_QUEUE_BEACON, AH_TRUE /* enable interrupts */ ); if (sc->sc_bhalq == (u_int) -1) { if_printf(ifp, "unable to setup a beacon xmit queue!\n"); goto bad; } ifp->if_softc = sc; ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST; ifp->if_start = ath_start; ifp->if_watchdog = ath_watchdog; ifp->if_ioctl = ath_ioctl; ifp->if_init = ath_init; ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; ic->ic_softc = sc; - ic->ic_newstate = ath_newstate; ic->ic_newassoc = ath_newassoc; /* XXX not right but it's not used anywhere important */ ic->ic_phytype = IEEE80211_T_OFDM; ic->ic_opmode = IEEE80211_M_STA; ic->ic_caps = IEEE80211_C_WEP | IEEE80211_C_IBSS | IEEE80211_C_HOSTAP; /* NB: 11g support is identified when we fetch the channel set */ if (sc->sc_have11g) ic->ic_caps |= IEEE80211_C_SHPREAMBLE; /* get mac address from hardware */ ath_hal_getmac(ah, ic->ic_myaddr); /* call MI attach routine. */ ieee80211_ifattach(ifp); /* override default methods */ ic->ic_node_alloc = ath_node_alloc; ic->ic_node_free = ath_node_free; ic->ic_node_copy = ath_node_copy; - + sc->sc_newstate = ic->ic_newstate; + ic->ic_newstate = ath_newstate; + /* complete initialization */ ieee80211_media_init(ifp, ath_media_change, ieee80211_media_status); if_printf(ifp, "802.11 address: %s\n", ether_sprintf(ic->ic_myaddr)); return 0; bad: if (ah) ath_hal_detach(ah); sc->sc_invalid = 1; return error; } int ath_detach(struct ath_softc *sc) { struct ifnet *ifp = &sc->sc_ic.ic_if; DPRINTF(("ath_detach: if_flags %x\n", ifp->if_flags)); mtx_lock(&sc->sc_mtx); ath_stop(ifp); ath_desc_free(sc); ath_hal_detach(sc->sc_ah); ieee80211_ifdetach(ifp); mtx_unlock(&sc->sc_mtx); return 0; } void ath_suspend(struct ath_softc *sc) { struct ifnet *ifp = &sc->sc_ic.ic_if; DPRINTF(("ath_suspend: if_flags %x\n", ifp->if_flags)); ath_stop(ifp); } void ath_resume(struct ath_softc *sc) { struct ifnet *ifp = &sc->sc_ic.ic_if; DPRINTF(("ath_resume: if_flags %x\n", ifp->if_flags)); ath_init(ifp); if (ifp->if_flags & IFF_UP) ath_start(ifp); } void ath_shutdown(struct ath_softc *sc) { struct ifnet *ifp = &sc->sc_ic.ic_if; DPRINTF(("ath_shutdown: if_flags %x\n", ifp->if_flags)); ath_stop(ifp); } void ath_intr(void *arg) { struct ath_softc *sc = arg; struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; struct ath_hal *ah = sc->sc_ah; HAL_INT status; if (sc->sc_invalid) { /* * The hardware is gone, don't touch anything. * XXX can this happen? */ DPRINTF(("ath_intr: invalid; ignored\n")); return; } if ((ifp->if_flags & (IFF_RUNNING|IFF_UP)) != (IFF_RUNNING|IFF_UP)) { DPRINTF(("ath_intr: if_flags 0x%x\n", ifp->if_flags)); ath_hal_getisr(ah, &status); /* clear ISR */ ath_hal_intrset(ah, 0); /* disable further intr's */ return; } ath_hal_getisr(ah, &status); /* NB: clears ISR too */ DPRINTF2(("ath_intr: status 0x%x\n", status)); if (ath_bmisshack) status &= ~HAL_INT_BMISS; /*XXX*/ #ifdef AR_DEBUG if (ath_debug && (status & (HAL_INT_FATAL|HAL_INT_RXORN|HAL_INT_BMISS))) { if_printf(ifp, "ath_intr: status 0x%x\n", status); ath_hal_dumpstate(ah); } #endif /* AR_DEBUG */ if (status & HAL_INT_FATAL) { sc->sc_stats.ast_hardware++; ath_hal_intrset(ah, 0); /* disable intr's until reset */ taskqueue_enqueue(taskqueue_swi, &sc->sc_fataltask); } else if (status & HAL_INT_RXORN) { sc->sc_stats.ast_rxorn++; ath_hal_intrset(ah, 0); /* disable intr's until reset */ taskqueue_enqueue(taskqueue_swi, &sc->sc_rxorntask); } else { if (status & HAL_INT_RXEOL) { /* * NB: the hardware should re-read the link when * RXE bit is written, but it doesn't work at * least on older hardware revs. */ sc->sc_stats.ast_rxeol++; sc->sc_rxlink = NULL; } if (status & HAL_INT_TXURN) { sc->sc_stats.ast_txurn++; /* bump tx trigger level */ ath_hal_updatetxtriglevel(ah, AH_TRUE); } if (status & HAL_INT_RX) taskqueue_enqueue(taskqueue_swi, &sc->sc_rxtask); if (status & HAL_INT_TX) taskqueue_enqueue(taskqueue_swi, &sc->sc_txtask); if (status & HAL_INT_SWBA) taskqueue_enqueue(taskqueue_swi, &sc->sc_swbatask); if (status & HAL_INT_BMISS) { sc->sc_stats.ast_bmiss++; taskqueue_enqueue(taskqueue_swi, &sc->sc_bmisstask); } } } static void ath_fatal_proc(void *arg, int pending) { struct ath_softc *sc = arg; device_printf(sc->sc_dev, "hardware error; resetting\n"); ath_reset(sc); } static void ath_rxorn_proc(void *arg, int pending) { struct ath_softc *sc = arg; device_printf(sc->sc_dev, "rx FIFO overrun; resetting\n"); ath_reset(sc); } static void ath_bmiss_proc(void *arg, int pending) { struct ath_softc *sc = arg; struct ieee80211com *ic = &sc->sc_ic; - struct ifnet *ifp = &ic->ic_if; DPRINTF(("ath_bmiss_proc: pending %u\n", pending)); KASSERT(ic->ic_opmode == IEEE80211_M_STA, ("unexpect operating mode %u", ic->ic_opmode)); if (ic->ic_state == IEEE80211_S_RUN) - ieee80211_new_state(ifp, IEEE80211_S_SCAN, -1); + ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); } static u_int ath_chan2flags(struct ieee80211com *ic, struct ieee80211_channel *chan) { static const u_int modeflags[] = { 0, /* IEEE80211_MODE_AUTO */ CHANNEL_A, /* IEEE80211_MODE_11A */ CHANNEL_B, /* IEEE80211_MODE_11B */ CHANNEL_PUREG, /* IEEE80211_MODE_11G */ CHANNEL_T /* IEEE80211_MODE_TURBO */ }; return modeflags[ieee80211_chan2mode(ic, chan)]; } static void ath_init(void *arg) { struct ath_softc *sc = (struct ath_softc *) arg; struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; struct ieee80211_node *ni; enum ieee80211_phymode mode; struct ath_hal *ah = sc->sc_ah; HAL_STATUS status; HAL_CHANNEL hchan; DPRINTF(("ath_init: if_flags 0x%x\n", ifp->if_flags)); mtx_lock(&sc->sc_mtx); /* * Stop anything previously setup. This is safe * whether this is the first time through or not. */ ath_stop(ifp); /* * The basic interface to setting the hardware in a good * state is ``reset''. On return the hardware is known to * be powered up and with interrupts disabled. This must * be followed by initialization of the appropriate bits * and then setup of the interrupt mask. */ hchan.channel = ic->ic_ibss_chan->ic_freq; hchan.channelFlags = ath_chan2flags(ic, ic->ic_ibss_chan); if (!ath_hal_reset(ah, ic->ic_opmode, &hchan, AH_FALSE, &status)) { if_printf(ifp, "unable to reset hardware; hal status %u\n", status); goto done; } /* * Setup the hardware after reset: the key cache * is filled as needed and the receive engine is * set going. Frame transmit is handled entirely * in the frame output path; there's nothing to do * here except setup the interrupt mask. */ if (ic->ic_flags & IEEE80211_F_WEPON) ath_initkeytable(sc); if (ath_startrecv(sc) != 0) { if_printf(ifp, "unable to start recv logic\n"); goto done; } /* * Enable interrupts. */ sc->sc_imask = HAL_INT_RX | HAL_INT_TX | HAL_INT_RXEOL | HAL_INT_RXORN | HAL_INT_FATAL | HAL_INT_GLOBAL; ath_hal_intrset(ah, sc->sc_imask); ifp->if_flags |= IFF_RUNNING; ic->ic_state = IEEE80211_S_INIT; /* * The hardware should be ready to go now so it's safe * to kick the 802.11 state machine as it's likely to * immediately call back to us to send mgmt frames. */ ni = ic->ic_bss; ni->ni_chan = ic->ic_ibss_chan; mode = ieee80211_chan2mode(ic, ni->ni_chan); if (mode != sc->sc_curmode) ath_setcurmode(sc, mode); - ieee80211_new_state(ifp, IEEE80211_S_SCAN, -1); + ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); done: mtx_unlock(&sc->sc_mtx); } static void ath_stop(struct ifnet *ifp) { + struct ieee80211com *ic = (struct ieee80211com *) ifp; struct ath_softc *sc = ifp->if_softc; struct ath_hal *ah = sc->sc_ah; DPRINTF(("ath_stop: invalid %u if_flags 0x%x\n", sc->sc_invalid, ifp->if_flags)); mtx_lock(&sc->sc_mtx); if (ifp->if_flags & IFF_RUNNING) { /* * Shutdown the hardware and driver: * disable interrupts * turn off timers * clear transmit machinery * clear receive machinery * drain and release tx queues * reclaim beacon resources * reset 802.11 state machine * power down hardware * * Note that some of this work is not possible if the * hardware is gone (invalid). */ ifp->if_flags &= ~IFF_RUNNING; ifp->if_timer = 0; if (!sc->sc_invalid) ath_hal_intrset(ah, 0); ath_draintxq(sc); if (!sc->sc_invalid) ath_stoprecv(sc); else sc->sc_rxlink = NULL; IF_DRAIN(&ifp->if_snd); ath_beacon_free(sc); - ieee80211_new_state(ifp, IEEE80211_S_INIT, -1); + ieee80211_new_state(ic, IEEE80211_S_INIT, -1); if (!sc->sc_invalid) ath_hal_setpower(ah, HAL_PM_FULL_SLEEP, 0); } mtx_unlock(&sc->sc_mtx); } /* * Reset the hardware w/o losing operational state. This is * basically a more efficient way of doing ath_stop, ath_init, * followed by state transitions to the current 802.11 * operational state. Used to recover from errors rx overrun * and to reset the hardware when rf gain settings must be reset. */ static void ath_reset(struct ath_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; struct ath_hal *ah = sc->sc_ah; struct ieee80211_channel *c; HAL_STATUS status; HAL_CHANNEL hchan; /* * Convert to a HAL channel description with the flags * constrained to reflect the current operating mode. */ c = ic->ic_ibss_chan; hchan.channel = c->ic_freq; hchan.channelFlags = ath_chan2flags(ic, c); ath_hal_intrset(ah, 0); /* disable interrupts */ ath_draintxq(sc); /* stop xmit side */ ath_stoprecv(sc); /* stop recv side */ /* NB: indicate channel change so we do a full reset */ if (!ath_hal_reset(ah, ic->ic_opmode, &hchan, AH_TRUE, &status)) if_printf(ifp, "%s: unable to reset hardware; hal status %u\n", __func__, status); ath_hal_intrset(ah, sc->sc_imask); if (ath_startrecv(sc) != 0) /* restart recv */ if_printf(ifp, "%s: unable to start recv logic\n", __func__); ath_start(ifp); /* restart xmit */ if (ic->ic_state == IEEE80211_S_RUN) ath_beacon_config(sc); /* restart beacons */ } static void ath_start(struct ifnet *ifp) { struct ath_softc *sc = ifp->if_softc; struct ath_hal *ah = sc->sc_ah; struct ieee80211com *ic = &sc->sc_ic; struct ieee80211_node *ni; struct ath_buf *bf; struct mbuf *m; struct ieee80211_frame *wh; if ((ifp->if_flags & IFF_RUNNING) == 0 || sc->sc_invalid) return; for (;;) { /* * Grab a TX buffer and associated resources. */ mtx_lock(&sc->sc_txbuflock); bf = TAILQ_FIRST(&sc->sc_txbuf); if (bf != NULL) TAILQ_REMOVE(&sc->sc_txbuf, bf, bf_list); mtx_unlock(&sc->sc_txbuflock); if (bf == NULL) { DPRINTF(("ath_start: out of xmit buffers\n")); sc->sc_stats.ast_tx_qstop++; ifp->if_flags |= IFF_OACTIVE; break; } /* * Poll the management queue for frames; they * have priority over normal data frames. */ IF_DEQUEUE(&ic->ic_mgtq, m); if (m == NULL) { /* * No data frames go out unless we're associated. */ if (ic->ic_state != IEEE80211_S_RUN) { DPRINTF(("ath_start: ignore data packet, " "state %u\n", ic->ic_state)); sc->sc_stats.ast_tx_discard++; mtx_lock(&sc->sc_txbuflock); TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list); mtx_unlock(&sc->sc_txbuflock); break; } IF_DEQUEUE(&ifp->if_snd, m); if (m == NULL) { mtx_lock(&sc->sc_txbuflock); TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list); mtx_unlock(&sc->sc_txbuflock); break; } ifp->if_opackets++; BPF_MTAP(ifp, m); /* * Encapsulate the packet in prep for transmission. */ m = ieee80211_encap(ifp, m); if (m == NULL) { DPRINTF(("ath_start: encapsulation failure\n")); sc->sc_stats.ast_tx_encap++; goto bad; } wh = mtod(m, struct ieee80211_frame *); if (ic->ic_flags & IEEE80211_F_WEPON) wh->i_fc[1] |= IEEE80211_FC1_WEP; } else { wh = mtod(m, struct ieee80211_frame *); if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_PROBE_RESP) { /* fill time stamp */ u_int64_t tsf; u_int32_t *tstamp; tsf = ath_hal_gettsf64(ah); /* XXX: adjust 100us delay to xmit */ tsf += 100; tstamp = (u_int32_t *)&wh[1]; tstamp[0] = htole32(tsf & 0xffffffff); tstamp[1] = htole32(tsf >> 32); } sc->sc_stats.ast_tx_mgmt++; } if (ic->ic_rawbpf) bpf_mtap(ic->ic_rawbpf, m); if (ic->ic_opmode != IEEE80211_M_STA) { ni = ieee80211_find_node(ic, wh->i_addr1); if (ni == NULL) { /* * When not in station mode the destination * address should always be in the node table * unless this is a multicast/broadcast frame. */ if (!IEEE80211_IS_MULTICAST(wh->i_addr1) && (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_DATA) { m_freem(m); sc->sc_stats.ast_tx_nonode++; goto bad; } ni = ic->ic_bss; } } else ni = ic->ic_bss; /* * TODO: * The duration field of 802.11 header should be filled. * XXX This may be done in the ieee80211 layer, but the upper * doesn't know the detail of parameters such as IFS * for now.. */ if (IFF_DUMPPKTS(ifp)) ieee80211_dump_pkt(mtod(m, u_int8_t *), m->m_len, ni->ni_rates.rs_rates[ni->ni_txrate] & IEEE80211_RATE_VAL, -1); if (ath_tx_start(sc, ni, bf, m)) { bad: mtx_lock(&sc->sc_txbuflock); TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list); mtx_unlock(&sc->sc_txbuflock); ifp->if_oerrors++; continue; } sc->sc_tx_timer = 5; ifp->if_timer = 1; } } static int ath_media_change(struct ifnet *ifp) { int error; error = ieee80211_media_change(ifp); if (error == ENETRESET) { if ((ifp->if_flags & (IFF_RUNNING|IFF_UP)) == (IFF_RUNNING|IFF_UP)) ath_init(ifp); /* XXX lose error */ error = 0; } return error; } static void ath_watchdog(struct ifnet *ifp) { struct ath_softc *sc = ifp->if_softc; struct ieee80211com *ic = &sc->sc_ic; ifp->if_timer = 0; if ((ifp->if_flags & IFF_RUNNING) == 0 || sc->sc_invalid) return; if (sc->sc_tx_timer) { if (--sc->sc_tx_timer == 0) { if_printf(ifp, "device timeout\n"); #ifdef AR_DEBUG if (ath_debug) ath_hal_dumpstate(sc->sc_ah); #endif /* AR_DEBUG */ ath_init(ifp); /* XXX ath_reset??? */ ifp->if_oerrors++; sc->sc_stats.ast_watchdog++; return; } ifp->if_timer = 1; } if (ic->ic_fixed_rate == -1) { /* * Run the rate control algorithm if we're not * locked at a fixed rate. */ if (ic->ic_opmode == IEEE80211_M_STA) ath_rate_ctl(sc, ic->ic_bss); else ieee80211_iterate_nodes(ic, ath_rate_ctl, sc); } ieee80211_watchdog(ifp); } static int ath_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) { struct ath_softc *sc = ifp->if_softc; struct ifreq *ifr = (struct ifreq *)data; int error = 0; mtx_lock(&sc->sc_mtx); switch (cmd) { case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { if (ifp->if_flags & IFF_RUNNING) { /* * To avoid rescanning another access point, * do not call ath_init() here. Instead, * only reflect promisc mode settings. */ ath_mode_init(sc); } else ath_init(ifp); /* XXX lose error */ } else ath_stop(ifp); break; case SIOCADDMULTI: case SIOCDELMULTI: /* * The upper layer has already installed/removed * the multicast address(es), just recalculate the * multicast filter for the card. */ if (ifp->if_flags & IFF_RUNNING) ath_mode_init(sc); break; case SIOCGATHSTATS: copyout(&sc->sc_stats, ifr->ifr_data, sizeof (sc->sc_stats)); break; default: error = ieee80211_ioctl(ifp, cmd, data); if (error == ENETRESET) { if ((ifp->if_flags & (IFF_RUNNING|IFF_UP)) == (IFF_RUNNING|IFF_UP)) ath_init(ifp); /* XXX lose error */ error = 0; } break; } mtx_unlock(&sc->sc_mtx); return error; } /* * Fill the hardware key cache with key entries. */ static void ath_initkeytable(struct ath_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; struct ath_hal *ah = sc->sc_ah; int i; for (i = 0; i < IEEE80211_WEP_NKID; i++) { struct ieee80211_wepkey *k = &ic->ic_nw_keys[i]; if (k->wk_len == 0) ath_hal_keyreset(ah, i); else /* XXX return value */ /* NB: this uses HAL_KEYVAL == ieee80211_wepkey */ ath_hal_keyset(ah, i, (const HAL_KEYVAL *) k); } } static void ath_mode_init(struct ath_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; struct ath_hal *ah = sc->sc_ah; struct ifnet *ifp = &ic->ic_if; u_int32_t rfilt, mfilt[2], val; u_int8_t pos; struct ifmultiaddr *ifma; /* configure operational mode */ ath_hal_setopmode(ah, ic->ic_opmode); /* receive filter */ rfilt = (ath_hal_getrxfilter(ah) & HAL_RX_FILTER_PHYERR) | HAL_RX_FILTER_UCAST | HAL_RX_FILTER_BCAST | HAL_RX_FILTER_MCAST; if (ic->ic_opmode != IEEE80211_M_HOSTAP && (ifp->if_flags & IFF_PROMISC)) rfilt |= HAL_RX_FILTER_PROM; if (ic->ic_state == IEEE80211_S_SCAN) rfilt |= HAL_RX_FILTER_BEACON; ath_hal_setrxfilter(ah, rfilt); /* calculate and install multicast filter */ if ((ifp->if_flags & IFF_ALLMULTI) == 0) { mfilt[0] = mfilt[1] = 0; TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { caddr_t dl; /* calculate XOR of eight 6bit values */ dl = LLADDR((struct sockaddr_dl *) ifma->ifma_addr); val = LE_READ_4(dl + 0); pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val; val = LE_READ_4(dl + 3); pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val; pos &= 0x3f; mfilt[pos / 32] |= (1 << (pos % 32)); } } else { mfilt[0] = mfilt[1] = ~0; } ath_hal_setmcastfilter(ah, mfilt[0], mfilt[1]); DPRINTF(("ath_mode_init: RX filter 0x%x, MC filter %08x:%08x\n", rfilt, mfilt[0], mfilt[1])); } static void ath_mbuf_load_cb(void *arg, bus_dma_segment_t *seg, int nseg, bus_size_t mapsize, int error) { struct ath_buf *bf = arg; KASSERT(nseg <= ATH_MAX_SCATTER, ("ath_mbuf_load_cb: too many DMA segments %u", nseg)); bf->bf_mapsize = mapsize; bf->bf_nseg = nseg; bcopy(seg, bf->bf_segs, nseg * sizeof (seg[0])); } static int ath_beacon_alloc(struct ath_softc *sc, struct ieee80211_node *ni) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; struct ath_hal *ah = sc->sc_ah; struct ieee80211_frame *wh; struct ath_buf *bf; struct ath_desc *ds; struct mbuf *m; int error, pktlen; u_int8_t *frm, rate; u_int16_t capinfo; struct ieee80211_rateset *rs; const HAL_RATE_TABLE *rt; bf = sc->sc_bcbuf; if (bf->bf_m != NULL) { bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap); m_freem(bf->bf_m); bf->bf_m = NULL; bf->bf_node = NULL; } /* * NB: the beacon data buffer must be 32-bit aligned; * we assume the mbuf routines will return us something * with this alignment (perhaps should assert). */ rs = &ni->ni_rates; pktlen = 8 + 2 + 2+ 2+ni->ni_esslen + 2+rs->rs_nrates + 6; if (rs->rs_nrates > IEEE80211_RATE_SIZE) pktlen += 2; if (pktlen <= MHLEN) MGETHDR(m, M_DONTWAIT, MT_DATA); else m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); if (m == NULL) { DPRINTF(("ath_beacon_alloc: cannot get mbuf/cluster; size %u\n", pktlen)); sc->sc_stats.ast_be_nombuf++; return ENOMEM; } wh = mtod(m, struct ieee80211_frame *); wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_BEACON; wh->i_fc[1] = IEEE80211_FC1_DIR_NODS; *(u_int16_t *)wh->i_dur = 0; memcpy(wh->i_addr1, ifp->if_broadcastaddr, IEEE80211_ADDR_LEN); memcpy(wh->i_addr2, ic->ic_myaddr, IEEE80211_ADDR_LEN); memcpy(wh->i_addr3, ni->ni_bssid, IEEE80211_ADDR_LEN); *(u_int16_t *)wh->i_seq = 0; /* * beacon frame format * [8] time stamp * [2] beacon interval * [2] cabability information * [tlv] ssid * [tlv] supported rates * [tlv] parameter set (IBSS) * [tlv] extended supported rates */ frm = (u_int8_t *)&wh[1]; memset(frm, 0, 8); /* timestamp is set by hardware */ frm += 8; *(u_int16_t *)frm = htole16(ni->ni_intval); frm += 2; if (ic->ic_opmode == IEEE80211_M_IBSS) capinfo = IEEE80211_CAPINFO_IBSS; else capinfo = IEEE80211_CAPINFO_ESS; if (ic->ic_flags & IEEE80211_F_WEPON) capinfo |= IEEE80211_CAPINFO_PRIVACY; if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE; if (ic->ic_flags & IEEE80211_F_SHSLOT) capinfo |= IEEE80211_CAPINFO_SHORT_SLOTTIME; *(u_int16_t *)frm = htole16(capinfo); frm += 2; *frm++ = IEEE80211_ELEMID_SSID; *frm++ = ni->ni_esslen; memcpy(frm, ni->ni_essid, ni->ni_esslen); frm += ni->ni_esslen; frm = ieee80211_add_rates(frm, rs); if (ic->ic_opmode == IEEE80211_M_IBSS) { *frm++ = IEEE80211_ELEMID_IBSSPARMS; *frm++ = 2; *frm++ = 0; *frm++ = 0; /* TODO: ATIM window */ } else { /* TODO: TIM */ *frm++ = IEEE80211_ELEMID_TIM; *frm++ = 4; /* length */ *frm++ = 0; /* DTIM count */ *frm++ = 1; /* DTIM period */ *frm++ = 0; /* bitmap control */ *frm++ = 0; /* Partial Virtual Bitmap (variable length) */ } frm = ieee80211_add_xrates(frm, rs); m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); DPRINTF2(("ath_beacon_alloc: m %p len %u\n", m, m->m_len)); error = bus_dmamap_load_mbuf(sc->sc_dmat, bf->bf_dmamap, m, ath_mbuf_load_cb, bf, BUS_DMA_NOWAIT); if (error != 0) { m_freem(m); return error; } KASSERT(bf->bf_nseg == 1, ("ath_beacon_alloc: multi-segment packet; nseg %u", bf->bf_nseg)); bf->bf_m = m; /* setup descriptors */ ds = bf->bf_desc; ds->ds_link = 0; ds->ds_data = bf->bf_segs[0].ds_addr; /* XXX verify mbuf data area covers this roundup */ /* * Calculate rate code. * XXX everything at min xmit rate */ rt = sc->sc_currates; KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) == 0) rate = rt->info[0].rateCode | rt->info[0].shortPreamble; else rate = rt->info[0].rateCode; ath_hal_setuptxdesc(ah, ds , m->m_pkthdr.len + IEEE80211_CRC_LEN /* packet length */ , sizeof(struct ieee80211_frame) /* header length */ , HAL_PKT_TYPE_BEACON /* Atheros packet type */ , 0x20 /* txpower XXX */ , rate, 1 /* series 0 rate/tries */ , HAL_TXKEYIX_INVALID /* no encryption */ , 0 /* antenna mode */ , HAL_TXDESC_NOACK /* no ack for beacons */ , 0 /* rts/cts rate */ , 0 /* rts/cts duration */ ); /* NB: beacon's BufLen must be a multiple of 4 bytes */ ath_hal_filltxdesc(ah, ds , roundup(bf->bf_segs[0].ds_len, 4) /* buffer length */ , AH_TRUE /* first segment */ , AH_TRUE /* last segment */ ); return 0; } static void ath_beacon_proc(void *arg, int pending) { struct ath_softc *sc = arg; struct ieee80211com *ic = &sc->sc_ic; struct ath_buf *bf = sc->sc_bcbuf; struct ath_hal *ah = sc->sc_ah; DPRINTF2(("%s: pending %u\n", __func__, pending)); if (ic->ic_opmode == IEEE80211_M_STA || bf == NULL || bf->bf_m == NULL) { DPRINTF(("%s: ic_flags=%x bf=%p bf_m=%p\n", __func__, ic->ic_flags, bf, bf ? bf->bf_m : NULL)); return; } /* update beacon to reflect PS poll state */ if (!ath_hal_stoptxdma(ah, sc->sc_bhalq)) { DPRINTF(("%s: beacon queue %u did not stop?", __func__, sc->sc_bhalq)); return; /* busy, XXX is this right? */ } bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE); ath_hal_puttxbuf(ah, sc->sc_bhalq, bf->bf_daddr); ath_hal_txstart(ah, sc->sc_bhalq); DPRINTF2(("%s: TXDP%u = %p (%p)\n", __func__, sc->sc_bhalq, (caddr_t)bf->bf_daddr, bf->bf_desc)); } static void ath_beacon_free(struct ath_softc *sc) { struct ath_buf *bf = sc->sc_bcbuf; if (bf->bf_m != NULL) { bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap); m_freem(bf->bf_m); bf->bf_m = NULL; bf->bf_node = NULL; } } /* * Configure the beacon and sleep timers. * * When operating as an AP this resets the TSF and sets * up the hardware to notify us when we need to issue beacons. * * When operating in station mode this sets up the beacon * timers according to the timestamp of the last received * beacon and the current TSF, configures PCF and DTIM * handling, programs the sleep registers so the hardware * will wakeup in time to receive beacons, and configures * the beacon miss handling so we'll receive a BMISS * interrupt when we stop seeing beacons from the AP * we've associated with. */ static void ath_beacon_config(struct ath_softc *sc) { struct ath_hal *ah = sc->sc_ah; struct ieee80211com *ic = &sc->sc_ic; struct ieee80211_node *ni = ic->ic_bss; u_int32_t nexttbtt; nexttbtt = (LE_READ_4(ni->ni_tstamp + 4) << 22) | (LE_READ_4(ni->ni_tstamp) >> 10); DPRINTF(("%s: nexttbtt=%u\n", __func__, nexttbtt)); nexttbtt += ni->ni_intval; if (ic->ic_opmode != IEEE80211_M_HOSTAP) { HAL_BEACON_STATE bs; u_int32_t bmisstime; /* NB: no PCF support right now */ memset(&bs, 0, sizeof(bs)); bs.bs_intval = ni->ni_intval; bs.bs_nexttbtt = nexttbtt; bs.bs_dtimperiod = bs.bs_intval; bs.bs_nextdtim = nexttbtt; /* * Calculate the number of consecutive beacons to miss * before taking a BMISS interrupt. The configuration * is specified in ms, so we need to convert that to * TU's and then calculate based on the beacon interval. * Note that we clamp the result to at most 10 beacons. */ bmisstime = (ic->ic_bmisstimeout * 1000) / 1024; bs.bs_bmissthreshold = howmany(bmisstime,ni->ni_intval); if (bs.bs_bmissthreshold > 10) bs.bs_bmissthreshold = 10; else if (bs.bs_bmissthreshold <= 0) bs.bs_bmissthreshold = 1; /* * Calculate sleep duration. The configuration is * given in ms. We insure a multiple of the beacon * period is used. Also, if the sleep duration is * greater than the DTIM period then it makes senses * to make it a multiple of that. * * XXX fixed at 100ms */ bs.bs_sleepduration = roundup((100 * 1000) / 1024, bs.bs_intval); if (bs.bs_sleepduration > bs.bs_dtimperiod) bs.bs_sleepduration = roundup(bs.bs_sleepduration, bs.bs_dtimperiod); DPRINTF(("%s: intval %u nexttbtt %u dtim %u nextdtim %u bmiss %u sleep %u\n" , __func__ , bs.bs_intval , bs.bs_nexttbtt , bs.bs_dtimperiod , bs.bs_nextdtim , bs.bs_bmissthreshold , bs.bs_sleepduration )); ath_hal_intrset(ah, 0); /* * Reset our tsf so the hardware will update the * tsf register to reflect timestamps found in * received beacons. */ ath_hal_resettsf(ah); ath_hal_beacontimers(ah, &bs, 0/*XXX*/, 0, 0); sc->sc_imask |= HAL_INT_BMISS; ath_hal_intrset(ah, sc->sc_imask); } else { DPRINTF(("%s: intval %u nexttbtt %u\n", __func__, ni->ni_intval, nexttbtt)); ath_hal_intrset(ah, 0); ath_hal_beaconinit(ah, ic->ic_opmode, nexttbtt, ni->ni_intval); sc->sc_imask |= HAL_INT_SWBA; /* beacon prepare */ ath_hal_intrset(ah, sc->sc_imask); } } static void ath_load_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error) { bus_addr_t *paddr = (bus_addr_t*) arg; *paddr = segs->ds_addr; } static int ath_desc_alloc(struct ath_softc *sc) { int i, bsize, error; struct ath_desc *ds; struct ath_buf *bf; /* allocate descriptors */ sc->sc_desc_len = sizeof(struct ath_desc) * (ATH_TXBUF * ATH_TXDESC + ATH_RXBUF + 1); error = bus_dmamap_create(sc->sc_dmat, BUS_DMA_NOWAIT, &sc->sc_ddmamap); if (error != 0) return error; error = bus_dmamem_alloc(sc->sc_dmat, (void**) &sc->sc_desc, BUS_DMA_NOWAIT, &sc->sc_ddmamap); if (error != 0) goto fail0; error = bus_dmamap_load(sc->sc_dmat, sc->sc_ddmamap, sc->sc_desc, sc->sc_desc_len, ath_load_cb, &sc->sc_desc_paddr, BUS_DMA_NOWAIT); if (error != 0) goto fail1; ds = sc->sc_desc; DPRINTF(("ath_desc_alloc: DMA map: %p (%d) -> %p (%lu)\n", ds, sc->sc_desc_len, (caddr_t) sc->sc_desc_paddr, /*XXX*/ (u_long) sc->sc_desc_len)); /* allocate buffers */ bsize = sizeof(struct ath_buf) * (ATH_TXBUF + ATH_RXBUF + 1); bf = malloc(bsize, M_DEVBUF, M_NOWAIT | M_ZERO); if (bf == NULL) goto fail2; sc->sc_bufptr = bf; TAILQ_INIT(&sc->sc_rxbuf); for (i = 0; i < ATH_RXBUF; i++, bf++, ds++) { bf->bf_desc = ds; bf->bf_daddr = sc->sc_desc_paddr + ((caddr_t)ds - (caddr_t)sc->sc_desc); error = bus_dmamap_create(sc->sc_dmat, BUS_DMA_NOWAIT, &bf->bf_dmamap); if (error != 0) break; TAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list); } TAILQ_INIT(&sc->sc_txbuf); for (i = 0; i < ATH_TXBUF; i++, bf++, ds += ATH_TXDESC) { bf->bf_desc = ds; bf->bf_daddr = sc->sc_desc_paddr + ((caddr_t)ds - (caddr_t)sc->sc_desc); error = bus_dmamap_create(sc->sc_dmat, BUS_DMA_NOWAIT, &bf->bf_dmamap); if (error != 0) break; TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list); } TAILQ_INIT(&sc->sc_txq); /* beacon buffer */ bf->bf_desc = ds; bf->bf_daddr = sc->sc_desc_paddr + ((caddr_t)ds - (caddr_t)sc->sc_desc); error = bus_dmamap_create(sc->sc_dmat, BUS_DMA_NOWAIT, &bf->bf_dmamap); if (error != 0) return error; sc->sc_bcbuf = bf; return 0; fail2: bus_dmamap_unload(sc->sc_dmat, sc->sc_ddmamap); fail1: bus_dmamem_free(sc->sc_dmat, sc->sc_desc, sc->sc_ddmamap); fail0: bus_dmamap_destroy(sc->sc_dmat, sc->sc_ddmamap); sc->sc_ddmamap = NULL; return error; } static void ath_desc_free(struct ath_softc *sc) { struct ath_buf *bf; bus_dmamap_unload(sc->sc_dmat, sc->sc_ddmamap); bus_dmamem_free(sc->sc_dmat, sc->sc_desc, sc->sc_ddmamap); bus_dmamap_destroy(sc->sc_dmat, sc->sc_ddmamap); TAILQ_FOREACH(bf, &sc->sc_txq, bf_list) { bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap); bus_dmamap_destroy(sc->sc_dmat, bf->bf_dmamap); m_freem(bf->bf_m); } TAILQ_FOREACH(bf, &sc->sc_txbuf, bf_list) bus_dmamap_destroy(sc->sc_dmat, bf->bf_dmamap); TAILQ_FOREACH(bf, &sc->sc_rxbuf, bf_list) { if (bf->bf_m) { bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap); bus_dmamap_destroy(sc->sc_dmat, bf->bf_dmamap); m_freem(bf->bf_m); bf->bf_m = NULL; } } if (sc->sc_bcbuf != NULL) { bus_dmamap_unload(sc->sc_dmat, sc->sc_bcbuf->bf_dmamap); bus_dmamap_destroy(sc->sc_dmat, sc->sc_bcbuf->bf_dmamap); sc->sc_bcbuf = NULL; } TAILQ_INIT(&sc->sc_rxbuf); TAILQ_INIT(&sc->sc_txbuf); TAILQ_INIT(&sc->sc_txq); free(sc->sc_bufptr, M_DEVBUF); sc->sc_bufptr = NULL; } static struct ieee80211_node * ath_node_alloc(struct ieee80211com *ic) { struct ath_node *an = malloc(sizeof(struct ath_node), M_DEVBUF, M_NOWAIT | M_ZERO); return an ? &an->st_node : NULL; } static void ath_node_free(struct ieee80211com *ic, struct ieee80211_node *ni) { struct ath_softc *sc = ic->ic_if.if_softc; struct ath_buf *bf; TAILQ_FOREACH(bf, &sc->sc_txq, bf_list) { if (bf->bf_node == ni) bf->bf_node = NULL; } free(ni, M_DEVBUF); } static void ath_node_copy(struct ieee80211com *ic, struct ieee80211_node *dst, const struct ieee80211_node *src) { *(struct ath_node *)dst = *(const struct ath_node *)src; } static int ath_rxbuf_init(struct ath_softc *sc, struct ath_buf *bf) { struct ath_hal *ah = sc->sc_ah; int error; struct mbuf *m; struct ath_desc *ds; m = bf->bf_m; if (m == NULL) { /* * NB: by assigning a page to the rx dma buffer we * implicitly satisfy the Atheros requirement that * this buffer be cache-line-aligned and sized to be * multiple of the cache line size. Not doing this * causes weird stuff to happen (for the 5210 at least). */ m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); if (m == NULL) { DPRINTF(("ath_rxbuf_init: no mbuf/cluster\n")); sc->sc_stats.ast_rx_nombuf++; return ENOMEM; } bf->bf_m = m; m->m_pkthdr.len = m->m_len = m->m_ext.ext_size; error = bus_dmamap_load_mbuf(sc->sc_dmat, bf->bf_dmamap, m, ath_mbuf_load_cb, bf, BUS_DMA_NOWAIT); if (error != 0) { DPRINTF(("ath_rxbuf_init: bus_dmamap_load_mbuf failed;" " error %d\n", error)); sc->sc_stats.ast_rx_busdma++; return error; } KASSERT(bf->bf_nseg == 1, ("ath_rxbuf_init: multi-segment packet; nseg %u", bf->bf_nseg)); } bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREREAD); /* setup descriptors */ ds = bf->bf_desc; ds->ds_link = 0; ds->ds_data = bf->bf_segs[0].ds_addr; ath_hal_setuprxdesc(ah, ds , m->m_len /* buffer size */ , 0 ); if (sc->sc_rxlink != NULL) *sc->sc_rxlink = bf->bf_daddr; sc->sc_rxlink = &ds->ds_link; return 0; } static void ath_rx_proc(void *arg, int npending) { struct ath_softc *sc = arg; struct ath_buf *bf; struct ifnet *ifp = &sc->sc_ic.ic_if; struct ath_hal *ah = sc->sc_ah; struct ath_desc *ds; struct mbuf *m; struct ieee80211_frame *wh, whbuf; int len; u_int phyerr; HAL_STATUS status; DPRINTF2(("ath_rx_proc: pending %u\n", npending)); do { bf = TAILQ_FIRST(&sc->sc_rxbuf); if (bf == NULL) { /* NB: shouldn't happen */ if_printf(ifp, "ath_rx_proc: no buffer!\n"); break; } m = bf->bf_m; if (m == NULL) { /* NB: shouldn't happen */ if_printf(ifp, "ath_rx_proc: no mbuf!\n"); continue; } ds = bf->bf_desc; status = ath_hal_rxprocdesc(ah, ds); #ifdef AR_DEBUG if (ath_debug > 1) ath_printrxbuf(bf, status == HAL_OK); #endif if (status == HAL_EINPROGRESS) break; TAILQ_REMOVE(&sc->sc_rxbuf, bf, bf_list); if (ds->ds_rxstat.rs_status != 0) { ifp->if_ierrors++; if (ds->ds_rxstat.rs_status & HAL_RXERR_CRC) sc->sc_stats.ast_rx_crcerr++; if (ds->ds_rxstat.rs_status & HAL_RXERR_FIFO) sc->sc_stats.ast_rx_fifoerr++; if (ds->ds_rxstat.rs_status & HAL_RXERR_DECRYPT) sc->sc_stats.ast_rx_badcrypt++; if (ds->ds_rxstat.rs_status & HAL_RXERR_PHY) { sc->sc_stats.ast_rx_phyerr++; phyerr = ds->ds_rxstat.rs_phyerr & 0x1f; sc->sc_stats.ast_rx_phy[phyerr]++; } goto rx_next; } len = ds->ds_rxstat.rs_datalen; if (len < sizeof(struct ieee80211_frame)) { DPRINTF(("ath_rx_proc: short packet %d\n", len)); goto rx_next; } bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_POSTREAD); wh = mtod(m, struct ieee80211_frame *); if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL) { /* * Ignore control frame received in promisc mode. */ DPRINTF(("ath_rx_proc: control frame\n")); goto rx_next; } bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap); bf->bf_m = NULL; m->m_pkthdr.rcvif = ifp; m->m_pkthdr.len = m->m_len = len; if (IFF_DUMPPKTS(ifp)) { struct ieee80211com *ic = &sc->sc_ic; const HAL_RATE_TABLE *rt = sc->sc_rates[ic->ic_curmode]; ieee80211_dump_pkt(mtod(m, u_int8_t *), len, rt ? rt->info[rt->rateCodeToIndex[ds->ds_rxstat.rs_rate]].dot11Rate & IEEE80211_RATE_VAL : 0, ds->ds_rxstat.rs_rssi); } m_adj(m, -IEEE80211_CRC_LEN); if (wh->i_fc[1] & IEEE80211_FC1_WEP) { /* * WEP is decrypted by hardware. Clear WEP bit * and trim WEP header for ieee80211_input(). */ wh->i_fc[1] &= ~IEEE80211_FC1_WEP; memcpy(&whbuf, wh, sizeof(whbuf)); m_adj(m, IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN); memcpy(mtod(m, caddr_t), &whbuf, sizeof(whbuf)); /* * Also trim WEP ICV from the tail. */ m_adj(m, -IEEE80211_WEP_CRCLEN); } ieee80211_input(ifp, m, ds->ds_rxstat.rs_rssi, ds->ds_rxstat.rs_tstamp, ds->ds_rxstat.rs_antenna); rx_next: TAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list); } while (ath_rxbuf_init(sc, bf) == 0); ath_hal_rxmonitor(ah); /* rx signal state monitoring */ ath_hal_rxena(ah); /* in case of RXEOL */ } /* * XXX Size of an ACK control frame in bytes. */ #define IEEE80211_ACK_SIZE (2+2+IEEE80211_ADDR_LEN+4) static int ath_tx_start(struct ath_softc *sc, struct ieee80211_node *ni, struct ath_buf *bf, struct mbuf *m0) { struct ieee80211com *ic = &sc->sc_ic; struct ath_hal *ah = sc->sc_ah; struct ifnet *ifp = &sc->sc_ic.ic_if; int i, error, iswep, hdrlen, pktlen; u_int8_t rix, cix, txrate, ctsrate; struct ath_desc *ds; struct mbuf *m; struct ieee80211_frame *wh; u_int32_t iv; u_int8_t *ivp; u_int8_t hdrbuf[sizeof(struct ieee80211_frame) + IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN]; u_int subtype, flags, ctsduration, antenna; HAL_PKT_TYPE atype; const HAL_RATE_TABLE *rt; HAL_BOOL shortPreamble; struct ath_node *an; wh = mtod(m0, struct ieee80211_frame *); iswep = wh->i_fc[1] & IEEE80211_FC1_WEP; hdrlen = sizeof(struct ieee80211_frame); pktlen = m0->m_pkthdr.len; if (iswep) { memcpy(hdrbuf, mtod(m0, caddr_t), hdrlen); m_adj(m0, hdrlen); M_PREPEND(m0, sizeof(hdrbuf), M_DONTWAIT); if (m0 == NULL) { sc->sc_stats.ast_tx_nombuf++; return ENOMEM; } ivp = hdrbuf + hdrlen; /* * XXX * IV must not duplicate during the lifetime of the key. * But no mechanism to renew keys is defined in IEEE 802.11 * WEP. And IV may be duplicated between other stations * because of the session key itself is shared. * So we use pseudo random IV for now, though it is not the * right way. */ iv = arc4random(); for (i = 0; i < IEEE80211_WEP_IVLEN; i++) { ivp[i] = iv; iv >>= 8; } ivp[i] = sc->sc_ic.ic_wep_txkey << 6; /* Key ID and pad */ memcpy(mtod(m0, caddr_t), hdrbuf, sizeof(hdrbuf)); /* * The ICV length must be included into hdrlen and pktlen. */ hdrlen = sizeof(hdrbuf) + IEEE80211_WEP_CRCLEN; pktlen = m0->m_pkthdr.len + IEEE80211_WEP_CRCLEN; } pktlen += IEEE80211_CRC_LEN; /* * Load the DMA map so any coalescing is done. This * also calculates the number of descriptors we need. */ error = bus_dmamap_load_mbuf(sc->sc_dmat, bf->bf_dmamap, m0, ath_mbuf_load_cb, bf, BUS_DMA_NOWAIT); if (error != 0) { sc->sc_stats.ast_tx_busdma++; m_freem(m0); return error; } /* * Discard null packets and check for packets that * require too many TX descriptors. We try to convert * the latter to a cluster. */ if (bf->bf_nseg > ATH_TXDESC) { /* too many desc's, linearize */ sc->sc_stats.ast_tx_linear++; MGETHDR(m, M_DONTWAIT, MT_DATA); if (m == NULL) { sc->sc_stats.ast_tx_nombuf++; m_freem(m0); return ENOMEM; } M_MOVE_PKTHDR(m, m0); MCLGET(m, M_DONTWAIT); if ((m->m_flags & M_EXT) == 0) { sc->sc_stats.ast_tx_nomcl++; m_freem(m0); m_free(m); return ENOMEM; } m_copydata(m0, 0, m0->m_pkthdr.len, mtod(m, caddr_t)); m_freem(m0); m->m_len = m->m_pkthdr.len; m0 = m; error = bus_dmamap_load_mbuf(sc->sc_dmat, bf->bf_dmamap, m0, ath_mbuf_load_cb, bf, BUS_DMA_NOWAIT); if (error != 0) { sc->sc_stats.ast_tx_busdma++; m_freem(m0); return error; } KASSERT(bf->bf_nseg == 1, ("ath_tx_start: packet not one segment; nseg %u", bf->bf_nseg)); } else if (bf->bf_nseg == 0) { /* null packet, discard */ sc->sc_stats.ast_tx_nodata++; m_freem(m0); return EIO; } DPRINTF2(("ath_tx_start: m %p len %u\n", m0, pktlen)); bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_PREWRITE); bf->bf_m = m0; bf->bf_node = ni; /* setup descriptors */ ds = bf->bf_desc; rt = sc->sc_currates; KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); /* * Calculate Atheros packet type from IEEE80211 packet header * and setup for rate calculations. */ atype = HAL_PKT_TYPE_NORMAL; /* default */ switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) { case IEEE80211_FC0_TYPE_MGT: subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) atype = HAL_PKT_TYPE_BEACON; else if (subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP) atype = HAL_PKT_TYPE_PROBE_RESP; else if (subtype == IEEE80211_FC0_SUBTYPE_ATIM) atype = HAL_PKT_TYPE_ATIM; rix = 0; /* XXX lowest rate */ break; case IEEE80211_FC0_TYPE_CTL: subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; if (subtype == IEEE80211_FC0_SUBTYPE_PS_POLL) atype = HAL_PKT_TYPE_PSPOLL; rix = 0; /* XXX lowest rate */ break; default: rix = sc->sc_rixmap[ni->ni_rates.rs_rates[ni->ni_txrate] & IEEE80211_RATE_VAL]; if (rix == 0xff) { if_printf(ifp, "bogus xmit rate 0x%x\n", ni->ni_rates.rs_rates[ni->ni_txrate]); sc->sc_stats.ast_tx_badrate++; m_freem(m0); return EIO; } break; } /* * NB: the 802.11 layer marks whether or not we should * use short preamble based on the current mode and * negotiated parameters. */ if (ic->ic_flags & IEEE80211_F_SHPREAMBLE) { txrate = rt->info[rix].rateCode | rt->info[rix].shortPreamble; shortPreamble = AH_TRUE; sc->sc_stats.ast_tx_shortpre++; } else { txrate = rt->info[rix].rateCode; shortPreamble = AH_FALSE; } /* * Calculate miscellaneous flags. */ flags = HAL_TXDESC_CLRDMASK; /* XXX needed for wep errors */ if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { flags |= HAL_TXDESC_NOACK; /* no ack on broad/multicast */ sc->sc_stats.ast_tx_noack++; } else if (pktlen > ic->ic_rtsthreshold) { flags |= HAL_TXDESC_RTSENA; /* RTS based on frame length */ sc->sc_stats.ast_tx_rts++; } /* * Calculate RTS/CTS rate and duration if needed. */ ctsduration = 0; if (flags & (HAL_TXDESC_RTSENA|HAL_TXDESC_CTSENA)) { /* * CTS transmit rate is derived from the transmit rate * by looking in the h/w rate table. We must also factor * in whether or not a short preamble is to be used. */ cix = rt->info[rix].controlRate; ctsrate = rt->info[cix].rateCode; if (shortPreamble) ctsrate |= rt->info[cix].shortPreamble; /* * Compute the transmit duration based on the size * of an ACK frame. We call into the HAL to do the * computation since it depends on the characteristics * of the actual PHY being used. */ if (flags & HAL_TXDESC_RTSENA) { /* SIFS + CTS */ ctsduration += ath_hal_computetxtime(ah, rt, IEEE80211_ACK_SIZE, cix, shortPreamble); } /* SIFS + data */ ctsduration += ath_hal_computetxtime(ah, rt, pktlen, rix, shortPreamble); if ((flags & HAL_TXDESC_NOACK) == 0) { /* SIFS + ACK */ ctsduration += ath_hal_computetxtime(ah, rt, IEEE80211_ACK_SIZE, cix, shortPreamble); } } else ctsrate = 0; /* * For now use the antenna on which the last good * frame was received on. We assume this field is * initialized to 0 which gives us ``auto'' or the * ``default'' antenna. */ an = (struct ath_node *) ni; if (an->an_tx_antenna) antenna = an->an_tx_antenna; else antenna = ni->ni_rantenna; /* * Formulate first tx descriptor with tx controls. */ /* XXX check return value? */ ath_hal_setuptxdesc(ah, ds , pktlen /* packet length */ , hdrlen /* header length */ , atype /* Atheros packet type */ , 60 /* txpower XXX */ , txrate, 1+10 /* series 0 rate/tries */ , iswep ? sc->sc_ic.ic_wep_txkey : HAL_TXKEYIX_INVALID , antenna /* antenna mode */ , flags /* flags */ , ctsrate /* rts/cts rate */ , ctsduration /* rts/cts duration */ ); #ifdef notyet ath_hal_setupxtxdesc(ah, ds , AH_FALSE /* short preamble */ , 0, 0 /* series 1 rate/tries */ , 0, 0 /* series 2 rate/tries */ , 0, 0 /* series 3 rate/tries */ ); #endif /* * Fillin the remainder of the descriptor info. */ for (i = 0; i < bf->bf_nseg; i++, ds++) { ds->ds_data = bf->bf_segs[i].ds_addr; if (i == bf->bf_nseg - 1) ds->ds_link = 0; else ds->ds_link = bf->bf_daddr + sizeof(*ds) * (i + 1); ath_hal_filltxdesc(ah, ds , bf->bf_segs[i].ds_len /* segment length */ , i == 0 /* first segment */ , i == bf->bf_nseg - 1 /* last segment */ ); DPRINTF2(("ath_tx_start: %d: %08x %08x %08x %08x %08x %08x\n", i, ds->ds_link, ds->ds_data, ds->ds_ctl0, ds->ds_ctl1, ds->ds_hw[0], ds->ds_hw[1])); } /* * Insert the frame on the outbound list and * pass it on to the hardware. */ mtx_lock(&sc->sc_txqlock); TAILQ_INSERT_TAIL(&sc->sc_txq, bf, bf_list); if (sc->sc_txlink == NULL) { ath_hal_puttxbuf(ah, sc->sc_txhalq, bf->bf_daddr); DPRINTF2(("ath_tx_start: TXDP0 = %p (%p)\n", (caddr_t)bf->bf_daddr, bf->bf_desc)); } else { *sc->sc_txlink = bf->bf_daddr; DPRINTF2(("ath_tx_start: link(%p)=%p (%p)\n", sc->sc_txlink, (caddr_t)bf->bf_daddr, bf->bf_desc)); } sc->sc_txlink = &bf->bf_desc[bf->bf_nseg - 1].ds_link; mtx_unlock(&sc->sc_txqlock); ath_hal_txstart(ah, sc->sc_txhalq); return 0; } static void ath_tx_proc(void *arg, int npending) { struct ath_softc *sc = arg; struct ath_hal *ah = sc->sc_ah; struct ath_buf *bf; struct ifnet *ifp = &sc->sc_ic.ic_if; struct ath_desc *ds; struct ieee80211_node *ni; struct ath_node *an; int sr, lr; HAL_STATUS status; DPRINTF2(("ath_tx_proc: pending %u tx queue %p, link %p\n", npending, (caddr_t) ath_hal_gettxbuf(sc->sc_ah, sc->sc_txhalq), sc->sc_txlink)); for (;;) { mtx_lock(&sc->sc_txqlock); bf = TAILQ_FIRST(&sc->sc_txq); if (bf == NULL) { sc->sc_txlink = NULL; mtx_unlock(&sc->sc_txqlock); break; } /* only the last descriptor is needed */ ds = &bf->bf_desc[bf->bf_nseg - 1]; status = ath_hal_txprocdesc(ah, ds); #ifdef AR_DEBUG if (ath_debug > 1) ath_printtxbuf(bf, status == HAL_OK); #endif if (status == HAL_EINPROGRESS) { mtx_unlock(&sc->sc_txqlock); break; } TAILQ_REMOVE(&sc->sc_txq, bf, bf_list); mtx_unlock(&sc->sc_txqlock); ni = bf->bf_node; if (ni != NULL) { an = (struct ath_node *) ni; if (ds->ds_txstat.ts_status == 0) { an->an_tx_ok++; an->an_tx_antenna = ds->ds_txstat.ts_antenna; } else { an->an_tx_err++; ifp->if_oerrors++; if (ds->ds_txstat.ts_status & HAL_TXERR_XRETRY) sc->sc_stats.ast_tx_xretries++; if (ds->ds_txstat.ts_status & HAL_TXERR_FIFO) sc->sc_stats.ast_tx_fifoerr++; if (ds->ds_txstat.ts_status & HAL_TXERR_FILT) sc->sc_stats.ast_tx_filtered++; an->an_tx_antenna = 0; /* invalidate */ } sr = ds->ds_txstat.ts_shortretry; lr = ds->ds_txstat.ts_longretry; sc->sc_stats.ast_tx_shortretry += sr; sc->sc_stats.ast_tx_longretry += lr; if (sr + lr) an->an_tx_retr++; } bus_dmamap_sync(sc->sc_dmat, bf->bf_dmamap, BUS_DMASYNC_POSTWRITE); bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap); m_freem(bf->bf_m); bf->bf_m = NULL; bf->bf_node = NULL; mtx_lock(&sc->sc_txbuflock); TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list); mtx_unlock(&sc->sc_txbuflock); } ifp->if_flags &= ~IFF_OACTIVE; sc->sc_tx_timer = 0; ath_start(ifp); } /* * Drain the transmit queue and reclaim resources. */ static void ath_draintxq(struct ath_softc *sc) { struct ath_hal *ah = sc->sc_ah; struct ifnet *ifp = &sc->sc_ic.ic_if; struct ath_buf *bf; /* XXX return value */ if (!sc->sc_invalid) { /* don't touch the hardware if marked invalid */ (void) ath_hal_stoptxdma(ah, sc->sc_txhalq); DPRINTF(("ath_draintxq: tx queue %p, link %p\n", (caddr_t) ath_hal_gettxbuf(ah, sc->sc_txhalq), sc->sc_txlink)); (void) ath_hal_stoptxdma(ah, sc->sc_bhalq); DPRINTF(("ath_draintxq: beacon queue %p\n", (caddr_t) ath_hal_gettxbuf(ah, sc->sc_bhalq))); } for (;;) { mtx_lock(&sc->sc_txqlock); bf = TAILQ_FIRST(&sc->sc_txq); if (bf == NULL) { sc->sc_txlink = NULL; mtx_unlock(&sc->sc_txqlock); break; } TAILQ_REMOVE(&sc->sc_txq, bf, bf_list); mtx_unlock(&sc->sc_txqlock); #ifdef AR_DEBUG if (ath_debug) ath_printtxbuf(bf, ath_hal_txprocdesc(ah, bf->bf_desc) == HAL_OK); #endif /* AR_DEBUG */ bus_dmamap_unload(sc->sc_dmat, bf->bf_dmamap); m_freem(bf->bf_m); bf->bf_m = NULL; bf->bf_node = NULL; mtx_lock(&sc->sc_txbuflock); TAILQ_INSERT_TAIL(&sc->sc_txbuf, bf, bf_list); mtx_unlock(&sc->sc_txbuflock); } ifp->if_flags &= ~IFF_OACTIVE; sc->sc_tx_timer = 0; } /* * Disable the receive h/w in preparation for a reset. */ static void ath_stoprecv(struct ath_softc *sc) { struct ath_hal *ah = sc->sc_ah; ath_hal_stoppcurecv(ah); /* disable PCU */ ath_hal_setrxfilter(ah, 0); /* clear recv filter */ ath_hal_stopdmarecv(ah); /* disable DMA engine */ DELAY(3000); /* long enough for 1 frame */ #ifdef AR_DEBUG if (ath_debug) { struct ath_buf *bf; DPRINTF(("ath_stoprecv: rx queue %p, link %p\n", (caddr_t) ath_hal_getrxbuf(ah), sc->sc_rxlink)); TAILQ_FOREACH(bf, &sc->sc_rxbuf, bf_list) { if (ath_hal_rxprocdesc(ah, bf->bf_desc) == HAL_OK) ath_printrxbuf(bf, 1); } } #endif sc->sc_rxlink = NULL; /* just in case */ } /* * Enable the receive h/w following a reset. */ static int ath_startrecv(struct ath_softc *sc) { struct ath_hal *ah = sc->sc_ah; struct ath_buf *bf; sc->sc_rxlink = NULL; TAILQ_FOREACH(bf, &sc->sc_rxbuf, bf_list) { int error = ath_rxbuf_init(sc, bf); if (error != 0) { DPRINTF(("ath_startrecv: ath_rxbuf_init failed %d\n", error)); return error; } } bf = TAILQ_FIRST(&sc->sc_rxbuf); ath_hal_putrxbuf(ah, bf->bf_daddr); ath_hal_rxena(ah); /* enable recv descriptors */ ath_mode_init(sc); /* set filters, etc. */ ath_hal_startpcurecv(ah); /* re-enable PCU/DMA engine */ return 0; } /* * Set/change channels. If the channel is really being changed, * it's done by resetting the chip. To accomplish this we must * first cleanup any pending DMA, then restart stuff after a la * ath_init. */ static int ath_chan_set(struct ath_softc *sc, struct ieee80211_channel *chan) { struct ath_hal *ah = sc->sc_ah; struct ieee80211com *ic = &sc->sc_ic; DPRINTF(("ath_chan_set: %u (%u MHz) -> %u (%u MHz)\n", ieee80211_chan2ieee(ic, ic->ic_ibss_chan), ic->ic_ibss_chan->ic_freq, ieee80211_chan2ieee(ic, chan), chan->ic_freq)); if (chan != ic->ic_ibss_chan) { HAL_STATUS status; HAL_CHANNEL hchan; enum ieee80211_phymode mode; /* * To switch channels clear any pending DMA operations; * wait long enough for the RX fifo to drain, reset the * hardware at the new frequency, and then re-enable * the relevant bits of the h/w. */ ath_hal_intrset(ah, 0); /* disable interrupts */ ath_draintxq(sc); /* clear pending tx frames */ ath_stoprecv(sc); /* turn off frame recv */ /* * Convert to a HAL channel description with * the flags constrained to reflect the current * operating mode. */ hchan.channel = chan->ic_freq; hchan.channelFlags = ath_chan2flags(ic, chan); if (!ath_hal_reset(ah, ic->ic_opmode, &hchan, AH_TRUE, &status)) { if_printf(&ic->ic_if, "ath_chan_set: unable to reset " "channel %u (%u Mhz)\n", ieee80211_chan2ieee(ic, chan), chan->ic_freq); return EIO; } /* * Re-enable rx framework. */ if (ath_startrecv(sc) != 0) { if_printf(&ic->ic_if, "ath_chan_set: unable to restart recv logic\n"); return EIO; } /* * Re-enable interrupts. */ ath_hal_intrset(ah, sc->sc_imask); /* * Change channels and update the h/w rate map * if we're switching; e.g. 11a to 11b/g. */ ic->ic_ibss_chan = chan; mode = ieee80211_chan2mode(ic, chan); if (mode != sc->sc_curmode) ath_setcurmode(sc, mode); } return 0; } static void ath_next_scan(void *arg) { struct ath_softc *sc = arg; struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; if (ic->ic_state == IEEE80211_S_SCAN) ieee80211_next_scan(ifp); } /* * Periodically recalibrate the PHY to account * for temperature/environment changes. */ static void ath_calibrate(void *arg) { struct ath_softc *sc = arg; struct ath_hal *ah = sc->sc_ah; struct ieee80211com *ic = &sc->sc_ic; struct ieee80211_channel *c; HAL_CHANNEL hchan; sc->sc_stats.ast_per_cal++; /* * Convert to a HAL channel description with the flags * constrained to reflect the current operating mode. */ c = ic->ic_ibss_chan; hchan.channel = c->ic_freq; hchan.channelFlags = ath_chan2flags(ic, c); DPRINTF(("%s: channel %u/%x\n", __func__, c->ic_freq, c->ic_flags)); if (ath_hal_getrfgain(ah) == HAL_RFGAIN_NEED_CHANGE) { /* * Rfgain is out of bounds, reset the chip * to load new gain values. */ sc->sc_stats.ast_per_rfgain++; ath_reset(sc); } if (!ath_hal_calibrate(ah, &hchan)) { DPRINTF(("%s: calibration of channel %u failed\n", __func__, c->ic_freq)); sc->sc_stats.ast_per_calfail++; } callout_reset(&sc->sc_cal_ch, hz * ath_calinterval, ath_calibrate, sc); } static int -ath_newstate(void *arg, enum ieee80211_state nstate) +ath_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg) { - struct ath_softc *sc = arg; - struct ath_hal *ah = sc->sc_ah; - struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; + struct ath_softc *sc = ifp->if_softc; + struct ath_hal *ah = sc->sc_ah; struct ieee80211_node *ni; int i, error; u_int8_t *bssid; u_int32_t rfilt; - enum ieee80211_state ostate; -#ifdef AR_DEBUG - static const char *stname[] = - { "INIT", "SCAN", "AUTH", "ASSOC", "RUN" }; -#endif /* AR_DEBUG */ static const HAL_LED_STATE leds[] = { HAL_LED_INIT, /* IEEE80211_S_INIT */ HAL_LED_SCAN, /* IEEE80211_S_SCAN */ HAL_LED_AUTH, /* IEEE80211_S_AUTH */ HAL_LED_ASSOC, /* IEEE80211_S_ASSOC */ HAL_LED_RUN, /* IEEE80211_S_RUN */ }; - ostate = ic->ic_state; + DPRINTF(("%s: %s -> %s\n", __func__, + ieee80211_state_name[ic->ic_state], + ieee80211_state_name[nstate])); - DPRINTF(("%s: %s -> %s\n", __func__, stname[ostate], stname[nstate])); - ath_hal_setledstate(ah, leds[nstate]); /* set LED */ if (nstate == IEEE80211_S_INIT) { sc->sc_imask &= ~(HAL_INT_SWBA | HAL_INT_BMISS); ath_hal_intrset(ah, sc->sc_imask); - error = 0; /* cheat + use error return */ - goto bad; + callout_stop(&sc->sc_scan_ch); + callout_stop(&sc->sc_cal_ch); + return (*sc->sc_newstate)(ic, nstate, arg); } ni = ic->ic_bss; error = ath_chan_set(sc, ni->ni_chan); if (error != 0) goto bad; rfilt = (ath_hal_getrxfilter(ah) & HAL_RX_FILTER_PHYERR) | HAL_RX_FILTER_UCAST | HAL_RX_FILTER_BCAST | HAL_RX_FILTER_MCAST; if (ic->ic_opmode != IEEE80211_M_HOSTAP && (ifp->if_flags & IFF_PROMISC)) rfilt |= HAL_RX_FILTER_PROM; if (nstate == IEEE80211_S_SCAN) { callout_reset(&sc->sc_scan_ch, (hz * ath_dwelltime) / 1000, ath_next_scan, sc); bssid = ifp->if_broadcastaddr; rfilt |= HAL_RX_FILTER_BEACON; } else { callout_stop(&sc->sc_scan_ch); bssid = ni->ni_bssid; } ath_hal_setrxfilter(ah, rfilt); DPRINTF(("%s: RX filter 0x%x bssid %s\n", __func__, rfilt, ether_sprintf(bssid))); if (nstate == IEEE80211_S_RUN && ic->ic_opmode == IEEE80211_M_STA) ath_hal_setassocid(ah, bssid, ni->ni_associd); else ath_hal_setassocid(ah, bssid, 0); if (ic->ic_flags & IEEE80211_F_WEPON) { for (i = 0; i < IEEE80211_WEP_NKID; i++) if (ath_hal_keyisvalid(ah, i)) ath_hal_keysetmac(ah, i, bssid); } if (nstate == IEEE80211_S_RUN) { DPRINTF(("%s(RUN): ic_flags=0x%08x iv=%d bssid=%s " "capinfo=0x%04x chan=%d\n" , __func__ , ic->ic_flags , ni->ni_intval , ether_sprintf(ni->ni_bssid) , ni->ni_capinfo , ieee80211_chan2ieee(ic, ni->ni_chan))); /* * Allocate and setup the beacon frame for AP or adhoc mode. */ if (ic->ic_opmode != IEEE80211_M_STA) { error = ath_beacon_alloc(sc, ni); if (error != 0) goto bad; } /* * Configure the beacon and sleep timers. */ ath_beacon_config(sc); /* start periodic recalibration timer */ callout_reset(&sc->sc_cal_ch, hz * ath_calinterval, ath_calibrate, sc); } else { sc->sc_imask &= ~(HAL_INT_SWBA | HAL_INT_BMISS); ath_hal_intrset(ah, sc->sc_imask); callout_stop(&sc->sc_cal_ch); /* no calibration */ } /* * Reset the rate control state. */ ath_rate_ctl_reset(sc, nstate); - return 0; + /* + * Invoke the parent method to complete the work. + */ + return (*sc->sc_newstate)(ic, nstate, arg); bad: callout_stop(&sc->sc_scan_ch); callout_stop(&sc->sc_cal_ch); + /* NB: do not invoke the parent */ return error; } /* * Setup driver-specific state for a newly associated node. * Note that we're called also on a re-associate, the isnew * param tells us if this is the first time or not. */ static void ath_newassoc(struct ieee80211com *ic, struct ieee80211_node *ni, int isnew) { if (isnew) { struct ath_node *an = (struct ath_node *) ni; an->an_tx_ok = an->an_tx_err = an->an_tx_retr = an->an_tx_upper = 0; /* start with highest negotiated rate */ /* * XXX should do otherwise but only when * the rate control algorithm is better. */ KASSERT(ni->ni_rates.rs_nrates > 0, ("new association w/ no rates!")); ni->ni_txrate = ni->ni_rates.rs_nrates - 1; } } static int ath_getchannels(struct ath_softc *sc, u_int cc, HAL_BOOL outdoor) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; struct ath_hal *ah = sc->sc_ah; HAL_CHANNEL *chans; int i, ix, nchan; sc->sc_have11g = 0; chans = malloc(IEEE80211_CHAN_MAX * sizeof(HAL_CHANNEL), M_TEMP, M_NOWAIT); if (chans == NULL) { if_printf(ifp, "unable to allocate channel table\n"); return ENOMEM; } if (!ath_hal_init_channels(ah, chans, IEEE80211_CHAN_MAX, &nchan, cc, HAL_MODE_ALL, outdoor)) { if_printf(ifp, "unable to collect channel list from hal\n"); free(chans, M_TEMP); return EINVAL; } /* * Convert HAL channels to ieee80211 ones and insert * them in the table according to their channel number. */ for (i = 0; i < nchan; i++) { HAL_CHANNEL *c = &chans[i]; ix = ath_hal_mhz2ieee(c->channel, c->channelFlags); if (ix > IEEE80211_CHAN_MAX) { if_printf(ifp, "bad hal channel %u (%u/%x) ignored\n", ix, c->channel, c->channelFlags); continue; } /* NB: flags are known to be compatible */ if (ic->ic_channels[ix].ic_freq == 0) { ic->ic_channels[ix].ic_freq = c->channel; ic->ic_channels[ix].ic_flags = c->channelFlags; } else { /* channels overlap; e.g. 11g and 11b */ ic->ic_channels[ix].ic_flags |= c->channelFlags; } if ((c->channelFlags & CHANNEL_G) == CHANNEL_G) sc->sc_have11g = 1; } free(chans, M_TEMP); return 0; } static int ath_rate_setup(struct ath_softc *sc, u_int mode) { struct ath_hal *ah = sc->sc_ah; struct ieee80211com *ic = &sc->sc_ic; const HAL_RATE_TABLE *rt; struct ieee80211_rateset *rs; int i, maxrates; switch (mode) { case IEEE80211_MODE_11A: sc->sc_rates[mode] = ath_hal_getratetable(ah, HAL_MODE_11A); break; case IEEE80211_MODE_11B: sc->sc_rates[mode] = ath_hal_getratetable(ah, HAL_MODE_11B); break; case IEEE80211_MODE_11G: sc->sc_rates[mode] = ath_hal_getratetable(ah, HAL_MODE_11G); break; case IEEE80211_MODE_TURBO: sc->sc_rates[mode] = ath_hal_getratetable(ah, HAL_MODE_TURBO); break; default: DPRINTF(("%s: invalid mode %u\n", __func__, mode)); return 0; } rt = sc->sc_rates[mode]; if (rt == NULL) return 0; if (rt->rateCount > IEEE80211_RATE_MAXSIZE) { DPRINTF(("%s: rate table too small (%u > %u)\n", __func__, rt->rateCount, IEEE80211_RATE_MAXSIZE)); maxrates = IEEE80211_RATE_MAXSIZE; } else maxrates = rt->rateCount; rs = &ic->ic_sup_rates[mode]; for (i = 0; i < maxrates; i++) rs->rs_rates[i] = rt->info[i].dot11Rate; rs->rs_nrates = maxrates; return 1; } static void ath_setcurmode(struct ath_softc *sc, enum ieee80211_phymode mode) { const HAL_RATE_TABLE *rt; int i; memset(sc->sc_rixmap, 0xff, sizeof(sc->sc_rixmap)); rt = sc->sc_rates[mode]; KASSERT(rt != NULL, ("no h/w rate set for phy mode %u", mode)); for (i = 0; i < rt->rateCount; i++) sc->sc_rixmap[rt->info[i].dot11Rate & IEEE80211_RATE_VAL] = i; sc->sc_currates = rt; sc->sc_curmode = mode; } /* * Reset the rate control state for each 802.11 state transition. */ static void ath_rate_ctl_reset(struct ath_softc *sc, enum ieee80211_state state) { struct ieee80211com *ic = &sc->sc_ic; struct ieee80211_node *ni; struct ath_node *an; an = (struct ath_node *) ic->ic_bss; an->an_tx_ok = an->an_tx_err = an->an_tx_retr = an->an_tx_upper = 0; if (ic->ic_opmode == IEEE80211_M_STA) { ni = ic->ic_bss; if (state == IEEE80211_S_RUN) { /* start with highest negotiated rate */ KASSERT(ni->ni_rates.rs_nrates > 0, ("transition to RUN state w/ no rates!")); ni->ni_txrate = ni->ni_rates.rs_nrates - 1; } else { /* use lowest rate */ ni->ni_txrate = 0; } } else { TAILQ_FOREACH(ni, &ic->ic_node, ni_list) { ni->ni_txrate = 0; /* use lowest rate */ an = (struct ath_node *) ni; an->an_tx_ok = an->an_tx_err = an->an_tx_retr = an->an_tx_upper = 0; } } } /* * Examine and potentially adjust the transmit rate. */ static void ath_rate_ctl(void *arg, struct ieee80211_node *ni) { struct ath_softc *sc = arg; struct ath_node *an = (struct ath_node *) ni; struct ieee80211_rateset *rs = &ni->ni_rates; int mod = 0, orate, enough; /* * Rate control * XXX: very primitive version. */ sc->sc_stats.ast_rate_calls++; enough = (an->an_tx_ok + an->an_tx_err >= 10); /* no packet reached -> down */ if (an->an_tx_err > 0 && an->an_tx_ok == 0) mod = -1; /* all packets needs retry in average -> down */ if (enough && an->an_tx_ok < an->an_tx_retr) mod = -1; /* no error and less than 10% of packets needs retry -> up */ if (enough && an->an_tx_err == 0 && an->an_tx_ok > an->an_tx_retr * 10) mod = 1; orate = ni->ni_txrate; switch (mod) { case 0: if (enough && an->an_tx_upper > 0) an->an_tx_upper--; break; case -1: if (ni->ni_txrate > 0) { ni->ni_txrate--; sc->sc_stats.ast_rate_drop++; } an->an_tx_upper = 0; break; case 1: if (++an->an_tx_upper < 2) break; an->an_tx_upper = 0; if (ni->ni_txrate + 1 < rs->rs_nrates) { ni->ni_txrate++; sc->sc_stats.ast_rate_raise++; } break; } if (ni->ni_txrate != orate) { printf("%s: %dM -> %dM (%d ok, %d err, %d retr)\n", __func__, (rs->rs_rates[orate] & IEEE80211_RATE_VAL) / 2, (rs->rs_rates[ni->ni_txrate] & IEEE80211_RATE_VAL) / 2, an->an_tx_ok, an->an_tx_err, an->an_tx_retr); } if (ni->ni_txrate != orate || enough) an->an_tx_ok = an->an_tx_err = an->an_tx_retr = 0; } #ifdef AR_DEBUG static int sysctl_hw_ath_dump(SYSCTL_HANDLER_ARGS) { char dmode[64]; int error; strncpy(dmode, "", sizeof(dmode) - 1); dmode[sizeof(dmode) - 1] = '\0'; error = sysctl_handle_string(oidp, &dmode[0], sizeof(dmode), req); if (error == 0 && req->newptr != NULL) { struct ifnet *ifp; struct ath_softc *sc; ifp = ifunit("ath0"); /* XXX */ if (!ifp) return EINVAL; sc = ifp->if_softc; if (strcmp(dmode, "hal") == 0) ath_hal_dumpstate(sc->sc_ah); else if (strcmp(dmode, "eeprom") == 0) ath_hal_dumpeeprom(sc->sc_ah); else if (strcmp(dmode, "rfgain") == 0) ath_hal_dumprfgain(sc->sc_ah); else if (strcmp(dmode, "ani") == 0) ath_hal_dumpani(sc->sc_ah); else return EINVAL; } return error; } SYSCTL_PROC(_hw_ath, OID_AUTO, dump, CTLTYPE_STRING | CTLFLAG_RW, 0, 0, sysctl_hw_ath_dump, "A", "Dump driver state"); static void ath_printrxbuf(struct ath_buf *bf, int done) { struct ath_desc *ds; int i; for (i = 0, ds = bf->bf_desc; i < bf->bf_nseg; i++, ds++) { printf("R%d (%p %p) %08x %08x %08x %08x %08x %08x %c\n", i, ds, (struct ath_desc *)bf->bf_daddr + i, ds->ds_link, ds->ds_data, ds->ds_ctl0, ds->ds_ctl1, ds->ds_hw[0], ds->ds_hw[1], !done ? ' ' : (ds->ds_rxstat.rs_status == 0) ? '*' : '!'); } } static void ath_printtxbuf(struct ath_buf *bf, int done) { struct ath_desc *ds; int i; for (i = 0, ds = bf->bf_desc; i < bf->bf_nseg; i++, ds++) { printf("T%d (%p %p) %08x %08x %08x %08x %08x %08x %08x %08x %c\n", i, ds, (struct ath_desc *)bf->bf_daddr + i, ds->ds_link, ds->ds_data, ds->ds_ctl0, ds->ds_ctl1, ds->ds_hw[0], ds->ds_hw[1], ds->ds_hw[2], ds->ds_hw[3], !done ? ' ' : (ds->ds_txstat.ts_status == 0) ? '*' : '!'); } } #endif /* AR_DEBUG */ Index: head/sys/dev/ath/if_athvar.h =================================================================== --- head/sys/dev/ath/if_athvar.h (revision 117811) +++ head/sys/dev/ath/if_athvar.h (revision 117812) @@ -1,267 +1,269 @@ /*- * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any * redistribution must be conditioned upon including a substantially * similar Disclaimer requirement for further binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGES. * * $FreeBSD$ */ /* * Defintions for the Atheros Wireless LAN controller driver. */ #ifndef _DEV_ATH_ATHVAR_H #define _DEV_ATH_ATHVAR_H #include #include #include #define ATH_TIMEOUT 1000 #define ATH_RXBUF 40 /* number of RX buffers */ #define ATH_TXBUF 60 /* number of TX buffers */ #define ATH_TXDESC 8 /* number of descriptors per buffer */ /* driver-specific node */ struct ath_node { struct ieee80211_node st_node; /* base class */ u_int an_tx_ok; /* tx ok pkt */ u_int an_tx_err; /* tx !ok pkt */ u_int an_tx_retr; /* tx retry count */ int an_tx_upper; /* tx upper rate req cnt */ u_int an_tx_antenna; /* antenna for last good frame */ }; struct ath_buf { TAILQ_ENTRY(ath_buf) bf_list; int bf_nseg; bus_dmamap_t bf_dmamap; /* DMA map of the buffer */ struct ath_desc *bf_desc; /* virtual addr of desc */ bus_addr_t bf_daddr; /* physical addr of desc */ struct mbuf *bf_m; /* mbuf for buf */ struct ieee80211_node *bf_node; /* pointer to the node */ bus_size_t bf_mapsize; #define ATH_MAX_SCATTER 64 bus_dma_segment_t bf_segs[ATH_MAX_SCATTER]; }; struct ath_softc { struct ieee80211com sc_ic; /* IEEE 802.11 common */ + int (*sc_newstate)(struct ieee80211com *, + enum ieee80211_state, int); device_t sc_dev; bus_space_tag_t sc_st; /* bus space tag */ bus_space_handle_t sc_sh; /* bus space handle */ bus_dma_tag_t sc_dmat; /* bus DMA tag */ struct mtx sc_mtx; /* master lock (recursive) */ struct ath_hal *sc_ah; /* Atheros HAL */ unsigned int sc_invalid : 1,/* disable hardware accesses */ sc_have11g : 1,/* have 11g support */ sc_doani : 1,/* dynamic noise immunity */ sc_probing : 1;/* probing AP on beacon miss */ /* rate tables */ const HAL_RATE_TABLE *sc_rates[IEEE80211_MODE_MAX]; const HAL_RATE_TABLE *sc_currates; /* current rate table */ enum ieee80211_phymode sc_curmode; /* current phy mode */ u_int8_t sc_rixmap[256]; /* IEEE to h/w rate table ix */ HAL_INT sc_imask; /* interrupt mask copy */ struct ath_desc *sc_desc; /* TX/RX descriptors */ bus_dma_segment_t sc_dseg; bus_dmamap_t sc_ddmamap; /* DMA map for descriptors */ bus_addr_t sc_desc_paddr; /* physical addr of sc_desc */ bus_addr_t sc_desc_len; /* size of sc_desc */ struct task sc_fataltask; /* fatal int processing */ struct task sc_rxorntask; /* rxorn int processing */ TAILQ_HEAD(, ath_buf) sc_rxbuf; /* receive buffer */ u_int32_t *sc_rxlink; /* link ptr in last RX desc */ struct task sc_rxtask; /* rx int processing */ u_int sc_txhalq; /* HAL q for outgoing frames */ u_int32_t *sc_txlink; /* link ptr in last TX desc */ int sc_tx_timer; /* transmit timeout */ TAILQ_HEAD(, ath_buf) sc_txbuf; /* transmit buffer */ struct mtx sc_txbuflock; /* txbuf lock */ TAILQ_HEAD(, ath_buf) sc_txq; /* transmitting queue */ struct mtx sc_txqlock; /* lock on txq and txlink */ struct task sc_txtask; /* tx int processing */ u_int sc_bhalq; /* HAL q for outgoing beacons */ struct ath_buf *sc_bcbuf; /* beacon buffer */ struct ath_buf *sc_bufptr; /* allocated buffer ptr */ struct task sc_swbatask; /* swba int processing */ struct task sc_bmisstask; /* bmiss int processing */ struct callout sc_cal_ch; /* callout handle for cals */ struct callout sc_scan_ch; /* callout handle for scan */ struct ath_stats sc_stats; /* interface statistics */ }; int ath_attach(u_int16_t, struct ath_softc *); int ath_detach(struct ath_softc *); void ath_resume(struct ath_softc *); void ath_suspend(struct ath_softc *); void ath_shutdown(struct ath_softc *); void ath_intr(void *); /* * HAL definitions to comply with local coding convention. */ #define ath_hal_reset(_ah, _opmode, _chan, _outdoor, _pstatus) \ ((*(_ah)->ah_reset)((_ah), (_opmode), (_chan), (_outdoor), (_pstatus))) #define ath_hal_getratetable(_ah, _mode) \ ((*(_ah)->ah_getRateTable)((_ah), (_mode))) #define ath_hal_getregdomain(_ah) \ ((*(_ah)->ah_getRegDomain)((_ah))) #define ath_hal_getcountrycode(_ah) (_ah)->ah_countryCode #define ath_hal_getmac(_ah, _mac) \ ((*(_ah)->ah_getMacAddress)((_ah), (_mac))) #define ath_hal_detach(_ah) \ ((*(_ah)->ah_detach)((_ah))) #define ath_hal_intrset(_ah, _mask) \ ((*(_ah)->ah_setInterrupts)((_ah), (_mask))) #define ath_hal_intrget(_ah) \ ((*(_ah)->ah_getInterrupts)((_ah))) #define ath_hal_intrpend(_ah) \ ((*(_ah)->ah_isInterruptPending)((_ah))) #define ath_hal_getisr(_ah, _pmask) \ ((*(_ah)->ah_getPendingInterrupts)((_ah), (_pmask))) #define ath_hal_updatetxtriglevel(_ah, _inc) \ ((*(_ah)->ah_updateTxTrigLevel)((_ah), (_inc))) #define ath_hal_setpower(_ah, _mode, _sleepduration) \ ((*(_ah)->ah_setPowerMode)((_ah), (_mode), AH_TRUE, (_sleepduration))) #define ath_hal_keyreset(_ah, _ix) \ ((*(_ah)->ah_resetKeyCacheEntry)((_ah), (_ix))) #define ath_hal_keyset(_ah, _ix, _pk) \ ((*(_ah)->ah_setKeyCacheEntry)((_ah), (_ix), (_pk), NULL, AH_FALSE)) #define ath_hal_keyisvalid(_ah, _ix) \ (((*(_ah)->ah_isKeyCacheEntryValid)((_ah), (_ix)))) #define ath_hal_keysetmac(_ah, _ix, _mac) \ ((*(_ah)->ah_setKeyCacheEntryMac)((_ah), (_ix), (_mac))) #define ath_hal_getrxfilter(_ah) \ ((*(_ah)->ah_getRxFilter)((_ah))) #define ath_hal_setrxfilter(_ah, _filter) \ ((*(_ah)->ah_setRxFilter)((_ah), (_filter))) #define ath_hal_setmcastfilter(_ah, _mfilt0, _mfilt1) \ ((*(_ah)->ah_setMulticastFilter)((_ah), (_mfilt0), (_mfilt1))) #define ath_hal_waitforbeacon(_ah, _bf) \ ((*(_ah)->ah_waitForBeaconDone)((_ah), (_bf)->bf_daddr)) #define ath_hal_putrxbuf(_ah, _bufaddr) \ ((*(_ah)->ah_setRxDP)((_ah), (_bufaddr))) #define ath_hal_gettsf32(_ah) \ ((*(_ah)->ah_getTsf32)((_ah))) #define ath_hal_gettsf64(_ah) \ ((*(_ah)->ah_getTsf64)((_ah))) #define ath_hal_resettsf(_ah) \ ((*(_ah)->ah_resetTsf)((_ah))) #define ath_hal_rxena(_ah) \ ((*(_ah)->ah_enableReceive)((_ah))) #define ath_hal_puttxbuf(_ah, _q, _bufaddr) \ ((*(_ah)->ah_setTxDP)((_ah), (_q), (_bufaddr))) #define ath_hal_gettxbuf(_ah, _q) \ ((*(_ah)->ah_getTxDP)((_ah), (_q))) #define ath_hal_getrxbuf(_ah) \ ((*(_ah)->ah_getRxDP)((_ah))) #define ath_hal_txstart(_ah, _q) \ ((*(_ah)->ah_startTxDma)((_ah), (_q))) #define ath_hal_setchannel(_ah, _chan) \ ((*(_ah)->ah_setChannel)((_ah), (_chan))) #define ath_hal_calibrate(_ah, _chan) \ ((*(_ah)->ah_perCalibration)((_ah), (_chan))) #define ath_hal_setledstate(_ah, _state) \ ((*(_ah)->ah_setLedState)((_ah), (_state))) #define ath_hal_beaconinit(_ah, _opmode, _nextb, _bperiod) \ ((*(_ah)->ah_beaconInit)((_ah), (_opmode), (_nextb), (_bperiod))) #define ath_hal_beaconreset(_ah) \ ((*(_ah)->ah_resetStationBeaconTimers)((_ah))) #define ath_hal_beacontimers(_ah, _bs, _tsf, _dc, _cc) \ ((*(_ah)->ah_setStationBeaconTimers)((_ah), (_bs), (_tsf), \ (_dc), (_cc))) #define ath_hal_setassocid(_ah, _bss, _associd) \ ((*(_ah)->ah_writeAssocid)((_ah), (_bss), (_associd), 0)) #define ath_hal_setopmode(_ah, _opmode) \ ((*(_ah)->ah_setPCUConfig)((_ah), (_opmode))) #define ath_hal_stoptxdma(_ah, _qnum) \ ((*(_ah)->ah_stopTxDma)((_ah), (_qnum))) #define ath_hal_stoppcurecv(_ah) \ ((*(_ah)->ah_stopPcuReceive)((_ah))) #define ath_hal_startpcurecv(_ah) \ ((*(_ah)->ah_startPcuReceive)((_ah))) #define ath_hal_stopdmarecv(_ah) \ ((*(_ah)->ah_stopDmaReceive)((_ah))) #define ath_hal_dumpstate(_ah) \ ((*(_ah)->ah_dumpState)((_ah))) #define ath_hal_dumpeeprom(_ah) \ ((*(_ah)->ah_dumpEeprom)((_ah))) #define ath_hal_dumprfgain(_ah) \ ((*(_ah)->ah_dumpRfGain)((_ah))) #define ath_hal_dumpani(_ah) \ ((*(_ah)->ah_dumpAni)((_ah))) #define ath_hal_setuptxqueue(_ah, _type, _irq) \ ((*(_ah)->ah_setupTxQueue)((_ah), (_type), (_irq))) #define ath_hal_resettxqueue(_ah, _q) \ ((*(_ah)->ah_resetTxQueue)((_ah), (_q))) #define ath_hal_releasetxqueue(_ah, _q) \ ((*(_ah)->ah_releaseTxQueue)((_ah), (_q))) #define ath_hal_hasveol(_ah) \ ((*(_ah)->ah_hasVEOL)((_ah))) #define ath_hal_getrfgain(_ah) \ ((*(_ah)->ah_getRfGain)((_ah))) #define ath_hal_rxmonitor(_ah) \ ((*(_ah)->ah_rxMonitor)((_ah))) #define ath_hal_setupbeacondesc(_ah, _ds, _opmode, _flen, _hlen, \ _rate, _antmode) \ ((*(_ah)->ah_setupBeaconDesc)((_ah), (_ds), (_opmode), \ (_flen), (_hlen), (_rate), (_antmode))) #define ath_hal_setuprxdesc(_ah, _ds, _size, _intreq) \ ((*(_ah)->ah_setupRxDesc)((_ah), (_ds), (_size), (_intreq))) #define ath_hal_rxprocdesc(_ah, _ds) \ ((*(_ah)->ah_procRxDesc)((_ah), (_ds))) #define ath_hal_setuptxdesc(_ah, _ds, _plen, _hlen, _atype, _txpow, \ _txr0, _txtr0, _keyix, _ant, _flags, \ _rtsrate, _rtsdura) \ ((*(_ah)->ah_setupTxDesc)((_ah), (_ds), (_plen), (_hlen), (_atype), \ (_txpow), (_txr0), (_txtr0), (_keyix), (_ant), \ (_flags), (_rtsrate), (_rtsdura))) #define ath_hal_setupxtxdesc(_ah, _ds, _short, \ _txr1, _txtr1, _txr2, _txtr2, _txr3, _txtr3) \ ((*(_ah)->ah_setupXTxDesc)((_ah), (_ds), (_short), \ (_txr1), (_txtr1), (_txr2), (_txtr2), (_txr3), (_txtr3))) #define ath_hal_filltxdesc(_ah, _ds, _l, _first, _last) \ ((*(_ah)->ah_fillTxDesc)((_ah), (_ds), (_l), (_first), (_last))) #define ath_hal_txprocdesc(_ah, _ds) \ ((*(_ah)->ah_procTxDesc)((_ah), (_ds))) #endif /* _DEV_ATH_ATHVAR_H */ Index: head/sys/dev/wi/if_wi.c =================================================================== --- head/sys/dev/wi/if_wi.c (revision 117811) +++ head/sys/dev/wi/if_wi.c (revision 117812) @@ -1,3055 +1,3054 @@ /* $NetBSD: wi.c,v 1.109 2003/01/09 08:52:19 dyoung Exp $ */ /* * Copyright (c) 1997, 1998, 1999 * Bill Paul . All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Bill Paul. * 4. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ /* * Lucent WaveLAN/IEEE 802.11 PCMCIA driver. * * Original FreeBSD driver written by Bill Paul * Electrical Engineering Department * Columbia University, New York City */ /* * The WaveLAN/IEEE adapter is the second generation of the WaveLAN * from Lucent. Unlike the older cards, the new ones are programmed * entirely via a firmware-driven controller called the Hermes. * Unfortunately, Lucent will not release the Hermes programming manual * without an NDA (if at all). What they do release is an API library * called the HCF (Hardware Control Functions) which is supposed to * do the device-specific operations of a device driver for you. The * publically available version of the HCF library (the 'HCF Light') is * a) extremely gross, b) lacks certain features, particularly support * for 802.11 frames, and c) is contaminated by the GNU Public License. * * This driver does not use the HCF or HCF Light at all. Instead, it * programs the Hermes controller directly, using information gleaned * from the HCF Light code and corresponding documentation. * * This driver supports the ISA, PCMCIA and PCI versions of the Lucent * WaveLan cards (based on the Hermes chipset), as well as the newer * Prism 2 chipsets with firmware from Intersil and Symbol. */ #include __FBSDID("$FreeBSD$"); #define WI_HERMES_AUTOINC_WAR /* Work around data write autoinc bug. */ #define WI_HERMES_STATS_WAR /* Work around stats counter bug. */ #define NBPFILTER 1 #include #include #if __FreeBSD_version >= 500033 #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define IF_POLL(ifq, m) ((m) = (ifq)->ifq_head) #define IFQ_POLL(ifq, m) IF_POLL((ifq), (m)) #define IFQ_DEQUEUE(ifq, m) IF_DEQUEUE((ifq), (m)) static void wi_start(struct ifnet *); static int wi_reset(struct wi_softc *); static void wi_watchdog(struct ifnet *); static int wi_ioctl(struct ifnet *, u_long, caddr_t); static int wi_media_change(struct ifnet *); static void wi_media_status(struct ifnet *, struct ifmediareq *); static void wi_rx_intr(struct wi_softc *); static void wi_tx_intr(struct wi_softc *); static void wi_tx_ex_intr(struct wi_softc *); static void wi_info_intr(struct wi_softc *); static int wi_get_cfg(struct ifnet *, u_long, caddr_t); static int wi_set_cfg(struct ifnet *, u_long, caddr_t); static int wi_write_txrate(struct wi_softc *); static int wi_write_wep(struct wi_softc *); static int wi_write_multi(struct wi_softc *); static int wi_alloc_fid(struct wi_softc *, int, int *); static void wi_read_nicid(struct wi_softc *); static int wi_write_ssid(struct wi_softc *, int, u_int8_t *, int); static int wi_cmd(struct wi_softc *, int, int, int, int); static int wi_seek_bap(struct wi_softc *, int, int); static int wi_read_bap(struct wi_softc *, int, int, void *, int); static int wi_write_bap(struct wi_softc *, int, int, void *, int); static int wi_mwrite_bap(struct wi_softc *, int, int, struct mbuf *, int); static int wi_read_rid(struct wi_softc *, int, void *, int *); static int wi_write_rid(struct wi_softc *, int, void *, int); -static int wi_newstate(void *, enum ieee80211_state); +static int wi_newstate(struct ieee80211com *, enum ieee80211_state, int); static int wi_scan_ap(struct wi_softc *, u_int16_t, u_int16_t); static void wi_scan_result(struct wi_softc *, int, int); static void wi_dump_pkt(struct wi_frame *, struct ieee80211_node *, int rssi); static int wi_get_debug(struct wi_softc *, struct wi_req *); static int wi_set_debug(struct wi_softc *, struct wi_req *); #if __FreeBSD_version >= 500000 /* support to download firmware for symbol CF card */ static int wi_symbol_write_firm(struct wi_softc *, const void *, int, const void *, int); static int wi_symbol_set_hcr(struct wi_softc *, int); #endif static __inline int wi_write_val(struct wi_softc *sc, int rid, u_int16_t val) { val = htole16(val); return wi_write_rid(sc, rid, &val, sizeof(val)); } SYSCTL_NODE(_hw, OID_AUTO, wi, CTLFLAG_RD, 0, "Wireless driver parameters"); static struct timeval lasttxerror; /* time of last tx error msg */ static int curtxeps; /* current tx error msgs/sec */ static int wi_txerate = 0; /* tx error rate: max msgs/sec */ SYSCTL_INT(_hw_wi, OID_AUTO, txerate, CTLFLAG_RW, &wi_txerate, 0, "max tx error msgs/sec; 0 to disable msgs"); #define WI_DEBUG #ifdef WI_DEBUG static int wi_debug = 0; SYSCTL_INT(_hw_wi, OID_AUTO, debug, CTLFLAG_RW, &wi_debug, 0, "control debugging printfs"); #define DPRINTF(X) if (wi_debug) printf X #define DPRINTF2(X) if (wi_debug > 1) printf X #define IFF_DUMPPKTS(_ifp) \ (((_ifp)->if_flags & (IFF_DEBUG|IFF_LINK2)) == (IFF_DEBUG|IFF_LINK2)) #else #define DPRINTF(X) #define DPRINTF2(X) #define IFF_DUMPPKTS(_ifp) 0 #endif #define WI_INTRS (WI_EV_RX | WI_EV_ALLOC | WI_EV_INFO) struct wi_card_ident wi_card_ident[] = { /* CARD_ID CARD_NAME FIRM_TYPE */ { WI_NIC_LUCENT_ID, WI_NIC_LUCENT_STR, WI_LUCENT }, { WI_NIC_SONY_ID, WI_NIC_SONY_STR, WI_LUCENT }, { WI_NIC_LUCENT_EMB_ID, WI_NIC_LUCENT_EMB_STR, WI_LUCENT }, { WI_NIC_EVB2_ID, WI_NIC_EVB2_STR, WI_INTERSIL }, { WI_NIC_HWB3763_ID, WI_NIC_HWB3763_STR, WI_INTERSIL }, { WI_NIC_HWB3163_ID, WI_NIC_HWB3163_STR, WI_INTERSIL }, { WI_NIC_HWB3163B_ID, WI_NIC_HWB3163B_STR, WI_INTERSIL }, { WI_NIC_EVB3_ID, WI_NIC_EVB3_STR, WI_INTERSIL }, { WI_NIC_HWB1153_ID, WI_NIC_HWB1153_STR, WI_INTERSIL }, { WI_NIC_P2_SST_ID, WI_NIC_P2_SST_STR, WI_INTERSIL }, { WI_NIC_EVB2_SST_ID, WI_NIC_EVB2_SST_STR, WI_INTERSIL }, { WI_NIC_3842_EVA_ID, WI_NIC_3842_EVA_STR, WI_INTERSIL }, { WI_NIC_3842_PCMCIA_AMD_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL }, { WI_NIC_3842_PCMCIA_SST_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL }, { WI_NIC_3842_PCMCIA_ATL_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL }, { WI_NIC_3842_PCMCIA_ATS_ID, WI_NIC_3842_PCMCIA_STR, WI_INTERSIL }, { WI_NIC_3842_MINI_AMD_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL }, { WI_NIC_3842_MINI_SST_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL }, { WI_NIC_3842_MINI_ATL_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL }, { WI_NIC_3842_MINI_ATS_ID, WI_NIC_3842_MINI_STR, WI_INTERSIL }, { WI_NIC_3842_PCI_AMD_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL }, { WI_NIC_3842_PCI_SST_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL }, { WI_NIC_3842_PCI_ATS_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL }, { WI_NIC_3842_PCI_ATL_ID, WI_NIC_3842_PCI_STR, WI_INTERSIL }, { WI_NIC_P3_PCMCIA_AMD_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL }, { WI_NIC_P3_PCMCIA_SST_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL }, { WI_NIC_P3_PCMCIA_ATL_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL }, { WI_NIC_P3_PCMCIA_ATS_ID, WI_NIC_P3_PCMCIA_STR, WI_INTERSIL }, { WI_NIC_P3_MINI_AMD_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL }, { WI_NIC_P3_MINI_SST_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL }, { WI_NIC_P3_MINI_ATL_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL }, { WI_NIC_P3_MINI_ATS_ID, WI_NIC_P3_MINI_STR, WI_INTERSIL }, { 0, NULL, 0 }, }; devclass_t wi_devclass; int wi_attach(device_t dev) { struct wi_softc *sc = device_get_softc(dev); struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; int i, nrates, buflen; u_int16_t val; u_int8_t ratebuf[2 + IEEE80211_RATE_SIZE]; struct ieee80211_rateset *rs; static const u_int8_t empty_macaddr[IEEE80211_ADDR_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; int error; /* * NB: no locking is needed here; don't put it here * unless you can prove it! */ error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, wi_intr, sc, &sc->wi_intrhand); if (error) { device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); wi_free(dev); return (error); } #if __FreeBSD_version >= 500000 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, MTX_DEF | MTX_RECURSE); #endif /* Reset the NIC. */ if (wi_reset(sc) != 0) return ENXIO; /* XXX */ /* * Read the station address. * And do it twice. I've seen PRISM-based cards that return * an error when trying to read it the first time, which causes * the probe to fail. */ buflen = IEEE80211_ADDR_LEN; error = wi_read_rid(sc, WI_RID_MAC_NODE, ic->ic_myaddr, &buflen); if (error != 0) { buflen = IEEE80211_ADDR_LEN; error = wi_read_rid(sc, WI_RID_MAC_NODE, ic->ic_myaddr, &buflen); } if (error || IEEE80211_ADDR_EQ(ic->ic_myaddr, empty_macaddr)) { if (error != 0) device_printf(dev, "mac read failed %d\n", error); else device_printf(dev, "mac read failed (all zeros)\n"); wi_free(dev); return (error); } device_printf(dev, "802.11 address: %6D\n", ic->ic_myaddr, ":"); /* Read NIC identification */ wi_read_nicid(sc); ifp->if_softc = sc; ifp->if_unit = sc->sc_unit; ifp->if_name = "wi"; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = wi_ioctl; ifp->if_start = wi_start; ifp->if_watchdog = wi_watchdog; ifp->if_init = wi_init; ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; ic->ic_phytype = IEEE80211_T_DS; ic->ic_opmode = IEEE80211_M_STA; ic->ic_caps = IEEE80211_C_PMGT | IEEE80211_C_AHDEMO; ic->ic_state = IEEE80211_S_INIT; - ic->ic_newstate = wi_newstate; /* * Query the card for available channels and setup the * channel table. We assume these are all 11b channels. */ buflen = sizeof(val); if (wi_read_rid(sc, WI_RID_CHANNEL_LIST, &val, &buflen) != 0) val = htole16(0x1fff); /* assume 1-11 */ KASSERT(val != 0, ("wi_attach: no available channels listed!")); val <<= 1; /* shift for base 1 indices */ for (i = 1; i < 16; i++) { if (isset((u_int8_t*)&val, i)) { ic->ic_channels[i].ic_freq = ieee80211_ieee2mhz(i, IEEE80211_CHAN_B); ic->ic_channels[i].ic_flags = IEEE80211_CHAN_B; } } /* * Read the default channel from the NIC. This may vary * depending on the country where the NIC was purchased, so * we can't hard-code a default and expect it to work for * everyone. * * If no channel is specified, let the 802.11 code select. */ buflen = sizeof(val); if (wi_read_rid(sc, WI_RID_OWN_CHNL, &val, &buflen) == 0) { val = le16toh(val); KASSERT(val < IEEE80211_CHAN_MAX && ic->ic_channels[val].ic_flags != 0, ("wi_attach: invalid own channel %u!", val)); ic->ic_ibss_chan = &ic->ic_channels[val]; } else { device_printf(dev, "WI_RID_OWN_CHNL failed, using first channel!\n"); ic->ic_ibss_chan = &ic->ic_channels[0]; } /* * Set flags based on firmware version. */ switch (sc->sc_firmware_type) { case WI_LUCENT: sc->sc_ntxbuf = 1; sc->sc_flags |= WI_FLAGS_HAS_SYSSCALE; #ifdef WI_HERMES_AUTOINC_WAR /* XXX: not confirmed, but never seen for recent firmware */ if (sc->sc_sta_firmware_ver < 40000) { sc->sc_flags |= WI_FLAGS_BUG_AUTOINC; } #endif if (sc->sc_sta_firmware_ver >= 60000) sc->sc_flags |= WI_FLAGS_HAS_MOR; if (sc->sc_sta_firmware_ver >= 60006) ic->ic_caps |= IEEE80211_C_IBSS; sc->sc_ibss_port = htole16(1); break; case WI_INTERSIL: sc->sc_ntxbuf = WI_NTXBUF; sc->sc_flags |= WI_FLAGS_HAS_FRAGTHR; sc->sc_flags |= WI_FLAGS_HAS_ROAMING; sc->sc_flags |= WI_FLAGS_HAS_SYSSCALE; if (sc->sc_sta_firmware_ver > 10101) sc->sc_flags |= WI_FLAGS_HAS_DBMADJUST; if (sc->sc_sta_firmware_ver >= 800) ic->ic_caps |= IEEE80211_C_IBSS; /* * version 0.8.3 and newer are the only ones that are known * to currently work. Earlier versions can be made to work, * at least according to the Linux driver. */ if (sc->sc_sta_firmware_ver >= 803) ic->ic_caps |= IEEE80211_C_HOSTAP; sc->sc_ibss_port = htole16(0); break; case WI_SYMBOL: sc->sc_ntxbuf = 1; sc->sc_flags |= WI_FLAGS_HAS_DIVERSITY; if (sc->sc_sta_firmware_ver >= 25000) ic->ic_caps |= IEEE80211_C_IBSS; sc->sc_ibss_port = htole16(4); break; } /* * Find out if we support WEP on this card. */ buflen = sizeof(val); if (wi_read_rid(sc, WI_RID_WEP_AVAIL, &val, &buflen) == 0 && val != htole16(0)) ic->ic_caps |= IEEE80211_C_WEP; /* Find supported rates. */ buflen = sizeof(ratebuf); rs = &ic->ic_sup_rates[IEEE80211_MODE_11B]; if (wi_read_rid(sc, WI_RID_DATA_RATES, ratebuf, &buflen) == 0) { nrates = le16toh(*(u_int16_t *)ratebuf); if (nrates > IEEE80211_RATE_MAXSIZE) nrates = IEEE80211_RATE_MAXSIZE; rs->rs_nrates = 0; for (i = 0; i < nrates; i++) if (ratebuf[2+i]) rs->rs_rates[rs->rs_nrates++] = ratebuf[2+i]; } else { /* XXX fallback on error? */ rs->rs_nrates = 0; } buflen = sizeof(val); if ((sc->sc_flags & WI_FLAGS_HAS_DBMADJUST) && wi_read_rid(sc, WI_RID_DBM_ADJUST, &val, &buflen) == 0) { sc->sc_dbm_adjust = le16toh(val); } else sc->sc_dbm_adjust = 100; /* default */ sc->sc_max_datalen = 2304; sc->sc_system_scale = 1; sc->sc_cnfauthmode = IEEE80211_AUTH_OPEN; sc->sc_roaming_mode = 1; sc->sc_portnum = WI_DEFAULT_PORT; sc->sc_authtype = WI_DEFAULT_AUTHTYPE; bzero(sc->sc_nodename, sizeof(sc->sc_nodename)); sc->sc_nodelen = sizeof(WI_DEFAULT_NODENAME) - 1; bcopy(WI_DEFAULT_NODENAME, sc->sc_nodename, sc->sc_nodelen); bzero(sc->sc_net_name, sizeof(sc->sc_net_name)); bcopy(WI_DEFAULT_NETNAME, sc->sc_net_name, sizeof(WI_DEFAULT_NETNAME) - 1); /* * Call MI attach routine. */ ieee80211_ifattach(ifp); + /* override state transition method */ + sc->sc_newstate = ic->ic_newstate; + ic->ic_newstate = wi_newstate; ieee80211_media_init(ifp, wi_media_change, wi_media_status); return (0); } int wi_detach(device_t dev) { struct wi_softc *sc = device_get_softc(dev); struct ifnet *ifp = &sc->sc_ic.ic_if; WI_LOCK_DECL(); WI_LOCK(sc); /* check if device was removed */ sc->wi_gone = !bus_child_present(dev); wi_stop(ifp, 0); ieee80211_ifdetach(ifp); WI_UNLOCK(sc); bus_teardown_intr(dev, sc->irq, sc->wi_intrhand); wi_free(dev); #if __FreeBSD_version >= 500000 mtx_destroy(&sc->sc_mtx); #endif return (0); } #ifdef __NetBSD__ int wi_activate(struct device *self, enum devact act) { struct wi_softc *sc = (struct wi_softc *)self; int rv = 0, s; s = splnet(); switch (act) { case DVACT_ACTIVATE: rv = EOPNOTSUPP; break; case DVACT_DEACTIVATE: if_deactivate(&sc->sc_ic.ic_if); break; } splx(s); return rv; } void wi_power(struct wi_softc *sc, int why) { struct ifnet *ifp = &sc->sc_ic.ic_if; int s; s = splnet(); switch (why) { case PWR_SUSPEND: case PWR_STANDBY: wi_stop(ifp, 1); break; case PWR_RESUME: if (ifp->if_flags & IFF_UP) { wi_init(ifp); (void)wi_intr(sc); } break; case PWR_SOFTSUSPEND: case PWR_SOFTSTANDBY: case PWR_SOFTRESUME: break; } splx(s); } #endif /* __NetBSD__ */ void wi_shutdown(device_t dev) { struct wi_softc *sc = device_get_softc(dev); wi_stop(&sc->sc_if, 1); } void wi_intr(void *arg) { struct wi_softc *sc = arg; struct ifnet *ifp = &sc->sc_ic.ic_if; u_int16_t status; WI_LOCK_DECL(); WI_LOCK(sc); if (sc->wi_gone || (ifp->if_flags & IFF_UP) == 0) { CSR_WRITE_2(sc, WI_INT_EN, 0); CSR_WRITE_2(sc, WI_EVENT_ACK, ~0); WI_UNLOCK(sc); return; } /* Disable interrupts. */ CSR_WRITE_2(sc, WI_INT_EN, 0); status = CSR_READ_2(sc, WI_EVENT_STAT); if (status & WI_EV_RX) wi_rx_intr(sc); if (status & WI_EV_ALLOC) wi_tx_intr(sc); if (status & WI_EV_TX_EXC) wi_tx_ex_intr(sc); if (status & WI_EV_INFO) wi_info_intr(sc); if ((ifp->if_flags & IFF_OACTIVE) == 0 && (sc->sc_flags & WI_FLAGS_OUTRANGE) == 0 && _IF_QLEN(&ifp->if_snd) != 0) wi_start(ifp); /* Re-enable interrupts. */ CSR_WRITE_2(sc, WI_INT_EN, WI_INTRS); WI_UNLOCK(sc); return; } void wi_init(void *arg) { struct wi_softc *sc = arg; struct ifnet *ifp = &sc->sc_if; struct ieee80211com *ic = &sc->sc_ic; struct wi_joinreq join; int i; int error = 0, wasenabled; struct ifaddr *ifa; struct sockaddr_dl *sdl; WI_LOCK_DECL(); WI_LOCK(sc); if (sc->wi_gone) { WI_UNLOCK(sc); return; } if ((wasenabled = sc->sc_enabled)) wi_stop(ifp, 0); wi_reset(sc); /* common 802.11 configuration */ ic->ic_flags &= ~IEEE80211_F_IBSSON; sc->sc_flags &= ~WI_FLAGS_OUTRANGE; switch (ic->ic_opmode) { case IEEE80211_M_STA: wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_BSS); break; case IEEE80211_M_IBSS: wi_write_val(sc, WI_RID_PORTTYPE, sc->sc_ibss_port); ic->ic_flags |= IEEE80211_F_IBSSON; break; case IEEE80211_M_AHDEMO: wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_ADHOC); break; case IEEE80211_M_HOSTAP: wi_write_val(sc, WI_RID_PORTTYPE, WI_PORTTYPE_HOSTAP); break; } /* Intersil interprets this RID as joining ESS even in IBSS mode */ if (sc->sc_firmware_type == WI_LUCENT && (ic->ic_flags & IEEE80211_F_IBSSON) && ic->ic_des_esslen > 0) wi_write_val(sc, WI_RID_CREATE_IBSS, 1); else wi_write_val(sc, WI_RID_CREATE_IBSS, 0); wi_write_val(sc, WI_RID_MAX_SLEEP, ic->ic_lintval); wi_write_ssid(sc, WI_RID_DESIRED_SSID, ic->ic_des_essid, ic->ic_des_esslen); wi_write_val(sc, WI_RID_OWN_CHNL, ieee80211_chan2ieee(ic, ic->ic_ibss_chan)); wi_write_ssid(sc, WI_RID_OWN_SSID, ic->ic_des_essid, ic->ic_des_esslen); ifa = ifaddr_byindex(ifp->if_index); sdl = (struct sockaddr_dl *) ifa->ifa_addr; IEEE80211_ADDR_COPY(ic->ic_myaddr, LLADDR(sdl)); wi_write_rid(sc, WI_RID_MAC_NODE, ic->ic_myaddr, IEEE80211_ADDR_LEN); wi_write_val(sc, WI_RID_PM_ENABLED, (ic->ic_flags & IEEE80211_F_PMGTON) ? 1 : 0); /* not yet common 802.11 configuration */ wi_write_val(sc, WI_RID_MAX_DATALEN, sc->sc_max_datalen); wi_write_val(sc, WI_RID_RTS_THRESH, ic->ic_rtsthreshold); if (sc->sc_flags & WI_FLAGS_HAS_FRAGTHR) wi_write_val(sc, WI_RID_FRAG_THRESH, ic->ic_fragthreshold); /* driver specific 802.11 configuration */ if (sc->sc_flags & WI_FLAGS_HAS_SYSSCALE) wi_write_val(sc, WI_RID_SYSTEM_SCALE, sc->sc_system_scale); if (sc->sc_flags & WI_FLAGS_HAS_ROAMING) wi_write_val(sc, WI_RID_ROAMING_MODE, sc->sc_roaming_mode); if (sc->sc_flags & WI_FLAGS_HAS_MOR) wi_write_val(sc, WI_RID_MICROWAVE_OVEN, sc->sc_microwave_oven); wi_write_txrate(sc); wi_write_ssid(sc, WI_RID_NODENAME, sc->sc_nodename, sc->sc_nodelen); if (ic->ic_opmode == IEEE80211_M_HOSTAP && sc->sc_firmware_type == WI_INTERSIL) { wi_write_val(sc, WI_RID_OWN_BEACON_INT, ic->ic_lintval); wi_write_val(sc, WI_RID_BASIC_RATE, 0x03); /* 1, 2 */ wi_write_val(sc, WI_RID_SUPPORT_RATE, 0x0f); /* 1, 2, 5.5, 11 */ wi_write_val(sc, WI_RID_DTIM_PERIOD, 1); } /* * Initialize promisc mode. * Being in the Host-AP mode causes a great * deal of pain if primisc mode is set. * Therefore we avoid confusing the firmware * and always reset promisc mode in Host-AP * mode. Host-AP sees all the packets anyway. */ if (ic->ic_opmode != IEEE80211_M_HOSTAP && (ifp->if_flags & IFF_PROMISC) != 0) { wi_write_val(sc, WI_RID_PROMISC, 1); } else { wi_write_val(sc, WI_RID_PROMISC, 0); } /* Configure WEP. */ if (ic->ic_caps & IEEE80211_C_WEP) wi_write_wep(sc); /* Set multicast filter. */ wi_write_multi(sc); /* Allocate fids for the card */ if (sc->sc_firmware_type != WI_SYMBOL || !wasenabled) { sc->sc_buflen = IEEE80211_MAX_LEN + sizeof(struct wi_frame); if (sc->sc_firmware_type == WI_SYMBOL) sc->sc_buflen = 1585; /* XXX */ for (i = 0; i < sc->sc_ntxbuf; i++) { error = wi_alloc_fid(sc, sc->sc_buflen, &sc->sc_txd[i].d_fid); if (error) { device_printf(sc->sc_dev, "tx buffer allocation failed (error %u)\n", error); goto out; } sc->sc_txd[i].d_len = 0; } } sc->sc_txcur = sc->sc_txnext = 0; /* Enable desired port */ wi_cmd(sc, WI_CMD_ENABLE | sc->sc_portnum, 0, 0, 0); sc->sc_enabled = 1; ifp->if_flags |= IFF_RUNNING; ifp->if_flags &= ~IFF_OACTIVE; if (ic->ic_opmode == IEEE80211_M_AHDEMO || ic->ic_opmode == IEEE80211_M_HOSTAP) - wi_newstate(sc, IEEE80211_S_RUN); + ieee80211_new_state(ic, IEEE80211_S_RUN, -1); /* Enable interrupts */ CSR_WRITE_2(sc, WI_INT_EN, WI_INTRS); if (!wasenabled && ic->ic_opmode == IEEE80211_M_HOSTAP && sc->sc_firmware_type == WI_INTERSIL) { /* XXX: some card need to be re-enabled for hostap */ wi_cmd(sc, WI_CMD_DISABLE | WI_PORT0, 0, 0, 0); wi_cmd(sc, WI_CMD_ENABLE | WI_PORT0, 0, 0, 0); } if (ic->ic_opmode == IEEE80211_M_STA && ((ic->ic_flags & IEEE80211_F_DESBSSID) || ic->ic_des_chan != IEEE80211_CHAN_ANYC)) { memset(&join, 0, sizeof(join)); if (ic->ic_flags & IEEE80211_F_DESBSSID) IEEE80211_ADDR_COPY(&join.wi_bssid, ic->ic_des_bssid); if (ic->ic_des_chan != IEEE80211_CHAN_ANYC) join.wi_chan = htole16( ieee80211_chan2ieee(ic, ic->ic_des_chan)); /* Lucent firmware does not support the JOIN RID. */ if (sc->sc_firmware_type != WI_LUCENT) wi_write_rid(sc, WI_RID_JOIN_REQ, &join, sizeof(join)); } WI_UNLOCK(sc); return; out: if (error) { if_printf(ifp, "interface not running\n"); wi_stop(ifp, 0); } WI_UNLOCK(sc); DPRINTF(("wi_init: return %d\n", error)); return; } void wi_stop(struct ifnet *ifp, int disable) { + struct ieee80211com *ic = (struct ieee80211com *) ifp; struct wi_softc *sc = ifp->if_softc; WI_LOCK_DECL(); WI_LOCK(sc); - ieee80211_new_state(ifp, IEEE80211_S_INIT, -1); + ieee80211_new_state(ic, IEEE80211_S_INIT, -1); if (sc->sc_enabled && !sc->wi_gone) { CSR_WRITE_2(sc, WI_INT_EN, 0); wi_cmd(sc, WI_CMD_DISABLE | sc->sc_portnum, 0, 0, 0); if (disable) { #ifdef __NetBSD__ if (sc->sc_disable) (*sc->sc_disable)(sc); #endif sc->sc_enabled = 0; } } sc->sc_tx_timer = 0; sc->sc_scan_timer = 0; sc->sc_syn_timer = 0; sc->sc_false_syns = 0; sc->sc_naps = 0; ifp->if_flags &= ~(IFF_OACTIVE | IFF_RUNNING); ifp->if_timer = 0; WI_UNLOCK(sc); } static void wi_start(struct ifnet *ifp) { struct wi_softc *sc = ifp->if_softc; struct ieee80211com *ic = &sc->sc_ic; struct ieee80211_frame *wh; struct mbuf *m0; struct wi_frame frmhdr; int cur, fid, off; WI_LOCK_DECL(); WI_LOCK(sc); if (sc->wi_gone) { WI_UNLOCK(sc); return; } if (sc->sc_flags & WI_FLAGS_OUTRANGE) { WI_UNLOCK(sc); return; } memset(&frmhdr, 0, sizeof(frmhdr)); cur = sc->sc_txnext; for (;;) { IF_POLL(&ic->ic_mgtq, m0); if (m0 != NULL) { if (sc->sc_txd[cur].d_len != 0) { ifp->if_flags |= IFF_OACTIVE; break; } IF_DEQUEUE(&ic->ic_mgtq, m0); m_copydata(m0, 4, ETHER_ADDR_LEN * 2, (caddr_t)&frmhdr.wi_ehdr); frmhdr.wi_ehdr.ether_type = 0; wh = mtod(m0, struct ieee80211_frame *); } else { if (ic->ic_state != IEEE80211_S_RUN) break; IFQ_POLL(&ifp->if_snd, m0); if (m0 == NULL) break; if (sc->sc_txd[cur].d_len != 0) { ifp->if_flags |= IFF_OACTIVE; break; } IFQ_DEQUEUE(&ifp->if_snd, m0); ifp->if_opackets++; m_copydata(m0, 0, ETHER_HDR_LEN, (caddr_t)&frmhdr.wi_ehdr); #if NBPFILTER > 0 BPF_MTAP(ifp, m0); #endif if ((m0 = ieee80211_encap(ifp, m0)) == NULL) { ifp->if_oerrors++; continue; } wh = mtod(m0, struct ieee80211_frame *); if (ic->ic_opmode == IEEE80211_M_HOSTAP && !IEEE80211_IS_MULTICAST(wh->i_addr1) && (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_DATA) { struct ieee80211_node *ni = ieee80211_find_node(ic, wh->i_addr1); int err = (ni == NULL || ni->ni_associd == 0); if (ni != NULL) ieee80211_unref_node(&ni); if (err) { m_freem(m0); ifp->if_oerrors++; continue; } } if (ic->ic_flags & IEEE80211_F_WEPON) wh->i_fc[1] |= IEEE80211_FC1_WEP; } #if NBPFILTER > 0 if (ic->ic_rawbpf) bpf_mtap(ic->ic_rawbpf, m0); #endif frmhdr.wi_tx_ctl = htole16(WI_ENC_TX_802_11|WI_TXCNTL_TX_EX); if (ic->ic_opmode == IEEE80211_M_HOSTAP && (wh->i_fc[1] & IEEE80211_FC1_WEP)) { if ((m0 = ieee80211_wep_crypt(ifp, m0, 1)) == NULL) { ifp->if_oerrors++; continue; } frmhdr.wi_tx_ctl |= htole16(WI_TXCNTL_NOCRYPT); } m_copydata(m0, 0, sizeof(struct ieee80211_frame), (caddr_t)&frmhdr.wi_whdr); m_adj(m0, sizeof(struct ieee80211_frame)); frmhdr.wi_dat_len = htole16(m0->m_pkthdr.len); #if NBPFILTER > 0 if (sc->sc_drvbpf) { struct mbuf *mb; MGETHDR(mb, M_DONTWAIT, m0->m_type); if (mb != NULL) { (void) m_dup_pkthdr(mb, m0, M_DONTWAIT); mb->m_next = m0; mb->m_data = (caddr_t)&frmhdr; mb->m_len = sizeof(frmhdr); mb->m_pkthdr.len += mb->m_len; bpf_mtap(sc->sc_drvbpf, mb); m_free(mb); } } #endif if (IFF_DUMPPKTS(ifp)) wi_dump_pkt(&frmhdr, NULL, -1); fid = sc->sc_txd[cur].d_fid; off = sizeof(frmhdr); if (wi_write_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr)) != 0 || wi_mwrite_bap(sc, fid, off, m0, m0->m_pkthdr.len) != 0) { ifp->if_oerrors++; m_freem(m0); continue; } m_freem(m0); sc->sc_txd[cur].d_len = off; if (sc->sc_txcur == cur) { if (wi_cmd(sc, WI_CMD_TX | WI_RECLAIM, fid, 0, 0)) { if_printf(ifp, "xmit failed\n"); sc->sc_txd[cur].d_len = 0; continue; } sc->sc_tx_timer = 5; ifp->if_timer = 1; } sc->sc_txnext = cur = (cur + 1) % sc->sc_ntxbuf; } WI_UNLOCK(sc); } static int wi_reset(struct wi_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; #define WI_INIT_TRIES 3 int i; int error = 0; int tries; /* Symbol firmware cannot be initialized more than once */ if (sc->sc_firmware_type != WI_INTERSIL && sc->sc_reset) return (0); if (sc->sc_firmware_type == WI_SYMBOL) tries = 1; else tries = WI_INIT_TRIES; for (i = 0; i < tries; i++) { if ((error = wi_cmd(sc, WI_CMD_INI, 0, 0, 0)) == 0) break; DELAY(WI_DELAY * 1000); } sc->sc_reset = 1; if (i == tries) { if_printf(ifp, "init failed\n"); return (error); } CSR_WRITE_2(sc, WI_INT_EN, 0); CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF); /* Calibrate timer. */ wi_write_val(sc, WI_RID_TICK_TIME, 8); return (0); #undef WI_INIT_TRIES } static void wi_watchdog(struct ifnet *ifp) { struct wi_softc *sc = ifp->if_softc; ifp->if_timer = 0; if (!sc->sc_enabled) return; if (sc->sc_tx_timer) { if (--sc->sc_tx_timer == 0) { if_printf(ifp, "device timeout\n"); ifp->if_oerrors++; wi_init(ifp->if_softc); return; } ifp->if_timer = 1; } if (sc->sc_scan_timer) { if (--sc->sc_scan_timer <= WI_SCAN_WAIT - WI_SCAN_INQWAIT && sc->sc_firmware_type == WI_INTERSIL) { DPRINTF(("wi_watchdog: inquire scan\n")); wi_cmd(sc, WI_CMD_INQUIRE, WI_INFO_SCAN_RESULTS, 0, 0); } if (sc->sc_scan_timer) ifp->if_timer = 1; } if (sc->sc_syn_timer) { if (--sc->sc_syn_timer == 0) { + struct ieee80211com *ic = (struct ieee80211com *) ifp; DPRINTF2(("wi_watchdog: %d false syns\n", sc->sc_false_syns)); sc->sc_false_syns = 0; - ieee80211_new_state(ifp, IEEE80211_S_RUN, -1); + ieee80211_new_state(ic, IEEE80211_S_RUN, -1); sc->sc_syn_timer = 5; } ifp->if_timer = 1; } /* TODO: rate control */ ieee80211_watchdog(ifp); } static int wi_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) { struct wi_softc *sc = ifp->if_softc; struct ieee80211com *ic = &sc->sc_ic; struct ifreq *ifr = (struct ifreq *)data; struct ieee80211req *ireq; u_int8_t nodename[IEEE80211_NWID_LEN]; int error = 0; #if __FreeBSD_version >= 500000 struct thread *td = curthread; #else struct proc *td = curproc; /* Little white lie */ #endif struct wi_req wreq; WI_LOCK_DECL(); WI_LOCK(sc); if (sc->wi_gone) { error = ENODEV; goto out; } switch (cmd) { case SIOCSIFFLAGS: /* * Can't do promisc and hostap at the same time. If all that's * changing is the promisc flag, try to short-circuit a call to * wi_init() by just setting PROMISC in the hardware. */ if (ifp->if_flags & IFF_UP) { if (ic->ic_opmode != IEEE80211_M_HOSTAP && ifp->if_flags & IFF_RUNNING) { if (ifp->if_flags & IFF_PROMISC && !(sc->sc_if_flags & IFF_PROMISC)) { wi_write_val(sc, WI_RID_PROMISC, 1); } else if (!(ifp->if_flags & IFF_PROMISC) && sc->sc_if_flags & IFF_PROMISC) { wi_write_val(sc, WI_RID_PROMISC, 0); } else { wi_init(sc); } } else { wi_init(sc); } } else { if (ifp->if_flags & IFF_RUNNING) { wi_stop(ifp, 0); } } sc->sc_if_flags = ifp->if_flags; error = 0; break; case SIOCADDMULTI: case SIOCDELMULTI: error = wi_write_multi(sc); break; case SIOCGIFGENERIC: error = wi_get_cfg(ifp, cmd, data); break; case SIOCSIFGENERIC: error = suser(td); if (error) break; error = wi_set_cfg(ifp, cmd, data); break; case SIOCGPRISM2DEBUG: error = copyin(ifr->ifr_data, &wreq, sizeof(wreq)); if (error) break; if (!(ifp->if_flags & IFF_RUNNING) || sc->sc_firmware_type == WI_LUCENT) { error = EIO; break; } error = wi_get_debug(sc, &wreq); if (error == 0) error = copyout(&wreq, ifr->ifr_data, sizeof(wreq)); break; case SIOCSPRISM2DEBUG: if ((error = suser(td))) goto out; error = copyin(ifr->ifr_data, &wreq, sizeof(wreq)); if (error) break; error = wi_set_debug(sc, &wreq); break; case SIOCG80211: ireq = (struct ieee80211req *) data; switch (ireq->i_type) { case IEEE80211_IOC_STATIONNAME: ireq->i_len = sc->sc_nodelen + 1; error = copyout(sc->sc_nodename, ireq->i_data, ireq->i_len); break; default: error = ieee80211_ioctl(ifp, cmd, data); break; } break; case SIOCS80211: error = suser(td); if (error) break; ireq = (struct ieee80211req *) data; switch (ireq->i_type) { case IEEE80211_IOC_STATIONNAME: if (ireq->i_val != 0 || ireq->i_len > IEEE80211_NWID_LEN) { error = EINVAL; break; } memset(nodename, 0, IEEE80211_NWID_LEN); error = copyin(ireq->i_data, nodename, ireq->i_len); if (error) break; if (sc->sc_enabled) { error = wi_write_ssid(sc, WI_RID_NODENAME, nodename, ireq->i_len); if (error) break; } memcpy(sc->sc_nodename, nodename, IEEE80211_NWID_LEN); sc->sc_nodelen = ireq->i_len; break; default: error = ieee80211_ioctl(ifp, cmd, data); break; } break; default: error = ieee80211_ioctl(ifp, cmd, data); break; } if (error == ENETRESET) { if (sc->sc_enabled) wi_init(sc); /* XXX no error return */ error = 0; } out: WI_UNLOCK(sc); return (error); } static int wi_media_change(struct ifnet *ifp) { struct wi_softc *sc = ifp->if_softc; int error; error = ieee80211_media_change(ifp); if (error == ENETRESET) { if (sc->sc_enabled) wi_init(sc); /* XXX no error return */ error = 0; } return error; } static void wi_media_status(struct ifnet *ifp, struct ifmediareq *imr) { struct wi_softc *sc = ifp->if_softc; struct ieee80211com *ic = &sc->sc_ic; u_int16_t val; int rate, len; if (sc->wi_gone || !sc->sc_enabled) { imr->ifm_active = IFM_IEEE80211 | IFM_NONE; imr->ifm_status = 0; return; } imr->ifm_status = IFM_AVALID; imr->ifm_active = IFM_IEEE80211; if (ic->ic_state == IEEE80211_S_RUN && (sc->sc_flags & WI_FLAGS_OUTRANGE) == 0) imr->ifm_status |= IFM_ACTIVE; len = sizeof(val); if (wi_read_rid(sc, WI_RID_CUR_TX_RATE, &val, &len) != 0) rate = 0; else { /* convert to 802.11 rate */ rate = val * 2; if (sc->sc_firmware_type == WI_LUCENT) { if (rate == 4 * 2) rate = 11; /* 5.5Mbps */ else if (rate == 5 * 2) rate = 22; /* 11Mbps */ } else { if (rate == 4*2) rate = 11; /* 5.5Mbps */ else if (rate == 8*2) rate = 22; /* 11Mbps */ } } imr->ifm_active |= ieee80211_rate2media(ic, rate, IEEE80211_MODE_11B); switch (ic->ic_opmode) { case IEEE80211_M_STA: break; case IEEE80211_M_IBSS: imr->ifm_active |= IFM_IEEE80211_ADHOC; break; case IEEE80211_M_AHDEMO: imr->ifm_active |= IFM_IEEE80211_ADHOC | IFM_FLAG0; break; case IEEE80211_M_HOSTAP: imr->ifm_active |= IFM_IEEE80211_HOSTAP; break; } } static void wi_sync_bssid(struct wi_softc *sc, u_int8_t new_bssid[IEEE80211_ADDR_LEN]) { struct ieee80211com *ic = &sc->sc_ic; struct ieee80211_node *ni = ic->ic_bss; struct ifnet *ifp = &ic->ic_if; if (IEEE80211_ADDR_EQ(new_bssid, ni->ni_bssid)) return; DPRINTF(("wi_sync_bssid: bssid %s -> ", ether_sprintf(ni->ni_bssid))); DPRINTF(("%s ?\n", ether_sprintf(new_bssid))); /* In promiscuous mode, the BSSID field is not a reliable * indicator of the firmware's BSSID. Damp spurious * change-of-BSSID indications. */ if ((ifp->if_flags & IFF_PROMISC) != 0 && sc->sc_false_syns >= WI_MAX_FALSE_SYNS) return; - ieee80211_new_state(ifp, IEEE80211_S_RUN, -1); + ieee80211_new_state(ic, IEEE80211_S_RUN, -1); } static void wi_rx_monitor(struct wi_softc *sc, int fid) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; struct wi_frame *rx_frame; struct mbuf *m; int datlen, hdrlen; /* first allocate mbuf for packet storage */ m = m_getcl(M_DONTWAIT, MT_DATA, 0); if (m == NULL) { ifp->if_ierrors++; return; } m->m_pkthdr.rcvif = ifp; /* now read wi_frame first so we know how much data to read */ if (wi_read_bap(sc, fid, 0, mtod(m, caddr_t), sizeof(*rx_frame))) { ifp->if_ierrors++; goto done; } rx_frame = mtod(m, struct wi_frame *); switch ((rx_frame->wi_status & WI_STAT_MAC_PORT) >> 8) { case 7: switch (rx_frame->wi_whdr.i_fc[0] & IEEE80211_FC0_TYPE_MASK) { case IEEE80211_FC0_TYPE_DATA: hdrlen = WI_DATA_HDRLEN; datlen = rx_frame->wi_dat_len + WI_FCS_LEN; break; case IEEE80211_FC0_TYPE_MGT: hdrlen = WI_MGMT_HDRLEN; datlen = rx_frame->wi_dat_len + WI_FCS_LEN; break; case IEEE80211_FC0_TYPE_CTL: /* * prism2 cards don't pass control packets * down properly or consistently, so we'll only * pass down the header. */ hdrlen = WI_CTL_HDRLEN; datlen = 0; break; default: if_printf(ifp, "received packet of unknown type " "on port 7\n"); ifp->if_ierrors++; goto done; } break; case 0: hdrlen = WI_DATA_HDRLEN; datlen = rx_frame->wi_dat_len + WI_FCS_LEN; break; default: if_printf(ifp, "received packet on invalid " "port (wi_status=0x%x)\n", rx_frame->wi_status); ifp->if_ierrors++; goto done; } if (hdrlen + datlen + 2 > MCLBYTES) { if_printf(ifp, "oversized packet received " "(wi_dat_len=%d, wi_status=0x%x)\n", datlen, rx_frame->wi_status); ifp->if_ierrors++; goto done; } if (wi_read_bap(sc, fid, hdrlen, mtod(m, caddr_t) + hdrlen, datlen + 2) == 0) { m->m_pkthdr.len = m->m_len = hdrlen + datlen; ifp->if_ipackets++; BPF_MTAP(ifp, m); /* Handle BPF listeners. */ } else ifp->if_ierrors++; done: m_freem(m); } static void wi_rx_intr(struct wi_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; struct wi_frame frmhdr; struct mbuf *m; struct ieee80211_frame *wh; int fid, len, off, rssi; u_int8_t dir; u_int16_t status; u_int32_t rstamp; fid = CSR_READ_2(sc, WI_RX_FID); if (sc->wi_debug.wi_monitor) { /* * If we are in monitor mode just * read the data from the device. */ wi_rx_monitor(sc, fid); CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX); return; } /* First read in the frame header */ if (wi_read_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr))) { CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX); ifp->if_ierrors++; DPRINTF(("wi_rx_intr: read fid %x failed\n", fid)); return; } if (IFF_DUMPPKTS(ifp)) wi_dump_pkt(&frmhdr, NULL, frmhdr.wi_rx_signal); /* * Drop undecryptable or packets with receive errors here */ status = le16toh(frmhdr.wi_status); if (status & WI_STAT_ERRSTAT) { CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX); ifp->if_ierrors++; DPRINTF(("wi_rx_intr: fid %x error status %x\n", fid, status)); return; } rssi = frmhdr.wi_rx_signal; rstamp = (le16toh(frmhdr.wi_rx_tstamp0) << 16) | le16toh(frmhdr.wi_rx_tstamp1); len = le16toh(frmhdr.wi_dat_len); off = ALIGN(sizeof(struct ieee80211_frame)); MGETHDR(m, M_DONTWAIT, MT_DATA); if (m == NULL) { CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX); ifp->if_ierrors++; DPRINTF(("wi_rx_intr: MGET failed\n")); return; } if (off + len > MHLEN) { MCLGET(m, M_DONTWAIT); if ((m->m_flags & M_EXT) == 0) { CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX); m_freem(m); ifp->if_ierrors++; DPRINTF(("wi_rx_intr: MCLGET failed\n")); return; } } m->m_data += off - sizeof(struct ieee80211_frame); memcpy(m->m_data, &frmhdr.wi_whdr, sizeof(struct ieee80211_frame)); wi_read_bap(sc, fid, sizeof(frmhdr), m->m_data + sizeof(struct ieee80211_frame), len); m->m_pkthdr.len = m->m_len = sizeof(struct ieee80211_frame) + len; m->m_pkthdr.rcvif = ifp; CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX); #if NBPFILTER > 0 if (sc->sc_drvbpf) { struct mbuf *mb; MGETHDR(mb, M_DONTWAIT, m->m_type); if (mb != NULL) { (void) m_dup_pkthdr(mb, m, M_DONTWAIT); mb->m_next = m; mb->m_data = (caddr_t)&frmhdr; mb->m_len = sizeof(frmhdr); mb->m_pkthdr.len += mb->m_len; bpf_mtap(sc->sc_drvbpf, mb); m_free(mb); } } #endif wh = mtod(m, struct ieee80211_frame *); if (wh->i_fc[1] & IEEE80211_FC1_WEP) { /* * WEP is decrypted by hardware. Clear WEP bit * header for ieee80211_input(). */ wh->i_fc[1] &= ~IEEE80211_FC1_WEP; } /* synchronize driver's BSSID with firmware's BSSID */ dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK; if (ic->ic_opmode == IEEE80211_M_IBSS && dir == IEEE80211_FC1_DIR_NODS) wi_sync_bssid(sc, wh->i_addr3); ieee80211_input(ifp, m, rssi, rstamp, 0); } static void wi_tx_ex_intr(struct wi_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; struct wi_frame frmhdr; int fid; fid = CSR_READ_2(sc, WI_TX_CMP_FID); /* Read in the frame header */ if (wi_read_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr)) == 0) { u_int16_t status = le16toh(frmhdr.wi_status); /* * Spontaneous station disconnects appear as xmit * errors. Don't announce them and/or count them * as an output error. */ if ((status & WI_TXSTAT_DISCONNECT) == 0) { if (ppsratecheck(&lasttxerror, &curtxeps, wi_txerate)) { if_printf(ifp, "tx failed"); if (status & WI_TXSTAT_RET_ERR) printf(", retry limit exceeded"); if (status & WI_TXSTAT_AGED_ERR) printf(", max transmit lifetime exceeded"); if (status & WI_TXSTAT_DISCONNECT) printf(", port disconnected"); if (status & WI_TXSTAT_FORM_ERR) printf(", invalid format (data len %u src %6D)", le16toh(frmhdr.wi_dat_len), frmhdr.wi_ehdr.ether_shost, ":"); if (status & ~0xf) printf(", status=0x%x", status); printf("\n"); } ifp->if_oerrors++; } else { DPRINTF(("port disconnected\n")); ifp->if_collisions++; /* XXX */ } } else DPRINTF(("wi_tx_ex_intr: read fid %x failed\n", fid)); CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_TX_EXC); } static void wi_tx_intr(struct wi_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; int fid, cur; fid = CSR_READ_2(sc, WI_ALLOC_FID); CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_ALLOC); cur = sc->sc_txcur; if (sc->sc_txd[cur].d_fid != fid) { if_printf(ifp, "bad alloc %x != %x, cur %d nxt %d\n", fid, sc->sc_txd[cur].d_fid, cur, sc->sc_txnext); return; } sc->sc_tx_timer = 0; sc->sc_txd[cur].d_len = 0; sc->sc_txcur = cur = (cur + 1) % sc->sc_ntxbuf; if (sc->sc_txd[cur].d_len == 0) ifp->if_flags &= ~IFF_OACTIVE; else { if (wi_cmd(sc, WI_CMD_TX | WI_RECLAIM, sc->sc_txd[cur].d_fid, 0, 0)) { if_printf(ifp, "xmit failed\n"); sc->sc_txd[cur].d_len = 0; } else { sc->sc_tx_timer = 5; ifp->if_timer = 1; } } } static void wi_info_intr(struct wi_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; int i, fid, len, off; u_int16_t ltbuf[2]; u_int16_t stat; u_int32_t *ptr; fid = CSR_READ_2(sc, WI_INFO_FID); wi_read_bap(sc, fid, 0, ltbuf, sizeof(ltbuf)); switch (le16toh(ltbuf[1])) { case WI_INFO_LINK_STAT: wi_read_bap(sc, fid, sizeof(ltbuf), &stat, sizeof(stat)); DPRINTF(("wi_info_intr: LINK_STAT 0x%x\n", le16toh(stat))); switch (le16toh(stat)) { case WI_INFO_LINK_STAT_CONNECTED: sc->sc_flags &= ~WI_FLAGS_OUTRANGE; if (ic->ic_state == IEEE80211_S_RUN && ic->ic_opmode != IEEE80211_M_IBSS) break; /* FALLTHROUGH */ case WI_INFO_LINK_STAT_AP_CHG: - ieee80211_new_state(ifp, IEEE80211_S_RUN, -1); + ieee80211_new_state(ic, IEEE80211_S_RUN, -1); break; case WI_INFO_LINK_STAT_AP_INR: sc->sc_flags &= ~WI_FLAGS_OUTRANGE; break; case WI_INFO_LINK_STAT_AP_OOR: if (sc->sc_firmware_type == WI_SYMBOL && sc->sc_scan_timer > 0) { if (wi_cmd(sc, WI_CMD_INQUIRE, WI_INFO_HOST_SCAN_RESULTS, 0, 0) != 0) sc->sc_scan_timer = 0; break; } if (ic->ic_opmode == IEEE80211_M_STA) sc->sc_flags |= WI_FLAGS_OUTRANGE; break; case WI_INFO_LINK_STAT_DISCONNECTED: case WI_INFO_LINK_STAT_ASSOC_FAILED: if (ic->ic_opmode == IEEE80211_M_STA) - ieee80211_new_state(ifp, IEEE80211_S_INIT, -1); + ieee80211_new_state(ic, IEEE80211_S_INIT, -1); break; } break; case WI_INFO_COUNTERS: /* some card versions have a larger stats structure */ len = min(le16toh(ltbuf[0]) - 1, sizeof(sc->sc_stats) / 4); ptr = (u_int32_t *)&sc->sc_stats; off = sizeof(ltbuf); for (i = 0; i < len; i++, off += 2, ptr++) { wi_read_bap(sc, fid, off, &stat, sizeof(stat)); #ifdef WI_HERMES_STATS_WAR if (stat & 0xf000) stat = ~stat; #endif *ptr += stat; } ifp->if_collisions = sc->sc_stats.wi_tx_single_retries + sc->sc_stats.wi_tx_multi_retries + sc->sc_stats.wi_tx_retry_limit; break; case WI_INFO_SCAN_RESULTS: case WI_INFO_HOST_SCAN_RESULTS: wi_scan_result(sc, fid, le16toh(ltbuf[0])); break; default: DPRINTF(("wi_info_intr: got fid %x type %x len %d\n", fid, le16toh(ltbuf[1]), le16toh(ltbuf[0]))); break; } CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_INFO); } static int wi_write_multi(struct wi_softc *sc) { struct ifnet *ifp = &sc->sc_ic.ic_if; int n; struct ifmultiaddr *ifma; struct wi_mcast mlist; if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { allmulti: memset(&mlist, 0, sizeof(mlist)); return wi_write_rid(sc, WI_RID_MCAST_LIST, &mlist, sizeof(mlist)); } n = 0; #if __FreeBSD_version < 500000 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { #else TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { #endif if (ifma->ifma_addr->sa_family != AF_LINK) continue; if (n >= 16) goto allmulti; IEEE80211_ADDR_COPY(&mlist.wi_mcast[n], (LLADDR((struct sockaddr_dl *)ifma->ifma_addr))); n++; } return wi_write_rid(sc, WI_RID_MCAST_LIST, &mlist, IEEE80211_ADDR_LEN * n); } static void wi_read_nicid(struct wi_softc *sc) { struct wi_card_ident *id; char *p; int len; u_int16_t ver[4]; /* getting chip identity */ memset(ver, 0, sizeof(ver)); len = sizeof(ver); wi_read_rid(sc, WI_RID_CARD_ID, ver, &len); device_printf(sc->sc_dev, "using "); sc->sc_firmware_type = WI_NOTYPE; for (id = wi_card_ident; id->card_name != NULL; id++) { if (le16toh(ver[0]) == id->card_id) { printf("%s", id->card_name); sc->sc_firmware_type = id->firm_type; break; } } if (sc->sc_firmware_type == WI_NOTYPE) { if (le16toh(ver[0]) & 0x8000) { printf("Unknown PRISM2 chip"); sc->sc_firmware_type = WI_INTERSIL; } else { printf("Unknown Lucent chip"); sc->sc_firmware_type = WI_LUCENT; } } /* get primary firmware version (Only Prism chips) */ if (sc->sc_firmware_type != WI_LUCENT) { memset(ver, 0, sizeof(ver)); len = sizeof(ver); wi_read_rid(sc, WI_RID_PRI_IDENTITY, ver, &len); sc->sc_pri_firmware_ver = le16toh(ver[2]) * 10000 + le16toh(ver[3]) * 100 + le16toh(ver[1]); } /* get station firmware version */ memset(ver, 0, sizeof(ver)); len = sizeof(ver); wi_read_rid(sc, WI_RID_STA_IDENTITY, ver, &len); sc->sc_sta_firmware_ver = le16toh(ver[2]) * 10000 + le16toh(ver[3]) * 100 + le16toh(ver[1]); if (sc->sc_firmware_type == WI_INTERSIL && (sc->sc_sta_firmware_ver == 10102 || sc->sc_sta_firmware_ver == 20102)) { char ident[12]; memset(ident, 0, sizeof(ident)); len = sizeof(ident); /* value should be the format like "V2.00-11" */ if (wi_read_rid(sc, WI_RID_SYMBOL_IDENTITY, ident, &len) == 0 && *(p = (char *)ident) >= 'A' && p[2] == '.' && p[5] == '-' && p[8] == '\0') { sc->sc_firmware_type = WI_SYMBOL; sc->sc_sta_firmware_ver = (p[1] - '0') * 10000 + (p[3] - '0') * 1000 + (p[4] - '0') * 100 + (p[6] - '0') * 10 + (p[7] - '0'); } } printf("\n"); device_printf(sc->sc_dev, "%s Firmware: ", sc->sc_firmware_type == WI_LUCENT ? "Lucent" : (sc->sc_firmware_type == WI_SYMBOL ? "Symbol" : "Intersil")); if (sc->sc_firmware_type != WI_LUCENT) /* XXX */ printf("Primary (%u.%u.%u), ", sc->sc_pri_firmware_ver / 10000, (sc->sc_pri_firmware_ver % 10000) / 100, sc->sc_pri_firmware_ver % 100); printf("Station (%u.%u.%u)\n", sc->sc_sta_firmware_ver / 10000, (sc->sc_sta_firmware_ver % 10000) / 100, sc->sc_sta_firmware_ver % 100); } static int wi_write_ssid(struct wi_softc *sc, int rid, u_int8_t *buf, int buflen) { struct wi_ssid ssid; if (buflen > IEEE80211_NWID_LEN) return ENOBUFS; memset(&ssid, 0, sizeof(ssid)); ssid.wi_len = htole16(buflen); memcpy(ssid.wi_ssid, buf, buflen); return wi_write_rid(sc, rid, &ssid, sizeof(ssid)); } static int wi_get_cfg(struct ifnet *ifp, u_long cmd, caddr_t data) { struct wi_softc *sc = ifp->if_softc; struct ieee80211com *ic = &sc->sc_ic; struct ifreq *ifr = (struct ifreq *)data; struct wi_req wreq; struct wi_scan_res *res; int len, n, error, mif, val, off, i; error = copyin(ifr->ifr_data, &wreq, sizeof(wreq)); if (error) return error; len = (wreq.wi_len - 1) * 2; if (len < sizeof(u_int16_t)) return ENOSPC; if (len > sizeof(wreq.wi_val)) len = sizeof(wreq.wi_val); switch (wreq.wi_type) { case WI_RID_IFACE_STATS: memcpy(wreq.wi_val, &sc->sc_stats, sizeof(sc->sc_stats)); if (len < sizeof(sc->sc_stats)) error = ENOSPC; else len = sizeof(sc->sc_stats); break; case WI_RID_ENCRYPTION: case WI_RID_TX_CRYPT_KEY: case WI_RID_DEFLT_CRYPT_KEYS: case WI_RID_TX_RATE: return ieee80211_cfgget(ifp, cmd, data); case WI_RID_MICROWAVE_OVEN: if (sc->sc_enabled && (sc->sc_flags & WI_FLAGS_HAS_MOR)) { error = wi_read_rid(sc, wreq.wi_type, wreq.wi_val, &len); break; } wreq.wi_val[0] = htole16(sc->sc_microwave_oven); len = sizeof(u_int16_t); break; case WI_RID_DBM_ADJUST: if (sc->sc_enabled && (sc->sc_flags & WI_FLAGS_HAS_DBMADJUST)) { error = wi_read_rid(sc, wreq.wi_type, wreq.wi_val, &len); break; } wreq.wi_val[0] = htole16(sc->sc_dbm_adjust); len = sizeof(u_int16_t); break; case WI_RID_ROAMING_MODE: if (sc->sc_enabled && (sc->sc_flags & WI_FLAGS_HAS_ROAMING)) { error = wi_read_rid(sc, wreq.wi_type, wreq.wi_val, &len); break; } wreq.wi_val[0] = htole16(sc->sc_roaming_mode); len = sizeof(u_int16_t); break; case WI_RID_SYSTEM_SCALE: if (sc->sc_enabled && (sc->sc_flags & WI_FLAGS_HAS_SYSSCALE)) { error = wi_read_rid(sc, wreq.wi_type, wreq.wi_val, &len); break; } wreq.wi_val[0] = htole16(sc->sc_system_scale); len = sizeof(u_int16_t); break; case WI_RID_FRAG_THRESH: if (sc->sc_enabled && (sc->sc_flags & WI_FLAGS_HAS_FRAGTHR)) { error = wi_read_rid(sc, wreq.wi_type, wreq.wi_val, &len); break; } wreq.wi_val[0] = htole16(ic->ic_fragthreshold); len = sizeof(u_int16_t); break; case WI_RID_READ_APS: if (ic->ic_opmode == IEEE80211_M_HOSTAP) return ieee80211_cfgget(ifp, cmd, data); if (sc->sc_scan_timer > 0) { error = EINPROGRESS; break; } n = sc->sc_naps; if (len < sizeof(n)) { error = ENOSPC; break; } if (len < sizeof(n) + sizeof(struct wi_apinfo) * n) n = (len - sizeof(n)) / sizeof(struct wi_apinfo); len = sizeof(n) + sizeof(struct wi_apinfo) * n; memcpy(wreq.wi_val, &n, sizeof(n)); memcpy((caddr_t)wreq.wi_val + sizeof(n), sc->sc_aps, sizeof(struct wi_apinfo) * n); break; case WI_RID_PRISM2: wreq.wi_val[0] = sc->sc_firmware_type != WI_LUCENT; len = sizeof(u_int16_t); break; case WI_RID_MIF: mif = wreq.wi_val[0]; error = wi_cmd(sc, WI_CMD_READMIF, mif, 0, 0); val = CSR_READ_2(sc, WI_RESP0); wreq.wi_val[0] = val; len = sizeof(u_int16_t); break; case WI_RID_ZERO_CACHE: case WI_RID_PROCFRAME: /* ignore for compatibility */ /* XXX ??? */ break; case WI_RID_READ_CACHE: return ieee80211_cfgget(ifp, cmd, data); case WI_RID_SCAN_RES: /* compatibility interface */ if (ic->ic_opmode == IEEE80211_M_HOSTAP) return ieee80211_cfgget(ifp, cmd, data); if (sc->sc_scan_timer > 0) { error = EINPROGRESS; break; } n = sc->sc_naps; off = sc->sc_firmware_type != WI_LUCENT ? sizeof(struct wi_scan_p2_hdr) : 0; if (len < off + sizeof(struct wi_scan_res) * n) n = (len - off) / sizeof(struct wi_scan_res); len = off + sizeof(struct wi_scan_res) * n; if (off != 0) { struct wi_scan_p2_hdr *p2 = (struct wi_scan_p2_hdr *)wreq.wi_val; /* * Prepend Prism-specific header. */ if (len < sizeof(struct wi_scan_p2_hdr)) { error = ENOSPC; break; } p2 = (struct wi_scan_p2_hdr *)wreq.wi_val; p2->wi_rsvd = 0; p2->wi_reason = n; /* XXX */ } for (i = 0; i < n; i++) { const struct wi_apinfo *ap = &sc->sc_aps[i]; res = (struct wi_scan_res *)((char *)wreq.wi_val + off); res->wi_chan = ap->channel; res->wi_noise = ap->noise; res->wi_signal = ap->signal; IEEE80211_ADDR_COPY(res->wi_bssid, ap->bssid); res->wi_interval = ap->interval; res->wi_capinfo = ap->capinfo; res->wi_ssid_len = ap->namelen; memcpy(res->wi_ssid, ap->name, IEEE80211_NWID_LEN); if (sc->sc_firmware_type != WI_LUCENT) { /* XXX not saved from Prism cards */ memset(res->wi_srates, 0, sizeof(res->wi_srates)); res->wi_rate = ap->rate; res->wi_rsvd = 0; off += WI_PRISM2_RES_SIZE; } else off += WI_WAVELAN_RES_SIZE; } break; default: if (sc->sc_enabled) { error = wi_read_rid(sc, wreq.wi_type, wreq.wi_val, &len); break; } switch (wreq.wi_type) { case WI_RID_MAX_DATALEN: wreq.wi_val[0] = htole16(sc->sc_max_datalen); len = sizeof(u_int16_t); break; case WI_RID_RTS_THRESH: wreq.wi_val[0] = htole16(ic->ic_rtsthreshold); len = sizeof(u_int16_t); break; case WI_RID_CNFAUTHMODE: wreq.wi_val[0] = htole16(sc->sc_cnfauthmode); len = sizeof(u_int16_t); break; case WI_RID_NODENAME: if (len < sc->sc_nodelen + sizeof(u_int16_t)) { error = ENOSPC; break; } len = sc->sc_nodelen + sizeof(u_int16_t); wreq.wi_val[0] = htole16((sc->sc_nodelen + 1) / 2); memcpy(&wreq.wi_val[1], sc->sc_nodename, sc->sc_nodelen); break; default: return ieee80211_cfgget(ifp, cmd, data); } break; } if (error) return error; wreq.wi_len = (len + 1) / 2 + 1; return copyout(&wreq, ifr->ifr_data, (wreq.wi_len + 1) * 2); } static int wi_set_cfg(struct ifnet *ifp, u_long cmd, caddr_t data) { struct wi_softc *sc = ifp->if_softc; struct ieee80211com *ic = &sc->sc_ic; struct ifreq *ifr = (struct ifreq *)data; struct wi_req wreq; struct mbuf *m; int i, len, error, mif, val; struct ieee80211_rateset *rs; error = copyin(ifr->ifr_data, &wreq, sizeof(wreq)); if (error) return error; len = wreq.wi_len ? (wreq.wi_len - 1) * 2 : 0; switch (wreq.wi_type) { case WI_RID_DBM_ADJUST: return ENODEV; case WI_RID_NODENAME: if (le16toh(wreq.wi_val[0]) * 2 > len || le16toh(wreq.wi_val[0]) > sizeof(sc->sc_nodename)) { error = ENOSPC; break; } if (sc->sc_enabled) { error = wi_write_rid(sc, wreq.wi_type, wreq.wi_val, len); if (error) break; } sc->sc_nodelen = le16toh(wreq.wi_val[0]) * 2; memcpy(sc->sc_nodename, &wreq.wi_val[1], sc->sc_nodelen); break; case WI_RID_MICROWAVE_OVEN: case WI_RID_ROAMING_MODE: case WI_RID_SYSTEM_SCALE: case WI_RID_FRAG_THRESH: if (wreq.wi_type == WI_RID_MICROWAVE_OVEN && (sc->sc_flags & WI_FLAGS_HAS_MOR) == 0) break; if (wreq.wi_type == WI_RID_ROAMING_MODE && (sc->sc_flags & WI_FLAGS_HAS_ROAMING) == 0) break; if (wreq.wi_type == WI_RID_SYSTEM_SCALE && (sc->sc_flags & WI_FLAGS_HAS_SYSSCALE) == 0) break; if (wreq.wi_type == WI_RID_FRAG_THRESH && (sc->sc_flags & WI_FLAGS_HAS_FRAGTHR) == 0) break; /* FALLTHROUGH */ case WI_RID_RTS_THRESH: case WI_RID_CNFAUTHMODE: case WI_RID_MAX_DATALEN: if (sc->sc_enabled) { error = wi_write_rid(sc, wreq.wi_type, wreq.wi_val, sizeof(u_int16_t)); if (error) break; } switch (wreq.wi_type) { case WI_RID_FRAG_THRESH: ic->ic_fragthreshold = le16toh(wreq.wi_val[0]); break; case WI_RID_RTS_THRESH: ic->ic_rtsthreshold = le16toh(wreq.wi_val[0]); break; case WI_RID_MICROWAVE_OVEN: sc->sc_microwave_oven = le16toh(wreq.wi_val[0]); break; case WI_RID_ROAMING_MODE: sc->sc_roaming_mode = le16toh(wreq.wi_val[0]); break; case WI_RID_SYSTEM_SCALE: sc->sc_system_scale = le16toh(wreq.wi_val[0]); break; case WI_RID_CNFAUTHMODE: sc->sc_cnfauthmode = le16toh(wreq.wi_val[0]); break; case WI_RID_MAX_DATALEN: sc->sc_max_datalen = le16toh(wreq.wi_val[0]); break; } break; case WI_RID_TX_RATE: switch (le16toh(wreq.wi_val[0])) { case 3: ic->ic_fixed_rate = -1; break; default: rs = &ic->ic_sup_rates[IEEE80211_MODE_11B]; for (i = 0; i < rs->rs_nrates; i++) { if ((rs->rs_rates[i] & IEEE80211_RATE_VAL) / 2 == le16toh(wreq.wi_val[0])) break; } if (i == rs->rs_nrates) return EINVAL; ic->ic_fixed_rate = i; } if (sc->sc_enabled) error = wi_write_txrate(sc); break; case WI_RID_SCAN_APS: if (sc->sc_enabled && ic->ic_opmode != IEEE80211_M_HOSTAP) error = wi_scan_ap(sc, 0x3fff, 0x000f); break; case WI_RID_SCAN_REQ: /* compatibility interface */ if (sc->sc_enabled && ic->ic_opmode != IEEE80211_M_HOSTAP) error = wi_scan_ap(sc, wreq.wi_val[0], wreq.wi_val[1]); break; case WI_RID_MGMT_XMIT: if (!sc->sc_enabled) { error = ENETDOWN; break; } if (ic->ic_mgtq.ifq_len > 5) { error = EAGAIN; break; } /* XXX wi_len looks in u_int8_t, not in u_int16_t */ m = m_devget((char *)&wreq.wi_val, wreq.wi_len, 0, ifp, NULL); if (m == NULL) { error = ENOMEM; break; } IF_ENQUEUE(&ic->ic_mgtq, m); break; case WI_RID_MIF: mif = wreq.wi_val[0]; val = wreq.wi_val[1]; error = wi_cmd(sc, WI_CMD_WRITEMIF, mif, val, 0); break; case WI_RID_PROCFRAME: /* ignore for compatibility */ break; case WI_RID_OWN_SSID: if (le16toh(wreq.wi_val[0]) * 2 > len || le16toh(wreq.wi_val[0]) > IEEE80211_NWID_LEN) { error = ENOSPC; break; } memset(ic->ic_des_essid, 0, IEEE80211_NWID_LEN); ic->ic_des_esslen = le16toh(wreq.wi_val[0]) * 2; memcpy(ic->ic_des_essid, &wreq.wi_val[1], ic->ic_des_esslen); error = ENETRESET; break; default: if (sc->sc_enabled) { error = wi_write_rid(sc, wreq.wi_type, wreq.wi_val, len); if (error) break; } error = ieee80211_cfgset(ifp, cmd, data); break; } return error; } static int wi_write_txrate(struct wi_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; int i; u_int16_t rate; if (ic->ic_fixed_rate < 0) rate = 0; /* auto */ else rate = (ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[ic->ic_fixed_rate] & IEEE80211_RATE_VAL) / 2; /* rate: 0, 1, 2, 5, 11 */ switch (sc->sc_firmware_type) { case WI_LUCENT: switch (rate) { case 0: /* auto == 11mbps auto */ rate = 3; break; /* case 1, 2 map to 1, 2*/ case 5: /* 5.5Mbps -> 4 */ rate = 4; break; case 11: /* 11mbps -> 5 */ rate = 5; break; default: break; } break; default: /* Choose a bit according to this table. * * bit | data rate * ----+------------------- * 0 | 1Mbps * 1 | 2Mbps * 2 | 5.5Mbps * 3 | 11Mbps */ for (i = 8; i > 0; i >>= 1) { if (rate >= i) break; } if (i == 0) rate = 0xf; /* auto */ else rate = i; break; } return wi_write_val(sc, WI_RID_TX_RATE, rate); } static int wi_write_wep(struct wi_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; int error = 0; int i, keylen; u_int16_t val; struct wi_key wkey[IEEE80211_WEP_NKID]; switch (sc->sc_firmware_type) { case WI_LUCENT: val = (ic->ic_flags & IEEE80211_F_WEPON) ? 1 : 0; error = wi_write_val(sc, WI_RID_ENCRYPTION, val); if (error) break; error = wi_write_val(sc, WI_RID_TX_CRYPT_KEY, ic->ic_wep_txkey); if (error) break; memset(wkey, 0, sizeof(wkey)); for (i = 0; i < IEEE80211_WEP_NKID; i++) { keylen = ic->ic_nw_keys[i].wk_len; wkey[i].wi_keylen = htole16(keylen); memcpy(wkey[i].wi_keydat, ic->ic_nw_keys[i].wk_key, keylen); } error = wi_write_rid(sc, WI_RID_DEFLT_CRYPT_KEYS, wkey, sizeof(wkey)); break; case WI_INTERSIL: case WI_SYMBOL: if (ic->ic_flags & IEEE80211_F_WEPON) { /* * ONLY HWB3163 EVAL-CARD Firmware version * less than 0.8 variant2 * * If promiscuous mode disable, Prism2 chip * does not work with WEP . * It is under investigation for details. * (ichiro@netbsd.org) */ if (sc->sc_firmware_type == WI_INTERSIL && sc->sc_sta_firmware_ver < 802 ) { /* firm ver < 0.8 variant 2 */ wi_write_val(sc, WI_RID_PROMISC, 1); } wi_write_val(sc, WI_RID_CNFAUTHMODE, sc->sc_cnfauthmode); val = PRIVACY_INVOKED | EXCLUDE_UNENCRYPTED; /* * Encryption firmware has a bug for HostAP mode. */ if (sc->sc_firmware_type == WI_INTERSIL && ic->ic_opmode == IEEE80211_M_HOSTAP) val |= HOST_ENCRYPT; } else { wi_write_val(sc, WI_RID_CNFAUTHMODE, IEEE80211_AUTH_OPEN); val = HOST_ENCRYPT | HOST_DECRYPT; } error = wi_write_val(sc, WI_RID_P2_ENCRYPTION, val); if (error) break; error = wi_write_val(sc, WI_RID_P2_TX_CRYPT_KEY, ic->ic_wep_txkey); if (error) break; /* * It seems that the firmware accept 104bit key only if * all the keys have 104bit length. We get the length of * the transmit key and use it for all other keys. * Perhaps we should use software WEP for such situation. */ keylen = ic->ic_nw_keys[ic->ic_wep_txkey].wk_len; if (keylen > IEEE80211_WEP_KEYLEN) keylen = 13; /* 104bit keys */ else keylen = IEEE80211_WEP_KEYLEN; for (i = 0; i < IEEE80211_WEP_NKID; i++) { error = wi_write_rid(sc, WI_RID_P2_CRYPT_KEY0 + i, ic->ic_nw_keys[i].wk_key, keylen); if (error) break; } break; } return error; } static int wi_cmd(struct wi_softc *sc, int cmd, int val0, int val1, int val2) { int i, s = 0; static volatile int count = 0; if (count > 0) panic("Hey partner, hold on there!"); count++; /* wait for the busy bit to clear */ for (i = 500; i > 0; i--) { /* 5s */ if (!(CSR_READ_2(sc, WI_COMMAND) & WI_CMD_BUSY)) break; DELAY(10*1000); /* 10 m sec */ } if (i == 0) { device_printf(sc->sc_dev, "wi_cmd: busy bit won't clear.\n" ); count--; return(ETIMEDOUT); } CSR_WRITE_2(sc, WI_PARAM0, val0); CSR_WRITE_2(sc, WI_PARAM1, val1); CSR_WRITE_2(sc, WI_PARAM2, val2); CSR_WRITE_2(sc, WI_COMMAND, cmd); if (cmd == WI_CMD_INI) { /* XXX: should sleep here. */ DELAY(100*1000); /* 100ms delay for init */ } for (i = 0; i < WI_TIMEOUT; i++) { /* * Wait for 'command complete' bit to be * set in the event status register. */ s = CSR_READ_2(sc, WI_EVENT_STAT); if (s & WI_EV_CMD) { /* Ack the event and read result code. */ s = CSR_READ_2(sc, WI_STATUS); CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_CMD); if (s & WI_STAT_CMD_RESULT) { count--; return(EIO); } break; } DELAY(WI_DELAY); } count--; if (i == WI_TIMEOUT) { device_printf(sc->sc_dev, "timeout in wi_cmd 0x%04x; event status 0x%04x\n", cmd, s); return(ETIMEDOUT); } return (0); } static int wi_seek_bap(struct wi_softc *sc, int id, int off) { int i, status; CSR_WRITE_2(sc, WI_SEL0, id); CSR_WRITE_2(sc, WI_OFF0, off); for (i = 0; ; i++) { status = CSR_READ_2(sc, WI_OFF0); if ((status & WI_OFF_BUSY) == 0) break; if (i == WI_TIMEOUT) { device_printf(sc->sc_dev, "timeout in wi_seek to %x/%x\n", id, off); sc->sc_bap_off = WI_OFF_ERR; /* invalidate */ return ETIMEDOUT; } DELAY(1); } if (status & WI_OFF_ERR) { device_printf(sc->sc_dev, "failed in wi_seek to %x/%x\n", id, off); sc->sc_bap_off = WI_OFF_ERR; /* invalidate */ return EIO; } sc->sc_bap_id = id; sc->sc_bap_off = off; return 0; } static int wi_read_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen) { u_int16_t *ptr; int i, error, cnt; if (buflen == 0) return 0; if (id != sc->sc_bap_id || off != sc->sc_bap_off) { if ((error = wi_seek_bap(sc, id, off)) != 0) return error; } cnt = (buflen + 1) / 2; ptr = (u_int16_t *)buf; for (i = 0; i < cnt; i++) *ptr++ = CSR_READ_2(sc, WI_DATA0); sc->sc_bap_off += cnt * 2; return 0; } static int wi_write_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen) { u_int16_t *ptr; int i, error, cnt; if (buflen == 0) return 0; #ifdef WI_HERMES_AUTOINC_WAR again: #endif if (id != sc->sc_bap_id || off != sc->sc_bap_off) { if ((error = wi_seek_bap(sc, id, off)) != 0) return error; } cnt = (buflen + 1) / 2; ptr = (u_int16_t *)buf; for (i = 0; i < cnt; i++) CSR_WRITE_2(sc, WI_DATA0, ptr[i]); sc->sc_bap_off += cnt * 2; #ifdef WI_HERMES_AUTOINC_WAR /* * According to the comments in the HCF Light code, there is a bug * in the Hermes (or possibly in certain Hermes firmware revisions) * where the chip's internal autoincrement counter gets thrown off * during data writes: the autoincrement is missed, causing one * data word to be overwritten and subsequent words to be written to * the wrong memory locations. The end result is that we could end * up transmitting bogus frames without realizing it. The workaround * for this is to write a couple of extra guard words after the end * of the transfer, then attempt to read then back. If we fail to * locate the guard words where we expect them, we preform the * transfer over again. */ if ((sc->sc_flags & WI_FLAGS_BUG_AUTOINC) && (id & 0xf000) == 0) { CSR_WRITE_2(sc, WI_DATA0, 0x1234); CSR_WRITE_2(sc, WI_DATA0, 0x5678); wi_seek_bap(sc, id, sc->sc_bap_off); sc->sc_bap_off = WI_OFF_ERR; /* invalidate */ if (CSR_READ_2(sc, WI_DATA0) != 0x1234 || CSR_READ_2(sc, WI_DATA0) != 0x5678) { device_printf(sc->sc_dev, "detect auto increment bug, try again\n"); goto again; } } #endif return 0; } static int wi_mwrite_bap(struct wi_softc *sc, int id, int off, struct mbuf *m0, int totlen) { int error, len; struct mbuf *m; for (m = m0; m != NULL && totlen > 0; m = m->m_next) { if (m->m_len == 0) continue; len = min(m->m_len, totlen); if (((u_long)m->m_data) % 2 != 0 || len % 2 != 0) { m_copydata(m, 0, totlen, (caddr_t)&sc->sc_txbuf); return wi_write_bap(sc, id, off, (caddr_t)&sc->sc_txbuf, totlen); } if ((error = wi_write_bap(sc, id, off, m->m_data, len)) != 0) return error; off += m->m_len; totlen -= len; } return 0; } static int wi_alloc_fid(struct wi_softc *sc, int len, int *idp) { int i; if (wi_cmd(sc, WI_CMD_ALLOC_MEM, len, 0, 0)) { device_printf(sc->sc_dev, "failed to allocate %d bytes on NIC\n", len); return ENOMEM; } for (i = 0; i < WI_TIMEOUT; i++) { if (CSR_READ_2(sc, WI_EVENT_STAT) & WI_EV_ALLOC) break; if (i == WI_TIMEOUT) { device_printf(sc->sc_dev, "timeout in alloc\n"); return ETIMEDOUT; } DELAY(1); } *idp = CSR_READ_2(sc, WI_ALLOC_FID); CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_ALLOC); return 0; } static int wi_read_rid(struct wi_softc *sc, int rid, void *buf, int *buflenp) { int error, len; u_int16_t ltbuf[2]; /* Tell the NIC to enter record read mode. */ error = wi_cmd(sc, WI_CMD_ACCESS | WI_ACCESS_READ, rid, 0, 0); if (error) return error; error = wi_read_bap(sc, rid, 0, ltbuf, sizeof(ltbuf)); if (error) return error; if (le16toh(ltbuf[1]) != rid) { device_printf(sc->sc_dev, "record read mismatch, rid=%x, got=%x\n", rid, le16toh(ltbuf[1])); return EIO; } len = (le16toh(ltbuf[0]) - 1) * 2; /* already got rid */ if (*buflenp < len) { device_printf(sc->sc_dev, "record buffer is too small, " "rid=%x, size=%d, len=%d\n", rid, *buflenp, len); return ENOSPC; } *buflenp = len; return wi_read_bap(sc, rid, sizeof(ltbuf), buf, len); } static int wi_write_rid(struct wi_softc *sc, int rid, void *buf, int buflen) { int error; u_int16_t ltbuf[2]; ltbuf[0] = htole16((buflen + 1) / 2 + 1); /* includes rid */ ltbuf[1] = htole16(rid); error = wi_write_bap(sc, rid, 0, ltbuf, sizeof(ltbuf)); if (error) return error; error = wi_write_bap(sc, rid, sizeof(ltbuf), buf, buflen); if (error) return error; return wi_cmd(sc, WI_CMD_ACCESS | WI_ACCESS_WRITE, rid, 0, 0); } static int -wi_newstate(void *arg, enum ieee80211_state nstate) +wi_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg) { - struct wi_softc *sc = arg; - struct ieee80211com *ic = &sc->sc_ic; + struct ifnet *ifp = &ic->ic_if; + struct wi_softc *sc = ifp->if_softc; struct ieee80211_node *ni = ic->ic_bss; int buflen; u_int16_t val; struct wi_ssid ssid; u_int8_t old_bssid[IEEE80211_ADDR_LEN]; - enum ieee80211_state ostate; -#ifdef WI_DEBUG - static const char *stname[] = - { "INIT", "SCAN", "AUTH", "ASSOC", "RUN" }; -#endif /* WI_DEBUG */ - ostate = ic->ic_state; - DPRINTF(("wi_newstate: %s -> %s\n", stname[ostate], stname[nstate])); + DPRINTF(("%s: %s -> %s\n", __func__, + ieee80211_state_name[ic->ic_state], + ieee80211_state_name[nstate])); - ic->ic_state = nstate; switch (nstate) { case IEEE80211_S_INIT: ic->ic_flags &= ~IEEE80211_F_SIBSS; sc->sc_flags &= ~WI_FLAGS_OUTRANGE; - return 0; + return (*sc->sc_newstate)(ic, nstate, arg); case IEEE80211_S_RUN: sc->sc_flags &= ~WI_FLAGS_OUTRANGE; buflen = IEEE80211_ADDR_LEN; wi_read_rid(sc, WI_RID_CURRENT_BSSID, ni->ni_bssid, &buflen); IEEE80211_ADDR_COPY(ni->ni_macaddr, ni->ni_bssid); buflen = sizeof(val); wi_read_rid(sc, WI_RID_CURRENT_CHAN, &val, &buflen); /* XXX validate channel */ ni->ni_chan = &ic->ic_channels[le16toh(val)]; if (IEEE80211_ADDR_EQ(old_bssid, ni->ni_bssid)) sc->sc_false_syns++; else sc->sc_false_syns = 0; if (ic->ic_opmode == IEEE80211_M_HOSTAP) { ni->ni_esslen = ic->ic_des_esslen; memcpy(ni->ni_essid, ic->ic_des_essid, ni->ni_esslen); ni->ni_rates = ic->ic_sup_rates[IEEE80211_MODE_11B]; ni->ni_intval = ic->ic_lintval; ni->ni_capinfo = IEEE80211_CAPINFO_ESS; if (ic->ic_flags & IEEE80211_F_WEPON) ni->ni_capinfo |= IEEE80211_CAPINFO_PRIVACY; } else { /* XXX check return value */ buflen = sizeof(ssid); wi_read_rid(sc, WI_RID_CURRENT_SSID, &ssid, &buflen); ni->ni_esslen = le16toh(ssid.wi_len); if (ni->ni_esslen > IEEE80211_NWID_LEN) ni->ni_esslen = IEEE80211_NWID_LEN; /*XXX*/ memcpy(ni->ni_essid, ssid.wi_ssid, ni->ni_esslen); } break; case IEEE80211_S_SCAN: case IEEE80211_S_AUTH: case IEEE80211_S_ASSOC: break; } - /* skip standard ieee80211 handling */ - return EINPROGRESS; + ic->ic_state = nstate; /* NB: skip normal ieee80211 handling */ + return 0; } static int wi_scan_ap(struct wi_softc *sc, u_int16_t chanmask, u_int16_t txrate) { int error = 0; u_int16_t val[2]; if (!sc->sc_enabled) return ENXIO; switch (sc->sc_firmware_type) { case WI_LUCENT: (void)wi_cmd(sc, WI_CMD_INQUIRE, WI_INFO_SCAN_RESULTS, 0, 0); break; case WI_INTERSIL: val[0] = chanmask; /* channel */ val[1] = txrate; /* tx rate */ error = wi_write_rid(sc, WI_RID_SCAN_REQ, val, sizeof(val)); break; case WI_SYMBOL: /* * XXX only supported on 3.x ? */ val[0] = BSCAN_BCAST | BSCAN_ONETIME; error = wi_write_rid(sc, WI_RID_BCAST_SCAN_REQ, val, sizeof(val[0])); break; } if (error == 0) { sc->sc_scan_timer = WI_SCAN_WAIT; sc->sc_ic.ic_if.if_timer = 1; DPRINTF(("wi_scan_ap: start scanning, " "chamask 0x%x txrate 0x%x\n", chanmask, txrate)); } return error; } static void wi_scan_result(struct wi_softc *sc, int fid, int cnt) { #define N(a) (sizeof (a) / sizeof (a[0])) int i, naps, off, szbuf; struct wi_scan_header ws_hdr; /* Prism2 header */ struct wi_scan_data_p2 ws_dat; /* Prism2 scantable*/ struct wi_apinfo *ap; off = sizeof(u_int16_t) * 2; memset(&ws_hdr, 0, sizeof(ws_hdr)); switch (sc->sc_firmware_type) { case WI_INTERSIL: wi_read_bap(sc, fid, off, &ws_hdr, sizeof(ws_hdr)); off += sizeof(ws_hdr); szbuf = sizeof(struct wi_scan_data_p2); break; case WI_SYMBOL: szbuf = sizeof(struct wi_scan_data_p2) + 6; break; case WI_LUCENT: szbuf = sizeof(struct wi_scan_data); break; default: device_printf(sc->sc_dev, "wi_scan_result: unknown firmware type %u\n", sc->sc_firmware_type); naps = 0; goto done; } naps = (cnt * 2 + 2 - off) / szbuf; if (naps > N(sc->sc_aps)) naps = N(sc->sc_aps); sc->sc_naps = naps; /* Read Data */ ap = sc->sc_aps; memset(&ws_dat, 0, sizeof(ws_dat)); for (i = 0; i < naps; i++, ap++) { wi_read_bap(sc, fid, off, &ws_dat, (sizeof(ws_dat) < szbuf ? sizeof(ws_dat) : szbuf)); DPRINTF2(("wi_scan_result: #%d: off %d bssid %s\n", i, off, ether_sprintf(ws_dat.wi_bssid))); off += szbuf; ap->scanreason = le16toh(ws_hdr.wi_reason); memcpy(ap->bssid, ws_dat.wi_bssid, sizeof(ap->bssid)); ap->channel = le16toh(ws_dat.wi_chid); ap->signal = le16toh(ws_dat.wi_signal); ap->noise = le16toh(ws_dat.wi_noise); ap->quality = ap->signal - ap->noise; ap->capinfo = le16toh(ws_dat.wi_capinfo); ap->interval = le16toh(ws_dat.wi_interval); ap->rate = le16toh(ws_dat.wi_rate); ap->namelen = le16toh(ws_dat.wi_namelen); if (ap->namelen > sizeof(ap->name)) ap->namelen = sizeof(ap->name); memcpy(ap->name, ws_dat.wi_name, ap->namelen); } done: /* Done scanning */ sc->sc_scan_timer = 0; DPRINTF(("wi_scan_result: scan complete: ap %d\n", naps)); #undef N } static void wi_dump_pkt(struct wi_frame *wh, struct ieee80211_node *ni, int rssi) { ieee80211_dump_pkt((u_int8_t *) &wh->wi_whdr, sizeof(wh->wi_whdr), ni ? ni->ni_rates.rs_rates[ni->ni_txrate] & IEEE80211_RATE_VAL : -1, rssi); printf(" status 0x%x rx_tstamp1 %u rx_tstamp0 0x%u rx_silence %u\n", le16toh(wh->wi_status), le16toh(wh->wi_rx_tstamp1), le16toh(wh->wi_rx_tstamp0), wh->wi_rx_silence); printf(" rx_signal %u rx_rate %u rx_flow %u\n", wh->wi_rx_signal, wh->wi_rx_rate, wh->wi_rx_flow); printf(" tx_rtry %u tx_rate %u tx_ctl 0x%x dat_len %u\n", wh->wi_tx_rtry, wh->wi_tx_rate, le16toh(wh->wi_tx_ctl), le16toh(wh->wi_dat_len)); printf(" ehdr dst %6D src %6D type 0x%x\n", wh->wi_ehdr.ether_dhost, ":", wh->wi_ehdr.ether_shost, ":", wh->wi_ehdr.ether_type); } int wi_alloc(device_t dev, int rid) { struct wi_softc *sc = device_get_softc(dev); if (sc->wi_bus_type != WI_BUS_PCI_NATIVE) { sc->iobase_rid = rid; sc->iobase = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->iobase_rid, 0, ~0, (1 << 6), rman_make_alignment_flags(1 << 6) | RF_ACTIVE); if (!sc->iobase) { device_printf(dev, "No I/O space?!\n"); return (ENXIO); } sc->wi_io_addr = rman_get_start(sc->iobase); sc->wi_btag = rman_get_bustag(sc->iobase); sc->wi_bhandle = rman_get_bushandle(sc->iobase); } else { sc->mem_rid = rid; sc->mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mem_rid, 0, ~0, 1, RF_ACTIVE); if (!sc->mem) { device_printf(dev, "No Mem space on prism2.5?\n"); return (ENXIO); } sc->wi_btag = rman_get_bustag(sc->mem); sc->wi_bhandle = rman_get_bushandle(sc->mem); } sc->irq_rid = 0; sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid, 0, ~0, 1, RF_ACTIVE | ((sc->wi_bus_type == WI_BUS_PCCARD) ? 0 : RF_SHAREABLE)); if (!sc->irq) { wi_free(dev); device_printf(dev, "No irq?!\n"); return (ENXIO); } sc->sc_dev = dev; sc->sc_unit = device_get_unit(dev); return (0); } void wi_free(device_t dev) { struct wi_softc *sc = device_get_softc(dev); if (sc->iobase != NULL) { bus_release_resource(dev, SYS_RES_IOPORT, sc->iobase_rid, sc->iobase); sc->iobase = NULL; } if (sc->irq != NULL) { bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq); sc->irq = NULL; } if (sc->mem != NULL) { bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem); sc->mem = NULL; } return; } static int wi_get_debug(struct wi_softc *sc, struct wi_req *wreq) { int error = 0; wreq->wi_len = 1; switch (wreq->wi_type) { case WI_DEBUG_SLEEP: wreq->wi_len++; wreq->wi_val[0] = sc->wi_debug.wi_sleep; break; case WI_DEBUG_DELAYSUPP: wreq->wi_len++; wreq->wi_val[0] = sc->wi_debug.wi_delaysupp; break; case WI_DEBUG_TXSUPP: wreq->wi_len++; wreq->wi_val[0] = sc->wi_debug.wi_txsupp; break; case WI_DEBUG_MONITOR: wreq->wi_len++; wreq->wi_val[0] = sc->wi_debug.wi_monitor; break; case WI_DEBUG_LEDTEST: wreq->wi_len += 3; wreq->wi_val[0] = sc->wi_debug.wi_ledtest; wreq->wi_val[1] = sc->wi_debug.wi_ledtest_param0; wreq->wi_val[2] = sc->wi_debug.wi_ledtest_param1; break; case WI_DEBUG_CONTTX: wreq->wi_len += 2; wreq->wi_val[0] = sc->wi_debug.wi_conttx; wreq->wi_val[1] = sc->wi_debug.wi_conttx_param0; break; case WI_DEBUG_CONTRX: wreq->wi_len++; wreq->wi_val[0] = sc->wi_debug.wi_contrx; break; case WI_DEBUG_SIGSTATE: wreq->wi_len += 2; wreq->wi_val[0] = sc->wi_debug.wi_sigstate; wreq->wi_val[1] = sc->wi_debug.wi_sigstate_param0; break; case WI_DEBUG_CONFBITS: wreq->wi_len += 2; wreq->wi_val[0] = sc->wi_debug.wi_confbits; wreq->wi_val[1] = sc->wi_debug.wi_confbits_param0; break; default: error = EIO; break; } return (error); } static int wi_set_debug(struct wi_softc *sc, struct wi_req *wreq) { int error = 0; u_int16_t cmd, param0 = 0, param1 = 0; switch (wreq->wi_type) { case WI_DEBUG_RESET: case WI_DEBUG_INIT: case WI_DEBUG_CALENABLE: break; case WI_DEBUG_SLEEP: sc->wi_debug.wi_sleep = 1; break; case WI_DEBUG_WAKE: sc->wi_debug.wi_sleep = 0; break; case WI_DEBUG_CHAN: param0 = wreq->wi_val[0]; break; case WI_DEBUG_DELAYSUPP: sc->wi_debug.wi_delaysupp = 1; break; case WI_DEBUG_TXSUPP: sc->wi_debug.wi_txsupp = 1; break; case WI_DEBUG_MONITOR: sc->wi_debug.wi_monitor = 1; break; case WI_DEBUG_LEDTEST: param0 = wreq->wi_val[0]; param1 = wreq->wi_val[1]; sc->wi_debug.wi_ledtest = 1; sc->wi_debug.wi_ledtest_param0 = param0; sc->wi_debug.wi_ledtest_param1 = param1; break; case WI_DEBUG_CONTTX: param0 = wreq->wi_val[0]; sc->wi_debug.wi_conttx = 1; sc->wi_debug.wi_conttx_param0 = param0; break; case WI_DEBUG_STOPTEST: sc->wi_debug.wi_delaysupp = 0; sc->wi_debug.wi_txsupp = 0; sc->wi_debug.wi_monitor = 0; sc->wi_debug.wi_ledtest = 0; sc->wi_debug.wi_ledtest_param0 = 0; sc->wi_debug.wi_ledtest_param1 = 0; sc->wi_debug.wi_conttx = 0; sc->wi_debug.wi_conttx_param0 = 0; sc->wi_debug.wi_contrx = 0; sc->wi_debug.wi_sigstate = 0; sc->wi_debug.wi_sigstate_param0 = 0; break; case WI_DEBUG_CONTRX: sc->wi_debug.wi_contrx = 1; break; case WI_DEBUG_SIGSTATE: param0 = wreq->wi_val[0]; sc->wi_debug.wi_sigstate = 1; sc->wi_debug.wi_sigstate_param0 = param0; break; case WI_DEBUG_CONFBITS: param0 = wreq->wi_val[0]; param1 = wreq->wi_val[1]; sc->wi_debug.wi_confbits = param0; sc->wi_debug.wi_confbits_param0 = param1; break; default: error = EIO; break; } if (error) return (error); cmd = WI_CMD_DEBUG | (wreq->wi_type << 8); error = wi_cmd(sc, cmd, param0, param1, 0); return (error); } #if __FreeBSD_version >= 500000 /* * Special routines to download firmware for Symbol CF card. * XXX: This should be modified generic into any PRISM-2 based card. */ #define WI_SBCF_PDIADDR 0x3100 /* unaligned load little endian */ #define GETLE32(p) ((p)[0] | ((p)[1]<<8) | ((p)[2]<<16) | ((p)[3]<<24)) #define GETLE16(p) ((p)[0] | ((p)[1]<<8)) int wi_symbol_load_firm(struct wi_softc *sc, const void *primsym, int primlen, const void *secsym, int seclen) { uint8_t ebuf[256]; int i; /* load primary code and run it */ wi_symbol_set_hcr(sc, WI_HCR_EEHOLD); if (wi_symbol_write_firm(sc, primsym, primlen, NULL, 0)) return EIO; wi_symbol_set_hcr(sc, WI_HCR_RUN); for (i = 0; ; i++) { if (i == 10) return ETIMEDOUT; tsleep(sc, PWAIT, "wiinit", 1); if (CSR_READ_2(sc, WI_CNTL) == WI_CNTL_AUX_ENA_STAT) break; /* write the magic key value to unlock aux port */ CSR_WRITE_2(sc, WI_PARAM0, WI_AUX_KEY0); CSR_WRITE_2(sc, WI_PARAM1, WI_AUX_KEY1); CSR_WRITE_2(sc, WI_PARAM2, WI_AUX_KEY2); CSR_WRITE_2(sc, WI_CNTL, WI_CNTL_AUX_ENA_CNTL); } /* issue read EEPROM command: XXX copied from wi_cmd() */ CSR_WRITE_2(sc, WI_PARAM0, 0); CSR_WRITE_2(sc, WI_PARAM1, 0); CSR_WRITE_2(sc, WI_PARAM2, 0); CSR_WRITE_2(sc, WI_COMMAND, WI_CMD_READEE); for (i = 0; i < WI_TIMEOUT; i++) { if (CSR_READ_2(sc, WI_EVENT_STAT) & WI_EV_CMD) break; DELAY(1); } CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_CMD); CSR_WRITE_2(sc, WI_AUX_PAGE, WI_SBCF_PDIADDR / WI_AUX_PGSZ); CSR_WRITE_2(sc, WI_AUX_OFFSET, WI_SBCF_PDIADDR % WI_AUX_PGSZ); CSR_READ_MULTI_STREAM_2(sc, WI_AUX_DATA, (uint16_t *)ebuf, sizeof(ebuf) / 2); if (GETLE16(ebuf) > sizeof(ebuf)) return EIO; if (wi_symbol_write_firm(sc, secsym, seclen, ebuf + 4, GETLE16(ebuf))) return EIO; return 0; } static int wi_symbol_write_firm(struct wi_softc *sc, const void *buf, int buflen, const void *ebuf, int ebuflen) { const uint8_t *p, *ep, *q, *eq; char *tp; uint32_t addr, id, eid; int i, len, elen, nblk, pdrlen; /* * Parse the header of the firmware image. */ p = buf; ep = p + buflen; while (p < ep && *p++ != ' '); /* FILE: */ while (p < ep && *p++ != ' '); /* filename */ while (p < ep && *p++ != ' '); /* type of the firmware */ nblk = strtoul(p, &tp, 10); p = tp; pdrlen = strtoul(p + 1, &tp, 10); p = tp; while (p < ep && *p++ != 0x1a); /* skip rest of header */ /* * Block records: address[4], length[2], data[length]; */ for (i = 0; i < nblk; i++) { addr = GETLE32(p); p += 4; len = GETLE16(p); p += 2; CSR_WRITE_2(sc, WI_AUX_PAGE, addr / WI_AUX_PGSZ); CSR_WRITE_2(sc, WI_AUX_OFFSET, addr % WI_AUX_PGSZ); CSR_WRITE_MULTI_STREAM_2(sc, WI_AUX_DATA, (const uint16_t *)p, len / 2); p += len; } /* * PDR: id[4], address[4], length[4]; */ for (i = 0; i < pdrlen; ) { id = GETLE32(p); p += 4; i += 4; addr = GETLE32(p); p += 4; i += 4; len = GETLE32(p); p += 4; i += 4; /* replace PDR entry with the values from EEPROM, if any */ for (q = ebuf, eq = q + ebuflen; q < eq; q += elen * 2) { elen = GETLE16(q); q += 2; eid = GETLE16(q); q += 2; elen--; /* elen includes eid */ if (eid == 0) break; if (eid != id) continue; CSR_WRITE_2(sc, WI_AUX_PAGE, addr / WI_AUX_PGSZ); CSR_WRITE_2(sc, WI_AUX_OFFSET, addr % WI_AUX_PGSZ); CSR_WRITE_MULTI_STREAM_2(sc, WI_AUX_DATA, (const uint16_t *)q, len / 2); break; } } return 0; } static int wi_symbol_set_hcr(struct wi_softc *sc, int mode) { uint16_t hcr; CSR_WRITE_2(sc, WI_COR, WI_COR_RESET); tsleep(sc, PWAIT, "wiinit", 1); hcr = CSR_READ_2(sc, WI_HCR); hcr = (hcr & WI_HCR_4WIRE) | (mode & ~WI_HCR_4WIRE); CSR_WRITE_2(sc, WI_HCR, hcr); tsleep(sc, PWAIT, "wiinit", 1); CSR_WRITE_2(sc, WI_COR, WI_COR_IOMODE); tsleep(sc, PWAIT, "wiinit", 1); return 0; } #endif Index: head/sys/dev/wi/if_wivar.h =================================================================== --- head/sys/dev/wi/if_wivar.h (revision 117811) +++ head/sys/dev/wi/if_wivar.h (revision 117812) @@ -1,211 +1,213 @@ /* * Copyright (c) 2002 * M Warner Losh . All rights reserved. * Copyright (c) 1997, 1998, 1999 * Bill Paul . All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Bill Paul. * 4. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #if 0 #define WICACHE /* turn on signal strength cache code */ #define MAXWICACHE 10 #endif /* * Encryption controls. We can enable or disable encryption as * well as specify up to 4 encryption keys. We can also specify * which of the four keys will be used for transmit encryption. */ #define WI_RID_ENCRYPTION 0xFC20 #define WI_RID_AUTHTYPE 0xFC21 #define WI_RID_DEFLT_CRYPT_KEYS 0xFCB0 #define WI_RID_TX_CRYPT_KEY 0xFCB1 #define WI_RID_WEP_AVAIL 0xFD4F #define WI_RID_P2_TX_CRYPT_KEY 0xFC23 #define WI_RID_P2_CRYPT_KEY0 0xFC24 #define WI_RID_P2_CRYPT_KEY1 0xFC25 #define WI_RID_MICROWAVE_OVEN 0xFC25 #define WI_RID_P2_CRYPT_KEY2 0xFC26 #define WI_RID_P2_CRYPT_KEY3 0xFC27 #define WI_RID_P2_ENCRYPTION 0xFC28 #define WI_RID_ROAMING_MODE 0xFC2D #define WI_RID_CUR_TX_RATE 0xFD44 /* current TX rate */ struct wi_softc { struct ieee80211com sc_ic; + int (*sc_newstate)(struct ieee80211com *, + enum ieee80211_state, int); device_t sc_dev; #if __FreeBSD_version >= 500000 struct mtx sc_mtx; #endif int sc_unit; int wi_gone; int sc_enabled; int sc_reset; int sc_firmware_type; #define WI_NOTYPE 0 #define WI_LUCENT 1 #define WI_INTERSIL 2 #define WI_SYMBOL 3 int sc_pri_firmware_ver; /* Primary firmware */ int sc_sta_firmware_ver; /* Station firmware */ int wi_bus_type; /* Bus attachment type */ struct resource * local; int local_rid; struct resource * iobase; int iobase_rid; struct resource * irq; int irq_rid; struct resource * mem; int mem_rid; bus_space_handle_t wi_localhandle; bus_space_tag_t wi_localtag; bus_space_handle_t wi_bhandle; bus_space_tag_t wi_btag; bus_space_handle_t wi_bmemhandle; bus_space_tag_t wi_bmemtag; void * wi_intrhand; int wi_io_addr; struct bpf_if *sc_drvbpf; int sc_flags; int sc_if_flags; int sc_bap_id; int sc_bap_off; u_int16_t sc_procframe; u_int16_t sc_portnum; u_int16_t sc_dbm_adjust; u_int16_t sc_max_datalen; u_int16_t sc_system_scale; u_int16_t sc_cnfauthmode; u_int16_t sc_roaming_mode; u_int16_t sc_microwave_oven; u_int16_t sc_authtype; int sc_nodelen; char sc_nodename[IEEE80211_NWID_LEN]; char sc_net_name[IEEE80211_NWID_LEN]; int sc_buflen; /* TX buffer size */ int sc_ntxbuf; #define WI_NTXBUF 3 struct { int d_fid; int d_len; } sc_txd[WI_NTXBUF]; /* TX buffers */ int sc_txnext; /* index of next TX */ int sc_txcur; /* index of current TX*/ int sc_tx_timer; int sc_scan_timer; int sc_syn_timer; struct wi_counters sc_stats; u_int16_t sc_ibss_port; #define WI_MAXAPINFO 30 struct wi_apinfo sc_aps[WI_MAXAPINFO]; int sc_naps; struct { u_int16_t wi_sleep; u_int16_t wi_delaysupp; u_int16_t wi_txsupp; u_int16_t wi_monitor; u_int16_t wi_ledtest; u_int16_t wi_ledtest_param0; u_int16_t wi_ledtest_param1; u_int16_t wi_conttx; u_int16_t wi_conttx_param0; u_int16_t wi_contrx; u_int16_t wi_sigstate; u_int16_t wi_sigstate_param0; u_int16_t wi_confbits; u_int16_t wi_confbits_param0; } wi_debug; int sc_false_syns; u_int16_t sc_txbuf[IEEE80211_MAX_LEN/2]; }; #define sc_if sc_ic.ic_if /* maximum consecutive false change-of-BSSID indications */ #define WI_MAX_FALSE_SYNS 10 #define WI_SCAN_INQWAIT 3 /* wait sec before inquire */ #define WI_SCAN_WAIT 5 /* maximum scan wait */ #define WI_FLAGS_ATTACHED 0x0001 #define WI_FLAGS_INITIALIZED 0x0002 #define WI_FLAGS_OUTRANGE 0x0004 #define WI_FLAGS_HAS_MOR 0x0010 #define WI_FLAGS_HAS_ROAMING 0x0020 #define WI_FLAGS_HAS_DIVERSITY 0x0040 #define WI_FLAGS_HAS_SYSSCALE 0x0080 #define WI_FLAGS_BUG_AUTOINC 0x0100 #define WI_FLAGS_HAS_FRAGTHR 0x0200 #define WI_FLAGS_HAS_DBMADJUST 0x0400 struct wi_card_ident { u_int16_t card_id; char *card_name; u_int8_t firm_type; }; #if __FreeBSD_version < 500000 /* * Various compat hacks/kludges */ #define le16toh(x) (x) #define htole16(x) (x) #define ifaddr_byindex(idx) ifnet_addrs[(idx) - 1]; #define WI_LOCK_DECL() int s #define WI_LOCK(_sc) s = splimp() #define WI_UNLOCK(_sc) splx(s) #else #define WI_LOCK_DECL() #define WI_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) #define WI_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) #endif int wi_attach(device_t); int wi_detach(device_t); void wi_shutdown(device_t); int wi_alloc(device_t, int); void wi_free(device_t); extern devclass_t wi_devclass; void wi_init(void *); void wi_intr(void *); int wi_mgmt_xmit(struct wi_softc *, caddr_t, int); void wi_stop(struct ifnet *, int); int wi_symbol_load_firm(struct wi_softc *, const void *, int, const void *, int);