2001-11-13 16:14:31 +03:00
|
|
|
/* $NetBSD: awi.c,v 1.41 2001/11/13 13:14:35 lukem Exp $ */
|
1999-11-05 08:13:36 +03:00
|
|
|
|
2000-06-09 18:36:25 +04:00
|
|
|
/*-
|
2001-09-18 13:09:57 +04:00
|
|
|
* Copyright (c) 1999,2000,2001 The NetBSD Foundation, Inc.
|
1999-11-04 20:10:53 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2000-06-09 18:36:25 +04:00
|
|
|
* by Bill Sommerfeld
|
1999-11-04 20:10:53 +03:00
|
|
|
*
|
|
|
|
* 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:
|
2000-06-09 18:36:25 +04:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
1999-11-04 20:10:53 +03:00
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* 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.
|
|
|
|
*/
|
2000-06-09 18:36:25 +04:00
|
|
|
/*
|
|
|
|
* Driver for AMD 802.11 firmware.
|
|
|
|
* Uses am79c930 chip driver to talk to firmware running on the am79c930.
|
|
|
|
*
|
|
|
|
* More-or-less a generic ethernet-like if driver, with 802.11 gorp added.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* todo:
|
|
|
|
* - flush tx queue on resynch.
|
|
|
|
* - clear oactive on "down".
|
|
|
|
* - rewrite copy-into-mbuf code
|
|
|
|
* - mgmt state machine gets stuck retransmitting assoc requests.
|
|
|
|
* - multicast filter.
|
|
|
|
* - fix device reset so it's more likely to work
|
|
|
|
* - show status goo through ifmedia.
|
|
|
|
*
|
|
|
|
* more todo:
|
|
|
|
* - deal with more 802.11 frames.
|
|
|
|
* - send reassoc request
|
|
|
|
* - deal with reassoc response
|
|
|
|
* - send/deal with disassociation
|
|
|
|
* - deal with "full" access points (no room for me).
|
|
|
|
* - power save mode
|
|
|
|
*
|
|
|
|
* later:
|
|
|
|
* - SSID preferences
|
|
|
|
* - need ioctls for poking at the MIBs
|
|
|
|
* - implement ad-hoc mode (including bss creation).
|
|
|
|
* - decide when to do "ad hoc" vs. infrastructure mode (IFF_LINK flags?)
|
|
|
|
* (focus on inf. mode since that will be needed for ietf)
|
|
|
|
* - deal with DH vs. FH versions of the card
|
|
|
|
* - deal with faster cards (2mb/s)
|
|
|
|
* - ?WEP goo (mmm, rc4) (it looks not particularly useful).
|
|
|
|
* - ifmedia revision.
|
|
|
|
* - common 802.11 mibish things.
|
|
|
|
* - common 802.11 media layer.
|
|
|
|
*/
|
1999-11-04 20:10:53 +03:00
|
|
|
|
|
|
|
/*
|
2000-03-22 14:22:20 +03:00
|
|
|
* Driver for AMD 802.11 PCnetMobile firmware.
|
|
|
|
* Uses am79c930 chip driver to talk to firmware running on the am79c930.
|
1999-11-04 20:10:53 +03:00
|
|
|
*
|
2000-03-22 14:22:20 +03:00
|
|
|
* The initial version of the driver was written by
|
|
|
|
* Bill Sommerfeld <sommerfeld@netbsd.org>.
|
|
|
|
* Then the driver module completely rewritten to support cards with DS phy
|
|
|
|
* and to support adhoc mode by Atsushi Onoe <onoe@netbsd.org>
|
1999-11-04 20:10:53 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__KERNEL_RCSID(0, "$NetBSD: awi.c,v 1.41 2001/11/13 13:14:35 lukem Exp $");
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "bpfilter.h"
|
1999-11-04 20:10:53 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mbuf.h>
|
2000-03-22 14:22:20 +03:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/proc.h>
|
1999-11-04 20:10:53 +03:00
|
|
|
#include <sys/socket.h>
|
2000-03-22 14:22:20 +03:00
|
|
|
#include <sys/sockio.h>
|
1999-11-04 20:10:53 +03:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_media.h>
|
2000-03-22 14:22:20 +03:00
|
|
|
#include <net/if_llc.h>
|
|
|
|
#include <net/if_ieee80211.h>
|
1999-11-04 20:10:53 +03:00
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
2000-03-22 14:22:20 +03:00
|
|
|
#ifdef __NetBSD__
|
1999-11-04 20:10:53 +03:00
|
|
|
#include <netinet/if_inarp.h>
|
2000-03-22 14:22:20 +03:00
|
|
|
#else
|
|
|
|
#include <netinet/if_ether.h>
|
|
|
|
#endif
|
1999-11-04 20:10:53 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
#include <dev/ic/am79c930reg.h>
|
|
|
|
#include <dev/ic/am79c930var.h>
|
|
|
|
#include <dev/ic/awireg.h>
|
|
|
|
#include <dev/ic/awivar.h>
|
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
static int awi_init(struct ifnet *);
|
|
|
|
static void awi_stop(struct ifnet *, int);
|
|
|
|
static void awi_start(struct ifnet *);
|
|
|
|
static void awi_watchdog(struct ifnet *);
|
|
|
|
static int awi_ioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
static int awi_media_change(struct ifnet *);
|
|
|
|
static void awi_media_status(struct ifnet *, struct ifmediareq *);
|
|
|
|
static int awi_mode_init(struct awi_softc *);
|
|
|
|
static int awi_media_rate2opt(struct awi_softc *, int);
|
|
|
|
static int awi_media_opt2rate(struct awi_softc *, int);
|
|
|
|
static void awi_rx_int(struct awi_softc *);
|
|
|
|
static void awi_tx_int(struct awi_softc *);
|
|
|
|
static struct mbuf *awi_devget(struct awi_softc *, u_int32_t, u_int16_t);
|
|
|
|
static int awi_hw_init(struct awi_softc *);
|
|
|
|
static int awi_init_mibs(struct awi_softc *);
|
|
|
|
static int awi_chan_check(void *, u_char *);
|
|
|
|
static int awi_mib(struct awi_softc *, u_int8_t, u_int8_t, int);
|
|
|
|
static int awi_cmd(struct awi_softc *, u_int8_t, int);
|
|
|
|
static int awi_cmd_wait(struct awi_softc *);
|
|
|
|
static void awi_cmd_done(struct awi_softc *);
|
|
|
|
static int awi_next_txd(struct awi_softc *, int, u_int32_t *, u_int32_t *);
|
|
|
|
static int awi_lock(struct awi_softc *);
|
|
|
|
static void awi_unlock(struct awi_softc *);
|
|
|
|
static int awi_intr_lock(struct awi_softc *);
|
|
|
|
static void awi_intr_unlock(struct awi_softc *);
|
|
|
|
static int awi_newstate(void *, enum ieee80211_state);
|
|
|
|
static struct mbuf *awi_ether_encap(struct awi_softc *, struct mbuf *);
|
|
|
|
static struct mbuf *awi_ether_modcap(struct awi_softc *, struct mbuf *);
|
|
|
|
|
|
|
|
/* unalligned little endian access */
|
|
|
|
#define LE_READ_2(p) \
|
|
|
|
((((u_int8_t *)(p))[0] ) | (((u_int8_t *)(p))[1] << 8))
|
|
|
|
#define LE_READ_4(p) \
|
|
|
|
((((u_int8_t *)(p))[0] ) | (((u_int8_t *)(p))[1] << 8) | \
|
|
|
|
(((u_int8_t *)(p))[2] << 16) | (((u_int8_t *)(p))[3] << 24))
|
|
|
|
#define LE_WRITE_2(p, v) \
|
|
|
|
((((u_int8_t *)(p))[0] = (((u_int32_t)(v) ) & 0xff)), \
|
|
|
|
(((u_int8_t *)(p))[1] = (((u_int32_t)(v) >> 8) & 0xff)))
|
|
|
|
#define LE_WRITE_4(p, v) \
|
|
|
|
((((u_int8_t *)(p))[0] = (((u_int32_t)(v) ) & 0xff)), \
|
|
|
|
(((u_int8_t *)(p))[1] = (((u_int32_t)(v) >> 8) & 0xff)), \
|
|
|
|
(((u_int8_t *)(p))[2] = (((u_int32_t)(v) >> 16) & 0xff)), \
|
|
|
|
(((u_int8_t *)(p))[3] = (((u_int32_t)(v) >> 24) & 0xff)))
|
|
|
|
|
|
|
|
struct awi_chanset awi_chanset[] = {
|
|
|
|
/* PHY type domain min max def */
|
|
|
|
{ AWI_PHY_TYPE_FH, AWI_REG_DOMAIN_JP, 6, 17, 6 },
|
|
|
|
{ AWI_PHY_TYPE_FH, AWI_REG_DOMAIN_ES, 0, 26, 1 },
|
|
|
|
{ AWI_PHY_TYPE_FH, AWI_REG_DOMAIN_FR, 0, 32, 1 },
|
|
|
|
{ AWI_PHY_TYPE_FH, AWI_REG_DOMAIN_US, 0, 77, 1 },
|
|
|
|
{ AWI_PHY_TYPE_FH, AWI_REG_DOMAIN_CA, 0, 77, 1 },
|
|
|
|
{ AWI_PHY_TYPE_FH, AWI_REG_DOMAIN_EU, 0, 77, 1 },
|
|
|
|
{ AWI_PHY_TYPE_DS, AWI_REG_DOMAIN_JP, 14, 14, 14 },
|
|
|
|
{ AWI_PHY_TYPE_DS, AWI_REG_DOMAIN_ES, 10, 11, 10 },
|
|
|
|
{ AWI_PHY_TYPE_DS, AWI_REG_DOMAIN_FR, 10, 13, 10 },
|
|
|
|
{ AWI_PHY_TYPE_DS, AWI_REG_DOMAIN_US, 1, 11, 3 },
|
|
|
|
{ AWI_PHY_TYPE_DS, AWI_REG_DOMAIN_CA, 1, 11, 3 },
|
|
|
|
{ AWI_PHY_TYPE_DS, AWI_REG_DOMAIN_EU, 1, 13, 3 },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
2000-03-22 14:22:20 +03:00
|
|
|
|
|
|
|
#ifdef AWI_DEBUG
|
2001-09-18 13:09:57 +04:00
|
|
|
int awi_debug;
|
1999-11-09 17:58:07 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
#define DPRINTF(X) if (awi_debug) printf X
|
|
|
|
#define DPRINTF2(X) if (awi_debug > 1) printf X
|
2000-03-22 14:22:20 +03:00
|
|
|
#else
|
2001-09-18 13:09:57 +04:00
|
|
|
#define DPRINTF(X)
|
|
|
|
#define DPRINTF2(X)
|
1999-11-04 20:10:53 +03:00
|
|
|
#endif
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
int
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_attach(struct awi_softc *sc)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
struct ifnet *ifp = &ic->ic_if;
|
|
|
|
int s, i, error, nrate;
|
2000-03-22 14:22:20 +03:00
|
|
|
int mword;
|
|
|
|
struct ifmediareq imr;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
s = splnet();
|
|
|
|
sc->sc_busy = 1;
|
2001-09-18 13:09:57 +04:00
|
|
|
ic->ic_state = IEEE80211_S_INIT;
|
|
|
|
sc->sc_substate = AWI_ST_NONE;
|
|
|
|
if ((error = awi_hw_init(sc)) != 0) {
|
2000-03-22 14:22:20 +03:00
|
|
|
sc->sc_invalid = 1;
|
|
|
|
splx(s);
|
|
|
|
return error;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
error = awi_init_mibs(sc);
|
2001-09-18 13:09:57 +04:00
|
|
|
if (error != 0) {
|
2000-03-22 14:22:20 +03:00
|
|
|
sc->sc_invalid = 1;
|
2001-09-18 13:09:57 +04:00
|
|
|
splx(s);
|
2000-03-22 14:22:20 +03:00
|
|
|
return error;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
ifp->if_softc = sc;
|
2001-09-18 13:09:57 +04:00
|
|
|
ifp->if_flags =
|
|
|
|
IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST | IFF_NOTRAILERS;
|
2000-03-22 14:22:20 +03:00
|
|
|
ifp->if_ioctl = awi_ioctl;
|
2001-09-18 13:09:57 +04:00
|
|
|
ifp->if_start = awi_start;
|
2001-06-28 14:40:04 +04:00
|
|
|
ifp->if_init = awi_init;
|
|
|
|
ifp->if_stop = awi_stop;
|
2001-09-18 13:09:57 +04:00
|
|
|
ifp->if_watchdog = awi_watchdog;
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
2001-09-18 13:09:57 +04:00
|
|
|
memcpy(ifp->if_xname, sc->sc_dev.dv_xname, IFNAMSIZ);
|
|
|
|
|
|
|
|
ic->ic_flags = IEEE80211_F_HASWEP | IEEE80211_F_HASIBSS;
|
|
|
|
ic->ic_newstate = awi_newstate;
|
|
|
|
ic->ic_chancheck = awi_chan_check;
|
|
|
|
nrate = sc->sc_mib_phy.aSuprt_Data_Rates[1];
|
|
|
|
memcpy(ic->ic_sup_rates, sc->sc_mib_phy.aSuprt_Data_Rates + 2, nrate);
|
|
|
|
memcpy(ic->ic_myaddr, sc->sc_mib_addr.aMAC_Address, IEEE80211_ADDR_LEN);
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-06-09 09:31:15 +04:00
|
|
|
printf("%s: IEEE802.11 %s %dMbps (firmware %s)\n",
|
2000-03-22 14:22:20 +03:00
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH ? "FH" : "DS",
|
2001-09-18 13:09:57 +04:00
|
|
|
(ic->ic_sup_rates[nrate - 1] & IEEE80211_RATE_VAL) / 2,
|
|
|
|
sc->sc_banner);
|
|
|
|
printf("%s: 802.11 address: %s\n", sc->sc_dev.dv_xname,
|
|
|
|
ether_sprintf(ic->ic_myaddr));
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
if_attach(ifp);
|
2001-09-18 13:09:57 +04:00
|
|
|
ieee80211_ifattach(ifp);
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
ifmedia_init(&sc->sc_media, 0, awi_media_change, awi_media_status);
|
2001-09-18 13:09:57 +04:00
|
|
|
mword = IFM_MAKEWORD(IFM_IEEE80211, IFM_AUTO, 0, 0);
|
|
|
|
ifmedia_add(&sc->sc_media, mword, 0, NULL);
|
|
|
|
ifmedia_add(&sc->sc_media, mword | IFM_FLAG0, 0, NULL);
|
|
|
|
mword |= IFM_IEEE80211_ADHOC;
|
|
|
|
ifmedia_add(&sc->sc_media, mword, 0, NULL);
|
|
|
|
ifmedia_add(&sc->sc_media, mword | IFM_FLAG0, 0, NULL);
|
|
|
|
for (i = 0; i < nrate; i++) {
|
|
|
|
mword = awi_media_rate2opt(sc, ic->ic_sup_rates[i]);
|
2000-03-22 14:22:20 +03:00
|
|
|
if (mword == 0)
|
|
|
|
continue;
|
|
|
|
mword |= IFM_IEEE80211;
|
|
|
|
ifmedia_add(&sc->sc_media, mword, 0, NULL);
|
2001-09-18 13:09:57 +04:00
|
|
|
ifmedia_add(&sc->sc_media, mword | IFM_FLAG0, 0, NULL);
|
|
|
|
mword |= IFM_IEEE80211_ADHOC;
|
|
|
|
ifmedia_add(&sc->sc_media, mword, 0, NULL);
|
2000-07-04 18:27:56 +04:00
|
|
|
if (sc->sc_mib_phy.IEEE_PHY_Type != AWI_PHY_TYPE_FH)
|
2001-09-18 13:09:57 +04:00
|
|
|
ifmedia_add(&sc->sc_media, mword | IFM_FLAG0, 0, NULL);
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
awi_media_status(ifp, &imr);
|
|
|
|
ifmedia_set(&sc->sc_media, imr.ifm_active);
|
2001-09-18 13:09:57 +04:00
|
|
|
|
|
|
|
if ((sc->sc_sdhook = shutdownhook_establish(awi_shutdown, sc)) == NULL)
|
|
|
|
printf("%s: WARNING: unable to establish shutdown hook\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
if ((sc->sc_powerhook = powerhook_establish(awi_power, sc)) == NULL)
|
|
|
|
printf("%s: WARNING: unable to establish power hook\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
sc->sc_attached = 1;
|
|
|
|
splx(s);
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
/* ready to accept ioctl */
|
|
|
|
awi_unlock(sc);
|
2000-05-29 21:37:12 +04:00
|
|
|
|
1999-11-04 20:10:53 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
int
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_detach(struct awi_softc *sc)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
2000-03-22 14:22:20 +03:00
|
|
|
int s;
|
|
|
|
|
2000-05-29 21:37:12 +04:00
|
|
|
if (!sc->sc_attached)
|
2001-09-18 13:09:57 +04:00
|
|
|
return 0;
|
2000-05-29 21:37:12 +04:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
s = splnet();
|
|
|
|
sc->sc_invalid = 1;
|
2001-06-28 14:40:04 +04:00
|
|
|
awi_stop(ifp, 1);
|
2000-03-22 14:22:20 +03:00
|
|
|
while (sc->sc_sleep_cnt > 0) {
|
|
|
|
wakeup(sc);
|
|
|
|
(void)tsleep(sc, PWAIT, "awidet", 1);
|
|
|
|
}
|
|
|
|
ifmedia_delete_instance(&sc->sc_media, IFM_INST_ANY);
|
2001-09-18 13:09:57 +04:00
|
|
|
ieee80211_ifdetach(ifp);
|
2000-03-22 14:22:20 +03:00
|
|
|
if_detach(ifp);
|
2001-09-18 13:09:57 +04:00
|
|
|
shutdownhook_disestablish(sc->sc_sdhook);
|
|
|
|
powerhook_disestablish(sc->sc_powerhook);
|
2000-03-22 14:22:20 +03:00
|
|
|
splx(s);
|
|
|
|
return 0;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_activate(struct device *self, enum devact act)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2000-03-22 14:22:20 +03:00
|
|
|
struct awi_softc *sc = (struct awi_softc *)self;
|
2001-09-18 13:09:57 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
2000-03-22 14:22:20 +03:00
|
|
|
int s, error = 0;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
s = splnet();
|
|
|
|
switch (act) {
|
|
|
|
case DVACT_ACTIVATE:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
case DVACT_DEACTIVATE:
|
|
|
|
sc->sc_invalid = 1;
|
2001-09-18 13:09:57 +04:00
|
|
|
if_deactivate(ifp);
|
2000-03-22 14:22:20 +03:00
|
|
|
break;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
splx(s);
|
|
|
|
return error;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_power(int why, void *arg)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct awi_softc *sc = arg;
|
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
2000-03-22 14:22:20 +03:00
|
|
|
int s;
|
2000-06-09 09:31:15 +04:00
|
|
|
int ocansleep;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
DPRINTF(("awi_power: %d\n", why));
|
2000-03-22 14:22:20 +03:00
|
|
|
s = splnet();
|
2000-06-09 09:31:15 +04:00
|
|
|
ocansleep = sc->sc_cansleep;
|
|
|
|
sc->sc_cansleep = 0;
|
2000-11-26 14:08:57 +03:00
|
|
|
switch (why) {
|
|
|
|
case PWR_SUSPEND:
|
|
|
|
case PWR_STANDBY:
|
2001-06-28 14:40:04 +04:00
|
|
|
awi_stop(ifp, 1);
|
2000-11-26 14:08:57 +03:00
|
|
|
break;
|
|
|
|
case PWR_RESUME:
|
2001-06-28 14:40:04 +04:00
|
|
|
if (ifp->if_flags & IFF_UP) {
|
|
|
|
awi_init(ifp);
|
2001-09-18 13:09:57 +04:00
|
|
|
(void)awi_intr(sc); /* make sure */
|
2001-06-26 12:41:19 +04:00
|
|
|
}
|
2000-11-26 14:08:57 +03:00
|
|
|
break;
|
|
|
|
case PWR_SOFTSUSPEND:
|
|
|
|
case PWR_SOFTSTANDBY:
|
|
|
|
case PWR_SOFTRESUME:
|
|
|
|
break;
|
2000-06-09 09:31:15 +04:00
|
|
|
}
|
|
|
|
sc->sc_cansleep = ocansleep;
|
2000-03-22 14:22:20 +03:00
|
|
|
splx(s);
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
void
|
|
|
|
awi_shutdown(void *arg)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct awi_softc *sc = arg;
|
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
if (sc->sc_attached)
|
|
|
|
awi_stop(ifp, 1);
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
int
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_intr(void *arg)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2000-03-22 14:22:20 +03:00
|
|
|
struct awi_softc *sc = arg;
|
|
|
|
u_int16_t status;
|
|
|
|
int error, handled = 0, ocansleep;
|
2001-09-18 13:09:57 +04:00
|
|
|
#ifdef AWI_DEBUG
|
|
|
|
static const char *intname[] = {
|
|
|
|
"CMD", "RX", "TX", "SCAN_CMPLT",
|
|
|
|
"CFP_START", "DTIM", "CFP_ENDING", "GROGGY",
|
|
|
|
"TXDATA", "TXBCAST", "TXPS", "TXCF",
|
|
|
|
"TXMGT", "#13", "RXDATA", "RXMGT"
|
|
|
|
};
|
|
|
|
#endif
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-27 16:54:59 +04:00
|
|
|
if (!sc->sc_enabled || !sc->sc_enab_intr || sc->sc_invalid)
|
2000-03-22 14:22:20 +03:00
|
|
|
return 0;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
am79c930_gcr_setbits(&sc->sc_chip,
|
|
|
|
AM79C930_GCR_DISPWDN | AM79C930_GCR_ECINT);
|
|
|
|
awi_write_1(sc, AWI_DIS_PWRDN, 1);
|
|
|
|
ocansleep = sc->sc_cansleep;
|
|
|
|
sc->sc_cansleep = 0;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
for (;;) {
|
2001-09-18 13:09:57 +04:00
|
|
|
if ((error = awi_intr_lock(sc)) != 0)
|
2000-03-22 14:22:20 +03:00
|
|
|
break;
|
|
|
|
status = awi_read_1(sc, AWI_INTSTAT);
|
|
|
|
awi_write_1(sc, AWI_INTSTAT, 0);
|
|
|
|
awi_write_1(sc, AWI_INTSTAT, 0);
|
|
|
|
status |= awi_read_1(sc, AWI_INTSTAT2) << 8;
|
|
|
|
awi_write_1(sc, AWI_INTSTAT2, 0);
|
|
|
|
DELAY(10);
|
|
|
|
awi_intr_unlock(sc);
|
|
|
|
if (!sc->sc_cmd_inprog)
|
|
|
|
status &= ~AWI_INT_CMD; /* make sure */
|
|
|
|
if (status == 0)
|
|
|
|
break;
|
2001-09-18 13:09:57 +04:00
|
|
|
#ifdef AWI_DEBUG
|
|
|
|
if (awi_debug > 1) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("awi_intr: status 0x%04x", status);
|
|
|
|
for (i = 0; i < sizeof(intname)/sizeof(intname[0]);
|
|
|
|
i++) {
|
|
|
|
if (status & (1 << i))
|
|
|
|
printf(" %s", intname[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
2000-03-22 14:22:20 +03:00
|
|
|
handled = 1;
|
|
|
|
if (status & AWI_INT_RX)
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_rx_int(sc);
|
2000-03-22 14:22:20 +03:00
|
|
|
if (status & AWI_INT_TX)
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_tx_int(sc);
|
2000-03-22 14:22:20 +03:00
|
|
|
if (status & AWI_INT_CMD)
|
|
|
|
awi_cmd_done(sc);
|
|
|
|
if (status & AWI_INT_SCAN_CMPLT) {
|
2001-09-18 13:09:57 +04:00
|
|
|
if (sc->sc_ic.ic_state == IEEE80211_S_SCAN)
|
|
|
|
ieee80211_next_scan(&sc->sc_ic.ic_if);
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sc->sc_cansleep = ocansleep;
|
|
|
|
am79c930_gcr_clearbits(&sc->sc_chip, AM79C930_GCR_DISPWDN);
|
|
|
|
awi_write_1(sc, AWI_DIS_PWRDN, 0);
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
static int
|
|
|
|
awi_init(struct ifnet *ifp)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-06-28 14:40:04 +04:00
|
|
|
struct awi_softc *sc = ifp->if_softc;
|
2001-09-18 13:09:57 +04:00
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
struct ieee80211_bss *bs = &ic->ic_bss;
|
|
|
|
int i, error;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
DPRINTF(("awi_init: enabled=%d\n", sc->sc_enabled));
|
|
|
|
if (sc->sc_enabled) {
|
|
|
|
awi_stop(ifp, 0);
|
|
|
|
} else {
|
2000-03-22 14:22:20 +03:00
|
|
|
if (sc->sc_enable)
|
|
|
|
(*sc->sc_enable)(sc);
|
2001-09-18 13:09:57 +04:00
|
|
|
sc->sc_enabled = 1;
|
|
|
|
if ((error = awi_hw_init(sc)) != 0) {
|
2001-06-28 14:40:04 +04:00
|
|
|
awi_stop(ifp, 1);
|
2000-03-22 14:22:20 +03:00
|
|
|
return error;
|
2001-06-28 14:40:04 +04:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
ic->ic_state = IEEE80211_S_INIT;
|
|
|
|
|
|
|
|
sc->sc_mib_local.Network_Mode =
|
|
|
|
(ic->ic_flags & IEEE80211_F_ADHOC) ? 0 : 1;
|
|
|
|
|
|
|
|
if ((error = awi_mode_init(sc)) != 0) {
|
|
|
|
DPRINTF(("awi_init: awi_mode_init failed %d\n", error));
|
2001-06-28 14:40:04 +04:00
|
|
|
awi_stop(ifp, 1);
|
2000-03-22 14:22:20 +03:00
|
|
|
return error;
|
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
/* start transmitter */
|
|
|
|
sc->sc_txdone = sc->sc_txnext = sc->sc_txbase;
|
|
|
|
awi_write_4(sc, sc->sc_txbase + AWI_TXD_START, 0);
|
|
|
|
awi_write_4(sc, sc->sc_txbase + AWI_TXD_NEXT, 0);
|
|
|
|
awi_write_4(sc, sc->sc_txbase + AWI_TXD_LENGTH, 0);
|
|
|
|
awi_write_1(sc, sc->sc_txbase + AWI_TXD_RATE, 0);
|
|
|
|
awi_write_4(sc, sc->sc_txbase + AWI_TXD_NDA, 0);
|
|
|
|
awi_write_4(sc, sc->sc_txbase + AWI_TXD_NRA, 0);
|
|
|
|
awi_write_1(sc, sc->sc_txbase + AWI_TXD_STATE, 0);
|
|
|
|
awi_write_4(sc, AWI_CA_TX_DATA, sc->sc_txbase);
|
|
|
|
awi_write_4(sc, AWI_CA_TX_MGT, 0);
|
|
|
|
awi_write_4(sc, AWI_CA_TX_BCAST, 0);
|
|
|
|
awi_write_4(sc, AWI_CA_TX_PS, 0);
|
|
|
|
awi_write_4(sc, AWI_CA_TX_CF, 0);
|
|
|
|
if ((error = awi_cmd(sc, AWI_CMD_INIT_TX, AWI_WAIT)) != 0) {
|
|
|
|
DPRINTF(("awi_init: failed to start transmitter: %d\n", error));
|
|
|
|
awi_stop(ifp, 1);
|
|
|
|
return error;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
|
|
|
|
/* start receiver */
|
|
|
|
if ((error = awi_cmd(sc, AWI_CMD_INIT_RX, AWI_WAIT)) != 0) {
|
|
|
|
DPRINTF(("awi_init: failed to start receiver: %d\n", error));
|
|
|
|
awi_stop(ifp, 1);
|
|
|
|
return error;
|
2000-06-09 09:31:15 +04:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
sc->sc_rxdoff = awi_read_4(sc, AWI_CA_IRX_DATA_DESC);
|
|
|
|
sc->sc_rxmoff = awi_read_4(sc, AWI_CA_IRX_PS_DESC);
|
|
|
|
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
if ((sc->sc_ic.ic_flags & IEEE80211_F_ADHOC) && sc->sc_no_bssid) {
|
|
|
|
bs->bs_chan = ic->ic_ibss_chan;
|
|
|
|
bs->bs_intval = ic->ic_lintval;
|
|
|
|
bs->bs_nrate = 0;
|
|
|
|
for (i = 0; i < IEEE80211_RATE_SIZE; i++) {
|
|
|
|
if (ic->ic_sup_rates[i])
|
|
|
|
bs->bs_rates[bs->bs_nrate++] =
|
|
|
|
ic->ic_sup_rates[i];
|
|
|
|
}
|
|
|
|
memcpy(bs->bs_macaddr, ic->ic_myaddr, IEEE80211_ADDR_LEN);
|
|
|
|
memset(bs->bs_bssid, 0, IEEE80211_ADDR_LEN);
|
|
|
|
bs->bs_esslen = 0;
|
|
|
|
ic->ic_flags |= IEEE80211_F_SIBSS;
|
|
|
|
ic->ic_state = IEEE80211_S_SCAN; /*XXX*/
|
|
|
|
sc->sc_substate = AWI_ST_NONE;
|
|
|
|
ieee80211_new_state(&ic->ic_if, IEEE80211_S_RUN, -1);
|
|
|
|
} else {
|
|
|
|
bs->bs_chan = sc->sc_cur_chan;
|
|
|
|
ieee80211_new_state(&ic->ic_if, IEEE80211_S_SCAN, -1);
|
2001-06-28 14:40:04 +04:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
return 0;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static void
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_stop(struct ifnet *ifp, int disable)
|
2000-03-22 14:22:20 +03:00
|
|
|
{
|
|
|
|
struct awi_softc *sc = ifp->if_softc;
|
1999-11-08 18:45:00 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
if (!sc->sc_enabled)
|
2000-03-22 14:22:20 +03:00
|
|
|
return;
|
1999-11-08 18:45:00 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
DPRINTF(("awi_stop(%d)\n", disable));
|
|
|
|
|
|
|
|
ieee80211_new_state(&sc->sc_ic.ic_if, IEEE80211_S_INIT, -1);
|
|
|
|
|
|
|
|
if (!sc->sc_invalid) {
|
|
|
|
if (sc->sc_cmd_inprog)
|
|
|
|
(void)awi_cmd_wait(sc);
|
|
|
|
(void)awi_cmd(sc, AWI_CMD_KILL_RX, AWI_WAIT);
|
|
|
|
sc->sc_cmd_inprog = AWI_CMD_FLUSH_TX;
|
|
|
|
awi_write_1(sc, AWI_CA_FTX_DATA, 1);
|
|
|
|
awi_write_1(sc, AWI_CA_FTX_MGT, 0);
|
|
|
|
awi_write_1(sc, AWI_CA_FTX_BCAST, 0);
|
|
|
|
awi_write_1(sc, AWI_CA_FTX_PS, 0);
|
|
|
|
awi_write_1(sc, AWI_CA_FTX_CF, 0);
|
|
|
|
(void)awi_cmd(sc, AWI_CMD_FLUSH_TX, AWI_WAIT);
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
sc->sc_tx_timer = sc->sc_rx_timer = 0;
|
|
|
|
if (sc->sc_rxpend != NULL) {
|
|
|
|
m_freem(sc->sc_rxpend);
|
|
|
|
sc->sc_rxpend = NULL;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
IFQ_PURGE(&ifp->if_snd);
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
if (disable) {
|
|
|
|
if (sc->sc_disable)
|
|
|
|
(*sc->sc_disable)(sc);
|
|
|
|
sc->sc_enabled = 0;
|
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static void
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_start(struct ifnet *ifp)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2000-03-22 14:22:20 +03:00
|
|
|
struct awi_softc *sc = ifp->if_softc;
|
2001-09-18 13:09:57 +04:00
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
struct mbuf *m, *m0;
|
|
|
|
int len;
|
2000-03-22 14:22:20 +03:00
|
|
|
u_int32_t txd, frame, ntxd;
|
|
|
|
u_int8_t rate;
|
2001-09-18 13:09:57 +04:00
|
|
|
|
|
|
|
if (!sc->sc_enabled || sc->sc_invalid)
|
|
|
|
return;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
for (;;) {
|
|
|
|
txd = sc->sc_txnext;
|
2001-09-18 13:09:57 +04:00
|
|
|
IF_POLL(&ic->ic_mgtq, m0);
|
2000-03-22 14:22:20 +03:00
|
|
|
if (m0 != NULL) {
|
|
|
|
if (awi_next_txd(sc, m0->m_pkthdr.len, &frame, &ntxd)) {
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
IF_DEQUEUE(&ic->ic_mgtq, m0);
|
2000-03-22 14:22:20 +03:00
|
|
|
} else {
|
2001-09-18 13:09:57 +04:00
|
|
|
if (ic->ic_state != IEEE80211_S_RUN)
|
2000-03-22 14:22:20 +03:00
|
|
|
break;
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_POLL(&ifp->if_snd, m0);
|
2000-03-22 14:22:20 +03:00
|
|
|
if (m0 == NULL)
|
|
|
|
break;
|
2001-09-18 13:09:57 +04:00
|
|
|
/*
|
|
|
|
* Need to calculate the real length to determine
|
|
|
|
* if the transmit buffer has a room for the packet.
|
|
|
|
*/
|
2000-06-09 09:31:15 +04:00
|
|
|
len = m0->m_pkthdr.len + sizeof(struct ieee80211_frame);
|
2001-09-18 13:09:57 +04:00
|
|
|
if (!(ifp->if_flags & IFF_LINK0) && !sc->sc_adhoc_ap)
|
2000-06-09 09:31:15 +04:00
|
|
|
len += sizeof(struct llc) -
|
|
|
|
sizeof(struct ether_header);
|
2001-09-18 13:09:57 +04:00
|
|
|
if (ic->ic_flags & IEEE80211_F_WEPON)
|
2000-06-09 09:31:15 +04:00
|
|
|
len += IEEE80211_WEP_IVLEN +
|
|
|
|
IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN;
|
|
|
|
if (awi_next_txd(sc, len, &frame, &ntxd)) {
|
2000-03-22 14:22:20 +03:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m0);
|
2001-09-18 13:09:57 +04:00
|
|
|
ifp->if_opackets++;
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m0);
|
2001-06-25 16:09:51 +04:00
|
|
|
#endif
|
2001-09-18 13:09:57 +04:00
|
|
|
if ((ifp->if_flags & IFF_LINK0) || sc->sc_adhoc_ap)
|
|
|
|
m0 = awi_ether_encap(sc, m0);
|
|
|
|
else
|
|
|
|
m0 = ieee80211_encap(ifp, m0);
|
|
|
|
if ((ic->ic_flags & IEEE80211_F_WEPON) && m0 != NULL)
|
|
|
|
m0 = ieee80211_wep_crypt(ifp, m0, 1);
|
2000-03-22 14:22:20 +03:00
|
|
|
if (m0 == NULL) {
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
continue;
|
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (m0->m_pkthdr.len != len) {
|
|
|
|
printf("%s: length %d should be %d\n",
|
|
|
|
ifp->if_xname, m0->m_pkthdr.len, len);
|
|
|
|
m_freem(m0);
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
|
|
|
|
if ((ifp->if_flags & IFF_DEBUG) && (ifp->if_flags & IFF_LINK2))
|
|
|
|
ieee80211_dump_pkt(m0->m_data, m0->m_len,
|
|
|
|
ic->ic_bss.bs_rates[ic->ic_bss.bs_txrate] &
|
|
|
|
IEEE80211_RATE_VAL, -1);
|
|
|
|
|
|
|
|
for (m = m0, len = 0; m != NULL; m = m->m_next) {
|
2000-03-22 14:22:20 +03:00
|
|
|
awi_write_bytes(sc, frame + len, mtod(m, u_int8_t *),
|
|
|
|
m->m_len);
|
|
|
|
len += m->m_len;
|
|
|
|
}
|
|
|
|
m_freem(m0);
|
2001-09-18 13:09:57 +04:00
|
|
|
rate = (ic->ic_bss.bs_rates[ic->ic_bss.bs_txrate] &
|
|
|
|
IEEE80211_RATE_VAL) * 5;
|
2000-03-22 14:22:20 +03:00
|
|
|
awi_write_1(sc, ntxd + AWI_TXD_STATE, 0);
|
|
|
|
awi_write_4(sc, txd + AWI_TXD_START, frame);
|
|
|
|
awi_write_4(sc, txd + AWI_TXD_NEXT, ntxd);
|
|
|
|
awi_write_4(sc, txd + AWI_TXD_LENGTH, len);
|
|
|
|
awi_write_1(sc, txd + AWI_TXD_RATE, rate);
|
|
|
|
awi_write_4(sc, txd + AWI_TXD_NDA, 0);
|
|
|
|
awi_write_4(sc, txd + AWI_TXD_NRA, 0);
|
|
|
|
awi_write_1(sc, txd + AWI_TXD_STATE, AWI_TXD_ST_OWN);
|
|
|
|
sc->sc_txnext = ntxd;
|
2001-09-18 13:09:57 +04:00
|
|
|
|
|
|
|
sc->sc_tx_timer = 5;
|
2000-03-22 14:22:20 +03:00
|
|
|
ifp->if_timer = 1;
|
|
|
|
}
|
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static void
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_watchdog(struct ifnet *ifp)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct awi_softc *sc = ifp->if_softc;
|
|
|
|
u_int32_t prevdone;
|
|
|
|
int ocansleep;
|
2000-03-22 14:22:20 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
ifp->if_timer = 0;
|
|
|
|
if (!sc->sc_enabled || sc->sc_invalid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ocansleep = sc->sc_cansleep;
|
|
|
|
sc->sc_cansleep = 0;
|
|
|
|
if (sc->sc_tx_timer) {
|
|
|
|
if (--sc->sc_tx_timer == 0) {
|
|
|
|
printf("%s: device timeout\n", ifp->if_xname);
|
|
|
|
prevdone = sc->sc_txdone;
|
|
|
|
awi_tx_int(sc);
|
|
|
|
if (sc->sc_txdone == prevdone) {
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
awi_init(ifp);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ifp->if_timer = 1;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
if (sc->sc_rx_timer) {
|
|
|
|
if (--sc->sc_rx_timer == 0) {
|
|
|
|
if (sc->sc_ic.ic_state == IEEE80211_S_RUN) {
|
|
|
|
ieee80211_new_state(ifp, IEEE80211_S_SCAN, -1);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
ifp->if_timer = 1;
|
|
|
|
}
|
|
|
|
/* TODO: rate control */
|
|
|
|
ieee80211_watchdog(ifp);
|
|
|
|
out:
|
|
|
|
sc->sc_cansleep = ocansleep;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
static int
|
|
|
|
awi_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct awi_softc *sc = ifp->if_softc;
|
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
int s, error;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
s = splnet();
|
|
|
|
/* serialize ioctl, since we may sleep */
|
|
|
|
if ((error = awi_lock(sc)) != 0)
|
|
|
|
goto cantlock;
|
2000-03-22 14:22:20 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
switch (cmd) {
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
if (ifp->if_flags & IFF_UP) {
|
|
|
|
if (sc->sc_enabled) {
|
|
|
|
/*
|
|
|
|
* To avoid rescanning another access point,
|
|
|
|
* do not call awi_init() here. Instead,
|
|
|
|
* only reflect promisc mode settings.
|
|
|
|
*/
|
|
|
|
error = awi_mode_init(sc);
|
|
|
|
} else
|
|
|
|
error = awi_init(ifp);
|
|
|
|
} else if (sc->sc_enabled)
|
|
|
|
awi_stop(ifp, 1);
|
|
|
|
break;
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
|
|
|
|
break;
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
error = (cmd == SIOCADDMULTI) ?
|
|
|
|
ether_addmulti(ifr, &sc->sc_ic.ic_ec) :
|
|
|
|
ether_delmulti(ifr, &sc->sc_ic.ic_ec);
|
|
|
|
if (error == ENETRESET) {
|
|
|
|
/* do not rescan */
|
|
|
|
if (sc->sc_enabled)
|
|
|
|
error = awi_mode_init(sc);
|
|
|
|
else
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = ieee80211_ioctl(ifp, cmd, data);
|
|
|
|
if (error == ENETRESET) {
|
|
|
|
if (sc->sc_enabled)
|
|
|
|
error = awi_init(ifp);
|
|
|
|
else
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
break;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_unlock(sc);
|
|
|
|
cantlock:
|
|
|
|
splx(s);
|
|
|
|
return error;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
/*
|
|
|
|
* Called from ifmedia_ioctl via awi_ioctl with lock obtained.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
awi_media_change(struct ifnet *ifp)
|
2000-03-22 14:22:20 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct awi_softc *sc = ifp->if_softc;
|
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
struct ifmedia_entry *ime;
|
|
|
|
int i, rate, error = 0;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
ime = sc->sc_media.ifm_cur;
|
|
|
|
if (IFM_SUBTYPE(ime->ifm_media) == IFM_AUTO) {
|
|
|
|
ic->ic_fixed_rate = -1;
|
|
|
|
} else {
|
|
|
|
rate = awi_media_opt2rate(sc, ime->ifm_media);
|
|
|
|
if (rate == 0)
|
|
|
|
return EINVAL;
|
|
|
|
for (i = 0; i < IEEE80211_RATE_SIZE; i++) {
|
|
|
|
if ((ic->ic_sup_rates[i] & IEEE80211_RATE_VAL) == rate)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == IEEE80211_RATE_SIZE)
|
|
|
|
return EINVAL;
|
|
|
|
ic->ic_fixed_rate = i;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ADHOC,-FLAG0 ADHOC, !no_bssid, !adhoc_ap IBSS
|
|
|
|
* ADHOC, FLAG0 ADHOC no_bssid, !adhoc_ap WaveLAN adhoc
|
|
|
|
* -ADHOC,-FLAG0 ~ADHOC, !no_bssid, !adhoc_ap Infra
|
|
|
|
* -ADHOC, FLAG0 ADHOC, !no_bssid, adhoc_ap Melco old AP
|
|
|
|
* also LINK0
|
|
|
|
*/
|
|
|
|
if (ime->ifm_media & IFM_IEEE80211_ADHOC) {
|
|
|
|
if ((ic->ic_flags & IEEE80211_F_ADHOC) == 0) {
|
|
|
|
ic->ic_flags |= IEEE80211_F_ADHOC;
|
|
|
|
error = ENETRESET;
|
|
|
|
}
|
|
|
|
ic->ic_flags |= IEEE80211_F_IBSSON;
|
|
|
|
if (sc->sc_mib_phy.IEEE_PHY_Type != AWI_PHY_TYPE_FH &&
|
|
|
|
(ime->ifm_media & IFM_FLAG0)) {
|
|
|
|
if (sc->sc_no_bssid == 0) {
|
|
|
|
sc->sc_no_bssid = 1;
|
|
|
|
error = ENETRESET;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sc->sc_no_bssid) {
|
|
|
|
sc->sc_no_bssid = 0;
|
|
|
|
error = ENETRESET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sc->sc_adhoc_ap) {
|
|
|
|
sc->sc_adhoc_ap = 0;
|
|
|
|
error = ENETRESET;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
|
|
|
} else {
|
2001-09-18 13:09:57 +04:00
|
|
|
ic->ic_flags &= ~IEEE80211_F_IBSSON;
|
|
|
|
if (sc->sc_no_bssid) {
|
|
|
|
sc->sc_no_bssid = 0;
|
|
|
|
error = ENETRESET;
|
|
|
|
}
|
|
|
|
if (ime->ifm_media & IFM_FLAG0) {
|
|
|
|
if ((ic->ic_flags & IEEE80211_F_ADHOC) == 0) {
|
|
|
|
ic->ic_flags |= IEEE80211_F_ADHOC;
|
|
|
|
error = ENETRESET;
|
|
|
|
}
|
|
|
|
if (!sc->sc_adhoc_ap) {
|
|
|
|
sc->sc_adhoc_ap = 1;
|
|
|
|
error = ENETRESET;
|
2000-07-04 18:27:56 +04:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
} else {
|
|
|
|
if (ic->ic_flags & IEEE80211_F_ADHOC) {
|
|
|
|
ic->ic_flags &= ~IEEE80211_F_ADHOC;
|
|
|
|
error = ENETRESET;
|
2000-07-04 18:27:56 +04:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
if (sc->sc_adhoc_ap) {
|
|
|
|
sc->sc_adhoc_ap = 0;
|
|
|
|
error = ENETRESET;
|
2000-07-04 18:27:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
if (error == ENETRESET) {
|
|
|
|
if (sc->sc_enabled)
|
|
|
|
error = awi_init(ifp);
|
|
|
|
else
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
return error;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static void
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_media_status(struct ifnet *ifp, struct ifmediareq *imr)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct awi_softc *sc = ifp->if_softc;
|
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
int rate;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
imr->ifm_status = IFM_AVALID;
|
|
|
|
if (ic->ic_state == IEEE80211_S_RUN)
|
|
|
|
imr->ifm_status |= IFM_ACTIVE;
|
|
|
|
imr->ifm_active = IFM_IEEE80211;
|
|
|
|
if (ic->ic_state == IEEE80211_S_RUN)
|
|
|
|
rate = ic->ic_bss.bs_rates[ic->ic_bss.bs_txrate] &
|
|
|
|
IEEE80211_RATE_VAL;
|
|
|
|
else {
|
|
|
|
if (ic->ic_fixed_rate == -1)
|
|
|
|
rate = 0;
|
|
|
|
else
|
|
|
|
rate = ic->ic_sup_rates[ic->ic_fixed_rate] &
|
|
|
|
IEEE80211_RATE_VAL;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
imr->ifm_active |= awi_media_rate2opt(sc, rate);
|
|
|
|
if (ic->ic_flags & IEEE80211_F_ADHOC) {
|
|
|
|
if (sc->sc_adhoc_ap)
|
|
|
|
imr->ifm_active |= IFM_FLAG0;
|
|
|
|
else {
|
|
|
|
imr->ifm_active |= IFM_IEEE80211_ADHOC;
|
|
|
|
if (sc->sc_no_bssid)
|
|
|
|
imr->ifm_active |= IFM_FLAG0;
|
2000-06-09 09:31:15 +04:00
|
|
|
}
|
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
static int
|
|
|
|
awi_mode_init(struct awi_softc *sc)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
|
|
|
int n, error;
|
|
|
|
struct ether_multi *enm;
|
|
|
|
struct ether_multistep step;
|
|
|
|
|
|
|
|
/* reinitialize muticast filter */
|
|
|
|
n = 0;
|
|
|
|
sc->sc_mib_local.Accept_All_Multicast_Dis = 0;
|
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
|
|
|
sc->sc_mib_mac.aPromiscuous_Enable = 1;
|
|
|
|
goto set_mib;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
sc->sc_mib_mac.aPromiscuous_Enable = 0;
|
|
|
|
ETHER_FIRST_MULTI(step, &sc->sc_ic.ic_ec, enm);
|
|
|
|
while (enm != NULL) {
|
|
|
|
if (n == AWI_GROUP_ADDR_SIZE ||
|
|
|
|
memcmp(enm->enm_addrlo, enm->enm_addrhi, IEEE80211_ADDR_LEN)
|
|
|
|
!= 0)
|
|
|
|
goto set_mib;
|
|
|
|
memcpy(sc->sc_mib_addr.aGroup_Addresses[n], enm->enm_addrlo,
|
|
|
|
IEEE80211_ADDR_LEN);
|
|
|
|
n++;
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
|
|
|
for (; n < AWI_GROUP_ADDR_SIZE; n++)
|
|
|
|
memset(sc->sc_mib_addr.aGroup_Addresses[n], 0, IEEE80211_ADDR_LEN);
|
|
|
|
sc->sc_mib_local.Accept_All_Multicast_Dis = 1;
|
|
|
|
|
|
|
|
set_mib:
|
|
|
|
if (sc->sc_mib_local.Accept_All_Multicast_Dis)
|
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
|
|
|
else
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
sc->sc_mib_mgt.Wep_Required =
|
|
|
|
(sc->sc_ic.ic_flags & IEEE80211_F_WEPON) ? 1 : 0;
|
|
|
|
|
|
|
|
if ((error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_LOCAL, AWI_WAIT)) ||
|
|
|
|
(error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_ADDR, AWI_WAIT)) ||
|
|
|
|
(error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_MAC, AWI_WAIT)) ||
|
|
|
|
(error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_MGT, AWI_WAIT)) ||
|
|
|
|
(error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_PHY, AWI_WAIT))) {
|
|
|
|
DPRINTF(("awi_mode_init: MIB set failed: %d\n", error));
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX should be moved to if_ieee80211subr.c ? */
|
|
|
|
static int
|
|
|
|
awi_media_rate2opt(struct awi_softc *sc, int rate)
|
|
|
|
{
|
|
|
|
int mword;
|
|
|
|
|
|
|
|
mword = 0;
|
|
|
|
switch (rate & IEEE80211_RATE_VAL) {
|
|
|
|
case 2:
|
|
|
|
if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH)
|
|
|
|
mword = IFM_IEEE80211_FH1;
|
|
|
|
else
|
|
|
|
mword = IFM_IEEE80211_DS1;
|
1999-11-04 20:10:53 +03:00
|
|
|
break;
|
2001-09-18 13:09:57 +04:00
|
|
|
case 4:
|
|
|
|
if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH)
|
|
|
|
mword = IFM_IEEE80211_FH2;
|
|
|
|
else
|
|
|
|
mword = IFM_IEEE80211_DS2;
|
1999-11-04 20:10:53 +03:00
|
|
|
break;
|
2001-09-18 13:09:57 +04:00
|
|
|
case 11:
|
|
|
|
if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_DS)
|
|
|
|
mword = IFM_IEEE80211_DS5;
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_DS)
|
|
|
|
mword = IFM_IEEE80211_DS11;
|
1999-11-04 20:10:53 +03:00
|
|
|
break;
|
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
return mword;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
awi_media_opt2rate(struct awi_softc *sc, int opt)
|
|
|
|
{
|
|
|
|
int rate;
|
|
|
|
|
|
|
|
rate = 0;
|
|
|
|
switch (IFM_SUBTYPE(opt)) {
|
|
|
|
case IFM_IEEE80211_FH1:
|
|
|
|
case IFM_IEEE80211_FH2:
|
|
|
|
if (sc->sc_mib_phy.IEEE_PHY_Type != AWI_PHY_TYPE_FH)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case IFM_IEEE80211_DS1:
|
|
|
|
case IFM_IEEE80211_DS2:
|
|
|
|
case IFM_IEEE80211_DS5:
|
|
|
|
case IFM_IEEE80211_DS11:
|
|
|
|
if (sc->sc_mib_phy.IEEE_PHY_Type != AWI_PHY_TYPE_DS)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (IFM_SUBTYPE(opt)) {
|
|
|
|
case IFM_IEEE80211_FH1:
|
|
|
|
case IFM_IEEE80211_DS1:
|
|
|
|
rate = 2;
|
|
|
|
break;
|
|
|
|
case IFM_IEEE80211_FH2:
|
|
|
|
case IFM_IEEE80211_DS2:
|
|
|
|
rate = 4;
|
|
|
|
break;
|
|
|
|
case IFM_IEEE80211_DS5:
|
|
|
|
rate = 11;
|
|
|
|
break;
|
|
|
|
case IFM_IEEE80211_DS11:
|
|
|
|
rate = 22;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rate;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static void
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_rx_int(struct awi_softc *sc)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
2000-03-22 14:22:20 +03:00
|
|
|
u_int8_t state, rate, rssi;
|
|
|
|
u_int16_t len;
|
2001-09-18 13:09:57 +04:00
|
|
|
u_int32_t frame, next, timoff, rxoff;
|
2000-03-22 14:22:20 +03:00
|
|
|
struct mbuf *m;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
rxoff = sc->sc_rxdoff;
|
|
|
|
for (;;) {
|
|
|
|
state = awi_read_1(sc, rxoff + AWI_RXD_HOST_DESC_STATE);
|
|
|
|
if (state & AWI_RXD_ST_OWN)
|
|
|
|
break;
|
|
|
|
if (!(state & AWI_RXD_ST_CONSUMED)) {
|
2001-09-18 13:09:57 +04:00
|
|
|
if (state & AWI_RXD_ST_RXERROR) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
goto rx_next;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
len = awi_read_2(sc, rxoff + AWI_RXD_LEN);
|
|
|
|
rate = awi_read_1(sc, rxoff + AWI_RXD_RATE);
|
|
|
|
rssi = awi_read_1(sc, rxoff + AWI_RXD_RSSI);
|
|
|
|
frame = awi_read_4(sc, rxoff + AWI_RXD_START_FRAME) &
|
|
|
|
0x7fff;
|
|
|
|
timoff = awi_read_4(sc, rxoff + AWI_RXD_LOCALTIME);
|
|
|
|
m = awi_devget(sc, frame, len);
|
|
|
|
if (m == NULL) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
goto rx_next;
|
|
|
|
}
|
|
|
|
if (state & AWI_RXD_ST_LF) {
|
|
|
|
/* TODO check my bss */
|
|
|
|
if (!(sc->sc_ic.ic_flags & IEEE80211_F_SIBSS) &&
|
|
|
|
sc->sc_ic.ic_state == IEEE80211_S_RUN) {
|
|
|
|
sc->sc_rx_timer = 10;
|
|
|
|
ifp->if_timer = 1;
|
|
|
|
}
|
|
|
|
if ((ifp->if_flags & IFF_DEBUG) &&
|
|
|
|
(ifp->if_flags & IFF_LINK2))
|
|
|
|
ieee80211_dump_pkt(m->m_data, m->m_len,
|
|
|
|
rate / 5, rssi);
|
|
|
|
if ((ifp->if_flags & IFF_LINK0) ||
|
|
|
|
sc->sc_adhoc_ap)
|
|
|
|
m = awi_ether_modcap(sc, m);
|
|
|
|
if (m == NULL)
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
else
|
|
|
|
ieee80211_input(ifp, m, rssi, timoff);
|
|
|
|
} else
|
|
|
|
sc->sc_rxpend = m;
|
|
|
|
rx_next:
|
2000-03-22 14:22:20 +03:00
|
|
|
state |= AWI_RXD_ST_CONSUMED;
|
|
|
|
awi_write_1(sc, rxoff + AWI_RXD_HOST_DESC_STATE, state);
|
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
next = awi_read_4(sc, rxoff + AWI_RXD_NEXT);
|
2000-03-22 14:22:20 +03:00
|
|
|
if (next & AWI_RXD_NEXT_LAST)
|
|
|
|
break;
|
|
|
|
/* make sure the next pointer is correct */
|
|
|
|
if (next != awi_read_4(sc, rxoff + AWI_RXD_NEXT))
|
|
|
|
break;
|
|
|
|
state |= AWI_RXD_ST_OWN;
|
|
|
|
awi_write_1(sc, rxoff + AWI_RXD_HOST_DESC_STATE, state);
|
|
|
|
rxoff = next & 0x7fff;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
sc->sc_rxdoff = rxoff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
awi_tx_int(struct awi_softc *sc)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
|
|
|
u_int8_t flags;
|
|
|
|
|
|
|
|
while (sc->sc_txdone != sc->sc_txnext) {
|
|
|
|
flags = awi_read_1(sc, sc->sc_txdone + AWI_TXD_STATE);
|
|
|
|
if ((flags & AWI_TXD_ST_OWN) || !(flags & AWI_TXD_ST_DONE))
|
|
|
|
break;
|
|
|
|
if (flags & AWI_TXD_ST_ERROR)
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
sc->sc_txdone = awi_read_4(sc, sc->sc_txdone + AWI_TXD_NEXT) &
|
|
|
|
0x7fff;
|
|
|
|
}
|
|
|
|
DPRINTF2(("awi_txint: txdone %d txnext %d txbase %d txend %d\n",
|
|
|
|
sc->sc_txdone, sc->sc_txnext, sc->sc_txbase, sc->sc_txend));
|
|
|
|
sc->sc_tx_timer = 0;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
awi_start(ifp);
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-06-09 09:31:15 +04:00
|
|
|
static struct mbuf *
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_devget(struct awi_softc *sc, u_int32_t off, u_int16_t len)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
2000-03-22 14:22:20 +03:00
|
|
|
struct mbuf *m;
|
2000-06-09 09:31:15 +04:00
|
|
|
struct mbuf *top, **mp;
|
2000-03-22 14:22:20 +03:00
|
|
|
u_int tlen;
|
|
|
|
|
|
|
|
top = sc->sc_rxpend;
|
2000-06-09 09:31:15 +04:00
|
|
|
mp = ⊤
|
2000-03-22 14:22:20 +03:00
|
|
|
if (top != NULL) {
|
|
|
|
sc->sc_rxpend = NULL;
|
|
|
|
top->m_pkthdr.len += len;
|
2000-07-04 18:27:56 +04:00
|
|
|
m = top;
|
2000-06-09 09:31:15 +04:00
|
|
|
while (*mp != NULL) {
|
|
|
|
m = *mp;
|
2000-03-22 14:22:20 +03:00
|
|
|
mp = &m->m_next;
|
2000-06-09 09:31:15 +04:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
if (m->m_flags & M_EXT)
|
|
|
|
tlen = m->m_ext.ext_size;
|
|
|
|
else if (m->m_flags & M_PKTHDR)
|
|
|
|
tlen = MHLEN;
|
|
|
|
else
|
|
|
|
tlen = MLEN;
|
|
|
|
tlen -= m->m_len;
|
|
|
|
if (tlen > len)
|
|
|
|
tlen = len;
|
|
|
|
awi_read_bytes(sc, off, mtod(m, u_int8_t *) + m->m_len, tlen);
|
|
|
|
off += tlen;
|
|
|
|
len -= tlen;
|
1999-11-09 17:58:07 +03:00
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
while (len > 0) {
|
|
|
|
if (top == NULL) {
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL)
|
|
|
|
return NULL;
|
2001-09-18 13:09:57 +04:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
2000-03-22 14:22:20 +03:00
|
|
|
m->m_pkthdr.len = len;
|
|
|
|
m->m_len = MHLEN;
|
2001-09-18 13:09:57 +04:00
|
|
|
m->m_flags |= M_HASFCS;
|
2000-03-22 14:22:20 +03:00
|
|
|
} else {
|
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL) {
|
|
|
|
m_freem(top);
|
|
|
|
return NULL;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
m->m_len = MLEN;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
if (len >= MINCLSIZE) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if (m->m_flags & M_EXT)
|
|
|
|
m->m_len = m->m_ext.ext_size;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2000-07-04 18:27:56 +04:00
|
|
|
if (top == NULL) {
|
|
|
|
int hdrlen = sizeof(struct ieee80211_frame) +
|
2001-09-18 13:09:57 +04:00
|
|
|
sizeof(struct llc);
|
2000-07-04 18:27:56 +04:00
|
|
|
caddr_t newdata = (caddr_t)
|
|
|
|
ALIGN(m->m_data + hdrlen) - hdrlen;
|
|
|
|
m->m_len -= newdata - m->m_data;
|
|
|
|
m->m_data = newdata;
|
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
if (m->m_len > len)
|
|
|
|
m->m_len = len;
|
|
|
|
awi_read_bytes(sc, off, mtod(m, u_int8_t *), m->m_len);
|
|
|
|
off += m->m_len;
|
|
|
|
len -= m->m_len;
|
|
|
|
*mp = m;
|
|
|
|
mp = &m->m_next;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
return top;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
/*
|
|
|
|
* Initialize hardware and start firmware to accept commands.
|
|
|
|
* Called everytime after power on firmware.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_hw_init(struct awi_softc *sc)
|
1999-11-09 17:58:07 +03:00
|
|
|
{
|
2000-03-22 14:22:20 +03:00
|
|
|
u_int8_t status;
|
|
|
|
u_int16_t intmask;
|
|
|
|
int i, error;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-27 16:54:59 +04:00
|
|
|
sc->sc_enab_intr = 0;
|
2000-07-04 18:27:56 +04:00
|
|
|
sc->sc_invalid = 0; /* XXX: really? */
|
2000-03-22 14:22:20 +03:00
|
|
|
awi_drvstate(sc, AWI_DRV_RESET);
|
1999-11-09 17:58:07 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
/* reset firmware */
|
|
|
|
am79c930_gcr_setbits(&sc->sc_chip, AM79C930_GCR_CORESET);
|
|
|
|
DELAY(100);
|
|
|
|
awi_write_1(sc, AWI_SELFTEST, 0);
|
2000-07-04 18:27:56 +04:00
|
|
|
awi_write_1(sc, AWI_CMD, 0);
|
|
|
|
awi_write_1(sc, AWI_BANNER, 0);
|
2000-03-22 14:22:20 +03:00
|
|
|
am79c930_gcr_clearbits(&sc->sc_chip, AM79C930_GCR_CORESET);
|
|
|
|
DELAY(100);
|
|
|
|
|
|
|
|
/* wait for selftest completion */
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
if (i >= AWI_SELFTEST_TIMEOUT*hz/1000) {
|
|
|
|
printf("%s: failed to complete selftest (timeout)\n",
|
1999-11-09 17:58:07 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
2000-03-22 14:22:20 +03:00
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
status = awi_read_1(sc, AWI_SELFTEST);
|
|
|
|
if ((status & 0xf0) == 0xf0)
|
1999-11-09 17:58:07 +03:00
|
|
|
break;
|
2000-03-22 14:22:20 +03:00
|
|
|
if (sc->sc_cansleep) {
|
|
|
|
sc->sc_sleep_cnt++;
|
|
|
|
(void)tsleep(sc, PWAIT, "awitst", 1);
|
|
|
|
sc->sc_sleep_cnt--;
|
|
|
|
} else {
|
|
|
|
DELAY(1000*1000/hz);
|
1999-11-09 17:58:07 +03:00
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
if (status != AWI_SELFTEST_PASSED) {
|
|
|
|
printf("%s: failed to complete selftest (code %x)\n",
|
|
|
|
sc->sc_dev.dv_xname, status);
|
|
|
|
return ENXIO;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
/* check banner to confirm firmware write it */
|
2000-06-09 09:31:15 +04:00
|
|
|
awi_read_bytes(sc, AWI_BANNER, sc->sc_banner, AWI_BANNER_LEN);
|
|
|
|
if (memcmp(sc->sc_banner, "PCnetMobile:", 12) != 0) {
|
2000-03-22 14:22:20 +03:00
|
|
|
printf("%s: failed to complete selftest (bad banner)\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
for (i = 0; i < AWI_BANNER_LEN; i++)
|
2000-06-09 09:31:15 +04:00
|
|
|
printf("%s%02x", i ? ":" : "\t", sc->sc_banner[i]);
|
2000-03-22 14:22:20 +03:00
|
|
|
printf("\n");
|
|
|
|
return ENXIO;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
/* initializing interrupt */
|
2000-03-27 16:54:59 +04:00
|
|
|
sc->sc_enab_intr = 1;
|
2000-03-22 14:22:20 +03:00
|
|
|
error = awi_intr_lock(sc);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
intmask = AWI_INT_GROGGY | AWI_INT_SCAN_CMPLT |
|
|
|
|
AWI_INT_TX | AWI_INT_RX | AWI_INT_CMD;
|
|
|
|
awi_write_1(sc, AWI_INTMASK, ~intmask & 0xff);
|
|
|
|
awi_write_1(sc, AWI_INTMASK2, 0);
|
|
|
|
awi_write_1(sc, AWI_INTSTAT, 0);
|
|
|
|
awi_write_1(sc, AWI_INTSTAT2, 0);
|
|
|
|
awi_intr_unlock(sc);
|
|
|
|
am79c930_gcr_setbits(&sc->sc_chip, AM79C930_GCR_ENECINT);
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-07-27 02:55:12 +04:00
|
|
|
/* issuing interface test command */
|
2001-09-18 13:09:57 +04:00
|
|
|
error = awi_cmd(sc, AWI_CMD_NOP, AWI_WAIT);
|
2000-03-22 14:22:20 +03:00
|
|
|
if (error) {
|
|
|
|
printf("%s: failed to complete selftest", sc->sc_dev.dv_xname);
|
2000-07-04 18:27:56 +04:00
|
|
|
if (error == ENXIO)
|
|
|
|
printf(" (no hardware)\n");
|
|
|
|
else if (error != EWOULDBLOCK)
|
2000-03-22 14:22:20 +03:00
|
|
|
printf(" (error %d)\n", error);
|
|
|
|
else if (sc->sc_cansleep)
|
|
|
|
printf(" (lost interrupt)\n");
|
|
|
|
else
|
|
|
|
printf(" (command timeout)\n");
|
|
|
|
}
|
|
|
|
return error;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-03-22 14:22:20 +03:00
|
|
|
* Extract the factory default MIB value from firmware and assign the driver
|
|
|
|
* default value.
|
|
|
|
* Called once at attaching the interface.
|
1999-11-04 20:10:53 +03:00
|
|
|
*/
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static int
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_init_mibs(struct awi_softc *sc)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2000-03-22 14:22:20 +03:00
|
|
|
int i, error;
|
2001-09-18 13:09:57 +04:00
|
|
|
struct awi_chanset *cs;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
if ((error = awi_mib(sc, AWI_CMD_GET_MIB, AWI_MIB_LOCAL, AWI_WAIT)) ||
|
|
|
|
(error = awi_mib(sc, AWI_CMD_GET_MIB, AWI_MIB_ADDR, AWI_WAIT)) ||
|
|
|
|
(error = awi_mib(sc, AWI_CMD_GET_MIB, AWI_MIB_MAC, AWI_WAIT)) ||
|
|
|
|
(error = awi_mib(sc, AWI_CMD_GET_MIB, AWI_MIB_MGT, AWI_WAIT)) ||
|
|
|
|
(error = awi_mib(sc, AWI_CMD_GET_MIB, AWI_MIB_PHY, AWI_WAIT))) {
|
|
|
|
printf("%s: failed to get default mib value (error %d)\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
return error;
|
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
memset(&sc->sc_ic.ic_chan_avail, 0, sizeof(sc->sc_ic.ic_chan_avail));
|
|
|
|
for (cs = awi_chanset; ; cs++) {
|
|
|
|
if (cs->cs_type == 0) {
|
|
|
|
printf("%s: failed to set available channel\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
if (cs->cs_type == sc->sc_mib_phy.IEEE_PHY_Type &&
|
|
|
|
cs->cs_region == sc->sc_mib_phy.aCurrent_Reg_Domain)
|
|
|
|
break;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2001-09-19 08:09:54 +04:00
|
|
|
if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
|
|
|
|
for (i = cs->cs_min; i <= cs->cs_max; i++) {
|
|
|
|
setbit(sc->sc_ic.ic_chan_avail,
|
|
|
|
IEEE80211_FH_CHAN(i % 3 + 1, i));
|
|
|
|
/*
|
|
|
|
* According to the IEEE 802.11 specification,
|
|
|
|
* hop pattern parameter for FH phy should be
|
|
|
|
* incremented by 3 for given hop chanset, i.e.,
|
|
|
|
* the chanset parameter is calculated for given
|
|
|
|
* hop patter. However, BayStack 650 Access Points
|
|
|
|
* apparently use fixed hop chanset parameter value
|
|
|
|
* 1 for any hop pattern. So we also try this
|
|
|
|
* combination of hop chanset and pattern.
|
|
|
|
*/
|
|
|
|
setbit(sc->sc_ic.ic_chan_avail,
|
|
|
|
IEEE80211_FH_CHAN(1, i));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = cs->cs_min; i <= cs->cs_max; i++)
|
|
|
|
setbit(sc->sc_ic.ic_chan_avail, i);
|
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
sc->sc_cur_chan = cs->cs_def;
|
|
|
|
|
|
|
|
memset(&sc->sc_mib_mac.aDesired_ESS_ID, 0, AWI_ESS_ID_SIZE);
|
|
|
|
sc->sc_mib_mac.aDesired_ESS_ID[0] = IEEE80211_ELEMID_SSID;
|
|
|
|
sc->sc_mib_local.Fragmentation_Dis = 1;
|
|
|
|
sc->sc_mib_local.Accept_All_Multicast_Dis = 1;
|
|
|
|
sc->sc_mib_local.Power_Saving_Mode_Dis = 1;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
/* allocate buffers */
|
|
|
|
sc->sc_txbase = AWI_BUFFERS;
|
|
|
|
sc->sc_txend = sc->sc_txbase +
|
|
|
|
(AWI_TXD_SIZE + sizeof(struct ieee80211_frame) +
|
|
|
|
sizeof(struct ether_header) + ETHERMTU) * AWI_NTXBUFS;
|
|
|
|
LE_WRITE_4(&sc->sc_mib_local.Tx_Buffer_Offset, sc->sc_txbase);
|
|
|
|
LE_WRITE_4(&sc->sc_mib_local.Tx_Buffer_Size,
|
|
|
|
sc->sc_txend - sc->sc_txbase);
|
|
|
|
LE_WRITE_4(&sc->sc_mib_local.Rx_Buffer_Offset, sc->sc_txend);
|
|
|
|
LE_WRITE_4(&sc->sc_mib_local.Rx_Buffer_Size,
|
|
|
|
AWI_BUFFERS_END - sc->sc_txend);
|
|
|
|
sc->sc_mib_local.Network_Mode = 1;
|
|
|
|
sc->sc_mib_local.Acting_as_AP = 0;
|
|
|
|
return 0;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
static int
|
|
|
|
awi_chan_check(void *arg, u_char *chanreq)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct awi_softc *sc = arg;
|
|
|
|
int i;
|
|
|
|
struct awi_chanset *cs;
|
|
|
|
u_char chanlist[(IEEE80211_CHAN_MAX+1)/NBBY];
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
for (cs = awi_chanset; cs->cs_type != 0; cs++) {
|
|
|
|
if (cs->cs_type != sc->sc_mib_phy.IEEE_PHY_Type)
|
2000-03-22 14:22:20 +03:00
|
|
|
continue;
|
2001-09-18 13:09:57 +04:00
|
|
|
memset(chanlist, 0, sizeof(chanlist));
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
if (i == IEEE80211_CHAN_MAX) {
|
|
|
|
sc->sc_mib_phy.aCurrent_Reg_Domain =
|
|
|
|
cs->cs_region;
|
|
|
|
memcpy(sc->sc_ic.ic_chan_avail, chanlist,
|
|
|
|
sizeof(sc->sc_ic.ic_chan_avail));
|
|
|
|
sc->sc_cur_chan = cs->cs_def;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (i >= cs->cs_min && i <= cs->cs_max)
|
|
|
|
setbit(chanlist, i);
|
|
|
|
else if (isset(chanreq, i))
|
|
|
|
break;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
return EINVAL;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static int
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_mib(struct awi_softc *sc, u_int8_t cmd, u_int8_t mib, int wflag)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2000-03-22 14:22:20 +03:00
|
|
|
int error;
|
|
|
|
u_int8_t size, *ptr;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
switch (mib) {
|
|
|
|
case AWI_MIB_LOCAL:
|
|
|
|
ptr = (u_int8_t *)&sc->sc_mib_local;
|
|
|
|
size = sizeof(sc->sc_mib_local);
|
|
|
|
break;
|
|
|
|
case AWI_MIB_ADDR:
|
|
|
|
ptr = (u_int8_t *)&sc->sc_mib_addr;
|
|
|
|
size = sizeof(sc->sc_mib_addr);
|
|
|
|
break;
|
|
|
|
case AWI_MIB_MAC:
|
|
|
|
ptr = (u_int8_t *)&sc->sc_mib_mac;
|
|
|
|
size = sizeof(sc->sc_mib_mac);
|
|
|
|
break;
|
|
|
|
case AWI_MIB_STAT:
|
|
|
|
ptr = (u_int8_t *)&sc->sc_mib_stat;
|
|
|
|
size = sizeof(sc->sc_mib_stat);
|
|
|
|
break;
|
|
|
|
case AWI_MIB_MGT:
|
|
|
|
ptr = (u_int8_t *)&sc->sc_mib_mgt;
|
|
|
|
size = sizeof(sc->sc_mib_mgt);
|
|
|
|
break;
|
|
|
|
case AWI_MIB_PHY:
|
|
|
|
ptr = (u_int8_t *)&sc->sc_mib_phy;
|
|
|
|
size = sizeof(sc->sc_mib_phy);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
if (sc->sc_cmd_inprog) {
|
2001-09-18 13:09:57 +04:00
|
|
|
if ((error = awi_cmd_wait(sc)) != 0) {
|
2000-07-04 18:27:56 +04:00
|
|
|
if (error == EWOULDBLOCK)
|
2001-09-18 13:09:57 +04:00
|
|
|
DPRINTF(("awi_mib: cmd %d inprog",
|
|
|
|
sc->sc_cmd_inprog));
|
2000-03-22 14:22:20 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
2000-07-04 18:27:56 +04:00
|
|
|
sc->sc_cmd_inprog = cmd;
|
2000-03-22 14:22:20 +03:00
|
|
|
if (cmd == AWI_CMD_SET_MIB)
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_write_bytes(sc, AWI_CA_MIB_DATA, ptr, size);
|
|
|
|
awi_write_1(sc, AWI_CA_MIB_TYPE, mib);
|
|
|
|
awi_write_1(sc, AWI_CA_MIB_SIZE, size);
|
|
|
|
awi_write_1(sc, AWI_CA_MIB_INDEX, 0);
|
|
|
|
if ((error = awi_cmd(sc, cmd, wflag)) != 0)
|
2000-03-22 14:22:20 +03:00
|
|
|
return error;
|
|
|
|
if (cmd == AWI_CMD_GET_MIB) {
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_read_bytes(sc, AWI_CA_MIB_DATA, ptr, size);
|
2000-03-22 14:22:20 +03:00
|
|
|
#ifdef AWI_DEBUG
|
2001-09-18 13:09:57 +04:00
|
|
|
if (awi_debug) {
|
2000-03-22 14:22:20 +03:00
|
|
|
int i;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
printf("awi_mib: #%d:", mib);
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
printf(" %02x", ptr[i]);
|
|
|
|
printf("\n");
|
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
#endif
|
1999-11-08 18:45:00 +03:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
return 0;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static int
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_cmd(struct awi_softc *sc, u_int8_t cmd, int wflag)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2000-03-22 14:22:20 +03:00
|
|
|
u_int8_t status;
|
|
|
|
int error = 0;
|
2001-09-18 13:09:57 +04:00
|
|
|
#ifdef AWI_DEBUG
|
|
|
|
static const char *cmdname[] = {
|
|
|
|
"IDLE", "NOP", "SET_MIB", "INIT_TX", "FLUSH_TX", "INIT_RX",
|
|
|
|
"KILL_RX", "SLEEP", "WAKE", "GET_MIB", "SCAN", "SYNC", "RESUME"
|
|
|
|
};
|
|
|
|
#endif
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
#ifdef AWI_DEBUG
|
|
|
|
if (awi_debug > 1) {
|
|
|
|
if (cmd >= sizeof(cmdname)/sizeof(cmdname[0]))
|
|
|
|
printf("awi_cmd: #%d", cmd);
|
|
|
|
else
|
|
|
|
printf("awi_cmd: %s", cmdname[cmd]);
|
|
|
|
printf(" %s\n", wflag == AWI_NOWAIT ? "nowait" : "wait");
|
|
|
|
}
|
|
|
|
#endif
|
2000-07-04 18:27:56 +04:00
|
|
|
sc->sc_cmd_inprog = cmd;
|
2000-03-22 14:22:20 +03:00
|
|
|
awi_write_1(sc, AWI_CMD_STATUS, AWI_STAT_IDLE);
|
|
|
|
awi_write_1(sc, AWI_CMD, cmd);
|
2001-09-18 13:09:57 +04:00
|
|
|
if (wflag == AWI_NOWAIT)
|
|
|
|
return EINPROGRESS;
|
|
|
|
if ((error = awi_cmd_wait(sc)) != 0)
|
2000-03-22 14:22:20 +03:00
|
|
|
return error;
|
|
|
|
status = awi_read_1(sc, AWI_CMD_STATUS);
|
|
|
|
awi_write_1(sc, AWI_CMD, 0);
|
|
|
|
switch (status) {
|
|
|
|
case AWI_STAT_OK:
|
|
|
|
break;
|
|
|
|
case AWI_STAT_BADPARM:
|
|
|
|
return EINVAL;
|
|
|
|
default:
|
|
|
|
printf("%s: command %d failed %x\n",
|
|
|
|
sc->sc_dev.dv_xname, cmd, status);
|
|
|
|
return ENXIO;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
return 0;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
static int
|
|
|
|
awi_cmd_wait(struct awi_softc *sc)
|
|
|
|
{
|
|
|
|
int i, error = 0;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (sc->sc_cmd_inprog) {
|
|
|
|
if (sc->sc_invalid)
|
|
|
|
return ENXIO;
|
|
|
|
if (awi_read_1(sc, AWI_CMD) != sc->sc_cmd_inprog) {
|
|
|
|
printf("%s: failed to access hardware\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
sc->sc_invalid = 1;
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
if (sc->sc_cansleep) {
|
|
|
|
sc->sc_sleep_cnt++;
|
|
|
|
error = tsleep(sc, PWAIT, "awicmd",
|
|
|
|
AWI_CMD_TIMEOUT*hz/1000);
|
|
|
|
sc->sc_sleep_cnt--;
|
|
|
|
} else {
|
|
|
|
if (awi_read_1(sc, AWI_CMD_STATUS) != AWI_STAT_IDLE) {
|
|
|
|
awi_cmd_done(sc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i++ >= AWI_CMD_TIMEOUT*1000/10)
|
|
|
|
error = EWOULDBLOCK;
|
|
|
|
else
|
|
|
|
DELAY(10);
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
DPRINTF(("awi_cmd_wait: cmd 0x%x, error %d\n",
|
|
|
|
sc->sc_cmd_inprog, error));
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static void
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_cmd_done(struct awi_softc *sc)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2000-03-22 14:22:20 +03:00
|
|
|
u_int8_t cmd, status;
|
1999-11-09 17:58:07 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
status = awi_read_1(sc, AWI_CMD_STATUS);
|
|
|
|
if (status == AWI_STAT_IDLE)
|
|
|
|
return; /* stray interrupt */
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-07-04 18:27:56 +04:00
|
|
|
cmd = sc->sc_cmd_inprog;
|
2000-03-22 14:22:20 +03:00
|
|
|
sc->sc_cmd_inprog = 0;
|
2001-09-18 13:09:57 +04:00
|
|
|
wakeup(sc);
|
2000-03-22 14:22:20 +03:00
|
|
|
awi_write_1(sc, AWI_CMD, 0);
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
if (status != AWI_STAT_OK) {
|
|
|
|
printf("%s: command %d failed %x\n",
|
|
|
|
sc->sc_dev.dv_xname, cmd, status);
|
2001-09-18 13:09:57 +04:00
|
|
|
sc->sc_substate = AWI_ST_NONE;
|
1999-11-04 20:10:53 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
if (sc->sc_substate != AWI_ST_NONE)
|
|
|
|
(void)ieee80211_new_state(&sc->sc_ic.ic_if, sc->sc_nstate, -1);
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static int
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_next_txd(struct awi_softc *sc, int len, u_int32_t *framep, u_int32_t *ntxdp)
|
2000-03-22 14:22:20 +03:00
|
|
|
{
|
|
|
|
u_int32_t txd, ntxd, frame;
|
|
|
|
|
|
|
|
txd = sc->sc_txnext;
|
|
|
|
frame = txd + AWI_TXD_SIZE;
|
|
|
|
if (frame + len > sc->sc_txend)
|
|
|
|
frame = sc->sc_txbase;
|
|
|
|
ntxd = frame + len;
|
|
|
|
if (ntxd + AWI_TXD_SIZE > sc->sc_txend)
|
|
|
|
ntxd = sc->sc_txbase;
|
|
|
|
*framep = frame;
|
|
|
|
*ntxdp = ntxd;
|
|
|
|
/*
|
|
|
|
* Determine if there are any room in ring buffer.
|
|
|
|
* --- send wait, === new data, +++ conflict (ENOBUFS)
|
|
|
|
* base........................end
|
|
|
|
* done----txd=====ntxd OK
|
|
|
|
* --txd=====done++++ntxd-- full
|
|
|
|
* --txd=====ntxd done-- OK
|
|
|
|
* ==ntxd done----txd=== OK
|
|
|
|
* ==done++++ntxd----txd=== full
|
|
|
|
* ++ntxd txd=====done++ full
|
|
|
|
*/
|
|
|
|
if (txd < ntxd) {
|
|
|
|
if (txd < sc->sc_txdone && ntxd + AWI_TXD_SIZE > sc->sc_txdone)
|
|
|
|
return ENOBUFS;
|
|
|
|
} else {
|
|
|
|
if (txd < sc->sc_txdone || ntxd + AWI_TXD_SIZE > sc->sc_txdone)
|
|
|
|
return ENOBUFS;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static int
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_lock(struct awi_softc *sc)
|
2000-03-22 14:22:20 +03:00
|
|
|
{
|
|
|
|
int error = 0;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
if (curproc == NULL) {
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* Though driver ioctl should be called with context,
|
|
|
|
* KAME ipv6 stack calls ioctl in interrupt for now.
|
|
|
|
* We simply abort the request if there are other
|
|
|
|
* ioctl requests in progress.
|
|
|
|
*/
|
2000-07-04 18:27:56 +04:00
|
|
|
if (sc->sc_busy) {
|
2000-03-22 14:22:20 +03:00
|
|
|
return EWOULDBLOCK;
|
2000-07-04 18:27:56 +04:00
|
|
|
if (sc->sc_invalid)
|
|
|
|
return ENXIO;
|
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
sc->sc_busy = 1;
|
|
|
|
sc->sc_cansleep = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
while (sc->sc_busy) {
|
2000-07-04 18:27:56 +04:00
|
|
|
if (sc->sc_invalid)
|
|
|
|
return ENXIO;
|
2000-03-22 14:22:20 +03:00
|
|
|
sc->sc_sleep_cnt++;
|
|
|
|
error = tsleep(sc, PWAIT | PCATCH, "awilck", 0);
|
|
|
|
sc->sc_sleep_cnt--;
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
sc->sc_busy = 1;
|
|
|
|
sc->sc_cansleep = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static void
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_unlock(struct awi_softc *sc)
|
2000-03-22 14:22:20 +03:00
|
|
|
{
|
|
|
|
sc->sc_busy = 0;
|
|
|
|
sc->sc_cansleep = 0;
|
|
|
|
if (sc->sc_sleep_cnt)
|
|
|
|
wakeup(sc);
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static int
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_intr_lock(struct awi_softc *sc)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2000-03-22 14:22:20 +03:00
|
|
|
u_int8_t status;
|
|
|
|
int i, retry;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
status = 1;
|
|
|
|
for (retry = 0; retry < 10; retry++) {
|
|
|
|
for (i = 0; i < AWI_LOCKOUT_TIMEOUT*1000/5; i++) {
|
2001-09-18 13:09:57 +04:00
|
|
|
if ((status = awi_read_1(sc, AWI_LOCKOUT_HOST)) == 0)
|
2000-03-22 14:22:20 +03:00
|
|
|
break;
|
|
|
|
DELAY(5);
|
|
|
|
}
|
|
|
|
if (status != 0)
|
|
|
|
break;
|
|
|
|
awi_write_1(sc, AWI_LOCKOUT_MAC, 1);
|
2001-09-18 13:09:57 +04:00
|
|
|
if ((status = awi_read_1(sc, AWI_LOCKOUT_HOST)) == 0)
|
2000-03-22 14:22:20 +03:00
|
|
|
break;
|
|
|
|
awi_write_1(sc, AWI_LOCKOUT_MAC, 0);
|
|
|
|
}
|
|
|
|
if (status != 0) {
|
|
|
|
printf("%s: failed to lock interrupt\n",
|
1999-11-08 18:45:00 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
2000-03-22 14:22:20 +03:00
|
|
|
return ENXIO;
|
1999-11-08 18:45:00 +03:00
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
return 0;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static void
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_intr_unlock(struct awi_softc *sc)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2000-03-22 14:22:20 +03:00
|
|
|
|
|
|
|
awi_write_1(sc, AWI_LOCKOUT_MAC, 0);
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2000-03-22 14:22:20 +03:00
|
|
|
static int
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_newstate(void *arg, enum ieee80211_state nstate)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct awi_softc *sc = arg;
|
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
struct ieee80211_bss *bs = &ic->ic_bss;
|
|
|
|
struct ifnet *ifp = &ic->ic_if;
|
2001-09-20 17:54:43 +04:00
|
|
|
int error;
|
2001-09-18 13:09:57 +04:00
|
|
|
u_int8_t newmode;
|
|
|
|
enum ieee80211_state ostate;
|
|
|
|
#ifdef AWI_DEBUG
|
|
|
|
static const char *stname[] =
|
|
|
|
{ "INIT", "SCAN", "AUTH", "ASSOC", "RUN" };
|
|
|
|
static const char *substname[] =
|
|
|
|
{ "NONE", "SCAN_INIT", "SCAN_SETMIB", "SCAN_SCCMD",
|
|
|
|
"SUB_INIT", "SUB_SETSS", "SUB_SYNC" };
|
|
|
|
#endif /* AWI_DEBUG */
|
|
|
|
|
|
|
|
ostate = ic->ic_state;
|
|
|
|
DPRINTF(("awi_newstate: %s (%s/%s) -> %s\n", stname[ostate],
|
|
|
|
stname[sc->sc_nstate], substname[sc->sc_substate], stname[nstate]));
|
|
|
|
|
|
|
|
/* set LED */
|
|
|
|
switch (nstate) {
|
|
|
|
case IEEE80211_S_INIT:
|
|
|
|
awi_drvstate(sc, AWI_DRV_RESET);
|
|
|
|
break;
|
|
|
|
case IEEE80211_S_SCAN:
|
|
|
|
if (ic->ic_flags & IEEE80211_F_ADHOC)
|
|
|
|
awi_drvstate(sc, AWI_DRV_ADHSC);
|
|
|
|
else
|
|
|
|
awi_drvstate(sc, AWI_DRV_INFSY);
|
|
|
|
break;
|
|
|
|
case IEEE80211_S_AUTH:
|
|
|
|
awi_drvstate(sc, AWI_DRV_INFSY);
|
|
|
|
break;
|
|
|
|
case IEEE80211_S_ASSOC:
|
|
|
|
awi_drvstate(sc, AWI_DRV_INFAUTH);
|
|
|
|
break;
|
|
|
|
case IEEE80211_S_RUN:
|
|
|
|
if (ic->ic_flags & IEEE80211_F_ADHOC)
|
|
|
|
awi_drvstate(sc, AWI_DRV_ADHSY);
|
|
|
|
else
|
|
|
|
awi_drvstate(sc, AWI_DRV_INFASSOC);
|
|
|
|
break;
|
|
|
|
}
|
2000-03-22 14:22:20 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
if (nstate == IEEE80211_S_INIT) {
|
|
|
|
sc->sc_substate = AWI_ST_NONE;
|
|
|
|
ic->ic_flags &= ~IEEE80211_F_SIBSS;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* state transition */
|
|
|
|
if (nstate == IEEE80211_S_SCAN) {
|
|
|
|
/* SCAN substate */
|
|
|
|
if (sc->sc_substate == AWI_ST_NONE) {
|
|
|
|
sc->sc_nstate = nstate; /* next state in transition */
|
|
|
|
sc->sc_substate = AWI_ST_SCAN_INIT;
|
|
|
|
}
|
|
|
|
switch (sc->sc_substate) {
|
|
|
|
case AWI_ST_SCAN_INIT:
|
|
|
|
sc->sc_substate = AWI_ST_SCAN_SETMIB;
|
|
|
|
switch (ostate) {
|
|
|
|
case IEEE80211_S_RUN:
|
|
|
|
/* beacon miss */
|
|
|
|
if (ifp->if_flags & IFF_DEBUG)
|
|
|
|
printf("%s: no recent beacons from %s;"
|
|
|
|
" rescanning\n",
|
|
|
|
ifp->if_xname,
|
|
|
|
ether_sprintf(ic->ic_bss.bs_bssid));
|
|
|
|
/* FALLTHRU */
|
|
|
|
case IEEE80211_S_AUTH:
|
|
|
|
case IEEE80211_S_ASSOC:
|
|
|
|
/* timeout restart scan */
|
|
|
|
ieee80211_free_scan(ifp);
|
|
|
|
/* FALLTHRU */
|
|
|
|
case IEEE80211_S_INIT:
|
|
|
|
ic->ic_flags |= IEEE80211_F_ASCAN;
|
|
|
|
ic->ic_scan_timer = 0;
|
|
|
|
/* FALLTHRU */
|
|
|
|
case IEEE80211_S_SCAN:
|
|
|
|
/* scan next */
|
2000-03-22 14:22:20 +03:00
|
|
|
break;
|
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
if (ic->ic_flags & IEEE80211_F_ASCAN)
|
|
|
|
newmode = AWI_SCAN_ACTIVE;
|
2000-03-22 14:22:20 +03:00
|
|
|
else
|
2001-09-18 13:09:57 +04:00
|
|
|
newmode = AWI_SCAN_PASSIVE;
|
|
|
|
if (sc->sc_mib_mgt.aScan_Mode != newmode) {
|
|
|
|
sc->sc_mib_mgt.aScan_Mode = newmode;
|
|
|
|
if ((error = awi_mib(sc, AWI_CMD_SET_MIB,
|
|
|
|
AWI_MIB_MGT, AWI_NOWAIT)) != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FALLTHRU */
|
|
|
|
case AWI_ST_SCAN_SETMIB:
|
|
|
|
sc->sc_substate = AWI_ST_SCAN_SCCMD;
|
|
|
|
if (sc->sc_cmd_inprog) {
|
|
|
|
if ((error = awi_cmd_wait(sc)) != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc->sc_cmd_inprog = AWI_CMD_SCAN;
|
|
|
|
awi_write_2(sc, AWI_CA_SCAN_DURATION,
|
|
|
|
(ic->ic_flags & IEEE80211_F_ASCAN) ?
|
|
|
|
AWI_ASCAN_DURATION : AWI_PSCAN_DURATION);
|
|
|
|
if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
|
2001-09-19 08:09:54 +04:00
|
|
|
awi_write_1(sc, AWI_CA_SCAN_SET,
|
|
|
|
IEEE80211_FH_CHANSET(bs->bs_chan));
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_write_1(sc, AWI_CA_SCAN_PATTERN,
|
2001-09-19 08:09:54 +04:00
|
|
|
IEEE80211_FH_CHANPAT(bs->bs_chan));
|
2001-09-18 13:09:57 +04:00
|
|
|
awi_write_1(sc, AWI_CA_SCAN_IDX, 1);
|
|
|
|
} else {
|
|
|
|
awi_write_1(sc, AWI_CA_SCAN_SET, bs->bs_chan);
|
|
|
|
awi_write_1(sc, AWI_CA_SCAN_PATTERN, 0);
|
|
|
|
awi_write_1(sc, AWI_CA_SCAN_IDX, 0);
|
|
|
|
}
|
|
|
|
awi_write_1(sc, AWI_CA_SCAN_SUSP, 0);
|
|
|
|
sc->sc_cur_chan = bs->bs_chan;
|
|
|
|
if ((error = awi_cmd(sc, AWI_CMD_SCAN, AWI_NOWAIT))
|
|
|
|
!= 0)
|
|
|
|
break;
|
|
|
|
/* FALLTHRU */
|
|
|
|
case AWI_ST_SCAN_SCCMD:
|
|
|
|
if (ic->ic_scan_timer == 0)
|
|
|
|
ic->ic_scan_timer =
|
|
|
|
(ic->ic_flags & IEEE80211_F_ASCAN) ?
|
|
|
|
IEEE80211_ASCAN_WAIT : IEEE80211_PSCAN_WAIT;
|
|
|
|
ifp->if_timer = 1;
|
|
|
|
ic->ic_state = nstate;
|
|
|
|
sc->sc_substate = AWI_ST_NONE;
|
|
|
|
error = EINPROGRESS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DPRINTF(("awi_newstate: unexpected state %s/%s\n",
|
|
|
|
stname[nstate], substname[sc->sc_substate]));
|
|
|
|
sc->sc_substate = AWI_ST_NONE;
|
|
|
|
error = EIO;
|
2000-03-22 14:22:20 +03:00
|
|
|
break;
|
2001-09-18 13:09:57 +04:00
|
|
|
}
|
|
|
|
return error;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
if (ostate == IEEE80211_S_SCAN) {
|
|
|
|
/* set SSID and channel */
|
|
|
|
/* substate */
|
|
|
|
if (sc->sc_substate == AWI_ST_NONE) {
|
|
|
|
sc->sc_nstate = nstate; /* next state in transition */
|
|
|
|
sc->sc_substate = AWI_ST_SUB_INIT;
|
|
|
|
}
|
|
|
|
switch (sc->sc_substate) {
|
|
|
|
case AWI_ST_SUB_INIT:
|
|
|
|
sc->sc_substate = AWI_ST_SUB_SETSS;
|
|
|
|
memcpy(&sc->sc_mib_mgt.aCurrent_BSS_ID, bs->bs_bssid,
|
|
|
|
IEEE80211_ADDR_LEN);
|
|
|
|
memset(&sc->sc_mib_mgt.aCurrent_ESS_ID, 0,
|
|
|
|
AWI_ESS_ID_SIZE);
|
|
|
|
sc->sc_mib_mgt.aCurrent_ESS_ID[0] =
|
|
|
|
IEEE80211_ELEMID_SSID;
|
|
|
|
sc->sc_mib_mgt.aCurrent_ESS_ID[1] = bs->bs_esslen;
|
|
|
|
memcpy(&sc->sc_mib_mgt.aCurrent_ESS_ID[2],
|
|
|
|
bs->bs_essid, bs->bs_esslen);
|
|
|
|
LE_WRITE_2(&sc->sc_mib_mgt.aBeacon_Period,
|
|
|
|
bs->bs_intval);
|
|
|
|
if ((error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_MGT,
|
|
|
|
AWI_NOWAIT)) != 0)
|
|
|
|
break;
|
|
|
|
/* FALLTHRU */
|
|
|
|
case AWI_ST_SUB_SETSS:
|
|
|
|
sc->sc_substate = AWI_ST_SUB_SYNC;
|
|
|
|
if (sc->sc_cmd_inprog) {
|
|
|
|
if (awi_cmd_wait(sc))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc->sc_cmd_inprog = AWI_CMD_SYNC;
|
|
|
|
if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
|
2001-09-19 08:09:54 +04:00
|
|
|
awi_write_1(sc, AWI_CA_SYNC_SET,
|
|
|
|
IEEE80211_FH_CHANSET(bs->bs_chan));
|
|
|
|
awi_write_1(sc, AWI_CA_SYNC_PATTERN,
|
|
|
|
IEEE80211_FH_CHANPAT(bs->bs_chan));
|
2001-09-20 17:54:43 +04:00
|
|
|
awi_write_1(sc, AWI_CA_SYNC_IDX,
|
|
|
|
bs->bs_fhindex);
|
|
|
|
awi_write_2(sc, AWI_CA_SYNC_DWELL,
|
|
|
|
bs->bs_fhdwell);
|
2001-09-18 13:09:57 +04:00
|
|
|
} else {
|
|
|
|
awi_write_1(sc, AWI_CA_SYNC_SET, bs->bs_chan);
|
|
|
|
awi_write_1(sc, AWI_CA_SYNC_PATTERN, 0);
|
2001-09-20 17:54:43 +04:00
|
|
|
awi_write_1(sc, AWI_CA_SYNC_IDX, 0);
|
|
|
|
awi_write_2(sc, AWI_CA_SYNC_DWELL, 0);
|
2001-09-18 13:09:57 +04:00
|
|
|
}
|
|
|
|
if ((ic->ic_flags & IEEE80211_F_SIBSS) &&
|
|
|
|
!sc->sc_no_bssid)
|
|
|
|
awi_write_1(sc, AWI_CA_SYNC_STARTBSS, 1);
|
|
|
|
else
|
|
|
|
awi_write_1(sc, AWI_CA_SYNC_STARTBSS, 0);
|
|
|
|
awi_write_2(sc, AWI_CA_SYNC_MBZ, 0);
|
|
|
|
awi_write_bytes(sc, AWI_CA_SYNC_TIMESTAMP,
|
|
|
|
bs->bs_tstamp, 8);
|
|
|
|
awi_write_4(sc, AWI_CA_SYNC_REFTIME, bs->bs_timoff);
|
|
|
|
sc->sc_cur_chan = bs->bs_chan;
|
|
|
|
if ((error = awi_cmd(sc, AWI_CMD_SYNC, AWI_NOWAIT))
|
|
|
|
!= 0)
|
|
|
|
break;
|
|
|
|
/* FALLTHRU */
|
|
|
|
case AWI_ST_SUB_SYNC:
|
|
|
|
sc->sc_substate = AWI_ST_NONE;
|
|
|
|
if (ic->ic_flags & IEEE80211_F_SIBSS) {
|
|
|
|
if ((error = awi_mib(sc, AWI_CMD_GET_MIB,
|
|
|
|
AWI_MIB_MGT, AWI_WAIT)) != 0)
|
|
|
|
break;
|
|
|
|
memcpy(bs->bs_bssid,
|
|
|
|
&sc->sc_mib_mgt.aCurrent_BSS_ID,
|
|
|
|
IEEE80211_ADDR_LEN);
|
|
|
|
} else {
|
|
|
|
if (nstate == IEEE80211_S_RUN) {
|
|
|
|
sc->sc_rx_timer = 10;
|
|
|
|
ifp->if_timer = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error = 0;
|
2000-07-04 18:27:56 +04:00
|
|
|
break;
|
2001-09-18 13:09:57 +04:00
|
|
|
default:
|
|
|
|
DPRINTF(("awi_newstate: unexpected state %s/%s\n",
|
|
|
|
stname[nstate], substname[sc->sc_substate]));
|
|
|
|
sc->sc_substate = AWI_ST_NONE;
|
|
|
|
error = EIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return error;
|
2000-07-04 18:27:56 +04:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
|
|
|
|
sc->sc_substate = AWI_ST_NONE;
|
|
|
|
|
|
|
|
return 0;
|
2000-07-04 18:27:56 +04:00
|
|
|
}
|
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
static struct mbuf *
|
|
|
|
awi_ether_encap(struct awi_softc *sc, struct mbuf *m)
|
1999-11-04 20:10:53 +03:00
|
|
|
{
|
2001-09-18 13:09:57 +04:00
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
struct ieee80211_bss *bs = &ic->ic_bss;
|
|
|
|
struct ether_header *eh;
|
2000-03-22 14:22:20 +03:00
|
|
|
struct ieee80211_frame *wh;
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
if (m->m_len < sizeof(struct ether_header)) {
|
|
|
|
m = m_pullup(m, sizeof(struct ether_header));
|
|
|
|
if (m == NULL)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
eh = mtod(m, struct ether_header *);
|
|
|
|
M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT);
|
|
|
|
if (m == NULL)
|
|
|
|
return NULL;
|
2000-03-22 14:22:20 +03:00
|
|
|
wh = mtod(m, struct ieee80211_frame *);
|
2001-09-18 13:09:57 +04:00
|
|
|
wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA;
|
|
|
|
*(u_int16_t *)wh->i_dur = 0;
|
|
|
|
*(u_int16_t *)wh->i_seq =
|
|
|
|
htole16(bs->bs_txseq << IEEE80211_SEQ_SEQ_SHIFT);
|
|
|
|
bs->bs_txseq++;
|
|
|
|
if (ic->ic_flags & IEEE80211_F_ADHOC) {
|
|
|
|
wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
|
|
|
|
if (sc->sc_adhoc_ap)
|
|
|
|
memcpy(wh->i_addr1, bs->bs_macaddr, IEEE80211_ADDR_LEN);
|
|
|
|
else
|
|
|
|
memcpy(wh->i_addr1, eh->ether_dhost,
|
|
|
|
IEEE80211_ADDR_LEN);
|
|
|
|
memcpy(wh->i_addr2, eh->ether_shost, IEEE80211_ADDR_LEN);
|
|
|
|
memcpy(wh->i_addr3, bs->bs_bssid, IEEE80211_ADDR_LEN);
|
|
|
|
} else {
|
|
|
|
wh->i_fc[1] = IEEE80211_FC1_DIR_TODS;
|
|
|
|
memcpy(wh->i_addr1, bs->bs_bssid, IEEE80211_ADDR_LEN);
|
|
|
|
memcpy(wh->i_addr2, eh->ether_shost, IEEE80211_ADDR_LEN);
|
|
|
|
memcpy(wh->i_addr3, eh->ether_dhost, IEEE80211_ADDR_LEN);
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
return m;
|
|
|
|
}
|
1999-11-04 20:10:53 +03:00
|
|
|
|
2001-09-18 13:09:57 +04:00
|
|
|
static struct mbuf *
|
|
|
|
awi_ether_modcap(struct awi_softc *sc, struct mbuf *m)
|
|
|
|
{
|
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
struct ether_header eh;
|
|
|
|
struct ieee80211_frame wh;
|
|
|
|
struct llc *llc;
|
|
|
|
|
|
|
|
if (m->m_len < sizeof(wh) + sizeof(eh)) {
|
|
|
|
m = m_pullup(m, sizeof(wh) + sizeof(eh));
|
|
|
|
if (m == NULL)
|
|
|
|
return NULL;
|
2000-03-22 14:22:20 +03:00
|
|
|
}
|
2001-09-18 13:09:57 +04:00
|
|
|
memcpy(&wh, mtod(m, caddr_t), sizeof(wh));
|
|
|
|
if (wh.i_fc[0] != (IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA))
|
|
|
|
return m;
|
|
|
|
memcpy(&eh, mtod(m, caddr_t) + sizeof(wh), sizeof(eh));
|
|
|
|
m_adj(m, sizeof(eh) - sizeof(*llc));
|
|
|
|
if (ic->ic_flags & IEEE80211_F_ADHOC)
|
|
|
|
memcpy(wh.i_addr2, eh.ether_shost, IEEE80211_ADDR_LEN);
|
|
|
|
memcpy(mtod(m, caddr_t), &wh, sizeof(wh));
|
|
|
|
llc = (struct llc *)(mtod(m, caddr_t) + sizeof(wh));
|
|
|
|
llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
|
|
|
|
llc->llc_control = LLC_UI;
|
|
|
|
llc->llc_snap.org_code[0] = 0;
|
|
|
|
llc->llc_snap.org_code[1] = 0;
|
|
|
|
llc->llc_snap.org_code[2] = 0;
|
|
|
|
llc->llc_snap.ether_type = eh.ether_type;
|
|
|
|
return m;
|
1999-11-04 20:10:53 +03:00
|
|
|
}
|